use of com.squareup.javapoet.ClassName in project requery by requery.
the class ModelGenerator method generate.
@Override
public void generate() throws IOException {
ClassName typeName = ClassName.get(packageName, "Models");
TypeSpec.Builder type = TypeSpec.classBuilder(typeName).addModifiers(Modifier.PUBLIC).addMethod(MethodSpec.constructorBuilder().addModifiers(Modifier.PRIVATE).build());
CodeGeneration.addGeneratedAnnotation(processingEnvironment, type);
Map<String, Set<EntityDescriptor>> models = new HashMap<>();
entities.forEach(entity -> models.computeIfAbsent(entity.modelName(), key -> new HashSet<>()).add(entity));
for (String model : models.keySet()) {
Set<EntityDescriptor> types = models.get(model);
FieldSpec.Builder field = FieldSpec.builder(ClassName.get(EntityModel.class), model.toUpperCase(), Modifier.PUBLIC, Modifier.STATIC, Modifier.FINAL);
CodeBlock.Builder fieldType = CodeBlock.builder();
fieldType.add("new $T($S)\n", ClassName.get(EntityModelBuilder.class), model);
types.forEach(e -> fieldType.add(".addType($T.$L)\n", ClassName.bestGuess(e.typeName().toString()), EntityGenerator.TYPE_NAME));
fieldType.add(".build()");
field.initializer("$L", fieldType.build());
type.addField(field.build());
}
CodeGeneration.writeType(processingEnvironment, typeName.packageName(), type.build());
}
use of com.squareup.javapoet.ClassName in project storio by pushtorefresh.
the class GetResolverGenerator method generateJavaFile.
@NotNull
public JavaFile generateJavaFile(@NotNull StorIOSQLiteTypeMeta storIOSQLiteTypeMeta) {
final ClassName storIOSQLiteTypeClassName = ClassName.get(storIOSQLiteTypeMeta.packageName, storIOSQLiteTypeMeta.simpleName);
final TypeSpec getResolver = TypeSpec.classBuilder(generateName(storIOSQLiteTypeMeta)).addJavadoc("Generated resolver for Get Operation.\n").addModifiers(PUBLIC).superclass(ParameterizedTypeName.get(ClassName.get("com.pushtorefresh.storio.sqlite.operations.get", "DefaultGetResolver"), storIOSQLiteTypeClassName)).addMethod(storIOSQLiteTypeMeta.needCreator ? createMapFromCursorWithCreatorMethodSpec(storIOSQLiteTypeMeta, storIOSQLiteTypeClassName) : createMapFromCursorMethodSpec(storIOSQLiteTypeMeta, storIOSQLiteTypeClassName)).build();
return JavaFile.builder(storIOSQLiteTypeMeta.packageName, getResolver).indent(INDENT).build();
}
use of com.squareup.javapoet.ClassName in project storio by pushtorefresh.
the class PutResolverGenerator method generateJavaFile.
@NotNull
public JavaFile generateJavaFile(@NotNull StorIOSQLiteTypeMeta storIOSQLiteTypeMeta) {
final ClassName storIOSQLiteTypeClassName = ClassName.get(storIOSQLiteTypeMeta.packageName, storIOSQLiteTypeMeta.simpleName);
final TypeSpec putResolver = TypeSpec.classBuilder(generateName(storIOSQLiteTypeMeta)).addJavadoc("Generated resolver for Put Operation.\n").addModifiers(PUBLIC).superclass(ParameterizedTypeName.get(ClassName.get("com.pushtorefresh.storio.sqlite.operations.put", "DefaultPutResolver"), storIOSQLiteTypeClassName)).addMethod(createMapToInsertQueryMethodSpec(storIOSQLiteTypeMeta, storIOSQLiteTypeClassName)).addMethod(createMapToUpdateQueryMethodSpec(storIOSQLiteTypeMeta, storIOSQLiteTypeClassName)).addMethod(createMapToContentValuesMethodSpec(storIOSQLiteTypeMeta, storIOSQLiteTypeClassName)).build();
return JavaFile.builder(storIOSQLiteTypeMeta.packageName, putResolver).indent(INDENT).build();
}
use of com.squareup.javapoet.ClassName in project butterknife by JakeWharton.
the class ButterKnifeProcessor method parseCompiledR.
private void parseCompiledR(String respectivePackageName, TypeElement rClass) {
for (Element element : rClass.getEnclosedElements()) {
String innerClassName = element.getSimpleName().toString();
if (SUPPORTED_TYPES.contains(innerClassName)) {
for (Element enclosedElement : element.getEnclosedElements()) {
if (enclosedElement instanceof VariableElement) {
VariableElement variableElement = (VariableElement) enclosedElement;
Object value = variableElement.getConstantValue();
if (value instanceof Integer) {
int id = (Integer) value;
ClassName rClassName = ClassName.get(elementUtils.getPackageOf(variableElement).toString(), "R", innerClassName);
String resourceName = variableElement.getSimpleName().toString();
QualifiedId qualifiedId = new QualifiedId(respectivePackageName, id);
symbols.put(qualifiedId, new Id(id, rClassName, resourceName));
}
}
}
}
}
}
use of com.squareup.javapoet.ClassName in project butterknife by JakeWharton.
the class BindingSet method newBuilder.
static Builder newBuilder(TypeElement enclosingElement) {
TypeMirror typeMirror = enclosingElement.asType();
boolean isView = isSubtypeOfType(typeMirror, VIEW_TYPE);
boolean isActivity = isSubtypeOfType(typeMirror, ACTIVITY_TYPE);
boolean isDialog = isSubtypeOfType(typeMirror, DIALOG_TYPE);
TypeName targetType = TypeName.get(typeMirror);
if (targetType instanceof ParameterizedTypeName) {
targetType = ((ParameterizedTypeName) targetType).rawType;
}
String packageName = getPackage(enclosingElement).getQualifiedName().toString();
String className = enclosingElement.getQualifiedName().toString().substring(packageName.length() + 1).replace('.', '$');
ClassName bindingClassName = ClassName.get(packageName, className + "_ViewBinding");
boolean isFinal = enclosingElement.getModifiers().contains(Modifier.FINAL);
return new Builder(targetType, bindingClassName, isFinal, isView, isActivity, isDialog);
}
Aggregations