Java Code Examples for com.squareup.javapoet.ArrayTypeName#get()
The following examples show how to use
com.squareup.javapoet.ArrayTypeName#get() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Names.java From featured with Apache License 2.0 | 5 votes |
public TypeName getTypeNameByKind(VariableElement param) { switch (param.asType().getKind()) { 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; case DECLARED: TypeMirror type = param.asType(); TypeName typeName = ClassName.get(type); typeName = applyAnnotations(typeName, param); return typeName; case ARRAY: ArrayType arrayType = (ArrayType) param.asType(); TypeName arrayTypeName = ArrayTypeName.get(arrayType); arrayTypeName = applyAnnotations(arrayTypeName, param); return arrayTypeName; default: throw new IllegalStateException("unsupported kind: " + param.asType().getKind()); } }
Example 2
Source File: IntrospectorConstructorInvokerCreator.java From reflection-no-reflection with Apache License 2.0 | 5 votes |
public MethodSpec createConstructorInvoker(Class<?> aClass) { ParameterSpec parameterSpec1 = ParameterSpec.builder(STRING_TYPE_NAME, "signature").build(); TypeName objectVarArgsType = ArrayTypeName.get(Object[].class); ParameterSpec parameterSpec2 = ParameterSpec.builder(objectVarArgsType, "params").build(); String packageName = aClass.getName().substring(0, aClass.getName().lastIndexOf('.')); String className = aClass.getSimpleName(); MethodSpec.Builder newInstanceMethodBuilder = MethodSpec.methodBuilder("newInstance") .addModifiers(Modifier.PUBLIC) .addAnnotation(Override.class) .addParameter(parameterSpec1) .addParameter(parameterSpec2) .returns(ClassName.get(packageName, className)) .addException(InvocationTargetException.class) .varargs() .returns(OBJECT_TYPE_NAME) .addCode("switch(signature) {\n"); for (Object constructorObj : aClass.getConstructors()) { Constructor constructor = (Constructor) constructorObj; newInstanceMethodBuilder.addCode(" case($S) :\n", constructor.toString()); invokeConstructor(aClass, newInstanceMethodBuilder, constructor); } newInstanceMethodBuilder.addCode(" default :\n"); newInstanceMethodBuilder.addStatement("throw new InvocationTargetException(new java.lang.NoSuchMethodException(\"constructor:\" + signature + \" not found\"))"); newInstanceMethodBuilder.addCode("}\n"); return newInstanceMethodBuilder.build(); }
Example 3
Source File: IntrospectorMethodInvokerCreator.java From reflection-no-reflection with Apache License 2.0 | 5 votes |
public MethodSpec createMethodInvoker(Class<?> aClass) { ParameterSpec parameterSpec1 = ParameterSpec.builder(OBJECT_TYPE_NAME, "instance").build(); ParameterSpec parameterSpec2 = ParameterSpec.builder(STRING_TYPE_NAME, "methodName").build(); ParameterSpec parameterSpec3 = ParameterSpec.builder(STRING_TYPE_NAME, "signature").build(); TypeName objectVarArgsType = ArrayTypeName.get(Object[].class); ParameterSpec parameterSpec4 = ParameterSpec.builder(objectVarArgsType, "params").build(); MethodSpec.Builder invokeMethodBuilder = MethodSpec.methodBuilder("invokeMethod") .addModifiers(Modifier.PUBLIC) .addAnnotation(Override.class) .addParameter(parameterSpec1) .addParameter(parameterSpec2) .addParameter(parameterSpec3) .addParameter(parameterSpec4) .addException(InvocationTargetException.class) .varargs() .returns(OBJECT_TYPE_NAME) .addCode("switch(signature) {\n"); for (Object methodObj : aClass.getMethods()) { Method method = (Method) methodObj; invokeMethodBuilder.addCode(" case($S) :\n", method.toString()); invokeMethod(aClass, invokeMethodBuilder, method); } invokeMethodBuilder.addCode(" default :\n"); invokeMethodBuilder.addStatement("throw new InvocationTargetException(new java.lang.NoSuchMethodException(\"method:\" + signature + \" not found\"))"); invokeMethodBuilder.addCode("}\n"); return invokeMethodBuilder.build(); }
Example 4
Source File: ProcessUtils.java From RxAndroidOrm with Apache License 2.0 | 4 votes |
public static TypeName getArrayEnclosedType(Element element) { return ((ArrayTypeName) ArrayTypeName.get(element.asType())).componentType; }
Example 5
Source File: ProcessUtils.java From Freezer with Apache License 2.0 | 4 votes |
public static TypeName getArrayEnclosedType(Element element) { return ((ArrayTypeName) ArrayTypeName.get(element.asType())).componentType; }