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 {


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

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

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

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

// 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.
String qualifiedName = resolvedImplementedType.getQualifiedName();
assertEquals("testresource.DuplicateTypeName", qualifiedName, "Error - not resolved to interface in separate file.");
assertNotEquals("testresource.ExtendingType.DuplicateTypeName", qualifiedName, "Error - resolved to nested class.");
String qualifiedName = resolvedExtendedType.getQualifiedName();
assertEquals("extends_duplicate.DuplicateTypeName", qualifiedName, "Error - not resolved to interface in separate file.");
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
void testTypesWithSameNameInPackageAndNested_directExtends() throws IOException {
Path srcRootPath = adaptPath("src/test/resources/TypeResolutionWithSameNameTest/src1");
Path extendingTypePath = adaptPath("src/test/resources/TypeResolutionWithSameNameTest/src1/testresource/A.java");
void testTypesWithSameNameInPackageAndNested_directImplements() throws IOException {
Path srcRootPath = adaptPath("src/test/resources/TypeResolutionWithSameNameTest/src2");
Path implementingTypePath = adaptPath("src/test/resources/TypeResolutionWithSameNameTest/src2/implements_duplicate/A.java");

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

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

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

// 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.
String qualifiedName = resolvedImplementedType.getQualifiedName();
assertEquals("testresource.DuplicateTypeName", qualifiedName, "Error - not resolved to interface in separate file.");
assertNotEquals("testresource.ExtendingType.DuplicateTypeName", qualifiedName, "Error - resolved to nested class.");
assertEquals("implements_duplicate.DuplicateTypeName", qualifiedName, "Error - not resolved to interface in separate file.");
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 {
class DuplicateTypeName extends A {
Expand Down
@@ -1,4 +1,4 @@
package testresource;
package extends_duplicate;

public abstract class DuplicateTypeName {

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

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

public interface DuplicateTypeName {

Expand Down

0 comments on commit 0978d70

Please sign in to comment.