Repository: haxefoundation/intellij-haxe
Issue: "update()" in FlxState are "unresolved symbols"

see https://groups.google.com/forum/#!msg/haxeflixel/gGmJ_B3x6tQ/Dxltcsvsi7sJ

we can reproduce the bug by open structure view for Bar.hx with the following code:

//file Foo.hx

```
class Foo { }
```

//file Col.hx

```
class Col<T> {
    var iiii: Int;
}
```

//file Bar.hx

```
class Bar extends Col<Foo> {
    var ssss: String;
}
```

Note that, if we put all class in one file then structure view will show Col as super class of Bar but if put each class in one file then structure view (for Bar.hx) will NOT show Col.


Changed files:
src/com/intellij/plugins/haxe/util/HaxeResolveUtil.java

diff --git a/src/com/intellij/plugins/haxe/util/HaxeResolveUtil.java b/src/com/intellij/plugins/haxe/util/HaxeResolveUtil.java
index 7a4c9ada..872558c0 100644
--- a/src/com/intellij/plugins/haxe/util/HaxeResolveUtil.java
+++ b/src/com/intellij/plugins/haxe/util/HaxeResolveUtil.java
@@ -530,8 +530,8 @@ public class HaxeResolveUtil {
       return null;
     }
 
-    String name = getQName(type, false);
-    HaxeClass result = findClassByQName(name, type.getContext());
+    String name = getQName(type);
+    HaxeClass result = name == null? tryResolveClassByQNameWhenGetQNameFail(type) : findClassByQName(name, type.getContext());
     result = result != null ? result : tryFindHelper(type);
     result = result != null ? result : findClassByQNameInSuperPackages(type);
     return result;
@@ -565,7 +565,8 @@ public class HaxeResolveUtil {
     return ownerClass == null ? null : findComponentDeclaration(ownerClass.getContainingFile(), element.getText());
   }
 
-  public static String getQName(@NotNull PsiElement type, boolean searchInSamePackage) {
+  @Nullable
+  private static String getQName(@NotNull PsiElement type) {
     HaxeImportStatementWithInSupport importStatementWithInSupport = PsiTreeUtil.getParentOfType(type,
                                                                                                 HaxeImportStatementWithInSupport.class,
                                                                                                 false);
@@ -575,24 +576,20 @@ public class HaxeResolveUtil {
 
     HaxeUsingStatement usingStatement = PsiTreeUtil.getParentOfType(type, HaxeUsingStatement.class, false);
     if (usingStatement != null) {
-      return usingStatement.getReferenceExpression().getText();
+      HaxeReferenceExpression expression = usingStatement.getReferenceExpression();
+      return expression == null? null : expression.getText();
     }
 
-    String text = type.getText();
     if (type instanceof HaxeReferenceExpression) {
-      String text1 = type.getText();
-      PsiElement element = null;
       if (type.getParent() instanceof HaxeReferenceExpression) {
-        element = type;
+        PsiElement element = type;
         while (element.getParent() instanceof HaxeReferenceExpression) {
           element = element.getParent();
         }
 
-        if (element != null) {
-          HaxeClass haxeClass = findClassByQName(element.getText(), element.getContext());
-          if (haxeClass != null) {
-            return element.getText();
-          }
+        HaxeClass haxeClass = findClassByQName(element.getText(), element.getContext());
+        if (haxeClass != null) {
+          return element.getText();
         }
 
         PsiElement parent = type.getParent();
@@ -603,16 +600,32 @@ public class HaxeResolveUtil {
       }
     }
 
+    return null;
+  }
+
+  @Nullable
+  private static HaxeClass tryResolveClassByQNameWhenGetQNameFail(@NotNull PsiElement type) {
     if (type instanceof HaxeType) {
       type = ((HaxeType)type).getReferenceExpression();
     }
 
-    final String result = type.getText();
-    if (result.indexOf('.') == -1) {
+    final String name = type.getText();
+    HaxeClass result = null;
+
+    //1. try searchInSamePackage, ex if type is Bar, be referenced in foo.Foo then we will find class foo.Bar
+    //note if there are 2 class: Bar & foo.Bar then we need resolve foo.Bar instead of Bar.
+    if (name != null && name.indexOf('.') == -1) {
       final PsiFile psiFile = type.getContainingFile();
       final PsiElement[] fileChildren = psiFile.getChildren();
-      return getQName(fileChildren, result, searchInSamePackage);
+      String nameWithPackage = getQName(fileChildren, name, true);
+      result = findClassByQName(nameWithPackage, type.getContext());
     }
+
+    //2. try without searchInSamePackage,
+    // ex if type is Int, be referenced in foo.Foo then we will find class has qName = Int, not foo.Int
+	// (if foo.Int exist then the prev step have aready resolved & returned it)
+    result = result != null ? result : findClassByQName(name, type.getContext());
+
     return result;
   }