replaced methodkey with different identification string for handler classes and handler methods to avoid jdt bug on windows
This commit is contained in:
@@ -49,27 +49,34 @@ public class WebfluxHandlerCodeLensProvider implements CodeLensProvider {
|
||||
protected void provideCodeLens(MethodDeclaration node, TextDocument document, List<CodeLens> resultAccumulator) {
|
||||
IMethodBinding methodBinding = node.resolveBinding();
|
||||
|
||||
final String methodKey = methodBinding.getKey();
|
||||
List<Object> handlerInfos = this.springIndexer.getAllAdditionalInformation((addon) -> {
|
||||
if (addon instanceof WebfluxHandlerInformation) {
|
||||
WebfluxHandlerInformation handlerInfo = (WebfluxHandlerInformation) addon;
|
||||
return handlerInfo.getMethodKey() != null && handlerInfo.getMethodKey().equals(methodKey);
|
||||
}
|
||||
return false;
|
||||
});
|
||||
if (methodBinding != null && methodBinding.getDeclaringClass() != null && methodBinding.getMethodDeclaration() != null
|
||||
&& methodBinding.getDeclaringClass().getBinaryName() != null && methodBinding.getMethodDeclaration().toString() != null) {
|
||||
|
||||
if (handlerInfos != null && handlerInfos.size() > 0) {
|
||||
for (Object object : handlerInfos) {
|
||||
try {
|
||||
WebfluxHandlerInformation handlerInfo = (WebfluxHandlerInformation) object;
|
||||
|
||||
CodeLens codeLens = new CodeLens();
|
||||
codeLens.setRange(document.toRange(node.getName().getStartPosition(), node.getName().getLength()));
|
||||
codeLens.setCommand(new Command(handlerInfo.getSymbol(), null));
|
||||
|
||||
resultAccumulator.add(codeLens);
|
||||
} catch (BadLocationException e) {
|
||||
e.printStackTrace();
|
||||
final String handlerClass = methodBinding.getDeclaringClass().getBinaryName().trim();
|
||||
final String handlerMethod = methodBinding.getMethodDeclaration().toString().trim();
|
||||
|
||||
List<Object> handlerInfos = this.springIndexer.getAllAdditionalInformation((addon) -> {
|
||||
if (addon instanceof WebfluxHandlerInformation) {
|
||||
WebfluxHandlerInformation handlerInfo = (WebfluxHandlerInformation) addon;
|
||||
return handlerInfo.getHandlerClass() != null && handlerInfo.getHandlerClass().equals(handlerClass)
|
||||
&& handlerInfo.getHandlerMethod() != null && handlerInfo.getHandlerMethod().equals(handlerMethod);
|
||||
}
|
||||
return false;
|
||||
});
|
||||
|
||||
if (handlerInfos != null && handlerInfos.size() > 0) {
|
||||
for (Object object : handlerInfos) {
|
||||
try {
|
||||
WebfluxHandlerInformation handlerInfo = (WebfluxHandlerInformation) object;
|
||||
|
||||
CodeLens codeLens = new CodeLens();
|
||||
codeLens.setRange(document.toRange(node.getName().getStartPosition(), node.getName().getLength()));
|
||||
codeLens.setCommand(new Command(handlerInfo.getSymbol(), null));
|
||||
|
||||
resultAccumulator.add(codeLens);
|
||||
} catch (BadLocationException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,25 +16,25 @@ package org.springframework.ide.vscode.boot.java.requestmapping;
|
||||
public class WebfluxHandlerInformation {
|
||||
|
||||
private final String symbol;
|
||||
private String destinationClass;
|
||||
private String methodKey;
|
||||
private String handlerClass;
|
||||
private String handlerMethod;
|
||||
|
||||
public WebfluxHandlerInformation(String symbol, String destinationClass, String methodKey) {
|
||||
public WebfluxHandlerInformation(String symbol, String handlerClass, String handlerMethod) {
|
||||
this.symbol = symbol;
|
||||
this.destinationClass = destinationClass;
|
||||
this.methodKey = methodKey;
|
||||
this.handlerClass = handlerClass;
|
||||
this.handlerMethod = handlerMethod;
|
||||
}
|
||||
|
||||
public String getSymbol() {
|
||||
return symbol;
|
||||
}
|
||||
|
||||
public String getDestinationClass() {
|
||||
return destinationClass;
|
||||
public String getHandlerClass() {
|
||||
return handlerClass;
|
||||
}
|
||||
|
||||
public String getMethodKey() {
|
||||
return methodKey;
|
||||
public String getHandlerMethod() {
|
||||
return handlerMethod;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -163,7 +163,7 @@ public class WebfluxRouterSymbolProvider implements SymbolProvider {
|
||||
|
||||
private WebfluxHandlerInformation extractHandlerInformation(MethodInvocation node, String symbol) {
|
||||
List<?> arguments = node.arguments();
|
||||
|
||||
|
||||
if (arguments != null) {
|
||||
for (Object argument : arguments) {
|
||||
if (argument instanceof ExpressionMethodReference) {
|
||||
@@ -171,11 +171,13 @@ public class WebfluxRouterSymbolProvider implements SymbolProvider {
|
||||
IMethodBinding methodBinding = methodReference.resolveMethodBinding();
|
||||
|
||||
if (methodBinding != null && methodBinding.getDeclaringClass() != null && methodBinding.getMethodDeclaration() != null) {
|
||||
ITypeBinding declaringClass = methodBinding.getDeclaringClass();
|
||||
String destinationClass = declaringClass.getBinaryName();
|
||||
String methodKey = methodBinding.getMethodDeclaration().getKey();
|
||||
|
||||
return new WebfluxHandlerInformation(symbol, destinationClass, methodKey);
|
||||
String handlerClass = methodBinding.getDeclaringClass().getBinaryName();
|
||||
if (handlerClass != null) handlerClass = handlerClass.trim();
|
||||
|
||||
String handlerMethod = methodBinding.getMethodDeclaration().toString();
|
||||
if (handlerMethod != null) handlerMethod = handlerMethod.trim();
|
||||
|
||||
return new WebfluxHandlerInformation(symbol, handlerClass, handlerMethod);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -71,27 +71,23 @@ public class WebFluxMappingSymbolProviderTest {
|
||||
|
||||
WebfluxHandlerInformation handlerInfo1 = getWebfluxHandler(addons, "@/hello -- GET").get(0);
|
||||
assertEquals("@/hello -- GET", handlerInfo1.getSymbol());
|
||||
assertEquals("org.test.QuoteHandler", handlerInfo1.getDestinationClass());
|
||||
assertTrue(handlerInfo1.getMethodKey().startsWith("Lorg/test/"));
|
||||
assertTrue(handlerInfo1.getMethodKey().endsWith("QuoteHandler;.hello(Lorg/springframework/web/reactive/function/server/ServerRequest;)Lreactor/core/publisher/Mono<Lorg/springframework/web/reactive/function/server/ServerResponse;>;"));
|
||||
assertEquals("org.test.QuoteHandler", handlerInfo1.getHandlerClass());
|
||||
assertEquals("public Mono<org.springframework.web.reactive.function.server.ServerResponse> hello(org.springframework.web.reactive.function.server.ServerRequest)", handlerInfo1.getHandlerMethod());
|
||||
|
||||
WebfluxHandlerInformation handlerInfo2 = getWebfluxHandler(addons, "@/echo -- POST").get(0);
|
||||
assertEquals("@/echo -- POST", handlerInfo2.getSymbol());
|
||||
assertEquals("org.test.QuoteHandler", handlerInfo2.getDestinationClass());
|
||||
assertTrue(handlerInfo2.getMethodKey().startsWith("Lorg/test/"));
|
||||
assertTrue(handlerInfo2.getMethodKey().endsWith("QuoteHandler;.echo(Lorg/springframework/web/reactive/function/server/ServerRequest;)Lreactor/core/publisher/Mono<Lorg/springframework/web/reactive/function/server/ServerResponse;>;"));
|
||||
assertEquals("org.test.QuoteHandler", handlerInfo2.getHandlerClass());
|
||||
assertEquals("public Mono<org.springframework.web.reactive.function.server.ServerResponse> echo(org.springframework.web.reactive.function.server.ServerRequest)", handlerInfo2.getHandlerMethod());
|
||||
|
||||
WebfluxHandlerInformation handlerInfo3 = getWebfluxHandler(addons, "@/quotes -- GET").get(0);
|
||||
assertEquals("@/quotes -- GET", handlerInfo3.getSymbol());
|
||||
assertEquals("org.test.QuoteHandler", handlerInfo3.getDestinationClass());
|
||||
assertTrue(handlerInfo3.getMethodKey().startsWith("Lorg/test/"));
|
||||
assertTrue(handlerInfo3.getMethodKey().endsWith("QuoteHandler;.streamQuotes(Lorg/springframework/web/reactive/function/server/ServerRequest;)Lreactor/core/publisher/Mono<Lorg/springframework/web/reactive/function/server/ServerResponse;>;"));
|
||||
assertEquals("org.test.QuoteHandler", handlerInfo3.getHandlerClass());
|
||||
assertEquals("public Mono<org.springframework.web.reactive.function.server.ServerResponse> streamQuotes(org.springframework.web.reactive.function.server.ServerRequest)", handlerInfo3.getHandlerMethod());
|
||||
|
||||
WebfluxHandlerInformation handlerInfo4 = getWebfluxHandler(addons, "@/quotes -- GET").get(1);
|
||||
assertEquals("@/quotes -- GET", handlerInfo4.getSymbol());
|
||||
assertEquals("org.test.QuoteHandler", handlerInfo4.getDestinationClass());
|
||||
assertTrue(handlerInfo4.getMethodKey().startsWith("Lorg/test/"));
|
||||
assertTrue(handlerInfo4.getMethodKey().endsWith("QuoteHandler;.fetchQuotes(Lorg/springframework/web/reactive/function/server/ServerRequest;)Lreactor/core/publisher/Mono<Lorg/springframework/web/reactive/function/server/ServerResponse;>;"));
|
||||
assertEquals("org.test.QuoteHandler", handlerInfo4.getHandlerClass());
|
||||
assertEquals("public Mono<org.springframework.web.reactive.function.server.ServerResponse> fetchQuotes(org.springframework.web.reactive.function.server.ServerRequest)", handlerInfo4.getHandlerMethod());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -111,21 +107,18 @@ public class WebFluxMappingSymbolProviderTest {
|
||||
|
||||
WebfluxHandlerInformation handlerInfo1 = getWebfluxHandler(addons, "@/person/{id} -- GET").get(0);
|
||||
assertEquals("@/person/{id} -- GET", handlerInfo1.getSymbol());
|
||||
assertEquals("org.test.PersonHandler", handlerInfo1.getDestinationClass());
|
||||
assertTrue(handlerInfo1.getMethodKey().startsWith("Lorg/test/"));
|
||||
assertTrue(handlerInfo1.getMethodKey().endsWith("PersonHandler;.getPerson(Lorg/springframework/web/reactive/function/server/ServerRequest;)Lreactor/core/publisher/Mono<Lorg/springframework/web/reactive/function/server/ServerResponse;>;"));
|
||||
assertEquals("org.test.PersonHandler", handlerInfo1.getHandlerClass());
|
||||
assertEquals("public Mono<org.springframework.web.reactive.function.server.ServerResponse> getPerson(org.springframework.web.reactive.function.server.ServerRequest)", handlerInfo1.getHandlerMethod());
|
||||
|
||||
WebfluxHandlerInformation handlerInfo2 = getWebfluxHandler(addons, "@/person/ -- POST").get(0);
|
||||
assertEquals("@/person/ -- POST", handlerInfo2.getSymbol());
|
||||
assertEquals("org.test.PersonHandler", handlerInfo2.getDestinationClass());
|
||||
assertTrue(handlerInfo2.getMethodKey().startsWith("Lorg/test/"));
|
||||
assertTrue(handlerInfo2.getMethodKey().endsWith("PersonHandler;.createPerson(Lorg/springframework/web/reactive/function/server/ServerRequest;)Lreactor/core/publisher/Mono<Lorg/springframework/web/reactive/function/server/ServerResponse;>;"));
|
||||
assertEquals("org.test.PersonHandler", handlerInfo2.getHandlerClass());
|
||||
assertEquals("public Mono<org.springframework.web.reactive.function.server.ServerResponse> createPerson(org.springframework.web.reactive.function.server.ServerRequest)", handlerInfo2.getHandlerMethod());
|
||||
|
||||
WebfluxHandlerInformation handlerInfo3 = getWebfluxHandler(addons, "@/person -- GET").get(0);
|
||||
assertEquals("@/person -- GET", handlerInfo3.getSymbol());
|
||||
assertEquals("org.test.PersonHandler", handlerInfo3.getDestinationClass());
|
||||
assertTrue(handlerInfo3.getMethodKey().startsWith("Lorg/test/"));
|
||||
assertTrue(handlerInfo3.getMethodKey().endsWith("PersonHandler;.listPeople(Lorg/springframework/web/reactive/function/server/ServerRequest;)Lreactor/core/publisher/Mono<Lorg/springframework/web/reactive/function/server/ServerResponse;>;"));
|
||||
assertEquals("org.test.PersonHandler", handlerInfo3.getHandlerClass());
|
||||
assertEquals("public Mono<org.springframework.web.reactive.function.server.ServerResponse> listPeople(org.springframework.web.reactive.function.server.ServerRequest)", handlerInfo3.getHandlerMethod());
|
||||
}
|
||||
|
||||
private boolean containsSymbol(List<? extends SymbolInformation> symbols, String name, String uri, int startLine, int startCHaracter, int endLine, int endCharacter) {
|
||||
|
||||
Reference in New Issue
Block a user