com.intellij.util.indexing.IndexingDataKeys Java Examples

The following examples show how to use com.intellij.util.indexing.IndexingDataKeys. 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: BashIncludeCommandElementType.java    From BashSupport with Apache License 2.0 6 votes vote down vote up
public BashIncludeCommandStub createStub(@NotNull BashIncludeCommand psi, StubElement parentStub) {
    BashFileReference fileReference = psi.getFileReference();

    String filename = null;
    String includer = null;

    if (fileReference != null && fileReference.isStatic()) {
        filename = fileReference.getFilename();
        if (filename.contains("/") && !filename.endsWith("/")) {
            int index = filename.lastIndexOf("/");
            filename = filename.substring(index + 1);
        }

        VirtualFile virtualFile = psi.getContainingFile().getUserData(IndexingDataKeys.VIRTUAL_FILE);
        if (virtualFile == null) {
            virtualFile = psi.getContainingFile().getViewProvider().getVirtualFile();
        }

        includer = virtualFile.getPath();
    }

    return new BashIncludeCommandStubImpl(parentStub, StringRef.fromString(filename), StringRef.fromString(includer), BashElementTypes.INCLUDE_COMMAND_ELEMENT);
}
 
Example #2
Source File: CoreStubTreeLoader.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
public ObjectStubTree readOrBuild(Project project, VirtualFile vFile, @Nullable PsiFile psiFile) {
  if (!canHaveStub(vFile)) {
    return null;
  }

  try {
    final FileContent fc = new FileContentImpl(vFile, vFile.contentsToByteArray());
    fc.putUserData(IndexingDataKeys.PROJECT, project);
    final Stub element = StubTreeBuilder.buildStubTree(fc);
    if (element instanceof PsiFileStub) {
      return new StubTree((PsiFileStub)element);
    }
  }
  catch (IOException e) {
    throw new RuntimeException(e);
  }

  return null;
}
 
Example #3
Source File: CSharpFileStubElementType.java    From consulo-csharp with Apache License 2.0 5 votes vote down vote up
@Nonnull
@RequiredReadAction
public static Set<String> getStableDefines(@Nonnull PsiFile psi)
{
	FileViewProvider viewProvider = psi.getViewProvider();
	VirtualFile virtualFile = viewProvider.getVirtualFile();
	if(virtualFile instanceof LightVirtualFile)
	{
		virtualFile = ((LightVirtualFile) virtualFile).getOriginalFile();
		// we need call second time, due second original file will be light
		if(virtualFile instanceof LightVirtualFile)
		{
			virtualFile = ((LightVirtualFile) virtualFile).getOriginalFile();
		}
	}
	if(virtualFile == null)
	{
		virtualFile = psi.getUserData(IndexingDataKeys.VIRTUAL_FILE);
	}

	Set<String> defVariables = Collections.emptySet();
	if(virtualFile != null)
	{
		List<String> variables = findVariables(virtualFile, psi.getProject());

		if(variables != null)
		{
			defVariables = new HashSet<>(variables);
		}
	}
	return defVariables;
}
 
Example #4
Source File: HaxeSourceRootModel.java    From intellij-haxe with Apache License 2.0 5 votes vote down vote up
public boolean contains(PsiFileSystemItem file) {
  if (this == DUMMY) return false;

  VirtualFile virtualFile = file.getVirtualFile();
  if (virtualFile == null) {
    virtualFile = file.getOriginalElement().getContainingFile().getVirtualFile();
  }
  if (virtualFile == null) {
    virtualFile = file.getUserData(IndexingDataKeys.VIRTUAL_FILE);
  }

  return virtualFile != null && (virtualFile.getCanonicalPath() + '/').startsWith(root.getCanonicalPath() + '/');
}
 
Example #5
Source File: StubTextInconsistencyException.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
private static List<PsiFileStub> restoreStubsFromText(FileViewProvider viewProvider) {
  FileContentImpl fc = new FileContentImpl(viewProvider.getVirtualFile(), viewProvider.getContents(), 0);
  fc.putUserData(IndexingDataKeys.PROJECT, viewProvider.getManager().getProject());
  PsiFileStubImpl copyTree = (PsiFileStubImpl)StubTreeBuilder.buildStubTree(fc);
  return copyTree == null ? Collections.emptyList() : Arrays.asList(copyTree.getStubRoots());
}
 
Example #6
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;
  }
}