Search in sources :

Example 1 with EnumDeclarationDescr

use of org.drools.compiler.lang.descr.EnumDeclarationDescr in project drools by kiegroup.

the class KnowledgeBuilderImpl method buildTypeDeclarations.

protected void buildTypeDeclarations(Collection<CompositePackageDescr> packages) {
    Map<String, AbstractClassTypeDeclarationDescr> unprocesseableDescrs = new HashMap<String, AbstractClassTypeDeclarationDescr>();
    List<TypeDefinition> unresolvedTypes = new ArrayList<TypeDefinition>();
    List<AbstractClassTypeDeclarationDescr> unsortedDescrs = new ArrayList<AbstractClassTypeDeclarationDescr>();
    for (CompositePackageDescr packageDescr : packages) {
        for (TypeDeclarationDescr typeDeclarationDescr : packageDescr.getTypeDeclarations()) {
            unsortedDescrs.add(typeDeclarationDescr);
        }
        for (EnumDeclarationDescr enumDeclarationDescr : packageDescr.getEnumDeclarations()) {
            unsortedDescrs.add(enumDeclarationDescr);
        }
    }
    getTypeBuilder().processTypeDeclarations(packages, unsortedDescrs, unresolvedTypes, unprocesseableDescrs);
    for (CompositePackageDescr packageDescr : packages) {
        for (ImportDescr importDescr : packageDescr.getImports()) {
            getPackageRegistry(packageDescr.getNamespace()).addImport(importDescr);
        }
    }
}
Also used : TypeDeclarationDescr(org.drools.compiler.lang.descr.TypeDeclarationDescr) AbstractClassTypeDeclarationDescr(org.drools.compiler.lang.descr.AbstractClassTypeDeclarationDescr) LinkedHashMap(java.util.LinkedHashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) CompositePackageDescr(org.drools.compiler.lang.descr.CompositePackageDescr) EnumDeclarationDescr(org.drools.compiler.lang.descr.EnumDeclarationDescr) AbstractClassTypeDeclarationDescr(org.drools.compiler.lang.descr.AbstractClassTypeDeclarationDescr) ArrayList(java.util.ArrayList) ImportDescr(org.drools.compiler.lang.descr.ImportDescr) FunctionImportDescr(org.drools.compiler.lang.descr.FunctionImportDescr) AccumulateImportDescr(org.drools.compiler.lang.descr.AccumulateImportDescr)

Example 2 with EnumDeclarationDescr

use of org.drools.compiler.lang.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<String, PackageDescr>();
                }
                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.compiler.lang.descr.AbstractClassTypeDeclarationDescr) TypeDeclarationDescr(org.drools.compiler.lang.descr.TypeDeclarationDescr) EnumDeclarationDescr(org.drools.compiler.lang.descr.EnumDeclarationDescr) AbstractClassTypeDeclarationDescr(org.drools.compiler.lang.descr.AbstractClassTypeDeclarationDescr) ImportDescr(org.drools.compiler.lang.descr.ImportDescr) PackageDescr(org.drools.compiler.lang.descr.PackageDescr)

Example 3 with EnumDeclarationDescr

use of org.drools.compiler.lang.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 : TypeDeclarationDescr(org.drools.compiler.lang.descr.TypeDeclarationDescr) AbstractClassTypeDeclarationDescr(org.drools.compiler.lang.descr.AbstractClassTypeDeclarationDescr) EnumDeclarationDescr(org.drools.compiler.lang.descr.EnumDeclarationDescr)

Example 4 with EnumDeclarationDescr

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

Aggregations

AbstractClassTypeDeclarationDescr (org.drools.compiler.lang.descr.AbstractClassTypeDeclarationDescr)4 EnumDeclarationDescr (org.drools.compiler.lang.descr.EnumDeclarationDescr)4 TypeDeclarationDescr (org.drools.compiler.lang.descr.TypeDeclarationDescr)4 ImportDescr (org.drools.compiler.lang.descr.ImportDescr)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 AccumulateImportDescr (org.drools.compiler.lang.descr.AccumulateImportDescr)1 CompositePackageDescr (org.drools.compiler.lang.descr.CompositePackageDescr)1 FunctionImportDescr (org.drools.compiler.lang.descr.FunctionImportDescr)1 PackageDescr (org.drools.compiler.lang.descr.PackageDescr)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