private ExpressionFormLine visitExpressionFormLine(ExpressionFormLine efl) { ExpressionFormLine clone = new ExpressionFormLine( efl ); clone.setBinding( efl.getBinding() ); return clone; }
public ExpressionFormLine(ExpressionPart part) { appendPart( part ); }
@Override public String getFieldType() { return getExpressionLeftSide().getClassType(); }
private String paramsToString(Map<String, ExpressionFormLine> params) { if ( params.isEmpty() ) { return ""; } ToStringVisitor stringVisitor = new ToStringVisitor(); StringBuilder strParams = new StringBuilder(); for ( ExpressionFormLine param : params.values() ) { strParams.append( ", " ).append( stringVisitor.buildString( param.getBinding(), param.getRootExpression() ) ); } return strParams.substring( 2 ); }
public ExpressionFormLine(ExpressionFormLine other) { CopyExpressionVisitor copier = new CopyExpressionVisitor(); if ( other.getParts().size() == 0 ) { return; } for ( ExpressionPart exp = copier.copy( other.getRootExpression() ); exp != null; exp = exp.getNext() ) { parts.add( exp ); } }
ExpressionFormLine eflhs0 = new ExpressionFormLine(); eflhs0.setBinding( "$eflhs0" ); ExpressionText eflhs0p0 = new ExpressionText( "eflhs0p0" ); eflhs0.appendPart( eflhs0p0 ); sfc0.setExpressionLeftSide( eflhs0 ); ExpressionFormLine efl0 = new ExpressionFormLine(); efl0.setBinding( "$efl0" ); ExpressionText efl0p0 = new ExpressionText( "efl0p0" ); efl0.appendPart( efl0p0 ); sfc0.setExpressionValue( efl0 ); sfc0Clone.getExpressionLeftSide().getParts().size() ); assertTrue( sfc0Clone.getExpressionLeftSide().getParts().get( 0 ) instanceof ExpressionText ); ExpressionText eflhs0p0Clone = (ExpressionText) sfc0Clone.getExpressionLeftSide().getParts().get( 0 ); assertEquals( eflhs0p0.getClassType(), eflhs0p0Clone.getClassType() ); assertEquals( eflhs0.getBinding(), eflhs0Clone.getBinding() ); assertEquals( eflhs0.getClassType(), eflhs0Clone.getClassType() ); assertEquals( eflhs0.getFieldName(), eflhs0Clone.getFieldName() ); assertEquals( eflhs0.getGenericType(), eflhs0Clone.getGenericType() ); assertEquals( eflhs0.getParametricType(), eflhs0Clone.getParametricType() ); assertEquals( eflhs0.getCurrentName(),
@Test public void toStringText() { ExpressionFormLine efl = new ExpressionFormLine(); FactPattern fact = new FactPattern( "String" ); fact.setBoundName( "$v" ); efl.appendPart( new ExpressionVariable( fact ) ); efl.appendPart( new ExpressionMethod( "size", "int", SuggestionCompletionEngine.TYPE_NUMERIC_INTEGER ) ); assertEquals( "$v.size()", efl.getText() ); efl.setBinding( "$s" ); assertEquals( "$s: $v.size()", efl.getText( true ) ); } }
@Test public void testCopy() { ExpressionFormLine efl = new ExpressionFormLine(); FactPattern fp = new FactPattern(SuggestionCompletionEngine.TYPE_OBJECT); fp.setBoundName("$o"); efl.appendPart(new ExpressionVariable(fp)); ExpressionMethod em = new ExpressionMethod("aMethod", "aClass", "aType"); ExpressionFormLine param = new ExpressionFormLine(); param.appendPart(new ExpressionText("\"hello world\"")); em.putParam("hi", param); efl.appendPart(em); ExpressionCollectionIndex index = new ExpressionCollectionIndex("get", "aRetType", "aGeneric"); efl.appendPart(index); index = new ExpressionCollectionIndex("get2", "aRetType", "aGeneric"); efl.appendPart(index); System.out.println(efl.getText()); ExpressionFormLine copy = new ExpressionFormLine(efl); assertNotSame(efl, copy); assertEquals(efl.getText(), copy.getText()); for (ExpressionPart e1 = efl.getRootExpression(), e2 = copy.getRootExpression(); e1 != null; e1 = e1.getNext(), e2 = e2.getNext()) { assertNotSame(e1, e2); assertEquals(e1.getClass(), e2.getClass()); } }
protected List<String> getFieldBinding(FieldConstraint f) { List<String> result = new ArrayList<String>(); if ( f instanceof SingleFieldConstraint ) { SingleFieldConstraint con = (SingleFieldConstraint) f; if ( con.isBound() ) { result.add( con.getFieldBinding() ); } if ( con.getExpressionValue() != null && con.getExpressionValue().isBound() ) { result.add( con.getExpressionValue().getBinding() ); } if ( con instanceof SingleFieldConstraintEBLeftSide ) { SingleFieldConstraintEBLeftSide exp = (SingleFieldConstraintEBLeftSide) con; if ( exp.getExpressionLeftSide() != null && exp.getExpressionLeftSide().isBound() ) { result.add( exp.getExpressionLeftSide().getBinding() ); } } } else if ( f instanceof CompositeFieldConstraint ) { CompositeFieldConstraint cfc = (CompositeFieldConstraint) f; if ( cfc.constraints != null ) { for ( FieldConstraint ss : cfc.constraints ) { List<String> t = getFieldBinding( ss ); result.addAll( t ); } } } return result; }
/** * This adds a new connective. */ @Override public void addNewConnective() { String factType = getExpressionLeftSide().getPreviousGenericType(); if ( factType == null ) { factType = getExpressionLeftSide().getGenericType(); } String fieldName = getExpressionLeftSide().getFieldName(); String fieldType = getExpressionLeftSide().getGenericType(); if ( this.connectives == null ) { this.connectives = new ConnectiveConstraint[]{new ConnectiveConstraint( factType, fieldName, fieldType )}; } else { final ConnectiveConstraint[] newList = new ConnectiveConstraint[this.connectives.length + 1]; for ( int i = 0; i < this.connectives.length; i++ ) { newList[i] = this.connectives[i]; } newList[this.connectives.length] = new ConnectiveConstraint( factType, fieldName, fieldType ); this.connectives = newList; } }
private void visitSingleFieldConstraint(SingleFieldConstraintEBLeftSide sfexp) { String genericType = sfexp.getExpressionLeftSide().getGenericType(); String factType = sfexp.getExpressionLeftSide().getPreviousClassType(); if ( factType == null ) { factType = sfexp.getExpressionLeftSide().getClassType(); } InterpolationVariable var = new InterpolationVariable( sfexp.getValue(), genericType, factType, sfexp.getFieldName() ); if ( BaseSingleFieldConstraint.TYPE_TEMPLATE == sfexp.getConstraintValueType() && !vars.containsKey( var ) ) { vars.put( var, vars.size() ); } //Visit Connection constraints if ( sfexp.connectives != null ) { for ( int i = 0; i < sfexp.connectives.length; i++ ) { final ConnectiveConstraint cc = sfexp.connectives[i]; InterpolationVariable ccVar = new InterpolationVariable( cc.getValue(), genericType, factType, cc.getFieldName() ); if ( BaseSingleFieldConstraint.TYPE_TEMPLATE == cc.getConstraintValueType() && !vars.containsKey( ccVar ) ) { vars.put( ccVar, vars.size() ); } } } }
public String getText() { return getText( false ); }
buf.append( ( (SingleFieldConstraintEBLeftSide) constr ).getExpressionLeftSide().getText() ); } else { String fieldName = constr.getFieldName(); addFieldRestriction( buf, sfexp.getConstraintValueType(), sfexp.getExpressionLeftSide().getGenericType(), sfexp.getOperator(), parameters,
ExpressionFormLine efl0sfc0p0 = new ExpressionFormLine(); ExpressionField ef0sfc0p0 = new ExpressionField( "sfc0p0", "sfc0p0class", SuggestionCompletionEngine.TYPE_STRING ); efl0sfc0p0.appendPart( ef0sfc0p0 ); sfc0p0.setExpressionLeftSide( efl0sfc0p0 ); ExpressionFormLine efl0sfc1p0 = new ExpressionFormLine(); ExpressionField ef0sfc1p0 = new ExpressionField( "sfc1p0", "sfc1p0class", SuggestionCompletionEngine.TYPE_STRING ); efl0sfc1p0.appendPart( ef0sfc1p0 ); sfc1p0.setExpressionLeftSide( efl0sfc1p0 ); ExpressionFormLine efl0sfc0p1 = new ExpressionFormLine(); ExpressionField ef0sfc0p1 = new ExpressionField( "sfc0p1", "sfc0p1class", SuggestionCompletionEngine.TYPE_STRING ); efl0sfc0p1.appendPart( ef0sfc0p1 ); sfc0p1.setExpressionLeftSide( efl0sfc0p1 ); ExpressionFormLine efl0sfc1p1 = new ExpressionFormLine(); ExpressionField ef0sfc1p1 = new ExpressionField( "sfc1p1", "sfc1p1class", SuggestionCompletionEngine.TYPE_STRING ); efl0sfc1p1.appendPart( ef0sfc1p1 ); sfc1p1.setExpressionLeftSide( efl0sfc1p1 );
private void copyMethodParams(ExpressionMethod part, ExpressionMethod method) { Map<String, ExpressionFormLine> params = new HashMap<String, ExpressionFormLine>(); for (Map.Entry<String, ExpressionFormLine> entry : part.getParams().entrySet()) { params.put(entry.getKey(), new ExpressionFormLine(entry.getValue())); } method.setParams(params); }
@Override public String getFieldName() { return getExpressionLeftSide().getFieldName(); }
@Override public void setFieldBinding(String fieldBinding) { getExpressionLeftSide().setBinding( fieldBinding ); }
@Override public String getFieldBinding() { return getExpressionLeftSide().getBinding(); }
protected String getFieldBinding(FieldConstraint fc, String var) { String fieldType = null; if ( fc instanceof SingleFieldConstraint ) { SingleFieldConstraint s = (SingleFieldConstraint) fc; if ( s.isBound() && var.equals( s.getFieldBinding() ) ) { fieldType = s.getFieldType(); } } if ( fc instanceof SingleFieldConstraintEBLeftSide ) { SingleFieldConstraintEBLeftSide s = (SingleFieldConstraintEBLeftSide) fc; if ( s.isBound() && var.equals( s.getFieldBinding() ) ) { fieldType = s.getExpressionLeftSide().getGenericType(); } } if ( fc instanceof CompositeFieldConstraint ) { CompositeFieldConstraint s = (CompositeFieldConstraint) fc; if ( s.constraints != null ) { for ( FieldConstraint ss : s.constraints ) { fieldType = getFieldBinding( ss, var ); } } } return fieldType; }
ExpressionFormLine efl0 = new ExpressionFormLine(); efl0.setBinding( "$efl0" ); ExpressionText efl0p0 = new ExpressionText( "efl0p0" ); efl0.appendPart( efl0p0 ); fp0.setExpression( efl0 ); FactPattern fp0FactPattern = new FactPattern( "fp0FactPattern" ); fp0Clone.getExpression().getParts().size() ); assertTrue( fp0Clone.getExpression().getParts().get( 0 ) instanceof ExpressionText ); ExpressionText efl0p0Clone = (ExpressionText) fp0Clone.getExpression().getParts().get( 0 ); assertEquals( efl0p0.getClassType(), efl0p0Clone.getClassType() ); efl0p0Clone.getParametricType() ); assertEquals( efl0.getBinding(), efl0Clone.getBinding() ); assertEquals( efl0.getClassType(), efl0Clone.getClassType() ); assertEquals( efl0.getFieldName(), efl0Clone.getFieldName() ); assertEquals( efl0.getGenericType(), efl0Clone.getGenericType() ); assertEquals( efl0.getParametricType(), efl0Clone.getParametricType() ); assertEquals( efl0.getCurrentName(), efl0Clone.getCurrentName() );