Merge branch 'master' of github.com:spring-projects/sts4
This commit is contained in:
@@ -20,7 +20,9 @@ Require-Bundle: org.eclipse.jdt.launching;bundle-version="3.9.0",
|
||||
org.eclipse.xtext.xbase.lib,
|
||||
org.springframework.tooling.ls.eclipse.commons;bundle-version="0.2.0",
|
||||
org.eclipse.core.resources,
|
||||
org.eclipse.ui
|
||||
org.eclipse.ui,
|
||||
org.eclipse.ui.ide,
|
||||
org.eclipse.jdt.core
|
||||
Import-Package: com.google.gson;version="2.7.0",
|
||||
org.eclipse.jface.preference,
|
||||
org.osgi.framework
|
||||
|
||||
@@ -99,6 +99,40 @@
|
||||
class="org.springframework.tooling.boot.ls.PrefsInitializer">
|
||||
</initializer>
|
||||
</extension>
|
||||
|
||||
<extension
|
||||
point="org.eclipse.ui.handlers">
|
||||
<handler
|
||||
class="org.springframework.tooling.boot.ls.commands.OpenFullyQualifiedNameInEditor"
|
||||
commandId="org.springframework.tooling.boot.ls.OpenJavaType">
|
||||
</handler>
|
||||
<handler
|
||||
class="org.springframework.tooling.boot.ls.commands.OpenResourceInEditor"
|
||||
commandId="org.springframework.tooling.boot.ls.OpenResourceInEditor">
|
||||
</handler>
|
||||
</extension>
|
||||
<extension
|
||||
point="org.eclipse.ui.commands">
|
||||
<command
|
||||
id="org.springframework.tooling.boot.ls.OpenJavaType"
|
||||
name="Open Java Type in Editor">
|
||||
<commandParameter
|
||||
id="fqName"
|
||||
name="fqName"
|
||||
optional="false">
|
||||
</commandParameter>
|
||||
</command>
|
||||
<command
|
||||
id="org.springframework.tooling.boot.ls.OpenResourceInEditor"
|
||||
name="Open File in Editor">
|
||||
<commandParameter
|
||||
id="path"
|
||||
name="path"
|
||||
optional="false">
|
||||
</commandParameter>
|
||||
</command>
|
||||
</extension>
|
||||
|
||||
<!--
|
||||
<extension
|
||||
point="org.eclipse.ui.editors">
|
||||
|
||||
@@ -36,28 +36,17 @@ public class SpringBootLanguageServer extends STS4LanguageServerProcessStreamCon
|
||||
|
||||
public SpringBootLanguageServer() {
|
||||
super(SPRING_BOOT_SERVER);
|
||||
JRE jre = getJRE();
|
||||
List<String> vmargs = new ArrayList<>();
|
||||
|
||||
// vmargs.add("-Xdebug");
|
||||
// vmargs.add("-Xrunjdwp:server=y,transport=dt_socket,address=4000,suspend=n");
|
||||
|
||||
vmargs.add("-Dlsp.lazy.completions.disable=true");
|
||||
vmargs.add("-Dlsp.completions.indentation.enable=true");
|
||||
vmargs.add("-Xmx1024m");
|
||||
|
||||
String workingDir = getWorkingDirLocation();
|
||||
|
||||
setCommands(jre.jarLaunchCommand(getLanguageServerJARLocation(),
|
||||
setCommands(getJRE().jarLaunchCommand(getLanguageServerJARLocation(),
|
||||
ImmutableList.of(
|
||||
//"-Xdebug",
|
||||
// "-Xrunjdwp:server=y,transport=dt_socket,address=4000,suspend=n"
|
||||
"-Dsts.lsp.client=eclipse",
|
||||
"-Dlsp.lazy.completions.disable=true",
|
||||
"-Dlsp.completions.indentation.enable=true",
|
||||
"-Xmx1024m"
|
||||
)
|
||||
));
|
||||
setWorkingDirectory(workingDir);
|
||||
setWorkingDirectory(getWorkingDirLocation());
|
||||
}
|
||||
|
||||
private JRE getJRE() {
|
||||
|
||||
@@ -0,0 +1,138 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2018 Pivotal, Inc.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Pivotal, Inc. - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.springframework.tooling.boot.ls.commands;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.core.commands.AbstractHandler;
|
||||
import org.eclipse.core.commands.ExecutionEvent;
|
||||
import org.eclipse.core.commands.ExecutionException;
|
||||
import org.eclipse.core.resources.IProject;
|
||||
import org.eclipse.core.resources.ResourcesPlugin;
|
||||
import org.eclipse.core.runtime.IStatus;
|
||||
import org.eclipse.core.runtime.NullProgressMonitor;
|
||||
import org.eclipse.core.runtime.Status;
|
||||
import org.eclipse.jdt.core.IJavaElement;
|
||||
import org.eclipse.jdt.core.IJavaProject;
|
||||
import org.eclipse.jdt.core.IType;
|
||||
import org.eclipse.jdt.core.JavaCore;
|
||||
import org.eclipse.jdt.core.JavaModelException;
|
||||
import org.eclipse.jdt.core.WorkingCopyOwner;
|
||||
import org.eclipse.jdt.core.search.IJavaSearchConstants;
|
||||
import org.eclipse.jdt.core.search.IJavaSearchScope;
|
||||
import org.eclipse.jdt.core.search.SearchEngine;
|
||||
import org.eclipse.jdt.core.search.SearchPattern;
|
||||
import org.eclipse.jdt.core.search.TypeNameMatch;
|
||||
import org.eclipse.jdt.core.search.TypeNameMatchRequestor;
|
||||
import org.eclipse.jdt.ui.JavaUI;
|
||||
import org.eclipse.ui.IEditorPart;
|
||||
import org.eclipse.ui.PartInitException;
|
||||
import org.springframework.tooling.boot.ls.BootLanguageServerPlugin;
|
||||
|
||||
/**
|
||||
* Command for opening Java type given by its fully qualified name in an editor
|
||||
*
|
||||
* @author Alex Boyko
|
||||
*
|
||||
*/
|
||||
public class OpenFullyQualifiedNameInEditor extends AbstractHandler {
|
||||
|
||||
private static final String FQ_NAME = "fqName";
|
||||
private static final String PROJECT_NAME = "projectName";
|
||||
|
||||
@Override
|
||||
public Object execute(ExecutionEvent event) throws ExecutionException {
|
||||
String fqName = event.getParameter(FQ_NAME);
|
||||
String projectName = event.getParameter(PROJECT_NAME);
|
||||
|
||||
String packageName = "";
|
||||
String typeName = fqName;
|
||||
int idx = fqName.lastIndexOf('.');
|
||||
if (idx >= 0) {
|
||||
packageName = fqName.substring(0, idx);
|
||||
typeName = idx < fqName.length() - 1 ? fqName.substring(idx + 1) : "";
|
||||
}
|
||||
|
||||
if (!typeName.isEmpty()) {
|
||||
SearchEngine engine= new SearchEngine((WorkingCopyOwner) null);
|
||||
List<TypeNameMatch> matches = new ArrayList<>();
|
||||
String searchedTypeName = getSearchedTypeName(typeName);
|
||||
final boolean isInnerType = searchedTypeName != typeName;
|
||||
TypeNameMatchRequestor requestor = new TypeNameMatchRequestor() {
|
||||
@Override
|
||||
public void acceptTypeNameMatch(TypeNameMatch match) {
|
||||
if (isInnerType) {
|
||||
if (match.getFullyQualifiedName().equals(fqName.replace("$", "."))) {
|
||||
matches.add(match);
|
||||
}
|
||||
} else {
|
||||
matches.add(match);
|
||||
}
|
||||
}
|
||||
};
|
||||
try {
|
||||
IJavaSearchScope searchScope = createSearchScope(projectName);
|
||||
engine.searchAllTypeNames(packageName.toCharArray(), SearchPattern.R_EXACT_MATCH,
|
||||
searchedTypeName.toCharArray(), SearchPattern.R_EXACT_MATCH, IJavaSearchConstants.TYPE, searchScope,
|
||||
requestor, IJavaSearchConstants.WAIT_UNTIL_READY_TO_SEARCH, new NullProgressMonitor());
|
||||
if (matches.isEmpty()) {
|
||||
BootLanguageServerPlugin.getDefault().getLog().log(new Status(IStatus.WARNING, BootLanguageServerPlugin.ID, "Cannot find type: " + fqName));
|
||||
} else {
|
||||
if (matches.size() > 1) {
|
||||
BootLanguageServerPlugin.getDefault().getLog().log(new Status(IStatus.WARNING, BootLanguageServerPlugin.ID, "More than one type is defined for: " + fqName));
|
||||
}
|
||||
try {
|
||||
IType type = matches.get(0).getType();
|
||||
IEditorPart editorPart= JavaUI.openInEditor(type);
|
||||
JavaUI.revealInEditor(editorPart, (IJavaElement)type);
|
||||
} catch (JavaModelException ex) {
|
||||
throw new ExecutionException("Error opening java element in editor", ex); //$NON-NLS-1$
|
||||
} catch (PartInitException ex) {
|
||||
throw new ExecutionException("Error opening java element in editor", ex); //$NON-NLS-1$
|
||||
}
|
||||
}
|
||||
} catch (JavaModelException e) {
|
||||
BootLanguageServerPlugin.getDefault().getLog().log(e.getStatus());
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private String getSearchedTypeName(String typeName) {
|
||||
int idx = typeName.lastIndexOf('$');
|
||||
if (idx >= 0 && idx < typeName.length()) {
|
||||
return typeName.substring(idx + 1);
|
||||
}
|
||||
return typeName;
|
||||
}
|
||||
|
||||
private IJavaSearchScope createSearchScope(String projectName) {
|
||||
try {
|
||||
if (projectName != null) {
|
||||
IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName);
|
||||
if (project != null) {
|
||||
IJavaProject javaProject = JavaCore.create(project);
|
||||
if (javaProject != null) {
|
||||
return SearchEngine.createJavaSearchScope(new IJavaElement[] { javaProject });
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Throwable t) {
|
||||
BootLanguageServerPlugin.getDefault().getLog().log(new Status(IStatus.WARNING, BootLanguageServerPlugin.ID, "Failed creating Java search scope for project: " + projectName));
|
||||
}
|
||||
return SearchEngine.createWorkspaceScope();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2018 Pivotal, Inc.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Pivotal, Inc. - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.springframework.tooling.boot.ls.commands;
|
||||
|
||||
import org.eclipse.core.commands.AbstractHandler;
|
||||
import org.eclipse.core.commands.ExecutionEvent;
|
||||
import org.eclipse.core.commands.ExecutionException;
|
||||
import org.eclipse.core.resources.IFile;
|
||||
import org.eclipse.core.resources.IResource;
|
||||
import org.eclipse.core.resources.IWorkspaceRoot;
|
||||
import org.eclipse.core.resources.ResourcesPlugin;
|
||||
import org.eclipse.core.runtime.IPath;
|
||||
import org.eclipse.core.runtime.Path;
|
||||
import org.eclipse.ui.IWorkbenchPage;
|
||||
import org.eclipse.ui.IWorkbenchWindow;
|
||||
import org.eclipse.ui.PartInitException;
|
||||
import org.eclipse.ui.PlatformUI;
|
||||
import org.eclipse.ui.ide.IDE;
|
||||
|
||||
/**
|
||||
* Command for opening an editor given URI of the resource. (Platform command
|
||||
* takes platform URI or path relative to the workspace)
|
||||
*
|
||||
* @author Alex Boyko
|
||||
*
|
||||
*/
|
||||
public class OpenResourceInEditor extends AbstractHandler {
|
||||
|
||||
private static final String PATH = "path";
|
||||
|
||||
@Override
|
||||
public Object execute(ExecutionEvent event) throws ExecutionException {
|
||||
IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
|
||||
IPath rootPath = root.getLocation();
|
||||
IPath resourcePath = new Path(event.getParameter(PATH));
|
||||
|
||||
IResource resource = root.findMember(resourcePath.makeRelativeTo(rootPath));
|
||||
|
||||
if (resource == null && !(resource instanceof IFile)) {
|
||||
throw new ExecutionException("cannot find file: " + event.getParameter(PATH)); //$NON-NLS-1$
|
||||
}
|
||||
|
||||
final IWorkbenchWindow window = PlatformUI.getWorkbench()
|
||||
.getActiveWorkbenchWindow();
|
||||
if (window == null) {
|
||||
throw new ExecutionException("no active workbench window"); //$NON-NLS-1$
|
||||
}
|
||||
|
||||
final IWorkbenchPage page = window.getActivePage();
|
||||
if (page == null) {
|
||||
throw new ExecutionException("no active workbench page"); //$NON-NLS-1$
|
||||
}
|
||||
|
||||
try {
|
||||
IDE.openEditor(page, (IFile) resource, true);
|
||||
} catch (final PartInitException e) {
|
||||
throw new ExecutionException("error opening file in editor", e); //$NON-NLS-1$
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -6,20 +6,17 @@
|
||||
point="org.eclipse.core.contenttype.contentTypes">
|
||||
<content-type
|
||||
default-charset="UTF-8"
|
||||
id="org.springframework.boot.ide.manifest.yml"
|
||||
id="org.springframework.ide.eclipse.manifest.yml"
|
||||
name="Cloudfoundry Manifest"
|
||||
file-names="manifest.yml"
|
||||
priority="high">
|
||||
</content-type>
|
||||
<file-association
|
||||
content-type="org.springframework.boot.ide.manifest.yml"
|
||||
file-names="manifest.yml">
|
||||
</file-association>
|
||||
</extension>
|
||||
|
||||
<extension
|
||||
point="org.eclipse.ui.editors">
|
||||
<editorContentTypeBinding
|
||||
contentTypeId="org.springframework.boot.ide.manifest.yml"
|
||||
contentTypeId="org.springframework.ide.eclipse.manifest.yml"
|
||||
editorId="org.eclipse.ui.genericeditor.GenericEditor">
|
||||
</editorContentTypeBinding>
|
||||
</extension>
|
||||
@@ -28,7 +25,7 @@
|
||||
point="org.eclipse.ui.genericeditor.presentationReconcilers">
|
||||
<presentationReconciler
|
||||
class="org.eclipse.tm4e.ui.text.TMPresentationReconciler"
|
||||
contentType="org.springframework.boot.ide.manifest.yml">
|
||||
contentType="org.springframework.ide.eclipse.manifest.yml">
|
||||
</presentationReconciler>
|
||||
</extension>
|
||||
|
||||
@@ -39,7 +36,7 @@
|
||||
path="./syntaxes/YAML.tmLanguage" >
|
||||
</grammar>
|
||||
<scopeNameContentTypeBinding
|
||||
contentTypeId="org.springframework.boot.ide.manifest.yml"
|
||||
contentTypeId="org.springframework.ide.eclipse.manifest.yml"
|
||||
scopeName="source.yaml">
|
||||
</scopeNameContentTypeBinding>
|
||||
</extension>
|
||||
|
||||
@@ -10,19 +10,6 @@
|
||||
clientImpl="org.springframework.tooling.ls.eclipse.commons.STS4LanguageClientImpl"
|
||||
label="Cloud Foundry Manifest Language Server">
|
||||
</server>
|
||||
<contentTypeMapping
|
||||
contentType="org.springframework.boot.ide.manifest.yml"
|
||||
id="org.eclipse.languageserver.languages.cloudfoundrymanifest">
|
||||
</contentTypeMapping>
|
||||
</extension>
|
||||
|
||||
<extension
|
||||
point="org.eclipse.lsp4e.languageServer">
|
||||
<server
|
||||
class="org.springframework.tooling.cloudfoundry.manifest.ls.CloudFoundryManifestLanguageServer"
|
||||
id="org.eclipse.languageserver.languages.cloudfoundrymanifest"
|
||||
label="Cloud Foundry Manifest Language Server">
|
||||
</server>
|
||||
<contentTypeMapping
|
||||
contentType="org.springframework.ide.eclipse.manifest.yml"
|
||||
id="org.eclipse.languageserver.languages.cloudfoundrymanifest">
|
||||
|
||||
@@ -0,0 +1,107 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2018 Pivotal, Inc.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Pivotal, Inc. - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.springframework.ide.vscode.boot.java.links;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.URLEncoder;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.ide.vscode.commons.java.IJavaProject;
|
||||
|
||||
import com.google.common.base.Supplier;
|
||||
import com.google.common.base.Suppliers;
|
||||
|
||||
/**
|
||||
* Source links for Eclipse client. Eclipse IntroURLs.
|
||||
*
|
||||
* @author Alex Boyko
|
||||
*
|
||||
*/
|
||||
public class EclipseSourceLinks implements SourceLinks {
|
||||
|
||||
private static final String URL_PREFIX = "http://org.eclipse.ui.intro/execute?command=";
|
||||
private static final String EQUALS = "=";
|
||||
private static final String PARAMETERS_SEPARATOR = ",";
|
||||
private static final String PARAMETERS_START = "(";
|
||||
private static final String PARAMETERS_END = ")";
|
||||
|
||||
private static final String JAVA_TYPE_COMMAND = "org.springframework.tooling.boot.ls.OpenJavaType";
|
||||
private static final String FQ_NAME_PARAMETER_ID = "fqName";
|
||||
private static final String PROJECT_NAME_PARAMETER_ID = "projectName";
|
||||
|
||||
private static final String RESOURCE_COMMAND = "org.springframework.tooling.boot.ls.OpenResourceInEditor";
|
||||
private static final String PATH = "path";
|
||||
|
||||
|
||||
private static final Supplier<Logger> LOG = Suppliers.memoize(() -> LoggerFactory.getLogger(EclipseSourceLinks.class));
|
||||
|
||||
@Override
|
||||
public Optional<String> sourceLinkUrlForFQName(IJavaProject project, String fqName) {
|
||||
try {
|
||||
StringBuilder paramBuilder = new StringBuilder(JAVA_TYPE_COMMAND);
|
||||
paramBuilder.append(PARAMETERS_START);
|
||||
paramBuilder.append(FQ_NAME_PARAMETER_ID);
|
||||
paramBuilder.append(EQUALS);
|
||||
paramBuilder.append(fqName);
|
||||
if (project != null && project.getElementName() != null) {
|
||||
paramBuilder.append(PARAMETERS_SEPARATOR);
|
||||
paramBuilder.append(PROJECT_NAME_PARAMETER_ID);
|
||||
paramBuilder.append(EQUALS);
|
||||
paramBuilder.append(project.getElementName());
|
||||
}
|
||||
paramBuilder.append(PARAMETERS_END);
|
||||
|
||||
StringBuilder urlBuilder = new StringBuilder(URL_PREFIX);
|
||||
urlBuilder.append(URLEncoder.encode(paramBuilder.toString(), "UTF8"));
|
||||
return Optional.of(urlBuilder.toString());
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
LOG.get().error("{}", e);
|
||||
}
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<String> sourceLinkUrlForClasspathResource(IJavaProject project, String path) {
|
||||
int idx = path.lastIndexOf(CLASS);
|
||||
if (idx >= 0) {
|
||||
Path p = Paths.get(path.substring(0, idx));
|
||||
return sourceLinkUrlForFQName(project, p.toString().replace(File.separator, "."));
|
||||
}
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<String> sourceLinkForResourcePath(Path path) {
|
||||
try {
|
||||
if (path != null) {
|
||||
StringBuilder paramBuilder = new StringBuilder(RESOURCE_COMMAND);
|
||||
paramBuilder.append(PARAMETERS_START);
|
||||
paramBuilder.append(PATH);
|
||||
paramBuilder.append(EQUALS);
|
||||
paramBuilder.append(path);
|
||||
paramBuilder.append(PARAMETERS_END);
|
||||
|
||||
StringBuilder urlBuilder = new StringBuilder(URL_PREFIX);
|
||||
urlBuilder.append(URLEncoder.encode(paramBuilder.toString(), "UTF8"));
|
||||
return Optional.of(urlBuilder.toString());
|
||||
}
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
LOG.get().error("{}", e);
|
||||
}
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -53,6 +53,8 @@ public final class SourceLinkFactory {
|
||||
switch (LspClient.currentClient()) {
|
||||
case VSCODE:
|
||||
return new VSCodeSourceLinks(server);
|
||||
case ECLIPSE:
|
||||
return new EclipseSourceLinks();
|
||||
default:
|
||||
return NO_SOURCE_LINKS;
|
||||
}
|
||||
|
||||
@@ -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