Search in sources :

Example 6 with DummyHolder

use of com.intellij.psi.impl.source.DummyHolder in project intellij-community by JetBrains.

the class PsiJavaParserFacadeImpl method createModuleFromText.

@NotNull
@Override
public PsiJavaModule createModuleFromText(@NotNull String text) throws IncorrectOperationException {
    DummyHolder holder = DummyHolderFactory.createHolder(myManager, new JavaDummyElement(text, MODULE, LanguageLevel.JDK_1_9), null);
    PsiElement element = SourceTreeToPsiMap.treeElementToPsi(holder.getTreeElement().getFirstChildNode());
    if (!(element instanceof PsiJavaModule))
        throw new IncorrectOperationException("Incorrect module declaration '" + text + "'");
    return (PsiJavaModule) element;
}
Also used : JavaDummyElement(com.intellij.psi.impl.source.JavaDummyElement) DummyHolder(com.intellij.psi.impl.source.DummyHolder) IncorrectOperationException(com.intellij.util.IncorrectOperationException) NotNull(org.jetbrains.annotations.NotNull)

Example 7 with DummyHolder

use of com.intellij.psi.impl.source.DummyHolder in project intellij-community by JetBrains.

the class PsiJavaParserFacadeImpl method createAnnotationFromText.

@NotNull
@Override
public PsiAnnotation createAnnotationFromText(@NotNull final String text, @Nullable final PsiElement context) throws IncorrectOperationException {
    final DummyHolder holder = DummyHolderFactory.createHolder(myManager, new JavaDummyElement(text, ANNOTATION, level(context)), context);
    final PsiElement element = SourceTreeToPsiMap.treeElementToPsi(holder.getTreeElement().getFirstChildNode());
    if (!(element instanceof PsiAnnotation)) {
        throw new IncorrectOperationException("Incorrect annotation '" + text + "'");
    }
    return (PsiAnnotation) element;
}
Also used : JavaDummyElement(com.intellij.psi.impl.source.JavaDummyElement) DummyHolder(com.intellij.psi.impl.source.DummyHolder) IncorrectOperationException(com.intellij.util.IncorrectOperationException) NotNull(org.jetbrains.annotations.NotNull)

Example 8 with DummyHolder

use of com.intellij.psi.impl.source.DummyHolder in project intellij-community by JetBrains.

the class PsiJavaParserFacadeImpl method createExpressionFromText.

@NotNull
@Override
public PsiExpression createExpressionFromText(@NotNull final String text, @Nullable final PsiElement context) throws IncorrectOperationException {
    final DummyHolder holder = DummyHolderFactory.createHolder(myManager, new JavaDummyElement(text, EXPRESSION, level(context)), context);
    final PsiElement element = SourceTreeToPsiMap.treeElementToPsi(holder.getTreeElement().getFirstChildNode());
    if (!(element instanceof PsiExpression)) {
        throw new IncorrectOperationException("Incorrect expression '" + text + "'");
    }
    return (PsiExpression) element;
}
Also used : JavaDummyElement(com.intellij.psi.impl.source.JavaDummyElement) DummyHolder(com.intellij.psi.impl.source.DummyHolder) IncorrectOperationException(com.intellij.util.IncorrectOperationException) NotNull(org.jetbrains.annotations.NotNull)

Example 9 with DummyHolder

use of com.intellij.psi.impl.source.DummyHolder in project intellij-community by JetBrains.

the class PsiJavaParserFacadeImpl method createStatementFromText.

@NotNull
@Override
public PsiStatement createStatementFromText(@NotNull final String text, @Nullable final PsiElement context) throws IncorrectOperationException {
    final DummyHolder holder = DummyHolderFactory.createHolder(myManager, new JavaDummyElement(text, STATEMENT, level(context)), context);
    final PsiElement element = SourceTreeToPsiMap.treeElementToPsi(holder.getTreeElement().getFirstChildNode());
    if (!(element instanceof PsiStatement)) {
        throw new IncorrectOperationException("Incorrect statement '" + text + "'");
    }
    return (PsiStatement) element;
}
Also used : JavaDummyElement(com.intellij.psi.impl.source.JavaDummyElement) DummyHolder(com.intellij.psi.impl.source.DummyHolder) IncorrectOperationException(com.intellij.util.IncorrectOperationException) NotNull(org.jetbrains.annotations.NotNull)

Example 10 with DummyHolder

use of com.intellij.psi.impl.source.DummyHolder in project intellij-community by JetBrains.

the class PsiJavaParserFacadeImpl method createReferenceFromText.

@NotNull
@Override
public PsiJavaCodeReferenceElement createReferenceFromText(@NotNull final String text, @Nullable final PsiElement context) throws IncorrectOperationException {
    final boolean isStaticImport = context instanceof PsiImportStaticStatement && !((PsiImportStaticStatement) context).isOnDemand();
    final boolean mayHaveDiamonds = context instanceof PsiNewExpression && PsiUtil.getLanguageLevel(context).isAtLeast(LanguageLevel.JDK_1_7);
    final JavaParserUtil.ParserWrapper wrapper = isStaticImport ? STATIC_IMPORT_REF : mayHaveDiamonds ? DIAMOND_REF : REFERENCE;
    final DummyHolder holder = DummyHolderFactory.createHolder(myManager, new JavaDummyElement(text, wrapper, level(context)), context);
    final PsiElement element = SourceTreeToPsiMap.treeElementToPsi(holder.getTreeElement().getFirstChildNode());
    if (!(element instanceof PsiJavaCodeReferenceElement)) {
        throw new IncorrectOperationException("Incorrect reference '" + text + "'");
    }
    return (PsiJavaCodeReferenceElement) element;
}
Also used : JavaDummyElement(com.intellij.psi.impl.source.JavaDummyElement) DummyHolder(com.intellij.psi.impl.source.DummyHolder) IncorrectOperationException(com.intellij.util.IncorrectOperationException) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

DummyHolder (com.intellij.psi.impl.source.DummyHolder)23 IncorrectOperationException (com.intellij.util.IncorrectOperationException)15 NotNull (org.jetbrains.annotations.NotNull)15 JavaDummyElement (com.intellij.psi.impl.source.JavaDummyElement)14 FileElement (com.intellij.psi.impl.source.tree.FileElement)3 ASTNode (com.intellij.lang.ASTNode)2 Project (com.intellij.openapi.project.Project)2 LanguageLevel (com.intellij.pom.java.LanguageLevel)2 PsiFileImpl (com.intellij.psi.impl.source.PsiFileImpl)2 CharTable (com.intellij.util.CharTable)2 Nullable (org.jetbrains.annotations.Nullable)2 FileASTNode (com.intellij.lang.FileASTNode)1 Language (com.intellij.lang.Language)1 PsiBuilder (com.intellij.lang.PsiBuilder)1 Lexer (com.intellij.lexer.Lexer)1 CommandProcessor (com.intellij.openapi.command.CommandProcessor)1 Document (com.intellij.openapi.editor.Document)1 FileType (com.intellij.openapi.fileTypes.FileType)1 PlainTextLanguage (com.intellij.openapi.fileTypes.PlainTextLanguage)1 EmptyProgressIndicator (com.intellij.openapi.progress.EmptyProgressIndicator)1