use of javax.lang.model.element.Element in project androidannotations by androidannotations.
the class ValidatorHelper method typeOrTargetValueHasAnnotation.
public void typeOrTargetValueHasAnnotation(Class<? extends Annotation> annotation, Element element, ElementValidation valid) {
Element targetElement = findTargetElement(element, valid);
if (targetElement == null) {
return;
}
DeclaredType targetAnnotationClassValue = annotationHelper.extractAnnotationClassParameter(element);
if (targetAnnotationClassValue != null) {
typeHasAnnotation(annotation, targetAnnotationClassValue, valid);
if (!annotationHelper.getTypeUtils().isAssignable(targetAnnotationClassValue, targetElement.asType())) {
valid.addError("The value of %s must be assignable into the annotated field");
}
} else {
typeHasAnnotation(annotation, targetElement, valid);
}
}
use of javax.lang.model.element.Element 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.Element in project androidannotations by androidannotations.
the class BaseGeneratedClassHolder method setGeneratedClass.
protected void setGeneratedClass() throws Exception {
String annotatedComponentQualifiedName = annotatedElement.getQualifiedName().toString();
annotatedClass = getCodeModel().directClass(annotatedElement.asType().toString());
if (annotatedElement.getNestingKind().isNested()) {
Element enclosingElement = annotatedElement.getEnclosingElement();
GeneratedClassHolder enclosingHolder = environment.getGeneratedClassHolder(enclosingElement);
String generatedBeanSimpleName = annotatedElement.getSimpleName().toString() + classSuffix();
int modifier = PUBLIC | STATIC;
if (environment.getOptionBooleanValue(OPTION_GENERATE_FINAL_CLASSES)) {
modifier |= FINAL;
}
generatedClass = enclosingHolder.getGeneratedClass()._class(modifier, generatedBeanSimpleName, EClassType.CLASS);
} else {
String generatedClassQualifiedName = annotatedComponentQualifiedName + classSuffix();
int modifier = PUBLIC;
if (environment.getOptionBooleanValue(OPTION_GENERATE_FINAL_CLASSES)) {
modifier |= FINAL;
}
generatedClass = getCodeModel()._class(modifier, generatedClassQualifiedName, EClassType.CLASS);
}
codeModelHelper.generify(generatedClass, annotatedElement);
setExtends();
codeModelHelper.copyNonAAAnnotations(generatedClass, annotatedElement.getAnnotationMirrors());
}
use of javax.lang.model.element.Element in project androidannotations by androidannotations.
the class RestServiceHandler method validate.
@Override
public void validate(Element element, ElementValidation validation) {
injectHelper.validate(RestService.class, element, validation);
if (!validation.isValid()) {
return;
}
validatorHelper.isNotPrivate(element, validation);
Element param = injectHelper.getParam(element);
validatorHelper.typeHasAnnotation(Rest.class, param, validation);
}
use of javax.lang.model.element.Element in project antlr4 by antlr.
the class CommentHasStringValueProcessor method process.
@Override
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
// Messager messager = processingEnv.getMessager();
// messager.printMessage(Diagnostic.Kind.NOTE, "PROCESS--------------------");
Set<? extends Element> annotatedElements = roundEnv.getElementsAnnotatedWith(CommentHasStringValue.class);
for (Element annotatedElement : annotatedElements) {
String docComment = utilities.getDocComment(annotatedElement);
JCTree.JCLiteral literal = treeMaker.Literal(docComment != null ? docComment : "");
JCTree elementTree = utilities.getTree(annotatedElement);
if (elementTree instanceof JCTree.JCVariableDecl) {
((JCTree.JCVariableDecl) elementTree).init = literal;
} else if (elementTree instanceof JCTree.JCMethodDecl) {
JCTree.JCStatement[] statements = new JCTree.JCStatement[1];
statements[0] = treeMaker.Return(literal);
JCTree.JCBlock body = treeMaker.Block(0, List.from(statements));
((JCTree.JCMethodDecl) elementTree).body = body;
}
}
return true;
}
Aggregations