don't highlight groovy operator methods as unused
authorpeter <peter@jetbrains.com>
Wed, 1 Feb 2012 22:28:45 +0000 (23:28 +0100)
committerpeter <peter@jetbrains.com>
Wed, 1 Feb 2012 22:33:37 +0000 (23:33 +0100)
plugins/groovy/src/org/jetbrains/plugins/groovy/codeInspection/local/GroovyPostHighlightingPass.java
plugins/groovy/testdata/highlighting/GloballyUnusedSymbols.groovy

index 85ebd3864b35b69f63e1cf1fc28485c3ec2353ab..6635d44b6086561046a08d765a69270585c750be 100644 (file)
@@ -44,6 +44,7 @@ import com.intellij.util.Processor;
 import org.jetbrains.annotations.NotNull;
 import org.jetbrains.plugins.groovy.codeInspection.GroovyInspectionBundle;
 import org.jetbrains.plugins.groovy.codeInspection.GroovyUnusedDeclarationInspection;
+import org.jetbrains.plugins.groovy.lang.completion.GroovyCompletionUtil;
 import org.jetbrains.plugins.groovy.lang.editor.GroovyImportOptimizer;
 import org.jetbrains.plugins.groovy.lang.lexer.GroovyTokenTypes;
 import org.jetbrains.plugins.groovy.lang.psi.GrNamedElement;
@@ -126,7 +127,8 @@ public class GroovyPostHighlightingPass extends TextEditorHighlightingPass {
             }
             else if (element instanceof GrMethod) {
               GrMethod method = (GrMethod)element;
-              if (!PostHighlightingPass.isMethodReferenced(method, progress, usageHelper)) {
+              if (!GroovyCompletionUtil.OPERATOR_METHOD_NAMES.contains(method.getName()) &&
+                  !PostHighlightingPass.isMethodReferenced(method, progress, usageHelper)) {
                 unusedDeclarations.add(
                   PostHighlightingPass.createUnusedSymbolInfo(nameId, (method.isConstructor() ? "Constructor" : "Method") +" " + name + " is unused", HighlightInfoType.UNUSED_SYMBOL));
               }
index 2d98c8e740066a9c2f02f12dd388d8c0ecde4e55..06a58af451d1ee879ecad1b916501d29747a80f6 100644 (file)
@@ -7,6 +7,7 @@ class Bar<T, <warning descr="Class Unused is unused">Unused</warning>> {
   int usedProperty3 = 39
   def <warning descr="Method unusedMethod is unused">unusedMethod</warning>() {}
   Bar usedMethod() { this }
+  Object getAt(int key) {}
 
   Bar getUsedPropertyGetter() {}
 
@@ -20,3 +21,4 @@ println new Bar().usedMethod().usedProperty
 new Bar().setUsedProperty2 42
 println new Bar().getUsedProperty3()
 println new Bar().usedPropertyGetter
+println new Bar()['2']