Hello,
I am using JDT's search engine to search for annotation references inside a builder:
// search the project my builder was invoked on, including referenced libraries...
IJavaSearchScope scope = SearchEngine.createJavaSearchScope(false,
new IJavaElement[] { javaProject },
IJavaSearchScope.SOURCES | IJavaSearchScope.APPLICATION_LIBRARIES);
// search for references to annotation from a specific package prefix:
searchEngine.search(SearchPattern.createPattern("my.test.prefix.**", //
IJavaSearchConstants.ANNOTATION_TYPE, IJavaSearchConstants.ANNOTATION_TYPE_REFERENCE,
SearchPattern.R_PATTERN_MATCH),
new SearchParticipant[] { SearchEngine.getDefaultSearchParticipant() },
scope, requestor, monitor);
The project that has spring in its classpath and I get a lot of unrelated matches with accuracy 1. For example I get a match with (this is output from the requestor's "acceptSearchMatch(SearchMatch match)" method logging the result:
In my-project-with-spring / exact:true, accuracy:1 found: void onWebSocketConnect(org.eclipse.jetty.websocket.api.Session) {key=Lorg/springframework/web/reactive/socket/adapter/JettyWebSocketHandlerAdapter;.onWebSocketConnect(LSession;)V} [in JettyWebSocketHandlerAdapter [in JettyWebSocketHandlerAdapter.class [in org.springframework.web.reactive.socket.adapter [in /Users/myuser/.m2/repository/org/springframework/spring-webflux/5.1.6.RELEASE/spring-webflux-5.1.6.RELEASE.jar]]]]
ANNOS: [@org.eclipse.jetty.websocket.api.annotations.OnWebSocketConnect [in onWebSocketConnect(org.eclipse.jetty.websocket.api.Session) [in JettyWebSocketHandlerAdapter [in JettyWebSocketHandlerAdapter.class [in org.springframework.web.reactive.socket.adapter [in /Users/myuser/.m2/repository/org/springframework/spring-webflux/5.1.6.RELEASE/spring-webflux-5.1.6.RELEASE.jar]]]]]]
The code for the method suggested as an inaccurate result is:
@OnWebSocketConnect
public void onWebSocketConnect(Session session) {
this.delegateSession = this.sessionFactory.apply(session);
this.delegateHandler.handle(this.delegateSession).subscribe(this.delegateSession);
}
The annotation has absolutely no relation to package "my.test.prefix" that I asked for. Its fully qualified name is: org.eclipse.jetty.websocket.api.annotations.OnWebSocketClose
Why is it being reported? There are no compilation errors in the workspace so it should be pretty straight-forward to exclude this result...
[Updated on: Sat, 01 June 2019 13:39] by Moderator