From e72fe6bd81146582cb319ab9d926b993f648bbed Mon Sep 17 00:00:00 2001 From: "Anna.Kozlova" Date: Fri, 29 Apr 2016 12:14:25 +0200 Subject: [PATCH] push down: provide context for newly created class to check resulted accessibility (IDEA-155387) --- .../memberPushDown/JavaPushDownDelegate.java | 17 ++++++++++++++--- .../memberPushDown/PushDownDelegate.java | 9 ++++++--- .../memberPushDown/PushDownProcessor.java | 4 ++-- 3 files changed, 22 insertions(+), 8 deletions(-) diff --git a/java/java-impl/src/com/intellij/refactoring/memberPushDown/JavaPushDownDelegate.java b/java/java-impl/src/com/intellij/refactoring/memberPushDown/JavaPushDownDelegate.java index a2a76dfc7d73..c344f6df60a1 100644 --- a/java/java-impl/src/com/intellij/refactoring/memberPushDown/JavaPushDownDelegate.java +++ b/java/java-impl/src/com/intellij/refactoring/memberPushDown/JavaPushDownDelegate.java @@ -45,6 +45,7 @@ import com.intellij.util.IncorrectOperationException; import com.intellij.util.containers.HashSet; import com.intellij.util.containers.MultiMap; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import java.util.*; @@ -90,11 +91,21 @@ public class JavaPushDownDelegate extends PushDownDelegate pushDownData, - MultiMap conflicts) { + MultiMap conflicts, + NewSubClassData subClassData) { List toMove = pushDownData.getMembersToMove(); - new PushDownConflicts((PsiClass)pushDownData.getSourceClass(), toMove.toArray(new MemberInfo[0]), conflicts).checkTargetClassConflicts(targetClass, targetClass); + PsiElement context = targetClass; + if (context == null) { + assert subClassData != null; + Object newClassContext = subClassData.getContext(); + if (newClassContext instanceof PsiElement) { + context = (PsiElement)newClassContext; + } + } + new PushDownConflicts((PsiClass)pushDownData.getSourceClass(), toMove.toArray(new MemberInfo[0]), conflicts) + .checkTargetClassConflicts(targetClass, context); } @Override diff --git a/platform/lang-impl/src/com/intellij/refactoring/memberPushDown/PushDownDelegate.java b/platform/lang-impl/src/com/intellij/refactoring/memberPushDown/PushDownDelegate.java index 7d5dbcfde902..c85aedc6d4bf 100644 --- a/platform/lang-impl/src/com/intellij/refactoring/memberPushDown/PushDownDelegate.java +++ b/platform/lang-impl/src/com/intellij/refactoring/memberPushDown/PushDownDelegate.java @@ -54,7 +54,7 @@ public abstract class PushDownDelegate * Implementations are supposed to override this method when overriding default behaviour for the language, * e.g. pushing members from groovy class to java, groovy could provide additional delegate which inherits delegate for java and accepts groovy sources. * Methods to process target class should be updated to cope with source of another language (e.g. calling super on PushDownData translated to java): - * {@link #checkTargetClassConflicts(PsiElement, PushDownData, MultiMap) }, + * {@link #checkTargetClassConflicts(PsiElement, PushDownData, MultiMap, NewSubClassData) }, * {@link #pushDownToClass(PsiElement, PushDownData)} */ protected abstract boolean isApplicableForSource(@NotNull PsiElement sourceClass); @@ -78,10 +78,13 @@ public abstract class PushDownDelegate * Collect conflicts inside targetClass assuming methods would be pushed, * e.g. check if target class already has field with the same name, some references types * won't be accessible anymore, etc + * + * If targetClass == null (target class should be created), then subClassData would be not null */ - protected abstract void checkTargetClassConflicts(PsiElement targetClass, + protected abstract void checkTargetClassConflicts(@Nullable PsiElement targetClass, PushDownData pushDownData, - MultiMap conflicts); + MultiMap conflicts, + @Nullable NewSubClassData subClassData); /** * Could be used e.g. to encode mutual references between moved members diff --git a/platform/lang-impl/src/com/intellij/refactoring/memberPushDown/PushDownProcessor.java b/platform/lang-impl/src/com/intellij/refactoring/memberPushDown/PushDownProcessor.java index eab53508ba7e..1f280b23da73 100644 --- a/platform/lang-impl/src/com/intellij/refactoring/memberPushDown/PushDownProcessor.java +++ b/platform/lang-impl/src/com/intellij/refactoring/memberPushDown/PushDownProcessor.java @@ -109,7 +109,7 @@ public class PushDownProcessor, } Runnable runnable = () -> ApplicationManager.getApplication().runReadAction(() -> { if (mySubClassData != null) { - myDelegate.checkTargetClassConflicts(null, myPushDownData, conflicts); + myDelegate.checkTargetClassConflicts(null, myPushDownData, conflicts, mySubClassData); } else { for (UsageInfo usage : usagesIn) { @@ -117,7 +117,7 @@ public class PushDownProcessor, if (element != null) { final PushDownDelegate delegate = PushDownDelegate.findDelegateForTarget(myPushDownData.getSourceClass(), element); if (delegate != null) { - delegate.checkTargetClassConflicts(element, myPushDownData, conflicts); + delegate.checkTargetClassConflicts(element, myPushDownData, conflicts, null); } else { conflicts.putValue(element, "Not supported source/target pair detected");