Search in sources :

Example 6 with ResolvedMethodDeclaration

use of com.github.javaparser.resolution.declarations.ResolvedMethodDeclaration in project javaparser by javaparser.

the class ClassOrInterfaceDeclarationContextResolutionTest method solveMethodOverrideCase.

@Test
public void solveMethodOverrideCase() {
    CompilationUnit cu = parseSample("ClassWithMethods");
    ClassOrInterfaceDeclaration classOrInterfaceDeclaration = Navigator.demandClass(cu, "A");
    Context context = new ClassOrInterfaceDeclarationContext(classOrInterfaceDeclaration, typeSolver);
    SymbolReference<ResolvedMethodDeclaration> ref = context.solveMethod("foo1", ImmutableList.of(), false, new ReflectionTypeSolver());
    assertEquals(true, ref.isSolved());
    assertEquals("A", ref.getCorrespondingDeclaration().declaringType().getName());
    assertEquals(0, ref.getCorrespondingDeclaration().getNumberOfParams());
}
Also used : CompilationUnit(com.github.javaparser.ast.CompilationUnit) ClassOrInterfaceDeclarationContext(com.github.javaparser.symbolsolver.javaparsermodel.contexts.ClassOrInterfaceDeclarationContext) Context(com.github.javaparser.symbolsolver.core.resolution.Context) CompilationUnitContext(com.github.javaparser.symbolsolver.javaparsermodel.contexts.CompilationUnitContext) ClassOrInterfaceDeclaration(com.github.javaparser.ast.body.ClassOrInterfaceDeclaration) ClassOrInterfaceDeclarationContext(com.github.javaparser.symbolsolver.javaparsermodel.contexts.ClassOrInterfaceDeclarationContext) ReflectionTypeSolver(com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver) ResolvedMethodDeclaration(com.github.javaparser.resolution.declarations.ResolvedMethodDeclaration) AbstractResolutionTest(com.github.javaparser.symbolsolver.resolution.AbstractResolutionTest) Test(org.junit.Test)

Example 7 with ResolvedMethodDeclaration

use of com.github.javaparser.resolution.declarations.ResolvedMethodDeclaration in project javaparser by javaparser.

the class ClassOrInterfaceDeclarationContextResolutionTest method solveMethodInheritedCase.

@Test
public void solveMethodInheritedCase() {
    CompilationUnit cu = parseSample("ClassWithMethods");
    ClassOrInterfaceDeclaration classOrInterfaceDeclaration = Navigator.demandClass(cu, "A");
    Context context = new ClassOrInterfaceDeclarationContext(classOrInterfaceDeclaration, typeSolver);
    SymbolReference<ResolvedMethodDeclaration> ref = context.solveMethod("foo2", ImmutableList.of(), false, new ReflectionTypeSolver());
    assertEquals(true, ref.isSolved());
    assertEquals("Super", ref.getCorrespondingDeclaration().declaringType().getName());
    assertEquals(0, ref.getCorrespondingDeclaration().getNumberOfParams());
}
Also used : CompilationUnit(com.github.javaparser.ast.CompilationUnit) ClassOrInterfaceDeclarationContext(com.github.javaparser.symbolsolver.javaparsermodel.contexts.ClassOrInterfaceDeclarationContext) Context(com.github.javaparser.symbolsolver.core.resolution.Context) CompilationUnitContext(com.github.javaparser.symbolsolver.javaparsermodel.contexts.CompilationUnitContext) ClassOrInterfaceDeclaration(com.github.javaparser.ast.body.ClassOrInterfaceDeclaration) ClassOrInterfaceDeclarationContext(com.github.javaparser.symbolsolver.javaparsermodel.contexts.ClassOrInterfaceDeclarationContext) ReflectionTypeSolver(com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver) ResolvedMethodDeclaration(com.github.javaparser.resolution.declarations.ResolvedMethodDeclaration) AbstractResolutionTest(com.github.javaparser.symbolsolver.resolution.AbstractResolutionTest) Test(org.junit.Test)

Example 8 with ResolvedMethodDeclaration

use of com.github.javaparser.resolution.declarations.ResolvedMethodDeclaration in project javaparser by javaparser.

the class ClassOrInterfaceDeclarationContextResolutionTest method solveMethodWithAmbiguosCall.

@Test(expected = MethodAmbiguityException.class)
public void solveMethodWithAmbiguosCall() {
    CompilationUnit cu = parseSample("ClassWithMethods");
    ClassOrInterfaceDeclaration classOrInterfaceDeclaration = Navigator.demandClass(cu, "A");
    Context context = new ClassOrInterfaceDeclarationContext(classOrInterfaceDeclaration, typeSolver);
    SymbolReference<ResolvedMethodDeclaration> ref = context.solveMethod("foo5", ImmutableList.of(NullType.INSTANCE), false, new ReflectionTypeSolver());
}
Also used : CompilationUnit(com.github.javaparser.ast.CompilationUnit) ClassOrInterfaceDeclarationContext(com.github.javaparser.symbolsolver.javaparsermodel.contexts.ClassOrInterfaceDeclarationContext) Context(com.github.javaparser.symbolsolver.core.resolution.Context) CompilationUnitContext(com.github.javaparser.symbolsolver.javaparsermodel.contexts.CompilationUnitContext) ClassOrInterfaceDeclaration(com.github.javaparser.ast.body.ClassOrInterfaceDeclaration) ClassOrInterfaceDeclarationContext(com.github.javaparser.symbolsolver.javaparsermodel.contexts.ClassOrInterfaceDeclarationContext) ReflectionTypeSolver(com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver) ResolvedMethodDeclaration(com.github.javaparser.resolution.declarations.ResolvedMethodDeclaration) AbstractResolutionTest(com.github.javaparser.symbolsolver.resolution.AbstractResolutionTest) Test(org.junit.Test)

Example 9 with ResolvedMethodDeclaration

use of com.github.javaparser.resolution.declarations.ResolvedMethodDeclaration in project javaparser by javaparser.

the class ClassOrInterfaceDeclarationContextResolutionTest method solveMethodWithPrimitiveParameters.

@Test
public void solveMethodWithPrimitiveParameters() {
    CompilationUnit cu = parseSample("ClassWithMethods");
    ClassOrInterfaceDeclaration classOrInterfaceDeclaration = Navigator.demandClass(cu, "A");
    Context context = new ClassOrInterfaceDeclarationContext(classOrInterfaceDeclaration, typeSolver);
    ResolvedType intType = ResolvedPrimitiveType.INT;
    SymbolReference<ResolvedMethodDeclaration> ref = context.solveMethod("foo3", ImmutableList.of(intType), false, new ReflectionTypeSolver());
    assertEquals(true, ref.isSolved());
    assertEquals("A", ref.getCorrespondingDeclaration().declaringType().getName());
    assertEquals(1, ref.getCorrespondingDeclaration().getNumberOfParams());
}
Also used : CompilationUnit(com.github.javaparser.ast.CompilationUnit) ClassOrInterfaceDeclarationContext(com.github.javaparser.symbolsolver.javaparsermodel.contexts.ClassOrInterfaceDeclarationContext) Context(com.github.javaparser.symbolsolver.core.resolution.Context) CompilationUnitContext(com.github.javaparser.symbolsolver.javaparsermodel.contexts.CompilationUnitContext) ClassOrInterfaceDeclaration(com.github.javaparser.ast.body.ClassOrInterfaceDeclaration) ClassOrInterfaceDeclarationContext(com.github.javaparser.symbolsolver.javaparsermodel.contexts.ClassOrInterfaceDeclarationContext) ReflectionTypeSolver(com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver) ResolvedType(com.github.javaparser.resolution.types.ResolvedType) ResolvedMethodDeclaration(com.github.javaparser.resolution.declarations.ResolvedMethodDeclaration) AbstractResolutionTest(com.github.javaparser.symbolsolver.resolution.AbstractResolutionTest) Test(org.junit.Test)

Example 10 with ResolvedMethodDeclaration

use of com.github.javaparser.resolution.declarations.ResolvedMethodDeclaration in project javaparser by javaparser.

the class ClassOrInterfaceDeclarationContextResolutionTest method solveMethodSimpleCase.

@Test
public void solveMethodSimpleCase() {
    CompilationUnit cu = parseSample("ClassWithMethods");
    ClassOrInterfaceDeclaration classOrInterfaceDeclaration = Navigator.demandClass(cu, "A");
    Context context = new ClassOrInterfaceDeclarationContext(classOrInterfaceDeclaration, typeSolver);
    SymbolReference<ResolvedMethodDeclaration> ref = context.solveMethod("foo0", ImmutableList.of(), false, new ReflectionTypeSolver());
    assertEquals(true, ref.isSolved());
    assertEquals("A", ref.getCorrespondingDeclaration().declaringType().getName());
    assertEquals(0, ref.getCorrespondingDeclaration().getNumberOfParams());
}
Also used : CompilationUnit(com.github.javaparser.ast.CompilationUnit) ClassOrInterfaceDeclarationContext(com.github.javaparser.symbolsolver.javaparsermodel.contexts.ClassOrInterfaceDeclarationContext) Context(com.github.javaparser.symbolsolver.core.resolution.Context) CompilationUnitContext(com.github.javaparser.symbolsolver.javaparsermodel.contexts.CompilationUnitContext) ClassOrInterfaceDeclaration(com.github.javaparser.ast.body.ClassOrInterfaceDeclaration) ClassOrInterfaceDeclarationContext(com.github.javaparser.symbolsolver.javaparsermodel.contexts.ClassOrInterfaceDeclarationContext) ReflectionTypeSolver(com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver) ResolvedMethodDeclaration(com.github.javaparser.resolution.declarations.ResolvedMethodDeclaration) AbstractResolutionTest(com.github.javaparser.symbolsolver.resolution.AbstractResolutionTest) Test(org.junit.Test)

Aggregations

ResolvedMethodDeclaration (com.github.javaparser.resolution.declarations.ResolvedMethodDeclaration)35 ReflectionTypeSolver (com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver)27 Test (org.junit.Test)27 CompilationUnit (com.github.javaparser.ast.CompilationUnit)23 ClassOrInterfaceDeclaration (com.github.javaparser.ast.body.ClassOrInterfaceDeclaration)19 MethodDeclaration (com.github.javaparser.ast.body.MethodDeclaration)12 MethodCallExpr (com.github.javaparser.ast.expr.MethodCallExpr)12 TypeSolver (com.github.javaparser.symbolsolver.model.resolution.TypeSolver)12 Context (com.github.javaparser.symbolsolver.core.resolution.Context)11 SymbolReference (com.github.javaparser.symbolsolver.model.resolution.SymbolReference)11 AbstractResolutionTest (com.github.javaparser.symbolsolver.resolution.AbstractResolutionTest)11 CompilationUnitContext (com.github.javaparser.symbolsolver.javaparsermodel.contexts.CompilationUnitContext)8 ResolvedType (com.github.javaparser.resolution.types.ResolvedType)7 List (java.util.List)7 MethodUsage (com.github.javaparser.resolution.MethodUsage)6 ResolvedInterfaceDeclaration (com.github.javaparser.resolution.declarations.ResolvedInterfaceDeclaration)6 ResolvedReferenceTypeDeclaration (com.github.javaparser.resolution.declarations.ResolvedReferenceTypeDeclaration)5 ResolvedTypeParameterDeclaration (com.github.javaparser.resolution.declarations.ResolvedTypeParameterDeclaration)5 ResolvedReferenceType (com.github.javaparser.resolution.types.ResolvedReferenceType)5 ClassOrInterfaceDeclarationContext (com.github.javaparser.symbolsolver.javaparsermodel.contexts.ClassOrInterfaceDeclarationContext)5