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


Java MethodSpec.Builder方法代码示例

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


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

示例1: buildInitializer

import com.squareup.javapoet.MethodSpec; //导入方法依赖的package包/类
/**
 * Setup initial state of autorun in constructor.
 */
void buildInitializer( @Nonnull final MethodSpec.Builder builder )
{
  final ArrayList<Object> parameters = new ArrayList<>();
  final StringBuilder sb = new StringBuilder();
  sb.append( "this.$N = $N().autorun( $T.areNativeComponentsEnabled() ? this.$N : null, " +
             "$T.areNamesEnabled() ? $N() + $S : null, " );
  parameters.add( GeneratorUtil.FIELD_PREFIX + getName() );
  parameters.add( _componentDescriptor.getContextMethodName() );
  parameters.add( GeneratorUtil.AREZ_CLASSNAME );
  parameters.add( GeneratorUtil.COMPONENT_FIELD_NAME );
  parameters.add( GeneratorUtil.AREZ_CLASSNAME );
  parameters.add( _componentDescriptor.getComponentNameMethodName() );
  parameters.add( "." + getName() );
  sb.append( _mutation );
  sb.append( ", () -> super.$N(), false )" );
  parameters.add( getAutorun().getSimpleName().toString() );

  builder.addStatement( sb.toString(), parameters.toArray() );
}
 
开发者ID:arez,项目名称:arez,代码行数:23,代码来源:AutorunDescriptor.java

示例2: addMarkerAnnotationInstance

import com.squareup.javapoet.MethodSpec; //导入方法依赖的package包/类
/**
 * Adds a statement creating a new MarkerAnnotation instance to builder.
 * Returns the name of the instance.
 * @param builder The builder to add to.
 * @param annotation The service annotation to gather info from.
 * @return The name of the new instance.
 */
public static String addMarkerAnnotationInstance(MethodSpec.Builder builder,
                                                 UserMarkerAnnotation annotation,
                                                 Types types,
                                                 Elements elements) {

    String siName =
            ((TypeElement)types.asElement(annotation.getServiceInterfaceType())).getQualifiedName().toString();
    builder.addComment("The following values were gathered from the original @Service annotation parameters,");
    builder.addComment("and included here for this specialized service processor.");
    builder.addStatement("$T marker = new $T($S, $S, $S, $S)",
            MARKER_ANNOTATION_CLASS_NAME,
            MARKER_ANNOTATION_CLASS_NAME,
            siName,
            annotation.getServiceInterfaceName(),
            annotation.getIndividualNameKey(),
            annotation.getOutputPackage(elements));

    return "marker";
}
 
开发者ID:c0d3d,项目名称:easy-plugins,代码行数:27,代码来源:MarkerAnnotation.java

示例3: buildOnChangeBinding

import com.squareup.javapoet.MethodSpec; //导入方法依赖的package包/类
private void buildOnChangeBinding(MethodSpec.Builder constructorBuilder, Element element) {
  OnPrefChange onPrefChange = element.getAnnotation(OnPrefChange.class);
  if (onPrefChange != null) {
    int[] resourceIds = onPrefChange.value();

    for (int resourceId : resourceIds) {
      constructorBuilder.addStatement("target.findPreference(target.getString($L))"
          + ".setOnPreferenceChangeListener(new $T(){\n"
          + "@Override public boolean onPreferenceChange($T preference, Object newValue) {\n"
          + "\t\ttarget.$L(preference, newValue);\n"
          + "\t\treturn true;\n"
          + "\t}\n"
          + "})", resourceId, CHANGE_LISTENER, PREFERENCE, element.getSimpleName());
    }
  }
}
 
开发者ID:quangctkm9207,项目名称:prefpin,代码行数:17,代码来源:PrefPinProcessor.java

示例4: readResultsFromStub

import com.squareup.javapoet.MethodSpec; //导入方法依赖的package包/类
@Override
public void readResultsFromStub(TypeMirror resultType, MethodSpec.Builder methodBuilder) {
    if (resultType.getKind() == TypeKind.ARRAY) {
        methodBuilder.addStatement("reply.writeTypedArray(result, android.os.Parcelable.PARCELABLE_WRITE_RETURN_VALUE)");
    } else {
        methodBuilder.beginControlFlow("if (result != null)");
        methodBuilder.addStatement("reply.writeInt(1)");
        methodBuilder.addStatement("result.writeToParcel(reply, android.os.Parcelable.PARCELABLE_WRITE_RETURN_VALUE)");
        methodBuilder.endControlFlow();
        methodBuilder.beginControlFlow("else");
        methodBuilder.addStatement("reply.writeInt(0)");
        methodBuilder.endControlFlow();
    }
}
 
开发者ID:josesamuel,项目名称:remoter,代码行数:15,代码来源:ParcellableParamBuilder.java

示例5: getAttachViewMethod

import com.squareup.javapoet.MethodSpec; //导入方法依赖的package包/类
private MethodSpec getAttachViewMethod() {
    MethodSpec.Builder method =
            MethodSpec.methodBuilder(METHOD_ATTACH_VIEW)
                    .addModifiers(Modifier.PUBLIC)
                    .addAnnotation(Override.class)
                    .addParameter(delegateClassGenerator.getViewClass(), "view").returns(TypeName.VOID);
    method.addStatement(
            callPresenterAttachView(FIELD_PRESENTER, "view", "$T"),
            ClassName.bestGuess(delegateClassGenerator.getPresenterViewQualifiedName()));
    return method.build();
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:12,代码来源:BaseDecorator.java

示例6: mimicParameters

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

示例7: readResultsFromProxy

import com.squareup.javapoet.MethodSpec; //导入方法依赖的package包/类
@Override
public void readResultsFromProxy(TypeMirror resultType, MethodSpec.Builder methodBuilder) {
    if (resultType.getKind() == TypeKind.ARRAY) {
        logError("Binder[] is not supported");
    } else {
        methodBuilder.addStatement("result = new $T(reply.readStrongBinder())", getProxyClassName(resultType));
    }
}
 
开发者ID:josesamuel,项目名称:remoter,代码行数:9,代码来源:BinderParamBuilder.java

示例8: addTests

import com.squareup.javapoet.MethodSpec; //导入方法依赖的package包/类
@Override
public void addTests() {
    if (!checkSupport())
        return;

    String methodName = testMethodName();

    MethodSpec.Builder specBuilder = MethodSpec.methodBuilder(methodName)
            .addModifiers(Modifier.PUBLIC)
            .addAnnotation(testAnnotation)
            .addException(Exception.class)
            .returns(void.class);

    for (PatternMatchExample example : examples) {
        ClassName assertion = booleanAssertion(example.getAnnotation());
        String description = example.getAnnotation().annotationType().getSimpleName() + " " + example.toMatch();
        ClassName className = ClassName.get((TypeElement) element.getEnclosingElement());
        String patternName = element.getSimpleName().toString();
        if (element.getModifiers().contains(Modifier.STATIC)) {
            specBuilder.addCode(
                    "$L($S, $T.$L.matcher($S).matches());\n",
                    assertion, description, className, patternName, example.toMatch());
        } else {
            specBuilder.addCode(
                    "$L($S, new $T().$L.matcher($S).matches());\n",
                    assertion, description, className, patternName, example.toMatch());
        }
    }
    toAddTo.addMethod(specBuilder.build());
}
 
开发者ID:dleppik,项目名称:EgTest,代码行数:31,代码来源:PatternMatchWriter.java

示例9: writeParamsToProxy

import com.squareup.javapoet.MethodSpec; //导入方法依赖的package包/类
@Override
public void writeParamsToProxy(VariableElement param, ParamType paramType, MethodSpec.Builder methodBuilder) {
    if (param.asType().getKind() == TypeKind.ARRAY) {
        if (paramType == ParamType.OUT) {
            writeArrayOutParamsToProxy(param, methodBuilder);
        } else {
            methodBuilder.addStatement("data.writeFloatArray(" + param.getSimpleName() + ")");
        }
    } else {
        methodBuilder.addStatement("data.writeFloat(" + param.getSimpleName() + ")");
    }
}
 
开发者ID:josesamuel,项目名称:remoter,代码行数:13,代码来源:FloatParamBuilder.java

示例10: getNewActivateCallersMethodPrototype

import com.squareup.javapoet.MethodSpec; //导入方法依赖的package包/类
public static MethodSpec.Builder getNewActivateCallersMethodPrototype() {
	return MethodSpec
			.methodBuilder(ACTIVATE_CALLERS.name)
			.addModifiers(PUBLIC)
			.addAnnotation(Override.class)
			.returns(void.class);
}
 
开发者ID:MatthewTamlin,项目名称:Spyglass,代码行数:8,代码来源:CompanionDef.java

示例11: buildInitializer

import com.squareup.javapoet.MethodSpec; //导入方法依赖的package包/类
void buildInitializer( @Nonnull final MethodSpec.Builder builder )
{
  assert null != _memoize;
  assert null != _memoizeType;
  final ArrayList<Object> parameters = new ArrayList<>();
  final StringBuilder sb = new StringBuilder();
  sb.append( "this.$N = new $T<>( $N(), $T.areNamesEnabled() ? $N() + $S : null, args -> super.$N(" );
  parameters.add( getCacheName() );
  parameters.add( GeneratorUtil.MEMOIZE_CACHE_CLASSNAME );
  parameters.add( _componentDescriptor.getContextMethodName() );
  parameters.add( GeneratorUtil.AREZ_CLASSNAME );
  parameters.add( _componentDescriptor.getComponentNameMethodName() );
  parameters.add( "." + getName() );
  parameters.add( _memoize.getSimpleName().toString() );

  int index = 0;
  for ( final TypeMirror arg : _memoizeType.getParameterTypes() )
  {
    if ( 0 != index )
    {
      sb.append( ", " );
    }
    sb.append( "($T) args[ " ).append( index ).append( " ]" );
    parameters.add( arg );
    index++;
  }

  sb.append( "), " ).append( _memoize.getParameters().size() ).append( ")" );

  builder.addStatement( sb.toString(), parameters.toArray() );
}
 
开发者ID:arez,项目名称:arez,代码行数:32,代码来源:MemoizeDescriptor.java

示例12: buildObservableAccessorMethod

import com.squareup.javapoet.MethodSpec; //导入方法依赖的package包/类
@Nonnull
private MethodSpec buildObservableAccessorMethod()
{
  final MethodSpec.Builder method =
    MethodSpec.methodBuilder( GET_OBSERVABLE_METHOD ).
      addAnnotation( ClassName.bestGuess( Constants.OBSERVABLE_REF_ANNOTATION_CLASSNAME ) ).
      returns( GeneratorUtil.OBSERVABLE_CLASSNAME );
  method.addStatement( "throw new $T()", IllegalStateException.class );
  return method.build();
}
 
开发者ID:arez,项目名称:arez,代码行数:11,代码来源:ComponentDescriptor.java

示例13: testParcelConstructor

import com.squareup.javapoet.MethodSpec; //导入方法依赖的package包/类
private static void testParcelConstructor() {
    final String in = "in";
    MethodSpec.Builder builder = MethodSpec.constructorBuilder()
            .addModifiers(Modifier.PROTECTED)
            .addParameter(parcel, in);
    MethodSpec methodSpec = builder.addStatement("int[] arr = $N.createIntArray()", in)
            .addStatement("final int size = arr.length")
            .addStatement("this.$N = new short[size]", "age")
            .beginControlFlow("for(int i= 0 ; i < size ; i++)")
            .addStatement("this.$N[i] = (short)arr[i]", "age")
            .endControlFlow()
            .build();

    testMethod(methodSpec);
}
 
开发者ID:LightSun,项目名称:data-mediator,代码行数:16,代码来源:SimpleGenerator.java

示例14: buildEventHandlerBuilderMethod

import com.squareup.javapoet.MethodSpec; //导入方法依赖的package包/类
@Nonnull
private static MethodSpec.Builder buildEventHandlerBuilderMethod( @Nonnull final ComponentDescriptor descriptor,
                                                                  @Nonnull final EventHandlerDescriptor eventHandler )
{
  final TypeName handlerType = TypeName.get( eventHandler.getEventHandlerType().asType() );
  final MethodSpec.Builder method =
    MethodSpec.methodBuilder( "create_" + eventHandler.getMethod().getSimpleName() ).
      addModifiers( Modifier.PRIVATE ).
      addAnnotation( NONNULL_CLASSNAME ).
      returns( handlerType );

  final ExecutableElement target = eventHandler.getEventHandlerMethod();
  final int targetParameterCount = target.getParameters().size();
  String args =
    0 == targetParameterCount ?
    "()" :
    IntStream.range( 0, targetParameterCount ).mapToObj( i -> "arg" + i ).collect( Collectors.joining( "," ) );
  if ( 1 < targetParameterCount )
  {
    args = "(" + args + ")";
  }

  final int paramCount = eventHandler.getMethod().getParameters().size();
  final String params =
    0 == paramCount ?
    "" :
    IntStream.range( 0, paramCount ).mapToObj( i -> "arg" + i ).collect( Collectors.joining( "," ) );

  method.addStatement( "final $T handler = " + args + " -> this.$N(" + params + ")",
                       handlerType,
                       eventHandler.getMethod().getSimpleName() );

  final CodeBlock.Builder block = CodeBlock.builder();
  block.beginControlFlow( "if( $T.enableComponentNames() )", REACT_CONFIG_CLASSNAME );
  final String code =
    "$T.defineProperty( $T.cast( handler ), \"name\", $T.cast( $T.of( \"value\", $S ) ) )";
  block.addStatement( code,
                      JS_OBJECT_CLASSNAME,
                      JS_CLASSNAME,
                      JS_CLASSNAME,
                      JS_PROPERTY_MAP_CLASSNAME,
                      descriptor.getName() + "." + eventHandler.getName() );
  block.endControlFlow();
  method.addCode( block.build() );
  method.addStatement( "return handler" );
  return method;
}
 
开发者ID:react4j,项目名称:react4j,代码行数:48,代码来源:Generator.java

示例15: addParseFieldLines

import com.squareup.javapoet.MethodSpec; //导入方法依赖的package包/类
private int addParseFieldLines(MethodSpec.Builder builder) {
    int entryCount = 0;
    for (Map.Entry<String, JsonFieldHolder> entry : mJsonObjectHolder.fieldMap.entrySet()) {
        JsonFieldHolder fieldHolder = entry.getValue();

        if (fieldHolder.shouldParse) {
            List<Object> args = new ArrayList<>();
            StringBuilder ifStatement = new StringBuilder();
            boolean isFirst = true;
            for (String fieldName : fieldHolder.fieldName) {
                if (isFirst) {
                    isFirst = false;
                } else {
                    ifStatement.append(" || ");
                }
                ifStatement.append("$S.equals(fieldName)");
                args.add(fieldName);
            }

            if (entryCount == 0) {
                builder.beginControlFlow("if (" + ifStatement.toString() + ")", args.toArray(new Object[args.size()]));
            } else {
                builder.nextControlFlow("else if (" + ifStatement.toString() + ")", args.toArray(new Object[args.size()]));
            }

            String setter;
            Object[] stringFormatArgs;
            if (fieldHolder.hasSetter()) {
                setter = "instance.$L($L)";
                stringFormatArgs = new Object[] { fieldHolder.setterMethod };
            } else {
                setter = "instance.$L = $L";
                stringFormatArgs = new Object[] { entry.getKey() };
            }

            if (fieldHolder.type != null) {
                setFieldHolderJsonMapperVariableName(fieldHolder.type);
                fieldHolder.type.parse(builder, 1, setter, stringFormatArgs);
            }

            entryCount++;
        }
    }
    return entryCount;
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:46,代码来源:ObjectMapperInjector.java


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