當前位置: 首頁>>代碼示例>>Java>>正文


Java TypeName類代碼示例

本文整理匯總了Java中com.squareup.javapoet.TypeName的典型用法代碼示例。如果您正苦於以下問題:Java TypeName類的具體用法?Java TypeName怎麽用?Java TypeName使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


TypeName類屬於com.squareup.javapoet包,在下文中一共展示了TypeName類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: builderCopyMethodForList

import com.squareup.javapoet.TypeName; //導入依賴的package包/類
private MethodSpec builderCopyMethodForList() {
    TypeName keyType = typeProvider.getTypeNameForSimpleType(memberModel.getMapModel().getKeyModel()
                                                                        .getVariable().getVariableType());
    ClassName valueParameter = poetExtensions.getModelClass(memberModel.getMapModel().getValueModel().getC2jShape());
    ClassName builderForParameter = valueParameter.nestedClass("Builder");
    TypeName parameterType =
        ParameterizedTypeName.get(ClassName.get(Map.class), keyType, WildcardTypeName.subtypeOf(builderForParameter));

    CodeBlock code =
        CodeBlock.builder()
                 .beginControlFlow("if ($N == null)", memberParamName())
                 .addStatement("return null")
                 .endControlFlow()
                 .addStatement("return $N($N.entrySet().stream().collect(toMap($T::getKey, e -> e.getValue().build())))",
                               serviceModelCopiers.copyMethodName(),
                               memberParamName(),
                               Map.Entry.class)
                 .build();

    return MethodSpec.methodBuilder(serviceModelCopiers.builderCopyMethodName())
                     .addModifiers(Modifier.STATIC)
                     .addParameter(parameterType, memberParamName())
                     .returns(typeProvider.fieldType(memberModel))
                     .addCode(code)
                     .build();
}
 
開發者ID:aws,項目名稱:aws-sdk-java-v2,代碼行數:27,代碼來源:MemberCopierSpec.java

示例2: getMethodByType

import com.squareup.javapoet.TypeName; //導入依賴的package包/類
private String getMethodByType(TypeName clazz) {
    StringBuilder sb = new StringBuilder("get");
    if (clazz.equals(TypeName.INT) || clazz.equals(TypeName.INT.box())) {
        sb.append("Int");
    } else if (clazz.equals(TypeName.BOOLEAN) || clazz.equals(TypeName.BOOLEAN.box())) {
        sb.append("Boolean");
    } else if (clazz.equals(TypeName.FLOAT) || clazz.equals(TypeName.FLOAT.box())) {
        sb.append("Float");
    } else if (clazz.equals(TypeName.DOUBLE) || clazz.equals(TypeName.DOUBLE.box())) {
        sb.append("Double");
    } else if (clazz.equals(TypeName.LONG) || clazz.equals(TypeName.LONG.box())) {
        sb.append("Long");
    } else if (clazz.equals(TypeName.SHORT) || clazz.equals(TypeName.SHORT.box())) {
        sb.append("Short");
    } else if (clazz.equals(TypeName.CHAR) || clazz.equals(TypeName.CHAR.box())) {
        sb.append("Char");
    } else if (clazz.equals(TypeName.VOID) || clazz.equals(TypeName.VOID.box()) ||
            clazz.equals(TypeName.BYTE) || clazz.equals(TypeName.BYTE.box())
            || clazz.equals(TypeName.OBJECT)) {
        //should not use this type
    } else {
        sb.append("String");
    }
    return sb.append("Param").toString();
}
 
開發者ID:bboylin,項目名稱:D-Router,代碼行數:26,代碼來源:ActivityHelperGenerator.java

示例3: defaultValue

import com.squareup.javapoet.TypeName; //導入依賴的package包/類
private String defaultValue(JsonProperty property, TypeName type) {
  if (property.defaultValue != null) {
    return property.defaultValue;
  }
  if (type == TypeName.BOOLEAN) {
    return "false";
  } else if (type == TypeName.BYTE) {
    return "(byte) 0";
  } else if (type == TypeName.SHORT) {
    return "0";
  } else if (type == TypeName.INT) {
    return "0";
  } else if (type == TypeName.LONG) {
    return "0L";
  } else if (type == TypeName.CHAR) {
    return "'\0'";
  } else if (type == TypeName.FLOAT) {
    return "0.0f";
  } else if (type == TypeName.DOUBLE) {
    return "0.0d";
  } else {
    return "null";
  }
}
 
開發者ID:setheclark,項目名稱:auto-value-json,代碼行數:25,代碼來源:AutoValueJsonExtension.java

示例4: getSuperMethodSpecs

import com.squareup.javapoet.TypeName; //導入依賴的package包/類
private List<MethodSpec> getSuperMethodSpecs() {
    List<MethodSpec> methodSpecs = new ArrayList<>();
    this.annotatedClazz.annotatedElement.getEnclosedElements().stream()
            .filter(element -> element instanceof ExecutableElement)
            .map(element -> (ExecutableElement) element)
            .forEach(method -> {
                ClassName preferenceRoom = ClassName.get(PreferenceRoom.class);
                MethodSpec.Builder builder = MethodSpec.overriding(method);
                MethodSpec methodSpec = builder.addStatement("$T.inject($N)", preferenceRoom, method.getParameters().get(0).getSimpleName()).build();
                if(methodSpec.returnType != TypeName.get(Void.TYPE)) {
                    throw new VerifyException(String.format("Returned '%s'. only return type can be void.", methodSpec.returnType.toString()));
                }
                methodSpecs.add(methodSpec);
            });
    return methodSpecs;
}
 
開發者ID:skydoves,項目名稱:PreferenceRoom,代碼行數:17,代碼來源:PreferenceComponentGenerator.java

示例5: buildMethods

import com.squareup.javapoet.TypeName; //導入依賴的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,代碼來源:ModelClassBuilder.java

示例6: buildIsDisposed

import com.squareup.javapoet.TypeName; //導入依賴的package包/類
/**
 * Generate the isDisposed method.
 */
@Nonnull
private MethodSpec buildIsDisposed()
  throws ArezProcessorException
{
  final MethodSpec.Builder builder =
    MethodSpec.methodBuilder( "isDisposed" ).
      addModifiers( Modifier.PUBLIC ).
      addAnnotation( Override.class ).
      returns( TypeName.BOOLEAN );

  final CodeBlock.Builder block = CodeBlock.builder();
  block.beginControlFlow( "if ( $N().isTransactionActive() && !this.$N.isDisposed() ) ",
                          getContextMethodName(),
                          GeneratorUtil.DISPOSED_OBSERVABLE_FIELD_NAME );
  block.addStatement( "this.$N.reportObserved()", GeneratorUtil.DISPOSED_OBSERVABLE_FIELD_NAME );
  block.addStatement( "return this.$N", GeneratorUtil.DISPOSED_FIELD_NAME );
  block.nextControlFlow( "else" );
  block.addStatement( "return this.$N", GeneratorUtil.DISPOSED_FIELD_NAME );
  block.endControlFlow();
  builder.addCode( block.build() );

  return builder.build();
}
 
開發者ID:arez,項目名稱:arez,代碼行數:27,代碼來源:ComponentDescriptor.java

示例7: buildComponentTypeNameMethod

import com.squareup.javapoet.TypeName; //導入依賴的package包/類
@Nullable
private MethodSpec buildComponentTypeNameMethod()
  throws ArezProcessorException
{
  if ( null == _componentTypeName )
  {
    return null;
  }

  final MethodSpec.Builder builder =
    MethodSpec.methodBuilder( _componentTypeName.getSimpleName().toString() );
  ProcessorUtil.copyAccessModifiers( _componentTypeName, builder );
  builder.addModifiers( Modifier.FINAL );
  builder.addAnnotation( GeneratorUtil.NONNULL_CLASSNAME );

  builder.returns( TypeName.get( String.class ) );
  builder.addStatement( "return $S", _type );
  return builder.build();
}
 
開發者ID:arez,項目名稱:arez,代碼行數:20,代碼來源:ComponentDescriptor.java

示例8: checkCompiles

import com.squareup.javapoet.TypeName; //導入依賴的package包/類
private void checkCompiles(final MethodSpec method) {
	final TypeSpec wrapperTypeSpec = CallerDef
			.getNewCallerSubclassPrototype("Wrapper", TypeName.OBJECT)
			.addMethod(CallerDef.getNewCallMethodPrototype().build())
			.addMethod(CallerDef.getNewConstructorPrototype(TypeName.OBJECT).build())
			.addMethod(method)
			.build();

	final JavaFile wrapperJavaFile = JavaFile
			.builder("", wrapperTypeSpec)
			.build();

	final Set<JavaFile> filesToCompile = new HashSet<>();
	filesToCompile.add(wrapperJavaFile);
	filesToCompile.add(CallerDef.SRC_FILE);

	CompileChecker.checkCompiles(filesToCompile);
}
 
開發者ID:MatthewTamlin,項目名稱:Spyglass,代碼行數:19,代碼來源:TestValueIsAvailableMethodGenerator.java

示例9: BindingSet

import com.squareup.javapoet.TypeName; //導入依賴的package包/類
private BindingSet(TypeName targetTypeName, ClassName bindingClassName, boolean isFinal,
                   boolean isView, boolean isActivity,boolean isFragment, boolean isDialog, ImmutableList<ViewBinding> viewBindings,
                   ImmutableList<FieldCollectionViewBinding> collectionBindings,
                   ImmutableList<ResourceBinding> resourceBindings, BindingSet parentBinding, @LayoutRes int layoutId) {
    this.isFinal = isFinal;
    this.targetTypeName = targetTypeName;
    this.bindingClassName = bindingClassName;
    this.isView = isView;
    this.isActivity = isActivity;
    this.isFragment = isFragment;
    this.isDialog = isDialog;
    this.viewBindings = viewBindings;
    this.collectionBindings = collectionBindings;
    this.resourceBindings = resourceBindings;
    this.parentBinding = parentBinding;
    this.layoutId = layoutId;
}
 
開發者ID:qq542391099,項目名稱:butterknife-parent,代碼行數:18,代碼來源:BindingSet.java

示例10: generateSetPropertySpec

import com.squareup.javapoet.TypeName; //導入依賴的package包/類
private static MethodSpec generateSetPropertySpec(
    ClassInfo classInfo,
    List<PropertyInfo> properties) {
  MethodSpec.Builder builder = MethodSpec.methodBuilder("setProperty")
      .addModifiers(PUBLIC)
      .addAnnotation(Override.class)
      .returns(TypeName.VOID);

  switch (classInfo.getType()) {
    case VIEW_MANAGER:
      builder
          .addParameter(classInfo.mClassName, "manager")
          .addParameter(classInfo.mViewType, "view");
      break;
    case SHADOW_NODE:
      builder
          .addParameter(classInfo.mClassName, "node");
      break;
  }

  return builder
      .addParameter(STRING_TYPE, "name")
      .addParameter(PROPS_TYPE, "props")
      .addCode(generateSetProperty(classInfo, properties))
      .build();
}
 
開發者ID:qq565999484,項目名稱:RNLearn_Project1,代碼行數:27,代碼來源:ReactPropertyProcessor.java

示例11: streamingSimpleMethods

import com.squareup.javapoet.TypeName; //導入依賴的package包/類
private List<MethodSpec> streamingSimpleMethods(OperationModel opModel) {
    TypeName responseType = ClassName.get(model.getMetadata().getFullModelPackageName(),
                                          opModel.getReturnType().getReturnType());
    ClassName requestType = ClassName.get(model.getMetadata().getFullModelPackageName(),
                                          opModel.getInput().getVariableType());
    List<MethodSpec> simpleMethods = new ArrayList<>();
    if (opModel.hasStreamingInput()) {
        simpleMethods.add(uploadFromFileSimpleMethod(opModel, responseType, requestType));
    }
    if (opModel.hasStreamingOutput()) {
        simpleMethods.add(downloadToFileSimpleMethod(opModel, responseType, requestType));
        simpleMethods.add(inputStreamSimpleMethod(opModel, responseType, requestType));
        simpleMethods.add(bytesSimpleMethod(opModel, responseType, requestType));
    }
    return simpleMethods;
}
 
開發者ID:aws,項目名稱:aws-sdk-java-v2,代碼行數:17,代碼來源:SyncClientInterface.java

示例12: create

import com.squareup.javapoet.TypeName; //導入依賴的package包/類
static OutputValue create(Value value, ClassName specOutputClass, Spec spec)
    throws ParserException {
  ClassName outputClass = specOutputClass.nestedClass(value.name());
  Iterable<TypeVariableName> typeVariables = getTypeVariables(value, spec.typeVariables());

  List<Parameter> parameters = new ArrayList<>();
  for (Parameter parameter : value.parameters()) {
    TypeName rawParamType = withoutTypeParameters(parameter.type());

    if (isDataEnumParameter(rawParamType)) {
      TypeName paramOutputType =
          withParametersFromOther(toOutputClass(rawParamType), parameter.type());
      parameters.add(new Parameter(parameter.name(), paramOutputType, parameter.canBeNull()));
    } else {
      parameters.add(parameter);
    }
  }

  return new OutputValue(outputClass, value.name(), parameters, typeVariables);
}
 
開發者ID:spotify,項目名稱:dataenum,代碼行數:21,代碼來源:OutputValueFactory.java

示例13: addOnBind

import com.squareup.javapoet.TypeName; //導入依賴的package包/類
private void addOnBind(Element targetMember, TypeMirror bindTypeMirror, HashMap<Element, List<ViewBinder.Builder>> targetViewBinders) {
    boolean match = false;

    TypeName typeName = TypeName.get(bindTypeMirror);
    DeclaredType bindingDeclaredType = typeUtils.types().getDeclaredType(elementUtils.getTypeElement(bindTypeMirror.toString()));
    OnBind onBind = new NewInstance(typeName);

    // OnBind
    TypeMirror onBindTypeMirror = typeUtils.onBindDeclaredType();
    if (typeUtils.types().isSubtype(bindingDeclaredType, onBindTypeMirror)) {
        addOnBind(targetMember, onBind, targetViewBinders);
        match = true;
    }

    if (!match) {
        String stringBuilder = String.valueOf(typeName) +
                " does not implement required interface. Make sure classes provided in: " +
                "@" + SupportedAnnotations.OnBind.name + " or " +
                "@" + SupportedAnnotations.OnBindEach.name +
                " implements one or more of the following: " +
                TypeUtils.ON_BIND;

        throw new WitchException(logger.logError(stringBuilder));
    }
}
 
開發者ID:sedstrom,項目名稱:Witch-Android,代碼行數:26,代碼來源:WitchProcessor.java

示例14: getUnboxedClass

import com.squareup.javapoet.TypeName; //導入依賴的package包/類
public static TypeName getUnboxedClass(Element element) {
    TypeName typeName = getFieldClass(element);
    if (TypeName.INT.equals(typeName)) {
        return TypeName.get(Integer.class);
    }
    if (TypeName.LONG.equals(typeName)) {
        return TypeName.get(Long.class);
    }
    if (TypeName.FLOAT.equals(typeName)) {
        return TypeName.get(Float.class);
    }
    if (TypeName.DOUBLE.equals(typeName)) {
        return TypeName.get(Double.class);
    }
    if (TypeName.BOOLEAN.equals(typeName)) {
        return TypeName.get(Boolean.class);
    }
    if (TypeName.get(String.class).equals(typeName)) {
        return typeName;
    }
    return null;
}
 
開發者ID:florent37,項目名稱:RxAndroidOrm,代碼行數:23,代碼來源:ProcessUtils.java

示例15: onRegularMapperMethodStatement

import com.squareup.javapoet.TypeName; //導入依賴的package包/類
private void onRegularMapperMethodStatement(ClassName hashMapClassName, TypeName routerTargetTypeName, MethodSpec.Builder calcRegMapperMethodBuilder, UriEntry uriEntry) {
    calcRegMapperMethodBuilder.addCode("// " + uriEntry.getRouterTargetClass() + "\n");

    List<ParamEntry> paramEntries = uriEntry.getParams();
    int paramSize = null == paramEntries ? 0 : paramEntries.size();
    if (paramSize <= 0) {
        calcRegMapperMethodBuilder.addStatement(
                "$L.put($S, new $T($T.class, null))",
                "routerMapper", uriEntry.getUriRegular(), routerTargetTypeName, ClassName.get(uriEntry.getRouterTargetClass().asType()));
    } else {
        calcRegMapperMethodBuilder.addStatement("$L = new $T<>(" + paramSize + ", 1F)",
                "params", hashMapClassName);
        for (ParamEntry paramEntry : paramEntries) {
            LogUtil.logger("[Reg]paramEntry: " + paramEntry);
            calcRegMapperMethodBuilder.addStatement("params.put($S, $T.class)", paramEntry.getName(), paramEntry.getType());
        }

        calcRegMapperMethodBuilder.addStatement(
                "$L.put($S, new $T($T.class, $L))",
                "routerMapper", uriEntry.getUriRegular(), routerTargetTypeName, ClassName.get(uriEntry.getRouterTargetClass().asType()), "params");

    }
}
 
開發者ID:wangjiegulu,項目名稱:RapidRouter,代碼行數:24,代碼來源:RouterEntry.java


注:本文中的com.squareup.javapoet.TypeName類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。