use of org.drools.compiler.lang.descr.AbstractClassTypeDeclarationDescr in project drools by kiegroup.
the class TypeDeclarationBuilder method mergeTypeDescriptors.
private boolean mergeTypeDescriptors(AbstractClassTypeDeclarationDescr prev, AbstractClassTypeDeclarationDescr descr) {
boolean isDef1 = isDefinition(prev);
boolean isDef2 = isDefinition(descr);
if (isDef1 && isDef2) {
return false;
}
if (!prev.getSuperTypes().isEmpty() && !descr.getSuperTypes().isEmpty() && prev.getSuperTypes().size() != descr.getSuperTypes().size()) {
return false;
}
if (prev.getSuperTypes().isEmpty()) {
for (QualifiedName qn : descr.getSuperTypes()) {
((TypeDeclarationDescr) prev).addSuperType(qn);
}
}
if (prev.getFields().isEmpty()) {
for (String fieldName : descr.getFields().keySet()) {
prev.addField(descr.getFields().get(fieldName));
}
}
for (AnnotationDescr ad : descr.getAnnotations()) {
prev.addQualifiedAnnotation(ad);
}
for (AnnotationDescr ad : prev.getAnnotations()) {
if (!descr.getAnnotations().contains(ad)) {
descr.addQualifiedAnnotation(ad);
}
}
return true;
}
use of org.drools.compiler.lang.descr.AbstractClassTypeDeclarationDescr in project drools by kiegroup.
the class TypeDeclarationFactory method processAnnotations.
public static void processAnnotations(AbstractClassTypeDeclarationDescr typeDescr, TypeDeclaration type) {
Role role = typeDescr.getTypedAnnotation(Role.class);
if (role != null) {
type.setRole(role.value());
}
TypeSafe typeSafe = typeDescr.getTypedAnnotation(TypeSafe.class);
if (typeSafe != null) {
type.setTypesafe(typeSafe.value());
}
if (typeDescr instanceof EnumDeclarationDescr) {
type.setKind(TypeDeclaration.Kind.ENUM);
} else if (typeDescr instanceof TypeDeclarationDescr && ((TypeDeclarationDescr) typeDescr).isTrait()) {
type.setKind(TypeDeclaration.Kind.TRAIT);
}
type.setDynamic(typeDescr.hasAnnotation(PropertyChangeSupport.class));
}
use of org.drools.compiler.lang.descr.AbstractClassTypeDeclarationDescr in project drools by kiegroup.
the class TypeDeclarationUtils method resolveType.
/**
* Tries to determine the namespace (package) of a simple type chosen to be
* the superclass of a declared bean. Looks among imports, local
* declarations and previous declarations. Means that a class can't extend
* another class declared in package that has not been loaded yet.
*
* @param klass the simple name of the class
* @param packageDescr the descriptor of the package the base class is declared in
* @param pkgRegistry the current package registry
* @return the fully qualified name of the superclass
*/
public static String resolveType(String klass, PackageDescr packageDescr, PackageRegistry pkgRegistry) {
String arraySuffix = "";
int arrayIndex = klass.indexOf("[");
if (arrayIndex >= 0) {
arraySuffix = klass.substring(arrayIndex);
klass = klass.substring(0, arrayIndex);
}
// look among imports
String temp = klass;
while (temp.length() > 0) {
for (ImportDescr id : packageDescr.getImports()) {
String fqKlass = id.getTarget();
if (fqKlass.endsWith("." + temp)) {
// logger.info("Replace supertype " + sup + " with full name " + id.getTarget());
fqKlass = fqKlass.substring(0, fqKlass.lastIndexOf(temp)) + klass;
return arrayIndex < 0 ? fqKlass : fqKlass + arraySuffix;
}
}
temp = temp.substring(0, Math.max(0, temp.lastIndexOf('.')));
}
// look among local declarations
if (pkgRegistry != null) {
for (String declaredName : pkgRegistry.getPackage().getTypeDeclarations().keySet()) {
if (declaredName.equals(klass)) {
TypeDeclaration typeDeclaration = pkgRegistry.getPackage().getTypeDeclaration(declaredName);
if (typeDeclaration.getTypeClass() != null) {
klass = typeDeclaration.getTypeClass().getName();
}
}
}
}
if ((klass != null) && (!klass.contains(".")) && (packageDescr.getNamespace() != null && !packageDescr.getNamespace().isEmpty())) {
for (AbstractClassTypeDeclarationDescr td : packageDescr.getClassAndEnumDeclarationDescrs()) {
if (klass.equals(td.getTypeName())) {
if (td.getType().getFullName().contains(".")) {
klass = td.getType().getFullName();
}
}
}
}
return arrayIndex < 0 ? klass : klass + arraySuffix;
}
Aggregations