Search in sources :

Example 1 with ResolvedDeclaration

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

the class FindingAllFields method findAllInheritedFields.

@Test
public void findAllInheritedFields() {
    CompilationUnit cu = parseSample("AClassWithFields");
    ClassOrInterfaceDeclaration classC = Navigator.demandClass(cu, "C");
    ResolvedReferenceTypeDeclaration typeDeclaration = JavaParserFacade.get(new ReflectionTypeSolver()).getTypeDeclaration(classC);
    assertEquals(3, typeDeclaration.getAllFields().size());
    assertEquals(ImmutableSet.of("a", "b", "c"), typeDeclaration.getAllFields().stream().map(ResolvedDeclaration::getName).collect(Collectors.toSet()));
}
Also used : CompilationUnit(com.github.javaparser.ast.CompilationUnit) ResolvedDeclaration(com.github.javaparser.resolution.declarations.ResolvedDeclaration) ResolvedReferenceTypeDeclaration(com.github.javaparser.resolution.declarations.ResolvedReferenceTypeDeclaration) ClassOrInterfaceDeclaration(com.github.javaparser.ast.body.ClassOrInterfaceDeclaration) ReflectionTypeSolver(com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver) AbstractResolutionTest(com.github.javaparser.symbolsolver.resolution.AbstractResolutionTest) Test(org.junit.Test)

Example 2 with ResolvedDeclaration

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

the class FindingAllFields method findAllInheritedFieldsAndGenerics.

@Test
public void findAllInheritedFieldsAndGenerics() {
    CompilationUnit cu = parseSample("AClassWithFieldsAndGenerics");
    ClassOrInterfaceDeclaration classC = Navigator.demandClass(cu, "C");
    ResolvedReferenceTypeDeclaration typeDeclaration = JavaParserFacade.get(new ReflectionTypeSolver()).getTypeDeclaration(classC);
    assertEquals(3, typeDeclaration.getAllFields().size());
    assertEquals(ImmutableSet.of("a", "b", "c"), typeDeclaration.getAllFields().stream().map(ResolvedDeclaration::getName).collect(Collectors.toSet()));
    assertEquals("java.util.List<java.lang.String>", typeDeclaration.getField("b").getType().describe());
}
Also used : CompilationUnit(com.github.javaparser.ast.CompilationUnit) ResolvedDeclaration(com.github.javaparser.resolution.declarations.ResolvedDeclaration) ResolvedReferenceTypeDeclaration(com.github.javaparser.resolution.declarations.ResolvedReferenceTypeDeclaration) ClassOrInterfaceDeclaration(com.github.javaparser.ast.body.ClassOrInterfaceDeclaration) ReflectionTypeSolver(com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver) AbstractResolutionTest(com.github.javaparser.symbolsolver.resolution.AbstractResolutionTest) Test(org.junit.Test)

Aggregations

CompilationUnit (com.github.javaparser.ast.CompilationUnit)2 ClassOrInterfaceDeclaration (com.github.javaparser.ast.body.ClassOrInterfaceDeclaration)2 ResolvedDeclaration (com.github.javaparser.resolution.declarations.ResolvedDeclaration)2 ResolvedReferenceTypeDeclaration (com.github.javaparser.resolution.declarations.ResolvedReferenceTypeDeclaration)2 AbstractResolutionTest (com.github.javaparser.symbolsolver.resolution.AbstractResolutionTest)2 ReflectionTypeSolver (com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver)2 Test (org.junit.Test)2