type migration: do not add roots outside source content IDEA-163223

This commit is contained in:
Dmitry Batkovich
2016-11-01 12:11:27 +03:00
parent 9caa6d5ede
commit 96d85271d7
@@ -21,6 +21,7 @@ import com.intellij.lang.java.JavaLanguage;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.roots.ProjectRootManager;
import com.intellij.openapi.ui.Messages;
import com.intellij.openapi.util.Comparing;
import com.intellij.openapi.util.Pair;
@@ -575,18 +576,12 @@ public class TypeMigrationLabeler {
if (type.equals(PsiType.NULL)) {
return false;
}
final PsiElement resolved = Util.normalizeElement(element);
final SearchScope searchScope = myRules.getSearchScope();
if (!resolved.isPhysical() || !PsiSearchScopeUtil.isInScope(searchScope, resolved)) {
if (!canBeRoot(resolved, myRules.getSearchScope())) {
return false;
}
final PsiType originalType = getElementType(resolved);
LOG.assertTrue(originalType != null);
type = userDefinedType ? type : TypeEvaluator.substituteType(type, originalType, isContraVariantPosition);
if (!userDefinedType) {
@@ -1123,6 +1118,14 @@ public class TypeMigrationLabeler {
return refs;
}
private boolean canBeRoot(@Nullable PsiElement element, @NotNull SearchScope migrationScope) {
if (element == null) return false;
return element.isValid() &&
element.isPhysical() &&
PsiSearchScopeUtil.isInScope(migrationScope, element) &&
ProjectRootManager.getInstance(element.getProject()).getFileIndex().isInSourceContent(element.getContainingFile().getVirtualFile());
}
@TestOnly
public String getMigrationReport() {
final StringBuilder buffer = new StringBuilder();