@@ -61,39 +61,41 @@ public void provideCompletions(ASTNode node, Annotation annotation, ITypeBinding
61
61
62
62
// case: @Qualifier(<*>)
63
63
if (node == annotation && doc .get (offset - 1 , 2 ).endsWith ("()" )) {
64
- createCompletionProposals (project , doc , node , completions , offset , offset , "" , (beanName ) -> "\" " + beanName + "\" " );
64
+ createCompletionProposals (project , doc , node , "value" , completions , offset , offset , "" , (beanName ) -> "\" " + beanName + "\" " );
65
65
}
66
66
// case: @Qualifier(prefix<*>)
67
67
else if (node instanceof SimpleName && node .getParent () instanceof Annotation ) {
68
- computeProposalsForSimpleName (project , node , completions , offset , doc );
68
+ computeProposalsForSimpleName (project , node , "value" , completions , offset , doc );
69
69
}
70
70
// case: @Qualifier(value=<*>)
71
71
else if (node instanceof SimpleName && node .getParent () instanceof MemberValuePair
72
- && "value" .equals (((MemberValuePair )node .getParent ()).getName ().toString ())) {
73
- computeProposalsForSimpleName (project , node , completions , offset , doc );
72
+ && completionProviders .containsKey (((MemberValuePair )node .getParent ()).getName ().toString ())) {
73
+ String attributeName = ((MemberValuePair )node .getParent ()).getName ().toString ();
74
+ computeProposalsForSimpleName (project , node , attributeName , completions , offset , doc );
74
75
}
75
76
// case: @Qualifier("prefix<*>")
76
77
else if (node instanceof StringLiteral && node .getParent () instanceof Annotation ) {
77
78
if (node .toString ().startsWith ("\" " ) && node .toString ().endsWith ("\" " )) {
78
- computeProposalsForStringLiteral (project , node , completions , offset , doc );
79
+ computeProposalsForStringLiteral (project , node , "value" , completions , offset , doc );
79
80
}
80
81
}
81
82
// case: @Qualifier({"prefix<*>"})
82
83
else if (node instanceof StringLiteral && node .getParent () instanceof ArrayInitializer ) {
83
84
if (node .toString ().startsWith ("\" " ) && node .toString ().endsWith ("\" " )) {
84
- computeProposalsForInsideArrayInitializer (project , node , completions , offset , doc );
85
+ computeProposalsForInsideArrayInitializer (project , node , "value" , completions , offset , doc );
85
86
}
86
87
}
87
88
// case: @Qualifier(value="prefix<*>")
88
89
else if (node instanceof StringLiteral && node .getParent () instanceof MemberValuePair
89
- && "value" . equals (((MemberValuePair )node .getParent ()).getName ().toString ())) {
90
+ && completionProviders . containsKey (((MemberValuePair )node .getParent ()).getName ().toString ())) {
90
91
if (node .toString ().startsWith ("\" " ) && node .toString ().endsWith ("\" " )) {
91
- computeProposalsForStringLiteral (project , node , completions , offset , doc );
92
+ String attributeName = ((MemberValuePair )node .getParent ()).getName ().toString ();
93
+ computeProposalsForStringLiteral (project , node , attributeName , completions , offset , doc );
92
94
}
93
95
}
94
96
// case: @Qualifier({<*>})
95
97
else if (node instanceof ArrayInitializer && node .getParent () instanceof Annotation ) {
96
- computeProposalsForArrayInitializr (project , (ArrayInitializer ) node , completions , offset , doc );
98
+ computeProposalsForArrayInitializr (project , (ArrayInitializer ) node , "value" , completions , offset , doc );
97
99
}
98
100
}
99
101
catch (Exception e ) {
@@ -104,12 +106,12 @@ else if (node instanceof ArrayInitializer && node.getParent() instanceof Annotat
104
106
/**
105
107
* create the concrete completion proposal
106
108
*/
107
- private void createCompletionProposals (IJavaProject project , TextDocument doc , ASTNode node , Collection <ICompletionProposal > completions , int startOffset , int endOffset ,
109
+ private void createCompletionProposals (IJavaProject project , TextDocument doc , ASTNode node , String attributeName , Collection <ICompletionProposal > completions , int startOffset , int endOffset ,
108
110
String filterPrefix , Function <String , String > createReplacementText ) {
109
111
110
112
Set <String > alreadyMentionedValues = alreadyMentionedValues (node );
111
113
112
- AnnotationAttributeCompletionProvider completionProvider = this .completionProviders .get ("value" );
114
+ AnnotationAttributeCompletionProvider completionProvider = this .completionProviders .get (attributeName );
113
115
if (completionProvider != null ) {
114
116
List <String > candidates = completionProvider .getCompletionCandidates (project );
115
117
@@ -135,7 +137,7 @@ private void createCompletionProposals(IJavaProject project, TextDocument doc, A
135
137
// internal computation of the right positions, prefixes, etc.
136
138
//
137
139
138
- private void computeProposalsForSimpleName (IJavaProject project , ASTNode node , Collection <ICompletionProposal > completions , int offset , TextDocument doc ) {
140
+ private void computeProposalsForSimpleName (IJavaProject project , ASTNode node , String attributeName , Collection <ICompletionProposal > completions , int offset , TextDocument doc ) {
139
141
String prefix = identifyPropertyPrefix (node .toString (), offset - node .getStartPosition ());
140
142
141
143
int startOffset = node .getStartPosition ();
@@ -144,30 +146,30 @@ private void computeProposalsForSimpleName(IJavaProject project, ASTNode node, C
144
146
String proposalPrefix = "\" " ;
145
147
String proposalPostfix = "\" " ;
146
148
147
- createCompletionProposals (project , doc , node , completions , startOffset , endOffset , prefix , (beanName ) -> proposalPrefix + beanName + proposalPostfix );
149
+ createCompletionProposals (project , doc , node , attributeName , completions , startOffset , endOffset , prefix , (beanName ) -> proposalPrefix + beanName + proposalPostfix );
148
150
}
149
151
150
- private void computeProposalsForStringLiteral (IJavaProject project , ASTNode node , Collection <ICompletionProposal > completions , int offset , TextDocument doc ) throws BadLocationException {
152
+ private void computeProposalsForStringLiteral (IJavaProject project , ASTNode node , String attributeName , Collection <ICompletionProposal > completions , int offset , TextDocument doc ) throws BadLocationException {
151
153
int length = offset - (node .getStartPosition () + 1 );
152
154
153
155
String prefix = identifyPropertyPrefix (doc .get (node .getStartPosition () + 1 , length ), length );
154
156
int startOffset = offset - prefix .length ();
155
157
int endOffset = node .getStartPosition () + node .getLength () - 1 ;
156
158
157
- createCompletionProposals (project , doc , node , completions , startOffset , endOffset , prefix , (beanName ) -> beanName );
159
+ createCompletionProposals (project , doc , node , attributeName , completions , startOffset , endOffset , prefix , (beanName ) -> beanName );
158
160
}
159
161
160
- private void computeProposalsForArrayInitializr (IJavaProject project , ArrayInitializer node , Collection <ICompletionProposal > completions , int offset , TextDocument doc ) {
161
- createCompletionProposals (project , doc , node , completions , offset , offset , "" , (beanName ) -> "\" " + beanName + "\" " );
162
+ private void computeProposalsForArrayInitializr (IJavaProject project , ArrayInitializer node , String attributeName , Collection <ICompletionProposal > completions , int offset , TextDocument doc ) {
163
+ createCompletionProposals (project , doc , node , attributeName , completions , offset , offset , "" , (beanName ) -> "\" " + beanName + "\" " );
162
164
}
163
165
164
- private void computeProposalsForInsideArrayInitializer (IJavaProject project , ASTNode node , Collection <ICompletionProposal > completions , int offset , TextDocument doc ) throws BadLocationException {
166
+ private void computeProposalsForInsideArrayInitializer (IJavaProject project , ASTNode node , String attributeName , Collection <ICompletionProposal > completions , int offset , TextDocument doc ) throws BadLocationException {
165
167
int length = offset - (node .getStartPosition () + 1 );
166
168
if (length >= 0 ) {
167
- computeProposalsForStringLiteral (project , node , completions , offset , doc );
169
+ computeProposalsForStringLiteral (project , node , attributeName , completions , offset , doc );
168
170
}
169
171
else {
170
- createCompletionProposals (project , doc , node , completions , offset , offset , "" , (beanName ) -> "\" " + beanName + "\" ," );
172
+ createCompletionProposals (project , doc , node , attributeName , completions , offset , offset , "" , (beanName ) -> "\" " + beanName + "\" ," );
171
173
}
172
174
}
173
175
0 commit comments