mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
fixed PY-6548 @type in class docstrings does not recognize class variables
This commit is contained in:
@@ -40,6 +40,16 @@ public class DocStringParameterReference extends PsiReferenceBase<PsiElement> {
|
||||
if (init != null) {
|
||||
return resolveParameter(init);
|
||||
}
|
||||
else {
|
||||
final PyStatementList statementList = ((PyClass)owner).getStatementList();
|
||||
for (PsiElement element : statementList.getChildren()) {
|
||||
if (element instanceof PyAssignmentStatement) {
|
||||
final PyExpression[] targets = ((PyAssignmentStatement)element).getTargets();
|
||||
if (targets.length > 0 && targets[0].getText().equals(getCanonicalText()))
|
||||
return targets[0];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -47,6 +47,9 @@ public class DocStringReferenceProvider extends PsiReferenceProvider {
|
||||
docString.getTagArguments(StructuredDocString.PARAM_TYPE_TAGS), "parameter_type"));
|
||||
result.addAll(referencesFromNames(element, offset, docString,
|
||||
docString.getKeywordArgumentSubstrings(), "keyword"));
|
||||
|
||||
result.addAll(referencesFromNames(element, offset, docString,
|
||||
docString.getTagArguments(StructuredDocString.VARIABLE_TAGS), "variable"));
|
||||
}
|
||||
return result.toArray(new PsiReference[result.size()]);
|
||||
}
|
||||
|
||||
@@ -11,12 +11,9 @@ import java.util.*;
|
||||
* @author yole
|
||||
*/
|
||||
public class EpydocString extends StructuredDocString {
|
||||
public static String[] RAISES_TAGS = new String[] { "raises", "raise", "except", "exception" };
|
||||
|
||||
public static String[] RETURN_TAGS = new String[] { "return", "returns" };
|
||||
public static String[] RTYPE_TAGS = new String[] { "rtype", "returntype" };
|
||||
public static String[] KEYWORD_ARGUMENT_TAGS = new String[] { "keyword", "kwarg", "kwparam" };
|
||||
public static String[] VARIABLE_TAGS = new String[] { "ivar", "cvar", "var" };
|
||||
|
||||
public static String[] ALL_TAGS = new String[] {
|
||||
"@param", "@type", "@return", "@rtype", "@keyword", "@raise", "@ivar", "@cvar", "@var", "@group", "@sort", "@note", "@attention",
|
||||
|
||||
@@ -61,12 +61,12 @@ public class SphinxDocString extends StructuredDocString {
|
||||
|
||||
@Override
|
||||
public String getReturnDescription() {
|
||||
return concatTrimmedLines(getTagValue(EpydocString.RETURN_TAGS));
|
||||
return concatTrimmedLines(getTagValue(RETURN_TAGS));
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getRaisedExceptions() {
|
||||
return toUniqueStrings(getTagArguments(EpydocString.RAISES_TAGS));
|
||||
return toUniqueStrings(getTagArguments(RAISES_TAGS));
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@@ -75,12 +75,12 @@ public class SphinxDocString extends StructuredDocString {
|
||||
if (exceptionName == null) {
|
||||
return null;
|
||||
}
|
||||
return concatTrimmedLines(getTagValue(EpydocString.RAISES_TAGS, exceptionName));
|
||||
return concatTrimmedLines(getTagValue(RAISES_TAGS, exceptionName));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getAttributeDescription() {
|
||||
return concatTrimmedLines(getTagValue(EpydocString.VARIABLE_TAGS));
|
||||
return concatTrimmedLines(getTagValue(VARIABLE_TAGS));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -27,6 +27,10 @@ public abstract class StructuredDocString {
|
||||
|
||||
public static String[] PARAM_TAGS = new String[] { "param", "parameter", "arg", "argument" };
|
||||
public static String[] PARAM_TYPE_TAGS = new String[] { "type" };
|
||||
public static String[] VARIABLE_TAGS = new String[] { "ivar", "cvar", "var" };
|
||||
|
||||
public static String[] RAISES_TAGS = new String[] { "raises", "raise", "except", "exception" };
|
||||
public static String[] RETURN_TAGS = new String[] { "return", "returns" };
|
||||
|
||||
@Nullable
|
||||
public static StructuredDocString parse(String text) {
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
class Test(object):
|
||||
"""
|
||||
@cvar some: some variable
|
||||
@type some: C{str}
|
||||
"""
|
||||
some = 'hello'
|
||||
|
||||
def q(self, another):
|
||||
"""
|
||||
@param another: another variable
|
||||
@type another: C{str}
|
||||
"""
|
||||
pass
|
||||
+5
@@ -116,6 +116,11 @@ public class PyUnresolvedReferencesInspectionTest extends PyTestCase {
|
||||
doMultiFileTest("a.py");
|
||||
}
|
||||
|
||||
// PY-6548
|
||||
public void testDocstring() {
|
||||
doTest();
|
||||
}
|
||||
|
||||
private void doTest() {
|
||||
myFixture.configureByFile(TEST_DIRECTORY + getTestName(true) + ".py");
|
||||
myFixture.enableInspections(PyUnresolvedReferencesInspection.class);
|
||||
|
||||
Reference in New Issue
Block a user