use of com.intellij.psi.impl.source.PsiFileImpl in project intellij-community by JetBrains.
the class TemplateDataElementType method parseContents.
@Override
public ASTNode parseContents(ASTNode chameleon) {
final CharTable charTable = SharedImplUtil.findCharTableByTree(chameleon);
final FileElement fileElement = TreeUtil.getFileElement((TreeElement) chameleon);
final PsiFile psiFile = (PsiFile) fileElement.getPsi();
PsiFile originalPsiFile = psiFile.getOriginalFile();
final TemplateLanguageFileViewProvider viewProvider = (TemplateLanguageFileViewProvider) originalPsiFile.getViewProvider();
final Language templateLanguage = getTemplateFileLanguage(viewProvider);
final CharSequence sourceCode = chameleon.getChars();
RangesCollector collector = new RangesCollector();
final PsiFile templatePsiFile = createTemplateFile(psiFile, templateLanguage, sourceCode, viewProvider, collector);
final FileElement templateFileElement = ((PsiFileImpl) templatePsiFile).calcTreeElement();
DebugUtil.startPsiModification("template language parsing");
try {
prepareParsedTemplateFile(templateFileElement);
insertOuters(templateFileElement, sourceCode, collector.myRanges, charTable);
TreeElement childNode = templateFileElement.getFirstChildNode();
DebugUtil.checkTreeStructure(templateFileElement);
DebugUtil.checkTreeStructure(chameleon);
if (fileElement != chameleon) {
DebugUtil.checkTreeStructure(psiFile.getNode());
DebugUtil.checkTreeStructure(originalPsiFile.getNode());
}
return childNode;
} finally {
DebugUtil.finishPsiModification();
}
}
use of com.intellij.psi.impl.source.PsiFileImpl in project intellij-community by JetBrains.
the class PomModelImpl method startTransaction.
private void startTransaction(@NotNull PomTransaction transaction) {
final ProgressIndicator progressIndicator = ProgressIndicatorProvider.getGlobalProgressIndicator();
if (progressIndicator != null)
progressIndicator.startNonCancelableSection();
final PsiDocumentManagerBase manager = (PsiDocumentManagerBase) PsiDocumentManager.getInstance(myProject);
final PsiToDocumentSynchronizer synchronizer = manager.getSynchronizer();
final PsiElement changeScope = transaction.getChangeScope();
final PsiFile containingFileByTree = getContainingFileByTree(changeScope);
if (containingFileByTree != null && !(containingFileByTree instanceof DummyHolder) && !manager.isCommitInProgress()) {
PsiUtilCore.ensureValid(containingFileByTree);
}
boolean physical = changeScope.isPhysical();
if (physical && synchronizer.toProcessPsiEvent()) {
// so it's important to throw something outside event processing
if (isDocumentUncommitted(containingFileByTree)) {
throw new IllegalStateException("Attempt to modify PSI for non-committed Document!");
}
CommandProcessor commandProcessor = CommandProcessor.getInstance();
if (!commandProcessor.isUndoTransparentActionInProgress() && commandProcessor.getCurrentCommand() == null) {
throw new IncorrectOperationException("Must not change PSI outside command or undo-transparent action. See com.intellij.openapi.command.WriteCommandAction or com.intellij.openapi.command.CommandProcessor");
}
}
if (containingFileByTree != null) {
((SmartPointerManagerImpl) SmartPointerManager.getInstance(myProject)).fastenBelts(containingFileByTree.getViewProvider().getVirtualFile());
if (containingFileByTree instanceof PsiFileImpl) {
((PsiFileImpl) containingFileByTree).beforeAstChange();
}
}
BlockSupportImpl.sendBeforeChildrenChangeEvent((PsiManagerImpl) PsiManager.getInstance(myProject), changeScope, true);
Document document = containingFileByTree == null ? null : physical ? manager.getDocument(containingFileByTree) : manager.getCachedDocument(containingFileByTree);
if (document != null) {
synchronizer.startTransaction(myProject, document, changeScope);
}
}
use of com.intellij.psi.impl.source.PsiFileImpl in project intellij-community by JetBrains.
the class StubBasedPsiElementBase method getNode.
/**
* Ensures this element is AST-based. This is an expensive operation that might take significant time and allocate lots of objects,
* so it should be to be avoided if possible.
*
* @return an AST node corresponding to this element. If the element is currently operating via stubs,
* this causes AST to be loaded for the whole file and all stub-based PSI elements in this file (including the current one)
* to be switched from stub to AST. So, after this call {@link #getStub()} will return null.
*/
@Override
@NotNull
public ASTNode getNode() {
if (mySubstrateRef instanceof SubstrateRef.StubRef) {
ApplicationManager.getApplication().assertReadAccessAllowed();
PsiFileImpl file = (PsiFileImpl) getContainingFile();
if (!file.isValid())
throw new PsiInvalidElementAccessException(this);
FileElement treeElement = file.getTreeElement();
if (treeElement != null && mySubstrateRef instanceof SubstrateRef.StubRef) {
return notBoundInExistingAst(file, treeElement);
}
treeElement = file.calcTreeElement();
if (mySubstrateRef instanceof SubstrateRef.StubRef) {
return failedToBindStubToAst(file, treeElement);
}
}
return mySubstrateRef.getNode();
}
use of com.intellij.psi.impl.source.PsiFileImpl in project intellij-community by JetBrains.
the class SmartPsiElementPointersTest method testCreatePointerDoesNotLoadPsiTree.
public void testCreatePointerDoesNotLoadPsiTree() throws IOException {
VirtualFile vfile = createChildData(myRoot, "X.java");
setFileText(vfile, "public class X { public int X; }");
PsiClass aClass = myJavaFacade.findClass("X", GlobalSearchScope.allScope(getProject()));
assertNotNull(aClass);
assertTrue(aClass.isValid());
PsiFileImpl file = (PsiFileImpl) aClass.getContainingFile();
assertTreeLoaded(file, false);
SmartPsiElementPointer p = createPointer(aClass);
assertNotNull(p);
assertTreeLoaded(file, false);
assertInstanceOf(p.getElement(), PsiClass.class);
assertTreeLoaded(file, false);
PsiDocumentManager documentManager = PsiDocumentManager.getInstance(myProject);
Document document = documentManager.getDocument(file);
insertString(document, 0, "/** asdasd */");
documentManager.commitAllDocuments();
// loaded tree
assertTreeLoaded(file, true);
assertInstanceOf(p.getElement(), PsiClass.class);
assertTreeLoaded(file, true);
}
use of com.intellij.psi.impl.source.PsiFileImpl in project intellij-community by JetBrains.
the class LightStubBuilder method buildStubTree.
@Override
public StubElement buildStubTree(@NotNull PsiFile file) {
LighterAST tree = FORCED_AST.get();
if (tree == null) {
FileType fileType = file.getFileType();
if (!(fileType instanceof LanguageFileType)) {
LOG.error("File is not of LanguageFileType: " + fileType + ", " + file);
return null;
}
assert file instanceof PsiFileImpl;
final IFileElementType contentType = ((PsiFileImpl) file).getElementTypeForStubBuilder();
if (contentType == null) {
LOG.error("File is not of IStubFileElementType: " + file);
return null;
}
final FileASTNode node = file.getNode();
if (node.getElementType() instanceof ILightStubFileElementType) {
tree = node.getLighterAST();
} else {
tree = new TreeBackedLighterAST(node);
}
} else {
FORCED_AST.set(null);
}
if (tree == null)
return null;
final StubElement rootStub = createStubForFile(file, tree);
buildStubTree(tree, tree.getRoot(), rootStub);
return rootStub;
}
Aggregations