Java 类com.intellij.util.indexing.IndexingDataKeys 实例源码

项目:intellij-ce-playground    文件:PsiJavaFileBaseImpl.java   
private LanguageLevel getLanguageLevelInner() {
  if (myOriginalFile instanceof PsiJavaFile) {
    return ((PsiJavaFile)myOriginalFile).getLanguageLevel();
  }

  LanguageLevel forcedLanguageLevel = getUserData(PsiUtil.FILE_LANGUAGE_LEVEL_KEY);
  if (forcedLanguageLevel != null) return forcedLanguageLevel;

  VirtualFile virtualFile = getVirtualFile();
  if (virtualFile == null) virtualFile = getUserData(IndexingDataKeys.VIRTUAL_FILE);

  final Project project = getProject();
  if (virtualFile == null) {
    final PsiFile originalFile = getOriginalFile();
    if (originalFile instanceof PsiJavaFile && originalFile != this) {
      return ((PsiJavaFile)originalFile).getLanguageLevel();
    }
    return LanguageLevelProjectExtension.getInstance(project).getLanguageLevel();
  }

  return JavaPsiImplementationHelper.getInstance(project).getEffectiveLanguageLevel(virtualFile);
}
项目:intellij-ce-playground    文件:CoreStubTreeLoader.java   
@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;
}
项目:tools-idea    文件:CoreStubTreeLoader.java   
@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;
}
项目:consulo    文件:CoreStubTreeLoader.java   
@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;
}
项目:manifold-ij    文件:FileUtil.java   
public static VirtualFile toVirtualFile( PsiFile file )
{
  VirtualFile vfile = file.getUserData( IndexingDataKeys.VIRTUAL_FILE );
  if( vfile == null )
  {
    vfile = file.getVirtualFile();
    if( vfile == null )
    {
      vfile = file.getOriginalFile().getVirtualFile();
      if( vfile == null )
      {
        vfile = file.getViewProvider().getVirtualFile();
      }
    }
    else if( vfile instanceof LightVirtualFile )
    {
      PsiFile containingFile = file.getContainingFile();
      if( containingFile != null && containingFile != file )
      {
        PsiFile originalFile = containingFile.getOriginalFile();
        SmartPsiElementPointer owningFile = originalFile.getUserData( FileContextUtil.INJECTED_IN_ELEMENT );
        if( owningFile != null )
        {
          vfile = owningFile.getVirtualFile();
        }
      }
    }
  }
  return vfile;
}
项目:intellij-ce-playground    文件:PyFileImpl.java   
@Override
public LanguageLevel getLanguageLevel() {
  if (myOriginalFile != null) {
    return ((PyFileImpl)myOriginalFile).getLanguageLevel();
  }
  VirtualFile virtualFile = getVirtualFile();

  if (virtualFile == null) {
    virtualFile = getUserData(IndexingDataKeys.VIRTUAL_FILE);
  }
  if (virtualFile == null) {
    virtualFile = getViewProvider().getVirtualFile();
  }
  return PyUtil.getLanguageLevelForVirtualFile(getProject(), virtualFile);
}
项目:tools-idea    文件:PsiJavaFileBaseImpl.java   
private LanguageLevel getLanguageLevelInner() {
  if (myOriginalFile instanceof PsiJavaFile) {
    return ((PsiJavaFile)myOriginalFile).getLanguageLevel();
  }

  LanguageLevel forcedLanguageLevel = getUserData(PsiUtil.FILE_LANGUAGE_LEVEL_KEY);
  if (forcedLanguageLevel != null) return forcedLanguageLevel;

  VirtualFile virtualFile = getVirtualFile();
  if (virtualFile == null) virtualFile = getUserData(IndexingDataKeys.VIRTUAL_FILE);

  final Project project = getProject();
  if (virtualFile == null) {
    final PsiFile originalFile = getOriginalFile();
    if (originalFile instanceof PsiJavaFile && originalFile != this) {
      return ((PsiJavaFile)originalFile).getLanguageLevel();
    }
    return LanguageLevelProjectExtension.getInstance(project).getLanguageLevel();
  }

  final VirtualFile folder = virtualFile.getParent();
  if (folder != null) {
    final LanguageLevel level = folder.getUserData(LanguageLevel.KEY);
    if (level != null) return level;
  }

  final LanguageLevel classesLanguageLevel = JavaPsiImplementationHelper.getInstance(project).getClassesLanguageLevel(virtualFile);
  if (classesLanguageLevel != null) {
    return classesLanguageLevel;
  }

  return PsiUtil.getLanguageLevel(project);
}
项目:intellij-ce-playground    文件:StubTreeBuilder.java   
@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();
      FileContentImpl fileContent = (FileContentImpl)inputData;
      PsiFile psi = fileContent.getPsiFileForPsiDependentIndex();
      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.getLighterASTForPsiDependentIndex());
          }
          data = stubBuilder.buildStubTree(psi);

          final List<Pair<IStubFileElementType, PsiFile>> stubbedRoots = getStubbedRoots(viewProvider);
          final List<PsiFileStub> stubs = new ArrayList<PsiFileStub>(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);
            }
          }
          final PsiFileStub[] stubsArray = stubs.toArray(new PsiFileStub[stubs.size()]);
          for (PsiFileStub stub : stubsArray) {
            if (stub instanceof PsiFileStubImpl) {
              ((PsiFileStubImpl)stub).setStubRoots(stubsArray);
            }
          }
        }
      }
      finally {
        psi.putUserData(IndexingDataKeys.FILE_TEXT_CONTENT_KEY, null);
        psi.getManager().finishBatchFilesProcessingMode();
      }
    }

    inputData.putUserData(stubElementKey, data);
    return data;
  }
}
项目:tools-idea    文件:StubTreeBuilder.java   
@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 == null && !fileType.isBinary()) {
      final LanguageFileType languageFileType = (LanguageFileType)fileType;
      Language l = languageFileType.getLanguage();
      final IFileElementType type = LanguageParserDefinitions.INSTANCE.forLanguage(l).getFileNodeType();

      PsiFile psi = inputData.getPsiFile();
      psi = psi.getViewProvider().getStubBindingRoot();
      CharSequence contentAsText = inputData.getContentAsText();
      psi.putUserData(IndexingDataKeys.FILE_TEXT_CONTENT_KEY, contentAsText);

      try {
        if (type instanceof IStubFileElementType) {
          data = ((IStubFileElementType)type).getBuilder().buildStubTree(psi);
        }
        else if (languageFileType instanceof SubstitutedFileType) {
          SubstitutedFileType substituted = (SubstitutedFileType) languageFileType;
          LanguageFileType original = (LanguageFileType)substituted.getOriginalFileType();
          final IFileElementType originalType = LanguageParserDefinitions.INSTANCE.forLanguage(original.getLanguage()).getFileNodeType();
          if (originalType instanceof IStubFileElementType) {
            data = ((IStubFileElementType)originalType).getBuilder().buildStubTree(psi);
          }
        }
      }
      finally {
        psi.putUserData(IndexingDataKeys.FILE_TEXT_CONTENT_KEY, null);
      }
    }

    inputData.putUserData(stubElementKey, data);
    return data;
  }
}
项目:consulo-csharp    文件:CSharpFileStubElementType.java   
@RequiredReadAction
@Override
protected ASTNode doParseContents(@NotNull ASTNode chameleon, @NotNull PsiElement psi)
{
    final Project project = psi.getProject();
    final Language languageForParser = getLanguageForParser(psi);
    final LanguageVersion tempLanguageVersion = chameleon.getUserData(LanguageVersion.KEY);
    final CSharpLanguageVersionWrapper languageVersion = (CSharpLanguageVersionWrapper) (tempLanguageVersion == null ? psi.getLanguageVersion() : tempLanguageVersion);

    FileViewProvider viewProvider = ((PsiFile) 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, project);

        if(variables != null)
        {
            defVariables = new HashSet<>(variables);
        }
    }

    final PsiBuilder builder = PsiBuilderFactory.getInstance().createBuilder(project, chameleon, null, languageForParser, languageVersion, chameleon.getChars());
    builder.putUserData(PREPROCESSOR_VARIABLES, defVariables);

    final PsiParser parser = LanguageParserDefinitions.INSTANCE.forLanguage(languageForParser).createParser(languageVersion);
    return parser.parse(this, builder, languageVersion).getFirstChildNode();
}
项目:consulo    文件:StubTreeBuilder.java   
@Nullable
@RequiredReadAction
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();
      FileContentImpl fileContent = (FileContentImpl)inputData;
      PsiFile psi = fileContent.getPsiFileForPsiDependentIndex();
      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.getLighterASTForPsiDependentIndex());
          }
          data = stubBuilder.buildStubTree(psi);

          final List<Pair<IStubFileElementType, PsiFile>> stubbedRoots = getStubbedRoots(viewProvider);
          final List<PsiFileStub> stubs = new ArrayList<PsiFileStub>(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);
            }
          }
          final PsiFileStub[] stubsArray = stubs.toArray(new PsiFileStub[stubs.size()]);
          for (PsiFileStub stub : stubsArray) {
            if (stub instanceof PsiFileStubImpl) {
              ((PsiFileStubImpl)stub).setStubRoots(stubsArray);
            }
          }
        }
      }
      finally {
        psi.putUserData(IndexingDataKeys.FILE_TEXT_CONTENT_KEY, null);
        psi.getManager().finishBatchFilesProcessingMode();
      }
    }

    inputData.putUserData(stubElementKey, data);
    return data;
  }
}
项目:consulo-java    文件:PsiJavaFileBaseImpl.java   
private LanguageLevel getLanguageLevelInner()
{
    if(myOriginalFile instanceof PsiJavaFile)
    {
        return ((PsiJavaFile) myOriginalFile).getLanguageLevel();
    }
    final LanguageLevel forcedLanguageLevel = getUserData(PsiUtil.FILE_LANGUAGE_LEVEL_KEY);
    if(forcedLanguageLevel != null)
    {
        return forcedLanguageLevel;
    }
    VirtualFile virtualFile = getVirtualFile();

    if(virtualFile == null)
    {
        virtualFile = getUserData(IndexingDataKeys.VIRTUAL_FILE);
    }

    final Project project = getProject();
    if(virtualFile == null)
    {
        final PsiFile originalFile = getOriginalFile();
        if(originalFile instanceof PsiJavaFile && originalFile != this)
        {
            return ((PsiJavaFile) originalFile).getLanguageLevel();
        }

        final Module moduleForPsiElement = ModuleUtilCore.findModuleForPsiElement(originalFile);
        if(moduleForPsiElement != null)
        {
            return EffectiveLanguageLevelUtil.getEffectiveLanguageLevel(moduleForPsiElement);
        }
    }
    else
    {
        final VirtualFile folder = virtualFile.getParent();
        if(folder != null)
        {
            final LanguageLevel level = folder.getUserData(LanguageLevel.KEY);
            if(level != null)
            {
                return level;
            }
        }

        final LanguageLevel classesLanguageLevel = JavaPsiImplementationHelper.getInstance(project).getClassesLanguageLevel(virtualFile);
        if(classesLanguageLevel != null)
        {
            return classesLanguageLevel;
        }
    }
    return LanguageLevel.HIGHEST;
}