Search in sources :

Example 46 with CompilationUnit

use of com.github.javaparser.ast.CompilationUnit in project javaparser by javaparser.

the class JavaParserAPIIntegrationTest method parameterDeclarationResolve.

@Test
public void parameterDeclarationResolve() throws IOException {
    File f = adaptPath(new File("src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/CompilationUnit.java"));
    ParserConfiguration parserConfiguration = new ParserConfiguration();
    parserConfiguration.setSymbolResolver(new JavaSymbolSolver(typeSolver));
    CompilationUnit cu = new JavaParser(parserConfiguration).parse(ParseStart.COMPILATION_UNIT, new StreamProvider(new FileInputStream(f))).getResult().get();
    ClassOrInterfaceDeclaration classDeclaration = (ClassOrInterfaceDeclaration) cu.getType(0);
    assertEquals("CompilationUnit", classDeclaration.getNameAsString());
    MethodDeclaration methodDeclaration = classDeclaration.getMethodsByName("setComments").get(0);
    Parameter declaration = methodDeclaration.getParameter(0);
    ResolvedParameterDeclaration resolvedDeclaration = declaration.resolve();
}
Also used : CompilationUnit(com.github.javaparser.ast.CompilationUnit) JavaParser(com.github.javaparser.JavaParser) StreamProvider(com.github.javaparser.StreamProvider) File(java.io.File) FileInputStream(java.io.FileInputStream) ParserConfiguration(com.github.javaparser.ParserConfiguration) Test(org.junit.Test)

Example 47 with CompilationUnit

use of com.github.javaparser.ast.CompilationUnit in project javaparser by javaparser.

the class JavaParserAPIIntegrationTest method constructorDeclarationResolve.

@Test
public void constructorDeclarationResolve() throws IOException {
    File f = adaptPath(new File("src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/CompilationUnit.java"));
    CompilationUnit cu = parseWithSymbolResolution(f);
    ClassOrInterfaceDeclaration classOrInterfaceDeclaration = (ClassOrInterfaceDeclaration) cu.getType(0);
    ConstructorDeclaration constructorDeclaration = classOrInterfaceDeclaration.getDefaultConstructor().get();
    ResolvedConstructorDeclaration resolvedConstructorDeclaration = constructorDeclaration.resolve();
}
Also used : CompilationUnit(com.github.javaparser.ast.CompilationUnit) File(java.io.File) Test(org.junit.Test)

Example 48 with CompilationUnit

use of com.github.javaparser.ast.CompilationUnit in project javaparser by javaparser.

the class JavaParserAPIIntegrationTest method classDeclarationResolve.

@Test
public void classDeclarationResolve() throws IOException {
    File f = adaptPath(new File("src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/CompilationUnit.java"));
    CompilationUnit cu = parseWithSymbolResolution(f);
    ClassOrInterfaceDeclaration declaration = (ClassOrInterfaceDeclaration) cu.getType(0);
    declaration.resolve();
}
Also used : CompilationUnit(com.github.javaparser.ast.CompilationUnit) File(java.io.File) Test(org.junit.Test)

Example 49 with CompilationUnit

use of com.github.javaparser.ast.CompilationUnit 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)

Example 50 with CompilationUnit

use of com.github.javaparser.ast.CompilationUnit in project javaparser by javaparser.

the class Issue144 method issue144WithReflectionTypeSolver.

@Test
public void issue144WithReflectionTypeSolver() {
    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 ReflectionTypeSolver(true));
    assertEquals(true, 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) ReflectionTypeSolver(com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver) 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

CompilationUnit (com.github.javaparser.ast.CompilationUnit)489 Test (org.junit.Test)304 ClassOrInterfaceDeclaration (com.github.javaparser.ast.body.ClassOrInterfaceDeclaration)160 MethodDeclaration (com.github.javaparser.ast.body.MethodDeclaration)140 ReflectionTypeSolver (com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver)128 AbstractResolutionTest (com.github.javaparser.symbolsolver.resolution.AbstractResolutionTest)101 MethodCallExpr (com.github.javaparser.ast.expr.MethodCallExpr)70 ResolvedType (com.github.javaparser.resolution.types.ResolvedType)66 Context (com.github.javaparser.symbolsolver.core.resolution.Context)62 TypeSolver (com.github.javaparser.symbolsolver.model.resolution.TypeSolver)55 CompilationUnitContext (com.github.javaparser.symbolsolver.javaparsermodel.contexts.CompilationUnitContext)51 JavaParserFacade (com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade)45 File (java.io.File)39 Expression (com.github.javaparser.ast.expr.Expression)38 ClassOrInterfaceDeclarationContext (com.github.javaparser.symbolsolver.javaparsermodel.contexts.ClassOrInterfaceDeclarationContext)38 MethodUsage (com.github.javaparser.resolution.MethodUsage)34 MemoryTypeSolver (com.github.javaparser.symbolsolver.resolution.typesolvers.MemoryTypeSolver)33 AbstractTest (com.github.javaparser.symbolsolver.AbstractTest)29 CombinedTypeSolver (com.github.javaparser.symbolsolver.resolution.typesolvers.CombinedTypeSolver)29 ArrayList (java.util.ArrayList)29