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


Java TypeName.get方法代码示例

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


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

示例1: replaceReturnType

import com.squareup.javapoet.TypeName; //导入方法依赖的package包/类
@Override
public TypeName replaceReturnType(String currentPkg, String directParentInterface, String curClassname,
                                  List<? extends TypeMirror> superInterfaces, TypeName superClass, ExecutableElement method) {
    final TypeMirror returnType = method.getReturnType();
    switch (method.getSimpleName().toString()){
        case TypeCopyableFiller.NAME_COPY: {
            switch (returnType.getKind()) {
                case TYPEVAR: //泛型
                    return  TypeVariableName.get(directParentInterface);

                default:
                    return TypeName.get(returnType);
            }
        }

        default:
            return TypeName.get(returnType);

    }

}
 
开发者ID:LightSun,项目名称:data-mediator,代码行数:22,代码来源:CopyReplacer.java

示例2: getTypeNameFor

import com.squareup.javapoet.TypeName; //导入方法依赖的package包/类
private TypeName getTypeNameFor(String arg) {
    switch (arg) {
        case "string":
            return TypeName.get(String.class);
        case "int":
            return TypeName.get(int.class);
        case "byte":
            return TypeName.get(byte.class);
        case "long":
            return TypeName.get(long.class);
        case "float":
            return TypeName.get(float.class);
        case "double":
            return TypeName.get(float.class);
        case "parcelable":
            return ClassName.get("android.os", "Parcelable");

        default: {
            messager.printMessage(Diagnostic.Kind.NOTE, " return default 'Serializable' for" + arg);
            return TypeName.get(Serializable.class);
        }

    }
}
 
开发者ID:daawa,项目名称:auto-nav,代码行数:25,代码来源:NavProcessor.java

示例3: buildGetByQueryMethod

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

示例4: JsonProperty

import com.squareup.javapoet.TypeName; //导入方法依赖的package包/类
public JsonProperty(String humanName, ExecutableElement element) {
  this.methodName = element.getSimpleName().toString();
  this.humanName = humanName;
  this.element = element;
  this.type = TypeName.get(element.getReturnType());
  this.annotations = buildAnnotations(element);

  JsonAdapter jsonAdapter = element.getAnnotation(JsonAdapter.class);
  if (jsonAdapter != null) {
    try {
      jsonAdapter.value();
    } catch (MirroredTypeException e) {
      typeAdapter = e.getTypeMirror();
    }
  }

  DefaultValue defaultValue = element.getAnnotation(DefaultValue.class);
  if (defaultValue != null) {
    this.defaultValue = defaultValue.value();
  }
}
 
开发者ID:setheclark,项目名称:auto-value-json,代码行数:22,代码来源:JsonProperty.java

示例5: generateReadMethod

import com.squareup.javapoet.TypeName; //导入方法依赖的package包/类
private static boolean generateReadMethod(Context context) {
  TypeElement type = context.autoValueClass();
  //Find method with param as JSONObject and return type as autovalue class.
  for (ExecutableElement method : ElementFilter.methodsIn(type.getEnclosedElements())) {
    if (method.getModifiers().contains(Modifier.STATIC) && method.getParameters().size() == 1) {
      TypeMirror rType = method.getReturnType();
      TypeName returnType = TypeName.get(rType);

      TypeMirror pType = method.getParameters().get(0).asType();
      TypeName paramType = TypeName.get(pType);
      if (returnType.equals(TypeName.get(type.asType())) && paramType.equals(
          JSON_OBJ_CLASS_NAME)) {
        return true;
      }
    }
  }
  return false;
}
 
开发者ID:setheclark,项目名称:auto-value-json,代码行数:19,代码来源:AutoValueJsonExtension.java

示例6: getTypeAdapters

import com.squareup.javapoet.TypeName; //导入方法依赖的package包/类
private ImmutableMap<TypeMirror, FieldSpec> getTypeAdapters(List<JsonProperty> properties,
    NameAllocator nameAllocator) {
  Map<TypeMirror, FieldSpec> typeAdapters = new LinkedHashMap<>();
  for (JsonProperty property : properties) {
    if (property.typeAdapter != null && !typeAdapters.containsKey(property.typeAdapter)) {
      ClassName typeName = (ClassName) TypeName.get(property.typeAdapter);
      String name = CaseFormat.LOWER_CAMEL.to(CaseFormat.UPPER_UNDERSCORE, typeName.simpleName());
      name = nameAllocator.newName(name, typeName);

      typeAdapters.put(property.typeAdapter,
          FieldSpec.builder(typeName, NameAllocator.toJavaIdentifier(name), PRIVATE, STATIC,
              FINAL).initializer("new $T()", typeName).build());
    }
  }

  return ImmutableMap.copyOf(typeAdapters);
}
 
开发者ID:setheclark,项目名称:auto-value-json,代码行数:18,代码来源:AutoValueJsonExtension.java

示例7: getValueType

import com.squareup.javapoet.TypeName; //导入方法依赖的package包/类
public TypeName getValueType(Element value) {

        TypeMirror type = getType(value);

        // Box if primitive
        if(type.getKind() != null && type.getKind().isPrimitive()) {
            type = types.boxedClass((PrimitiveType) type).asType();
        }

        // Get generic type if value container
        if(isValueContainer(type)) {
            DeclaredType declaredType = (DeclaredType) type;
            TypeMirror genericParameter = declaredType.getTypeArguments().get(0);
            return TypeName.get(genericParameter);
        }

        return TypeName.get(type);
    }
 
开发者ID:sedstrom,项目名称:Witch-Android,代码行数:19,代码来源:TypeUtils.java

示例8: getParameter

import com.squareup.javapoet.TypeName; //导入方法依赖的package包/类
private static ParameterSpec getParameter(VariableElement method) {
  TypeName type = TypeName.get(method.asType());
  String name = method.getSimpleName().toString();
  return ParameterSpec.builder(type, name)
      .addModifiers(method.getModifiers())
      .addAnnotations(getAnnotations(method))
      .build();
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:9,代码来源:ProcessorUtil.java

示例9: getOnBindToViewClass

import com.squareup.javapoet.TypeName; //导入方法依赖的package包/类
public static TypeName getOnBindToViewClass(Element action) {
    TypeMirror bindClass;
    try {
        action.getAnnotation(se.snylt.witch.annotations.BindToView.class).view();
        return null;
    } catch (MirroredTypeException mte) {
        bindClass = mte.getTypeMirror();
    }
    return TypeName.get(bindClass);
}
 
开发者ID:sedstrom,项目名称:Witch-Android,代码行数:11,代码来源:AnnotationUtils.java

示例10: getEnclosedArrayElement

import com.squareup.javapoet.TypeName; //导入方法依赖的package包/类
public static TypeElement getEnclosedArrayElement(Element element, Elements elementUtils) {
    ArrayType arrayType = (ArrayType) element.asType();
    if (arrayType != null) {
        TypeName tName = TypeName.get(arrayType.getComponentType());
        if (tName != null) {
            return elementUtils.getTypeElement(tName.toString());
        }
    }
    return null;
}
 
开发者ID:foodora,项目名称:android-auto-mapper,代码行数:11,代码来源:TypeUtil.java

示例11: build

import com.squareup.javapoet.TypeName; //导入方法依赖的package包/类
public PropertyInfo build(Element element, Property property)
    throws ReactPropertyException {
  String methodName = element.getSimpleName().toString();

  ExecutableElement method = (ExecutableElement) element;
  List<? extends VariableElement> parameters = method.getParameters();

  if (parameters.size() != getArgCount(mClassInfo.getType(), property)) {
    throw new ReactPropertyException("Wrong number of args", element);
  }

  int index = 0;
  if (mClassInfo.getType() == SettableType.VIEW_MANAGER) {
    TypeMirror mirror = parameters.get(index++).asType();
    if (!mTypes.isSubtype(mirror, mElements.getTypeElement("android.view.View").asType())) {
      throw new ReactPropertyException("First argument must be a subclass of View", element);
    }
  }

  if (property instanceof GroupProperty) {
    TypeName indexType = TypeName.get(parameters.get(index++).asType());
    if (!indexType.equals(TypeName.INT)) {
      throw new ReactPropertyException(
          "Argument " + index + " must be an int for @ReactPropGroup",
          element);
    }
  }

  TypeName propertyType = TypeName.get(parameters.get(index++).asType());
  if (!DEFAULT_TYPES.containsKey(propertyType)) {
    throw new ReactPropertyException(
        "Argument " + index + " must be of a supported type",
        element);
  }

  return new PropertyInfo(methodName, propertyType, element, property);
}
 
开发者ID:qq565999484,项目名称:RNLearn_Project1,代码行数:38,代码来源:ReactPropertyProcessor.java

示例12: getTypeName

import com.squareup.javapoet.TypeName; //导入方法依赖的package包/类
public static TypeName getTypeName(TypeElement enclosingElement) {
    TypeName targetType = TypeName.get(enclosingElement.asType());
    if (targetType instanceof ParameterizedTypeName) {
        targetType = ((ParameterizedTypeName) targetType).rawType;
    }
    return targetType;
}
 
开发者ID:chiclaim,项目名称:MRouter,代码行数:8,代码来源:ProcessorUtils.java

示例13: isPrimitiveArray

import com.squareup.javapoet.TypeName; //导入方法依赖的package包/类
public static boolean isPrimitiveArray(Element element) {
    if (element.asType().getKind() != TypeKind.ARRAY) {
        return false;
    }

    ArrayType arrayType = (ArrayType) element.asType();
    TypeMirror componentType = arrayType.getComponentType();

    TypeName typeName = TypeName.get(componentType);
    return typeName.isPrimitive() || typeName.isBoxedPrimitive();
}
 
开发者ID:srym,项目名称:vulture,代码行数:12,代码来源:TypeUtils.java

示例14: PreferenceKeyField

import com.squareup.javapoet.TypeName; //导入方法依赖的package包/类
public PreferenceKeyField(@NonNull VariableElement variableElement, @NonNull Elements elementUtils) throws IllegalAccessException {
    KeyName annotation_keyName = variableElement.getAnnotation(KeyName.class);
    this.variableElement = variableElement;
    PackageElement packageElement = elementUtils.getPackageOf(variableElement);
    this.packageName = packageElement.isUnnamed() ? null : packageElement.getQualifiedName().toString();
    this.typeName = TypeName.get(variableElement.asType());
    this.clazzName = variableElement.getSimpleName().toString();
    this.value = variableElement.getConstantValue();
    setTypeStringName();

    if(annotation_keyName != null)
        this.keyName = Strings.isNullOrEmpty(annotation_keyName.name()) ? StringUtils.toUpperCamel(this.clazzName) : annotation_keyName.name();
    else
        this.keyName = StringUtils.toUpperCamel(this.clazzName);

    if(this.isObjectField) {
        variableElement.getAnnotationMirrors().stream()
                .filter(annotationMirror -> TypeName.get(annotationMirror.getAnnotationType()).equals(TypeName.get(TypeConverter.class)))
                .forEach(annotationMirror -> {
                    annotationMirror.getElementValues().forEach((type, value) -> {
                        String[] split = value.getValue().toString().split("\\.");
                        StringBuilder builder = new StringBuilder();
                        for (int i=0; i<split.length-1; i++)
                            builder.append(split[i] + ".");
                        this.converterPackage = builder.toString().substring(0, builder.toString().length()-1);
                        this.converter = split[split.length-1];
                    });
        });
    }

    if(variableElement.getModifiers().contains(Modifier.PRIVATE)) {
        throw new IllegalAccessException(String.format("Field \'%s\' should not be private.", variableElement.getSimpleName()));
    } else if(!this.isObjectField && !variableElement.getModifiers().contains(Modifier.FINAL)) {
        throw new IllegalAccessException(String.format("Field \'%s\' should be final.", variableElement.getSimpleName()));
    }
}
 
开发者ID:skydoves,项目名称:PreferenceRoom,代码行数:37,代码来源:PreferenceKeyField.java

示例15: getTypeName

import com.squareup.javapoet.TypeName; //导入方法依赖的package包/类
public TypeName getTypeName(){
    return TypeName.get(tm);
}
 
开发者ID:LightSun,项目名称:data-mediator,代码行数:4,代码来源:FieldData.java


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