Extract common parts from 'if'

GitOrigin-RevId: 60ebdfdb9588caf907ef111e3ed08e799c0a7d17
This commit is contained in:
Tagir Valeev
2019-07-25 10:03:44 +03:00
committed by intellij-monorepo-bot
parent 58cabf86c4
commit 3e12574595
34 changed files with 63 additions and 141 deletions
@@ -272,14 +272,15 @@ public class DebuggerTreeRenderer extends ColoredTreeCellRenderer {
final EvaluateException exception = descriptor.getEvaluateException();
if(exception != null) {
final String errorMessage = exception.getMessage();
if(valueLabel.endsWith(errorMessage)) {
appendValueTextWithEscapesRendering(descriptorText, valueLabel.substring(0, valueLabel.length() - errorMessage.length()), valueLabelAttribs, colorScheme);
descriptorText.append(errorMessage, XDebuggerUIConstants.EXCEPTION_ATTRIBUTES);
final String valueText;
if (valueLabel.endsWith(errorMessage)) {
valueText = valueLabel.substring(0, valueLabel.length() - errorMessage.length());
}
else {
appendValueTextWithEscapesRendering(descriptorText, valueLabel, valueLabelAttribs, colorScheme);
descriptorText.append(errorMessage, XDebuggerUIConstants.EXCEPTION_ATTRIBUTES);
valueText = valueLabel;
}
appendValueTextWithEscapesRendering(descriptorText, valueText, valueLabelAttribs, colorScheme);
descriptorText.append(errorMessage, XDebuggerUIConstants.EXCEPTION_ATTRIBUTES);
}
else {
if(valueLabel.equals(XDebuggerUIConstants.COLLECTING_DATA_MESSAGE)) {
@@ -33,12 +33,11 @@ class LoopAnalyzer {
int[] froms = myIns.get(toIndex);
if (froms == null) {
froms = new int[]{fromIndex};
myIns.put(toIndex, froms);
}
else {
froms = ArrayUtil.append(froms, fromIndex);
myIns.put(toIndex, froms);
}
myIns.put(toIndex, froms);
}
}
}
@@ -153,7 +153,6 @@ public final class Match {
myParameterValues.put(psiVariable, values);
final ArrayList<PsiElement> elements = new ArrayList<>();
myParameterOccurrences.put(psiVariable, elements);
return true;
}
else {
for (PsiElement val : currentValue) {
@@ -168,8 +167,8 @@ public final class Match {
}
}
myParameterOccurrences.get(psiVariable).add(value);
return true;
}
return true;
}
public ReturnValue getReturnValue() {
@@ -67,7 +67,6 @@ public class PsiGenerationInfo<T extends PsiMember> extends GenerationInfoBase i
PsiElement newMember = GenerateMembersUtil.insert(aClass, member, anchor, before);
member = (T)JavaCodeStyleManager.getInstance(aClass.getProject()).shortenClassReferences(newMember);
LOG.assertTrue(member.isValid(), member);
setMember(member);
}
else {
final PsiModifierList modifierList = member.getModifierList();
@@ -94,7 +93,7 @@ public class PsiGenerationInfo<T extends PsiMember> extends GenerationInfoBase i
" self modified list: " + modifierList +
" existing modified list: " + existingModifierList);
}
setMember(member);
}
setMember(member);
}
}
@@ -960,24 +960,16 @@ public class InheritanceToDelegationProcessor extends BaseRefactoringProcessor {
if (classMember != null && myBaseClassMembers.contains(classMember) && !isDelegated(classMember)) {
final FieldAccessibility delegateFieldVisibility = new FieldAccessibility(true, getPsiClass());
final InheritanceToDelegationUsageInfo usageInfo;
if (classMemberReference instanceof PsiReferenceExpression) {
if (((PsiReferenceExpression) classMemberReference).getQualifierExpression() == null) {
usageInfo = new UnqualifiedNonDelegatedMemberUsageInfo(classMemberReference, classMember,
delegateFieldVisibility);
} else {
usageInfo = new NonDelegatedMemberUsageInfo(
((PsiReferenceExpression) classMemberReference).getQualifierExpression(),
classMember, delegateFieldVisibility
);
}
myUsageInfoStorage.add(usageInfo);
if (classMemberReference instanceof PsiReferenceExpression &&
((PsiReferenceExpression)classMemberReference).getQualifierExpression() != null) {
usageInfo = new NonDelegatedMemberUsageInfo(((PsiReferenceExpression)classMemberReference).getQualifierExpression(),
classMember, delegateFieldVisibility);
}
else /*if (classMemberReference instanceof PsiJavaCodeReferenceElement)*/ {
usageInfo = new UnqualifiedNonDelegatedMemberUsageInfo(classMemberReference, classMember,
delegateFieldVisibility);
myUsageInfoStorage.add(usageInfo);
else {
usageInfo = new UnqualifiedNonDelegatedMemberUsageInfo(classMemberReference, classMember,
delegateFieldVisibility);
}
myUsageInfoStorage.add(usageInfo);
}
}
@@ -1004,7 +996,7 @@ public class InheritanceToDelegationProcessor extends BaseRefactoringProcessor {
}
/**
* This visitor should be called for overriden methods before they are moved to an inner class
* This visitor should be called for overridden methods before they are moved to an inner class
*/
private class OverriddenMethodClassMemberReferencesVisitor extends ClassMemberReferencesVisitor {
private final ArrayList<PsiAction> myPsiActions;
@@ -85,7 +85,6 @@ public class UsageContextDataflowToPanel extends UsageContextPanelBase {
removeAll();
JComponent titleComp = new JLabel(UsageViewBundle.message("select.the.usage.to.preview", myPresentation.getUsagesWord()), SwingConstants.CENTER);
add(titleComp, BorderLayout.CENTER);
revalidate();
}
else {
PsiElement element = getElementToSliceOn(infos);
@@ -99,8 +98,8 @@ public class UsageContextDataflowToPanel extends UsageContextPanelBase {
Disposer.register(this, (Disposable)panel);
removeAll();
add(panel, BorderLayout.CENTER);
revalidate();
}
revalidate();
}
protected boolean isDataflowToThis() {
@@ -379,13 +379,12 @@ public class EnterHandler extends BaseEnterHandler {
if (isCommentComplete(comment, commentContext.commenter, myEditor)) {
if (myOffset >= commentEnd) {
commentContext.docAsterisk = false;
commentContext.docStart = false;
}
else {
commentContext.docAsterisk =
CodeStyleManager.getInstance(getProject()).getDocCommentSettings(myFile).isLeadingAsteriskEnabled();
commentContext.docStart = false;
}
commentContext.docStart = false;
}
else {
generateJavadoc(commentContext.commenter);
@@ -113,11 +113,10 @@ public class SuppressActionWrapper extends ActionGroup implements CompactActionG
text = mySuppressAction.getText();
}
e.getPresentation().setText(text);
return true;
} else {
e.getPresentation().setText(mySuppressAction.getFamilyName());
return true;
}
return true;
}
public boolean isSuppressAll() {
@@ -132,10 +132,7 @@ public class CloseSearchTask extends SearchTaskBase {
* if such result exists; '-1' if doesn't.
*/
private static int tryGetClosestResult(ArrayList<SearchResult> allMatchesAtFrame, SearchTaskOptions options) {
if (allMatchesAtFrame.isEmpty()) {
return -1;
}
else {
if (!allMatchesAtFrame.isEmpty()) {
SearchResult searchResult;
if (options.searchForwardDirection) {
@@ -169,7 +166,7 @@ public class CloseSearchTask extends SearchTaskBase {
}
}
}
return -1;
}
return -1;
}
}
@@ -128,7 +128,6 @@ public class DetectedRootsChooserDialog extends DialogWrapper {
VirtualFile file = node.getFile();
String text;
SimpleTextAttributes attributes;
Icon icon;
boolean isValid = true;
if (leaf) {
VirtualFile ancestor = ((VirtualFileCheckedTreeNode)node.getParent()).getFile();
@@ -146,15 +145,13 @@ public class DetectedRootsChooserDialog extends DialogWrapper {
text = file.getPresentableUrl();
}
attributes = SimpleTextAttributes.REGULAR_ATTRIBUTES;
icon = PlatformIcons.FOLDER_ICON;
}
else {
text = file.getPresentableUrl();
attributes = SimpleTextAttributes.REGULAR_BOLD_ATTRIBUTES;
icon = PlatformIcons.FOLDER_ICON;
}
final ColoredTreeCellRenderer textRenderer = getTextRenderer();
textRenderer.setIcon(icon);
textRenderer.setIcon(PlatformIcons.FOLDER_ICON);
if (!isValid) {
textRenderer.append("[INVALID] ", SimpleTextAttributes.ERROR_ATTRIBUTES);
}
@@ -31,17 +31,13 @@ public class NameSuggester {
myNewClassName = NameUtilCore.splitNameIntoWords(newClassName);
myChanges = new ArrayList<>();
int oldIndex = myOldClassName.length - 1;
int oldLastMatch = myOldClassName.length;
int newLastMatch = myNewClassName.length;
while(oldIndex >= 0) {
for (int oldIndex = myOldClassName.length - 1; oldIndex >= 0; oldIndex--) {
final String patternWord = myOldClassName[oldIndex];
final int matchingWordIndex = findInNewBackwardsFromIndex(patternWord, newLastMatch - 1);
if (matchingWordIndex < 0) { // no matching word
oldIndex--;
}
else { // matching word found
if (matchingWordIndex >= 0) { // matching word found
if (oldIndex + 1 <= oldLastMatch - 1 || matchingWordIndex + 1 <= newLastMatch - 1) {
final OriginalToNewChange change = new OriginalToNewChange(
oldIndex + 1, oldLastMatch - 1, matchingWordIndex + 1, newLastMatch - 1);
@@ -49,7 +45,6 @@ public class NameSuggester {
}
oldLastMatch = oldIndex;
newLastMatch = matchingWordIndex;
oldIndex--;
}
}
if (0 <= oldLastMatch - 1 || 0 <= newLastMatch - 1) {
@@ -99,7 +99,6 @@ public class UsageContextCallHierarchyPanel extends UsageContextPanelBase {
if (element == null) {
JComponent titleComp = new JLabel(UsageViewBundle.message("select.the.usage.to.preview", myPresentation.getUsagesWord()), SwingConstants.CENTER);
add(titleComp, BorderLayout.CENTER);
revalidate();
}
else {
if (myBrowser instanceof Disposable) {
@@ -107,8 +106,8 @@ public class UsageContextCallHierarchyPanel extends UsageContextPanelBase {
}
JComponent panel = myBrowser.getComponent();
add(panel, BorderLayout.CENTER);
revalidate();
}
revalidate();
}
@Nullable
@@ -496,13 +496,12 @@ public abstract class AbstractWizard<T extends Step> extends DialogWrapper {
else {
myNextButton.setText(IdeBundle.message("button.ok"));
}
myNextButton.setEnabled(canGoNext);
}
else {
myNextButton.setText(UIUtil.removeMnemonic(IdeBundle.message("button.wizard.next")));
myNextButton.setMnemonic('N');
myNextButton.setEnabled(canGoNext);
}
myNextButton.setEnabled(canGoNext);
if (myNextButton.isEnabled() && !ApplicationManager.getApplication().isUnitTestMode() && getRootPane() != null) {
getRootPane().setDefaultButton(myNextButton);
@@ -204,7 +204,6 @@ public class PopupUtil {
MenuElement[] selectedPath = menuSelectionManager.getSelectedPath();
if (selectedPath.length > 0) { // hide popup menu if any
menuSelectionManager.clearSelectedPath();
return true;
}
else {
if (ApplicationManager.getApplication() == null) {
@@ -214,7 +213,7 @@ public class PopupUtil {
if (popupDispatcher != null && !popupDispatcher.isPopupFocused()) {
return false;
}
return true;
}
return true;
}
}
@@ -95,19 +95,13 @@ public class RowsDnDSupport {
event.setHighlighting(rectangle, DnDEvent.DropTargetHighlightingType.FILLED_RECTANGLE);
break;
}
return true;
}
else {
event.hideHighlighter();
return true;
}
}
else {
if (oldIndex == newIndex) { // Drag&Drop always starts with new==old and we shouldn't display 'rejecting' cursor in this case
return true;
}
else if (oldIndex != newIndex) {
// Drag&Drop always starts with new==old and we shouldn't display 'rejecting' cursor if they are equal
boolean canExchange = model.canExchangeRows(oldIndex, newIndex);
if (canExchange) {
if (oldIndex < newIndex) {
@@ -121,8 +115,8 @@ public class RowsDnDSupport {
else {
event.setDropPossible(false);
}
return true;
}
return true;
}
})
.setDropHandler(new DnDDropHandler() {
@@ -1123,16 +1123,14 @@ public class UiDropperAction extends ToggleAction implements DumbAware {
window.switchInfo(c);
//window.highlightCmp(true);
window.setVisible(true);
window.toFront();
}
else {
window = new InspectorWindow(c);
myComponentToInspector.put(c, window);
window.pack();
window.setVisible(true);
window.toFront();
}
window.setVisible(true);
window.toFront();
}
@Override
@@ -73,14 +73,8 @@ class HttpVirtualFileImpl extends HttpVirtualFile {
}
else {
int prevSlash = path.lastIndexOf('/', lastSlash - 1);
if (prevSlash < 0) {
myParentPath = path.substring(0, lastSlash + 1);
myName = path.substring(lastSlash + 1);
}
else {
myParentPath = path.substring(0, lastSlash);
myName = path.substring(lastSlash + 1);
}
myParentPath = path.substring(0, prevSlash < 0 ? lastSlash + 1 : lastSlash);
myName = path.substring(lastSlash + 1);
}
}
}
@@ -92,13 +92,8 @@ public class SliderSelectorAction extends DumbAwareAction {
slider.setPaintLabels(true);
slider.setLabelTable(dictionary);
if (! myConfiguration.isShowOk()) {
result.add(wrapper, BorderLayout.WEST);
result.add(slider, BorderLayout.CENTER);
} else {
result.add(wrapper, BorderLayout.WEST);
result.add(slider, BorderLayout.CENTER);
}
result.add(wrapper, BorderLayout.WEST);
result.add(slider, BorderLayout.CENTER);
final Runnable saveSelection = () -> {
int value = slider.getModel().getValue();
@@ -66,23 +66,21 @@ public class MacPopupMenuUI extends BasicPopupMenuUI {
if (rectangle1.x + rectangle1.width < rectangle.x + 10) {
if (flag) {
graphics2d.fillRect(-2, -2, 8, 8);
return;
}
else {
graphics2d.fillRect(-2, rectangle.height - 6, 8, 8);
return;
}
return;
}
if (rectangle.x + rectangle.width < rectangle1.x + 10) {
if (flag) {
graphics2d.fillRect(rectangle.width - 6, -2, 8, 8);
return;
}
else {
graphics2d.fillRect(rectangle.width - 6, rectangle.height - 6, 8, 8);
return;
}
return;
}
if (rectangle1.y + rectangle1.height < rectangle.y + 10) {
@@ -191,12 +191,7 @@ public class BegTabbedPaneUI extends MetalTabbedPaneUI {
UIUtil.drawLine(g, x, y, selRect.x, y);
if (selRect.x + selRect.width < right - 1) {
if (leftToRight && !lastInRun) {
UIUtil.drawLine(g, selRect.x + selRect.width - 2, y, right, y);
}
else {
UIUtil.drawLine(g, selRect.x + selRect.width - 2, y, right, y);
}
UIUtil.drawLine(g, selRect.x + selRect.width - 2, y, right, y);
}
else {
UIUtil.drawLine(g, x + w - 2, y, x + w - 2, y);
@@ -187,11 +187,10 @@ public class TestsUIUtil {
if (icon.hideProgress(project, TESTS)) {
if (problemsCounter > 0) {
icon.setErrorBadge(project, String.valueOf(problemsCounter));
icon.requestAttention(project, false);
} else {
icon.setOkBadge(project, true);
icon.requestAttention(project, false);
}
icon.requestAttention(project, false);
}
}
}
@@ -105,13 +105,11 @@ public class TemporaryPlacesRegistry {
newHost.putUserData(LanguageInjectionSupport.TEMPORARY_INJECTED_LANGUAGE, place.language);
place.elementPointer = SmartPointerManager.createPointer(newHost);
return false;
}
else {
element.putUserData(LanguageInjectionSupport.TEMPORARY_INJECTED_LANGUAGE, place.language);
return false;
}
return false;
});
if (!placesToRemove.isEmpty()) {
myTempPlaces.removeAll(placesToRemove);
@@ -135,17 +135,16 @@ public abstract class AbstractFileObject {
}
if (parentPathLength1 > parentPathLength2) {
if (parentPath1.charAt(parentPathLength2) == '/') {
return DirectoryObject.createInstance(parentPath2);
}
return DirectoryObject.createInstance(parentPath1.substring(0, lastSlashIndex));
if (parentPath1.charAt(parentPathLength2) == '/') {
return DirectoryObject.createInstance(parentPath2);
}
}
else {
if (parentPath2.charAt(parentPathLength1) == '/') {
return DirectoryObject.createInstance(parentPath1);
return DirectoryObject.createInstance(parentPath1);
}
return DirectoryObject.createInstance(parentPath1.substring(0, lastSlashIndex));
}
return DirectoryObject.createInstance(parentPath1.substring(0, lastSlashIndex));
}
private static DirectoryObject getDirectory(AbstractFileObject abstractFileObject) {
@@ -103,14 +103,8 @@ public class GitMergeUtil {
@Override
public void elementMarkChanged(final String element, final boolean isMarked) {
final List<String> elements = branchChooser.getMarkedElements();
if (elements.size() == 0) {
strategy.setEnabled(false);
updateStrategies(elements);
}
else {
strategy.setEnabled(true);
updateStrategies(elements);
}
strategy.setEnabled(!elements.isEmpty());
updateStrategies(elements);
}
};
listener.elementMarkChanged(null, true);
@@ -62,13 +62,10 @@ public class GitLocalCommitCompareInfo extends LocalCommitCompareInfo {
Repository repository = repositoryManager.getRepositoryForFile(ObjectUtils.chooseNotNull(currentPath, branchPath));
if (currentPath != null && branchPath != null) {
if (Comparing.equal(currentPath, branchPath)) {
toCheckout.putValue(repository, branchPath);
}
else {
if (!Comparing.equal(currentPath, branchPath)) {
toDelete.putValue(repository, currentPath);
toCheckout.putValue(repository, branchPath);
}
toCheckout.putValue(repository, branchPath);
}
else if (currentPath != null) {
toDelete.putValue(repository, currentPath);
@@ -164,13 +164,12 @@ public class UnusedDefInspection extends GroovyLocalInspectionBase {
PsiFile file = var.getContainingFile();
if (file == null) {
LOG.error("no file??? var of type" + var.getClass().getCanonicalName());
return false;
}
else {
TextRange range = var.getTextRange();
LOG.error("var: " + var.getName() + ", offset:" + (range != null ? range.getStartOffset() : -1));
return false;
}
return false;
}
return ReferencesSearch.search(var, var.getUseScope()).forEach(
@@ -565,13 +565,12 @@ public class GroovySpacingProcessor extends GroovyElementVisitor {
if (TokenSets.METHOD_DEFS.contains(myType1) || isSemiAfter(TokenSets.METHOD_DEFS) || TokenSets.METHOD_DEFS.contains((myType2))) {
if (myType1 == GroovyDocElementTypes.GROOVY_DOC_COMMENT) {
createLF(true);
return;
}
else {
final int minBlankLines = isInterface ? mySettings.BLANK_LINES_AROUND_METHOD_IN_INTERFACE : mySettings.BLANK_LINES_AROUND_METHOD;
myResult = Spacing.createSpacing(0, 0, minBlankLines + 1, mySettings.KEEP_LINE_BREAKS, keepBlankLines());
return;
}
return;
}
if (TokenSets.TYPE_DEFINITIONS.contains(myType1) || isSemiAfter(TokenSets.TYPE_DEFINITIONS) || TokenSets.TYPE_DEFINITIONS.contains((myType2)) ) {
@@ -320,7 +320,6 @@ public class AssertProcessor {
key.equals(InterpreterUtil.makeUniqueKey(fdparam.getName(), fdparam.getDescriptor().descriptorString));
}
}
return false;
}
else {
if (exprent.type == Exprent.EXPRENT_FIELD) {
@@ -328,7 +327,7 @@ public class AssertProcessor {
return classname.equals(fdparam.getClassname()) &&
key.equals(InterpreterUtil.makeUniqueKey(fdparam.getName(), fdparam.getDescriptor().descriptorString));
}
return false;
}
return false;
}
}
@@ -122,7 +122,6 @@ public class SwitchStatement extends Statement {
for (int j = 0; j < edges.size(); j++) {
if (edges.get(j) == default_edge) {
buf.appendIndent(indent).append("default:").appendLineSeparator();
tracer.incrementCurrentSourceLine();
}
else {
buf.appendIndent(indent).append("case ");
@@ -139,8 +138,8 @@ public class SwitchStatement extends Statement {
}
buf.append(":").appendLineSeparator();
tracer.incrementCurrentSourceLine();
}
tracer.incrementCurrentSourceLine();
}
buf.append(ExprProcessor.jmpWrapper(stat, indent + 1, false, tracer));
@@ -447,14 +447,11 @@ public class MavenProjectsManagerWatcher {
newCrc = file.getModificationStamp();
}
if (newCrc == -1 // file is invalid
|| newCrc.equals(crc)) {
return true;
}
else {
if (newCrc != -1 // file is valid
&& !newCrc.equals(crc)) {
map.put(myProject, newCrc);
return true;
}
return true;
}
@Nullable
@@ -552,12 +552,11 @@ public class PyUnresolvedReferencesInspection extends PyInspection {
else {
description = PyBundle.message("INSP.unresolved.ref.$0.for.class.$1", refText, type.getName());
}
markedQualified = true;
}
else {
description = PyBundle.message("INSP.cannot.find.$0.in.$1", refText, type.getName());
markedQualified = true;
}
markedQualified = true;
}
}
if (!markedQualified) {
@@ -125,12 +125,11 @@ public class PyNumericLiteralExpressionImpl extends PyElementImpl implements PyN
else if (text.startsWith("0")) {
if (StringUtil.isChar(text, 1, 'o') || StringUtil.isChar(text, 1, 'O')) {
beginIndex = 2;
radix = 8;
}
else {
beginIndex = 1;
radix = 8;
}
radix = 8;
}
else {
beginIndex = 0;
@@ -121,13 +121,12 @@ public abstract class DomAnchorImpl<T extends DomElement> implements DomAnchor<T
for (XmlAttribute attribute : parentTag.getAttributes()) {
diag.append(", attr: ").append(attribute.getName());
}
diag.append("\n");
} else {
for (XmlTag tag : parentTag.getSubTags()) {
diag.append("\n subtag: ").append(tag.getName());
}
diag.append("\n");
}
diag.append("\n");
}
diag.append("Child name: ").append(t.getXmlElementName()).append(";").append(t.getXmlElementNamespaceKey());
LOG.error(diag);
@@ -128,8 +128,6 @@ public class XmlSmartEnterProcessor extends SmartEnterProcessor {
}
commitChanges(project, editor, psiFile, caretTo, null);
return true;
}
else {
final XmlTag unclosedTag = findClosestUnclosedTag(tagAtCaret);
@@ -147,8 +145,8 @@ public class XmlSmartEnterProcessor extends SmartEnterProcessor {
doc.insertString(offset, closingTagString);
commitChanges(project, editor, psiFile, offset, parentTag != null ? parentTag : unclosedTag);
return true;
}
return true;
}
catch (IncorrectOperationException e) {
LOG.error(e);