better resolve
authoralexey.ivanov <alexey.ivanov@jetbrains.com>
Fri, 22 Oct 2010 16:55:43 +0000 (20:55 +0400)
committeralexey.ivanov <alexey.ivanov@jetbrains.com>
Fri, 22 Oct 2010 16:55:43 +0000 (20:55 +0400)
src/org/jetbrains/javafx/lang/parser/JavaFxElementTypes.java
src/org/jetbrains/javafx/lang/psi/impl/JavaFxClassDefinitionImpl.java
src/org/jetbrains/javafx/lang/psi/impl/JavaFxImportStatementImpl.java
src/org/jetbrains/javafx/lang/psi/impl/JavaFxParameterImpl.java
src/org/jetbrains/javafx/lang/psi/impl/JavaFxReferenceElementImpl.java
src/org/jetbrains/javafx/lang/psi/impl/resolve/JavaFxQualifiedReference.java
src/org/jetbrains/javafx/lang/psi/impl/resolve/JavaFxReference.java
src/org/jetbrains/javafx/lang/psi/impl/resolve/JavaFxResolveProcessor.java
src/org/jetbrains/javafx/lang/psi/impl/types/JavaFxTypeUtil.java

index 53e24647db9364dda29d958a825297f337c9d737..011929b61573d6a64c20a46cb15be7b2a9a85bfc 100644 (file)
@@ -92,7 +92,8 @@ public interface JavaFxElementTypes extends JavaFxStubElementTypes, JavaFxTokenT
                                          INDEX_EXPRESSION, SEQUENCE_SELECT_EXPRESSION, SLICE_EXPRESSION,
                                          REFERENCE_EXPRESSION, OBJECT_LITERAL, SEQUENCE_LITERAL, RANGE_EXPRESSION,
                                          LITERAL_EXPRESSION, FUNCTION_EXPRESSION, BLOCK_EXPRESSION, PARENTHESIZED_EXPRESSION,
-                                         TIMELINE_EXPRESSION, THIS_EXPRESSION, INVALIDATE_EXPRESSION, BOUND_EXPRESSION);
+                                         TIMELINE_EXPRESSION, THIS_EXPRESSION, INVALIDATE_EXPRESSION, BOUND_EXPRESSION,
+                                         STRING_EXPRESSION);
 
   TokenSet CLASS_MEMBERS = TokenSet.create(INIT_BLOCK, POSTINIT_BLOCK, VARIABLE_DECLARATION, FUNCTION_DEFINITION);
   TokenSet DEFINITIONS = TokenSet.orSet(EXPRESSIONS, TokenSet.create(CLASS_DEFINITION, FUNCTION_DEFINITION));
index 2f54f9ef99f5dd4547c3eeaf669d2239d823c894..5253523f3bb8b9af5913964a4c3d0d3d85a07fba 100644 (file)
@@ -16,7 +16,9 @@
 package org.jetbrains.javafx.lang.psi.impl;
 
 import com.intellij.lang.ASTNode;
+import com.intellij.openapi.util.io.FileUtil;
 import com.intellij.psi.PsiElement;
+import com.intellij.psi.PsiFile;
 import com.intellij.psi.PsiReference;
 import com.intellij.psi.ResolveState;
 import com.intellij.psi.scope.PsiScopeProcessor;
@@ -103,6 +105,15 @@ public class JavaFxClassDefinitionImpl extends JavaFxPresentableElementImpl<Java
     if (!JavaFxResolveUtil.processElements(getMembers(), lastParent, processor, state)) {
       return false;
     }
+    final PsiFile containingFile = getContainingFile();
+    if (containingFile instanceof JavaFxFile) {
+      final String name = containingFile.getName();
+      if (FileUtil.getNameWithoutExtension(name).equals(getName())) {
+        if (!JavaFxResolveUtil.processElements(((JavaFxFile)containingFile).getDefinitions(), this, processor, state)) {
+          return false;
+        }
+      }
+    }
     final JavaFxReferenceElement[] superClassElements = getSuperClassElements();
     for (JavaFxReferenceElement referenceElement : superClassElements) {
       final PsiReference reference = referenceElement.getReference();
index f532e87026e73c982337e6b241736727f9e8b550..8451a39a42a350c35cfa167cba1a89a58310ebf2 100644 (file)
@@ -98,7 +98,8 @@ public class JavaFxImportStatementImpl extends JavaFxBaseElementImpl implements
         }
         else {
           final PsiElement resolveResult = importReference.resolve();
-          if (resolveResult instanceof PsiPackage || resolveResult instanceof PsiFile && resolveResult != containingFile) {
+          if (resolveResult instanceof PsiClass || resolveResult instanceof PsiPackage ||
+                  resolveResult instanceof PsiFile && resolveResult != containingFile) {
             return resolveResult.processDeclarations(processor, state, this, place);
           }
         }
index fd46da3fc8a7f70f99f1edb4c0a3daba6f7cfb09..56757e761900ec52e06f447904ab5bc34f08d201 100644 (file)
@@ -16,6 +16,7 @@
 package org.jetbrains.javafx.lang.psi.impl;
 
 import com.intellij.lang.ASTNode;
+import com.intellij.psi.PsiArrayType;
 import com.intellij.psi.PsiElement;
 import com.intellij.psi.PsiType;
 import com.intellij.util.IncorrectOperationException;
@@ -73,8 +74,13 @@ public class JavaFxParameterImpl extends JavaFxPresentableElementImpl<JavaFxPara
       final JavaFxExpression iteratedExpression = ((JavaFxInClause)parent).getIteratedExpression();
       if (iteratedExpression != null) {
         final PsiType type = iteratedExpression.getType();
-        if (type != null && type instanceof JavaFxSequenceType) {
-          return ((JavaFxSequenceType)type).getElementType();
+        if (type != null) {
+          if (type instanceof JavaFxSequenceType) {
+            return ((JavaFxSequenceType)type).getElementType();
+          }
+          if (type instanceof PsiArrayType) {
+            return ((PsiArrayType)type).getComponentType();
+          }
         }
       }
     }
index cb2b712d87c05a44051355f231b1d0d71154aa36..7ac3d04925e0719812b452eb3a064fca234e4cc1 100644 (file)
@@ -43,6 +43,10 @@ public class JavaFxReferenceElementImpl extends JavaFxBaseElementImpl implements
     if (importStatement != null) {
       return new JavaFxImportReference(this, importStatement.isOnDemand());
     }
+    final JavaFxElement javaFxElement = childToPsi(JavaFxElementTypes.REFERENCE_ELEMENT);
+    if (javaFxElement != null) {
+      return new JavaFxImportReference(this, false);
+    }
     final JavaFxPackageDefinition packageDefinition = PsiTreeUtil.getParentOfType(this, JavaFxPackageDefinition.class);
     if (packageDefinition != null) {
       return new JavaFxPackageReference(this);
index d9ef3adb1730ac97328adab7a257fa42c73e2ed9..b6b094394c9dec461eef4b9031bcd2a68b1cc35d 100644 (file)
@@ -47,8 +47,7 @@ public class JavaFxQualifiedReference extends JavaFxReference {
 
   @Override
   protected ResolveResult[] multiResolveInner(boolean incompleteCode) {
-    final String name = myElement.getName();
-    final JavaFxResolveProcessor resolveProcessor = new JavaFxResolveProcessor(name);
+    final JavaFxResolveProcessor resolveProcessor = createResolveProcessor(myElement.getName());
     PsiType type = myQualifier.getType();
     if (type instanceof JavaFxFunctionType && myQualifier instanceof JavaFxCallExpression) {
       type = ((JavaFxFunctionType)type).getReturnType();
index 226618144fc5e2b79c866e0c8394be903bfc524f..dd765b4ae64cc4528b77ff8e1ad73704edfde162 100644 (file)
  */
 package org.jetbrains.javafx.lang.psi.impl.resolve;
 
+import com.intellij.psi.PsiElement;
 import com.intellij.psi.PsiPolyVariantReferenceBase;
 import com.intellij.psi.ResolveResult;
 import com.intellij.psi.impl.PsiManagerEx;
 import com.intellij.psi.impl.source.resolve.ResolveCache;
 import org.jetbrains.annotations.NotNull;
+import org.jetbrains.javafx.lang.psi.JavaFxCallExpression;
+import org.jetbrains.javafx.lang.psi.JavaFxNewExpression;
 import org.jetbrains.javafx.lang.psi.JavaFxReferenceElement;
 
 /**
@@ -54,7 +57,7 @@ public class JavaFxReference extends PsiPolyVariantReferenceBase<JavaFxReference
   protected ResolveResult[] multiResolveInner(final boolean incompleteCode) {
     final String name = myElement.getName();
     if (name != null) {
-      final JavaFxResolveProcessor resolveProcessor = new JavaFxResolveProcessor(name);
+      final JavaFxResolveProcessor resolveProcessor = createResolveProcessor(name);
       if (!JavaFxResolveUtil.treeWalkUp(myElement, resolveProcessor)) {
         return JavaFxResolveUtil.createResolveResult(resolveProcessor.getResult());
       }
@@ -62,6 +65,14 @@ public class JavaFxReference extends PsiPolyVariantReferenceBase<JavaFxReference
     return ResolveResult.EMPTY_ARRAY;
   }
 
+  protected JavaFxResolveProcessor createResolveProcessor(final String name) {
+    final PsiElement parent = myElement.getParent();
+    if (parent instanceof JavaFxCallExpression || parent instanceof JavaFxNewExpression) {
+      return new JavaFxResolveProcessor(name, true);
+    }
+    return new JavaFxResolveProcessor(name);
+  }
+
   @NotNull
   @Override
   public Object[] getVariants() {
index 3f46c097fa6ebc88dd0b894d0d324767a898b5e2..5ab9f08d7de012515c0dc70620b52b55083586ce 100644 (file)
@@ -19,6 +19,7 @@ import com.intellij.openapi.util.Key;
 import com.intellij.openapi.util.io.FileUtil;
 import com.intellij.openapi.util.text.StringUtil;
 import com.intellij.psi.*;
+import com.intellij.psi.scope.ElementClassHint;
 import com.intellij.psi.scope.PsiScopeProcessor;
 import org.jetbrains.annotations.NotNull;
 import org.jetbrains.javafx.lang.psi.JavaFxFile;
@@ -28,14 +29,20 @@ import org.jetbrains.javafx.lang.psi.JavaFxFile;
  *
  * @author: Alexey.Ivanov
  */
-public class JavaFxResolveProcessor implements PsiScopeProcessor {
+public class JavaFxResolveProcessor implements PsiScopeProcessor, ElementClassHint {
   private final String myName;
+  private final boolean myShouldProcessMethods;
   private PsiElement myResult;
 
-  public JavaFxResolveProcessor(final String name) {
+  public JavaFxResolveProcessor(final String name, boolean shouldProcessMethods) {
+    myShouldProcessMethods = shouldProcessMethods;
     myName = (name != null && StringUtil.startsWith(name, "<<")) ? getRealName(name) : name;
   }
 
+  public JavaFxResolveProcessor(final String name) {
+    this(name, false);
+  }
+
   @Override
   public boolean execute(final PsiElement element, final ResolveState state) {
     if (myResult != null) {
@@ -48,8 +55,7 @@ public class JavaFxResolveProcessor implements PsiScopeProcessor {
           elementName = FileUtil.getNameWithoutExtension(elementName);
         }
         if (isNamesEqual(elementName)) {
-          myResult = element;
-          return false;
+          return createResolveResult(element);
         }
       }
       // compiled code
@@ -63,8 +69,7 @@ public class JavaFxResolveProcessor implements PsiScopeProcessor {
               final Object o = ((PsiLiteralExpression)value).getValue();
               if (o instanceof String) {
                 if (isNamesEqual((String)o)) {
-                  myResult = element;
-                  return false;
+                  return createResolveResult(element);
                 }
               }
             }
@@ -75,6 +80,11 @@ public class JavaFxResolveProcessor implements PsiScopeProcessor {
     return true;
   }
 
+  private boolean createResolveResult(PsiElement element) {
+    myResult = element;
+    return false;
+  }
+
   private boolean isNamesEqual(@NotNull final String elementName) {
     if (elementName.equals(myName)) {
       return true;
@@ -92,6 +102,9 @@ public class JavaFxResolveProcessor implements PsiScopeProcessor {
 
   @Override
   public <T> T getHint(final Key<T> hintKey) {
+    if (KEY == hintKey) {
+      return (T)this;
+    }
     return null;
   }
 
@@ -106,4 +119,12 @@ public class JavaFxResolveProcessor implements PsiScopeProcessor {
   public PsiElement getResult() {
     return myResult;
   }
+
+  @Override
+  public boolean shouldProcess(DeclaractionKind kind) {
+    if (kind == DeclaractionKind.METHOD) {
+      return myShouldProcessMethods;
+    }
+    return true;
+  }
 }
index e31677e62a90751448a0e083b3294acbfff38cdf..38a8a920f6529c078565bb9024415d5b6d5acbb9 100644 (file)
@@ -129,7 +129,7 @@ public class JavaFxTypeUtil {
     }
     if (psiElement instanceof PsiClass) {
       final String qualifiedName = ((PsiClass)psiElement).getQualifiedName();
-      if (isPrimitiveType(qualifiedName)) {
+      if (isPrimitiveType(qualifiedName) || "java.lang.Number".equals(qualifiedName)) {
         return getPrimitiveType(qualifiedName);
       }
       return new JavaClassTypeImpl((PsiClass)psiElement);