当前位置: 首页>>代码示例>>Java>>正文


Java AnnotationSpec.Builder方法代码示例

本文整理汇总了Java中com.squareup.javapoet.AnnotationSpec.Builder方法的典型用法代码示例。如果您正苦于以下问题:Java AnnotationSpec.Builder方法的具体用法?Java AnnotationSpec.Builder怎么用?Java AnnotationSpec.Builder使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.squareup.javapoet.AnnotationSpec的用法示例。


在下文中一共展示了AnnotationSpec.Builder方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: generate

import com.squareup.javapoet.AnnotationSpec; //导入方法依赖的package包/类
private static TypeSpec generate(List<TypeElement> libraryModules,
    Class<? extends Annotation> annotation) {
  AnnotationSpec.Builder annotationBuilder =
      AnnotationSpec.builder(Index.class);

  String value = getAnnotationValue(annotation);
  for (TypeElement childModule : libraryModules) {
    annotationBuilder.addMember(value, "$S", ClassName.get(childModule).toString());
  }

  String indexerName = INDEXER_NAME_PREFIX + annotation.getSimpleName() + "_";
  for (TypeElement element : libraryModules) {
    indexerName += element.getQualifiedName().toString().replace(".", "_");
    indexerName += "_";
  }
  indexerName = indexerName.substring(0, indexerName.length() - 1);

  return TypeSpec.classBuilder(indexerName)
      .addAnnotation(annotationBuilder.build())
      .addModifiers(Modifier.PUBLIC)
      .build();
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:23,代码来源:IndexerGenerator.java

示例2: generate

import com.squareup.javapoet.AnnotationSpec; //导入方法依赖的package包/类
private static TypeSpec generate(List<TypeElement> libraryModules,
    Class<? extends Annotation> annotation) {
  AnnotationSpec.Builder annotationBuilder =
      AnnotationSpec.builder(Index.class);

  String value = getAnnotationValue(annotation);
  for (TypeElement childModule : libraryModules) {
    annotationBuilder.addMember(value, "$S", ClassName.get(childModule).toString());
  }

  StringBuilder indexerName = new StringBuilder(
      INDEXER_NAME_PREFIX + annotation.getSimpleName() + "_");
  for (TypeElement element : libraryModules) {
    indexerName.append(element.getQualifiedName().toString().replace(".", "_"));
    indexerName.append("_");
  }
  indexerName = new StringBuilder(indexerName.substring(0, indexerName.length() - 1));

  return TypeSpec.classBuilder(indexerName.toString())
      .addAnnotation(annotationBuilder.build())
      .addModifiers(Modifier.PUBLIC)
      .build();
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:24,代码来源:IndexerGenerator.java

示例3: getMethodSpec

import com.squareup.javapoet.AnnotationSpec; //导入方法依赖的package包/类
/**
 * genera il metodo di test per method di clazz
 * 
 * @param count
 * @param method
 * @param clazz
 * @param infoFromMongoDb
 * @param methodOutput
 * @return
 */
private MethodSpec getMethodSpec(int count, Method method, Class<?> clazz, Document methodInputs,
		Document methodOutput) {
	String result = getAssignmentOfMethodResult(method);
	String expected = getExpectedResultAsBooleanAssert(method, methodOutput);
	MethodSpec.Builder methodBuilder = MethodSpec.methodBuilder(method.getName() + count + TEST);
	/*
	 * for non spring test
	 */
	String invokerName = getInvokerName(method, clazz, methodInputs, methodBuilder);
	String params = getParams(method, methodBuilder, methodInputs);
	AnnotationSpec.Builder annSpecBuilder = AnnotationSpec.builder(Test.class);
	addExpectedExceptionIfAny(methodInputs, annSpecBuilder);
	AnnotationSpec annTestSpec = annSpecBuilder.build();
	methodBuilder.addAnnotation(annTestSpec)
			.addStatement(result + invokerName + ".$N(" + params + ")", method.getName())
			.addModifiers(Modifier.PUBLIC);
	methodBuilder.addStatement("$L.assertTrue(" + expected + ")", Assert.class.getName());
	methodBuilder.addJavadoc("\n");
	return methodBuilder.build();
}
 
开发者ID:sap-nocops,项目名称:Jerkoff,代码行数:31,代码来源:PojoCreatorImpl.java

示例4: getTypeSpec

import com.squareup.javapoet.AnnotationSpec; //导入方法依赖的package包/类
/**
 * genera classe di test per clazz
 * 
 * @param clazz
 * @param prop
 * @param mongo
 * @return
 */
@Override
public TypeSpec getTypeSpec(Class<?> clazz) {
	Builder classTestBuilder = TypeSpec.classBuilder(clazz.getSimpleName() + TEST);
	ClassName superClass = ClassName.get(
			PropertiesUtils.getRequiredProperty(prop, PropertiesUtils.TEST_BASE_PACKAGE),
			PropertiesUtils.getRequiredProperty(prop, PropertiesUtils.TEST_BASE_CLASS));
	classTestBuilder.superclass(superClass);
	classTestBuilder.addJavadoc("@author \n");
	classTestBuilder.addModifiers(Modifier.PUBLIC);
	AnnotationSpec.Builder annSpecBuilder = AnnotationSpec.builder(Generated.class);
	annSpecBuilder.addMember("value", "\"it.fratta.jerkoff.Generator\"");
	annSpecBuilder.addMember("date", "\"" + Calendar.getInstance().getTime().toString() + "\"");
	AnnotationSpec annGenSpec = annSpecBuilder.build();
	classTestBuilder.addAnnotation(annGenSpec);
	/*
	 * for spring test
	 */
	// FieldSpec.Builder spec = FieldSpec.builder(clazz,
	// getNewInstanceOfNoParameters(clazz), Modifier.PRIVATE);
	// spec.addAnnotation(Autowired.class);
	// classTestBuilder.addField(spec.build());
	addClassMethodsToBuilder(classTestBuilder, clazz);
	return classTestBuilder.build();
}
 
开发者ID:sap-nocops,项目名称:Jerkoff,代码行数:33,代码来源:PojoCreatorImpl.java

示例5: suppressWarnings

import com.squareup.javapoet.AnnotationSpec; //导入方法依赖的package包/类
public static AnnotationSpec suppressWarnings(String... warnings) {
    AnnotationSpec.Builder builder = AnnotationSpec.builder(SuppressWarnings.class);
    CodeBlock.Builder names = CodeBlock.builder();
    boolean first = true;
    for (String warning : warnings) {
        if (first) {
            names.add("$S", warning);
            first = false;
        } else {
            names.add(", $S", warning);
        }
    }
    if (warnings.length == 1) {
        builder.addMember("value", names.build());
    } else {
        builder.addMember("value", "{$L}", names.build());
    }
    return builder.build();
}
 
开发者ID:maskarade,项目名称:StaticGson,代码行数:20,代码来源:Annotations.java

示例6: build

import com.squareup.javapoet.AnnotationSpec; //导入方法依赖的package包/类
public AnnotationSpec build() {
  AnnotationSpec.Builder builder = SPEC.toBuilder();

  if (value != null) {
    builder.addMember("value", valueFormat, value);
  }

  if (allOf != null && allOf.size() > 0) {
    builder.addMember("allOf", allOfFormat, allOf.toArray());
  }

  if (anyOf != null && anyOf.size() > 0) {
    builder.addMember("anyOf", anyOfFormat, anyOf.toArray());
  }

  if (conditional != null) {
    builder.addMember("conditional", conditionalFormat, conditional);
  }

  return builder.build();
}
 
开发者ID:trevjonez,项目名称:AndroidSupportAnnotationsHaiku,代码行数:22,代码来源:RequiresPermission.java

示例7: build

import com.squareup.javapoet.AnnotationSpec; //导入方法依赖的package包/类
public AnnotationSpec build() {
  AnnotationSpec.Builder builder = SPEC.toBuilder();

  if (value != null) {
    builder.addMember("value", valueFormat, value);
  }

  if (min != null) {
    builder.addMember("min", minFormat, min);
  }

  if (max != null) {
    builder.addMember("max", maxFormat, max);
  }

  if (multiple != null) {
    builder.addMember("multiple", multipleFormat, multiple);
  }

  return builder.build();
}
 
开发者ID:trevjonez,项目名称:AndroidSupportAnnotationsHaiku,代码行数:22,代码来源:Size.java

示例8: build

import com.squareup.javapoet.AnnotationSpec; //导入方法依赖的package包/类
public AnnotationSpec build() {
  AnnotationSpec.Builder builder = SPEC.toBuilder();

  if (from != null) {
    builder.addMember("from", fromFormat, this.from);
  }

  if (to != null) {
    builder.addMember("to", toFormat, this.to);
  }

  if (fromInclusive != null) {
    builder.addMember("fromInclusive", fromInclusiveFormat, this.fromInclusive);
  }

  if (toInclusive != null) {
    builder.addMember("toInclusive", toInclusiveFormat, this.toInclusive);
  }

  return builder.build();
}
 
开发者ID:trevjonez,项目名称:AndroidSupportAnnotationsHaiku,代码行数:22,代码来源:FloatRange.java

示例9: suppressWarnings

import com.squareup.javapoet.AnnotationSpec; //导入方法依赖的package包/类
private AnnotationSpec suppressWarnings(Collection<String> warnings) {
    AnnotationSpec.Builder anno = AnnotationSpec.builder(SuppressWarnings.class);

    if (warnings.isEmpty()) {
        throw new IllegalArgumentException("No warnings present - compiler error?");
    }

    if (warnings.size() == 1) {
        anno.addMember("value", "$S", Iterables.get(warnings, 0));
    } else {
        StringBuilder sb = new StringBuilder("{");
        for (String warning : warnings) {
            sb.append("\"");
            sb.append(warning);
            sb.append("\", ");
        }
        sb.setLength(sb.length() - 2);
        sb.append("}");

        anno.addMember("value", "$L", sb.toString());
    }

    return anno.build();
}
 
开发者ID:Microsoft,项目名称:thrifty,代码行数:25,代码来源:ThriftyCodeGenerator.java

示例10: fieldAnnotation

import com.squareup.javapoet.AnnotationSpec; //导入方法依赖的package包/类
private static AnnotationSpec fieldAnnotation(Field field) {
    AnnotationSpec.Builder ann = AnnotationSpec.builder(ThriftField.class)
            .addMember("fieldId", "$L", field.id());

    if (field.required()) {
        ann.addMember("isRequired", "$L", field.required());
    }

    if (field.optional()) {
        ann.addMember("isOptional", "$L", field.optional());
    }

    String typedef = field.typedefName();
    if (!Strings.isNullOrEmpty(typedef)) {
        ann = ann.addMember("typedefName", "$S", typedef);
    }

    return ann.build();
}
 
开发者ID:Microsoft,项目名称:thrifty,代码行数:20,代码来源:ThriftyCodeGenerator.java

示例11: build

import com.squareup.javapoet.AnnotationSpec; //导入方法依赖的package包/类
@Override
protected TypeSpec.Builder build()
{
    String params = "{";
    ClassName[] vars = new ClassName[viewElements.size()];
    int i = 0;
    for (Iterator<Element> it = viewElements.iterator(); it.hasNext(); i++)
    {
        Element element = it.next();
        params += "$T.class";
        vars[i] = ClassName.bestGuess(element.asType().toString());
        if (i < viewElements.size() - 1)
        {
            params += ", ";
        }
    }
    params += "}";
    AnnotationSpec.Builder annotationBuilder = AnnotationSpec.builder(Generate.class);
    annotationBuilder.addMember("views", params, (Object[]) vars);
    annotationBuilder.addMember("application", "$T.class", applicationClassName);
    return TypeSpec.classBuilder("Trigger")
            .addModifiers(Modifier.ABSTRACT)
            .addAnnotation(annotationBuilder.build());
}
 
开发者ID:aschattney,项目名称:annotated-mvp,代码行数:25,代码来源:TriggerType.java

示例12: getQualifiers

import com.squareup.javapoet.AnnotationSpec; //导入方法依赖的package包/类
/**
 * Returns list of all annotations given <code>element</code> has.
 *
 * @param element Element.
 */
public List<AnnotationSpec> getQualifiers(Element element) {
    List<AnnotationSpec> list = new ArrayList<>();
    for (AnnotationMirror a : element.getAnnotationMirrors()) {
        if (a.getAnnotationType().asElement().getAnnotation(Qualifier.class) == null) {
            continue; // ignore non-Qualifier annotations
        }

        ClassName annotationClassName = (ClassName) ClassName.get(a.getAnnotationType());
        AnnotationSpec.Builder annotation = AnnotationSpec.builder(annotationClassName);
        for (Map.Entry<? extends ExecutableElement, ? extends AnnotationValue> entry : a.getElementValues().entrySet()) {
            String format = (entry.getValue().getValue() instanceof String) ? "$S" : "$L";
            annotation.addMember(entry.getKey().getSimpleName().toString(), format, entry.getValue().getValue());
        }
        list.add(annotation.build());
    }
    return list;
}
 
开发者ID:inloop,项目名称:Knight,代码行数:23,代码来源:BaseClassBuilder.java

示例13: addGeneratedAnnotation

import com.squareup.javapoet.AnnotationSpec; //导入方法依赖的package包/类
private void addGeneratedAnnotation(
    final TypeSpec.Builder typeSpecBuilder, final ProcessorContext processorContext
) {
    final AnnotationSpec.Builder annotationBuilder =
        AnnotationSpec.builder(Generated.class)
            .addMember("value", "$S", JackdawProcessor.class.getName());

    if (processorContext.isAddGeneratedDate()) {
        final String currentTime =
            DateFormatUtils.ISO_DATETIME_TIME_ZONE_FORMAT.format(new Date());

        annotationBuilder.addMember("date", "$S", currentTime);
    }

    typeSpecBuilder.addAnnotation(annotationBuilder.build());
}
 
开发者ID:vbauer,项目名称:jackdaw,代码行数:17,代码来源:GeneratedCodeGenerator.java

示例14: mimicMethodAnnotations

import com.squareup.javapoet.AnnotationSpec; //导入方法依赖的package包/类
/** Mimic annotations of the method, but exclude @Yield annotation during processing. */
public static void mimicMethodAnnotations(@NonNull final MethodSpec.Builder builder,
                                          @NonNull final Symbol.MethodSymbol ms) throws Exception {
    if (ms.hasAnnotations()) {
        for (final Attribute.Compound am : ms.getAnnotationMirrors()) {
            if (extractClass(am) == AutoProxy.Yield.class) continue;
            if (extractClass(am) == AutoProxy.AfterCall.class) continue;

            final AnnotationSpec.Builder builderAnnotation = mimicAnnotation(am);
            if (null != builderAnnotation) {
                builder.addAnnotation(builderAnnotation.build());
            }
        }
    }
}
 
开发者ID:OleksandrKucherenko,项目名称:autoproxy,代码行数:16,代码来源:CommonClassGenerator.java

示例15: mimicParameters

import com.squareup.javapoet.AnnotationSpec; //导入方法依赖的package包/类
/** Compose method parameters that mimic original code. */
@NonNull
public static StringBuilder mimicParameters(@NonNull final MethodSpec.Builder builder,
                                            @NonNull final Symbol.MethodSymbol ms) throws Exception {
    String delimiter = "";
    final StringBuilder arguments = new StringBuilder();

    final com.sun.tools.javac.util.List<Symbol.VarSymbol> parameters = ms.getParameters();

    for (int i = 0, len = parameters.size(); i < len; i++) {
        final Symbol.VarSymbol param = parameters.get(i);

        // mimic parameter of the method: name, type, modifiers
        final TypeName paramType = TypeName.get(param.asType());
        final String parameterName = param.name.toString();
        final ParameterSpec.Builder parameter = ParameterSpec.builder(paramType, parameterName, Modifier.FINAL);

        if (param.hasAnnotations()) {
            // DONE: copy annotations of parameter
            for (final Attribute.Compound am : param.getAnnotationMirrors()) {
                final AnnotationSpec.Builder builderAnnotation = mimicAnnotation(am);

                if (null != builderAnnotation) {
                    parameter.addAnnotation(builderAnnotation.build());
                }
            }
        }

        // support VarArgs if needed
        builder.varargs(ms.isVarArgs() && i == len - 1);
        builder.addParameter(parameter.build());

        // compose parameters list for forwarding
        arguments.append(delimiter).append(parameterName);
        delimiter = ", ";
    }

    return arguments;
}
 
开发者ID:OleksandrKucherenko,项目名称:autoproxy,代码行数:40,代码来源:CommonClassGenerator.java


注:本文中的com.squareup.javapoet.AnnotationSpec.Builder方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。