Search in sources :

Example 1 with ResolvedReferenceType

use of com.github.javaparser.resolution.types.ResolvedReferenceType in project javaparser by javaparser.

the class ResolvedInterfaceDeclaration method getAllInterfacesExtended.

/**
 * Return the list of interfaces extended directly or indirectly by this one.
 */
default List<ResolvedReferenceType> getAllInterfacesExtended() {
    List<ResolvedReferenceType> interfaces = new ArrayList<>();
    for (ResolvedReferenceType interfaceDeclaration : getInterfacesExtended()) {
        interfaces.add(interfaceDeclaration);
        interfaces.addAll(interfaceDeclaration.getAllInterfacesAncestors());
    }
    return interfaces;
}
Also used : ResolvedReferenceType(com.github.javaparser.resolution.types.ResolvedReferenceType) ArrayList(java.util.ArrayList)

Example 2 with ResolvedReferenceType

use of com.github.javaparser.resolution.types.ResolvedReferenceType in project javaparser by javaparser.

the class JavassistClassDeclarationTest method testGetAllInterfacesWithParameters.

@Test
public void testGetAllInterfacesWithParameters() {
    JavassistClassDeclaration constructorDeclaration = (JavassistClassDeclaration) newTypeSolver.solveType("com.github.javaparser.ast.body.ConstructorDeclaration");
    assertEquals(9, constructorDeclaration.getAllInterfaces().size());
    ResolvedReferenceType interfaze = null;
    interfaze = constructorDeclaration.getAllInterfaces().get(0);
    assertEquals("com.github.javaparser.ast.nodeTypes.NodeWithJavaDoc", interfaze.getQualifiedName());
    assertEquals("com.github.javaparser.ast.body.ConstructorDeclaration", interfaze.typeParametersMap().getValueBySignature("com.github.javaparser.ast.nodeTypes.NodeWithJavaDoc.T").get().asReferenceType().getQualifiedName());
    interfaze = constructorDeclaration.getAllInterfaces().get(1);
    assertEquals("com.github.javaparser.ast.nodeTypes.NodeWithDeclaration", interfaze.getQualifiedName());
    interfaze = constructorDeclaration.getAllInterfaces().get(2);
    assertEquals("com.github.javaparser.ast.nodeTypes.NodeWithName", interfaze.getQualifiedName());
    assertEquals("com.github.javaparser.ast.body.ConstructorDeclaration", interfaze.typeParametersMap().getValueBySignature("com.github.javaparser.ast.nodeTypes.NodeWithName.T").get().asReferenceType().getQualifiedName());
    interfaze = constructorDeclaration.getAllInterfaces().get(3);
    assertEquals("com.github.javaparser.ast.nodeTypes.NodeWithModifiers", interfaze.getQualifiedName());
    assertEquals("com.github.javaparser.ast.body.ConstructorDeclaration", interfaze.typeParametersMap().getValueBySignature("com.github.javaparser.ast.nodeTypes.NodeWithModifiers.T").get().asReferenceType().getQualifiedName());
    interfaze = constructorDeclaration.getAllInterfaces().get(4);
    assertEquals("com.github.javaparser.ast.nodeTypes.NodeWithParameters", interfaze.getQualifiedName());
    assertEquals("com.github.javaparser.ast.body.ConstructorDeclaration", interfaze.typeParametersMap().getValueBySignature("com.github.javaparser.ast.nodeTypes.NodeWithParameters.T").get().asReferenceType().getQualifiedName());
    interfaze = constructorDeclaration.getAllInterfaces().get(5);
    assertEquals("com.github.javaparser.ast.nodeTypes.NodeWithThrowable", interfaze.getQualifiedName());
    assertEquals("com.github.javaparser.ast.body.ConstructorDeclaration", interfaze.typeParametersMap().getValueBySignature("com.github.javaparser.ast.nodeTypes.NodeWithThrowable.T").get().asReferenceType().getQualifiedName());
    interfaze = constructorDeclaration.getAllInterfaces().get(6);
    assertEquals("com.github.javaparser.ast.nodeTypes.NodeWithBlockStmt", interfaze.getQualifiedName());
    assertEquals("com.github.javaparser.ast.body.ConstructorDeclaration", interfaze.typeParametersMap().getValueBySignature("com.github.javaparser.ast.nodeTypes.NodeWithBlockStmt.T").get().asReferenceType().getQualifiedName());
    interfaze = constructorDeclaration.getAllInterfaces().get(7);
    assertEquals("java.lang.Cloneable", interfaze.getQualifiedName());
    interfaze = constructorDeclaration.getAllInterfaces().get(8);
    assertEquals("com.github.javaparser.ast.nodeTypes.NodeWithAnnotations", interfaze.getQualifiedName());
    assertEquals("com.github.javaparser.ast.body.ConstructorDeclaration", interfaze.typeParametersMap().getValueBySignature("com.github.javaparser.ast.nodeTypes.NodeWithAnnotations.T").get().asReferenceType().getQualifiedName());
}
Also used : ResolvedReferenceType(com.github.javaparser.resolution.types.ResolvedReferenceType) AbstractTest(com.github.javaparser.symbolsolver.AbstractTest) Test(org.junit.Test)

Example 3 with ResolvedReferenceType

use of com.github.javaparser.resolution.types.ResolvedReferenceType in project javaparser by javaparser.

the class JavassistClassDeclarationTest method testGetAllAncestorsWithTypeParameters.

@Test
public void testGetAllAncestorsWithTypeParameters() {
    JavassistClassDeclaration constructorDeclaration = (JavassistClassDeclaration) newTypeSolver.solveType("com.github.javaparser.ast.body.ConstructorDeclaration");
    assertEquals(12, constructorDeclaration.getAllAncestors().size());
    ResolvedReferenceType ancestor = null;
    ancestor = constructorDeclaration.getAllAncestors().get(0);
    assertEquals("com.github.javaparser.ast.body.BodyDeclaration", ancestor.getQualifiedName());
    assertEquals("com.github.javaparser.ast.body.ConstructorDeclaration", ancestor.typeParametersMap().getValueBySignature("com.github.javaparser.ast.body.BodyDeclaration.T").get().asReferenceType().getQualifiedName());
    ancestor = constructorDeclaration.getAllAncestors().get(1);
    assertEquals("com.github.javaparser.ast.Node", ancestor.getQualifiedName());
    ancestor = constructorDeclaration.getAllAncestors().get(2);
    assertEquals("java.lang.Cloneable", ancestor.getQualifiedName());
    ancestor = constructorDeclaration.getAllAncestors().get(3);
    assertEquals("com.github.javaparser.ast.nodeTypes.NodeWithAnnotations", ancestor.getQualifiedName());
    assertEquals("com.github.javaparser.ast.body.ConstructorDeclaration", ancestor.typeParametersMap().getValueBySignature("com.github.javaparser.ast.nodeTypes.NodeWithAnnotations.T").get().asReferenceType().getQualifiedName());
    ancestor = constructorDeclaration.getAllAncestors().get(4);
    assertEquals("java.lang.Object", ancestor.getQualifiedName());
    ancestor = constructorDeclaration.getAllAncestors().get(5);
    assertEquals("com.github.javaparser.ast.nodeTypes.NodeWithJavaDoc", ancestor.getQualifiedName());
    assertEquals("com.github.javaparser.ast.body.ConstructorDeclaration", ancestor.typeParametersMap().getValueBySignature("com.github.javaparser.ast.nodeTypes.NodeWithJavaDoc.T").get().asReferenceType().getQualifiedName());
    ancestor = constructorDeclaration.getAllAncestors().get(6);
    assertEquals("com.github.javaparser.ast.nodeTypes.NodeWithDeclaration", ancestor.getQualifiedName());
    ancestor = constructorDeclaration.getAllAncestors().get(7);
    assertEquals("com.github.javaparser.ast.nodeTypes.NodeWithName", ancestor.getQualifiedName());
    assertEquals("com.github.javaparser.ast.body.ConstructorDeclaration", ancestor.typeParametersMap().getValueBySignature("com.github.javaparser.ast.nodeTypes.NodeWithName.T").get().asReferenceType().getQualifiedName());
    ancestor = constructorDeclaration.getAllAncestors().get(8);
    assertEquals("com.github.javaparser.ast.nodeTypes.NodeWithModifiers", ancestor.getQualifiedName());
    assertEquals("com.github.javaparser.ast.body.ConstructorDeclaration", ancestor.typeParametersMap().getValueBySignature("com.github.javaparser.ast.nodeTypes.NodeWithModifiers.T").get().asReferenceType().getQualifiedName());
    ancestor = constructorDeclaration.getAllAncestors().get(9);
    assertEquals("com.github.javaparser.ast.nodeTypes.NodeWithParameters", ancestor.getQualifiedName());
    assertEquals("com.github.javaparser.ast.body.ConstructorDeclaration", ancestor.typeParametersMap().getValueBySignature("com.github.javaparser.ast.nodeTypes.NodeWithParameters.T").get().asReferenceType().getQualifiedName());
    ancestor = constructorDeclaration.getAllAncestors().get(10);
    assertEquals("com.github.javaparser.ast.nodeTypes.NodeWithThrowable", ancestor.getQualifiedName());
    assertEquals("com.github.javaparser.ast.body.ConstructorDeclaration", ancestor.typeParametersMap().getValueBySignature("com.github.javaparser.ast.nodeTypes.NodeWithThrowable.T").get().asReferenceType().getQualifiedName());
    ancestor = constructorDeclaration.getAllAncestors().get(11);
    assertEquals("com.github.javaparser.ast.nodeTypes.NodeWithBlockStmt", ancestor.getQualifiedName());
    assertEquals("com.github.javaparser.ast.body.ConstructorDeclaration", ancestor.typeParametersMap().getValueBySignature("com.github.javaparser.ast.nodeTypes.NodeWithBlockStmt.T").get().asReferenceType().getQualifiedName());
}
Also used : ResolvedReferenceType(com.github.javaparser.resolution.types.ResolvedReferenceType) AbstractTest(com.github.javaparser.symbolsolver.AbstractTest) Test(org.junit.Test)

Example 4 with ResolvedReferenceType

use of com.github.javaparser.resolution.types.ResolvedReferenceType in project javaparser by javaparser.

the class JavaParserClassDeclarationTest method testGetAllSuperclassesWithTypeParameters.

@Test
public void testGetAllSuperclassesWithTypeParameters() {
    JavaParserClassDeclaration constructorDeclaration = (JavaParserClassDeclaration) typeSolverNewCode.solveType("com.github.javaparser.ast.body.ConstructorDeclaration");
    assertEquals(3, constructorDeclaration.getAllSuperClasses().size());
    assertEquals(true, constructorDeclaration.getAllSuperClasses().stream().anyMatch(s -> s.getQualifiedName().equals("com.github.javaparser.ast.body.BodyDeclaration")));
    assertEquals(true, constructorDeclaration.getAllSuperClasses().stream().anyMatch(s -> s.getQualifiedName().equals("com.github.javaparser.ast.Node")));
    assertEquals(true, constructorDeclaration.getAllSuperClasses().stream().anyMatch(s -> s.getQualifiedName().equals("java.lang.Object")));
    ResolvedReferenceType ancestor = null;
    ancestor = constructorDeclaration.getAllSuperClasses().get(0);
    assertEquals("com.github.javaparser.ast.body.BodyDeclaration", ancestor.getQualifiedName());
    assertEquals("com.github.javaparser.ast.body.ConstructorDeclaration", ancestor.typeParametersMap().getValueBySignature("com.github.javaparser.ast.body.BodyDeclaration.T").get().asReferenceType().getQualifiedName());
    ancestor = constructorDeclaration.getAllSuperClasses().get(1);
    assertEquals("com.github.javaparser.ast.Node", ancestor.getQualifiedName());
    ancestor = constructorDeclaration.getAllSuperClasses().get(2);
    assertEquals("java.lang.Object", ancestor.getQualifiedName());
}
Also used : MethodUsage(com.github.javaparser.resolution.MethodUsage) AccessSpecifier(com.github.javaparser.ast.AccessSpecifier) CombinedTypeSolver(com.github.javaparser.symbolsolver.resolution.typesolvers.CombinedTypeSolver) ParseException(com.github.javaparser.ParseException) ImmutableList(com.google.common.collect.ImmutableList) ResolvedFieldDeclaration(com.github.javaparser.resolution.declarations.ResolvedFieldDeclaration) CompilationUnit(com.github.javaparser.ast.CompilationUnit) Before(org.junit.Before) JavaParserTypeSolver(com.github.javaparser.symbolsolver.resolution.typesolvers.JavaParserTypeSolver) ResolvedMethodDeclaration(com.github.javaparser.resolution.declarations.ResolvedMethodDeclaration) ImmutableSet(com.google.common.collect.ImmutableSet) ReflectionFactory(com.github.javaparser.symbolsolver.reflectionmodel.ReflectionFactory) UnsolvedSymbolException(com.github.javaparser.resolution.UnsolvedSymbolException) TypeSolver(com.github.javaparser.symbolsolver.model.resolution.TypeSolver) ResolvedConstructorDeclaration(com.github.javaparser.resolution.declarations.ResolvedConstructorDeclaration) ReferenceTypeImpl(com.github.javaparser.symbolsolver.model.typesystem.ReferenceTypeImpl) AbstractTest(com.github.javaparser.symbolsolver.AbstractTest) Set(java.util.Set) Test(org.junit.Test) IOException(java.io.IOException) ResolvedReferenceType(com.github.javaparser.resolution.types.ResolvedReferenceType) Collectors(java.util.stream.Collectors) File(java.io.File) List(java.util.List) SymbolReference(com.github.javaparser.symbolsolver.model.resolution.SymbolReference) Navigator(com.github.javaparser.symbolsolver.javaparser.Navigator) ResolvedPrimitiveType(com.github.javaparser.resolution.types.ResolvedPrimitiveType) ReflectionTypeSolver(com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver) Assert.assertEquals(org.junit.Assert.assertEquals) JavaParser(com.github.javaparser.JavaParser) ResolvedReferenceType(com.github.javaparser.resolution.types.ResolvedReferenceType) AbstractTest(com.github.javaparser.symbolsolver.AbstractTest) Test(org.junit.Test)

Example 5 with ResolvedReferenceType

use of com.github.javaparser.resolution.types.ResolvedReferenceType in project javaparser by javaparser.

the class JavaParserClassDeclarationTest method testSolveMethodNotExistingBecauseOfTypeParameters.

@Test
public void testSolveMethodNotExistingBecauseOfTypeParameters() {
    JavaParserClassDeclaration constructorDeclaration = (JavaParserClassDeclaration) typeSolverNewCode.solveType("com.github.javaparser.ast.body.ConstructorDeclaration");
    SymbolReference<ResolvedMethodDeclaration> res = null;
    ResolvedReferenceType stringType = (ResolvedReferenceType) ReflectionFactory.typeUsageFor(String.class, typeSolverNewCode);
    ResolvedReferenceType rawClassType = (ResolvedReferenceType) ReflectionFactory.typeUsageFor(Class.class, typeSolverNewCode);
    ResolvedReferenceType classOfStringType = (ResolvedReferenceType) rawClassType.replaceTypeVariables(rawClassType.getTypeDeclaration().getTypeParameters().get(0), stringType);
    res = constructorDeclaration.solveMethod("isThrows", ImmutableList.of(classOfStringType));
    assertEquals(false, res.isSolved());
}
Also used : ResolvedReferenceType(com.github.javaparser.resolution.types.ResolvedReferenceType) ResolvedMethodDeclaration(com.github.javaparser.resolution.declarations.ResolvedMethodDeclaration) AbstractTest(com.github.javaparser.symbolsolver.AbstractTest) Test(org.junit.Test)

Aggregations

ResolvedReferenceType (com.github.javaparser.resolution.types.ResolvedReferenceType)64 Test (org.junit.Test)36 AbstractTest (com.github.javaparser.symbolsolver.AbstractTest)28 ReferenceTypeImpl (com.github.javaparser.symbolsolver.model.typesystem.ReferenceTypeImpl)16 ResolvedType (com.github.javaparser.resolution.types.ResolvedType)14 TypeSolver (com.github.javaparser.symbolsolver.model.resolution.TypeSolver)14 Collectors (java.util.stream.Collectors)11 ReflectionTypeSolver (com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver)10 MethodUsage (com.github.javaparser.resolution.MethodUsage)9 List (java.util.List)9 ArrayList (java.util.ArrayList)8 ResolvedMethodDeclaration (com.github.javaparser.resolution.declarations.ResolvedMethodDeclaration)6 ResolvedReferenceTypeDeclaration (com.github.javaparser.resolution.declarations.ResolvedReferenceTypeDeclaration)6 Pair (com.github.javaparser.utils.Pair)6 ResolvedTypeVariable (com.github.javaparser.resolution.types.ResolvedTypeVariable)5 CombinedTypeSolver (com.github.javaparser.symbolsolver.resolution.typesolvers.CombinedTypeSolver)5 ObjectSchema (io.swagger.v3.oas.models.media.ObjectSchema)5 HashMap (java.util.HashMap)5 Optional (java.util.Optional)5 CompilationUnit (com.github.javaparser.ast.CompilationUnit)4