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 @@ -202,7 +202,7 @@ private static ExtractMethodProcessor getProcessor(
}

final ExtractMethodProcessor processor =
new ExtractMethodProcessor(project, editor, elements, null, REFACTORING_NAME, "", HelpID.EXTRACT_METHOD);
new ExtractMethodProcessor(project, editor, elements, null, REFACTORING_NAME.get(), "", HelpID.EXTRACT_METHOD);
processor.setShowErrorDialogs(showErrorMessages);
try {
if (!processor.prepare(pass)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ public static PsiTypeParameter findTypeParameterInDerived(final PsiClass aClass,
return null;
}

public static void checkSuperAccessible(PsiDirectory targetDirectory, MultiMap<PsiElement, String> conflicts, final PsiClass subclass) {
public static void checkSuperAccessible(PsiDirectory targetDirectory, MultiMap<PsiElement, LocalizeValue> conflicts, PsiClass subclass) {
final VirtualFile virtualFile = subclass.getContainingFile().getVirtualFile();
if (virtualFile != null) {
final boolean inTestSourceContent =
Expand All @@ -251,7 +251,7 @@ public static void checkSuperAccessible(PsiDirectory targetDirectory, MultiMap<P
module != null &&
!GlobalSearchScope.moduleWithDependenciesAndLibrariesScope(module, inTestSourceContent)
.contains(targetDirectory.getVirtualFile())) {
conflicts.putValue(subclass, "Superclass won't be accessible in subclass");
conflicts.putValue(subclass, LocalizeValue.localizeTODO("Superclass won't be accessible in subclass"));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ private boolean convertExpressionToField(

PsiElement tempAnchorElement = RefactoringUtil.getParentExpressionAnchorElement(selectedExpr);
if (!IntroduceConstantHandlerImpl.REFACTORING_NAME.equals(getRefactoringName())
&& IntroduceVariableBase.checkAnchorBeforeThisOrSuper(project, editor, tempAnchorElement, getRefactoringName(), getHelpID())) {
&& IntroduceVariableBase.checkAnchorBeforeThisOrSuper(project, editor, tempAnchorElement, getRefactoringName().get(), getHelpID())) {
return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,64 +27,67 @@
import consulo.util.collection.MultiMap;

import java.util.HashSet;
import java.util.Set;

public class InputValidator implements IntroduceVariableBase.Validator {
private final Project myProject;
private final PsiElement myAnchorStatementIfAll;
private final PsiElement myAnchorStatement;
private final ExpressionOccurrenceManager myOccurenceManager;
private final IntroduceVariableBase myIntroduceVariableBase;
private final Project myProject;
private final PsiElement myAnchorStatementIfAll;
private final PsiElement myAnchorStatement;
private final ExpressionOccurrenceManager myOccurrenceManager;
private final IntroduceVariableBase myIntroduceVariableBase;

public boolean isOK(IntroduceVariableSettings settings) {
String name = settings.getEnteredName();
final PsiElement anchor;
final boolean replaceAllOccurrences = settings.isReplaceAllOccurrences();
if (replaceAllOccurrences) {
anchor = myAnchorStatementIfAll;
} else {
anchor = myAnchorStatement;
}
final PsiElement scope = anchor.getParent();
if(scope == null) return true;
final MultiMap<PsiElement, String> conflicts = new MultiMap<PsiElement, String>();
final HashSet<PsiVariable> reportedVariables = new HashSet<PsiVariable>();
JavaUnresolvableLocalCollisionDetector.CollidingVariableVisitor visitor = new JavaUnresolvableLocalCollisionDetector.CollidingVariableVisitor() {
public void visitCollidingElement(PsiVariable collidingVariable) {
if (!reportedVariables.contains(collidingVariable)) {
reportedVariables.add(collidingVariable);
LocalizeValue message =
RefactoringLocalize.introducedVariableWillConflictWith0(RefactoringUIUtil.getDescription(collidingVariable, true));
conflicts.putValue(collidingVariable, message.get());
@Override
public boolean isOK(IntroduceVariableSettings settings) {
String name = settings.getEnteredName();
PsiElement anchor;
boolean replaceAllOccurrences = settings.isReplaceAllOccurrences();
if (replaceAllOccurrences) {
anchor = myAnchorStatementIfAll;
}
else {
anchor = myAnchorStatement;
}
PsiElement scope = anchor.getParent();
if (scope == null) {
return true;
}
MultiMap<PsiElement, LocalizeValue> conflicts = new MultiMap<>();
Set<PsiVariable> reportedVariables = new HashSet<>();
JavaUnresolvableLocalCollisionDetector.CollidingVariableVisitor visitor = collidingVariable -> {
if (!reportedVariables.contains(collidingVariable)) {
reportedVariables.add(collidingVariable);
LocalizeValue message =
RefactoringLocalize.introducedVariableWillConflictWith0(RefactoringUIUtil.getDescription(
collidingVariable,
true
));
conflicts.putValue(collidingVariable, message);
}
};
JavaUnresolvableLocalCollisionDetector.visitLocalsCollisions(anchor, name, scope, anchor, visitor);
if (replaceAllOccurrences) {
for (PsiExpression occurrence : myOccurrenceManager.getOccurrences()) {
IntroduceVariableBase.checkInLoopCondition(occurrence, conflicts);
}
}
else {
IntroduceVariableBase.checkInLoopCondition(myOccurrenceManager.getMainOccurence(), conflicts);
}
}
};
JavaUnresolvableLocalCollisionDetector.visitLocalsCollisions(anchor, name, scope, anchor, visitor);
if (replaceAllOccurrences) {
final PsiExpression[] occurences = myOccurenceManager.getOccurrences();
for (PsiExpression occurence : occurences) {
IntroduceVariableBase.checkInLoopCondition(occurence, conflicts);
}
} else {
IntroduceVariableBase.checkInLoopCondition(myOccurenceManager.getMainOccurence(), conflicts);
}

if (conflicts.size() > 0) {
return myIntroduceVariableBase.reportConflicts(conflicts, myProject, settings);
} else {
return true;
return conflicts.size() <= 0 || myIntroduceVariableBase.reportConflicts(conflicts, myProject, settings);
}
}


public InputValidator(final IntroduceVariableBase introduceVariableBase,
Project project,
PsiElement anchorStatementIfAll,
PsiElement anchorStatement,
ExpressionOccurrenceManager occurenceManager) {
myIntroduceVariableBase = introduceVariableBase;
myProject = project;
myAnchorStatementIfAll = anchorStatementIfAll;
myAnchorStatement = anchorStatement;
myOccurenceManager = occurenceManager;
}
public InputValidator(
IntroduceVariableBase introduceVariableBase,
Project project,
PsiElement anchorStatementIfAll,
PsiElement anchorStatement,
ExpressionOccurrenceManager occurrenceManager
) {
myIntroduceVariableBase = introduceVariableBase;
myProject = project;
myAnchorStatementIfAll = anchorStatementIfAll;
myAnchorStatement = anchorStatement;
myOccurrenceManager = occurrenceManager;
}
}
Loading
Loading