[groovy] @Field support: use stubs
authorDaniil Ovchinnikov <daniil.ovchinnikov@jetbrains.com>
Mon, 31 Oct 2016 19:55:53 +0000 (22:55 +0300)
committerDaniil Ovchinnikov <daniil.ovchinnikov@jetbrains.com>
Mon, 31 Oct 2016 20:05:56 +0000 (23:05 +0300)
plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/transformations/impl/FieldScriptTransformationSupport.java

index 8c4b024fd602845f6dfb44a206d0c5b57554627a..e7b18810df719fe92aa9bf1c2a3b9d8b33ffc2f0 100644 (file)
 package org.jetbrains.plugins.groovy.transformations.impl;
 
 import org.jetbrains.annotations.NotNull;
-import org.jetbrains.plugins.groovy.lang.psi.GroovyRecursiveElementVisitor;
 import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrVariable;
 import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrVariableDeclaration;
-import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrTypeDefinition;
-import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrMethod;
 import org.jetbrains.plugins.groovy.lang.psi.impl.synthetic.GrScriptField;
 import org.jetbrains.plugins.groovy.lang.psi.impl.synthetic.GroovyScriptClass;
 import org.jetbrains.plugins.groovy.lang.psi.util.GroovyCommonClassNames;
@@ -37,26 +34,12 @@ public class FieldScriptTransformationSupport implements AstTransformationSuppor
     if (!hasNameInFile(scriptClass.getContainingFile(), "Field")) {
       return;
     }
-    scriptClass.getContainingFile().accept(new GroovyRecursiveElementVisitor() {
-      @Override
-      public void visitVariableDeclaration(@NotNull GrVariableDeclaration element) {
-        if (element.getModifierList().findAnnotation(GroovyCommonClassNames.GROOVY_TRANSFORM_FIELD) != null) {
-          for (GrVariable variable : element.getVariables()) {
-            context.addField(new GrScriptField(variable, scriptClass));
-          }
+    for (GrVariableDeclaration declaration : scriptClass.getContainingFile().getAnnotatedScriptDeclarations()) {
+      if (declaration.getModifierList().findAnnotation(GroovyCommonClassNames.GROOVY_TRANSFORM_FIELD) != null) {
+        for (GrVariable variable : declaration.getVariables()) {
+          context.addField(new GrScriptField(variable, scriptClass));
         }
-        super.visitVariableDeclaration(element);
       }
-
-      @Override
-      public void visitMethod(@NotNull GrMethod method) {
-        //skip methods
-      }
-
-      @Override
-      public void visitTypeDefinition(@NotNull GrTypeDefinition typeDefinition) {
-        //skip type defs
-      }
-    });
+    }
   }
 }