grails controller, domain class implicit members resolve 92.35
authorMaxim Medvedev <maxim.medvedev@jetbrains.com>
Thu, 19 Nov 2009 16:14:44 +0000 (19:14 +0300)
committerMaxim Medvedev <maxim.medvedev@jetbrains.com>
Thu, 19 Nov 2009 16:14:44 +0000 (19:14 +0300)
plugins/groovy/src/org/jetbrains/plugins/groovy/annotator/intentions/dynamic/elements/DPropertyElement.java
plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/statements/arguments/GrArgumentLabelImpl.java
plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/synthetic/GrDynamicImplicitProperty.java
plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/synthetic/GrImplicitVariableImpl.java
plugins/groovy/test/org/jetbrains/plugins/groovy/lang/completion/CompletionTestBase.java

index ecfea426c1ec742b9eb36e3ef1f90c163c9b24f8..f4016bba1968aa4f0afb920911ce059e8ac7dbc0 100644 (file)
  */
 package org.jetbrains.plugins.groovy.annotator.intentions.dynamic.elements;
 
+import com.intellij.psi.PsiElement;
 import com.intellij.psi.PsiManager;
-import com.intellij.psi.PsiVariable;
 import com.intellij.psi.PsiModifier;
-import com.intellij.psi.PsiElement;
+import com.intellij.psi.PsiVariable;
 import com.intellij.util.IncorrectOperationException;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.plugins.groovy.annotator.intentions.dynamic.DynamicManager;
 import org.jetbrains.plugins.groovy.lang.psi.impl.synthetic.GrDynamicImplicitProperty;
 import org.jetbrains.plugins.groovy.lang.psi.impl.synthetic.LightModifierList;
-import org.jetbrains.plugins.groovy.annotator.intentions.dynamic.DynamicManager;
-import org.jetbrains.annotations.NotNull;
 
 import java.util.LinkedHashSet;
 
@@ -57,7 +57,7 @@ public class DPropertyElement extends DItemElement {
     if (isStatic != null && isStatic.booleanValue()) {
       hashSet.add(PsiModifier.STATIC);
     }
-    myPsi = new GrDynamicImplicitProperty(manager, getName(), getType(), containingClassName, new LightModifierList(manager, hashSet)) {
+    myPsi = new GrDynamicImplicitProperty(manager, getName(), getType(), containingClassName, new LightModifierList(manager, hashSet), null) {
       @Override
       public PsiElement setName(@NotNull String name) throws IncorrectOperationException {
         DynamicManager.getInstance(getProject()).replaceDynamicPropertyName(containingClassName, getName(), name);
index f2d70c1776aca535c3fd568be7dcae6515a5f464..6449e508b9c6ca4e411eab83fd67782cbd7286ea 100644 (file)
@@ -26,6 +26,7 @@ import org.jetbrains.annotations.NotNull;
 import org.jetbrains.annotations.Nullable;
 import org.jetbrains.plugins.groovy.lang.psi.GroovyElementVisitor;
 import org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElementFactory;
+import org.jetbrains.plugins.groovy.lang.psi.api.GroovyResolveResult;
 import org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrArgumentLabel;
 import org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrArgumentList;
 import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression;
@@ -33,6 +34,8 @@ import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.path.GrC
 import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrAnonymousClassDefinition;
 import org.jetbrains.plugins.groovy.lang.psi.impl.GroovyPsiElementImpl;
 import org.jetbrains.plugins.groovy.lang.psi.util.PsiUtil;
+import org.jetbrains.plugins.groovy.lang.resolve.ResolveUtil;
+import org.jetbrains.plugins.groovy.lang.resolve.processors.PropertyResolverProcessor;
 
 /**
  * @author ilyas
@@ -95,7 +98,14 @@ public class GrArgumentLabelImpl extends GroovyPsiElementImpl implements GrArgum
           if (clazz != null) {
             PsiMethod[] byName = clazz.findMethodsByName(setterName, true);
             if (byName.length > 0) return byName[0];
-            return clazz.findFieldByName(propName, true);
+            final PsiField field = clazz.findFieldByName(propName, true);
+            if (field != null) return field;
+            final PropertyResolverProcessor processor = new PropertyResolverProcessor(propName, this);
+            ResolveUtil
+              .processNonCodeMethods(JavaPsiFacade.getElementFactory(getProject()).createType(clazz), processor, getProject(), this, false);
+            final GroovyResolveResult[] candidates = processor.getCandidates();
+            if (candidates.length == 0) return null;
+            return candidates[0].getElement();
           }
         }
       }
index ef43699bc3162494ec5717ce70304e37cdaab09b..481fea866cd846ab8436ef14c04f0a82029917d8 100644 (file)
@@ -24,9 +24,9 @@ import com.intellij.psi.javadoc.PsiDocComment;
 import com.intellij.psi.search.GlobalSearchScope;
 import com.intellij.psi.search.ProjectScope;
 import com.intellij.psi.search.SearchScope;
-import com.intellij.util.ui.tree.TreeUtil;
 import com.intellij.ui.treeStructure.treetable.ListTreeTableModelOnColumns;
 import com.intellij.ui.treeStructure.treetable.TreeTable;
+import com.intellij.util.ui.tree.TreeUtil;
 import org.jetbrains.annotations.NonNls;
 import org.jetbrains.annotations.NotNull;
 import org.jetbrains.annotations.Nullable;
@@ -47,11 +47,19 @@ import javax.swing.tree.TreePath;
 public class GrDynamicImplicitProperty extends GrImplicitVariableImpl implements GrDynamicImplicitElement, PsiField {
   private final String myContainingClassName;
   private final Project myProject;
+  private final PsiElement myNavigationalElement;
 
-  public GrDynamicImplicitProperty(PsiManager manager, @NonNls String name, @NonNls String type, String containingClassName, LightModifierList modifierList) {
-    super(modifierList, manager, name, type, null);
+  public GrDynamicImplicitProperty(PsiManager manager, @NonNls String name, @NonNls String type, String containingClassName,
+                                   LightModifierList modifierList, PsiElement navigationalElement) {
+    super(modifierList, manager, name, type, navigationalElement);
     myContainingClassName = containingClassName;
     myProject = manager.getProject();
+    if (navigationalElement==null) {
+      myNavigationalElement = this;
+    }
+    else {
+      myNavigationalElement = navigationalElement;
+    }
   }
 
   @Nullable
@@ -94,6 +102,10 @@ public class GrDynamicImplicitProperty extends GrImplicitVariableImpl implements
   }
 
   public void navigate(boolean requestFocus) {
+    if (canNavigateToSource()) {
+      super.navigate(requestFocus);
+      return;
+    }
     DynamicToolWindowWrapper.getInstance(myProject).getToolWindow().activate(new Runnable() {
       public void run() {
         DynamicToolWindowWrapper toolWindowWrapper = DynamicToolWindowWrapper.getInstance(myProject);
@@ -143,7 +155,13 @@ public class GrDynamicImplicitProperty extends GrImplicitVariableImpl implements
   }
 
   public boolean canNavigateToSource() {
-    return false;
+    return myNavigationalElement != this;
+  }
+
+  @NotNull
+  @Override
+  public PsiElement getNavigationElement() {
+    return myNavigationalElement;
   }
 
   public boolean canNavigate() {
index 231f3a3e7aeae7261fb8687a81ce75b66adc9b20..b11ef8129d86daf5d0373e4a6343e9dde8b8432a 100644 (file)
@@ -7,7 +7,6 @@ package org.jetbrains.plugins.groovy.lang.psi.impl.synthetic;
 import com.intellij.psi.*;
 import com.intellij.psi.impl.light.LightIdentifier;
 import com.intellij.psi.impl.light.LightVariableBase;
-import com.intellij.psi.search.ProjectScope;
 import com.intellij.util.IncorrectOperationException;
 import org.jetbrains.annotations.NonNls;
 import org.jetbrains.annotations.NotNull;
@@ -25,9 +24,8 @@ public class GrImplicitVariableImpl extends LightVariableBase implements GrImpli
     }
 
   public GrImplicitVariableImpl(PsiModifierList modifierList, PsiManager manager, @NonNls String name, @NonNls String type, PsiElement referenceExpression) {
-    this(modifierList, manager, null,
-        JavaPsiFacade.getInstance(manager.getProject()).getElementFactory().
-            createTypeByFQClassName(type, ProjectScope.getAllScope(manager.getProject())), false, referenceExpression);
+    this(modifierList, manager, null, JavaPsiFacade.getElementFactory(manager.getProject()).
+      createTypeFromText(type, referenceExpression), false, referenceExpression);
     myNameIdentifier = new GrLightIdentifier(myManager, name);
   }
 
index c5d5bf4ab833a380866849114fc3876256cc3bdc..dedbf943e4951f168dd3a7fa02ea2a663e9dfbb5 100644 (file)
@@ -20,8 +20,12 @@ import java.util.List;
 public abstract class CompletionTestBase extends JavaCodeInsightFixtureTestCase {
 
   protected void doTest() throws Throwable {
+    doTest("");
+  }
+  protected void doTest(String directory) throws Throwable {
     final List<String> stringList = TestUtils.readInput(getTestDataPath() + "/" + getTestName(true) + ".test");
-    final String fileName = getTestName(true) + "." + getExtension();
+    if (!directory.isEmpty()) directory += "/";
+    final String fileName = directory + getTestName(true) + "." + getExtension();
     myFixture.addFileToProject(fileName, stringList.get(0));
     myFixture.configureByFile(fileName);