Skip to content

goto definition for beans and methods references in spel expressions - #1360

Merged
BoykoAlex merged 3 commits into
spring-projects:mainfrom
vudayani:spel-definition-provider
Oct 4, 2024
Merged

BoykoAlex merged 3 commits into
spring-projects:mainfrom
vudayani:spel-definition-provider

Conversation

@vudayani

@vudayani vudayani commented Oct 1, 2024

Copy link
Copy Markdown
Collaborator

No description provided.

@martinlippert martinlippert added this to the 4.26.0.RELEASE milestone Oct 1, 2024
@martinlippert

Copy link
Copy Markdown
Member

Some newly created files are missing copyright statements at the top. Can you add them?

@vudayani
vudayani force-pushed the spel-definition-provider branch 2 times, most recently from 164c6cd to 988c0d9 Compare October 3, 2024 05:41
IAnnotationBinding binding = a.resolveAnnotationBinding();
if (binding != null && binding.getAnnotationType() != null
&& Annotations.VALUE.equals(binding.getAnnotationType().getQualifiedName())) {
return parseSpelAndFetchLocation(cancelToken, project, cu, offset);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I was looking at this PR in the past and just didn't look closely enough :-
I think I like everything except this piece. We're only interested in this literal the cursor is at and nothing else. At this point whatever parseSpelAndFetchLocation(...) is doing is wrong. No need to visit the CU and find all possible SPEL expressions and collect them. Instead of CU you should really visit just one single annotation.

Anyway, I'd try to extract SPEL Region from the found annotation a (line 101). Once you have the Region check that offset paremter is within that region. If yes, then:

			List<TokenData> beanReferenceTokens = computeTokens(snippet, offset);
							if (beanReferenceTokens != null && beanReferenceTokens.size() > 0) {
								locationLink.addAll(findLocationLinksForBeanRef(project, offset, beanReferenceTokens));
							}

							Optional<Tuple2<String, String>> result = parseAndExtractMethodClassPairFromSpel(snippet,
									offset);
							result.ifPresent(tuple -> {
								locationLink.addAll(findLocationLinksForMethodRef(tuple.getT1(), tuple.getT2(), project));
							});

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this makes sense. Thanks for pointing this out. Removed the unnecessary parsing logic.

@vudayani
vudayani force-pushed the spel-definition-provider branch from 02ed5ae to 64d5411 Compare October 4, 2024 09:26
@vudayani
vudayani force-pushed the spel-definition-provider branch from 64d5411 to b0743ff Compare October 4, 2024 09:51
@BoykoAlex
BoykoAlex merged commit f4c4121 into spring-projects:main Oct 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

for: vscode something that is specific for VSCode theme: spel-support type: enhancement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants