diff --git a/build.gradle b/build.gradle index 23e4276..230a5ba 100644 --- a/build.gradle +++ b/build.gradle @@ -11,7 +11,7 @@ checkstyle { } group 'davidsar.gent' -version '0.2.0-alpha.7' +version '0.2.0-alpha.8' sourceCompatibility = 1.8 diff --git a/src/main/java/davidsar/gent/stubjars/components/JarClass.java b/src/main/java/davidsar/gent/stubjars/components/JarClass.java index ecadadb..30eaa93 100644 --- a/src/main/java/davidsar/gent/stubjars/components/JarClass.java +++ b/src/main/java/davidsar/gent/stubjars/components/JarClass.java @@ -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; @@ -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; @@ -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; } diff --git a/src/main/java/davidsar/gent/stubjars/components/JarMethod.java b/src/main/java/davidsar/gent/stubjars/components/JarMethod.java index 6558fa1..de879ca 100644 --- a/src/main/java/davidsar/gent/stubjars/components/JarMethod.java +++ b/src/main/java/davidsar/gent/stubjars/components/JarMethod.java @@ -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; @@ -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; @@ -219,4 +224,8 @@ Expression compileToExpression(boolean isEnumField) { public JarClass getParentClazz() { return parentClazz; } + + public AnnotatedElement method() { + return method; + } } diff --git a/src/main/java/davidsar/gent/stubjars/components/expressions/MethodDeclarationExpression.java b/src/main/java/davidsar/gent/stubjars/components/expressions/MethodDeclarationExpression.java index dc50350..5fb7f94 100644 --- a/src/main/java/davidsar/gent/stubjars/components/expressions/MethodDeclarationExpression.java +++ b/src/main/java/davidsar/gent/stubjars/components/expressions/MethodDeclarationExpression.java @@ -18,6 +18,13 @@ public MethodDeclarationExpression(List children) { public static MethodDeclarationExpression from(JarMethod method, boolean isEnumField) { // Figure out method signature List 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()); diff --git a/src/main/java/davidsar/gent/stubjars/components/expressions/StringExpression.java b/src/main/java/davidsar/gent/stubjars/components/expressions/StringExpression.java index 7c6d736..fd6ac07 100644 --- a/src/main/java/davidsar/gent/stubjars/components/expressions/StringExpression.java +++ b/src/main/java/davidsar/gent/stubjars/components/expressions/StringExpression.java @@ -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); diff --git a/src/main/java/davidsar/gent/stubjars/components/writer/Constants.java b/src/main/java/davidsar/gent/stubjars/components/writer/Constants.java index 4d990cc..f0dcd7e 100644 --- a/src/main/java/davidsar/gent/stubjars/components/writer/Constants.java +++ b/src/main/java/davidsar/gent/stubjars/components/writer/Constants.java @@ -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"; }