use of com.squareup.javapoet.ClassName in project epoxy by airbnb.
the class ResourceProcessor method parseCompiledR.
private void parseCompiledR(TypeElement rClass, Map<Integer, AndroidResource> symbols) {
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();
symbols.put(id, new AndroidResource(id, rClassName, resourceName));
}
}
}
}
}
}
use of com.squareup.javapoet.ClassName in project RxCache by VictorAlbertos.
the class GetProvidersClass method from.
ProvidersClass from(Element element) throws ValidationException {
if (!SuperficialValidation.validateElement(element))
return null;
if (element.getKind() != ElementKind.INTERFACE)
return null;
ClassName className = ClassName.get((TypeElement) element);
List<ProvidersClass.Method> methods = getMethods(element);
return new ProvidersClass(className, element, methods);
}
use of com.squareup.javapoet.ClassName in project storio by pushtorefresh.
the class GetResolverGenerator method generateJavaFile.
@NotNull
public JavaFile generateJavaFile(@NotNull final StorIOContentResolverTypeMeta storIOContentResolverTypeMeta) {
final ClassName storIOContentResolverTypeClassName = ClassName.get(storIOContentResolverTypeMeta.packageName, storIOContentResolverTypeMeta.simpleName);
final TypeSpec getResolver = TypeSpec.classBuilder(generateName(storIOContentResolverTypeMeta)).addJavadoc("Generated resolver for Get Operation\n").addModifiers(PUBLIC).superclass(ParameterizedTypeName.get(ClassName.get("com.pushtorefresh.storio.contentresolver.operations.get", "DefaultGetResolver"), storIOContentResolverTypeClassName)).addMethod(storIOContentResolverTypeMeta.needCreator ? createMapFromCursorWithCreatorMethodSpec(storIOContentResolverTypeMeta, storIOContentResolverTypeClassName) : createMapFromCursorMethodSpec(storIOContentResolverTypeMeta, storIOContentResolverTypeClassName)).build();
return JavaFile.builder(storIOContentResolverTypeMeta.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 final StorIOContentResolverTypeMeta storIOContentResolverTypeMeta) {
final ClassName storIOContentResolverTypeClassName = ClassName.get(storIOContentResolverTypeMeta.packageName, storIOContentResolverTypeMeta.simpleName);
final TypeSpec putResolver = TypeSpec.classBuilder(generateName(storIOContentResolverTypeMeta)).addJavadoc("Generated resolver for Put Operation\n").addModifiers(PUBLIC).superclass(ParameterizedTypeName.get(ClassName.get("com.pushtorefresh.storio.contentresolver.operations.put", "DefaultPutResolver"), storIOContentResolverTypeClassName)).addMethod(createMapToInsertQueryMethodSpec(storIOContentResolverTypeMeta, storIOContentResolverTypeClassName)).addMethod(createMapToUpdateQueryMethodSpec(storIOContentResolverTypeMeta, storIOContentResolverTypeClassName)).addMethod(createMapToContentValuesMethodSpec(storIOContentResolverTypeMeta, storIOContentResolverTypeClassName)).build();
return JavaFile.builder(storIOContentResolverTypeMeta.packageName, putResolver).indent(INDENT).build();
}
use of com.squareup.javapoet.ClassName in project requery by requery.
the class EntityGenerator method generateListeners.
private void generateListeners(MethodSpec.Builder constructor) {
for (Map.Entry<Element, ? extends ListenerDescriptor> entry : entity.listeners().entrySet()) {
for (Annotation annotation : entry.getValue().listenerAnnotations()) {
String annotationName = annotation.annotationType().getSimpleName().replace("Persist", "Insert").replace("Remove", "Delete");
String methodName = Names.lowerCaseFirst(annotationName);
// avoid hardcoding the package name here
Element listener = elements.getTypeElement(PreInsertListener.class.getCanonicalName());
PackageElement packageElement = elements.getPackageOf(listener);
// generate the listener name
String packageName = packageElement.getQualifiedName().toString();
ClassName listenerName = ClassName.get(packageName, annotationName + "Listener");
ParameterizedTypeName getterType = ParameterizedTypeName.get(listenerName, typeName);
TypeSpec.Builder listenerBuilder = TypeSpec.anonymousClassBuilder("").addSuperinterface(getterType).addMethod(CodeGeneration.overridePublicMethod(methodName).addParameter(typeName, "entity").addStatement("$L()", entry.getKey().getSimpleName()).build());
constructor.addStatement("$L.modifyListeners().add$L($L)", PROXY_NAME, annotationName + "Listener", listenerBuilder.build());
}
}
}
Aggregations