use of com.intellij.psi.impl.source.DummyHolder 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;
}
use of com.intellij.psi.impl.source.DummyHolder 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;
}
use of com.intellij.psi.impl.source.DummyHolder in project intellij-community by JetBrains.
the class JavaResolveUtil method resolveImaginarySuperCallInThisPlace.
/**
* @return the constructor (or a class if there are none)
* which the "{@code super();}" no-args call resolves to if inserted in the {@code place} (typically it would be inserted in the sub class constructor)
* No code modifications happen in this method; it's used for resolving multiple overloaded constructors.
*/
public static PsiElement resolveImaginarySuperCallInThisPlace(@NotNull PsiMember place, @NotNull Project project, @NotNull PsiClass superClassWhichTheSuperCallMustResolveTo) {
PsiExpressionListImpl expressionList = new PsiExpressionListImpl();
final DummyHolder result = DummyHolderFactory.createHolder(PsiManager.getInstance(project), place);
final FileElement holder = result.getTreeElement();
holder.rawAddChildren((TreeElement) expressionList.getNode());
return PsiResolveHelper.SERVICE.getInstance(project).resolveConstructor(PsiTypesUtil.getClassType(superClassWhichTheSuperCallMustResolveTo), expressionList, place).getElement();
}
use of com.intellij.psi.impl.source.DummyHolder in project intellij-community by JetBrains.
the class JavaSourceUtil method addParenthToReplacedChild.
public static TreeElement addParenthToReplacedChild(@NotNull IElementType parenthType, @NotNull TreeElement newChild, @NotNull PsiManager manager) {
CompositeElement parenthExpr = ASTFactory.composite(parenthType);
TreeElement dummyExpr = (TreeElement) newChild.clone();
final CharTable charTableByTree = SharedImplUtil.findCharTableByTree(newChild);
new DummyHolder(manager, parenthExpr, null, charTableByTree);
parenthExpr.putUserData(CharTable.CHAR_TABLE_KEY, charTableByTree);
parenthExpr.rawAddChildren(ASTFactory.leaf(JavaTokenType.LPARENTH, "("));
parenthExpr.rawAddChildren(dummyExpr);
parenthExpr.rawAddChildren(ASTFactory.leaf(JavaTokenType.RPARENTH, ")"));
try {
CodeStyleManager codeStyleManager = CodeStyleManager.getInstance(manager.getProject());
PsiElement formatted = codeStyleManager.reformat(SourceTreeToPsiMap.treeToPsiNotNull(parenthExpr));
parenthExpr = (CompositeElement) SourceTreeToPsiMap.psiToTreeNotNull(formatted);
} catch (IncorrectOperationException e) {
// should not happen
LOG.error(e);
}
newChild.putUserData(CharTable.CHAR_TABLE_KEY, SharedImplUtil.findCharTableByTree(newChild));
dummyExpr.getTreeParent().replaceChild(dummyExpr, newChild);
// TODO remove explicit caches drop since this should be ok if we will use ChangeUtil for the modification
TreeUtil.clearCaches(TreeUtil.getFileElement(parenthExpr));
return parenthExpr;
}
use of com.intellij.psi.impl.source.DummyHolder 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;
}
Aggregations