Merge remote-tracking branch 'origin/master'

This commit is contained in:
Daniil Ovchinnikov
2015-02-09 19:51:08 +03:00
15 changed files with 100 additions and 150 deletions
@@ -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;
}
}
@@ -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() {
@@ -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
@@ -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);
}
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 124 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 152 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 170 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 293 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 129 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 158 B

@@ -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) {
@@ -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));
}
@@ -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(); }";
@@ -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
@@ -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));
}