2424import org .eclipse .jdt .core .dom .Annotation ;
2525import org .eclipse .jdt .core .dom .ITypeBinding ;
2626import org .eclipse .jdt .core .dom .MemberValuePair ;
27+ import org .eclipse .jdt .core .dom .Name ;
2728import org .eclipse .jdt .core .dom .QualifiedName ;
2829import org .eclipse .jdt .core .dom .SimpleName ;
2930import org .eclipse .jdt .core .dom .StringLiteral ;
@@ -75,6 +76,11 @@ public void provideCompletions(ASTNode node, Annotation annotation, ITypeBinding
7576
7677 IJavaProject project = optionalProject .get ();
7778
79+ // in case the node is embedded in an qualified name, e.g. "file.txt", use the fully qualified node instead just a part
80+ if (node instanceof Name && node .getParent () instanceof QualifiedName ) {
81+ node = node .getParent ();
82+ }
83+
7884 // case: @Value(<*>)
7985 if (node == annotation && doc .get (offset - 1 , 2 ).endsWith ("()" )) {
8086 List <Match <PropertyInfo >> matches = findMatches ("" , doc );
@@ -95,20 +101,16 @@ public void provideCompletions(ASTNode node, Annotation annotation, ITypeBinding
95101 addClasspathResourceProposals (project , doc , offset , offset , "" , true , completions );
96102 }
97103 // case: @Value(prefix<*>)
98- else if (node instanceof SimpleName && node .getParent () instanceof Annotation ) {
104+ else if (node instanceof Name && node .getParent () instanceof Annotation ) {
99105 computeProposalsForSimpleName (project , node , completions , offset , doc );
100106 }
101- // case: @Value(file.ext<*>) - the "." causes a QualifierNode to be generated
102- else if (node instanceof SimpleName && node .getParent () instanceof QualifiedName && node .getParent ().getParent () instanceof Annotation ) {
103- computeProposalsForSimpleName (project , node .getParent (), completions , offset , doc );
104- }
105107 // case: @Value(value=<*>)
106- else if (node instanceof SimpleName && node .getParent () instanceof MemberValuePair
108+ else if (node instanceof Name && node .getParent () instanceof MemberValuePair
107109 && "value" .equals (((MemberValuePair )node .getParent ()).getName ().toString ())) {
108110 computeProposalsForSimpleName (project , node , completions , offset , doc );
109111 }
110112 // case: @Value(value=<*>)
111- else if (node instanceof SimpleName && node .getParent () instanceof QualifiedName && node .getParent ().getParent () instanceof MemberValuePair
113+ else if (node instanceof Name && node .getParent () instanceof QualifiedName && node .getParent ().getParent () instanceof MemberValuePair
112114 && "value" .equals (((MemberValuePair )node .getParent ().getParent ()).getName ().toString ())) {
113115 computeProposalsForSimpleName (project , node .getParent (), completions , offset , doc );
114116 }
@@ -131,29 +133,6 @@ else if (node instanceof StringLiteral && node.getParent() instanceof MemberValu
131133 }
132134 }
133135
134- private void addClasspathResourceProposals (IJavaProject project , TextDocument doc , int startOffset , int endOffset , String prefix , boolean includeQuotes , Collection <ICompletionProposal > completions ) {
135- String [] resources = findResources (project , prefix );
136-
137- double score = resources .length + 1000 ;
138- for (String resource : resources ) {
139-
140- DocumentEdits edits = new DocumentEdits (doc , false );
141-
142- if (includeQuotes ) {
143- edits .replace (startOffset , endOffset , "\" classpath:" + resource + "\" " );
144- }
145- else {
146- edits .replace (startOffset , endOffset , "classpath:" + resource );
147- }
148-
149- String label = "classpath:" + resource ;
150-
151- ICompletionProposal proposal = new AnnotationAttributeCompletionProposal (edits , label , label , null , score --);
152- completions .add (proposal );
153- }
154-
155- }
156-
157136 private void computeProposalsForSimpleName (IJavaProject project , ASTNode node , Collection <ICompletionProposal > completions , int offset , TextDocument doc ) {
158137 String prefix = identifyPropertyPrefix (node .toString (), offset - node .getStartPosition ());
159138
@@ -253,15 +232,15 @@ public String identifyPropertyPrefix(String nodeContent, int offset) {
253232
254233 private List <Match <PropertyInfo >> findMatches (String prefix , IDocument doc ) {
255234 FuzzyMap <PropertyInfo > index = indexProvider .getIndex (doc ).getProperties ();
256- List <Match <PropertyInfo >> matches =index .find (camelCaseToHyphens (prefix ));
235+ List <Match <PropertyInfo >> matches = index .find (camelCaseToHyphens (prefix ));
257236
258- //First the 'real' properties.
237+ // First the 'real' properties.
259238 Set <String > suggestedKeys = new HashSet <>();
260239 for (Match <PropertyInfo > m : matches ) {
261240 suggestedKeys .add (m .data .getId ());
262241 }
263242
264- //Then also add 'ad-hoc' properties (see https://www.pivotaltracker.com/story/show/153107266).
243+ // Then also add 'ad-hoc' properties
265244 Optional <IJavaProject > p = projectFinder .find (new TextDocumentIdentifier (doc .getUri ()));
266245 if (p .isPresent ()) {
267246 index = adHocIndexProvider .getIndex (p .get ());
@@ -274,6 +253,29 @@ private List<Match<PropertyInfo>> findMatches(String prefix, IDocument doc) {
274253 return matches ;
275254 }
276255
256+ private void addClasspathResourceProposals (IJavaProject project , TextDocument doc , int startOffset , int endOffset , String prefix , boolean includeQuotes , Collection <ICompletionProposal > completions ) {
257+ String [] resources = findResources (project , prefix );
258+
259+ double score = resources .length + 1000 ;
260+ for (String resource : resources ) {
261+
262+ DocumentEdits edits = new DocumentEdits (doc , false );
263+
264+ if (includeQuotes ) {
265+ edits .replace (startOffset , endOffset , "\" classpath:" + resource + "\" " );
266+ }
267+ else {
268+ edits .replace (startOffset , endOffset , "classpath:" + resource );
269+ }
270+
271+ String label = "classpath:" + resource ;
272+
273+ ICompletionProposal proposal = new AnnotationAttributeCompletionProposal (edits , label , label , null , score --);
274+ completions .add (proposal );
275+ }
276+
277+ }
278+
277279 private String [] findResources (IJavaProject project , String prefix ) {
278280 String [] resources = IClasspathUtil .getClasspathResources (project .getClasspath ()).stream ()
279281 .distinct ()
0 commit comments