Refactor visitName from PythonSemanticHighlighter
authorJulien Enselme <jenselme@netbeans.org>
Sun, 05 Jul 2015 00:01:18 +0200
changeset 18284046ea62c1af4
parent 18283 fed454e84e08
child 18285 b047cef8879f
Refactor visitName from PythonSemanticHighlighter
python.editor/src/org/netbeans/modules/python/editor/PythonSemanticHighlighter.java
     1.1 --- a/python.editor/src/org/netbeans/modules/python/editor/PythonSemanticHighlighter.java	Sat Jul 04 23:40:14 2015 +0200
     1.2 +++ b/python.editor/src/org/netbeans/modules/python/editor/PythonSemanticHighlighter.java	Sun Jul 05 00:01:18 2015 +0200
     1.3 @@ -172,7 +172,7 @@
     1.4          }
     1.5  
     1.6          private void highlightName(Name name, EnumSet<ColoringAttributes> color) {
     1.7 -            if (name != null) {
     1.8 +            if (name != null && !color.isEmpty()) {
     1.9                  OffsetRange range = PythonAstUtils.getNameRange(info, name);
    1.10                  highlights.put(range, color);
    1.11              }
    1.12 @@ -182,17 +182,16 @@
    1.13          public Object visitName(Name node) throws Exception {
    1.14              String name = node.getInternalId();
    1.15              if (scope != null) {
    1.16 +                EnumSet<ColoringAttributes> color = EnumSet.noneOf(ColoringAttributes.class);
    1.17                  if (scope.isUnused(name)) {
    1.18 -                    OffsetRange r = PythonAstUtils.getNameRange(info, node);
    1.19 -                    if (scope.isParameter(name) && !name.equals("self")) {
    1.20 -                        highlights.put(r, EnumSet.of(ColoringAttributes.UNUSED, ColoringAttributes.PARAMETER));
    1.21 -                    } else {
    1.22 -                        highlights.put(r, EnumSet.of(ColoringAttributes.UNUSED));
    1.23 -                    }
    1.24 -                } else if (scope.isParameter(name) && !name.equals("self")) {
    1.25 -                    OffsetRange r = PythonAstUtils.getNameRange(info, node);
    1.26 -                    highlights.put(r, ColoringAttributes.PARAMETER_SET);
    1.27 +                    color.add(ColoringAttributes.UNUSED);
    1.28                  }
    1.29 +
    1.30 +                if (scope.isParameter(name) && !name.equals("self")) {
    1.31 +                    color.add(ColoringAttributes.PARAMETER);
    1.32 +                }
    1.33 +
    1.34 +                highlightName(node, color);
    1.35              }
    1.36  
    1.37              return super.visitName(node);