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


Java ParameterSpec类代码示例

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


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

示例1: buildContainsMethod

import com.squareup.javapoet.ParameterSpec; //导入依赖的package包/类
@Nonnull
private MethodSpec buildContainsMethod( final TypeElement element, final ClassName arezType )
{
  final MethodSpec.Builder method =
    MethodSpec.methodBuilder( "contains" ).
      addModifiers( Modifier.PUBLIC ).
      addParameter( ParameterSpec.builder( TypeName.get( element.asType() ), "entity", Modifier.FINAL ).
        addAnnotation( GeneratorUtil.NONNULL_CLASSNAME ).build() ).
      returns( TypeName.BOOLEAN );
  method.addStatement( "$N().reportObserved()", GET_OBSERVABLE_METHOD );
  if ( null != _componentId )
  {
    method.addStatement( "return this.$N.containsKey( entity.$N() )", ENTITIES_FIELD_NAME, getIdMethodName() );
  }
  else
  {
    method.addStatement( "return entity instanceof $T && this.$N.containsKey( (($T) entity).$N() )",
                         arezType,
                         ENTITIES_FIELD_NAME,
                         arezType,
                         getIdMethodName() );
  }
  return method.build();
}
 
开发者ID:arez,项目名称:arez,代码行数:25,代码来源:ComponentDescriptor.java

示例2: getSingletonSetterMethod

import com.squareup.javapoet.ParameterSpec; //导入依赖的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

示例3: getMethod

import com.squareup.javapoet.ParameterSpec; //导入依赖的package包/类
private static MethodSpec getMethod(ClassName name, Key key) {
	Class<?> type = parseTypeFormat(key.getType(), key.getFormat());
	if(type.isPrimitive()) {
		type = ClassUtils.primitiveToWrapper(type);
	}
	
	ParameterSpec parameter = ParameterSpec.builder(type, key.getId()).build();
	
	return MethodSpec.methodBuilder(key.getId())
			.addModifiers(Modifier.PUBLIC, Modifier.FINAL)
			.addParameter(parameter)
			.addStatement("this.$N = $N", key.getId(), parameter)
			.addJavadoc(key.getDescription())
			.returns(name)
			.addStatement("return this")
			.build();
}
 
开发者ID:skjolber,项目名称:json-log-domain,代码行数:18,代码来源:MarkerGenerator.java

示例4: logger

import com.squareup.javapoet.ParameterSpec; //导入依赖的package包/类
public static JavaFile logger(Domain ontology) {
	ClassName name = ClassName.get(ontology.getTargetPackage(), ontology.getName() + LOGGER);

	ClassName statementName = ClassName.get(ontology.getTargetPackage(), ontology.getName() + STATEMENT);

	ParameterSpec loggerParameter = ParameterSpec.builder(org.slf4j.Logger.class, "logger").build();

	return JavaFile.builder(name.packageName(), TypeSpec.classBuilder(name)
		.superclass(ParameterizedTypeName.get(ClassName.get(AbstractDomainLogger.class), statementName))				
		.addJavadoc(composeJavadoc(ontology, name))
		.addModifiers(Modifier.PUBLIC)
		.addMethod(MethodSpec.constructorBuilder()
			.addModifiers(Modifier.PUBLIC)
			.addParameter(loggerParameter)
			.addStatement("super($N)", loggerParameter)
	        .build())
		.addMethod(getCreateLogStatementMethod(statementName)).build()).build();
}
 
开发者ID:skjolber,项目名称:json-log-domain,代码行数:19,代码来源:LoggerGenerator.java

示例5: buildStaticEventHandlerMethod

import com.squareup.javapoet.ParameterSpec; //导入依赖的package包/类
@Nonnull
private static MethodSpec.Builder buildStaticEventHandlerMethod( @Nonnull final ComponentDescriptor descriptor,
                                                                 @Nonnull final EventHandlerDescriptor eventHandler )
{
  final TypeName handlerType = TypeName.get( eventHandler.getEventHandlerType().asType() );
  final String handlerName = "_" + eventHandler.getMethod().getSimpleName();
  final MethodSpec.Builder method =
    MethodSpec.methodBuilder( handlerName ).
      addAnnotation( NONNULL_CLASSNAME ).
      returns( handlerType );

  method.addModifiers( Modifier.STATIC );

  final ParameterSpec.Builder parameter =
    ParameterSpec.builder( TypeName.get( descriptor.getElement().asType() ), "component", Modifier.FINAL ).
      addAnnotation( NONNULL_CLASSNAME );
  method.addParameter( parameter.build() );

  method.addStatement( "return (($T) component).$N", descriptor.getEnhancedClassName(), handlerName );
  return method;
}
 
开发者ID:react4j,项目名称:react4j,代码行数:22,代码来源:Generator.java

示例6: buildResultWrapperMethod

import com.squareup.javapoet.ParameterSpec; //导入依赖的package包/类
@Nonnull
private MethodSpec buildResultWrapperMethod()
{
  final ParameterizedTypeName listType =
    ParameterizedTypeName.get( ClassName.get( List.class ), TypeName.get( getElement().asType() ) );
  return MethodSpec.methodBuilder( "wrap" ).
    addModifiers( Modifier.PROTECTED, Modifier.FINAL ).
    addJavadoc( "If config option enabled, wrap the specified list in an immutable list and return it.\n" +
                "This method should be called by repository extensions when returning list results " +
                "when not using {@link #toList(List)}.\n" ).
    addAnnotation( GeneratorUtil.NONNULL_CLASSNAME ).
    addParameter( ParameterSpec.builder( listType, "list", Modifier.FINAL ).
      addAnnotation( GeneratorUtil.NONNULL_CLASSNAME ).build() ).
    returns( listType ).
    addStatement( "return $T.areRepositoryResultsModifiable() ? $T.unmodifiableList( list ) : list",
                  GeneratorUtil.AREZ_CLASSNAME,
                  Collections.class ).
    build();
}
 
开发者ID:arez,项目名称:arez,代码行数:20,代码来源:ComponentDescriptor.java

示例7: buildGetByIdMethod

import com.squareup.javapoet.ParameterSpec; //导入依赖的package包/类
@Nonnull
private MethodSpec buildGetByIdMethod()
{
  final TypeName entityType = TypeName.get( getElement().asType() );
  return MethodSpec.methodBuilder( "getBy" + getIdName() ).
    addModifiers( Modifier.PUBLIC, Modifier.FINAL ).
    addAnnotation( GeneratorUtil.NONNULL_CLASSNAME ).
    addParameter( ParameterSpec.builder( getIdType(), "id", Modifier.FINAL ).build() ).
    returns( entityType ).
    addStatement( "final $T entity = $N( id )", entityType, "findBy" + getIdName() ).
    addCode( CodeBlock.builder().
      beginControlFlow( "if ( null == entity )" ).
      addStatement( "throw new $T( $T.class, id )", GeneratorUtil.NO_SUCH_ENTITY_EXCEPTION_CLASSNAME, entityType ).
      endControlFlow().
      build() ).
    addStatement( "return entity" ).
    build();
}
 
开发者ID:arez,项目名称:arez,代码行数:19,代码来源:ComponentDescriptor.java

示例8: createFoldSignature

import com.squareup.javapoet.ParameterSpec; //导入依赖的package包/类
private MethodSpec.Builder createFoldSignature(Iterable<TypeVariableName> availableTypeVariables)
    throws ParserException {
  MethodSpec.Builder builder =
      MethodSpec.methodBuilder("map")
          .addTypeVariable(FOLD_RETURN_TYPE)
          .addModifiers(Modifier.PUBLIC)
          .returns(FOLD_RETURN_TYPE);

  for (OutputValue arg : values) {
    TypeName visitor =
        ParameterizedTypeName.get(
            ClassName.get(Function.class),
            TypeVariableUtils.withoutMissingTypeVariables(
                arg.parameterizedOutputClass(), availableTypeVariables),
            FOLD_RETURN_TYPE);

    builder.addParameter(
        ParameterSpec.builder(visitor, asCamelCase(arg.name()))
            .addAnnotation(Nonnull.class)
            .build());
  }

  return builder;
}
 
开发者ID:spotify,项目名称:dataenum,代码行数:25,代码来源:MapMethods.java

示例9: createFoldVoidSignature

import com.squareup.javapoet.ParameterSpec; //导入依赖的package包/类
private MethodSpec.Builder createFoldVoidSignature(
    Iterable<TypeVariableName> availableTypeVariables) throws ParserException {
  MethodSpec.Builder builder =
      MethodSpec.methodBuilder("match").addModifiers(Modifier.PUBLIC).returns(void.class);

  for (OutputValue arg : values) {
    TypeName visitor =
        ParameterizedTypeName.get(
            ClassName.get(Consumer.class),
            withoutMissingTypeVariables(arg.parameterizedOutputClass(), availableTypeVariables));

    builder.addParameter(
        ParameterSpec.builder(visitor, asCamelCase(arg.name()))
            .addAnnotation(Nonnull.class)
            .build());
  }

  return builder;
}
 
开发者ID:spotify,项目名称:dataenum,代码行数:20,代码来源:MatchMethods.java

示例10: buildMethods

import com.squareup.javapoet.ParameterSpec; //导入依赖的package包/类
@Nonnull
@Override
protected List<MethodSpec> buildMethods() {
    final MethodSpec.Builder constructorBuilder = MethodSpec.constructorBuilder()
            .addModifiers(Modifier.PUBLIC);

    final ImmutableList.Builder<MethodSpec> builder = ImmutableList.builder();
    getProperties().entrySet().forEach(property -> {
        final String name = property.getKey();
        final TypeName type = property.getValue();
        final String fieldName = fieldNamePolicy.convert(name, type);
        final String methodName = methodNamePolicy.convert(name, type);
        builder.add(MethodSpec.methodBuilder(methodName)
                .addModifiers(Modifier.PUBLIC)
                .returns(type)
                .addStatement("return $L", fieldName)
                .build());

        final String propertyName = parameterNamePolicy.convert(name, type);
        constructorBuilder.addParameter(ParameterSpec.builder(type, propertyName)
                .build())
                .addStatement("this.$L = $L", fieldName, propertyName);
    });
    builder.add(constructorBuilder.build());
    return builder.build();
}
 
开发者ID:t28hub,项目名称:json2java4idea,代码行数:27,代码来源:MoshiClassBuilder.java

示例11: generateUnboxMethod

import com.squareup.javapoet.ParameterSpec; //导入依赖的package包/类
private MethodSpec generateUnboxMethod(
        ClassName className,
        TypeName typeName,
        String primitiveType) {
    String paramName = className.simpleName() + "Param";
    paramName = Character.toLowerCase(paramName.charAt(0)) + paramName.substring(1);
    String primitiveArray = primitiveType + "s";
    return MethodSpec.methodBuilder("toPrimitive")
            .addParameters(ImmutableList.of(ParameterSpec.builder(ArrayTypeName.of(className), paramName).build()))
            .returns(ArrayTypeName.of(typeName))
            .addModifiers(PUBLIC)
            .addModifiers(STATIC)
            .addStatement("$L[] $L = new $L[$L.length]", primitiveType, primitiveArray, primitiveType, paramName)
            .beginControlFlow("for (int i = 0; i < $L.length; i++)", paramName)
            .addStatement("$L[i] = $L[i]", primitiveArray, paramName)
            .endControlFlow()
            .addStatement("return $L", primitiveArray)
            .build();
}
 
开发者ID:uber,项目名称:auto-value-bundle,代码行数:20,代码来源:BundleExtension.java

示例12: processInjector

import com.squareup.javapoet.ParameterSpec; //导入依赖的package包/类
private void processInjector(PreferenceComponentAnnotatedClass annotatedClass) throws VerifyException {
    try {
        annotatedClass.annotatedElement.getEnclosedElements().stream()
                .filter(element -> element instanceof ExecutableElement)
                .map(element -> (ExecutableElement) element)
                .forEach(method -> {
                    MethodSpec methodSpec = MethodSpec.overriding(method).build();
                    ParameterSpec parameterSpec = methodSpec.parameters.get(0);
                    TypeElement injectedElement = processingEnv.getElementUtils().getTypeElement(parameterSpec.type.toString());
                    generateProcessInjector(annotatedClass, injectedElement);
                });
    } catch (VerifyException e) {
        showErrorLog(e.getMessage(), annotatedClass.annotatedElement);
        e.printStackTrace();
    }
}
 
开发者ID:skydoves,项目名称:PreferenceRoom,代码行数:17,代码来源:PreferenceRoomProcessor.java

示例13: buildFindAllByQuerySortedMethod

import com.squareup.javapoet.ParameterSpec; //导入依赖的package包/类
@Nonnull
private MethodSpec buildFindAllByQuerySortedMethod()
{
  final ParameterizedTypeName queryType =
    ParameterizedTypeName.get( ClassName.get( Predicate.class ), TypeName.get( getElement().asType() ) );
  final ParameterizedTypeName sorterType =
    ParameterizedTypeName.get( ClassName.get( Comparator.class ), TypeName.get( getElement().asType() ) );
  return MethodSpec.methodBuilder( "findAllByQuery" ).
    addModifiers( Modifier.PUBLIC, Modifier.FINAL ).
    addAnnotation( GeneratorUtil.NONNULL_CLASSNAME ).
    addParameter( ParameterSpec.builder( queryType, "query", Modifier.FINAL ).
      addAnnotation( GeneratorUtil.NONNULL_CLASSNAME ).build() ).
    addParameter( ParameterSpec.builder( sorterType, "sorter", Modifier.FINAL ).
      addAnnotation( GeneratorUtil.NONNULL_CLASSNAME ).build() ).
    returns( ParameterizedTypeName.get( ClassName.get( List.class ), TypeName.get( getElement().asType() ) ) ).
    addStatement( "return toList( entities().stream().filter( query ).sorted( sorter ) )",
                  Collectors.class ).
    build();
}
 
开发者ID:arez,项目名称:arez,代码行数:20,代码来源:ComponentDescriptor.java

示例14: decorateClass

import com.squareup.javapoet.ParameterSpec; //导入依赖的package包/类
@Override
public void decorateClass(TypeSpec.Builder toAddTo) {
    if (needsClassDecoration) {
        ParameterSpec param = ParameterSpec.builder(String.class, "code").build();
        ClassName shell = ClassName.get("groovy.lang", "GroovyShell");
        MethodSpec.Builder specBuilder = MethodSpec.methodBuilder(EXEC_NAME)
                .addModifiers(Modifier.PRIVATE)
                .addParameter(param)
                .returns(Object.class)
                .addCode("StringBuilder script = new StringBuilder();\n")
                .addCode("script.append($S);\n", "import "+packageName+".*\n")
                .addCode("script.append($N);\n", param)
                .addCode("return new $L().evaluate(script.toString());\n", shell);
        toAddTo.addMethod(specBuilder.build());
    }
}
 
开发者ID:dleppik,项目名称:EgTest,代码行数:17,代码来源:GroovyInjector.java

示例15: buildGetByQueryMethod

import com.squareup.javapoet.ParameterSpec; //导入依赖的package包/类
@Nonnull
private MethodSpec buildGetByQueryMethod()
{
  final TypeName entityType = TypeName.get( getElement().asType() );
  final ParameterizedTypeName queryType =
    ParameterizedTypeName.get( ClassName.get( Predicate.class ), entityType );
  return MethodSpec.methodBuilder( "getByQuery" ).
    addModifiers( Modifier.PUBLIC, Modifier.FINAL ).
    addAnnotation( GeneratorUtil.NONNULL_CLASSNAME ).
    addParameter( ParameterSpec.builder( queryType, "query", Modifier.FINAL ).
      addAnnotation( GeneratorUtil.NONNULL_CLASSNAME ).build() ).
    returns( entityType ).
    addStatement( "final $T entity = findByQuery( query )", entityType ).
    addCode( CodeBlock.builder().
      beginControlFlow( "if ( null == entity )" ).
      addStatement( "throw new $T()", GeneratorUtil.NO_RESULT_EXCEPTION_CLASSNAME ).
      endControlFlow().
      build() ).
    addStatement( "return entity" ).
    build();
}
 
开发者ID:arez,项目名称:arez,代码行数:22,代码来源:ComponentDescriptor.java


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