Search in sources :

Example 1 with JavaDummyElement

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

Example 2 with JavaDummyElement

use of com.intellij.psi.impl.source.JavaDummyElement 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 3 with JavaDummyElement

use of com.intellij.psi.impl.source.JavaDummyElement 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 4 with JavaDummyElement

use of com.intellij.psi.impl.source.JavaDummyElement 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 5 with JavaDummyElement

use of com.intellij.psi.impl.source.JavaDummyElement 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)

Aggregations

DummyHolder (com.intellij.psi.impl.source.DummyHolder)14 JavaDummyElement (com.intellij.psi.impl.source.JavaDummyElement)14 NotNull (org.jetbrains.annotations.NotNull)13 IncorrectOperationException (com.intellij.util.IncorrectOperationException)12 LanguageLevel (com.intellij.pom.java.LanguageLevel)2