refactored boot java handlers to be more dynamic and structured around spring types

This commit is contained in:
Martin Lippert
2017-08-28 14:51:44 +02:00
parent 698cc8ef97
commit 51ad3f58fd
16 changed files with 333 additions and 115 deletions

View File

@@ -12,10 +12,10 @@ package org.springframework.ide.vscode.boot.java;
import org.springframework.ide.vscode.boot.java.completions.BootJavaCompletionEngine;
import org.springframework.ide.vscode.boot.java.completions.BootJavaReconcileEngine;
import org.springframework.ide.vscode.boot.java.hover.BootJavaHoverProvider;
import org.springframework.ide.vscode.boot.java.references.BootJavaReferencesHandler;
import org.springframework.ide.vscode.boot.java.symbols.BootJavaDocumentSymbolHandler;
import org.springframework.ide.vscode.boot.java.symbols.BootJavaWorkspaceSymbolHandler;
import org.springframework.ide.vscode.boot.java.handlers.BootJavaDocumentSymbolHandler;
import org.springframework.ide.vscode.boot.java.handlers.BootJavaHoverProvider;
import org.springframework.ide.vscode.boot.java.handlers.BootJavaReferencesHandler;
import org.springframework.ide.vscode.boot.java.handlers.BootJavaWorkspaceSymbolHandler;
import org.springframework.ide.vscode.boot.metadata.SpringPropertyIndexProvider;
import org.springframework.ide.vscode.commons.gradle.GradleCore;
import org.springframework.ide.vscode.commons.gradle.GradleProjectFinderStrategy;

View File

@@ -8,10 +8,11 @@
* Contributors:
* Pivotal, Inc. - initial API and implementation
*******************************************************************************/
package org.springframework.ide.vscode.boot.java.symbols;
package org.springframework.ide.vscode.boot.java.handlers;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Stream;
@@ -22,18 +23,16 @@ import org.eclipse.jdt.core.dom.ASTNode;
import org.eclipse.jdt.core.dom.ASTParser;
import org.eclipse.jdt.core.dom.ASTVisitor;
import org.eclipse.jdt.core.dom.Annotation;
import org.eclipse.jdt.core.dom.AnnotationTypeDeclaration;
import org.eclipse.jdt.core.dom.AnnotationTypeMemberDeclaration;
import org.eclipse.jdt.core.dom.CompilationUnit;
import org.eclipse.jdt.core.dom.ITypeBinding;
import org.eclipse.jdt.core.dom.MarkerAnnotation;
import org.eclipse.jdt.core.dom.MemberValuePair;
import org.eclipse.jdt.core.dom.NormalAnnotation;
import org.eclipse.jdt.core.dom.SingleMemberAnnotation;
import org.eclipse.lsp4j.DocumentSymbolParams;
import org.eclipse.lsp4j.Location;
import org.eclipse.lsp4j.SymbolInformation;
import org.eclipse.lsp4j.SymbolKind;
import org.springframework.ide.vscode.boot.java.requestmapping.RequestMappingSymbolProvider;
import org.springframework.ide.vscode.commons.java.IClasspath;
import org.springframework.ide.vscode.commons.java.IJavaProject;
import org.springframework.ide.vscode.commons.languageserver.java.JavaProjectFinder;
@@ -50,10 +49,14 @@ public class BootJavaDocumentSymbolHandler implements DocumentSymbolHandler {
private SimpleLanguageServer server;
private JavaProjectFinder projectFinder;
private Map<String, SymbolProvider> symbolProviders;
public BootJavaDocumentSymbolHandler(SimpleLanguageServer server, JavaProjectFinder projectFinder) {
this.server = server;
this.projectFinder = projectFinder;
this.symbolProviders = new HashMap<>();
RequestMappingSymbolProvider.register(this.symbolProviders);
}
@Override
@@ -102,57 +105,22 @@ public class BootJavaDocumentSymbolHandler implements DocumentSymbolHandler {
private List<? extends SymbolInformation> provideDocumentSymbolsForAnnotations(ASTNode node, TextDocument doc) {
List<SymbolInformation> result = new ArrayList<>();
ASTVisitor visitor = new ASTVisitor() {
@Override
public boolean visit(AnnotationTypeDeclaration node) {
// TODO Auto-generated method stub
return super.visit(node);
}
@Override
public boolean visit(SingleMemberAnnotation node) {
ITypeBinding type = node.resolveTypeBinding();
if (type != null) {
String qualifiedName = type.getQualifiedName();
if (qualifiedName != null && qualifiedName.startsWith("org.springframework")) {
provideDocumentSymbolsForSpringAnnotations(node, type, doc, result);
}
}
return super.visit(node);
}
@Override
public boolean visit(AnnotationTypeMemberDeclaration node) {
// TODO Auto-generated method stub
return super.visit(node);
}
@Override
public boolean visit(MemberValuePair node) {
// TODO Auto-generated method stub
extractSymbol(node, doc, result);
return super.visit(node);
}
@Override
public boolean visit(NormalAnnotation node) {
ITypeBinding type = node.resolveTypeBinding();
if (type != null) {
String qualifiedName = type.getQualifiedName();
if (qualifiedName != null && qualifiedName.startsWith("org.springframework")) {
provideDocumentSymbolsForSpringAnnotations(node, type, doc, result);
}
}
extractSymbol(node, doc, result);
return super.visit(node);
}
@Override
public boolean visit(MarkerAnnotation node) {
ITypeBinding type = node.resolveTypeBinding();
if (type != null) {
String qualifiedName = type.getQualifiedName();
if (qualifiedName != null && qualifiedName.startsWith("org.springframework")) {
provideDocumentSymbolsForSpringAnnotations(node, type, doc, result);
}
}
extractSymbol(node, doc, result);
return super.visit(node);
}
};
@@ -161,11 +129,37 @@ public class BootJavaDocumentSymbolHandler implements DocumentSymbolHandler {
return result;
}
private void provideDocumentSymbolsForSpringAnnotations(Annotation node, ITypeBinding type,
TextDocument doc, List<SymbolInformation> resultAccumulator) {
private void extractSymbol(Annotation node, TextDocument doc, List<SymbolInformation> result) {
System.out.println("annotation found: " + node.toString());
ITypeBinding typeBinding = node.resolveTypeBinding();
if (typeBinding != null) {
String qualifiedTypeName = typeBinding.getQualifiedName();
SymbolProvider provider = symbolProviders.get(qualifiedTypeName);
if (provider != null) {
SymbolInformation symbol = provider.getSymbol(node, doc);
if (symbol != null) {
result.add(symbol);
}
}
else {
provideDefaultSymbol(node, doc, result);
}
}
}
private void provideDefaultSymbol(Annotation node, TextDocument doc, List<SymbolInformation> result) {
try {
resultAccumulator.add(new SymbolInformation(node.toString(), SymbolKind.Interface, new Location(doc.getUri(),
doc.toRange(node.getStartPosition(), node.getLength()))));
ITypeBinding type = node.resolveTypeBinding();
if (type != null) {
String qualifiedName = type.getQualifiedName();
if (qualifiedName != null && qualifiedName.startsWith("org.springframework")) {
SymbolInformation symbol = new SymbolInformation(node.toString(), SymbolKind.Interface,
new Location(doc.getUri(), doc.toRange(node.getStartPosition(), node.getLength())));
result.add(symbol);
}
}
}
catch (Exception e) {
e.printStackTrace();

View File

@@ -8,9 +8,10 @@
* Contributors:
* Pivotal, Inc. - initial API and implementation
*******************************************************************************/
package org.springframework.ide.vscode.boot.java.hover;
package org.springframework.ide.vscode.boot.java.handlers;
import java.nio.file.Path;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.CompletableFuture;
import java.util.stream.Stream;
@@ -25,6 +26,8 @@ import org.eclipse.jdt.core.dom.ITypeBinding;
import org.eclipse.jdt.core.dom.NodeFinder;
import org.eclipse.lsp4j.Hover;
import org.eclipse.lsp4j.TextDocumentPositionParams;
import org.springframework.ide.vscode.boot.java.requestmapping.RequestMappingHoverProvider;
import org.springframework.ide.vscode.boot.java.value.ValueHoverProvider;
import org.springframework.ide.vscode.commons.java.IClasspath;
import org.springframework.ide.vscode.commons.java.IJavaProject;
import org.springframework.ide.vscode.commons.languageserver.java.JavaProjectFinder;
@@ -39,21 +42,18 @@ import org.springframework.ide.vscode.commons.util.text.TextDocument;
*/
public class BootJavaHoverProvider implements HoverHandler {
private static final String SPRING_VALUE = "org.springframework.beans.factory.annotation.Value";
private static final String SPRING_REQUEST_MAPPING = "org.springframework.web.bind.annotation.RequestMapping";
private static final String SPRING_GET_MAPPING = "org.springframework.web.bind.annotation.GetMapping";
private static final String SPRING_POST_MAPPING = "org.springframework.web.bind.annotation.PostMapping";
private static final String SPRING_PUT_MAPPING = "org.springframework.web.bind.annotation.PutMapping";
private static final String SPRING_DELETE_MAPPING = "org.springframework.web.bind.annotation.DeleteMapping";
private static final String SPRING_PATCH_MAPPING = "org.springframework.web.bind.annotation.PatchMapping";
private JavaProjectFinder projectFinder;
private SimpleLanguageServer server;
private Map<String, HoverProvider> hoverProviders;
public BootJavaHoverProvider(SimpleLanguageServer server, JavaProjectFinder projectFinder) {
this.server = server;
this.projectFinder = projectFinder;
this.hoverProviders = new HashMap<>();
RequestMappingHoverProvider.register(this.hoverProviders);
ValueHoverProvider.register(this.hoverProviders);
}
@Override
@@ -128,15 +128,10 @@ public class BootJavaHoverProvider implements HoverHandler {
}
private CompletableFuture<Hover> provideHoverForSpringAnnotation(ASTNode node, Annotation annotation, ITypeBinding type, int offset, TextDocument doc) {
if (type.getQualifiedName().equals(SPRING_VALUE)) {
return new ValueHoverProvider().provideHoverForValueAnnotation(node, annotation, type, offset, doc);
} else if (type.getQualifiedName().equals(SPRING_REQUEST_MAPPING)
|| type.getQualifiedName().equals(SPRING_GET_MAPPING)
|| type.getQualifiedName().equals(SPRING_POST_MAPPING)
|| type.getQualifiedName().equals(SPRING_PUT_MAPPING)
|| type.getQualifiedName().equals(SPRING_DELETE_MAPPING)
|| type.getQualifiedName().equals(SPRING_PATCH_MAPPING)) {
return new RequestMappingHoverProvider().provideHoverForRequestMappingAnnotation(node, annotation, type, offset, doc);
String typeName = type.getQualifiedName();
HoverProvider provider = this.hoverProviders.get(typeName);
if (provider != null) {
return provider.provideHover(node, annotation, type, offset, doc);
}
return null;

View File

@@ -8,7 +8,7 @@
* Contributors:
* Pivotal, Inc. - initial API and implementation
*******************************************************************************/
package org.springframework.ide.vscode.boot.java.references;
package org.springframework.ide.vscode.boot.java.handlers;
import java.nio.file.Path;
import java.util.List;

View File

@@ -1,9 +1,20 @@
package org.springframework.ide.vscode.boot.java.symbols;
/*******************************************************************************
* Copyright (c) 2017 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.handlers;
import java.io.File;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Stream;
@@ -12,6 +23,7 @@ import org.eclipse.jdt.core.JavaCore;
import org.eclipse.jdt.core.dom.AST;
import org.eclipse.jdt.core.dom.ASTParser;
import org.eclipse.jdt.core.dom.ASTVisitor;
import org.eclipse.jdt.core.dom.Annotation;
import org.eclipse.jdt.core.dom.CompilationUnit;
import org.eclipse.jdt.core.dom.ITypeBinding;
import org.eclipse.jdt.core.dom.MarkerAnnotation;
@@ -22,6 +34,7 @@ import org.eclipse.lsp4j.SymbolInformation;
import org.eclipse.lsp4j.SymbolKind;
import org.eclipse.lsp4j.WorkspaceSymbolParams;
import org.springframework.ide.vscode.boot.java.BootJavaLanguageServer;
import org.springframework.ide.vscode.boot.java.requestmapping.RequestMappingSymbolProvider;
import org.springframework.ide.vscode.commons.java.IClasspath;
import org.springframework.ide.vscode.commons.java.IJavaProject;
import org.springframework.ide.vscode.commons.languageserver.java.JavaProjectFinder;
@@ -30,10 +43,14 @@ import org.springframework.ide.vscode.commons.languageserver.util.WorkspaceSymbo
import org.springframework.ide.vscode.commons.util.text.LanguageId;
import org.springframework.ide.vscode.commons.util.text.TextDocument;
/**
* @author Martin Lippert
*/
public class BootJavaWorkspaceSymbolHandler implements WorkspaceSymbolHandler {
private SimpleLanguageServer server;
private JavaProjectFinder projectFinder;
private Map<String, SymbolProvider> symbolProviders;
private List<SymbolInformation> symbols;
@@ -41,6 +58,9 @@ public class BootJavaWorkspaceSymbolHandler implements WorkspaceSymbolHandler {
this.server = server;
this.projectFinder = projectFinder;
this.symbols = new ArrayList<>();
this.symbolProviders = new HashMap<>();
RequestMappingSymbolProvider.register(this.symbolProviders);
}
@Override
@@ -49,6 +69,7 @@ public class BootJavaWorkspaceSymbolHandler implements WorkspaceSymbolHandler {
symbols.clear();
scanFiles(root.toFile());
return collectSymbols();
}
@@ -127,23 +148,13 @@ public class BootJavaWorkspaceSymbolHandler implements WorkspaceSymbolHandler {
}
}
private void scanAST(CompilationUnit cu, TextDocument doc) {
private void scanAST(final CompilationUnit cu, final TextDocument doc) {
cu.accept(new ASTVisitor() {
@Override
public boolean visit(SingleMemberAnnotation node) {
try {
System.out.println("annotation found: " + node.toString());
ITypeBinding typeBinding = node.resolveTypeBinding();
if (typeBinding != null) {
String qualifiedTypeName = typeBinding.getQualifiedName();
if (qualifiedTypeName.startsWith("org.springframework.")) {
SymbolInformation symbol = new SymbolInformation(node.toString(), SymbolKind.Interface,
new Location(doc.getUri(), doc.toRange(node.getStartPosition(), node.getLength())));
symbols.add(symbol);
}
}
extractSymbolInformation(node, doc);
}
catch (Exception e) {
e.printStackTrace();
@@ -155,17 +166,7 @@ public class BootJavaWorkspaceSymbolHandler implements WorkspaceSymbolHandler {
@Override
public boolean visit(NormalAnnotation node) {
try {
System.out.println("annotation found: " + node.toString());
ITypeBinding typeBinding = node.resolveTypeBinding();
if (typeBinding != null) {
String qualifiedTypeName = typeBinding.getQualifiedName();
if (qualifiedTypeName.startsWith("org.springframework.")) {
SymbolInformation symbol = new SymbolInformation(node.toString(), SymbolKind.Interface,
new Location(doc.getUri(), doc.toRange(node.getStartPosition(), node.getLength())));
symbols.add(symbol);
}
}
extractSymbolInformation(node, doc);
}
catch (Exception e) {
e.printStackTrace();
@@ -177,17 +178,7 @@ public class BootJavaWorkspaceSymbolHandler implements WorkspaceSymbolHandler {
@Override
public boolean visit(MarkerAnnotation node) {
try {
System.out.println("annotation found: " + node.toString());
ITypeBinding typeBinding = node.resolveTypeBinding();
if (typeBinding != null) {
String qualifiedTypeName = typeBinding.getQualifiedName();
if (qualifiedTypeName.startsWith("org.springframework.")) {
SymbolInformation symbol = new SymbolInformation(node.toString(), SymbolKind.Interface,
new Location(doc.getUri(), doc.toRange(node.getStartPosition(), node.getLength())));
symbols.add(symbol);
}
}
extractSymbolInformation(node, doc);
}
catch (Exception e) {
e.printStackTrace();
@@ -198,6 +189,48 @@ public class BootJavaWorkspaceSymbolHandler implements WorkspaceSymbolHandler {
});
}
private void extractSymbolInformation(Annotation node, TextDocument doc) {
System.out.println("annotation found: " + node.toString());
ITypeBinding typeBinding = node.resolveTypeBinding();
if (typeBinding != null) {
String qualifiedTypeName = typeBinding.getQualifiedName();
SymbolProvider provider = symbolProviders.get(qualifiedTypeName);
if (provider != null) {
SymbolInformation symbol = provider.getSymbol(node, doc);
if (symbol != null) {
symbols.add(symbol);
}
}
else {
SymbolInformation symbol = provideDefaultSymbol(node, doc);
if (symbol != null) {
symbols.add(symbol);
}
}
}
}
private SymbolInformation provideDefaultSymbol(Annotation node, TextDocument doc) {
try {
ITypeBinding type = node.resolveTypeBinding();
if (type != null) {
String qualifiedName = type.getQualifiedName();
if (qualifiedName != null && qualifiedName.startsWith("org.springframework")) {
SymbolInformation symbol = new SymbolInformation(node.toString(), SymbolKind.Interface,
new Location(doc.getUri(), doc.toRange(node.getStartPosition(), node.getLength())));
return symbol;
}
}
}
catch (Exception e) {
e.printStackTrace();
}
return null;
}
private String[] getClasspathEntries(IJavaProject project) throws Exception {
IClasspath classpath = project.getClasspath();
Stream<Path> classpathEntries = classpath.getClasspathEntries();

View File

@@ -0,0 +1,29 @@
/*******************************************************************************
* Copyright (c) 2017 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.handlers;
import java.util.concurrent.CompletableFuture;
import org.eclipse.jdt.core.dom.ASTNode;
import org.eclipse.jdt.core.dom.Annotation;
import org.eclipse.jdt.core.dom.ITypeBinding;
import org.eclipse.lsp4j.Hover;
import org.springframework.ide.vscode.commons.util.text.TextDocument;
/**
* @author Martin Lippert
*/
public interface HoverProvider {
CompletableFuture<Hover> provideHover(ASTNode node, Annotation annotation, ITypeBinding type, int offset,
TextDocument doc);
}

View File

@@ -0,0 +1,24 @@
/*******************************************************************************
* Copyright (c) 2017 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.handlers;
import org.eclipse.jdt.core.dom.Annotation;
import org.eclipse.lsp4j.SymbolInformation;
import org.springframework.ide.vscode.commons.util.text.TextDocument;
/**
* @author Martin Lippert
*/
public interface SymbolProvider {
SymbolInformation getSymbol(Annotation node, TextDocument doc);
}

View File

@@ -8,7 +8,7 @@
* Contributors:
* Pivotal, Inc. - initial API and implementation
*******************************************************************************/
package org.springframework.ide.vscode.boot.java.references;
package org.springframework.ide.vscode.boot.java.handlers;
import static org.springframework.ide.vscode.commons.yaml.ast.NodeUtil.asScalar;

View File

@@ -0,0 +1,25 @@
/*******************************************************************************
* Copyright (c) 2017 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.requestmapping;
/**
* @author Martin Lippert
*/
public class Constants {
public static final String SPRING_REQUEST_MAPPING = "org.springframework.web.bind.annotation.RequestMapping";
public static final String SPRING_GET_MAPPING = "org.springframework.web.bind.annotation.GetMapping";
public static final String SPRING_POST_MAPPING = "org.springframework.web.bind.annotation.PostMapping";
public static final String SPRING_PUT_MAPPING = "org.springframework.web.bind.annotation.PutMapping";
public static final String SPRING_DELETE_MAPPING = "org.springframework.web.bind.annotation.DeleteMapping";
public static final String SPRING_PATCH_MAPPING = "org.springframework.web.bind.annotation.PatchMapping";
}

View File

@@ -0,0 +1,18 @@
/*******************************************************************************
* Copyright (c) 2017 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.requestmapping;
/**
* @author Martin Lippert
*/
public class RequestMappingAssistProvider {
}

View File

@@ -8,7 +8,7 @@
* Contributors:
* Pivotal, Inc. - initial API and implementation
*******************************************************************************/
package org.springframework.ide.vscode.boot.java.hover;
package org.springframework.ide.vscode.boot.java.requestmapping;
import java.util.ArrayList;
import java.util.Iterator;
@@ -29,15 +29,28 @@ import org.eclipse.lsp4j.MarkedString;
import org.eclipse.lsp4j.Range;
import org.eclipse.lsp4j.jsonrpc.messages.Either;
import org.json.JSONObject;
import org.springframework.ide.vscode.boot.java.handlers.HoverProvider;
import org.springframework.ide.vscode.commons.boot.app.cli.SpringBootApp;
import org.springframework.ide.vscode.commons.util.text.TextDocument;
/**
* @author Martin Lippert
*/
public class RequestMappingHoverProvider {
public class RequestMappingHoverProvider implements HoverProvider {
public CompletableFuture<Hover> provideHoverForRequestMappingAnnotation(ASTNode node, Annotation annotation,
public static void register(Map<String, HoverProvider> hoverProviders) {
RequestMappingHoverProvider provider = new RequestMappingHoverProvider();
hoverProviders.put(Constants.SPRING_REQUEST_MAPPING, provider);
hoverProviders.put(Constants.SPRING_GET_MAPPING, provider);
hoverProviders.put(Constants.SPRING_POST_MAPPING, provider);
hoverProviders.put(Constants.SPRING_PUT_MAPPING, provider);
hoverProviders.put(Constants.SPRING_DELETE_MAPPING, provider);
hoverProviders.put(Constants.SPRING_PATCH_MAPPING, provider);
}
@Override
public CompletableFuture<Hover> provideHover(ASTNode node, Annotation annotation,
ITypeBinding type, int offset, TextDocument doc) {
return provideHover(annotation, doc);
}

View File

@@ -0,0 +1,60 @@
/*******************************************************************************
* Copyright (c) 2017 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.requestmapping;
import java.util.Map;
import org.eclipse.jdt.core.dom.Annotation;
import org.eclipse.lsp4j.Location;
import org.eclipse.lsp4j.SymbolInformation;
import org.eclipse.lsp4j.SymbolKind;
import org.springframework.ide.vscode.boot.java.handlers.SymbolProvider;
import org.springframework.ide.vscode.commons.util.text.TextDocument;
/**
* @author Martin Lippert
*/
public class RequestMappingSymbolProvider implements SymbolProvider {
private static RequestMappingSymbolProvider symbolProvider;
public static void register(Map<String, SymbolProvider> symbolProviders) {
synchronized(RequestMappingSymbolProvider.class) {
if (symbolProvider == null) {
symbolProvider = new RequestMappingSymbolProvider();
}
}
symbolProviders.put(Constants.SPRING_REQUEST_MAPPING, symbolProvider);
symbolProviders.put(Constants.SPRING_GET_MAPPING, symbolProvider);
symbolProviders.put(Constants.SPRING_POST_MAPPING, symbolProvider);
symbolProviders.put(Constants.SPRING_PUT_MAPPING, symbolProvider);
symbolProviders.put(Constants.SPRING_DELETE_MAPPING, symbolProvider);
symbolProviders.put(Constants.SPRING_PATCH_MAPPING, symbolProvider);
}
@Override
public SymbolInformation getSymbol(Annotation node, TextDocument doc) {
try {
SymbolInformation symbol = new SymbolInformation(node.toString(), SymbolKind.Interface,
new Location(doc.getUri(), doc.toRange(node.getStartPosition(), node.getLength())));
return symbol;
}
catch (Exception e) {
e.printStackTrace();
}
return null;
}
}

View File

@@ -0,0 +1,20 @@
/*******************************************************************************
* Copyright (c) 2017 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.value;
/**
* @author Martin Lippert
*/
public class Constants {
public static final String SPRING_VALUE = "org.springframework.beans.factory.annotation.Value";
}

View File

@@ -8,7 +8,7 @@
* Contributors:
* Pivotal, Inc. - initial API and implementation
*******************************************************************************/
package org.springframework.ide.vscode.boot.java.hover;
package org.springframework.ide.vscode.boot.java.value;
import java.util.ArrayList;
import java.util.Iterator;
@@ -26,16 +26,23 @@ import org.eclipse.lsp4j.MarkedString;
import org.eclipse.lsp4j.Range;
import org.eclipse.lsp4j.jsonrpc.messages.Either;
import org.json.JSONObject;
import org.springframework.ide.vscode.boot.java.handlers.HoverProvider;
import org.springframework.ide.vscode.commons.boot.app.cli.SpringBootApp;
import org.springframework.ide.vscode.commons.util.text.TextDocument;
/**
* @author Martin Lippert
*/
public class ValueHoverProvider {
public class ValueHoverProvider implements HoverProvider {
public CompletableFuture<Hover> provideHoverForValueAnnotation(ASTNode node, Annotation annotation,
ITypeBinding type, int offset, TextDocument doc) {
public static void register(Map<String, HoverProvider> hoverProviders) {
ValueHoverProvider provider = new ValueHoverProvider();
hoverProviders.put(Constants.SPRING_VALUE, provider);
}
@Override
public CompletableFuture<Hover> provideHover(ASTNode node, Annotation annotation, ITypeBinding type, int offset,
TextDocument doc) {
try {
// case: @Value("prefix<*>")

View File

@@ -14,7 +14,7 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import org.junit.Test;
import org.springframework.ide.vscode.boot.java.hover.ValueHoverProvider;
import org.springframework.ide.vscode.boot.java.value.ValueHoverProvider;
/**
* @author Martin Lippert

View File

@@ -21,7 +21,7 @@ import java.util.concurrent.CompletableFuture;
import org.eclipse.lsp4j.Location;
import org.junit.Test;
import org.springframework.ide.vscode.boot.java.references.ValuePropertyReferencesProvider;
import org.springframework.ide.vscode.boot.java.handlers.ValuePropertyReferencesProvider;
import org.springframework.ide.vscode.project.harness.ProjectsHarness;
/**