Beispiel #1
0
/** @author [email protected] (Marcio Endo) */
class Annotations {

  public static final AnnotationSpec RETENTION_SOURCE =
      AnnotationSpec.builder(Retention.class)
          .addMember("value", "$T.$L", RetentionPolicy.class, RetentionPolicy.SOURCE)
          .build();

  public static final AnnotationSpec TARGET_PACKAGE =
      AnnotationSpec.builder(Target.class)
          .addMember("value", "$T.$L", ElementType.class, ElementType.PACKAGE)
          .build();

  public static final AnnotationSpec SERVICES_PROCESSOR =
      AnnotationSpec.builder(Services.class)
          .addMember("value", "$T.class", Processor.class)
          .build();

  private Annotations() {}

  public static AnnotationSpec repeatable(ClassName arrayAnnotationClassName) {
    return AnnotationSpec.builder(Repeatable.class)
        .addMember("value", "$T.class", arrayAnnotationClassName)
        .build();
  }
}
 private AnnotationSpec columnAnnotationClassArrayAnnotation() {
   return AnnotationSpec.builder(ColumnAnnotationClassArray.class)
       .addMember(
           "value",
           annotationClassArrayAnnotationValue((part) -> part.columnInfo().annotationTypeName()))
       .build();
 }
 public MethodSpec createPublicConstructor() {
   final ParameterSpec value =
       ParameterSpec.builder(String.class, "value", Modifier.FINAL)
           .addAnnotation(
               AnnotationSpec.builder(Text.class).addMember("required", "false").build())
           .build();
   return MethodSpec.constructorBuilder()
       .addJavadoc(
           "Creates a new {@code $L} instance.\n\n@param value the value representing the actual $L.\n",
           terminalName,
           simpleName)
       .addModifiers(Modifier.PUBLIC)
       .addParameter(value)
       .addCode(
           CodeBlock.builder()
               .addStatement("$T.checkNotNull(value, \"Missing 'value'.\")", Preconditions.class)
               .addStatement("this.value = value.trim()")
               .build())
       .build();
 }
 public TypeSpec createTerminalType() {
   final TypeName terminal =
       ParameterizedTypeName.get(
           ClassName.get(Terminal.class), ClassName.get(packageName, terminalName));
   return TypeSpec.classBuilder(terminalName)
       .addJavadoc("The <$L> element.\n", tag)
       .addAnnotation(AnnotationSpec.builder(Root.class).build())
       .addModifiers(Modifier.PUBLIC, Modifier.FINAL)
       .addSuperinterface(terminal)
       .addField(createFieldMissing())
       .addField(createFieldValue())
       .addMethod(createPublicConstructor())
       .addMethod(createPrivateConstructor())
       .addMethod(createValueGetter())
       .addMethod(createCompareTo())
       .addMethod(createHashCode())
       .addMethod(createEquals())
       .addMethod(createShow())
       .build();
 }
 private AnnotationSpec target() {
   return AnnotationSpec.builder(Target.class)
       .addMember("value", "{ $T.$L }", ElementType.class, ElementType.METHOD)
       .build();
 }
 private AnnotationSpec retention() {
   return AnnotationSpec.builder(Retention.class)
       .addMember("value", "$T.$L", RetentionPolicy.class, RetentionPolicy.RUNTIME)
       .build();
 }
Beispiel #7
0
 public static AnnotationSpec repeatable(ClassName arrayAnnotationClassName) {
   return AnnotationSpec.builder(Repeatable.class)
       .addMember("value", "$T.class", arrayAnnotationClassName)
       .build();
 }
 public FieldSpec createFieldValue() {
   return FieldSpec.builder(String.class, "value", Modifier.PRIVATE, Modifier.FINAL)
       .addAnnotation(AnnotationSpec.builder(Text.class).addMember("required", "false").build())
       .build();
 }
 private AnnotationSpec schemaAnnotation(MigrationVersionMetadata migrationVersion) {
   return AnnotationSpec.builder(Schema.class)
       .addMember("migrations", "{ $T.class }", migrationVersion.className())
       .build();
 }
Beispiel #10
0
 private AnnotationSpec migrationAnnotation() {
   return AnnotationSpec.builder(Migration.class)
       .addMember("schema", "$T.class", schemaName().className())
       .build();
 }
  private TypeSpec build(ScopeSpec spec) {
    MethodSpec configureScopeSpec =
        MethodSpec.methodBuilder("configureScope")
            .addModifiers(Modifier.PUBLIC)
            .addAnnotation(Override.class)
            .addParameter(ClassName.get(MortarScope.Builder.class), "builder")
            .addParameter(ClassName.get(MortarScope.class), "parentScope")
            .addCode(
                CodeBlock.builder()
                    .add(
                        "builder.withService($T.SERVICE_NAME, $T.builder()\n",
                        DAGGERSERVICE_CLS,
                        spec.getDaggerComponentTypeName())
                    .indent()
                    .add(
                        ".$L(parentScope.<$T>getService($T.SERVICE_NAME))\n",
                        spec.getDaggerComponentBuilderDependencyMethodName(),
                        spec.getDaggerComponentBuilderDependencyTypeName(),
                        DAGGERSERVICE_CLS)
                    .add(".module(new Module())\n")
                    .add(".build());\n")
                    .unindent()
                    .build())
            .build();

    List<FieldSpec> fieldSpecs = new ArrayList<>();
    for (ParameterSpec parameterSpec : spec.getModuleSpec().getInternalParameters()) {
      fieldSpecs.add(FieldSpec.builder(parameterSpec.type, parameterSpec.name).build());
    }

    MethodSpec.Builder constructorBuilder =
        MethodSpec.constructorBuilder()
            .addModifiers(Modifier.PUBLIC)
            .addAnnotation(AnnotationSpec.builder(ParcelConstructor.class).build())
            .addParameters(spec.getModuleSpec().getInternalParameters());
    for (ParameterSpec parameterSpec : spec.getModuleSpec().getInternalParameters()) {
      constructorBuilder.addStatement("this.$L = $L", parameterSpec.name, parameterSpec.name);
    }

    TypeSpec.Builder builder =
        TypeSpec.classBuilder(spec.getClassName().simpleName())
            .addModifiers(Modifier.PUBLIC)
            .addAnnotation(
                AnnotationSpec.builder(Generated.class)
                    .addMember(
                        "value",
                        "$S",
                        architect.autostack.compiler.AnnotationProcessor.class.getName())
                    .build())
            .addAnnotation(spec.getComponentAnnotationSpec())
            .addAnnotation(
                AnnotationSpec.builder(Parcel.class).addMember("parcelsIndex", "false").build())
            .addType(buildModule(spec.getModuleSpec()))
            .addMethod(constructorBuilder.build())
            .addMethod(configureScopeSpec)
            .addFields(fieldSpecs);

    if (spec.getScopeAnnotationSpec() != null) {
      builder.addAnnotation(spec.getScopeAnnotationSpec());
    }

    if (spec.getPathViewTypeName() != null) {
      builder.addSuperinterface(PATH_CLS);
      MethodSpec createViewSpec =
          MethodSpec.methodBuilder("createView")
              .addModifiers(Modifier.PUBLIC)
              .returns(spec.getPathViewTypeName())
              .addAnnotation(Override.class)
              .addParameter(CONTEXT_CLS, "context")
              .addStatement("return new $T(context)", spec.getPathViewTypeName())
              .build();

      builder.addMethod(createViewSpec);
    } else {
      builder.addSuperinterface(STACKABLE_CLS);
    }

    return builder.build();
  }