Search in sources :

Example 11 with ClassOrInterfaceDeclarationContext

use of com.github.javaparser.symbolsolver.javaparsermodel.contexts.ClassOrInterfaceDeclarationContext 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 12 with ClassOrInterfaceDeclarationContext

use of com.github.javaparser.symbolsolver.javaparsermodel.contexts.ClassOrInterfaceDeclarationContext 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 13 with ClassOrInterfaceDeclarationContext

use of com.github.javaparser.symbolsolver.javaparsermodel.contexts.ClassOrInterfaceDeclarationContext 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 14 with ClassOrInterfaceDeclarationContext

use of com.github.javaparser.symbolsolver.javaparsermodel.contexts.ClassOrInterfaceDeclarationContext 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)

Example 15 with ClassOrInterfaceDeclarationContext

use of com.github.javaparser.symbolsolver.javaparsermodel.contexts.ClassOrInterfaceDeclarationContext in project javaparser by javaparser.

the class ClassOrInterfaceDeclarationContextResolutionTest method solveSymbolAsValueReferringToInheritedInstanceField.

@Test
public void solveSymbolAsValueReferringToInheritedInstanceField() {
    CompilationUnit cu = parseSample("ClassWithSymbols");
    ClassOrInterfaceDeclaration classOrInterfaceDeclaration = Navigator.demandClass(cu, "A");
    Context context = new ClassOrInterfaceDeclarationContext(classOrInterfaceDeclaration, typeSolver);
    Optional<Value> ref = context.solveSymbolAsValue("k", new MemoryTypeSolver());
    assertEquals(true, ref.isPresent());
    assertEquals("boolean", ref.get().getType().describe());
}
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) MemoryTypeSolver(com.github.javaparser.symbolsolver.resolution.typesolvers.MemoryTypeSolver) ClassOrInterfaceDeclaration(com.github.javaparser.ast.body.ClassOrInterfaceDeclaration) ClassOrInterfaceDeclarationContext(com.github.javaparser.symbolsolver.javaparsermodel.contexts.ClassOrInterfaceDeclarationContext) Value(com.github.javaparser.symbolsolver.model.resolution.Value) AbstractResolutionTest(com.github.javaparser.symbolsolver.resolution.AbstractResolutionTest) Test(org.junit.Test)

Aggregations

CompilationUnit (com.github.javaparser.ast.CompilationUnit)38 ClassOrInterfaceDeclaration (com.github.javaparser.ast.body.ClassOrInterfaceDeclaration)38 ClassOrInterfaceDeclarationContext (com.github.javaparser.symbolsolver.javaparsermodel.contexts.ClassOrInterfaceDeclarationContext)38 AbstractResolutionTest (com.github.javaparser.symbolsolver.resolution.AbstractResolutionTest)38 Test (org.junit.Test)38 Context (com.github.javaparser.symbolsolver.core.resolution.Context)37 CompilationUnitContext (com.github.javaparser.symbolsolver.javaparsermodel.contexts.CompilationUnitContext)37 MemoryTypeSolver (com.github.javaparser.symbolsolver.resolution.typesolvers.MemoryTypeSolver)23 ReflectionTypeSolver (com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver)14 ResolvedTypeDeclaration (com.github.javaparser.resolution.declarations.ResolvedTypeDeclaration)11 MethodUsage (com.github.javaparser.resolution.MethodUsage)6 ResolvedMethodDeclaration (com.github.javaparser.resolution.declarations.ResolvedMethodDeclaration)6 ResolvedType (com.github.javaparser.resolution.types.ResolvedType)6 Value (com.github.javaparser.symbolsolver.model.resolution.Value)6 ReferenceTypeImpl (com.github.javaparser.symbolsolver.model.typesystem.ReferenceTypeImpl)2 ReflectionClassDeclaration (com.github.javaparser.symbolsolver.reflectionmodel.ReflectionClassDeclaration)2