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


Java TypeName.isPrimitive方法代码示例

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


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

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

示例2: getKiiGetter

import com.squareup.javapoet.TypeName; //导入方法依赖的package包/类
public static String getKiiGetter(TypeName typeName) {
    if (typeName.isPrimitive()) {
        return String.format(Locale.US, "%s%s", typeName.toString().substring(0, 1).toUpperCase(), typeName.toString().substring(1, typeName.toString().length()));
    } else {
        String[] strings = typeName.toString().split("\\.");
        return strings[strings.length - 1];
    }
}
 
开发者ID:daisuke-nomura,项目名称:KiiAnnotation,代码行数:9,代码来源:GetterSetterGenerator.java

示例3: checkIfTypeIsSupported

import com.squareup.javapoet.TypeName; //导入方法依赖的package包/类
private void checkIfTypeIsSupported(VariableElement variableElement) {
    final TypeName typeOfCurrentElement = ClassName.get(variableElement.asType());
    if (!typeOfCurrentElement.equals(ClassName.get(String.class)) &&
            !typeOfCurrentElement.equals(BYTE_ARRAY_TYPE) &&
            !typeOfCurrentElement.isPrimitive() &&
            !typeOfCurrentElement.isBoxedPrimitive()) {

        throwError("SlimOrm: Type " + typeOfCurrentElement + " is not supported");
    } else if ((typeOfCurrentElement.isPrimitive() || typeOfCurrentElement.isBoxedPrimitive())
            && (typeOfCurrentElement.unbox().equals(TypeName.BYTE) || typeOfCurrentElement.unbox().equals(TypeName.CHAR))) {

        throwError("SlimOrm: Type " + typeOfCurrentElement + " is not supported");
    }
}
 
开发者ID:Neristance,项目名称:slimorm,代码行数:15,代码来源:SlimOrmProcessor.java

示例4: parse

import com.squareup.javapoet.TypeName; //导入方法依赖的package包/类
@Override
public void parse(Builder builder, int depth, String setter, Object... setterFormatArgs) {
    TypeName fieldType = arrayType.getTypeName();
    final String collectionVarName = "collection" + depth;

    final String instanceCreator = String.format("$T<%s> $L = new $T<%s>()", arrayType.getParameterizedTypeString(), arrayType.getParameterizedTypeString());
    final Object[] instanceCreatorArgs = expandStringArgs(List.class, arrayType.getParameterizedTypeStringArgs(), collectionVarName, ArrayList.class, arrayType.getParameterizedTypeStringArgs());

    builder.beginControlFlow("if ($L.getCurrentToken() == $T.START_ARRAY)", JSON_PARSER_VARIABLE_NAME, JsonToken.class)
            .addStatement(instanceCreator, instanceCreatorArgs)
            .beginControlFlow("while ($L.nextToken() != $T.END_ARRAY)", JSON_PARSER_VARIABLE_NAME, JsonToken.class);

    if (!fieldType.isPrimitive()) {
        final String valueVarName = "value" + depth;

        builder.addStatement("$T $L", arrayType.getTypeName(), valueVarName);
        arrayType.parse(builder, depth + 1, "$L = $L", valueVarName);

        builder.addStatement("$L.add($L)", collectionVarName, valueVarName);
    } else {
        arrayType.parse(builder, depth + 1, "$L.add($L)", collectionVarName);
    }

    builder.endControlFlow();

    if (fieldType.isPrimitive()) {
        builder
                .addStatement("$T[] array = new $T[$L.size()]", fieldType, fieldType, collectionVarName)
                .addStatement("int i = 0")
                .beginControlFlow("for ($T value : $L)", fieldType, collectionVarName)
                .addStatement("array[i++] = value")
                .endControlFlow();
    } else {
        builder.addStatement("$T[] array = $L.toArray(new $T[$L.size()])", fieldType, collectionVarName, fieldType, collectionVarName);
    }

    builder
            .addStatement(setter, expandStringArgs(setterFormatArgs, "array"))
            .nextControlFlow("else")
            .addStatement(setter, expandStringArgs(setterFormatArgs, "null"))
            .endControlFlow();
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:43,代码来源:ArrayCollectionType.java

示例5: isSupportedType

import com.squareup.javapoet.TypeName; //导入方法依赖的package包/类
public static boolean isSupportedType(TypeName type) {
  return type.isPrimitive() || type.isBoxedPrimitive() || SUPPORTED_TYPES.contains(type);
}
 
开发者ID:setheclark,项目名称:auto-value-json,代码行数:4,代码来源:JsonGeneratorUtils.java

示例6: isPrimitive

import com.squareup.javapoet.TypeName; //导入方法依赖的package包/类
public static boolean isPrimitive(TypeName typeName) {
    return typeName.isPrimitive() || typeName.isBoxedPrimitive();
}
 
开发者ID:srym,项目名称:vulture,代码行数:4,代码来源:TypeUtils.java

示例7: isPrimitive

import com.squareup.javapoet.TypeName; //导入方法依赖的package包/类
public static boolean isPrimitive(TypeName typeName) {
    return typeName.isPrimitive()
        || unbox(typeName).isPrimitive()
        || (ClassName.get(String.class).equals(typeName))
        || isDate(typeName);
}
 
开发者ID:florent37,项目名称:RxAndroidOrm,代码行数:7,代码来源:ProcessUtils.java

示例8: isValidType

import com.squareup.javapoet.TypeName; //导入方法依赖的package包/类
public static boolean isValidType(TypeName typeName) {
    return typeName.isPrimitive() || typeName.isBoxedPrimitive() || VALID_TYPES.contains(typeName);
}
 
开发者ID:foodora,项目名称:android-auto-mapper,代码行数:4,代码来源:Parcelables.java

示例9: isPrimitiveOrWrapper

import com.squareup.javapoet.TypeName; //导入方法依赖的package包/类
public static boolean isPrimitiveOrWrapper(TypeMirror type) {
    TypeName typeName = TypeName.get(type);

    return typeName.isPrimitive() || typeName.isBoxedPrimitive();
}
 
开发者ID:foodora,项目名称:android-auto-mapper,代码行数:6,代码来源:TypeUtil.java

示例10: createDefaultBinding

import com.squareup.javapoet.TypeName; //导入方法依赖的package包/类
private static void createDefaultBinding(final String containingClassFieldName, final String contextFieldName, final StyleableField field, final MethodSpec.Builder builder) {
    final ResourcesWriter resWriter = ResourcesWriter.writer(containingClassFieldName, RESOURCES_FIELD_NAME);
    final PixelConverterWriter pixelWriter = PixelConverterWriter.writer(containingClassFieldName, contextFieldName);
    final TypeName typeName = field.getTypeName();
    int exceptionCount = 0;

    if (typeName.isBoxedPrimitive() || typeName.isPrimitive()) {
        final TypeName unboxedTypeName = typeName.unbox();

        if (unboxedTypeName.equals(TypeName.BOOLEAN)) {
            builder.addCode(resWriter.getBoolean(field.getName(), field.getDefaultValue()));
        } else if (unboxedTypeName.equals(TypeName.INT)) {
            // getColor(), getDimensionPixelOffset(), getDimensionPixelSize(), getInteger()
            if (field.isColorInt()) {
                builder.addCode(resWriter.getColor(field.getName(), field.getDefaultValue()));
            } else if (field.isDimension()) {
                StyleableField.DimensionUnit unit = field.getDimensionUnit();

                if (unit == null || unit == StyleableField.DimensionUnit.PX) {
                    builder.addCode(resWriter.getDimensionPixelOffset(field.getName(), field.getDefaultValue()));
                } else if (unit == StyleableField.DimensionUnit.DP) {
                    builder.addCode(resWriter.getDimensionPixelOffset(field.getName(), field.getDefaultValue()));
                    builder.addCode("\n");
                    builder.addCode(pixelWriter.convertPixelToDp(field.getName()));
                } else if (unit == StyleableField.DimensionUnit.SP) {
                    builder.addCode(resWriter.getDimensionPixelSize(field.getName(), field.getDefaultValue()));
                    builder.addCode("\n");
                    builder.addCode(pixelWriter.convertPixelToDp(field.getName()));
                }
            } else {
                builder.beginControlFlow("try");
                builder.addCode(resWriter.getColor(field.getName(), field.getDefaultValue()));
                builder.addCode("\n");
                builder.nextControlFlow("catch (Exception e$L)", exceptionCount);
                exceptionCount++;
                builder.beginControlFlow("try");
                builder.addCode(resWriter.getDimensionPixelOffset(field.getName(), field.getDefaultValue()));
                builder.addCode("\n");
                builder.nextControlFlow("catch (Exception e$L)", exceptionCount);
                builder.addCode(resWriter.getInteger(field.getName(), field.getDefaultValue()));
                builder.addCode("\n");
                builder.endControlFlow();
                builder.endControlFlow();
            }
        } else if (unboxedTypeName.equals(TypeName.FLOAT)) {
            if (field.isDimension()) {
                builder.addCode(resWriter.getDimension(field.getName(), field.getDefaultValue()));
            } else {
                builder.beginControlFlow("try");
                builder.addCode(resWriter.getDimension(field.getName(), field.getDefaultValue()));
                builder.addCode("\n");
                builder.nextControlFlow("catch (Exception e$L)", exceptionCount);
                builder.addCode(resWriter.getFraction(field.getName(), field.getDefaultValue(), 0, 1));
                builder.addCode("\n");
                builder.endControlFlow();
            }
        }
    } else if (typeName.equals(COLOR_STATE_LIST)) {
        builder.addCode(resWriter.getColorStateList(field.getName(), field.getDefaultValue()));
    } else if (typeName.equals(DRAWABLE)) {
        builder.addCode(resWriter.getDrawable(field.getName(), field.getDefaultValue()));
    } else if (typeName.equals(CHAR_SEQUENCE)) {
        builder.addCode(resWriter.getText(field.getName(), field.getDefaultValue()));
    } else if (typeName.equals(CHAR_SEQUENCE_ARRAY)) {
        builder.addCode(resWriter.getTextArray(field.getName(), field.getDefaultValue()));
    } else if (typeName.equals(STRING)) {
        builder.addCode(resWriter.getString(field.getName(), field.getDefaultValue()));
    }

    builder.addCode("\n");
}
 
开发者ID:chRyNaN,项目名称:glimpse,代码行数:72,代码来源:StyleableAttributeClassCreator.java


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