Search in sources :

Example 1 with DuplicatedDeclarationError

use of org.drools.modelcompiler.builder.errors.DuplicatedDeclarationError 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)

Aggregations

TypeDeclaration (com.github.javaparser.ast.body.TypeDeclaration)1 HashSet (java.util.HashSet)1 TypeResolver (org.drools.core.addon.TypeResolver)1 EnumDeclarationDescr (org.drools.drl.ast.descr.EnumDeclarationDescr)1 TypeDeclarationDescr (org.drools.drl.ast.descr.TypeDeclarationDescr)1 DuplicatedDeclarationError (org.drools.modelcompiler.builder.errors.DuplicatedDeclarationError)1