Search in sources :

Example 6 with AnnotationDescr

use of org.drools.drl.ast.descr.AnnotationDescr in project drools by kiegroup.

the class DRL6Expressions method fullAnnotation.

// $ANTLR end "ternaryExpression"
// $ANTLR start "fullAnnotation"
// src/main/resources/org/drools/compiler/lang/DRL6Expressions.g:180:1: fullAnnotation[AnnotatedDescrBuilder inDescrBuilder] returns [AnnotationDescr result] : AT name= ID ( DOT x= ID )* annotationArgs[result, annoBuilder] ;
public final AnnotationDescr fullAnnotation(AnnotatedDescrBuilder inDescrBuilder) throws RecognitionException {
    AnnotationDescr result = null;
    Token name = null;
    Token x = null;
    String n = "";
    AnnotationDescrBuilder annoBuilder = null;
    try {
        // src/main/resources/org/drools/compiler/lang/DRL6Expressions.g:182:3: ( AT name= ID ( DOT x= ID )* annotationArgs[result, annoBuilder] )
        // src/main/resources/org/drools/compiler/lang/DRL6Expressions.g:182:5: AT name= ID ( DOT x= ID )* annotationArgs[result, annoBuilder]
        {
            match(input, AT, FOLLOW_AT_in_fullAnnotation894);
            if (state.failed)
                return result;
            name = (Token) match(input, ID, FOLLOW_ID_in_fullAnnotation898);
            if (state.failed)
                return result;
            if (state.backtracking == 0) {
                n = (name != null ? name.getText() : null);
            }
            // src/main/resources/org/drools/compiler/lang/DRL6Expressions.g:182:36: ( DOT x= ID )*
            loop18: while (true) {
                int alt18 = 2;
                int LA18_0 = input.LA(1);
                if ((LA18_0 == DOT)) {
                    alt18 = 1;
                }
                switch(alt18) {
                    case 1:
                        // src/main/resources/org/drools/compiler/lang/DRL6Expressions.g:182:38: DOT x= ID
                        {
                            match(input, DOT, FOLLOW_DOT_in_fullAnnotation904);
                            if (state.failed)
                                return result;
                            x = (Token) match(input, ID, FOLLOW_ID_in_fullAnnotation908);
                            if (state.failed)
                                return result;
                            if (state.backtracking == 0) {
                                n += "." + (x != null ? x.getText() : null);
                            }
                        }
                        break;
                    default:
                        break loop18;
                }
            }
            if (state.backtracking == 0) {
                if (buildDescr) {
                    if (inDescrBuilder == null) {
                        result = new AnnotationDescr(n);
                    } else {
                        annoBuilder = inDescrBuilder instanceof AnnotationDescrBuilder ? ((AnnotationDescrBuilder) inDescrBuilder).newAnnotation(n) : inDescrBuilder.newAnnotation(n);
                        result = (AnnotationDescr) annoBuilder.getDescr();
                    }
                }
            }
            pushFollow(FOLLOW_annotationArgs_in_fullAnnotation929);
            annotationArgs(result, annoBuilder);
            state._fsp--;
            if (state.failed)
                return result;
        }
    } catch (RecognitionException re) {
        throw re;
    } finally {
    // do for sure before leaving
    }
    return result;
}
Also used : AnnotationDescrBuilder(org.drools.drl.ast.dsl.AnnotationDescrBuilder) AnnotationDescr(org.drools.drl.ast.descr.AnnotationDescr)

Example 7 with AnnotationDescr

use of org.drools.drl.ast.descr.AnnotationDescr in project drools by kiegroup.

the class DRL6Expressions method orRestriction.

// $ANTLR end "relationalExpression"
// $ANTLR start "orRestriction"
// src/main/resources/org/drools/compiler/lang/DRL6Expressions.g:405:1: orRestriction returns [BaseDescr result] : left= andRestriction ( ( DOUBLE_PIPE ( fullAnnotation[null] )? andRestriction )=>lop= DOUBLE_PIPE (args= fullAnnotation[null] )? right= andRestriction )* ( EOF )? ;
public final BaseDescr orRestriction() throws RecognitionException {
    BaseDescr result = null;
    Token lop = null;
    BaseDescr left = null;
    AnnotationDescr args = null;
    BaseDescr right = null;
    try {
        // src/main/resources/org/drools/compiler/lang/DRL6Expressions.g:406:3: (left= andRestriction ( ( DOUBLE_PIPE ( fullAnnotation[null] )? andRestriction )=>lop= DOUBLE_PIPE (args= fullAnnotation[null] )? right= andRestriction )* ( EOF )? )
        // src/main/resources/org/drools/compiler/lang/DRL6Expressions.g:406:5: left= andRestriction ( ( DOUBLE_PIPE ( fullAnnotation[null] )? andRestriction )=>lop= DOUBLE_PIPE (args= fullAnnotation[null] )? right= andRestriction )* ( EOF )?
        {
            pushFollow(FOLLOW_andRestriction_in_orRestriction1892);
            left = andRestriction();
            state._fsp--;
            if (state.failed)
                return result;
            if (state.backtracking == 0) {
                if (buildDescr) {
                    result = left;
                }
            }
            // src/main/resources/org/drools/compiler/lang/DRL6Expressions.g:407:5: ( ( DOUBLE_PIPE ( fullAnnotation[null] )? andRestriction )=>lop= DOUBLE_PIPE (args= fullAnnotation[null] )? right= andRestriction )*
            loop39: while (true) {
                int alt39 = 2;
                int LA39_0 = input.LA(1);
                if ((LA39_0 == DOUBLE_PIPE)) {
                    int LA39_9 = input.LA(2);
                    if ((synpred10_DRL6Expressions())) {
                        alt39 = 1;
                    }
                }
                switch(alt39) {
                    case 1:
                        // src/main/resources/org/drools/compiler/lang/DRL6Expressions.g:407:7: ( DOUBLE_PIPE ( fullAnnotation[null] )? andRestriction )=>lop= DOUBLE_PIPE (args= fullAnnotation[null] )? right= andRestriction
                        {
                            lop = (Token) match(input, DOUBLE_PIPE, FOLLOW_DOUBLE_PIPE_in_orRestriction1914);
                            if (state.failed)
                                return result;
                            // src/main/resources/org/drools/compiler/lang/DRL6Expressions.g:407:79: (args= fullAnnotation[null] )?
                            int alt38 = 2;
                            int LA38_0 = input.LA(1);
                            if ((LA38_0 == AT)) {
                                alt38 = 1;
                            }
                            switch(alt38) {
                                case 1:
                                    // src/main/resources/org/drools/compiler/lang/DRL6Expressions.g:407:79: args= fullAnnotation[null]
                                    {
                                        pushFollow(FOLLOW_fullAnnotation_in_orRestriction1918);
                                        args = fullAnnotation(null);
                                        state._fsp--;
                                        if (state.failed)
                                            return result;
                                    }
                                    break;
                            }
                            pushFollow(FOLLOW_andRestriction_in_orRestriction1924);
                            right = andRestriction();
                            state._fsp--;
                            if (state.failed)
                                return result;
                            if (state.backtracking == 0) {
                                if (buildDescr) {
                                    ConstraintConnectiveDescr descr = ConstraintConnectiveDescr.newOr();
                                    descr.addOrMerge(result);
                                    descr.addOrMerge(right);
                                    if (args != null) {
                                        descr.addAnnotation(args);
                                    }
                                    result = descr;
                                }
                            }
                        }
                        break;
                    default:
                        break loop39;
                }
            }
            // src/main/resources/org/drools/compiler/lang/DRL6Expressions.g:416:7: ( EOF )?
            int alt40 = 2;
            int LA40_0 = input.LA(1);
            if ((LA40_0 == EOF)) {
                int LA40_1 = input.LA(2);
                if ((LA40_1 == EOF)) {
                    int LA40_3 = input.LA(3);
                    if ((LA40_3 == EOF)) {
                        alt40 = 1;
                    }
                } else if (((LA40_1 >= AMPER && LA40_1 <= AND_ASSIGN) || LA40_1 == AT || (LA40_1 >= COLON && LA40_1 <= COMMA) || LA40_1 == DIV_ASSIGN || (LA40_1 >= DOUBLE_AMPER && LA40_1 <= DOUBLE_PIPE) || (LA40_1 >= EQUALS && LA40_1 <= EQUALS_ASSIGN) || (LA40_1 >= GREATER && LA40_1 <= GREATER_EQUALS) || LA40_1 == ID || LA40_1 == LEFT_PAREN || (LA40_1 >= LESS && LA40_1 <= LESS_EQUALS) || LA40_1 == MINUS_ASSIGN || LA40_1 == MOD_ASSIGN || LA40_1 == MULT_ASSIGN || LA40_1 == NOT_EQUALS || LA40_1 == OR_ASSIGN || LA40_1 == PIPE || (LA40_1 >= PLUS_ASSIGN && LA40_1 <= QUESTION) || (LA40_1 >= RIGHT_CURLY && LA40_1 <= SEMICOLON) || LA40_1 == TILDE || (LA40_1 >= XOR && LA40_1 <= XOR_ASSIGN))) {
                    alt40 = 1;
                }
            }
            switch(alt40) {
                case 1:
                    // src/main/resources/org/drools/compiler/lang/DRL6Expressions.g:416:7: EOF
                    {
                        match(input, EOF, FOLLOW_EOF_in_orRestriction1943);
                        if (state.failed)
                            return result;
                    }
                    break;
            }
        }
    } catch (RecognitionException re) {
        throw re;
    } finally {
    // do for sure before leaving
    }
    return result;
}
Also used : BaseDescr(org.drools.drl.ast.descr.BaseDescr) ConstraintConnectiveDescr(org.drools.drl.ast.descr.ConstraintConnectiveDescr) AnnotationDescr(org.drools.drl.ast.descr.AnnotationDescr)

Example 8 with AnnotationDescr

use of org.drools.drl.ast.descr.AnnotationDescr in project drools by kiegroup.

the class DRL6Expressions method annotationValue.

// $ANTLR end "annotationElementValuePair"
// $ANTLR start "annotationValue"
// src/main/resources/org/drools/compiler/lang/DRL6Expressions.g:213:1: annotationValue[AnnotatedDescrBuilder inDescrBuilder] returns [Object result] : (exp= expression |annos= annotationArray[inDescrBuilder] |anno= fullAnnotation[inDescrBuilder] );
public final Object annotationValue(AnnotatedDescrBuilder inDescrBuilder) throws RecognitionException {
    Object result = null;
    ParserRuleReturnScope exp = null;
    java.util.List annos = null;
    AnnotationDescr anno = null;
    try {
        // src/main/resources/org/drools/compiler/lang/DRL6Expressions.g:214:3: (exp= expression |annos= annotationArray[inDescrBuilder] |anno= fullAnnotation[inDescrBuilder] )
        int alt21 = 3;
        switch(input.LA(1)) {
            case BOOL:
            case DECIMAL:
            case DECR:
            case DIV:
            case DOT:
            case FLOAT:
            case HEX:
            case ID:
            case INCR:
            case LEFT_PAREN:
            case LEFT_SQUARE:
            case LESS:
            case MINUS:
            case NEGATION:
            case NULL:
            case PLUS:
            case QUESTION_DIV:
            case STAR:
            case STRING:
            case TILDE:
            case TIME_INTERVAL:
                {
                    alt21 = 1;
                }
                break;
            case LEFT_CURLY:
                {
                    alt21 = 2;
                }
                break;
            case AT:
                {
                    alt21 = 3;
                }
                break;
            default:
                if (state.backtracking > 0) {
                    state.failed = true;
                    return result;
                }
                NoViableAltException nvae = new NoViableAltException("", 21, 0, input);
                throw nvae;
        }
        switch(alt21) {
            case 1:
                // src/main/resources/org/drools/compiler/lang/DRL6Expressions.g:214:5: exp= expression
                {
                    pushFollow(FOLLOW_expression_in_annotationValue1070);
                    exp = expression();
                    state._fsp--;
                    if (state.failed)
                        return result;
                    if (state.backtracking == 0) {
                        if (buildDescr)
                            result = (exp != null ? input.toString(exp.start, exp.stop) : null);
                    }
                }
                break;
            case 2:
                // src/main/resources/org/drools/compiler/lang/DRL6Expressions.g:215:7: annos= annotationArray[inDescrBuilder]
                {
                    pushFollow(FOLLOW_annotationArray_in_annotationValue1082);
                    annos = annotationArray(inDescrBuilder);
                    state._fsp--;
                    if (state.failed)
                        return result;
                    if (state.backtracking == 0) {
                        if (buildDescr)
                            result = annos.toArray();
                    }
                }
                break;
            case 3:
                // src/main/resources/org/drools/compiler/lang/DRL6Expressions.g:216:7: anno= fullAnnotation[inDescrBuilder]
                {
                    pushFollow(FOLLOW_fullAnnotation_in_annotationValue1095);
                    anno = fullAnnotation(inDescrBuilder);
                    state._fsp--;
                    if (state.failed)
                        return result;
                    if (state.backtracking == 0) {
                        if (buildDescr)
                            result = anno;
                    }
                }
                break;
        }
    } catch (RecognitionException re) {
        throw re;
    } finally {
    // do for sure before leaving
    }
    return result;
}
Also used : List(java.util.List) AnnotationDescr(org.drools.drl.ast.descr.AnnotationDescr)

Example 9 with AnnotationDescr

use of org.drools.drl.ast.descr.AnnotationDescr in project drools by kiegroup.

the class DRL5Expressions method orRestriction.

// $ANTLR end "relationalExpression"
// $ANTLR start "orRestriction"
// src/main/resources/org/drools/compiler/lang/DRL5Expressions.g:391:1: orRestriction returns [BaseDescr result] : left= andRestriction ( ( DOUBLE_PIPE ( fullAnnotation[null] )? andRestriction )=>lop= DOUBLE_PIPE (args= fullAnnotation[null] )? right= andRestriction )* ( EOF )? ;
public final BaseDescr orRestriction() throws RecognitionException {
    BaseDescr result = null;
    Token lop = null;
    BaseDescr left = null;
    AnnotationDescr args = null;
    BaseDescr right = null;
    try {
        // src/main/resources/org/drools/compiler/lang/DRL5Expressions.g:392:3: (left= andRestriction ( ( DOUBLE_PIPE ( fullAnnotation[null] )? andRestriction )=>lop= DOUBLE_PIPE (args= fullAnnotation[null] )? right= andRestriction )* ( EOF )? )
        // src/main/resources/org/drools/compiler/lang/DRL5Expressions.g:392:5: left= andRestriction ( ( DOUBLE_PIPE ( fullAnnotation[null] )? andRestriction )=>lop= DOUBLE_PIPE (args= fullAnnotation[null] )? right= andRestriction )* ( EOF )?
        {
            pushFollow(FOLLOW_andRestriction_in_orRestriction1810);
            left = andRestriction();
            state._fsp--;
            if (state.failed)
                return result;
            if (state.backtracking == 0) {
                if (buildDescr) {
                    result = left;
                }
            }
            // src/main/resources/org/drools/compiler/lang/DRL5Expressions.g:393:5: ( ( DOUBLE_PIPE ( fullAnnotation[null] )? andRestriction )=>lop= DOUBLE_PIPE (args= fullAnnotation[null] )? right= andRestriction )*
            loop39: while (true) {
                int alt39 = 2;
                int LA39_0 = input.LA(1);
                if ((LA39_0 == DOUBLE_PIPE)) {
                    int LA39_9 = input.LA(2);
                    if ((synpred9_DRL5Expressions())) {
                        alt39 = 1;
                    }
                }
                switch(alt39) {
                    case 1:
                        // src/main/resources/org/drools/compiler/lang/DRL5Expressions.g:393:7: ( DOUBLE_PIPE ( fullAnnotation[null] )? andRestriction )=>lop= DOUBLE_PIPE (args= fullAnnotation[null] )? right= andRestriction
                        {
                            lop = (Token) match(input, DOUBLE_PIPE, FOLLOW_DOUBLE_PIPE_in_orRestriction1832);
                            if (state.failed)
                                return result;
                            // src/main/resources/org/drools/compiler/lang/DRL5Expressions.g:393:79: (args= fullAnnotation[null] )?
                            int alt38 = 2;
                            int LA38_0 = input.LA(1);
                            if ((LA38_0 == AT)) {
                                alt38 = 1;
                            }
                            switch(alt38) {
                                case 1:
                                    // src/main/resources/org/drools/compiler/lang/DRL5Expressions.g:393:79: args= fullAnnotation[null]
                                    {
                                        pushFollow(FOLLOW_fullAnnotation_in_orRestriction1836);
                                        args = fullAnnotation(null);
                                        state._fsp--;
                                        if (state.failed)
                                            return result;
                                    }
                                    break;
                            }
                            pushFollow(FOLLOW_andRestriction_in_orRestriction1842);
                            right = andRestriction();
                            state._fsp--;
                            if (state.failed)
                                return result;
                            if (state.backtracking == 0) {
                                if (buildDescr) {
                                    ConstraintConnectiveDescr descr = ConstraintConnectiveDescr.newOr();
                                    descr.addOrMerge(result);
                                    descr.addOrMerge(right);
                                    if (args != null) {
                                        descr.addAnnotation(args);
                                    }
                                    result = descr;
                                }
                            }
                        }
                        break;
                    default:
                        break loop39;
                }
            }
            // src/main/resources/org/drools/compiler/lang/DRL5Expressions.g:402:7: ( EOF )?
            int alt40 = 2;
            int LA40_0 = input.LA(1);
            if ((LA40_0 == EOF)) {
                int LA40_1 = input.LA(2);
                if ((LA40_1 == EOF)) {
                    int LA40_3 = input.LA(3);
                    if ((LA40_3 == EOF)) {
                        alt40 = 1;
                    }
                } else if (((LA40_1 >= AMPER && LA40_1 <= AND_ASSIGN) || LA40_1 == AT || (LA40_1 >= COLON && LA40_1 <= COMMA) || LA40_1 == DIV_ASSIGN || (LA40_1 >= DOUBLE_AMPER && LA40_1 <= DOUBLE_PIPE) || (LA40_1 >= EQUALS && LA40_1 <= EQUALS_ASSIGN) || (LA40_1 >= GREATER && LA40_1 <= GREATER_EQUALS) || LA40_1 == ID || LA40_1 == LEFT_PAREN || (LA40_1 >= LESS && LA40_1 <= LESS_EQUALS) || LA40_1 == MINUS_ASSIGN || LA40_1 == MOD_ASSIGN || LA40_1 == MULT_ASSIGN || LA40_1 == NOT_EQUALS || LA40_1 == OR_ASSIGN || LA40_1 == PIPE || (LA40_1 >= PLUS_ASSIGN && LA40_1 <= SEMICOLON) || LA40_1 == TILDE || (LA40_1 >= XOR && LA40_1 <= XOR_ASSIGN))) {
                    alt40 = 1;
                }
            }
            switch(alt40) {
                case 1:
                    // src/main/resources/org/drools/compiler/lang/DRL5Expressions.g:402:7: EOF
                    {
                        match(input, EOF, FOLLOW_EOF_in_orRestriction1861);
                        if (state.failed)
                            return result;
                    }
                    break;
            }
        }
    } catch (RecognitionException re) {
        throw re;
    } finally {
    // do for sure before leaving
    }
    return result;
}
Also used : BaseDescr(org.drools.drl.ast.descr.BaseDescr) ConstraintConnectiveDescr(org.drools.drl.ast.descr.ConstraintConnectiveDescr) AnnotationDescr(org.drools.drl.ast.descr.AnnotationDescr)

Example 10 with AnnotationDescr

use of org.drools.drl.ast.descr.AnnotationDescr in project drools by kiegroup.

the class ClassHierarchyManager method buildInheritedFieldDescrFromDefinition.

protected TypeFieldDescr buildInheritedFieldDescrFromDefinition(org.kie.api.definition.type.FactField fld, TypeDeclarationDescr typeDescr) {
    TypeFieldDescr inheritedFldDescr = new TypeFieldDescr();
    inheritedFldDescr.setFieldName(fld.getName());
    inheritedFldDescr.setResource(typeDescr.getResource());
    PatternDescr fldType = new PatternDescr();
    fldType.setObjectType(((FieldDefinition) fld).getTypeName());
    // also sets resource for PatternDescr fldType
    inheritedFldDescr.setPattern(fldType);
    if (fld.isKey()) {
        AnnotationDescr keyAnnotation = new AnnotationDescr(Key.class.getCanonicalName());
        keyAnnotation.setFullyQualifiedName(Key.class.getCanonicalName());
        keyAnnotation.setResource(typeDescr.getResource());
        inheritedFldDescr.addAnnotation(keyAnnotation);
    }
    inheritedFldDescr.setIndex(((FieldDefinition) fld).getDeclIndex());
    inheritedFldDescr.setInherited(true);
    String initExprOverride = ((FieldDefinition) fld).getInitExpr();
    int overrideCount = 0;
    // only @aliasing local fields may override defaults.
    for (TypeFieldDescr localField : typeDescr.getFields().values()) {
        Alias alias = getTypedAnnotation(localField, Alias.class);
        if (alias != null && fld.getName().equals(alias.value().replaceAll("\"", "")) && localField.getInitExpr() != null) {
            overrideCount++;
            initExprOverride = localField.getInitExpr();
        }
    }
    if (overrideCount > 1) {
        // however, only one is allowed
        initExprOverride = null;
    }
    inheritedFldDescr.setInitExpr(initExprOverride);
    return inheritedFldDescr;
}
Also used : PatternDescr(org.drools.drl.ast.descr.PatternDescr) TypeFieldDescr(org.drools.drl.ast.descr.TypeFieldDescr) Alias(org.drools.core.factmodel.traits.Alias) FieldDefinition(org.drools.core.factmodel.FieldDefinition) AnnotationDescr(org.drools.drl.ast.descr.AnnotationDescr) Key(org.kie.api.definition.type.Key)

Aggregations

AnnotationDescr (org.drools.drl.ast.descr.AnnotationDescr)26 BaseDescr (org.drools.drl.ast.descr.BaseDescr)8 ConstraintConnectiveDescr (org.drools.drl.ast.descr.ConstraintConnectiveDescr)8 AnnotationDefinition (org.drools.core.factmodel.AnnotationDefinition)5 ArrayList (java.util.ArrayList)3 TypeDeclarationError (org.drools.compiler.compiler.TypeDeclarationError)3 TypeDeclarationDescr (org.drools.drl.ast.descr.TypeDeclarationDescr)3 TypeFieldDescr (org.drools.drl.ast.descr.TypeFieldDescr)3 MethodCallExpr (com.github.javaparser.ast.expr.MethodCallExpr)2 HashMap (java.util.HashMap)2 List (java.util.List)2 Map (java.util.Map)2 AnnotationDeclarationError (org.drools.compiler.compiler.AnnotationDeclarationError)2 FieldDefinition (org.drools.core.factmodel.FieldDefinition)2 QualifiedName (org.drools.drl.ast.descr.QualifiedName)2 NullLiteralExpr (com.github.javaparser.ast.expr.NullLiteralExpr)1 IOException (java.io.IOException)1 Annotation (java.lang.annotation.Annotation)1 Arrays (java.util.Arrays)1 BitSet (java.util.BitSet)1