IDEA-154389 Remove and restore superclass leads to wrong state of ClassToSubclasses mappings

This commit is contained in:
Eugene Zhuravlev
2016-04-21 19:42:31 +02:00
parent 8a035e0ecf
commit ba90cfbd86
7 changed files with 50 additions and 1 deletions
@@ -0,0 +1,13 @@
Cleaning output files:
out/production/IntegrateOnSuperclassRemovedAndRestored/A.class
End of files
Cleaning output files:
out/production/IntegrateOnSuperclassRemovedAndRestored/B.class
End of files
Compiling files:
src/B.java
End of files
Compiling files:
src/A.java
src/B.java
End of files
@@ -2164,6 +2164,31 @@ public class Mappings {
}
}
// Now that the list of added classes is complete,
// check that super-classes of compiled classes are among newly added ones.
// Even if compiled class did not change, we should register 'added' superclass
// Consider situation for class B extends A:
// 1. file A is removed, make fails with error in file B
// 2. A is added back, B and A are compiled together in the second make session
// 3. Even if B did not change, A is considered as newly added and should be registered again in ClassToSubclasses dependencies
// Without this code such registration will not happen because list of B's parents did not change
final Set<ClassRepr> addedClasses = myDelta.getAddedClasses();
if (!addedClasses.isEmpty()) {
final TIntHashSet addedNames = new TIntHashSet();
for (ClassRepr repr : addedClasses) {
addedNames.add(repr.name);
}
for (FileClasses compiledFile : newClasses) {
for (ClassRepr aClass : compiledFile.myFileClasses) {
for (int parent : aClass.getSupers()) {
if (addedNames.contains(parent)) {
myDelta.registerAddedSuperClass(aClass.name, parent);
}
}
}
}
}
debug("End of Differentiate.");
if (myEasyMode) {
@@ -149,7 +149,12 @@ public class CommonTest extends IncrementalTestCase {
JpsModuleRootModificationUtil.addDependency(moduleB, moduleA);
doTestBuild(1).assertSuccessful();
}
public void testIntegrateOnSuperclassRemovedAndRestored() throws Exception {
setupInitialProject();
doTestBuild(2);
}
public void testMoveToplevelClassToAnotherFile() throws Exception {
doTest();
}