Skip to content

Commit

Permalink
Include @OverRide and @deprecated annotations in output
Browse files Browse the repository at this point in the history
  • Loading branch information
dmssargent committed Jul 14, 2019
1 parent b48d7a0 commit 1ec2419
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 11 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ checkstyle {
}

group 'davidsar.gent'
version '0.2.0-alpha.7'
version '0.2.0-alpha.8'


sourceCompatibility = 1.8
Expand Down
28 changes: 24 additions & 4 deletions src/main/java/davidsar/gent/stubjars/components/JarClass.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,14 @@
package davidsar.gent.stubjars.components;

import davidsar.gent.stubjars.Utils;
import davidsar.gent.stubjars.components.expressions.*;
import davidsar.gent.stubjars.components.expressions.AnnotationExpression;
import davidsar.gent.stubjars.components.expressions.ClassHeaderExpression;
import davidsar.gent.stubjars.components.expressions.CompileableExpression;
import davidsar.gent.stubjars.components.expressions.EnumMembers;
import davidsar.gent.stubjars.components.expressions.Expression;
import davidsar.gent.stubjars.components.expressions.Expressions;
import davidsar.gent.stubjars.components.expressions.StringExpression;
import davidsar.gent.stubjars.components.expressions.TypeExpression;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.slf4j.Logger;
Expand All @@ -26,7 +33,13 @@
import java.lang.reflect.Method;
import java.lang.reflect.Type;
import java.net.URLClassLoader;
import java.util.*;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -441,12 +454,19 @@ public Expression compileTypeParameters() {

@NotNull
public Expression compileHeaderAnnotation() {
final Expression annotationS;
Expression annotationS;
if (isAnnotation() && getClazz().isAnnotationPresent(Retention.class)) {
RetentionPolicy retentionPolicy = getClazz().getAnnotation(Retention.class).value();
annotationS = new AnnotationExpression(this, Retention.class, retentionPolicy.name());
if (getClazz().isAnnotationPresent(Deprecated.class)) {
annotationS = Expressions.of(StringExpression.ANNOTATION_DEPRECATED, StringExpression.SPACE, annotationS);
}
} else {
annotationS = StringExpression.EMPTY;
if (getClazz().isAnnotationPresent(Deprecated.class)) {
annotationS = StringExpression.ANNOTATION_DEPRECATED;
} else {
annotationS = StringExpression.EMPTY;
}
}
return annotationS;
}
Expand Down
21 changes: 15 additions & 6 deletions src/main/java/davidsar/gent/stubjars/components/JarMethod.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,21 @@

package davidsar.gent.stubjars.components;

import davidsar.gent.stubjars.components.expressions.*;
import davidsar.gent.stubjars.components.expressions.CompileableExpression;
import davidsar.gent.stubjars.components.expressions.Expression;
import davidsar.gent.stubjars.components.expressions.Expressions;
import davidsar.gent.stubjars.components.expressions.MethodDeclarationExpression;
import davidsar.gent.stubjars.components.expressions.StringExpression;
import org.jetbrains.annotations.NotNull;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.lang.reflect.*;
import java.lang.reflect.AnnotatedElement;
import java.lang.reflect.GenericArrayType;
import java.lang.reflect.Method;
import java.lang.reflect.Parameter;
import java.lang.reflect.Type;
import java.lang.reflect.TypeVariable;
import java.util.Arrays;
import java.util.Set;

Expand Down Expand Up @@ -80,10 +89,6 @@ private Expression buildMethod(boolean isEnumField) {
}

Expression methodDeclaration = MethodDeclarationExpression.from(this, isEnumField).getFormattedString();
if (isEnumField) {
int i = 1;
i += 1;
}

// What should the method body be?
final Expression stubMethod;
Expand Down Expand Up @@ -219,4 +224,8 @@ Expression compileToExpression(boolean isEnumField) {
public JarClass<?> getParentClazz() {
return parentClazz;
}

public AnnotatedElement method() {
return method;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@ public MethodDeclarationExpression(List<Expression> children) {
public static MethodDeclarationExpression from(JarMethod method, boolean isEnumField) {
// Figure out method signature
List<Expression> signature = new ArrayList<>();
if (method.method().isAnnotationPresent(Deprecated.class)) {
signature.add(StringExpression.ANNOTATION_DEPRECATED);
}

if (method.method().isAnnotationPresent(Override.class)) {
signature.add(StringExpression.ANNOTATION_OVERRIDE);
}

if (!method.getParentClazz().isInterface()) {
signature.add(method.security().expression());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ public final class StringExpression extends Expression implements FormattedExpre
public static final Expression THROWS = new StringExpression(Constants.THROWS);
public static final Expression VARARGS = new StringExpression(Constants.VARARGS);
public static final Expression RETURN = new StringExpression(Constants.RETURN);
public static final Expression ANNOTATION_OVERRIDE = new StringExpression(Constants.ANNOTATION_OVERRIDE);
public static final Expression ANNOTATION_DEPRECATED = new StringExpression(Constants.ANNOTATION_DEPRECATED);
static final Expression LEFT_PAREN = new StringExpression(Constants.LEFT_PAREN);
static final Expression RIGHT_PAREN = new StringExpression(Constants.RIGHT_PAREN);
public static final Expression SPACE = new StringExpression(Constants.SPACE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,6 @@ public class Constants {
public static final String THROWS = "throws";
public static final String VARARGS = "...";
public static final String RETURN = "return";
public static final String ANNOTATION_DEPRECATED = "@Deprecated";
public static final String ANNOTATION_OVERRIDE = "@Override";
}

0 comments on commit 1ec2419

Please sign in to comment.