use of javax.lang.model.element.ExecutableElement in project storio by pushtorefresh.
the class StorIOContentResolverProcessor method processAnnotatedExecutables.
/**
* Processes factory methods or constructors annotated with {@link StorIOContentResolverCreator}.
*
* @param roundEnvironment current processing environment
* @param annotatedClasses map of classes annotated with {@link StorIOContentResolverType}
*/
@Override
protected void processAnnotatedExecutables(@NotNull RoundEnvironment roundEnvironment, @NotNull Map<TypeElement, StorIOContentResolverTypeMeta> annotatedClasses) {
final Set<? extends Element> elementsAnnotatedWithStorIOContentResolverCreator = roundEnvironment.getElementsAnnotatedWith(StorIOContentResolverCreator.class);
for (final Element annotatedElement : elementsAnnotatedWithStorIOContentResolverCreator) {
final ExecutableElement annotatedExecutableElement = (ExecutableElement) annotatedElement;
validateAnnotatedExecutable(annotatedExecutableElement);
final StorIOContentResolverCreatorMeta storIOContentResolverCreatorMeta = new StorIOContentResolverCreatorMeta(annotatedExecutableElement.getEnclosingElement(), annotatedExecutableElement, annotatedExecutableElement.getAnnotation(StorIOContentResolverCreator.class));
final StorIOContentResolverTypeMeta storIOContentResolverTypeMeta = annotatedClasses.get(storIOContentResolverCreatorMeta.enclosingElement);
// If class already contains another creator -> throw exception.
if (storIOContentResolverTypeMeta.creator == null) {
storIOContentResolverTypeMeta.creator = annotatedExecutableElement;
} else {
throw new ProcessingException(annotatedExecutableElement, "Only one creator method or constructor is allowed: " + annotatedExecutableElement.getEnclosingElement().getSimpleName());
}
}
}
use of javax.lang.model.element.ExecutableElement in project androidannotations by androidannotations.
the class APTCodeModelHelper method getMethod.
private ExecutableElement getMethod(List<ExecutableElement> methods, String methodName, String returnType, String... parameterTypes) {
for (ExecutableElement method : methods) {
List<? extends VariableElement> parameters = method.getParameters();
// Get the method return type or "VOID" if none.
String methodReturnType = method.getReturnType().getKind() == TypeKind.VOID ? TypeKind.VOID.toString() : method.getReturnType().toString();
if (parameters.size() == parameterTypes.length && methodReturnType.equals(returnType)) {
if (methodName == null || method.getSimpleName().toString().equals(methodName)) {
// At this point, method name, return type and number of
// parameters are correct. Now we need to validate the
// parameter types.
boolean validMethod = true;
for (int i = 0; i < parameters.size(); i++) {
VariableElement param = parameters.get(i);
if (!param.asType().toString().equals(parameterTypes[i])) {
// Parameter type does not match, this is not the
// correct method.
validMethod = false;
break;
}
}
if (validMethod) {
return method;
}
}
}
}
return null;
}
use of javax.lang.model.element.ExecutableElement in project androidannotations by androidannotations.
the class InjectHelper method processMethod.
private void processMethod(Element element, T holder) {
ExecutableElement executableElement = (ExecutableElement) element;
VariableElement param = executableElement.getParameters().get(0);
String methodName = executableElement.getSimpleName().toString();
JBlock block = createBlock(holder, true);
AbstractJClass type = codeModelHelper.typeMirrorToJClass(param.asType());
JVar fieldRef = block.decl(type, param.getSimpleName().toString(), getDefault(param.asType()));
handler.assignValue(block, fieldRef, holder, element, param);
block.add(JExpr.invoke(methodName).arg(fieldRef));
}
use of javax.lang.model.element.ExecutableElement in project androidannotations by androidannotations.
the class InjectHelper method validate.
public void validate(Class<? extends Annotation> expectedAnnotation, Element element, ElementValidation valid) {
Element enclosingElement = element.getEnclosingElement();
if (element instanceof VariableElement && enclosingElement instanceof ExecutableElement) {
validatorHelper.param.annotatedWith(expectedAnnotation).multiple().validate((ExecutableElement) enclosingElement, valid);
validatorHelper.doesNotHaveAnyOfSupportedAnnotations(enclosingElement, valid);
handler.validateEnclosingElement(enclosingElement, valid);
} else if (element instanceof ExecutableElement) {
handler.validateEnclosingElement(element, valid);
validatorHelper.param.anyType().validate((ExecutableElement) element, valid);
List<? extends VariableElement> parameters = ((ExecutableElement) element).getParameters();
for (VariableElement param : parameters) {
validatorHelper.doesNotHaveAnyOfSupportedAnnotations(param, valid);
}
} else {
handler.validateEnclosingElement(element, valid);
}
}
use of javax.lang.model.element.ExecutableElement in project androidannotations by androidannotations.
the class APTCodeModelHelper method implementMethod.
public JMethod implementMethod(GeneratedClassHolder holder, List<ExecutableElement> methods, String methodName, String returnType, boolean finalParams, String... parameterTypes) {
// First get the ExecutableElement method object from the util function.
ExecutableElement method = getMethod(methods, methodName, returnType, parameterTypes);
JMethod jmethod = null;
if (method != null) {
// Get the return type or VOID if none.
AbstractJType jcReturnType = returnType.equals(TypeKind.VOID.toString()) ? environment.getCodeModel().VOID : environment.getJClass(returnType);
// Create the implementation and annotate it with the Override
// annotation.
jmethod = holder.getGeneratedClass().method(JMod.PUBLIC, jcReturnType, method.getSimpleName().toString());
jmethod.annotate(Override.class);
// Create the parameters.
int paramMods = finalParams ? JMod.FINAL : JMod.NONE;
for (int i = 0; i < method.getParameters().size(); i++) {
VariableElement param = method.getParameters().get(i);
jmethod.param(paramMods, environment.getJClass(parameterTypes[i]), param.getSimpleName().toString());
}
}
return jmethod;
}
Aggregations