use of org.drools.drl.ast.descr.EnumDeclarationDescr in project drools by kiegroup.
the class TypeDeclarationNameResolver method qualifyNames.
private void qualifyNames(List<TypeDefinition> unresolvedTypes, PackageDescr packageDescr, TypeResolver typeResolver) {
for (TypeDeclarationDescr declarationDescr : packageDescr.getTypeDeclarations()) {
qualifyNames(declarationDescr, packageDescr, unresolvedTypes, typeResolver);
discoverHierarchyForRedeclarations(declarationDescr, packageDescr, typeResolver);
}
for (EnumDeclarationDescr enumDeclarationDescr : packageDescr.getEnumDeclarations()) {
qualifyNames(enumDeclarationDescr, packageDescr, unresolvedTypes, typeResolver);
}
}
use of org.drools.drl.ast.descr.EnumDeclarationDescr in project drools by kiegroup.
the class TypeDeclarationBuilder method normalizeForeignPackages.
protected void normalizeForeignPackages(PackageDescr packageDescr) {
Map<String, PackageDescr> foreignPackages = null;
for (AbstractClassTypeDeclarationDescr typeDescr : packageDescr.getClassAndEnumDeclarationDescrs()) {
if (kbuilder.filterAccepts(ResourceChange.Type.DECLARATION, typeDescr.getNamespace(), typeDescr.getTypeName())) {
if (!typeDescr.getNamespace().equals(packageDescr.getNamespace())) {
// If the type declaration is for a different namespace, process that separately.
PackageDescr altDescr;
if (foreignPackages == null) {
foreignPackages = new HashMap<>();
}
if (foreignPackages.containsKey(typeDescr.getNamespace())) {
altDescr = foreignPackages.get(typeDescr.getNamespace());
} else {
altDescr = new PackageDescr(typeDescr.getNamespace());
altDescr.setResource(packageDescr.getResource());
foreignPackages.put(typeDescr.getNamespace(), altDescr);
}
if (typeDescr instanceof TypeDeclarationDescr) {
altDescr.addTypeDeclaration((TypeDeclarationDescr) typeDescr);
} else if (typeDescr instanceof EnumDeclarationDescr) {
altDescr.addEnumDeclaration((EnumDeclarationDescr) typeDescr);
}
for (ImportDescr imp : packageDescr.getImports()) {
altDescr.addImport(imp);
}
kbuilder.getOrCreatePackageRegistry(altDescr);
}
}
}
}
use of org.drools.drl.ast.descr.EnumDeclarationDescr in project drools by kiegroup.
the class POJOGenerator method findPOJOorGenerate.
public void findPOJOorGenerate() {
TypeResolver typeResolver = pkg.getTypeResolver();
Set<String> generatedPojos = new HashSet<>();
for (TypeDeclarationDescr typeDescr : packageDescr.getTypeDeclarations()) {
if (!generatedPojos.add(typeDescr.getFullTypeName())) {
builder.addBuilderResult(new DuplicatedDeclarationError(typeDescr.getFullTypeName()));
continue;
}
try {
Class<?> type = typeResolver.resolveType(typeDescr.getFullTypeName());
checkRedeclarationCompatibility(type, typeDescr);
processTypeMetadata(type, typeDescr.getAnnotations());
} catch (ClassNotFoundException e) {
createPOJO(typeDescr);
}
}
for (EnumDeclarationDescr enumDescr : packageDescr.getEnumDeclarations()) {
try {
Class<?> type = typeResolver.resolveType(enumDescr.getFullTypeName());
processTypeMetadata(type, enumDescr.getAnnotations());
} catch (ClassNotFoundException e) {
TypeDeclaration generatedEnum = new EnumGenerator().generate(enumDescr);
packageModel.addGeneratedPOJO(generatedEnum);
addTypeMetadata(enumDescr.getTypeName());
}
}
}
use of org.drools.drl.ast.descr.EnumDeclarationDescr in project drools by kiegroup.
the class TypeDeclarationFactory method processAnnotations.
public static void processAnnotations(AbstractClassTypeDeclarationDescr typeDescr, TypeDeclaration type) {
Role role = getTypedAnnotation(typeDescr, Role.class);
if (role != null) {
type.setRole(role.value());
}
TypeSafe typeSafe = getTypedAnnotation(typeDescr, 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.drl.ast.descr.EnumDeclarationDescr in project drools by kiegroup.
the class CompositePackageDescr method internalAdd.
private void internalAdd(Resource resource, PackageDescr packageDescr) {
for (ImportDescr descr : packageDescr.getImports()) {
addImport(descr);
descr.setResource(resource);
}
for (FunctionImportDescr descr : packageDescr.getFunctionImports()) {
addFunctionImport(descr);
descr.setResource(resource);
}
for (AccumulateImportDescr descr : packageDescr.getAccumulateImports()) {
addAccumulateImport(descr);
descr.setResource(resource);
}
for (AttributeDescr descr : packageDescr.getAttributes()) {
addAttribute(descr);
descr.setResource(resource);
}
for (GlobalDescr descr : packageDescr.getGlobals()) {
addGlobal(descr);
descr.setResource(resource);
}
for (FunctionDescr descr : packageDescr.getFunctions()) {
addFunction(descr);
descr.setResource(resource);
}
for (RuleDescr descr : packageDescr.getRules()) {
addRule(descr);
descr.setResource(resource);
}
// Avoid adding the same type declaration twice, see
// TypeDeclarationTest.testDuplicatedTypeDeclarationInDifferentResources
// IncrementalCompilationTest.testIncrementalCompilationWithAmbiguousRedeclares
// RHDM-1738
Set<TypeDeclarationDescr> typeDeclarationDescrs = new HashSet<>(getTypeDeclarations());
for (TypeDeclarationDescr descr : packageDescr.getTypeDeclarations()) {
if (!typeDeclarationDescrs.contains(descr)) {
addTypeDeclaration(descr);
descr.setResource(resource);
}
}
for (EnumDeclarationDescr enumDescr : packageDescr.getEnumDeclarations()) {
addEnumDeclaration(enumDescr);
enumDescr.setResource(resource);
}
for (EntryPointDeclarationDescr descr : packageDescr.getEntryPointDeclarations()) {
addEntryPointDeclaration(descr);
descr.setResource(resource);
}
for (WindowDeclarationDescr descr : packageDescr.getWindowDeclarations()) {
addWindowDeclaration(descr);
descr.setResource(resource);
}
packageDescr.getPreferredPkgUUID().ifPresent(pkgUUID -> {
if (getPreferredPkgUUID().isPresent() && !pkgUUID.equals(getPreferredPkgUUID().get())) {
throw new RuntimeException(String.format("Trying to overwrite preferredPkgUUID %s with a different value %s", getPreferredPkgUUID().get(), pkgUUID));
}
setPreferredPkgUUID(pkgUUID);
});
}
Aggregations