|
10 | 10 | import com.intellij.psi.PsiPolyVariantReferenceBase;
|
11 | 11 | import com.intellij.psi.ResolveResult;
|
12 | 12 | import com.intellij.util.ArrayUtilRt;
|
| 13 | +import java.util.Objects; |
13 | 14 | import nl.jrdie.idea.springql.icons.QLIcons;
|
14 | 15 | import nl.jrdie.idea.springql.svc.QLIdeService;
|
15 | 16 | import nl.jrdie.idea.springql.types.SchemaMappingSummary;
|
16 | 17 | import org.jetbrains.annotations.NotNull;
|
17 | 18 | import org.jetbrains.uast.UMethod;
|
18 | 19 | import org.jetbrains.uast.UastContextKt;
|
19 | 20 |
|
20 |
| -import java.util.Objects; |
21 |
| - |
22 | 21 | public class QLArgumentNamePolyReference extends PsiPolyVariantReferenceBase<PsiElement> {
|
23 | 22 |
|
24 |
| - public QLArgumentNamePolyReference(@NotNull PsiElement psiElement) { |
25 |
| - super(Objects.requireNonNull(psiElement, "element")); |
26 |
| - } |
27 |
| - |
28 |
| - @NotNull |
29 |
| - @Override |
30 |
| - public Object[] getVariants() { |
31 |
| - final UMethod uMethod = UastContextKt.getUastParentOfType(myElement, UMethod.class); |
32 |
| - if (uMethod == null) { |
33 |
| - return ArrayUtilRt.EMPTY_OBJECT_ARRAY; |
34 |
| - } |
| 23 | + public QLArgumentNamePolyReference(@NotNull PsiElement psiElement) { |
| 24 | + super(Objects.requireNonNull(psiElement, "element")); |
| 25 | + } |
35 | 26 |
|
36 |
| - final QLIdeService svc = myElement.getProject().getService(QLIdeService.class); |
37 |
| - final SchemaMappingSummary summary = svc.getSummaryForMethod(uMethod); |
38 |
| - if (summary == null) { |
39 |
| - return ArrayUtilRt.EMPTY_OBJECT_ARRAY; |
40 |
| - } |
| 27 | + @NotNull |
| 28 | + @Override |
| 29 | + public Object[] getVariants() { |
| 30 | + final UMethod uMethod = UastContextKt.getUastParentOfType(myElement, UMethod.class); |
| 31 | + if (uMethod == null) { |
| 32 | + return ArrayUtilRt.EMPTY_OBJECT_ARRAY; |
| 33 | + } |
41 | 34 |
|
42 |
| - final FieldDefinition fieldDefinition = svc.getSchemaRegistry() |
43 |
| - .getFieldDefinition(summary.getTypeName(), summary.getFieldName()); |
44 |
| - if (fieldDefinition == null) { |
45 |
| - return ArrayUtilRt.EMPTY_OBJECT_ARRAY; |
46 |
| - } |
| 35 | + final QLIdeService svc = myElement.getProject().getService(QLIdeService.class); |
| 36 | + final SchemaMappingSummary summary = svc.getSummaryForMethod(uMethod); |
| 37 | + if (summary == null) { |
| 38 | + return ArrayUtilRt.EMPTY_OBJECT_ARRAY; |
| 39 | + } |
47 | 40 |
|
48 |
| - return fieldDefinition |
49 |
| - .getInputValueDefinitions() |
50 |
| - .stream() |
51 |
| - .map(input -> LookupElementBuilder.create(input.getName()) |
52 |
| - .withTypeText(TypeUtil.simplePrint(input.getType())) |
53 |
| - .withPsiElement(input.getElement()) |
54 |
| - .withIcon(QLIcons.INSTANCE.getVariable())) |
55 |
| - .toArray(LookupElement[]::new); |
| 41 | + final FieldDefinition fieldDefinition = |
| 42 | + svc.getSchemaRegistry().getFieldDefinition(summary.getTypeName(), summary.getFieldName()); |
| 43 | + if (fieldDefinition == null) { |
| 44 | + return ArrayUtilRt.EMPTY_OBJECT_ARRAY; |
56 | 45 | }
|
57 | 46 |
|
58 |
| - @NotNull |
59 |
| - @Override |
60 |
| - public ResolveResult[] multiResolve(boolean incompleteCode) { |
61 |
| - final UMethod uMethod = UastContextKt.getUastParentOfType(myElement, UMethod.class); |
62 |
| - if (uMethod == null) { |
63 |
| - return ResolveResult.EMPTY_ARRAY; |
64 |
| - } |
| 47 | + return fieldDefinition.getInputValueDefinitions().stream() |
| 48 | + .map( |
| 49 | + input -> |
| 50 | + LookupElementBuilder.create(input.getName()) |
| 51 | + .withTypeText(TypeUtil.simplePrint(input.getType())) |
| 52 | + .withPsiElement(input.getElement()) |
| 53 | + .withIcon(QLIcons.INSTANCE.getVariable())) |
| 54 | + .toArray(LookupElement[]::new); |
| 55 | + } |
65 | 56 |
|
66 |
| - final QLIdeService svc = myElement.getProject().getService(QLIdeService.class); |
67 |
| - final SchemaMappingSummary summary = svc.getSummaryForMethod(uMethod); |
68 |
| - if (summary == null) { |
69 |
| - return ResolveResult.EMPTY_ARRAY; |
70 |
| - } |
| 57 | + @NotNull |
| 58 | + @Override |
| 59 | + public ResolveResult[] multiResolve(boolean incompleteCode) { |
| 60 | + final UMethod uMethod = UastContextKt.getUastParentOfType(myElement, UMethod.class); |
| 61 | + if (uMethod == null) { |
| 62 | + return ResolveResult.EMPTY_ARRAY; |
| 63 | + } |
71 | 64 |
|
72 |
| - final FieldDefinition fieldDefinition = svc.getSchemaRegistry() |
73 |
| - .getFieldDefinition(summary.getTypeName(), summary.getFieldName()); |
74 |
| - if (fieldDefinition == null) { |
75 |
| - return ResolveResult.EMPTY_ARRAY; |
76 |
| - } |
| 65 | + final QLIdeService svc = myElement.getProject().getService(QLIdeService.class); |
| 66 | + final SchemaMappingSummary summary = svc.getSummaryForMethod(uMethod); |
| 67 | + if (summary == null) { |
| 68 | + return ResolveResult.EMPTY_ARRAY; |
| 69 | + } |
77 | 70 |
|
78 |
| - return fieldDefinition |
79 |
| - .getInputValueDefinitions() |
80 |
| - .stream() |
81 |
| - .map(AbstractNode::getElement) |
82 |
| - .filter(Objects::nonNull) |
83 |
| - .map(PsiElementResolveResult::new) |
84 |
| - .toArray(ResolveResult[]::new); |
| 71 | + final FieldDefinition fieldDefinition = |
| 72 | + svc.getSchemaRegistry().getFieldDefinition(summary.getTypeName(), summary.getFieldName()); |
| 73 | + if (fieldDefinition == null) { |
| 74 | + return ResolveResult.EMPTY_ARRAY; |
85 | 75 | }
|
| 76 | + |
| 77 | + return fieldDefinition.getInputValueDefinitions().stream() |
| 78 | + .map(AbstractNode::getElement) |
| 79 | + .filter(Objects::nonNull) |
| 80 | + .map(PsiElementResolveResult::new) |
| 81 | + .toArray(ResolveResult[]::new); |
| 82 | + } |
86 | 83 | }
|
0 commit comments