Search in sources :

Example 6 with JavaDummyElement

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

Example 7 with JavaDummyElement

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

the class PsiJavaParserFacadeImpl method createTypeParameterFromText.

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

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

the class PsiJavaParserFacadeImpl method createTypeElementFromText.

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

Example 9 with JavaDummyElement

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

the class PsiJavaParserFacadeImpl method createResourceFromText.

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

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

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