use of javax.lang.model.element.Element in project androidannotations by androidannotations.
the class IdValidatorHelper method uniqueResourceId.
public void uniqueResourceId(Element element, Res resourceType, ElementValidation valid) {
if (valid.isValid()) {
List<String> annotationQualifiedIds = idAnnotationHelper.extractAnnotationResources(element, resourceType, true);
Element elementEnclosingElement = element.getEnclosingElement();
Set<? extends Element> annotatedElements = validatedModel().getRootAnnotatedElements(annotationHelper.getTarget());
for (Element uniqueCheckElement : annotatedElements) {
Element uniqueCheckEnclosingElement = uniqueCheckElement.getEnclosingElement();
if (elementEnclosingElement.equals(uniqueCheckEnclosingElement)) {
List<String> checkQualifiedIds = idAnnotationHelper.extractAnnotationResources(uniqueCheckElement, resourceType, true);
for (String checkQualifiedId : checkQualifiedIds) {
for (String annotationQualifiedId : annotationQualifiedIds) {
if (annotationQualifiedId.equals(checkQualifiedId)) {
String annotationSimpleId = annotationQualifiedId.substring(annotationQualifiedId.lastIndexOf('.') + 1);
valid.addError("The resource id " + annotationSimpleId + " is already used on the following " + annotationHelper.annotationName() + " method: " + uniqueCheckElement);
return;
}
}
}
}
}
}
}
use of javax.lang.model.element.Element 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.Element in project androidannotations by androidannotations.
the class KeyCodeHelper method uniqueKeyCode.
public boolean uniqueKeyCode(Element element, String targetAnnotationClass) {
int[] elementsKeyCodes = extractKeyCode(element);
if (elementsKeyCodes.length == 0) {
return false;
}
Set<Integer> uniqueKeyCodes = new HashSet<>(elementsKeyCodes.length);
for (int keyCode : elementsKeyCodes) {
uniqueKeyCodes.add(keyCode);
}
Element enclosingElement = element.getEnclosingElement();
List<? extends Element> enclosedMethodElements = ElementFilter.methodsIn(enclosingElement.getEnclosedElements());
for (Element oneEnclosedElement : enclosedMethodElements) {
if (oneEnclosedElement != element) {
List<? extends AnnotationMirror> annotationMirrors = oneEnclosedElement.getAnnotationMirrors();
for (AnnotationMirror annotationMirror : annotationMirrors) {
if (annotationMirror.getAnnotationType().asElement().toString().equals(targetAnnotationClass)) {
int[] keyCodes = extractKeyCode(oneEnclosedElement);
for (int keyCode : keyCodes) {
if (uniqueKeyCodes.contains(keyCode)) {
return false;
} else {
uniqueKeyCodes.add(keyCode);
}
}
}
}
}
}
return true;
}
use of javax.lang.model.element.Element in project androidannotations by androidannotations.
the class ValidatorHelper method enclosingElementHasAnnotation.
public void enclosingElementHasAnnotation(Class<? extends Annotation> annotation, Element element, ElementValidation valid, String error) {
Element enclosingElement = element.getEnclosingElement();
elementHasAnnotation(annotation, enclosingElement, valid, error);
}
use of javax.lang.model.element.Element in project androidannotations by androidannotations.
the class ValidatorHelper method extendsMenuItem.
public void extendsMenuItem(Element element, ElementValidation valid) {
Element enclosingElement = element.getEnclosingElement();
String enclosingQualifiedName = enclosingElement.asType().toString();
TypeElement enclosingTypeElement = annotationHelper.typeElementFromQualifiedName(enclosingQualifiedName);
if (enclosingTypeElement != null) {
extendsType(element, CanonicalNameConstants.MENU_ITEM, valid);
}
}
Aggregations