use of com.squareup.javapoet.ClassName in project storio by pushtorefresh.
the class DeleteResolverGenerator method generateJavaFile.
@NotNull
public JavaFile generateJavaFile(@NotNull StorIOSQLiteTypeMeta storIOSQLiteTypeMeta) {
final ClassName storIOSQLiteTypeClassName = ClassName.get(storIOSQLiteTypeMeta.packageName, storIOSQLiteTypeMeta.simpleName);
final TypeSpec deleteResolver = TypeSpec.classBuilder(generateName(storIOSQLiteTypeMeta)).addJavadoc("Generated resolver for Delete Operation.\n").addModifiers(PUBLIC).superclass(ParameterizedTypeName.get(ClassName.get("com.pushtorefresh.storio.sqlite.operations.delete", "DefaultDeleteResolver"), storIOSQLiteTypeClassName)).addMethod(createMapToDeleteQueryMethodSpec(storIOSQLiteTypeMeta, storIOSQLiteTypeClassName)).build();
return JavaFile.builder(storIOSQLiteTypeMeta.packageName, deleteResolver).indent(INDENT).build();
}
use of com.squareup.javapoet.ClassName in project storio by pushtorefresh.
the class MappingGenerator method createConstructor.
@NotNull
private MethodSpec createConstructor(StorIOSQLiteTypeMeta storIOSQLiteTypeMeta) {
final ClassName putResolver = ClassName.get(storIOSQLiteTypeMeta.packageName, PutResolverGenerator.generateName(storIOSQLiteTypeMeta));
final ClassName getResolver = ClassName.get(storIOSQLiteTypeMeta.packageName, GetResolverGenerator.generateName(storIOSQLiteTypeMeta));
final ClassName deleteResolver = ClassName.get(storIOSQLiteTypeMeta.packageName, DeleteResolverGenerator.generateName(storIOSQLiteTypeMeta));
return MethodSpec.constructorBuilder().addModifiers(PUBLIC).addStatement("super(new $T(),\nnew $T(),\nnew $T())", putResolver, getResolver, deleteResolver).build();
}
use of com.squareup.javapoet.ClassName in project storio by pushtorefresh.
the class MappingGenerator method generateJavaFile.
@NotNull
@Override
public JavaFile generateJavaFile(@NotNull StorIOSQLiteTypeMeta storIOSQLiteTypeMeta) {
final ClassName storIOSQLiteTypeClassName = ClassName.get(storIOSQLiteTypeMeta.packageName, storIOSQLiteTypeMeta.simpleName);
ClassName superclass = ClassName.get("com.pushtorefresh.storio.sqlite", SUFFIX);
ParameterizedTypeName superclassParametrized = ParameterizedTypeName.get(superclass, storIOSQLiteTypeClassName);
final TypeSpec mapping = TypeSpec.classBuilder(storIOSQLiteTypeMeta.simpleName + SUFFIX).addJavadoc("Generated mapping with collection of resolvers.\n").addModifiers(PUBLIC).superclass(superclassParametrized).addMethod(createConstructor(storIOSQLiteTypeMeta)).build();
return JavaFile.builder(storIOSQLiteTypeMeta.packageName, mapping).indent(INDENT).build();
}
use of com.squareup.javapoet.ClassName in project tiger by google.
the class Utils method getSourceCodeName.
/**
* Returns "com_Foo" for com.Foo, "com_Foo_com_Bar_com_Baz" for Foo<Bar, Baz>.
* upper_bounds_UpperBound_Foo for "? extends Foo" and
* lower_bounds_LowerBound_Foo for "? super Foo". Assuming raw types are not
* used, there will be not conflicts.
*/
public static String getSourceCodeName(TypeName typeName) {
Preconditions.checkNotNull(typeName);
if (typeName.isPrimitive()) {
return typeName.toString();
} else if (typeName instanceof ClassName) {
return getClassCanonicalName((ClassName) typeName).replace(".", "_");
} else if (typeName instanceof ParameterizedTypeName) {
ParameterizedTypeName p = (ParameterizedTypeName) typeName;
StringBuilder builder = new StringBuilder(getSourceCodeName(p.rawType));
for (TypeName t : p.typeArguments) {
builder.append("_").append(getSourceCodeName(t));
}
return builder.toString();
} else if (typeName instanceof WildcardTypeName) {
WildcardTypeName w = (WildcardTypeName) typeName;
if (w.upperBounds.size() > 0) {
return "upper_bounds_" + getSourceCodeName(w.upperBounds.get(0));
} else {
Preconditions.checkState(w.lowerBounds.size() > 0);
return "lower_bounds_" + getSourceCodeName(w.lowerBounds.get(0));
}
} else if (typeName instanceof ArrayTypeName) {
ArrayTypeName arrayTypeName = (ArrayTypeName) typeName;
return "ArrayOf" + getSourceCodeName(arrayTypeName.componentType);
}
throw new RuntimeException("Unexpected type: " + typeName);
}
use of com.squareup.javapoet.ClassName in project tiger by google.
the class TigerDaggerGeneratorProcessor method generateComponentBuilder.
private void generateComponentBuilder(ClassName componentClassName, @Nullable TypeElement dependencyComponent, List<TypeElement> sortedPassedModules, TypeSpec.Builder componentBuilder, ComponentInfo coreInjector) {
TypeSpec.Builder builderBuilder = TypeSpec.classBuilder("Builder").addModifiers(Modifier.PUBLIC, Modifier.STATIC);
// set parent inject methods.
ClassName dependencyClassName = null;
if (dependencyComponent != null) {
dependencyClassName = (ClassName) ClassName.get(dependencyComponent.asType());
Utils.addSetMethod(componentClassName, builderBuilder, dependencyClassName);
}
/**
* Set module methods.
*/
for (TypeElement m : sortedPassedModules) {
Utils.addSetMethod(componentClassName, builderBuilder, (ClassName) ClassName.get(m.asType()));
}
// build() method.
MethodSpec.Builder buildMethodBuilder = MethodSpec.methodBuilder("build").addModifiers(Modifier.PUBLIC).returns(componentClassName);
StringBuilder returnCodeBuilder = new StringBuilder("return new $T(");
if (dependencyClassName != null) {
returnCodeBuilder.append(Utils.getSourceCodeName(dependencyComponent));
if (!sortedPassedModules.isEmpty()) {
returnCodeBuilder.append(", ");
}
}
if (!sortedPassedModules.isEmpty()) {
for (TypeElement module : sortedPassedModules) {
String moduleFiledName = Utils.getSourceCodeName(module);
returnCodeBuilder.append(moduleFiledName).append(", ");
}
returnCodeBuilder.delete(returnCodeBuilder.length() - 2, returnCodeBuilder.length());
}
returnCodeBuilder.append(");");
buildMethodBuilder.addCode(returnCodeBuilder.toString(), componentClassName);
builderBuilder.addMethod(buildMethodBuilder.build());
componentBuilder.addType(builderBuilder.build());
}
Aggregations