本文整理汇总了Java中com.squareup.javapoet.TypeName.VOID属性的典型用法代码示例。如果您正苦于以下问题:Java TypeName.VOID属性的具体用法?Java TypeName.VOID怎么用?Java TypeName.VOID使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类com.squareup.javapoet.TypeName
的用法示例。
在下文中一共展示了TypeName.VOID属性的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: bestGuess
private static TypeName bestGuess(String type) {
switch (type) {
case "void": return TypeName.VOID;
case "boolean": return TypeName.BOOLEAN;
case "byte": return TypeName.BYTE;
case "char": return TypeName.CHAR;
case "double": return TypeName.DOUBLE;
case "float": return TypeName.FLOAT;
case "int": return TypeName.INT;
case "long": return TypeName.LONG;
case "short": return TypeName.SHORT;
default:
int left = type.indexOf('<');
if (left != -1) {
ClassName typeClassName = ClassName.bestGuess(type.substring(0, left));
List<TypeName> typeArguments = new ArrayList<>();
do {
typeArguments.add(WildcardTypeName.subtypeOf(Object.class));
left = type.indexOf('<', left + 1);
} while (left != -1);
return ParameterizedTypeName.get(typeClassName,
typeArguments.toArray(new TypeName[typeArguments.size()]));
}
return ClassName.bestGuess(type);
}
}
示例2: classToTypeName
public static TypeName classToTypeName(Class scalar) {
if (scalar.isPrimitive()) {
switch (scalar.getSimpleName()) {
case "int":
return TypeName.INT;
case "boolean":
return TypeName.BOOLEAN;
case "double":
return TypeName.DOUBLE;
case "float":
return TypeName.FLOAT;
case "byte":
return TypeName.BYTE;
case "char":
return TypeName.CHAR;
case "short":
return TypeName.SHORT;
case "long":
return TypeName.LONG;
case "void":
return TypeName.VOID; // ?
default:
throw new GenerationException("can't handle type: " + scalar);
}
} else {
return ClassName.get(scalar);
}
}
示例3: bestGuess
public static TypeName bestGuess(String type) {
switch (type) {
case "void":
return TypeName.VOID;
case "boolean":
return TypeName.BOOLEAN;
case "byte":
return TypeName.BYTE;
case "char":
return TypeName.CHAR;
case "double":
return TypeName.DOUBLE;
case "float":
return TypeName.FLOAT;
case "int":
return TypeName.INT;
case "long":
return TypeName.LONG;
case "short":
return TypeName.SHORT;
default:
int left = type.indexOf('<');
if (left != -1) {
ClassName typeClassName = ClassName.bestGuess(type.substring(0, left));
List<TypeName> typeArguments = new ArrayList<>();
do {
typeArguments.add(WildcardTypeName.subtypeOf(Object.class));
left = type.indexOf('<', left + 1);
} while (left != -1);
return ParameterizedTypeName.get(typeClassName,
typeArguments.toArray(new TypeName[typeArguments.size()]));
}
return ClassName.bestGuess(type);
}
}
示例4: bestGuessDeep
/**
* @param type
* @return
*/
public static TypeName bestGuessDeep(String type) {
switch (type) {
case "void":
return TypeName.VOID;
case "boolean":
return TypeName.BOOLEAN;
case "byte":
return TypeName.BYTE;
case "char":
return TypeName.CHAR;
case "double":
return TypeName.DOUBLE;
case "float":
return TypeName.FLOAT;
case "int":
return TypeName.INT;
case "long":
return TypeName.LONG;
case "short":
return TypeName.SHORT;
default:
int left = type.indexOf('<');
int right = type.indexOf('>');
if (-1 != left && -1 != right) {
ClassName typeClassName = ClassName.bestGuess(type.substring(0, left));
List<TypeName> typeArguments = new ArrayList<>();
do {
typeArguments.add(WildcardTypeName.subtypeOf(bestGuess(type.substring(left + 1, right))));
left = type.indexOf('<', left + 1);
right = type.indexOf('>', right - 1);
} while (left != -1);
return ParameterizedTypeName.get(typeClassName,
typeArguments.toArray(new TypeName[typeArguments.size()]));
}
return ClassName.bestGuess(type);
}
}
示例5: getTypeName
public static TypeName getTypeName(String type){
switch (type){
case NAME_int:
return TypeName.INT;
case NAME_long:
return TypeName.LONG;
case NAME_short:
return TypeName.SHORT;
case NAME_byte:
return TypeName.BYTE;
case NAME_boolean:
return TypeName.BOOLEAN;
case NAME_float:
return TypeName.FLOAT;
case NAME_double:
return TypeName.DOUBLE;
case NAME_char:
return TypeName.CHAR;
case NAME_void:
return TypeName.VOID;
}
return ClassName.bestGuess(type);
}
示例6: generateInitMapMethod
/**
* create init map method
*/
private MethodSpec generateInitMapMethod() {
TypeName returnType = TypeName.VOID;
MethodSpec.Builder openUriMethodSpecBuilder = MethodSpec.methodBuilder("initMap")
.returns(returnType)
.addAnnotation(Override.class)
.addModifiers(Modifier.PUBLIC);
openUriMethodSpecBuilder.addStatement("super.initMap()");
for (Node node : routerNodes) {
openUriMethodSpecBuilder.addStatement(
mRouteMapperFieldName + ".put($S,$T.class)",
node.getPath(),
ClassName.get((TypeElement) node.getRawType()));
// Make map body for paramsType
StringBuilder mapBodyBuilder = new StringBuilder();
Map<String, Integer> paramsType = node.getParamsType();
if (MapUtils.isNotEmpty(paramsType)) {
for (Map.Entry<String, Integer> types : paramsType.entrySet()) {
mapBodyBuilder.append("put(\"").append(types.getKey()).append("\", ").append(types.getValue()).append("); ");
}
}
String mapBody = mapBodyBuilder.toString();
logger.info(">>> mapBody: " + mapBody + " <<<");
if (!StringUtils.isEmpty(mapBody)) {
openUriMethodSpecBuilder.addStatement(
mParamsMapperFieldName + ".put($T.class,"
+ "new java.util.HashMap<String, Integer>(){{" + mapBody + "}}" + ")",
ClassName.get((TypeElement) node.getRawType()));
}
}
return openUriMethodSpecBuilder.build();
}
示例7: bestGuess
private static TypeName bestGuess(String type) {
switch (type) {
case "void":
return TypeName.VOID;
case "boolean":
return TypeName.BOOLEAN;
case "byte":
return TypeName.BYTE;
case "char":
return TypeName.CHAR;
case "double":
return TypeName.DOUBLE;
case "float":
return TypeName.FLOAT;
case "int":
return TypeName.INT;
case "long":
return TypeName.LONG;
case "short":
return TypeName.SHORT;
default:
int left = type.indexOf('<');
if (left != -1) {
ClassName typeClassName = ClassName.bestGuess(type.substring(0, left));
List<TypeName> typeArguments = new ArrayList<>();
do {
typeArguments.add(WildcardTypeName.subtypeOf(Object.class));
left = type.indexOf('<', left + 1);
} while (left != -1);
return ParameterizedTypeName.get(typeClassName,
typeArguments.toArray(new TypeName[typeArguments.size()]));
}
return ClassName.bestGuess(type);
}
}
示例8: isVoid
public boolean isVoid(TypeName returnType) {
return returnType == TypeName.VOID || ClassName.get("java.lang", "Void").equals(returnType);
}
示例9: prepareNewThreadMethod
private void prepareNewThreadMethod(MethodThreadStitching binding,
MethodSpec.Builder methodSpecBuilder, String returnStatement) {
if (binding.getReturnType() == TypeName.VOID) {
methodSpecBuilder
.returns(TypeName.VOID);
methodSpecBuilder
.addStatement("$T.getInstance().submitVoidTask($L)",
mNewThreadExecutor,
TypeSpec.anonymousClassBuilder("")
.addSuperinterface(ClassName.get(Runnable.class))
.addMethod(MethodSpec.methodBuilder("run")
.addAnnotation(Override.class)
.addModifiers(Modifier.PUBLIC)
.returns(binding.getReturnType())
.addStatement("$L", returnStatement)
.build())
.build());
} else {
methodSpecBuilder
.returns(binding.getReturnType().box());
methodSpecBuilder
.beginControlFlow("try")
.addStatement("return $T.getInstance().submitCallableTask($L)",
mNewThreadExecutor,
TypeSpec.anonymousClassBuilder("")
.addSuperinterface(ParameterizedTypeName
.get(ClassName.get(Callable.class),
binding.getReturnType().box()))
.addMethod(MethodSpec.methodBuilder("call")
.addAnnotation(Override.class)
.addModifiers(Modifier.PUBLIC)
.addException(Exception.class)
.returns(binding.getReturnType().box())
.addStatement("return $L", returnStatement)
.build())
.build())
.nextControlFlow(Constants.CATCH_BLOCK, InterruptedException.class)
.addStatement(Constants.PRINT_STACKTRACE)
.addStatement(Constants.RETURN_NULL)
.nextControlFlow(Constants.CATCH_BLOCK, ExecutionException.class)
.addStatement(Constants.PRINT_STACKTRACE)
.addStatement(Constants.RETURN_NULL)
.endControlFlow();
}
}
示例10: prepareAnyThreadMethod
private void prepareAnyThreadMethod(MethodThreadStitching binding,
MethodSpec.Builder methodSpecBuilder, String returnStatement) {
if (binding.getReturnType() == TypeName.VOID) {
methodSpecBuilder
.returns(TypeName.VOID);
methodSpecBuilder
.addStatement("$T.getInstance().submitVoidTask($L)",
mBackgroundExecutor,
TypeSpec.anonymousClassBuilder("")
.addSuperinterface(ClassName.get(Runnable.class))
.addMethod(MethodSpec.methodBuilder("run")
.addAnnotation(Override.class)
.addModifiers(Modifier.PUBLIC)
.returns(binding.getReturnType())
.addStatement("$L", returnStatement)
.build())
.build());
} else {
methodSpecBuilder
.returns(binding.getReturnType().box());
methodSpecBuilder
.beginControlFlow("try")
.addStatement("return $T.getInstance().submitCallableTask($L)",
mBackgroundExecutor,
TypeSpec.anonymousClassBuilder("")
.addSuperinterface(ParameterizedTypeName
.get(ClassName.get(Callable.class),
binding.getReturnType().box()))
.addMethod(MethodSpec.methodBuilder("call")
.addAnnotation(Override.class)
.addModifiers(Modifier.PUBLIC)
.addException(Exception.class)
.returns(binding.getReturnType().box())
.addStatement("return $L", returnStatement)
.build())
.build())
.nextControlFlow(Constants.CATCH_BLOCK, InterruptedException.class)
.addStatement(Constants.PRINT_STACKTRACE)
.addStatement(Constants.RETURN_NULL)
.nextControlFlow(Constants.CATCH_BLOCK, ExecutionException.class)
.addStatement(Constants.PRINT_STACKTRACE)
.addStatement(Constants.RETURN_NULL)
.endControlFlow();
}
}