Search in sources :

Example 21 with FileElement

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);
}
Also used : CommonCodeStyleSettings(com.intellij.psi.codeStyle.CommonCodeStyleSettings) FileElement(com.intellij.psi.impl.source.tree.FileElement) Block(com.intellij.formatting.Block) AbstractJavaBlock(com.intellij.psi.formatter.java.AbstractJavaBlock) JavaCodeStyleSettings(com.intellij.psi.codeStyle.JavaCodeStyleSettings) FormattingDocumentModelImpl(com.intellij.psi.formatter.FormattingDocumentModelImpl) PsiBasedFormatterModelWithShiftIndentInside(com.intellij.psi.impl.source.codeStyle.PsiBasedFormatterModelWithShiftIndentInside) NotNull(org.jetbrains.annotations.NotNull)

Example 22 with FileElement

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;
    }
}
Also used : FileElement(com.intellij.psi.impl.source.tree.FileElement) NotNull(org.jetbrains.annotations.NotNull)

Example 23 with 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;
}
Also used : FileElement(com.intellij.psi.impl.source.tree.FileElement)

Example 24 with FileElement

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);
    }
}
Also used : FileElement(com.intellij.psi.impl.source.tree.FileElement) ReplaceChangeInfoImpl(com.intellij.pom.tree.events.impl.ReplaceChangeInfoImpl)

Example 25 with FileElement

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();
}
Also used : Project(com.intellij.openapi.project.Project) Lexer(com.intellij.lexer.Lexer) DummyHolder(com.intellij.psi.impl.source.DummyHolder) FileElement(com.intellij.psi.impl.source.tree.FileElement) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

FileElement (com.intellij.psi.impl.source.tree.FileElement)33 NotNull (org.jetbrains.annotations.NotNull)10 ASTNode (com.intellij.lang.ASTNode)7 LightVirtualFile (com.intellij.testFramework.LightVirtualFile)6 PsiManagerEx (com.intellij.psi.impl.PsiManagerEx)5 FileManager (com.intellij.psi.impl.file.impl.FileManager)5 Project (com.intellij.openapi.project.Project)4 PsiFile (com.intellij.psi.PsiFile)4 PsiFileImpl (com.intellij.psi.impl.source.PsiFileImpl)4 SingleRootFileViewProvider (com.intellij.psi.SingleRootFileViewProvider)3 Nullable (org.jetbrains.annotations.Nullable)3 Lexer (com.intellij.lexer.Lexer)2 Disposable (com.intellij.openapi.Disposable)2 Document (com.intellij.openapi.editor.Document)2 ProcessCanceledException (com.intellij.openapi.progress.ProcessCanceledException)2 PomModel (com.intellij.pom.PomModel)2 PomTransactionBase (com.intellij.pom.impl.PomTransactionBase)2 GeneratedMarkerVisitor (com.intellij.psi.impl.GeneratedMarkerVisitor)2 DummyHolder (com.intellij.psi.impl.source.DummyHolder)2 LeafElement (com.intellij.psi.impl.source.tree.LeafElement)2