@Test public void innerAnnotationInAnnotationDeclaration() throws Exception { TypeSpec bar = TypeSpec.annotationBuilder("Bar") .addMethod(MethodSpec.methodBuilder("value") .addModifiers(Modifier.PUBLIC, Modifier.ABSTRACT) .defaultValue("@$T", Deprecated.class) .returns(Deprecated.class) .build()) .build(); assertThat(toString(bar)).isEqualTo("" + "package com.squareup.tacos;\n" + "\n" + "import java.lang.Deprecated;\n" + "\n" + "@interface Bar {\n" + " Deprecated value() default @Deprecated;\n" + "}\n" ); }
@Test public void multipleAnnotationAddition() { TypeSpec taco = TypeSpec.classBuilder("Taco") .addAnnotations(Arrays.asList( AnnotationSpec.builder(SuppressWarnings.class) .addMember("value", "$S", "unchecked") .build(), AnnotationSpec.builder(Deprecated.class).build())) .build(); assertThat(toString(taco)).isEqualTo("" + "package com.squareup.tacos;\n" + "\n" + "import java.lang.Deprecated;\n" + "import java.lang.SuppressWarnings;\n" + "\n" + "@SuppressWarnings(\"unchecked\")\n" + "@Deprecated\n" + "class Taco {\n" + "}\n"); }
/** https://github.com/square/javapoet/issues/253 */ @Test public void enumWithAnnotatedValues() throws Exception { TypeSpec roshambo = TypeSpec.enumBuilder("Roshambo") .addModifiers(Modifier.PUBLIC) .addEnumConstant("ROCK", TypeSpec.anonymousClassBuilder("") .addAnnotation(Deprecated.class) .build()) .addEnumConstant("PAPER") .addEnumConstant("SCISSORS") .build(); assertThat(toString(roshambo)).isEqualTo("" + "package com.squareup.tacos;\n" + "\n" + "import java.lang.Deprecated;\n" + "\n" + "public enum Roshambo {\n" + " @Deprecated\n" + " ROCK,\n" + "\n" + " PAPER,\n" + "\n" + " SCISSORS\n" + "}\n"); }
/** * @see Glide#init(Glide) */ @Deprecated @VisibleForTesting @SuppressLint("VisibleForTests") public static void init(Glide glide) { Glide.init(glide); }
/** * https://github.com/square/javapoet/issues/253 */ @Test public void enumWithAnnotatedValues() throws Exception { TypeSpec roshambo = TypeSpec.enumBuilder("Roshambo") .addModifiers(Modifier.PUBLIC) .addEnumConstant("ROCK", TypeSpec.anonymousClassBuilder("") .addAnnotation(Deprecated.class) .build()) .addEnumConstant("PAPER") .addEnumConstant("SCISSORS") .build(); assertThat(toString(roshambo)).isEqualTo("" + "package com.squareup.tacos;\n" + "\n" + "import java.lang.Deprecated;\n" + "\n" + "public enum Roshambo {\n" + " @Deprecated\n" + " ROCK,\n" + "\n" + " PAPER,\n" + "\n" + " SCISSORS\n" + "}\n"); }
@Deprecated public static deprecatedMethod() { /* bad code to generate warnings and errors */ int unusedVar; if (1 == 2) { /* missed bracket: } */ }
@Override @Deprecated @CheckResult public GlideRequest<TranscodeType> load(@Nullable URL arg0) { return (GlideRequest<TranscodeType>) super.load(arg0); }
public Friend2(@Nonnull String __typename, @Nonnull String id, @Nonnull @Deprecated String deprecated) { this.__typename = Utils.checkNotNull(__typename, "__typename == null"); this.id = Utils.checkNotNull(id, "id == null"); this.deprecated = Utils.checkNotNull(deprecated, "deprecated == null"); }
public Friend5(@Nonnull String __typename, @Nonnull String id, @Nonnull @Deprecated String deprecated) { this.__typename = Utils.checkNotNull(__typename, "__typename == null"); this.id = Utils.checkNotNull(id, "id == null"); this.deprecated = Utils.checkNotNull(deprecated, "deprecated == null"); }
public Hero(@Nonnull String __typename, @Nonnull String name, @Nonnull @Deprecated String deprecated) { this.__typename = Utils.checkNotNull(__typename, "__typename == null"); this.name = Utils.checkNotNull(name, "name == null"); this.deprecated = Utils.checkNotNull(deprecated, "deprecated == null"); }
@Deprecated public void deprecatedMethod() { System.out.println("DEPRECATED"); }
/** * Test deprecated field * @deprecated For test purpose only */ public @Nonnull @Deprecated String deprecated() { return this.deprecated; }