mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
synchronized fixer
This commit is contained in:
+13
-13
@@ -13,26 +13,25 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jetbrains.plugins.groovy.lang.completion.smartEnter.fixers
|
||||
package org.jetbrains.plugins.groovy.lang.completion.smartEnter.fixers;
|
||||
|
||||
import com.intellij.lang.SmartEnterProcessorWithFixers
|
||||
import com.intellij.openapi.editor.Document
|
||||
import com.intellij.openapi.editor.Editor
|
||||
import com.intellij.psi.PsiElement
|
||||
import com.intellij.psi.util.PsiTreeUtil
|
||||
import org.jetbrains.annotations.NotNull
|
||||
import org.jetbrains.plugins.groovy.lang.completion.smartEnter.GroovySmartEnterProcessor
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrSynchronizedStatement
|
||||
import com.intellij.lang.SmartEnterProcessorWithFixers;
|
||||
import com.intellij.openapi.editor.Document;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.plugins.groovy.lang.completion.smartEnter.GroovySmartEnterProcessor;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrSynchronizedStatement;
|
||||
|
||||
/**
|
||||
* @author Max Medvedev
|
||||
*/
|
||||
public class GrSynchronizedFixer extends SmartEnterProcessorWithFixers.Fixer<GroovySmartEnterProcessor> {
|
||||
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();
|
||||
@@ -41,6 +40,7 @@ public class GrSynchronizedFixer extends SmartEnterProcessorWithFixers.Fixer<Gro
|
||||
eltToInsertAfter = synchronizedStatement.getMonitor();
|
||||
text = "){\n}";
|
||||
}
|
||||
|
||||
doc.insertString(eltToInsertAfter.getTextRange().getEndOffset(), text);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user