use of com.intellij.psi.FileViewProvider in project intellij-community by JetBrains.
the class LanguageUtil method getRootLanguage.
@NotNull
public static Language getRootLanguage(@NotNull PsiElement element) {
final FileViewProvider provider = element.getContainingFile().getViewProvider();
final Set<Language> languages = provider.getLanguages();
if (languages.size() > 1) {
PsiElement current = element;
while (current != null) {
final Language language = current.getLanguage();
if (languages.contains(language))
return language;
current = current.getParent();
}
}
return provider.getBaseLanguage();
}
use of com.intellij.psi.FileViewProvider in project intellij-community by JetBrains.
the class PsiFileStubImpl method getStubRoots.
@NotNull
@Override
public PsiFileStub[] getStubRoots() {
if (myStubRoots != null)
return myStubRoots;
final T psi = getPsi();
if (psi == null) {
return new PsiFileStub[] { this };
}
final FileViewProvider viewProvider = psi.getViewProvider();
final PsiFile stubBindingRoot = viewProvider.getStubBindingRoot();
StubTree baseTree = getOrCalcStubTree(stubBindingRoot);
if (baseTree != null) {
final List<PsiFileStub> roots = new SmartList<>(baseTree.getRoot());
final List<Pair<IStubFileElementType, PsiFile>> stubbedRoots = StubTreeBuilder.getStubbedRoots(viewProvider);
for (Pair<IStubFileElementType, PsiFile> stubbedRoot : stubbedRoots) {
if (stubbedRoot.second == stubBindingRoot)
continue;
final StubTree secondaryStubTree = getOrCalcStubTree(stubbedRoot.second);
if (secondaryStubTree != null) {
final PsiFileStub root = secondaryStubTree.getRoot();
roots.add(root);
}
}
final PsiFileStub[] rootsArray = roots.toArray(new PsiFileStub[roots.size()]);
for (PsiFileStub root : rootsArray) {
if (root instanceof PsiFileStubImpl) {
((PsiFileStubImpl) root).setStubRoots(rootsArray);
}
}
myStubRoots = rootsArray;
return rootsArray;
}
return PsiFileStub.EMPTY_ARRAY;
}
use of com.intellij.psi.FileViewProvider in project intellij-community by JetBrains.
the class StubTreeBuilder method buildStubTree.
@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<>(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;
}
}
use of com.intellij.psi.FileViewProvider in project intellij-plugins by JetBrains.
the class CfmlCommenter method getCfmlElementAtOffset.
private static PsiElement getCfmlElementAtOffset(int offset, PsiFile file) {
final FileViewProvider fileViewProvider = file.getViewProvider();
file = fileViewProvider.getPsi(fileViewProvider.getBaseLanguage());
final Language cfmlLanguage = file.getLanguage();
return fileViewProvider.findElementAt(offset, cfmlLanguage);
}
use of com.intellij.psi.FileViewProvider in project intellij-plugins by JetBrains.
the class AngularJSIndexingHandler method createLiteralImplicitElementProvider.
@Override
public JSLiteralImplicitElementProvider createLiteralImplicitElementProvider(@NotNull final String command) {
return new JSLiteralImplicitElementProvider() {
@Override
public void fillIndexingData(@NotNull JSLiteralExpression argument, @NotNull JSCallExpression callExpression, @NotNull JSElementIndexingData outIndexingData) {
JSExpression[] arguments = callExpression.getArguments();
if (arguments.length == 0 || arguments[0] != argument)
return;
final JSExpression methodExpression = callExpression.getMethodExpression();
if (!(methodExpression instanceof JSReferenceExpression))
return;
JSExpression qualifier = ((JSReferenceExpression) methodExpression).getQualifier();
if (qualifier == null)
return;
final StubIndexKey<String, JSImplicitElementProvider> index = INDEXERS.get(command);
if (index != null) {
if (argument.isQuotedLiteral()) {
final Processor<JSArgumentList> argumentListProcessor = ARGUMENT_LIST_CHECKERS.get(command);
if (argumentListProcessor != null && !argumentListProcessor.process(callExpression.getArgumentList()))
return;
final Function<PsiElement, String> calculator = DATA_CALCULATORS.get(command);
final String data = calculator != null ? calculator.fun(argument) : null;
final String argumentText = unquote(argument);
addImplicitElements(argument, command, index, argumentText, data, outIndexingData);
}
} else if (INJECTABLE_METHODS.contains(command)) {
// INTERESTING_METHODS are contained in INJECTABLE_METHODS
if (argument.isQuotedLiteral()) {
generateNamespace(argument, outIndexingData);
}
}
if (START_SYMBOL.equals(command) || END_SYMBOL.equals(command)) {
while (qualifier != null) {
if (qualifier instanceof JSReferenceExpression) {
if ("$interpolateProvider".equals(((JSReferenceExpression) qualifier).getReferenceName())) {
if (argument.isQuotedLiteral()) {
String interpolation = unquote(argument);
// '//' interpolations are usually dragged from examples folder and not supposed to be used by real users
if ("//".equals(interpolation))
return;
FileViewProvider provider = qualifier.getContainingFile().getOriginalFile().getViewProvider();
VirtualFile virtualFile = provider.getVirtualFile();
virtualFile = virtualFile instanceof LightVirtualFile ? ((LightVirtualFile) virtualFile).getOriginalFile() : virtualFile;
if (JSLibraryUtil.isProbableLibraryFile(virtualFile))
return;
addImplicitElements(argument, null, AngularInjectionDelimiterIndex.KEY, command, interpolation, outIndexingData);
}
}
qualifier = ((JSReferenceExpression) qualifier).getQualifier();
} else {
qualifier = qualifier instanceof JSCallExpression ? ((JSCallExpression) qualifier).getMethodExpression() : null;
}
}
}
}
};
}
Aggregations