use of org.jetbrains.plugins.groovy.lang.psi.api.toplevel.GrTopStatement in project intellij-community by JetBrains.
the class GroovyPsiElementFactoryImpl method createReferenceExpressionFromText.
@NotNull
@Override
public GrReferenceExpression createReferenceExpressionFromText(@NotNull String idText) {
PsiFile file = createGroovyFileChecked(idText);
final GrTopStatement[] statements = ((GroovyFileBase) file).getTopStatements();
if (!(statements.length == 1 && statements[0] instanceof GrReferenceExpression))
throw new IncorrectOperationException(idText);
return (GrReferenceExpression) statements[0];
}
use of org.jetbrains.plugins.groovy.lang.psi.api.toplevel.GrTopStatement in project intellij-community by JetBrains.
the class GroovyPsiElementFactoryImpl method createReferenceNameFromText.
@Override
@NotNull
public PsiElement createReferenceNameFromText(@NotNull String refName) {
PsiFile file = createGroovyFileChecked("a." + refName);
GrTopStatement statement = ((GroovyFileBase) file).getTopStatements()[0];
if (!(statement instanceof GrReferenceExpression)) {
throw new IncorrectOperationException("Incorrect reference name: " + refName);
}
final PsiElement element = ((GrReferenceExpression) statement).getReferenceNameElement();
if (element == null) {
throw new IncorrectOperationException("Incorrect reference name: " + refName);
}
return element;
}
use of org.jetbrains.plugins.groovy.lang.psi.api.toplevel.GrTopStatement in project intellij-community by JetBrains.
the class GroovyCodeStyleManagerImpl method removeImport.
@Override
public void removeImport(@NotNull GroovyFileBase psiFile, @NotNull GrImportStatement importStatement) throws IncorrectOperationException {
PsiElement psiElement = psiFile;
PsiElement before = importStatement;
while (PsiImplUtil.isWhiteSpaceOrNls(before.getPrevSibling())) {
before = before.getPrevSibling();
}
if (PsiImplUtil.hasElementType(before.getPrevSibling(), GroovyTokenTypes.mSEMI))
before = before.getPrevSibling();
if (PsiImplUtil.isWhiteSpaceOrNls(before.getPrevSibling()))
before = before.getPrevSibling();
PsiElement after = importStatement;
if (PsiImplUtil.isWhiteSpaceOrNls(after.getNextSibling()))
after = after.getNextSibling();
if (PsiImplUtil.hasElementType(after.getNextSibling(), GroovyTokenTypes.mSEMI))
after = after.getNextSibling();
while (PsiImplUtil.isWhiteSpaceOrNls(after.getNextSibling())) after = after.getNextSibling();
if (before == null)
before = importStatement;
PsiElement anchor_before = before.getPrevSibling();
PsiElement anchor_after = after.getNextSibling();
if (before == after) {
importStatement.delete();
} else {
psiFile.deleteChildRange(before, after);
}
if (anchor_before instanceof GrImportStatement && anchor_after instanceof GrImportStatement) {
addLineFeedAfter(psiFile, (GrImportStatement) anchor_before);
} else if (anchor_before != null && anchor_after != null) {
String text = anchor_after instanceof GrTopStatement && anchor_before instanceof GrTopStatement ? "\n\n" : "\n";
psiElement.getNode().addLeaf(GroovyTokenTypes.mNLS, text, anchor_after.getNode());
}
}
Aggregations