Highlight built-in decorators with decorators colors, not not built-in colors (PY-25381)

This commit is contained in:
Elizaveta Shashkova
2017-12-18 18:49:12 +03:00
parent 5fd40e63e8
commit e5b6c6cc09
5 changed files with 26 additions and 16 deletions
@@ -16,8 +16,6 @@
package com.jetbrains.python.validation;
import com.intellij.lang.ASTNode;
import com.intellij.lang.annotation.Annotation;
import com.intellij.psi.PsiElement;
import com.jetbrains.python.PyNames;
import com.jetbrains.python.PyTokenTypes;
import com.jetbrains.python.codeInsight.dataflow.scope.ScopeUtil;
@@ -40,16 +38,8 @@ public class PyBuiltinAnnotator extends PyAnnotator {
if (highlightedAsAttribute) {
return;
}
if (PyBuiltinCache.isInBuiltins(node) || PyUtil.isPy2ReservedWord(node)) {
final Annotation ann;
final PsiElement parent = node.getParent();
if (parent instanceof PyDecorator) {
// don't mark the entire decorator, only mark the "@", else we'll conflict with deco annotator
addHighlightingAnnotation(parent.getFirstChild(), PyHighlighter.PY_BUILTIN_NAME);
}
else {
addHighlightingAnnotation(node, PyHighlighter.PY_BUILTIN_NAME);
}
if ((PyBuiltinCache.isInBuiltins(node) || PyUtil.isPy2ReservedWord(node)) && !(node.getParent() instanceof PyDecorator)) {
addHighlightingAnnotation(node, PyHighlighter.PY_BUILTIN_NAME);
}
}
@@ -40,7 +40,7 @@ public class PyDefinitionsAnnotator extends PyAnnotator {
@Override
public void visitPyFunction(PyFunction node) {
ASTNode name_node = node.getNameNode();
ASTNode name_node = node.getNameNode();
if (name_node != null) {
final String name = node.getName();
LanguageLevel languageLevel = LanguageLevel.forElement(node);
@@ -61,7 +61,9 @@ public class PyDefinitionsAnnotator extends PyAnnotator {
addHighlightingAnnotation(name_node, PyHighlighter.PY_PREDEFINED_DEFINITION);
}
}
else addHighlightingAnnotation(name_node, PyHighlighter.PY_FUNC_DEFINITION);
else {
addHighlightingAnnotation(name_node, PyHighlighter.PY_FUNC_DEFINITION);
}
}
}
@@ -69,7 +71,7 @@ public class PyDefinitionsAnnotator extends PyAnnotator {
public void visitPyDecoratorList(PyDecoratorList node) {
PyDecorator[] decos = node.getDecorators();
for (PyDecorator deco : decos) {
highlightDecorator(deco);
highlightDecorator(deco);
}
}
@@ -0,0 +1,13 @@
<info descr="PY.DECORATOR">@</info> <info descr="PY.DECORATOR">foo</info>
def <info descr="PY.FUNC_DEFINITION">f</info>():
pass
class <info descr="PY.CLASS_DEFINITION">C</info>:
<info descr="PY.DECORATOR">@</info> <info descr="PY.DECORATOR">f</info>
def <info descr="PY.FUNC_DEFINITION">bar</info>(<info descr="PY.SELF_PARAMETER">self</info>):
pass
<info descr="PY.DECORATOR">@</info><info descr="PY.DECORATOR">staticmethod</info>
def <info descr="PY.FUNC_DEFINITION">bar</info>():
pass
+1 -1
View File
@@ -12,7 +12,7 @@ len # no highlight
class <info descr="PY.CLASS_DEFINITION" type="INFORMATION">A</info>(<info descr="PY.BUILTIN_NAME" type="INFORMATION" foreground="0x00ff00" background="0x000000" effectcolor="0xffffff" effecttype="BOXED" fonttype="1">object</info>):
<info descr="PY.PREDEFINED_USAGE" type="INFORMATION" foreground="0xffff00" background="0x000000" effectcolor="0xffffff" effecttype="BOXED" fonttype="1">__metaclass__</info> = M # assignment target
<info descr="PY.BUILTIN_NAME"><info descr="PY.DECORATOR">@</info></info><info descr="PY.DECORATOR">classmethod</info>
<info descr="PY.DECORATOR">@</info><info descr="PY.DECORATOR">classmethod</info>
def <info descr="PY.FUNC_DEFINITION">foo</info>(<info descr="PY.SELF_PARAMETER">cls</info>):
pass
@@ -346,6 +346,11 @@ public class PythonHighlightingTest extends PyTestCase {
doTest(true, true);
}
// PY-25381
public void testBuiltinDecorator() {
doTest(true, true);
}
// PY-11418
public void testFunctionCalls() {
doTest();