From 32133c0ad1c71ecd68b2a9b961912ff30bdc20a9 Mon Sep 17 00:00:00 2001 From: Alexey Kudravtsev Date: Fri, 20 Dec 2013 13:52:57 +0400 Subject: [PATCH] IDEA-118096 Documentation popup not usable because of Jetbrains annotations --- .../api/impls/MethodParameterInfoHandler.java | 29 +++++---- .../codeInsight/ParameterInfoTest.java | 61 ++++++++++++++---- java/mockJDK-1.7/jre/lib/annotations.jar | Bin 22252 -> 22215 bytes .../org/intellij/lang/annotations/Flow.java | 1 - 4 files changed, 67 insertions(+), 24 deletions(-) diff --git a/java/java-impl/src/com/intellij/codeInsight/hint/api/impls/MethodParameterInfoHandler.java b/java/java-impl/src/com/intellij/codeInsight/hint/api/impls/MethodParameterInfoHandler.java index 427383c9007f..5da27d9c18d3 100644 --- a/java/java-impl/src/com/intellij/codeInsight/hint/api/impls/MethodParameterInfoHandler.java +++ b/java/java-impl/src/com/intellij/codeInsight/hint/api/impls/MethodParameterInfoHandler.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2013 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. @@ -78,13 +78,13 @@ public class MethodParameterInfoHandler implements ParameterInfoHandlerWithTabAc @Override @Nullable - public PsiExpressionList findElementForParameterInfo(final CreateParameterInfoContext context) { + public PsiExpressionList findElementForParameterInfo(@NotNull final CreateParameterInfoContext context) { PsiExpressionList argumentList = findArgumentList(context.getFile(), context.getOffset(), context.getParameterListStart()); if (argumentList != null) { return findMethodsForArgumentList(context, argumentList); } - return argumentList; + return null; } private PsiExpressionList findArgumentList(final PsiFile file, int offset, int parameterStart) { @@ -112,17 +112,17 @@ public class MethodParameterInfoHandler implements ParameterInfoHandlerWithTabAc } @Override - public void showParameterInfo(@NotNull final PsiExpressionList element, final CreateParameterInfoContext context) { + public void showParameterInfo(@NotNull final PsiExpressionList element, @NotNull final CreateParameterInfoContext context) { context.showHint(element, element.getTextRange().getStartOffset(), this); } @Override - public PsiExpressionList findElementForUpdatingParameterInfo(final UpdateParameterInfoContext context) { + public PsiExpressionList findElementForUpdatingParameterInfo(@NotNull final UpdateParameterInfoContext context) { return findArgumentList(context.getFile(), context.getOffset(), context.getParameterListStart()); } @Override - public void updateParameterInfo(@NotNull final PsiExpressionList o, final UpdateParameterInfoContext context) { + public void updateParameterInfo(@NotNull final PsiExpressionList o, @NotNull final UpdateParameterInfoContext context) { PsiElement parameterOwner = context.getParameterOwner(); if (parameterOwner != o) { context.removeHint(); @@ -357,7 +357,8 @@ public class MethodParameterInfoHandler implements ParameterInfoHandlerWithTabAc } } - public static String updateMethodPresentation(PsiMethod method, @Nullable PsiSubstitutor substitutor, ParameterInfoUIContext context) { + @NotNull + public static String updateMethodPresentation(@NotNull PsiMethod method, @Nullable PsiSubstitutor substitutor, @NotNull ParameterInfoUIContext context) { CodeInsightSettings settings = CodeInsightSettings.getInstance(); if (!method.isValid() || substitutor != null && !substitutor.isValid()) { @@ -444,16 +445,20 @@ public class MethodParameterInfoHandler implements ParameterInfoHandlerWithTabAc private static void appendModifierList(@NotNull StringBuilder buffer, @NotNull PsiModifierListOwner owner) { int lastSize = buffer.length(); - for (PsiAnnotation a : AnnotationUtil.getAllAnnotations(owner, false, null)) { - if (lastSize != buffer.length()) buffer.append(" "); - final PsiJavaCodeReferenceElement element = a.getNameReferenceElement(); - if (element != null) buffer.append("@").append(element.getReferenceName()); + for (PsiAnnotation annotation : AnnotationUtil.getAllAnnotations(owner, false, null)) { + final PsiJavaCodeReferenceElement element = annotation.getNameReferenceElement(); + if (element != null) { + final PsiElement resolved = element.resolve(); + if (resolved instanceof PsiClass && !AnnotationUtil.isAnnotated((PsiClass)resolved, "java.lang.annotation.Documented", false)) continue; + if (lastSize != buffer.length()) buffer.append(" "); + buffer.append("@").append(element.getReferenceName()); + } } if (lastSize != buffer.length()) buffer.append(" "); } @Override - public void updateUI(final Object p, final ParameterInfoUIContext context) { + public void updateUI(final Object p, @NotNull final ParameterInfoUIContext context) { if (p instanceof CandidateInfo) { CandidateInfo info = (CandidateInfo)p; PsiMethod method = (PsiMethod)info.getElement(); diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/ParameterInfoTest.java b/java/java-tests/testSrc/com/intellij/codeInsight/ParameterInfoTest.java index 2c757c1725b9..83c54f94a390 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/ParameterInfoTest.java +++ b/java/java-tests/testSrc/com/intellij/codeInsight/ParameterInfoTest.java @@ -1,3 +1,18 @@ +/* + * Copyright 2000-2013 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.codeInsight; import com.intellij.codeInsight.hint.ParameterInfoComponent; @@ -8,21 +23,29 @@ import com.intellij.lang.parameterInfo.ParameterInfoUIContextEx; import com.intellij.openapi.util.text.StringUtil; import com.intellij.psi.*; import com.intellij.psi.infos.MethodCandidateInfo; +import com.intellij.psi.util.PsiTreeUtil; import com.intellij.testFramework.LightCodeInsightTestCase; import com.intellij.testFramework.utils.parameterInfo.MockCreateParameterInfoContext; +import com.intellij.testFramework.utils.parameterInfo.MockParameterInfoUIContext; import com.intellij.testFramework.utils.parameterInfo.MockUpdateParameterInfoContext; -import com.intellij.util.ArrayUtil; import com.intellij.util.ArrayUtilRt; import com.intellij.util.Function; import junit.framework.Assert; +import java.io.IOException; + public class ParameterInfoTest extends LightCodeInsightTestCase { private static final String BASE_PATH = "/codeInsight/parameterInfo/"; - private Object[] doTest(String paramsList) throws Exception { + private void doTest(String paramsList) throws Exception { configureByFile(BASE_PATH + getTestName(false) + ".java"); + String joined = invokeParameterInfo(); + assertEquals(paramsList, joined); + } + + private static String invokeParameterInfo() { final MethodParameterInfoHandler handler = new MethodParameterInfoHandler(); final CreateParameterInfoContext context = new MockCreateParameterInfoContext(myEditor, myFile); final PsiExpressionList list = handler.findElementForParameterInfo(context); @@ -31,14 +54,12 @@ public class ParameterInfoTest extends LightCodeInsightTestCase { assertTrue(context.getItemsToShow().length > 0); Object[] params = handler.getParametersForDocumentation(context.getItemsToShow()[0], context); assertNotNull(params); - String joined = StringUtil.join(params, new Function() { + return StringUtil.join(params, new Function() { @Override public String fun(Object o) { return ((PsiParameter)o).getName(); } }, ","); - assertEquals(paramsList, joined); - return params; } public void testPrivateMethodOfEnclosingClass() throws Exception { @@ -49,6 +70,20 @@ public class ParameterInfoTest extends LightCodeInsightTestCase { doTest("param"); } + public void testParameterInfoDoesNotShowInternalJetbrainsAnnotations() throws IOException { + configureFromFileText("x.java", "class X { void f(@org.intellij.lang.annotations.Flow int i) { f(0); }}"); + + final CreateParameterInfoContext context = new MockCreateParameterInfoContext(myEditor, myFile); + + PsiMethod method = PsiTreeUtil.getParentOfType(myFile.findElementAt(context.getOffset()), PsiMethod.class); + final String list = MethodParameterInfoHandler.updateMethodPresentation(method, PsiSubstitutor.EMPTY, new MockParameterInfoUIContext(method)); + + assertEquals("int i", list); + + PsiAnnotation[] annotations = AnnotationUtil.getAllAnnotations(method.getParameterList().getParameters()[0], false, null); + assertEquals(1, annotations.length); + } + public void testNoParams() throws Exception { doTestPresentation("<no parameters>"); } @@ -66,7 +101,7 @@ public class ParameterInfoTest extends LightCodeInsightTestCase { assertNotNull(list); final Object[] itemsToShow = context.getItemsToShow(); assertNotNull(itemsToShow); - assertTrue(itemsToShow.length == 2); + assertEquals(2, itemsToShow.length); assertTrue(itemsToShow[0] instanceof MethodCandidateInfo); final ParameterInfoUIContextEx parameterContext = ParameterInfoComponent.createContext(itemsToShow, myEditor, handler, -1); final Boolean [] enabled = new Boolean[itemsToShow.length]; @@ -95,7 +130,7 @@ public class ParameterInfoTest extends LightCodeInsightTestCase { assertNotNull(list); final Object[] itemsToShow = context.getItemsToShow(); assertNotNull(itemsToShow); - assertTrue(itemsToShow.length == 2); + assertEquals(2, itemsToShow.length); assertTrue(itemsToShow[0] instanceof MethodCandidateInfo); final PsiMethod method = ((MethodCandidateInfo)itemsToShow[0]).getElement(); final ParameterInfoUIContextEx parameterContext = ParameterInfoComponent.createContext(itemsToShow, myEditor, handler, 1); @@ -118,7 +153,7 @@ public class ParameterInfoTest extends LightCodeInsightTestCase { assertNotNull(list); final Object[] itemsToShow = context.getItemsToShow(); assertNotNull(itemsToShow); - assertTrue(itemsToShow.length == 1); + assertEquals(1, itemsToShow.length); assertTrue(itemsToShow[0] instanceof MethodCandidateInfo); final PsiMethod method = ((MethodCandidateInfo)itemsToShow[0]).getElement(); final ParameterInfoUIContextEx parameterContext = ParameterInfoComponent.createContext(itemsToShow, myEditor, handler, -1); @@ -134,17 +169,21 @@ public class ParameterInfoTest extends LightCodeInsightTestCase { private void doTestAnnotationPresentation(String expectedString) { configureByFile(BASE_PATH + getTestName(false) + ".java"); + String text = invokeParameterInfoForAnnotations(); + Assert.assertEquals(expectedString, text); + } + + private static String invokeParameterInfoForAnnotations() { final AnnotationParameterInfoHandler handler = new AnnotationParameterInfoHandler(); final CreateParameterInfoContext context = new MockCreateParameterInfoContext(myEditor, myFile); final PsiAnnotationParameterList list = handler.findElementForParameterInfo(context); assertNotNull(list); final Object[] itemsToShow = context.getItemsToShow(); assertNotNull(itemsToShow); - assertTrue(itemsToShow.length == 1); + assertEquals(1, itemsToShow.length); assertTrue(itemsToShow[0] instanceof PsiAnnotationMethod); final PsiAnnotationMethod method = (PsiAnnotationMethod)itemsToShow[0]; final ParameterInfoUIContextEx parameterContext = ParameterInfoComponent.createContext(itemsToShow, myEditor, handler, -1); - Assert.assertEquals(expectedString, - AnnotationParameterInfoHandler.updateUIText(method, parameterContext)); + return AnnotationParameterInfoHandler.updateUIText(method, parameterContext); } } diff --git a/java/mockJDK-1.7/jre/lib/annotations.jar b/java/m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q?3=l#FlFj|%hYUzqty*O)Xkq7Aemno-9%Ujr6os3A40H@}~Z#rzE)2@=eOSc|_V;LR7@X z_AVe2aUURsq=*!AxrfjLq=c06pEAWzsXOX1iI0)mr#UUeO7@FF9Mq-7g8r}|(VSC4 zd}}-;M3X5^zBG?WCVmce>t|jnmI&d|%*L;R8y$A|Oj8fHt$%2E#xIGQNtm{8hc}D$ zDMMa`=u~feS%^>VLqb$K-jT3iuyQU4HI7iqkRKCE`gz%`tgS}I&gYyXk?C@o$F8aT~y3}Cp_o6VmT_^E3lX@o5 zE6CM`S|OHpGzwAC^qdfH1qXy!4JCw#?bcEi^A7B74Jge67hAXS5n;Ynw%yElMWR-f za2#LLhh^y=c*6N^er6eKF=5W!3t*O+*~8P-mb?p-g);yvYd6}(W2=1 zlnIm9S&uU&HLSIZfwdhnT{Pp;s3iyXcbL(x{0jhgJdZwWWos>PJTCfk-#@~7^JrA` zU)X|8*!KX9on{_D^} z)5B4R#Ttt$92UaQ${)+43vxQoi=}d$y&fl`vrZcyAMqOuueliZfvZ3b^J%=qu&#_@ zH^k~RP~9cwpPMsY_=*z3<59)@|9CL@L{|Ym=({`jEI!SWcz6|wb{`scvCEG8uXV}v zS~Wvn2qnZOiZ5DGJLqSL0hmmP*{>&Lda@SxeUPxDf5P95y?u+-@TgGK_JhAWfc`(+ zEz_X@`u|e51E-i_Xtsf&Qs2h&eC^7QPpq@o#iLBoQEFrbPI$j;^VaJA=lh0-HG>XU2-7_>{V0g&deFeFi&L3;Wom9=I3FUtPDFzY9omiP>nAmE Mxi?Qe+{#=33mnefF#rGn diff --git a/platform/annotations/src/org/intellij/lang/annotations/Flow.java b/platform/annotations/src/org/intellij/lang/annotations/Flow.java index b52ae79d39c2..a6ea57837336 100644 --- a/platform/annotations/src/org/intellij/lang/annotations/Flow.java +++ b/platform/annotations/src/org/intellij/lang/annotations/Flow.java @@ -19,7 +19,6 @@ import org.jetbrains.annotations.NonNls; import java.lang.annotation.*; -@Documented @Retention(RetentionPolicy.CLASS) @Target({ElementType.PARAMETER, ElementType.METHOD}) /**