Search in sources :

Example 16 with DummyHolder

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

the class PsiJavaParserFacadeImpl method createFieldFromText.

@NotNull
@Override
public PsiField createFieldFromText(@NotNull final String text, @Nullable final PsiElement context) throws IncorrectOperationException {
    final DummyHolder holder = DummyHolderFactory.createHolder(myManager, new JavaDummyElement(text, DECLARATION, level(context)), context);
    final PsiElement element = SourceTreeToPsiMap.treeElementToPsi(holder.getTreeElement().getFirstChildNode());
    if (!(element instanceof PsiField)) {
        throw new IncorrectOperationException("Incorrect field '" + text + "'");
    }
    return (PsiField) 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 17 with DummyHolder

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

the class PsiJavaParserFacadeImpl method createParameterFromText.

@NotNull
@Override
public PsiParameter createParameterFromText(@NotNull final String text, @Nullable final PsiElement context) throws IncorrectOperationException {
    final DummyHolder holder = DummyHolderFactory.createHolder(myManager, new JavaDummyElement(text, PARAMETER, level(context)), context);
    final PsiElement element = SourceTreeToPsiMap.treeElementToPsi(holder.getTreeElement().getFirstChildNode());
    if (!(element instanceof PsiParameter)) {
        throw new IncorrectOperationException("Incorrect parameter '" + text + "'");
    }
    return (PsiParameter) 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 18 with DummyHolder

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

the class PsiJavaParserFacadeImpl method createCodeBlockFromText.

@NotNull
@Override
public PsiCodeBlock createCodeBlockFromText(@NotNull final String text, @Nullable final PsiElement context) throws IncorrectOperationException {
    final DummyHolder holder = DummyHolderFactory.createHolder(myManager, new JavaDummyElement(text, CODE_BLOCK, level(context), true), context);
    final PsiElement element = SourceTreeToPsiMap.treeElementToPsi(holder.getTreeElement().getFirstChildNode());
    if (!(element instanceof PsiCodeBlock)) {
        throw new IncorrectOperationException("Incorrect code block '" + text + "'");
    }
    return (PsiCodeBlock) 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 19 with DummyHolder

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

the class PsiJavaParserFacadeImpl method createEnumConstantFromText.

@NotNull
@Override
public PsiEnumConstant createEnumConstantFromText(@NotNull final String text, @Nullable final PsiElement context) throws IncorrectOperationException {
    final DummyHolder holder = DummyHolderFactory.createHolder(myManager, new JavaDummyElement(text, ENUM_CONSTANT, level(context)), context);
    final PsiElement element = SourceTreeToPsiMap.treeElementToPsi(holder.getTreeElement().getFirstChildNode());
    if (!(element instanceof PsiEnumConstant)) {
        throw new IncorrectOperationException("Incorrect enum constant '" + text + "'");
    }
    return (PsiEnumConstant) 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 20 with DummyHolder

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

the class ClsParsingUtil method createMemberValueFromText.

public static PsiAnnotationMemberValue createMemberValueFromText(@NotNull String text, @NotNull PsiManager manager, @NotNull ClsElementImpl parent) {
    LanguageLevel level = PsiUtil.getLanguageLevel(parent);
    DummyHolder holder = DummyHolderFactory.createHolder(manager, new JavaDummyElement(text, ANNOTATION_VALUE, level), null);
    PsiElement element = SourceTreeToPsiMap.treeElementToPsi(holder.getTreeElement().getFirstChildNode());
    if (!(element instanceof PsiAnnotationMemberValue)) {
        LOG.error("Could not parse initializer:'" + text + "'");
        return null;
    }
    return getMemberValue(element, parent);
}
Also used : JavaDummyElement(com.intellij.psi.impl.source.JavaDummyElement) LanguageLevel(com.intellij.pom.java.LanguageLevel) DummyHolder(com.intellij.psi.impl.source.DummyHolder)

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