diff --git a/microprofile.jdt/com.redhat.microprofile.jdt.core/plugin.xml b/microprofile.jdt/com.redhat.microprofile.jdt.core/plugin.xml
index 8fd6abf9c..11258945e 100644
--- a/microprofile.jdt/com.redhat.microprofile.jdt.core/plugin.xml
+++ b/microprofile.jdt/com.redhat.microprofile.jdt.core/plugin.xml
@@ -25,6 +25,7 @@
+
diff --git a/microprofile.jdt/com.redhat.microprofile.jdt.core/src/main/java/com/redhat/microprofile/commons/JavaKind.java b/microprofile.jdt/com.redhat.microprofile.jdt.core/src/main/java/com/redhat/microprofile/commons/JavaKind.java
new file mode 100644
index 000000000..713cc32d5
--- /dev/null
+++ b/microprofile.jdt/com.redhat.microprofile.jdt.core/src/main/java/com/redhat/microprofile/commons/JavaKind.java
@@ -0,0 +1,52 @@
+/*******************************************************************************
+* Copyright (c) 2020 Red Hat Inc. and others.
+* All rights reserved. This program and the accompanying materials
+* which accompanies this distribution, and is available at
+* http://www.eclipse.org/legal/epl-v20.html
+*
+* SPDX-License-Identifier: EPL-2.0
+*
+* Contributors:
+* Red Hat Inc. - initial API and implementation
+*******************************************************************************/
+package com.redhat.microprofile.commons;
+
+/**
+ * The java element kind.
+ *
+ * @author Angelo ZERR
+ *
+ */
+public enum JavaKind {
+
+ TYPE(1), METHOD(2), ANNOTATION(3);
+
+ private final int value;
+
+ JavaKind(int value) {
+ this.value = value;
+ }
+
+ public int getValue() {
+ return value;
+ }
+
+ public static JavaKind forValue(int value) {
+ JavaKind[] allValues = JavaKind.values();
+ if (value < 1 || value > allValues.length)
+ throw new IllegalArgumentException("Illegal enum value: " + value);
+ return allValues[value - 1];
+ }
+
+ public static JavaKind getScope(String scope) {
+ if (scope != null) {
+ scope = scope.toUpperCase();
+ try {
+ return JavaKind.valueOf(scope);
+ } catch (Exception e) {
+ // Do nothing
+ }
+ }
+ return TYPE;
+ }
+}
diff --git a/microprofile.jdt/com.redhat.microprofile.jdt.core/src/main/java/com/redhat/microprofile/commons/JavaSnippetContext.java b/microprofile.jdt/com.redhat.microprofile.jdt.core/src/main/java/com/redhat/microprofile/commons/JavaSnippetContext.java
new file mode 100644
index 000000000..7b419e774
--- /dev/null
+++ b/microprofile.jdt/com.redhat.microprofile.jdt.core/src/main/java/com/redhat/microprofile/commons/JavaSnippetContext.java
@@ -0,0 +1,28 @@
+package com.redhat.microprofile.commons;
+
+import java.util.List;
+
+public class JavaSnippetContext {
+
+ private JavaKind kind;
+
+ private List type;
+
+ public JavaKind getKind() {
+ return kind;
+ }
+
+ public void setKind(JavaKind kind) {
+ this.kind = kind;
+ }
+
+ public List getType() {
+ return type;
+ }
+
+ public void setType(List type) {
+ this.type = type;
+ }
+
+
+}
diff --git a/microprofile.jdt/com.redhat.microprofile.jdt.core/src/main/java/com/redhat/microprofile/commons/MicroProfileJavaCompletionParams.java b/microprofile.jdt/com.redhat.microprofile.jdt.core/src/main/java/com/redhat/microprofile/commons/MicroProfileJavaCompletionParams.java
new file mode 100644
index 000000000..f3aca718c
--- /dev/null
+++ b/microprofile.jdt/com.redhat.microprofile.jdt.core/src/main/java/com/redhat/microprofile/commons/MicroProfileJavaCompletionParams.java
@@ -0,0 +1,83 @@
+/*******************************************************************************
+* Copyright (c) 2020 Red Hat Inc. and others.
+* All rights reserved. This program and the accompanying materials
+* which accompanies this distribution, and is available at
+* http://www.eclipse.org/legal/epl-v20.html
+*
+* SPDX-License-Identifier: EPL-2.0
+*
+* Contributors:
+* Red Hat Inc. - initial API and implementation
+*******************************************************************************/
+package com.redhat.microprofile.commons;
+
+import java.util.List;
+
+import org.eclipse.lsp4j.Position;
+
+/**
+ * MicroProfile Java completion parameters.
+ *
+ * @author Angelo ZERR
+ *
+ */
+public class MicroProfileJavaCompletionParams {
+
+ private String uri;
+ private Position position;
+ private List contexts;
+
+ public MicroProfileJavaCompletionParams() {
+
+ }
+
+ public MicroProfileJavaCompletionParams(String uri, Position position) {
+ this();
+ setUri(uri);
+ setPosition(position);
+ }
+
+ /**
+ * Returns the java file uri.
+ *
+ * @return the java file uri.
+ */
+ public String getUri() {
+ return uri;
+ }
+
+ /**
+ * Set the java file uri.
+ *
+ * @param uri the java file uri.
+ */
+ public void setUri(String uri) {
+ this.uri = uri;
+ }
+
+ /**
+ * Returns the completion position
+ *
+ * @return the completion position
+ */
+ public Position getPosition() {
+ return position;
+ }
+
+ /**
+ * Sets the completion position
+ *
+ * @param position the completion position
+ */
+ public void setPosition(Position position) {
+ this.position = position;
+ }
+
+ public List getContexts() {
+ return contexts;
+ }
+
+ public void setContexts(List contexts) {
+ this.contexts = contexts;
+ }
+}
diff --git a/microprofile.jdt/com.redhat.microprofile.jdt.core/src/main/java/com/redhat/microprofile/commons/MicroProfileJavaCompletionResult.java b/microprofile.jdt/com.redhat.microprofile.jdt.core/src/main/java/com/redhat/microprofile/commons/MicroProfileJavaCompletionResult.java
new file mode 100644
index 000000000..eef7ed377
--- /dev/null
+++ b/microprofile.jdt/com.redhat.microprofile.jdt.core/src/main/java/com/redhat/microprofile/commons/MicroProfileJavaCompletionResult.java
@@ -0,0 +1,33 @@
+/*******************************************************************************
+* Copyright (c) 2020 Red Hat Inc. and others.
+* All rights reserved. This program and the accompanying materials
+* which accompanies this distribution, and is available at
+* http://www.eclipse.org/legal/epl-v20.html
+*
+* SPDX-License-Identifier: EPL-2.0
+*
+* Contributors:
+* Red Hat Inc. - initial API and implementation
+*******************************************************************************/
+package com.redhat.microprofile.commons;
+
+import java.util.List;
+
+/**
+ * MicroProfile Java completion result.
+ *
+ * @author Angelo ZERR
+ *
+ */
+public class MicroProfileJavaCompletionResult {
+
+ private List resolvedContexts;
+
+ public List getResolvedContexts() {
+ return resolvedContexts;
+ }
+
+ public void setResolvedContexts(List resolvedContexts) {
+ this.resolvedContexts = resolvedContexts;
+ }
+}
diff --git a/microprofile.jdt/com.redhat.microprofile.jdt.core/src/main/java/com/redhat/microprofile/jdt/core/PropertiesManagerForJava.java b/microprofile.jdt/com.redhat.microprofile.jdt.core/src/main/java/com/redhat/microprofile/jdt/core/PropertiesManagerForJava.java
index a0bfa1d37..1c5d906d9 100644
--- a/microprofile.jdt/com.redhat.microprofile.jdt.core/src/main/java/com/redhat/microprofile/jdt/core/PropertiesManagerForJava.java
+++ b/microprofile.jdt/com.redhat.microprofile.jdt.core/src/main/java/com/redhat/microprofile/jdt/core/PropertiesManagerForJava.java
@@ -22,16 +22,16 @@
import org.eclipse.jdt.core.JavaModelException;
import org.eclipse.lsp4j.CodeAction;
import org.eclipse.lsp4j.CodeLens;
-import org.eclipse.lsp4j.Command;
import org.eclipse.lsp4j.Diagnostic;
import org.eclipse.lsp4j.Hover;
import org.eclipse.lsp4j.Position;
import org.eclipse.lsp4j.PublishDiagnosticsParams;
-import org.eclipse.lsp4j.jsonrpc.messages.Either;
import com.redhat.microprofile.commons.DocumentFormat;
import com.redhat.microprofile.commons.MicroProfileJavaCodeActionParams;
import com.redhat.microprofile.commons.MicroProfileJavaCodeLensParams;
+import com.redhat.microprofile.commons.MicroProfileJavaCompletionParams;
+import com.redhat.microprofile.commons.MicroProfileJavaCompletionResult;
import com.redhat.microprofile.commons.MicroProfileJavaDiagnosticsParams;
import com.redhat.microprofile.commons.MicroProfileJavaHoverParams;
import com.redhat.microprofile.jdt.core.java.codelens.JavaCodeLensContext;
@@ -41,6 +41,7 @@
import com.redhat.microprofile.jdt.internal.core.java.JavaFeaturesRegistry;
import com.redhat.microprofile.jdt.internal.core.java.codeaction.CodeActionHandler;
import com.redhat.microprofile.jdt.internal.core.java.codelens.JavaCodeLensDefinition;
+import com.redhat.microprofile.jdt.internal.core.java.completion.CompletionHandler;
import com.redhat.microprofile.jdt.internal.core.java.diagnostics.JavaDiagnosticsDefinition;
import com.redhat.microprofile.jdt.internal.core.java.hover.JavaHoverDefinition;
@@ -60,8 +61,11 @@ public static PropertiesManagerForJava getInstance() {
private final CodeActionHandler codeActionHandler;
+ private final CompletionHandler completionHandler;
+
private PropertiesManagerForJava() {
this.codeActionHandler = new CodeActionHandler();
+ this.completionHandler = new CompletionHandler();
}
/**
@@ -124,6 +128,20 @@ private void collectCodeLens(String uri, ITypeRoot typeRoot, IJDTUtils utils, Mi
definitions.forEach(definition -> definition.endCodeLens(context, monitor));
}
+ /**
+ * Returns completion result for the given uri and position.
+ *
+ * @param params the completion parameters
+ * @param utils the utilities class
+ * @param monitor the monitor
+ * @return completion result for the given uri and position.
+ * @throws JavaModelException
+ */
+ public MicroProfileJavaCompletionResult completion(MicroProfileJavaCompletionParams params, IJDTUtils utils,
+ IProgressMonitor monitor) throws JavaModelException {
+ return completionHandler.completion(params, utils, monitor);
+ }
+
/**
* Returns diagnostics for the given uris list.
*
diff --git a/microprofile.jdt/com.redhat.microprofile.jdt.core/src/main/java/com/redhat/microprofile/jdt/internal/core/java/completion/CompletionHandler.java b/microprofile.jdt/com.redhat.microprofile.jdt.core/src/main/java/com/redhat/microprofile/jdt/internal/core/java/completion/CompletionHandler.java
new file mode 100644
index 000000000..a42135ed1
--- /dev/null
+++ b/microprofile.jdt/com.redhat.microprofile.jdt.core/src/main/java/com/redhat/microprofile/jdt/internal/core/java/completion/CompletionHandler.java
@@ -0,0 +1,236 @@
+/*******************************************************************************
+* Copyright (c) 2020 Red Hat Inc. and others.
+* All rights reserved. This program and the accompanying materials
+* which accompanies this distribution, and is available at
+* http://www.eclipse.org/legal/epl-v20.html
+*
+* SPDX-License-Identifier: EPL-2.0
+*
+* Contributors:
+* Red Hat Inc. - initial API and implementation
+*******************************************************************************/
+package com.redhat.microprofile.jdt.internal.core.java.completion;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.jdt.core.IAnnotation;
+import org.eclipse.jdt.core.ICompilationUnit;
+import org.eclipse.jdt.core.IJavaProject;
+import org.eclipse.jdt.core.IMemberValuePair;
+import org.eclipse.jdt.core.IType;
+import org.eclipse.jdt.core.JavaModelException;
+import org.eclipse.jdt.core.dom.CompilationUnit;
+import org.eclipse.jdt.core.dom.NodeFinder;
+import org.eclipse.jdt.core.manipulation.CoreASTProvider;
+import org.eclipse.jdt.internal.codeassist.complete.CompletionOnMarkerAnnotationName;
+import org.eclipse.jdt.internal.compiler.ast.ASTNode;
+
+import com.redhat.microprofile.commons.JavaKind;
+import com.redhat.microprofile.commons.JavaSnippetContext;
+import com.redhat.microprofile.commons.MicroProfileJavaCompletionParams;
+import com.redhat.microprofile.commons.MicroProfileJavaCompletionResult;
+import com.redhat.microprofile.jdt.core.utils.AnnotationUtils;
+import com.redhat.microprofile.jdt.core.utils.IJDTUtils;
+import com.redhat.microprofile.jdt.core.utils.JDTTypeUtils;
+import com.redhat.microprofile.jdt.internal.core.java.completion.JavaScopeFinder.JavaScope;
+
+/**
+ * Java completion handler.
+ *
+ * @author Angelo ZERR
+ *
+ */
+public class CompletionHandler {
+
+ /**
+ * Returns completion result for the given uri and position.
+ *
+ * @param params the completion parameters
+ * @param utils the utilities class
+ * @param monitor the monitor
+ * @return completion result for the given uri and position.
+ * @throws JavaModelException
+ */
+ public MicroProfileJavaCompletionResult completion(MicroProfileJavaCompletionParams params, IJDTUtils utils,
+ IProgressMonitor monitor) throws JavaModelException {
+ MicroProfileJavaCompletionResult result = new MicroProfileJavaCompletionResult();
+
+ String uri = params.getUri();
+ ICompilationUnit unit = utils.resolveCompilationUnit(uri);
+ if (unit == null) {
+ return result;
+ }
+
+ IJavaProject javaProject = unit.getJavaProject();
+ int offset = utils.toOffset(unit.getBuffer(), params.getPosition().getLine(),
+ params.getPosition().getCharacter());
+ JavaScope scope = getJavaScope(unit, offset, monitor);
+
+ List resolvedContexts = new ArrayList<>();
+ result.setResolvedContexts(resolvedContexts);
+ for (JavaSnippetContext context : params.getContexts()) {
+ resolvedContexts.add(resolve(context, scope, javaProject));
+ }
+
+ /*
+ * JavaScope scope = getJavaScope(unit, offset, monitor);
+ * result.setScope(scope);
+ *
+ * if (params.isCollectProjectDependencies()) { List projectDependencies
+ * = Stream.of(((JavaProject) javaProject).getResolvedClasspath()) .map(entry ->
+ * getExtensionName(entry.getPath().toString())).filter(Objects::nonNull).
+ * collect(Collectors.toList());
+ * result.setProjectDependencies(projectDependencies); }
+ */
+ /*
+ * CompletionProposalRequestor collector = new CompletionProposalRequestor(unit,
+ * offset); unit.codeComplete(offset, collector);
+ *
+ * CompletionContext completionContext = collector.getContext(); if
+ * (completionContext instanceof InternalCompletionContext) { ASTNode node =
+ * ((InternalCompletionContext) completionContext).getCompletionNode();
+ * result.setScope(getJavaScope(node, unit, completionContext.getTokenStart(),
+ * offset, monitor)); }
+ */
+ return result;
+ }
+
+ private boolean resolve(JavaSnippetContext context, JavaScope scope, IJavaProject javaProject) {
+ if (context == null) {
+ return true;
+ }
+ if (context.getKind() == JavaKind.ANNOTATION) {
+ String type = context.getType().get(0);
+ IType annotationType = JDTTypeUtils.findType(javaProject, type);
+ if (annotationType != null) {
+ try {
+ IAnnotation target = AnnotationUtils.getAnnotation(annotationType, "java.lang.annotation.Target");
+ if (target != null) {
+ List all = null;
+ IMemberValuePair pair = target.getMemberValuePairs()[0];
+ if (pair.getValue() instanceof String) {
+ all = Arrays.asList(getName(((String) pair.getValue())));
+ } else if (pair.getValue() instanceof String[]) {
+ all = Stream.of((String[]) pair.getValue()).map(v -> getName(v))
+ .collect(Collectors.toList());
+ }
+ if (all.isEmpty()) {
+ return true;
+ }
+ switch (scope) {
+ case TYPE:
+ return all.contains("TYPE");
+ case FIELD:
+ return all.contains("FIELD");
+ case METHOD:
+ return all.contains("METHOD");
+ case PARAMETER:
+ return all.contains("PARAMETER");
+ default:
+ return true;
+ }
+
+ }
+ } catch (JavaModelException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+ return false;
+
+ }
+ if (context.getType() != null) {
+ for (String type : context.getType()) {
+ if (JDTTypeUtils.findType(javaProject, type) == null) {
+ return false;
+ }
+ }
+ }
+ return true;
+ }
+
+ private static String getName(String v) {
+ return v.substring(v.lastIndexOf('.') + 1);
+ }
+
+ private static String getExtensionName(String location) {
+ if (location == null) {
+ return null;
+ }
+ if (!location.endsWith(".jar")) {
+ return null;
+ }
+ int start = location.lastIndexOf('/');
+ if (start == -1) {
+ return null;
+ }
+ start++;
+ int end = location.lastIndexOf('-');
+ if (end == -1) {
+ end = location.lastIndexOf('.');
+ }
+ if (end < start) {
+ return null;
+ }
+ String extensionName = location.substring(start, end);
+ if (extensionName.endsWith("-deployment")) {
+ extensionName = extensionName.substring(0, extensionName.length() - "-deployment".length());
+ }
+ return extensionName;
+ }
+
+ private static JavaScope getJavaScope(ICompilationUnit unit, int start, IProgressMonitor monitor) {
+ CompilationUnit ast = CoreASTProvider.getInstance().getAST(unit, CoreASTProvider.WAIT_YES, monitor);
+ JavaScopeFinder finder = new JavaScopeFinder(ast, start);
+ return finder.getScope();
+ }
+
+ private static JavaScope getOLDJavaScope(ASTNode node, ICompilationUnit unit, int start, int end,
+ IProgressMonitor monitor) {
+ CompilationUnit ast = CoreASTProvider.getInstance().getAST(unit, CoreASTProvider.WAIT_YES, monitor);
+ JavaScopeFinder finder = new JavaScopeFinder(ast, start);
+ JavaScope scope = finder.getScope();
+ if (true) {
+ return scope;
+ }
+ if (node instanceof CompletionOnMarkerAnnotationName) {
+
+ NodeFinder nodeFinder = new NodeFinder(ast, start, 100);
+ org.eclipse.jdt.core.dom.ASTNode coveredNode = nodeFinder.getCoveredNode();
+ org.eclipse.jdt.core.dom.ASTNode coveringNode = nodeFinder.getCoveringNode();
+ // nodeFinder.getCoveredNode()
+ if (coveredNode != null) {
+
+ }
+// if (coveringNode != null) {
+// switch (coveringNode.getNodeType()) {
+// case org.eclipse.jdt.core.dom.ASTNode.COMPILATION_UNIT:
+// return JavaKind.TYPE;
+// case org.eclipse.jdt.core.dom.ASTNode.TYPE_DECLARATION:
+// return JavaKind.METHOD;
+// case org.eclipse.jdt.core.dom.ASTNode.METHOD_DECLARATION:
+// return JavaKind.PARAMETER;
+// }
+// }
+ /*
+ * CompletionOnMarkerAnnotationName marker = (CompletionOnMarkerAnnotationName)
+ * node; if ((node.bits & ASTNode.T_JavaLangAnnotationTarget) != 0) { // marker.
+ * }
+ *
+ * TypeReference typeReference = marker.type; Binding recipent =
+ * marker.resolvedType; if (recipent != null) { int kind = recipent.kind();
+ * switch (kind) { case Binding.FIELD: return JavaScope.FIELD; case
+ * Binding.METHOD: return JavaScope.METHOD; case Binding.TYPE_PARAMETER: return
+ * JavaScope.PARAMETER; case Binding.TYPE: return JavaScope.TYPE; default:
+ * break; } }
+ */
+ }
+ return JavaScope.UNKNOWN;
+ }
+
+}
diff --git a/microprofile.jdt/com.redhat.microprofile.jdt.core/src/main/java/com/redhat/microprofile/jdt/internal/core/java/completion/CompletionProposalRequestor.java b/microprofile.jdt/com.redhat.microprofile.jdt.core/src/main/java/com/redhat/microprofile/jdt/internal/core/java/completion/CompletionProposalRequestor.java
new file mode 100644
index 000000000..2f92274a8
--- /dev/null
+++ b/microprofile.jdt/com.redhat.microprofile.jdt.core/src/main/java/com/redhat/microprofile/jdt/internal/core/java/completion/CompletionProposalRequestor.java
@@ -0,0 +1,46 @@
+/*******************************************************************************
+* Copyright (c) 2020 Red Hat Inc. and others.
+* All rights reserved. This program and the accompanying materials
+* which accompanies this distribution, and is available at
+* http://www.eclipse.org/legal/epl-v20.html
+*
+* SPDX-License-Identifier: EPL-2.0
+*
+* Contributors:
+* Red Hat Inc. - initial API and implementation
+*******************************************************************************/
+package com.redhat.microprofile.jdt.internal.core.java.completion;
+
+import org.eclipse.jdt.core.CompletionContext;
+import org.eclipse.jdt.core.CompletionProposal;
+import org.eclipse.jdt.core.CompletionRequestor;
+import org.eclipse.jdt.core.ICompilationUnit;
+
+/**
+ * JDT completion request to get the JDT completion context.
+ *
+ * @author Angelo ZERR
+ *
+ */
+public class CompletionProposalRequestor extends CompletionRequestor {
+
+ private CompletionContext context;
+
+ public void acceptContext(CompletionContext context) {
+ super.acceptContext(context);
+ this.context = context;
+ }
+
+ public CompletionProposalRequestor(ICompilationUnit unit, int offset) {
+ super.setRequireExtendedContext(true);
+ }
+
+ @Override
+ public void accept(CompletionProposal proposal) {
+
+ }
+
+ public CompletionContext getContext() {
+ return context;
+ }
+}
diff --git a/microprofile.jdt/com.redhat.microprofile.jdt.core/src/main/java/com/redhat/microprofile/jdt/internal/core/java/completion/JavaScopeFinder.java b/microprofile.jdt/com.redhat.microprofile.jdt.core/src/main/java/com/redhat/microprofile/jdt/internal/core/java/completion/JavaScopeFinder.java
new file mode 100644
index 000000000..4af3a0d26
--- /dev/null
+++ b/microprofile.jdt/com.redhat.microprofile.jdt.core/src/main/java/com/redhat/microprofile/jdt/internal/core/java/completion/JavaScopeFinder.java
@@ -0,0 +1,109 @@
+package com.redhat.microprofile.jdt.internal.core.java.completion;
+
+import org.eclipse.jdt.core.dom.ASTNode;
+import org.eclipse.jdt.core.dom.ASTVisitor;
+import org.eclipse.jdt.core.dom.Annotation;
+import org.eclipse.jdt.core.dom.Block;
+import org.eclipse.jdt.core.dom.FieldDeclaration;
+import org.eclipse.jdt.core.dom.MethodDeclaration;
+import org.eclipse.jdt.core.dom.Modifier;
+import org.eclipse.jdt.core.dom.SimpleName;
+import org.eclipse.jdt.core.dom.TypeDeclaration;
+
+public class JavaScopeFinder {
+
+ static enum JavaScope {
+ UNKNOWN, TYPE, METHOD, FIELD, PARAMETER
+
+ }
+
+ private static class JavaScopeFinderVisitor extends ASTVisitor {
+
+ private JavaScope scope;
+ private int fStart;
+ private ASTNode fCoveringNode;
+ private ASTNode fCoveredNode;
+
+ JavaScopeFinderVisitor(int offset) {
+ super(true); // include Javadoc tags
+ this.fStart = offset;
+ }
+
+ @Override
+ public boolean preVisit2(ASTNode node) {
+ int nodeStart = node.getStartPosition();
+ int nodeEnd = nodeStart + node.getLength();
+ if (nodeEnd < this.fStart /* || this.fEnd < nodeStart */) {
+ return false;
+ }
+ if (nodeStart <= this.fStart /* && this.fEnd <= nodeEnd */) {
+ this.fCoveringNode = node;
+ }
+ if (this.fStart <= nodeStart /* && nodeEnd <= this.fEnd */) {
+ if (this.fCoveringNode == node) { // nodeStart == fStart && nodeEnd == fEnd
+ this.fCoveredNode = node;
+ return true; // look further for node with same length as parent
+ } else if (this.fCoveredNode == null) { // no better found
+ this.fCoveredNode = node;
+ }
+ return false;
+ }
+ return true;
+ }
+
+ public JavaScope getScope() {
+ return scope;
+ }
+
+ }
+
+ private JavaScope scope;
+
+ /**
+ * Instantiate a new node finder using the given root node, the given start and
+ * the given length.
+ *
+ * @param root the given root node
+ * @param start the given start
+ * @param length the given length
+ */
+ public JavaScopeFinder(ASTNode root, int start) {
+ JavaScopeFinderVisitor nodeFinderVisitor = new JavaScopeFinderVisitor(start);
+ root.accept(nodeFinderVisitor);
+ this.scope = computeScope(nodeFinderVisitor.fCoveredNode);
+ }
+
+ private static JavaScope computeScope(ASTNode coveredNode) {
+ if (coveredNode == null) {
+ return JavaScope.UNKNOWN;
+ }
+ if (coveredNode instanceof SimpleName) {
+ ASTNode parent = coveredNode.getParent();
+ if (parent instanceof Annotation) {
+ parent = parent.getParent();
+ return computeScope(parent);
+ }
+ return JavaScope.UNKNOWN;
+ } else if (coveredNode instanceof MethodDeclaration) {
+ return JavaScope.METHOD;
+ } else if (coveredNode instanceof TypeDeclaration) {
+ return JavaScope.TYPE;
+ } else if (coveredNode instanceof FieldDeclaration) {
+ return JavaScope.FIELD;
+ } else if (coveredNode instanceof Block) {
+ ASTNode parent = coveredNode.getParent();
+ if (parent instanceof MethodDeclaration) {
+ return JavaScope.PARAMETER;
+ }
+ } else if (coveredNode instanceof Modifier) {
+ ASTNode parent = coveredNode.getParent();
+ return computeScope(parent);
+ }
+
+ return JavaScope.UNKNOWN;
+ }
+
+ public JavaScope getScope() {
+ return scope;
+ }
+}
diff --git a/microprofile.jdt/com.redhat.microprofile.jdt.core/src/main/java/com/redhat/microprofile/jdt/internal/core/ls/MicroProfileDelegateCommandHandlerForJava.java b/microprofile.jdt/com.redhat.microprofile.jdt.core/src/main/java/com/redhat/microprofile/jdt/internal/core/ls/MicroProfileDelegateCommandHandlerForJava.java
index 4fef3d0ad..dd80942bf 100644
--- a/microprofile.jdt/com.redhat.microprofile.jdt.core/src/main/java/com/redhat/microprofile/jdt/internal/core/ls/MicroProfileDelegateCommandHandlerForJava.java
+++ b/microprofile.jdt/com.redhat.microprofile.jdt.core/src/main/java/com/redhat/microprofile/jdt/internal/core/ls/MicroProfileDelegateCommandHandlerForJava.java
@@ -12,7 +12,6 @@
package com.redhat.microprofile.jdt.internal.core.ls;
import static com.redhat.microprofile.jdt.internal.core.ls.ArgumentUtils.getBoolean;
-import static com.redhat.microprofile.jdt.internal.core.ls.ArgumentUtils.getCodeActionContext;
import static com.redhat.microprofile.jdt.internal.core.ls.ArgumentUtils.getFirst;
import static com.redhat.microprofile.jdt.internal.core.ls.ArgumentUtils.getInt;
import static com.redhat.microprofile.jdt.internal.core.ls.ArgumentUtils.getPosition;
@@ -21,8 +20,10 @@
import static com.redhat.microprofile.jdt.internal.core.ls.ArgumentUtils.getStringList;
import static com.redhat.microprofile.jdt.internal.core.ls.ArgumentUtils.getTextDocumentIdentifier;
+import java.util.Collections;
import java.util.List;
import java.util.Map;
+import java.util.stream.Collectors;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
@@ -31,17 +32,20 @@
import org.eclipse.lsp4j.CodeAction;
import org.eclipse.lsp4j.CodeActionContext;
import org.eclipse.lsp4j.CodeLens;
-import org.eclipse.lsp4j.Command;
+import org.eclipse.lsp4j.Diagnostic;
import org.eclipse.lsp4j.Hover;
import org.eclipse.lsp4j.Position;
import org.eclipse.lsp4j.PublishDiagnosticsParams;
import org.eclipse.lsp4j.Range;
import org.eclipse.lsp4j.TextDocumentIdentifier;
-import org.eclipse.lsp4j.jsonrpc.messages.Either;
import com.redhat.microprofile.commons.DocumentFormat;
+import com.redhat.microprofile.commons.JavaKind;
+import com.redhat.microprofile.commons.JavaSnippetContext;
import com.redhat.microprofile.commons.MicroProfileJavaCodeActionParams;
import com.redhat.microprofile.commons.MicroProfileJavaCodeLensParams;
+import com.redhat.microprofile.commons.MicroProfileJavaCompletionParams;
+import com.redhat.microprofile.commons.MicroProfileJavaCompletionResult;
import com.redhat.microprofile.commons.MicroProfileJavaDiagnosticsParams;
import com.redhat.microprofile.commons.MicroProfileJavaHoverParams;
import com.redhat.microprofile.jdt.core.PropertiesManagerForJava;
@@ -56,6 +60,8 @@ public class MicroProfileDelegateCommandHandlerForJava implements IDelegateComma
private static final String JAVA_CODEACTION_COMMAND_ID = "microprofile/java/codeAction";
private static final String JAVA_CODELENS_COMMAND_ID = "microprofile/java/codeLens";
+ private static final String JAVA_COMPLETION_COMMAND_ID = "microprofile/java/completion";
+
private static final String JAVA_DIAGNOSTICS_COMMAND_ID = "microprofile/java/diagnostics";
private static final String JAVA_HOVER_COMMAND_ID = "microprofile/java/hover";
@@ -69,6 +75,8 @@ public Object executeCommand(String commandId, List