Search in sources :

Example 1 with JavaParserClassDeclaration

use of com.github.javaparser.symbolsolver.javaparsermodel.declarations.JavaParserClassDeclaration in project javaparser by javaparser.

the class DifferentiateDotExpressionTest method staticMethodCallsFromInnerClasses.

@Test
public void staticMethodCallsFromInnerClasses() {
    ClassOrInterfaceDeclaration clazz = ((JavaParserClassDeclaration) typeSolver.solveType("InnerClassDotExpressions")).getWrappedNode();
    MethodDeclaration mainMethod = Navigator.demandMethod(clazz, "main");
    JavaParserFacade javaParserFacade = JavaParserFacade.get(typeSolver);
    MethodCallExpr methodCall = Navigator.findMethodCall(mainMethod, "methodCall").get();
    MethodCallExpr innerMethodCall = Navigator.findMethodCall(mainMethod, "innerMethodCall").get();
    MethodCallExpr innerInnerMethodCall = Navigator.findMethodCall(mainMethod, "innerInnerMethodCall").get();
    assertEquals(true, javaParserFacade.solve(methodCall).isSolved());
    assertEquals(true, javaParserFacade.solve(innerMethodCall).isSolved());
    assertEquals(true, javaParserFacade.solve(innerInnerMethodCall).isSolved());
}
Also used : JavaParserClassDeclaration(com.github.javaparser.symbolsolver.javaparsermodel.declarations.JavaParserClassDeclaration) ClassOrInterfaceDeclaration(com.github.javaparser.ast.body.ClassOrInterfaceDeclaration) MethodDeclaration(com.github.javaparser.ast.body.MethodDeclaration) MethodCallExpr(com.github.javaparser.ast.expr.MethodCallExpr) AbstractResolutionTest(com.github.javaparser.symbolsolver.resolution.AbstractResolutionTest) Test(org.junit.Test)

Example 2 with JavaParserClassDeclaration

use of com.github.javaparser.symbolsolver.javaparsermodel.declarations.JavaParserClassDeclaration in project javaparser by javaparser.

the class DifferentiateDotExpressionTest method staticFieldCallsFromInnerClasses.

@Test
public void staticFieldCallsFromInnerClasses() {
    ClassOrInterfaceDeclaration clazz = ((JavaParserClassDeclaration) typeSolver.solveType("InnerStaticClassFieldDotExpressions")).getWrappedNode();
    MethodDeclaration mainMethod = Navigator.demandMethod(clazz, "main");
    JavaParserFacade javaParserFacade = JavaParserFacade.get(typeSolver);
    MethodCallExpr methodCallWithNestedStaticFieldParam = Navigator.findMethodCall(mainMethod, "parseInt").get();
    assertEquals(true, javaParserFacade.solve(methodCallWithNestedStaticFieldParam).isSolved());
}
Also used : JavaParserClassDeclaration(com.github.javaparser.symbolsolver.javaparsermodel.declarations.JavaParserClassDeclaration) ClassOrInterfaceDeclaration(com.github.javaparser.ast.body.ClassOrInterfaceDeclaration) MethodDeclaration(com.github.javaparser.ast.body.MethodDeclaration) MethodCallExpr(com.github.javaparser.ast.expr.MethodCallExpr) AbstractResolutionTest(com.github.javaparser.symbolsolver.resolution.AbstractResolutionTest) Test(org.junit.Test)

Example 3 with JavaParserClassDeclaration

use of com.github.javaparser.symbolsolver.javaparsermodel.declarations.JavaParserClassDeclaration in project javaparser by javaparser.

the class Issue1364 method setup.

@Before
public void setup() {
    ClassOrInterfaceDeclaration fakeObject = new ClassOrInterfaceDeclaration();
    fakeObject.setName(new SimpleName("java.lang.Object"));
    TypeSolver typeSolver = new TypeSolver() {

        @Override
        public TypeSolver getParent() {
            return null;
        }

        @Override
        public void setParent(TypeSolver parent) {
        }

        @Override
        public SymbolReference<ResolvedReferenceTypeDeclaration> tryToSolveType(String name) {
            if ("java.lang.Object".equals(name)) {
                // custom handling
                return SymbolReference.solved(new JavaParserClassDeclaration(fakeObject, this));
            }
            return SymbolReference.unsolved(ResolvedReferenceTypeDeclaration.class);
        }
    };
    ParserConfiguration config = new ParserConfiguration();
    config.setSymbolResolver(new JavaSymbolSolver(typeSolver));
    javaParser = new JavaParser(config);
}
Also used : JavaParser(com.github.javaparser.JavaParser) ResolvedReferenceTypeDeclaration(com.github.javaparser.resolution.declarations.ResolvedReferenceTypeDeclaration) JavaParserClassDeclaration(com.github.javaparser.symbolsolver.javaparsermodel.declarations.JavaParserClassDeclaration) ClassOrInterfaceDeclaration(com.github.javaparser.ast.body.ClassOrInterfaceDeclaration) TypeSolver(com.github.javaparser.symbolsolver.model.resolution.TypeSolver) SimpleName(com.github.javaparser.ast.expr.SimpleName) ParserConfiguration(com.github.javaparser.ParserConfiguration) Before(org.junit.Before)

Example 4 with JavaParserClassDeclaration

use of com.github.javaparser.symbolsolver.javaparsermodel.declarations.JavaParserClassDeclaration in project javaparser by javaparser.

the class Issue113 method issue113superClassIsResolvedCorrectly.

@Test
public void issue113superClassIsResolvedCorrectly() throws FileNotFoundException {
    String pathToSourceFile = adaptPath("src/test/resources/issue113/com/foo/Widget.java");
    CompilationUnit cu = JavaParser.parse(new File(pathToSourceFile));
    JavaParserClassDeclaration jssExtendedWidget = new JavaParserClassDeclaration(cu.getClassByName("Widget").get(), typeSolver);
    ResolvedReferenceType superClass = jssExtendedWidget.getSuperClass();
    assertEquals("com.foo.base.Widget", superClass.getQualifiedName());
}
Also used : CompilationUnit(com.github.javaparser.ast.CompilationUnit) JavaParserClassDeclaration(com.github.javaparser.symbolsolver.javaparsermodel.declarations.JavaParserClassDeclaration) ResolvedReferenceType(com.github.javaparser.resolution.types.ResolvedReferenceType) File(java.io.File) Test(org.junit.Test)

Example 5 with JavaParserClassDeclaration

use of com.github.javaparser.symbolsolver.javaparsermodel.declarations.JavaParserClassDeclaration in project javaparser by javaparser.

the class SymbolSolverTest method testSolveSymbolUnexisting.

@Test
public void testSolveSymbolUnexisting() {
    JavaParserClassDeclaration constructorDeclaration = (JavaParserClassDeclaration) typeSolverNewCode.solveType("com.github.javaparser.ast.body.ConstructorDeclaration");
    SymbolReference<? extends ResolvedValueDeclaration> res = symbolSolver.solveSymbolInType(constructorDeclaration, "unexisting");
    assertEquals(false, res.isSolved());
}
Also used : JavaParserClassDeclaration(com.github.javaparser.symbolsolver.javaparsermodel.declarations.JavaParserClassDeclaration) AbstractTest(com.github.javaparser.symbolsolver.AbstractTest) Test(org.junit.Test)

Aggregations

JavaParserClassDeclaration (com.github.javaparser.symbolsolver.javaparsermodel.declarations.JavaParserClassDeclaration)13 Test (org.junit.Test)12 ClassOrInterfaceDeclaration (com.github.javaparser.ast.body.ClassOrInterfaceDeclaration)5 MethodDeclaration (com.github.javaparser.ast.body.MethodDeclaration)4 MethodCallExpr (com.github.javaparser.ast.expr.MethodCallExpr)4 ResolvedReferenceType (com.github.javaparser.resolution.types.ResolvedReferenceType)4 AbstractTest (com.github.javaparser.symbolsolver.AbstractTest)4 AbstractResolutionTest (com.github.javaparser.symbolsolver.resolution.AbstractResolutionTest)4 MethodUsage (com.github.javaparser.resolution.MethodUsage)3 JavaParser (com.github.javaparser.JavaParser)1 ParserConfiguration (com.github.javaparser.ParserConfiguration)1 CompilationUnit (com.github.javaparser.ast.CompilationUnit)1 SimpleName (com.github.javaparser.ast.expr.SimpleName)1 ResolvedReferenceTypeDeclaration (com.github.javaparser.resolution.declarations.ResolvedReferenceTypeDeclaration)1 TypeSolver (com.github.javaparser.symbolsolver.model.resolution.TypeSolver)1 File (java.io.File)1 Before (org.junit.Before)1