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


Java AnnotationSpec类代码示例

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


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

示例1: getSingletonSetterMethod

import com.squareup.javapoet.AnnotationSpec; //导入依赖的package包/类
private MethodSpec getSingletonSetterMethod(ClassName className, FieldSpec singletonField) {
    ParameterSpec parameter = ParameterSpec
            .builder(className, "wrapper")
            .build();

    AnnotationSpec visibleForTesting = AnnotationSpec
            .builder(VisibleForTesting.class)
            .addMember("otherwise", "VisibleForTesting.NONE")
            .build();

    return MethodSpec
            .methodBuilder("setInstance")
            .addAnnotation(visibleForTesting)
            .addModifiers(Modifier.PUBLIC, Modifier.STATIC)
            .addParameter(parameter)
            .addStatement("$N = $N", singletonField, parameter)
            .build();
}
 
开发者ID:srym,项目名称:shoebill,代码行数:19,代码来源:ShoebillProcessor.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());
  }

  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

示例3: generateAsMethod

import com.squareup.javapoet.AnnotationSpec; //导入依赖的package包/类
private MethodSpec generateAsMethod(String generatedCodePackageName, TypeSpec requestBuilder) {
  TypeVariableName resourceType = TypeVariableName.get("ResourceType");
  ParameterizedTypeName classOfResouceType = ParameterizedTypeName
      .get(ClassName.get(Class.class), resourceType);

  ClassName generatedRequestBuilderClassName =
      ClassName.get(generatedCodePackageName, requestBuilder.name);

  ParameterizedTypeName requestBuilderOfResourceType = ParameterizedTypeName
      .get(generatedRequestBuilderClassName, resourceType);

  return MethodSpec.methodBuilder("as")
      .addModifiers(Modifier.PUBLIC)
      .addAnnotation(Override.class)
      .addTypeVariable(TypeVariableName.get("ResourceType"))
      .addParameter(classOfResouceType, "resourceClass")
      .addAnnotation(AnnotationSpec.builder(CHECK_RESULT_CLASS_NAME).build())
      .returns(requestBuilderOfResourceType)
      .addStatement("return new $T<>(glide, this, resourceClass, context)",
          this.generatedRequestBuilderClassName)
      .build();
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:23,代码来源:RequestManagerGenerator.java

示例4: generateRequestManagerRequestBuilderMethodOverride

import com.squareup.javapoet.AnnotationSpec; //导入依赖的package包/类
/**
 * Generates overrides of existing RequestManager methods so that they return our generated
 * RequestBuilder subtype.
 */
private MethodSpec generateRequestManagerRequestBuilderMethodOverride(
    ExecutableElement methodToOverride) {
   // We've already verified that this method returns a RequestBuilder and RequestBuilders have
  // exactly one type argument, so this is safe unless those assumptions change.
  TypeMirror typeArgument =
      ((DeclaredType) methodToOverride.getReturnType()).getTypeArguments().get(0);

  ParameterizedTypeName generatedRequestBuilderOfType =
      ParameterizedTypeName.get(generatedRequestBuilderClassName, ClassName.get(typeArgument));

  MethodSpec.Builder builder = ProcessorUtil.overriding(methodToOverride)
      .returns(generatedRequestBuilderOfType)
      .addCode(
          ProcessorUtil.generateCastingSuperCall(
              generatedRequestBuilderOfType, methodToOverride));

  for (AnnotationMirror mirror : methodToOverride.getAnnotationMirrors()) {
    builder.addAnnotation(AnnotationSpec.get(mirror));
  }
  return builder.build();
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:26,代码来源:RequestManagerGenerator.java

示例5: 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

示例6: hasMember

import com.squareup.javapoet.AnnotationSpec; //导入依赖的package包/类
public static Matcher<AnnotationSpec> hasMember(final String member) {

    return new TypeSafeMatcher<AnnotationSpec>() {

      @Override
      protected boolean matchesSafely(AnnotationSpec item) {
        return item.members.containsKey(member);
      }

      @Override
      public void describeTo(Description description) {

        description.appendText("has member " + member);
      }
    };
  }
 
开发者ID:mulesoft-labs,项目名称:raml-java-tools,代码行数:17,代码来源:AnnotationSpecMatchers.java

示例7: generate

import com.squareup.javapoet.AnnotationSpec; //导入依赖的package包/类
void generate() {
    TypeSpec shortbread = TypeSpec.classBuilder("ShortbreadGenerated")
            .addAnnotation(AnnotationSpec.builder(suppressLint)
                    .addMember("value", "$S", "NewApi")
                    .addMember("value", "$S", "ResourceType")
                    .build())
            .addModifiers(Modifier.PUBLIC, Modifier.FINAL)
            .addMethod(createShortcuts())
            .addMethod(callMethodShortcut())
            .build();

    JavaFile javaFile = JavaFile.builder("shortbread", shortbread)
            .indent("    ")
            .build();

    try {
        javaFile.writeTo(filer);
    } catch (IOException e) {
        e.printStackTrace();
    }
}
 
开发者ID:MatthiasRobbers,项目名称:shortbread,代码行数:22,代码来源:CodeGenerator.java

示例8: defineLifecycleHook

import com.squareup.javapoet.AnnotationSpec; //导入依赖的package包/类
private MethodSpec defineLifecycleHook() {

        final String methodName = "onLifecycleEvent";

        Lifecycle.Event lifecycleEvent = annotatedElement.getAnnotation(LifecycleAware.class).value();

        AnnotationSpec archLifeCycleSpec = AnnotationSpec.builder(OnLifecycleEvent.class)
                .addMember(ANNOT_DEFAULT_NAME, "$T.$L", Lifecycle.Event.class, lifecycleEvent)
                .build();

        return MethodSpec.methodBuilder(lifecycleEvent.name())
                .addAnnotation(archLifeCycleSpec)
                .addModifiers(Modifier.PUBLIC)
                .addStatement("$L.$L($T.$L)", FIELD_OBSERVER, methodName, Lifecycle.Event.class, lifecycleEvent)
                .build();
    }
 
开发者ID:jzallas,项目名称:LifecycleAware,代码行数:17,代码来源:LifecycleObserverGenerator.java

示例9: createInitMethodSpecBuilder

import com.squareup.javapoet.AnnotationSpec; //导入依赖的package包/类
/**
 * 创建init方法,用于数据初始化
 *
 * @param methodName        方法名
 * @param genericTypesClass ArrayList泛型的类型
 * @param gsonDataString    ArrayList被Gson转换出的字符串
 * @param modelListVariableName      GsonData被还原后的临时变量名
 * @return 初始化方法的构造器
 */
public static MethodSpec.Builder createInitMethodSpecBuilder(String methodName, Class genericTypesClass, String gsonDataString, String modelListVariableName) {
	String tmpStr;

	//Override注解
	AnnotationSpec annotation = createOverrideAnnotation();

	//return type,返回值
	ParameterizedType returnType = GenericTypesUtil.type(ArrayList.class, genericTypesClass);

	//protected ArrayList<DUnitModel> initUnitModels(),函数声明
	MethodSpec.Builder initMethodBuilder = MethodSpec
			.methodBuilder(methodName)
			.addModifiers(Modifier.PROTECTED)
			.addAnnotation(annotation)
			.returns(returnType);

	//Gson gson = new Gson();
	initMethodBuilder.addStatement("$T gson = new $T()", Gson.class, Gson.class);
	//ParameterizedType type = GenericTypesUtil.type(ArrayList.class,DUnitModel.class);
	initMethodBuilder.addStatement("$T type = $T.type($T.class,$T.class)", ParameterizedType.class, GenericTypesUtil.class, ArrayList.class, genericTypesClass);
	//ArrayList<DUnitModel> unitModels = gson.fromJson(unitModelsString_c,type);
	tmpStr = String.format("$T<$T> %s = gson.fromJson($S,type)", modelListVariableName);
	initMethodBuilder.addStatement(tmpStr, ArrayList.class, genericTypesClass, gsonDataString);
	return initMethodBuilder;
}
 
开发者ID:tik5213,项目名称:DUnit,代码行数:35,代码来源:InitMethodUtil.java

示例10: buildFields

import com.squareup.javapoet.AnnotationSpec; //导入依赖的package包/类
@Nonnull
@Override
protected List<FieldSpec> buildFields() {
    return getProperties()
            .entrySet()
            .stream()
            .map(property -> {
                final String name = property.getKey();
                final TypeName type = property.getValue();

                final String fieldName = fieldNamePolicy.convert(name, type);
                return FieldSpec.builder(type, fieldName)
                        .addModifiers(Modifier.PRIVATE, Modifier.FINAL)
                        .addAnnotation(AnnotationSpec.builder(SerializedName.class)
                                .addMember("value", "$S", name)
                                .build())
                        .build();
            })
            .collect(Collectors.toList());
}
 
开发者ID:t28hub,项目名称:json2java4idea,代码行数:21,代码来源:GsonClassBuilder.java

示例11: createJsArrayInterface

import com.squareup.javapoet.AnnotationSpec; //导入依赖的package包/类
private TypeSpec createJsArrayInterface() {
    TypeVariableName variableName = TypeVariableName.get("T");
    return TypeSpec.classBuilder("JsArray")
            .addModifiers(Modifier.STATIC, Modifier.FINAL)
            .addTypeVariable(variableName)
            .addAnnotation(AnnotationSpec.builder(ClassNames.JSINTEROP_JSTYPE)
                    .addMember("isNative", "true")
                    .addMember("namespace", "$T.GLOBAL", ClassNames.JSINTEROP_JSPACKAGE)
                    .addMember("name", "$S", "Array")
                    .build())
            .addMethod(MethodSpec.methodBuilder("push")
                    .addModifiers(Modifier.PUBLIC, Modifier.NATIVE)
                    .addParameter(variableName, "item")
                    .build())
            .build();
}
 
开发者ID:codegen-io,项目名称:jso-builder,代码行数:17,代码来源:JSOBuilderProcessor.java

示例12: createGlobalInterface

import com.squareup.javapoet.AnnotationSpec; //导入依赖的package包/类
private TypeSpec createGlobalInterface() {
    return TypeSpec.classBuilder("Global")
            .addModifiers(Modifier.STATIC, Modifier.FINAL)
            .addAnnotation(AnnotationSpec.builder(ClassNames.JSINTEROP_JSTYPE)
                    .addMember("isNative", "true")
                    .addMember("namespace", "$T.GLOBAL", ClassNames.JSINTEROP_JSPACKAGE)
                    .build())
            .addFields(Stream.of(Object.class,
                    Boolean.TYPE, Byte.TYPE, Character.TYPE, Double.TYPE,
                    Float.TYPE, Integer.TYPE, Long.TYPE, Short.TYPE)
                    .map(type -> FieldSpec.builder(type, "UNDEFINED_" + type.getSimpleName().toUpperCase())
                            .addModifiers(Modifier.PUBLIC, Modifier.STATIC)
                            .addAnnotation(AnnotationSpec.builder(ClassNames.JSINTEROP_JSPROPERTY)
                                    .addMember("namespace", "$T.GLOBAL", ClassNames.JSINTEROP_JSPACKAGE)
                                    .addMember("name", "$S", "undefined")
                                    .build())
                            .build())
                .collect(Collectors.toList()))
            .build();
}
 
开发者ID:codegen-io,项目名称:jso-builder,代码行数:21,代码来源:JSOBuilderProcessor.java

示例13: 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

示例14: 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

示例15: visitTypeAsClass

import com.squareup.javapoet.AnnotationSpec; //导入依赖的package包/类
@Override
public DeferredTypeSpecBuilder visitTypeAsClass(final TypeElement element, final DeferredTypeSpecBuilder outerBuilder) {

	final Collection<AnnotationSpec> descriptorAnnotations = descriptorInventory.typeAnnotations(element);
	final TypeSubstitution substitution = applyDeclaredTypeSubstitution(element);
	final DeferredTypeSpecBuilder innerBuilder = DeferredTypeSpecBuilder.create(classBuilder(substitution.raw())
			.addTypeVariables(substitution.typeParameters())
			.addModifiers(modifiers(element))
			.addAnnotations(mergeAnnotations(copyableAnnotations(element), descriptorAnnotations))
			.superclass(applyTypeSubstitution(element.getSuperclass())))
			;

	element.getInterfaces().forEach(iface -> innerBuilder.wrapped().addSuperinterface(applyTypeSubstitution(iface)));
	element.getEnclosedElements().forEach(child -> visit(child, innerBuilder));

	// If this is a nested type, we now roll up the new type into the parent.
	return (outerBuilder != null)
			? outerBuilder.addDeferred(innerBuilder)
					: innerBuilder;
}
 
开发者ID:FermioCloud,项目名称:java-code-templates,代码行数:21,代码来源:TemplateSubstitutionVisitor.java


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