set stub roots when tree is built with BinaryFileStubBuilder
authorKonstantin Ulitin <konstantin.ulitin@jetbrains.com>
Mon, 6 Jul 2015 11:52:03 +0000 (14:52 +0300)
committerKonstantin Ulitin <konstantin.ulitin@jetbrains.com>
Wed, 8 Jul 2015 13:11:20 +0000 (16:11 +0300)
platform/core-impl/src/com/intellij/psi/impl/source/PsiFileImpl.java
platform/core-impl/src/com/intellij/psi/stubs/PsiFileStubImpl.java
platform/core-impl/src/com/intellij/psi/stubs/StubTreeBuilder.java

index 2c84323beaed76ce9cc4cc8dc04fc17de631e7b2..63d0fcb9388d38ff0143f2861bbea720caa83441 100644 (file)
@@ -667,11 +667,11 @@ public abstract class PsiFileImpl extends ElementBase implements PsiFileEx, PsiF
       if (derefdOnLock != null) return derefdOnLock;
 
       final PsiFileStub baseRoot = stubHolder.getRoot();
-      final PsiFileStub[] stubRoots = ((PsiFileStubImpl)baseRoot).getStubRootsAsIs();
-      if (stubRoots == null) {
+      if (baseRoot instanceof PsiFileStubImpl && !((PsiFileStubImpl)baseRoot).rootsAreSet()) {
         LOG.error("Stub roots must be set when stub tree was read or built with StubTreeLoader");
         return stubHolder;
       }
+      final PsiFileStub[] stubRoots = baseRoot.getStubRoots();
       if (stubRoots.length != roots.size()) {
         LOG.error("stubRoots.length = " + stubRoots.length + "; roots.size() = " + roots.size());
       }
index 1746df6463c8636d0bb3b401d153ac80f30089c0..04f9f6959bf351458a6f3fe1ac97911071faa355 100644 (file)
@@ -131,8 +131,7 @@ public class PsiFileStubImpl<T extends PsiFile> extends StubBase<T> implements P
     myStubRoots = roots;
   }
 
-  @Nullable
-  public PsiFileStub[] getStubRootsAsIs() {
-    return myStubRoots;
+  public boolean rootsAreSet() {
+    return myStubRoots != null;
   }
 }
\ No newline at end of file
index d70b213c72c9faa801ab90c1daa20a6fd6195380..9de06c01cdafbce70845d47339399d2ab0cddab9 100644 (file)
@@ -65,6 +65,9 @@ public class StubTreeBuilder {
       final BinaryFileStubBuilder builder = BinaryFileStubBuilders.INSTANCE.forFileType(fileType);
       if (builder != null) {
         data = builder.buildStubTree(inputData);
+        if (data instanceof PsiFileStubImpl && !((PsiFileStubImpl)data).rootsAreSet()) {
+          ((PsiFileStubImpl)data).setStubRoots(new PsiFileStub[]{(PsiFileStubImpl)data});
+        }
       }
       else {
         final LanguageFileType languageFileType = (LanguageFileType)fileType;