use of javax.lang.model.element.TypeParameterElement in project androidannotations by androidannotations.
the class APTCodeModelHelper method overrideAnnotatedMethod.
public JMethod overrideAnnotatedMethod(ExecutableElement executableElement, GeneratedClassHolder holder) {
TypeMirror annotatedClass = holder.getAnnotatedElement().asType();
DeclaredType baseClass = (DeclaredType) executableElement.getEnclosingElement().asType();
Types typeUtils = environment.getProcessingEnvironment().getTypeUtils();
Map<String, TypeMirror> actualTypes = getActualTypes(typeUtils, baseClass, annotatedClass);
Map<String, List<AbstractJClass>> methodTypes = new LinkedHashMap<>();
for (TypeParameterElement typeParameter : executableElement.getTypeParameters()) {
List<? extends TypeMirror> bounds = typeParameter.getBounds();
List<AbstractJClass> addedBounds = typeBoundsToJClass(bounds, actualTypes);
methodTypes.put(typeParameter.toString(), addedBounds);
}
actualTypes.keySet().removeAll(methodTypes.keySet());
JMethod existingMethod = findAlreadyGeneratedMethod(executableElement, holder);
if (existingMethod != null) {
return existingMethod;
}
String methodName = executableElement.getSimpleName().toString();
AbstractJClass returnType = typeMirrorToJClass(executableElement.getReturnType(), actualTypes);
int modifier = elementVisibilityModifierToJMod(executableElement);
JMethod method = holder.getGeneratedClass().method(modifier, returnType, methodName);
copyNonAAAnnotations(method, executableElement.getAnnotationMirrors());
if (!hasAnnotation(method, Override.class)) {
method.annotate(Override.class);
}
for (Map.Entry<String, List<AbstractJClass>> typeDeclaration : methodTypes.entrySet()) {
List<AbstractJClass> bounds = typeDeclaration.getValue();
addTypeBounds(method, bounds, typeDeclaration.getKey());
}
int i = 0;
for (VariableElement parameter : executableElement.getParameters()) {
boolean varParam = i == executableElement.getParameters().size() - 1 && executableElement.isVarArgs();
addParamToMethod(method, parameter, JMod.FINAL, actualTypes, varParam);
i++;
}
for (TypeMirror superThrownType : executableElement.getThrownTypes()) {
AbstractJClass thrownType = typeMirrorToJClass(superThrownType, actualTypes);
method._throws(thrownType);
}
callSuperMethod(method, holder, method.body());
return method;
}
Aggregations