From 49caa2b777cb846fbc021cf154f991cf5b6d4f54 Mon Sep 17 00:00:00 2001 From: Lada Gagina Date: Mon, 25 Jul 2016 22:06:59 +0300 Subject: [PATCH] PY-19927 Add highlighting to __setstate__ and __sizeof__ magic methods --- .../psi-api/src/com/jetbrains/python/PyNames.java | 2 ++ python/testData/highlighting/magicMethods.py | 6 ++++++ .../jetbrains/python/PythonHighlightingTest.java | 14 ++++++++++++++ 3 files changed, 22 insertions(+) create mode 100644 python/testData/highlighting/magicMethods.py diff --git a/python/psi-api/src/com/jetbrains/python/PyNames.java b/python/psi-api/src/com/jetbrains/python/PyNames.java index 97244d9e285c..25bf044e8796 100644 --- a/python/psi-api/src/com/jetbrains/python/PyNames.java +++ b/python/psi-api/src/com/jetbrains/python/PyNames.java @@ -388,6 +388,8 @@ public class PyNames { .put("__setattr__", new BuiltinDescription("(self, key, value)")) .put("__setitem__", new BuiltinDescription("(self, key, value)")) .put("__setslice__", new BuiltinDescription("(self, i, j, sequence)")) + .put("__setstate__", new BuiltinDescription("(self, state)")) + .put(SIZEOF, _only_self_descr) //_BuiltinMethods.put("__self__", _only_self_descr); //_BuiltinMethods.put("__slots__", _only_self_descr); .put("__str__", _only_self_descr) diff --git a/python/testData/highlighting/magicMethods.py b/python/testData/highlighting/magicMethods.py new file mode 100644 index 000000000000..979ab59e1569 --- /dev/null +++ b/python/testData/highlighting/magicMethods.py @@ -0,0 +1,6 @@ +class A(): + def __sizeof__(self): + pass + + def __setstate__(self, state): + pass \ No newline at end of file diff --git a/python/testSrc/com/jetbrains/python/PythonHighlightingTest.java b/python/testSrc/com/jetbrains/python/PythonHighlightingTest.java index 634bc91823a7..d60bd137c288 100644 --- a/python/testSrc/com/jetbrains/python/PythonHighlightingTest.java +++ b/python/testSrc/com/jetbrains/python/PythonHighlightingTest.java @@ -266,6 +266,20 @@ public class PythonHighlightingTest extends PyTestCase { doTest(LanguageLevel.PYTHON35, false, false); } + // PY-19927 + public void testMagicMethods() { + EditorColorsManager manager = EditorColorsManager.getInstance(); + EditorColorsScheme scheme = (EditorColorsScheme)manager.getGlobalScheme().clone(); + manager.addColorsScheme(scheme); + EditorColorsManager.getInstance().setGlobalScheme(scheme); + + TextAttributesKey xKey = TextAttributesKey.find("PY.PREDEFINED_DEFINITION"); + TextAttributes xAttributes = new TextAttributes(Color.green, Color.black, Color.white, EffectType.BOXED, Font.BOLD); + scheme.setAttributes(xKey, xAttributes); + + doTest(); + } + // PY-19775 public void testAsyncBuiltinMethods() { doTest(LanguageLevel.PYTHON35, true, false);