diff options
Diffstat (limited to 'platform/structuralsearch')
7 files changed, 64 insertions, 71 deletions
diff --git a/platform/structuralsearch/source/com/intellij/structuralsearch/impl/matcher/CompiledPattern.java b/platform/structuralsearch/source/com/intellij/structuralsearch/impl/matcher/CompiledPattern.java index 565f80ac01ce..70c1cdccd03e 100644 --- a/platform/structuralsearch/source/com/intellij/structuralsearch/impl/matcher/CompiledPattern.java +++ b/platform/structuralsearch/source/com/intellij/structuralsearch/impl/matcher/CompiledPattern.java @@ -82,7 +82,7 @@ public abstract class CompiledPattern { public boolean isRealTypedVar(PsiElement element) { if (element!=null && element.getTextLength()>0) { String str = getTypedVarString(element); - if (str.length()==0) { + if (str == null || str.length()==0) { return false; } return isTypedVar( str ); diff --git a/platform/structuralsearch/source/com/intellij/structuralsearch/impl/matcher/compiler/PatternCompiler.java b/platform/structuralsearch/source/com/intellij/structuralsearch/impl/matcher/compiler/PatternCompiler.java index e290ebb70793..6dba855121cb 100644 --- a/platform/structuralsearch/source/com/intellij/structuralsearch/impl/matcher/compiler/PatternCompiler.java +++ b/platform/structuralsearch/source/com/intellij/structuralsearch/impl/matcher/compiler/PatternCompiler.java @@ -272,12 +272,8 @@ public class PatternCompiler { element.accept(new PsiRecursiveElementWalkingVisitor() { @Override - public void visitElement(PsiElement element) { - super.visitElement(element); - - if (!(element instanceof PsiErrorElement)) { - return; - } + public void visitErrorElement(PsiErrorElement element) { + super.visitErrorElement(element); final int startOffset = element.getTextRange().getStartOffset(); diff --git a/platform/structuralsearch/source/com/intellij/structuralsearch/plugin/ui/EditVarConstraintsDialog.java b/platform/structuralsearch/source/com/intellij/structuralsearch/plugin/ui/EditVarConstraintsDialog.java index 368240ff50be..f82ad12e5f4f 100644 --- a/platform/structuralsearch/source/com/intellij/structuralsearch/plugin/ui/EditVarConstraintsDialog.java +++ b/platform/structuralsearch/source/com/intellij/structuralsearch/plugin/ui/EditVarConstraintsDialog.java @@ -22,7 +22,6 @@ import com.intellij.openapi.project.Project; import com.intellij.openapi.ui.ComponentWithBrowseButton; import com.intellij.openapi.ui.DialogWrapper; import com.intellij.openapi.ui.Messages; -import com.intellij.openapi.ui.popup.JBPopup; import com.intellij.openapi.util.text.StringUtil; import com.intellij.psi.PsiDocumentManager; import com.intellij.psi.PsiFile; @@ -36,8 +35,6 @@ import com.intellij.structuralsearch.plugin.replace.ReplaceOptions; import com.intellij.structuralsearch.plugin.replace.ui.ReplaceConfiguration; import com.intellij.ui.ComboboxWithBrowseButton; import com.intellij.ui.EditorTextField; -import com.intellij.ui.components.labels.LinkLabel; -import com.intellij.ui.components.labels.LinkListener; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; @@ -46,7 +43,6 @@ import javax.swing.event.ChangeEvent; import javax.swing.event.ChangeListener; import javax.swing.event.ListSelectionEvent; import javax.swing.event.ListSelectionListener; -import javax.swing.text.BadLocationException; import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; @@ -117,7 +113,7 @@ class EditVarConstraintsDialog extends DialogWrapper { withinCombo.getComboBox().setEditable(true); withinCombo.getButton().addActionListener(new ActionListener() { - public void actionPerformed(final ActionEvent e) { + public void actionPerformed(@NotNull final ActionEvent e) { final SelectTemplateDialog dialog = new SelectTemplateDialog(project, false, false); dialog.show(); if (dialog.getExitCode() == OK_EXIT_CODE) { @@ -191,7 +187,7 @@ class EditVarConstraintsDialog extends DialogWrapper { new ListSelectionListener() { boolean rollingBackSelection; - public void valueChanged(ListSelectionEvent e) { + public void valueChanged(@NotNull ListSelectionEvent e) { if (e.getValueIsAdjusting()) return; if (rollingBackSelection) { rollingBackSelection=false; @@ -212,7 +208,7 @@ class EditVarConstraintsDialog extends DialogWrapper { parameterList.setCellRenderer( new DefaultListCellRenderer() { - public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { + public Component getListCellRendererComponent(@NotNull JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { String name = ((Variable)value).getName(); if (Configuration.CONTEXT_VAR_NAME.equals(name)) name = SSRBundle.message("complete.match.variable.name"); if (isReplacementVariable(name)) { @@ -226,7 +222,7 @@ class EditVarConstraintsDialog extends DialogWrapper { maxoccursUnlimited.addChangeListener(new MyChangeListener(maxoccurs, true)); customScriptCode.getButton().addActionListener(new ActionListener() { - public void actionPerformed(final ActionEvent e) { + public void actionPerformed(@NotNull final ActionEvent e) { final EditScriptDialog dialog = new EditScriptDialog(project, customScriptCode.getChildComponent().getText()); dialog.show(); if (dialog.getExitCode() == OK_EXIT_CODE) { @@ -505,18 +501,7 @@ class EditVarConstraintsDialog extends DialogWrapper { formalArgType = createRegexComponent(); customScriptCode = new ComponentWithBrowseButton<EditorTextField>(createScriptComponent(), null); - myRegExHelpLabel = new LinkLabel(SSRBundle.message("regular.expression.help.label"), null, new LinkListener() { - public void linkSelected(LinkLabel aSource, Object aLinkData) { - try { - final JBPopup helpPopup = RegExHelpPopup.createRegExHelpPopup(); - helpPopup.showInCenterOf(mainForm); - } - catch (BadLocationException e) { - LOG.info(e); - } - } - }); - + myRegExHelpLabel = RegExHelpPopup.createRegExLink(SSRBundle.message("regular.expression.help.label"), regexp, LOG); myRegExHelpLabel.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 5)); } @@ -559,7 +544,7 @@ class EditVarConstraintsDialog extends DialogWrapper { inverted = _inverted; } - public void stateChanged(ChangeEvent e) { + public void stateChanged(@NotNull ChangeEvent e) { final JCheckBox jCheckBox = (JCheckBox)e.getSource(); component.setEnabled(inverted ^ jCheckBox.isSelected()); } diff --git a/platform/structuralsearch/source/com/intellij/structuralsearch/plugin/ui/SubstitutionShortInfoHandler.java b/platform/structuralsearch/source/com/intellij/structuralsearch/plugin/ui/SubstitutionShortInfoHandler.java index 32f1302336f3..ecdccbe0e40b 100644 --- a/platform/structuralsearch/source/com/intellij/structuralsearch/plugin/ui/SubstitutionShortInfoHandler.java +++ b/platform/structuralsearch/source/com/intellij/structuralsearch/plugin/ui/SubstitutionShortInfoHandler.java @@ -1,6 +1,6 @@ package com.intellij.structuralsearch.plugin.ui; -import com.intellij.codeInsight.hint.TooltipGroup; +import com.intellij.codeInsight.hint.TooltipController; import com.intellij.codeInsight.template.impl.TemplateImplUtil; import com.intellij.codeInsight.template.impl.Variable; import com.intellij.openapi.editor.Document; @@ -11,7 +11,6 @@ import com.intellij.openapi.util.Key; import org.jetbrains.annotations.NotNull; import java.util.ArrayList; -import java.util.Iterator; /** * Created by IntelliJ IDEA. @@ -21,7 +20,6 @@ import java.util.Iterator; * To change this template use File | Settings | File Templates. */ public class SubstitutionShortInfoHandler implements DocumentListener, EditorMouseMotionListener, CaretListener { - private static final TooltipGroup SS_INFO_TOOLTIP_GROUP = new TooltipGroup("SS_INFO_TOOLTIP_GROUP", 0); private long modificationTimeStamp; private final ArrayList<Variable> variables = new ArrayList<Variable>(); @@ -63,9 +61,7 @@ public class SubstitutionShortInfoHandler implements DocumentListener, EditorMou String varname = elements.subSequence(start + 1, end).toString(); Variable foundVar = null; - for(Iterator<Variable> i=variables.iterator();i.hasNext();) { - final Variable var = i.next(); - + for (final Variable var : variables) { if (var.getName().equals(varname)) { foundVar = var; break; @@ -79,7 +75,10 @@ public class SubstitutionShortInfoHandler implements DocumentListener, EditorMou } if (text.length() > 0) { - UIUtil.showTooltip(editor, start, end, text, SS_INFO_TOOLTIP_GROUP); + UIUtil.showTooltip(editor, start, end + 1, text); + } + else { + TooltipController.getInstance().cancelTooltips(); } } diff --git a/platform/structuralsearch/source/com/intellij/structuralsearch/plugin/ui/UIUtil.java b/platform/structuralsearch/source/com/intellij/structuralsearch/plugin/ui/UIUtil.java index aa3ca82725b0..e2c16bfbc355 100644 --- a/platform/structuralsearch/source/com/intellij/structuralsearch/plugin/ui/UIUtil.java +++ b/platform/structuralsearch/source/com/intellij/structuralsearch/plugin/ui/UIUtil.java @@ -15,17 +15,14 @@ import com.intellij.openapi.editor.colors.EditorColors; import com.intellij.openapi.editor.colors.EditorColorsManager; import com.intellij.openapi.editor.colors.EditorColorsScheme; import com.intellij.openapi.editor.ex.EditorEx; -import com.intellij.openapi.fileEditor.FileEditorManager; -import com.intellij.openapi.fileEditor.OpenFileDescriptor; import com.intellij.openapi.project.Project; import com.intellij.openapi.util.Key; import com.intellij.openapi.util.text.StringUtil; -import com.intellij.psi.*; import com.intellij.structuralsearch.*; import com.intellij.structuralsearch.plugin.StructuralReplaceAction; import com.intellij.structuralsearch.plugin.StructuralSearchAction; import com.intellij.structuralsearch.plugin.replace.ui.ReplaceConfiguration; -import com.intellij.structuralsearch.plugin.util.SmartPsiPointer; +import com.intellij.ui.HintHint; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -41,6 +38,7 @@ import java.awt.*; public class UIUtil { static Key<SubstitutionShortInfoHandler> LISTENER_KEY = Key.create("sslistener.key"); private static final String MODIFY_EDITOR_CONTENT = SSRBundle.message("modify.editor.content.command.name"); + private static final TooltipGroup SS_INFO_TOOLTIP_GROUP = new TooltipGroup("SS_INFO_TOOLTIP_GROUP", 0); @NonNls private static final String SS_GROUP = "structuralsearchgroup"; @NotNull @@ -191,18 +189,6 @@ public class UIUtil { buf.append(str); } - public static void navigate(PsiElement result) { - FileEditorManager.getInstance(result.getProject()).openTextEditor( - new OpenFileDescriptor(result.getProject(), result.getContainingFile().getVirtualFile(), result.getTextOffset()), true); - } - - public static void navigate(MatchResult result) { - final SmartPsiPointer ref = result.getMatchRef(); - - FileEditorManager.getInstance(ref.getProject()) - .openTextEditor(new OpenFileDescriptor(ref.getProject(), ref.getFile(), ref.getOffset()), true); - } - public static void invokeAction(Configuration config, SearchContext context) { if (config instanceof SearchConfiguration) { StructuralSearchAction.triggerAction(config, context); @@ -212,22 +198,27 @@ public class UIUtil { } } - static void showTooltip(@NotNull Editor editor, final int start, int end, @NotNull String text, @NotNull TooltipGroup group) { - Rectangle visibleArea = editor.getScrollingModel().getVisibleArea(); - Point top = editor.logicalPositionToXY(editor.offsetToLogicalPosition(start)); + static void showTooltip(@NotNull Editor editor, final int start, int end, @NotNull String text) { + final Rectangle visibleArea = editor.getScrollingModel().getVisibleArea(); + final Point left = editor.logicalPositionToXY(editor.offsetToLogicalPosition(start)); final int documentLength = editor.getDocument().getTextLength(); if (end >= documentLength) end = documentLength; - Point bottom = editor.logicalPositionToXY(editor.offsetToLogicalPosition(end)); + final Point right = editor.logicalPositionToXY(editor.offsetToLogicalPosition(end)); - Point bestPoint = new Point(top.x, bottom.y + editor.getLineHeight()); + final Point bestPoint = new Point(left.x + (right.x - left.x) / 2, right.y + editor.getLineHeight() / 2); - if (!visibleArea.contains(bestPoint)) { - int defaultOffset = editor.logicalPositionToOffset(editor.xyToLogicalPosition(new Point(0, 0))); - bestPoint = editor.logicalPositionToXY(editor.offsetToLogicalPosition(defaultOffset)); + if (visibleArea.x > bestPoint.x) { + bestPoint.x = visibleArea.x; + } + else if (visibleArea.x + visibleArea.width < bestPoint.x) { + bestPoint.x = visibleArea.x + visibleArea.width - 5; } - Point p = SwingUtilities.convertPoint(editor.getContentComponent(), bestPoint, editor.getComponent().getRootPane().getLayeredPane()); - TooltipController.getInstance().showTooltip(editor, p, text, false, group); + final Point p = SwingUtilities.convertPoint(editor.getContentComponent(), bestPoint, + editor.getComponent().getRootPane().getLayeredPane()); + final HintHint hint = new HintHint(editor, bestPoint).setAwtTooltip(true).setHighlighterType(true) + .setCalloutShift(editor.getLineHeight() / 2 - 1); + TooltipController.getInstance().showTooltip(editor, p, text, visibleArea.width, false, SS_INFO_TOOLTIP_GROUP, hint); } public static void updateHighlighter(Editor editor, StructuralSearchProfile profile) { diff --git a/platform/structuralsearch/source/com/intellij/structuralsearch/plugin/ui/UsageViewContext.java b/platform/structuralsearch/source/com/intellij/structuralsearch/plugin/ui/UsageViewContext.java index afd2ae1b029d..a55a16d4c379 100644 --- a/platform/structuralsearch/source/com/intellij/structuralsearch/plugin/ui/UsageViewContext.java +++ b/platform/structuralsearch/source/com/intellij/structuralsearch/plugin/ui/UsageViewContext.java @@ -1,13 +1,13 @@ package com.intellij.structuralsearch.plugin.ui; import com.intellij.navigation.ItemPresentation; -import com.intellij.openapi.actionSystem.*; +import com.intellij.openapi.actionSystem.ActionManager; +import com.intellij.openapi.actionSystem.KeyboardShortcut; import com.intellij.openapi.editor.Editor; import com.intellij.openapi.fileEditor.FileEditor; import com.intellij.openapi.util.text.StringUtil; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.psi.PsiFile; -import com.intellij.psi.search.GlobalSearchScope; import com.intellij.structuralsearch.SSRBundle; import com.intellij.structuralsearch.plugin.replace.ui.ReplaceCommand; import com.intellij.usages.*; @@ -81,7 +81,7 @@ public class UsageViewContext { protected void configureActions() {} - private class MyUsageTarget implements ConfigurableUsageTarget,ItemPresentation, TypeSafeDataProvider { + private class MyUsageTarget implements ConfigurableUsageTarget,ItemPresentation { private final String myPresentableText; MyUsageTarget(String str) { @@ -179,12 +179,5 @@ public class UsageViewContext { public String getLongDescriptiveName() { return _getPresentableText(); } - - @Override - public void calcData(DataKey key, DataSink sink) { - if (key == UsageView.USAGE_SCOPE) { - sink.put(UsageView.USAGE_SCOPE, GlobalSearchScope.allScope(mySearchContext.getProject())); - } - } } } diff --git a/platform/structuralsearch/testSource/com/intellij/structuralsearch/StructuralReplaceTest.java b/platform/structuralsearch/testSource/com/intellij/structuralsearch/StructuralReplaceTest.java index de9b668be4d3..fe1b6e09d99f 100644 --- a/platform/structuralsearch/testSource/com/intellij/structuralsearch/StructuralReplaceTest.java +++ b/platform/structuralsearch/testSource/com/intellij/structuralsearch/StructuralReplaceTest.java @@ -1809,6 +1809,35 @@ public class StructuralReplaceTest extends StructuralReplaceTestCase { ); } + public void testUseStaticImport() { + final String in = "class X {{ Math.abs(-1); }}"; + final String what = "Math.abs('a)"; + final String by = "Math.abs($a$)"; + options.setToUseStaticImport(true); + + final String expected = "import static java.lang.Math.abs;class X {{ abs(-1); }}"; + assertEquals("Replacing with static import", expected, replacer.testReplace(in, what, by, options, true)); + } + + public void testUseStaticStarImport() { + final String in = "class ImportTest {{\n" + + " Math.abs(-0.5);\n" + + " Math.sin(0.5);\n" + + " Math.max(1, 2);\n" + + "}}"; + final String what = "Math.'m('a*)"; + final String by = "Math.$m$($a$)"; + options.setToUseStaticImport(true); + + // depends on default setting being equal to 3 for names count to use import on demand + final String expected = "import static java.lang.Math.*;class ImportTest {{\n" + + " abs(-0.5);\n" + + " sin(0.5);\n" + + " max(1,2);\n" + + "}}"; + assertEquals("Replacing with static star import", expected, replacer.testReplace(in, what, by, options, true)); + } + public void testReformatAndShortenClassRefPerformance() throws IOException { final String testName = getTestName(false); final String ext = "java"; |