use of javax.lang.model.element.VariableElement 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.VariableElement 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.VariableElement 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;
}
use of javax.lang.model.element.VariableElement 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.VariableElement in project androidannotations by androidannotations.
the class RestMethodHandler method addMethodParams.
protected SortedMap<String, JVar> addMethodParams(ExecutableElement executableElement, RestHolder restHolder, JMethod method) {
List<? extends VariableElement> params = executableElement.getParameters();
SortedMap<String, JVar> methodParams = new TreeMap<>();
for (VariableElement parameter : params) {
String paramName = parameter.getSimpleName().toString();
String paramType = parameter.asType().toString();
JVar param;
if (parameter.asType().getKind().isPrimitive()) {
param = method.param(getCodeModel().parseType(paramType), paramName);
} else {
AbstractJClass parameterClass = codeModelHelper.typeMirrorToJClass(parameter.asType());
param = method.param(parameterClass, paramName);
}
methodParams.put(paramName, param);
}
return methodParams;
}
Aggregations