| /* |
| * Copyright 2016 Federico Tomassetti |
| * |
| * Licensed under the Apache License, Version 2.0 (the "License"); |
| * you may not use this file except in compliance with the License. |
| * You may obtain a copy of the License at |
| * |
| * http://www.apache.org/licenses/LICENSE-2.0 |
| * |
| * Unless required by applicable law or agreed to in writing, software |
| * distributed under the License is distributed on an "AS IS" BASIS, |
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| * See the License for the specific language governing permissions and |
| * limitations under the License. |
| */ |
| |
| package com.github.javaparser.symbolsolver.javassistmodel; |
| |
| import com.github.javaparser.resolution.MethodUsage; |
| import com.github.javaparser.resolution.declarations.ResolvedFieldDeclaration; |
| import com.github.javaparser.resolution.declarations.ResolvedMethodDeclaration; |
| import com.github.javaparser.resolution.types.ResolvedReferenceType; |
| import com.github.javaparser.resolution.types.ResolvedType; |
| import com.github.javaparser.symbolsolver.AbstractSymbolResolutionTest; |
| import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; |
| import com.github.javaparser.symbolsolver.resolution.typesolvers.CombinedTypeSolver; |
| import com.github.javaparser.symbolsolver.resolution.typesolvers.JarTypeSolver; |
| import com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver; |
| import com.google.common.collect.ImmutableSet; |
| import org.junit.jupiter.api.BeforeEach; |
| import org.junit.jupiter.api.Test; |
| |
| import java.io.IOException; |
| import java.nio.file.Path; |
| import java.util.HashMap; |
| import java.util.List; |
| import java.util.Map; |
| import java.util.Set; |
| import java.util.stream.Collectors; |
| |
| import static org.junit.jupiter.api.Assertions.*; |
| import static org.junit.jupiter.api.Assertions.assertThrows; |
| |
| class JavassistClassDeclarationTest extends AbstractSymbolResolutionTest { |
| |
| private TypeSolver typeSolver; |
| |
| private TypeSolver newTypeSolver; |
| |
| private TypeSolver anotherTypeSolver; |
| |
| @BeforeEach |
| void setup() throws IOException { |
| Path pathToJar = adaptPath("src/test/resources/javaparser-core-2.1.0.jar"); |
| typeSolver = new CombinedTypeSolver(new JarTypeSolver(pathToJar), new ReflectionTypeSolver()); |
| |
| Path newPathToJar = adaptPath("src/test/resources/javaparser-core-3.0.0-alpha.2.jar"); |
| newTypeSolver = new CombinedTypeSolver(new JarTypeSolver(newPathToJar), new ReflectionTypeSolver()); |
| |
| Path anotherPathToJar = adaptPath("src/test/resources/test-artifact-1.0.0.jar"); |
| anotherTypeSolver = new CombinedTypeSolver(new JarTypeSolver(anotherPathToJar), new ReflectionTypeSolver()); |
| } |
| |
| /// |
| /// Test misc |
| /// |
| |
| @Test |
| void testIsClass() { |
| JavassistClassDeclaration compilationUnit = (JavassistClassDeclaration) typeSolver.solveType("com.github.javaparser.ast.CompilationUnit"); |
| assertTrue(compilationUnit.isClass()); |
| } |
| |
| @Test |
| void testIsInterface() { |
| JavassistClassDeclaration compilationUnit = (JavassistClassDeclaration) typeSolver.solveType("com.github.javaparser.ast.CompilationUnit"); |
| assertFalse(compilationUnit.isInterface()); |
| } |
| |
| @Test |
| void testIsEnum() { |
| JavassistClassDeclaration compilationUnit = (JavassistClassDeclaration) typeSolver.solveType("com.github.javaparser.ast.CompilationUnit"); |
| assertFalse(compilationUnit.isEnum()); |
| } |
| |
| @Test |
| void testIsTypeVariable() { |
| JavassistClassDeclaration compilationUnit = (JavassistClassDeclaration) typeSolver.solveType("com.github.javaparser.ast.CompilationUnit"); |
| assertFalse(compilationUnit.isTypeParameter()); |
| } |
| |
| @Test |
| void testIsType() { |
| JavassistClassDeclaration compilationUnit = (JavassistClassDeclaration) typeSolver.solveType("com.github.javaparser.ast.CompilationUnit"); |
| assertTrue(compilationUnit.isType()); |
| } |
| |
| @Test |
| void testAsType() { |
| JavassistClassDeclaration compilationUnit = (JavassistClassDeclaration) typeSolver.solveType("com.github.javaparser.ast.CompilationUnit"); |
| assertEquals(compilationUnit, compilationUnit.asType()); |
| } |
| |
| @Test |
| void testAsClass() { |
| JavassistClassDeclaration compilationUnit = (JavassistClassDeclaration) typeSolver.solveType("com.github.javaparser.ast.CompilationUnit"); |
| assertEquals(compilationUnit, compilationUnit.asClass()); |
| } |
| |
| @Test |
| void testAsInterface() { |
| assertThrows(UnsupportedOperationException.class, () -> { |
| JavassistClassDeclaration compilationUnit = (JavassistClassDeclaration) typeSolver.solveType("com.github.javaparser.ast.CompilationUnit"); |
| compilationUnit.asInterface(); |
| }); |
| } |
| |
| @Test |
| void testAsEnum() { |
| assertThrows(UnsupportedOperationException.class, () -> { |
| JavassistClassDeclaration compilationUnit = (JavassistClassDeclaration) typeSolver.solveType("com.github.javaparser.ast.CompilationUnit"); |
| compilationUnit.asEnum(); |
| }); |
| } |
| |
| @Test |
| void testGetPackageName() { |
| JavassistClassDeclaration compilationUnit = (JavassistClassDeclaration) typeSolver.solveType("com.github.javaparser.ast.CompilationUnit"); |
| assertEquals("com.github.javaparser.ast", compilationUnit.getPackageName()); |
| } |
| |
| @Test |
| void testGetClassName() { |
| JavassistClassDeclaration compilationUnit = (JavassistClassDeclaration) typeSolver.solveType("com.github.javaparser.ast.CompilationUnit"); |
| assertEquals("CompilationUnit", compilationUnit.getClassName()); |
| } |
| |
| @Test |
| void testGetQualifiedName() { |
| JavassistClassDeclaration compilationUnit = (JavassistClassDeclaration) typeSolver.solveType("com.github.javaparser.ast.CompilationUnit"); |
| assertEquals("com.github.javaparser.ast.CompilationUnit", compilationUnit.getQualifiedName()); |
| } |
| |
| @Test |
| void testHasDirectlyAnnotation() { |
| JavassistClassDeclaration compilationUnit = (JavassistClassDeclaration) anotherTypeSolver.solveType("com.github.javaparser.test.TestClass"); |
| assertTrue(compilationUnit.hasDirectlyAnnotation("com.github.javaparser.test.TestAnnotation")); |
| } |
| |
| @Test |
| void testHasAnnotation() { |
| JavassistClassDeclaration compilationUnit = (JavassistClassDeclaration) anotherTypeSolver.solveType("com.github.javaparser.test.TestChildClass"); |
| assertTrue(compilationUnit.hasAnnotation("com.github.javaparser.test.TestAnnotation")); |
| } |
| |
| @Test |
| void testGetGenericTypeField(){ |
| JavassistClassDeclaration compilationUnit = (JavassistClassDeclaration) anotherTypeSolver.solveType("com.github.javaparser.test.ClassWithFields"); |
| List<ResolvedFieldDeclaration> declarationList = compilationUnit.getAllFields(); |
| assertEquals(6, declarationList.size()); |
| |
| Map<String, ResolvedType> fields = new HashMap<>(); |
| for (ResolvedFieldDeclaration fieldDeclaration : declarationList) { |
| String name = fieldDeclaration.getName(); |
| ResolvedType type = fieldDeclaration.getType(); |
| fields.put(name, type); |
| } |
| |
| assertTrue(fields.containsKey("genericParamObjectField")); |
| assertTrue(fields.containsKey("genericPrimitiveArrayField")); |
| assertTrue(fields.containsKey("genericObjectArrayField")); |
| assertTrue(fields.containsKey("genericField")); |
| assertTrue(fields.containsKey("primitiveField")); |
| assertTrue(fields.containsKey("objectField")); |
| } |
| |
| @Test |
| void testGetDeclaredMethods() { |
| JavassistClassDeclaration compilationUnit = (JavassistClassDeclaration) newTypeSolver.solveType("com.github.javaparser.Position"); |
| Set<ResolvedMethodDeclaration> methodsSet = compilationUnit.getDeclaredMethods(); |
| assertEquals(12, methodsSet.size()); |
| |
| Map<String, MethodUsage> methods = new HashMap<>(); |
| for (ResolvedMethodDeclaration method : methodsSet) { |
| methods.put(method.getName(), new MethodUsage(method)); |
| } |
| |
| assertTrue(methods.containsKey("pos")); |
| assertEquals(2, methods.get("pos").getNoParams()); |
| assertTrue(methods.containsKey("withColumn")); |
| assertEquals(1, methods.get("withColumn").getNoParams()); |
| assertTrue(methods.containsKey("withLine")); |
| assertEquals(1, methods.get("withLine").getNoParams()); |
| assertTrue(methods.containsKey("valid")); |
| assertEquals(0, methods.get("valid").getNoParams()); |
| assertTrue(methods.containsKey("invalid")); |
| assertEquals(0, methods.get("invalid").getNoParams()); |
| assertTrue(methods.containsKey("orIfInvalid")); |
| assertEquals(1, methods.get("orIfInvalid").getNoParams()); |
| assertTrue(methods.containsKey("isAfter")); |
| assertEquals(1, methods.get("isAfter").getNoParams()); |
| assertTrue(methods.containsKey("isBefore")); |
| assertEquals(1, methods.get("isBefore").getNoParams()); |
| assertTrue(methods.containsKey("compareTo")); |
| assertEquals(1, methods.get("compareTo").getNoParams()); |
| assertTrue(methods.containsKey("equals")); |
| assertEquals(1, methods.get("equals").getNoParams()); |
| assertTrue(methods.containsKey("hashCode")); |
| assertEquals(0, methods.get("hashCode").getNoParams()); |
| assertTrue(methods.containsKey("toString")); |
| assertEquals(0, methods.get("toString").getNoParams()); |
| } |
| |
| /// |
| /// Test ancestors |
| /// |
| |
| @Test |
| void testGetSuperclass() { |
| JavassistClassDeclaration compilationUnit = (JavassistClassDeclaration) typeSolver.solveType("com.github.javaparser.ast.CompilationUnit"); |
| assertEquals("com.github.javaparser.ast.Node", compilationUnit.getSuperClass().getQualifiedName()); |
| } |
| |
| @Test |
| void testGetSuperclassWithoutTypeParameters() { |
| JavassistClassDeclaration compilationUnit = (JavassistClassDeclaration) newTypeSolver.solveType("com.github.javaparser.ast.CompilationUnit"); |
| assertEquals("com.github.javaparser.ast.Node", compilationUnit.getSuperClass().getQualifiedName()); |
| } |
| |
| @Test |
| void testGetSuperclassWithTypeParameters() { |
| JavassistClassDeclaration compilationUnit = (JavassistClassDeclaration) newTypeSolver.solveType("com.github.javaparser.ast.body.ConstructorDeclaration"); |
| assertEquals("com.github.javaparser.ast.body.BodyDeclaration", compilationUnit.getSuperClass().getQualifiedName()); |
| assertEquals("com.github.javaparser.ast.body.ConstructorDeclaration", compilationUnit.getSuperClass().typeParametersMap().getValueBySignature("com.github.javaparser.ast.body.BodyDeclaration.T").get().asReferenceType().getQualifiedName()); |
| } |
| |
| @Test |
| void testGetAllSuperclasses() { |
| JavassistClassDeclaration cu = (JavassistClassDeclaration) typeSolver.solveType("com.github.javaparser.ast.CompilationUnit"); |
| assertEquals(ImmutableSet.of("com.github.javaparser.ast.Node", "java.lang.Object"), cu.getAllSuperClasses().stream().map(ResolvedReferenceType::getQualifiedName).collect(Collectors.toSet())); |
| } |
| |
| @Test |
| void testGetAllAncestors() { |
| JavassistClassDeclaration cu = (JavassistClassDeclaration) typeSolver.solveType("com.github.javaparser.ast.CompilationUnit"); |
| assertEquals(ImmutableSet.of("com.github.javaparser.ast.Node", "java.lang.Object"), cu.getAllAncestors().stream().map(ResolvedReferenceType::getQualifiedName).collect(Collectors.toSet())); |
| } |
| |
| @Test |
| void testGetInterfaces() { |
| JavassistClassDeclaration compilationUnit = (JavassistClassDeclaration) typeSolver.solveType("com.github.javaparser.ast.CompilationUnit"); |
| assertEquals(ImmutableSet.of(), compilationUnit.getInterfaces().stream().map(ResolvedReferenceType::getQualifiedName).collect(Collectors.toSet())); |
| |
| JavassistClassDeclaration coid = (JavassistClassDeclaration) typeSolver.solveType("com.github.javaparser.ast.body.ClassOrInterfaceDeclaration"); |
| assertEquals(ImmutableSet.of("com.github.javaparser.ast.DocumentableNode"), coid.getInterfaces().stream().map(ResolvedReferenceType::getQualifiedName).collect(Collectors.toSet())); |
| } |
| |
| @Test |
| void testGetAllInterfaces() { |
| JavassistClassDeclaration compilationUnit = (JavassistClassDeclaration) typeSolver.solveType("com.github.javaparser.ast.CompilationUnit"); |
| assertEquals(ImmutableSet.of(), compilationUnit.getAllInterfaces().stream().map(ResolvedReferenceType::getQualifiedName).collect(Collectors.toSet())); |
| |
| JavassistClassDeclaration coid = (JavassistClassDeclaration) typeSolver.solveType("com.github.javaparser.ast.body.ClassOrInterfaceDeclaration"); |
| assertEquals(ImmutableSet.of("com.github.javaparser.ast.NamedNode", "com.github.javaparser.ast.body.AnnotableNode", "com.github.javaparser.ast.DocumentableNode"), coid.getAllInterfaces().stream().map(ResolvedReferenceType::getQualifiedName).collect(Collectors.toSet())); |
| } |
| |
| @Test |
| void testGetAllSuperclassesWithoutTypeParameters() { |
| JavassistClassDeclaration cu = (JavassistClassDeclaration) newTypeSolver.solveType("com.github.javaparser.ast.CompilationUnit"); |
| assertEquals(ImmutableSet.of("com.github.javaparser.ast.Node", "java.lang.Object"), cu.getAllSuperClasses().stream().map(ResolvedReferenceType::getQualifiedName).collect(Collectors.toSet())); |
| } |
| |
| @Test |
| void testGetAllSuperclassesWithTypeParameters() { |
| JavassistClassDeclaration constructorDeclaration = (JavassistClassDeclaration) newTypeSolver.solveType("com.github.javaparser.ast.body.ConstructorDeclaration"); |
| assertEquals(3, constructorDeclaration.getAllSuperClasses().size()); |
| assertTrue(constructorDeclaration.getAllSuperClasses().stream().anyMatch(s -> s.getQualifiedName().equals("com.github.javaparser.ast.body.BodyDeclaration"))); |
| assertTrue(constructorDeclaration.getAllSuperClasses().stream().anyMatch(s -> s.getQualifiedName().equals("com.github.javaparser.ast.Node"))); |
| assertTrue(constructorDeclaration.getAllSuperClasses().stream().anyMatch(s -> s.getQualifiedName().equals("java.lang.Object"))); |
| |
| ResolvedReferenceType ancestor; |
| |
| 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()); |
| } |
| |
| @Test |
| void testGetInterfacesWithoutParameters() { |
| JavassistClassDeclaration compilationUnit = (JavassistClassDeclaration) newTypeSolver.solveType("com.github.javaparser.ast.CompilationUnit"); |
| assertEquals(ImmutableSet.of(), compilationUnit.getInterfaces().stream().map(ResolvedReferenceType::getQualifiedName).collect(Collectors.toSet())); |
| |
| JavassistClassDeclaration coid = (JavassistClassDeclaration) newTypeSolver.solveType("com.github.javaparser.ast.body.ClassOrInterfaceDeclaration"); |
| assertEquals(ImmutableSet.of("com.github.javaparser.ast.nodeTypes.NodeWithExtends", "com.github.javaparser.ast.nodeTypes.NodeWithImplements"), coid.getInterfaces().stream().map(ResolvedReferenceType::getQualifiedName).collect(Collectors.toSet())); |
| } |
| |
| @Test |
| void testGetInterfacesWithParameters() { |
| JavassistClassDeclaration constructorDeclaration = (JavassistClassDeclaration) newTypeSolver.solveType("com.github.javaparser.ast.body.ConstructorDeclaration"); |
| assertEquals(7, constructorDeclaration.getInterfaces().size()); |
| |
| ResolvedReferenceType interfaze; |
| |
| 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()); |
| } |
| |
| @Test |
| void testGetAllInterfacesWithoutParameters() { |
| JavassistClassDeclaration compilationUnit = (JavassistClassDeclaration) newTypeSolver.solveType("com.github.javaparser.ast.CompilationUnit"); |
| assertEquals(ImmutableSet.of("java.lang.Cloneable"), compilationUnit.getAllInterfaces().stream().map(ResolvedReferenceType::getQualifiedName).collect(Collectors.toSet())); |
| |
| JavassistClassDeclaration coid = (JavassistClassDeclaration) newTypeSolver.solveType("com.github.javaparser.ast.body.ClassOrInterfaceDeclaration"); |
| assertEquals(ImmutableSet.of("com.github.javaparser.ast.nodeTypes.NodeWithExtends", |
| "com.github.javaparser.ast.nodeTypes.NodeWithAnnotations", |
| "java.lang.Cloneable", |
| "com.github.javaparser.ast.nodeTypes.NodeWithImplements", |
| "com.github.javaparser.ast.nodeTypes.NodeWithName", |
| "com.github.javaparser.ast.nodeTypes.NodeWithModifiers", |
| "com.github.javaparser.ast.nodeTypes.NodeWithJavaDoc", |
| "com.github.javaparser.ast.nodeTypes.NodeWithMembers"), coid.getAllInterfaces().stream().map(ResolvedReferenceType::getQualifiedName).collect(Collectors.toSet())); |
| } |
| |
| @Test |
| void testGetAllInterfacesWithParameters() { |
| JavassistClassDeclaration constructorDeclaration = (JavassistClassDeclaration) newTypeSolver.solveType("com.github.javaparser.ast.body.ConstructorDeclaration"); |
| assertEquals(9, constructorDeclaration.getAllInterfaces().size()); |
| |
| ResolvedReferenceType interfaze; |
| |
| 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()); |
| } |
| |
| @Test |
| void testGetAncestorsWithTypeParameters() { |
| JavassistClassDeclaration constructorDeclaration = (JavassistClassDeclaration) newTypeSolver.solveType("com.github.javaparser.ast.body.ConstructorDeclaration"); |
| assertEquals(8, constructorDeclaration.getAncestors().size()); |
| |
| ResolvedReferenceType ancestor; |
| |
| 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()); |
| } |
| |
| @Test |
| void testGetAllAncestorsWithoutTypeParameters() { |
| JavassistClassDeclaration cu = (JavassistClassDeclaration) newTypeSolver.solveType("com.github.javaparser.ast.CompilationUnit"); |
| assertEquals(ImmutableSet.of("java.lang.Cloneable", "com.github.javaparser.ast.Node", "java.lang.Object"), cu.getAllAncestors().stream().map(ResolvedReferenceType::getQualifiedName).collect(Collectors.toSet())); |
| } |
| |
| @Test |
| void testGetAllAncestorsWithTypeParameters() { |
| JavassistClassDeclaration constructorDeclaration = (JavassistClassDeclaration) newTypeSolver.solveType("com.github.javaparser.ast.body.ConstructorDeclaration"); |
| assertEquals(12, constructorDeclaration.getAllAncestors().size()); |
| |
| ResolvedReferenceType ancestor; |
| |
| 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()); |
| } |
| |
| } |