Search in sources :

Example 1 with GrSynchronizedStatement

use of org.jetbrains.plugins.groovy.lang.psi.api.statements.GrSynchronizedStatement in project intellij-community by JetBrains.

the class GrSynchronizedFixer method apply.

@Override
public void apply(@NotNull Editor editor, @NotNull GroovySmartEnterProcessor processor, @NotNull PsiElement psiElement) {
    GrSynchronizedStatement synchronizedStatement = PsiTreeUtil.getParentOfType(psiElement, GrSynchronizedStatement.class);
    if (synchronizedStatement == null || synchronizedStatement.getBody() != null)
        return;
    if (!PsiTreeUtil.isAncestor(synchronizedStatement.getMonitor(), psiElement, false))
        return;
    final Document doc = editor.getDocument();
    PsiElement eltToInsertAfter = synchronizedStatement.getRParenth();
    String text = "{\n}";
    if (eltToInsertAfter == null) {
        eltToInsertAfter = synchronizedStatement.getMonitor();
        text = "){\n}";
    }
    doc.insertString(eltToInsertAfter.getTextRange().getEndOffset(), text);
}
Also used : GrSynchronizedStatement(org.jetbrains.plugins.groovy.lang.psi.api.statements.GrSynchronizedStatement) Document(com.intellij.openapi.editor.Document) PsiElement(com.intellij.psi.PsiElement)

Example 2 with GrSynchronizedStatement

use of org.jetbrains.plugins.groovy.lang.psi.api.statements.GrSynchronizedStatement in project intellij-community by JetBrains.

the class GroovySynchronizedUnwrapper method doUnwrap.

@Override
protected void doUnwrap(PsiElement element, Context context) throws IncorrectOperationException {
    GrOpenBlock body = ((GrSynchronizedStatement) element).getBody();
    context.extractFromCodeBlock(body, element);
    context.delete(element);
}
Also used : GrSynchronizedStatement(org.jetbrains.plugins.groovy.lang.psi.api.statements.GrSynchronizedStatement) GrOpenBlock(org.jetbrains.plugins.groovy.lang.psi.api.statements.blocks.GrOpenBlock)

Aggregations

GrSynchronizedStatement (org.jetbrains.plugins.groovy.lang.psi.api.statements.GrSynchronizedStatement)2 Document (com.intellij.openapi.editor.Document)1 PsiElement (com.intellij.psi.PsiElement)1 GrOpenBlock (org.jetbrains.plugins.groovy.lang.psi.api.statements.blocks.GrOpenBlock)1