use of javax.lang.model.element.AnnotationMirror in project androidannotations by androidannotations.
the class AnnotationHelper method extractAnnotationClassParameter.
public DeclaredType extractAnnotationClassParameter(Element element, String annotationName, String methodName) {
AnnotationMirror annotationMirror = findAnnotationMirror(element, annotationName);
Map<? extends ExecutableElement, ? extends AnnotationValue> elementValues = annotationMirror.getElementValues();
for (Map.Entry<? extends ExecutableElement, ? extends AnnotationValue> entry : elementValues.entrySet()) {
/*
* "methodName" is unset when the default value is used
*/
if (methodName.equals(entry.getKey().getSimpleName().toString())) {
AnnotationValue annotationValue = entry.getValue();
return (DeclaredType) annotationValue.getValue();
}
}
return null;
}
use of javax.lang.model.element.AnnotationMirror 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.AnnotationMirror in project androidannotations by androidannotations.
the class RestSpringValidatorHelper method urlVariableNameExistsInEnclosingAnnotation.
public void urlVariableNameExistsInEnclosingAnnotation(Element element, ElementValidation validation) {
Set<String> validRestMethodAnnotationNames = new HashSet<>();
for (Class<? extends Annotation> validAnnotation : REST_ANNOTATION_CLASSES) {
validRestMethodAnnotationNames.add(validAnnotation.getCanonicalName());
}
String url = null;
for (AnnotationMirror annotationMirror : element.getEnclosingElement().getAnnotationMirrors()) {
if (validRestMethodAnnotationNames.contains(annotationMirror.getAnnotationType().toString())) {
url = restAnnotationHelper.extractAnnotationParameter(element.getEnclosingElement(), annotationMirror.getAnnotationType().toString(), "value");
break;
}
}
Set<String> urlVariableNames = restAnnotationHelper.extractUrlVariableNames(url);
String expectedUrlVariableName = restAnnotationHelper.getUrlVariableCorrespondingTo((VariableElement) element);
if (!urlVariableNames.contains(expectedUrlVariableName)) {
validation.addError(element, "%s annotated parameter is has no corresponding url variable");
}
}
use of javax.lang.model.element.AnnotationMirror in project androidannotations by androidannotations.
the class RoboGuiceHandler method extractListenerTypeMirrors.
private List<TypeMirror> extractListenerTypeMirrors(Element activityElement) {
List<? extends AnnotationMirror> annotationMirrors = activityElement.getAnnotationMirrors();
String annotationName = RoboGuice.class.getName();
for (AnnotationMirror annotationMirror : annotationMirrors) {
if (annotationName.equals(annotationMirror.getAnnotationType().toString())) {
for (Map.Entry<? extends ExecutableElement, ? extends AnnotationValue> entry : annotationMirror.getElementValues().entrySet()) {
if ("value".equals(entry.getKey().getSimpleName().toString())) {
AnnotationValue action = entry.getValue();
@SuppressWarnings("unchecked") List<AnnotationValue> elements = (List<AnnotationValue>) action.getValue();
List<TypeMirror> listenerTypeMirrors = new ArrayList<>(elements.size());
for (AnnotationValue annotationValue : elements) {
listenerTypeMirrors.add((TypeMirror) annotationValue.getValue());
}
return listenerTypeMirrors;
}
}
}
}
return Collections.emptyList();
}
use of javax.lang.model.element.AnnotationMirror in project dagger by square.
the class GeneratorKeys method get.
/** Returns the provider key for {@code variable}. */
public static String get(VariableElement variable) {
StringBuilder result = new StringBuilder();
AnnotationMirror qualifier = getQualifier(variable.getAnnotationMirrors());
if (qualifier != null) {
qualifierToString(qualifier, result);
}
typeToString(variable.asType(), result, '$');
return result.toString();
}
Aggregations