[groovy] generate documentation for implicit closure parameters and local variables (IDEA-130679)

This commit is contained in:
Daniil Ovchinnikov
2016-09-12 21:28:59 +03:00
parent 0323e6fc5e
commit bf4082a748
2 changed files with 19 additions and 3 deletions
@@ -311,10 +311,10 @@ public class GroovyDocumentationProvider implements CodeDocumentationProvider, E
if (element == null) return null;
String standard = element.getNavigationElement() instanceof PsiDocCommentOwner ? generateExternalJavaDoc(element) : null;
String standard = generateExternalJavaDoc(element);
if (element instanceof GrVariable &&
((GrVariable)element).getTypeElementGroovy() == null &&
((GrVariable)element).getDeclaredType() == null &&
standard != null) {
final String truncated = StringUtil.trimEnd(standard, BODY_HTML);
@@ -63,11 +63,27 @@ new Gr().fo<caret>o()
Use <a href="psi_element://Gr#bar()"><code>bar()</code></a> from class <a href="psi_element://Gr"><code>Gr</code></a> instead</body></html>'''
}
void 'test untyped local variable'() {
doTest '''\
def aa = 1
a<caret>a
''', '''\
<html><head> <style type="text/css"> #error { background-color: #eeeeee; margin-bottom: 10px; } p { margin: 5px 0; } </style></head><body><PRE><a href="psi_element://java.lang.Object"><code>Object</code></a> <b>aa</b></PRE><p>[inferred type] <a href="psi_element://java.lang.Integer"><code>Integer</code></a></body></html>'''
}
void 'test implicit closure parameter'() {
doTest '''\
List<String> ss = []
ss.collect { i<caret>t }
''', '''\
<html><head> <style type="text/css"> #error { background-color: #eeeeee; margin-bottom: 10px; } p { margin: 5px 0; } </style></head><body><PRE><a href="psi_element://java.lang.Object"><code>Object</code></a> <b>it</b></PRE><p>[inferred type] <a href="psi_element://java.lang.String"><code>String</code></a></body></html>'''
}
private void doTest(String text, String doc) {
myFixture.configureByText '_.groovy', text
def ref = myFixture.file.findReferenceAt(myFixture.editor.caretModel.offset)
def provider = new GroovyDocumentationProvider()
def info = provider.generateDoc(ref.resolve(), ref.element)
assert info == doc
assertEquals(doc, info)
}
}