Java Code Examples for com.squareup.javapoet.TypeName.VOID

The following are Jave code examples for showing how to use VOID of the com.squareup.javapoet.TypeName class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: GitHub   File: BindingSet.java   View Source Code Vote up 6 votes
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);
  }
}
 
Example 2
Project: raml-java-tools   File: Scalars.java   View Source Code Vote up 5 votes
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);
    }
}
 
Example 3
Project: RapidRouter   File: EasyType.java   View Source Code Vote up 5 votes
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);
    }
}
 
Example 4
Project: RapidRouter   File: EasyType.java   View Source Code Vote up 5 votes
/**
 * @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);
    }
}
 
Example 5
Project: data-mediator   File: TypeUtils.java   View Source Code Vote up 5 votes
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);
}
 
Example 6
Project: DDComponentForAndroid   File: RouterProcessor.java   View Source Code Vote up 5 votes
/**
 * 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();
}
 
Example 7
Project: butterknife-parent   File: BindingSet.java   View Source Code Vote up 5 votes
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);
    }
}
 
Example 8
Project: Rx.Observe   File: ProcessUtils.java   View Source Code Vote up 4 votes
public boolean isVoid(TypeName returnType) {
    return returnType == TypeName.VOID || ClassName.get("java.lang", "Void").equals(returnType);
}
 
Example 9
Project: Stitch   File: StitchGenerator.java   View Source Code Vote up 4 votes
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();
    }

}
 
Example 10
Project: Stitch   File: StitchGenerator.java   View Source Code Vote up 4 votes
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();
    }
}