本文整理匯總了Java中com.intellij.psi.FileViewProvider.getStubBindingRoot方法的典型用法代碼示例。如果您正苦於以下問題:Java FileViewProvider.getStubBindingRoot方法的具體用法?Java FileViewProvider.getStubBindingRoot怎麽用?Java FileViewProvider.getStubBindingRoot使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.intellij.psi.FileViewProvider
的用法示例。
在下文中一共展示了FileViewProvider.getStubBindingRoot方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getStubbedRoots
import com.intellij.psi.FileViewProvider; //導入方法依賴的package包/類
/** Order is deterministic. First element matches {@link FileViewProvider#getStubBindingRoot()} */
@NotNull
public static List<Pair<IStubFileElementType, PsiFile>> getStubbedRoots(@NotNull FileViewProvider viewProvider) {
final List<Trinity<Language, IStubFileElementType, PsiFile>> roots =
new SmartList<Trinity<Language, IStubFileElementType, PsiFile>>();
final PsiFile stubBindingRoot = viewProvider.getStubBindingRoot();
for (Language language : viewProvider.getLanguages()) {
final PsiFile file = viewProvider.getPsi(language);
if (file instanceof PsiFileImpl) {
final IElementType type = ((PsiFileImpl)file).getElementTypeForStubBuilder();
if (type != null) {
roots.add(Trinity.create(language, (IStubFileElementType)type, file));
}
}
}
ContainerUtil.sort(roots, new Comparator<Trinity<Language, IStubFileElementType, PsiFile>>() {
@Override
public int compare(Trinity<Language, IStubFileElementType, PsiFile> o1, Trinity<Language, IStubFileElementType, PsiFile> o2) {
if (o1.third == stubBindingRoot) return o2.third == stubBindingRoot ? 0 : -1;
else if (o2.third == stubBindingRoot) return 1;
else return StringUtil.compare(o1.first.getID(), o2.first.getID(), false);
}
});
return ContainerUtil.map(roots, new Function<Trinity<Language, IStubFileElementType, PsiFile>, Pair<IStubFileElementType, PsiFile>>() {
@Override
public Pair<IStubFileElementType, PsiFile> fun(Trinity<Language, IStubFileElementType, PsiFile> trinity) {
return Pair.create(trinity.second, trinity.third);
}
});
}
示例2: buildStubTree
import com.intellij.psi.FileViewProvider; //導入方法依賴的package包/類
@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;
}
}