use of javax.lang.model.element.ElementKind in project hibernate-orm by hibernate.
the class XmlMetaEntity method parseAttributes.
private void parseAttributes(Attributes attributes) {
XmlMetaSingleAttribute attribute;
for (Id id : attributes.getId()) {
ElementKind elementKind = getElementKind(id.getAccess());
String type = getType(id.getName(), null, elementKind);
if (type != null) {
attribute = new XmlMetaSingleAttribute(this, id.getName(), type);
members.add(attribute);
}
}
if (attributes.getEmbeddedId() != null) {
EmbeddedId embeddedId = attributes.getEmbeddedId();
ElementKind elementKind = getElementKind(embeddedId.getAccess());
String type = getType(embeddedId.getName(), null, elementKind);
if (type != null) {
attribute = new XmlMetaSingleAttribute(this, embeddedId.getName(), type);
members.add(attribute);
}
}
for (Basic basic : attributes.getBasic()) {
parseBasic(basic);
}
for (ManyToOne manyToOne : attributes.getManyToOne()) {
parseManyToOne(manyToOne);
}
for (OneToOne oneToOne : attributes.getOneToOne()) {
parseOneToOne(oneToOne);
}
for (ManyToMany manyToMany : attributes.getManyToMany()) {
if (parseManyToMany(manyToMany)) {
break;
}
}
for (OneToMany oneToMany : attributes.getOneToMany()) {
if (parseOneToMany(oneToMany)) {
break;
}
}
for (ElementCollection collection : attributes.getElementCollection()) {
if (parseElementCollection(collection)) {
break;
}
}
for (Embedded embedded : attributes.getEmbedded()) {
parseEmbedded(embedded);
}
}
use of javax.lang.model.element.ElementKind in project hibernate-orm by hibernate.
the class XmlMetaEntity method parseOneToMany.
private boolean parseOneToMany(OneToMany oneToMany) {
String[] types;
XmlMetaCollection metaCollection;
ElementKind elementKind = getElementKind(oneToMany.getAccess());
String explicitTargetClass = determineExplicitTargetEntity(oneToMany.getTargetEntity());
String explicitMapKey = determineExplicitMapKeyClass(oneToMany.getMapKeyClass());
try {
types = getCollectionTypes(oneToMany.getName(), explicitTargetClass, explicitMapKey, elementKind);
} catch (MetaModelGenerationException e) {
logMetaModelException(oneToMany.getName(), e);
return true;
}
if (types != null) {
if (types[2] == null) {
metaCollection = new XmlMetaCollection(this, oneToMany.getName(), types[0], types[1]);
} else {
metaCollection = new XmlMetaMap(this, oneToMany.getName(), types[0], types[1], types[2]);
}
members.add(metaCollection);
}
return false;
}
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;
}
Aggregations