public void visit(ExpressionMethod part) { ExpressionMethod method = new ExpressionMethod(part.getName(), part.getClassType(), part.getGenericType(), part.getParametricType()); copyMethodParams(part, method); add(method); moveNext(part); }
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); }
@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()); } }
public static ExpressionPart getExpressionPartForMethod(SuggestionCompletionEngine sce, String factName, String methodName) { MethodInfo mi = sce.getMethodinfo(factName, methodName); if (SuggestionCompletionEngine.TYPE_COLLECTION.equals(mi.getGenericType())) { return new ExpressionCollection(methodName, mi.getReturnClassType(), mi.getGenericType(), mi.getParametricReturnType()); } return new ExpressionMethod(mi.getName(), mi.getReturnClassType(), mi.getGenericType()); }
public static ExpressionPart getExpressionPartForMethod(SuggestionCompletionEngine sce, String factName, String methodName) { MethodInfo mi = sce.getMethodinfo(factName, methodName); if (SuggestionCompletionEngine.TYPE_COLLECTION.equals(mi.getGenericType())) { return new ExpressionCollection(methodName, mi.getReturnClassType(), mi.getGenericType(), mi.getParametricReturnType()); } return new ExpressionMethod(mi.getName(), mi.getReturnClassType(), mi.getGenericType()); }
public void visit(ExpressionMethod part) { ExpressionMethod method = new ExpressionMethod(part.getName(), part.getClassType(), part.getGenericType(), part.getParametricType()); copyMethodParams(part, method); add(method); moveNext(part); }
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); }
@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 ) ); } }