From 049f3bd8fd3df4a2d943babacd1aabeaba399783 Mon Sep 17 00:00:00 2001 From: Max Medvedev Date: Wed, 5 Dec 2012 11:53:17 +0400 Subject: [PATCH] Groovy: Quick info for methods. Use links for parameter types --- .../GroovyDocumentationProvider.java | 4 +-- .../documentation/GroovyPresentationUtil.java | 26 ++++++++++++------- .../lang/documentation/TypePresentation.java | 23 ++++++++++++++++ .../GroovyParameterInfoHandler.java | 5 ++-- .../groovy/GroovyDocumentationTest.groovy | 10 ++++--- 5 files changed, 50 insertions(+), 18 deletions(-) create mode 100644 plugins/groovy/src/org/jetbrains/plugins/groovy/lang/documentation/TypePresentation.java diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/documentation/GroovyDocumentationProvider.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/documentation/GroovyDocumentationProvider.java index 4d3e6155fd3a..f05f39e2e14f 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/documentation/GroovyDocumentationProvider.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/documentation/GroovyDocumentationProvider.java @@ -153,7 +153,7 @@ public class GroovyDocumentationProvider implements CodeDocumentationProvider, E PsiParameter parameter = parameters[i]; if (i > 0) buffer.append(", "); if (parameter instanceof GrParameter) { - GroovyPresentationUtil.appendParameterPresentation((GrParameter)parameter, substitutor, false, buffer); + GroovyPresentationUtil.appendParameterPresentation((GrParameter)parameter, substitutor, TypePresentation.LINK, buffer); } else { PsiType type = parameter.getType(); @@ -311,7 +311,7 @@ public class GroovyDocumentationProvider implements CodeDocumentationProvider, E } - private static void appendTypeString(StringBuilder buffer, final PsiType type, PsiElement context) { + public static void appendTypeString(StringBuilder buffer, final PsiType type, PsiElement context) { if (type != null) { JavaDocInfoGenerator.generateType(buffer, type, context); } diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/documentation/GroovyPresentationUtil.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/documentation/GroovyPresentationUtil.java index a2a4ce404eea..a88b2e6771de 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/documentation/GroovyPresentationUtil.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/documentation/GroovyPresentationUtil.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2012 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. @@ -35,24 +35,30 @@ import java.util.Set; public class GroovyPresentationUtil { private static final int CONSTRAINTS_NUMBER = 2; - public static String getParameterPresentation(GrParameter parameter, PsiSubstitutor substitutor, boolean presentable) { - StringBuilder builder = new StringBuilder(); - appendParameterPresentation(parameter, substitutor, presentable, builder); - return builder.toString(); - } - public static void appendParameterPresentation(GrParameter parameter, PsiSubstitutor substitutor, - boolean presentable, + TypePresentation typePresentation, StringBuilder builder) { for (PsiAnnotation annotation : parameter.getModifierList().getAnnotations()) { builder.append(annotation.getText()).append(' '); } PsiType type = parameter.getTypeGroovy(); + type = substitutor.substitute(type); + + if (typePresentation == TypePresentation.LINK) { + GroovyDocumentationProvider.appendTypeString(builder, type, parameter); + builder.append(' ').append(parameter.getName()); + return; + } + if (type != null) { - type = substitutor.substitute(type); - builder.append(presentable ? type.getPresentableText() : type.getCanonicalText()).append(' ').append(parameter.getName()); + if (typePresentation == TypePresentation.PRESENTABLE) { + builder.append(type.getPresentableText()).append(' ').append(parameter.getName()); + } + else if (typePresentation == TypePresentation.CANONICAL) { + builder.append(type.getCanonicalText()).append(' ').append(parameter.getName()); + } } else { builder.append(parameter.getName()); diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/documentation/TypePresentation.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/documentation/TypePresentation.java new file mode 100644 index 000000000000..200752d6fec8 --- /dev/null +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/documentation/TypePresentation.java @@ -0,0 +1,23 @@ +/* + * Copyright 2000-2012 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 org.jetbrains.plugins.groovy.lang.documentation; + +/** +* @author Max Medvedev +*/ +public enum TypePresentation { + PRESENTABLE, CANONICAL, LINK +} diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/parameterInfo/GroovyParameterInfoHandler.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/parameterInfo/GroovyParameterInfoHandler.java index c9ded2b037c3..f10937a54f54 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/parameterInfo/GroovyParameterInfoHandler.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/parameterInfo/GroovyParameterInfoHandler.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2012 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. @@ -29,6 +29,7 @@ import com.intellij.util.text.CharArrayUtil; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.jetbrains.plugins.groovy.lang.documentation.GroovyPresentationUtil; +import org.jetbrains.plugins.groovy.lang.documentation.TypePresentation; import org.jetbrains.plugins.groovy.lang.lexer.GroovyTokenTypes; import org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElement; import org.jetbrains.plugins.groovy.lang.psi.api.GroovyResolveResult; @@ -447,7 +448,7 @@ public class GroovyParameterInfoHandler implements ParameterInfoHandlerWithTabAc private static void appendParameterText(PsiParameter param, PsiSubstitutor substitutor, StringBuilder buffer) { if (param instanceof GrParameter) { GrParameter grParam = (GrParameter)param; - GroovyPresentationUtil.appendParameterPresentation(grParam, substitutor, true, buffer); + GroovyPresentationUtil.appendParameterPresentation(grParam, substitutor, TypePresentation.PRESENTABLE, buffer); final GrExpression initializer = grParam.getInitializerGroovy(); if (initializer != null) { diff --git a/plugins/groovy/test/org/jetbrains/plugins/groovy/GroovyDocumentationTest.groovy b/plugins/groovy/test/org/jetbrains/plugins/groovy/GroovyDocumentationTest.groovy index cfd1370e4c3e..1efe53603626 100644 --- a/plugins/groovy/test/org/jetbrains/plugins/groovy/GroovyDocumentationTest.groovy +++ b/plugins/groovy/test/org/jetbrains/plugins/groovy/GroovyDocumentationTest.groovy @@ -29,8 +29,9 @@ class Bar { java.util.List foo(T param); } new Bar().foo(); ''' def ref = myFixture.file.findReferenceAt(myFixture.editor.caretModel.offset) - assert CtrlMouseHandler.getInfo(ref.resolve(), ref.element) == """Bar -java.util.List<java.lang.String> foo (java.lang.String param)""" + assert CtrlMouseHandler.getInfo(ref.resolve(), ref.element) == """\ +Bar +List<String> foo (String param)""" } public void testGenericField() { @@ -39,8 +40,9 @@ class Bar { T field; } new Bar().field ''' def ref = myFixture.file.findReferenceAt(myFixture.editor.caretModel.offset) - assert CtrlMouseHandler.getInfo(ref.resolve(), ref.element) == """Bar -java.lang.Integer getField ()""" + assert CtrlMouseHandler.getInfo(ref.resolve(), ref.element) == """\ +Bar +Integer getField ()""" } }