Search in sources :

Example 1 with EnumDeclarationDescr

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);
    }
}
Also used : AbstractClassTypeDeclarationDescr(org.drools.drl.ast.descr.AbstractClassTypeDeclarationDescr) TypeDeclarationDescr(org.drools.drl.ast.descr.TypeDeclarationDescr) EnumDeclarationDescr(org.drools.drl.ast.descr.EnumDeclarationDescr)

Example 2 with EnumDeclarationDescr

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);
            }
        }
    }
}
Also used : AbstractClassTypeDeclarationDescr(org.drools.drl.ast.descr.AbstractClassTypeDeclarationDescr) TypeDeclarationDescr(org.drools.drl.ast.descr.TypeDeclarationDescr) EnumDeclarationDescr(org.drools.drl.ast.descr.EnumDeclarationDescr) AbstractClassTypeDeclarationDescr(org.drools.drl.ast.descr.AbstractClassTypeDeclarationDescr) ImportDescr(org.drools.drl.ast.descr.ImportDescr) PackageDescr(org.drools.drl.ast.descr.PackageDescr)

Example 3 with EnumDeclarationDescr

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());
        }
    }
}
Also used : DuplicatedDeclarationError(org.drools.modelcompiler.builder.errors.DuplicatedDeclarationError) TypeDeclarationDescr(org.drools.drl.ast.descr.TypeDeclarationDescr) TypeResolver(org.drools.core.addon.TypeResolver) EnumDeclarationDescr(org.drools.drl.ast.descr.EnumDeclarationDescr) TypeDeclaration(com.github.javaparser.ast.body.TypeDeclaration) HashSet(java.util.HashSet)

Example 4 with EnumDeclarationDescr

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));
}
Also used : Role(org.kie.api.definition.type.Role) AbstractClassTypeDeclarationDescr(org.drools.drl.ast.descr.AbstractClassTypeDeclarationDescr) TypeDeclarationDescr(org.drools.drl.ast.descr.TypeDeclarationDescr) EnumDeclarationDescr(org.drools.drl.ast.descr.EnumDeclarationDescr) PropertyChangeSupport(org.kie.api.definition.type.PropertyChangeSupport) TypeSafe(org.kie.api.definition.type.TypeSafe)

Example 5 with EnumDeclarationDescr

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);
    });
}
Also used : GlobalDescr(org.drools.drl.ast.descr.GlobalDescr) FunctionImportDescr(org.drools.drl.ast.descr.FunctionImportDescr) TypeDeclarationDescr(org.drools.drl.ast.descr.TypeDeclarationDescr) AccumulateImportDescr(org.drools.drl.ast.descr.AccumulateImportDescr) EntryPointDeclarationDescr(org.drools.drl.ast.descr.EntryPointDeclarationDescr) AccumulateImportDescr(org.drools.drl.ast.descr.AccumulateImportDescr) FunctionImportDescr(org.drools.drl.ast.descr.FunctionImportDescr) ImportDescr(org.drools.drl.ast.descr.ImportDescr) FunctionDescr(org.drools.drl.ast.descr.FunctionDescr) EnumDeclarationDescr(org.drools.drl.ast.descr.EnumDeclarationDescr) RuleDescr(org.drools.drl.ast.descr.RuleDescr) AttributeDescr(org.drools.drl.ast.descr.AttributeDescr) WindowDeclarationDescr(org.drools.drl.ast.descr.WindowDeclarationDescr) HashSet(java.util.HashSet)

Aggregations

EnumDeclarationDescr (org.drools.drl.ast.descr.EnumDeclarationDescr)5 TypeDeclarationDescr (org.drools.drl.ast.descr.TypeDeclarationDescr)5 AbstractClassTypeDeclarationDescr (org.drools.drl.ast.descr.AbstractClassTypeDeclarationDescr)3 HashSet (java.util.HashSet)2 ImportDescr (org.drools.drl.ast.descr.ImportDescr)2 TypeDeclaration (com.github.javaparser.ast.body.TypeDeclaration)1 TypeResolver (org.drools.core.addon.TypeResolver)1 AccumulateImportDescr (org.drools.drl.ast.descr.AccumulateImportDescr)1 AttributeDescr (org.drools.drl.ast.descr.AttributeDescr)1 EntryPointDeclarationDescr (org.drools.drl.ast.descr.EntryPointDeclarationDescr)1 FunctionDescr (org.drools.drl.ast.descr.FunctionDescr)1 FunctionImportDescr (org.drools.drl.ast.descr.FunctionImportDescr)1 GlobalDescr (org.drools.drl.ast.descr.GlobalDescr)1 PackageDescr (org.drools.drl.ast.descr.PackageDescr)1 RuleDescr (org.drools.drl.ast.descr.RuleDescr)1 WindowDeclarationDescr (org.drools.drl.ast.descr.WindowDeclarationDescr)1 DuplicatedDeclarationError (org.drools.modelcompiler.builder.errors.DuplicatedDeclarationError)1 PropertyChangeSupport (org.kie.api.definition.type.PropertyChangeSupport)1 Role (org.kie.api.definition.type.Role)1 TypeSafe (org.kie.api.definition.type.TypeSafe)1