use of com.intellij.psi.impl.source.DummyHolder in project intellij-community by JetBrains.
the class DtdParsing method parse.
public ASTNode parse() {
final PsiBuilder.Marker root = myBuilder.mark();
if (myRootType == XML_MARKUP_DECL) {
parseTopLevelMarkupDecl();
root.done(myRootType);
return myBuilder.getTreeBuilt();
}
PsiBuilder.Marker document = null;
if (myRootType == DTD_FILE) {
document = myBuilder.mark();
parseProlog();
}
switch(myContextType) {
case GENERIC_XML:
parseGenericXml();
break;
case ELEMENT_CONTENT_SPEC:
doParseContentSpec(true);
break;
case ATTLIST_SPEC:
parseAttlistContent();
break;
case ATTR_VALUE:
parseAttrValue();
case ATTRIBUTE_SPEC:
parseAttributeContentSpec();
break;
case ENTITY_DECL_CONTENT:
parseEntityDeclContent();
break;
case ENUMERATED_TYPE:
parseEnumeratedTypeContent();
break;
}
while (!myBuilder.eof()) myBuilder.advanceLexer();
if (document != null)
document.done(XML_DOCUMENT);
root.done(myRootType);
ASTNode astNode = myBuilder.getTreeBuilt();
if (myRootType != DTD_FILE) {
PsiFile file = myBuilder.getUserDataUnprotected(FileContextUtil.CONTAINING_FILE_KEY);
if (file != null) {
final DummyHolder result = DummyHolderFactory.createHolder(file.getManager(), DTDLanguage.INSTANCE, file);
final FileElement holder = result.getTreeElement();
holder.rawAddChildren((TreeElement) astNode);
}
}
return astNode;
}
use of com.intellij.psi.impl.source.DummyHolder 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.DummyHolder in project intellij-community by JetBrains.
the class BlockSupportImpl method makeFullParse.
@NotNull
private static DiffLog makeFullParse(@NotNull PsiFileImpl fileImpl, @NotNull FileASTNode oldFileNode, @NotNull CharSequence newFileText, @NotNull ProgressIndicator indicator, @NotNull CharSequence lastCommittedText) {
if (fileImpl instanceof PsiCodeFragment) {
FileElement parent = fileImpl.getTreeElement();
final FileElement holderElement = new DummyHolder(fileImpl.getManager(), fileImpl.getContext()).getTreeElement();
holderElement.rawAddChildren(fileImpl.createContentLeafElement(holderElement.getCharTable().intern(newFileText, 0, newFileText.length())));
DiffLog diffLog = new DiffLog();
diffLog.appendReplaceFileElement(parent, (FileElement) holderElement.getFirstChildNode());
return diffLog;
} else {
FileViewProvider viewProvider = fileImpl.getViewProvider();
viewProvider.getLanguages();
FileType fileType = viewProvider.getVirtualFile().getFileType();
String fileName = fileImpl.getName();
final LightVirtualFile lightFile = new LightVirtualFile(fileName, fileType, newFileText, viewProvider.getVirtualFile().getCharset(), fileImpl.getViewProvider().getModificationStamp());
lightFile.setOriginalFile(viewProvider.getVirtualFile());
FileViewProvider copy = viewProvider.createCopy(lightFile);
if (copy.isEventSystemEnabled()) {
throw new AssertionError("Copied view provider must be non-physical for reparse to deliver correct events: " + viewProvider);
}
copy.getLanguages();
// optimization: do not convert file contents to bytes to determine if we should codeinsight it
SingleRootFileViewProvider.doNotCheckFileSizeLimit(lightFile);
PsiFileImpl newFile = getFileCopy(fileImpl, copy);
newFile.setOriginalFile(fileImpl);
final FileElement newFileElement = (FileElement) newFile.getNode();
final FileElement oldFileElement = (FileElement) oldFileNode;
if (!lastCommittedText.toString().equals(oldFileElement.getText())) {
throw new IncorrectOperationException(viewProvider.toString());
}
DiffLog diffLog = mergeTrees(fileImpl, oldFileElement, newFileElement, indicator, lastCommittedText);
((PsiManagerEx) fileImpl.getManager()).getFileManager().setViewProvider(lightFile, null);
return diffLog;
}
}
use of com.intellij.psi.impl.source.DummyHolder in project intellij-community by JetBrains.
the class Factory method createSingleLeafElement.
@NotNull
public static LeafElement createSingleLeafElement(@NotNull IElementType type, CharSequence buffer, int startOffset, int endOffset, CharTable table, PsiManager manager, PsiFile originalFile) {
DummyHolder dummyHolder = DummyHolderFactory.createHolder(manager, table, type.getLanguage());
dummyHolder.setOriginalFile(originalFile);
FileElement holderElement = dummyHolder.getTreeElement();
LeafElement newElement = ASTFactory.leaf(type, holderElement.getCharTable().intern(buffer, startOffset, endOffset));
holderElement.rawAddChildren(newElement);
CodeEditUtil.setNodeGenerated(newElement, true);
return newElement;
}
use of com.intellij.psi.impl.source.DummyHolder in project intellij-community by JetBrains.
the class PsiJavaParserFacadeImpl method createMethodFromText.
@NotNull
@Override
public PsiMethod createMethodFromText(@NotNull final String text, @Nullable final PsiElement context, final LanguageLevel level) throws IncorrectOperationException {
final DummyHolder holder = DummyHolderFactory.createHolder(myManager, new JavaDummyElement(text, DECLARATION, level), context);
final PsiElement element = SourceTreeToPsiMap.treeElementToPsi(holder.getTreeElement().getFirstChildNode());
if (!(element instanceof PsiMethod)) {
throw newException("Incorrect method '" + text + "'", holder);
}
return (PsiMethod) element;
}
Aggregations