本文整理汇总了Java中com.squareup.javapoet.ArrayTypeName类的典型用法代码示例。如果您正苦于以下问题:Java ArrayTypeName类的具体用法?Java ArrayTypeName怎么用?Java ArrayTypeName使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ArrayTypeName类属于com.squareup.javapoet包,在下文中一共展示了ArrayTypeName类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getTagsBuilderMethod
import com.squareup.javapoet.ArrayTypeName; //导入依赖的package包/类
private static MethodSpec getTagsBuilderMethod(ClassName name, ClassName tags, int size) {
ParameterSpec parameter = ParameterSpec.builder(ArrayTypeName.of(tags), "tags").build();
return MethodSpec.methodBuilder("tags")
.addModifiers(Modifier.PUBLIC)
.addParameter(parameter)
.varargs()
.addStatement("$T clone = new $T[" + size + "]", ArrayTypeName.of(tags), tags)
.beginControlFlow("if(this.tags != null)")
.addStatement("System.arraycopy(this.tags, 0, clone, 0, " + size + ")")
.endControlFlow()
.beginControlFlow("for($T tag : tags)", tags)
.addStatement("clone[tag.ordinal()] = tag")
.endControlFlow()
.addStatement("this.tags = clone")
.returns(name)
.addStatement("return this")
.build();
}
示例2: typeNeedsTypeVariable
import com.squareup.javapoet.ArrayTypeName; //导入依赖的package包/类
private static boolean typeNeedsTypeVariable(TypeName type, TypeVariableName typeVariable) {
if (typeVariable.equals(type)) {
return true;
}
if (type instanceof ParameterizedTypeName) {
ParameterizedTypeName parameterized = ((ParameterizedTypeName) type);
for (TypeName typeArgument : parameterized.typeArguments) {
if (typeVariable.equals(typeArgument)) {
return true;
}
}
}
if (type instanceof ArrayTypeName) {
ArrayTypeName arrayType = (ArrayTypeName) type;
if (typeVariable.equals(arrayType.componentType)) {
return true;
}
}
return false;
}
示例3: generateUnboxMethod
import com.squareup.javapoet.ArrayTypeName; //导入依赖的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();
}
示例4: createIdSearch
import com.squareup.javapoet.ArrayTypeName; //导入依赖的package包/类
public static TypeName createIdSearch(ProcessingEnvironment processingEnvironment, LocalConfiguration localConfiguration) {
TypeName idTypeName = TypeName.get(localConfiguration.getIdTypeMirror());
if (idTypeName.equals(ClassName.get("java.lang", "Boolean")) || idTypeName.equals(TypeName.BOOLEAN)) {
return ClassName.get(GlobalConfiguration.BOOLEAN_ID_SEARCH_CLASS_PACKAGE, GlobalConfiguration.BOOLEAN_ID_SEARCH_CLASS_NAME);
} else if (idTypeName.equals(ArrayTypeName.of(TypeName.BYTE))) {
return ClassName.get(GlobalConfiguration.BYTE_ARRAY_ID_SEARCH_CLASS_PACKAGE, GlobalConfiguration.BYTE_ARRAY_ID_SEARCH_CLASS_NAME);
} else if (idTypeName.equals(ClassName.get("java.lang", "Byte")) || idTypeName.equals(TypeName.BYTE)) {
return ClassName.get(GlobalConfiguration.BOOLEAN_ID_SEARCH_CLASS_PACKAGE, GlobalConfiguration.BOOLEAN_ID_SEARCH_CLASS_NAME);
} else if (idTypeName.equals(ClassName.get("java.util", "Date"))) {
return ClassName.get(GlobalConfiguration.DATE_ID_SEARCH_CLASS_PACKAGE, GlobalConfiguration.DATE_ID_SEARCH_CLASS_NAME);
} else if (idTypeName.equals(ClassName.get("java.lang", "Double")) || idTypeName.equals(TypeName.DOUBLE)) {
return ClassName.get(GlobalConfiguration.DOUBLE_ID_SEARCH_CLASS_PACKAGE, GlobalConfiguration.DOUBLE_ID_SEARCH_CLASS_NAME);
} else if (idTypeName.equals(ClassName.get("java.lang", "Float")) || idTypeName.equals(TypeName.FLOAT)) {
return ClassName.get(GlobalConfiguration.FLOAT_ID_SEARCH_CLASS_PACKAGE, GlobalConfiguration.FLOAT_ID_SEARCH_CLASS_NAME);
} else if (idTypeName.equals(ClassName.get("java.lang", "Integer")) || idTypeName.equals(TypeName.INT)) {
return ClassName.get(GlobalConfiguration.INTEGER_ID_SEARCH_CLASS_PACKAGE, GlobalConfiguration.INTEGER_ID_SEARCH_CLASS_NAME);
} else if (idTypeName.equals(ClassName.get("java.lang", "Long")) || idTypeName.equals(TypeName.LONG)) {
return ClassName.get(GlobalConfiguration.LONG_ID_SEARCH_CLASS_PACKAGE, GlobalConfiguration.LONG_ID_SEARCH_CLASS_NAME);
} else if (idTypeName.equals(ClassName.get("java.lang", "Short")) || idTypeName.equals(TypeName.SHORT)) {
return ClassName.get(GlobalConfiguration.SHORT_ID_SEARCH_CLASS_PACKAGE, GlobalConfiguration.SHORT_ID_SEARCH_CLASS_NAME);
} else if (idTypeName.equals(ClassName.get("java.lang", "String"))) {
return ClassName.get(GlobalConfiguration.STRING_ID_SEARCH_CLASS_PACKAGE, GlobalConfiguration.STRING_ID_SEARCH_CLASS_NAME);
} else {
throw new RealmRepositoryException("Not supported id type " + idTypeName.toString() + " in " + localConfiguration.getDataRepositoryInterfaceTypeElement().getSimpleName().toString());
}
}
示例5: valueOf
import com.squareup.javapoet.ArrayTypeName; //导入依赖的package包/类
public static Type valueOf(TypeName typeName) {
if (ArrayTypeName.of(byte.class).equals(typeName)) {
return CursorRowElement.Type.BLOB;
} else if (TypeName.DOUBLE.equals(typeName) || TypeName.DOUBLE.box().equals(typeName)) {
return CursorRowElement.Type.DOUBLE;
} else if (TypeName.INT.equals(typeName) || TypeName.INT.box().equals(typeName)) {
return CursorRowElement.Type.INT;
} else if (TypeName.FLOAT.equals(typeName) || TypeName.FLOAT.box().equals(typeName)) {
return CursorRowElement.Type.FLOAT;
} else if (TypeName.LONG.equals(typeName) || TypeName.LONG.box().equals(typeName)) {
return CursorRowElement.Type.LONG;
} else if (ClassName.get(String.class).equals(typeName)) {
return CursorRowElement.Type.STRING;
} else if (TypeName.SHORT.equals(typeName) || TypeName.SHORT.box().equals(typeName)) {
return CursorRowElement.Type.SHORT;
}
return null;
}
示例6: genNFieldInfo
import com.squareup.javapoet.ArrayTypeName; //导入依赖的package包/类
protected void genNFieldInfo() {
FieldInfo dynfieldinfo, fieldinfo;
List<long[]> finfo = new ArrayList<long[]>();
for (String name : m_gettersinfo.keySet()) {
dynfieldinfo = m_dynfieldsinfo.get(name);
if (dynfieldinfo.id > 0) {
finfo.add(new long[]{dynfieldinfo.id, dynfieldinfo.fieldoff, dynfieldinfo.fieldsize});
}
}
fieldinfo = new FieldInfo();
fieldinfo.name = String.format("m_nfieldinfo_%s", Utils.genRandomString());
fieldinfo.type = ArrayTypeName.of(ArrayTypeName.of(TypeName.LONG));
String initlstr = Utils.toInitLiteral(finfo);
fieldinfo.specbuilder = FieldSpec.builder(fieldinfo.type, fieldinfo.name, Modifier.PRIVATE, Modifier.STATIC)
.initializer("$1L", initlstr);
m_fieldsinfo.put("nfieldinfo", fieldinfo);
}
示例7: buildGetSingleByRawQueryMethod
import com.squareup.javapoet.ArrayTypeName; //导入依赖的package包/类
private MethodSpec buildGetSingleByRawQueryMethod() {
final String cursorVarName = "cursor";
return MethodSpec.methodBuilder("getSingle")
.addAnnotation(Override.class)
.addModifiers(Modifier.PUBLIC)
.returns(getClassNameOfElement())
.addParameter(CONTEXT, "context", Modifier.FINAL)
.addParameter(STRING, "rawQueryClause", Modifier.FINAL)
.addParameter(ArrayTypeName.of(STRING), "rawQueryArgs", Modifier.FINAL)
.addParameter(TypeName.BOOLEAN, "fromCache", Modifier.FINAL)
.addStatement("final $T $L = getReadableDatabase($L)"
+ ".rawQuery(rawQueryClause, rawQueryArgs)",
CURSOR, cursorVarName, "context")
.beginControlFlow("if (!$L.moveToFirst())", cursorVarName)
.addStatement("$L.close()", cursorVarName)
.addStatement("return null")
.endControlFlow()
.addStatement("$T ret = instantiateObject(cursor, context, fromCache)",
getClassNameOfElement())
.addStatement("$L.close()", cursorVarName)
.addStatement("return ret")
.build();
}
示例8: buildGetListByRawQueryMethod
import com.squareup.javapoet.ArrayTypeName; //导入依赖的package包/类
private MethodSpec buildGetListByRawQueryMethod() {
final String cursorVarName = "cursor";
return MethodSpec.methodBuilder("getList")
.addAnnotation(Override.class)
.addModifiers(Modifier.PUBLIC)
.returns(ParameterizedTypeName.get(LIST, getClassNameOfElement()))
.addParameter(CONTEXT, "context", Modifier.FINAL)
.addParameter(STRING, "rawQueryClause", Modifier.FINAL)
.addParameter(ArrayTypeName.of(STRING), "rawQueryArgs", Modifier.FINAL)
.addParameter(TypeName.BOOLEAN, "fromCache", Modifier.FINAL)
.addStatement("final $T<$T> ret = new $T<>()", LIST, getClassNameOfElement(),
ARRAY_LIST)
.addStatement("final $T $L = getReadableDatabase($L)"
+ ".rawQuery(rawQueryClause, rawQueryArgs)",
CURSOR, cursorVarName, "context")
.beginControlFlow("if (!$L.moveToFirst())", cursorVarName)
.addStatement("$L.close()", cursorVarName)
.addStatement("return ret")
.endControlFlow()
.beginControlFlow("do")
.addStatement("ret.add(instantiateObject(cursor, context, fromCache))")
.endControlFlow("while(cursor.moveToNext())")
.addStatement("$L.close()", cursorVarName)
.addStatement("return ret")
.build();
}
示例9: generateUpdateMethod
import com.squareup.javapoet.ArrayTypeName; //导入依赖的package包/类
private MethodSpec generateUpdateMethod() {
MethodSpec.Builder saveMethodBuidler = MethodSpec.methodBuilder("update")
.addAnnotation(Override.class)
.addModifiers(Modifier.PUBLIC)
.returns(TypeName.INT)
.addParameter(ClassName.get(Class.class), "clazz")
.addParameter(ClassName.get(ContentValuesWrapper.class), "valuesWrapper")
.addParameter(ClassName.get(String.class), "where")
.addParameter(ArrayTypeName.of(ClassName.get(String.class)), "whereArgs");
for (TableInfo table : tables) {
String daoField = table.getDaoClassName().replace("$$", "").toLowerCase();
saveMethodBuidler.addStatement("if($L.class.equals(clazz)) return $L.update(valuesWrapper, where, whereArgs)", table.getClassName(), daoField);
}
saveMethodBuidler.addStatement("return 0");
return saveMethodBuidler.build();
}
示例10: generateDeleteMethod
import com.squareup.javapoet.ArrayTypeName; //导入依赖的package包/类
private MethodSpec generateDeleteMethod() {
MethodSpec.Builder saveMethodBuidler = MethodSpec.methodBuilder("delete")
.addAnnotation(Override.class)
.addModifiers(Modifier.PUBLIC)
.returns(TypeName.INT)
.addParameter(ClassName.get(Class.class), "clazz")
.addParameter(ClassName.get(String.class), "where")
.addParameter(ArrayTypeName.of(ClassName.get(String.class)), "whereArgs");
for (TableInfo table : tables) {
String daoField = table.getDaoClassName().replace("$$", "").toLowerCase();
saveMethodBuidler.addStatement("if($L.class.equals(clazz)) return $L.delete(where, whereArgs)", table.getClassName(), daoField);
}
saveMethodBuidler.addStatement("return 0");
return saveMethodBuidler.build();
}
示例11: generateRawQueryMethod
import com.squareup.javapoet.ArrayTypeName; //导入依赖的package包/类
private MethodSpec generateRawQueryMethod() {
MethodSpec.Builder queryMethodBuidler = MethodSpec.methodBuilder("rawQuery")
.addAnnotation(Override.class)
.addModifiers(Modifier.PUBLIC)
.returns(ClassName.get("android.database", "Cursor"))
.addParameter(ClassName.get(Class.class), "clazz")
.addParameter(TypeName.BOOLEAN, "distinct")
.addParameter(ArrayTypeName.of(ClassName.get(String.class)), "columns")
.addParameter(ClassName.get(String.class), "selection")
.addParameter(ArrayTypeName.of(ClassName.get(String.class)), "selectionArgs")
.addParameter(ClassName.get(String.class), "groupBy")
.addParameter(ClassName.get(String.class), "having")
.addParameter(ClassName.get(String.class), "orderBy")
.addParameter(ClassName.get(String.class), "limit");
for (TableInfo table : tables) {
String daoField = table.getDaoClassName().replace("$$", "").toLowerCase();
queryMethodBuidler.addStatement("if($L.class.equals(clazz)) return $L.rawQuery(distinct, columns, selection, selectionArgs, groupBy, having, orderBy, limit)", table.getClassName(), daoField);
}
queryMethodBuidler.addStatement("return null");
return queryMethodBuidler.build();
}
示例12: generatorQueryMethod
import com.squareup.javapoet.ArrayTypeName; //导入依赖的package包/类
private MethodSpec generatorQueryMethod() {
MethodSpec.Builder queryBuilder = MethodSpec.methodBuilder("query")
.addModifiers(Modifier.PUBLIC)
.returns(ClassName.get(List.class))
.addParameter(TypeName.BOOLEAN, "distinct")
.addParameter(ArrayTypeName.of(ClassName.get(String.class)), "columns")
.addParameter(ClassName.get(String.class), "selection")
.addParameter(ArrayTypeName.of(ClassName.get(String.class)), "selectionArgs")
.addParameter(ClassName.get(String.class), "groupBy")
.addParameter(ClassName.get(String.class), "having")
.addParameter(ClassName.get(String.class), "orderBy")
.addParameter(ClassName.get(String.class), "limit")
.addStatement("$T cursor = this.rawQuery(distinct, columns, selection, selectionArgs, groupBy, having, orderBy, limit)", ClassName.get("android.database", "Cursor"));
queryBuilder.addStatement("$T list = new $T()", ArrayList.class, ArrayList.class);
queryBuilder.addCode("if (cursor.moveToFirst()) {");
queryBuilder.addCode(" do {");
queryBuilder.addCode(" list.add(fillData(cursor));");
queryBuilder.addCode(" } while (cursor.moveToNext());");
queryBuilder.addCode("}");
queryBuilder.addStatement("return list");
return queryBuilder.build();
}
示例13: buildSignature
import com.squareup.javapoet.ArrayTypeName; //导入依赖的package包/类
@Override
MethodSpec buildSignature(RDFSClazz domainClazz, OntGenerationConfig config) throws RepositoryException {
if (getRanges() != null) {
MethodSpec.Builder setter = buildParameterlessSetterSignature(domainClazz, config);
// Get the vararg parameter type:
TypeName paramType = ArrayTypeName.of(getParameterType(config, false));
return setter.addParameter(paramType, "values")
.varargs()
.build();
} else {
return null;
}
}
示例14: simpleName
import com.squareup.javapoet.ArrayTypeName; //导入依赖的package包/类
private static String simpleName(TypeName typeName) {
if (typeName instanceof ClassName) {
return UPPER_CAMEL.to(LOWER_CAMEL, ((ClassName) typeName).simpleName());
} else if (typeName instanceof ParameterizedTypeName) {
ParameterizedTypeName parameterizedTypeName = (ParameterizedTypeName) typeName;
return UPPER_CAMEL.to(LOWER_CAMEL, parameterizedTypeName.rawType.simpleName())
+ (parameterizedTypeName.typeArguments.isEmpty() ? "" : "__")
+ simpleName(parameterizedTypeName.typeArguments);
} else if (typeName instanceof ArrayTypeName) {
return "array__" + simpleName(((ArrayTypeName) typeName).componentType);
} else if (typeName instanceof WildcardTypeName) {
WildcardTypeName wildcardTypeName = (WildcardTypeName) typeName;
return "wildcard__"
+ simpleName(ImmutableList.<TypeName>builder().addAll(wildcardTypeName.lowerBounds)
.addAll(wildcardTypeName.upperBounds)
.build());
} else if (typeName instanceof TypeVariableName) {
TypeVariableName variable = (TypeVariableName) typeName;
return variable.name
+ (variable.bounds.isEmpty() ? "" : "__")
+ simpleName(variable.bounds);
} else {
return typeName.toString();
}
}
示例15: buildProjectionField
import com.squareup.javapoet.ArrayTypeName; //导入依赖的package包/类
private FieldSpec buildProjectionField() {
CodeBlock.Builder initializer = CodeBlock.builder();
initializer.add("{");
boolean first = true;
for (RecordField field : parsed.fields) {
if (!first) {
initializer.add(", ");
}
initializer.add("$N.$L()", projectionsClass, field.name);
first = false;
}
initializer.add("}");
TypeName arrayOfStrings = ArrayTypeName.of(ClassName.get(String.class));
return FieldSpec.builder(arrayOfStrings, "PROJECTION", Modifier.PRIVATE, Modifier.STATIC, Modifier.FINAL)
.initializer(initializer.build().toString())
.build();
}