use of javax.lang.model.element.ElementKind in project hibernate-orm by hibernate.
the class XmlMetaEntity method parseOneToOne.
private void parseOneToOne(OneToOne oneToOne) {
XmlMetaSingleAttribute attribute;
ElementKind elementKind = getElementKind(oneToOne.getAccess());
String type = getType(oneToOne.getName(), oneToOne.getTargetEntity(), elementKind);
if (type != null) {
attribute = new XmlMetaSingleAttribute(this, oneToOne.getName(), type);
members.add(attribute);
}
}
use of javax.lang.model.element.ElementKind in project hibernate-orm by hibernate.
the class TypeUtils method getAccessTypeOfIdAnnotation.
private static AccessType getAccessTypeOfIdAnnotation(Element element) {
AccessType accessType = null;
final ElementKind kind = element.getKind();
if (kind == ElementKind.FIELD || kind == ElementKind.METHOD) {
accessType = kind == ElementKind.FIELD ? AccessType.FIELD : AccessType.PROPERTY;
}
return accessType;
}
use of javax.lang.model.element.ElementKind in project DeepLinkDispatch by airbnb.
the class DeepLinkProcessor method process.
@Override
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
Set<Element> customAnnotations = new HashSet<>();
for (Element annotation : annotations) {
if (annotation.getAnnotation(DEEP_LINK_SPEC_CLASS) != null) {
customAnnotations.add(annotation);
}
}
Map<Element, String[]> prefixes = new HashMap<>();
Set<Element> customAnnotatedElements = new HashSet<>();
for (Element customAnnotation : customAnnotations) {
ElementKind kind = customAnnotation.getKind();
if (kind != ElementKind.ANNOTATION_TYPE) {
error(customAnnotation, "Only annotation types can be annotated with @%s", DEEP_LINK_SPEC_CLASS.getSimpleName());
}
String[] prefix = customAnnotation.getAnnotation(DEEP_LINK_SPEC_CLASS).prefix();
if (Utils.hasEmptyOrNullString(prefix)) {
error(customAnnotation, "Prefix property cannot have null or empty strings");
}
if (prefix.length == 0) {
error(customAnnotation, "Prefix property cannot be empty");
}
prefixes.put(customAnnotation, prefix);
for (Element customAnnotatedElement : roundEnv.getElementsAnnotatedWith(MoreElements.asType(customAnnotation))) {
customAnnotatedElements.add(customAnnotatedElement);
}
}
Set<Element> elementsToProcess = new HashSet<>(customAnnotatedElements);
elementsToProcess.addAll(roundEnv.getElementsAnnotatedWith(DEEP_LINK_CLASS));
List<DeepLinkAnnotatedElement> deepLinkElements = new ArrayList<>();
for (Element element : elementsToProcess) {
ElementKind kind = element.getKind();
if (kind != ElementKind.METHOD && kind != ElementKind.CLASS) {
error(element, "Only classes and methods can be annotated with @%s", DEEP_LINK_CLASS.getSimpleName());
}
if (kind == ElementKind.METHOD) {
Set<Modifier> methodModifiers = element.getModifiers();
if (!methodModifiers.contains(Modifier.STATIC)) {
error(element, "Only static methods can be annotated with @%s", DEEP_LINK_CLASS.getSimpleName());
}
}
DeepLink deepLinkAnnotation = element.getAnnotation(DEEP_LINK_CLASS);
List<String> deepLinks = new ArrayList<>();
if (deepLinkAnnotation != null) {
deepLinks.addAll(Arrays.asList(deepLinkAnnotation.value()));
}
if (customAnnotatedElements.contains(element)) {
deepLinks.addAll(enumerateCustomDeepLinks(element, prefixes));
}
DeepLinkEntry.Type type = kind == ElementKind.CLASS ? DeepLinkEntry.Type.CLASS : DeepLinkEntry.Type.METHOD;
for (String deepLink : deepLinks) {
try {
deepLinkElements.add(new DeepLinkAnnotatedElement(deepLink, element, type));
} catch (MalformedURLException e) {
messager.printMessage(Diagnostic.Kind.ERROR, "Malformed Deep Link URL " + deepLink);
}
}
}
Set<? extends Element> deepLinkHandlerElements = roundEnv.getElementsAnnotatedWith(DeepLinkHandler.class);
for (Element deepLinkHandlerElement : deepLinkHandlerElements) {
Optional<AnnotationMirror> annotationMirror = getAnnotationMirror(deepLinkHandlerElement, DeepLinkHandler.class);
if (annotationMirror.isPresent()) {
Iterable<TypeMirror> klasses = getTypeValue(annotationMirror.get(), "value");
List<TypeElement> typeElements = FluentIterable.from(klasses).transform(new Function<TypeMirror, TypeElement>() {
@Override
public TypeElement apply(TypeMirror klass) {
return MoreTypes.asTypeElement(klass);
}
}).toList();
String packageName = processingEnv.getElementUtils().getPackageOf(deepLinkHandlerElement).getQualifiedName().toString();
try {
generateDeepLinkDelegate(packageName, typeElements);
} catch (IOException e) {
messager.printMessage(Diagnostic.Kind.ERROR, "Error creating file");
} catch (RuntimeException e) {
messager.printMessage(Diagnostic.Kind.ERROR, "Internal error during annotation processing: " + e.getClass().getSimpleName());
}
}
}
Set<? extends Element> deepLinkModuleElements = roundEnv.getElementsAnnotatedWith(DeepLinkModule.class);
for (Element deepLinkModuleElement : deepLinkModuleElements) {
String packageName = processingEnv.getElementUtils().getPackageOf(deepLinkModuleElement).getQualifiedName().toString();
try {
generateDeepLinkLoader(packageName, deepLinkModuleElement.getSimpleName().toString(), deepLinkElements);
} catch (IOException e) {
messager.printMessage(Diagnostic.Kind.ERROR, "Error creating file");
} catch (RuntimeException e) {
messager.printMessage(Diagnostic.Kind.ERROR, "Internal error during annotation processing: " + e.getClass().getSimpleName());
}
}
return false;
}
use of javax.lang.model.element.ElementKind in project spring-framework by spring-projects.
the class StandardStereotypesProvider method getStereotypes.
@Override
public Set<String> getStereotypes(Element element) {
Set<String> stereotypes = new LinkedHashSet<>();
ElementKind kind = element.getKind();
if (kind != ElementKind.CLASS && kind != ElementKind.INTERFACE) {
return stereotypes;
}
for (AnnotationMirror annotation : this.typeHelper.getAllAnnotationMirrors(element)) {
String type = this.typeHelper.getType(annotation);
if (type.startsWith("javax.")) {
stereotypes.add(type);
}
}
return stereotypes;
}
use of javax.lang.model.element.ElementKind in project checker-framework by typetools.
the class InitializationAnnotatedTypeFactory method getFreeOrRawAnnotationOfSuperType.
/**
* Returns a {@link UnderInitialization} annotation (or {@link UnknownInitialization} if rawness
* is used) that has the supertype of {@code type} as type frame.
*/
protected AnnotationMirror getFreeOrRawAnnotationOfSuperType(TypeMirror type) {
// Find supertype if possible.
AnnotationMirror annotation;
List<? extends TypeMirror> superTypes = types.directSupertypes(type);
TypeMirror superClass = null;
for (TypeMirror superType : superTypes) {
ElementKind kind = types.asElement(superType).getKind();
if (kind == ElementKind.CLASS) {
superClass = superType;
break;
}
}
// Create annotation.
if (superClass != null) {
if (useFbc) {
annotation = createFreeAnnotation(superClass);
} else {
annotation = createUnclassifiedAnnotation(superClass);
}
} else {
// Use Object as a valid super-class
if (useFbc) {
annotation = createFreeAnnotation(Object.class);
} else {
annotation = createUnclassifiedAnnotation(Object.class);
}
}
return annotation;
}
Aggregations