use of com.github.javaparser.ast.stmt.ExpressionStmt in project javaparser by javaparser.
the class Issue251 method testSolveStaticallyImportedMemberType.
@Test
public void testSolveStaticallyImportedMemberType() {
CompilationUnit cu = parseSample("Issue251");
ClassOrInterfaceDeclaration cls = Navigator.demandClassOrInterface(cu, "Main");
TypeSolver typeSolver = new ReflectionTypeSolver();
JavaParserFacade javaParserFacade = JavaParserFacade.get(typeSolver);
MethodDeclaration m = Navigator.demandMethod(cls, "bar");
ExpressionStmt stmt = (ExpressionStmt) m.getBody().get().getStatements().get(1);
MethodCallExpr expression = (MethodCallExpr) stmt.getExpression();
Assert.assertNotNull(javaParserFacade.solve(expression));
}
use of com.github.javaparser.ast.stmt.ExpressionStmt in project javaparser by javaparser.
the class Issue144 method issue144WithCombinedTypeSolver.
@Test
public void issue144WithCombinedTypeSolver() {
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(new CombinedTypeSolver(typeSolver, new ReflectionTypeSolver(true)));
assertEquals(true, javaParserFacade.solve(firstParameter).isSolved());
}
use of com.github.javaparser.ast.stmt.ExpressionStmt in project javaparser by javaparser.
the class Issue116 method arrayTypeIsNotPartOfTheTree.
@Test
public void arrayTypeIsNotPartOfTheTree() {
CompilationUnit cu = parseSample("Issue116");
ClassOrInterfaceDeclaration clazz = Navigator.demandClass(cu, "JavaTest");
MethodDeclaration methodDeclaration = Navigator.demandMethod(clazz, "foo");
TypeSolver typeSolver = new ReflectionTypeSolver();
JavaParserFacade javaParserFacade = JavaParserFacade.get(typeSolver);
com.github.javaparser.ast.type.Type typeNode = methodDeclaration.getParameters().get(0).getType();
ResolvedType type = javaParserFacade.convert(typeNode, typeNode);
assertEquals("java.lang.String[]", type.describe());
ExpressionStmt expressionStmt = (ExpressionStmt) methodDeclaration.getBody().get().getStatements().get(0);
Expression argRef = expressionStmt.getExpression();
assertEquals("java.lang.String[]", javaParserFacade.getType(argRef).describe());
}
use of com.github.javaparser.ast.stmt.ExpressionStmt in project javaparser by javaparser.
the class Issue18 method typeDeclarationSuperClassImplicitlyIncludeObject.
@Test
public void typeDeclarationSuperClassImplicitlyIncludeObject() {
CompilationUnit cu = parseSample("Issue18");
ClassOrInterfaceDeclaration clazz = Navigator.demandClass(cu, "Foo");
MethodDeclaration methodDeclaration = Navigator.demandMethod(clazz, "bar");
ExpressionStmt expr = (ExpressionStmt) methodDeclaration.getBody().get().getStatements().get(1);
TypeSolver typeSolver = new ReflectionTypeSolver();
JavaParserFacade javaParserFacade = JavaParserFacade.get(typeSolver);
ResolvedType type = javaParserFacade.getType(expr.getExpression());
assertEquals("java.lang.Object", type.describe());
}
use of com.github.javaparser.ast.stmt.ExpressionStmt in project javaparser by javaparser.
the class Issue235 method issue235.
@Test
public void issue235() {
CompilationUnit cu = parseSample("Issue235");
ClassOrInterfaceDeclaration cls = Navigator.demandClassOrInterface(cu, "Foo");
TypeSolver typeSolver = new ReflectionTypeSolver();
JavaParserFacade javaParserFacade = JavaParserFacade.get(typeSolver);
MethodDeclaration m = Navigator.demandMethod(cls, this.method);
ExpressionStmt stmt = (ExpressionStmt) m.getBody().get().getStatements().get(0);
ObjectCreationExpr expression = (ObjectCreationExpr) stmt.getExpression();
Assert.assertNotNull(javaParserFacade.convertToUsage(expression.getType()));
}
Aggregations