use of com.squareup.javapoet.TypeSpec in project RxBus by ViTess.
the class ProxyBuilder method createFunc1.
/**
* just add the filter which about param
*
* @return
*/
private TypeSpec createFunc1(List<TypeMirror> paramTypes) {
MethodSpec.Builder methodBuilder = MethodSpec.methodBuilder("call").addAnnotation(Override.class).addModifiers(Modifier.PUBLIC).addParameter(Object.class, "o").returns(Boolean.class);
methodBuilder.addStatement("return true");
TypeSpec func1 = TypeSpec.anonymousClassBuilder("").addSuperinterface(ParameterizedTypeName.get(FILTER_FUNC, TypeName.get(Object.class), TypeName.get(Boolean.class))).addMethod(methodBuilder.build()).build();
return func1;
}
use of com.squareup.javapoet.TypeSpec in project RxBus by ViTess.
the class ProxyBuilder method createProxyAction.
private TypeSpec createProxyAction(MethodBinder binder) {
MethodSpec.Builder methodBuilder = MethodSpec.methodBuilder("toDo").addAnnotation(Override.class).addModifiers(Modifier.PUBLIC).addParameter(mTargetClassName, "target");
// if (binder.getParamTypes().size() > 0) {
// TypeName typeName;
// TypeMirror paramType = binder.getParamTypes().get(0);
// if (paramType.getKind().isPrimitive()) {
// typeName = TypeName.get(paramType);
// if (!typeName.isBoxedPrimitive())
// typeName = typeName.box();
// } else if (paramType.getKind().equals(TypeKind.ARRAY))
// typeName = TypeName.get(paramType);
// else
// typeName = ClassName.get((TypeElement) Util.TypeUtils.asElement(paramType));
// methodBuilder.addStatement("target." + binder.getMethodName() + "($T.class.cast(o))", typeName);
// } else
// methodBuilder.addStatement("target." + binder.getMethodName() + "()");
TypeMirror paramType = binder.getParamType();
TypeName typeName;
if (paramType == null) {
typeName = DEFAULT_OBJECT;
methodBuilder.addStatement("target." + binder.getMethodName() + "()");
} else {
if (paramType.getKind().isPrimitive()) {
typeName = TypeName.get(paramType);
if (!typeName.isBoxedPrimitive())
typeName = typeName.box();
} else
typeName = ClassName.get(paramType);
methodBuilder.addStatement("target." + binder.getMethodName() + "(o)");
}
methodBuilder.addParameter(typeName, "o");
TypeSpec proxyAction = TypeSpec.anonymousClassBuilder("").addSuperinterface(ParameterizedTypeName.get(PROXY_ACTION, mTargetClassName, typeName)).addMethod(methodBuilder.build()).build();
return proxyAction;
}
use of com.squareup.javapoet.TypeSpec in project bazel by bazelbuild.
the class JavaCodeGeneratorHelper method targetWithNextHelper.
/**
* Writes a class file {@code Deps(index).java} to the directory
* {@code projectPath/com/example/deps(index)}
*
* @param callNext if we should call the method from {@code Deps(index+1).java}
*/
static void targetWithNextHelper(int index, boolean callNext, Path projectPath) throws IOException {
ClassName nextClass = ClassName.get("com.example.deps" + (index + 1), "Deps" + (index + 1));
MethodSpec callNextMethod = MethodSpec.methodBuilder("CallNext").addModifiers(Modifier.PUBLIC, Modifier.STATIC).returns(void.class).addStatement("$T.PrintSth()", nextClass).build();
TypeSpec.Builder klassBuilder = TypeSpec.classBuilder("Deps" + index).addModifiers(Modifier.PUBLIC, Modifier.FINAL).addMethod(randomMethod);
if (callNext) {
klassBuilder.addMethod(callNextMethod);
}
TypeSpec klass = klassBuilder.build();
writeClassToDir(klass, "com.example.deps" + index, projectPath);
}
use of com.squareup.javapoet.TypeSpec in project bazel by bazelbuild.
the class JavaCodeGeneratorHelper method writeRandomClassToDir.
static void writeRandomClassToDir(boolean addExtraMethod, String className, String packageName, Path projectPath) throws IOException {
TypeSpec klass = genRandomClass(addExtraMethod, className);
writeClassToDir(klass, packageName, projectPath);
}
use of com.squareup.javapoet.TypeSpec in project bazel by bazelbuild.
the class JavaCodeGeneratorHelper method targetWithNextExtraHelper.
/**
* Writes a class file {@code Deps(index).java} with extra method {@code printSthElse()}
* to the directory {@code projectPath/com/example/deps(index)}
*
* @param callNext if we should call the method from {@code Deps(index+1).java}
*/
static void targetWithNextExtraHelper(int index, boolean callNext, Path projectPath) throws IOException {
ClassName nextClass = ClassName.get("com.example.deps" + (index + 1), "Deps" + (index + 1));
MethodSpec callNextMethod = MethodSpec.methodBuilder("CallNext").addModifiers(Modifier.PUBLIC, Modifier.STATIC).returns(void.class).addStatement("$T.PrintSth()", nextClass).build();
TypeSpec.Builder klassBuilder = TypeSpec.classBuilder("Deps" + index).addModifiers(Modifier.PUBLIC, Modifier.FINAL).addMethod(randomMethod).addMethod(somethingElseMethod);
if (callNext) {
klassBuilder.addMethod(callNextMethod);
}
TypeSpec klass = klassBuilder.build();
writeClassToDir(klass, "com.example.deps" + index, projectPath);
}
Aggregations