Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -28,79 +28,79 @@
* To change this template use Options | File Templates.
*/
public class GlobalAnalyzer {
private static boolean stepOneEnd(MarkedNode currNode, LinkedList worklist, OneEndFunctor functor) {
boolean result = false;

for (Iterator i = currNode.outIterator(); i.hasNext();) {
MarkedEdge currEdge = (MarkedEdge)i.next();
MarkedNode nextNode = (MarkedNode)currEdge.end();
Mark theMark = functor.compute(currNode.getMark(), currEdge.getMark(), nextNode.getMark());
if (!theMark.coincidesWith(nextNode.getMark())) {
result = true;
nextNode.setMark(theMark);
worklist.addFirst(nextNode);
}
private static boolean stepOneEnd(MarkedNode currNode, LinkedList worklist, OneEndFunctor functor) {
boolean result = false;

for (Iterator i = currNode.outIterator(); i.hasNext(); ) {
MarkedEdge currEdge = (MarkedEdge)i.next();
MarkedNode nextNode = (MarkedNode)currEdge.end();
Mark theMark = functor.compute(currNode.getMark(), currEdge.getMark(), nextNode.getMark());
if (!theMark.coincidesWith(nextNode.getMark())) {
result = true;
nextNode.setMark(theMark);
worklist.addFirst(nextNode);
}
}

return result;
}

return result;
}
private static boolean stepTwoEnds(final MarkedNode currNode, final LinkedList worklist, final TwoEndsFunctor functor) {
boolean result = false;

private static boolean stepTwoEnds(final MarkedNode currNode, final LinkedList worklist, final TwoEndsFunctor functor) {
boolean result = false;
for (Iterator i = currNode.outIterator(); i.hasNext(); ) {
final MarkedEdge currEdge = (MarkedEdge)i.next();
final MarkedNode nextNode = (MarkedNode)currEdge.end();
final Pair<Mark, Mark> markPair = functor.compute(currNode.getMark(), currEdge.getMark(), nextNode.getMark());

for (Iterator i = currNode.outIterator(); i.hasNext();) {
final MarkedEdge currEdge = (MarkedEdge)i.next();
final MarkedNode nextNode = (MarkedNode)currEdge.end();
final Pair<Mark,Mark> markPair = functor.compute(currNode.getMark(), currEdge.getMark(), nextNode.getMark());
final Mark leftMark = markPair.getFirst();
final Mark rightMark = markPair.getSecond();

final Mark leftMark = markPair.getFirst();
final Mark rightMark = markPair.getSecond();
if (!leftMark.coincidesWith(currNode.getMark())) {
result = true;
currNode.setMark(leftMark);
worklist.addFirst(currNode);
}

if (!leftMark.coincidesWith(currNode.getMark())) {
result = true;
currNode.setMark(leftMark);
worklist.addFirst(currNode);
}
if (!rightMark.coincidesWith(nextNode.getMark())) {
result = true;
nextNode.setMark(rightMark);
worklist.addFirst(nextNode);
}
}

if (!rightMark.coincidesWith(nextNode.getMark())) {
result = true;
nextNode.setMark(rightMark);
worklist.addFirst(nextNode);
}
return result;
}

return result;
}
public static <T extends MarkedNode> boolean doOneEnd(final LinkedList<T> init, final OneEndFunctor functor) {
boolean result = false;

public static <T extends MarkedNode>boolean doOneEnd(final LinkedList<T> init, final OneEndFunctor functor) {
boolean result = false;
final LinkedList<T> worklist = new LinkedList<T>();

final LinkedList<T> worklist = new LinkedList<T>();
for (Iterator<T> i = init.iterator(); i.hasNext(); ) {
result = stepOneEnd(i.next(), worklist, functor) || result;
}

for (Iterator<T> i = init.iterator(); i.hasNext();) {
result = stepOneEnd(i.next(), worklist, functor) || result;
}
while (worklist.size() > 0) {
result = stepOneEnd(worklist.removeFirst(), worklist, functor) || result;
}

while (worklist.size() > 0) {
result = stepOneEnd(worklist.removeFirst(), worklist, functor) || result;
return result;
}

return result;
}
public static <T extends MarkedNode> boolean doTwoEnds(final LinkedList<T> init, final TwoEndsFunctor functor) {
boolean result = false;

public static <T extends MarkedNode>boolean doTwoEnds(final LinkedList<T> init, final TwoEndsFunctor functor) {
boolean result = false;
final LinkedList<T> worklist = new LinkedList<T>();

final LinkedList<T> worklist = new LinkedList<T>();
for (Iterator<T> i = init.iterator(); i.hasNext(); ) {
result = stepTwoEnds(i.next(), worklist, functor) || result;
}

for (Iterator<T> i = init.iterator(); i.hasNext();) {
result = stepTwoEnds(i.next(), worklist, functor) || result;
}
while (worklist.size() > 0) {
result = stepTwoEnds(worklist.removeFirst(), worklist, functor) || result;
}

while (worklist.size() > 0) {
result = stepTwoEnds(worklist.removeFirst(), worklist, functor) || result;
return result;
}

return result;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import com.intellij.java.language.psi.*;
import com.intellij.java.language.psi.util.PsiUtil;
import consulo.annotation.access.RequiredReadAction;
import consulo.annotation.access.RequiredWriteAction;
import consulo.language.editor.refactoring.BaseRefactoringProcessor;
import consulo.language.editor.refactoring.ui.RefactoringUIUtil;
import consulo.language.psi.PsiElement;
Expand Down Expand Up @@ -121,6 +122,7 @@ protected UsageInfo[] findUsages() {
}

@Override
@RequiredWriteAction
protected void performRefactoring(@Nonnull UsageInfo[] usages) {
LocalHistoryAction a = LocalHistory.getInstance().startAction(getCommandName());
try {
Expand All @@ -134,6 +136,7 @@ protected void performRefactoring(@Nonnull UsageInfo[] usages) {
}
}

@RequiredWriteAction
private void doRefactoring(UsageInfo[] usages) throws IncorrectOperationException {
PsiTypeParameter[] typeParameters = myClass.getTypeParameters();
boolean[] toRemoveParms = detectRemovedParameters(typeParameters);
Expand Down Expand Up @@ -162,6 +165,7 @@ public void visitTypeElement(@Nonnull PsiTypeElement typeElement) {
changeClassSignature(typeParameters, toRemoveParms);
}

@RequiredWriteAction
private void changeClassSignature(PsiTypeParameter[] originalTypeParameters, boolean[] toRemoveParms)
throws IncorrectOperationException {
PsiElementFactory factory = JavaPsiFacade.getInstance(myClass.getProject()).getElementFactory();
Expand Down Expand Up @@ -190,6 +194,7 @@ private boolean[] detectRemovedParameters(PsiTypeParameter[] originaltypeParamet
return toRemoveParms;
}

@RequiredWriteAction
private void processUsage(UsageInfo usage, PsiTypeParameter[] originalTypeParameters, boolean[] toRemoveParms)
throws IncorrectOperationException {
PsiElementFactory factory = JavaPsiFacade.getInstance(myClass.getProject()).getElementFactory();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -244,8 +244,7 @@ private void askToRemoveCovariantOverriders(Set<UsageInfo> usages) {
if (PsiUtil.isLanguageLevel5OrHigher(myChangeInfo.getMethod())) {
List<UsageInfo> covariantOverriderInfos = new ArrayList<>();
for (UsageInfo usageInfo : usages) {
if (usageInfo instanceof OverriderUsageInfo) {
OverriderUsageInfo info = (OverriderUsageInfo)usageInfo;
if (usageInfo instanceof OverriderUsageInfo info) {
PsiMethod overrider = info.getElement();
PsiMethod baseMethod = info.getBaseMethod();
PsiSubstitutor substitutor = calculateSubstitutor(overrider, baseMethod);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import com.intellij.java.language.psi.JavaTokenType;
import com.intellij.java.language.psi.PsiMethod;
import com.intellij.java.language.psi.PsiType;
import consulo.annotation.access.RequiredWriteAction;
import consulo.language.editor.refactoring.RefactoringSupportProvider;
import consulo.language.editor.refactoring.changeSignature.ChangeSignatureHandler;
import consulo.language.editor.util.PsiUtilBase;
Expand All @@ -39,11 +40,12 @@ public class ChangeSignatureUtil {
private ChangeSignatureUtil() {
}

@RequiredWriteAction
public static <Parent extends PsiElement, Child extends PsiElement> void synchronizeList(
Parent list,
final List<Child> newElements,
List<Child> newElements,
ChildrenGenerator<Parent, Child> generator,
final boolean[] shouldRemoveChild
boolean[] shouldRemoveChild
) throws IncorrectOperationException {
ArrayList<Child> elementsToRemove = null;
List<Child> elements;
Expand Down Expand Up @@ -89,7 +91,7 @@ else if (newElements.size() > 1 && (!elements.isEmpty() || index < newElements.s
else {
anchor = index - 1 < elements.size() ? elements.get(index - 1) : null;
}
final PsiElement psi = Factory.createSingleLeafElement(
PsiElement psi = Factory.createSingleLeafElement(
JavaTokenType.COMMA,
",",
0,
Expand All @@ -114,14 +116,15 @@ else if (newElements.size() > 1 && (!elements.isEmpty() || index < newElements.s

@RequiredUIAccess
public static void invokeChangeSignatureOn(PsiMethod method, Project project) {
final ChangeSignatureHandler handler = RefactoringSupportProvider.forLanguage(method.getLanguage()).getChangeSignatureHandler();
ChangeSignatureHandler handler = RefactoringSupportProvider.forLanguage(method.getLanguage()).getChangeSignatureHandler();
handler.invoke(project, new PsiElement[]{method}, null);
}

public static boolean deepTypeEqual(PsiType type1, PsiType type2) {
if (type1 == type2) {
return true;
}
//noinspection SimplifiableIfStatement
if (type1 == null || !type1.equals(type2)) {
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,29 +142,29 @@ else if (element instanceof PsiDocTagValue) {
@RequiredUIAccess
protected boolean preprocessUsages(@Nonnull SimpleReference<UsageInfo[]> refUsages) {
UsageInfo[] usagesIn = refUsages.get();
MultiMap<PsiElement, String> conflicts = new MultiMap<PsiElement, String>();
final Set<PsiMember> methods = Collections.singleton((PsiMember)myMethod);
MultiMap<PsiElement, String> conflicts = new MultiMap<>();
Set<PsiMember> methods = Collections.singleton((PsiMember)myMethod);
if (!myTargetClass.isInterface()) {
RefactoringConflictsUtil.analyzeAccessibilityConflicts(methods, myTargetClass, conflicts, myNewVisibility);
}
else {
for (final UsageInfo usage : usagesIn) {
if (usage instanceof ImplementingClassUsageInfo) {
for (UsageInfo usage : usagesIn) {
if (usage instanceof ImplementingClassUsageInfo implementingClassUsageInfo) {
RefactoringConflictsUtil.analyzeAccessibilityConflicts(
methods,
((ImplementingClassUsageInfo)usage).getPsiClass(),
implementingClassUsageInfo.getPsiClass(),
conflicts,
PsiModifier.PUBLIC
);
}
}
}

for (final UsageInfo usageInfo : usagesIn) {
if (usageInfo instanceof MethodCallUsageInfo) {
final PsiMethodCallExpression methodCall = ((MethodCallUsageInfo)usageInfo).getMethodCall();
final PsiExpression[] expressions = methodCall.getArgumentList().getExpressions();
final int index = myMethod.getParameterList().getParameterIndex(myTargetParameter);
for (UsageInfo usageInfo : usagesIn) {
if (usageInfo instanceof MethodCallUsageInfo methodCallUsageInfo) {
PsiMethodCallExpression methodCall = methodCallUsageInfo.getMethodCall();
PsiExpression[] expressions = methodCall.getArgumentList().getExpressions();
int index = myMethod.getParameterList().getParameterIndex(myTargetParameter);
if (index < expressions.length) {
PsiExpression instanceValue = expressions[index];
instanceValue = RefactoringUtil.unparenthesizeExpression(instanceValue);
Expand All @@ -182,7 +182,9 @@ protected boolean preprocessUsages(@Nonnull SimpleReference<UsageInfo[]> refUsag
return showConflicts(conflicts, usagesIn);
}

protected void performRefactoring(UsageInfo[] usages) {
@Override
@RequiredUIAccess
protected void performRefactoring(@Nonnull UsageInfo[] usages) {
if (!CommonRefactoringUtil.checkReadOnlyStatus(myProject, myTargetClass)) {
return;
}
Expand All @@ -200,12 +202,12 @@ protected void performRefactoring(UsageInfo[] usages) {

private void doRefactoring(UsageInfo[] usages) throws IncorrectOperationException {
myTypeParameterReplacements = buildTypeParameterReplacements();
List<PsiClass> inheritors = new ArrayList<PsiClass>();
List<PsiClass> inheritors = new ArrayList<>();

CommonRefactoringUtil.sortDepthFirstRightLeftOrder(usages);

// Process usages
for (final UsageInfo usage : usages) {
for (UsageInfo usage : usages) {
if (usage instanceof MethodCallUsageInfo) {
processMethodCall((MethodCallUsageInfo)usage);
}
Expand All @@ -225,15 +227,15 @@ else if (usage instanceof ImplementingClassUsageInfo) {
fixVisibility(method, usages);
}
else {
final PsiMethod interfaceMethod = addMethodToClass(myTargetClass);
final PsiModifierList modifierList = interfaceMethod.getModifierList();
PsiMethod interfaceMethod = addMethodToClass(myTargetClass);
PsiModifierList modifierList = interfaceMethod.getModifierList();
modifierList.setModifierProperty(PsiModifier.PRIVATE, false);
modifierList.setModifierProperty(PsiModifier.PUBLIC, false);
modifierList.setModifierProperty(PsiModifier.PROTECTED, false);
RefactoringUtil.makeMethodAbstract(myTargetClass, interfaceMethod);

for (final PsiClass psiClass : inheritors) {
final PsiMethod newMethod = addMethodToClass(psiClass);
for (PsiClass psiClass : inheritors) {
PsiMethod newMethod = addMethodToClass(psiClass);
PsiUtil.setModifierProperty(
newMethod,
myNewVisibility != null && !myNewVisibility.equals(VisibilityUtil.ESCALATE_VISIBILITY) ? myNewVisibility
Expand All @@ -245,12 +247,12 @@ else if (usage instanceof ImplementingClassUsageInfo) {
myMethod.delete();
}

private void fixVisibility(final PsiMethod method, final UsageInfo[] usages) throws IncorrectOperationException {
final PsiModifierList modifierList = method.getModifierList();
private void fixVisibility(PsiMethod method, UsageInfo[] usages) throws IncorrectOperationException {
PsiModifierList modifierList = method.getModifierList();
if (VisibilityUtil.ESCALATE_VISIBILITY.equals(myNewVisibility)) {
for (UsageInfo usage : usages) {
if (usage instanceof MethodCallUsageInfo) {
final PsiElement place = usage.getElement();
PsiElement place = usage.getElement();
if (place != null) {
VisibilityUtil.escalateVisibility(method, place);
}
Expand Down
Loading
Loading