|
24 | 24 | import com.jetbrains.python.impl.psi.PyUtil; |
25 | 25 | import consulo.language.editor.completion.lookup.InsertHandler; |
26 | 26 | import consulo.language.editor.completion.lookup.InsertionContext; |
| 27 | +import consulo.ui.annotation.RequiredUIAccess; |
27 | 28 |
|
28 | 29 | /** |
29 | 30 | * @author yole |
30 | 31 | */ |
31 | | -public class PyClassInsertHandler implements InsertHandler<LookupElement> |
32 | | -{ |
33 | | - public static PyClassInsertHandler INSTANCE = new PyClassInsertHandler(); |
| 32 | +public class PyClassInsertHandler implements InsertHandler<LookupElement> { |
| 33 | + public static PyClassInsertHandler INSTANCE = new PyClassInsertHandler(); |
34 | 34 |
|
35 | | - private PyClassInsertHandler() |
36 | | - { |
37 | | - } |
| 35 | + private PyClassInsertHandler() { |
| 36 | + } |
38 | 37 |
|
39 | | - public void handleInsert(InsertionContext context, LookupElement item) |
40 | | - { |
41 | | - Editor editor = context.getEditor(); |
42 | | - Document document = editor.getDocument(); |
43 | | - if(context.getCompletionChar() == '(') |
44 | | - { |
45 | | - context.setAddCompletionChar(false); |
46 | | - int offset = context.getTailOffset(); |
47 | | - document.insertString(offset, "()"); |
| 38 | + @Override |
| 39 | + @RequiredUIAccess |
| 40 | + public void handleInsert(InsertionContext context, LookupElement item) { |
| 41 | + Editor editor = context.getEditor(); |
| 42 | + Document document = editor.getDocument(); |
| 43 | + if (context.getCompletionChar() == '(') { |
| 44 | + context.setAddCompletionChar(false); |
| 45 | + int offset = context.getTailOffset(); |
| 46 | + document.insertString(offset, "()"); |
48 | 47 |
|
49 | | - PyClass pyClass = PyUtil.as(item.getPsiElement(), PyClass.class); |
50 | | - PyFunction init = pyClass != null ? pyClass.findInitOrNew(true, null) : null; |
51 | | - if(init != null && PyFunctionInsertHandler.hasParams(context, init)) |
52 | | - { |
53 | | - editor.getCaretModel().moveToOffset(offset + 1); |
54 | | - AutoPopupController.getInstance(context.getProject()).autoPopupParameterInfo(context.getEditor(), init); |
55 | | - } |
56 | | - else |
57 | | - { |
58 | | - editor.getCaretModel().moveToOffset(offset + 2); |
59 | | - } |
60 | | - } |
61 | | - } |
| 48 | + PyClass pyClass = PyUtil.as(item.getPsiElement(), PyClass.class); |
| 49 | + PyFunction init = pyClass != null ? pyClass.findInitOrNew(true, null) : null; |
| 50 | + if (init != null && PyFunctionInsertHandler.hasParams(context, init)) { |
| 51 | + editor.getCaretModel().moveToOffset(offset + 1); |
| 52 | + AutoPopupController.getInstance(context.getProject()).autoPopupParameterInfo(context.getEditor(), init); |
| 53 | + } |
| 54 | + else { |
| 55 | + editor.getCaretModel().moveToOffset(offset + 2); |
| 56 | + } |
| 57 | + } |
| 58 | + } |
62 | 59 | } |
0 commit comments