use of com.goide.psi.GoBlock in project go-lang-idea-plugin by go-lang-plugin-org.
the class GoWithBlockSurrounder method surroundStatements.
@Nullable
@Override
protected TextRange surroundStatements(@NotNull Project project, @NotNull PsiElement container, @NotNull PsiElement[] statements) throws IncorrectOperationException {
GoBlock block = GoElementFactory.createBlock(project);
PsiElement first = ArrayUtil.getFirstElement(statements);
PsiElement last = ArrayUtil.getLastElement(statements);
block = (GoBlock) container.addAfter(block, last);
block.addRangeAfter(first, last, block.getLbrace());
CodeEditUtil.markToReformat(block.getNode(), true);
container.deleteChildRange(first, last);
int offset = block.getTextRange().getEndOffset();
return new TextRange(offset, offset);
}
use of com.goide.psi.GoBlock in project go-lang-idea-plugin by go-lang-plugin-org.
the class GoAddFunctionBlockIntention method invoke.
@Override
public void invoke(@NotNull Project project, Editor editor, @NotNull PsiElement element) throws IncorrectOperationException {
PsiElement parent = element.getParent();
if (parent instanceof GoFunctionOrMethodDeclaration) {
GoBlock block = ((GoFunctionOrMethodDeclaration) parent).getBlock();
if (block == null) {
GoBlock newBlock = ObjectUtils.tryCast(parent.add(GoElementFactory.createBlock(project)), GoBlock.class);
if (newBlock != null) {
PsiDocumentManager.getInstance(project).doPostponedOperationsAndUnblockDocument(editor.getDocument());
new GoSmartEnterProcessor.PlainEnterProcessor().doEnter(newBlock, newBlock.getContainingFile(), editor, false);
}
}
}
}
Aggregations