use of org.drools.compiler.lang.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 = localField.getTypedAnnotation(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;
}
use of org.drools.compiler.lang.descr.AnnotationDescr in project drools by kiegroup.
the class KnowledgeBuilderImpl method normalizeAnnotations.
protected void normalizeAnnotations(AnnotatedBaseDescr annotationsContainer, TypeResolver typeResolver, boolean isStrict) {
for (AnnotationDescr annotationDescr : annotationsContainer.getAnnotations()) {
annotationDescr.setResource(annotationsContainer.getResource());
annotationDescr.setStrict(isStrict);
if (annotationDescr.isDuplicated()) {
addBuilderResult(new AnnotationDeclarationError(annotationDescr, "Duplicated annotation: " + annotationDescr.getName()));
}
if (isStrict) {
normalizeStrictAnnotation(typeResolver, annotationDescr);
} else {
normalizeAnnotation(typeResolver, annotationDescr);
}
}
annotationsContainer.indexByFQN(isStrict);
}
use of org.drools.compiler.lang.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;
}
use of org.drools.compiler.lang.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;
}
use of org.drools.compiler.lang.descr.AnnotationDescr in project drools by kiegroup.
the class DRL5Expressions method conditionalAndExpression.
// $ANTLR end "conditionalOrExpression"
// $ANTLR start "conditionalAndExpression"
// src/main/resources/org/drools/compiler/lang/DRL5Expressions.g:230:1: conditionalAndExpression returns [BaseDescr result] : left= inclusiveOrExpression ( DOUBLE_AMPER (args= fullAnnotation[null] )? right= inclusiveOrExpression )* ;
public final BaseDescr conditionalAndExpression() throws RecognitionException {
BaseDescr result = null;
BaseDescr left = null;
AnnotationDescr args = null;
BaseDescr right = null;
try {
// src/main/resources/org/drools/compiler/lang/DRL5Expressions.g:231:3: (left= inclusiveOrExpression ( DOUBLE_AMPER (args= fullAnnotation[null] )? right= inclusiveOrExpression )* )
// src/main/resources/org/drools/compiler/lang/DRL5Expressions.g:231:5: left= inclusiveOrExpression ( DOUBLE_AMPER (args= fullAnnotation[null] )? right= inclusiveOrExpression )*
{
pushFollow(FOLLOW_inclusiveOrExpression_in_conditionalAndExpression1182);
left = inclusiveOrExpression();
state._fsp--;
if (state.failed)
return result;
if (state.backtracking == 0) {
if (buildDescr) {
result = left;
}
}
// src/main/resources/org/drools/compiler/lang/DRL5Expressions.g:232:3: ( DOUBLE_AMPER (args= fullAnnotation[null] )? right= inclusiveOrExpression )*
loop27: while (true) {
int alt27 = 2;
int LA27_0 = input.LA(1);
if ((LA27_0 == DOUBLE_AMPER)) {
alt27 = 1;
}
switch(alt27) {
case 1:
// src/main/resources/org/drools/compiler/lang/DRL5Expressions.g:232:5: DOUBLE_AMPER (args= fullAnnotation[null] )? right= inclusiveOrExpression
{
match(input, DOUBLE_AMPER, FOLLOW_DOUBLE_AMPER_in_conditionalAndExpression1190);
if (state.failed)
return result;
if (state.backtracking == 0) {
if (isNotEOF())
helper.emit(Location.LOCATION_LHS_INSIDE_CONDITION_OPERATOR);
}
// src/main/resources/org/drools/compiler/lang/DRL5Expressions.g:234:13: (args= fullAnnotation[null] )?
int alt26 = 2;
int LA26_0 = input.LA(1);
if ((LA26_0 == AT)) {
alt26 = 1;
}
switch(alt26) {
case 1:
// src/main/resources/org/drools/compiler/lang/DRL5Expressions.g:234:13: args= fullAnnotation[null]
{
pushFollow(FOLLOW_fullAnnotation_in_conditionalAndExpression1213);
args = fullAnnotation(null);
state._fsp--;
if (state.failed)
return result;
}
break;
}
pushFollow(FOLLOW_inclusiveOrExpression_in_conditionalAndExpression1219);
right = inclusiveOrExpression();
state._fsp--;
if (state.failed)
return result;
if (state.backtracking == 0) {
if (buildDescr) {
ConstraintConnectiveDescr descr = ConstraintConnectiveDescr.newAnd();
descr.addOrMerge(result);
descr.addOrMerge(right);
if (args != null) {
descr.addAnnotation(args);
}
result = descr;
}
}
}
break;
default:
break loop27;
}
}
}
} catch (RecognitionException re) {
throw re;
} finally {
// do for sure before leaving
}
return result;
}
Aggregations