Skip to content

Commit

Permalink
Renaming of packages;
Browse files Browse the repository at this point in the history
  • Loading branch information
MysterAitch committed May 4, 2019
1 parent 03bc9d8 commit 0978d70
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 25 deletions.
Expand Up @@ -19,53 +19,67 @@


public class TypeResolutionWithSameNameTest extends AbstractResolutionTest { public class TypeResolutionWithSameNameTest extends AbstractResolutionTest {



/*
* abstract class extends_duplicate.DuplicateTypeName
* class extends_duplicate.A extends extends_duplicate.DuplicateTypeName
* class extends_duplicate.A.DuplicateTypeName extends extends_duplicate.A
*/
@Test @Test
void testTypesWithSameNameInPackageAndNested_directImplements() throws IOException { void testTypesWithSameNameInPackageAndNested_directExtends() throws IOException {
Path srcRootPath = adaptPath("src/test/resources/TypeResolutionWithSameNameTest/src2"); Path srcRootPath = adaptPath("src/test/resources/TypeResolutionWithSameNameTest/src1");
Path extendingTypePath = adaptPath("src/test/resources/TypeResolutionWithSameNameTest/src2/testresource/A.java"); Path extendsTypePath = adaptPath("src/test/resources/TypeResolutionWithSameNameTest/src1/extends_duplicate/A.java");


JavaParserTypeSolver javaParserTypeSolver = new JavaParserTypeSolver(srcRootPath); JavaParserTypeSolver javaParserTypeSolver = new JavaParserTypeSolver(srcRootPath);
StaticJavaParser StaticJavaParser
.getConfiguration() .getConfiguration()
.setSymbolResolver(new JavaSymbolSolver(javaParserTypeSolver)); .setSymbolResolver(new JavaSymbolSolver(javaParserTypeSolver));


CompilationUnit cu = StaticJavaParser.parse(extendingTypePath); CompilationUnit cu = StaticJavaParser.parse(extendsTypePath);
ClassOrInterfaceDeclaration extendingTypeClass = Navigator.demandClass(cu, "A"); ClassOrInterfaceDeclaration extendingTypeClass = Navigator.demandClass(cu, "A");


// Attempt to resolve `DuplicateTypeName` from `class ExtendingType implements **DuplicateTypeName**` // Attempt to resolve `DuplicateTypeName` from `class ExtendingType extends **DuplicateTypeName**`
assumeTrue(extendingTypeClass.getImplementedTypes().size() > 0); assumeTrue(extendingTypeClass.getExtendedTypes().size() > 0);
ClassOrInterfaceType implementedType = extendingTypeClass.getImplementedTypes(0); ClassOrInterfaceType extendedType = extendingTypeClass.getExtendedTypes(0);
ResolvedReferenceType resolvedImplementedType = implementedType.resolve(); ResolvedReferenceType resolvedExtendedType = extendedType.resolve();


// Verify qualified name matches the non-nested class in the same package. // Verify qualified name matches the non-nested class in the same package.
// Note verbose assertions show both the "correct" expected value, and the erroneous value to be avoided. // Note verbose assertions show both the "correct" expected value, and the erroneous value to be avoided.
String qualifiedName = resolvedImplementedType.getQualifiedName(); String qualifiedName = resolvedExtendedType.getQualifiedName();
assertEquals("testresource.DuplicateTypeName", qualifiedName, "Error - not resolved to interface in separate file."); assertEquals("extends_duplicate.DuplicateTypeName", qualifiedName, "Error - not resolved to interface in separate file.");
assertNotEquals("testresource.ExtendingType.DuplicateTypeName", qualifiedName, "Error - resolved to nested class."); assertNotEquals("extends_duplicate.A.DuplicateTypeName", qualifiedName, "Error - resolved to nested class.");
} }



/*
* interface implements_duplicate.DuplicateTypeName
* class implements_duplicate.class A implements implements_duplicate.DuplicateTypeName
* class implements_duplicate.A.DuplicateTypeName extends implements_duplicate.A
*/
@Test @Test
void testTypesWithSameNameInPackageAndNested_directExtends() throws IOException { void testTypesWithSameNameInPackageAndNested_directImplements() throws IOException {
Path srcRootPath = adaptPath("src/test/resources/TypeResolutionWithSameNameTest/src1"); Path srcRootPath = adaptPath("src/test/resources/TypeResolutionWithSameNameTest/src2");
Path extendingTypePath = adaptPath("src/test/resources/TypeResolutionWithSameNameTest/src1/testresource/A.java"); Path implementingTypePath = adaptPath("src/test/resources/TypeResolutionWithSameNameTest/src2/implements_duplicate/A.java");


JavaParserTypeSolver javaParserTypeSolver = new JavaParserTypeSolver(srcRootPath); JavaParserTypeSolver javaParserTypeSolver = new JavaParserTypeSolver(srcRootPath);
StaticJavaParser StaticJavaParser
.getConfiguration() .getConfiguration()
.setSymbolResolver(new JavaSymbolSolver(javaParserTypeSolver)); .setSymbolResolver(new JavaSymbolSolver(javaParserTypeSolver));


CompilationUnit cu = StaticJavaParser.parse(extendingTypePath); CompilationUnit cu = StaticJavaParser.parse(implementingTypePath);
ClassOrInterfaceDeclaration extendingTypeClass = Navigator.demandClass(cu, "A"); ClassOrInterfaceDeclaration implementingTypeClass = Navigator.demandClass(cu, "A");


// Attempt to resolve `DuplicateTypeName` from `class ExtendingType implements **DuplicateTypeName**` // Attempt to resolve `DuplicateTypeName` from `class ImplementingType implements **DuplicateTypeName**`
assumeTrue(extendingTypeClass.getExtendedTypes().size() > 0); assumeTrue(implementingTypeClass.getImplementedTypes().size() > 0);
ClassOrInterfaceType implementedType = extendingTypeClass.getExtendedTypes(0); ClassOrInterfaceType implementedType = implementingTypeClass.getImplementedTypes(0);
ResolvedReferenceType resolvedImplementedType = implementedType.resolve(); ResolvedReferenceType resolvedImplementedType = implementedType.resolve();


// Verify qualified name matches the non-nested class in the same package. // Verify qualified name matches the non-nested class in the same package.
// Note verbose assertions show both the "correct" expected value, and the erroneous value to be avoided. // Note verbose assertions show both the "correct" expected value, and the erroneous value to be avoided.
String qualifiedName = resolvedImplementedType.getQualifiedName(); String qualifiedName = resolvedImplementedType.getQualifiedName();
assertEquals("testresource.DuplicateTypeName", qualifiedName, "Error - not resolved to interface in separate file."); assertEquals("implements_duplicate.DuplicateTypeName", qualifiedName, "Error - not resolved to interface in separate file.");
assertNotEquals("testresource.ExtendingType.DuplicateTypeName", qualifiedName, "Error - resolved to nested class."); assertNotEquals("implements_duplicate.A.DuplicateTypeName", qualifiedName, "Error - resolved to nested class.");
} }


} }
@@ -1,4 +1,4 @@
package testresource; package extends_duplicate;


public class A extends DuplicateTypeName { public class A extends DuplicateTypeName {
class DuplicateTypeName extends A { class DuplicateTypeName extends A {
Expand Down
@@ -1,4 +1,4 @@
package testresource; package extends_duplicate;


public abstract class DuplicateTypeName { public abstract class DuplicateTypeName {


Expand Down
@@ -1,4 +1,4 @@
package testresource; package implements_duplicate;


public class A implements DuplicateTypeName { public class A implements DuplicateTypeName {
class DuplicateTypeName extends A { class DuplicateTypeName extends A {
Expand Down
@@ -1,4 +1,4 @@
package testresource; package implements_duplicate;


public interface DuplicateTypeName { public interface DuplicateTypeName {


Expand Down

0 comments on commit 0978d70

Please sign in to comment.