From c8f11b95f809dd3b5d3cabe27ff3e121ea933d73 Mon Sep 17 00:00:00 2001 From: Kirill Likhodedov Date: Sun, 15 Jun 2014 20:48:36 +0300 Subject: [PATCH 01/12] [vcs] Nullify fields in tearDown of git & hg base test classes --- .../git4idea/tests/git4idea/test/GitPlatformTest.java | 1 + plugins/hg4idea/testSrc/hg4idea/test/HgPlatformTest.java | 9 +++++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/plugins/git4idea/tests/git4idea/test/GitPlatformTest.java b/plugins/git4idea/tests/git4idea/test/GitPlatformTest.java index a073ceda0c96..08eab43005c9 100644 --- a/plugins/git4idea/tests/git4idea/test/GitPlatformTest.java +++ b/plugins/git4idea/tests/git4idea/test/GitPlatformTest.java @@ -125,6 +125,7 @@ public abstract class GitPlatformTest extends UsefulTestCase { myDialogManager.cleanup(); myVcsNotifier.cleanup(); myProjectFixture.tearDown(); + clearFields(this); } finally { super.tearDown(); diff --git a/plugins/hg4idea/testSrc/hg4idea/test/HgPlatformTest.java b/plugins/hg4idea/testSrc/hg4idea/test/HgPlatformTest.java index ac64812f6239..5cb02e06ca62 100644 --- a/plugins/hg4idea/testSrc/hg4idea/test/HgPlatformTest.java +++ b/plugins/hg4idea/testSrc/hg4idea/test/HgPlatformTest.java @@ -90,8 +90,13 @@ public abstract class HgPlatformTest extends UsefulTestCase { @Override protected void tearDown() throws Exception { - myProjectFixture.tearDown(); - super.tearDown(); + try { + myProjectFixture.tearDown(); + clearFields(this); + } + finally { + super.tearDown(); + } } private static void setUpHgrc(@NotNull VirtualFile repositoryRoot) throws IOException { From c52b9d51b4deda7765a0c9bcb6281c524fd547b8 Mon Sep 17 00:00:00 2001 From: Konstantin Bulenkov Date: Sun, 15 Jun 2014 19:12:51 +0100 Subject: [PATCH 02/12] fix yellow code (NPE) and change literal to constant from CommonClassNames --- .../wordSelection/LiteralSelectioner.java | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/java/java-impl/src/com/intellij/codeInsight/editorActions/wordSelection/LiteralSelectioner.java b/java/java-impl/src/com/intellij/codeInsight/editorActions/wordSelection/LiteralSelectioner.java index 1c51da143810..6d903cafb418 100644 --- a/java/java-impl/src/com/intellij/codeInsight/editorActions/wordSelection/LiteralSelectioner.java +++ b/java/java-impl/src/com/intellij/codeInsight/editorActions/wordSelection/LiteralSelectioner.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2014 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -22,9 +22,12 @@ import com.intellij.openapi.util.TextRange; import com.intellij.psi.JavaTokenType; import com.intellij.psi.PsiElement; import com.intellij.psi.PsiLiteralExpression; +import com.intellij.psi.PsiType; import java.util.List; +import static com.intellij.psi.CommonClassNames.JAVA_LANG_STRING; + public class LiteralSelectioner extends BasicSelectioner { @Override public boolean canSelect(PsiElement e) { @@ -34,8 +37,10 @@ public class LiteralSelectioner extends BasicSelectioner { } private static boolean isStringLiteral(PsiElement element) { - return element instanceof PsiLiteralExpression && - ((PsiLiteralExpression)element).getType().equalsToText("java.lang.String") && element.getText().startsWith("\"") && element.getText().endsWith("\""); + final PsiType type = element instanceof PsiLiteralExpression ? ((PsiLiteralExpression)element).getType() : null; + return type != null && type.equalsToText(JAVA_LANG_STRING) + && element.getText().startsWith("\"") + && element.getText().endsWith("\""); } @Override From 533dc6d57bd469f689e025993e1a8e0b90e598fa Mon Sep 17 00:00:00 2001 From: Konstantin Bulenkov Date: Sun, 15 Jun 2014 19:14:52 +0100 Subject: [PATCH 03/12] use CommonClassNames constants for standard FQNs --- .../quickfix/ChangeStringLiteralToCharInMethodCallFix.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/java/java-analysis-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/ChangeStringLiteralToCharInMethodCallFix.java b/java/java-analysis-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/ChangeStringLiteralToCharInMethodCallFix.java index 19fcc3b9fcc3..367f28719d1b 100644 --- a/java/java-analysis-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/ChangeStringLiteralToCharInMethodCallFix.java +++ b/java/java-analysis-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/ChangeStringLiteralToCharInMethodCallFix.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2012 JetBrains s.r.o. + * Copyright 2000-2014 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -33,6 +33,8 @@ import org.jetbrains.annotations.Nullable; import java.util.HashSet; import java.util.Set; +import static com.intellij.psi.CommonClassNames.JAVA_LANG_STRING; + public class ChangeStringLiteralToCharInMethodCallFix implements IntentionAction { private final PsiLiteralExpression myLiteral; private final PsiCall myCall; @@ -171,6 +173,6 @@ public class ChangeStringLiteralToCharInMethodCallFix implements IntentionAction } private static boolean isString(final PsiType type) { - return type != null && "java.lang.String".equals(type.getCanonicalText()); + return type != null && type.equalsToText(JAVA_LANG_STRING); } } From 668e1f52e2ac27d0625afc255a14abb7a7c0afce Mon Sep 17 00:00:00 2001 From: Anna Kozlova Date: Mon, 16 Jun 2014 11:25:23 +0400 Subject: [PATCH 04/12] redundant assignment in arg list fixed (IDEA-126190) --- .../intellij/codeInspection/RemoveAssignmentFix.java | 2 +- .../unusedAssignment/afterCallAsArgument.java | 11 +++++++++++ .../unusedAssignment/beforeCallAsArgument.java | 11 +++++++++++ 3 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/unusedAssignment/afterCallAsArgument.java create mode 100644 java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/unusedAssignment/beforeCallAsArgument.java diff --git a/java/java-impl/src/com/intellij/codeInspection/RemoveAssignmentFix.java b/java/java-impl/src/com/intellij/codeInspection/RemoveAssignmentFix.java index b80e3a07121d..9db065ad321f 100644 --- a/java/java-impl/src/com/intellij/codeInspection/RemoveAssignmentFix.java +++ b/java/java-impl/src/com/intellij/codeInspection/RemoveAssignmentFix.java @@ -40,7 +40,7 @@ public class RemoveAssignmentFix extends RemoveInitializerFix { if (!(parent instanceof PsiAssignmentExpression)) return; final PsiExpression rExpression = ((PsiAssignmentExpression)parent).getRExpression(); final PsiElement gParent = parent.getParent(); - if (gParent instanceof PsiExpression && rExpression != null) { + if ((gParent instanceof PsiExpression || gParent instanceof PsiExpressionList) && rExpression != null) { if (!FileModificationService.getInstance().prepareFileForWrite(gParent.getContainingFile())) return; if (gParent instanceof PsiParenthesizedExpression) { gParent.replace(rExpression); diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/unusedAssignment/afterCallAsArgument.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/unusedAssignment/afterCallAsArgument.java new file mode 100644 index 000000000000..6ef1870458fb --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/unusedAssignment/afterCallAsArgument.java @@ -0,0 +1,11 @@ +// "Remove redundant assignment" "true" +class Test { + void foo() { + String var; + this.bar("someString"); + } + + void bar(String arg) { + + } +} diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/unusedAssignment/beforeCallAsArgument.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/unusedAssignment/beforeCallAsArgument.java new file mode 100644 index 000000000000..116cc94e30f4 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/unusedAssignment/beforeCallAsArgument.java @@ -0,0 +1,11 @@ +// "Remove redundant assignment" "true" +class Test { + void foo() { + String var; + this.bar(var = "someString"); + } + + void bar(String arg) { + + } +} From 8cbfea6b51cf68ed1b6da709a0ad022a7a095c2a Mon Sep 17 00:00:00 2001 From: nik Date: Mon, 16 Jun 2014 11:26:37 +0400 Subject: [PATCH 05/12] fixed 'change library level' action: keep position in classpath, 'exported' and 'scope' values (IDEA-100632) --- .../roots/ui/configuration/ModuleEditor.java | 2 +- .../ChangeLibraryLevelActionBase.java | 2 +- .../ChangeLibraryLevelInClasspathAction.java | 10 ++-- .../openapi/roots/impl/OrderEntryUtil.java | 49 ++++++++++++++----- 4 files changed, 46 insertions(+), 17 deletions(-) diff --git a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/ModuleEditor.java b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/ModuleEditor.java index 47e901512ed5..14c5fba1ded9 100644 --- a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/ModuleEditor.java +++ b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/ModuleEditor.java @@ -332,7 +332,7 @@ public abstract class ModuleEditor implements Place.Navigator, Disposable { private final ModifiableRootModel myDelegateModel; @NonNls private final Set myCheckedNames = new HashSet( Arrays.asList("addOrderEntry", "addLibraryEntry", "addInvalidLibrary", "addModuleOrderEntry", "addInvalidModuleEntry", - "removeOrderEntry", "setSdk", "inheritSdk", "inheritCompilerOutputPath", "setExcludeOutput", "replaceEntryOfType")); + "removeOrderEntry", "setSdk", "inheritSdk", "inheritCompilerOutputPath", "setExcludeOutput", "replaceEntryOfType", "rearrangeOrderEntries")); ModifiableRootModelInvocationHandler(ModifiableRootModel model) { myDelegateModel = model; diff --git a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/classpath/ChangeLibraryLevelActionBase.java b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/classpath/ChangeLibraryLevelActionBase.java index 046157ef3bc7..0a162f49bb90 100644 --- a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/classpath/ChangeLibraryLevelActionBase.java +++ b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/classpath/ChangeLibraryLevelActionBase.java @@ -103,7 +103,7 @@ public abstract class ChangeLibraryLevelActionBase extends AnAction { } } - final Library copied = ((LibraryTableBase.ModifiableModelEx)provider.getModifiableModel()).createLibrary(dialog.getLibraryName(), library.getKind()); + final Library copied = ((LibraryTableBase.ModifiableModelEx)provider.getModifiableModel()).createLibrary(StringUtil.nullize(dialog.getLibraryName()), library.getKind()); final LibraryEx.ModifiableModelEx model = (LibraryEx.ModifiableModelEx)copied.getModifiableModel(); LibraryEditingUtil.copyLibrary(library, copiedFiles, model); diff --git a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/classpath/ChangeLibraryLevelInClasspathAction.java b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/classpath/ChangeLibraryLevelInClasspathAction.java index 2b42fd3158e4..9a670be8f458 100644 --- a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/classpath/ChangeLibraryLevelInClasspathAction.java +++ b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/classpath/ChangeLibraryLevelInClasspathAction.java @@ -18,6 +18,7 @@ package com.intellij.openapi.roots.ui.configuration.classpath; import com.intellij.openapi.actionSystem.AnActionEvent; import com.intellij.openapi.roots.LibraryOrderEntry; import com.intellij.openapi.roots.OrderEntry; +import com.intellij.openapi.roots.impl.OrderEntryUtil; import com.intellij.openapi.roots.impl.libraries.LibraryEx; import com.intellij.openapi.roots.impl.libraries.LibraryTableImplUtil; import com.intellij.openapi.roots.libraries.Library; @@ -43,15 +44,18 @@ class ChangeLibraryLevelInClasspathAction extends ChangeLibraryLevelActionBase { public void actionPerformed(AnActionEvent event) { final OrderEntry entry = myPanel.getSelectedEntry(); if (!(entry instanceof LibraryOrderEntry)) return; - final LibraryEx library = (LibraryEx)((LibraryOrderEntry)entry).getLibrary(); + LibraryOrderEntry libraryEntry = (LibraryOrderEntry)entry; + final LibraryEx library = (LibraryEx)libraryEntry.getLibrary(); if (library == null) return; final Library copied = doCopy(library); if (copied == null) return; - myPanel.getRootModel().removeOrderEntry(entry); if (!isConvertingToModuleLibrary()) { - myPanel.getRootModel().addLibraryEntry(copied); + OrderEntryUtil.replaceLibrary(myPanel.getRootModel(), library, copied); + } + else { + OrderEntryUtil.replaceLibraryEntryByAdded(myPanel.getRootModel(), libraryEntry); } } diff --git a/platform/lang-impl/src/com/intellij/openapi/roots/impl/OrderEntryUtil.java b/platform/lang-impl/src/com/intellij/openapi/roots/impl/OrderEntryUtil.java index 1b58b05357a6..100eb1bcd284 100644 --- a/platform/lang-impl/src/com/intellij/openapi/roots/impl/OrderEntryUtil.java +++ b/platform/lang-impl/src/com/intellij/openapi/roots/impl/OrderEntryUtil.java @@ -26,6 +26,7 @@ import com.intellij.openapi.roots.libraries.Library; import com.intellij.openapi.roots.libraries.LibraryTable; import com.intellij.openapi.util.Comparing; import com.intellij.openapi.vfs.VirtualFile; +import com.intellij.util.ArrayUtil; import com.intellij.util.Processor; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -152,21 +153,45 @@ public class OrderEntryUtil { rootModel.commit(); } - public static void replaceLibrary(@NotNull ModifiableRootModel model, @NotNull Library oldLibrary, @NotNull Library newLibrary) { - OrderEntry[] entries = model.getOrderEntries(); + private static int findLibraryOrderEntry(@NotNull OrderEntry[] entries, @NotNull Library library) { for (int i = 0; i < entries.length; i++) { - OrderEntry orderEntry = entries[i]; - if (orderEntry instanceof LibraryOrderEntry && oldLibrary.equals(((LibraryOrderEntry)orderEntry).getLibrary())) { - model.removeOrderEntry(orderEntry); - final LibraryOrderEntry newEntry = model.addLibraryEntry(newLibrary); - final OrderEntry[] newEntries = new OrderEntry[entries.length]; - System.arraycopy(entries, 0, newEntries, 0, i); - newEntries[i] = newEntry; - System.arraycopy(entries, i, newEntries, i+1, entries.length - i - 1); - model.rearrangeOrderEntries(newEntries); - return; + OrderEntry entry = entries[i]; + if (entry instanceof LibraryOrderEntry && library.equals(((LibraryOrderEntry)entry).getLibrary())) { + return i; } } + return -1; + } + + public static void replaceLibrary(@NotNull ModifiableRootModel model, @NotNull Library oldLibrary, @NotNull Library newLibrary) { + int i = findLibraryOrderEntry(model.getOrderEntries(), oldLibrary); + if (i == -1) return; + + model.addLibraryEntry(newLibrary); + replaceLibraryByAdded(model, i); + } + + public static void replaceLibraryEntryByAdded(@NotNull ModifiableRootModel model, @NotNull LibraryOrderEntry entry) { + int i = ArrayUtil.indexOf(model.getOrderEntries(), entry); + if (i == -1) return; + + replaceLibraryByAdded(model, i); + } + + private static void replaceLibraryByAdded(ModifiableRootModel model, int toReplace) { + OrderEntry[] entries = model.getOrderEntries(); + LibraryOrderEntry newEntry = (LibraryOrderEntry)entries[entries.length - 1]; + LibraryOrderEntry libraryEntry = (LibraryOrderEntry)entries[toReplace]; + boolean exported = libraryEntry.isExported(); + DependencyScope scope = libraryEntry.getScope(); + model.removeOrderEntry(libraryEntry); + newEntry.setExported(exported); + newEntry.setScope(scope); + final OrderEntry[] newEntries = new OrderEntry[entries.length-1]; + System.arraycopy(entries, 0, newEntries, 0, toReplace); + newEntries[toReplace] = newEntry; + System.arraycopy(entries, toReplace + 1, newEntries, toReplace + 1, entries.length - toReplace - 2); + model.rearrangeOrderEntries(newEntries); } public static void processOrderEntries(@NotNull Module module, From c61a7a7a16ac9fa69f874d89501d1f1ff0110307 Mon Sep 17 00:00:00 2001 From: Aleksey Pivovarov Date: Mon, 16 Jun 2014 11:49:25 +0400 Subject: [PATCH 06/12] diff: fix NPE this should not happen normally, but can be caused by other exceptions --- .../src/com/intellij/openapi/vcs/ex/LineStatusTracker.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/ex/LineStatusTracker.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/ex/LineStatusTracker.java index 548cc514b300..59a63a591a07 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/ex/LineStatusTracker.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/ex/LineStatusTracker.java @@ -452,7 +452,9 @@ public class LineStatusTracker { private void replaceRanges(List rangesInChange, List newRangesInChange) { for (Range range : rangesInChange) { - range.getHighlighter().dispose(); + if (range.getHighlighter() != null) { + range.getHighlighter().dispose(); + } range.setHighlighter(null); } for (Range range : newRangesInChange) { From 803f4a6918937d2015928fd3fcf11e71af80e16b Mon Sep 17 00:00:00 2001 From: Aleksey Pivovarov Date: Mon, 16 Jun 2014 11:49:28 +0400 Subject: [PATCH 07/12] IDEA-95430 IDEA-103824 diff: fix changed range calculation bug case: modification right before previously deleted block vcs version: A B C Before: A B After: X B --- .../openapi/vcs/ex/LineStatusTracker.java | 139 +++++++----------- .../com/intellij/openapi/vcs/ex/Range.java | 18 --- 2 files changed, 54 insertions(+), 103 deletions(-) diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/ex/LineStatusTracker.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/ex/LineStatusTracker.java index 59a63a591a07..a0fcbd1770e9 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/ex/LineStatusTracker.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/ex/LineStatusTracker.java @@ -38,6 +38,7 @@ import com.intellij.openapi.vcs.changes.VcsDirtyScopeManager; import com.intellij.openapi.vcs.history.VcsRevisionNumber; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.ui.EditorNotificationPanel; +import com.intellij.util.containers.ContainerUtil; import com.intellij.util.diff.FilesTooBigForDiffException; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -156,7 +157,7 @@ public class LineStatusTracker { } private void removeAnathema() { - if (! myAnathemaThrown) return; + if (!myAnathemaThrown) return; myAnathemaThrown = false; final FileEditor[] editors = myFileEditorManager.getEditors(myVirtualFile); for (FileEditor editor : editors) { @@ -286,8 +287,6 @@ public class LineStatusTracker { private class MyDocumentListener extends DocumentAdapter { private int myFirstChangedLine; - private int myUpToDateFirstLine; - private int myUpToDateLastLine; private int myLastChangedLine; private int myLinesBeforeChange; private final VcsDirtyScopeManager myVcsDirtyScopeManager = VcsDirtyScopeManager.getInstance(myProject); @@ -302,50 +301,14 @@ public class LineStatusTracker { try { myFirstChangedLine = myDocument.getLineNumber(e.getOffset()); myLastChangedLine = myDocument.getLineNumber(e.getOffset() + e.getOldLength()); + myLinesBeforeChange = myLastChangedLine - myFirstChangedLine; if (StringUtil.endsWithChar(e.getOldFragment(), '\n')) myLastChangedLine++; - - myLinesBeforeChange = myDocument.getLineNumber(e.getOffset() + e.getOldLength()) - myDocument.getLineNumber(e.getOffset()); - - Range firstChangedRange = getLastRangeBeforeLine(myFirstChangedLine); - - if (firstChangedRange == null) { - myUpToDateFirstLine = myFirstChangedLine; - } - else if (firstChangedRange.containsLine(myFirstChangedLine)) { - myFirstChangedLine = firstChangedRange.getOffset1(); - myUpToDateFirstLine = firstChangedRange.getUOffset1(); - } - else { - myUpToDateFirstLine = firstChangedRange.getUOffset2() + myFirstChangedLine - firstChangedRange.getOffset2(); - } - - Range myLastChangedRange = getLastRangeBeforeLine(myLastChangedLine); - - if (myLastChangedRange == null) { - myUpToDateLastLine = myLastChangedLine; - } - else if (myLastChangedRange.containsLine(myLastChangedLine)) { - myUpToDateLastLine = myLastChangedRange.getUOffset2(); - myLastChangedLine = myLastChangedRange.getOffset2(); - } - else { - myUpToDateLastLine = myLastChangedRange.getUOffset2() + myLastChangedLine - myLastChangedRange.getOffset2(); - } - } catch (ProcessCanceledException ignore) { + } + catch (ProcessCanceledException ignore) { } } } - @Nullable - private Range getLastRangeBeforeLine(int line) { - Range result = null; - for (Range range : myRanges) { - if (range.isAfter(line)) return result; - result = range; - } - return result; - } - @Override public void documentChanged(final DocumentEvent e) { myApplication.assertWriteAccessAllowed(); @@ -354,27 +317,40 @@ public class LineStatusTracker { if (myReleased) return; if (myBulkUpdate || myAnathemaThrown || BaseLoadState.LOADED != myBaseLoaded) return; try { + int upToDateFirstLine; + int upToDateLastLine; - int line = myDocument.getLineNumber(e.getOffset() + e.getNewLength()); - int linesAfterChange = line - myDocument.getLineNumber(e.getOffset()); + int linesAfterChange = myDocument.getLineNumber(e.getOffset() + e.getNewLength()) - myDocument.getLineNumber(e.getOffset()); int linesShift = linesAfterChange - myLinesBeforeChange; - List rangesAfterChange = getRangesAfter(myRanges, myLastChangedLine); - List rangesBeforeChange = getRangesBefore(myRanges, myFirstChangedLine); + List rangesBeforeChange = new ArrayList(); + List rangesAfterChange = new ArrayList(); + List changedRanges = new ArrayList(); + sortRanges(myRanges, myFirstChangedLine, myLastChangedLine, rangesBeforeChange, changedRanges, rangesAfterChange); - List changedRanges = getChangedRanges(myFirstChangedLine, myLastChangedLine); + Range firstChangedRange = ContainerUtil.getFirstItem(changedRanges); + Range lastChangedRange = ContainerUtil.getLastItem(changedRanges); + Range lastRangeBefore = ContainerUtil.getLastItem(rangesBeforeChange); - int newSize = rangesBeforeChange.size() + changedRanges.size() + rangesAfterChange.size(); - if (myRanges.size() != newSize) { - LOG.info("Ranges: " + myRanges + "; first changed line: " + myFirstChangedLine + "; last changed line: " + myLastChangedLine); - LOG.assertTrue(false); + if (firstChangedRange != null && firstChangedRange.getOffset1() < myFirstChangedLine) { + myFirstChangedLine = firstChangedRange.getOffset1(); + } + if (lastChangedRange != null && lastChangedRange.getOffset2() > myLastChangedLine) { + myLastChangedLine = lastChangedRange.getOffset2(); } + upToDateFirstLine = getUpToDateLine(lastRangeBefore, myFirstChangedLine); + + if (lastChangedRange == null) { + upToDateLastLine = getUpToDateLine(lastRangeBefore, myLastChangedLine); + } + else { + upToDateLastLine = getUpToDateLine(lastChangedRange, myLastChangedLine); + } myLastChangedLine += linesShift; - - List newChangedRanges = getNewChangedRanges(); + List newChangedRanges = getNewChangedRanges(upToDateFirstLine, upToDateLastLine); shiftRanges(rangesAfterChange, linesShift); @@ -418,11 +394,14 @@ public class LineStatusTracker { } } - private List getNewChangedRanges() throws FilesTooBigForDiffException { + private int getUpToDateLine(@Nullable Range range, int line) { + return range == null ? line : line + range.getUOffset2() - range.getOffset2(); + } + + private List getNewChangedRanges(int upToDateFirstLine, int upToDateLastLine) throws FilesTooBigForDiffException { List lines = new DocumentWrapper(myDocument).getLines(myFirstChangedLine, myLastChangedLine); - List uLines = new DocumentWrapper(myUpToDateDocument) - .getLines(myUpToDateFirstLine, myUpToDateLastLine); - return new RangesBuilder(lines, uLines, myFirstChangedLine, myUpToDateFirstLine).getRanges(); + List uLines = new DocumentWrapper(myUpToDateDocument).getLines(upToDateFirstLine, upToDateLastLine); + return new RangesBuilder(lines, uLines, myFirstChangedLine, upToDateFirstLine).getRanges(); } private List mergeRanges(List ranges) { @@ -467,20 +446,28 @@ public class LineStatusTracker { aRangesAfterChange.shift(shift); } } - } - private List getChangedRanges(int from, int to) { - return getChangedRanges(myRanges, from, to); - } - - public static List getChangedRanges(List ranges, int from, int to) { - ArrayList result = new ArrayList(); + public static void sortRanges(@NotNull List ranges, + int firstChangedLine, + int lastChangedLine, + @NotNull List rangesBeforeChange, + @NotNull List changedRanges, + @NotNull List rangesAfterChange) { for (Range range : ranges) { - if (range.getOffset1() <= to && range.getOffset2() >= from) result.add(range); -// if (range.getOffset1() > to) break; + int offset1 = range.getType() == Range.DELETED ? range.getOffset1() - 1 : range.getOffset1(); + int offset2 = range.getOffset2(); + + if (offset2 < firstChangedLine) { + rangesBeforeChange.add(range); + } + else if (offset1 > lastChangedLine) { + rangesAfterChange.add(range); + } + else { + changedRanges.add(range); + } } - return result; } @Nullable @@ -538,24 +525,6 @@ public class LineStatusTracker { } } - public static List getRangesBefore(List ranges, int line) { - ArrayList result = new ArrayList(); - - for (Range range : ranges) { - if (range.getOffset2() < line) result.add(range); - //if (range.getOffset2() > line) break; - } - return result; - } - - public static List getRangesAfter(List ranges, int line) { - ArrayList result = new ArrayList(); - for (Range range : ranges) { - if (range.getOffset1() > line) result.add(range); - } - return result; - } - @Nullable public Range getRangeForLine(final int line) { synchronized (myLock) { diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/ex/Range.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/ex/Range.java index 6900d46c9f10..03338a4510f9 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/ex/Range.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/ex/Range.java @@ -154,22 +154,4 @@ public class Range { public RangeHighlighter getHighlighter() { return myRangeHighlighter; } - - public boolean contains(int offset1, int offset2) { - return getOffset1() <= offset1 && getOffset2() >= offset2; - } - - public boolean containsLine(int line) { - if (myType == DELETED) return (myOffset1 - 1) <= line - && (myOffset2) >= line; - return myOffset1 <= line && myOffset2 >= line; - } - - public boolean isAfter(int line) { - if (myType == DELETED) - return (getOffset1() - 1) > line; - else - return getOffset1() > line; - } - } From 9c2daf694d246c11b20dbe2584eb85e192172658 Mon Sep 17 00:00:00 2001 From: Aleksey Pivovarov Date: Mon, 16 Jun 2014 11:49:31 +0400 Subject: [PATCH 08/12] diff: fix IDEA-97563 and related issues --- .../openapi/vcs/ex/LineStatusTracker.java | 55 ++++++++++++------- .../vcs/ex/ShowLineStatusRangeDiffAction.java | 4 +- 2 files changed, 38 insertions(+), 21 deletions(-) diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/ex/LineStatusTracker.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/ex/LineStatusTracker.java index a0fcbd1770e9..d8fd155c366b 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/ex/LineStatusTracker.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/ex/LineStatusTracker.java @@ -544,25 +544,34 @@ public class LineStatusTracker { myApplication.assertWriteAccessAllowed(); synchronized (myLock) { - TextRange currentTextRange = getCurrentTextRange(range); + TextRange currentTextRange = getCurrentTextRangeWithMagic(range); if (range.getType() == Range.INSERTED) { myDocument .replaceString(currentTextRange.getStartOffset(), Math.min(currentTextRange.getEndOffset() + 1, myDocument.getTextLength()), ""); } else if (range.getType() == Range.DELETED) { - String upToDateContent = getUpToDateContent(range); + String upToDateContent = getUpToDateContentWithMagic(range); myDocument.insertString(currentTextRange.getStartOffset(), upToDateContent); } else { - String upToDateContent = getUpToDateContent(range); + String upToDateContent = getUpToDateContentWithMagic(range); myDocument.replaceString(currentTextRange.getStartOffset(), Math.min(currentTextRange.getEndOffset() + 1, myDocument.getTextLength()), upToDateContent); } } } + public String getUpToDateContentWithMagic(Range range) { + synchronized (myLock) { + TextRange textRange = getUpToDateRangeWithMagic(range); + final int startOffset = textRange.getStartOffset(); + final int endOffset = Math.min(textRange.getEndOffset() + 1, myUpToDateDocument.getTextLength()); + return myUpToDateDocument.getCharsSequence().subSequence(startOffset, endOffset).toString(); + } + } + public String getUpToDateContent(Range range) { synchronized (myLock) { TextRange textRange = getUpToDateRange(range); @@ -576,25 +585,23 @@ public class LineStatusTracker { return myProject; } + TextRange getCurrentTextRangeWithMagic(Range range) { + return getRangeWithMagic(range.getType(), range.getOffset1(), range.getOffset2(), Range.DELETED, myDocument); + } + + TextRange getUpToDateRangeWithMagic(Range range) { + return getRangeWithMagic(range.getType(), range.getUOffset1(), range.getUOffset2(), Range.INSERTED, myUpToDateDocument); + } + TextRange getCurrentTextRange(Range range) { - return getRange(range.getType(), range.getOffset1(), range.getOffset2(), Range.DELETED, myDocument, false); + return getRange(range.getType(), range.getOffset1(), range.getOffset2(), Range.DELETED, myDocument); } TextRange getUpToDateRange(Range range) { - return getRange(range.getType(), range.getUOffset1(), range.getUOffset2(), Range.INSERTED, myUpToDateDocument, false); + return getRange(range.getType(), range.getUOffset1(), range.getUOffset2(), Range.INSERTED, myUpToDateDocument); } - TextRange getCurrentTextRangeWithEndSymbol(Range range) { - return getRange(range.getType(), range.getOffset1(), range.getOffset2(), Range.DELETED, myDocument, true); - } - - // a hack - TextRange getUpToDateRangeWithEndSymbol(Range range) { - return getRange(range.getType(), range.getUOffset1(), range.getUOffset2(), Range.INSERTED, myUpToDateDocument, true); - } - - private static TextRange getRange(byte rangeType, int offset1, int offset2, byte emptyRangeCondition, Document document, - final boolean keepEnd) { + private static TextRange getRangeWithMagic(byte rangeType, int offset1, int offset2, byte emptyRangeCondition, Document document) { if (rangeType == emptyRangeCondition) { int lineStartOffset; if (offset1 == 0) { @@ -612,14 +619,24 @@ public class LineStatusTracker { int endOffset = document.getLineEndOffset(offset2 - 1); if (startOffset > 0) { -- startOffset; - if (! keepEnd) { - -- endOffset; - } + -- endOffset; } return new TextRange(startOffset, endOffset); } } + private static TextRange getRange(byte rangeType, int offset1, int offset2, byte emptyRangeCondition, Document document) { + if (rangeType == emptyRangeCondition) { + int lineStartOffset = offset1 < document.getLineCount() ? document.getLineStartOffset(offset1) : document.getTextLength(); + return new TextRange(lineStartOffset, lineStartOffset); + } + else { + int startOffset = document.getLineStartOffset(offset1); + int endOffset = document.getLineEndOffset(offset2 - 1); + return new TextRange(startOffset, endOffset); + } + } + public static LineStatusTracker createOn(@Nullable VirtualFile virtualFile, final Document doc, final Project project) { final Document document = new DocumentImpl("",true); return new LineStatusTracker(doc, document, project, virtualFile); diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/ex/ShowLineStatusRangeDiffAction.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/ex/ShowLineStatusRangeDiffAction.java index 50622b27d0ce..c5dba0cab29c 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/ex/ShowLineStatusRangeDiffAction.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/ex/ShowLineStatusRangeDiffAction.java @@ -56,10 +56,10 @@ public class ShowLineStatusRangeDiffAction extends BaseLineStatusRangeAction { public DiffContent[] getContents() { return new DiffContent[]{ createDiffContent(myLineStatusTracker.getUpToDateDocument(), - myLineStatusTracker.getUpToDateRangeWithEndSymbol(myRange), + myLineStatusTracker.getUpToDateRange(myRange), null), createDiffContent(myLineStatusTracker.getDocument(), - myLineStatusTracker.getCurrentTextRangeWithEndSymbol(myRange), + myLineStatusTracker.getCurrentTextRange(myRange), myLineStatusTracker.getVirtualFile())}; } From ffcbeab9c5555fe1935902a6a2791073762593e2 Mon Sep 17 00:00:00 2001 From: Aleksey Pivovarov Date: Mon, 16 Jun 2014 11:49:34 +0400 Subject: [PATCH 09/12] diff: cleanup --- .../openapi/vcs/ex/LineStatusTracker.java | 63 +++++++++++-------- 1 file changed, 36 insertions(+), 27 deletions(-) diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/ex/LineStatusTracker.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/ex/LineStatusTracker.java index d8fd155c366b..39585fe8678b 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/ex/LineStatusTracker.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/ex/LineStatusTracker.java @@ -51,14 +51,14 @@ import java.util.ListIterator; /** * @author irengrig - * author: lesya + * author: lesya */ public class LineStatusTracker { private static final Logger LOG = Logger.getInstance("#com.intellij.openapi.vcs.ex.LineStatusTracker"); - private static final Key PANEL_KEY = new Key("LineStatusTracker.CanNotCalculateDiffPanel"); + private static final Key PANEL_KEY = + new Key("LineStatusTracker.CanNotCalculateDiffPanel"); private final Object myLock = new Object(); - // true -> have contents private BaseLoadState myBaseLoaded; private final Document myDocument; @@ -72,15 +72,17 @@ public class LineStatusTracker { private boolean myBulkUpdate; private final Application myApplication; - @Nullable - private RevisionPack myBaseRevisionNumber; + @Nullable private RevisionPack myBaseRevisionNumber; private String myPreviousBaseRevision; private boolean myAnathemaThrown; private FileEditorManager myFileEditorManager; private final VirtualFile myVirtualFile; private boolean myReleased = false; - private LineStatusTracker(final Document document, final Document upToDateDocument, final Project project, final VirtualFile virtualFile) { + private LineStatusTracker(@NotNull final Document document, + @NotNull final Document upToDateDocument, + final Project project, + @Nullable final VirtualFile virtualFile) { myVirtualFile = virtualFile; myApplication = ApplicationManager.getApplication(); myDocument = document; @@ -386,8 +388,10 @@ public class LineStatusTracker { }); } } - } catch (ProcessCanceledException ignore) { - } catch (FilesTooBigForDiffException e1) { + } + catch (ProcessCanceledException ignore) { + } + catch (FilesTooBigForDiffException e1) { installAnathema(); removeHighlightersFromMarkupModel(); } @@ -404,7 +408,8 @@ public class LineStatusTracker { return new RangesBuilder(lines, uLines, myFirstChangedLine, upToDateFirstLine).getRanges(); } - private List mergeRanges(List ranges) { + @NotNull + private List mergeRanges(@NotNull List ranges) { ArrayList result = new ArrayList(); Iterator iterator = ranges.iterator(); if (!iterator.hasNext()) return result; @@ -429,7 +434,7 @@ public class LineStatusTracker { return result; } - private void replaceRanges(List rangesInChange, List newRangesInChange) { + private void replaceRanges(@NotNull List rangesInChange, @NotNull List newRangesInChange) { for (Range range : rangesInChange) { if (range.getHighlighter() != null) { range.getHighlighter().dispose(); @@ -441,7 +446,7 @@ public class LineStatusTracker { } } - private void shiftRanges(List rangesAfterChange, int shift) { + private void shiftRanges(@NotNull List rangesAfterChange, int shift) { for (final Range aRangesAfterChange : rangesAfterChange) { aRangesAfterChange.shift(shift); } @@ -514,7 +519,7 @@ public class LineStatusTracker { return getPrevRange(currentRange); } - for (ListIterator iterator = myRanges.listIterator(myRanges.size()); iterator.hasPrevious();) { + for (ListIterator iterator = myRanges.listIterator(myRanges.size()); iterator.hasPrevious(); ) { final Range range = iterator.previous(); if (range.getOffset1() > line) { continue; @@ -546,19 +551,18 @@ public class LineStatusTracker { synchronized (myLock) { TextRange currentTextRange = getCurrentTextRangeWithMagic(range); + int offset1 = currentTextRange.getStartOffset(); + int offset2 = Math.min(currentTextRange.getEndOffset() + 1, myDocument.getTextLength()); if (range.getType() == Range.INSERTED) { - myDocument - .replaceString(currentTextRange.getStartOffset(), Math.min(currentTextRange.getEndOffset() + 1, myDocument.getTextLength()), ""); + myDocument.replaceString(offset1, offset2, ""); } else if (range.getType() == Range.DELETED) { String upToDateContent = getUpToDateContentWithMagic(range); - myDocument.insertString(currentTextRange.getStartOffset(), upToDateContent); + myDocument.insertString(offset1, upToDateContent); } else { - String upToDateContent = getUpToDateContentWithMagic(range); - myDocument.replaceString(currentTextRange.getStartOffset(), Math.min(currentTextRange.getEndOffset() + 1, myDocument.getTextLength()), - upToDateContent); + myDocument.replaceString(offset1, offset2, upToDateContent); } } } @@ -585,22 +589,27 @@ public class LineStatusTracker { return myProject; } - TextRange getCurrentTextRangeWithMagic(Range range) { + @NotNull + TextRange getCurrentTextRangeWithMagic(@NotNull Range range) { return getRangeWithMagic(range.getType(), range.getOffset1(), range.getOffset2(), Range.DELETED, myDocument); } - TextRange getUpToDateRangeWithMagic(Range range) { + @NotNull + TextRange getUpToDateRangeWithMagic(@NotNull Range range) { return getRangeWithMagic(range.getType(), range.getUOffset1(), range.getUOffset2(), Range.INSERTED, myUpToDateDocument); } - TextRange getCurrentTextRange(Range range) { + @NotNull + TextRange getCurrentTextRange(@NotNull Range range) { return getRange(range.getType(), range.getOffset1(), range.getOffset2(), Range.DELETED, myDocument); } - TextRange getUpToDateRange(Range range) { + @NotNull + TextRange getUpToDateRange(@NotNull Range range) { return getRange(range.getType(), range.getUOffset1(), range.getUOffset2(), Range.INSERTED, myUpToDateDocument); } + @NotNull private static TextRange getRangeWithMagic(byte rangeType, int offset1, int offset2, byte emptyRangeCondition, Document document) { if (rangeType == emptyRangeCondition) { int lineStartOffset; @@ -612,19 +621,19 @@ public class LineStatusTracker { } //if (lineStartOffset > 0) lineStartOffset--; return new TextRange(lineStartOffset, lineStartOffset); - } else { int startOffset = document.getLineStartOffset(offset1); int endOffset = document.getLineEndOffset(offset2 - 1); if (startOffset > 0) { - -- startOffset; - -- endOffset; + --startOffset; + --endOffset; } return new TextRange(startOffset, endOffset); } } + @NotNull private static TextRange getRange(byte rangeType, int offset1, int offset2, byte emptyRangeCondition, Document document) { if (rangeType == emptyRangeCondition) { int lineStartOffset = offset1 < document.getLineCount() ? document.getLineStartOffset(offset1) : document.getTextLength(); @@ -637,8 +646,8 @@ public class LineStatusTracker { } } - public static LineStatusTracker createOn(@Nullable VirtualFile virtualFile, final Document doc, final Project project) { - final Document document = new DocumentImpl("",true); + public static LineStatusTracker createOn(@Nullable VirtualFile virtualFile, @NotNull final Document doc, final Project project) { + final Document document = new DocumentImpl("", true); return new LineStatusTracker(doc, document, project, virtualFile); } From d809d097f46077012c36f8f4c53ae1bd3bbb9098 Mon Sep 17 00:00:00 2001 From: nik Date: Mon, 16 Jun 2014 13:18:10 +0400 Subject: [PATCH 10/12] added logging for BookmarkManagerTest#testBookmarkLineRemove --- .../openapi/components/impl/ComponentManagerImpl.java | 5 +++++ .../extensions/impl/ExtensionComponentAdapter.java | 5 +++++ .../openapi/components/impl/ServiceManagerImpl.java | 5 +++++ .../com/intellij/ide/bookmarks/BookmarkManagerTest.java | 8 ++++++++ 4 files changed, 23 insertions(+) diff --git a/platform/core-impl/src/com/intellij/openapi/components/impl/ComponentManagerImpl.java b/platform/core-impl/src/com/intellij/openapi/components/impl/ComponentManagerImpl.java index 7a0e77707300..6d280a5e11af 100644 --- a/platform/core-impl/src/com/intellij/openapi/components/impl/ComponentManagerImpl.java +++ b/platform/core-impl/src/com/intellij/openapi/components/impl/ComponentManagerImpl.java @@ -611,5 +611,10 @@ public abstract class ComponentManagerImpl extends UserDataHolderBase implements visitor.visitComponentAdapter(this); myDelegate.accept(visitor); } + + @Override + public String toString() { + return "ComponentConfigAdapter[" + getComponentKey() + "]: implementation=" + getComponentImplementation() + ", plugin=" + myConfig.getPluginId(); + } } } diff --git a/platform/extensions/src/com/intellij/openapi/extensions/impl/ExtensionComponentAdapter.java b/platform/extensions/src/com/intellij/openapi/extensions/impl/ExtensionComponentAdapter.java index d172a30ff285..f992e45bc9fc 100644 --- a/platform/extensions/src/com/intellij/openapi/extensions/impl/ExtensionComponentAdapter.java +++ b/platform/extensions/src/com/intellij/openapi/extensions/impl/ExtensionComponentAdapter.java @@ -191,4 +191,9 @@ public class ExtensionComponentAdapter implements LoadingOrder.Orderable, Assign public void setNotificationSent(boolean notificationSent) { myNotificationSent = notificationSent; } + + @Override + public String toString() { + return "ExtensionComponentAdapter[" + myImplementationClassName + "]: plugin=" + myPluginDescriptor; + } } diff --git a/platform/platform-impl/src/com/intellij/openapi/components/impl/ServiceManagerImpl.java b/platform/platform-impl/src/com/intellij/openapi/components/impl/ServiceManagerImpl.java index 641208bf4477..0b302d11f9c1 100644 --- a/platform/platform-impl/src/com/intellij/openapi/components/impl/ServiceManagerImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/components/impl/ServiceManagerImpl.java @@ -190,5 +190,10 @@ public class ServiceManagerImpl implements BaseComponent { public String getAssignableToClassName() { return myDescriptor.getInterface(); } + + @Override + public String toString() { + return "ServiceComponentAdapter[" + myDescriptor.getInterface() + "]: implementation=" + myDescriptor.getImplementation() + ", plugin=" + myPluginDescriptor; + } } } diff --git a/platform/platform-tests/testSrc/com/intellij/ide/bookmarks/BookmarkManagerTest.java b/platform/platform-tests/testSrc/com/intellij/ide/bookmarks/BookmarkManagerTest.java index 6c0a9f10886b..ed3c995edf48 100644 --- a/platform/platform-tests/testSrc/com/intellij/ide/bookmarks/BookmarkManagerTest.java +++ b/platform/platform-tests/testSrc/com/intellij/ide/bookmarks/BookmarkManagerTest.java @@ -21,10 +21,12 @@ import com.intellij.openapi.editor.LogicalPosition; import com.intellij.openapi.editor.impl.AbstractEditorTest; import com.intellij.openapi.fileEditor.FileDocumentManager; import com.intellij.openapi.fileEditor.OpenFileDescriptor; +import com.intellij.openapi.vcs.changes.ChangeListManagerImpl; import com.intellij.openapi.vfs.VfsUtil; import com.intellij.testFramework.LeakHunter; import com.intellij.testFramework.TestFileType; import org.jetbrains.annotations.NonNls; +import org.picocontainer.ComponentAdapter; import java.io.IOException; import java.util.ArrayList; @@ -69,6 +71,12 @@ public class BookmarkManagerTest extends AbstractEditorTest { } public void testBookmarkLineRemove() throws IOException { + List adapters = getProject().getPicoContainer().getComponentAdaptersOfType(ChangeListManagerImpl.class); + System.out.println(adapters.size() + " adapters:"); + for (ComponentAdapter adapter : adapters) { + System.out.println(adapter); + } + @NonNls String text = "public class Test {\n" + " public void test() {\n" + From bbc13de04a2382753b99db7df4e68307449688cb Mon Sep 17 00:00:00 2001 From: "Vladislav.Soroka" Date: Mon, 16 Jun 2014 13:27:27 +0400 Subject: [PATCH 11/12] IDEA-126138 Open gradle test report should not be visible for non-gradle projects --- .../OpenGradleTestResultActionProvider.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/plugins/gradle/src/org/jetbrains/plugins/gradle/execution/test/runner/OpenGradleTestResultActionProvider.java b/plugins/gradle/src/org/jetbrains/plugins/gradle/execution/test/runner/OpenGradleTestResultActionProvider.java index 6ae3a2cfb8b6..522c6057b9eb 100644 --- a/plugins/gradle/src/org/jetbrains/plugins/gradle/execution/test/runner/OpenGradleTestResultActionProvider.java +++ b/plugins/gradle/src/org/jetbrains/plugins/gradle/execution/test/runner/OpenGradleTestResultActionProvider.java @@ -15,17 +15,21 @@ */ package org.jetbrains.plugins.gradle.execution.test.runner; +import com.intellij.execution.configurations.RunConfiguration; import com.intellij.execution.testframework.TestConsoleProperties; import com.intellij.execution.testframework.TestFrameworkRunningModel; import com.intellij.execution.testframework.ToggleModelAction; import com.intellij.execution.testframework.ToggleModelActionProvider; import com.intellij.ide.BrowserUtil; import com.intellij.openapi.actionSystem.AnActionEvent; +import com.intellij.openapi.externalSystem.model.ProjectSystemId; +import com.intellij.openapi.externalSystem.service.execution.ExternalSystemRunConfiguration; import com.intellij.util.config.AbstractProperty; import com.intellij.util.config.BooleanProperty; import icons.GradleIcons; import org.jetbrains.annotations.Nullable; import org.jetbrains.plugins.gradle.util.GradleBundle; +import org.jetbrains.plugins.gradle.util.GradleConstants; import java.io.File; @@ -42,6 +46,9 @@ public class OpenGradleTestResultActionProvider implements ToggleModelActionProv } private static class MyToggleModelAction extends ToggleModelAction { + @Nullable + private ProjectSystemId mySystemId; + public MyToggleModelAction(TestConsoleProperties properties) { super(GradleBundle.message("gradle.test.runner.ui.tests.actions.open.gradle.report.text"), GradleBundle.message("gradle.test.runner.ui.tests.actions.open.gradle.report.desc"), @@ -50,6 +57,10 @@ public class OpenGradleTestResultActionProvider implements ToggleModelActionProv @Override public void setModel(TestFrameworkRunningModel model) { + final RunConfiguration runConfiguration = model.getProperties().getConfiguration(); + if(runConfiguration instanceof ExternalSystemRunConfiguration) { + mySystemId = ((ExternalSystemRunConfiguration)runConfiguration).getSettings().getExternalSystemId(); + } } @Override @@ -66,6 +77,11 @@ public class OpenGradleTestResultActionProvider implements ToggleModelActionProv return reportFilePath != null; } + @Override + protected boolean isVisible() { + return GradleConstants.SYSTEM_ID.equals(mySystemId); + } + @Nullable private String getReportFilePath() { final AbstractProperty.AbstractPropertyContainer properties = getProperties(); From 229e7edf8741569bb7ddc499ce6a5e680ecacfa1 Mon Sep 17 00:00:00 2001 From: Roman Shevchenko Date: Mon, 16 Jun 2014 13:37:07 +0400 Subject: [PATCH 12/12] EA-52085 (diagnostic performance impact eliminated) --- .../com/intellij/util/messages/impl/MessageBusImpl.java | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/platform/util/src/com/intellij/util/messages/impl/MessageBusImpl.java b/platform/util/src/com/intellij/util/messages/impl/MessageBusImpl.java index 4f0bca735b14..a8ce8f1cb73b 100644 --- a/platform/util/src/com/intellij/util/messages/impl/MessageBusImpl.java +++ b/platform/util/src/com/intellij/util/messages/impl/MessageBusImpl.java @@ -13,10 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - -/* - * @author max - */ package com.intellij.util.messages.impl; import com.intellij.openapi.Disposable; @@ -39,6 +35,9 @@ import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentLinkedQueue; import java.util.concurrent.ConcurrentMap; +/** + * @author max + */ public class MessageBusImpl implements MessageBus { private static final Logger LOG = Logger.getInstance("#com.intellij.util.messages.impl.MessageBusImpl"); private static final Comparator MESSAGE_BUS_COMPARATOR = new Comparator() { @@ -224,7 +223,7 @@ public class MessageBusImpl implements MessageBus { } private void checkNotDisposed() { - LOG.assertTrue(!myDisposed, "Already disposed: " + myOwner); + if (myDisposed) LOG.error("Already disposed: " + myOwner); } private void calcSubscribers(Topic topic, List result) {