use of com.intellij.psi.impl.source.tree.FileElement in project intellij-community by JetBrains.
the class JavaFormattingModelBuilder method createModel.
@Override
@NotNull
public FormattingModel createModel(final PsiElement element, final CodeStyleSettings settings) {
final FileElement fileElement = TreeUtil.getFileElement((TreeElement) SourceTreeToPsiMap.psiElementToTree(element));
LOG.assertTrue(fileElement != null, "File element should not be null for " + element);
CommonCodeStyleSettings commonSettings = settings.getCommonSettings(JavaLanguage.INSTANCE);
JavaCodeStyleSettings customJavaSettings = settings.getCustomSettings(JavaCodeStyleSettings.class);
Block block = AbstractJavaBlock.newJavaBlock(fileElement, commonSettings, customJavaSettings);
FormattingDocumentModelImpl model = FormattingDocumentModelImpl.createOn(element.getContainingFile());
return new PsiBasedFormatterModelWithShiftIndentInside(element.getContainingFile(), block, model);
}
use of com.intellij.psi.impl.source.tree.FileElement in project intellij-community by JetBrains.
the class DummyHolder method getTreeElement.
@Override
@NotNull
public FileElement getTreeElement() {
FileElement fileElement = super.derefTreeElement();
if (fileElement != null)
return fileElement;
synchronized (myTreeElementLock) {
fileElement = super.derefTreeElement();
if (fileElement == null) {
fileElement = new FileElement(TokenType.DUMMY_HOLDER, null);
fileElement.setPsi(this);
if (myTable != null)
fileElement.setCharTable(myTable);
setTreeElementPointer(fileElement);
clearCaches();
}
return fileElement;
}
}
use of com.intellij.psi.impl.source.tree.FileElement in project intellij-community by JetBrains.
the class DummyHolder method clone.
@Override
@SuppressWarnings({ "CloneDoesntDeclareCloneNotSupportedException" })
protected PsiFileImpl clone() {
final PsiFileImpl psiClone = cloneImpl(getTreeElement());
final DummyHolderViewProvider dummyHolderViewProvider = new DummyHolderViewProvider(getManager());
myViewProvider = dummyHolderViewProvider;
dummyHolderViewProvider.setDummyHolder((DummyHolder) psiClone);
final FileElement treeClone = (FileElement) calcTreeElement().clone();
// should not use setTreeElement here because cloned file still have VirtualFile (SCR17963)
psiClone.setTreeElementPointer(treeClone);
psiClone.myOriginalFile = isPhysical() ? this : myOriginalFile;
treeClone.setPsi(psiClone);
return psiClone;
}
use of com.intellij.psi.impl.source.tree.FileElement in project intellij-community by JetBrains.
the class ASTDiffBuilder method nodeReplaced.
@Override
public void nodeReplaced(@NotNull ASTNode oldNode, @NotNull ASTNode newNode) {
if (oldNode instanceof FileElement && newNode instanceof FileElement) {
} else {
final ReplaceChangeInfoImpl change = new ReplaceChangeInfoImpl(newNode);
change.setReplaced(oldNode);
myEvent.addElementaryChange(newNode, change);
}
}
use of com.intellij.psi.impl.source.tree.FileElement in project intellij-community by JetBrains.
the class PsiFileFactoryImpl method createElementFromText.
@Nullable
public PsiElement createElementFromText(@Nullable final String text, @NotNull final Language language, @NotNull final IElementType type, @Nullable final PsiElement context) {
if (text == null)
return null;
final DummyHolder result = DummyHolderFactory.createHolder(myManager, language, context);
final FileElement holder = result.getTreeElement();
final ParserDefinition parserDefinition = LanguageParserDefinitions.INSTANCE.forLanguage(language);
if (parserDefinition == null) {
throw new AssertionError("No parser definition for " + language);
}
final Project project = myManager.getProject();
final Lexer lexer = parserDefinition.createLexer(project);
final PsiBuilder builder = PsiBuilderFactory.getInstance().createBuilder(project, holder, lexer, language, text);
final ASTNode node = parserDefinition.createParser(project).parse(type, builder);
holder.rawAddChildren((TreeElement) node);
markGenerated(result);
return node.getPsi();
}
Aggregations