use of javax.lang.model.element.TypeElement in project immutables by immutables.
the class Annotations method getAnnotationLines.
static List<CharSequence> getAnnotationLines(Element element, Set<String> includeAnnotations, boolean includeAllAnnotations, boolean includeJacksonAnnotations, ElementType elementType, Function<String, String> importsResolver) {
List<CharSequence> lines = Lists.newArrayList();
Set<String> seenAnnotations = new HashSet<>();
for (AnnotationMirror annotation : element.getAnnotationMirrors()) {
TypeElement annotationElement = (TypeElement) annotation.getAnnotationType().asElement();
if (annotationTypeMatches(element, annotationElement, includeAnnotations, includeAllAnnotations, includeJacksonAnnotations, seenAnnotations) && annotationMatchesTarget(annotationElement, elementType)) {
lines.add(AnnotationMirrors.toCharSequence(annotation, importsResolver));
}
}
return lines;
}
use of javax.lang.model.element.TypeElement in project immutables by immutables.
the class Annotations method annotationTypeMatches.
private static boolean annotationTypeMatches(Element element, TypeElement annotationElement, Set<String> includeAnnotations, boolean includeAllAnnotations, boolean includeJacksonAnnotations, Set<String> seenAnnotations) {
String qualifiedName = annotationElement.getQualifiedName().toString();
if (seenAnnotations.contains(qualifiedName) || qualifiedName.startsWith(PREFIX_IMMUTABLES) || qualifiedName.startsWith(PREFIX_JAVA_LANG)) {
// also skip any we've already seen, since we're recursing.
return false;
}
seenAnnotations.add(qualifiedName);
if (annotationElement.getSimpleName().contentEquals(NULLABLE_SIMPLE_NAME)) {
// we expect to propagate nullability separately
return false;
}
if (includeAllAnnotations) {
return true;
}
if (qualifiedName.equals(PREFIX_JACKSON_IGNORE_PROPERTIES)) {
// but preferred way is to use additionalJsonAnnotations style attribute.
return true;
}
if (includeJacksonAnnotations) {
if (element.getKind() != ElementKind.METHOD) {
if (qualifiedName.equals(Proto.JACKSON_DESERIALIZE) || qualifiedName.equals(Proto.JACKSON_SERIALIZE)) {
return false;
}
}
if (qualifiedName.startsWith(PREFIX_JACKSON) || qualifiedName.startsWith(PREFIX_JACKSON_DATABIND)) {
return true;
}
}
if (includeAnnotations.contains(qualifiedName)) {
return true;
}
// This block of code can include annotation if it's parent annotation is included
if (includeJacksonAnnotations || !includeAnnotations.isEmpty()) {
for (AnnotationMirror parentAnnotation : annotationElement.getAnnotationMirrors()) {
TypeElement parentElement = (TypeElement) parentAnnotation.getAnnotationType().asElement();
if (annotationTypeMatches(element, parentElement, includeAnnotations, false, includeJacksonAnnotations, seenAnnotations)) {
return true;
}
}
}
return false;
}
use of javax.lang.model.element.TypeElement in project hibernate-orm by hibernate.
the class TypeUtils method getDefaultAccessForHierarchy.
private static AccessType getDefaultAccessForHierarchy(TypeElement element, Context context) {
AccessType defaultAccessType = null;
TypeElement superClass = element;
do {
superClass = TypeUtils.getSuperclassTypeElement(superClass);
if (superClass != null) {
String fqcn = superClass.getQualifiedName().toString();
AccessTypeInformation accessTypeInfo = context.getAccessTypeInfo(fqcn);
if (accessTypeInfo != null && accessTypeInfo.getDefaultAccessType() != null) {
return accessTypeInfo.getDefaultAccessType();
}
if (TypeUtils.containsAnnotation(superClass, Constants.ENTITY, Constants.MAPPED_SUPERCLASS)) {
defaultAccessType = getAccessTypeInCaseElementIsRoot(superClass, context);
if (defaultAccessType != null) {
accessTypeInfo = new AccessTypeInformation(fqcn, null, defaultAccessType);
context.addAccessTypeInformation(fqcn, accessTypeInfo);
// we found an id within the class hierarchy and determined a default access type
// there cannot be any super entity classes (otherwise it would be a configuration error)
// but there might be mapped super classes
// Also note, that if two different class hierarchies with different access types have a common
// mapped super class, the access type of the mapped super class will be the one of the last
// hierarchy processed. The result is not determined which is odd with the spec
setDefaultAccessTypeForMappedSuperclassesInHierarchy(superClass, defaultAccessType, context);
// we found a default access type, no need to look further
break;
} else {
defaultAccessType = getDefaultAccessForHierarchy(superClass, context);
}
}
}
} while (superClass != null);
return defaultAccessType;
}
use of javax.lang.model.element.TypeElement in project hibernate-orm by hibernate.
the class TypeUtils method setDefaultAccessTypeForMappedSuperclassesInHierarchy.
private static void setDefaultAccessTypeForMappedSuperclassesInHierarchy(TypeElement element, AccessType defaultAccessType, Context context) {
TypeElement superClass = element;
do {
superClass = TypeUtils.getSuperclassTypeElement(superClass);
if (superClass != null) {
String fqcn = superClass.getQualifiedName().toString();
if (TypeUtils.containsAnnotation(superClass, Constants.MAPPED_SUPERCLASS)) {
AccessTypeInformation accessTypeInfo;
AccessType forcedAccessType = determineAnnotationSpecifiedAccessType(superClass);
if (forcedAccessType != null) {
accessTypeInfo = new AccessTypeInformation(fqcn, null, forcedAccessType);
} else {
accessTypeInfo = new AccessTypeInformation(fqcn, null, defaultAccessType);
}
context.addAccessTypeInformation(fqcn, accessTypeInfo);
}
}
} while (superClass != null);
}
use of javax.lang.model.element.TypeElement in project hibernate-orm by hibernate.
the class JPAMetaModelEntityProcessor method process.
@Override
public boolean process(final Set<? extends TypeElement> annotations, final RoundEnvironment roundEnvironment) {
// see also METAGEN-45
if (roundEnvironment.processingOver() || annotations.size() == 0) {
return ALLOW_OTHER_PROCESSORS_TO_CLAIM_ANNOTATIONS;
}
if (context.isFullyXmlConfigured()) {
context.logMessage(Diagnostic.Kind.OTHER, "Skipping the processing of annotations since persistence unit is purely xml configured.");
return ALLOW_OTHER_PROCESSORS_TO_CLAIM_ANNOTATIONS;
}
Set<? extends Element> elements = roundEnvironment.getRootElements();
for (Element element : elements) {
if (isJPAEntity(element)) {
context.logMessage(Diagnostic.Kind.OTHER, "Processing annotated class " + element.toString());
handleRootElementAnnotationMirrors(element);
}
}
createMetaModelClasses();
return ALLOW_OTHER_PROCESSORS_TO_CLAIM_ANNOTATIONS;
}
Aggregations