Search in sources :

Example 6 with JavaParserClassDeclaration

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

the class MethodsResolutionLogicTest method compatibilityShouldConsiderAlsoTypeVariablesNegative.

@Test
public void compatibilityShouldConsiderAlsoTypeVariablesNegative() {
    JavaParserClassDeclaration constructorDeclaration = (JavaParserClassDeclaration) typeSolver.solveType("com.github.javaparser.ast.body.ConstructorDeclaration");
    ResolvedReferenceType stringType = (ResolvedReferenceType) ReflectionFactory.typeUsageFor(String.class, typeSolver);
    ResolvedReferenceType rawClassType = (ResolvedReferenceType) ReflectionFactory.typeUsageFor(Class.class, typeSolver);
    assertEquals(true, rawClassType.isRawType());
    ResolvedReferenceType classOfStringType = (ResolvedReferenceType) rawClassType.replaceTypeVariables(rawClassType.getTypeDeclaration().getTypeParameters().get(0), stringType);
    MethodUsage mu = constructorDeclaration.getAllMethods().stream().filter(m -> m.getDeclaration().getSignature().equals("isThrows(java.lang.Class<? extends java.lang.Throwable>)")).findFirst().get();
    assertEquals(false, MethodResolutionLogic.isApplicable(mu, "isThrows", ImmutableList.of(classOfStringType), typeSolver));
}
Also used : JavaParserClassDeclaration(com.github.javaparser.symbolsolver.javaparsermodel.declarations.JavaParserClassDeclaration) ResolvedReferenceType(com.github.javaparser.resolution.types.ResolvedReferenceType) MethodUsage(com.github.javaparser.resolution.MethodUsage) Test(org.junit.Test)

Example 7 with JavaParserClassDeclaration

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

the class MethodsResolutionLogicTest method compatibilityShouldConsiderAlsoTypeVariablesPositive.

@Test
public void compatibilityShouldConsiderAlsoTypeVariablesPositive() {
    JavaParserClassDeclaration constructorDeclaration = (JavaParserClassDeclaration) typeSolver.solveType("com.github.javaparser.ast.body.ConstructorDeclaration");
    ResolvedReferenceType runtimeException = (ResolvedReferenceType) ReflectionFactory.typeUsageFor(RuntimeException.class, typeSolver);
    ResolvedReferenceType rawClassType = (ResolvedReferenceType) ReflectionFactory.typeUsageFor(Class.class, typeSolver);
    ResolvedReferenceType classOfRuntimeType = (ResolvedReferenceType) rawClassType.replaceTypeVariables(rawClassType.getTypeDeclaration().getTypeParameters().get(0), runtimeException);
    MethodUsage mu = constructorDeclaration.getAllMethods().stream().filter(m -> m.getDeclaration().getSignature().equals("isThrows(java.lang.Class<? extends java.lang.Throwable>)")).findFirst().get();
    assertEquals(true, MethodResolutionLogic.isApplicable(mu, "isThrows", ImmutableList.of(classOfRuntimeType), typeSolver));
}
Also used : JavaParserClassDeclaration(com.github.javaparser.symbolsolver.javaparsermodel.declarations.JavaParserClassDeclaration) ResolvedReferenceType(com.github.javaparser.resolution.types.ResolvedReferenceType) MethodUsage(com.github.javaparser.resolution.MethodUsage) Test(org.junit.Test)

Example 8 with JavaParserClassDeclaration

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

the class SymbolSolverTest method testSolveSymbolToInheritedPublicField.

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

Example 9 with JavaParserClassDeclaration

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

the class SymbolSolverTest method testSolveSymbolToDeclaredField.

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

Example 10 with JavaParserClassDeclaration

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

the class SymbolSolverTest method testSolveSymbolToInheritedPrivateField.

@Test
public void testSolveSymbolToInheritedPrivateField() {
    JavaParserClassDeclaration constructorDeclaration = (JavaParserClassDeclaration) typeSolverNewCode.solveType("com.github.javaparser.ast.body.ConstructorDeclaration");
    SymbolReference<? extends ResolvedValueDeclaration> res = symbolSolver.solveSymbolInType(constructorDeclaration, "parentNode");
    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