diff --git a/java/structuralsearch-java/src/com/intellij/structuralsearch/impl/matcher/predicates/ReadPredicate.java b/java/structuralsearch-java/src/com/intellij/structuralsearch/impl/matcher/predicates/ReadPredicate.java index ce25b998ba9b..a5967d5ca661 100644 --- a/java/structuralsearch-java/src/com/intellij/structuralsearch/impl/matcher/predicates/ReadPredicate.java +++ b/java/structuralsearch-java/src/com/intellij/structuralsearch/impl/matcher/predicates/ReadPredicate.java @@ -10,19 +10,21 @@ import com.intellij.structuralsearch.impl.matcher.MatchUtils; */ public final class ReadPredicate extends MatchPredicate { public boolean match(PsiElement patternNode, PsiElement matchedNode, MatchContext context) { + PsiElement parent = matchedNode.getParent(); if (matchedNode instanceof PsiIdentifier) { - matchedNode = matchedNode.getParent(); + matchedNode = parent; + parent = matchedNode.getParent(); } - if (matchedNode instanceof PsiReferenceExpression && - ( !(matchedNode.getParent() instanceof PsiMethodCallExpression) && - ( !(matchedNode.getParent() instanceof PsiAssignmentExpression) || - ((PsiAssignmentExpression)matchedNode.getParent()).getLExpression() != matchedNode - ) - ) && - MatchUtils.getReferencedElement(matchedNode) instanceof PsiVariable - ) { - return true; + if (!(matchedNode instanceof PsiReferenceExpression) || parent instanceof PsiMethodCallExpression) { + return false; } - return false; + if (parent instanceof PsiAssignmentExpression) { + final PsiAssignmentExpression assignmentExpression = (PsiAssignmentExpression)parent; + if (assignmentExpression.getLExpression() == matchedNode && + assignmentExpression.getOperationTokenType() == JavaTokenType.EQ) { + return false; + } + } + return MatchUtils.getReferencedElement(matchedNode) instanceof PsiVariable; } } diff --git a/platform/diff-impl/src/com/intellij/diff/tools/simple/SimpleDiffChange.java b/platform/diff-impl/src/com/intellij/diff/tools/simple/SimpleDiffChange.java index 4b91729c3733..3a0337f09a91 100644 --- a/platform/diff-impl/src/com/intellij/diff/tools/simple/SimpleDiffChange.java +++ b/platform/diff-impl/src/com/intellij/diff/tools/simple/SimpleDiffChange.java @@ -18,6 +18,7 @@ package com.intellij.diff.tools.simple; import com.intellij.diff.fragments.DiffFragment; import com.intellij.diff.fragments.LineFragment; import com.intellij.diff.util.*; +import com.intellij.icons.AllIcons; import com.intellij.openapi.actionSystem.AnAction; import com.intellij.openapi.actionSystem.AnActionEvent; import com.intellij.openapi.editor.Document; @@ -318,7 +319,7 @@ public class SimpleDiffChange { @Nullable private GutterIconRenderer createApplyRenderer(@NotNull final Side side) { - return createIconRenderer(side, DiffIcons.getReplaceIcon(Side.RIGHT), new Runnable() { + return createIconRenderer(side, AllIcons.Diff.Arrow, new Runnable() { @Override public void run() { replaceChange(side); @@ -328,7 +329,7 @@ public class SimpleDiffChange { @Nullable private GutterIconRenderer createAppendRenderer(@NotNull final Side side) { - return createIconRenderer(side, DiffIcons.getAppendIcon(Side.RIGHT), new Runnable() { + return createIconRenderer(side, AllIcons.Diff.ArrowLeftDown, new Runnable() { @Override public void run() { appendChange(side); @@ -338,7 +339,7 @@ public class SimpleDiffChange { @Nullable private GutterIconRenderer createRevertRenderer(@NotNull final Side side) { - return createIconRenderer(side.other(), DiffIcons.getRevertIcon(Side.RIGHT), new Runnable() { + return createIconRenderer(side.other(), AllIcons.Diff.Remove, new Runnable() { @Override public void run() { replaceChange(side.other()); @@ -357,6 +358,8 @@ public class SimpleDiffChange { return icon; } + public boolean isNavigateAction() { return true; } + @Nullable @Override public AnAction getClickAction() { diff --git a/platform/diff-impl/src/com/intellij/diff/tools/simple/SimpleDiffViewer.java b/platform/diff-impl/src/com/intellij/diff/tools/simple/SimpleDiffViewer.java index 0b0c191a393f..860745320afb 100644 --- a/platform/diff-impl/src/com/intellij/diff/tools/simple/SimpleDiffViewer.java +++ b/platform/diff-impl/src/com/intellij/diff/tools/simple/SimpleDiffViewer.java @@ -32,11 +32,11 @@ import com.intellij.diff.tools.util.FoldingModelSupport.SimpleFoldingModel; import com.intellij.diff.tools.util.base.HighlightPolicy; import com.intellij.diff.tools.util.twoside.TwosideTextDiffViewer; import com.intellij.diff.util.DiffDividerDrawUtil; -import com.intellij.diff.util.DiffIcons; import com.intellij.diff.util.DiffUserDataKeysEx.ScrollToPolicy; import com.intellij.diff.util.DiffUtil; import com.intellij.diff.util.DiffUtil.DocumentData; import com.intellij.diff.util.Side; +import com.intellij.icons.AllIcons; import com.intellij.ide.IdeEventQueue; import com.intellij.openapi.actionSystem.AnAction; import com.intellij.openapi.actionSystem.AnActionEvent; @@ -663,13 +663,13 @@ public class SimpleDiffViewer extends TwosideTextDiffViewer { private class ReplaceSelectedChangesAction extends ApplySelectedChangesActionBase { public ReplaceSelectedChangesAction() { - super("Replace", null, DiffIcons.getReplaceIcon(null), true); + super("Replace", null, AllIcons.Diff.Arrow, true); } @NotNull @Override protected Icon getIcon(@NotNull Side side) { - return DiffIcons.getReplaceIcon(side); + return side.isLeft() ? AllIcons.Diff.Arrow : AllIcons.Diff.ArrowRight; } @Override @@ -682,13 +682,13 @@ public class SimpleDiffViewer extends TwosideTextDiffViewer { private class AppendSelectedChangesAction extends ApplySelectedChangesActionBase { public AppendSelectedChangesAction() { - super("Insert", null, DiffIcons.getAppendIcon(null), true); + super("Insert", null, AllIcons.Diff.ArrowLeftDown, true); } @NotNull @Override protected Icon getIcon(@NotNull Side side) { - return DiffIcons.getAppendIcon(side); + return side.isLeft() ? AllIcons.Diff.ArrowLeftDown : AllIcons.Diff.ArrowRightDown; } @Override @@ -701,13 +701,13 @@ public class SimpleDiffViewer extends TwosideTextDiffViewer { private class RevertSelectedChangesAction extends ApplySelectedChangesActionBase { public RevertSelectedChangesAction() { - super("Revert", null, DiffIcons.getRevertIcon(null), false); + super("Revert", null, AllIcons.Diff.Remove, false); } @NotNull @Override protected Icon getIcon(@NotNull Side side) { - return DiffIcons.getRevertIcon(side); + return AllIcons.Diff.Remove; } @Override diff --git a/platform/diff-impl/src/com/intellij/diff/util/DiffIcons.java b/platform/diff-impl/src/com/intellij/diff/util/DiffIcons.java deleted file mode 100644 index 1fea0e06add1..000000000000 --- a/platform/diff-impl/src/com/intellij/diff/util/DiffIcons.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright 2000-2015 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.intellij.diff.util; - -import com.intellij.icons.AllIcons; -import com.intellij.util.IconUtil; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import javax.swing.*; - -public class DiffIcons { - public final static Icon REPLACE_LEFT = IconUtil.flip(AllIcons.Diff.Arrow, true); - public final static Icon REPLACE_RIGHT = AllIcons.Diff.Arrow; - - // TODO: different icon - public final static Icon APPEND_LEFT = IconUtil.flip(AllIcons.Diff.Arrow, true); - public final static Icon APPEND_RIGHT = AllIcons.Diff.Arrow; - - public final static Icon REVERT_LEFT = AllIcons.Diff.Remove; - public final static Icon REVERT_RIGHT = AllIcons.Diff.Remove; - - @NotNull - public static Icon getReplaceIcon(@Nullable Side side) { - if (side == null) side = Side.LEFT; - return side.selectN(REPLACE_LEFT, REPLACE_RIGHT); - } - - @NotNull - public static Icon getAppendIcon(@Nullable Side side) { - if (side == null) side = Side.LEFT; - return side.selectN(APPEND_LEFT, APPEND_RIGHT); - } - - @NotNull - public static Icon getRevertIcon(@Nullable Side side) { - if (side == null) side = Side.LEFT; - return side.selectN(REVERT_LEFT, REVERT_RIGHT); - } -} diff --git a/platform/icons/src/diff/arrowLeftDown.png b/platform/icons/src/diff/arrowLeftDown.png new file mode 100644 index 000000000000..e01b1b4206bd Binary files /dev/null and b/platform/icons/src/diff/arrowLeftDown.png differ diff --git a/platform/icons/src/diff/arrowLeftDown@2x.png b/platform/icons/src/diff/arrowLeftDown@2x.png new file mode 100644 index 000000000000..39397c4c65c8 Binary files /dev/null and b/platform/icons/src/diff/arrowLeftDown@2x.png differ diff --git a/platform/icons/src/diff/arrowRight.png b/platform/icons/src/diff/arrowRight.png new file mode 100644 index 000000000000..f7d76849a23a Binary files /dev/null and b/platform/icons/src/diff/arrowRight.png differ diff --git a/platform/icons/src/diff/arrowRight@2x.png b/platform/icons/src/diff/arrowRight@2x.png new file mode 100644 index 000000000000..299b7d315bc2 Binary files /dev/null and b/platform/icons/src/diff/arrowRight@2x.png differ diff --git a/platform/icons/src/diff/arrowRightDown.png b/platform/icons/src/diff/arrowRightDown.png new file mode 100644 index 000000000000..7f005f1d68fc Binary files /dev/null and b/platform/icons/src/diff/arrowRightDown.png differ diff --git a/platform/icons/src/diff/arrowRightDown@2x.png b/platform/icons/src/diff/arrowRightDown@2x.png new file mode 100644 index 000000000000..d116ce1447dd Binary files /dev/null and b/platform/icons/src/diff/arrowRightDown@2x.png differ diff --git a/platform/platform-impl/src/com/intellij/codeInsight/hint/EditorFragmentComponent.java b/platform/platform-impl/src/com/intellij/codeInsight/hint/EditorFragmentComponent.java index 88a1d744aeaa..1f8715dc3681 100644 --- a/platform/platform-impl/src/com/intellij/codeInsight/hint/EditorFragmentComponent.java +++ b/platform/platform-impl/src/com/intellij/codeInsight/hint/EditorFragmentComponent.java @@ -51,101 +51,81 @@ public class EditorFragmentComponent extends JPanel { } } - private void doInit(final EditorEx editor, int startLine, int endLine, final boolean showFolding, final boolean showGutter) { - + private void doInit(EditorEx editor, int startLine, int endLine, boolean showFolding, boolean showGutter) { Document doc = editor.getDocument(); final int endOffset = endLine < doc.getLineCount() ? doc.getLineEndOffset(endLine) : doc.getTextLength(); final int textImageWidth = Math.min(editor.getMaxWidthInRange(doc.getLineStartOffset(startLine), endOffset), ScreenUtil .getScreenRectangle(1, 1).width); LOG.assertTrue(textImageWidth > 0, "TextWidth: "+textImageWidth+"; startLine:" + startLine + "; endLine:" + endLine + ";"); - final FoldingModelEx foldingModel = editor.getFoldingModel(); - final boolean isFoldingEnabled = foldingModel.isFoldingEnabled(); + FoldingModelEx foldingModel = editor.getFoldingModel(); + boolean isFoldingEnabled = foldingModel.isFoldingEnabled(); if (!showFolding) { foldingModel.setFoldingEnabled(false); } Point p1 = editor.logicalPositionToXY(new LogicalPosition(startLine, 0)); Point p2 = editor.logicalPositionToXY(new LogicalPosition(Math.max(endLine, startLine + 1), 0)); - final int y1 = p1.y; + int y1 = p1.y; int y2 = p2.y; final int textImageHeight = y2 - y1 == 0 ? editor.getLineHeight() : y2 - y1; LOG.assertTrue(textImageHeight > 0, "Height: " + textImageHeight + "; startLine:" + startLine + "; endLine:" + endLine + "; p1:" + p1 + "; p2:" + p2); - final int savedScrollOffset = editor.getScrollingModel().getHorizontalScrollOffset(); + int savedScrollOffset = editor.getScrollingModel().getHorizontalScrollOffset(); if (savedScrollOffset > 0) { editor.getScrollingModel().scrollHorizontally(0); } + final BufferedImage textImage = UIUtil.createImage(textImageWidth, textImageHeight, BufferedImage.TYPE_INT_RGB); + Graphics textGraphics = textImage.getGraphics(); + UISettings.setupAntialiasing(textGraphics); + + final JComponent rowHeader; + final BufferedImage markersImage; + final int markersImageWidth; + + if (showGutter) { + rowHeader = editor.getGutterComponentEx(); + markersImageWidth = Math.max(1, rowHeader.getWidth()); + + markersImage = UIUtil.createImage(markersImageWidth, textImageHeight, BufferedImage.TYPE_INT_RGB); + Graphics markerGraphics = markersImage.getGraphics(); + UISettings.setupAntialiasing(markerGraphics); + + markerGraphics.translate(0, -y1); + markerGraphics.setClip(0, y1, rowHeader.getWidth(), textImageHeight); + markerGraphics.setColor(getBackgroundColor(editor)); + markerGraphics.fillRect(0, y1, rowHeader.getWidth(), textImageHeight); + rowHeader.paint(markerGraphics); + } + else { + markersImageWidth = 0; + rowHeader = null; + markersImage = null; + } + + textGraphics.translate(0, -y1); + textGraphics.setClip(0, y1, textImageWidth, textImageHeight); + final boolean wasVisible = editor.setCaretVisible(false); + editor.getContentComponent().paint(textGraphics); + if (wasVisible) { + editor.setCaretVisible(true); + } + + if (!showFolding) { + foldingModel.setFoldingEnabled(isFoldingEnabled); + } + + if (savedScrollOffset > 0) { + editor.getScrollingModel().scrollHorizontally(savedScrollOffset); + } + JComponent component = new JComponent() { - - private Graphics2D componentGraphics; - private JComponent rowHeader; - private BufferedImage markersImage; - private int markersImageWidth; - private BufferedImage textImage; - - private void updateImages() { - - if ((getGraphics()).equals(componentGraphics)) { - return; - } - - componentGraphics = (Graphics2D)getGraphics(); - - textImage = UIUtil.createImageForGraphics(componentGraphics, - textImageWidth, textImageHeight, BufferedImage.TYPE_INT_RGB); - Graphics textGraphics = textImage.getGraphics(); - UISettings.setupAntialiasing(textGraphics); - - if (showGutter) { - rowHeader = editor.getGutterComponentEx(); - markersImageWidth = Math.max(1, rowHeader.getWidth()); - - markersImage = UIUtil.createImageForGraphics(componentGraphics, markersImageWidth, textImageHeight, BufferedImage.TYPE_INT_RGB); - Graphics markerGraphics = markersImage.getGraphics(); - UISettings.setupAntialiasing(markerGraphics); - - markerGraphics.translate(0, -y1); - markerGraphics.setClip(0, y1, rowHeader.getWidth(), textImageHeight); - markerGraphics.setColor(getBackgroundColor(editor)); - markerGraphics.fillRect(0, y1, rowHeader.getWidth(), textImageHeight); - rowHeader.paint(markerGraphics); - } - else { - markersImageWidth = 0; - rowHeader = null; - markersImage = null; - } - - textGraphics.translate(0, -y1); - textGraphics.setClip(0, y1, textImageWidth, textImageHeight); - final boolean wasVisible = editor.setCaretVisible(false); - editor.getContentComponent().paint(textGraphics); - if (wasVisible) { - editor.setCaretVisible(true); - } - - if (!showFolding) { - foldingModel.setFoldingEnabled(isFoldingEnabled); - } - - if (savedScrollOffset > 0) { - editor.getScrollingModel().scrollHorizontally(savedScrollOffset); - } - } - @Override public Dimension getPreferredSize() { return new Dimension(textImageWidth + markersImageWidth, textImageHeight); } - @Override - public void addNotify() { - super.addNotify(); - updateImages(); - } - @Override protected void paintComponent(Graphics graphics) { if (markersImage != null) { diff --git a/platform/platform-impl/src/com/intellij/openapi/diff/actions/MergeOperations.java b/platform/platform-impl/src/com/intellij/openapi/diff/actions/MergeOperations.java index 2d41d5ab8eb7..1f7072d09a32 100644 --- a/platform/platform-impl/src/com/intellij/openapi/diff/actions/MergeOperations.java +++ b/platform/platform-impl/src/com/intellij/openapi/diff/actions/MergeOperations.java @@ -131,7 +131,7 @@ public class MergeOperations { private static Operation insertOperation(TextRange range, int offset, Document document, Document otherDocument) { return new Operation(DiffBundle.message("merge.editor.insert.operation.name"), - AllIcons.Diff.Arrow, + AllIcons.Diff.ArrowRightDown, otherDocument, insertModification(range, document, offset, otherDocument)); } diff --git a/platform/structuralsearch/testSource/com/intellij/structuralsearch/StructuralSearchTest.java b/platform/structuralsearch/testSource/com/intellij/structuralsearch/StructuralSearchTest.java index 6398627faff1..23250d8fe2fe 100644 --- a/platform/structuralsearch/testSource/com/intellij/structuralsearch/StructuralSearchTest.java +++ b/platform/structuralsearch/testSource/com/intellij/structuralsearch/StructuralSearchTest.java @@ -1233,6 +1233,21 @@ public class StructuralSearchTest extends StructuralSearchTestCase { "find sym finds declaration", 2, findMatchesCount(s133_2, s134, true) ); + final String in = "class C {" + + " {" + + " int i = 0;" + + " i += 1;" + + " i = 3;" + + " int j = i;" + + " i();" + + " }" + + " void i() {}" + + "}"; + final String pattern1 = "'_:[read]"; + assertEquals("Find reads of symbol (including operator assignment)", 2, findMatchesCount(in, pattern1)); + + final String pattern2 = "'_:[write && regex( i )]"; + assertEquals("Find writes of symbol", 3, findMatchesCount(in, pattern2)); } public void testSearchGenerics() { @@ -1900,14 +1915,14 @@ public class StructuralSearchTest extends StructuralSearchTestCase { assertEquals( "fields of class read", - findMatchesCount(s117,s118_2), - 2 + 2, + findMatchesCount(s117,s118_2) ); assertEquals( "fields of class written", - findMatchesCount(s117,s118_3), - 2 + 2, + findMatchesCount(s117,s118_3) ); final String s119 = "try { a.b(); } catch(IOException e) { c(); } catch(Exception ex) { d(); }"; diff --git a/platform/util/src/com/intellij/icons/AllIcons.java b/platform/util/src/com/intellij/icons/AllIcons.java index 49b548c4971c..fde46ce43706 100644 --- a/platform/util/src/com/intellij/icons/AllIcons.java +++ b/platform/util/src/com/intellij/icons/AllIcons.java @@ -311,6 +311,9 @@ public class AllIcons { public static class Diff { public static final Icon ApplyNotConflicts = IconLoader.getIcon("/diff/applyNotConflicts.png"); // 16x16 public static final Icon Arrow = IconLoader.getIcon("/diff/arrow.png"); // 11x11 + public static final Icon ArrowLeftDown = IconLoader.getIcon("/diff/arrowLeftDown.png"); // 11x11 + public static final Icon ArrowRight = IconLoader.getIcon("/diff/arrowRight.png"); // 11x11 + public static final Icon ArrowRightDown = IconLoader.getIcon("/diff/arrowRightDown.png"); // 11x11 public static final Icon BranchDiff = IconLoader.getIcon("/diff/branchDiff.png"); // 16x16 public static final Icon CurrentLine = IconLoader.getIcon("/diff/currentLine.png"); // 16x16 public static final Icon Diff = IconLoader.getIcon("/diff/Diff.png"); // 16x16 diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/CacheChangeProcessor.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/CacheChangeProcessor.java index f44497106063..05398a8edfba 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/CacheChangeProcessor.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/CacheChangeProcessor.java @@ -122,9 +122,9 @@ public abstract class CacheChangeProcessor extends DiffRequestProcessor { ChangeListManager.getInstance(myProject).invokeAfterUpdate(new Runnable() { @Override public void run() { - refresh(); + refresh(); // TODO: this could cause diff init in 'hide' state } - }, InvokeAfterUpdateMode.BACKGROUND_CANCELLABLE, "", ModalityState.current()); + }, InvokeAfterUpdateMode.SILENT, "", ModalityState.current()); return new LoadingDiffRequest(ChangeDiffRequestProducer.getRequestTitle(change)); }