com.intellij.psi.StubBuilder Java Examples

The following examples show how to use com.intellij.psi.StubBuilder. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: RmlFileStubElementType.java    From reasonml-idea-plugin with MIT License 6 votes vote down vote up
@NotNull
@Override
public StubBuilder getBuilder() {
    return new DefaultStubBuilder() {
        @NotNull
        @Override
        protected StubElement createStubForFile(@NotNull PsiFile file) {
            if (file instanceof RmlFile) {
                return new RmlFileStub((RmlFile) file, ((RmlFile) file).isComponent());
            } else if (file instanceof RmlInterfaceFile) {
                return new RmlFileStub((RmlInterfaceFile) file, ((RmlInterfaceFile) file).isComponent());
            }
            return super.createStubForFile(file);
        }
    };
}
 
Example #2
Source File: FileElement.java    From consulo with Apache License 2.0 6 votes vote down vote up
private List<CompositeElement> calcStubbedDescendants(StubBuilder builder) {
  List<CompositeElement> result = new ArrayList<>();
  result.add(this);

  acceptTree(new RecursiveTreeElementWalkingVisitor() {
    @Override
    public void visitComposite(CompositeElement node) {
      CompositeElement parent = node.getTreeParent();
      if (parent != null && builder.skipChildProcessingWhenBuildingStubs(parent, node)) {
        return;
      }

      IElementType type = node.getElementType();
      if (type instanceof IStubElementType && ((IStubElementType)type).shouldCreateStub(node)) {
        result.add(node);
      }

      super.visitNode(node);
    }
  });
  return result;
}
 
Example #3
Source File: NASMFileElementType.java    From JetBrains-NASM-Language with MIT License 5 votes vote down vote up
@NotNull
@Override
public StubBuilder getBuilder() {
    return new DefaultStubBuilder() {
        @NotNull
        @Override
        protected StubElement createStubForFile(@NotNull PsiFile file) {
            if (file instanceof NASMFile) {
                return new NASMFileStub((NASMFile)file);
            }
            return super.createStubForFile(file);
        }
    };
}
 
Example #4
Source File: OclFileStubElementType.java    From reasonml-idea-plugin with MIT License 5 votes vote down vote up
@NotNull
@Override
public StubBuilder getBuilder() {
    return new DefaultStubBuilder() {
        @NotNull
        @Override
        protected StubElement createStubForFile(@NotNull PsiFile file) {
            if (file instanceof OclFile) {
                return new OclFileStub((OclFile) file);
            }
            return super.createStubForFile(file);
        }
    };
}
 
Example #5
Source File: FileStub.java    From bamboo-soy with Apache License 2.0 5 votes vote down vote up
@Override
public StubBuilder getBuilder() {
  return new DefaultStubBuilder() {
    @Override
    protected StubElement createStubForFile(@NotNull PsiFile file) {
      return new FileStub((SoyFile) file);
    }
  };
}
 
Example #6
Source File: FusionFileStub.java    From intellij-neos with GNU General Public License v3.0 5 votes vote down vote up
@Override
public StubBuilder getBuilder() {
    return new DefaultStubBuilder() {
        @NotNull
        @Override
        protected StubElement createStubForFile(@NotNull PsiFile file) {
            return new FusionFileStub((FusionFile) file);
        }
    };
}
 
Example #7
Source File: FileStub.java    From protobuf-jetbrains-plugin with Apache License 2.0 5 votes vote down vote up
@Override
public StubBuilder getBuilder() {
    return new DefaultStubBuilder() {
        @Override
        protected StubElement createStubForFile(@NotNull PsiFile file) {
            return new FileStub((ProtoPsiFileRoot) file);
        }
    };
}
 
Example #8
Source File: BashStubFileElementType.java    From BashSupport with Apache License 2.0 5 votes vote down vote up
@Override
public StubBuilder getBuilder() {
    return new DefaultStubBuilder() {
        @NotNull
        @Override
        protected StubElement createStubForFile(@NotNull PsiFile file) {
            if (file instanceof BashFile) {
                return new BashFileStubImpl((BashFile) file);
            }

            return super.createStubForFile(file);
        }
    };
}
 
Example #9
Source File: HaskellFileStubElementType.java    From intellij-haskforce with Apache License 2.0 5 votes vote down vote up
@Override
public StubBuilder getBuilder() {
    return new DefaultStubBuilder() {
        @NotNull
        @Override
        protected StubElement createStubForFile(@NotNull PsiFile file) {
            if (file instanceof HaskellFile) {
                return new HaskellFileStub((HaskellFile)file);
            }
            return super.createStubForFile(file);
        }
    };
}
 
Example #10
Source File: CSharpFileStubElementType.java    From consulo-csharp with Apache License 2.0 5 votes vote down vote up
@Override
public StubBuilder getBuilder()
{
	return new DefaultStubBuilder()
	{
		@Nonnull
		@Override
		protected StubElement createStubForFile(@Nonnull PsiFile file)
		{
			if(file instanceof CSharpFileImpl)
			{
				return new CSharpFileStub((CSharpFileImpl) file);
			}
			return super.createStubForFile(file);
		}

		@Override
		public boolean skipChildProcessingWhenBuildingStubs(@Nonnull ASTNode parent, @Nonnull ASTNode node)
		{
			// skip any lazy parseable elements, like preprocessors or code blocks etc
			if(node.getElementType() instanceof ILazyParseableElementType)
			{
				return true;
			}
			return false;
		}
	};
}
 
Example #11
Source File: IStubFileElementType.java    From consulo with Apache License 2.0 4 votes vote down vote up
public StubBuilder getBuilder() {
  return new DefaultStubBuilder();
}
 
Example #12
Source File: StubTreeBuilder.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nullable
public static Stub buildStubTree(final FileContent inputData) {
  Stub data = inputData.getUserData(stubElementKey);
  if (data != null) return data;

  //noinspection SynchronizationOnLocalVariableOrMethodParameter
  synchronized (inputData) {
    data = inputData.getUserData(stubElementKey);
    if (data != null) return data;

    final FileType fileType = inputData.getFileType();

    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 {
      CharSequence contentAsText = inputData.getContentAsText();
      PsiDependentFileContent fileContent = (PsiDependentFileContent)inputData;
      PsiFile psi = fileContent.getPsiFile();
      final FileViewProvider viewProvider = psi.getViewProvider();
      psi = viewProvider.getStubBindingRoot();
      psi.putUserData(IndexingDataKeys.FILE_TEXT_CONTENT_KEY, contentAsText);

      // if we load AST, it should be easily gc-able. See PsiFileImpl.createTreeElementPointer()
      psi.getManager().startBatchFilesProcessingMode();

      try {
        IStubFileElementType stubFileElementType = ((PsiFileImpl)psi).getElementTypeForStubBuilder();
        if (stubFileElementType != null) {
          final StubBuilder stubBuilder = stubFileElementType.getBuilder();
          if (stubBuilder instanceof LightStubBuilder) {
            LightStubBuilder.FORCED_AST.set(fileContent.getLighterAST());
          }
          data = stubBuilder.buildStubTree(psi);

          final List<Pair<IStubFileElementType, PsiFile>> stubbedRoots = getStubbedRoots(viewProvider);
          final List<PsiFileStub> stubs = new ArrayList<>(stubbedRoots.size());
          stubs.add((PsiFileStub)data);

          for (Pair<IStubFileElementType, PsiFile> stubbedRoot : stubbedRoots) {
            final PsiFile secondaryPsi = stubbedRoot.second;
            if (psi == secondaryPsi) continue;
            final StubBuilder stubbedRootBuilder = stubbedRoot.first.getBuilder();
            if (stubbedRootBuilder instanceof LightStubBuilder) {
              LightStubBuilder.FORCED_AST.set(new TreeBackedLighterAST(secondaryPsi.getNode()));
            }
            final StubElement element = stubbedRootBuilder.buildStubTree(secondaryPsi);
            if (element instanceof PsiFileStub) {
              stubs.add((PsiFileStub)element);
            }
            ensureNormalizedOrder(element);
          }
          final PsiFileStub[] stubsArray = stubs.toArray(PsiFileStub.EMPTY_ARRAY);
          for (PsiFileStub stub : stubsArray) {
            if (stub instanceof PsiFileStubImpl) {
              ((PsiFileStubImpl)stub).setStubRoots(stubsArray);
            }
          }
        }
      }
      finally {
        psi.putUserData(IndexingDataKeys.FILE_TEXT_CONTENT_KEY, null);
        psi.getManager().finishBatchFilesProcessingMode();
      }
    }

    ensureNormalizedOrder(data);
    inputData.putUserData(stubElementKey, data);
    return data;
  }
}