use of javax.lang.model.element.Element in project hibernate-orm by hibernate.
the class JPAMetaModelEntityProcessor method modelGenerationNeedsToBeDeferred.
private boolean modelGenerationNeedsToBeDeferred(Collection<MetaEntity> entities, MetaEntity containedEntity) {
ContainsAttributeTypeVisitor visitor = new ContainsAttributeTypeVisitor(containedEntity.getTypeElement(), context);
for (MetaEntity entity : entities) {
if (entity.equals(containedEntity)) {
continue;
}
for (Element subElement : ElementFilter.fieldsIn(entity.getTypeElement().getEnclosedElements())) {
TypeMirror mirror = subElement.asType();
if (!TypeKind.DECLARED.equals(mirror.getKind())) {
continue;
}
boolean contains = mirror.accept(visitor, subElement);
if (contains) {
return true;
}
}
for (Element subElement : ElementFilter.methodsIn(entity.getTypeElement().getEnclosedElements())) {
TypeMirror mirror = subElement.asType();
if (!TypeKind.DECLARED.equals(mirror.getKind())) {
continue;
}
boolean contains = mirror.accept(visitor, subElement);
if (contains) {
return true;
}
}
}
return false;
}
use of javax.lang.model.element.Element in project hibernate-orm by hibernate.
the class AnnotationMetaEntity method addPersistentMembers.
private void addPersistentMembers(List<? extends Element> membersOfClass, AccessType membersKind) {
for (Element memberOfClass : membersOfClass) {
AccessType forcedAccessType = TypeUtils.determineAnnotationSpecifiedAccessType(memberOfClass);
if (entityAccessTypeInfo.getAccessType() != membersKind && forcedAccessType == null) {
continue;
}
if (TypeUtils.containsAnnotation(memberOfClass, Constants.TRANSIENT) || memberOfClass.getModifiers().contains(Modifier.TRANSIENT) || memberOfClass.getModifiers().contains(Modifier.STATIC)) {
continue;
}
MetaAttributeGenerationVisitor visitor = new MetaAttributeGenerationVisitor(this, context);
AnnotationMetaAttribute result = memberOfClass.asType().accept(visitor, memberOfClass);
if (result != null) {
members.put(result.getPropertyName(), result);
}
}
}
use of javax.lang.model.element.Element in project hibernate-orm by hibernate.
the class XmlMetaEntity method getCollectionTypes.
private String[] getCollectionTypes(String propertyName, String explicitTargetEntity, String explicitMapKeyClass, ElementKind expectedElementKind) {
for (Element elem : element.getEnclosedElements()) {
if (!expectedElementKind.equals(elem.getKind())) {
continue;
}
String elementPropertyName = elem.getSimpleName().toString();
if (elem.getKind().equals(ElementKind.METHOD)) {
elementPropertyName = StringUtil.getPropertyName(elementPropertyName);
}
if (!propertyName.equals(elementPropertyName)) {
continue;
}
DeclaredType type = determineDeclaredType(elem);
if (type == null) {
continue;
}
return determineTypes(propertyName, explicitTargetEntity, explicitMapKeyClass, type);
}
return null;
}
use of javax.lang.model.element.Element in project hibernate-orm by hibernate.
the class XmlMetaEntity method getType.
/**
* Returns the entity type for a property.
*
* @param propertyName The property name
* @param explicitTargetEntity The explicitly specified target entity type or {@code null}.
* @param expectedElementKind Determines property vs field access type
*
* @return The entity type for this property or {@code null} if the property with the name and the matching access
* type does not exist.
*/
private String getType(String propertyName, String explicitTargetEntity, ElementKind expectedElementKind) {
for (Element elem : element.getEnclosedElements()) {
if (!expectedElementKind.equals(elem.getKind())) {
continue;
}
TypeMirror mirror;
String name = elem.getSimpleName().toString();
if (ElementKind.METHOD.equals(elem.getKind())) {
name = StringUtil.getPropertyName(name);
mirror = ((ExecutableElement) elem).getReturnType();
} else {
mirror = elem.asType();
}
if (name == null || !name.equals(propertyName)) {
continue;
}
if (explicitTargetEntity != null) {
// TODO should there be a check of the target entity class and if it is loadable?
return explicitTargetEntity;
}
switch(mirror.getKind()) {
case INT:
{
return "java.lang.Integer";
}
case LONG:
{
return "java.lang.Long";
}
case BOOLEAN:
{
return "java.lang.Boolean";
}
case BYTE:
{
return "java.lang.Byte";
}
case SHORT:
{
return "java.lang.Short";
}
case CHAR:
{
return "java.lang.Char";
}
case FLOAT:
{
return "java.lang.Float";
}
case DOUBLE:
{
return "java.lang.Double";
}
case DECLARED:
{
return mirror.toString();
}
case TYPEVAR:
{
return mirror.toString();
}
default:
{
}
}
}
context.logMessage(Diagnostic.Kind.WARNING, "Unable to determine type for property " + propertyName + " of class " + getQualifiedName() + " using access type " + accessTypeInfo.getDefaultAccessType());
return null;
}
use of javax.lang.model.element.Element in project neo4j by neo4j.
the class UserFunctionVisitorTest method functions_with_specified_value_cannot_be_in_root_namespace.
@Test
public void functions_with_specified_value_cannot_be_in_root_namespace() {
Element function = elementTestUtils.findMethodElement(UserFunctionsExamples.class, "functionWithValue");
Stream<CompilationMessage> errors = visitor.visit(function);
assertThat(errors).hasSize(1).extracting(CompilationMessage::getCategory, CompilationMessage::getElement, CompilationMessage::getContents).contains(tuple(Diagnostic.Kind.ERROR, function, "Function <in_root_namespace_again> cannot be defined in the root namespace. Valid name example: com.acme.my_function"));
}
Aggregations