Search in sources :

Example 51 with ResolvedReferenceType

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

the class JavassistClassDeclarationTest method testGetAllSuperclassesWithTypeParameters.

@Test
public void testGetAllSuperclassesWithTypeParameters() {
    JavassistClassDeclaration constructorDeclaration = (JavassistClassDeclaration) newTypeSolver.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 : ImmutableSet(com.google.common.collect.ImmutableSet) TypeSolver(com.github.javaparser.symbolsolver.model.resolution.TypeSolver) AbstractTest(com.github.javaparser.symbolsolver.AbstractTest) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) IOException(java.io.IOException) ResolvedReferenceType(com.github.javaparser.resolution.types.ResolvedReferenceType) Collectors(java.util.stream.Collectors) CombinedTypeSolver(com.github.javaparser.symbolsolver.resolution.typesolvers.CombinedTypeSolver) JarTypeSolver(com.github.javaparser.symbolsolver.resolution.typesolvers.JarTypeSolver) ReflectionTypeSolver(com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver) Assert.assertEquals(org.junit.Assert.assertEquals) Before(org.junit.Before) ResolvedReferenceType(com.github.javaparser.resolution.types.ResolvedReferenceType) AbstractTest(com.github.javaparser.symbolsolver.AbstractTest) Test(org.junit.Test)

Example 52 with ResolvedReferenceType

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

the class JavassistClassDeclarationTest method testGetInterfacesWithParameters.

@Test
public void testGetInterfacesWithParameters() {
    JavassistClassDeclaration constructorDeclaration = (JavassistClassDeclaration) newTypeSolver.solveType("com.github.javaparser.ast.body.ConstructorDeclaration");
    assertEquals(7, constructorDeclaration.getInterfaces().size());
    ResolvedReferenceType interfaze = null;
    interfaze = constructorDeclaration.getInterfaces().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.getInterfaces().get(1);
    assertEquals("com.github.javaparser.ast.nodeTypes.NodeWithDeclaration", interfaze.getQualifiedName());
    interfaze = constructorDeclaration.getInterfaces().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.getInterfaces().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.getInterfaces().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.getInterfaces().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.getInterfaces().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());
}
Also used : ResolvedReferenceType(com.github.javaparser.resolution.types.ResolvedReferenceType) AbstractTest(com.github.javaparser.symbolsolver.AbstractTest) Test(org.junit.Test)

Example 53 with ResolvedReferenceType

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

the class JavassistClassDeclarationTest method testGetAncestorsWithTypeParameters.

@Test
public void testGetAncestorsWithTypeParameters() {
    JavassistClassDeclaration constructorDeclaration = (JavassistClassDeclaration) newTypeSolver.solveType("com.github.javaparser.ast.body.ConstructorDeclaration");
    assertEquals(8, constructorDeclaration.getAncestors().size());
    ResolvedReferenceType ancestor = null;
    ancestor = constructorDeclaration.getAncestors().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.getAncestors().get(1);
    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.getAncestors().get(2);
    assertEquals("com.github.javaparser.ast.nodeTypes.NodeWithDeclaration", ancestor.getQualifiedName());
    ancestor = constructorDeclaration.getAncestors().get(3);
    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.getAncestors().get(4);
    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.getAncestors().get(5);
    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.getAncestors().get(6);
    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.getAncestors().get(7);
    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 54 with ResolvedReferenceType

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

the class MethodsResolutionLogicTest method compatibilityShouldConsiderAlsoTypeVariablesRaw.

@Test
public void compatibilityShouldConsiderAlsoTypeVariablesRaw() {
    JavaParserClassDeclaration constructorDeclaration = (JavaParserClassDeclaration) typeSolver.solveType("com.github.javaparser.ast.body.ConstructorDeclaration");
    ResolvedReferenceType rawClassType = (ResolvedReferenceType) ReflectionFactory.typeUsageFor(Class.class, typeSolver);
    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(rawClassType), 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 55 with ResolvedReferenceType

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

the class ReflectionClassDeclarationTest method testGetAllSuperclassesWithTypeParameters.

@Test
public void testGetAllSuperclassesWithTypeParameters() {
    ReflectionClassDeclaration constructorDeclaration = (ReflectionClassDeclaration) typeResolver.solveType("com.github.javaparser.ast.body.ConstructorDeclaration");
    assertEquals(4, constructorDeclaration.getAllSuperClasses().size());
    assertEquals(true, constructorDeclaration.getAllSuperClasses().stream().anyMatch(s -> s.getQualifiedName().equals("com.github.javaparser.ast.body.CallableDeclaration")));
    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;
    ancestor = constructorDeclaration.getAllSuperClasses().get(0);
    assertEquals("com.github.javaparser.ast.body.CallableDeclaration", ancestor.getQualifiedName());
    assertEquals("com.github.javaparser.ast.body.ConstructorDeclaration", ancestor.typeParametersMap().getValueBySignature("com.github.javaparser.ast.body.CallableDeclaration.T").get().asReferenceType().getQualifiedName());
    ancestor = constructorDeclaration.getAllSuperClasses().get(1);
    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(2);
    assertEquals("com.github.javaparser.ast.Node", ancestor.getQualifiedName());
    ancestor = constructorDeclaration.getAllSuperClasses().get(3);
    assertEquals("java.lang.Object", ancestor.getQualifiedName());
}
Also used : java.util(java.util) ImmutableSet(com.google.common.collect.ImmutableSet) TypeSolver(com.github.javaparser.symbolsolver.model.resolution.TypeSolver) ReferenceTypeImpl(com.github.javaparser.symbolsolver.model.typesystem.ReferenceTypeImpl) AccessSpecifier(com.github.javaparser.ast.AccessSpecifier) AbstractTest(com.github.javaparser.symbolsolver.AbstractTest) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) ResolvedReferenceType(com.github.javaparser.resolution.types.ResolvedReferenceType) com.github.javaparser.resolution.declarations(com.github.javaparser.resolution.declarations) Collectors(java.util.stream.Collectors) Serializable(java.io.Serializable) ImmutableList(com.google.common.collect.ImmutableList) ReflectionTypeSolver(com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver) ResolvedTypeVariable(com.github.javaparser.resolution.types.ResolvedTypeVariable) Assert.assertEquals(org.junit.Assert.assertEquals) ResolvedReferenceType(com.github.javaparser.resolution.types.ResolvedReferenceType) 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