use of com.intellij.psi.impl.source.PsiFileImpl in project intellij-community by JetBrains.
the class BlockSupportImpl method reparseRange.
@Override
@NotNull
public DiffLog reparseRange(@NotNull final PsiFile file, @NotNull FileASTNode oldFileNode, @NotNull TextRange changedPsiRange, @NotNull final CharSequence newFileText, @NotNull final ProgressIndicator indicator, @NotNull CharSequence lastCommittedText) {
final PsiFileImpl fileImpl = (PsiFileImpl) file;
final Couple<ASTNode> reparseableRoots = findReparseableRoots(fileImpl, oldFileNode, changedPsiRange, newFileText);
return reparseableRoots != null ? mergeTrees(fileImpl, reparseableRoots.first, reparseableRoots.second, indicator, lastCommittedText) : makeFullParse(fileImpl, oldFileNode, newFileText, indicator, lastCommittedText);
}
use of com.intellij.psi.impl.source.PsiFileImpl in project intellij-community by JetBrains.
the class StubProcessingHelperBase method processStubsInFile.
public <Psi extends PsiElement> boolean processStubsInFile(@NotNull final Project project, @NotNull final VirtualFile file, @NotNull StubIdList value, @NotNull final Processor<? super Psi> processor, @NotNull Class<Psi> requiredClass, final boolean skipOnErrors) {
StubTree stubTree = null;
PsiFile candidatePsiFile = PsiManager.getInstance(project).findFile(file);
PsiFileWithStubSupport psiFile = null;
boolean customStubs = false;
if (candidatePsiFile != null && !(candidatePsiFile instanceof PsiPlainTextFile)) {
final FileViewProvider viewProvider = candidatePsiFile.getViewProvider();
final PsiFile stubBindingRoot = viewProvider.getStubBindingRoot();
if (stubBindingRoot instanceof PsiFileWithStubSupport) {
psiFile = (PsiFileWithStubSupport) stubBindingRoot;
stubTree = psiFile.getStubTree();
if (stubTree == null && psiFile instanceof PsiFileImpl) {
IStubFileElementType elementType = ((PsiFileImpl) psiFile).getElementTypeForStubBuilder();
if (elementType != null) {
stubTree = ((PsiFileImpl) psiFile).calcStubTree();
} else {
customStubs = true;
if (BinaryFileStubBuilders.INSTANCE.forFileType(psiFile.getFileType()) == null) {
LOG.error("unable to get stub builder for " + psiFile.getFileType() + ", " + StubTreeLoader.getFileViewProviderMismatchDiagnostics(viewProvider));
}
}
}
}
}
if (stubTree == null && psiFile == null) {
return true;
}
if (stubTree == null) {
ObjectStubTree objectStubTree = StubTreeLoader.getInstance().readFromVFile(project, file);
if (objectStubTree == null) {
return true;
}
if (customStubs && !(objectStubTree instanceof StubTree)) {
if (!skipOnErrors && !requiredClass.isInstance(psiFile)) {
inconsistencyDetected(objectStubTree, psiFile);
return true;
}
// e.g. dom indices
return processor.process((Psi) psiFile);
}
stubTree = (StubTree) objectStubTree;
final List<StubElement<?>> plained = stubTree.getPlainListFromAllRoots();
for (int i = 0, size = value.size(); i < size; i++) {
final int stubTreeIndex = value.get(i);
if (stubTreeIndex >= plained.size()) {
if (!skipOnErrors)
onInternalError(file);
break;
}
final StubElement<?> stub = plained.get(stubTreeIndex);
PsiUtilCore.ensureValid(psiFile);
final ASTNode tree = psiFile.findTreeForStub(stubTree, stub);
if (tree != null) {
if (tree.getElementType() == stubType(stub)) {
Psi psi = (Psi) tree.getPsi();
PsiUtilCore.ensureValid(psi);
if (!skipOnErrors && !requiredClass.isInstance(psi)) {
inconsistencyDetected(stubTree, psiFile);
break;
}
if (!processor.process(psi))
return false;
} else if (!skipOnErrors) {
String persistedStubTree = ((PsiFileStubImpl) stubTree.getRoot()).printTree();
String stubTreeJustBuilt = ((PsiFileStubImpl) ((PsiFileImpl) psiFile).getElementTypeForStubBuilder().getBuilder().buildStubTree(psiFile)).printTree();
StringBuilder builder = new StringBuilder();
builder.append("Oops\n");
builder.append("Recorded stub:-----------------------------------\n");
builder.append(persistedStubTree);
builder.append("\nAST built stub: ------------------------------------\n");
builder.append(stubTreeJustBuilt);
builder.append("\n");
LOG.info(builder.toString());
onInternalError(file);
}
}
}
} else {
final List<StubElement<?>> plained = stubTree.getPlainListFromAllRoots();
for (int i = 0, size = value.size(); i < size; i++) {
final int stubTreeIndex = value.get(i);
if (stubTreeIndex >= plained.size()) {
if (!skipOnErrors) {
inconsistencyDetected(stubTree, psiFile);
}
break;
}
Psi psi = (Psi) plained.get(stubTreeIndex).getPsi();
PsiUtilCore.ensureValid(psi);
if (!skipOnErrors && !requiredClass.isInstance(psi)) {
inconsistencyDetected(stubTree, psiFile);
break;
}
if (!processor.process(psi))
return false;
}
}
return true;
}
use of com.intellij.psi.impl.source.PsiFileImpl in project intellij-community by JetBrains.
the class LowLevelSearchUtil method diagnoseInvalidRange.
private static void diagnoseInvalidRange(@NotNull PsiElement scope, PsiFile file, FileViewProvider viewProvider, CharSequence buffer, TextRange range) {
String msg = "Range for element: '" + scope + "' = " + range + " is out of file '" + file + "' range: " + file.getTextRange();
msg += "; file contents length: " + buffer.length();
msg += "\n file provider: " + viewProvider;
Document document = viewProvider.getDocument();
if (document != null) {
msg += "\n committed=" + PsiDocumentManager.getInstance(file.getProject()).isCommitted(document);
}
for (Language language : viewProvider.getLanguages()) {
final PsiFile root = viewProvider.getPsi(language);
msg += "\n root " + language + " length=" + root.getTextLength() + (root instanceof PsiFileImpl ? "; contentsLoaded=" + ((PsiFileImpl) root).isContentsLoaded() : "");
}
LOG.error(msg);
}
use of com.intellij.psi.impl.source.PsiFileImpl in project intellij-community by JetBrains.
the class PatternCompiler method compilePattern.
public static CompiledPattern compilePattern(final Project project, final MatchOptions options) throws MalformedPatternException, UnsupportedOperationException {
FileType fileType = options.getFileType();
assert fileType instanceof LanguageFileType;
Language language = ((LanguageFileType) fileType).getLanguage();
StructuralSearchProfile profile = StructuralSearchUtil.getProfileByLanguage(language);
assert profile != null;
CompiledPattern result = profile.createCompiledPattern();
final String[] prefixes = result.getTypedVarPrefixes();
assert prefixes.length > 0;
final CompileContext context = new CompileContext();
if (ApplicationManager.getApplication().isUnitTestMode())
lastTestingContext = context;
try {
context.init(result, options, project, options.getScope() instanceof GlobalSearchScope);
List<PsiElement> elements = compileByAllPrefixes(project, options, result, context, prefixes);
final CompiledPattern pattern = context.getPattern();
checkForUnknownVariables(pattern, elements);
pattern.setNodes(elements);
if (context.getSearchHelper().doOptimizing() && context.getSearchHelper().isScannedSomething()) {
final Set<PsiFile> set = context.getSearchHelper().getFilesSetToScan();
final List<PsiFile> filesToScan = new ArrayList<>(set.size());
final GlobalSearchScope scope = (GlobalSearchScope) options.getScope();
for (final PsiFile file : set) {
if (!scope.contains(file.getVirtualFile())) {
continue;
}
if (file instanceof PsiFileImpl) {
((PsiFileImpl) file).clearCaches();
}
filesToScan.add(file);
}
if (filesToScan.size() == 0) {
throw new MalformedPatternException(SSRBundle.message("ssr.will.not.find.anything"));
}
result.setScope(new LocalSearchScope(PsiUtilCore.toPsiElementArray(filesToScan)));
}
} finally {
context.clear();
}
return result;
}
use of com.intellij.psi.impl.source.PsiFileImpl in project intellij-community by JetBrains.
the class AnchorRepository method restoreFromStubIndex.
private static PsiElement restoreFromStubIndex(PsiFileWithStubSupport fileImpl, int index) {
StubTree tree = fileImpl.getStubTree();
if (tree == null) {
if (fileImpl instanceof PsiFileImpl) {
tree = ((PsiFileImpl) fileImpl).calcStubTree();
} else {
return null;
}
}
List<StubElement<?>> list = tree.getPlainList();
if (index >= list.size()) {
return null;
}
return ((StubElement) list.get(index)).getPsi();
}
Aggregations