Use new Java parser
authorRoman Shevchenko <roman.shevchenko@jetbrains.com>
Mon, 20 Dec 2010 10:39:51 +0000 (13:39 +0300)
committerRoman Shevchenko <roman.shevchenko@jetbrains.com>
Mon, 20 Dec 2010 10:40:36 +0000 (13:40 +0300)
java/java-impl/src/com/intellij/psi/impl/source/PsiAnonymousClassImpl.java
java/java-impl/src/com/intellij/psi/impl/source/PsiJavaCodeReferenceElementImpl.java

index 5ab126d30990de06fcbcd33bd908bae8b8ea8ff5..3d82fa57f4b1443763214ebafa6ef2b48c36d5e2 100644 (file)
@@ -21,12 +21,10 @@ import com.intellij.psi.impl.PsiClassImplUtil;
 import com.intellij.psi.impl.PsiSuperMethodImplUtil;
 import com.intellij.psi.impl.java.stubs.JavaStubElementTypes;
 import com.intellij.psi.impl.java.stubs.PsiClassStub;
 import com.intellij.psi.impl.PsiSuperMethodImplUtil;
 import com.intellij.psi.impl.java.stubs.JavaStubElementTypes;
 import com.intellij.psi.impl.java.stubs.PsiClassStub;
-import com.intellij.psi.impl.source.parsing.Parsing;
 import com.intellij.psi.impl.source.tree.ChildRole;
 import com.intellij.psi.impl.source.tree.ChildRole;
-import com.intellij.psi.impl.source.tree.FileElement;
 import com.intellij.psi.impl.source.tree.SharedImplUtil;
 import com.intellij.psi.impl.source.tree.SharedImplUtil;
-import com.intellij.psi.impl.source.tree.TreeElement;
 import com.intellij.psi.scope.PsiScopeProcessor;
 import com.intellij.psi.scope.PsiScopeProcessor;
+import com.intellij.util.IncorrectOperationException;
 import com.intellij.util.PatchedSoftReference;
 import org.jetbrains.annotations.NotNull;
 
 import com.intellij.util.PatchedSoftReference;
 import org.jetbrains.annotations.NotNull;
 
@@ -60,7 +58,10 @@ public class PsiAnonymousClassImpl extends PsiClassImpl implements PsiAnonymousC
 
   @NotNull
   public PsiJavaCodeReferenceElement getBaseClassReference() {
 
   @NotNull
   public PsiJavaCodeReferenceElement getBaseClassReference() {
-    return (PsiJavaCodeReferenceElement)getNode().findChildByRoleAsPsiElement(ChildRole.BASE_CLASS_REFERENCE);
+    final PsiJavaCodeReferenceElement result =
+      (PsiJavaCodeReferenceElement)getNode().findChildByRoleAsPsiElement(ChildRole.BASE_CLASS_REFERENCE);
+    assert result != null;
+    return result;
   }
 
   @NotNull
   }
 
   @NotNull
@@ -77,23 +78,20 @@ public class PsiAnonymousClassImpl extends PsiClassImpl implements PsiAnonymousC
 
     if (!isInQualifiedNew()) {
       final PsiJavaCodeReferenceElement ref;
 
     if (!isInQualifiedNew()) {
       final PsiJavaCodeReferenceElement ref;
-      String refText = stub.getBaseClassReferenceText();
-      final DummyHolder holder = DummyHolderFactory
-        .createHolder(getManager(), calcBasesResolveContext(PsiNameHelper.getShortClassName(refText), getExtendsList()));
-      final FileElement holderElement = holder.getTreeElement();
-
-      ref = (PsiJavaCodeReferenceElementImpl)Parsing.parseJavaCodeReferenceText(getManager(), refText,
-                                                                                holderElement.getCharTable());
-      if (ref == null) {
+      final String refText = stub.getBaseClassReferenceText();
+      assert refText != null : stub;
+      final PsiElementFactory factory = JavaPsiFacade.getInstance(getProject()).getElementFactory();
+
+      final PsiElement context = calcBasesResolveContext(PsiNameHelper.getShortClassName(refText), getExtendsList());
+      try {
+        ref = factory.createReferenceFromText(refText, context);
+        ((PsiJavaCodeReferenceElementImpl)ref).setKindWhenDummy(PsiJavaCodeReferenceElementImpl.CLASS_NAME_KIND);
+        type = factory.createType(ref);
+      }
+      catch (IncorrectOperationException e) {
         type = PsiClassType.getJavaLangObject(getManager(), getResolveScope());
         type = PsiClassType.getJavaLangObject(getManager(), getResolveScope());
-        myCachedBaseType = new PatchedSoftReference<PsiClassType>(type);
-        return type;
       }
 
       }
 
-      holderElement.rawAddChildren((TreeElement)ref);
-      ((PsiJavaCodeReferenceElementImpl)ref).setKindWhenDummy(PsiJavaCodeReferenceElementImpl.CLASS_NAME_KIND);
-
-      type = JavaPsiFacade.getInstance(getProject()).getElementFactory().createType(ref);
       myCachedBaseType = new PatchedSoftReference<PsiClassType>(type);
       return type;
     }
       myCachedBaseType = new PatchedSoftReference<PsiClassType>(type);
       return type;
     }
index ece2dfe27e9fc03b5c95d55448824281e8b7f2b8..e37f0af014282dfddba2b73f06f70d9357a5898f 100644 (file)
@@ -76,13 +76,17 @@ public class PsiJavaCodeReferenceElementImpl extends CompositePsiElement impleme
   }
 
   public void setKindWhenDummy(final int kind) {
   }
 
   public void setKindWhenDummy(final int kind) {
-    LOG.assertTrue(getTreeParent().getElementType() == TokenType.DUMMY_HOLDER);
+    LOG.assertTrue(isDummy(getTreeParent().getElementType()));
     myKindWhenDummy = kind;
   }
 
     myKindWhenDummy = kind;
   }
 
+  private static boolean isDummy(final IElementType type) {
+    return type == TokenType.DUMMY_HOLDER || type == JavaElementType.DUMMY_ELEMENT;
+  }
+
   public int getKind() {
     IElementType i = getTreeParent().getElementType();
   public int getKind() {
     IElementType i = getTreeParent().getElementType();
-    if (i == TokenType.DUMMY_HOLDER) {
+    if (isDummy(i)) {
       return myKindWhenDummy;
     }
     if (i == JavaElementType.TYPE) {
       return myKindWhenDummy;
     }
     if (i == JavaElementType.TYPE) {