From c992b9c21662bedf5d1611fb82520ad9e8b35a1b Mon Sep 17 00:00:00 2001 From: Roman Shevchenko Date: Wed, 9 Mar 2011 13:02:38 +0100 Subject: [PATCH 1/5] Resolve in javadoc fixed --- .../javadoc/PsiDocMethodOrFieldRef.java | 2 +- .../javaDoc/resolve/pkg/See3.java | 28 +++++++++++++++++++ .../daemon/JavadocResolveTest.java | 1 + 3 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 java/java-tests/testData/codeInsight/daemonCodeAnalyzer/javaDoc/resolve/pkg/See3.java diff --git a/java/java-impl/src/com/intellij/psi/impl/source/javadoc/PsiDocMethodOrFieldRef.java b/java/java-impl/src/com/intellij/psi/impl/source/javadoc/PsiDocMethodOrFieldRef.java index e4416a428200..2e184b08c3b0 100644 --- a/java/java-impl/src/com/intellij/psi/impl/source/javadoc/PsiDocMethodOrFieldRef.java +++ b/java/java-impl/src/com/intellij/psi/impl/source/javadoc/PsiDocMethodOrFieldRef.java @@ -101,7 +101,7 @@ public class PsiDocMethodOrFieldRef extends CompositePsiElement implements PsiDo final PsiElementFactory elementFactory = JavaPsiFacade.getInstance(element.getProject()).getElementFactory(); for (String s : signature) { try { - types.add(elementFactory.createTypeFromText(s, scope)); + types.add(elementFactory.createTypeFromText(s, element)); } catch (IncorrectOperationException e) { types.add(PsiType.NULL); diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/javaDoc/resolve/pkg/See3.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/javaDoc/resolve/pkg/See3.java new file mode 100644 index 000000000000..dd7bf93b51a2 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/javaDoc/resolve/pkg/See3.java @@ -0,0 +1,28 @@ +package pkg; + +/** + * @see #equals(Object) + + * @see A3#equals(Object) + * @see pkg.A3#equals(Object) + + * @see Object#equals(Object) + * @see java.lang.Object#equals(Object) + */ +class A3 { + public boolean equals(Object obj) { + return super.equals(obj); + } +} + +/** + * @see #equals(Object) + + * @see B3#equals(Object) + * @see pkg.B3#equals(Object) + + * @see Object#equals(Object) + * @see java.lang.Object#equals(Object) + */ +class B3 { +} diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/JavadocResolveTest.java b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/JavadocResolveTest.java index 6b2be0270645..7b776d725ae7 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/JavadocResolveTest.java +++ b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/JavadocResolveTest.java @@ -30,6 +30,7 @@ public class JavadocResolveTest extends DaemonAnalyzerTestCase { public void testSee0() throws Exception { doTest(); } public void testSee1() throws Exception { doTest(); } public void testSee2() throws Exception { doTest(); } + public void testSee3() throws Exception { doTest(); } private void doTest() throws Exception { doTest(BASE_PATH + "/pkg/" + getTestName(false) + ".java", BASE_PATH, false, false); From d58209544c37270f2f53fc2b54d0dc40d0ab8ebf Mon Sep 17 00:00:00 2001 From: Kirill Kalishev Date: Wed, 9 Mar 2011 15:31:09 +0300 Subject: [PATCH 2/5] IDEA-52421 Implement the swipe-gesture on Mac OS X as Back and Forward --- .../impl/MouseGestureManager.java | 144 ++++++++++++++++++ .../openapi/wm/impl/IdeFrameImpl.java | 7 + .../src/misc/registry.properties | 3 +- .../src/componentSets/UICore.xml | 4 + 4 files changed, 157 insertions(+), 1 deletion(-) create mode 100644 platform/platform-impl/src/com/intellij/openapi/actionSystem/impl/MouseGestureManager.java diff --git a/platform/platform-impl/src/com/intellij/openapi/actionSystem/impl/MouseGestureManager.java b/platform/platform-impl/src/com/intellij/openapi/actionSystem/impl/MouseGestureManager.java new file mode 100644 index 000000000000..4922be8a46f7 --- /dev/null +++ b/platform/platform-impl/src/com/intellij/openapi/actionSystem/impl/MouseGestureManager.java @@ -0,0 +1,144 @@ +/* + * Copyright 2000-2011 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.openapi.actionSystem.impl; + +import com.intellij.openapi.actionSystem.AnAction; +import com.intellij.openapi.application.ApplicationManager; +import com.intellij.openapi.components.ApplicationComponent; +import com.intellij.openapi.diagnostic.Logger; +import com.intellij.openapi.util.SystemInfo; +import com.intellij.openapi.util.registry.Registry; +import com.intellij.openapi.wm.IdeFrame; +import org.jetbrains.annotations.NotNull; + +import javax.swing.*; +import java.awt.event.ActionEvent; +import java.awt.event.MouseEvent; +import java.lang.reflect.InvocationHandler; +import java.lang.reflect.Method; +import java.lang.reflect.Proxy; +import java.util.HashMap; +import java.util.Map; + +/** + * Created by IntelliJ IDEA. + * User: kirillk + * Date: 3/9/11 + * Time: 2:50 PM + * To change this template use File | Settings | File Templates. + */ +public class MouseGestureManager implements ApplicationComponent { + + private static final Logger LOG = Logger.getInstance("MouseGestureManager"); + private ActionManagerImpl myActionManager; + + private Map myListeners = new HashMap(); + + public MouseGestureManager(ActionManagerImpl actionManager) { + myActionManager = actionManager; + } + + public void add(final IdeFrame frame) { + if (!Registry.is("actionSystem.mouseGesturesEnabled")) return; + + if (SystemInfo.isMacOSSnowLeopard) { + try { + assert !myListeners.containsKey(frame) : "Frame already registered"; + + Class gestureListenerClass = Class.forName("com.apple.eawt.event.GestureListener"); + Class swipeListenerClass = Class.forName("com.apple.eawt.event.SwipeListener"); + Object listener = Proxy.newProxyInstance(getClass().getClassLoader(), new Class[]{swipeListenerClass}, new InvocationHandler() { + @Override + public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { + if ("swipedRight".equals(method.getName())) { + processRightSwipe(frame); + } else if ("swipedLeft".equals(method.getName())) { + processLeftSwipe(frame); + } + return null; + } + }); + + Class utilsClass = Class.forName("com.apple.eawt.event.GestureUtilities"); + Method addMethod = utilsClass.getDeclaredMethod("addGestureListenerTo", JComponent.class, gestureListenerClass); + addMethod.invoke(null, frame.getComponent(), listener); + + myListeners.put(frame, listener); + } + catch (Exception e) { + LOG.error(e); + } + } + } + + private void processLeftSwipe(IdeFrame frame) { + AnAction forward = myActionManager.getAction("Forward"); + if (forward == null) return; + + myActionManager.tryToExecute(forward, createMouseEventWrapper(frame), null, null, false); + } + + private void processRightSwipe(IdeFrame frame) { + AnAction back = myActionManager.getAction("Back"); + if (back == null) return; + + myActionManager.tryToExecute(back, createMouseEventWrapper(frame), null, null, false); + } + + private MouseEvent createMouseEventWrapper(IdeFrame frame) { + return new MouseEvent(frame.getComponent(), ActionEvent.ACTION_PERFORMED, System.currentTimeMillis(), 0, 0, 0, 0, false, 0); + } + + public void remove(IdeFrame frame) { + if (!Registry.is("actionSystem.mouseGesturesEnabled")) return; + + if (SystemInfo.isMacOSSnowLeopard) { + try { + Object listener = myListeners.get(frame); + if (listener != null) { + Class gestureListenerClass = Class.forName("com.apple.eawt.event.GestureListener"); + Class utilsClass = Class.forName("com.apple.eawt.event.GestureUtilities"); + Method addMethod = utilsClass.getDeclaredMethod("removeGestureListenerFrom", JComponent.class, gestureListenerClass); + addMethod.invoke(null, frame.getComponent(), listener); + } + } + catch (Exception e) { + LOG.error(e); + } + } + + } + + @Override + public void initComponent() { + + } + + @Override + public void disposeComponent() { + + } + + @NotNull + @Override + public String getComponentName() { + return "MouseGestureListener"; + } + + public static MouseGestureManager getInstance() { + return ApplicationManager.getApplication().getComponent(MouseGestureManager.class); + } +} diff --git a/platform/platform-impl/src/com/intellij/openapi/wm/impl/IdeFrameImpl.java b/platform/platform-impl/src/com/intellij/openapi/wm/impl/IdeFrameImpl.java index 5ef3b4d0e82f..a06a1f455bbf 100644 --- a/platform/platform-impl/src/com/intellij/openapi/wm/impl/IdeFrameImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/wm/impl/IdeFrameImpl.java @@ -24,6 +24,7 @@ import com.intellij.openapi.MnemonicHelper; import com.intellij.openapi.actionSystem.DataProvider; import com.intellij.openapi.actionSystem.PlatformDataKeys; import com.intellij.openapi.actionSystem.ex.ActionManagerEx; +import com.intellij.openapi.actionSystem.impl.MouseGestureManager; import com.intellij.openapi.application.Application; import com.intellij.openapi.application.ApplicationInfo; import com.intellij.openapi.application.ApplicationManager; @@ -57,6 +58,9 @@ import java.awt.*; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; import java.io.File; +import java.lang.reflect.InvocationHandler; +import java.lang.reflect.Method; +import java.lang.reflect.Proxy; /** * @author Anton Katilin @@ -99,6 +103,7 @@ public class IdeFrameImpl extends JFrame implements IdeFrame, DataProvider { setFocusableWindowState(false); } + MouseGestureManager.getInstance().add(this); } @Override @@ -326,6 +331,8 @@ public class IdeFrameImpl extends JFrame implements IdeFrame, DataProvider { } public void dispose() { + MouseGestureManager.getInstance().remove(this); + if (myRootPane != null) { myRootPane = null; } diff --git a/platform/platform-resources-en/src/misc/registry.properties b/platform/platform-resources-en/src/misc/registry.properties index 7e58a12cb257..4703a5999a24 100644 --- a/platform/platform-resources-en/src/misc/registry.properties +++ b/platform/platform-resources-en/src/misc/registry.properties @@ -29,6 +29,7 @@ actionSystem.quickAccessEnabled=false actionSystem.quickAccessModifiers= actionSystem.quickAccessShowSpotsTime=1500 actionSystem.win.supressAlt=true +actionSystem.mouseGesturesEnabled=true ide.firstStartup=true ide.debugMode=false @@ -116,4 +117,4 @@ vcs.show.history.numbers=true navbar.updateMergeTime=250 navbar.userActivityMergeTime=500 -inspectionGadgets.telemetry.enabled=false \ No newline at end of file +inspectionGadgets.telemetry.enabled=false diff --git a/platform/platform-resources/src/componentSets/UICore.xml b/platform/platform-resources/src/componentSets/UICore.xml index c2aeecea712c..852a29e993d1 100644 --- a/platform/platform-resources/src/componentSets/UICore.xml +++ b/platform/platform-resources/src/componentSets/UICore.xml @@ -35,6 +35,10 @@ com.intellij.ide.IdeTooltipManager + + com.intellij.openapi.actionSystem.impl.MouseGestureManager + + com.intellij.ide.SaveAndSyncHandler com.intellij.ide.SaveAndSyncHandler From f26ffb5608f84625f7c779c60ff3425a095aee39 Mon Sep 17 00:00:00 2001 From: Bas Leijdekkers Date: Wed, 9 Mar 2011 13:36:19 +0100 Subject: [PATCH 3/5] IDEA-64871 (Inspection result viewer screws up sorting) --- .../ui/InspectionResultsView.java | 7 +++---- .../codeInspection/ui/InspectionTree.java | 18 +++++------------- 2 files changed, 8 insertions(+), 17 deletions(-) diff --git a/platform/lang-impl/src/com/intellij/codeInspection/ui/InspectionResultsView.java b/platform/lang-impl/src/com/intellij/codeInspection/ui/InspectionResultsView.java index dafc108e254f..e8755c2f07b4 100644 --- a/platform/lang-impl/src/com/intellij/codeInspection/ui/InspectionResultsView.java +++ b/platform/lang-impl/src/com/intellij/codeInspection/ui/InspectionResultsView.java @@ -428,10 +428,10 @@ public class InspectionResultsView extends JPanel implements Disposable, Occuren private void addTool(InspectionTool tool, HighlightDisplayLevel errorLevel, boolean groupedBySeverity) { final InspectionTreeNode parentNode = getToolParentNode(tool.getGroupDisplayName().length() > 0 ? tool.getGroupDisplayName() : InspectionProfileEntry.GENERAL_GROUP_NAME, errorLevel, groupedBySeverity); tool.createToolNode(myProvider, parentNode, myGlobalInspectionContext.getUIOptions().SHOW_STRUCTURE); - regsisterActionShortcuts(tool); + registerActionShortcuts(tool); } - private void regsisterActionShortcuts(InspectionTool tool) { + private void registerActionShortcuts(InspectionTool tool) { final QuickFixAction[] fixes = tool.getQuickFixes(null); if (fixes != null) { for (QuickFixAction fix : fixes) { @@ -465,8 +465,7 @@ public class InspectionResultsView extends JPanel implements Disposable, Occuren } clearTree(); boolean resultsFound = buildTree(); - myTree.sort(); - myTree.restoreExpantionAndSelection(); + myTree.restoreExpansionAndSelection(); return resultsFound; } diff --git a/platform/lang-impl/src/com/intellij/codeInspection/ui/InspectionTree.java b/platform/lang-impl/src/com/intellij/codeInspection/ui/InspectionTree.java index 870b6e6aa849..46a111d42af5 100644 --- a/platform/lang-impl/src/com/intellij/codeInspection/ui/InspectionTree.java +++ b/platform/lang-impl/src/com/intellij/codeInspection/ui/InspectionTree.java @@ -212,26 +212,22 @@ public class InspectionTree extends Tree { } } - public void restoreExpantionAndSelection() { - restoreExpantion(); + public void restoreExpansionAndSelection() { + restoreExpansionStatus((InspectionTreeNode)getModel().getRoot()); if (mySelectionPath != null) { mySelectionPath.restore(); } } - private void restoreExpantion() { - restoreExpantionStatus((InspectionTreeNode)getModel().getRoot()); - } - - - private void restoreExpantionStatus(InspectionTreeNode node) { + private void restoreExpansionStatus(InspectionTreeNode node) { if (myExpandedUserObjects.contains(node.getUserObject())) { + sortChildren(node); TreeNode[] pathToNode = node.getPath(); expandPath(new TreePath(pathToNode)); Enumeration children = node.children(); while (children.hasMoreElements()) { InspectionTreeNode childNode = (InspectionTreeNode)children.nextElement(); - restoreExpantionStatus(childNode); + restoreExpansionStatus(childNode); } } } @@ -300,10 +296,6 @@ public class InspectionTree extends Tree { } } - public void sort() { - sortChildren(getRoot()); - } - private static void sortChildren(InspectionTreeNode node) { final List children = TreeUtil.childrenToArray(node); Collections.sort(children, InspectionResultsViewComparator.getInstance()); From 908a7adf2815fa507b091f4d4dfba9ac18943092 Mon Sep 17 00:00:00 2001 From: Bas Leijdekkers Date: Wed, 9 Mar 2011 13:39:34 +0100 Subject: [PATCH 4/5] cache line number because it is expensive to calculate and is used for sorting the inspection results tree --- .../ex/ProblemDescriptorImpl.java | 26 +++++++++++-------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/platform/lang-impl/src/com/intellij/codeInspection/ex/ProblemDescriptorImpl.java b/platform/lang-impl/src/com/intellij/codeInspection/ex/ProblemDescriptorImpl.java index d558064fdc00..cbb5a9709b0c 100644 --- a/platform/lang-impl/src/com/intellij/codeInspection/ex/ProblemDescriptorImpl.java +++ b/platform/lang-impl/src/com/intellij/codeInspection/ex/ProblemDescriptorImpl.java @@ -49,6 +49,7 @@ public class ProblemDescriptorImpl extends CommonProblemDescriptorImpl implement private final boolean myShowTooltip; private final HintAction myHintAction; private TextAttributesKey myEnforcedTextAttributes; + private int myLineNumber = -1; public ProblemDescriptorImpl(@NotNull PsiElement startElement, @NotNull PsiElement endElement, String descriptionTemplate, LocalQuickFix[] fixes, ProblemHighlightType highlightType, @@ -132,17 +133,20 @@ public class ProblemDescriptorImpl extends CommonProblemDescriptorImpl implement } public int getLineNumber() { - PsiElement psiElement = getPsiElement(); - if (psiElement == null) return -1; - if (!psiElement.isValid()) return -1; - LOG.assertTrue(psiElement.isPhysical()); - PsiFile containingFile = InjectedLanguageUtil.getTopLevelFile(psiElement); - Document document = PsiDocumentManager.getInstance(psiElement.getProject()).getDocument(containingFile); - if (document == null) return -1; - TextRange textRange = getTextRange(); - if (textRange == null) return -1; - textRange = InjectedLanguageManager.getInstance(containingFile.getProject()).injectedToHost(psiElement, textRange); - return document.getLineNumber(textRange.getStartOffset()) + 1; + if (myLineNumber == -1) { + PsiElement psiElement = getPsiElement(); + if (psiElement == null) return -1; + if (!psiElement.isValid()) return -1; + LOG.assertTrue(psiElement.isPhysical()); + PsiFile containingFile = InjectedLanguageUtil.getTopLevelFile(psiElement); + Document document = PsiDocumentManager.getInstance(psiElement.getProject()).getDocument(containingFile); + if (document == null) return -1; + TextRange textRange = getTextRange(); + if (textRange == null) return -1; + textRange = InjectedLanguageManager.getInstance(containingFile.getProject()).injectedToHost(psiElement, textRange); + myLineNumber = document.getLineNumber(textRange.getStartOffset()) + 1; + } + return myLineNumber; } public ProblemHighlightType getHighlightType() { From f064ec8d8452fa8e8d4f81037b5af6a5407b74d4 Mon Sep 17 00:00:00 2001 From: Bas Leijdekkers Date: Wed, 9 Mar 2011 13:42:27 +0100 Subject: [PATCH 5/5] compare element name before line number to get consistent results for files containing multiple classes --- .../ui/InspectionResultsViewComparator.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/platform/lang-impl/src/com/intellij/codeInspection/ui/InspectionResultsViewComparator.java b/platform/lang-impl/src/com/intellij/codeInspection/ui/InspectionResultsViewComparator.java index fd143315a1ab..826ed7730b8e 100644 --- a/platform/lang-impl/src/com/intellij/codeInspection/ui/InspectionResultsViewComparator.java +++ b/platform/lang-impl/src/com/intellij/codeInspection/ui/InspectionResultsViewComparator.java @@ -127,10 +127,14 @@ public class InspectionResultsViewComparator implements Comparator { } private static int compareEntities(final RefEntity entity1, final RefEntity entity2) { + if (entity1 != null && entity2 != null) { + final int nameComparison = entity1.getName().compareToIgnoreCase(entity2.getName()); + if (nameComparison != 0) { + return nameComparison; + } + } if (entity1 instanceof RefElement && entity2 instanceof RefElement) { return PsiUtilBase.compareElementsByPosition(((RefElement)entity1).getElement(), ((RefElement)entity2).getElement()); - } else if (entity1 != null && entity2 != null) { - return entity1.getName().compareToIgnoreCase(entity2.getName()); } return 0; }