diff --git a/build.gradle b/build.gradle
index 3e99ddd71..88ecc86a5 100644
--- a/build.gradle
+++ b/build.gradle
@@ -1,6 +1,6 @@
plugins {
- id "org.jetbrains.intellij" version "1.10.1"
+ id "org.jetbrains.intellij" version "1.13.3"
id 'idea'
id 'java'
id 'org.jetbrains.kotlin.jvm' version '1.6.0'
@@ -149,20 +149,20 @@ dependencies {
implementation("io.quarkus:quarkus-arc:$quarkusVersion") {
transitive = false
}
- implementation 'org.eclipse.lsp4mp:org.eclipse.lsp4mp.ls:0.6.0'
+ implementation "org.eclipse.lsp4mp:org.eclipse.lsp4mp.ls:$lsp4mpVersion"
implementation 'org.eclipse.lsp4j:org.eclipse.lsp4j:0.15.0'
//required by lsp4j as the version from IJ is incompatible
implementation 'com.google.code.gson:gson:2.8.9'
implementation 'com.vladsch.flexmark:flexmark:0.50.50'
testImplementation 'com.redhat.devtools.intellij:intellij-common-ui-test-library:0.2.0'
- lsp('org.eclipse.lsp4mp:org.eclipse.lsp4mp.ls:0.6.0:uber') {
+ lsp("org.eclipse.lsp4mp:org.eclipse.lsp4mp.ls:$lsp4mpVersion:uber") {
transitive = false
}
- lsp ('com.redhat.microprofile:com.redhat.quarkus.ls:0.13.0') {
+ lsp ("com.redhat.microprofile:com.redhat.quarkus.ls:$quarkusLsVersion") {
transitive = false
}
- implementation 'com.redhat.microprofile:com.redhat.qute.ls:0.13.0'
- lsp ('com.redhat.microprofile:com.redhat.qute.ls:0.13.0:uber') {
+ implementation "com.redhat.microprofile:com.redhat.qute.ls:$quarkusLsVersion"
+ lsp ("com.redhat.microprofile:com.redhat.qute.ls:$quarkusLsVersion:uber") {
transitive = false
}
implementation files(new File(buildDir, 'server')) {
diff --git a/gradle.properties b/gradle.properties
index dc80104b4..a7d6f958b 100644
--- a/gradle.properties
+++ b/gradle.properties
@@ -3,4 +3,6 @@ projectVersion=1.19.1-SNAPSHOT
jetBrainsToken=invalid
jetBrainsChannel=stable
quarkusVersion=3.0.4.Final
+lsp4mpVersion=0.7.1
+quarkusLsVersion=0.14.1
kotlin.stdlib.default.dependency = false
diff --git a/projects/lsp4mp/projects/maven/config-hover/pom.xml b/projects/lsp4mp/projects/maven/config-hover/pom.xml
index ee03cd739..3c58c96ed 100644
--- a/projects/lsp4mp/projects/maven/config-hover/pom.xml
+++ b/projects/lsp4mp/projects/maven/config-hover/pom.xml
@@ -7,6 +7,7 @@
1.0-SNAPSHOT
3.8.1
+ 1.18.26
true
1.8
1.8
@@ -48,6 +49,11 @@
io.quarkus
quarkus-config-yaml
+
+ org.projectlombok
+ lombok
+ ${lombok.version}
+
@@ -66,6 +72,18 @@
maven-compiler-plugin
${compiler-plugin.version}
+
+
+ -parameters
+
+
+
+ org.projectlombok
+ lombok
+ ${lombok.version}
+
+
+
maven-surefire-plugin
diff --git a/projects/lsp4mp/projects/maven/config-hover/src/main/java/org/acme/config/Empty.java b/projects/lsp4mp/projects/maven/config-hover/src/main/java/org/acme/config/Empty.java
new file mode 100644
index 000000000..e69de29bb
diff --git a/projects/lsp4mp/projects/maven/config-hover/src/main/java/org/acme/config/GreetingResource.java b/projects/lsp4mp/projects/maven/config-hover/src/main/java/org/acme/config/GreetingResource.java
index 66eea3b2e..6fabfb3a4 100644
--- a/projects/lsp4mp/projects/maven/config-hover/src/main/java/org/acme/config/GreetingResource.java
+++ b/projects/lsp4mp/projects/maven/config-hover/src/main/java/org/acme/config/GreetingResource.java
@@ -24,6 +24,9 @@ public class GreetingResource {
@ConfigProperty(name = "greeting.missing")
String missing;
+ /**
+ * The number
of the greeting.
+ */
@ConfigProperty(name = "greeting.number", defaultValue="0")
int number;
diff --git a/projects/lsp4mp/projects/maven/config-hover/src/main/java/org/acme/config/MyAnnotation.java b/projects/lsp4mp/projects/maven/config-hover/src/main/java/org/acme/config/MyAnnotation.java
new file mode 100644
index 000000000..d4cca529e
--- /dev/null
+++ b/projects/lsp4mp/projects/maven/config-hover/src/main/java/org/acme/config/MyAnnotation.java
@@ -0,0 +1,9 @@
+package org.acme.config;
+
+public @interface MyAnnotation {
+
+ public static String MY_STRING = "asdf";
+
+ public String value() default MY_STRING;
+
+}
diff --git a/projects/lsp4mp/projects/maven/config-hover/src/main/java/org/acme/config/MyEnum.java b/projects/lsp4mp/projects/maven/config-hover/src/main/java/org/acme/config/MyEnum.java
new file mode 100644
index 000000000..b29795439
--- /dev/null
+++ b/projects/lsp4mp/projects/maven/config-hover/src/main/java/org/acme/config/MyEnum.java
@@ -0,0 +1,11 @@
+package org.acme.config;
+
+public enum MyEnum {
+
+ VALUE;
+
+ public static String MY_STRING = "asdf";
+
+ public void helloWorld();
+
+}
diff --git a/projects/lsp4mp/projects/maven/config-hover/src/main/java/org/acme/config/MyInterface.java b/projects/lsp4mp/projects/maven/config-hover/src/main/java/org/acme/config/MyInterface.java
new file mode 100644
index 000000000..f2c81adbe
--- /dev/null
+++ b/projects/lsp4mp/projects/maven/config-hover/src/main/java/org/acme/config/MyInterface.java
@@ -0,0 +1,9 @@
+package org.acme.config;
+
+public interface MyInterface {
+
+ public static String MY_STRING = "asdf";
+
+ public void helloWorld();
+
+}
diff --git a/projects/lsp4mp/projects/maven/config-hover/src/main/java/org/acme/config/MyNestedClass.java b/projects/lsp4mp/projects/maven/config-hover/src/main/java/org/acme/config/MyNestedClass.java
new file mode 100644
index 000000000..06b264a5a
--- /dev/null
+++ b/projects/lsp4mp/projects/maven/config-hover/src/main/java/org/acme/config/MyNestedClass.java
@@ -0,0 +1,10 @@
+package org.acme.config;
+
+@Singleton
+public class MyNestedClass {
+
+ @Singleton
+ static class MyNestedNestedClass {
+
+ }
+}
\ No newline at end of file
diff --git a/projects/lsp4mp/projects/maven/config-hover/src/main/java/org/acme/config/WithLombok.java b/projects/lsp4mp/projects/maven/config-hover/src/main/java/org/acme/config/WithLombok.java
new file mode 100644
index 000000000..7b6f7c310
--- /dev/null
+++ b/projects/lsp4mp/projects/maven/config-hover/src/main/java/org/acme/config/WithLombok.java
@@ -0,0 +1,14 @@
+package org.acme.config;
+
+import lombok.NoArgsConstructor;
+
+@NoArgsConstructor
+public class WithLombok {
+
+ public String myField;
+
+ WithLombok(String myField) {
+ this.myField = myField;
+ }
+
+}
diff --git a/src/main/java/com/redhat/devtools/intellij/lsp4mp4ij/psi/core/PropertiesManagerForJava.java b/src/main/java/com/redhat/devtools/intellij/lsp4mp4ij/psi/core/PropertiesManagerForJava.java
index eea6b992c..d7b9a245c 100644
--- a/src/main/java/com/redhat/devtools/intellij/lsp4mp4ij/psi/core/PropertiesManagerForJava.java
+++ b/src/main/java/com/redhat/devtools/intellij/lsp4mp4ij/psi/core/PropertiesManagerForJava.java
@@ -14,18 +14,11 @@
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.editor.Document;
import com.intellij.openapi.module.Module;
-import com.intellij.openapi.progress.ProgressIndicator;
import com.intellij.openapi.project.DumbService;
import com.intellij.openapi.util.Computable;
import com.intellij.openapi.util.ThrowableComputable;
import com.intellij.openapi.vfs.VirtualFile;
-import com.intellij.psi.PsiDocumentManager;
-import com.intellij.psi.PsiElement;
-import com.intellij.psi.PsiFile;
-import com.intellij.psi.PsiJavaFile;
-import com.intellij.psi.PsiMethod;
-import com.intellij.psi.PsiModifierListOwner;
-import com.intellij.psi.PsiParameter;
+import com.intellij.psi.*;
import com.intellij.psi.util.PsiTreeUtil;
import com.redhat.devtools.intellij.lsp4mp4ij.psi.core.java.codelens.IJavaCodeLensParticipant;
import com.redhat.devtools.intellij.lsp4mp4ij.psi.core.java.codelens.JavaCodeLensContext;
@@ -43,21 +36,12 @@
import org.eclipse.lsp4j.CodeLens;
import org.eclipse.lsp4j.CompletionItem;
import org.eclipse.lsp4j.CompletionList;
-import org.eclipse.lsp4mp.commons.DocumentFormat;
-import org.eclipse.lsp4mp.commons.JavaFileInfo;
-import org.eclipse.lsp4mp.commons.MicroProfileDefinition;
-import org.eclipse.lsp4mp.commons.MicroProfileJavaCodeActionParams;
-import org.eclipse.lsp4mp.commons.MicroProfileJavaCodeLensParams;
-import org.eclipse.lsp4mp.commons.MicroProfileJavaCompletionParams;
-import org.eclipse.lsp4mp.commons.MicroProfileJavaDefinitionParams;
-import org.eclipse.lsp4mp.commons.MicroProfileJavaDiagnosticsParams;
-import org.eclipse.lsp4mp.commons.MicroProfileJavaDiagnosticsSettings;
-import org.eclipse.lsp4mp.commons.MicroProfileJavaFileInfoParams;
-import org.eclipse.lsp4mp.commons.MicroProfileJavaHoverParams;
+import org.eclipse.lsp4mp.commons.*;
import org.eclipse.lsp4j.Diagnostic;
import org.eclipse.lsp4j.Hover;
import org.eclipse.lsp4j.Position;
import org.eclipse.lsp4j.PublishDiagnosticsParams;
+import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -370,6 +354,195 @@ public Hover hover(MicroProfileJavaHoverParams params, IPsiUtils utils) {
});
}
+ /**
+ * Returns the cursor context for the given file and cursor position.
+ *
+ * @param params the completion params that provide the file and cursor
+ * position to get the context for
+ * @param utils the jdt utils
+ * @return the cursor context for the given file and cursor position
+ */
+ public JavaCursorContextResult javaCursorContext(MicroProfileJavaCompletionParams params, IPsiUtils utils) {
+ String uri = params.getUri();
+ PsiFile typeRoot = resolveTypeRoot(uri, utils);
+ if (!(typeRoot instanceof PsiJavaFile)) {
+ return new JavaCursorContextResult(JavaCursorContextKind.IN_EMPTY_FILE, "");
+ }
+ Document document = PsiDocumentManager.getInstance(typeRoot.getProject()).getDocument(typeRoot);
+ if (document == null) {
+ return new JavaCursorContextResult(JavaCursorContextKind.IN_EMPTY_FILE, "");
+ }
+ Position completionPosition = params.getPosition();
+ int completionOffset = utils.toOffset(document, completionPosition.getLine(), completionPosition.getCharacter());
+
+ //CompilationUnit ast = ASTResolving.createQuickFixAST((ICompilationUnit) typeRoot);
+
+ JavaCursorContextKind kind = getJavaCursorContextKind((PsiJavaFile)typeRoot, completionOffset);
+ String prefix = getJavaCursorPrefix(document, completionOffset);
+
+ return new JavaCursorContextResult(kind, prefix);
+ }
+
+ private static @NotNull JavaCursorContextKind getJavaCursorContextKind(PsiJavaFile javaFile, int completionOffset) {
+ if (javaFile.getClasses().length == 0) {
+ return JavaCursorContextKind.IN_EMPTY_FILE;
+ }
+
+ PsiElement element = javaFile.findElementAt(completionOffset);
+ PsiElement parent = PsiTreeUtil.getParentOfType(element, PsiModifierListOwner.class);
+
+ if (parent == null) {
+ // We are likely before or after the class declaration
+ PsiElement firstClass = javaFile.getClasses()[0];
+
+ if (completionOffset <= firstClass.getTextOffset()) {
+ return JavaCursorContextKind.BEFORE_CLASS;
+ }
+
+ return JavaCursorContextKind.NONE;
+ }
+
+ if (parent instanceof PsiClass) {
+ PsiClass psiClass = (PsiClass) parent;
+ return getContextKindFromClass(completionOffset, psiClass, element);
+ }
+ if (parent instanceof PsiAnnotation) {
+ PsiAnnotation psiAnnotation = (PsiAnnotation) parent;
+ @Nullable PsiAnnotationOwner annotationOwner = psiAnnotation.getOwner();
+ if (annotationOwner instanceof PsiClass) {
+ return (psiAnnotation.getStartOffsetInParent() == 0)? JavaCursorContextKind.BEFORE_CLASS:JavaCursorContextKind.IN_CLASS_ANNOTATIONS;
+ }
+ if (annotationOwner instanceof PsiMethod){
+ return (psiAnnotation.getStartOffsetInParent() == 0)? JavaCursorContextKind.BEFORE_METHOD:JavaCursorContextKind.IN_METHOD_ANNOTATIONS;
+ }
+ if (annotationOwner instanceof PsiField) {
+ return (psiAnnotation.getStartOffsetInParent() == 0)? JavaCursorContextKind.BEFORE_FIELD:JavaCursorContextKind.IN_FIELD_ANNOTATIONS;
+ }
+ }
+ if (parent instanceof PsiMethod) {
+ PsiMethod psiMethod = (PsiMethod) parent;
+ if (completionOffset == psiMethod.getTextRange().getStartOffset()) {
+ return JavaCursorContextKind.BEFORE_METHOD;
+ }
+ int methodStartOffset = getMethodStartOffset(psiMethod);
+ if (completionOffset <= methodStartOffset) {
+ if (psiMethod.getAnnotations().length > 0) {
+ return JavaCursorContextKind.IN_METHOD_ANNOTATIONS;
+ }
+ return JavaCursorContextKind.BEFORE_METHOD;
+ }
+ }
+
+ if (parent instanceof PsiField) {
+ PsiField psiField = (PsiField) parent;
+ if (completionOffset == psiField.getTextRange().getStartOffset()) {
+ return JavaCursorContextKind.BEFORE_FIELD;
+ }
+ int fieldStartOffset = getFieldStartOffset(psiField);
+ if (completionOffset <= fieldStartOffset) {
+ if (psiField.getAnnotations().length > 0) {
+ return JavaCursorContextKind.IN_FIELD_ANNOTATIONS;
+ }
+ return JavaCursorContextKind.BEFORE_FIELD;
+ }
+ }
+
+ return JavaCursorContextKind.NONE;
+ }
+
+ @NotNull
+ private static JavaCursorContextKind getContextKindFromClass(int completionOffset, PsiClass psiClass, PsiElement element) {
+ if (completionOffset <= psiClass.getTextRange().getStartOffset()) {
+ return JavaCursorContextKind.BEFORE_CLASS;
+ }
+ int classStartOffset = getClassStartOffset(psiClass);
+ if (completionOffset <= classStartOffset) {
+ if (psiClass.getAnnotations().length > 0) {
+ return JavaCursorContextKind.IN_CLASS_ANNOTATIONS;
+ }
+ return JavaCursorContextKind.BEFORE_CLASS;
+ }
+
+ PsiElement nextElement = element.getNextSibling();
+
+ if (nextElement instanceof PsiField) {
+ return JavaCursorContextKind.BEFORE_FIELD;
+ }
+ if (nextElement instanceof PsiMethod) {
+ return JavaCursorContextKind.BEFORE_METHOD;
+ }
+ if (nextElement instanceof PsiClass) {
+ return JavaCursorContextKind.BEFORE_CLASS;
+ }
+
+ return JavaCursorContextKind.IN_CLASS;
+ }
+
+ private static @NotNull String getJavaCursorPrefix(@NotNull Document document, int completionOffset) {
+ String fileContents = document.getText();
+ int i;
+ for (i = completionOffset; i > 0 && !Character.isWhitespace(fileContents.charAt(i - 1)); i--) {
+ }
+ return fileContents.substring(i, completionOffset);
+ }
+
+ private static int getMethodStartOffset(PsiMethod psiMethod) {
+ int startOffset = psiMethod.getTextOffset();
+
+ int modifierStartOffset = getFirstKeywordOffset(psiMethod);
+ if (modifierStartOffset > -1) {
+ return Math.min(startOffset, modifierStartOffset);
+ }
+
+ PsiTypeElement returnTypeElement = psiMethod.getReturnTypeElement();
+ if (returnTypeElement != null) {
+ int returnTypeEndOffset = returnTypeElement.getTextRange().getStartOffset();
+ startOffset = Math.min(startOffset, returnTypeEndOffset);
+ }
+
+ return startOffset;
+ }
+
+ private static int getClassStartOffset(PsiClass psiClass) {
+ int startOffset = psiClass.getTextOffset();
+
+ int modifierStartOffset = getFirstKeywordOffset(psiClass);
+ if (modifierStartOffset > -1) {
+ return Math.min(startOffset, modifierStartOffset);
+ }
+ return startOffset;
+ }
+
+ private static int getFieldStartOffset(PsiField psiField) {
+ int startOffset = psiField.getTextOffset();
+
+ int modifierStartOffset = getFirstKeywordOffset(psiField);
+ if (modifierStartOffset > -1) {
+ return Math.min(startOffset, modifierStartOffset);
+ }
+
+ PsiTypeElement typeElement = psiField.getTypeElement();
+ if (typeElement != null) {
+ int typeElementOffset = typeElement.getTextRange().getStartOffset();
+ startOffset = Math.min(startOffset, typeElementOffset);
+ }
+
+ return startOffset;
+ }
+
+ private static int getFirstKeywordOffset(PsiModifierListOwner modifierOwner) {
+ PsiModifierList modifierList = modifierOwner.getModifierList();
+ if (modifierList != null) {
+ PsiElement[] modifiers = modifierList.getChildren();
+ for (PsiElement modifier : modifiers) {
+ if (modifier instanceof PsiKeyword) {
+ return modifier.getTextRange().getStartOffset();
+ }
+ }
+ }
+ return -1;
+ }
+
@Nullable
private PsiElement getHoveredElement(PsiFile typeRoot, int offset) {
PsiElement hoverElement = typeRoot.findElementAt(offset);
diff --git a/src/main/java/com/redhat/devtools/intellij/lsp4mp4ij/psi/core/java/codeaction/InsertAnnotationAttributeQuickFix.java b/src/main/java/com/redhat/devtools/intellij/lsp4mp4ij/psi/core/java/codeaction/InsertAnnotationAttributeQuickFix.java
index 35929debd..2886666fe 100644
--- a/src/main/java/com/redhat/devtools/intellij/lsp4mp4ij/psi/core/java/codeaction/InsertAnnotationAttributeQuickFix.java
+++ b/src/main/java/com/redhat/devtools/intellij/lsp4mp4ij/psi/core/java/codeaction/InsertAnnotationAttributeQuickFix.java
@@ -21,7 +21,8 @@
import org.eclipse.lsp4j.CodeAction;
import org.eclipse.lsp4j.CodeActionKind;
import org.eclipse.lsp4j.Diagnostic;
-import org.eclipse.lsp4mp.commons.CodeActionResolveData;
+import org.eclipse.lsp4mp.commons.codeaction.CodeActionResolveData;
+import org.eclipse.lsp4mp.commons.codeaction.MicroProfileCodeActionId;
import java.text.MessageFormat;
import java.util.ArrayList;
@@ -63,7 +64,8 @@ public List extends CodeAction> getCodeActions(JavaCodeActionContext context,
codeAction.setData(
new CodeActionResolveData(context.getUri(), getParticipantId(), context.getParams().getRange(), null,
context.getParams().isResourceOperationSupported(),
- context.getParams().isCommandConfigurationUpdateSupported()));
+ context.getParams().isCommandConfigurationUpdateSupported(),
+ getCodeActionId()));
return Collections.singletonList(codeAction);
}
@@ -84,6 +86,13 @@ public CodeAction resolveCodeAction(JavaCodeActionResolveContext context) {
return toResolve;
}
+ /**
+ * Returns the id for this code action.
+ *
+ * @return the id for this code action
+ */
+ protected abstract MicroProfileCodeActionId getCodeActionId();
+
private static String getLabel(String memberName) {
return MessageFormat.format(CODE_ACTION_LABEL, memberName);
}
diff --git a/src/main/java/com/redhat/devtools/intellij/lsp4mp4ij/psi/core/java/codeaction/InsertAnnotationMissingQuickFix.java b/src/main/java/com/redhat/devtools/intellij/lsp4mp4ij/psi/core/java/codeaction/InsertAnnotationMissingQuickFix.java
index 57c4d5f73..6c4640986 100644
--- a/src/main/java/com/redhat/devtools/intellij/lsp4mp4ij/psi/core/java/codeaction/InsertAnnotationMissingQuickFix.java
+++ b/src/main/java/com/redhat/devtools/intellij/lsp4mp4ij/psi/core/java/codeaction/InsertAnnotationMissingQuickFix.java
@@ -33,7 +33,8 @@
import org.eclipse.lsp4j.CodeActionKind;
import org.eclipse.lsp4j.Diagnostic;
import org.eclipse.lsp4j.WorkspaceEdit;
-import org.eclipse.lsp4mp.commons.CodeActionResolveData;
+import org.eclipse.lsp4mp.commons.codeaction.CodeActionResolveData;
+import org.eclipse.lsp4mp.commons.codeaction.ICodeActionId;
/**
* QuickFix for inserting annotations.
@@ -146,11 +147,19 @@ protected void insertAnnotation(Diagnostic diagnostic, JavaCodeActionContext con
codeAction.setData(new CodeActionResolveData(context.getUri(), getParticipantId(),
context.getParams().getRange(), extendedData,
context.getParams().isResourceOperationSupported(),
- context.getParams().isCommandConfigurationUpdateSupported()));
+ context.getParams().isCommandConfigurationUpdateSupported(),
+ getCodeActionId()));
codeActions.add(codeAction);
}
+ /**
+ * Returns the id for this code action.
+ *
+ * @return the id for this code action
+ */
+ protected abstract ICodeActionId getCodeActionId();
+
private static String getLabel(String[] annotations) {
StringBuilder name = new StringBuilder("Insert ");
for (int i = 0; i < annotations.length; i++) {
diff --git a/src/main/java/com/redhat/devtools/intellij/lsp4mp4ij/psi/internal/config/java/InsertDefaultValueAnnotationAttributeQuickFix.java b/src/main/java/com/redhat/devtools/intellij/lsp4mp4ij/psi/internal/config/java/InsertDefaultValueAnnotationAttributeQuickFix.java
index c3ea62cf5..c780f59b0 100644
--- a/src/main/java/com/redhat/devtools/intellij/lsp4mp4ij/psi/internal/config/java/InsertDefaultValueAnnotationAttributeQuickFix.java
+++ b/src/main/java/com/redhat/devtools/intellij/lsp4mp4ij/psi/internal/config/java/InsertDefaultValueAnnotationAttributeQuickFix.java
@@ -15,6 +15,7 @@
import com.redhat.devtools.intellij.lsp4mp4ij.psi.core.MicroProfileConfigConstants;
import com.redhat.devtools.intellij.lsp4mp4ij.psi.core.java.codeaction.InsertAnnotationAttributeQuickFix;
+import org.eclipse.lsp4mp.commons.codeaction.MicroProfileCodeActionId;
/**
* QuickFix for fixing
@@ -39,4 +40,9 @@ public String getParticipantId() {
return InsertDefaultValueAnnotationAttributeQuickFix.class.getName();
}
+ @Override
+ protected MicroProfileCodeActionId getCodeActionId() {
+ return MicroProfileCodeActionId.ConfigPropertyInsertDefaultValue;
+ }
+
}
diff --git a/src/main/java/com/redhat/devtools/intellij/lsp4mp4ij/psi/internal/config/java/NoValueAssignedToPropertyQuickFix.java b/src/main/java/com/redhat/devtools/intellij/lsp4mp4ij/psi/internal/config/java/NoValueAssignedToPropertyQuickFix.java
index 543c41142..4e2c14117 100644
--- a/src/main/java/com/redhat/devtools/intellij/lsp4mp4ij/psi/internal/config/java/NoValueAssignedToPropertyQuickFix.java
+++ b/src/main/java/com/redhat/devtools/intellij/lsp4mp4ij/psi/internal/config/java/NoValueAssignedToPropertyQuickFix.java
@@ -18,7 +18,7 @@
import static com.redhat.devtools.intellij.lsp4mp4ij.psi.core.MicroProfileConfigConstants.DIAGNOSTIC_DATA_NAME;
import static com.redhat.devtools.intellij.lsp4mp4ij.psi.core.utils.AnnotationUtils.getAnnotation;
import static com.redhat.devtools.intellij.lsp4mp4ij.psi.core.utils.AnnotationUtils.getAnnotationMemberValue;
-import static org.eclipse.lsp4mp.commons.MicroProfileCodeActionFactory.createAddToUnassignedExcludedCodeAction;
+import static org.eclipse.lsp4mp.commons.codeaction.MicroProfileCodeActionFactory.createAddToUnassignedExcludedCodeAction;
import java.text.MessageFormat;
import java.util.ArrayList;
@@ -51,7 +51,7 @@
import org.eclipse.lsp4j.VersionedTextDocumentIdentifier;
import org.eclipse.lsp4j.WorkspaceEdit;
import org.eclipse.lsp4j.jsonrpc.messages.Either;
-import org.eclipse.lsp4mp.commons.CodeActionResolveData;
+import org.eclipse.lsp4mp.commons.codeaction.CodeActionResolveData;
/**
* QuickFix for fixing
diff --git a/src/main/java/com/redhat/devtools/intellij/lsp4mp4ij/psi/internal/core/java/codeaction/CodeActionHandler.java b/src/main/java/com/redhat/devtools/intellij/lsp4mp4ij/psi/internal/core/java/codeaction/CodeActionHandler.java
index 2fe049548..587ae7561 100644
--- a/src/main/java/com/redhat/devtools/intellij/lsp4mp4ij/psi/internal/core/java/codeaction/CodeActionHandler.java
+++ b/src/main/java/com/redhat/devtools/intellij/lsp4mp4ij/psi/internal/core/java/codeaction/CodeActionHandler.java
@@ -26,7 +26,7 @@
import org.eclipse.lsp4j.Diagnostic;
import org.eclipse.lsp4j.VersionedTextDocumentIdentifier;
import org.eclipse.lsp4j.jsonrpc.messages.Either;
-import org.eclipse.lsp4mp.commons.CodeActionResolveData;
+import org.eclipse.lsp4mp.commons.codeaction.CodeActionResolveData;
import org.eclipse.lsp4mp.commons.MicroProfileJavaCodeActionParams;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
diff --git a/src/main/java/com/redhat/devtools/intellij/lsp4mp4ij/psi/internal/health/java/HealthAnnotationMissingQuickFix.java b/src/main/java/com/redhat/devtools/intellij/lsp4mp4ij/psi/internal/health/java/HealthAnnotationMissingQuickFix.java
index 606b46bcc..ca4fee691 100644
--- a/src/main/java/com/redhat/devtools/intellij/lsp4mp4ij/psi/internal/health/java/HealthAnnotationMissingQuickFix.java
+++ b/src/main/java/com/redhat/devtools/intellij/lsp4mp4ij/psi/internal/health/java/HealthAnnotationMissingQuickFix.java
@@ -19,6 +19,7 @@
import com.redhat.devtools.intellij.lsp4mp4ij.psi.internal.health.MicroProfileHealthConstants;
import org.eclipse.lsp4j.CodeAction;
import org.eclipse.lsp4j.Diagnostic;
+import org.eclipse.lsp4mp.commons.codeaction.MicroProfileCodeActionId;
import java.util.List;
@@ -67,4 +68,9 @@ protected void insertAnnotations(Diagnostic diagnostic, JavaCodeActionContext co
}
}
}
+
+ @Override
+ protected MicroProfileCodeActionId getCodeActionId() {
+ return MicroProfileCodeActionId.InsertMissingHealthAnnotation;
+ }
}
diff --git a/src/main/java/com/redhat/devtools/intellij/lsp4mp4ij/psi/internal/health/java/ImplementHealthCheckQuickFix.java b/src/main/java/com/redhat/devtools/intellij/lsp4mp4ij/psi/internal/health/java/ImplementHealthCheckQuickFix.java
index 018380d7d..e56e650a9 100644
--- a/src/main/java/com/redhat/devtools/intellij/lsp4mp4ij/psi/internal/health/java/ImplementHealthCheckQuickFix.java
+++ b/src/main/java/com/redhat/devtools/intellij/lsp4mp4ij/psi/internal/health/java/ImplementHealthCheckQuickFix.java
@@ -13,15 +13,8 @@
*******************************************************************************/
package com.redhat.devtools.intellij.lsp4mp4ij.psi.internal.health.java;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
import com.intellij.psi.PsiClass;
import com.intellij.psi.PsiElement;
-import com.intellij.psi.PsiModifierListOwner;
import com.intellij.psi.PsiNamedElement;
import com.intellij.psi.PsiVariable;
import com.intellij.psi.util.PsiTreeUtil;
@@ -36,7 +29,13 @@
import org.eclipse.lsp4j.CodeActionKind;
import org.eclipse.lsp4j.Diagnostic;
import org.eclipse.lsp4j.WorkspaceEdit;
-import org.eclipse.lsp4mp.commons.CodeActionResolveData;
+import org.eclipse.lsp4mp.commons.codeaction.CodeActionResolveData;
+import org.eclipse.lsp4mp.commons.codeaction.MicroProfileCodeActionId;
+
+import java.util.Collections;
+import java.util.List;
+import java.util.logging.Level;
+import java.util.logging.Logger;
/**
* QuickFix for fixing {@link MicroProfileHealthErrorCode#ImplementHealthCheck}
@@ -65,7 +64,8 @@ public List extends CodeAction> getCodeActions(JavaCodeActionContext context,
codeAction.setKind(CodeActionKind.QuickFix);
codeAction.setData(new CodeActionResolveData(context.getUri(), getParticipantId(),
context.getParams().getRange(), null, context.getParams().isResourceOperationSupported(),
- context.getParams().isCommandConfigurationUpdateSupported()));
+ context.getParams().isCommandConfigurationUpdateSupported(),
+ MicroProfileCodeActionId.ImplementHealthCheck));
return Collections.singletonList(codeAction);
}
diff --git a/src/main/java/com/redhat/devtools/intellij/lsp4mp4ij/psi/internal/metrics/java/ApplicationScopedAnnotationMissingQuickFix.java b/src/main/java/com/redhat/devtools/intellij/lsp4mp4ij/psi/internal/metrics/java/ApplicationScopedAnnotationMissingQuickFix.java
index b12aed6a5..73b409456 100644
--- a/src/main/java/com/redhat/devtools/intellij/lsp4mp4ij/psi/internal/metrics/java/ApplicationScopedAnnotationMissingQuickFix.java
+++ b/src/main/java/com/redhat/devtools/intellij/lsp4mp4ij/psi/internal/metrics/java/ApplicationScopedAnnotationMissingQuickFix.java
@@ -13,20 +13,13 @@
*******************************************************************************/
package com.redhat.devtools.intellij.lsp4mp4ij.psi.internal.metrics.java;
-import java.util.Collections;
-import java.util.List;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
import com.intellij.psi.PsiClass;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiModifierListOwner;
-import com.intellij.psi.PsiNamedElement;
import com.intellij.psi.PsiVariable;
import com.intellij.psi.util.PsiTreeUtil;
import com.redhat.devtools.intellij.lsp4mp4ij.psi.core.java.codeaction.ExtendedCodeAction;
import com.redhat.devtools.intellij.lsp4mp4ij.psi.core.java.codeaction.IJavaCodeActionParticipant;
-import com.redhat.devtools.intellij.lsp4mp4ij.psi.core.java.codeaction.InsertAnnotationMissingQuickFix;
import com.redhat.devtools.intellij.lsp4mp4ij.psi.core.java.codeaction.JavaCodeActionContext;
import com.redhat.devtools.intellij.lsp4mp4ij.psi.core.java.codeaction.JavaCodeActionResolveContext;
import com.redhat.devtools.intellij.lsp4mp4ij.psi.core.java.corrections.proposal.ChangeCorrectionProposal;
@@ -37,7 +30,13 @@
import org.eclipse.lsp4j.CodeActionKind;
import org.eclipse.lsp4j.Diagnostic;
import org.eclipse.lsp4j.WorkspaceEdit;
-import org.eclipse.lsp4mp.commons.CodeActionResolveData;
+import org.eclipse.lsp4mp.commons.codeaction.CodeActionResolveData;
+import org.eclipse.lsp4mp.commons.codeaction.MicroProfileCodeActionId;
+
+import java.util.Collections;
+import java.util.List;
+import java.util.logging.Level;
+import java.util.logging.Logger;
/**
* QuickFix for fixing
@@ -83,7 +82,8 @@ public List extends CodeAction> getCodeActions(JavaCodeActionContext context,
codeAction.setData(
new CodeActionResolveData(context.getUri(), getParticipantId(), context.getParams().getRange(), null,
context.getParams().isResourceOperationSupported(),
- context.getParams().isCommandConfigurationUpdateSupported()));
+ context.getParams().isCommandConfigurationUpdateSupported(),
+ MicroProfileCodeActionId.InsertApplicationScopedAnnotation));
return Collections.singletonList(codeAction);
}
diff --git a/src/main/java/com/redhat/devtools/intellij/lsp4mp4ij/psi/internal/openapi/java/MicroProfileGenerateOpenAPIOperation.java b/src/main/java/com/redhat/devtools/intellij/lsp4mp4ij/psi/internal/openapi/java/MicroProfileGenerateOpenAPIOperation.java
index 4492a9cef..bedb88a4b 100644
--- a/src/main/java/com/redhat/devtools/intellij/lsp4mp4ij/psi/internal/openapi/java/MicroProfileGenerateOpenAPIOperation.java
+++ b/src/main/java/com/redhat/devtools/intellij/lsp4mp4ij/psi/internal/openapi/java/MicroProfileGenerateOpenAPIOperation.java
@@ -29,7 +29,8 @@
import org.eclipse.lsp4j.CodeActionKind;
import org.eclipse.lsp4j.Diagnostic;
import org.eclipse.lsp4j.WorkspaceEdit;
-import org.eclipse.lsp4mp.commons.CodeActionResolveData;
+import org.eclipse.lsp4mp.commons.codeaction.CodeActionResolveData;
+import org.eclipse.lsp4mp.commons.codeaction.MicroProfileCodeActionId;
import java.text.MessageFormat;
import java.util.ArrayList;
@@ -77,7 +78,8 @@ public List extends CodeAction> getCodeActions(JavaCodeActionContext context,
CodeActionResolveData data = new CodeActionResolveData(context.getUri(), getParticipantId(),
context.getParams().getRange(),
extendedData, context.getParams().isResourceOperationSupported(),
- context.getParams().isCommandConfigurationUpdateSupported());
+ context.getParams().isCommandConfigurationUpdateSupported(),
+ MicroProfileCodeActionId.GenerateOpenApiAnnotations);
ExtendedCodeAction codeAction = new ExtendedCodeAction(
MessageFormat.format(MESSAGE, getSimpleName(typeName)));
diff --git a/src/main/java/com/redhat/devtools/intellij/lsp4mp4ij/psi/internal/restclient/java/InjectAndRestClientAnnotationMissingQuickFix.java b/src/main/java/com/redhat/devtools/intellij/lsp4mp4ij/psi/internal/restclient/java/InjectAndRestClientAnnotationMissingQuickFix.java
index f3657d061..08925355f 100644
--- a/src/main/java/com/redhat/devtools/intellij/lsp4mp4ij/psi/internal/restclient/java/InjectAndRestClientAnnotationMissingQuickFix.java
+++ b/src/main/java/com/redhat/devtools/intellij/lsp4mp4ij/psi/internal/restclient/java/InjectAndRestClientAnnotationMissingQuickFix.java
@@ -21,6 +21,7 @@
import com.redhat.devtools.intellij.lsp4mp4ij.psi.internal.restclient.MicroProfileRestClientErrorCode;
import org.eclipse.lsp4j.CodeAction;
import org.eclipse.lsp4j.Diagnostic;
+import org.eclipse.lsp4mp.commons.codeaction.MicroProfileCodeActionId;
import java.util.List;
@@ -67,4 +68,9 @@ protected void insertAnnotations(Diagnostic diagnostic, JavaCodeActionContext co
insertAnnotation(diagnostic, context, codeActions, MicroProfileRestClientConstants.REST_CLIENT_ANNOTATION);
}
}
+
+ @Override
+ protected MicroProfileCodeActionId getCodeActionId() {
+ return MicroProfileCodeActionId.InsertInjectAndRestClientAnnotations;
+ }
}
diff --git a/src/main/java/com/redhat/devtools/intellij/lsp4mp4ij/psi/internal/restclient/java/InjectAnnotationMissingQuickFix.java b/src/main/java/com/redhat/devtools/intellij/lsp4mp4ij/psi/internal/restclient/java/InjectAnnotationMissingQuickFix.java
index 9635d3c2a..fad7590e8 100644
--- a/src/main/java/com/redhat/devtools/intellij/lsp4mp4ij/psi/internal/restclient/java/InjectAnnotationMissingQuickFix.java
+++ b/src/main/java/com/redhat/devtools/intellij/lsp4mp4ij/psi/internal/restclient/java/InjectAnnotationMissingQuickFix.java
@@ -20,6 +20,7 @@
import com.redhat.devtools.intellij.lsp4mp4ij.psi.internal.restclient.MicroProfileRestClientErrorCode;
import org.eclipse.lsp4j.CodeAction;
import org.eclipse.lsp4j.Diagnostic;
+import org.eclipse.lsp4mp.commons.codeaction.MicroProfileCodeActionId;
import java.util.List;
@@ -56,4 +57,9 @@ protected void insertAnnotations(Diagnostic diagnostic, JavaCodeActionContext co
}
}
}
+
+ @Override
+ protected MicroProfileCodeActionId getCodeActionId() {
+ return MicroProfileCodeActionId.InsertInjectAnnotation;
+ }
}
diff --git a/src/main/java/com/redhat/devtools/intellij/lsp4mp4ij/psi/internal/restclient/java/RegisterRestClientAnnotationMissingQuickFix.java b/src/main/java/com/redhat/devtools/intellij/lsp4mp4ij/psi/internal/restclient/java/RegisterRestClientAnnotationMissingQuickFix.java
index cf1325d1f..06cd7a1ad 100644
--- a/src/main/java/com/redhat/devtools/intellij/lsp4mp4ij/psi/internal/restclient/java/RegisterRestClientAnnotationMissingQuickFix.java
+++ b/src/main/java/com/redhat/devtools/intellij/lsp4mp4ij/psi/internal/restclient/java/RegisterRestClientAnnotationMissingQuickFix.java
@@ -15,6 +15,8 @@
import com.redhat.devtools.intellij.lsp4mp4ij.psi.core.java.codeaction.InsertAnnotationMissingQuickFix;
import com.redhat.devtools.intellij.lsp4mp4ij.psi.internal.restclient.MicroProfileRestClientConstants;
+import com.redhat.devtools.intellij.lsp4mp4ij.psi.internal.restclient.MicroProfileRestClientErrorCode;
+import org.eclipse.lsp4mp.commons.codeaction.MicroProfileCodeActionId;
/**
* QuickFix for fixing
@@ -39,4 +41,8 @@ public String getParticipantId() {
return RegisterRestClientAnnotationMissingQuickFix.class.getName();
}
+ @Override
+ protected MicroProfileCodeActionId getCodeActionId() {
+ return MicroProfileCodeActionId.InsertRegisterRestClient;
+ }
}
diff --git a/src/main/java/com/redhat/devtools/intellij/lsp4mp4ij/psi/internal/restclient/java/RestClientAnnotationMissingQuickFix.java b/src/main/java/com/redhat/devtools/intellij/lsp4mp4ij/psi/internal/restclient/java/RestClientAnnotationMissingQuickFix.java
index 33a472ea3..28ca2f43f 100644
--- a/src/main/java/com/redhat/devtools/intellij/lsp4mp4ij/psi/internal/restclient/java/RestClientAnnotationMissingQuickFix.java
+++ b/src/main/java/com/redhat/devtools/intellij/lsp4mp4ij/psi/internal/restclient/java/RestClientAnnotationMissingQuickFix.java
@@ -15,6 +15,8 @@
import com.redhat.devtools.intellij.lsp4mp4ij.psi.core.java.codeaction.InsertAnnotationMissingQuickFix;
import com.redhat.devtools.intellij.lsp4mp4ij.psi.internal.restclient.MicroProfileRestClientConstants;
+import com.redhat.devtools.intellij.lsp4mp4ij.psi.internal.restclient.MicroProfileRestClientErrorCode;
+import org.eclipse.lsp4mp.commons.codeaction.MicroProfileCodeActionId;
/**
* QuickFix for fixing
@@ -39,4 +41,8 @@ public String getParticipantId() {
return RestClientAnnotationMissingQuickFix.class.getName();
}
+ @Override
+ protected MicroProfileCodeActionId getCodeActionId() {
+ return MicroProfileCodeActionId.InsertRestClientAnnotation;
+ }
}
diff --git a/src/main/java/com/redhat/devtools/intellij/quarkus/lsp/QuarkusLanguageClient.java b/src/main/java/com/redhat/devtools/intellij/quarkus/lsp/QuarkusLanguageClient.java
index 3327604c8..a3a9335dd 100644
--- a/src/main/java/com/redhat/devtools/intellij/quarkus/lsp/QuarkusLanguageClient.java
+++ b/src/main/java/com/redhat/devtools/intellij/quarkus/lsp/QuarkusLanguageClient.java
@@ -19,6 +19,7 @@
import com.redhat.devtools.intellij.lsp4mp4ij.psi.core.PropertiesManager;
import com.redhat.devtools.intellij.lsp4mp4ij.psi.core.PropertiesManagerForJava;
import com.redhat.devtools.intellij.lsp4mp4ij.psi.core.project.PsiMicroProfileProjectManager;
+import com.redhat.devtools.intellij.lsp4mp4ij.psi.core.utils.IPsiUtils;
import com.redhat.devtools.intellij.lsp4mp4ij.psi.internal.core.ls.PsiUtilsLSImpl;
import com.redhat.devtools.intellij.quarkus.QuarkusModuleUtil;
import com.redhat.devtools.intellij.quarkus.QuarkusProjectService;
@@ -26,6 +27,7 @@
import org.apache.commons.lang3.tuple.Pair;
import org.eclipse.lsp4j.*;
import org.eclipse.lsp4mp.commons.*;
+import org.eclipse.lsp4mp.commons.codeaction.CodeActionResolveData;
import org.eclipse.lsp4mp.commons.utils.JSONUtility;
import org.eclipse.lsp4mp.ls.api.MicroProfileLanguageClientAPI;
import org.eclipse.lsp4mp.ls.api.MicroProfileLanguageServerAPI;
@@ -116,7 +118,7 @@ public CompletableFuture getPropertyDefinition(MicroProfilePropertyDef
}
@Override
- public CompletableFuture getJavaProjectlabels(MicroProfileJavaProjectLabelsParams javaParams) {
+ public CompletableFuture getJavaProjectLabels(MicroProfileJavaProjectLabelsParams javaParams) {
return runAsBackground("Computing Java projects labels", monitor -> ProjectLabelManager.getInstance().getProjectLabelInfo(javaParams, PsiUtilsLSImpl.getInstance(getProject())));
}
@@ -131,8 +133,13 @@ public CompletableFuture> getJavaDefinition(MicroPr
}
@Override
- public CompletableFuture getJavaCompletion(MicroProfileJavaCompletionParams javaParams) {
- return runAsBackground("Computing Java completion", monitor -> PropertiesManagerForJava.getInstance().completion(javaParams, PsiUtilsLSImpl.getInstance(getProject())));
+ public CompletableFuture getJavaCompletion(MicroProfileJavaCompletionParams javaParams) {
+ return runAsBackground("Computing Java completion", monitor -> {
+ IPsiUtils utils = PsiUtilsLSImpl.getInstance(getProject());
+ CompletionList completionList = PropertiesManagerForJava.getInstance().completion(javaParams, utils);
+ JavaCursorContextResult cursorContext = PropertiesManagerForJava.getInstance().javaCursorContext(javaParams, utils);
+ return new MicroProfileJavaCompletionResult(completionList, cursorContext);
+ });
}
@Override
diff --git a/src/test/java/com/redhat/devtools/intellij/lsp4mp4ij/psi/core/config/java/MicroProfileConfigJavaDiagnosticsTest.java b/src/test/java/com/redhat/devtools/intellij/lsp4mp4ij/psi/core/config/java/MicroProfileConfigJavaDiagnosticsTest.java
index 97f39402d..f16fdf628 100644
--- a/src/test/java/com/redhat/devtools/intellij/lsp4mp4ij/psi/core/config/java/MicroProfileConfigJavaDiagnosticsTest.java
+++ b/src/test/java/com/redhat/devtools/intellij/lsp4mp4ij/psi/core/config/java/MicroProfileConfigJavaDiagnosticsTest.java
@@ -21,7 +21,7 @@
import org.eclipse.lsp4j.Diagnostic;
import org.eclipse.lsp4j.DiagnosticSeverity;
import org.eclipse.lsp4mp.commons.DocumentFormat;
-import org.eclipse.lsp4mp.commons.MicroProfileCodeActionFactory;
+import org.eclipse.lsp4mp.commons.codeaction.MicroProfileCodeActionFactory;
import org.eclipse.lsp4mp.commons.MicroProfileJavaCodeActionParams;
import org.eclipse.lsp4mp.commons.MicroProfileJavaDiagnosticsParams;
import org.eclipse.lsp4mp.commons.MicroProfileJavaDiagnosticsSettings;
diff --git a/src/test/java/com/redhat/devtools/intellij/lsp4mp4ij/psi/core/snippets/JavaFileCursorContextTest.java b/src/test/java/com/redhat/devtools/intellij/lsp4mp4ij/psi/core/snippets/JavaFileCursorContextTest.java
new file mode 100644
index 000000000..b1516ebbb
--- /dev/null
+++ b/src/test/java/com/redhat/devtools/intellij/lsp4mp4ij/psi/core/snippets/JavaFileCursorContextTest.java
@@ -0,0 +1,380 @@
+/*******************************************************************************
+* Copyright (c) 2023 Red Hat Inc. and others.
+*
+* This program and the accompanying materials are made available under the
+* terms of the Eclipse Public License v. 2.0 which is available at
+* http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0
+* which is available at https://www.apache.org/licenses/LICENSE-2.0.
+*
+* SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
+*
+* Contributors:
+* Red Hat Inc. - initial API and implementation
+*******************************************************************************/
+package com.redhat.devtools.intellij.lsp4mp4ij.psi.core.snippets;
+
+import static org.junit.Assert.assertEquals;
+
+import java.io.ByteArrayInputStream;
+import java.io.File;
+
+import com.intellij.openapi.module.Module;
+import com.intellij.openapi.module.ModuleUtilCore;
+import com.redhat.devtools.intellij.MavenModuleImportingTestCase;
+import com.redhat.devtools.intellij.lsp4mp4ij.psi.core.PropertiesManagerForJava;
+import org.eclipse.lsp4j.Position;
+import org.eclipse.lsp4mp.commons.JavaCursorContextKind;
+import org.eclipse.lsp4mp.commons.MicroProfileJavaCompletionParams;
+//import org.eclipse.lsp4mp.jdt.core.BasePropertiesManagerTest;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * Tests for the implementation of
+ * microprofile/java/javaCursorContext
.
+ */
+public class JavaFileCursorContextTest extends MavenModuleImportingTestCase {
+
+ private Module javaProject;
+
+ @Before
+ public void setUp() throws Exception {
+ super.setUp();
+ javaProject = createMavenModule(new File("projects/lsp4mp/projects/maven/config-hover"));
+ }
+
+ private String getJavaFileUri(String path) {
+ return new File(ModuleUtilCore.getModuleDirPath(javaProject), path).toURI().toString();
+ }
+
+// @After
+// public void cleanUp() throws Exception {
+// IFile javaFile = project.getFile(new Path("src/main/java/org/acme/config/Empty.java"));
+// javaFile.refreshLocal(IResource.DEPTH_ZERO, null);
+// javaFile.setContents(new ByteArrayInputStream("".getBytes()), 0, MONITOR);
+//
+// }
+
+ // context kind tests
+
+ public void testEmptyFileContext() throws Exception {
+ String javaFileUri = getJavaFileUri("src/main/java/org/acme/config/Empty.java");
+ // |
+ MicroProfileJavaCompletionParams params = new MicroProfileJavaCompletionParams(javaFileUri, new Position(0, 0));
+ assertEquals(JavaCursorContextKind.IN_EMPTY_FILE,
+ PropertiesManagerForJava.getInstance().javaCursorContext(params, getJDTUtils()).getKind());
+ }
+
+// @Test
+// public void testJustSnippetFileContext() throws Exception {
+// String javaFileUri = getJavaFileUri("src/main/java/org/acme/config/Empty.java");
+// javaFile.refreshLocal(IResource.DEPTH_ZERO, null);
+// javaFile.setContents(new ByteArrayInputStream("rest_class".getBytes()), 0, MONITOR);
+//
+// // rest_class|
+// MicroProfileJavaCompletionParams params = new MicroProfileJavaCompletionParams(javaFileUri,
+// new Position(0, "rest_class".length()));
+// assertEquals(JavaCursorContextKind.IN_EMPTY_FILE,
+// PropertiesManagerForJava.getInstance().javaCursorContext(params, getJDTUtils()).getKind());
+//
+// // |rest_class
+// params = new MicroProfileJavaCompletionParams(javaFileUri, new Position(0, 0));
+// assertEquals(JavaCursorContextKind.IN_EMPTY_FILE,
+// PropertiesManagerForJava.getInstance().javaCursorContext(params, getJDTUtils()).getKind());
+//
+// // rest|_class
+// params = new MicroProfileJavaCompletionParams(javaFileUri, new Position(0, 4));
+// assertEquals(JavaCursorContextKind.IN_EMPTY_FILE,
+// PropertiesManagerForJava.getInstance().javaCursorContext(params, getJDTUtils()).getKind());
+// }
+
+ @Test
+ public void testBeforeFieldContext() throws Exception {
+ String javaFileUri = getJavaFileUri("src/main/java/org/acme/config/GreetingResource.java");
+
+ // ...
+ // @ConfigProperty(name = "greeting.message")
+ // |String message;
+ // ...
+ MicroProfileJavaCompletionParams params = new MicroProfileJavaCompletionParams(javaFileUri,
+ new Position(15, 4));
+ assertEquals(JavaCursorContextKind.IN_FIELD_ANNOTATIONS,
+ PropertiesManagerForJava.getInstance().javaCursorContext(params, getJDTUtils()).getKind());
+
+ // ...
+ // |@ConfigProperty(name = "greeting.message")
+ // String message;
+ // ...
+ params = new MicroProfileJavaCompletionParams(javaFileUri, new Position(14, 4));
+ assertEquals(JavaCursorContextKind.BEFORE_FIELD,
+ PropertiesManagerForJava.getInstance().javaCursorContext(params, getJDTUtils()).getKind());
+ }
+
+ @Test
+ public void testBeforeMethodContext() throws Exception {
+ String javaFileUri = getJavaFileUri("src/main/java/org/acme/config/GreetingResource.java");
+ // ...
+ // @GET
+ // @Produces(MediaType.TEXT_PLAIN)
+ // |public String hello() {
+ // ...
+ MicroProfileJavaCompletionParams params = new MicroProfileJavaCompletionParams(javaFileUri,
+ new Position(34, 4));
+ assertEquals(JavaCursorContextKind.IN_METHOD_ANNOTATIONS,
+ PropertiesManagerForJava.getInstance().javaCursorContext(params, getJDTUtils()).getKind());
+
+ // ...
+ // |@GET
+ // @Produces(MediaType.TEXT_PLAIN)
+ // public String hello() {
+ // ...
+ params = new MicroProfileJavaCompletionParams(javaFileUri, new Position(32, 4));
+ assertEquals(JavaCursorContextKind.BEFORE_METHOD,
+ PropertiesManagerForJava.getInstance().javaCursorContext(params, getJDTUtils()).getKind());
+ }
+
+ @Test
+ public void testInMethodContext() throws Exception {
+ String javaFileUri = getJavaFileUri("src/main/java/org/acme/config/GreetingResource.java");
+ // ...
+ // @GET
+ // @Produces(MediaType.TEXT_PLAIN)
+ // public String hello() {
+ // | return message + " " + name.orElse("world") + suffix;
+ // }
+ // ...
+ MicroProfileJavaCompletionParams params = new MicroProfileJavaCompletionParams(javaFileUri,
+ new Position(35, 0));
+ assertEquals(JavaCursorContextKind.NONE,
+ PropertiesManagerForJava.getInstance().javaCursorContext(params, getJDTUtils()).getKind());
+
+ // ...
+ // @GET
+ // @Produces(MediaType.TEXT_PLAIN)
+ // p|ublic String hello() {
+ // return message + " " + name.orElse("world") + suffix;
+ // }
+ // ...
+ params = new MicroProfileJavaCompletionParams(javaFileUri, new Position(34, 5));
+ assertEquals(JavaCursorContextKind.NONE,
+ PropertiesManagerForJava.getInstance().javaCursorContext(params, getJDTUtils()).getKind());
+ }
+
+ @Test
+ public void testInClassContext() throws Exception {
+ String javaFileUri = getJavaFileUri("src/main/java/org/acme/config/GreetingResource.java");
+ // ...
+ // public String hello() {
+ // return message + " " + name.orElse("world") + suffix;
+ // }
+ // |}
+ MicroProfileJavaCompletionParams params = new MicroProfileJavaCompletionParams(javaFileUri,
+ new Position(37, 0));
+ assertEquals(JavaCursorContextKind.IN_CLASS,
+ PropertiesManagerForJava.getInstance().javaCursorContext(params, getJDTUtils()).getKind());
+ }
+
+ @Test
+ public void testAfterClassContext() throws Exception {
+ String javaFileUri = getJavaFileUri("src/main/java/org/acme/config/GreetingResource.java");
+ // ...
+ // public String hello() {
+ // return message + " " + name.orElse("world") + suffix;
+ // }
+ // }
+ // |
+ MicroProfileJavaCompletionParams params = new MicroProfileJavaCompletionParams(javaFileUri,
+ new Position(38, 0));
+ assertEquals(JavaCursorContextKind.NONE,
+ PropertiesManagerForJava.getInstance().javaCursorContext(params, getJDTUtils()).getKind());
+ }
+
+ @Test
+ public void testClassContextUsingInterface() throws Exception {
+ String javaFileUri = getJavaFileUri("src/main/java/org/acme/config/MyInterface.java");
+ // ...
+ // public interface MyInterface {
+ // |
+ // ...
+ MicroProfileJavaCompletionParams params = new MicroProfileJavaCompletionParams(javaFileUri, new Position(3, 0));
+ assertEquals(JavaCursorContextKind.BEFORE_FIELD,
+ PropertiesManagerForJava.getInstance().javaCursorContext(params, getJDTUtils()).getKind());
+
+ // ...
+ // public interface MyInterface {
+ // ...
+ // public void helloWorld();
+ // |
+ // }
+ params = new MicroProfileJavaCompletionParams(javaFileUri, new Position(7, 0));
+ assertEquals(JavaCursorContextKind.IN_CLASS,
+ PropertiesManagerForJava.getInstance().javaCursorContext(params, getJDTUtils()).getKind());
+ }
+
+ @Test
+ public void testClassContextUsingEnum() throws Exception {
+ String javaFileUri = getJavaFileUri("src/main/java/org/acme/config/MyEnum.java");
+ // ...
+ // public enum MyEnum {
+ // |
+ // VALUE;
+ // ...
+ MicroProfileJavaCompletionParams params = new MicroProfileJavaCompletionParams(javaFileUri, new Position(3, 0));
+ assertEquals(JavaCursorContextKind.BEFORE_FIELD,
+ PropertiesManagerForJava.getInstance().javaCursorContext(params, getJDTUtils()).getKind());
+
+ // ...
+ // public enum MyEnum {
+ // ...
+ // |
+ // public void helloWorld();
+ // ...
+ params = new MicroProfileJavaCompletionParams(javaFileUri, new Position(7, 0));
+ assertEquals(JavaCursorContextKind.BEFORE_METHOD,
+ PropertiesManagerForJava.getInstance().javaCursorContext(params, getJDTUtils()).getKind());
+
+ // ...
+ // public enum MyEnum {
+ // ...
+ // public void helloWorld();
+ // |
+ // }
+ params = new MicroProfileJavaCompletionParams(javaFileUri, new Position(9, 0));
+ assertEquals(JavaCursorContextKind.IN_CLASS,
+ PropertiesManagerForJava.getInstance().javaCursorContext(params, getJDTUtils()).getKind());
+ }
+
+ @Test
+ public void testClassContextUsingAnnotation() throws Exception {
+ String javaFileUri = getJavaFileUri("src/main/java/org/acme/config/MyAnnotation.java");
+ // ...
+ // public @interface MyAnnotation {
+ // |
+ // public static String MY_STRING = "asdf";
+ // ...
+ MicroProfileJavaCompletionParams params = new MicroProfileJavaCompletionParams(javaFileUri, new Position(3, 0));
+ assertEquals(JavaCursorContextKind.BEFORE_FIELD,
+ PropertiesManagerForJava.getInstance().javaCursorContext(params, getJDTUtils()).getKind());
+
+ // ...
+ // public @interface MyAnnotation {
+ // ...
+ // |
+ // public String value() default MY_STRING;
+ // ...
+ params = new MicroProfileJavaCompletionParams(javaFileUri, new Position(5, 0));
+ assertEquals(JavaCursorContextKind.BEFORE_METHOD,
+ PropertiesManagerForJava.getInstance().javaCursorContext(params, getJDTUtils()).getKind());
+
+ // ...
+ // public @interface MyAnnotation {
+ // ...
+ // public String value() default MY_STRING;
+ // |
+ // }
+ params = new MicroProfileJavaCompletionParams(javaFileUri, new Position(7, 0));
+ assertEquals(JavaCursorContextKind.IN_CLASS,
+ PropertiesManagerForJava.getInstance().javaCursorContext(params, getJDTUtils()).getKind());
+ }
+
+ @Test
+ public void testBeforeClassContext() throws Exception {
+ String javaFileUri = getJavaFileUri("src/main/java/org/acme/config/MyNestedClass.java");
+ // ...
+ // @Singleton
+ // public class MyNestedClass {
+ // |
+ // @Singleton
+ // static class MyNestedNestedClass {
+ // ...
+ MicroProfileJavaCompletionParams params = new MicroProfileJavaCompletionParams(javaFileUri, new Position(4, 0));
+ assertEquals(JavaCursorContextKind.BEFORE_CLASS,
+ PropertiesManagerForJava.getInstance().javaCursorContext(params, getJDTUtils()).getKind());
+
+ // ...
+ // @Singleton
+ // public class MyNestedClass {
+ //
+ // |@Singleton
+ // static class MyNestedNestedClass {
+ // ...
+ params = new MicroProfileJavaCompletionParams(javaFileUri, new Position(5, 0));
+ assertEquals(JavaCursorContextKind.BEFORE_CLASS,
+ PropertiesManagerForJava.getInstance().javaCursorContext(params, getJDTUtils()).getKind());
+
+ // ...
+ // @Singleton
+ // public class MyNestedClass {
+ //
+ // @Singleton
+ // | static class MyNestedNestedClass {
+ // ...
+ params = new MicroProfileJavaCompletionParams(javaFileUri, new Position(6, 0));
+ assertEquals(JavaCursorContextKind.IN_CLASS_ANNOTATIONS,
+ PropertiesManagerForJava.getInstance().javaCursorContext(params, getJDTUtils()).getKind());
+
+ // ...
+ // |
+ // @Singleton
+ // public class MyNestedClass {
+ // ...
+ params = new MicroProfileJavaCompletionParams(javaFileUri, new Position(1, 0));
+ assertEquals(JavaCursorContextKind.BEFORE_CLASS,
+ PropertiesManagerForJava.getInstance().javaCursorContext(params, getJDTUtils()).getKind());
+
+ // ...
+ // @Singleton
+ // |public class MyNestedClass {
+ // ...
+ params = new MicroProfileJavaCompletionParams(javaFileUri, new Position(3, 0));
+ assertEquals(JavaCursorContextKind.IN_CLASS_ANNOTATIONS,
+ PropertiesManagerForJava.getInstance().javaCursorContext(params, getJDTUtils()).getKind());
+ }
+
+ // prefix tests
+
+ @Test
+ public void testAtBeginningOfFile() throws Exception {
+ String javaFileUri = getJavaFileUri("src/main/java/org/acme/config/Empty.java");
+ // |
+ MicroProfileJavaCompletionParams params = new MicroProfileJavaCompletionParams(javaFileUri, new Position(0, 0));
+ assertEquals("", PropertiesManagerForJava.getInstance().javaCursorContext(params, getJDTUtils()).getPrefix());
+ }
+
+// @Test
+// public void testOneWord() throws Exception {
+// String javaFileUri = getJavaFileUri("src/main/java/org/acme/config/Empty.java");
+// javaFile.refreshLocal(IResource.DEPTH_ZERO, null);
+// javaFile.setContents(new ByteArrayInputStream("rest_class".getBytes()), 0, MONITOR);
+//
+// // rest_class|
+// MicroProfileJavaCompletionParams params = new MicroProfileJavaCompletionParams(javaFileUri,
+// new Position(0, "rest_class".length()));
+// assertEquals("rest_class", PropertiesManagerForJava.getInstance().javaCursorContext(params, getJDTUtils()).getPrefix());
+//
+// // |rest_class
+// params = new MicroProfileJavaCompletionParams(javaFileUri, new Position(0, 0));
+// assertEquals("", PropertiesManagerForJava.getInstance().javaCursorContext(params, getJDTUtils()).getPrefix());
+//
+// // rest_|class
+// params = new MicroProfileJavaCompletionParams(javaFileUri, new Position(0, 5));
+// assertEquals("rest_", PropertiesManagerForJava.getInstance().javaCursorContext(params, getJDTUtils()).getPrefix());
+// }
+//
+// @Test
+// public void testTwoWords() throws Exception {
+// String javaFileUri = getJavaFileUri("src/main/java/org/acme/config/Empty.java");
+// javaFile.refreshLocal(IResource.DEPTH_ZERO, null);
+// javaFile.setContents(new ByteArrayInputStream("asdf hjkl".getBytes()), 0, MONITOR);
+//
+// // asdf hjk|l
+// MicroProfileJavaCompletionParams params = new MicroProfileJavaCompletionParams(javaFileUri, new Position(0, 8));
+// assertEquals("hjk", PropertiesManagerForJava.getInstance().javaCursorContext(params, getJDTUtils()).getPrefix());
+//
+// // asdf |hjkl
+// params = new MicroProfileJavaCompletionParams(javaFileUri, new Position(0, 5));
+// assertEquals("", PropertiesManagerForJava.getInstance().javaCursorContext(params, getJDTUtils()).getPrefix());
+// }
+
+}
\ No newline at end of file