use of javax.lang.model.element.ExecutableElement in project androidannotations by androidannotations.
the class ValidatorHelper method findTargetElement.
Element findTargetElement(Element element, ElementValidation valid) {
if (element instanceof ExecutableElement) {
ExecutableElement executableElement = (ExecutableElement) element;
returnTypeIsVoid(executableElement, valid);
if (!valid.isValid()) {
return null;
}
List<? extends VariableElement> parameters = executableElement.getParameters();
if (parameters.size() != 1) {
valid.addError("The method can only have 1 parameter");
return null;
}
return parameters.get(0);
}
return element;
}
use of javax.lang.model.element.ExecutableElement in project androidannotations by androidannotations.
the class ValidatorHelper method allowedType.
public void allowedType(Element element, List<String> allowedTypes, ElementValidation valid) {
String qualifiedName;
Element enclosingElement = element.getEnclosingElement();
if (element instanceof VariableElement && enclosingElement instanceof ExecutableElement) {
qualifiedName = element.asType().toString();
} else if (element instanceof ExecutableElement) {
element = ((ExecutableElement) element).getParameters().get(0);
qualifiedName = element.asType().toString();
} else {
qualifiedName = element.asType().toString();
}
if (!allowedTypes.contains(qualifiedName)) {
valid.addError("%s can only be used on a field which is a " + allowedTypes.toString() + ", not " + qualifiedName);
}
}
use of javax.lang.model.element.ExecutableElement in project androidannotations by androidannotations.
the class EBeanHolder method setConstructor.
private void setConstructor() {
constructor = generatedClass.constructor(PRIVATE);
JVar constructorContextParam = constructor.param(getClasses().CONTEXT, "context");
JBlock constructorBody = constructor.body();
List<ExecutableElement> constructors = ElementFilter.constructorsIn(annotatedElement.getEnclosedElements());
ExecutableElement superConstructor = constructors.get(0);
if (superConstructor.getParameters().size() == 1) {
constructorBody.invoke("super").arg(constructorContextParam);
}
constructorBody.assign(getContextField(), constructorContextParam);
}
use of javax.lang.model.element.ExecutableElement in project androidannotations by androidannotations.
the class RestAnnotationHelper method getResponseClass.
public IJExpression getResponseClass(Element element, RestHolder holder) {
ExecutableElement executableElement = (ExecutableElement) element;
IJExpression responseClassExpr = nullCastedToNarrowedClass(holder);
TypeMirror returnType = executableElement.getReturnType();
if (returnType.getKind() != TypeKind.VOID) {
if (getElementUtils().getTypeElement(RestSpringClasses.PARAMETERIZED_TYPE_REFERENCE) != null) {
if (returnType.toString().startsWith(RestSpringClasses.RESPONSE_ENTITY)) {
List<? extends TypeMirror> typeArguments = ((DeclaredType) returnType).getTypeArguments();
if (!typeArguments.isEmpty()) {
returnType = typeArguments.get(0);
}
}
if (checkIfParameterizedTypeReferenceShouldBeUsed(returnType)) {
return createParameterizedTypeReferenceAnonymousSubclassInstance(returnType);
}
}
AbstractJClass responseClass = retrieveResponseClass(returnType, holder);
if (responseClass != null) {
responseClassExpr = responseClass.dotclass();
}
}
return responseClassExpr;
}
use of javax.lang.model.element.ExecutableElement in project androidannotations by androidannotations.
the class AbstractOttoHandler method process.
@Override
public void process(Element element, EComponentHolder holder) throws Exception {
if (!annotationHelper.enclosingElementHasEnhancedComponentAnnotation(element)) {
// do nothing when otto annotations are used in non-enhanced classes
return;
}
ExecutableElement executableElement = (ExecutableElement) element;
JMethod method = codeModelHelper.overrideAnnotatedMethod(executableElement, holder);
addOttoAnnotation(executableElement, method);
}
Aggregations