use of javax.lang.model.element.AnnotationMirror in project immutables by immutables.
the class TypeStringProvider method typeAnnotationsToBuffer.
private StringBuilder typeAnnotationsToBuffer(List<? extends AnnotationMirror> annotations) {
StringBuilder annotationBuffer = new StringBuilder(100);
for (AnnotationMirror annotationMirror : annotations) {
CharSequence sequence = AnnotationMirrors.toCharSequence(annotationMirror, importsResolver);
if (!nullableTypeAnnotation && sequence.toString().endsWith(EPHEMERAL_ANNOTATION_NULLABLE)) {
this.nullableTypeAnnotation = true;
}
annotationBuffer.append(sequence).append(' ');
}
return annotationBuffer;
}
use of javax.lang.model.element.AnnotationMirror in project hibernate-orm by hibernate.
the class TypeUtils method determineAnnotationSpecifiedAccessType.
public static AccessType determineAnnotationSpecifiedAccessType(Element element) {
final AnnotationMirror accessAnnotationMirror = TypeUtils.getAnnotationMirror(element, Constants.ACCESS);
AccessType forcedAccessType = null;
if (accessAnnotationMirror != null) {
Element accessElement = (Element) TypeUtils.getAnnotationValue(accessAnnotationMirror, DEFAULT_ANNOTATION_PARAMETER_NAME);
if (accessElement.getKind().equals(ElementKind.ENUM_CONSTANT)) {
if (accessElement.getSimpleName().toString().equals(AccessType.PROPERTY.toString())) {
forcedAccessType = AccessType.PROPERTY;
} else if (accessElement.getSimpleName().toString().equals(AccessType.FIELD.toString())) {
forcedAccessType = AccessType.FIELD;
}
}
}
return forcedAccessType;
}
use of javax.lang.model.element.AnnotationMirror in project hibernate-orm by hibernate.
the class TypeUtils method containsAnnotation.
public static boolean containsAnnotation(Element element, String... annotations) {
assert element != null;
assert annotations != null;
List<String> annotationClassNames = new ArrayList<String>();
Collections.addAll(annotationClassNames, annotations);
List<? extends AnnotationMirror> annotationMirrors = element.getAnnotationMirrors();
for (AnnotationMirror mirror : annotationMirrors) {
if (annotationClassNames.contains(mirror.getAnnotationType().toString())) {
return true;
}
}
return false;
}
use of javax.lang.model.element.AnnotationMirror in project hibernate-orm by hibernate.
the class JPAMetaModelEntityProcessor method handleRootElementAnnotationMirrors.
private void handleRootElementAnnotationMirrors(final Element element) {
List<? extends AnnotationMirror> annotationMirrors = element.getAnnotationMirrors();
for (AnnotationMirror mirror : annotationMirrors) {
if (!ElementKind.CLASS.equals(element.getKind())) {
continue;
}
String fqn = ((TypeElement) element).getQualifiedName().toString();
MetaEntity alreadyExistingMetaEntity = tryGettingExistingEntityFromContext(mirror, fqn);
if (alreadyExistingMetaEntity != null && alreadyExistingMetaEntity.isMetaComplete()) {
String msg = "Skipping processing of annotations for " + fqn + " since xml configuration is metadata complete.";
context.logMessage(Diagnostic.Kind.OTHER, msg);
continue;
}
boolean requiresLazyMemberInitialization = false;
AnnotationMetaEntity metaEntity;
if (TypeUtils.containsAnnotation(element, Constants.EMBEDDABLE) || TypeUtils.containsAnnotation(element, Constants.MAPPED_SUPERCLASS)) {
requiresLazyMemberInitialization = true;
}
metaEntity = new AnnotationMetaEntity((TypeElement) element, context, requiresLazyMemberInitialization);
if (alreadyExistingMetaEntity != null) {
metaEntity.mergeInMembers(alreadyExistingMetaEntity);
}
addMetaEntityToContext(mirror, metaEntity);
}
}
use of javax.lang.model.element.AnnotationMirror in project requery by requery.
the class AttributeMember method processAssociativeAnnotations.
private void processAssociativeAnnotations(ProcessingEnvironment processingEnvironment, ElementValidator validator) {
Optional<Annotation> oneToOne = annotationOf(OneToOne.class);
Optional<Annotation> oneToMany = annotationOf(OneToMany.class);
Optional<Annotation> manyToOne = annotationOf(ManyToOne.class);
Optional<Annotation> manyToMany = annotationOf(ManyToMany.class);
oneToOne = oneToOne.isPresent() ? oneToOne : annotationOf(javax.persistence.OneToOne.class);
oneToMany = oneToMany.isPresent() ? oneToMany : annotationOf(javax.persistence.OneToMany.class);
manyToOne = manyToOne.isPresent() ? manyToOne : annotationOf(javax.persistence.ManyToOne.class);
manyToMany = manyToMany.isPresent() ? manyToMany : annotationOf(javax.persistence.ManyToMany.class);
if (Stream.of(oneToOne, oneToMany, manyToOne, manyToMany).filter(Optional::isPresent).count() > 1) {
validator.error("Cannot have more than one associative annotation per field");
}
if (oneToOne.isPresent()) {
cardinality = Cardinality.ONE_TO_ONE;
ReflectiveAssociation reflect = new ReflectiveAssociation(oneToOne.get());
mappedBy = reflect.mappedBy();
cascadeActions = reflect.cascade();
if (!isForeignKey()) {
isReadOnly = true;
if (!isKey()) {
isUnique = true;
}
}
}
if (oneToMany.isPresent()) {
isIterable = true;
cardinality = Cardinality.ONE_TO_MANY;
isReadOnly = true;
ReflectiveAssociation reflect = new ReflectiveAssociation(oneToMany.get());
mappedBy = reflect.mappedBy();
cascadeActions = reflect.cascade();
checkIterable(validator);
processOrderBy();
}
if (manyToOne.isPresent()) {
cardinality = Cardinality.MANY_TO_ONE;
isForeignKey = true;
ReflectiveAssociation reflect = new ReflectiveAssociation(manyToOne.get());
cascadeActions = reflect.cascade();
if (deleteAction == null) {
deleteAction = ReferentialAction.CASCADE;
}
if (updateAction == null) {
updateAction = ReferentialAction.CASCADE;
}
}
if (manyToMany.isPresent()) {
isIterable = true;
cardinality = Cardinality.MANY_TO_MANY;
ReflectiveAssociation reflect = new ReflectiveAssociation(manyToMany.get());
mappedBy = reflect.mappedBy();
cascadeActions = reflect.cascade();
Optional<JunctionTable> junctionTable = annotationOf(JunctionTable.class);
Optional<javax.persistence.JoinTable> joinTable = annotationOf(javax.persistence.JoinTable.class);
if (junctionTable.isPresent()) {
Elements elements = processingEnvironment.getElementUtils();
associativeDescriptor = new JunctionTableAssociation(elements, this, junctionTable.get());
} else if (joinTable.isPresent()) {
associativeDescriptor = new JoinTableAssociation(joinTable.get());
}
isReadOnly = true;
checkIterable(validator);
processOrderBy();
}
if (isForeignKey()) {
if (deleteAction == ReferentialAction.SET_NULL && !isNullable()) {
validator.error("Cannot SET_NULL on optional attribute", ForeignKey.class);
}
// user mirror so generated type can be referenced
Optional<? extends AnnotationMirror> mirror = Mirrors.findAnnotationMirror(element(), ForeignKey.class);
if (mirror.isPresent()) {
referencedType = mirror.flatMap(m -> Mirrors.findAnnotationValue(m, "references")).map(value -> value.getValue().toString()).orElse(null);
} else if (!typeMirror().getKind().isPrimitive()) {
referencedType = typeMirror().toString();
}
}
}
Aggregations