Search in sources :

Example 11 with Expression

use of com.github.javaparser.ast.expr.Expression in project javaparser by javaparser.

the class XmlPrinterTest method testList.

@Test
public void testList() {
    Expression expression = JavaParser.parseExpression("a(1,2)");
    XmlPrinter xmlOutput = new XmlPrinter(true);
    String output = xmlOutput.output(expression);
    assertEquals("<root type='MethodCallExpr'><name type='SimpleName' identifier='a'></name><arguments><argument type='IntegerLiteralExpr' value='1'></argument><argument type='IntegerLiteralExpr' value='2'></argument></arguments></root>", output);
}
Also used : Expression(com.github.javaparser.ast.expr.Expression) Test(org.junit.Test)

Example 12 with Expression

use of com.github.javaparser.ast.expr.Expression in project javaparser by javaparser.

the class YamlPrinterTest method testWithType.

@Test
public void testWithType() {
    String expectedOutput = "---" + System.lineSeparator();
    expectedOutput += "root(Type=MethodCallExpr): " + System.lineSeparator();
    expectedOutput += "    name(Type=SimpleName): " + System.lineSeparator();
    expectedOutput += "        identifier: \"x\"" + System.lineSeparator();
    expectedOutput += "    arguments: " + System.lineSeparator();
    expectedOutput += "        - argument(Type=IntegerLiteralExpr): " + System.lineSeparator();
    expectedOutput += "            value: \"1\"" + System.lineSeparator();
    expectedOutput += "        - argument(Type=IntegerLiteralExpr): " + System.lineSeparator();
    expectedOutput += "            value: \"1\"" + System.lineSeparator();
    expectedOutput += "...";
    YamlPrinter yamlPrinter = new YamlPrinter(true);
    Expression expression = JavaParser.parseExpression("x(1,1)");
    String output = yamlPrinter.output(expression);
    assertEquals(expectedOutput, output);
}
Also used : Expression(com.github.javaparser.ast.expr.Expression) Test(org.junit.Test)

Example 13 with Expression

use of com.github.javaparser.ast.expr.Expression in project javaparser by javaparser.

the class YamlPrinterTest method testWithColonFollowedByLineSeparatorInValue.

@Test
public void testWithColonFollowedByLineSeparatorInValue() {
    String expectedOutput = "---" + System.lineSeparator();
    expectedOutput += "root(Type=StringLiteralExpr): " + System.lineSeparator();
    expectedOutput += "    value: \"a\\\\:\\\\nb\"" + System.lineSeparator();
    expectedOutput += "...";
    YamlPrinter yamlPrinter = new YamlPrinter(true);
    Expression expression = JavaParser.parseExpression("\"a\\\\:\\\\nb\"");
    String output = yamlPrinter.output(expression);
    assertEquals(expectedOutput, output);
}
Also used : Expression(com.github.javaparser.ast.expr.Expression) Test(org.junit.Test)

Example 14 with Expression

use of com.github.javaparser.ast.expr.Expression in project javaparser by javaparser.

the class YamlPrinterTest method testWithoutType.

@Test
public void testWithoutType() {
    String expectedOutput = "---" + System.lineSeparator();
    expectedOutput += "root: " + System.lineSeparator();
    expectedOutput += "    operator: \"PLUS\"" + System.lineSeparator();
    expectedOutput += "    left: " + System.lineSeparator();
    expectedOutput += "        value: \"1\"" + System.lineSeparator();
    expectedOutput += "    right: " + System.lineSeparator();
    expectedOutput += "        value: \"1\"" + System.lineSeparator();
    expectedOutput += "...";
    YamlPrinter yamlPrinter = new YamlPrinter(false);
    Expression expression = JavaParser.parseExpression("1+1");
    String output = yamlPrinter.output(expression);
    assertEquals(expectedOutput, output);
}
Also used : Expression(com.github.javaparser.ast.expr.Expression) Test(org.junit.Test)

Example 15 with Expression

use of com.github.javaparser.ast.expr.Expression in project javaparser by javaparser.

the class Issue144 method issue144.

@Test(expected = UnsolvedSymbolException.class)
public void issue144() {
    CompilationUnit cu = parseSampleWithStandardExtension("issue144/HelloWorld");
    ClassOrInterfaceDeclaration clazz = Navigator.demandClass(cu, "HelloWorld");
    ExpressionStmt expressionStmt = (ExpressionStmt) clazz.getMethodsByName("main").get(0).getBody().get().getStatement(0);
    MethodCallExpr methodCallExpr = (MethodCallExpr) expressionStmt.getExpression();
    Expression firstParameter = methodCallExpr.getArgument(0);
    JavaParserFacade javaParserFacade = JavaParserFacade.get(typeSolver);
    javaParserFacade.solve(firstParameter).isSolved();
}
Also used : CompilationUnit(com.github.javaparser.ast.CompilationUnit) ClassOrInterfaceDeclaration(com.github.javaparser.ast.body.ClassOrInterfaceDeclaration) Expression(com.github.javaparser.ast.expr.Expression) JavaParserFacade(com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade) ExpressionStmt(com.github.javaparser.ast.stmt.ExpressionStmt) MethodCallExpr(com.github.javaparser.ast.expr.MethodCallExpr) AbstractResolutionTest(com.github.javaparser.symbolsolver.resolution.AbstractResolutionTest) Test(org.junit.Test)

Aggregations

Expression (com.github.javaparser.ast.expr.Expression)429 Test (org.junit.Test)166 MethodCallExpr (com.github.javaparser.ast.expr.MethodCallExpr)149 NameExpr (com.github.javaparser.ast.expr.NameExpr)135 BlockStmt (com.github.javaparser.ast.stmt.BlockStmt)94 MethodDeclaration (com.github.javaparser.ast.body.MethodDeclaration)90 DrlxExpression (org.drools.mvel.parser.ast.expr.DrlxExpression)84 ObjectCreationExpr (com.github.javaparser.ast.expr.ObjectCreationExpr)73 StringLiteralExpr (com.github.javaparser.ast.expr.StringLiteralExpr)71 NodeList (com.github.javaparser.ast.NodeList)66 DrlxParser.parseExpression (org.drools.mvel.parser.DrlxParser.parseExpression)61 TypedExpression (org.drools.modelcompiler.builder.generator.TypedExpression)53 CompilationUnit (com.github.javaparser.ast.CompilationUnit)51 VariableDeclarator (com.github.javaparser.ast.body.VariableDeclarator)50 BinaryExpr (com.github.javaparser.ast.expr.BinaryExpr)49 ClassOrInterfaceType (com.github.javaparser.ast.type.ClassOrInterfaceType)49 NullLiteralExpr (com.github.javaparser.ast.expr.NullLiteralExpr)46 ClassOrInterfaceDeclaration (com.github.javaparser.ast.body.ClassOrInterfaceDeclaration)44 List (java.util.List)44 ExpressionStmt (com.github.javaparser.ast.stmt.ExpressionStmt)43