|
8 | 8 | import fr.adrienbrault.idea.symfony2plugin.templating.util.TwigTypeResolveUtil; |
9 | 9 | import fr.adrienbrault.idea.symfony2plugin.util.completion.TwigTypeInsertHandler; |
10 | 10 | import org.jetbrains.annotations.NotNull; |
| 11 | +import org.jetbrains.annotations.Nullable; |
11 | 12 |
|
12 | 13 | /** |
13 | 14 | * @author Daniel Espendiller <daniel@espendiller.net> |
14 | 15 | */ |
15 | 16 | public class PhpTwigMethodLookupElement extends PhpLookupElement { |
| 17 | + @Nullable |
| 18 | + private String methodName; |
| 19 | + |
16 | 20 | PhpTwigMethodLookupElement(@NotNull PhpNamedElement namedElement) { |
17 | 21 | super(namedElement); |
| 22 | + |
| 23 | + if (namedElement instanceof Method method) { |
| 24 | + this.methodName = method.getName(); |
| 25 | + } |
18 | 26 | } |
19 | 27 |
|
20 | 28 | @Override |
21 | | - public void handleInsert(InsertionContext context) { |
| 29 | + public void handleInsert(@NotNull InsertionContext context) { |
22 | 30 | TwigTypeInsertHandler.getInstance().handleInsert(context, this); |
23 | 31 | } |
24 | 32 |
|
25 | 33 | @Override |
26 | | - public void renderElement(LookupElementPresentation presentation) { |
| 34 | + public void renderElement(@NotNull LookupElementPresentation presentation) { |
27 | 35 | super.renderElement(presentation); |
28 | 36 |
|
29 | | - PhpNamedElement phpNamedElement = this.getNamedElement(); |
30 | | - |
31 | 37 | // reset method to show full name again, which was stripped inside getLookupString |
32 | | - if(phpNamedElement instanceof Method && TwigTypeResolveUtil.isPropertyShortcutMethod((Method) phpNamedElement)) { |
33 | | - presentation.setItemText(phpNamedElement.getName()); |
| 38 | + if (methodName != null && TwigTypeResolveUtil.isPropertyShortcutMethod(methodName)) { |
| 39 | + presentation.setItemText(methodName); |
34 | 40 | } |
35 | | - |
36 | 41 | } |
37 | 42 |
|
38 | 43 | @NotNull |
39 | 44 | public String getLookupString() { |
40 | 45 | String lookupString = super.getLookupString(); |
41 | 46 |
|
42 | 47 | // remove property shortcuts eg getter / issers |
43 | | - if(this.getNamedElement() instanceof Method && TwigTypeResolveUtil.isPropertyShortcutMethod((Method) this.getNamedElement())) { |
44 | | - lookupString = TwigTypeResolveUtil.getPropertyShortcutMethodName((Method) this.getNamedElement()); |
| 48 | + if (methodName != null && TwigTypeResolveUtil.isPropertyShortcutMethod(methodName)) { |
| 49 | + lookupString = TwigTypeResolveUtil.getPropertyShortcutMethodName(methodName); |
45 | 50 | } |
46 | 51 |
|
47 | 52 | return lookupString; |
|
0 commit comments