mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
documentation for gdsl named parameters (IDEA-71141)
This commit is contained in:
@@ -3,6 +3,7 @@ package org.jetbrains.plugins.groovy.dsl;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.impl.FakePsiElement;
|
||||
import com.intellij.psi.scope.PsiScopeProcessor;
|
||||
import com.intellij.psi.search.GlobalSearchScope;
|
||||
import groovy.lang.Closure;
|
||||
@@ -142,7 +143,7 @@ public class CustomMembersGenerator extends GroovyObjectSupport implements GdslM
|
||||
|
||||
@SuppressWarnings("MethodMayBeStatic")
|
||||
public ParameterDescriptor parameter(Map args) {
|
||||
return new ParameterDescriptor(args);
|
||||
return new ParameterDescriptor(args, myDescriptor.justGetPlaceFile());
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@@ -229,10 +230,11 @@ public class CustomMembersGenerator extends GroovyObjectSupport implements GdslM
|
||||
public final String name;
|
||||
public final GroovyNamedArgumentProvider.ArgumentDescriptor descriptor;
|
||||
|
||||
private ParameterDescriptor(Map args) {
|
||||
this.name = (String)args.get("name");
|
||||
private ParameterDescriptor(Map args, PsiElement context) {
|
||||
name = (String)args.get("name");
|
||||
final String typeText = stringifyType(args.get("type"));
|
||||
descriptor = new GroovyNamedArgumentProvider.ArgumentDescriptor() {
|
||||
Object doc = args.get("doc");
|
||||
descriptor = new GroovyNamedArgumentProvider.ArgumentDescriptor(new GdslNamedParameter(name, doc instanceof String ? (String)doc : null, context)) {
|
||||
@Override
|
||||
public boolean checkType(@NotNull PsiType type, @NotNull GroovyPsiElement context) {
|
||||
return typeText == null || ClassContextFilter.isSubtype(type, context.getContainingFile(), typeText);
|
||||
@@ -240,6 +242,29 @@ public class CustomMembersGenerator extends GroovyObjectSupport implements GdslM
|
||||
};
|
||||
descriptor.setShowFirst(true);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static class GdslNamedParameter extends FakePsiElement {
|
||||
private final String myName;
|
||||
public final String docString;
|
||||
private final PsiElement myParent;
|
||||
|
||||
public GdslNamedParameter(String name, String doc, @NotNull PsiElement parent) {
|
||||
myName = name;
|
||||
this.docString = doc;
|
||||
myParent = parent;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PsiElement getParent() {
|
||||
return myParent;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return myName;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+10
-1
@@ -38,6 +38,8 @@ import com.intellij.util.StringBuilderSpinAllocator;
|
||||
import com.intellij.util.containers.HashMap;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.plugins.groovy.dsl.CustomMembersGenerator;
|
||||
import org.jetbrains.plugins.groovy.extensions.GroovyNamedArgumentProvider;
|
||||
import org.jetbrains.plugins.groovy.lang.groovydoc.psi.api.GrDocComment;
|
||||
import org.jetbrains.plugins.groovy.lang.groovydoc.psi.api.GrDocCommentOwner;
|
||||
import org.jetbrains.plugins.groovy.lang.groovydoc.psi.impl.GrDocCommentUtil;
|
||||
@@ -296,6 +298,10 @@ public class GroovyDocumentationProvider implements CodeDocumentationProvider, E
|
||||
|
||||
@Nullable
|
||||
public String generateDoc(PsiElement element, PsiElement originalElement) {
|
||||
if (element instanceof CustomMembersGenerator.GdslNamedParameter) {
|
||||
return ((CustomMembersGenerator.GdslNamedParameter)element).docString;
|
||||
}
|
||||
|
||||
if (element instanceof GrReferenceExpression) {
|
||||
return getMethodCandidateInfo((GrReferenceExpression)element);
|
||||
}
|
||||
@@ -303,7 +309,7 @@ public class GroovyDocumentationProvider implements CodeDocumentationProvider, E
|
||||
if (element instanceof GrGdkMethod) {
|
||||
element = ((GrGdkMethod)element).getStaticMethod();
|
||||
}
|
||||
|
||||
|
||||
final GrDocComment doc = PsiTreeUtil.getParentOfType(originalElement, GrDocComment.class);
|
||||
if (doc != null) {
|
||||
element = GrDocCommentUtil.findDocOwner(doc);
|
||||
@@ -384,6 +390,9 @@ public class GroovyDocumentationProvider implements CodeDocumentationProvider, E
|
||||
if (object instanceof GroovyResolveResult) {
|
||||
return ((GroovyResolveResult)object).getElement();
|
||||
}
|
||||
if (object instanceof GroovyNamedArgumentProvider.ArgumentDescriptor) {
|
||||
return ((GroovyNamedArgumentProvider.ArgumentDescriptor)object).getNavigationElement();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@@ -28,6 +28,8 @@ import com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase
|
||||
import org.jetbrains.annotations.NotNull
|
||||
import org.jetbrains.plugins.groovy.codeInspection.assignment.GroovyAssignabilityCheckInspection
|
||||
import org.jetbrains.plugins.groovy.util.TestUtils
|
||||
import com.intellij.codeInsight.documentation.DocumentationManager
|
||||
import org.jetbrains.plugins.groovy.lang.documentation.GroovyDocumentationProvider
|
||||
|
||||
/**
|
||||
* @author peter
|
||||
@@ -168,16 +170,18 @@ public class MyCategory {
|
||||
assert myFixture.lookupElementStrings == ['param1', 'param2']
|
||||
}
|
||||
|
||||
public void testNamedParametersGroovyConverntion() {
|
||||
public void testNamedParametersGroovyConvention() {
|
||||
addGdsl '''contribute(currentType(String.name)) {
|
||||
method name:'foo', type:void, params:[args:[
|
||||
parameter(name:'param1', type:String),
|
||||
parameter(name:'param1', type:String, doc:'My doc'),
|
||||
parameter(name:'param2', type:Integer),
|
||||
]]
|
||||
}'''
|
||||
myFixture.configureByText 'a.groovy', '"".foo(par<caret>)'
|
||||
myFixture.completeBasic()
|
||||
assert myFixture.lookupElementStrings == ['param1', 'param2']
|
||||
def element = DocumentationManager.getInstance(project).getElementFromLookup(myFixture.editor, myFixture.file)
|
||||
assert 'My doc' == new GroovyDocumentationProvider().generateDoc(element, null)
|
||||
}
|
||||
|
||||
public void testCheckNamedArgumentTypes() {
|
||||
|
||||
Reference in New Issue
Block a user