JavaClassExpressionsPrettyPrinter extends CommonExpressionsPrettyPrinter implements JavaClassExpressionsVisitor { public String prettyprint(ASTExpression node) { getPrinter().clearBuffer(); node.accept(getRealThis()); return getPrinter().getContent(); } JavaClassExpressionsPrettyPrinter(IndentPrinter printer); @Override void visit(ASTPrimarySuperExpression node); @Override void handle(ASTSuperSuffix node); @Override void handle(ASTSuperExpression node); @Override void handle(ASTClassExpression node); @Override void handle(ASTTypeCastExpression node); @Override void handle(ASTGenericInvocationSuffix node); @Override void handle(ASTGenericInvocationExpression node); @Override void handle(ASTPrimaryGenericInvocationExpression node); @Override void handle(ASTInstanceofExpression node); @Override void handle(ASTThisExpression node); @Override void handle(ASTArrayExpression node); @Override void visit(ASTPrimaryThisExpression node); @Override void handle(ASTArrayCreator a); @Override void handle(ASTArrayDimensionByExpression a); @Override void handle(ASTCreatorExpression a); IndentPrinter getPrinter(); String prettyprint(ASTExpression node); String prettyprint(ASTGenericInvocationSuffix node); String prettyprint(ASTSuperSuffix node); @Override void setRealThis(JavaClassExpressionsVisitor realThis); @Override JavaClassExpressionsVisitor getRealThis();  }
@Test public void testPrimaryThisExpression() throws IOException { Optional<ASTPrimaryThisExpression> result = parser.parse_StringPrimaryThisExpression("this"); assertFalse(parser.hasErrors()); assertTrue(result.isPresent()); ASTPrimaryThisExpression ast = result.get(); String output = prettyPrinter.prettyprint(ast); result = parser.parse_StringPrimaryThisExpression(output); assertFalse(parser.hasErrors()); assertTrue(result.isPresent()); assertTrue(ast.deepEquals(result.get())); }
@Test public void testPrimarySuperExpression() throws IOException { Optional<ASTPrimarySuperExpression> result = parser.parse_StringPrimarySuperExpression("super"); assertFalse(parser.hasErrors()); assertTrue(result.isPresent()); ASTPrimarySuperExpression ast = result.get(); String output = prettyPrinter.prettyprint(ast); result = parser.parse_StringPrimarySuperExpression(output); assertFalse(parser.hasErrors()); assertTrue(result.isPresent()); assertTrue(ast.deepEquals(result.get())); }
@Test public void testTypeCaseExpression() throws IOException { Optional<ASTTypeCastExpression> result = parser.parse_StringTypeCastExpression("(Integer) a"); assertFalse(parser.hasErrors()); assertTrue(result.isPresent()); ASTTypeCastExpression ast = result.get(); String output = prettyPrinter.prettyprint(ast); assertEquals("()a", output); }
@Test public void testClassExpression() throws IOException { Optional<ASTClassExpression> result = parser.parse_StringClassExpression("Integer.class"); assertFalse(parser.hasErrors()); assertTrue(result.isPresent()); ASTClassExpression ast = result.get(); String output = prettyPrinter.prettyprint(ast); assertEquals(".class", output); }
@Test public void testPrimaryGenericInvocationExpressionExpression() throws IOException { Optional<ASTPrimaryGenericInvocationExpression> result = parser.parse_StringPrimaryGenericInvocationExpression("<Integer> super(a)"); assertFalse(parser.hasErrors()); assertTrue(result.isPresent()); ASTPrimaryGenericInvocationExpression ast = result.get(); String output = prettyPrinter.prettyprint(ast); assertEquals("<> super(a)", output); }
@Test public void testInstanceofExpression() throws IOException { Optional<ASTExpression> a = parser.parse_StringExpression("a"); Optional<ASTExtType> type = parser.parse_StringExtType("Integer"); assertFalse(parser.hasErrors()); assertTrue(a.isPresent()); assertTrue(type.isPresent()); ASTInstanceofExpression result = JavaClassExpressionsMill.instanceofExpressionBuilder() .setExpression(a.get()) .setExtType(type.get()) .build(); String output = prettyPrinter.prettyprint(result); assertEquals("a instanceof ", output); }
@Test public void testThisExpression() throws IOException { Optional<ASTExpression> a = parser.parse_StringExpression("a"); assertFalse(parser.hasErrors()); assertTrue(a.isPresent()); ASTThisExpression result = JavaClassExpressionsMill.thisExpressionBuilder() .setExpression(a.get()) .build(); String output = prettyPrinter.prettyprint(result); assertEquals("a.this", output); }
@Test public void testArrayExpression() throws IOException { Optional<ASTExpression> a = parser.parse_StringExpression("a"); Optional<ASTExpression> b = parser.parse_StringExpression("b"); assertFalse(parser.hasErrors()); assertTrue(a.isPresent()); assertTrue(b.isPresent()); ASTArrayExpression result = JavaClassExpressionsMill.arrayExpressionBuilder() .setExpression(a.get()) .setIndexExpression(b.get()) .build(); String output = prettyPrinter.prettyprint(result); assertEquals("a[b]", output); }
@Test public void testSuperExpression() throws IOException { Optional<ASTExpression> a = parser.parse_StringExpression("a"); Optional<ASTSuperSuffix> b = parser.parse_StringSuperSuffix("(b)"); assertFalse(parser.hasErrors()); assertTrue(a.isPresent()); assertTrue(b.isPresent()); ASTSuperExpression result = JavaClassExpressionsMill.superExpressionBuilder() .setExpression(a.get()) .setSuperSuffix(b.get()) .build(); String output = prettyPrinter.prettyprint(result); assertEquals("a.super(b)", output); }
@Test public void testGenericInvocationExpressionExpression() throws IOException { Optional<ASTExpression> a = parser.parse_StringExpression("a"); Optional<ASTPrimaryGenericInvocationExpression> b = parser.parse_StringPrimaryGenericInvocationExpression("<D> c(b)"); assertFalse(parser.hasErrors()); assertTrue(a.isPresent()); assertTrue(b.isPresent()); ASTGenericInvocationExpression result = JavaClassExpressionsMill.genericInvocationExpressionBuilder() .setExpression(a.get()) .setPrimaryGenericInvocationExpression(b.get()) .build(); String output = prettyPrinter.prettyprint(result); assertEquals("a.<> c(b)", output); }
@Test public void testGenericInvocationSuffixThis() throws IOException { Optional<ASTGenericInvocationSuffix> result = parser.parse_StringGenericInvocationSuffix("this(a)"); assertFalse(parser.hasErrors()); assertTrue(result.isPresent()); ASTGenericInvocationSuffix ast = result.get(); String output = prettyPrinter.prettyprint(ast); result = parser.parse_StringGenericInvocationSuffix(output); assertFalse(parser.hasErrors()); assertTrue(result.isPresent()); assertTrue(ast.deepEquals(result.get())); }
@Test public void testGenericInvocationSuffixSuper() throws IOException { Optional<ASTGenericInvocationSuffix> result = parser.parse_StringGenericInvocationSuffix("super(b)"); assertFalse(parser.hasErrors()); assertTrue(result.isPresent()); ASTGenericInvocationSuffix ast = result.get(); String output = prettyPrinter.prettyprint(ast); result = parser.parse_StringGenericInvocationSuffix(output); assertFalse(parser.hasErrors()); assertTrue(result.isPresent()); assertTrue(ast.deepEquals(result.get())); }
@Test public void testGenericInvocationSuffixSimple() throws IOException { Optional<ASTGenericInvocationSuffix> result = parser.parse_StringGenericInvocationSuffix("a(b)"); assertFalse(parser.hasErrors()); assertTrue(result.isPresent()); ASTGenericInvocationSuffix ast = result.get(); String output = prettyPrinter.prettyprint(ast); result = parser.parse_StringGenericInvocationSuffix(output); assertFalse(parser.hasErrors()); assertTrue(result.isPresent()); assertTrue(ast.deepEquals(result.get())); }
@Test public void testCreatorExpression() throws IOException { Optional<ASTCreatorExpression> result = parser.parse_StringCreatorExpression("new Integer(a,b)"); assertFalse(parser.hasErrors()); assertTrue(result.isPresent()); ASTCreatorExpression ast = result.get(); String output = prettyPrinter.prettyprint(ast); assertEquals(" new (a,b)", output); }
@Test public void testCreatorExpression2() throws IOException { Optional<ASTCreatorExpression> result = parser.parse_StringCreatorExpression("new double[a][]"); assertFalse(parser.hasErrors()); assertTrue(result.isPresent()); ASTCreatorExpression ast = result.get(); String output = prettyPrinter.prettyprint(ast); assertEquals(" new [a][]", output); }