diff --git a/headless-services/boot-java-language-server/src/main/java/org/springframework/ide/vscode/boot/java/BootJavaLanguageServer.java b/headless-services/boot-java-language-server/src/main/java/org/springframework/ide/vscode/boot/java/BootJavaLanguageServer.java index c7b616035..c646fbae1 100644 --- a/headless-services/boot-java-language-server/src/main/java/org/springframework/ide/vscode/boot/java/BootJavaLanguageServer.java +++ b/headless-services/boot-java-language-server/src/main/java/org/springframework/ide/vscode/boot/java/BootJavaLanguageServer.java @@ -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; diff --git a/headless-services/boot-java-language-server/src/main/java/org/springframework/ide/vscode/boot/java/symbols/BootJavaDocumentSymbolHandler.java b/headless-services/boot-java-language-server/src/main/java/org/springframework/ide/vscode/boot/java/handlers/BootJavaDocumentSymbolHandler.java similarity index 72% rename from headless-services/boot-java-language-server/src/main/java/org/springframework/ide/vscode/boot/java/symbols/BootJavaDocumentSymbolHandler.java rename to headless-services/boot-java-language-server/src/main/java/org/springframework/ide/vscode/boot/java/handlers/BootJavaDocumentSymbolHandler.java index 553d26e32..5bd55cb88 100644 --- a/headless-services/boot-java-language-server/src/main/java/org/springframework/ide/vscode/boot/java/symbols/BootJavaDocumentSymbolHandler.java +++ b/headless-services/boot-java-language-server/src/main/java/org/springframework/ide/vscode/boot/java/handlers/BootJavaDocumentSymbolHandler.java @@ -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 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 provideDocumentSymbolsForAnnotations(ASTNode node, TextDocument doc) { List 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 resultAccumulator) { + private void extractSymbol(Annotation node, TextDocument doc, List 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 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(); diff --git a/headless-services/boot-java-language-server/src/main/java/org/springframework/ide/vscode/boot/java/hover/BootJavaHoverProvider.java b/headless-services/boot-java-language-server/src/main/java/org/springframework/ide/vscode/boot/java/handlers/BootJavaHoverProvider.java similarity index 77% rename from headless-services/boot-java-language-server/src/main/java/org/springframework/ide/vscode/boot/java/hover/BootJavaHoverProvider.java rename to headless-services/boot-java-language-server/src/main/java/org/springframework/ide/vscode/boot/java/handlers/BootJavaHoverProvider.java index 6e0b0f5c9..5296895c0 100644 --- a/headless-services/boot-java-language-server/src/main/java/org/springframework/ide/vscode/boot/java/hover/BootJavaHoverProvider.java +++ b/headless-services/boot-java-language-server/src/main/java/org/springframework/ide/vscode/boot/java/handlers/BootJavaHoverProvider.java @@ -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 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 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; diff --git a/headless-services/boot-java-language-server/src/main/java/org/springframework/ide/vscode/boot/java/references/BootJavaReferencesHandler.java b/headless-services/boot-java-language-server/src/main/java/org/springframework/ide/vscode/boot/java/handlers/BootJavaReferencesHandler.java similarity index 98% rename from headless-services/boot-java-language-server/src/main/java/org/springframework/ide/vscode/boot/java/references/BootJavaReferencesHandler.java rename to headless-services/boot-java-language-server/src/main/java/org/springframework/ide/vscode/boot/java/handlers/BootJavaReferencesHandler.java index a0e9b6751..078311047 100644 --- a/headless-services/boot-java-language-server/src/main/java/org/springframework/ide/vscode/boot/java/references/BootJavaReferencesHandler.java +++ b/headless-services/boot-java-language-server/src/main/java/org/springframework/ide/vscode/boot/java/handlers/BootJavaReferencesHandler.java @@ -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; diff --git a/headless-services/boot-java-language-server/src/main/java/org/springframework/ide/vscode/boot/java/symbols/BootJavaWorkspaceSymbolHandler.java b/headless-services/boot-java-language-server/src/main/java/org/springframework/ide/vscode/boot/java/handlers/BootJavaWorkspaceSymbolHandler.java similarity index 68% rename from headless-services/boot-java-language-server/src/main/java/org/springframework/ide/vscode/boot/java/symbols/BootJavaWorkspaceSymbolHandler.java rename to headless-services/boot-java-language-server/src/main/java/org/springframework/ide/vscode/boot/java/handlers/BootJavaWorkspaceSymbolHandler.java index 7504c0564..3afbcebcd 100644 --- a/headless-services/boot-java-language-server/src/main/java/org/springframework/ide/vscode/boot/java/symbols/BootJavaWorkspaceSymbolHandler.java +++ b/headless-services/boot-java-language-server/src/main/java/org/springframework/ide/vscode/boot/java/handlers/BootJavaWorkspaceSymbolHandler.java @@ -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 symbolProviders; private List 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 classpathEntries = classpath.getClasspathEntries(); diff --git a/headless-services/boot-java-language-server/src/main/java/org/springframework/ide/vscode/boot/java/handlers/HoverProvider.java b/headless-services/boot-java-language-server/src/main/java/org/springframework/ide/vscode/boot/java/handlers/HoverProvider.java new file mode 100644 index 000000000..69df36e53 --- /dev/null +++ b/headless-services/boot-java-language-server/src/main/java/org/springframework/ide/vscode/boot/java/handlers/HoverProvider.java @@ -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 provideHover(ASTNode node, Annotation annotation, ITypeBinding type, int offset, + TextDocument doc); + +} diff --git a/headless-services/boot-java-language-server/src/main/java/org/springframework/ide/vscode/boot/java/handlers/SymbolProvider.java b/headless-services/boot-java-language-server/src/main/java/org/springframework/ide/vscode/boot/java/handlers/SymbolProvider.java new file mode 100644 index 000000000..701da570d --- /dev/null +++ b/headless-services/boot-java-language-server/src/main/java/org/springframework/ide/vscode/boot/java/handlers/SymbolProvider.java @@ -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); + +} diff --git a/headless-services/boot-java-language-server/src/main/java/org/springframework/ide/vscode/boot/java/references/ValuePropertyReferencesProvider.java b/headless-services/boot-java-language-server/src/main/java/org/springframework/ide/vscode/boot/java/handlers/ValuePropertyReferencesProvider.java similarity index 99% rename from headless-services/boot-java-language-server/src/main/java/org/springframework/ide/vscode/boot/java/references/ValuePropertyReferencesProvider.java rename to headless-services/boot-java-language-server/src/main/java/org/springframework/ide/vscode/boot/java/handlers/ValuePropertyReferencesProvider.java index b0a7b9ece..f01d0a9bd 100644 --- a/headless-services/boot-java-language-server/src/main/java/org/springframework/ide/vscode/boot/java/references/ValuePropertyReferencesProvider.java +++ b/headless-services/boot-java-language-server/src/main/java/org/springframework/ide/vscode/boot/java/handlers/ValuePropertyReferencesProvider.java @@ -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; diff --git a/headless-services/boot-java-language-server/src/main/java/org/springframework/ide/vscode/boot/java/requestmapping/Constants.java b/headless-services/boot-java-language-server/src/main/java/org/springframework/ide/vscode/boot/java/requestmapping/Constants.java new file mode 100644 index 000000000..8d655ce30 --- /dev/null +++ b/headless-services/boot-java-language-server/src/main/java/org/springframework/ide/vscode/boot/java/requestmapping/Constants.java @@ -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"; + +} diff --git a/headless-services/boot-java-language-server/src/main/java/org/springframework/ide/vscode/boot/java/requestmapping/RequestMappingAssistProvider.java b/headless-services/boot-java-language-server/src/main/java/org/springframework/ide/vscode/boot/java/requestmapping/RequestMappingAssistProvider.java new file mode 100644 index 000000000..2559a031b --- /dev/null +++ b/headless-services/boot-java-language-server/src/main/java/org/springframework/ide/vscode/boot/java/requestmapping/RequestMappingAssistProvider.java @@ -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 { + +} diff --git a/headless-services/boot-java-language-server/src/main/java/org/springframework/ide/vscode/boot/java/hover/RequestMappingHoverProvider.java b/headless-services/boot-java-language-server/src/main/java/org/springframework/ide/vscode/boot/java/requestmapping/RequestMappingHoverProvider.java similarity index 83% rename from headless-services/boot-java-language-server/src/main/java/org/springframework/ide/vscode/boot/java/hover/RequestMappingHoverProvider.java rename to headless-services/boot-java-language-server/src/main/java/org/springframework/ide/vscode/boot/java/requestmapping/RequestMappingHoverProvider.java index 39e8a4f69..9b6ededa5 100644 --- a/headless-services/boot-java-language-server/src/main/java/org/springframework/ide/vscode/boot/java/hover/RequestMappingHoverProvider.java +++ b/headless-services/boot-java-language-server/src/main/java/org/springframework/ide/vscode/boot/java/requestmapping/RequestMappingHoverProvider.java @@ -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 provideHoverForRequestMappingAnnotation(ASTNode node, Annotation annotation, + public static void register(Map 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 provideHover(ASTNode node, Annotation annotation, ITypeBinding type, int offset, TextDocument doc) { return provideHover(annotation, doc); } diff --git a/headless-services/boot-java-language-server/src/main/java/org/springframework/ide/vscode/boot/java/requestmapping/RequestMappingSymbolProvider.java b/headless-services/boot-java-language-server/src/main/java/org/springframework/ide/vscode/boot/java/requestmapping/RequestMappingSymbolProvider.java new file mode 100644 index 000000000..60cac2ce5 --- /dev/null +++ b/headless-services/boot-java-language-server/src/main/java/org/springframework/ide/vscode/boot/java/requestmapping/RequestMappingSymbolProvider.java @@ -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 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; + } + + +} diff --git a/headless-services/boot-java-language-server/src/main/java/org/springframework/ide/vscode/boot/java/value/Constants.java b/headless-services/boot-java-language-server/src/main/java/org/springframework/ide/vscode/boot/java/value/Constants.java new file mode 100644 index 000000000..95bdcf7d9 --- /dev/null +++ b/headless-services/boot-java-language-server/src/main/java/org/springframework/ide/vscode/boot/java/value/Constants.java @@ -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"; + +} diff --git a/headless-services/boot-java-language-server/src/main/java/org/springframework/ide/vscode/boot/java/hover/ValueHoverProvider.java b/headless-services/boot-java-language-server/src/main/java/org/springframework/ide/vscode/boot/java/value/ValueHoverProvider.java similarity index 90% rename from headless-services/boot-java-language-server/src/main/java/org/springframework/ide/vscode/boot/java/hover/ValueHoverProvider.java rename to headless-services/boot-java-language-server/src/main/java/org/springframework/ide/vscode/boot/java/value/ValueHoverProvider.java index a17941e10..4f615be6f 100644 --- a/headless-services/boot-java-language-server/src/main/java/org/springframework/ide/vscode/boot/java/hover/ValueHoverProvider.java +++ b/headless-services/boot-java-language-server/src/main/java/org/springframework/ide/vscode/boot/java/value/ValueHoverProvider.java @@ -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 provideHoverForValueAnnotation(ASTNode node, Annotation annotation, - ITypeBinding type, int offset, TextDocument doc) { + public static void register(Map hoverProviders) { + ValueHoverProvider provider = new ValueHoverProvider(); + hoverProviders.put(Constants.SPRING_VALUE, provider); + } + + @Override + public CompletableFuture provideHover(ASTNode node, Annotation annotation, ITypeBinding type, int offset, + TextDocument doc) { try { // case: @Value("prefix<*>") diff --git a/headless-services/boot-java-language-server/src/test/java/org/springframework/ide/vscode/boot/java/hover/test/ValueHoverTest.java b/headless-services/boot-java-language-server/src/test/java/org/springframework/ide/vscode/boot/java/hover/test/ValueHoverTest.java index 63a3401a9..48b816b85 100644 --- a/headless-services/boot-java-language-server/src/test/java/org/springframework/ide/vscode/boot/java/hover/test/ValueHoverTest.java +++ b/headless-services/boot-java-language-server/src/test/java/org/springframework/ide/vscode/boot/java/hover/test/ValueHoverTest.java @@ -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 diff --git a/headless-services/boot-java-language-server/src/test/java/org/springframework/ide/vscode/boot/java/references/test/PropertyReferenceFinderTest.java b/headless-services/boot-java-language-server/src/test/java/org/springframework/ide/vscode/boot/java/references/test/PropertyReferenceFinderTest.java index a253134ef..fcd2c0c7c 100644 --- a/headless-services/boot-java-language-server/src/test/java/org/springframework/ide/vscode/boot/java/references/test/PropertyReferenceFinderTest.java +++ b/headless-services/boot-java-language-server/src/test/java/org/springframework/ide/vscode/boot/java/references/test/PropertyReferenceFinderTest.java @@ -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; /**