public Object clone() { PatternDescr clone = new PatternDescr( this.objectType, this.identifier ); clone.setQuery( this.query ); clone.setUnification( unification ); clone.setLeftParentCharacter( this.leftParentCharacter ); clone.setRightParentCharacter( this.rightParentCharacter ); clone.setSource( this.source ); clone.setStartCharacter( this.getStartCharacter() ); clone.setEndCharacter( this.getEndCharacter() ); clone.setLocation( this.getLine(), this.getColumn() ); clone.setEndLocation( this.getEndLine(), this.getEndColumn() ); clone.setText( this.getText() ); for ( BaseDescr constraint : this.getDescrs() ) { clone.addConstraint( constraint ); } if ( behaviors != null ) { for ( BehaviorDescr behavior : behaviors ) { clone.addBehavior( behavior ); } } return clone; }
public void visitPatternDescr(final PatternDescr descr) { this.patternContext = true; this.template = new String(); StringBuilder localString = new StringBuilder(); if ( descr.getDescrs() != Collections.EMPTY_LIST ) { if ( descr.getIdentifier() != null ) { localString.append( "<pattern identifier=\"" + descr.getIdentifier() + "\" object-type=\"" + descr.getObjectType() + "\" >" + XmlDumper.eol + processDescrList( descr.getDescrs() ) + XmlDumper.eol ); } else { localString.append( "<pattern object-type=\"" + descr.getObjectType() + "\" >" + XmlDumper.eol + processDescrList( descr.getDescrs() ) + XmlDumper.eol ); } } else { if ( descr.getIdentifier() != null ) { localString.append( "<pattern identifier=\"" + descr.getIdentifier() + "\" object-type=\"" + descr.getObjectType() + "\" >" + XmlDumper.eol );; } else { localString.append( "<pattern object-type=\"" + descr.getObjectType() + "\" >" + XmlDumper.eol ); } } if ( descr.getSource() != null ) { visit( descr.getSource() ); localString.append( this.template ); } localString.append( "</pattern>" + XmlDumper.eol ); this.template = localString.toString(); this.patternContext = false; }
public AnnotationDescrBuilder<PatternDescrBuilder<P>> newAnnotation(String name) { AnnotationDescrBuilder<PatternDescrBuilder<P>> annotation = new AnnotationDescrBuilderImpl<PatternDescrBuilder<P>>( this, name ); descr.addAnnotation( annotation.getDescr() ); return annotation; } }
public String toString() { return "[Collect: input=" + this.inputPattern.getIdentifier() + "; objectType=" + this.inputPattern.getObjectType() + "]"; }
/** * Returns the base pattern from the forall CE * @return */ public PatternDescr getBasePattern() { if ( this.patterns.size() > 1 ) { return (PatternDescr) this.patterns.get( 0 ); } else if ( this.patterns.size() == 1 ) { // in case there is only one pattern, we do a rewrite, so: // forall( Cheese( type == "stilton" ) ) // becomes // forall( BASE_IDENTIFIER : Cheese() Cheese( this == BASE_IDENTIFIER, type == "stilton" ) ) PatternDescr original = (PatternDescr) this.patterns.get( 0 ); PatternDescr base = (PatternDescr) original.clone(); base.getDescrs().clear(); base.setIdentifier( BASE_IDENTIFIER ); return base; } return null; }
if ( patternDescr.getObjectType() == null || patternDescr.getObjectType().equals( "" ) ) { context.addError(new DescrBuildError(context.getParentDescr(), patternDescr, final FactTemplate factTemplate = context.getPkg().getFactTemplate( patternDescr.getObjectType() ); } else { try { final Class< ? > userProvidedClass = context.getDialect().getTypeResolver().resolveType( patternDescr.getObjectType() ); if ( !Modifier.isPublic(userProvidedClass.getModifiers()) ) { context.addError(new DescrBuildError(context.getParentDescr(), patternDescr, null, "The class '" + patternDescr.getObjectType() + "' is not public")); return null; if ( context.getRule().getName().equals( patternDescr.getObjectType() ) ) { Rule rule = context.getPkg().getRule( patternDescr.getObjectType() ); if ( rule instanceof Query ) { PackageRegistry pkgReg = context.getPackageBuilder().getPackageRegistry( pkgName ); if ( pkgReg != null ) { rule = pkgReg.getPackage().getRule( patternDescr.getObjectType() ); if ( rule instanceof Query ) { patternDescr, null, "Unable to resolve ObjectType '" + patternDescr.getObjectType() + "'"));
TypeFieldDescr inheritedFlDescr = new TypeFieldDescr( name, new PatternDescr( inspector.getFieldTypes().get( name ).getName() ) ); inheritedFlDescr.setInherited( !Modifier.isAbstract( inspector.getGetterMethods().get( name ).getModifiers() ) ); String type1 = fieldMap.get( fieldName ).getPattern().getObjectType(); String type2 = typeDescr.getFields().get( fieldName ).getPattern().getObjectType(); if (type2.lastIndexOf( "." ) < 0) { try { type2 = typeResolver.resolveType(type2).getName(); fieldMap.get( fieldName ).getPattern().setObjectType( type1 ); typeDescr.getFields().get( fieldName ).getPattern().setObjectType( type2 ); } catch ( ClassNotFoundException cnfe ) {
public int compareTo(TypeDeclarationDescr descr) { if ( ! this.getSuperTypes().isEmpty() && ! descr.getSuperTypes().isEmpty() ) { for ( QualifiedName q : descr.getSuperTypes() ) { if ( this.getSuperTypes().contains( q ) ) { return -1; } } for ( QualifiedName q : this.getSuperTypes() ) { if ( descr.getSuperTypes().contains( q ) ) { return +1; } } } for ( TypeFieldDescr field : this.getFields().values() ) { if ( descr.getTypeName().equals( field.getPattern().getObjectType() ) ) { return -1; } } for ( TypeFieldDescr field : descr.getFields().values() ) { if ( this.getTypeName().equals( field.getPattern().getObjectType() ) ) { return +1; } } return 0; } }
protected PatternDescrBuilderImpl(P parent, String type) { super( parent, new PatternDescr( type ) ); this.parent = parent; }
private void fillFieldTypes( AbstractClassTypeDeclarationDescr typeDescr, PackageDescr packageDescr ) { for (TypeFieldDescr field : typeDescr.getFields().values()) { String declaredType = field.getPattern().getObjectType(); if (declaredType != null) { int separator = declaredType.lastIndexOf( "." ); boolean qualified = separator > 0; // check if a simple name corresponds to a f.q.n. if (!qualified) { declaredType = resolveType( declaredType, packageDescr, this.pkgRegistryMap.get( typeDescr.getNamespace() ) ); field.getPattern().setObjectType( declaredType ); } } } }
protected TypeFieldDescr buildInheritedFieldDescrFromDefinition( FactField fld, TypeDeclarationDescr typeDescr ) { PatternDescr fldType = new PatternDescr(); TypeFieldDescr inheritedFldDescr = new TypeFieldDescr(); inheritedFldDescr.setFieldName( fld.getName() ); fldType.setObjectType( ( (FieldDefinition) fld ).getFieldAccessor().getExtractToClassName() ); inheritedFldDescr.setPattern( fldType ); if ( fld.isKey() ) { inheritedFldDescr.getAnnotations().put( TypeDeclaration.ATTR_KEY, new AnnotationDescr( TypeDeclaration.ATTR_KEY ) ); } 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() ) { AnnotationDescr ann = localField.getAnnotation( "Alias" ); if ( ann != null && fld.getName().equals( ann.getSingleValue().replaceAll( "\"", "" ) ) && localField.getInitExpr() != null ) { overrideCount++; initExprOverride = localField.getInitExpr(); } } if ( overrideCount > 1 ) { // however, only one is allowed initExprOverride = null; } inheritedFldDescr.setInitExpr( initExprOverride ); return inheritedFldDescr; }
public PatternDescrBuilder<P> constraint( String constraint, boolean positional ) { ExprConstraintDescr constr = new ExprConstraintDescr( constraint ); constr.setType( positional ? ExprConstraintDescr.Type.POSITIONAL : ExprConstraintDescr.Type.NAMED ); constr.setPosition( descr.getConstraint().getDescrs().size() ); descr.addConstraint( constr ); return this; }
/** * Returns the remaining patterns from the forall CE * @return */ public List<BaseDescr> getRemainingPatterns() { if ( this.patterns.size() > 1 ) { return this.patterns.subList( 1, this.patterns.size() ); } else if ( this.patterns.size() == 1 ) { // in case there is only one pattern, we do a rewrite, so: // forall( Cheese( type == "stilton" ) ) // becomes // forall( BASE_IDENTIFIER : Cheese() Cheese( this == BASE_IDENTIFIER, type == "stilton" ) ) PatternDescr original = (PatternDescr) this.patterns.get( 0 ); PatternDescr remaining = (PatternDescr) original.clone(); remaining.addConstraint( new ExprConstraintDescr( "this == " + BASE_IDENTIFIER ) ); return Collections.singletonList( (BaseDescr)remaining ); } return Collections.emptyList(); }
public PatternDescrBuilder<P> bind( String var, String target, boolean isUnification ) { descr.addConstraint( new BindingDescr( var, target, isUnification ) ); return this; }
protected BehaviorDescrBuilderImpl(P parent) { super( parent, new BehaviorDescr() ); this.parent.getDescr().addBehavior( descr ); }
protected void processAnnotations( final RuleBuildContext context, final PatternDescr patternDescr, final Pattern pattern ) { Map<String, AnnotationDescr> annotationMap = patternDescr.getAnnotations(); if (annotationMap == null) return; processListenedPropertiesAnnotation(context, patternDescr, pattern, annotationMap); processMetadataAnnotations( pattern, annotationMap ); }
QualifiedName typeName = new QualifiedName( field.getPattern().getObjectType() ); if ( ! hasCircularDependency( name, typeName, taxonomy ) ) { supers.add( typeName );
public FieldDescrBuilder type( String type ) { descr.setPattern( new PatternDescr( type ) ); return this; }
public PatternDescrBuilder<P> constraint( String constraint ) { ExprConstraintDescr constr = new ExprConstraintDescr( constraint ); constr.setType( ExprConstraintDescr.Type.NAMED ); constr.setPosition( descr.getConstraint().getDescrs().size() ); descr.addConstraint( constr ); return this; }
public Object end(final String uri, final String localName, final ExtensibleXmlParser parser) throws SAXException { final Element element = parser.endElementBuilder(); final String expression =((org.w3c.dom.Text)element.getChildNodes().item( 0 )).getWholeText(); if ( expression == null || expression.trim().equals( "" ) ) { throw new SAXParseException( "<predicate> must have some content", parser.getLocator() ); } final PatternDescr patternDescr = (PatternDescr) parser.getParent(); ExprConstraintDescr expr = new ExprConstraintDescr("eval(" + expression + ")"); patternDescr.addConstraint( expr ); return expr; }