+ * If the owner Java project of the Java file URI contains some type in the + * classpath, it will return the type as label in + * {@link ProjectLabelInfoEntry#getLabels()} + *
+ * + * @return the Java types list to check + */ + public List
- * |
- *
- */
- IN_EMPTY_FILE(1),
+ /**
+ * The cursor is in a file that does not have a root type declaration.
+ *
+ * eg.
+ *
+ * |
+ *
+ */
+ IN_EMPTY_FILE(1),
- /**
- * The cursor is before a type declaration body, either at the root of a file or
- * within another class. The cursor is before any annotations on the type.
- *
- * eg.
- *
- *
- * package org.acme;
- *
- * |
- * @Inject
- * public class MyClass {
- *
- * }
- *
- *
- * eg.
- *
- *
- * package org.acme;
- *
- * @Inject
- * public class MyClass {
- *
- * private int memberVariable;
- * |
- * @Inject
- * public static class MyChildClass {
- *
- * }
- * }
- *
- */
- BEFORE_CLASS(2),
+ /**
+ * The cursor is before a type declaration body, either at the root of a file or
+ * within another class. The cursor is before any annotations on the type.
+ *
+ * eg.
+ *
+ *
+ * package org.acme;
+ *
+ * |
+ * @Inject
+ * public class MyClass {
+ *
+ * }
+ *
+ *
+ * eg.
+ *
+ *
+ * package org.acme;
+ *
+ * @Inject
+ * public class MyClass {
+ *
+ * private int memberVariable;
+ * |
+ * @Inject
+ * public static class MyChildClass {
+ *
+ * }
+ * }
+ *
+ */
+ BEFORE_CLASS(2),
- /**
- * The cursor is in a type declaration body, and the next declaration in the
- * body is a method declaration. The cursor is before any annotations on the
- * method.
- *
- * eg.
- *
- *
- * package org.acme;
- *
- * public class MyClass {
- * |
- * @Deprecated
- * public void myMethod() {
- * }
- * }
- *
- */
- BEFORE_METHOD(3),
+ /**
+ * The cursor is in a type declaration body, and the next declaration in the
+ * body is a method declaration. The cursor is before any annotations on the
+ * method.
+ *
+ * eg.
+ *
+ *
+ * package org.acme;
+ *
+ * public class MyClass {
+ * |
+ * @Deprecated
+ * public void myMethod() {
+ * }
+ * }
+ *
+ */
+ BEFORE_METHOD(3),
- /**
- * The cursor is in a type declaration body, and the next declaration in the
- * body is a field declaration. The cursor is before any annotations on the
- * field.
- *
- * eg.
- *
- *
- * package org.acme;
- *
- * public class MyClass {
- * |
- * @Deprecated
- * public String myString;
- * }
- *
- */
- BEFORE_FIELD(4),
+ /**
+ * The cursor is in a type declaration body, and the next declaration in the
+ * body is a field declaration. The cursor is before any annotations on the
+ * field.
+ *
+ * eg.
+ *
+ *
+ * package org.acme;
+ *
+ * public class MyClass {
+ * |
+ * @Deprecated
+ * public String myString;
+ * }
+ *
+ */
+ BEFORE_FIELD(4),
- /**
- * The cursor is before a type declaration body, either at the root of a file or
- * within another class. The cursor is somewhere within the annotation
- * declarations on the class.
- *
- * eg.
- *
- *
- * package org.acme;
- *
- * @Inject|
- * public class MyClass {
- *
- * }
- *
- *
- * eg.
- *
- *
- * package org.acme;
- *
- * @Inject
- * public class MyClass {
- *
- * private int memberVariable;
- *
- * @Inject|
- * public static class MyChildClass {
- *
- * }
- * }
- *
- */
- IN_CLASS_ANNOTATIONS(5),
+ /**
+ * The cursor is before a type declaration body, either at the root of a file or
+ * within another class. The cursor is somewhere within the annotation
+ * declarations on the class.
+ *
+ * eg.
+ *
+ *
+ * package org.acme;
+ *
+ * @Inject|
+ * public class MyClass {
+ *
+ * }
+ *
+ *
+ * eg.
+ *
+ *
+ * package org.acme;
+ *
+ * @Inject
+ * public class MyClass {
+ *
+ * private int memberVariable;
+ *
+ * @Inject|
+ * public static class MyChildClass {
+ *
+ * }
+ * }
+ *
+ */
+ IN_CLASS_ANNOTATIONS(5),
- /**
- * The cursor is in a type declaration body, and the next declaration in the
- * body is a method declaration. The cursor is somewhere within the annotation
- * declarations on the method.
- *
- * eg.
- *
- *
- * package org.acme;
- *
- * public class MyClass {
- *
- * @Deprecated|
- * public void myMethod() {
- * }
- * }
- *
- */
- IN_METHOD_ANNOTATIONS(6),
+ /**
+ * The cursor is in a type declaration body, and the next declaration in the
+ * body is a method declaration. The cursor is somewhere within the annotation
+ * declarations on the method.
+ *
+ * eg.
+ *
+ *
+ * package org.acme;
+ *
+ * public class MyClass {
+ *
+ * @Deprecated|
+ * public void myMethod() {
+ * }
+ * }
+ *
+ */
+ IN_METHOD_ANNOTATIONS(6),
- /**
- * The cursor is in a type declaration body, and the next declaration in the
- * body is a field declaration. The cursor is somewhere within the annotation
- * declarations on the field.
- *
- * eg.
- *
- *
- * package org.acme;
- *
- * public class MyClass {
- *
- * @Deprecated|
- * public String myString;
- * }
- *
- */
- IN_FIELD_ANNOTATIONS(7),
+ /**
+ * The cursor is in a type declaration body, and the next declaration in the
+ * body is a field declaration. The cursor is somewhere within the annotation
+ * declarations on the field.
+ *
+ * eg.
+ *
+ *
+ * package org.acme;
+ *
+ * public class MyClass {
+ *
+ * @Deprecated|
+ * public String myString;
+ * }
+ *
+ */
+ IN_FIELD_ANNOTATIONS(7),
- /**
- * The cursor is in a type declaration body, after all the declarations for the
- * type.
- *
- * eg.
- *
- *
- * package org.acme;
- *
- * public class MyClass {
- *
- * @Deprecated
- * public String myString;
- * |
- * }
- *
- */
- IN_CLASS(8),
+ /**
+ * The cursor is in a type declaration body, after all the declarations for the
+ * type.
+ *
+ * eg.
+ *
+ *
+ * package org.acme;
+ *
+ * public class MyClass {
+ *
+ * @Deprecated
+ * public String myString;
+ * |
+ * }
+ *
+ */
+ IN_CLASS(8),
- /**
- * None of the above context apply.
- *
- * eg.
- *
- *
- * package org.acme;
- *
- * public class MyClass {
- *
- * @Deprecated
- * public void myMethod() {
- * |
- * }
- * }
- *
- */
- NONE(2000);
+ /**
+ * None of the above context apply.
+ *
+ * eg.
+ *
+ *
+ * package org.acme;
+ *
+ * public class MyClass {
+ *
+ * @Deprecated
+ * public void myMethod() {
+ * |
+ * }
+ * }
+ *
+ */
+ NONE(2000);
- private final int value;
+ private final int value;
- private JavaCursorContextKind(int value) {
- this.value = value;
- }
+ private JavaCursorContextKind(int value) {
+ this.value = value;
+ }
- public int getValue() {
- return value;
- }
+ public int getValue() {
+ return value;
+ }
- public static JavaCursorContextKind forValue(int value) {
- JavaCursorContextKind[] allValues = JavaCursorContextKind.values();
- if (value < 1 || value > allValues.length)
- throw new IllegalArgumentException("Illegal enum value: " + value);
- return allValues[value - 1];
- }
+ public static JavaCursorContextKind forValue(int value) {
+ JavaCursorContextKind[] allValues = JavaCursorContextKind.values();
+ if (value < 1 || value > allValues.length)
+ throw new IllegalArgumentException("Illegal enum value: " + value);
+ return allValues[value - 1];
+ }
}
diff --git a/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/commons/JavaCursorContextResult.java b/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/commons/JavaCursorContextResult.java
index 62db4a6b..bde53b4b 100644
--- a/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/commons/JavaCursorContextResult.java
+++ b/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/commons/JavaCursorContextResult.java
@@ -13,57 +13,56 @@
*******************************************************************************/
package org.eclipse.lsp4jakarta.commons;
-
/**
* Represents context related to the cursor location in the given document.
*/
public class JavaCursorContextResult {
- private JavaCursorContextKind kind;
- private String prefix;
+ private JavaCursorContextKind kind;
+ private String prefix;
- public JavaCursorContextResult(JavaCursorContextKind kind, String prefix) {
- this.kind = kind;
- this.prefix = prefix;
- }
+ public JavaCursorContextResult(JavaCursorContextKind kind, String prefix) {
+ this.kind = kind;
+ this.prefix = prefix;
+ }
- public JavaCursorContextResult() {
- this(null, null);
- }
+ public JavaCursorContextResult() {
+ this(null, null);
+ }
- /**
- * Returns the context of the cursor in the Java file or NONE
if
- * none of the contexts apply.
- *
- * For instance, it returns IN_METHOD_ANNOTATIONS
if the cursor is
- * in the list of annotations before a method declaration.
- *
- * @return the context of the cursor in the Java file
- */
- public JavaCursorContextKind getKind() {
- return kind;
- }
+ /**
+ * Returns the context of the cursor in the Java file or NONE
if
+ * none of the contexts apply.
+ *
+ * For instance, it returns IN_METHOD_ANNOTATIONS
if the cursor is
+ * in the list of annotations before a method declaration.
+ *
+ * @return the context of the cursor in the Java file
+ */
+ public JavaCursorContextKind getKind() {
+ return kind;
+ }
- /**
- * Returns the text content to the left of the cursor, up to the first whitespace.
- *
- * eg.
- *
- *
- * public static|
- *
- *
- * would return "static"
- *
- *
- * |
- *
- *
- * would return ""
- *
- *@return the text content to the left of the cursor, up to the first whitespace
- */
- public String getPrefix() {
- return prefix;
- }
+ /**
+ * Returns the text content to the left of the cursor, up to the first whitespace.
+ *
+ * eg.
+ *
+ *
+ * public static|
+ *
+ *
+ * would return "static"
+ *
+ *
+ * |
+ *
+ *
+ * would return ""
+ *
+ * @return the text content to the left of the cursor, up to the first whitespace
+ */
+ public String getPrefix() {
+ return prefix;
+ }
}
diff --git a/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/commons/ProjectLabelInfoEntry.java b/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/commons/ProjectLabelInfoEntry.java
new file mode 100644
index 00000000..720abd62
--- /dev/null
+++ b/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/commons/ProjectLabelInfoEntry.java
@@ -0,0 +1,77 @@
+/*******************************************************************************
+* Copyright (c) 2020 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 org.eclipse.lsp4jakarta.commons;
+
+import java.util.Collections;
+import java.util.List;
+
+/**
+ * Stores labels for the project located at a specific project uri
+ *
+ * @author dakwon
+ *
+ */
+public class ProjectLabelInfoEntry {
+ public static final ProjectLabelInfoEntry EMPTY_PROJECT_INFO = new ProjectLabelInfoEntry("", "", Collections.emptyList());
+
+ private final String uri;
+ private final String name;
+ private final List labels;
+
+ public ProjectLabelInfoEntry(String uri, String name, List labels) {
+ this.uri = uri;
+ this.name = name;
+ this.labels = labels;
+ }
+
+ /**
+ * Returns the project uri
+ *
+ * @return the project uri
+ */
+ public String getUri() {
+ return uri;
+ }
+
+ /**
+ * Returns the name of the project
+ *
+ * @return The name of this project
+ */
+ public String getName() {
+ return name;
+ }
+
+ /**
+ * Returns the labels for the current project uri
+ *
+ * @return the labels for the current project uri
+ */
+ public List getLabels() {
+ return labels;
+ }
+
+ /**
+ * Returns true if the project has the given label and false otherwise.
+ *
+ * @param label the label.
+ * @return true if the project has the given label and false otherwise.
+ */
+ public boolean hasLabel(String label) {
+ //boolean truth = true;
+ //return truth;
+ // right?
+ return labels != null && labels.contains(label);
+ }
+}
\ No newline at end of file
diff --git a/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/commons/codeaction/CodeActionData.java b/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/commons/codeaction/CodeActionData.java
new file mode 100644
index 00000000..398ffca2
--- /dev/null
+++ b/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/commons/codeaction/CodeActionData.java
@@ -0,0 +1,76 @@
+/*******************************************************************************
+* 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 org.eclipse.lsp4jakarta.commons.codeaction;
+
+import java.util.Objects;
+
+/**
+ * Represents the data that all code actions have.
+ */
+public class CodeActionData {
+
+ private String id;
+
+ public CodeActionData() {
+ this(null);
+ }
+
+ public CodeActionData(ICodeActionId id) {
+ setCodeActionId(id);
+ }
+
+ /**
+ * Returns the id of this code action as a string.
+ *
+ * Each type of code action has an id that represents it, so that it's easy to
+ * associate a given code action to the code that generated it.
+ *
+ * @return the id of this code action
+ */
+ public String getCodeActionId() {
+ return id;
+ }
+
+ /**
+ * Sets the id of this code action.
+ *
+ * @param id the new value for the id of this code action
+ */
+ public void setCodeActionId(ICodeActionId id) {
+ if (id != null) {
+ this.id = id.getId();
+ } else {
+ this.id = null;
+ }
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj)
+ return true;
+ if (obj == null)
+ return false;
+ if (!(obj instanceof CodeActionData)) {
+ return false;
+ }
+ CodeActionData other = (CodeActionData) obj;
+ return Objects.equals(id, other.id);
+ }
+
+ @Override
+ public String toString() {
+ return "CodeActionData [id=" + id + "]";
+ }
+
+}
diff --git a/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/commons/codeaction/CodeActionResolveData.java b/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/commons/codeaction/CodeActionResolveData.java
new file mode 100644
index 00000000..22dbbb94
--- /dev/null
+++ b/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/commons/codeaction/CodeActionResolveData.java
@@ -0,0 +1,132 @@
+/*******************************************************************************
+* Copyright (c) 2022 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 org.eclipse.lsp4jakarta.commons.codeaction;
+
+import java.util.Map;
+import java.util.Objects;
+
+import org.eclipse.lsp4j.Range;
+
+/**
+ * Represents additional data that is needed to resolve a code action.
+ *
+ * @author datho7561
+ */
+public class CodeActionResolveData extends CodeActionData {
+
+ private String participantId;
+ private String documentUri;
+
+ private Range range;
+
+ private Map extendedData;
+
+ private boolean resourceOperationSupported;
+ private boolean commandConfigurationUpdateSupported;
+
+ /**
+ * Make code action data will all fields nulled/false
+ *
+ * Needed for Gson
+ */
+ public CodeActionResolveData() {
+ this(null, null, null, null, false, false, null);
+ }
+
+ public CodeActionResolveData(String documentUri, String participantId, Range range,
+ Map extendedData, boolean resourceOperationSupported,
+ boolean commandConfigurationUpdateSupported, ICodeActionId id) {
+ super(id);
+ this.documentUri = documentUri;
+ this.participantId = participantId;
+ this.range = range;
+ this.extendedData = extendedData;
+ this.resourceOperationSupported = resourceOperationSupported;
+ this.commandConfigurationUpdateSupported = commandConfigurationUpdateSupported;
+ }
+
+ /**
+ * Returns the uri of the document that this code action applies to.
+ *
+ * @return the uri of the document that this code action applies to
+ */
+ public String getDocumentUri() {
+ return this.documentUri;
+ }
+
+ /**
+ * Returns the unique id of the IJavaCodeActionParticipant that can resolve the
+ * text edits for this code action.
+ *
+ * @return the unique id of the IJavaCodeActionParticipant that can resolve the
+ * text edits for this code action
+ */
+ public String getParticipantId() {
+ return this.participantId;
+ }
+
+ /**
+ * Returns the range for which this CodeAction is applicable for.
+ *
+ * @return the range for which this CodeAction is applicable for
+ */
+ public Range getRange() {
+ return this.range;
+ }
+
+ /**
+ * Returns the entry in the extended data for the given key
+ *
+ * @param key the key to get the entry for
+ * @return the entry in the extended data for the given key
+ */
+ public Object getExtendedDataEntry(String key) {
+ return extendedData.get(key);
+ }
+
+ /**
+ * Returns true if the client supports resource operations and false otherwise.
+ *
+ * @return true if the client supports resource operations and false otherwise
+ */
+ public boolean isResourceOperationSupported() {
+ return this.resourceOperationSupported;
+ }
+
+ /**
+ * Returns true if the client implements a command that allows the language
+ * server to update preferences, and false otherwise.
+ *
+ * @return true if the client implements a command that allows the language
+ * server to update preferences, and false otherwise
+ */
+ public boolean isCommandConfigurationUpdateSupported() {
+ return this.commandConfigurationUpdateSupported;
+ }
+
+ @Override
+ public boolean equals(Object other) {
+ if (this == other) {
+ return true;
+ }
+ if (!(other instanceof CodeActionResolveData)) {
+ return false;
+ }
+ CodeActionResolveData that = (CodeActionResolveData) other;
+ return Objects.equals(this.documentUri, that.documentUri)
+ && Objects.equals(this.participantId, that.participantId) && Objects.equals(this.range, that.range)
+ && Objects.equals(this.extendedData, that.extendedData)
+ && Objects.equals(this.resourceOperationSupported, that.resourceOperationSupported)
+ && Objects.equals(this.commandConfigurationUpdateSupported, that.commandConfigurationUpdateSupported);
+ }
+
+}
diff --git a/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/commons/codeaction/ICodeActionId.java b/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/commons/codeaction/ICodeActionId.java
new file mode 100644
index 00000000..c5a19ded
--- /dev/null
+++ b/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/commons/codeaction/ICodeActionId.java
@@ -0,0 +1,28 @@
+/*******************************************************************************
+* 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 org.eclipse.lsp4jakarta.commons.codeaction;
+
+/**
+ * Represents an id that identifies the type of code action.
+ */
+public interface ICodeActionId {
+
+ /**
+ * Returns the id of this code action as a string.
+ *
+ * @return the id of this code action as a string
+ */
+ String getId();
+
+}
diff --git a/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/commons/codeaction/JakartaCodeActionId.java b/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/commons/codeaction/JakartaCodeActionId.java
new file mode 100644
index 00000000..d8c987aa
--- /dev/null
+++ b/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/commons/codeaction/JakartaCodeActionId.java
@@ -0,0 +1,75 @@
+/*******************************************************************************
+* 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 org.eclipse.lsp4jakarta.commons.codeaction;
+
+/**
+ * Represents id of an lsp4mp code action.
+ */
+public enum JakartaCodeActionId implements ICodeActionId {
+ IgnoreUnknownProperty,
+ // JAXRS
+ jaxrsInsertPublicCtrtToClass,
+ MakeConstructorPublic,
+ MakeMethodPublic,
+ RemoveAllEntityParametersExcept,
+ // Annotations
+ ChangeReturnTypeToVoid,
+ InsertResourceAnnotationTypeAttribute,
+ InsertResourceAnnotationNameAttribute,
+ RemoveAllParameters,
+ RemoveAnnotationPreDestroy,
+ RemoveAnnotationPostConstruct,
+ AnnotationRemoveStaticModifier,
+ // Bean validation
+ RemoveConstraintAnnotation,
+ BBRemoveStaticModifier,
+ // Dependency injection
+ DIRemoveInjectAnnotation,
+ DIRemoveFinalModifier,
+ DIRemoveAbstractModifier,
+ DIRemoveStaticModifier,
+ // JSON-B
+ JSONBRemoveJsonbCreatorAnnotation,
+ JSONBRemoveJsonbTransientAnnotation,
+ JSONBRemoveAllButJsonbTransientAnnotation,
+ // Persistence
+ PersistenceRemoveFinalModifier,
+ PersistenceRemoveMapKeyAnnotation,
+ PersistenceInsertAttributesToMKJCAnnotation,
+ PersistenceInsertPublicCtrtToClass,
+ PersistenceInsertProtectedCtrtToClass,
+ // WebSockets
+ WBInsertPathParamAnnotationWithValueAttrib,
+ // Servlet
+ ServletCompleteWebFilterAnnotation,
+ ServletCompleteServletAnnotation,
+ ServletFilterImplementation,
+ ServletExtendClass,
+ ServletListenerImplementation,
+ // CDI
+ CDIRemoveProducesAndInjectAnnotations,
+ CDIInsertInjectAnnotation,
+ CDIInsertProtectedCtrtToClass,
+ CDIInsertPublicCtrtToClass,
+ CDIRemoveInvalidInjectAnnotations,
+ CDIRemoveProducesAnnotation,
+ CDIRemoveInjectAnnotation,
+ CDIRemoveScopeDeclarationAnnotationsButOne,
+ CDIReplaceScopeAnnotations;
+
+ @Override
+ public String getId() {
+ return name();
+ }
+}
\ No newline at end of file
diff --git a/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/codeAction/CodeActionHandler.java b/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/codeAction/CodeActionHandler.java
deleted file mode 100644
index 8124ce84..00000000
--- a/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/codeAction/CodeActionHandler.java
+++ /dev/null
@@ -1,281 +0,0 @@
-/*******************************************************************************
-* Copyright (c) 2020 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 org.eclipse.lsp4jakarta.jdt.codeAction;
-
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
-
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.jdt.core.IBuffer;
-import org.eclipse.jdt.core.ICompilationUnit;
-import org.eclipse.jdt.core.JavaModelException;
-import org.eclipse.jdt.core.dom.CompilationUnit;
-import org.eclipse.jdt.core.manipulation.CoreASTProvider;
-import org.eclipse.lsp4j.CodeAction;
-import org.eclipse.lsp4j.Diagnostic;
-import org.eclipse.lsp4j.Range;
-import org.eclipse.lsp4jakarta.commons.JakartaJavaCodeActionParams;
-import org.eclipse.lsp4jakarta.jdt.codeAction.proposal.quickfix.RemoveAbstractModifierQuickFix;
-import org.eclipse.lsp4jakarta.jdt.codeAction.proposal.quickfix.RemoveFinalModifierQuickFix;
-import org.eclipse.lsp4jakarta.jdt.codeAction.proposal.quickfix.RemoveInjectAnnotationQuickFix;
-import org.eclipse.lsp4jakarta.jdt.codeAction.proposal.quickfix.RemoveMethodParametersQuickFix;
-import org.eclipse.lsp4jakarta.jdt.codeAction.proposal.quickfix.RemoveStaticModifierQuickFix;
-import org.eclipse.lsp4jakarta.jdt.core.JDTUtils;
-import org.eclipse.lsp4jakarta.jdt.core.JsonRpcHelpers;
-import org.eclipse.lsp4jakarta.jdt.core.beanvalidation.BeanValidationConstants;
-import org.eclipse.lsp4jakarta.jdt.core.beanvalidation.BeanValidationQuickFix;
-import org.eclipse.lsp4jakarta.jdt.core.persistence.PersistenceAnnotationQuickFix;
-import org.eclipse.lsp4jakarta.jdt.core.persistence.PersistenceConstants;
-import org.eclipse.lsp4jakarta.jdt.core.persistence.PersistenceEntityQuickFix;
-import org.eclipse.lsp4jakarta.jdt.core.jax_rs.Jax_RSConstants;
-import org.eclipse.lsp4jakarta.jdt.core.jax_rs.NoResourcePublicConstructorQuickFix;
-import org.eclipse.lsp4jakarta.jdt.core.jax_rs.NonPublicResourceMethodQuickFix;
-import org.eclipse.lsp4jakarta.jdt.core.jax_rs.ResourceMethodMultipleEntityParamsQuickFix;
-import org.eclipse.lsp4jakarta.jdt.core.jsonb.JsonbAnnotationQuickFix;
-import org.eclipse.lsp4jakarta.jdt.core.jsonb.JsonbTransientAnnotationQuickFix;
-import org.eclipse.lsp4jakarta.jdt.core.jsonb.JsonbConstants;
-import org.eclipse.lsp4jakarta.jdt.core.cdi.ConflictProducesInjectQuickFix;
-import org.eclipse.lsp4jakarta.jdt.core.cdi.ManagedBeanConstants;
-import org.eclipse.lsp4jakarta.jdt.core.cdi.ManagedBeanConstructorQuickFix;
-import org.eclipse.lsp4jakarta.jdt.core.cdi.ManagedBeanNoArgConstructorQuickFix;
-import org.eclipse.lsp4jakarta.jdt.core.cdi.ManagedBeanQuickFix;
-import org.eclipse.lsp4jakarta.jdt.core.cdi.RemoveInvalidInjectParamAnnotationQuickFix;
-import org.eclipse.lsp4jakarta.jdt.core.cdi.RemoveProduceAnnotationQuickFix;
-import org.eclipse.lsp4jakarta.jdt.core.cdi.ScopeDeclarationQuickFix;
-import org.eclipse.lsp4jakarta.jdt.core.di.DependencyInjectionConstants;
-import org.eclipse.lsp4jakarta.jdt.core.servlet.CompleteFilterAnnotationQuickFix;
-import org.eclipse.lsp4jakarta.jdt.core.servlet.CompleteServletAnnotationQuickFix;
-import org.eclipse.lsp4jakarta.jdt.core.servlet.FilterImplementationQuickFix;
-import org.eclipse.lsp4jakarta.jdt.core.servlet.HttpServletQuickFix;
-import org.eclipse.lsp4jakarta.jdt.core.servlet.ListenerImplementationQuickFix;
-import org.eclipse.lsp4jakarta.jdt.core.servlet.ServletConstants;
-import org.eclipse.lsp4jakarta.jdt.core.persistence.DeleteConflictMapKeyQuickFix;
-import org.eclipse.lsp4jakarta.jdt.core.annotations.AddResourceMissingNameQuickFix;
-import org.eclipse.lsp4jakarta.jdt.core.annotations.AddResourceMissingTypeQuickFix;
-import org.eclipse.lsp4jakarta.jdt.core.annotations.AnnotationConstants;
-import org.eclipse.lsp4jakarta.jdt.core.annotations.PostConstructReturnTypeQuickFix;
-import org.eclipse.lsp4jakarta.jdt.core.annotations.RemovePreDestroyAnnotationQuickFix;
-import org.eclipse.lsp4jakarta.jdt.core.annotations.RemovePostConstructAnnotationQuickFix;
-import org.eclipse.lsp4jakarta.jdt.core.websocket.WebSocketConstants;
-import org.eclipse.lsp4jakarta.jdt.core.websocket.AddPathParamQuickFix;
-import org.eclipse.lsp4jakarta.jdt.core.JakartaCorePlugin;
-
-/**
- * Code action handler. Partially reused from
- * https://github.com/eclipse/lsp4mp/blob/b88710cc54170844717f655b9bff8bb4c4649a8d/microprofile.jdt/org.eclipse.lsp4mp.jdt.core/src/main/java/org/eclipse/lsp4mp/jdt/internal/core/java/codeaction/CodeActionHandler.java
- * Modified to fit the purposes of the Jakarta Language Server with deletions of
- * some unnecessary methods and modifications.
- *
- * @author credit to Angelo ZERR
- *
- */
-public class CodeActionHandler {
-
- public List codeAction(JakartaJavaCodeActionParams params, JDTUtils utils, IProgressMonitor monitor) {
- String uri = params.getUri();
- ICompilationUnit unit = utils.resolveCompilationUnit(uri);
- if (unit == null) {
- return Collections.emptyList();
- }
- try {
- Range range = params.getRange();
- int startOffset = toOffset(unit.getBuffer(), range.getStart().getLine(), range.getStart().getCharacter());
- int endOffset = toOffset(unit.getBuffer(), range.getEnd().getLine(), range.getEnd().getCharacter());
- JavaCodeActionContext context = new JavaCodeActionContext(unit, startOffset, endOffset - startOffset, utils,
- params);
- context.setASTRoot(getASTRoot(unit, monitor));
-
- List codeActions = new ArrayList<>();
-
- HttpServletQuickFix HttpServletQuickFix = new HttpServletQuickFix();
- FilterImplementationQuickFix FilterImplementationQuickFix = new FilterImplementationQuickFix();
- ListenerImplementationQuickFix ListenerImplementationQuickFix = new ListenerImplementationQuickFix();
- CompleteServletAnnotationQuickFix CompleteServletAnnotationQuickFix = new CompleteServletAnnotationQuickFix();
- CompleteFilterAnnotationQuickFix CompleteFilterAnnotationQuickFix = new CompleteFilterAnnotationQuickFix();
- PersistenceAnnotationQuickFix PersistenceAnnotationQuickFix = new PersistenceAnnotationQuickFix();
- DeleteConflictMapKeyQuickFix DeleteConflictMapKeyQuickFix = new DeleteConflictMapKeyQuickFix();
- NonPublicResourceMethodQuickFix NonPublicResourceMethodQuickFix = new NonPublicResourceMethodQuickFix();
- ResourceMethodMultipleEntityParamsQuickFix ResourceMethodMultipleEntityParamsQuickFix = new ResourceMethodMultipleEntityParamsQuickFix();
- NoResourcePublicConstructorQuickFix NoResourcePublicConstructorQuickFix = new NoResourcePublicConstructorQuickFix();
- ManagedBeanQuickFix ManagedBeanQuickFix = new ManagedBeanQuickFix();
- PersistenceEntityQuickFix PersistenceEntityQuickFix = new PersistenceEntityQuickFix();
- ConflictProducesInjectQuickFix ConflictProducesInjectQuickFix = new ConflictProducesInjectQuickFix();
- BeanValidationQuickFix BeanValidationQuickFix = new BeanValidationQuickFix();
- ManagedBeanConstructorQuickFix ManagedBeanConstructorQuickFix = new ManagedBeanConstructorQuickFix();
- ManagedBeanNoArgConstructorQuickFix ManagedBeanNoArgConstructorQuickFix = new ManagedBeanNoArgConstructorQuickFix();
- JsonbAnnotationQuickFix JsonbAnnotationQuickFix = new JsonbAnnotationQuickFix();
- JsonbTransientAnnotationQuickFix JsonbTransientAnnotationQuickFix = new JsonbTransientAnnotationQuickFix();
- ScopeDeclarationQuickFix ScopeDeclarationQuickFix = new ScopeDeclarationQuickFix();
- RemovePreDestroyAnnotationQuickFix RemovePreDestroyAnnotationQuickFix=new RemovePreDestroyAnnotationQuickFix();
- RemovePostConstructAnnotationQuickFix RemovePostConstructAnnotationQuickFix=new RemovePostConstructAnnotationQuickFix();
- PostConstructReturnTypeQuickFix PostConstructReturnTypeQuickFix = new PostConstructReturnTypeQuickFix();
- RemoveFinalModifierQuickFix RemoveFinalModifierQuickFix = new RemoveFinalModifierQuickFix();
- RemoveStaticModifierQuickFix RemoveStaticModifierQuickFix = new RemoveStaticModifierQuickFix();
- RemoveMethodParametersQuickFix RemoveMethodParametersQuickFix =new RemoveMethodParametersQuickFix();
- AddResourceMissingNameQuickFix AddResourceMissingNameQuickFix=new AddResourceMissingNameQuickFix();
- AddResourceMissingTypeQuickFix AddResourceMissingTypeQuickFix=new AddResourceMissingTypeQuickFix();
- RemoveAbstractModifierQuickFix RemoveAbstractModifierQuickFix = new RemoveAbstractModifierQuickFix();
- RemoveInjectAnnotationQuickFix RemoveInjectAnnotationQuickFix = new RemoveInjectAnnotationQuickFix();
- RemoveProduceAnnotationQuickFix RemoveProduceAnnotationQuickFix = new RemoveProduceAnnotationQuickFix();
- RemoveInvalidInjectParamAnnotationQuickFix RemoveInvalidInjectParamAnnotationQuickFix = new RemoveInvalidInjectParamAnnotationQuickFix();
- AddPathParamQuickFix AddPathParamQuickFix = new AddPathParamQuickFix();
-
- for (Diagnostic diagnostic : params.getContext().getDiagnostics()) {
- try {
- if (diagnostic.getCode().getLeft().equals(ServletConstants.DIAGNOSTIC_CODE)) {
- codeActions.addAll(HttpServletQuickFix.getCodeActions(context, diagnostic, monitor));
- }
- if (diagnostic.getCode().getLeft().equals(ServletConstants.DIAGNOSTIC_CODE_FILTER)) {
- codeActions.addAll(FilterImplementationQuickFix.getCodeActions(context, diagnostic, monitor));
- }
- if (diagnostic.getCode().getLeft().equals(ServletConstants.DIAGNOSTIC_CODE_LISTENER)) {
- codeActions.addAll(ListenerImplementationQuickFix.getCodeActions(context, diagnostic, monitor));
- }
- if (diagnostic.getCode().getLeft().equals(AnnotationConstants.DIAGNOSTIC_CODE_MISSING_RESOURCE_NAME_ATTRIBUTE)) {
- codeActions.addAll(AddResourceMissingNameQuickFix.getCodeActions(context, diagnostic, monitor));
- }
- if (diagnostic.getCode().getLeft().equals(AnnotationConstants.DIAGNOSTIC_CODE_MISSING_RESOURCE_TYPE_ATTRIBUTE)) {
- codeActions.addAll(AddResourceMissingTypeQuickFix.getCodeActions(context, diagnostic, monitor));
- }
- if (diagnostic.getCode().getLeft().equals(AnnotationConstants.DIAGNOSTIC_CODE_POSTCONSTRUCT_RETURN_TYPE)) {
- codeActions.addAll(PostConstructReturnTypeQuickFix.getCodeActions(context, diagnostic, monitor));
- }
- if (diagnostic.getCode().getLeft().equals(ServletConstants.DIAGNOSTIC_CODE_MISSING_ATTRIBUTE)
- || diagnostic.getCode().getLeft()
- .equals(ServletConstants.DIAGNOSTIC_CODE_DUPLICATE_ATTRIBUTES)) {
- codeActions
- .addAll(CompleteServletAnnotationQuickFix.getCodeActions(context, diagnostic, monitor));
- }
- if (diagnostic.getCode().getLeft().equals(ServletConstants.DIAGNOSTIC_CODE_FILTER_MISSING_ATTRIBUTE)
- || diagnostic.getCode().getLeft()
- .equals(ServletConstants.DIAGNOSTIC_CODE_FILTER_DUPLICATE_ATTRIBUTES)) {
- codeActions
- .addAll(CompleteFilterAnnotationQuickFix.getCodeActions(context, diagnostic, monitor));
- }
- if (diagnostic.getCode().getLeft().equals(Jax_RSConstants.DIAGNOSTIC_CODE_NON_PUBLIC)) {
- codeActions
- .addAll(NonPublicResourceMethodQuickFix.getCodeActions(context, diagnostic, monitor));
- }
- if (diagnostic.getCode().getLeft().equals(Jax_RSConstants.DIAGNOSTIC_CODE_MULTIPLE_ENTITY_PARAMS)) {
- codeActions.addAll(ResourceMethodMultipleEntityParamsQuickFix.getCodeActions(context,
- diagnostic, monitor));
- }
- if (diagnostic.getCode().getLeft().equals(Jax_RSConstants.DIAGNOSTIC_CODE_NO_PUBLIC_CONSTRUCTORS)) {
- codeActions.addAll(NoResourcePublicConstructorQuickFix.getCodeActions(context,
- diagnostic, monitor));
- }
- if (diagnostic.getCode().getLeft()
- .equals(PersistenceConstants.DIAGNOSTIC_CODE_MISSING_ATTRIBUTES)) {
- codeActions.addAll(PersistenceAnnotationQuickFix.getCodeActions(context, diagnostic, monitor));
- }
- if (diagnostic.getCode().getLeft()
- .equals(PersistenceConstants.DIAGNOSTIC_CODE_INVALID_ANNOTATION)) {
- codeActions.addAll(DeleteConflictMapKeyQuickFix.getCodeActions(context, diagnostic, monitor));
- }
- if (diagnostic.getCode().getLeft().equals(PersistenceConstants.DIAGNOSTIC_CODE_MISSING_EMPTY_CONSTRUCTOR)) {
- codeActions.addAll(PersistenceEntityQuickFix.getCodeActions(context, diagnostic, monitor));
- }
- if (diagnostic.getCode().getLeft().equals(PersistenceConstants.DIAGNOSTIC_CODE_FINAL_METHODS)
- || diagnostic.getCode().getLeft().equals(PersistenceConstants.DIAGNOSTIC_CODE_FINAL_VARIABLES)
- || diagnostic.getCode().getLeft().equals(PersistenceConstants.DIAGNOSTIC_CODE_FINAL_CLASS)) {
- codeActions.addAll(RemoveFinalModifierQuickFix.getCodeActions(context, diagnostic, monitor));
- }
- if (diagnostic.getCode().getLeft().equals(ManagedBeanConstants.DIAGNOSTIC_CODE)) {
- codeActions.addAll(ManagedBeanQuickFix.getCodeActions(context, diagnostic, monitor));
- }
- if (diagnostic.getCode().getLeft().equals(ManagedBeanConstants.DIAGNOSTIC_CODE_PRODUCES_INJECT)) {
- codeActions.addAll(ConflictProducesInjectQuickFix.getCodeActions(context, diagnostic, monitor));
- }
- if (diagnostic.getCode().getLeft().equals(ManagedBeanConstants.DIAGNOSTIC_CODE_INVALID_INJECT_PARAM)) {
- codeActions.addAll(RemoveInjectAnnotationQuickFix.getCodeActions(context, diagnostic, monitor));
- codeActions.addAll(RemoveInvalidInjectParamAnnotationQuickFix.getCodeActions(context, diagnostic, monitor));
- }
- if (diagnostic.getCode().getLeft().equals(ManagedBeanConstants.DIAGNOSTIC_CODE_INVALID_PRODUCES_PARAM)) {
- codeActions.addAll(RemoveProduceAnnotationQuickFix.getCodeActions(context, diagnostic, monitor));
- codeActions.addAll(RemoveInvalidInjectParamAnnotationQuickFix.getCodeActions(context, diagnostic, monitor));
- }
- if (diagnostic.getCode().getLeft().equals(BeanValidationConstants.DIAGNOSTIC_CODE_STATIC)
- || diagnostic.getCode().getLeft()
- .equals(BeanValidationConstants.DIAGNOSTIC_CODE_INVALID_TYPE)) {
- codeActions.addAll(BeanValidationQuickFix.getCodeActions(context, diagnostic, monitor));
- }
- if (diagnostic.getCode().getLeft().equals(ManagedBeanConstants.CONSTRUCTOR_DIAGNOSTIC_CODE)) {
- codeActions.addAll(ManagedBeanConstructorQuickFix.getCodeActions(context, diagnostic, monitor));
- codeActions.addAll(ManagedBeanNoArgConstructorQuickFix.getCodeActions(context, diagnostic, monitor));
- }
- if (diagnostic.getCode().getLeft().equals(JsonbConstants.DIAGNOSTIC_CODE_ANNOTATION)) {
- codeActions.addAll(JsonbAnnotationQuickFix.getCodeActions(context, diagnostic, monitor));
- }
- if (diagnostic.getCode().getLeft().equals(JsonbConstants.DIAGNOSTIC_CODE_ANNOTATION_TRANSIENT_FIELD)) {
- codeActions.addAll(JsonbTransientAnnotationQuickFix.getCodeActions(context, diagnostic, monitor));
- }
- if(diagnostic.getCode().getLeft().equals(ManagedBeanConstants.DIAGNOSTIC_CODE_SCOPEDECL)) {
- codeActions.addAll(ScopeDeclarationQuickFix.getCodeActions(context, diagnostic, monitor));
- }
- if(diagnostic.getCode().getLeft().equals(DependencyInjectionConstants.DIAGNOSTIC_CODE_INJECT_FINAL)) {
- codeActions.addAll(RemoveInjectAnnotationQuickFix.getCodeActions(context, diagnostic, monitor));
- codeActions.addAll(RemoveFinalModifierQuickFix.getCodeActions(context, diagnostic, monitor));
- }
- if(diagnostic.getCode().getLeft().equals(DependencyInjectionConstants.DIAGNOSTIC_CODE_INJECT_CONSTRUCTOR) ||
- diagnostic.getCode().getLeft().equals(DependencyInjectionConstants.DIAGNOSTIC_CODE_INJECT_GENERIC)) {
- codeActions.addAll(RemoveInjectAnnotationQuickFix.getCodeActions(context, diagnostic, monitor));
- }
- if(diagnostic.getCode().getLeft().equals(DependencyInjectionConstants.DIAGNOSTIC_CODE_INJECT_ABSTRACT)) {
- codeActions.addAll(RemoveInjectAnnotationQuickFix.getCodeActions(context, diagnostic, monitor));
- codeActions.addAll(RemoveAbstractModifierQuickFix.getCodeActions(context, diagnostic, monitor));
- }
- if(diagnostic.getCode().getLeft().equals(DependencyInjectionConstants.DIAGNOSTIC_CODE_INJECT_STATIC)) {
- codeActions.addAll(RemoveInjectAnnotationQuickFix.getCodeActions(context, diagnostic, monitor));
- codeActions.addAll(RemoveStaticModifierQuickFix.getCodeActions(context, diagnostic, monitor));
- }
-
- if(diagnostic.getCode().getLeft().equals(AnnotationConstants.DIAGNOSTIC_CODE_POSTCONSTRUCT_PARAMS)) {
- codeActions.addAll(RemovePostConstructAnnotationQuickFix.getCodeActions(context, diagnostic, monitor));
- codeActions.addAll(RemoveMethodParametersQuickFix.getCodeActions(context, diagnostic, monitor));
- }
- if(diagnostic.getCode().getLeft().equals(AnnotationConstants.DIAGNOSTIC_CODE_PREDESTROY_STATIC)) {
- codeActions.addAll(RemovePreDestroyAnnotationQuickFix.getCodeActions(context, diagnostic, monitor));
- codeActions.addAll(RemoveStaticModifierQuickFix.getCodeActions(context, diagnostic, monitor));
- }
- if(diagnostic.getCode().getLeft().equals(AnnotationConstants.DIAGNOSTIC_CODE_PREDESTROY_PARAMS)) {
- codeActions.addAll(RemovePreDestroyAnnotationQuickFix.getCodeActions(context, diagnostic, monitor));
- codeActions.addAll(RemoveMethodParametersQuickFix.getCodeActions(context,diagnostic,monitor));
- }
- if(diagnostic.getCode().getLeft().equals(WebSocketConstants.DIAGNOSTIC_CODE_PATH_PARAMS_ANNOT)) {
- codeActions.addAll(AddPathParamQuickFix.getCodeActions(context, diagnostic, monitor));
- }
-
- } catch (CoreException e) {
- e.printStackTrace();
- }
- }
- return codeActions;
-
- } catch (JavaModelException e) {
- JakartaCorePlugin.logException("Failed to retrieve Jakarta code action", e);
- }
- return null;
- }
-
- private static CompilationUnit getASTRoot(ICompilationUnit unit, IProgressMonitor monitor) {
- return CoreASTProvider.getInstance().getAST(unit, CoreASTProvider.WAIT_YES, monitor);
- }
-
- public int toOffset(IBuffer buffer, int line, int column) {
- return JsonRpcHelpers.toOffset(buffer, line, column);
- }
-}
diff --git a/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/codeAction/proposal/ChangeCorrectionProposal.java b/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/codeAction/proposal/ChangeCorrectionProposal.java
deleted file mode 100644
index d88ecc49..00000000
--- a/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/codeAction/proposal/ChangeCorrectionProposal.java
+++ /dev/null
@@ -1,262 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2014 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License 2.0
- * which accompanies this distribution, and is available at
- * https://www.eclipse.org/legal/epl-2.0/
- *
- * SPDX-License-Identifier: EPL-2.0
- *
- * Copied from /org.eclipse.jdt.ui/src/org/eclipse/jdt/ui/text/java/correction/ChangeCorrectionProposal.java
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.lsp4jakarta.jdt.codeAction.proposal;
-
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.NullProgressMonitor;
-import org.eclipse.core.runtime.Status;
-import org.eclipse.jdt.core.ICompilationUnit;
-import org.eclipse.jdt.core.dom.CompilationUnit;
-import org.eclipse.jdt.core.dom.rewrite.ASTRewrite;
-import org.eclipse.jdt.core.dom.rewrite.ImportRewrite;
-import org.eclipse.jdt.core.manipulation.CUCorrectionProposalCore;
-import org.eclipse.jdt.core.manipulation.ChangeCorrectionProposalCore;
-import org.eclipse.jdt.core.manipulation.CodeStyleConfiguration;
-import org.eclipse.jface.text.IDocument;
-import org.eclipse.ltk.core.refactoring.Change;
-import org.eclipse.ltk.core.refactoring.IUndoManager;
-import org.eclipse.ltk.core.refactoring.RefactoringCore;
-import org.eclipse.ltk.core.refactoring.RefactoringStatus;
-import org.eclipse.ltk.core.refactoring.TextChange;
-import org.eclipse.text.edits.TextEdit;
-import org.eclipse.lsp4jakarta.jdt.core.JakartaCorePlugin;
-
-/**
- * Adapted from
- * /org.eclipse.jdt.ui/src/org/eclipse/jdt/ui/text/java/correction/ChangeCorrectionProposal.java
- * and
- * https://github.com/eclipse/lsp4mp/blob/55ac697e9382db279480d992a993f17bc7a92c60/microprofile.jdt/org.eclipse.lsp4mp.jdt.core/src/main/java/org/eclipse/lsp4mp/jdt/core/java/corrections/proposal/ChangeCorrectionProposal.java
- */
-public class ChangeCorrectionProposal extends ChangeCorrectionProposalCore {
-
- // LSP: Code Action Kind
- private String fKind;
- private ASTRewrite fRewrite;
- private ImportRewrite fImportRewrite;
- private CUCorrectionProposalCore fProposalCore;
-
- /**
- * Constructs a change correction proposal.
- *
- * @param name the name that is displayed in the proposal selection dialog
- * @param change the change that is executed when the proposal is applied or
- * null
if the change will be created by implementors
- * of {@link #createChange()}
- */
- public ChangeCorrectionProposal(String name, String kind, ICompilationUnit cu, ASTRewrite rewrite, int relevance) {
- super(name, null, 0);
- fKind = kind;
- if (cu == null) {
- throw new IllegalArgumentException("Compilation unit must not be null"); //$NON-NLS-1$
- }
-
- fRewrite = rewrite;
- fProposalCore = new CUCorrectionProposalCore(name, cu, null, relevance);
- }
-
- /**
- * Performs the change associated with this proposal.
- *
- * Subclasses may extend, but must call the super implementation.
- *
- * @throws CoreException when the invocation of the change failed
- */
- @Override
- protected void performChange() throws CoreException {
- Change change = null;
- try {
- change = getChange();
- if (change != null) {
-
- change.initializeValidationData(new NullProgressMonitor());
- RefactoringStatus valid = change.isValid(new NullProgressMonitor());
- if (valid.hasFatalError()) {
- IStatus status = new Status(IStatus.ERROR, JakartaCorePlugin.PLUGIN_ID, IStatus.ERROR,
- valid.getMessageMatchingSeverity(RefactoringStatus.FATAL), null);
- throw new CoreException(status);
- } else {
- IUndoManager manager = RefactoringCore.getUndoManager();
- Change undoChange;
- boolean successful = false;
- try {
- manager.aboutToPerformChange(change);
- undoChange = change.perform(new NullProgressMonitor());
- successful = true;
- } finally {
- manager.changePerformed(change, successful);
- }
- if (undoChange != null) {
- undoChange.initializeValidationData(new NullProgressMonitor());
- manager.addUndo(getName(), undoChange);
- }
- }
- }
- } finally {
-
- if (change != null) {
- change.dispose();
- }
- }
- }
-
- @Override
- public Object getAdditionalProposalInfo(IProgressMonitor monitor) {
- return fProposalCore.getAdditionalProposalInfo(monitor);
- }
-
- @Override
- public void apply() throws CoreException {
- performChange();
- }
-
- @Override
- protected final Change createChange() throws CoreException {
- return createTextChange(); // make sure that only text changes are allowed here
- }
-
- /**
- * Returns the kind of the proposal.
- *
- * @return the kind of the proposal
- */
- public String getKind() {
- return fKind;
- }
-
- /**
- * @param codeActionKind the Code Action Kind to set
- */
- public void setKind(String codeActionKind) {
- this.fKind = codeActionKind;
- }
-
- /**
- * The compilation unit on which the change works.
- *
- * @return the compilation unit on which the change works
- */
- public final ICompilationUnit getCompilationUnit() {
- return fProposalCore.getCompilationUnit();
- }
-
- /**
- * Returns the text change that is invoked when the change is applied.
- *
- * @return the text change that is invoked when the change is applied
- * @throws CoreException if accessing the change failed
- */
- public final TextChange getTextChange() throws CoreException {
- return (TextChange) getChange();
- }
-
- /**
- * Creates the text change for this proposal. This method is only called once
- * and only when no text change has been passed in
- * {@link #CUCorrectionProposal(String, ICompilationUnit, TextChange, int)}.
- *
- * @return the created text change
- * @throws CoreException if the creation of the text change failed
- */
- protected TextChange createTextChange() throws CoreException {
- TextChange change = fProposalCore.getNewChange();
- // initialize text change
- IDocument document = change.getCurrentDocument(new NullProgressMonitor());
- addEdits(document, change.getEdit());
- return change;
- }
-
- /**
- * Creates a preview of the content of the compilation unit after applying the
- * change.
- *
- * @return the preview of the changed compilation unit
- * @throws CoreException if the creation of the change failed
- *
- * @noreference This method is not intended to be referenced by clients.
- */
- public String getPreviewContent() throws CoreException {
- return getTextChange().getPreviewContent(new NullProgressMonitor());
- }
-
- /**
- * Returns the import rewrite used for this compilation unit.
- *
- * @return the import rewrite or null
if no import rewrite has been
- * set
- * @nooverride This method is not intended to be re-implemented or extended by
- * clients.
- */
- public ImportRewrite getImportRewrite() {
- return fImportRewrite;
- }
-
- /**
- * Sets the import rewrite used for this compilation unit.
- *
- * @param rewrite the import rewrite
- * @nooverride This method is not intended to be re-implemented or extended by
- * clients.
- */
- public void setImportRewrite(ImportRewrite rewrite) {
- fImportRewrite = rewrite;
- }
-
- /**
- * Creates and sets the import rewrite used for this compilation unit.
- *
- * @param astRoot the AST for the current CU
- * @return the created import rewrite
- * @nooverride This method is not intended to be re-implemented or extended by
- * clients.
- */
- public ImportRewrite createImportRewrite(CompilationUnit astRoot) {
- fImportRewrite = CodeStyleConfiguration.createImportRewrite(astRoot, true);
- return fImportRewrite;
- }
-
- protected void addEdits(IDocument document, TextEdit editRoot) throws CoreException {
- ASTRewrite rewrite = getRewrite();
- if (rewrite != null) {
- try {
- TextEdit edit = rewrite.rewriteAST();
- editRoot.addChild(edit);
- } catch (IllegalArgumentException e) {
-// JakartaCorePlugin.log(new Status(IStatus.ERROR, JakartaCorePlugin.getDefault().getBundle().getSymbolicName(),
-// "Invalid AST Rewriter", e));
- }
- }
- if (fImportRewrite != null) {
- editRoot.addChild(fImportRewrite.rewriteImports(new NullProgressMonitor()));
- }
- }
-
- /**
- * Returns the rewrite that has been passed in the constructor. Implementors can
- * override this method to create the rewrite lazily. This method will only be
- * called once.
- *
- * @return the rewrite to be used
- * @throws CoreException when the rewrite could not be created
- */
- protected ASTRewrite getRewrite() throws CoreException {
- if (fRewrite == null) {
-// JakartaCorePlugin.log(new Status(IStatus.ERROR, JakartaCorePlugin.getDefault().getBundle().getSymbolicName(),
-// "Invalid AST Rewrite"));
- }
- return fRewrite;
- }
-}
\ No newline at end of file
diff --git a/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/codeAction/proposal/RemoveMultipleAnnotations.java b/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/codeAction/proposal/RemoveMultipleAnnotations.java
deleted file mode 100644
index 3956cd87..00000000
--- a/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/codeAction/proposal/RemoveMultipleAnnotations.java
+++ /dev/null
@@ -1,81 +0,0 @@
-/*******************************************************************************
-* Copyright (c) 2022 IBM Corporation 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.
-*
-* SPDX-License-Identifier: EPL-2.0
-*
-* Contributors:
-* IBM Corporation, Adit Rada - initial API and implementation
-*******************************************************************************/
-package org.eclipse.lsp4jakarta.jdt.codeAction.proposal;
-
-import java.util.ArrayList;
-import java.util.List;
-import java.util.stream.Collectors;
-import java.util.stream.IntStream;
-
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.jdt.core.dom.ASTNode;
-import org.eclipse.jdt.core.dom.IBinding;
-import org.eclipse.lsp4j.CodeAction;
-import org.eclipse.lsp4j.Diagnostic;
-import org.eclipse.lsp4jakarta.jdt.codeAction.JavaCodeActionContext;
-import org.eclipse.lsp4jakarta.jdt.codeAction.proposal.quickfix.RemoveAnnotationConflictQuickFix;
-
-import com.google.gson.JsonArray;
-
-/**
- * This class is used to provide options to remove multiple annotations
- * at the same time. For example, "Remove @A, @B", "Remove @C, @D, @E".
- *
- * @author Adit Rada
- *
- */
-public abstract class RemoveMultipleAnnotations extends RemoveAnnotationConflictQuickFix {
-
- public RemoveMultipleAnnotations() {
- // annotation list to be derived from the diagnostic passed to
- // `getCodeActions()`
- super();
- }
-
- @Override
- public List extends CodeAction> getCodeActions(JavaCodeActionContext context, Diagnostic diagnostic,
- IProgressMonitor monitor) throws CoreException {
- List codeActions = new ArrayList<>();
- ASTNode node = context.getCoveredNode();
- IBinding parentType = getBinding(node);
-
- JsonArray diagnosticData = (JsonArray) diagnostic.getData();
-
- List annotations = IntStream.range(0, diagnosticData.size())
- .mapToObj(idx -> diagnosticData.get(idx).getAsString()).collect(Collectors.toList());
-
- if (parentType != null) {
-
- List> annotationsListsToRemove = getMultipleRemoveAnnotations(annotations);
- for (List annotationList : annotationsListsToRemove) {
- String[] annotationsToRemove = annotationList.toArray(new String[annotationList.size()]);
- removeAnnotation(diagnostic, context, parentType, codeActions, annotationsToRemove);
- }
- }
- return codeActions;
- }
-
- /**
- * Each List in the returned List of Lists should be a set of annotations that
- * will be removed at one go. For example, to provide the user with the option to remove
- * "@A, @B" and "@C". The return should be [[A, B], [C]]
- *
- * @param All the annotations present on the member.
- * @return A List of Lists, with each list containing the annotations that must be
- * removed at the same time.
- * @author Adit Rada
- *
- */
- protected abstract List> getMultipleRemoveAnnotations(List annotations);
-}
diff --git a/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/codeAction/proposal/ReplaceAnnotationProposal.java b/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/codeAction/proposal/ReplaceAnnotationProposal.java
deleted file mode 100644
index 6631cfda..00000000
--- a/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/codeAction/proposal/ReplaceAnnotationProposal.java
+++ /dev/null
@@ -1,112 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2016 IBM Corporation 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
- *
- * Copied from /org.eclipse.jdt.ui/src/org/eclipse/jdt/internal/ui/text/correction/proposals/NewAnnotationMemberProposal.java
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.lsp4jakarta.jdt.codeAction.proposal;
-
-import java.util.Arrays;
-import java.util.List;
-
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.jdt.core.ICompilationUnit;
-import org.eclipse.jdt.core.dom.AST;
-import org.eclipse.jdt.core.dom.ASTNode;
-import org.eclipse.jdt.core.dom.Annotation;
-import org.eclipse.jdt.core.dom.CompilationUnit;
-import org.eclipse.jdt.core.dom.FieldDeclaration;
-import org.eclipse.jdt.core.dom.IAnnotationBinding;
-import org.eclipse.jdt.core.dom.IBinding;
-import org.eclipse.jdt.core.dom.TypeDeclaration;
-import org.eclipse.jdt.core.dom.VariableDeclarationFragment;
-import org.eclipse.jdt.core.dom.rewrite.ASTRewrite;
-import org.eclipse.jdt.core.dom.rewrite.ImportRewrite;
-import org.eclipse.jdt.core.dom.rewrite.ImportRewrite.ImportRewriteContext;
-import org.eclipse.jdt.internal.core.manipulation.dom.ASTResolving;
-import org.eclipse.jdt.internal.corext.codemanipulation.ContextSensitiveImportRewriteContext;
-
-/**
- * Similar functionality as NewAnnotationProposal. The main difference is that
- * first removes specified annotations before adding a new annotation.
- *
- * Note: This class only accepts one new annotation to add.
- *
- * @author Kathryn Kodama
- */
-public class ReplaceAnnotationProposal extends NewAnnotationProposal {
-
- private final String[] removeAnnotations;
-
- public ReplaceAnnotationProposal(String label, ICompilationUnit targetCU, CompilationUnit invocationNode,
- IBinding binding, int relevance, String annotation, String... removeAnnotations) {
- super(label, targetCU, invocationNode, binding, relevance, annotation);
- this.removeAnnotations = removeAnnotations;
- }
-
- @Override
- protected ASTRewrite getRewrite() throws CoreException {
- CompilationUnit fInvocationNode = getInvocationNode();
- IBinding fBinding = getBinding();
- String[] annotations = getAnnotations();
-
- ASTNode declNode = null;
- ASTNode boundNode = fInvocationNode.findDeclaringNode(fBinding);
- CompilationUnit newRoot = fInvocationNode;
- if (boundNode != null) {
- declNode = boundNode; // is same CU
- } else {
- newRoot = ASTResolving.createQuickFixAST(getCompilationUnit(), null);
- declNode = newRoot.findDeclaringNode(fBinding.getKey());
- }
- ImportRewrite imports = createImportRewrite(newRoot);
-
- boolean isField = declNode instanceof VariableDeclarationFragment;
- if (isField) {
- declNode = declNode.getParent();
- }
- if (declNode instanceof TypeDeclaration || isField) {
- AST ast = declNode.getAST();
- ASTRewrite rewrite = ASTRewrite.create(ast);
-
- ImportRewriteContext importRewriteContext = new ContextSensitiveImportRewriteContext(declNode, imports);
-
- // remove annotations in the removeAnnotations list
- @SuppressWarnings("unchecked")
- List extends ASTNode> children = (List extends ASTNode>) (declNode.getParent() instanceof CompilationUnit ? declNode : declNode.getParent())
- .getStructuralProperty(TypeDeclaration.MODIFIERS2_PROPERTY);
- for (ASTNode child : children) {
- if (child instanceof Annotation) {
- Annotation annotation = (Annotation) child;
- IAnnotationBinding annotationBinding = annotation.resolveAnnotationBinding();
- boolean containsAnnotation = Arrays.stream(removeAnnotations)
- .anyMatch(annotationBinding.getName()::contains);
- if (containsAnnotation) {
- rewrite.remove(child, null);
- }
- }
- }
- for (String annotation : annotations) {
- Annotation marker = ast.newMarkerAnnotation();
- marker.setTypeName(ast.newName(imports.addImport(annotation, importRewriteContext))); // $NON-NLS-1$
- rewrite.getListRewrite(declNode,
- isField ? FieldDeclaration.MODIFIERS2_PROPERTY : TypeDeclaration.MODIFIERS2_PROPERTY)
- .insertFirst(marker, null);
- }
-
- return rewrite;
- }
- return null;
- }
-
-
-
-}
\ No newline at end of file
diff --git a/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/codeAction/proposal/quickfix/InsertAnnotationAttributesQuickFix.java b/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/codeAction/proposal/quickfix/InsertAnnotationAttributesQuickFix.java
deleted file mode 100644
index 5765c26b..00000000
--- a/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/codeAction/proposal/quickfix/InsertAnnotationAttributesQuickFix.java
+++ /dev/null
@@ -1,36 +0,0 @@
-/*******************************************************************************
-* Copyright (c) 2022, 2023 IBM Corporation 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.
-*
-* SPDX-License-Identifier: EPL-2.0
-*
-* Contributors:
-* Lidia Ataupillco Ramos - initial API and implementation
-*******************************************************************************/
-package org.eclipse.lsp4jakarta.jdt.codeAction.proposal.quickfix;
-
-import org.eclipse.lsp4jakarta.jdt.core.Messages;
-
-/**
- * Quickfix for adding attributes to existing annotations
- *
- * @author Lidia Ataupillco Ramos
- *
- */
-public class InsertAnnotationAttributesQuickFix extends InsertAnnotationQuickFix {
- public InsertAnnotationAttributesQuickFix(String annotation, String... attributes) {
- this(annotation, false, attributes);
- }
-
- public InsertAnnotationAttributesQuickFix(String annotation, boolean generateOnlyOneCodeAction, String... attributes) {
- super(annotation, generateOnlyOneCodeAction, attributes);
- }
-
- @Override
- protected String getLabel(String annotation, String... attributes) {
- return Messages.getMessage("AddAtoB", attributes[0], annotation);
- }
-}
diff --git a/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/codeAction/proposal/quickfix/InsertAnnotationMissingQuickFix.java b/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/codeAction/proposal/quickfix/InsertAnnotationMissingQuickFix.java
deleted file mode 100644
index 6f752a41..00000000
--- a/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/codeAction/proposal/quickfix/InsertAnnotationMissingQuickFix.java
+++ /dev/null
@@ -1,140 +0,0 @@
-/*******************************************************************************
-* Copyright (c) 2020, 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 org.eclipse.lsp4jakarta.jdt.codeAction.proposal.quickfix;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.jdt.core.dom.ASTNode;
-import org.eclipse.jdt.core.dom.IBinding;
-import org.eclipse.jdt.core.dom.MethodDeclaration;
-import org.eclipse.jdt.core.dom.VariableDeclarationFragment;
-import org.eclipse.jdt.internal.corext.dom.Bindings;
-import org.eclipse.lsp4j.CodeAction;
-import org.eclipse.lsp4j.Diagnostic;
-import org.eclipse.lsp4jakarta.jdt.codeAction.IJavaCodeActionParticipant;
-import org.eclipse.lsp4jakarta.jdt.codeAction.JavaCodeActionContext;
-import org.eclipse.lsp4jakarta.jdt.codeAction.proposal.ChangeCorrectionProposal;
-import org.eclipse.lsp4jakarta.jdt.codeAction.proposal.NewAnnotationProposal;
-import org.eclipse.lsp4jakarta.jdt.core.Messages;
-
-/**
- * QuickFix for inserting annotations.
- * Reused from https://github.com/eclipse/lsp4mp/blob/6f2d700a88a3262e39cc2ba04beedb429e162246/microprofile.jdt/org.eclipse.lsp4mp.jdt.core/src/main/java/org/eclipse/lsp4mp/jdt/core/java/codeaction/InsertAnnotationMissingQuickFix.java
- *
- * @author Angelo ZERR
- *
- */
-public class InsertAnnotationMissingQuickFix implements IJavaCodeActionParticipant {
-
- private final String[] annotations;
-
- private final boolean generateOnlyOneCodeAction;
-
- /**
- * Constructor for insert annotation quick fix.
- *
- *
- * The participant will generate a CodeAction per annotation.
- *
- *
- * @param annotations list of annotation to insert.
- */
- public InsertAnnotationMissingQuickFix(String... annotations) {
- this(false, annotations);
- }
-
- /**
- * Constructor for insert annotation quick fix.
- *
- * @param generateOnlyOneCodeAction true if the participant must generate a
- * CodeAction which insert the list of
- * annotation and false otherwise.
- * @param annotations list of annotation to insert.
- */
- public InsertAnnotationMissingQuickFix(boolean generateOnlyOneCodeAction, String... annotations) {
- this.generateOnlyOneCodeAction = generateOnlyOneCodeAction;
- this.annotations = annotations;
- }
-
- @Override
- public List extends CodeAction> getCodeActions(JavaCodeActionContext context, Diagnostic diagnostic,
- IProgressMonitor monitor) throws CoreException {
- List codeActions = new ArrayList<>();
- ASTNode node = context.getCoveredNode();
- IBinding parentType = getBinding(node);
- if (parentType != null) {
- insertAnnotations(diagnostic, context, parentType, codeActions);
- }
- return codeActions;
- }
-
- protected static IBinding getBinding(ASTNode node) {
- if (node.getParent() instanceof VariableDeclarationFragment) {
- VariableDeclarationFragment fragment = (VariableDeclarationFragment) node.getParent();
- return ((VariableDeclarationFragment) node.getParent()).resolveBinding();
- }
- if (node.getParent() instanceof MethodDeclaration) {
- MethodDeclaration methodDecl = (MethodDeclaration) node.getParent();
- return methodDecl.resolveBinding();
- }
- return Bindings.getBindingOfParentType(node);
- }
-
- protected String[] getAnnotations() {
- return this.annotations;
- }
-
- protected void insertAnnotations(Diagnostic diagnostic, JavaCodeActionContext context, IBinding parentType,
- List codeActions) throws CoreException {
- if (generateOnlyOneCodeAction) {
- insertAnnotation(diagnostic, context, parentType, codeActions, annotations);
- } else {
- for (String annotation : annotations) {
- insertAnnotation(diagnostic, context, parentType, codeActions, annotation);
- }
- }
- }
-
- protected static void insertAnnotation(Diagnostic diagnostic, JavaCodeActionContext context, IBinding parentType,
- List codeActions, String... annotations) throws CoreException {
- // Insert the annotation and the proper import by using JDT Core Manipulation
- // API
- String name = getLabel(annotations);
- ChangeCorrectionProposal proposal = new NewAnnotationProposal(name, context.getCompilationUnit(),
- context.getASTRoot(), parentType, 0, annotations);
- // Convert the proposal to LSP4J CodeAction
- CodeAction codeAction = context.convertToCodeAction(proposal, diagnostic);
- if (codeAction != null) {
- codeActions.add(codeAction);
- }
- }
-
- private static String getLabel(String[] annotations) {
- StringBuilder list = new StringBuilder();
- for (int i = 0; i < annotations.length; i++) {
- String annotation = annotations[i];
- String annotationName = annotation.substring(annotation.lastIndexOf('.') + 1, annotation.length());
- if (i > 0) {
- list.append(", "); // assume comma list is ok: @A, @B, @C
- }
- list.append("@"); // Java syntax
- list.append(annotationName);
- }
- return Messages.getMessage("InsertItem", list.toString());
- }
-
-}
\ No newline at end of file
diff --git a/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/codeAction/proposal/quickfix/InsertAnnotationQuickFix.java b/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/codeAction/proposal/quickfix/InsertAnnotationQuickFix.java
deleted file mode 100644
index 37ecc01b..00000000
--- a/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/codeAction/proposal/quickfix/InsertAnnotationQuickFix.java
+++ /dev/null
@@ -1,129 +0,0 @@
-/*******************************************************************************
-* Copyright (c) 2021, 2023 IBM Corporation 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.
-*
-* SPDX-License-Identifier: EPL-2.0
-*
-* Contributors:
-* IBM Corporation - initial API and implementation
-* Lidia Ataupillco Ramos
-*******************************************************************************/
-
-package org.eclipse.lsp4jakarta.jdt.codeAction.proposal.quickfix;
-
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
-
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.jdt.core.dom.ASTNode;
-import org.eclipse.jdt.core.dom.IBinding;
-import org.eclipse.jdt.core.dom.VariableDeclarationFragment;
-import org.eclipse.jdt.core.dom.SingleVariableDeclaration;
-import org.eclipse.jdt.internal.corext.dom.Bindings;
-import org.eclipse.lsp4j.CodeAction;
-import org.eclipse.lsp4j.Diagnostic;
-import org.eclipse.lsp4jakarta.jdt.codeAction.IJavaCodeActionParticipant;
-import org.eclipse.lsp4jakarta.jdt.codeAction.JavaCodeActionContext;
-import org.eclipse.lsp4jakarta.jdt.codeAction.proposal.ChangeCorrectionProposal;
-import org.eclipse.lsp4jakarta.jdt.codeAction.proposal.ModifyAnnotationProposal;
-import org.eclipse.lsp4jakarta.jdt.core.Messages;
-
-/**
- * Quickfix for adding new annotations with or without attributes
- *
- * @author Zijian Pei
- * @author Lidia Ataupillco Ramos
- *
- */
-public class InsertAnnotationQuickFix implements IJavaCodeActionParticipant {
-
- private final String[] attributes;
-
- private final String annotation;
-
- protected final boolean generateOnlyOneCodeAction;
-
- public InsertAnnotationQuickFix(String annotation, String... attributes) {
- this(annotation, false, attributes);
- }
-
- /**
- * Constructor for add missing attributes quick fix.
- *
- * @param generateOnlyOneCodeAction true if the participant must generate a
- * CodeAction which add the list of attributes
- * and false otherwise.
- * @param attributes list of attributes to add.
- */
- public InsertAnnotationQuickFix(String annotation, boolean generateOnlyOneCodeAction,
- String... attributes) {
- this.annotation = annotation;
- this.generateOnlyOneCodeAction = generateOnlyOneCodeAction;
- this.attributes = attributes;
- }
-
- @Override
- public List extends CodeAction> getCodeActions(JavaCodeActionContext context, Diagnostic diagnostic,
- IProgressMonitor monitor) throws CoreException {
- ASTNode node = context.getCoveredNode();
- IBinding parentType = getBinding(node);
-
- List codeActions = new ArrayList<>();
- addAttributes(diagnostic, context, parentType, codeActions, annotation);
-
- return codeActions;
- }
-
- protected void addAttributes(Diagnostic diagnostic, JavaCodeActionContext context, IBinding parentType,
- List codeActions, String annotation) throws CoreException {
- if (generateOnlyOneCodeAction) {
- addAttribute(diagnostic, context, parentType, codeActions, annotation, attributes);
- } else {
- for (String attribute : attributes) {
- addAttribute(diagnostic, context, parentType, codeActions, annotation, attribute);
- }
- }
- }
-
- /**
- * use setData() API with diagnostic to pass in ElementType in diagnostic
- * collector class.
- *
- */
- private void addAttribute(Diagnostic diagnostic, JavaCodeActionContext context, IBinding parentType,
- List codeActions, String annotation, String... attributes) throws CoreException {
- // Remove the modifier and the proper import by using JDT Core Manipulation
- // API
- ASTNode coveredNode = context.getCoveredNode().getParent();
- String name = getLabel(annotation, attributes);
- ChangeCorrectionProposal proposal = new ModifyAnnotationProposal(name, context.getCompilationUnit(),
- context.getASTRoot(), parentType, 0, annotation, Arrays.asList(attributes));
- CodeAction codeAction = context.convertToCodeAction(proposal, diagnostic);
-
- if (codeAction != null) {
- codeActions.add(codeAction);
- }
- }
-
- protected IBinding getBinding(ASTNode node) {
- // handle annotation insertions for a single variable declaration
- if (node.getParent() instanceof SingleVariableDeclaration) {
- return ((SingleVariableDeclaration) node.getParent()).resolveBinding();
- }
-
- if (node.getParent() instanceof VariableDeclarationFragment) {
- return ((VariableDeclarationFragment) node.getParent()).resolveBinding();
- }
- return Bindings.getBindingOfParentType(node);
- }
-
- protected String getLabel(String annotation, String... attributes) {
- return Messages.getMessage("InsertItem", "@" + annotation); // uses Java syntax
- }
-
-}
diff --git a/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/codeAction/proposal/quickfix/RemoveAbstractModifierQuickFix.java b/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/codeAction/proposal/quickfix/RemoveAbstractModifierQuickFix.java
deleted file mode 100644
index cf7b04c5..00000000
--- a/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/codeAction/proposal/quickfix/RemoveAbstractModifierQuickFix.java
+++ /dev/null
@@ -1,26 +0,0 @@
-/*******************************************************************************
-* Copyright (c) 2021 IBM Corporation 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
-*
-* SPDX-License-Identifier: EPL-2.0
-*
-* Contributors:
-* IBM Corporation, Himanshu Chotwani - initial API and implementation
-*******************************************************************************/
-package org.eclipse.lsp4jakarta.jdt.codeAction.proposal.quickfix;
-
-/**
- *
- * Quick fix for removing abstract when it is used for method with @Inject
- *
- * @author Himanshu Chotwani
- *
- */
-public class RemoveAbstractModifierQuickFix extends RemoveModifierConflictQuickFix{
- public RemoveAbstractModifierQuickFix() {
- super (false, "abstract");
- }
-}
diff --git a/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/codeAction/proposal/quickfix/RemoveAnnotationConflictQuickFix.java b/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/codeAction/proposal/quickfix/RemoveAnnotationConflictQuickFix.java
deleted file mode 100644
index d923bf8b..00000000
--- a/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/codeAction/proposal/quickfix/RemoveAnnotationConflictQuickFix.java
+++ /dev/null
@@ -1,134 +0,0 @@
-/*******************************************************************************
-* Copyright (c) 2020, 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 org.eclipse.lsp4jakarta.jdt.codeAction.proposal.quickfix;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.jdt.core.dom.ASTNode;
-import org.eclipse.jdt.core.dom.IBinding;
-import org.eclipse.jdt.core.dom.VariableDeclarationFragment;
-import org.eclipse.jdt.internal.corext.dom.Bindings;
-import org.eclipse.lsp4j.CodeAction;
-import org.eclipse.lsp4j.Diagnostic;
-import org.eclipse.lsp4jakarta.jdt.codeAction.IJavaCodeActionParticipant;
-import org.eclipse.lsp4jakarta.jdt.codeAction.JavaCodeActionContext;
-import org.eclipse.lsp4jakarta.jdt.codeAction.proposal.ChangeCorrectionProposal;
-import org.eclipse.lsp4jakarta.jdt.codeAction.proposal.DeleteAnnotationProposal;
-import org.eclipse.lsp4jakarta.jdt.core.Messages;
-
-/**
- * QuickFix for removing annotations. Modified from
- * https://github.com/eclipse/lsp4mp/blob/6f2d700a88a3262e39cc2ba04beedb429e162246/microprofile.jdt/org.eclipse.lsp4mp.jdt.core/src/main/java/org/eclipse/lsp4mp/jdt/core/java/codeaction/InsertAnnotationMissingQuickFix.java
- *
- * @author Angelo ZERR
- *
- */
-public class RemoveAnnotationConflictQuickFix implements IJavaCodeActionParticipant {
-
- private final String[] annotations;
-
- protected final boolean generateOnlyOneCodeAction;
-
- /**
- * Constructor for insert annotation quick fix.
- *
- *
- * The participant will generate a CodeAction per annotation.
- *
- *
- * @param annotations list of annotation to insert.
- */
- public RemoveAnnotationConflictQuickFix(String... annotations) {
- this(false, annotations);
- }
-
- /**
- * Constructor for insert annotation quick fix.
- *
- * @param generateOnlyOneCodeAction true if the participant must generate a
- * CodeAction which insert the list of
- * annotation and false otherwise.
- * @param annotations list of annotation to insert.
- */
- public RemoveAnnotationConflictQuickFix(boolean generateOnlyOneCodeAction, String... annotations) {
- this.generateOnlyOneCodeAction = generateOnlyOneCodeAction;
- this.annotations = annotations;
- }
-
- @Override
- public List extends CodeAction> getCodeActions(JavaCodeActionContext context, Diagnostic diagnostic,
- IProgressMonitor monitor) throws CoreException {
- List codeActions = new ArrayList<>();
- ASTNode node = context.getCoveredNode();
- IBinding parentType = getBinding(node);
- if (parentType != null) {
- removeAnnotations(diagnostic, context, parentType, codeActions);
- }
- return codeActions;
- }
-
- protected void removeAnnotations(Diagnostic diagnostic, JavaCodeActionContext context, IBinding parentType,
- List codeActions) throws CoreException {
- if (generateOnlyOneCodeAction) {
- removeAnnotation(diagnostic, context, parentType, codeActions, annotations);
- } else {
- for (String annotation : annotations) {
- removeAnnotation(diagnostic, context, parentType, codeActions, annotation);
- }
- }
- }
-
- protected static void removeAnnotation(Diagnostic diagnostic, JavaCodeActionContext context, IBinding parentType,
- List codeActions, String... annotations) throws CoreException {
- // Remove the annotation and the proper import by using JDT Core Manipulation
- // API
- String name = getLabel(annotations);
- ChangeCorrectionProposal proposal = new DeleteAnnotationProposal(name, context.getCompilationUnit(),
- context.getASTRoot(), parentType, 0, context.getCoveredNode().getParent(), annotations);
- // Convert the proposal to LSP4J CodeAction
- CodeAction codeAction = context.convertToCodeAction(proposal, diagnostic);
- if (codeAction != null) {
- codeActions.add(codeAction);
- }
- }
-
- protected IBinding getBinding(ASTNode node) {
- if (node.getParent() instanceof VariableDeclarationFragment) {
- VariableDeclarationFragment fragment = (VariableDeclarationFragment) node.getParent();
- return ((VariableDeclarationFragment) node.getParent()).resolveBinding();
- }
- return Bindings.getBindingOfParentType(node);
- }
-
- protected String[] getAnnotations() {
- return this.annotations;
- }
-
- private static String getLabel(String[] annotations) {
- StringBuilder list = new StringBuilder();
- for (int i = 0; i < annotations.length; i++) {
- String annotation = annotations[i];
- String annotationName = annotation.substring(annotation.lastIndexOf('.') + 1, annotation.length());
- if (i > 0) {
- list.append(", "); // assume comma list is ok: @A, @B, @C
- }
- list.append("@"); // Java syntax
- list.append(annotationName);
- }
- return Messages.getMessage("RemoveItem", list.toString());
- }
-}
diff --git a/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/codeAction/proposal/quickfix/RemoveFinalModifierQuickFix.java b/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/codeAction/proposal/quickfix/RemoveFinalModifierQuickFix.java
deleted file mode 100644
index c40682fc..00000000
--- a/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/codeAction/proposal/quickfix/RemoveFinalModifierQuickFix.java
+++ /dev/null
@@ -1,28 +0,0 @@
-/*******************************************************************************
-* Copyright (c) 2021 IBM Corporation 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
-*
-* SPDX-License-Identifier: EPL-2.0
-*
-* Contributors:
-* IBM Corporation, Himanshu Chotwani - initial API and implementation
-*******************************************************************************/
-package org.eclipse.lsp4jakarta.jdt.codeAction.proposal.quickfix;
-
-
-/**
- *
- * Quick fix for removing final when it is used for @Inject field
- *
- * @author Himanshu Chotwani
- *
- */
-public class RemoveFinalModifierQuickFix extends RemoveModifierConflictQuickFix {
-
- public RemoveFinalModifierQuickFix() {
- super(false, "final");
- }
-}
diff --git a/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/codeAction/proposal/quickfix/RemoveInjectAnnotationQuickFix.java b/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/codeAction/proposal/quickfix/RemoveInjectAnnotationQuickFix.java
deleted file mode 100644
index ef02d1d0..00000000
--- a/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/codeAction/proposal/quickfix/RemoveInjectAnnotationQuickFix.java
+++ /dev/null
@@ -1,29 +0,0 @@
-/*******************************************************************************
-* Copyright (c) 2021 IBM Corporation 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.
-*
-* SPDX-License-Identifier: EPL-2.0
-*
-* Contributors:
-* IBM Corporation, Himanshu Chotwani - initial API and implementation
-*******************************************************************************/
-
-package org.eclipse.lsp4jakarta.jdt.codeAction.proposal.quickfix;
-
-/**
- *
- * Quick fix for removing @Inject when it is used for final field
- *
- * @author Himanshu Chotwani
- *
- */
-
-public class RemoveInjectAnnotationQuickFix extends RemoveAnnotationConflictQuickFix {
-
- public RemoveInjectAnnotationQuickFix() {
- super(false, "jakarta.inject.Inject");
- }
-}
diff --git a/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/codeAction/proposal/quickfix/RemoveMethodParametersQuickFix.java b/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/codeAction/proposal/quickfix/RemoveMethodParametersQuickFix.java
deleted file mode 100644
index 270a0414..00000000
--- a/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/codeAction/proposal/quickfix/RemoveMethodParametersQuickFix.java
+++ /dev/null
@@ -1,61 +0,0 @@
-/*******************************************************************************
-* Copyright (c) 2021, 2023 IBM Corporation 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.
-*
-* SPDX-License-Identifier: EPL-2.0
-*
-* Contributors:
-* IBM Corporation - initial API and implementation
-*******************************************************************************/
-
-package org.eclipse.lsp4jakarta.jdt.codeAction.proposal.quickfix;
-
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
-
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.jdt.core.dom.ASTNode;
-import org.eclipse.jdt.core.dom.IBinding;
-import org.eclipse.jdt.core.dom.IMethodBinding;
-import org.eclipse.jdt.core.dom.MethodDeclaration;
-import org.eclipse.jdt.core.dom.SingleVariableDeclaration;
-import org.eclipse.jdt.core.dom.VariableDeclarationFragment;
-import org.eclipse.jdt.internal.corext.dom.Bindings;
-import org.eclipse.lsp4j.CodeAction;
-import org.eclipse.lsp4j.Diagnostic;
-import org.eclipse.lsp4jakarta.jdt.codeAction.IJavaCodeActionParticipant;
-import org.eclipse.lsp4jakarta.jdt.codeAction.JavaCodeActionContext;
-import org.eclipse.lsp4jakarta.jdt.codeAction.proposal.ChangeCorrectionProposal;
-import org.eclipse.lsp4jakarta.jdt.codeAction.proposal.ModifyModifiersProposal;
-import org.eclipse.lsp4jakarta.jdt.codeAction.proposal.RemoveParamsProposal;
-import org.eclipse.lsp4jakarta.jdt.core.Messages;
-import org.eclipse.lsp4jakarta.jdt.core.annotations.AnnotationConstants;
-import org.eclipse.lsp4jakarta.jdt.core.beanvalidation.BeanValidationConstants;
-
-/**
- * Quickfix for removing all parameters from a method
- *
- * @author Zijian Pei
- *
- */
-public class RemoveMethodParametersQuickFix implements IJavaCodeActionParticipant {
- public List extends CodeAction> getCodeActions(JavaCodeActionContext context, Diagnostic diagnostic,
- IProgressMonitor monitor) throws CoreException {
- ASTNode node = context.getCoveredNode();
- MethodDeclaration parentNode = (MethodDeclaration) node.getParent();
- IMethodBinding parentMethod = parentNode.resolveBinding();
- List codeActions = new ArrayList<>();
- List parameters = (List) parentNode.parameters();
- String name = Messages.getMessage("RemoveAllParameters");
- ChangeCorrectionProposal proposal = new RemoveParamsProposal(name, context.getCompilationUnit(),
- context.getASTRoot(), parentMethod, 0, parameters, null);
- CodeAction codeAction = context.convertToCodeAction(proposal, diagnostic);
- codeActions.add(codeAction);
- return codeActions;
- }
-}
diff --git a/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/codeAction/proposal/quickfix/RemoveModifierConflictQuickFix.java b/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/codeAction/proposal/quickfix/RemoveModifierConflictQuickFix.java
deleted file mode 100644
index c8f94ff6..00000000
--- a/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/codeAction/proposal/quickfix/RemoveModifierConflictQuickFix.java
+++ /dev/null
@@ -1,161 +0,0 @@
-/*******************************************************************************
-* Copyright (c) 2021, 2023 IBM Corporation 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.
-*
-* SPDX-License-Identifier: EPL-2.0
-*
-* Contributors:
-* Himanshu Chotwani - initial API and implementation
-*******************************************************************************/
-
-package org.eclipse.lsp4jakarta.jdt.codeAction.proposal.quickfix;
-
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
-
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.jdt.core.IJavaElement;
-import org.eclipse.jdt.core.dom.ASTNode;
-import org.eclipse.jdt.core.dom.IBinding;
-import org.eclipse.jdt.core.dom.MethodDeclaration;
-import org.eclipse.jdt.core.dom.VariableDeclarationFragment;
-import org.eclipse.jdt.internal.corext.dom.Bindings;
-import org.eclipse.lsp4j.CodeAction;
-import org.eclipse.lsp4j.Diagnostic;
-import org.eclipse.lsp4jakarta.jdt.codeAction.IJavaCodeActionParticipant;
-import org.eclipse.lsp4jakarta.jdt.codeAction.JavaCodeActionContext;
-import org.eclipse.lsp4jakarta.jdt.codeAction.proposal.ModifyModifiersProposal;
-import org.eclipse.lsp4jakarta.jdt.core.Messages;
-
-
-/**
- * QuickFix for removing modifiers.
- *
- * @author Himanshu Chotwani
- *
- */
-public class RemoveModifierConflictQuickFix implements IJavaCodeActionParticipant {
-
- private final String[] modifiers;
-
- protected final boolean generateOnlyOneCodeAction;
-
-
- /**
- * Constructor for remove modifier quick fix.
- *
- *
- * The participant will generate a CodeAction per modifier.
- *
- *
- * @param modifiers list of modifiers to remove.
- */
- public RemoveModifierConflictQuickFix(String... modifiers) {
- this(false, modifiers);
- }
-
- /**
- * Constructor for remove modifiers quick fix.
- *
- * @param generateOnlyOneCodeAction true if the participant must generate a
- * CodeAction which remove the list of
- * modifiers and false otherwise.
- * @param modifiers list of modifiers to remove.
- */
- public RemoveModifierConflictQuickFix(boolean generateOnlyOneCodeAction, String... modifiers) {
- this.generateOnlyOneCodeAction = generateOnlyOneCodeAction;
- this.modifiers = modifiers;
- }
-
-
- @Override
- public List extends CodeAction> getCodeActions(JavaCodeActionContext context, Diagnostic diagnostic,
- IProgressMonitor monitor) throws CoreException {
- ASTNode node = context.getCoveredNode();
- IBinding parentType = getBinding(node);
-
- List codeActions = new ArrayList<>();
- removeModifiers(diagnostic, context, parentType, codeActions);
-
- return codeActions;
- }
-
- protected void removeModifiers(Diagnostic diagnostic, JavaCodeActionContext context, IBinding parentType,
- List codeActions) throws CoreException {
- if (generateOnlyOneCodeAction) {
- removeModifier(diagnostic, context, parentType, codeActions, modifiers);
- } else {
- for (String modifier : modifiers) {
- removeModifier(diagnostic, context, parentType, codeActions, modifier);
- }
- }
- }
-
- /**
- * use setData() API with diagnostic to pass in ElementType in diagnostic collector class.
- *
- */
- private void removeModifier(Diagnostic diagnostic, JavaCodeActionContext context, IBinding parentType,
- List codeActions, String... modifier) throws CoreException {
- // Remove the modifier and the proper import by using JDT Core Manipulation
- // API
- ASTNode coveredNode = context.getCoveredNode().getParent();
- String label = getLabel(diagnostic, modifier);
-
- ModifyModifiersProposal proposal = new ModifyModifiersProposal(label, context.getCompilationUnit(),
- context.getASTRoot(), parentType, 0, coveredNode, new ArrayList<>(), Arrays.asList(modifier));
- CodeAction codeAction = context.convertToCodeAction(proposal, diagnostic);
-
- if (codeAction != null) {
- codeActions.add(codeAction);
- }
- }
-
- private String getLabel(Diagnostic diagnostic, String... modifier) {
- String label;
- if (diagnostic.getData().toString().equals(String.valueOf(IJavaElement.LOCAL_VARIABLE))){
- label = Messages.getMessage("RemoveTheModifierFromThisVariable", modifier[0]);
- } else if (diagnostic.getData().toString().equals(String.valueOf(IJavaElement.FIELD))) {
- label = Messages.getMessage("RemoveTheModifierFromThisField", modifier[0]);
- } else if (diagnostic.getData().toString().equals(String.valueOf(IJavaElement.METHOD))) {
- label = Messages.getMessage("RemoveTheModifierFromThisMethod", modifier[0]);
- } else if (diagnostic.getData().toString().equals(String.valueOf(IJavaElement.CLASS_FILE)) ||
- diagnostic.getData().toString().equals(String.valueOf(IJavaElement.TYPE))) {
- label = Messages.getMessage("RemoveTheModifierFromThisClass", modifier[0]);
- } else {
- label = Messages.getMessage("RemoveTheModifierFromThis", modifier[0], "");
- }
- return label;
- }
-
- /**
- * Removes a set of modifiers from a given ASTNode with a given code action label
- */
- protected void removeModifier(Diagnostic diagnostic, JavaCodeActionContext context, IBinding parentType,
- List codeActions, ASTNode coveredNode, String label, String... modifier) throws CoreException {
-
- ModifyModifiersProposal proposal = new ModifyModifiersProposal(label, context.getCompilationUnit(),
- context.getASTRoot(), parentType, 0, coveredNode, new ArrayList<>(), Arrays.asList(modifiers));
- CodeAction codeAction = context.convertToCodeAction(proposal, diagnostic);
-
- if (codeAction != null) {
- codeActions.add(codeAction);
- }
- }
-
- protected IBinding getBinding(ASTNode node) {
- ASTNode parentNode = node.getParent();
- if (node.getParent() instanceof VariableDeclarationFragment) {
- return ((VariableDeclarationFragment) node.getParent()).resolveBinding();
- } else if (node.getParent() instanceof MethodDeclaration) {
- return ((MethodDeclaration) node.getParent()).resolveBinding();
- }
- return Bindings.getBindingOfParentType(node);
- }
-
-}
diff --git a/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/codeAction/proposal/quickfix/RemoveParamAnnotationQuickFix.java b/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/codeAction/proposal/quickfix/RemoveParamAnnotationQuickFix.java
deleted file mode 100644
index ff26409e..00000000
--- a/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/codeAction/proposal/quickfix/RemoveParamAnnotationQuickFix.java
+++ /dev/null
@@ -1,83 +0,0 @@
- /*******************************************************************************
- * Copyright (c) 2021, 2023 IBM Corporation 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.
- *
- * SPDX-License-Identifier: EPL-2.0
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
-*******************************************************************************/
-package org.eclipse.lsp4jakarta.jdt.codeAction.proposal.quickfix;
-
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
-
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.jdt.core.dom.ASTNode;
-import org.eclipse.jdt.core.dom.IMethodBinding;
-import org.eclipse.jdt.core.dom.MarkerAnnotation;
-import org.eclipse.jdt.core.dom.MethodDeclaration;
-import org.eclipse.jdt.core.dom.Name;
-import org.eclipse.jdt.core.dom.SingleVariableDeclaration;
-import org.eclipse.lsp4j.CodeAction;
-import org.eclipse.lsp4j.Diagnostic;
-import org.eclipse.lsp4jakarta.jdt.codeAction.JavaCodeActionContext;
-import org.eclipse.lsp4jakarta.jdt.core.Messages;
-
-/**
- * QuickFix for removing parameter annotations
- */
-public class RemoveParamAnnotationQuickFix extends RemoveModifierConflictQuickFix {
-
- String[] annotations;
-
- public RemoveParamAnnotationQuickFix(String ...annotations) {
- super(annotations);
- this.annotations = annotations;
- }
-
- @Override
- public List extends CodeAction> getCodeActions(JavaCodeActionContext context, Diagnostic diagnostic,
- IProgressMonitor monitor) throws CoreException {
-
- ASTNode node = context.getCoveredNode();
- MethodDeclaration parentNode = (MethodDeclaration) node.getParent();
- IMethodBinding parentMethod = parentNode.resolveBinding();
-
- List codeActions = new ArrayList<>();
-
- List parameters = (List) parentNode.parameters();
-
- for (SingleVariableDeclaration parameter : parameters) {
-
- List modifiers = (List) parameter.getStructuralProperty(SingleVariableDeclaration.MODIFIERS2_PROPERTY);
- ArrayList annotationsToRemove = new ArrayList<>();
-
- for(ASTNode modifier : modifiers) {
- Name markAnnotationTypeName = ((MarkerAnnotation) modifier).getTypeName();
- if (Arrays.asList(this.annotations).stream().anyMatch(m -> m.equals(markAnnotationTypeName.toString()))) {
- annotationsToRemove.add(markAnnotationTypeName.toString());
- }
- }
-
- StringBuilder sb = new StringBuilder();
- // Java annotations in comma delimited list, assume that is ok.
- sb.append("'@").append(annotationsToRemove.get(0)).append("'");
- for (int i = 1; i < annotationsToRemove.size();i++) {
- sb.append(", '@").append(annotationsToRemove.get(i)).append("'");
- }
- String label = Messages.getMessage("RemoveTheModifierFromParameter", sb.toString(), parameter.getName().toString());
-
- removeModifier(diagnostic, context, parentMethod, codeActions, parameter, label,
- (String []) annotationsToRemove.toArray(new String[annotationsToRemove.size()]));
- }
-
- return codeActions;
- }
-
-}
diff --git a/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/codeAction/proposal/quickfix/RemoveStaticModifierQuickFix.java b/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/codeAction/proposal/quickfix/RemoveStaticModifierQuickFix.java
deleted file mode 100644
index b68e5613..00000000
--- a/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/codeAction/proposal/quickfix/RemoveStaticModifierQuickFix.java
+++ /dev/null
@@ -1,29 +0,0 @@
-/*******************************************************************************
-* Copyright (c) 2021 IBM Corporation 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
-*
-* SPDX-License-Identifier: EPL-2.0
-*
-* Contributors:
-* IBM Corporation, Himanshu Chotwani - initial API and implementation
-*******************************************************************************/
-
-package org.eclipse.lsp4jakarta.jdt.codeAction.proposal.quickfix;
-
-/**
- *
- * Quick fix for removing static modifier when it is used for a method
- * with @Inject
- *
- * @author Himanshu Chotwani
- *
- */
-public class RemoveStaticModifierQuickFix extends RemoveModifierConflictQuickFix {
-
- public RemoveStaticModifierQuickFix() {
- super(false, "static");
- }
-}
diff --git a/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/core/ASTNodeUtils.java b/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/core/ASTNodeUtils.java
index dce60779..ebbe93a4 100644
--- a/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/core/ASTNodeUtils.java
+++ b/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/core/ASTNodeUtils.java
@@ -20,19 +20,18 @@
*/
public class ASTNodeUtils {
- private ASTNodeUtils() {
- }
+ private ASTNodeUtils() {}
- /**
- * Returns true if the given ASTNode
represents an annotation, and false otherwise.
- *
- * @param node the ast node to check, assumed to be non-null
- * @return true if the given ASTNode
represents an annotation, and false otherwise
- */
- public static boolean isAnnotation(ASTNode node) {
- int nodeType = node.getNodeType();
- return nodeType == ASTNode.MARKER_ANNOTATION || nodeType == ASTNode.SINGLE_MEMBER_ANNOTATION
- || nodeType == ASTNode.NORMAL_ANNOTATION;
- }
+ /**
+ * Returns true if the given ASTNode
represents an annotation, and false otherwise.
+ *
+ * @param node the ast node to check, assumed to be non-null
+ * @return true if the given ASTNode
represents an annotation, and false otherwise
+ */
+ public static boolean isAnnotation(ASTNode node) {
+ int nodeType = node.getNodeType();
+ return nodeType == ASTNode.MARKER_ANNOTATION || nodeType == ASTNode.SINGLE_MEMBER_ANNOTATION
+ || nodeType == ASTNode.NORMAL_ANNOTATION;
+ }
}
diff --git a/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/core/ASTUtils.java b/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/core/ASTUtils.java
index f2734478..fb23178e 100644
--- a/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/core/ASTUtils.java
+++ b/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/core/ASTUtils.java
@@ -28,7 +28,7 @@ public class ASTUtils {
/**
* Converts a given compilation unit to an ASTNode.
- *
+ *
* @param unit
* @return ASTNode parsed from the compilation unit
*/
@@ -42,7 +42,7 @@ public static ASTNode getASTNode(ICompilationUnit unit) {
/**
* Given a compilation unit returns a list of all method invocations.
- *
+ *
* @param unit
* @return list of method invocations
*/
diff --git a/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/core/AnnotationUtil.java b/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/core/AnnotationUtil.java
deleted file mode 100644
index e760697b..00000000
--- a/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/core/AnnotationUtil.java
+++ /dev/null
@@ -1,44 +0,0 @@
-/*******************************************************************************
-* Copyright (c) 2022 IBM Corporation, Lidia Ataupillco Ramos 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.
-*
-* SPDX-License-Identifier: EPL-2.0
-*
-* Contributors:
-* IBM Corporation - initial API and implementation
-*******************************************************************************/
-
-package org.eclipse.lsp4jakarta.jdt.core;
-
-import org.eclipse.jdt.core.IAnnotatable;
-
-import java.util.Arrays;
-import java.util.List;
-import java.util.Set;
-import java.util.stream.Collectors;
-import java.util.Collections;
-
-public class AnnotationUtil {
- /**
- * Returns the list of recognised defining annotations applied to a
- * class.
- *
- * @param type the type representing the class
- * @param scopes list of defining annotations
- * @return list of recognised defining annotations applied to a class
- */
- public static List getScopeAnnotations(IAnnotatable type, Set scopes) {
- try {
- // Construct a stream of only the annotations applied to the type that are also
- // recognised annotations found in scopes.
- return Arrays.stream(type.getAnnotations()).map(annotation -> annotation.getElementName())
- .filter(scopes::contains).distinct().collect(Collectors.toList());
-
- } catch (Exception e) {
- return Collections.emptyList();
- }
- }
-}
diff --git a/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/core/DiagnosticsCollector.java b/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/core/DiagnosticsCollector.java
deleted file mode 100644
index 3c8337fb..00000000
--- a/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/core/DiagnosticsCollector.java
+++ /dev/null
@@ -1,30 +0,0 @@
-/*******************************************************************************
-* Copyright (c) 2020 IBM Corporation, Pengyu Xiong 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.
-*
-* SPDX-License-Identifier: EPL-2.0
-*
-* Contributors:
-* IBM Corporation, Pengyu Xiong - initial API and implementation
-*******************************************************************************/
-
-package org.eclipse.lsp4jakarta.jdt.core;
-
-import java.util.List;
-
-import org.eclipse.jdt.core.ICompilationUnit;
-import org.eclipse.lsp4j.Diagnostic;
-
-/**
- * Diagnostics Collector interface
- * @author Pengyu Xiong
- *
- */
-public interface DiagnosticsCollector {
- public void completeDiagnostic(Diagnostic diagnostic);
-
- public void collectDiagnostics(ICompilationUnit unit, List diagnostics);
-}
diff --git a/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/core/IProjectLabelProvider.java b/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/core/IProjectLabelProvider.java
new file mode 100644
index 00000000..45836b93
--- /dev/null
+++ b/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/core/IProjectLabelProvider.java
@@ -0,0 +1,39 @@
+/*******************************************************************************
+* Copyright (c) 2020 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 org.eclipse.lsp4jakarta.jdt.core;
+
+import java.util.List;
+
+import org.eclipse.jdt.core.IJavaProject;
+import org.eclipse.jdt.core.JavaModelException;
+
+/**
+ * Project label provider API
+ *
+ * Based on: https://github.com/eclipse/lsp4mp/blob/0.9.0/microprofile.jdt/org.eclipse.lsp4mp.jdt.core/src/main/java/org/eclipse/lsp4mp/jdt/core/IProjectLabelProvider.java
+ *
+ * @author dakwon
+ */
+public interface IProjectLabelProvider {
+
+ /**
+ * Returns a list of project labels ("maven", "jakarta", etc.) for the given
+ * project
+ *
+ * @param project the project to get labels for
+ * @return a list of project labels for the given project
+ * @throws JavaModelException
+ */
+ List getProjectLabels(IJavaProject project) throws JavaModelException;
+}
diff --git a/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/core/JDTServicesManager.java b/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/core/JDTServicesManager.java
deleted file mode 100644
index 30be18ca..00000000
--- a/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/core/JDTServicesManager.java
+++ /dev/null
@@ -1,532 +0,0 @@
-/*******************************************************************************
-* Copyright (c) 2019, 2022 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 org.eclipse.lsp4jakarta.jdt.core;
-
-import java.net.URI;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
-
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.core.runtime.NullProgressMonitor;
-import org.eclipse.jdt.core.IBuffer;
-import org.eclipse.jdt.core.IClassFile;
-import org.eclipse.jdt.core.ICompilationUnit;
-import org.eclipse.jdt.core.IJavaProject;
-import org.eclipse.jdt.core.IType;
-import org.eclipse.jdt.core.ITypeRoot;
-import org.eclipse.jdt.core.JavaModelException;
-import org.eclipse.jdt.core.dom.ASTNode;
-import org.eclipse.jdt.core.dom.ASTVisitor;
-import org.eclipse.jdt.core.dom.AbstractTypeDeclaration;
-import org.eclipse.jdt.core.dom.AnnotationTypeDeclaration;
-import org.eclipse.jdt.core.dom.AnnotationTypeMemberDeclaration;
-import org.eclipse.jdt.core.dom.BodyDeclaration;
-import org.eclipse.jdt.core.dom.CompilationUnit;
-import org.eclipse.jdt.core.dom.EnumConstantDeclaration;
-import org.eclipse.jdt.core.dom.EnumDeclaration;
-import org.eclipse.jdt.core.dom.FieldDeclaration;
-import org.eclipse.jdt.core.dom.MethodDeclaration;
-import org.eclipse.jdt.core.dom.NodeFinder;
-import org.eclipse.jdt.core.dom.RecordDeclaration;
-import org.eclipse.jdt.core.dom.TypeDeclaration;
-import org.eclipse.jdt.internal.core.manipulation.dom.ASTResolving;
-import org.eclipse.jdt.ls.core.internal.JavaLanguageServerPlugin;
-import org.eclipse.lsp4j.CodeAction;
-import org.eclipse.lsp4j.Diagnostic;
-import org.eclipse.lsp4j.Position;
-import org.eclipse.lsp4j.PublishDiagnosticsParams;
-import org.eclipse.lsp4j.jsonrpc.validation.NonNull;
-import org.eclipse.lsp4jakarta.commons.JakartaDiagnosticsParams;
-import org.eclipse.lsp4jakarta.commons.JakartaJavaCodeActionParams;
-import org.eclipse.lsp4jakarta.commons.JakartaJavaCompletionParams;
-import org.eclipse.lsp4jakarta.commons.JavaCursorContextKind;
-import org.eclipse.lsp4jakarta.commons.JavaCursorContextResult;
-import org.eclipse.lsp4jakarta.jdt.codeAction.CodeActionHandler;
-import org.eclipse.lsp4jakarta.jdt.core.annotations.AnnotationDiagnosticsCollector;
-import org.eclipse.lsp4jakarta.jdt.core.beanvalidation.BeanValidationDiagnosticsCollector;
-import org.eclipse.lsp4jakarta.jdt.core.cdi.ManagedBeanDiagnosticsCollector;
-import org.eclipse.lsp4jakarta.jdt.core.di.DependencyInjectionDiagnosticsCollector;
-import org.eclipse.lsp4jakarta.jdt.core.jax_rs.Jax_RSClassDiagnosticsCollector;
-import org.eclipse.lsp4jakarta.jdt.core.jax_rs.ResourceMethodDiagnosticsCollector;
-import org.eclipse.lsp4jakarta.jdt.core.jsonb.JsonbDiagnosticsCollector;
-import org.eclipse.lsp4jakarta.jdt.core.jsonp.JsonpDiagnosticCollector;
-import org.eclipse.lsp4jakarta.jdt.core.persistence.PersistenceEntityDiagnosticsCollector;
-import org.eclipse.lsp4jakarta.jdt.core.persistence.PersistenceMapKeyDiagnosticsCollector;
-import org.eclipse.lsp4jakarta.jdt.core.servlet.FilterDiagnosticsCollector;
-import org.eclipse.lsp4jakarta.jdt.core.servlet.ListenerDiagnosticsCollector;
-import org.eclipse.lsp4jakarta.jdt.core.servlet.ServletDiagnosticsCollector;
-import org.eclipse.lsp4jakarta.jdt.core.websocket.WebSocketDiagnosticsCollector;
-
-/**
- * JDT manager for Java files Modified from
- * https://github.com/eclipse/lsp4mp/blob/master/microprofile.jdt/org.eclipse.lsp4mp.jdt.core/src/main/java/org/eclipse/lsp4mp/jdt/core/PropertiesManagerForJava.java
- * with methods modified and removed to fit the purposes of the Jakarta Language
- * Server
- *
- */
-public class JDTServicesManager {
-
- private List diagnosticsCollectors = new ArrayList<>();
-
- private static final JDTServicesManager INSTANCE = new JDTServicesManager();
-
- private final CodeActionHandler codeActionHandler;
-
- public static JDTServicesManager getInstance() {
- return INSTANCE;
- }
-
- private JDTServicesManager() {
- diagnosticsCollectors.add(new ServletDiagnosticsCollector());
- diagnosticsCollectors.add(new AnnotationDiagnosticsCollector());
- diagnosticsCollectors.add(new FilterDiagnosticsCollector());
- diagnosticsCollectors.add(new ListenerDiagnosticsCollector());
- diagnosticsCollectors.add(new BeanValidationDiagnosticsCollector());
- diagnosticsCollectors.add(new PersistenceEntityDiagnosticsCollector());
- diagnosticsCollectors.add(new PersistenceMapKeyDiagnosticsCollector());
- diagnosticsCollectors.add(new ResourceMethodDiagnosticsCollector());
- diagnosticsCollectors.add(new Jax_RSClassDiagnosticsCollector());
- diagnosticsCollectors.add(new JsonbDiagnosticsCollector());
- diagnosticsCollectors.add(new ManagedBeanDiagnosticsCollector());
- diagnosticsCollectors.add(new DependencyInjectionDiagnosticsCollector());
- diagnosticsCollectors.add(new JsonpDiagnosticCollector());
- diagnosticsCollectors.add(new WebSocketDiagnosticsCollector());
- // comment it out as the collector is doing nothing
- // diagnosticsCollectors.add(new TransactionsDiagnosticsCollector());
- this.codeActionHandler = new CodeActionHandler();
- }
-
- /**
- * Returns diagnostics for the given uris from the JakartaDiagnosticsParams.
- *
- * @param javaParams the diagnostics parameters
- * @return diagnostics
- */
- public List getJavaDiagnostics(JakartaDiagnosticsParams javaParams) {
- return getJavaDiagnostics(javaParams.getUris(), new NullProgressMonitor());
- }
-
- /**
- * Returns diagnostics for the given uris
- *
- * @param uris the list of uris to collect diagnostics for
- * @return diagnostics
- */
- public List getJavaDiagnostics(List uris,
- IProgressMonitor monitor) {
- if (uris == null) {
- return Collections.emptyList();
- }
-
- List publishDiagnostics = new ArrayList();
- for (String uri : uris) {
- List diagnostics = new ArrayList<>();
- URI u = JDTUtils.toURI(uri);
- ICompilationUnit unit = JDTUtils.resolveCompilationUnit(u);
- for (DiagnosticsCollector d : diagnosticsCollectors) {
- if (monitor.isCanceled()) {
- break;
- }
- d.collectDiagnostics(unit, diagnostics);
- }
- PublishDiagnosticsParams publishDiagnostic = new PublishDiagnosticsParams(uri, diagnostics);
- publishDiagnostics.add(publishDiagnostic);
- if (monitor.isCanceled()) {
- return Collections.emptyList();
- }
- }
- return publishDiagnostics;
- }
-
- /**
- * @author ankushsharma
- * @brief Gets all snippet contexts that exist in the current project classpath
- * @param uri - String representing file from which to derive project
- * classpath
- * @param snippetContext - get all the context fields from the snippets and
- * check if they exist in this method
- * @return List
- */
- public List getExistingContextsFromClassPath(String uri, List snippetContexts) {
- // Initialize the list that will hold the classpath
- List classpath = new ArrayList<>();
- // Convert URI into a compilation unit
- ICompilationUnit unit = JDTUtils.resolveCompilationUnit(JDTUtils.toURI(uri));
- // Get Java Project
- IJavaProject project = unit.getJavaProject();
- // Get Java Project
- if (project != null) {
- snippetContexts.forEach(ctx -> {
- IType classPathctx = null;
- try {
- classPathctx = project.findType(ctx);
- if (classPathctx != null) {
- classpath.add(ctx);
- } else {
- classpath.add(null);
- }
- } catch (JavaModelException e) {
- JavaLanguageServerPlugin.logException("Failed to retrieve projectContext from JDT...", e);
- classpath.add(null);
- }
- });
- } else {
- // Populate the Array with nulls up to length of snippetContext
- snippetContexts.forEach(ctx -> {
- classpath.add(null);
- });
- }
-
- // FOR NOW, append package name and class name to the list in order for LS to
- // resolve ${packagename} and ${classname} variables
- String className = unit.getElementName();
- if (className.endsWith(".java") == true) {
- className = className.substring(0, className.length() - 5);
- }
- String packageName = unit.getParent() != null ? unit.getParent().getElementName() : "";
- classpath.add(packageName);
- classpath.add(className);
-
- return classpath;
- }
-
- public List getCodeAction(JakartaJavaCodeActionParams params, JDTUtils utils, IProgressMonitor monitor)
- throws JavaModelException {
- return codeActionHandler.codeAction(params, utils, monitor);
- }
-
- /**
- * 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
- * @param monitor the progress monitor
- * @return the cursor context for the given file and cursor position
- * @throws JavaModelException when the buffer for the file cannot be accessed or
- * the Java model cannot be accessed
- */
- public JavaCursorContextResult javaCursorContext(JakartaJavaCompletionParams params, JDTUtils utils,
- IProgressMonitor monitor) throws JavaModelException {
- String uri = params.getUri();
- ITypeRoot typeRoot = resolveTypeRoot(uri, utils, monitor);
-
- if (typeRoot == null) {
- return new JavaCursorContextResult(JavaCursorContextKind.IN_EMPTY_FILE, "");
- }
- CompilationUnit ast = ASTResolving.createQuickFixAST((ICompilationUnit) typeRoot, monitor);
-
- JavaCursorContextKind kind = getJavaCursorContextKind(params, typeRoot, ast, utils, monitor);
- String prefix = getJavaCursorPrefix(params, typeRoot, ast, utils, monitor);
-
- return new JavaCursorContextResult(kind, prefix);
- }
-
- private static JavaCursorContextKind getJavaCursorContextKind(JakartaJavaCompletionParams params,
- ITypeRoot typeRoot, CompilationUnit ast, JDTUtils utils, IProgressMonitor monitor)
- throws JavaModelException {
-
- if (typeRoot.findPrimaryType() == null) {
- return JavaCursorContextKind.IN_EMPTY_FILE;
- }
-
- Position completionPosition = params.getPosition();
- int completionOffset = utils.toOffset(typeRoot.getBuffer(), completionPosition.getLine(),
- completionPosition.getCharacter());
-
- NodeFinder nodeFinder = new NodeFinder(ast, completionOffset, 0);
- ASTNode node = nodeFinder.getCoveringNode();
- ASTNode oldNode = node;
- while (node != null && (!(node instanceof AbstractTypeDeclaration)
- || offsetOfFirstNonAnnotationModifier((BodyDeclaration) node) >= completionOffset)) {
- if (node.getParent() != null) {
- switch (node.getParent().getNodeType()) {
- case ASTNode.METHOD_DECLARATION:
- case ASTNode.FIELD_DECLARATION:
- case ASTNode.ENUM_CONSTANT_DECLARATION:
- case ASTNode.ANNOTATION_TYPE_MEMBER_DECLARATION:
- if (!ASTNodeUtils.isAnnotation(node) && node.getStartPosition() < completionOffset) {
- return JavaCursorContextKind.NONE;
- }
- break;
- }
- }
- oldNode = node;
- node = node.getParent();
- }
-
- if (node == null) {
- // we are likely before or after the type root class declaration
- FindWhatsBeingAnnotatedASTVisitor visitor = new FindWhatsBeingAnnotatedASTVisitor(completionOffset, false);
- oldNode.accept(visitor);
- switch (visitor.getAnnotatedNodeType()) {
- case ASTNode.TYPE_DECLARATION:
- case ASTNode.ANNOTATION_TYPE_DECLARATION:
- case ASTNode.ENUM_DECLARATION:
- case ASTNode.RECORD_DECLARATION: {
- if (visitor.isInAnnotations()) {
- return JavaCursorContextKind.IN_CLASS_ANNOTATIONS;
- }
- return JavaCursorContextKind.BEFORE_CLASS;
- }
- default:
- return JavaCursorContextKind.NONE;
- }
- }
-
- AbstractTypeDeclaration typeDeclaration = (AbstractTypeDeclaration) node;
- FindWhatsBeingAnnotatedASTVisitor visitor = new FindWhatsBeingAnnotatedASTVisitor(completionOffset);
- typeDeclaration.accept(visitor);
- switch (visitor.getAnnotatedNodeType()) {
- case ASTNode.TYPE_DECLARATION:
- case ASTNode.ANNOTATION_TYPE_DECLARATION:
- case ASTNode.ENUM_DECLARATION:
- case ASTNode.RECORD_DECLARATION:
- return visitor.isInAnnotations() ? JavaCursorContextKind.IN_CLASS_ANNOTATIONS
- : JavaCursorContextKind.BEFORE_CLASS;
- case ASTNode.ANNOTATION_TYPE_MEMBER_DECLARATION:
- case ASTNode.METHOD_DECLARATION:
- return visitor.isInAnnotations() ? JavaCursorContextKind.IN_METHOD_ANNOTATIONS
- : JavaCursorContextKind.BEFORE_METHOD;
- case ASTNode.FIELD_DECLARATION:
- case ASTNode.ENUM_CONSTANT_DECLARATION:
- return visitor.isInAnnotations() ? JavaCursorContextKind.IN_FIELD_ANNOTATIONS
- : JavaCursorContextKind.BEFORE_FIELD;
- default:
- return JavaCursorContextKind.IN_CLASS;
- }
- }
-
- private static @NonNull String getJavaCursorPrefix(JakartaJavaCompletionParams params, ITypeRoot typeRoot,
- CompilationUnit ast, JDTUtils utils, IProgressMonitor monitor) throws JavaModelException {
- Position completionPosition = params.getPosition();
- int completionOffset = utils.toOffset(typeRoot.getBuffer(), completionPosition.getLine(),
- completionPosition.getCharacter());
-
- String fileContents = null;
- try {
- IBuffer buffer = typeRoot.getBuffer();
- if (buffer == null) {
- return null;
- }
- fileContents = buffer.getContents();
- } catch (JavaModelException e) {
- return "";
- }
- if (fileContents == null) {
- return "";
- }
- int i;
- for (i = completionOffset; i > 0 && !Character.isWhitespace(fileContents.charAt(i - 1)); i--) {
- }
- return fileContents.substring(i, completionOffset);
- }
-
- /**
- * Given the uri returns a {@link ITypeRoot}. May return null if it can not
- * associate the uri with a Java file or class file.
- *
- * @param uri
- * @param utils JDT LS utilities
- * @param monitor the progress monitor
- * @return compilation unit
- */
- private static ITypeRoot resolveTypeRoot(String uri, JDTUtils utils, IProgressMonitor monitor) {
- utils.waitForLifecycleJobs(monitor);
- final ICompilationUnit unit = utils.resolveCompilationUnit(uri);
- IClassFile classFile = null;
- if (unit == null) {
- classFile = utils.resolveClassFile(uri);
- if (classFile == null) {
- return null;
- }
- } else {
- if (!unit.getResource().exists() || monitor.isCanceled()) {
- return null;
- }
- }
- return unit != null ? unit : classFile;
- }
-
- /**
- * Searches through the AST to figure out the following:
- *
- * - If an annotation were to be placed at the completionOffset, what type of
- * node would it be annotating?
- * - Is the completionOffset within the list of annotations before a
- * member?
- *
- */
- private static class FindWhatsBeingAnnotatedASTVisitor extends ASTVisitor {
-
- private int completionOffset;
- private int closest = Integer.MAX_VALUE;
- private int annotatedNode = 0;
- private boolean visitedParentType;
- private boolean inAnnotations = false;
-
- public FindWhatsBeingAnnotatedASTVisitor(int completionOffset, boolean startingInParent) {
- this.completionOffset = completionOffset;
- this.visitedParentType = !startingInParent;
- }
-
- public FindWhatsBeingAnnotatedASTVisitor(int completionOffset) {
- this(completionOffset, true);
- }
-
- @Override
- public boolean visit(MethodDeclaration node) {
- return visitNode(node);
- }
-
- @Override
- public boolean visit(FieldDeclaration node) {
- return visitNode(node);
- }
-
- @Override
- public boolean visit(EnumConstantDeclaration node) {
- return visitNode(node);
- }
-
- @Override
- public boolean visit(AnnotationTypeMemberDeclaration node) {
- return visitNode(node);
- }
-
- @Override
- public boolean visit(TypeDeclaration node) {
- return visitAbstractType(node);
- }
-
- @Override
- public boolean visit(EnumDeclaration node) {
- return visitAbstractType(node);
- }
-
- @Override
- public boolean visit(AnnotationTypeDeclaration node) {
- return visitAbstractType(node);
- }
-
- @Override
- public boolean visit(RecordDeclaration node) {
- return visitAbstractType(node);
- }
-
- private boolean visitAbstractType(AbstractTypeDeclaration node) {
- // we need to visit the children of the first type declaration,
- // since the visitor start visiting from the supplied node.
- if (!visitedParentType) {
- visitedParentType = true;
- return true;
- }
- return visitNode(node);
- }
-
- private boolean visitNode(BodyDeclaration node) {
- // ignore generated nodes
- if (isGenerated(node)) {
- return false;
- }
- // consider the start of the declaration to be after the annotations
- int start = node.modifiers().isEmpty() ? node.getStartPosition() : offsetOfFirstNonAnnotationModifier(node);
- if (start < closest && completionOffset <= start) {
- closest = node.getStartPosition();
- annotatedNode = node.getNodeType();
- inAnnotations = node.getStartPosition() < completionOffset && completionOffset <= start;
- }
- // We don't want to enter nested classes
- return false;
- }
-
- /**
- * Returns the type of the node that an annotation placed at the completion
- * offset would be annotating.
- *
- * @see org.eclipse.jdt.core.dom.ASTNode#getNodeType()
- * @return the type of the node that an annotation placed at the completion
- * offset would be annotating
- */
- public int getAnnotatedNodeType() {
- return annotatedNode;
- }
-
- /**
- * Returns true if the completion offset is within the list of annotations
- * preceding a body declaration (field, method, class declaration) or false
- * otherwise.
- *
- * @return true if the completion offset is within the list of annotations
- * preceding a body declaration (field, method, class declaration) or
- * false otherwise
- */
- public boolean isInAnnotations() {
- return inAnnotations;
- }
-
- }
-
- private static int offsetOfFirstNonAnnotationModifier(BodyDeclaration node) {
- List modifiers = node.modifiers();
- for (int i = 0; i < modifiers.size(); i++) {
- ASTNode modifier = (ASTNode) modifiers.get(i);
- if (!ASTNodeUtils.isAnnotation(modifier)) {
- return modifier.getStartPosition();
- }
- }
- if (node instanceof MethodDeclaration method) {
- if (method.getReturnType2() != null) {
- return method.getReturnType2().getStartPosition();
- }
- // package protected constructor
- return method.getName().getStartPosition();
- } else if (node instanceof FieldDeclaration field) {
- return field.getType().getStartPosition();
- } else {
- var type = (AbstractTypeDeclaration) node;
- int nameOffset = type.getName().getStartPosition();
- int keywordLength = (switch (type.getNodeType()) {
- case ASTNode.TYPE_DECLARATION -> ((TypeDeclaration) type).isInterface() ? "interface" : "class";
- case ASTNode.ENUM_DECLARATION -> "enum";
- case ASTNode.ANNOTATION_TYPE_DECLARATION -> "@interface";
- case ASTNode.RECORD_DECLARATION -> "record";
- default -> "";
- }).length();
-
- // HACK: this assumes the code contains one space between the keyword and the
- // type name, which isn't always the case
- return nameOffset - (keywordLength + 1);
- }
- }
-
- /**
- * Returns true if the given node was generated by Project Lombok and false
- * otherwise.
- *
- * @param node the node to check if it's generated
- * @return true if the given node was generated by Project Lombok and false
- * otherwise
- */
- private static boolean isGenerated(ASTNode node) {
- try {
- return ((Boolean) node.getClass().getField("$isGenerated").get(node)).booleanValue();
- } catch (IllegalArgumentException | IllegalAccessException | NoSuchFieldException | SecurityException e) {
- return false;
- }
- }
-
-}
diff --git a/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/core/JDTUtils.java b/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/core/JDTUtils.java
deleted file mode 100644
index 9f60a33c..00000000
--- a/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/core/JDTUtils.java
+++ /dev/null
@@ -1,694 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2016-2017 Red Hat, Inc.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License 2.0
- * which accompanies this distribution, and is available at
- * https://www.eclipse.org/legal/epl-2.0/
- *
- * SPDX-License-Identifier: EPL-2.0
- *
- * Contributors:
- * Red Hat Inc. - initial API and implementation and/or initial documentation
- *******************************************************************************/
-
-package org.eclipse.lsp4jakarta.jdt.core;
-
-import java.io.File;
-import java.io.IOException;
-import java.net.URI;
-import java.net.URISyntaxException;
-import java.nio.file.Files;
-import java.nio.file.Paths;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
-import java.util.Set;
-import java.util.function.Function;
-
-import org.eclipse.core.internal.utils.FileUtil;
-import org.eclipse.core.resources.IContainer;
-import org.eclipse.core.resources.IFile;
-import org.eclipse.core.resources.IFolder;
-import org.eclipse.core.resources.IProject;
-import org.eclipse.core.resources.IResource;
-import org.eclipse.core.resources.IWorkspaceRoot;
-import org.eclipse.core.resources.ResourcesPlugin;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IPath;
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.core.runtime.NullProgressMonitor;
-import org.eclipse.core.runtime.OperationCanceledException;
-import org.eclipse.core.runtime.Path;
-import org.eclipse.core.runtime.Platform;
-import org.eclipse.core.runtime.URIUtil;
-import org.eclipse.core.runtime.jobs.Job;
-import org.eclipse.jdt.core.IAnnotatable;
-import org.eclipse.jdt.core.IAnnotation;
-import org.eclipse.jdt.core.IBuffer;
-import org.eclipse.jdt.core.IClassFile;
-import org.eclipse.jdt.core.ICompilationUnit;
-import org.eclipse.jdt.core.IField;
-import org.eclipse.jdt.core.IJavaElement;
-import org.eclipse.jdt.core.IJavaProject;
-import org.eclipse.jdt.core.ILocalVariable;
-import org.eclipse.jdt.core.IMember;
-import org.eclipse.jdt.core.IMemberValuePair;
-import org.eclipse.jdt.core.IMethod;
-import org.eclipse.jdt.core.IOpenable;
-import org.eclipse.jdt.core.ISourceRange;
-import org.eclipse.jdt.core.ISourceReference;
-import org.eclipse.jdt.core.IType;
-import org.eclipse.jdt.core.ITypeParameter;
-import org.eclipse.jdt.core.ITypeRoot;
-import org.eclipse.jdt.core.JavaCore;
-import org.eclipse.jdt.core.JavaModelException;
-import org.eclipse.jdt.core.SourceRange;
-import org.eclipse.jdt.core.dom.ASTParser;
-import org.eclipse.jdt.core.dom.CompilationUnit;
-import org.eclipse.jdt.core.dom.PackageDeclaration;
-import org.eclipse.jdt.internal.corext.dom.IASTSharedValues;
-import org.eclipse.jdt.ls.core.internal.JavaLanguageServerPlugin;
-import org.eclipse.jdt.ls.core.internal.handlers.DocumentLifeCycleHandler;
-import org.eclipse.lsp4j.Location;
-import org.eclipse.lsp4j.Position;
-import org.eclipse.lsp4j.Range;
-
-import com.google.common.base.Charsets;
-
-/**
- * This class is a copy/paste of JDT LS
- * https://github.com/eclipse/eclipse.jdt.ls/blob/master/org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/JDTUtils.java
- * with deletions of some unnecessary methods and modifications to logging for
- * Jakarta LS project.
- *
- */
-public class JDTUtils {
-
- public static final String PATH_SEPARATOR = "/";
- public static final String PERIOD = ".";
- public static final String SRC = "src";
-
- public static final String FILE_UNC_PREFIX = "file:////";
- private static final String JDT_SCHEME = "jdt";
- // Code generators known to cause problems
- private static Set SILENCED_CODEGENS = Collections.singleton("lombok");
-
- public static final String DEFAULT_PROJECT_NAME = "jdt.java-project";
-
- private static final int COMPILATION_UNIT_UPDATE_TIMEOUT = 3000;
- // Percent encoding obtained from: https://en.wikipedia.org/wiki/Percent-encoding#Reserved_characters
- private static final String LEVEL1_URI_REGEX = "(?:\\/(?:(?:\\{(\\w|-|%20|%21|%23|%24|%25|%26|%27|%28|%29|%2A|%2B|%2C|%2F|%3A|%3B|%3D|%3F|%40|%5B|%5D)+\\})|(?:(\\w|%20|%21|%23|%24|%25|%26|%27|%28|%29|%2A|%2B|%2C|%2F|%3A|%3B|%3D|%3F|%40|%5B|%5D)+)))*\\/?";
-
- /**
- * Given the uri returns a {@link ICompilationUnit}. May return null if it can
- * not associate the uri with a Java file.
- *
- * @param uriString
- * @return compilation unit
- */
- public static ICompilationUnit resolveCompilationUnit(String uriString) {
- return resolveCompilationUnit(toURI(uriString));
- }
-
- /**
- * Given the uri returns a {@link ICompilationUnit}. May return null if it can
- * not associate the uri with a Java file.
- *
- * @param uri
- * @return compilation unit
- */
- public static ICompilationUnit resolveCompilationUnit(URI uri) {
- if (uri == null || JDT_SCHEME.equals(uri.getScheme()) || !uri.isAbsolute()) {
- return null;
- }
-
- IFile resource = (IFile) findResource(uri, ResourcesPlugin.getWorkspace().getRoot()::findFilesForLocationURI);
- if (resource != null) {
- if (!ProjectUtils.isJavaProject(resource.getProject())) {
- return null;
- }
- if (resource.getFileExtension() != null) {
- String name = resource.getName();
- if (JavaCore.isJavaLikeFileName(name)) {
- ICompilationUnit unit = JavaCore.createCompilationUnitFrom(resource);
- try {
- // Give underlying resource time to catch up
- // (timeout at COMPILATION_UNIT_UPDATE_TIMEOUT milliseconds).
- long endTime = System.currentTimeMillis() + COMPILATION_UNIT_UPDATE_TIMEOUT;
- while (!unit.isConsistent() && System.currentTimeMillis() < endTime) {
- }
- } catch (JavaModelException e) {
- }
- return unit;
- }
- }
- return null;
- }
- return getFakeCompilationUnit(uri, new NullProgressMonitor());
-
- }
-
- static ICompilationUnit getFakeCompilationUnit(URI uri, IProgressMonitor monitor) {
- if (uri == null || !"file".equals(uri.getScheme()) || !uri.getPath().endsWith(".java")) {
- return null;
- }
- java.nio.file.Path path = Paths.get(uri);
- // Only support existing standalone java files
- if (!Files.isReadable(path)) {
- return null;
- }
-
- IProject project = getDefaultProject();
- if (project == null || !project.isAccessible()) {
- return null;
- }
- IJavaProject javaProject = JavaCore.create(project);
-
- String packageName = getPackageName(javaProject, uri);
- String fileName = path.getName(path.getNameCount() - 1).toString();
- String packagePath = packageName.replace(PERIOD, PATH_SEPARATOR);
-
- IPath filePath = new Path(SRC).append(packagePath).append(fileName);
- final IFile file = project.getFile(filePath);
- if (!file.isLinked()) {
- try {
- createFolders(file.getParent(), monitor);
- file.createLink(uri, IResource.REPLACE, monitor);
- } catch (CoreException e) {
- String errMsg = "Failed to create linked resource from " + uri + " to " + project.getName();
- JakartaCorePlugin.logException(errMsg, e);
- }
- }
- if (file.isLinked()) {
- return (ICompilationUnit) JavaCore.create(file, javaProject);
- }
- return null;
- }
-
- public static void createFolders(IContainer folder, IProgressMonitor monitor) throws CoreException {
- if (!folder.exists() && folder instanceof IFolder) {
- IContainer parent = folder.getParent();
- createFolders(parent, monitor);
- folder.refreshLocal(IResource.DEPTH_ZERO, monitor);
- if (!folder.exists()) {
- ((IFolder) folder).create(true, true, monitor);
- }
- }
- }
-
- public static String getPackageName(IJavaProject javaProject, URI uri) {
- try {
- File file = ResourceUtils.toFile(uri);
- // FIXME need to determine actual charset from file
- String content = com.google.common.io.Files.toString(file, Charsets.UTF_8);
- if (content.isEmpty() && javaProject != null
- && DEFAULT_PROJECT_NAME.equals(javaProject.getProject().getName())) {
- java.nio.file.Path path = Paths.get(uri);
- java.nio.file.Path parent = path;
- while (parent.getParent() != null && parent.getParent().getNameCount() > 0) {
- parent = parent.getParent();
- String name = parent.getName(parent.getNameCount() - 1).toString();
- if (SRC.equals(name)) {
- String pathStr = path.getParent().toString();
- if (pathStr.length() > parent.toString().length()) {
- pathStr = pathStr.substring(parent.toString().length() + 1);
- pathStr = pathStr.replace(PATH_SEPARATOR, PERIOD);
- return pathStr;
- }
- }
- }
- } else {
- return getPackageName(javaProject, content);
- }
- } catch (IOException e) {
- JakartaCorePlugin.logException("Failed to read package name from " + uri, e);
- }
- return "";
- }
-
- public static String getPackageName(IJavaProject javaProject, String fileContent) {
- if (fileContent == null) {
- return "";
- }
- // TODO probably not the most efficient way to get the package name as this
- // reads the whole file;
- char[] source = fileContent.toCharArray();
- ASTParser parser = ASTParser.newParser(IASTSharedValues.SHARED_AST_LEVEL);
- parser.setProject(javaProject);
- parser.setIgnoreMethodBodies(true);
- parser.setSource(source);
- CompilationUnit ast = (CompilationUnit) parser.createAST(null);
- PackageDeclaration pkg = ast.getPackage();
- return (pkg == null || pkg.getName() == null) ? "" : pkg.getName().getFullyQualifiedName();
- }
-
- /**
- * Given the uri returns a {@link IClassFile}. May return null if it can not
- * resolve the uri to a library.
- *
- * @see #toLocation(IClassFile, int, int)
- * @param uri with 'jdt' scheme
- * @return class file
- */
- public static IClassFile resolveClassFile(String uriString) {
- return resolveClassFile(toURI(uriString));
- }
-
- /**
- * Given the uri returns a {@link IClassFile}. May return null if it can not
- * resolve the uri to a library.
- *
- * @see #toLocation(IClassFile, int, int)
- * @param uri with 'jdt' scheme
- * @return class file
- */
- public static IClassFile resolveClassFile(URI uri) {
- if (uri != null && JDT_SCHEME.equals(uri.getScheme()) && "contents".equals(uri.getAuthority())) {
- String handleId = uri.getQuery();
- IJavaElement element = JavaCore.create(handleId);
- IClassFile cf = (IClassFile) element.getAncestor(IJavaElement.CLASS_FILE);
- return cf;
- }
- return null;
- }
-
- public static IProject getDefaultProject() {
- return getWorkspaceRoot().getProject(DEFAULT_PROJECT_NAME);
- }
-
- private static IWorkspaceRoot getWorkspaceRoot() {
- return ResourcesPlugin.getWorkspace().getRoot();
- }
-
- public static IFile findFile(String uriString) {
- return (IFile) findResource(toURI(uriString),
- ResourcesPlugin.getWorkspace().getRoot()::findFilesForLocationURI);
- }
-
- public static IResource findResource(URI uri, Function resourceFinder) {
- if (uri == null || !"file".equals(uri.getScheme())) {
- return null;
- }
- IResource[] resources = resourceFinder.apply(uri);
- if (resources.length == 0) {
- //On Mac, Linked resources are referenced via the "real" URI, i.e file://USERS/username/...
- //instead of file://Users/username/..., so we check against that real URI.
- URI realUri = FileUtil.realURI(uri);
- if (!uri.equals(realUri)) {
- uri = realUri;
- resources = resourceFinder.apply(uri);
- }
- }
- if (resources.length == 0 && Platform.OS_WIN32.equals(Platform.getOS())
- && uri.toString().startsWith(FILE_UNC_PREFIX)) {
- String uriString = uri.toString();
- int index = uriString.indexOf(PATH_SEPARATOR, FILE_UNC_PREFIX.length());
- if (index > 0) {
- String server = uriString.substring(FILE_UNC_PREFIX.length(), index);
- uriString = uriString.replace(server, server.toUpperCase());
- try {
- uri = new URI(uriString);
- } catch (URISyntaxException e) {
- // JavaLanguageServerPlugin.logException(e.getMessage(), e);
- }
- resources = resourceFinder.apply(uri);
- }
- }
- switch (resources.length) {
- case 0:
- return null;
- case 1:
- return resources[0];
- default:// several candidates if a linked resource was created before the real project
- // was configured
- IResource resource = null;
- for (IResource f : resources) {
- // find closest project containing that file, in case of nested projects
- if (resource == null || f.getProjectRelativePath().segmentCount() < resource.getProjectRelativePath()
- .segmentCount()) {
- resource = f;
- }
- }
- return resource;
- }
- }
-
- public static URI toURI(String uriString) {
- if (uriString == null || uriString.isEmpty()) {
- return null;
- }
- try {
- URI uri = new URI(uriString);
- if (Platform.OS_WIN32.equals(Platform.getOS()) && URIUtil.isFileURI(uri)) {
- uri = URIUtil.toFile(uri).toURI();
- }
- return uri;
- } catch (URISyntaxException e) {
- JakartaCorePlugin.logException("Failed to resolve " + uriString, e);
- return null;
- }
- }
-
- public static String toUri(IClassFile classFile) {
- String packageName = classFile.getParent().getElementName();
- String jarName = classFile.getParent().getParent().getElementName();
- String uriString = null;
- try {
- uriString = new URI(JDT_SCHEME, "contents", PATH_SEPARATOR + jarName + PATH_SEPARATOR + packageName
- + PATH_SEPARATOR + classFile.getElementName(), classFile.getHandleIdentifier(), null)
- .toASCIIString();
- } catch (URISyntaxException e) {
- JakartaCorePlugin.logException("Error generating URI for class ", e);
- }
- return uriString;
- }
-
- public static String toUri(ITypeRoot typeRoot) {
- if (typeRoot instanceof ICompilationUnit) {
- return toURI((ICompilationUnit) typeRoot);
- }
- if (typeRoot instanceof IClassFile) {
- return toUri((IClassFile) typeRoot);
- }
- return null;
- }
-
- /**
- * Creates a range for the given offset and length for an {@link IOpenable}
- *
- * @param openable
- * @param offset
- * @param length
- * @return
- * @throws JavaModelException
- */
- public static Range toRange(IOpenable openable, int offset, int length) throws JavaModelException {
- Range range = newRange();
- if (offset > 0 || length > 0) {
- int[] loc = null;
- int[] endLoc = null;
- IBuffer buffer = openable.getBuffer();
- if (buffer != null) {
- loc = JsonRpcHelpers.toLine(buffer, offset);
- endLoc = JsonRpcHelpers.toLine(buffer, offset + length);
- }
- if (loc == null) {
- loc = new int[2];
- }
- if (endLoc == null) {
- endLoc = new int[2];
- }
- setPosition(range.getStart(), loc);
- setPosition(range.getEnd(), endLoc);
- }
- return range;
- }
-
- /**
- * Creates a new {@link Range} with its start and end {@link Position}s set to
- * line=0, character=0
- *
- * @return a new {@link Range};
- */
- public static Range newRange() {
- return new Range(new Position(), new Position());
- }
-
- private static void setPosition(Position position, int[] coords) {
- assert coords.length == 2;
- position.setLine(coords[0]);
- position.setCharacter(coords[1]);
- }
-
- /**
- * Returns uri for a compilation unit
- *
- * @param cu
- * @return
- */
- public static String toURI(ICompilationUnit cu) {
- return getFileURI(cu.getResource());
- }
-
- /**
- * Returns uri for a resource
- *
- * @param resource
- * @return
- */
- public static String getFileURI(IResource resource) {
- return ResourceUtils.fixURI(
- resource.getRawLocationURI() == null ? resource.getLocationURI() : resource.getRawLocationURI());
- }
-
- public static boolean isHiddenGeneratedElement(IJavaElement element) {
- // generated elements are annotated with @Generated and they need to be filtered
- // out
- if (element instanceof IAnnotatable) {
- try {
- IAnnotation[] annotations = ((IAnnotatable) element).getAnnotations();
- if (annotations.length != 0) {
- for (IAnnotation annotation : annotations) {
- if (isSilencedGeneratedAnnotation(annotation)) {
- return true;
- }
- }
- }
- } catch (JavaModelException e) {
- // ignore
- }
- }
- return false;
- }
-
- private static boolean isSilencedGeneratedAnnotation(IAnnotation annotation) throws JavaModelException {
- if ("javax.annotation.Generated".equals(annotation.getElementName())
- || "javax.annotation.processing.Generated".equals(annotation.getElementName())) {
- IMemberValuePair[] memberValuePairs = annotation.getMemberValuePairs();
- for (IMemberValuePair m : memberValuePairs) {
- if ("value".equals(m.getMemberName()) && IMemberValuePair.K_STRING == m.getValueKind()) {
- if (m.getValue() instanceof String) {
- return SILENCED_CODEGENS.contains(m.getValue());
- } else if (m.getValue() instanceof Object[]) {
- for (Object val : (Object[]) m.getValue()) {
- if (SILENCED_CODEGENS.contains(val)) {
- return true;
- }
- }
- }
- }
- }
- }
- return false;
- }
-
- /**
- * Enumeration for determining the location of a Java element. Either returns
- * with the name range only, or the extended source range around the name of the
- * element.
- */
- public enum LocationType {
- /**
- * This is range encapsulating only the name of the Java element.
- */
- NAME_RANGE {
-
- @Override
- ISourceRange getRange(IJavaElement element) throws JavaModelException {
- return getNameRange(element);
- }
-
- },
- /**
- * The range enclosing this element not including leading/trailing whitespace
- * but everything else like comments. This information is typically used to
- * determine if the client's cursor is inside the element.
- */
- FULL_RANGE {
-
- @Override
- ISourceRange getRange(IJavaElement element) throws JavaModelException {
- return getSourceRange(element);
- }
-
- };
-
- /* default */ abstract ISourceRange getRange(IJavaElement element) throws JavaModelException;
- }
-
- public static Location toLocation(IJavaElement element) throws JavaModelException {
- return toLocation(element, LocationType.NAME_RANGE);
- }
-
- /**
- * Creates a location for a given java element. Unlike {@link #toLocation} this
- * method can be called to return with a range that contains surrounding
- * comments (method body), not just the name of the Java element. Element can be
- * a {@link ICompilationUnit} or {@link IClassFile}
- *
- * @param element
- * @param type the range type. The {@link LocationType#NAME_RANGE name} or
- * {@link LocationType#FULL_RANGE full} range.
- * @return location or null
- * @throws JavaModelException
- */
- public static Location toLocation(IJavaElement element, LocationType type) throws JavaModelException {
- ICompilationUnit unit = (ICompilationUnit) element.getAncestor(IJavaElement.COMPILATION_UNIT);
- IClassFile cf = (IClassFile) element.getAncestor(IJavaElement.CLASS_FILE);
- if (unit == null && cf == null) {
- return null;
- }
- if (element instanceof ISourceReference) {
- ISourceRange nameRange = type.getRange(element);
- if (SourceRange.isAvailable(nameRange)) {
- if (cf == null) {
- return toLocation(unit, nameRange.getOffset(), nameRange.getLength());
- } else {
- return toLocation(cf, nameRange.getOffset(), nameRange.getLength());
- }
- }
- }
- return null;
- }
-
- public static ISourceRange getNameRange(IJavaElement element) throws JavaModelException {
- ISourceRange nameRange = null;
- if (element instanceof IMember) {
- IMember member = (IMember) element;
- nameRange = member.getNameRange();
- if ((!SourceRange.isAvailable(nameRange))) {
- nameRange = member.getSourceRange();
- }
- } else if (element instanceof ITypeParameter || element instanceof ILocalVariable) {
- nameRange = ((ISourceReference) element).getNameRange();
- } else if (element instanceof ISourceReference) {
- nameRange = ((ISourceReference) element).getSourceRange();
- }
- if (!SourceRange.isAvailable(nameRange) && element.getParent() != null) {
- nameRange = getNameRange(element.getParent());
- }
- return nameRange;
- }
-
- private static ISourceRange getSourceRange(IJavaElement element) throws JavaModelException {
- ISourceRange sourceRange = null;
- if (element instanceof IMember) {
- IMember member = (IMember) element;
- sourceRange = member.getSourceRange();
- } else if (element instanceof ITypeParameter || element instanceof ILocalVariable) {
- sourceRange = ((ISourceReference) element).getSourceRange();
- } else if (element instanceof ISourceReference) {
- sourceRange = ((ISourceReference) element).getSourceRange();
- }
- if (!SourceRange.isAvailable(sourceRange) && element.getParent() != null) {
- sourceRange = getSourceRange(element.getParent());
- }
- return sourceRange;
- }
-
- /**
- * Creates location to the given offset and length for the compilation unit
- *
- * @param unit
- * @param offset
- * @param length
- * @return location or null
- * @throws JavaModelException
- */
- public static Location toLocation(ICompilationUnit unit, int offset, int length) throws JavaModelException {
- return new Location(ResourceUtils.toClientUri(toURI(unit)), toRange(unit, offset, length));
- }
-
- /**
- * Creates a default location for the class file.
- *
- * @param classFile
- * @return location
- * @throws JavaModelException
- */
- public static Location toLocation(IClassFile classFile) throws JavaModelException {
- return toLocation(classFile, 0, 0);
- }
-
- /**
- * Creates location to the given offset and length for the class file.
- *
- * @param unit
- * @param offset
- * @param length
- * @return location
- * @throws JavaModelException
- */
- public static Location toLocation(IClassFile classFile, int offset, int length) throws JavaModelException {
- String uriString = toUri(classFile);
- if (uriString != null) {
- Range range = toRange(classFile, offset, length);
- return new Location(uriString, range);
- }
- return null;
- }
-
- /**
- * Check if a URI starts with a leading slash.
- *
- * @param uriString
- * @return boolean
- */
- public static boolean hasLeadingSlash(String uriString) {
- return uriString.startsWith("/");
- }
-
- /**
- * Check if a URI follows a valid URI-template (level-1) specified by
- * RFC 6570.
- *
- * @param uriString
- * @return boolean
- */
- public static boolean isValidLevel1URI(String uriString) {
- return uriString.matches(LEVEL1_URI_REGEX);
- }
-
- /**
- * Returns a list of all accessors (getter and setter) of the given field.
- * Note that for boolean fields the accessor of the form "isField" is retuned
- * "getField" is not present.
- *
- * @param unit the compilation unit the field belongs to
- * @param field the accesors of this field are returned
- * @return a list of accessor methods
- * @throws JavaModelException
- */
- public static List getFieldAccessors(ICompilationUnit unit, IField field) throws JavaModelException {
- List accessors = new ArrayList();
- String fieldName = field.getElementName();
- fieldName = fieldName.substring(0, 1).toUpperCase() + fieldName.substring(1);
- List accessorNames = new ArrayList();
- accessorNames.add("get" + fieldName);
- accessorNames.add("set" + fieldName);
- accessorNames.add("is" + fieldName);
-
- for (IType type : unit.getAllTypes()) {
- for (IMethod method : type.getMethods()) {
- String methodName = method.getElementName();
- if (accessorNames.contains(methodName))
- accessors.add(method);
- }
- }
- return accessors;
- }
-
- public static void waitForLifecycleJobs(IProgressMonitor monitor) {
- try {
- Job.getJobManager().join(DocumentLifeCycleHandler.DOCUMENT_LIFE_CYCLE_JOBS, monitor);
- } catch (OperationCanceledException ignorable) {
- // No need to pollute logs when query is cancelled
- } catch (Exception e) {
- JavaLanguageServerPlugin.logException(e.getMessage(), e);
- }
- }
-
- public static int toOffset(IBuffer buffer, int line, int column) {
- return JsonRpcHelpers.toOffset(buffer, line, column);
- }
-}
diff --git a/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/core/JakartaCorePlugin.java b/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/core/JakartaCorePlugin.java
index 0a4e59a0..115431dd 100644
--- a/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/core/JakartaCorePlugin.java
+++ b/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/core/JakartaCorePlugin.java
@@ -32,38 +32,38 @@ public class JakartaCorePlugin implements BundleActivator {
public void start(BundleContext context) throws Exception {
// super.start(context);
- plugin = this;
- }
+ plugin = this;
+ }
- public void stop(BundleContext context) throws Exception {
- plugin = null;
+ public void stop(BundleContext context) throws Exception {
+ plugin = null;
// super.stop(context);
- }
+ }
- /**
- * Returns the shared instance
- *
- * @return the shared instance
- */
- public static JakartaCorePlugin getDefault() {
- return plugin;
- }
+ /**
+ * Returns the shared instance
+ *
+ * @return the shared instance
+ */
+ public static JakartaCorePlugin getDefault() {
+ return plugin;
+ }
- /**
- * Add the given Jakarta properties changed listener.
- *
- * @param listener the listener to add
- */
- public static void log(IStatus status) {
+ /**
+ * Add the given Jakarta properties changed listener.
+ *
+ * @param listener the listener to add
+ */
+ public static void log(IStatus status) {
// getDefault().getLog().log(status);
}
- /**
- * Remove the given Jakarta properties changed listener.
- *
- * @param listener the listener to remove
- */
- public static void logException(String errMsg, Throwable ex) {
+ /**
+ * Remove the given Jakarta properties changed listener.
+ *
+ * @param listener the listener to remove
+ */
+ public static void logException(String errMsg, Throwable ex) {
// getDefault().getLog().log(new Status(IStatus.ERROR, PLUGIN_ID, errMsg, ex));
}
diff --git a/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/core/JsonRpcHelpers.java b/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/core/JsonRpcHelpers.java
index c83679c6..819bd4bb 100644
--- a/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/core/JsonRpcHelpers.java
+++ b/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/core/JsonRpcHelpers.java
@@ -29,7 +29,7 @@
public class JsonRpcHelpers {
/**
* Convert line, column to a document offset.
- *
+ *
* @param buffer
* @param line
* @param column
@@ -44,7 +44,7 @@ public static int toOffset(IBuffer buffer, int line, int column) {
/**
* Convert line, column to a document offset.
- *
+ *
* @param document
* @param line
* @param column
@@ -54,14 +54,14 @@ public static int toOffset(IDocument document, int line, int column) {
try {
return document.getLineOffset(line) + column;
} catch (BadLocationException e) {
- JakartaCorePlugin.logException(e.getMessage(), e);
+ JakartaCorePlugin.logException(e.getMessage(), e);
}
return -1;
}
/**
* Convert offset to line number and column.
- *
+ *
* @param buffer
* @param line
* @param column
@@ -84,7 +84,7 @@ public static int[] toLine(IDocument document, int offset) {
int column = offset - document.getLineOffset(line);
return new int[] { line, column };
} catch (BadLocationException e) {
- JakartaCorePlugin.logException(e.getMessage(), e);
+ JakartaCorePlugin.logException(e.getMessage(), e);
}
return null;
}
diff --git a/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/core/ProjectLabelDefinition.java b/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/core/ProjectLabelDefinition.java
new file mode 100644
index 00000000..afcd1d2c
--- /dev/null
+++ b/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/core/ProjectLabelDefinition.java
@@ -0,0 +1,61 @@
+/*******************************************************************************
+* Copyright (c) 2020 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 org.eclipse.lsp4jakarta.jdt.core;
+
+import java.util.Collections;
+import java.util.List;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import org.eclipse.jdt.core.IJavaProject;
+import org.eclipse.jdt.core.JavaModelException;
+
+/**
+ * Wrapper class around IProjectLabelProvider
+ *
+ * Based on:
+ * https://github.com/eclipse/lsp4mp/blob/0.9.0/microprofile.jdt/org.eclipse.lsp4mp.jdt.core/src/main/java/org/eclipse/lsp4mp/jdt/core/ProjectLabelDefinition.java
+ */
+public class ProjectLabelDefinition {
+ /** Logger object to record events for this class. */
+ private static final Logger LOGGER = Logger.getLogger(ProjectLabelDefinition.class.getName());
+
+ /** Project label provider instance. */
+ private final IProjectLabelProvider projectLabelProvider;
+
+ /**
+ * Constructor.
+ *
+ * @param projectLabelProvider the project label provider instance.
+ */
+ public ProjectLabelDefinition(IProjectLabelProvider projectLabelProvider) {
+ this.projectLabelProvider = projectLabelProvider;
+ }
+
+ /**
+ * Returns a list of project labels ("maven", "jakarta", etc.) for the
+ * given project
+ *
+ * @param project the Java project
+ * @return a list of project labels for the given project
+ */
+ public List getProjectLabels(IJavaProject project) {
+ try {
+ return projectLabelProvider.getProjectLabels(project);
+ } catch (JavaModelException e) {
+ LOGGER.log(Level.SEVERE, "Error while getting project labels", e);
+ return Collections.emptyList();
+ }
+ }
+}
diff --git a/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/core/ProjectLabelManager.java b/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/core/ProjectLabelManager.java
new file mode 100644
index 00000000..2f3525ad
--- /dev/null
+++ b/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/core/ProjectLabelManager.java
@@ -0,0 +1,152 @@
+/*******************************************************************************
+* Copyright (c) 2019-2020 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 org.eclipse.lsp4jakarta.jdt.core;
+
+import java.net.URI;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.jdt.core.IJavaProject;
+import org.eclipse.jdt.core.IPackageFragmentRoot;
+import org.eclipse.jdt.core.JavaCore;
+import org.eclipse.lsp4jakarta.commons.JakartaJavaProjectLabelsParams;
+import org.eclipse.lsp4jakarta.commons.ProjectLabelInfoEntry;
+import org.eclipse.lsp4jakarta.jdt.core.utils.IJDTUtils;
+import org.eclipse.lsp4jakarta.jdt.core.utils.JDTJakartaUtils;
+import org.eclipse.lsp4jakarta.jdt.core.utils.JDTTypeUtils;
+import org.eclipse.lsp4jakarta.jdt.internal.core.ProjectLabelRegistry;
+
+/**
+ * Project label manager which provides ProjectLabelInfo
containing
+ * project labels for all projects in the workspace
+ *
+ */
+public class ProjectLabelManager {
+ private static final ProjectLabelManager INSTANCE = new ProjectLabelManager();
+
+ public static ProjectLabelManager getInstance() {
+ return INSTANCE;
+ }
+
+ private ProjectLabelManager() {
+
+ }
+
+ /**
+ * Returns project label results for all projects in the workspace
+ *
+ * @return project label results for all projects in the workspace
+ */
+ public List getProjectLabelInfo() {
+ List results = new ArrayList<>();
+ IProject[] projects = ResourcesPlugin.getWorkspace().getRoot().getProjects();
+
+ for (IProject project : projects) {
+ ProjectLabelInfoEntry info = getProjectLabelInfo(project, null);
+ if (info != null) {
+ results.add(info);
+ }
+ }
+ return results;
+ }
+
+ /**
+ * Returns project label results for the given Eclipse project.
+ *
+ * @param project Eclipse project.
+ * @param types the Java type list to check.
+ * @return project label results for the given Eclipse project.
+ */
+ private ProjectLabelInfoEntry getProjectLabelInfo(IProject project, List types) {
+ String uri = JDTJakartaUtils.getProjectURI(project);
+ if (uri != null) {
+ return new ProjectLabelInfoEntry(uri, project.getName(), getProjectLabels(project, types));
+ }
+ return null;
+ }
+
+ /**
+ * Returns project label results for the given Java file uri parameter.
+ *
+ * @param params the Java file uri parameter.
+ * @param utils the JDT utilities.
+ * @param monitor the progress monitor.
+ * @return project label results for the given Java file uri parameter.
+ */
+ public ProjectLabelInfoEntry getProjectLabelInfo(JakartaJavaProjectLabelsParams params, IJDTUtils utils,
+ IProgressMonitor monitor) {
+ IProject project = findProject(params.getUri(), utils);
+ if (project == null) {
+ // The uri doesn't belong to an Eclipse project
+ return ProjectLabelInfoEntry.EMPTY_PROJECT_INFO;
+ }
+ return getProjectLabelInfo(project, params.getTypes());
+ }
+
+ private static IProject findProject(String uri, IJDTUtils utils) {
+ if (uri.startsWith("jdt://jarentry")) {
+ URI jarEntryUri = URI.create(uri);
+ String rootId = jarEntryUri.getQuery();
+ IPackageFragmentRoot packageRoot = (IPackageFragmentRoot) JavaCore.create(rootId);
+ if (packageRoot != null) {
+ IJavaProject javaProject = packageRoot.getJavaProject();
+ return javaProject != null ? javaProject.getProject() : null;
+ }
+ return null;
+ }
+ IFile file = utils.findFile(uri);
+ return file != null ? file.getProject() : null;
+ }
+
+ /**
+ * Returns the project labels for the given project.
+ *
+ * @param project the Eclipse project.
+ * @param types the Java type list to check.
+ * @return the project labels for the given project.
+ */
+ private List getProjectLabels(IProject project, List types) {
+ IJavaProject javaProject = JavaCore.create(project);
+
+ if (javaProject == null) {
+ return Collections.emptyList();
+ }
+
+ // Update labels by using the
+ // "org.eclipse.lsp4mp.jdt.core.projectLabelProviders" extension point (ex
+ // : "maven", "gradle", "quarkus", "jakarta").
+ List projectLabels = new ArrayList<>();
+ List definitions = ProjectLabelRegistry.getInstance().getProjectLabelDefinitions();
+ for (ProjectLabelDefinition definition : definitions) {
+ projectLabels.addAll(definition.getProjectLabels(javaProject));
+ }
+ // Update labels by checking if some Java types are in the classpath of the Java
+ // project.
+ if (types != null) {
+ for (String type : types) {
+ if (JDTTypeUtils.findType(javaProject, type) != null) {
+ projectLabels.add(type);
+ }
+ }
+ }
+
+ return projectLabels;
+ }
+
+}
diff --git a/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/core/PropertiesManagerForJava.java b/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/core/PropertiesManagerForJava.java
new file mode 100644
index 00000000..fd925245
--- /dev/null
+++ b/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/core/PropertiesManagerForJava.java
@@ -0,0 +1,553 @@
+/*******************************************************************************
+* Copyright (c) 2019 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 org.eclipse.lsp4jakarta.jdt.core;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.stream.Collectors;
+
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.jdt.core.IBuffer;
+import org.eclipse.jdt.core.IClassFile;
+import org.eclipse.jdt.core.ICompilationUnit;
+import org.eclipse.jdt.core.ITypeRoot;
+import org.eclipse.jdt.core.JavaModelException;
+import org.eclipse.jdt.core.dom.ASTNode;
+import org.eclipse.jdt.core.dom.ASTVisitor;
+import org.eclipse.jdt.core.dom.AbstractTypeDeclaration;
+import org.eclipse.jdt.core.dom.AnnotationTypeDeclaration;
+import org.eclipse.jdt.core.dom.AnnotationTypeMemberDeclaration;
+import org.eclipse.jdt.core.dom.BodyDeclaration;
+import org.eclipse.jdt.core.dom.CompilationUnit;
+import org.eclipse.jdt.core.dom.EnumConstantDeclaration;
+import org.eclipse.jdt.core.dom.EnumDeclaration;
+import org.eclipse.jdt.core.dom.FieldDeclaration;
+import org.eclipse.jdt.core.dom.MethodDeclaration;
+import org.eclipse.jdt.core.dom.NodeFinder;
+import org.eclipse.jdt.core.dom.RecordDeclaration;
+import org.eclipse.jdt.core.dom.TypeDeclaration;
+import org.eclipse.jdt.internal.core.manipulation.dom.ASTResolving;
+import org.eclipse.lsp4j.CodeAction;
+import org.eclipse.lsp4j.CompletionItem;
+import org.eclipse.lsp4j.CompletionList;
+import org.eclipse.lsp4j.Diagnostic;
+import org.eclipse.lsp4j.Position;
+import org.eclipse.lsp4j.PublishDiagnosticsParams;
+import org.eclipse.lsp4j.jsonrpc.validation.NonNull;
+import org.eclipse.lsp4jakarta.commons.DocumentFormat;
+import org.eclipse.lsp4jakarta.commons.JakartaJavaCodeActionParams;
+import org.eclipse.lsp4jakarta.commons.JakartaJavaCompletionParams;
+import org.eclipse.lsp4jakarta.commons.JakartaJavaDiagnosticsParams;
+import org.eclipse.lsp4jakarta.commons.JakartaJavaDiagnosticsSettings;
+import org.eclipse.lsp4jakarta.commons.JakartaJavaFileInfo;
+import org.eclipse.lsp4jakarta.commons.JakartaJavaFileInfoParams;
+import org.eclipse.lsp4jakarta.commons.JavaCursorContextKind;
+import org.eclipse.lsp4jakarta.commons.JavaCursorContextResult;
+import org.eclipse.lsp4jakarta.jdt.core.java.completion.JavaCompletionContext;
+import org.eclipse.lsp4jakarta.jdt.core.java.diagnostics.JavaDiagnosticsContext;
+import org.eclipse.lsp4jakarta.jdt.core.utils.IJDTUtils;
+import org.eclipse.lsp4jakarta.jdt.internal.core.java.JavaFeaturesRegistry;
+import org.eclipse.lsp4jakarta.jdt.internal.core.java.codeaction.CodeActionHandler;
+import org.eclipse.lsp4jakarta.jdt.internal.core.java.completion.JavaCompletionDefinition;
+import org.eclipse.lsp4jakarta.jdt.internal.core.java.diagnostics.JavaDiagnosticsDefinition;
+
+/**
+ * JDT Jakarta manager for Java files.
+ *
+ * Based on: https://github.com/eclipse/lsp4mp/blob/0.9.0/microprofile.jdt/org.eclipse.lsp4mp.jdt.core/src/main/java/org/eclipse/lsp4mp/jdt/core/PropertiesManagerForJava.java
+ *
+ * @author Angelo ZERR
+ *
+ */
+public class PropertiesManagerForJava {
+
+ private static final PropertiesManagerForJava INSTANCE = new PropertiesManagerForJava();
+
+ private final CodeActionHandler codeActionHandler;
+
+ public static PropertiesManagerForJava getInstance() {
+ return INSTANCE;
+ }
+
+ private PropertiesManagerForJava() {
+ this.codeActionHandler = new CodeActionHandler();
+ }
+
+ /**
+ * Returns the CompletionItems given the completion item params
+ *
+ * @param params the completion item params
+ * @param utils the IJDTUtils
+ * @param monitor the progress monitors
+ * @return the CompletionItems for the given the completion item params
+ * @throws JavaModelException
+ */
+ public CompletionList completion(JakartaJavaCompletionParams params, IJDTUtils utils, IProgressMonitor monitor) throws JavaModelException {
+ String uri = params.getUri();
+ ITypeRoot typeRoot = resolveTypeRoot(uri, utils, monitor);
+ if (typeRoot == null) {
+ return null;
+ }
+
+ Position completionPosition = params.getPosition();
+ int completionOffset = utils.toOffset(typeRoot.getBuffer(), completionPosition.getLine(),
+ completionPosition.getCharacter());
+
+ List completionItems = new ArrayList<>();
+ JavaCompletionContext completionContext = new JavaCompletionContext(uri, typeRoot, utils, completionOffset);
+
+ List completions = JavaFeaturesRegistry.getInstance().getJavaCompletionDefinitions().stream().filter(completion -> completion.isAdaptedForCompletion(completionContext,
+ monitor)).collect(Collectors.toList());
+
+ if (completions.isEmpty()) {
+ return null;
+ }
+
+ completions.forEach(completion -> {
+ List extends CompletionItem> collectedCompletionItems = completion.collectCompletionItems(completionContext, monitor);
+ if (collectedCompletionItems != null) {
+ completionItems.addAll(collectedCompletionItems);
+ }
+ });
+
+ if (monitor.isCanceled()) {
+ return null;
+ }
+ CompletionList completionList = new CompletionList();
+ completionList.setItems(completionItems);
+ return completionList;
+ }
+
+ /**
+ * 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
+ * @param monitor the progress monitor
+ * @return the cursor context for the given file and cursor position
+ * @throws JavaModelException when the buffer for the file cannot be accessed or
+ * the Java model cannot be accessed
+ */
+ public JavaCursorContextResult javaCursorContext(JakartaJavaCompletionParams params, IJDTUtils utils,
+ IProgressMonitor monitor) throws JavaModelException {
+ String uri = params.getUri();
+ ITypeRoot typeRoot = resolveTypeRoot(uri, utils, monitor);
+
+ if (typeRoot == null) {
+ return new JavaCursorContextResult(JavaCursorContextKind.IN_EMPTY_FILE, "");
+ }
+ CompilationUnit ast = ASTResolving.createQuickFixAST((ICompilationUnit) typeRoot, monitor);
+
+ JavaCursorContextKind kind = getJavaCursorContextKind(params, typeRoot, ast, utils, monitor);
+ String prefix = getJavaCursorPrefix(params, typeRoot, ast, utils, monitor);
+
+ return new JavaCursorContextResult(kind, prefix);
+ }
+
+ private static JavaCursorContextKind getJavaCursorContextKind(JakartaJavaCompletionParams params,
+ ITypeRoot typeRoot, CompilationUnit ast, IJDTUtils utils, IProgressMonitor monitor) throws JavaModelException {
+
+ if (typeRoot.findPrimaryType() == null) {
+ return JavaCursorContextKind.IN_EMPTY_FILE;
+ }
+
+ Position completionPosition = params.getPosition();
+ int completionOffset = utils.toOffset(typeRoot.getBuffer(), completionPosition.getLine(),
+ completionPosition.getCharacter());
+
+ NodeFinder nodeFinder = new NodeFinder(ast, completionOffset, 0);
+ ASTNode node = nodeFinder.getCoveringNode();
+ ASTNode oldNode = node;
+ while (node != null && (!(node instanceof AbstractTypeDeclaration)
+ || offsetOfFirstNonAnnotationModifier((BodyDeclaration) node) >= completionOffset)) {
+ if (node.getParent() != null) {
+ switch (node.getParent().getNodeType()) {
+ case ASTNode.METHOD_DECLARATION:
+ case ASTNode.FIELD_DECLARATION:
+ case ASTNode.ENUM_CONSTANT_DECLARATION:
+ case ASTNode.ANNOTATION_TYPE_MEMBER_DECLARATION:
+ if (!ASTNodeUtils.isAnnotation(node) && node.getStartPosition() < completionOffset) {
+ return JavaCursorContextKind.NONE;
+ }
+ break;
+ }
+ }
+ oldNode = node;
+ node = node.getParent();
+ }
+
+ if (node == null) {
+ // we are likely before or after the type root class declaration
+ FindWhatsBeingAnnotatedASTVisitor visitor = new FindWhatsBeingAnnotatedASTVisitor(completionOffset, false);
+ oldNode.accept(visitor);
+ switch (visitor.getAnnotatedNodeType()) {
+ case ASTNode.TYPE_DECLARATION:
+ case ASTNode.ANNOTATION_TYPE_DECLARATION:
+ case ASTNode.ENUM_DECLARATION:
+ case ASTNode.RECORD_DECLARATION: {
+ if (visitor.isInAnnotations()) {
+ return JavaCursorContextKind.IN_CLASS_ANNOTATIONS;
+ }
+ return JavaCursorContextKind.BEFORE_CLASS;
+ }
+ default:
+ return JavaCursorContextKind.NONE;
+ }
+ }
+
+ AbstractTypeDeclaration typeDeclaration = (AbstractTypeDeclaration) node;
+ FindWhatsBeingAnnotatedASTVisitor visitor = new FindWhatsBeingAnnotatedASTVisitor(completionOffset);
+ typeDeclaration.accept(visitor);
+ switch (visitor.getAnnotatedNodeType()) {
+ case ASTNode.TYPE_DECLARATION:
+ case ASTNode.ANNOTATION_TYPE_DECLARATION:
+ case ASTNode.ENUM_DECLARATION:
+ case ASTNode.RECORD_DECLARATION:
+ return visitor.isInAnnotations() ? JavaCursorContextKind.IN_CLASS_ANNOTATIONS : JavaCursorContextKind.BEFORE_CLASS;
+ case ASTNode.ANNOTATION_TYPE_MEMBER_DECLARATION:
+ case ASTNode.METHOD_DECLARATION:
+ return visitor.isInAnnotations() ? JavaCursorContextKind.IN_METHOD_ANNOTATIONS : JavaCursorContextKind.BEFORE_METHOD;
+ case ASTNode.FIELD_DECLARATION:
+ case ASTNode.ENUM_CONSTANT_DECLARATION:
+ return visitor.isInAnnotations() ? JavaCursorContextKind.IN_FIELD_ANNOTATIONS : JavaCursorContextKind.BEFORE_FIELD;
+ default:
+ return JavaCursorContextKind.IN_CLASS;
+ }
+ }
+
+ private static @NonNull String getJavaCursorPrefix(JakartaJavaCompletionParams params, ITypeRoot typeRoot,
+ CompilationUnit ast, IJDTUtils utils, IProgressMonitor monitor) throws JavaModelException {
+ Position completionPosition = params.getPosition();
+ int completionOffset = utils.toOffset(typeRoot.getBuffer(), completionPosition.getLine(),
+ completionPosition.getCharacter());
+
+ String fileContents = null;
+ try {
+ IBuffer buffer = typeRoot.getBuffer();
+ if (buffer == null) {
+ return null;
+ }
+ fileContents = buffer.getContents();
+ } catch (JavaModelException e) {
+ return "";
+ }
+ if (fileContents == null) {
+ return "";
+ }
+ int i;
+ for (i = completionOffset; i > 0 && !Character.isWhitespace(fileContents.charAt(i - 1)); i--) {
+ }
+ return fileContents.substring(i, completionOffset);
+ }
+
+ /**
+ * Given the uri returns a {@link ITypeRoot}. May return null if it can not
+ * associate the uri with a Java file or class file.
+ *
+ * @param uri
+ * @param utils JDT LS utilities
+ * @param monitor the progress monitor
+ * @return compilation unit
+ */
+ private static ITypeRoot resolveTypeRoot(String uri, IJDTUtils utils, IProgressMonitor monitor) {
+ utils.waitForLifecycleJobs(monitor);
+ final ICompilationUnit unit = utils.resolveCompilationUnit(uri);
+ IClassFile classFile = null;
+ if (unit == null) {
+ classFile = utils.resolveClassFile(uri);
+ if (classFile == null) {
+ return null;
+ }
+ } else {
+ if (!unit.getResource().exists() || monitor.isCanceled()) {
+ return null;
+ }
+ }
+ return unit != null ? unit : classFile;
+ }
+
+ /**
+ * Returns the codeAction list according the given codeAction parameters.
+ *
+ * @param params the codeAction parameters
+ * @param utils the utilities class
+ * @param monitor the monitor
+ * @return the codeAction list according the given codeAction parameters.
+ * @throws JavaModelException
+ */
+ public List extends CodeAction> codeAction(JakartaJavaCodeActionParams params, IJDTUtils utils,
+ IProgressMonitor monitor) throws JavaModelException {
+ return codeActionHandler.codeAction(params, utils, monitor);
+ }
+
+ /**
+ * Returns the codeAction list according the given codeAction parameters.
+ *
+ * @param unresolved the CodeAction to resolve
+ * @param utils the utilities class
+ * @param monitor the monitor
+ * @return the codeAction list according the given codeAction parameters.
+ * @throws JavaModelException
+ */
+ public CodeAction resolveCodeAction(CodeAction unresolved, IJDTUtils utils, IProgressMonitor monitor) throws JavaModelException {
+ return codeActionHandler.resolveCodeAction(unresolved, utils, monitor);
+ }
+
+ /**
+ * Returns diagnostics for the given uris list.
+ *
+ * @param params the diagnostics parameters
+ * @param utils the utilities class
+ * @return diagnostics for the given uris list.
+ * @throws JavaModelException
+ */
+ public List diagnostics(JakartaJavaDiagnosticsParams params, IJDTUtils utils,
+ IProgressMonitor monitor) throws JavaModelException {
+ List uris = params.getUris();
+ if (uris == null) {
+ return Collections.emptyList();
+ }
+ DocumentFormat documentFormat = params.getDocumentFormat();
+ List publishDiagnostics = new ArrayList();
+ for (String uri : uris) {
+ List diagnostics = new ArrayList<>();
+ PublishDiagnosticsParams publishDiagnostic = new PublishDiagnosticsParams(uri, diagnostics);
+ publishDiagnostics.add(publishDiagnostic);
+ collectDiagnostics(uri, utils, documentFormat, params.getSettings(), diagnostics, monitor);
+ }
+ if (monitor.isCanceled()) {
+ return Collections.emptyList();
+ }
+ return publishDiagnostics;
+ }
+
+ private void collectDiagnostics(String uri, IJDTUtils utils, DocumentFormat documentFormat,
+ JakartaJavaDiagnosticsSettings settings, List diagnostics, IProgressMonitor monitor) {
+ ITypeRoot typeRoot = resolveTypeRoot(uri, utils, monitor);
+ if (typeRoot == null) {
+ return;
+ }
+
+ // Collect all adapted diagnostics participant
+ JavaDiagnosticsContext context = new JavaDiagnosticsContext(uri, typeRoot, utils, documentFormat, settings);
+ List definitions = JavaFeaturesRegistry.getInstance().getJavaDiagnosticsDefinitions().stream().filter(definition -> definition.isAdaptedForDiagnostics(context,
+ monitor)).collect(Collectors.toList());
+ if (definitions.isEmpty()) {
+ return;
+ }
+
+ // Begin, collect, end participants
+ definitions.forEach(definition -> definition.beginDiagnostics(context, monitor));
+ definitions.forEach(definition -> {
+ List collectedDiagnostics = definition.collectDiagnostics(context, monitor);
+ if (collectedDiagnostics != null && !collectedDiagnostics.isEmpty()) {
+ diagnostics.addAll(collectedDiagnostics);
+ }
+ });
+ definitions.forEach(definition -> definition.endDiagnostics(context, monitor));
+ }
+
+ /**
+ * Searches through the AST to figure out the following:
+ *
+ * - If an annotation were to be placed at the completionOffset, what type of
+ * node would it be annotating?
+ * - Is the completionOffset within the list of annotations before a
+ * member?
+ *
+ */
+ private static class FindWhatsBeingAnnotatedASTVisitor extends ASTVisitor {
+
+ private int completionOffset;
+ private int closest = Integer.MAX_VALUE;
+ private int annotatedNode = 0;
+ private boolean visitedParentType;
+ private boolean inAnnotations = false;
+
+ public FindWhatsBeingAnnotatedASTVisitor(int completionOffset, boolean startingInParent) {
+ this.completionOffset = completionOffset;
+ this.visitedParentType = !startingInParent;
+ }
+
+ public FindWhatsBeingAnnotatedASTVisitor(int completionOffset) {
+ this(completionOffset, true);
+ }
+
+ @Override
+ public boolean visit(MethodDeclaration node) {
+ return visitNode(node);
+ }
+
+ @Override
+ public boolean visit(FieldDeclaration node) {
+ return visitNode(node);
+ }
+
+ @Override
+ public boolean visit(EnumConstantDeclaration node) {
+ return visitNode(node);
+ }
+
+ @Override
+ public boolean visit(AnnotationTypeMemberDeclaration node) {
+ return visitNode(node);
+ }
+
+ @Override
+ public boolean visit(TypeDeclaration node) {
+ return visitAbstractType(node);
+ }
+
+ @Override
+ public boolean visit(EnumDeclaration node) {
+ return visitAbstractType(node);
+ }
+
+ @Override
+ public boolean visit(AnnotationTypeDeclaration node) {
+ return visitAbstractType(node);
+ }
+
+ @Override
+ public boolean visit(RecordDeclaration node) {
+ return visitAbstractType(node);
+ }
+
+ private boolean visitAbstractType(AbstractTypeDeclaration node) {
+ // we need to visit the children of the first type declaration,
+ // since the visitor start visiting from the supplied node.
+ if (!visitedParentType) {
+ visitedParentType = true;
+ return true;
+ }
+ return visitNode(node);
+ }
+
+ private boolean visitNode(BodyDeclaration node) {
+ // ignore generated nodes
+ if (isGenerated(node)) {
+ return false;
+ }
+ // consider the start of the declaration to be after the annotations
+ int start = node.modifiers().isEmpty() ? node.getStartPosition() : offsetOfFirstNonAnnotationModifier(node);
+ if (start < closest && completionOffset <= start) {
+ closest = node.getStartPosition();
+ annotatedNode = node.getNodeType();
+ inAnnotations = node.getStartPosition() < completionOffset && completionOffset <= start;
+ }
+ // We don't want to enter nested classes
+ return false;
+ }
+
+ /**
+ * Returns the type of the node that an annotation placed at the completion
+ * offset would be annotating.
+ *
+ * @see org.eclipse.jdt.core.dom.ASTNode#getNodeType()
+ * @return the type of the node that an annotation placed at the completion
+ * offset would be annotating
+ */
+ public int getAnnotatedNodeType() {
+ return annotatedNode;
+ }
+
+ /**
+ * Returns true if the completion offset is within the list of annotations
+ * preceding a body declaration (field, method, class declaration) or false
+ * otherwise.
+ *
+ * @return true if the completion offset is within the list of annotations
+ * preceding a body declaration (field, method, class declaration) or
+ * false otherwise
+ */
+ public boolean isInAnnotations() {
+ return inAnnotations;
+ }
+
+ }
+
+ private static int offsetOfFirstNonAnnotationModifier(BodyDeclaration node) {
+ List modifiers = node.modifiers();
+ for (int i = 0; i < modifiers.size(); i++) {
+ ASTNode modifier = (ASTNode) modifiers.get(i);
+ if (!ASTNodeUtils.isAnnotation(modifier)) {
+ return modifier.getStartPosition();
+ }
+ }
+ if (node instanceof MethodDeclaration method) {
+ if (method.getReturnType2() != null) {
+ return method.getReturnType2().getStartPosition();
+ }
+ // package protected constructor
+ return method.getName().getStartPosition();
+ } else if (node instanceof FieldDeclaration field) {
+ return field.getType().getStartPosition();
+ } else {
+ var type = (AbstractTypeDeclaration) node;
+ int nameOffset = type.getName().getStartPosition();
+ int keywordLength = (switch (type.getNodeType()) {
+ case ASTNode.TYPE_DECLARATION -> ((TypeDeclaration) type).isInterface() ? "interface" : "class";
+ case ASTNode.ENUM_DECLARATION -> "enum";
+ case ASTNode.ANNOTATION_TYPE_DECLARATION -> "@interface";
+ case ASTNode.RECORD_DECLARATION -> "record";
+ default -> "";
+ }).length();
+
+ // HACK: this assumes the code contains one space between the keyword and the
+ // type name, which isn't always the case
+ return nameOffset - (keywordLength + 1);
+ }
+ }
+
+ /**
+ * Returns true if the given node was generated by Project Lombok and false
+ * otherwise.
+ *
+ * @param node the node to check if it's generated
+ * @return true if the given node was generated by Project Lombok and false
+ * otherwise
+ */
+ private static boolean isGenerated(ASTNode node) {
+ try {
+ return ((Boolean) node.getClass().getField("$isGenerated").get(node)).booleanValue();
+ } catch (IllegalArgumentException | IllegalAccessException | NoSuchFieldException | SecurityException e) {
+ return false;
+ }
+ }
+
+ /**
+ * Returns the Java file information (ex : package name) from the given file URI
+ * and null otherwise.
+ *
+ * @param params the file information parameters.
+ * @param utils the utilities class
+ * @param monitor the monitor
+ * @return the Java file information (ex : package name) from the given file URI
+ * and null otherwise.
+ */
+ public JakartaJavaFileInfo fileInfo(JakartaJavaFileInfoParams params, IJDTUtils utils, IProgressMonitor monitor) {
+ String uri = params.getUri();
+ final ICompilationUnit unit = utils.resolveCompilationUnit(uri);
+ if (unit != null && unit.exists()) {
+ JakartaJavaFileInfo fileInfo = new JakartaJavaFileInfo();
+ String packageName = unit.getParent() != null ? unit.getParent().getElementName() : "";
+ fileInfo.setPackageName(packageName);
+ return fileInfo;
+ }
+ return null;
+ }
+
+}
diff --git a/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/core/annotations/AddResourceMissingNameQuickFix.java b/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/core/annotations/AddResourceMissingNameQuickFix.java
deleted file mode 100644
index d35083f7..00000000
--- a/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/core/annotations/AddResourceMissingNameQuickFix.java
+++ /dev/null
@@ -1,30 +0,0 @@
-/*******************************************************************************
-* Copyright (c) 2021 IBM Corporation 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.
-*
-* SPDX-License-Identifier: EPL-2.0
-*
-* Contributors:
-* IBM Corporation - initial API and implementation
-*******************************************************************************/
-
-package org.eclipse.lsp4jakarta.jdt.core.annotations;
-
-import org.eclipse.lsp4jakarta.jdt.codeAction.proposal.quickfix.InsertAnnotationAttributesQuickFix;
-
-/**
- * Quickfix for adding missing name to @Resource
- *
- * @author Zijian Pei
- *
- */
-public class AddResourceMissingNameQuickFix extends InsertAnnotationAttributesQuickFix {
-
- public AddResourceMissingNameQuickFix() {
- super("jakarta.annotation.Resource", false, "name");
- }
-
-}
diff --git a/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/core/annotations/AddResourceMissingTypeQuickFix.java b/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/core/annotations/AddResourceMissingTypeQuickFix.java
deleted file mode 100644
index 4c26c472..00000000
--- a/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/core/annotations/AddResourceMissingTypeQuickFix.java
+++ /dev/null
@@ -1,31 +0,0 @@
-/*******************************************************************************
-* Copyright (c) 2021 IBM Corporation 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.
-*
-* SPDX-License-Identifier: EPL-2.0
-*
-* Contributors:
-* IBM Corporation - initial API and implementation
-*******************************************************************************/
-
-package org.eclipse.lsp4jakarta.jdt.core.annotations;
-
-import org.eclipse.lsp4jakarta.jdt.codeAction.proposal.quickfix.InsertAnnotationAttributesQuickFix;
-
-/**
- * Quickfix for adding missing type to @Resource
- *
- *
- * @author Zijian Pei
- *
- */
-public class AddResourceMissingTypeQuickFix extends InsertAnnotationAttributesQuickFix {
-
- public AddResourceMissingTypeQuickFix() {
- super("jakarta.annotation.Resource", false, "type");
- }
-
-}
diff --git a/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/core/annotations/AnnotationDiagnosticsCollector.java b/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/core/annotations/AnnotationDiagnosticsCollector.java
deleted file mode 100644
index 3cd3c4b1..00000000
--- a/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/core/annotations/AnnotationDiagnosticsCollector.java
+++ /dev/null
@@ -1,254 +0,0 @@
-/*******************************************************************************
-* Copyright (c) 2021, 2023 IBM Corporation 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.
-*
-* SPDX-License-Identifier: EPL-2.0
-*
-* Contributors:
-* IBM Corporation - initial API and implementation
-*******************************************************************************/
-
-package org.eclipse.lsp4jakarta.jdt.core.annotations;
-
-import java.util.ArrayList;
-import java.util.List;
-import java.util.regex.Pattern;
-
-import org.eclipse.jdt.core.Flags;
-import org.eclipse.jdt.core.IAnnotatable;
-import org.eclipse.jdt.core.IAnnotation;
-import org.eclipse.jdt.core.ICompilationUnit;
-import org.eclipse.jdt.core.IField;
-import org.eclipse.jdt.core.IJavaElement;
-import org.eclipse.jdt.core.ILocalVariable;
-import org.eclipse.jdt.core.IMemberValuePair;
-import org.eclipse.jdt.core.IMethod;
-import org.eclipse.jdt.core.IPackageDeclaration;
-import org.eclipse.jdt.core.IType;
-import org.eclipse.jdt.core.JavaModelException;
-import org.eclipse.lsp4j.Diagnostic;
-import org.eclipse.lsp4j.DiagnosticSeverity;
-import org.eclipse.lsp4j.jsonrpc.messages.Tuple;
-import org.eclipse.lsp4j.jsonrpc.messages.Tuple.Two;
-import org.eclipse.lsp4jakarta.jdt.core.AbstractDiagnosticsCollector;
-import org.eclipse.lsp4jakarta.jdt.core.JakartaCorePlugin;
-import org.eclipse.lsp4jakarta.jdt.core.Messages;
-
-/**
- *
- * jararta.annotation Diagnostics
- *
- * Diagnostic 1: @Generated 'date' attribute does not follow ISO 8601.
- * Diagnostic 2: @Resource 'name' attribute missing (when annotation is used
- * on a class).
- * Diagnostic 3: @Resource 'type' attribute missing (when annotation is used
- * on a class).
- * Diagnostic 4: @PostConstruct method has parameters.
- * Diagnostic 5: @PostConstruct method is not void.
- * Diagnostic 6: @PostConstruct method throws checked exception(s).
- * Diagnostic 7: @PreDestroy method has parameters.
- * Diagnostic 8: @PreDestroy method is static.
- * Diagnostic 9: @PreDestroy method throws checked exception(s).
- *
- * @see https://jakarta.ee/specifications/annotations/2.0/annotations-spec-2.0.html#annotations
- *
- */
-public class AnnotationDiagnosticsCollector extends AbstractDiagnosticsCollector {
-
- public AnnotationDiagnosticsCollector() {
- super();
- }
-
- @Override
- protected String getDiagnosticSource() {
- return AnnotationConstants.DIAGNOSTIC_SOURCE;
- }
-
- @Override
- public void collectDiagnostics(ICompilationUnit unit, List diagnostics) {
- if (unit != null) {
- try {
- ArrayList> annotatables = new ArrayList>();
- String[] validAnnotations = { AnnotationConstants.GENERATED_FQ_NAME };
- String[] validTypeAnnotations = { AnnotationConstants.GENERATED_FQ_NAME,
- AnnotationConstants.RESOURCE_FQ_NAME };
- String[] validMethodAnnotations = { AnnotationConstants.GENERATED_FQ_NAME,
- AnnotationConstants.POST_CONSTRUCT_FQ_NAME, AnnotationConstants.PRE_DESTROY_FQ_NAME,
- AnnotationConstants.RESOURCE_FQ_NAME };
-
- IPackageDeclaration[] packages = unit.getPackageDeclarations();
- for (IPackageDeclaration p : packages) {
- IAnnotation[] annotations = p.getAnnotations();
- for (IAnnotation annotation : annotations) {
- if (isValidAnnotation(annotation.getElementName(), validAnnotations))
- annotatables.add(new Tuple.Two<>(annotation, p));
- }
- }
-
- IType[] types = unit.getAllTypes();
- for (IType type : types) {
- // Type
- IAnnotation[] annotations = type.getAnnotations();
- for (IAnnotation annotation : annotations) {
- if (isValidAnnotation(annotation.getElementName(), validTypeAnnotations))
- annotatables.add(new Tuple.Two<>(annotation, type));
- }
- // Method
- IMethod[] methods = type.getMethods();
- for (IMethod method : methods) {
- annotations = method.getAnnotations();
- for (IAnnotation annotation : annotations) {
- if (isValidAnnotation(annotation.getElementName(), validMethodAnnotations))
- annotatables.add(new Tuple.Two<>(annotation, method));
- }
- // method parameters
- ILocalVariable[] parameters = method.getParameters();
- for (ILocalVariable parameter : parameters) {
- annotations = parameter.getAnnotations();
- for (IAnnotation annotation : annotations) {
- if (isValidAnnotation(annotation.getElementName(), validAnnotations))
- annotatables.add(new Tuple.Two<>(annotation, parameter));
- }
- }
- }
- // Field
- IField[] fields = type.getFields();
- for (IField field : fields) {
- annotations = field.getAnnotations();
- for (IAnnotation annotation : annotations) {
- if (isValidAnnotation(annotation.getElementName(), validTypeAnnotations))
- annotatables.add(new Tuple.Two<>(annotation, field));
- }
- }
- }
-
- for (Tuple.Two annotatable : annotatables) {
- IAnnotation annotation = annotatable.getFirst();
- IAnnotatable element = annotatable.getSecond();
-
- if (isMatchedAnnotation(unit, annotation, AnnotationConstants.GENERATED_FQ_NAME)) {
- for (IMemberValuePair pair : annotation.getMemberValuePairs()) {
- // If date element exists and is non-empty, it must follow ISO 8601 format.
- if (pair.getMemberName().equals("date")) {
- if (pair.getValue() instanceof String) {
- String date = (String) pair.getValue();
- if (!date.equals("")) {
- if (!Pattern.matches(AnnotationConstants.ISO_8601_REGEX, date)) {
-
- String diagnosticMessage = Messages.getMessage(
- "AnnotationMustDefineAttributeFollowing8601", "@Generated", "date");
- diagnostics.add(createDiagnostic(annotation, unit, diagnosticMessage,
- AnnotationConstants.DIAGNOSTIC_CODE_DATE_FORMAT, null,
- DiagnosticSeverity.Error));
- }
- }
- }
- }
- }
- } else if (isMatchedAnnotation(unit, annotation, AnnotationConstants.RESOURCE_FQ_NAME)) {
- if (element instanceof IType) {
- IType type = (IType) element;
- if (type.getElementType() == IJavaElement.TYPE && ((IType) type).isClass()) {
- Boolean nameEmpty = true;
- Boolean typeEmpty = true;
- for (IMemberValuePair pair : annotation.getMemberValuePairs()) {
- if (pair.getMemberName().equals("name")) {
- nameEmpty = false;
- }
- if (pair.getMemberName().equals("type")) {
- typeEmpty = false;
- }
- }
- String diagnosticMessage;
- if (nameEmpty) {
- diagnosticMessage = Messages.getMessage("AnnotationMustDefineAttribute",
- "@Resource", "name");
- diagnostics.add(createDiagnostic(annotation, unit, diagnosticMessage,
- AnnotationConstants.DIAGNOSTIC_CODE_MISSING_RESOURCE_NAME_ATTRIBUTE, null,
- DiagnosticSeverity.Error));
- }
-
- if (typeEmpty) {
- diagnosticMessage = Messages.getMessage("AnnotationMustDefineAttribute",
- "@Resource", "type");
- diagnostics.add(createDiagnostic(annotation, unit, diagnosticMessage,
- AnnotationConstants.DIAGNOSTIC_CODE_MISSING_RESOURCE_TYPE_ATTRIBUTE, null,
- DiagnosticSeverity.Error));
- }
- }
- }
- }
- if (isMatchedAnnotation(unit, annotation, AnnotationConstants.POST_CONSTRUCT_FQ_NAME)) {
- if (element instanceof IMethod) {
- IMethod method = (IMethod) element;
- if (method.getNumberOfParameters() != 0) {
- String diagnosticMessage = Messages.getMessage("MethodMustNotHaveParameters",
- "@PostConstruct");
- diagnostics.add(createDiagnostic(method, unit, diagnosticMessage,
- AnnotationConstants.DIAGNOSTIC_CODE_POSTCONSTRUCT_PARAMS, null,
- DiagnosticSeverity.Error));
- }
-
- if (!method.getReturnType().equals("V")) {
- String diagnosticMessage = Messages.getMessage("MethodMustBeVoid",
- "@PostConstruct");
- diagnostics.add(createDiagnostic(method, unit, diagnosticMessage,
- AnnotationConstants.DIAGNOSTIC_CODE_POSTCONSTRUCT_RETURN_TYPE, null,
- DiagnosticSeverity.Error));
- }
-
- if (method.getExceptionTypes().length != 0) {
- String diagnosticMessage = Messages.getMessage("MethodMustNotThrow",
- "@PostConstruct");
- diagnostics.add(createDiagnostic(method, unit, diagnosticMessage,
- AnnotationConstants.DIAGNOSTIC_CODE_POSTCONSTRUCT_EXCEPTION, null,
- DiagnosticSeverity.Warning));
- }
- }
- } else if (isMatchedAnnotation(unit, annotation, AnnotationConstants.PRE_DESTROY_FQ_NAME)) {
- if (element instanceof IMethod) {
- IMethod method = (IMethod) element;
- if (method.getNumberOfParameters() != 0) {
- String diagnosticMessage = Messages.getMessage("MethodMustNotHaveParameters",
- "@PreDestroy");
- diagnostics.add(createDiagnostic(method, unit, diagnosticMessage,
- AnnotationConstants.DIAGNOSTIC_CODE_PREDESTROY_PARAMS, null,
- DiagnosticSeverity.Error));
- }
-
- if (Flags.isStatic(method.getFlags())) {
- String diagnosticMessage = Messages.getMessage("MethodMustNotBeStatic",
- "@PreDestroy");
- diagnostics.add(createDiagnostic(method, unit, diagnosticMessage,
- AnnotationConstants.DIAGNOSTIC_CODE_PREDESTROY_STATIC, method.getElementType(),
- DiagnosticSeverity.Error));
- }
-
- if (method.getExceptionTypes().length != 0) {
- String diagnosticMessage = Messages.getMessage("MethodMustNotThrow",
- "@PreDestroy");
- diagnostics.add(createDiagnostic(method, unit, diagnosticMessage,
- AnnotationConstants.DIAGNOSTIC_CODE_PREDESTROY_EXCEPTION, null,
- DiagnosticSeverity.Warning));
- }
- }
- }
- }
- } catch (JavaModelException e) {
- JakartaCorePlugin.logException("Cannot calculate diagnostics", e);
- }
- }
- }
-
- private static boolean isValidAnnotation(String annotationName, String[] validAnnotations) {
- for (String fqName : validAnnotations) {
- if (fqName.endsWith(annotationName)) {
- return true;
- }
- }
- return false;
- }
-}
diff --git a/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/core/annotations/PostConstructReturnTypeQuickFix.java b/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/core/annotations/PostConstructReturnTypeQuickFix.java
deleted file mode 100644
index 2d8a3bb5..00000000
--- a/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/core/annotations/PostConstructReturnTypeQuickFix.java
+++ /dev/null
@@ -1,62 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2022, 2023 IBM Corporation 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.
- *
- * SPDX-License-Identifier: EPL-2.0
- *
- * Contributors:
- * Yijia Jing
- *******************************************************************************/
-package org.eclipse.lsp4jakarta.jdt.core.annotations;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.jdt.core.dom.ASTNode;
-import org.eclipse.jdt.core.dom.IBinding;
-import org.eclipse.jdt.core.dom.MethodDeclaration;
-import org.eclipse.jdt.core.dom.PrimitiveType;
-import org.eclipse.lsp4j.CodeAction;
-import org.eclipse.lsp4j.Diagnostic;
-import org.eclipse.jdt.internal.corext.dom.Bindings;
-import org.eclipse.lsp4jakarta.jdt.codeAction.IJavaCodeActionParticipant;
-import org.eclipse.lsp4jakarta.jdt.codeAction.JavaCodeActionContext;
-import org.eclipse.lsp4jakarta.jdt.codeAction.proposal.ChangeCorrectionProposal;
-import org.eclipse.lsp4jakarta.jdt.codeAction.proposal.ModifyReturnTypeProposal;
-import org.eclipse.lsp4jakarta.jdt.core.Messages;
-
-/**
- * Quick fix for AnnotationDiagnosticsCollector that changes the return type of a method to void.
- * Uses ModifyReturnTypeProposal.
- *
- * @author Yijia Jing
- *
- */
-public class PostConstructReturnTypeQuickFix implements IJavaCodeActionParticipant {
-
- @Override
- public List extends CodeAction> getCodeActions(JavaCodeActionContext context, Diagnostic diagnostic,
- IProgressMonitor monitor) throws CoreException {
- List codeActions = new ArrayList<>();
- ASTNode node = context.getCoveredNode();
- IBinding parentType = getBinding(node);
- String name = Messages.getMessage("ChangeReturnTypeToVoid");
- ChangeCorrectionProposal proposal = new ModifyReturnTypeProposal(name, context.getCompilationUnit(),
- context.getASTRoot(), parentType, 0, node.getAST().newPrimitiveType(PrimitiveType.VOID));
- CodeAction codeAction = context.convertToCodeAction(proposal, diagnostic);
- codeActions.add(codeAction);
- return codeActions;
- }
-
- protected IBinding getBinding(ASTNode node) {
- if (node.getParent() instanceof MethodDeclaration) {
- return ((MethodDeclaration) node.getParent()).resolveBinding();
- }
- return Bindings.getBindingOfParentType(node);
- }
-}
diff --git a/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/core/annotations/RemovePostConstructAnnotationQuickFix.java b/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/core/annotations/RemovePostConstructAnnotationQuickFix.java
deleted file mode 100644
index b9e239eb..00000000
--- a/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/core/annotations/RemovePostConstructAnnotationQuickFix.java
+++ /dev/null
@@ -1,30 +0,0 @@
-/*******************************************************************************
-* Copyright (c) 2021 IBM Corporation 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.
-*
-* SPDX-License-Identifier: EPL-2.0
-*
-* Contributors:
-* IBM Corporation - initial API and implementation
-*******************************************************************************/
-
-package org.eclipse.lsp4jakarta.jdt.core.annotations;
-
-import org.eclipse.lsp4jakarta.jdt.codeAction.proposal.quickfix.RemoveAnnotationConflictQuickFix;
-
-/**
- * Quickfix for removing @PostConstruct
- *
- * @author Zijian Pei
- *
- */
-public class RemovePostConstructAnnotationQuickFix extends RemoveAnnotationConflictQuickFix {
-
- public RemovePostConstructAnnotationQuickFix() {
- super(false, "jakarta.annotation.PostConstruct");
- }
-
-}
diff --git a/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/core/annotations/RemovePreDestroyAnnotationQuickFix.java b/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/core/annotations/RemovePreDestroyAnnotationQuickFix.java
deleted file mode 100644
index 18304758..00000000
--- a/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/core/annotations/RemovePreDestroyAnnotationQuickFix.java
+++ /dev/null
@@ -1,30 +0,0 @@
-/*******************************************************************************
-* Copyright (c) 2021 IBM Corporation 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.
-*
-* SPDX-License-Identifier: EPL-2.0
-*
-* Contributors:
-* IBM Corporation - initial API and implementation
-*******************************************************************************/
-
-package org.eclipse.lsp4jakarta.jdt.core.annotations;
-
-import org.eclipse.lsp4jakarta.jdt.codeAction.proposal.quickfix.RemoveAnnotationConflictQuickFix;
-
-/**
- * Quickfix for removing @PreDestory
- *
- * @author Zijian Pei
- *
- */
-public class RemovePreDestroyAnnotationQuickFix extends RemoveAnnotationConflictQuickFix {
-
- public RemovePreDestroyAnnotationQuickFix() {
- super(false, "jakarta.annotation.PreDestroy");
- }
-
-}
diff --git a/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/core/beanvalidation/BeanValidationDiagnosticsCollector.java b/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/core/beanvalidation/BeanValidationDiagnosticsCollector.java
deleted file mode 100644
index 53ec9547..00000000
--- a/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/core/beanvalidation/BeanValidationDiagnosticsCollector.java
+++ /dev/null
@@ -1,276 +0,0 @@
-/*******************************************************************************
-* Copyright (c) 2020, 2023 IBM Corporation, Reza Akhavan 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.
-*
-* SPDX-License-Identifier: EPL-2.0
-*
-* Contributors:
-* IBM Corporation, Reza Akhavan - initial API and implementation
-*******************************************************************************/
-
-package org.eclipse.lsp4jakarta.jdt.core.beanvalidation;
-
-import static org.eclipse.lsp4jakarta.jdt.core.beanvalidation.BeanValidationConstants.ASSERT_FALSE;
-import static org.eclipse.lsp4jakarta.jdt.core.beanvalidation.BeanValidationConstants.ASSERT_TRUE;
-import static org.eclipse.lsp4jakarta.jdt.core.beanvalidation.BeanValidationConstants.BIG_DECIMAL;
-import static org.eclipse.lsp4jakarta.jdt.core.beanvalidation.BeanValidationConstants.BIG_INTEGER;
-import static org.eclipse.lsp4jakarta.jdt.core.beanvalidation.BeanValidationConstants.BOOLEAN;
-import static org.eclipse.lsp4jakarta.jdt.core.beanvalidation.BeanValidationConstants.BYTE;
-import static org.eclipse.lsp4jakarta.jdt.core.beanvalidation.BeanValidationConstants.CHAR_SEQUENCE;
-import static org.eclipse.lsp4jakarta.jdt.core.beanvalidation.BeanValidationConstants.DECIMAL_MAX;
-import static org.eclipse.lsp4jakarta.jdt.core.beanvalidation.BeanValidationConstants.DECIMAL_MIN;
-import static org.eclipse.lsp4jakarta.jdt.core.beanvalidation.BeanValidationConstants.DIAGNOSTIC_CODE_INVALID_TYPE;
-import static org.eclipse.lsp4jakarta.jdt.core.beanvalidation.BeanValidationConstants.DIAGNOSTIC_CODE_STATIC;
-import static org.eclipse.lsp4jakarta.jdt.core.beanvalidation.BeanValidationConstants.DIAGNOSTIC_SOURCE;
-import static org.eclipse.lsp4jakarta.jdt.core.beanvalidation.BeanValidationConstants.DIGITS;
-import static org.eclipse.lsp4jakarta.jdt.core.beanvalidation.BeanValidationConstants.DOUBLE;
-import static org.eclipse.lsp4jakarta.jdt.core.beanvalidation.BeanValidationConstants.EMAIL;
-import static org.eclipse.lsp4jakarta.jdt.core.beanvalidation.BeanValidationConstants.FLOAT;
-import static org.eclipse.lsp4jakarta.jdt.core.beanvalidation.BeanValidationConstants.FUTURE;
-import static org.eclipse.lsp4jakarta.jdt.core.beanvalidation.BeanValidationConstants.FUTURE_OR_PRESENT;
-import static org.eclipse.lsp4jakarta.jdt.core.beanvalidation.BeanValidationConstants.INTEGER;
-import static org.eclipse.lsp4jakarta.jdt.core.beanvalidation.BeanValidationConstants.LONG;
-import static org.eclipse.lsp4jakarta.jdt.core.beanvalidation.BeanValidationConstants.MAX;
-import static org.eclipse.lsp4jakarta.jdt.core.beanvalidation.BeanValidationConstants.MIN;
-import static org.eclipse.lsp4jakarta.jdt.core.beanvalidation.BeanValidationConstants.NEGATIVE;
-import static org.eclipse.lsp4jakarta.jdt.core.beanvalidation.BeanValidationConstants.NEGATIVE_OR_ZERO;
-import static org.eclipse.lsp4jakarta.jdt.core.beanvalidation.BeanValidationConstants.NOT_BLANK;
-import static org.eclipse.lsp4jakarta.jdt.core.beanvalidation.BeanValidationConstants.PAST;
-import static org.eclipse.lsp4jakarta.jdt.core.beanvalidation.BeanValidationConstants.PAST_OR_PRESENT;
-import static org.eclipse.lsp4jakarta.jdt.core.beanvalidation.BeanValidationConstants.PATTERN;
-import static org.eclipse.lsp4jakarta.jdt.core.beanvalidation.BeanValidationConstants.POSITIVE;
-import static org.eclipse.lsp4jakarta.jdt.core.beanvalidation.BeanValidationConstants.POSTIVE_OR_ZERO;
-import static org.eclipse.lsp4jakarta.jdt.core.beanvalidation.BeanValidationConstants.SET_OF_ANNOTATIONS;
-import static org.eclipse.lsp4jakarta.jdt.core.beanvalidation.BeanValidationConstants.SET_OF_DATE_TYPES;
-import static org.eclipse.lsp4jakarta.jdt.core.beanvalidation.BeanValidationConstants.SHORT;
-import static org.eclipse.lsp4jakarta.jdt.core.beanvalidation.BeanValidationConstants.STRING;
-
-import java.util.List;
-
-import org.eclipse.jdt.core.Flags;
-import org.eclipse.jdt.core.IAnnotation;
-import org.eclipse.jdt.core.ICompilationUnit;
-import org.eclipse.jdt.core.IField;
-import org.eclipse.jdt.core.IMember;
-import org.eclipse.jdt.core.IMethod;
-import org.eclipse.jdt.core.IType;
-import org.eclipse.jdt.core.JavaModelException;
-import org.eclipse.jdt.core.Signature;
-import org.eclipse.lsp4j.Diagnostic;
-import org.eclipse.lsp4j.DiagnosticSeverity;
-import org.eclipse.lsp4jakarta.jdt.core.AbstractDiagnosticsCollector;
-import org.eclipse.lsp4jakarta.jdt.core.JakartaCorePlugin;
-import org.eclipse.lsp4jakarta.jdt.core.Messages;
-
-public class BeanValidationDiagnosticsCollector extends AbstractDiagnosticsCollector {
-
- public BeanValidationDiagnosticsCollector() {
- super();
- }
-
- @Override
- protected String getDiagnosticSource() {
- return DIAGNOSTIC_SOURCE;
- }
-
- public void collectDiagnostics(ICompilationUnit unit, List diagnostics) {
-
- if (unit != null) {
- IType[] alltypes;
- IField[] allFields;
- IAnnotation[] annotations;
- IMethod[] allMethods;
-
- try {
- alltypes = unit.getAllTypes();
- for (IType type : alltypes) {
- allFields = type.getFields();
- for (IField field : allFields) {
- annotations = field.getAnnotations();
- for (IAnnotation annotation : annotations) {
- String matchedAnnotation = getMatchedJavaElementName(type, annotation.getElementName(),
- SET_OF_ANNOTATIONS.toArray(new String[0]));
- if (matchedAnnotation != null) {
- validAnnotation(field, annotation, matchedAnnotation, diagnostics);
- }
- }
- }
- allMethods = type.getMethods();
- for (IMethod method : allMethods) {
- annotations = method.getAnnotations();
- for (IAnnotation annotation : annotations) {
- String matchedAnnotation = getMatchedJavaElementName(type, annotation.getElementName(),
- SET_OF_ANNOTATIONS.toArray(new String[0]));
- if (matchedAnnotation != null) {
- validAnnotation(method, annotation, matchedAnnotation, diagnostics);
- }
- }
- }
- }
- } catch (JavaModelException e) {
- JakartaCorePlugin.logException("Cannot calculate diagnostics", e);
- }
- }
-
- }
-
- private void validAnnotation(IMember element, IAnnotation annotation, String matchedAnnotation,
- List diagnostics) throws JavaModelException {
- IType declaringType = element.getDeclaringType();
- if (declaringType != null) {
- String annotationName = annotation.getElementName();
- boolean isMethod = element instanceof IMethod;
-
- if (Flags.isStatic(element.getFlags())) {
- String source = isMethod ?
- Messages.getMessage("ConstraintAnnotationsMethod") :
- Messages.getMessage("ConstraintAnnotationsField");
- diagnostics.add(createDiagnostic(element, declaringType.getCompilationUnit(),
- source, DIAGNOSTIC_CODE_STATIC,
- annotationName, DiagnosticSeverity.Error));
- } else {
- String type = (isMethod) ? ((IMethod) element).getReturnType() : ((IField) element).getTypeSignature();
-
- if (matchedAnnotation.equals(ASSERT_FALSE) || matchedAnnotation.equals(ASSERT_TRUE)) {
- String source = isMethod ?
- Messages.getMessage("AnnotationBooleanMethods", "@" + annotationName) :
- Messages.getMessage("AnnotationBooleanFields", "@" + annotationName);
- if (!type.equals(getSignatureFormatOfType(BOOLEAN)) && !type.equals(Signature.SIG_BOOLEAN)) {
- diagnostics.add(createDiagnostic(element, declaringType.getCompilationUnit(),
- source, DIAGNOSTIC_CODE_INVALID_TYPE, annotationName, DiagnosticSeverity.Error));
- }
- } else if (matchedAnnotation.equals(DECIMAL_MAX) || matchedAnnotation.equals(DECIMAL_MIN)
- || matchedAnnotation.equals(DIGITS)) {
- if (!type.equals(getSignatureFormatOfType(BIG_DECIMAL))
- && !type.equals(getSignatureFormatOfType(BIG_INTEGER))
- && !type.equals(getSignatureFormatOfType(CHAR_SEQUENCE))
- && !type.equals(getSignatureFormatOfType(BYTE))
- && !type.equals(getSignatureFormatOfType(SHORT))
- && !type.equals(getSignatureFormatOfType(INTEGER))
- && !type.equals(getSignatureFormatOfType(LONG)) && !type.equals(Signature.SIG_BYTE)
- && !type.equals(Signature.SIG_SHORT) && !type.equals(Signature.SIG_INT)
- && !type.equals(Signature.SIG_LONG)) {
- String source = isMethod ?
- Messages.getMessage("AnnotationBigDecimalMethods", "@" + annotationName) :
- Messages.getMessage("AnnotationBigDecimalFields", "@" + annotationName);
- diagnostics.add(createDiagnostic(element, declaringType.getCompilationUnit(), source,
- DIAGNOSTIC_CODE_INVALID_TYPE, annotationName, DiagnosticSeverity.Error));
- }
- } else if (matchedAnnotation.equals(EMAIL)) {
- checkStringOnly(element, declaringType, diagnostics, annotationName, isMethod, type);
- } else if (matchedAnnotation.equals(NOT_BLANK)) {
- checkStringOnly(element, declaringType, diagnostics, annotationName, isMethod, type);
- } else if (matchedAnnotation.equals(PATTERN)) {
- checkStringOnly(element, declaringType, diagnostics, annotationName, isMethod, type);
- } else if (matchedAnnotation.equals(FUTURE) || matchedAnnotation.equals(FUTURE_OR_PRESENT)
- || matchedAnnotation.equals(PAST) || matchedAnnotation.equals(PAST_OR_PRESENT)) {
- String dataType = getDataTypeName(type);
- String dataTypeFQName = getMatchedJavaElementName(declaringType, dataType,
- SET_OF_DATE_TYPES.toArray(new String[0]));
- if (dataTypeFQName == null) {
- String source = isMethod ?
- Messages.getMessage("AnnotationDateMethods", "@" + annotationName) :
- Messages.getMessage("AnnotationDateFields", "@" + annotationName);
- diagnostics.add(createDiagnostic(element, declaringType.getCompilationUnit(),
- source, DIAGNOSTIC_CODE_INVALID_TYPE, annotationName, DiagnosticSeverity.Error));
- }
- } else if (matchedAnnotation.equals(MIN) || matchedAnnotation.equals(MAX)) {
- if (!type.equals(getSignatureFormatOfType(BIG_DECIMAL))
- && !type.equals(getSignatureFormatOfType(BIG_INTEGER))
- && !type.equals(getSignatureFormatOfType(BYTE))
- && !type.equals(getSignatureFormatOfType(SHORT))
- && !type.equals(getSignatureFormatOfType(INTEGER))
- && !type.equals(getSignatureFormatOfType(LONG)) && !type.equals(Signature.SIG_BYTE)
- && !type.equals(Signature.SIG_SHORT) && !type.equals(Signature.SIG_INT)
- && !type.equals(Signature.SIG_LONG)) {
- String source = isMethod ?
- Messages.getMessage("AnnotationMinMaxMethods", "@" + annotationName) :
- Messages.getMessage("AnnotationMinMaxFields", "@" + annotationName);
- diagnostics.add(createDiagnostic(element, declaringType.getCompilationUnit(),
- source, DIAGNOSTIC_CODE_INVALID_TYPE, annotationName, DiagnosticSeverity.Error));
- }
- } else if (matchedAnnotation.equals(NEGATIVE) || matchedAnnotation.equals(NEGATIVE_OR_ZERO)
- || matchedAnnotation.equals(POSITIVE) || matchedAnnotation.equals(POSTIVE_OR_ZERO)) {
- if (!type.equals(getSignatureFormatOfType(BIG_DECIMAL))
- && !type.equals(getSignatureFormatOfType(BIG_INTEGER))
- && !type.equals(getSignatureFormatOfType(BYTE))
- && !type.equals(getSignatureFormatOfType(SHORT))
- && !type.equals(getSignatureFormatOfType(INTEGER))
- && !type.equals(getSignatureFormatOfType(LONG))
- && !type.equals(getSignatureFormatOfType(FLOAT))
- && !type.equals(getSignatureFormatOfType(DOUBLE)) && !type.equals(Signature.SIG_BYTE)
- && !type.equals(Signature.SIG_SHORT) && !type.equals(Signature.SIG_INT)
- && !type.equals(Signature.SIG_LONG) && !type.equals(Signature.SIG_FLOAT)
- && !type.equals(Signature.SIG_DOUBLE)) {
- String source = isMethod ?
- Messages.getMessage("AnnotationPositiveMethods", "@" + annotationName) :
- Messages.getMessage("AnnotationPositiveFields", "@" + annotationName);
- diagnostics.add(createDiagnostic(element, declaringType.getCompilationUnit(),
- source, DIAGNOSTIC_CODE_INVALID_TYPE, annotationName, DiagnosticSeverity.Error));
- }
- }
-
- // These ones contains check on all collection types which requires resolving
- // the String of the type somehow
- // This will also require us to check if the field type was a custom collection
- // subtype which means we
- // have to resolve it and get the super interfaces and check to see if
- // Collection, Map or Array was implemented
- // for that custom type (which could as well be a user made subtype)
-
-// else if (annotation.getElementName().equals(NOT_EMPTY) || annotation.getElementName().equals(SIZE)) {
-//
-// System.out.println("--Field name: " + Signature.getTypeSignatureKind(fieldType));
-// System.out.println("--Field name: " + Signature.getParameterTypes(fieldType));
-// if ( !fieldType.equals(getSignatureFormatOfType(CHAR_SEQUENCE)) &&
-// !fieldType.contains("List") &&
-// !fieldType.contains("Set") &&
-// !fieldType.contains("Collection") &&
-// !fieldType.contains("Array") &&
-// !fieldType.contains("Vector") &&
-// !fieldType.contains("Stack") &&
-// !fieldType.contains("Queue") &&
-// !fieldType.contains("Deque") &&
-// !fieldType.contains("Map")) {
-//
-// diagnostics.add(new Diagnostic(fieldAnnotationrange,
-// "This annotation can only be used on CharSequence, Collection, Array, "
-// + "Map type fields."));
-// }
-// }
- }
- }
- }
-
- private void checkStringOnly(IMember element, IType declaringType, List diagnostics,
- String annotationName, boolean isMethod, String type) throws JavaModelException {
- if (!type.equals(getSignatureFormatOfType(STRING))
- && !type.equals(getSignatureFormatOfType(CHAR_SEQUENCE))) {
- String source = isMethod ?
- Messages.getMessage("AnnotationStringMethods", "@" + annotationName) :
- Messages.getMessage("AnnotationStringFields", "@" + annotationName);
- diagnostics.add(createDiagnostic(element, declaringType.getCompilationUnit(),
- source, DIAGNOSTIC_CODE_INVALID_TYPE, annotationName, DiagnosticSeverity.Error));
- }
- }
-
- /*
- * Refer to Class signature documentation for the formating
- * https://www.ibm.com/support/knowledgecenter/sl/SS5JSH_9.5.0/org.eclipse.jdt.
- * doc.isv/reference/api/org/eclipse/jdt/core/Signature.html
- */
- private static String getSignatureFormatOfType(String type) {
- return "Q" + type + ";";
- }
-
- private static String getDataTypeName(String type) {
- int length = type.length();
- if (length > 0 && type.charAt(0) == 'Q' && type.charAt(length - 1) == ';') {
- return type.substring(1, length - 1);
- }
- return type;
- }
-}
\ No newline at end of file
diff --git a/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/core/beanvalidation/BeanValidationQuickFix.java b/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/core/beanvalidation/BeanValidationQuickFix.java
deleted file mode 100644
index 2bed96b0..00000000
--- a/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/core/beanvalidation/BeanValidationQuickFix.java
+++ /dev/null
@@ -1,90 +0,0 @@
-/*******************************************************************************
-* Copyright (c) 2021, 2023 IBM Corporation 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.
-*
-* SPDX-License-Identifier: EPL-2.0
-*
-* Contributors:
-* IBM Corporation - initial API and implementation
-*******************************************************************************/
-package org.eclipse.lsp4jakarta.jdt.core.beanvalidation;
-
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
-
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.jdt.core.dom.ASTNode;
-import org.eclipse.jdt.core.dom.IBinding;
-import org.eclipse.jdt.core.dom.VariableDeclarationFragment;
-import org.eclipse.jdt.internal.corext.dom.Bindings;
-import org.eclipse.lsp4j.CodeAction;
-import org.eclipse.lsp4j.Diagnostic;
-import org.eclipse.lsp4jakarta.jdt.codeAction.IJavaCodeActionParticipant;
-import org.eclipse.lsp4jakarta.jdt.codeAction.JavaCodeActionContext;
-import org.eclipse.lsp4jakarta.jdt.codeAction.proposal.ChangeCorrectionProposal;
-import org.eclipse.lsp4jakarta.jdt.codeAction.proposal.DeleteAnnotationProposal;
-import org.eclipse.lsp4jakarta.jdt.codeAction.proposal.ModifyModifiersProposal;
-import org.eclipse.lsp4jakarta.jdt.core.Messages;
-
-/**
- * Quickfix for fixing {@link BeanValidationConstants#DIAGNOSTIC_CODE_Static} error by either action
- * 1. Removing constraint annotation on static field or method
- * 2. Removing static modifier from field or method
- *
- * @author Leslie Dawson (lamminade)
- *
- */
-public class BeanValidationQuickFix implements IJavaCodeActionParticipant {
-
- @Override
- public List extends CodeAction> getCodeActions(JavaCodeActionContext context, Diagnostic diagnostic,
- IProgressMonitor monitor) throws CoreException {
- ASTNode node = context.getCoveredNode();
- IBinding parentType = getBinding(node);
-
- List codeActions = new ArrayList<>();
- codeActions.add(removeConstraintAnnotations(diagnostic, context, parentType));
-
- if (diagnostic.getCode().getLeft().equals(BeanValidationConstants.DIAGNOSTIC_CODE_STATIC)) {
- codeActions.add(removeStaticModifier(diagnostic, context, parentType));
- }
-
- return codeActions;
- }
-
- private CodeAction removeConstraintAnnotations(Diagnostic diagnostic, JavaCodeActionContext context, IBinding parentType) throws CoreException {
- String annotationName = diagnostic.getData().toString().replace("\"", "");
- String name = Messages.getMessage("RemoveConstraintAnnotation", annotationName);
- ChangeCorrectionProposal proposal = new DeleteAnnotationProposal(name, context.getCompilationUnit(),
- context.getASTRoot(), parentType, 0, context.getCoveredNode().getParent(), annotationName);
- CodeAction codeAction = context.convertToCodeAction(proposal, diagnostic);
- if (codeAction != null) {
- return codeAction;
- }
- return null;
- }
-
- private CodeAction removeStaticModifier(Diagnostic diagnostic, JavaCodeActionContext context, IBinding parentType) throws CoreException {
- String name = Messages.getMessage("RemoveStaticModifier");
- ModifyModifiersProposal proposal = new ModifyModifiersProposal(name, context.getCompilationUnit(),
- context.getASTRoot(), parentType, 0, context.getCoveredNode().getParent(), new ArrayList<>(), Arrays.asList("static"));
- CodeAction codeAction = context.convertToCodeAction(proposal, diagnostic);
-
- if (codeAction != null) {
- return codeAction;
- }
- return null;
- }
-
- protected IBinding getBinding(ASTNode node) {
- if (node.getParent() instanceof VariableDeclarationFragment) {
- return ((VariableDeclarationFragment) node.getParent()).resolveBinding();
- }
- return Bindings.getBindingOfParentType(node);
- }
-}
\ No newline at end of file
diff --git a/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/core/cdi/ConflictProducesInjectQuickFix.java b/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/core/cdi/ConflictProducesInjectQuickFix.java
deleted file mode 100644
index faedd629..00000000
--- a/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/core/cdi/ConflictProducesInjectQuickFix.java
+++ /dev/null
@@ -1,33 +0,0 @@
-/*******************************************************************************
-* Copyright (c) 2021 IBM Corporation 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:
-* IBM Corporation, Jianing Xu - initial API and implementation
-*******************************************************************************/
-
-package org.eclipse.lsp4jakarta.jdt.core.cdi;
-
-import org.eclipse.lsp4jakarta.jdt.codeAction.proposal.quickfix.RemoveAnnotationConflictQuickFix;
-
-/**
- *
- * Quick fix for removing @Produces/@Inject when they are used for the same field
- * or property
- *
- * @author Jianing Xu
- *
- */
-public class ConflictProducesInjectQuickFix extends RemoveAnnotationConflictQuickFix {
-
- public ConflictProducesInjectQuickFix() {
- super(false, "jakarta.enterprise.inject.Produces", "jakarta.inject.Inject");
- }
-
-}
diff --git a/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/core/cdi/ManagedBeanConstructorQuickFix.java b/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/core/cdi/ManagedBeanConstructorQuickFix.java
deleted file mode 100644
index 537b9681..00000000
--- a/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/core/cdi/ManagedBeanConstructorQuickFix.java
+++ /dev/null
@@ -1,35 +0,0 @@
-/*******************************************************************************
-* Copyright (c) 2021 IBM Corporation.
-*
-* 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.
-*
-* SPDX-License-Identifier: EPL-2.0
-*
-* Contributors:
-* Hani Damlaj
-*******************************************************************************/
-
-package org.eclipse.lsp4jakarta.jdt.core.cdi;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.jdt.core.dom.ASTNode;
-import org.eclipse.jdt.core.dom.IBinding;
-import org.eclipse.jdt.core.dom.MethodDeclaration;
-import org.eclipse.jdt.core.dom.VariableDeclarationFragment;
-import org.eclipse.jdt.internal.corext.dom.Bindings;
-import org.eclipse.lsp4j.CodeAction;
-import org.eclipse.lsp4j.Diagnostic;
-import org.eclipse.lsp4jakarta.jdt.codeAction.JavaCodeActionContext;
-import org.eclipse.lsp4jakarta.jdt.codeAction.proposal.quickfix.InsertAnnotationMissingQuickFix;
-
-public class ManagedBeanConstructorQuickFix extends InsertAnnotationMissingQuickFix {
- public ManagedBeanConstructorQuickFix() {
- super("jakarta.inject.Inject");
- }
-}
diff --git a/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/core/cdi/ManagedBeanDiagnosticsCollector.java b/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/core/cdi/ManagedBeanDiagnosticsCollector.java
deleted file mode 100644
index 9d439934..00000000
--- a/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/core/cdi/ManagedBeanDiagnosticsCollector.java
+++ /dev/null
@@ -1,395 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2021, 2023 IBM Corporation.
- *
- * 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.
- *
- * SPDX-License-Identifier: EPL-2.0
- *
- * Contributors:
- * Hani Damlaj, Jianing Xu
- *******************************************************************************/
-
-package org.eclipse.lsp4jakarta.jdt.core.cdi;
-
-import static org.eclipse.lsp4jakarta.jdt.core.cdi.ManagedBeanConstants.CONSTRUCTOR_DIAGNOSTIC_CODE;
-import static org.eclipse.lsp4jakarta.jdt.core.cdi.ManagedBeanConstants.DEPENDENT;
-import static org.eclipse.lsp4jakarta.jdt.core.cdi.ManagedBeanConstants.DEPENDENT_FQ_NAME;
-import static org.eclipse.lsp4jakarta.jdt.core.cdi.ManagedBeanConstants.DIAGNOSTIC_CODE;
-import static org.eclipse.lsp4jakarta.jdt.core.cdi.ManagedBeanConstants.DIAGNOSTIC_CODE_SCOPEDECL;
-import static org.eclipse.lsp4jakarta.jdt.core.cdi.ManagedBeanConstants.DIAGNOSTIC_SOURCE;
-import static org.eclipse.lsp4jakarta.jdt.core.cdi.ManagedBeanConstants.DISPOSES;
-import static org.eclipse.lsp4jakarta.jdt.core.cdi.ManagedBeanConstants.DISPOSES_FQ_NAME;
-import static org.eclipse.lsp4jakarta.jdt.core.cdi.ManagedBeanConstants.INJECT;
-import static org.eclipse.lsp4jakarta.jdt.core.cdi.ManagedBeanConstants.INJECT_FQ_NAME;
-import static org.eclipse.lsp4jakarta.jdt.core.cdi.ManagedBeanConstants.INVALID_INJECT_PARAMS_FQ;
-import static org.eclipse.lsp4jakarta.jdt.core.cdi.ManagedBeanConstants.OBSERVES_ASYNC_FQ_NAME;
-import static org.eclipse.lsp4jakarta.jdt.core.cdi.ManagedBeanConstants.OBSERVES_FQ_NAME;
-import static org.eclipse.lsp4jakarta.jdt.core.cdi.ManagedBeanConstants.PRODUCES;
-import static org.eclipse.lsp4jakarta.jdt.core.cdi.ManagedBeanConstants.PRODUCES_FQ_NAME;
-import static org.eclipse.lsp4jakarta.jdt.core.cdi.ManagedBeanConstants.SCOPE_FQ_NAMES;
-
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Set;
-import java.util.TreeSet;
-import java.util.stream.Collectors;
-import java.util.stream.Stream;
-
-import org.eclipse.jdt.core.Flags;
-import org.eclipse.jdt.core.IAnnotation;
-import org.eclipse.jdt.core.ICompilationUnit;
-import org.eclipse.jdt.core.IField;
-import org.eclipse.jdt.core.ILocalVariable;
-import org.eclipse.jdt.core.IMethod;
-import org.eclipse.jdt.core.IType;
-import org.eclipse.jdt.core.JavaModelException;
-import org.eclipse.lsp4j.Diagnostic;
-import org.eclipse.lsp4j.DiagnosticSeverity;
-import org.eclipse.lsp4jakarta.jdt.core.AbstractDiagnosticsCollector;
-import org.eclipse.lsp4jakarta.jdt.core.JakartaCorePlugin;
-import org.eclipse.lsp4jakarta.jdt.core.Messages;
-
-import com.google.gson.Gson;
-import com.google.gson.JsonArray;
-
-public class ManagedBeanDiagnosticsCollector extends AbstractDiagnosticsCollector {
-
- public ManagedBeanDiagnosticsCollector() {
- super();
- }
-
- @Override
- protected String getDiagnosticSource() {
- return DIAGNOSTIC_SOURCE;
- }
-
- @Override
- public void collectDiagnostics(ICompilationUnit unit, List diagnostics) {
- if (unit == null)
- return;
-
- try {
- IType[] types = unit.getAllTypes();
- String[] scopeFQNames = SCOPE_FQ_NAMES.toArray(String[]::new);
- for (IType type : types) {
- List managedBeanAnnotations = getMatchedJavaElementNames(type, Stream.of(type.getAnnotations())
- .map(annotation -> annotation.getElementName()).toArray(String[]::new),
- scopeFQNames);
- boolean isManagedBean = managedBeanAnnotations.size() > 0;
-
- if (managedBeanAnnotations.size() > 1) {
- // convert to simple name
- List diagnosticData = managedBeanAnnotations.stream()
- .map(annotation -> getSimpleName(annotation)).collect(Collectors.toList());
- diagnostics.add(createDiagnostic(type, unit,
- Messages.getMessage("ScopeTypeAnnotationsManagedBean"),
- DIAGNOSTIC_CODE_SCOPEDECL, (JsonArray) (new Gson().toJsonTree(diagnosticData)),
- DiagnosticSeverity.Error));
- }
-
- String[] injectAnnotations = { PRODUCES_FQ_NAME, INJECT_FQ_NAME };
- IField fields[] = type.getFields();
- for (IField field : fields) {
- int fieldFlags = field.getFlags();
- String[] annotationNames = Stream.of(field.getAnnotations())
- .map(annotation -> annotation.getElementName()).toArray(String[]::new);
- List fieldScopes = getMatchedJavaElementNames(type, annotationNames, scopeFQNames);
-
- /**
- * If a managed bean has a non-static public field, it must have
- * scope @Dependent. If a managed bean with a non-static public field declares
- * any scope other than @Dependent, the container automatically detects the
- * problem and treats it as a definition error.
- *
- * https://jakarta.ee/specifications/cdi/3.0/jakarta-cdi-spec-3.0.html#managed_beans
- */
- if (isManagedBean && Flags.isPublic(fieldFlags) && !Flags.isStatic(fieldFlags)
- && (fieldScopes.size() != 1 || !fieldScopes.get(0).equals(DEPENDENT_FQ_NAME))) {
- diagnostics.add(createDiagnostic(field, unit,
- Messages.getMessage("ManagedBeanWithNonStaticPublicField"),
- DIAGNOSTIC_CODE, null,
- DiagnosticSeverity.Error));
- }
-
- /**
- * https://jakarta.ee/specifications/cdi/3.0/jakarta-cdi-spec-3.0.html#declaring_bean_scope
- * A bean class or producer method or field may specify at most one scope type
- * annotation. If a bean class or producer method or field specifies multiple
- * scope type annotations, the container automatically detects the problem and
- * treats it as a definition error.
- *
- * Here we only look at the fields.
- */
- List fieldInjects = getMatchedJavaElementNames(type, annotationNames, injectAnnotations);
- boolean isProducerField = false, isInjectField = false;
- for (String annotation : fieldInjects) {
- if (PRODUCES_FQ_NAME.equals(annotation))
- isProducerField = true;
- else if (INJECT_FQ_NAME.equals(annotation))
- isInjectField = true;
- }
- if (isProducerField && fieldScopes.size() > 1) {
- List diagnosticData = fieldScopes.stream().map(annotation -> getSimpleName(annotation))
- .collect(Collectors.toList()); // convert to simple name
- diagnosticData.add(PRODUCES);
- diagnostics.add(createDiagnostic(field, unit,
- Messages.getMessage("ScopeTypeAnnotationsProducerField"),
- DIAGNOSTIC_CODE_SCOPEDECL, (JsonArray) (new Gson().toJsonTree(diagnosticData)),
- DiagnosticSeverity.Error));
- }
-
- if (isProducerField && isInjectField) {
- /*
- * ========= Produces and Inject Annotations Checks =========
- *
- * go through each field and method to make sure @Produces and @Inject are not used together
- *
- * see: https://jakarta.ee/specifications/cdi/3.0/jakarta-cdi-spec-3.0.html#declaring_producer_field
- * https://jakarta.ee/specifications/cdi/3.0/jakarta-cdi-spec-3.0.html#declaring_producer_method
- * https://jakarta.ee/specifications/cdi/3.0/jakarta-cdi-spec-3.0.html#declaring_injected_field
- * https://jakarta.ee/specifications/cdi/3.0/jakarta-cdi-spec-3.0.html#declaring_initializer
- */
-
- // A single field cannot have the same
- diagnostics.add(createDiagnostic(field, unit,
- Messages.getMessage("ManagedBeanProducesAndInject"),
- ManagedBeanConstants.DIAGNOSTIC_CODE_PRODUCES_INJECT, null, DiagnosticSeverity.Error));
- }
-
- }
-
- IMethod[] methods = type.getMethods();
- List constructorMethods = new ArrayList();
- for (IMethod method : methods) {
-
- // Find all methods on the type that are constructors.
- if (isConstructorMethod(method))
- constructorMethods.add(method);
-
- /**
- * https://jakarta.ee/specifications/cdi/3.0/jakarta-cdi-spec-3.0.html#declaring_bean_scope
- * A bean class or producer method or field may specify at most one scope type
- * annotation. If a bean class or producer method or field specifies multiple
- * scope type annotations, the container automatically detects the problem and
- * treats it as a definition error.
- *
- * Here we only look at the methods.
- */
- String[] annotationNames = Stream.of(method.getAnnotations())
- .map(annotation -> annotation.getElementName()).toArray(String[]::new);
- List methodScopes = getMatchedJavaElementNames(type, annotationNames, scopeFQNames);
- List methodInjects = getMatchedJavaElementNames(type, annotationNames, injectAnnotations);
- boolean isProducerMethod = false, isInjectMethod = false;
- for (String annotation : methodInjects) {
- if (PRODUCES_FQ_NAME.equals(annotation))
- isProducerMethod = true;
- else if (INJECT_FQ_NAME.equals(annotation))
- isInjectMethod = true;
- }
-
- if (isProducerMethod && methodScopes.size() > 1) {
- List diagnosticData = methodScopes.stream().map(annotation -> getSimpleName(annotation))
- .collect(Collectors.toList()); // convert to simple name
- diagnosticData.add(PRODUCES);
- diagnostics.add(createDiagnostic(method, unit,
- Messages.getMessage("ScopeTypeAnnotationsProducerMethod"),
- DIAGNOSTIC_CODE_SCOPEDECL, (JsonArray) (new Gson().toJsonTree(diagnosticData)),
- DiagnosticSeverity.Error));
- }
-
- if (isProducerMethod && isInjectMethod) {
- /*
- * ========= Produces and Inject Annotations Checks =========
- *
- * go through each field and method to make sure @Produces and @Inject are not used together
- *
- * see: https://jakarta.ee/specifications/cdi/3.0/jakarta-cdi-spec-3.0.html#declaring_producer_field
- * https://jakarta.ee/specifications/cdi/3.0/jakarta-cdi-spec-3.0.html#declaring_producer_method
- * https://jakarta.ee/specifications/cdi/3.0/jakarta-cdi-spec-3.0.html#declaring_injected_field
- * https://jakarta.ee/specifications/cdi/3.0/jakarta-cdi-spec-3.0.html#declaring_initializer
- */
-
- // A single method cannot have the same
- diagnostics.add(createDiagnostic(method, unit,
- Messages.getMessage("ManagedBeanProducesAndInject"),
- ManagedBeanConstants.DIAGNOSTIC_CODE_PRODUCES_INJECT, null, DiagnosticSeverity.Error));
- }
-
- }
-
- if (isManagedBean && constructorMethods.size() > 0) {
- /**
- * If the managed bean does not have a constructor that takes no parameters, it
- * must have a constructor annotated @Inject. No additional special annotations
- * are required.
- */
-
- // If there are no constructor methods, there is an implicit empty constructor
- // generated by the compiler.
- List methodsNeedingDiagnostics = new ArrayList();
- for (IMethod m : constructorMethods) {
- if (m.getNumberOfParameters() == 0) {
- methodsNeedingDiagnostics.clear();
- break;
- }
- IAnnotation[] annotations = m.getAnnotations();
- boolean hasParameterizedInjectConstructor = false;
- // look up '@Inject' annotation
- for (IAnnotation annotation : annotations) {
- if (isMatchedJavaElement(type, annotation.getElementName(), INJECT_FQ_NAME)) {
- hasParameterizedInjectConstructor = true;
- break;
- }
- }
- if (hasParameterizedInjectConstructor) {
- methodsNeedingDiagnostics.clear();
- break;
- } else
- methodsNeedingDiagnostics.add(m);
- }
-
- // Deliver a diagnostic on all parameterized constructors that they must add an
- // @Inject annotation
- for (IMethod m : methodsNeedingDiagnostics) {
- diagnostics.add(createDiagnostic(m, unit, Messages.getMessage("ManagedBeanConstructorWithParameters"),
- CONSTRUCTOR_DIAGNOSTIC_CODE, null, DiagnosticSeverity.Error));
- }
- }
-
- /**
- * If a managed bean class is of generic type, it must be annotated with @Dependent
- */
- if (isManagedBean) {
- boolean isClassGeneric = type.getTypeParameters().length != 0;
- boolean isDependent = managedBeanAnnotations.stream()
- .anyMatch(annotation -> DEPENDENT_FQ_NAME.equals(annotation));
-
- if (isClassGeneric && !isDependent) {
- diagnostics.add(createDiagnostic(type, unit, Messages.getMessage("ManagedBeanGenericType"),
- DIAGNOSTIC_CODE, null, DiagnosticSeverity.Error));
- }
- }
-
- /*
- * ========= Inject and Disposes, Observes, ObservesAsync Annotations Checks=========
- */
- /*
- * go through each method to make sure @Inject
- * and @Disposes, @Observes, @ObservesAsync are not used together
- *
- * see: https://jakarta.ee/specifications/cdi/3.0/jakarta-cdi-spec-3.0.html#declaring_bean_constructor
- * https://jakarta.ee/specifications/cdi/3.0/jakarta-cdi-spec-3.0.html#declaring_initializer
- *
- */
- invalidParamsCheck(unit, diagnostics, type, INJECT_FQ_NAME,
- ManagedBeanConstants.DIAGNOSTIC_CODE_INVALID_INJECT_PARAM);
-
- if (isManagedBean) {
- /*
- * ========= Produces and Disposes, Observes, ObservesAsync Annotations Checks=========
- */
- /*
- * go through each method to make sure @Produces
- * and @Disposes, @Observes, @ObservesAsync are not used together
- *
- * see: https://jakarta.ee/specifications/cdi/3.0/jakarta-cdi-spec-3.0.html#declaring_producer_method
- *
- * note:
- * we need to check for bean defining annotations first to make sure the managed bean is discovered.
- *
- */
- invalidParamsCheck(unit, diagnostics, type, PRODUCES_FQ_NAME,
- ManagedBeanConstants.DIAGNOSTIC_CODE_INVALID_PRODUCES_PARAM);
-
- for (IMethod method : methods) {
- int numDisposes = 0;
- Set invalidAnnotations = new TreeSet<>();
- ILocalVariable[] params = method.getParameters();
-
- for (ILocalVariable param : params) {
- IAnnotation[] annotations = param.getAnnotations();
- for (IAnnotation annotation : annotations) {
- String matchedAnnotation = getMatchedJavaElementName(type, annotation.getElementName(),
- INVALID_INJECT_PARAMS_FQ);
- if (DISPOSES_FQ_NAME.equals(matchedAnnotation)) {
- numDisposes++;
- } else if (OBSERVES_FQ_NAME.equals(matchedAnnotation)
- || OBSERVES_ASYNC_FQ_NAME.equals(matchedAnnotation)) {
- invalidAnnotations.add("@" + annotation.getElementName());
- }
- }
- }
-
- if(numDisposes == 0) continue;
- if(numDisposes > 1) {
- diagnostics.add(createDiagnostic(method, unit,
- Messages.getMessage("ManagedBeanDisposeOneParameter"),
- ManagedBeanConstants.DIAGNOSTIC_CODE_REDUNDANT_DISPOSES, null,
- DiagnosticSeverity.Error));
- }
-
- if(!invalidAnnotations.isEmpty()) {
- diagnostics.add(createDiagnostic(method, unit,
- createInvalidDisposesLabel(invalidAnnotations),
- ManagedBeanConstants.DIAGNOSTIC_CODE_INVALID_DISPOSES_PARAM, null,
- DiagnosticSeverity.Error));
- }
- }
- }
- }
-
- } catch (JavaModelException e) {
- JakartaCorePlugin.logException("Cannot calculate diagnostics", e);
- }
- }
-
- private void invalidParamsCheck(ICompilationUnit unit, List diagnostics, IType type, String target,
- String diagnosticCode) throws JavaModelException {
- for (IMethod method : type.getMethods()) {
- IAnnotation targetAnnotation = null;
-
- for (IAnnotation annotation : method.getAnnotations()) {
- if (isMatchedJavaElement(type, annotation.getElementName(), target)) {
- targetAnnotation = annotation;
- break;
- }
- }
-
- if (targetAnnotation == null)
- continue;
-
- Set invalidAnnotations = new TreeSet<>();
- ILocalVariable[] params = method.getParameters();
- for (ILocalVariable param : params) {
- List paramScopes = getMatchedJavaElementNames(type, Stream.of(param.getAnnotations())
- .map(annotation -> annotation.getElementName()).toArray(String[]::new),
- INVALID_INJECT_PARAMS_FQ);
- for (String annotation : paramScopes) {
- invalidAnnotations.add("@" + getSimpleName(annotation));
- }
- }
-
- if (!invalidAnnotations.isEmpty()) {
- String label = PRODUCES_FQ_NAME.equals(target) ?
- createInvalidProducesLabel(invalidAnnotations) :
- createInvalidInjectLabel(invalidAnnotations);
- diagnostics.add(createDiagnostic(method, unit, label, diagnosticCode, null, DiagnosticSeverity.Error));
- }
-
- }
- }
-
- private String createInvalidInjectLabel(Set invalidAnnotations) {
- return Messages.getMessage("ManagedBeanInvalidInject", String.join(", ", invalidAnnotations)); // assuming comma delimited list is ok
- }
-
- private String createInvalidProducesLabel(Set invalidAnnotations) {
- return Messages.getMessage("ManagedBeanInvalidProduces", String.join(", ", invalidAnnotations)); // assuming comma delimited list is ok
- }
-
- private String createInvalidDisposesLabel(Set invalidAnnotations) {
- return Messages.getMessage("ManagedBeanInvalidDisposer", String.join(", ", invalidAnnotations)); // assuming comma delimited list is ok
- }
-}
diff --git a/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/core/cdi/ManagedBeanNoArgConstructorQuickFix.java b/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/core/cdi/ManagedBeanNoArgConstructorQuickFix.java
deleted file mode 100644
index dbd322aa..00000000
--- a/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/core/cdi/ManagedBeanNoArgConstructorQuickFix.java
+++ /dev/null
@@ -1,90 +0,0 @@
-/*******************************************************************************
-* Copyright (c) 2021, 2023 IBM Corporation.
-*
-* 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.
-*
-* SPDX-License-Identifier: EPL-2.0
-*
-* Contributors:
-* Hani Damlaj
-*******************************************************************************/
-
-package org.eclipse.lsp4jakarta.jdt.core.cdi;
-
-import java.util.ArrayList;
-import java.util.HashSet;
-import java.util.List;
-
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.jdt.core.dom.ASTNode;
-import org.eclipse.jdt.core.dom.IBinding;
-import org.eclipse.jdt.core.dom.VariableDeclarationFragment;
-import org.eclipse.jdt.internal.corext.dom.Bindings;
-import org.eclipse.lsp4j.CodeAction;
-import org.eclipse.lsp4j.Diagnostic;
-import org.eclipse.lsp4jakarta.jdt.codeAction.IJavaCodeActionParticipant;
-import org.eclipse.lsp4jakarta.jdt.codeAction.JavaCodeActionContext;
-import org.eclipse.lsp4jakarta.jdt.codeAction.proposal.AddConstructorProposal;
-import org.eclipse.lsp4jakarta.jdt.codeAction.proposal.ChangeCorrectionProposal;
-import org.eclipse.lsp4jakarta.jdt.core.Messages;
-
-/**
- *
- * Quick fix for adding a `protected`/`public` no argument constructor
- * for a managed bean that do not have:
- * - a no argument constructor
- * - a constructor annotated with `@Inject`
- *
- */
-
-public class ManagedBeanNoArgConstructorQuickFix implements IJavaCodeActionParticipant {
-
- @Override
- public List extends CodeAction> getCodeActions(JavaCodeActionContext context, Diagnostic diagnostic,
- IProgressMonitor monitor) throws CoreException {
- List codeActions = new ArrayList<>();
- ASTNode node = context.getCoveredNode();
- IBinding parentType = getBinding(node);
- if (parentType != null) {
- codeActions.addAll(addConstructor(diagnostic, context, parentType));
- }
- return codeActions;
- }
-
- protected static IBinding getBinding(ASTNode node) {
- if (node.getParent() instanceof VariableDeclarationFragment) {
- VariableDeclarationFragment fragment = (VariableDeclarationFragment) node.getParent();
- return ((VariableDeclarationFragment) node.getParent()).resolveBinding();
- }
- return Bindings.getBindingOfParentType(node);
- }
-
- private List addConstructor(Diagnostic diagnostic, JavaCodeActionContext context, IBinding parentType) throws CoreException {
- List codeActions = new ArrayList<>();
-
- // option for protected constructor
- String name = Messages.getMessage("AddProtectedConstructor");
- ChangeCorrectionProposal proposal = new AddConstructorProposal(name,
- context.getCompilationUnit(), context.getASTRoot(), parentType, 0);
- CodeAction codeAction = context.convertToCodeAction(proposal, diagnostic);
-
- if (codeAction != null) {
- codeActions.add(codeAction);
- }
-
- // option for public constructor
- name = Messages.getMessage("AddPublicConstructor");
- proposal = new AddConstructorProposal(name,
- context.getCompilationUnit(), context.getASTRoot(), parentType, 0, "public");
- codeAction = context.convertToCodeAction(proposal, diagnostic);
-
- if (codeAction != null) {
- codeActions.add(codeAction);
- }
-
- return codeActions;
- }
-}
diff --git a/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/core/cdi/ManagedBeanQuickFix.java b/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/core/cdi/ManagedBeanQuickFix.java
deleted file mode 100644
index a7da0d80..00000000
--- a/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/core/cdi/ManagedBeanQuickFix.java
+++ /dev/null
@@ -1,74 +0,0 @@
-/*******************************************************************************
-* Copyright (c) 2020, 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:
-* Hani Damlaj
-*******************************************************************************/
-
-package org.eclipse.lsp4jakarta.jdt.core.cdi;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.jdt.core.dom.ASTNode;
-import org.eclipse.jdt.core.dom.IBinding;
-import org.eclipse.lsp4j.CodeAction;
-import org.eclipse.lsp4j.Diagnostic;
-import org.eclipse.lsp4jakarta.jdt.codeAction.JavaCodeActionContext;
-import org.eclipse.lsp4jakarta.jdt.codeAction.proposal.ChangeCorrectionProposal;
-import org.eclipse.lsp4jakarta.jdt.codeAction.proposal.ReplaceAnnotationProposal;
-import org.eclipse.lsp4jakarta.jdt.codeAction.proposal.quickfix.InsertAnnotationMissingQuickFix;
-import org.eclipse.lsp4jakarta.jdt.core.Messages;
-
-import static org.eclipse.lsp4jakarta.jdt.core.cdi.ManagedBeanConstants.*;
-
-public class ManagedBeanQuickFix extends InsertAnnotationMissingQuickFix {
- public ManagedBeanQuickFix() {
- super("jakarta.enterprise.context.Dependent");
- }
-
- private static final String[] REMOVE_ANNOTATION_NAMES = new ArrayList<>(SCOPES).toArray(new String[SCOPES.size()]);
-
- @Override
- protected void insertAnnotations(Diagnostic diagnostic, JavaCodeActionContext context, IBinding parentType,
- List codeActions) throws CoreException {
- String[] annotations = getAnnotations();
- for (String annotation : annotations) {
- insertAndReplaceAnnotation(diagnostic, context, parentType, codeActions, annotation);
- }
- }
-
- private static void insertAndReplaceAnnotation(Diagnostic diagnostic, JavaCodeActionContext context,
- IBinding parentType, List codeActions, String annotation) throws CoreException {
- // Diagnostic is reported on the variable declaration, however the
- // annotations that need to be replaced are on the type declaration (class
- // definition) containing the variable declaration. We retrieve the type
- // declaration container here.
- ASTNode parentNode = context.getASTRoot().findDeclaringNode(parentType);
- IBinding classBinding = getBinding(parentNode);
-
- // Insert the annotation and the proper import by using JDT Core Manipulation
- // API
- String name = getLabel(annotation);
- ChangeCorrectionProposal proposal = new ReplaceAnnotationProposal(name, context.getCompilationUnit(),
- context.getASTRoot(), classBinding, 0, annotation, REMOVE_ANNOTATION_NAMES);
- // Convert the proposal to LSP4J CodeAction
- CodeAction codeAction = context.convertToCodeAction(proposal, diagnostic);
- if (codeAction != null) {
- codeActions.add(codeAction);
- }
- }
-
- private static String getLabel(String annotation) {
- String annotationName = annotation.substring(annotation.lastIndexOf('.') + 1, annotation.length());
- return Messages.getMessage("ReplaceCurrentScope", "@" + annotationName);
- }
-}
diff --git a/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/core/cdi/RemoveInvalidInjectParamAnnotationQuickFix.java b/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/core/cdi/RemoveInvalidInjectParamAnnotationQuickFix.java
deleted file mode 100644
index a24ff0e1..00000000
--- a/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/core/cdi/RemoveInvalidInjectParamAnnotationQuickFix.java
+++ /dev/null
@@ -1,26 +0,0 @@
- /*******************************************************************************
- * Copyright (c) 2021 IBM Corporation 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.
- *
- * SPDX-License-Identifier: EPL-2.0
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
-*******************************************************************************/
-package org.eclipse.lsp4jakarta.jdt.core.cdi;
-
-import org.eclipse.lsp4jakarta.jdt.codeAction.proposal.quickfix.RemoveParamAnnotationQuickFix;
-
-/**
- * QuickFix for deleting any of @Disposes, @Observes and @ObservesAsync annotation for parameters
- */
-public class RemoveInvalidInjectParamAnnotationQuickFix extends RemoveParamAnnotationQuickFix {
-
- public RemoveInvalidInjectParamAnnotationQuickFix() {
- super(ManagedBeanConstants.INVALID_INJECT_PARAMS.toArray((String[]::new)));
- }
-
-}
diff --git a/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/core/cdi/RemoveProduceAnnotationQuickFix.java b/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/core/cdi/RemoveProduceAnnotationQuickFix.java
deleted file mode 100644
index 7f40c750..00000000
--- a/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/core/cdi/RemoveProduceAnnotationQuickFix.java
+++ /dev/null
@@ -1,27 +0,0 @@
-/*******************************************************************************
-* Copyright (c) 2021 IBM Corporation 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
-*
-* SPDX-License-Identifier: EPL-2.0
-*
-* Contributors:
-* IBM Corporation, Himanshu Chotwani - initial API and implementation
-*******************************************************************************/
-package org.eclipse.lsp4jakarta.jdt.core.cdi;
-
-import org.eclipse.lsp4jakarta.jdt.codeAction.proposal.quickfix.RemoveAnnotationConflictQuickFix;
-
-/**
- *
- * Quick fix for removing @Produces annotation
- *
- */
-public class RemoveProduceAnnotationQuickFix extends RemoveAnnotationConflictQuickFix {
-
- public RemoveProduceAnnotationQuickFix() {
- super(false, "jakarta.enterprise.inject.Produces");
- }
-}
diff --git a/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/core/cdi/ScopeDeclarationQuickFix.java b/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/core/cdi/ScopeDeclarationQuickFix.java
deleted file mode 100644
index f83d7130..00000000
--- a/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/core/cdi/ScopeDeclarationQuickFix.java
+++ /dev/null
@@ -1,69 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2021 IBM Corporation 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.
- *
- * SPDX-License-Identifier: EPL-2.0
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.lsp4jakarta.jdt.core.cdi;
-
-import java.util.ArrayList;
-import java.util.List;
-import java.util.stream.Collectors;
-import java.util.stream.IntStream;
-
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.jdt.core.dom.ASTNode;
-import org.eclipse.jdt.core.dom.IBinding;
-import org.eclipse.lsp4j.CodeAction;
-import org.eclipse.lsp4j.Diagnostic;
-import org.eclipse.lsp4jakarta.jdt.codeAction.JavaCodeActionContext;
-import org.eclipse.lsp4jakarta.jdt.codeAction.proposal.quickfix.RemoveAnnotationConflictQuickFix;
-
-import com.google.gson.JsonArray;
-
-public class ScopeDeclarationQuickFix extends RemoveAnnotationConflictQuickFix {
- public ScopeDeclarationQuickFix() {
- // annotation list to be derived from the diagnostic passed to
- // `getCodeActions()`
- super();
- }
-
- @Override
- public List extends CodeAction> getCodeActions(JavaCodeActionContext context, Diagnostic diagnostic,
- IProgressMonitor monitor) throws CoreException {
- List codeActions = new ArrayList<>();
- ASTNode node = context.getCoveredNode();
- IBinding parentType = getBinding(node);
-
- JsonArray diagnosticData = (JsonArray) diagnostic.getData();
-
- List annotations = IntStream.range(0, diagnosticData.size())
- .mapToObj(idx -> diagnosticData.get(idx).getAsString()).collect(Collectors.toList());
-
- annotations.remove(ManagedBeanConstants.PRODUCES);
-
- if (parentType != null) {
- /**
- * for each annotation, choose the current annotation to keep and remove the
- * rest since we can have at most one scope annotation.
- */
- for (String annotation : annotations) {
- List resultingAnnotations = new ArrayList<>(annotations);
- resultingAnnotations.remove(annotation);
-
- removeAnnotation(diagnostic, context, parentType, codeActions,
- resultingAnnotations.toArray(new String[] {}));
- }
-
- }
- return codeActions;
-
- }
-}
diff --git a/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/core/cdi/Utils.java b/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/core/cdi/Utils.java
deleted file mode 100644
index e72d8e4e..00000000
--- a/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/core/cdi/Utils.java
+++ /dev/null
@@ -1,31 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2021, 2022 IBM Corporation 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.
- *
- * SPDX-License-Identifier: EPL-2.0
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.lsp4jakarta.jdt.core.cdi;
-
-import org.eclipse.jdt.core.IType;
-
-import static org.eclipse.lsp4jakarta.jdt.core.cdi.ManagedBeanConstants.*;
-import static org.eclipse.lsp4jakarta.jdt.core.AnnotationUtil.getScopeAnnotations;
-
-public class Utils {
- /**
- * Detects if a class is a managed bean by looking for a bean defining
- * annotation.
- *
- * @param type the type representing the potential bean class
- * @return true if the class has a bean defining annotation.
- */
- static boolean isManagedBean(IType type) {
- return getScopeAnnotations(type, SCOPES).size() > 0;
- }
-}
\ No newline at end of file
diff --git a/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/core/di/ConflictInjectMultipleConstructorQuickFix.java b/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/core/di/ConflictInjectMultipleConstructorQuickFix.java
deleted file mode 100644
index 95a0bb8e..00000000
--- a/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/core/di/ConflictInjectMultipleConstructorQuickFix.java
+++ /dev/null
@@ -1,30 +0,0 @@
-/*******************************************************************************
-* Copyright (c) 2021 IBM Corporation 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
-*
-* SPDX-License-Identifier: EPL-2.0
-*
-* Contributors:
-* IBM Corporation, Ananya Rao
-*******************************************************************************/
-package org.eclipse.lsp4jakarta.jdt.core.di;
-
-import org.eclipse.lsp4jakarta.jdt.codeAction.proposal.quickfix.RemoveAnnotationConflictQuickFix;
-
-/**
- *
- * Quick fix for removing @Inject when it is used with more than one constructor.
- *
- * @author Ananya Rao
- *
- */
-
-public class ConflictInjectMultipleConstructorQuickFix extends RemoveAnnotationConflictQuickFix {
- public ConflictInjectMultipleConstructorQuickFix(){
- super(false, "jakarta.inject.Inject");
- }
-
-}
diff --git a/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/core/di/DependencyInjectionDiagnosticsCollector.java b/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/core/di/DependencyInjectionDiagnosticsCollector.java
deleted file mode 100644
index 22cfcf8b..00000000
--- a/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/core/di/DependencyInjectionDiagnosticsCollector.java
+++ /dev/null
@@ -1,153 +0,0 @@
-/*******************************************************************************
-* Copyright (c) 2021, 2023 IBM Corporation 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
-*
-* SPDX-License-Identifier: EPL-2.0
-*
-* Contributors:
-* IBM Corporation, Himanshu Chotwani - initial API and implementation
-* Ananya Rao - Diagnostic Collection for multiple constructors annotated with inject
-*******************************************************************************/
-
-package org.eclipse.lsp4jakarta.jdt.core.di;
-
-import static org.eclipse.lsp4jakarta.jdt.core.di.DependencyInjectionConstants.DIAGNOSTIC_CODE_INJECT_ABSTRACT;
-import static org.eclipse.lsp4jakarta.jdt.core.di.DependencyInjectionConstants.DIAGNOSTIC_CODE_INJECT_CONSTRUCTOR;
-import static org.eclipse.lsp4jakarta.jdt.core.di.DependencyInjectionConstants.DIAGNOSTIC_CODE_INJECT_FINAL;
-import static org.eclipse.lsp4jakarta.jdt.core.di.DependencyInjectionConstants.DIAGNOSTIC_CODE_INJECT_GENERIC;
-import static org.eclipse.lsp4jakarta.jdt.core.di.DependencyInjectionConstants.DIAGNOSTIC_CODE_INJECT_STATIC;
-import static org.eclipse.lsp4jakarta.jdt.core.di.DependencyInjectionConstants.DIAGNOSTIC_SOURCE;
-import static org.eclipse.lsp4jakarta.jdt.core.di.DependencyInjectionConstants.INJECT;
-import static org.eclipse.lsp4jakarta.jdt.core.di.DependencyInjectionConstants.INJECT_FQ_NAME;
-
-import java.util.ArrayList;
-import java.util.List;
-import java.util.stream.Stream;
-
-import org.eclipse.jdt.core.Flags;
-import org.eclipse.jdt.core.IAnnotation;
-import org.eclipse.jdt.core.ICompilationUnit;
-import org.eclipse.jdt.core.IField;
-import org.eclipse.jdt.core.IMethod;
-import org.eclipse.jdt.core.IType;
-import org.eclipse.jdt.core.JavaModelException;
-import org.eclipse.lsp4j.Diagnostic;
-import org.eclipse.lsp4j.DiagnosticSeverity;
-import org.eclipse.lsp4jakarta.jdt.core.AbstractDiagnosticsCollector;
-import org.eclipse.lsp4jakarta.jdt.core.JakartaCorePlugin;
-import org.eclipse.lsp4jakarta.jdt.core.Messages;
-
-/**
- *
- * jararta.annotation Diagnostics
- *
- * Diagnostic 1: @Inject fields cannot be final.
- * Diagnostic 2: @Inject methods cannot be final.
- * Diagnostic 3: @Inject methods cannot be abstract.
- * Diagnostic 4: @Inject methods cannot be static.
- * Diagnostic 5: @Inject methods cannot be generic.
- *
- * @see https://jakarta.ee/specifications/dependency-injection/2.0/jakarta-injection-spec-2.0.html
- *
- */
-
-public class DependencyInjectionDiagnosticsCollector extends AbstractDiagnosticsCollector {
-
- public DependencyInjectionDiagnosticsCollector() {
- super();
- }
-
- @Override
- protected String getDiagnosticSource() {
- return DIAGNOSTIC_SOURCE;
- }
-
- @Override
- public void collectDiagnostics(ICompilationUnit unit, List diagnostics) {
- if (unit == null)
- return;
-
- IType[] alltypes;
- try {
- alltypes = unit.getAllTypes();
- for (IType type : alltypes) {
- IField[] allFields = type.getFields();
- for (IField field : allFields) {
- if (Flags.isFinal(field.getFlags())
- && containsAnnotation(type, field.getAnnotations(), INJECT_FQ_NAME)) {
- String msg = Messages.getMessage("InjectNoFinalField");
- diagnostics.add(createDiagnostic(field, unit, msg,
- DIAGNOSTIC_CODE_INJECT_FINAL, field.getElementType(),
- DiagnosticSeverity.Error));
- }
- }
-
- List injectedConstructors = new ArrayList();
- IMethod[] allMethods = type.getMethods();
- for (IMethod method : allMethods) {
- int methodFlag = method.getFlags();
- boolean isFinal = Flags.isFinal(methodFlag);
- boolean isAbstract = Flags.isAbstract(methodFlag);
- boolean isStatic = Flags.isStatic(methodFlag);
- boolean isGeneric = method.getTypeParameters().length != 0;
-
- if (containsAnnotation(type, method.getAnnotations(), INJECT_FQ_NAME)) {
- if (isConstructorMethod(method))
- injectedConstructors.add(method);
- if (isFinal) {
- String msg = Messages.getMessage("InjectNoFinalMethod");
- diagnostics.add(createDiagnostic(method, unit, msg,
- DIAGNOSTIC_CODE_INJECT_FINAL, method.getElementType(),
- DiagnosticSeverity.Error));
- }
- if (isAbstract) {
- String msg = Messages.getMessage("InjectNoAbstractMethod");
- diagnostics.add(createDiagnostic(method, unit, msg,
- DIAGNOSTIC_CODE_INJECT_ABSTRACT, method.getElementType(),
- DiagnosticSeverity.Error));
- }
- if (isStatic) {
- String msg = Messages.getMessage("InjectNoStaticMethod");
- diagnostics.add(createDiagnostic(method, unit, msg,
- DIAGNOSTIC_CODE_INJECT_STATIC, method.getElementType(),
- DiagnosticSeverity.Error));
- }
-
- if (isGeneric) {
- String msg = Messages.getMessage("InjectNoGenericMethod");
- diagnostics.add(createDiagnostic(method, unit, msg,
- DIAGNOSTIC_CODE_INJECT_GENERIC, method.getElementType(),
- DiagnosticSeverity.Error));
- }
- }
- }
-
- // if more than one 'inject' constructor, add diagnostic to all constructors
- if (injectedConstructors.size() > 1) {
- String msg = Messages.getMessage("InjectMoreThanOneConstructor");
- for (IMethod m : injectedConstructors) {
- diagnostics.add(createDiagnostic(m, unit,msg,
- DIAGNOSTIC_CODE_INJECT_CONSTRUCTOR, null, DiagnosticSeverity.Error));
- }
- }
- }
- } catch (JavaModelException e) {
- JakartaCorePlugin.logException("Cannot calculate diagnostics", e);
- }
- }
-
- private boolean containsAnnotation(IType type, IAnnotation[] annotations, String annotationFQName) {
- return Stream.of(annotations).anyMatch(annotation -> {
- try {
- return isMatchedJavaElement(type, annotation.getElementName(), annotationFQName);
- } catch (JavaModelException e) {
- JakartaCorePlugin.logException("Cannot validate annotations", e);
- return false;
- }
- });
- }
-}
-
diff --git a/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/codeAction/AbstractJavaContext.java b/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/core/java/AbstractJavaContext.java
similarity index 84%
rename from jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/codeAction/AbstractJavaContext.java
rename to jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/core/java/AbstractJavaContext.java
index 1c0df323..a7d195f5 100644
--- a/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/codeAction/AbstractJavaContext.java
+++ b/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/core/java/AbstractJavaContext.java
@@ -11,8 +11,7 @@
* Contributors:
* Red Hat Inc. - initial API and implementation
*******************************************************************************/
-
-package org.eclipse.lsp4jakarta.jdt.codeAction;
+package org.eclipse.lsp4jakarta.jdt.core.java;
import java.util.HashMap;
import java.util.Map;
@@ -22,14 +21,12 @@
import org.eclipse.jdt.core.ITypeRoot;
import org.eclipse.jdt.core.dom.CompilationUnit;
import org.eclipse.jdt.internal.core.manipulation.dom.ASTResolving;
-
-import org.eclipse.lsp4jakarta.jdt.core.JDTUtils;
+import org.eclipse.lsp4jakarta.jdt.core.utils.IJDTUtils;
/**
- * Abstract class for Java context for a given compilation unit. Reused from
- * https://github.com/eclipse/lsp4mp/blob/master/microprofile.jdt/org.eclipse.lsp4mp.jdt.core/src/main/java/org/eclipse/lsp4mp/jdt/core/java/AbtractJavaContext.java
+ * Abstract class for Java context for a given compilation unit.
*
- * @author credit to Angelo ZERR
+ * @author Angelo ZERR
*
*/
public abstract class AbstractJavaContext {
@@ -38,13 +35,13 @@ public abstract class AbstractJavaContext {
private final ITypeRoot typeRoot;
- private final JDTUtils utils;
+ private final IJDTUtils utils;
private Map cache;
private CompilationUnit fASTRoot;
- public AbstractJavaContext(String uri, ITypeRoot typeRoot, JDTUtils utils) {
+ public AbstractJavaContext(String uri, ITypeRoot typeRoot, IJDTUtils utils) {
this.uri = uri;
this.typeRoot = typeRoot;
this.utils = utils;
@@ -63,14 +60,14 @@ public IJavaProject getJavaProject() {
return getTypeRoot().getJavaProject();
}
- public JDTUtils getUtils() {
+ public IJDTUtils getUtils() {
return utils;
}
/**
* Associates the specified value with the specified key in the cache.
*
- * @param key the key.
+ * @param key the key.
* @param value the value.
*/
public void put(String key, Object value) {
@@ -109,4 +106,4 @@ public void setASTRoot(CompilationUnit root) {
fASTRoot = root;
}
-}
\ No newline at end of file
+}
diff --git a/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/core/java/codeaction/ExtendedCodeAction.java b/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/core/java/codeaction/ExtendedCodeAction.java
new file mode 100644
index 00000000..5dd2e45d
--- /dev/null
+++ b/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/core/java/codeaction/ExtendedCodeAction.java
@@ -0,0 +1,88 @@
+/*******************************************************************************
+* Copyright (c) 2020 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 org.eclipse.lsp4jakarta.jdt.core.java.codeaction;
+
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.List;
+
+import org.apache.commons.lang3.StringUtils;
+import org.eclipse.lsp4j.CodeAction;
+
+/**
+ * Extends LSP CodeAction to store relevance information used to sort the code
+ * actions.
+ *
+ * @author Angelo ZERR
+ *
+ */
+public class ExtendedCodeAction extends CodeAction {
+
+ private static class CodeActionComparator implements Comparator {
+
+ @Override
+ public int compare(CodeAction ca1, CodeAction ca2) {
+ String k1 = ca1.getKind();
+ String k2 = ca2.getKind();
+ if (!StringUtils.isBlank(k1) && !StringUtils.isBlank(k2) && !k1.equals(k2)) {
+ return k1.compareTo(k2);
+ }
+
+ if (ca1 instanceof ExtendedCodeAction && ca2 instanceof ExtendedCodeAction) {
+ int r1 = ((ExtendedCodeAction) ca1).getRelevance();
+ int r2 = ((ExtendedCodeAction) ca2).getRelevance();
+ int relevanceDif = r2 - r1;
+ if (relevanceDif != 0) {
+ return relevanceDif;
+ }
+ }
+ return ca1.getTitle().compareToIgnoreCase(ca2.getTitle());
+ }
+ }
+
+ private static final CodeActionComparator CODE_ACTION_COMPARATOR = new CodeActionComparator();
+
+ private transient int relevance;
+
+ public ExtendedCodeAction(String name) {
+ super(name);
+ }
+
+ /**
+ * Returns the relevance.
+ *
+ * @return the relevance.
+ */
+ public int getRelevance() {
+ return relevance;
+ }
+
+ /**
+ * Sets the relevance
+ *
+ * @param relevance the relevance
+ */
+ public void setRelevance(int relevance) {
+ this.relevance = relevance;
+ }
+
+ /**
+ * Sort the given code actions list by using relevance information.
+ *
+ * @param codeActions code actions to sort
+ */
+ public static void sort(List codeActions) {
+ Collections.sort(codeActions, CODE_ACTION_COMPARATOR);
+ }
+}
diff --git a/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/codeAction/IInvocationContext.java b/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/core/java/codeaction/IInvocationContext.java
similarity index 91%
rename from jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/codeAction/IInvocationContext.java
rename to jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/core/java/codeaction/IInvocationContext.java
index 1fd625c6..53aeede5 100644
--- a/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/codeAction/IInvocationContext.java
+++ b/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/core/java/codeaction/IInvocationContext.java
@@ -12,16 +12,13 @@
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
-
-package org.eclipse.lsp4jakarta.jdt.codeAction;
+package org.eclipse.lsp4jakarta.jdt.core.java.codeaction;
import org.eclipse.jdt.core.ICompilationUnit;
import org.eclipse.jdt.core.dom.ASTNode;
import org.eclipse.jdt.core.dom.CompilationUnit;
/**
- * Reused from
- * https://github.com/eclipse/lsp4mp/blob/1fb9b326d89774f4404b30eabdba0e73d9c40c07/microprofile.jdt/org.eclipse.lsp4mp.jdt.core/src/main/java/org/eclipse/lsp4mp/jdt/core/java/codeaction/IInvocationContext.java
* Context information for quick fix and quick assist processors.
*
* Note: this interface is not intended to be implemented.
diff --git a/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/codeAction/IJavaCodeActionParticipant.java b/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/core/java/codeaction/IJavaCodeActionParticipant.java
similarity index 68%
rename from jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/codeAction/IJavaCodeActionParticipant.java
rename to jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/core/java/codeaction/IJavaCodeActionParticipant.java
index dab95cc6..93129446 100644
--- a/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/codeAction/IJavaCodeActionParticipant.java
+++ b/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/core/java/codeaction/IJavaCodeActionParticipant.java
@@ -11,8 +11,7 @@
* Contributors:
* Red Hat Inc. - initial API and implementation
*******************************************************************************/
-
-package org.eclipse.lsp4jakarta.jdt.codeAction;
+package org.eclipse.lsp4jakarta.jdt.core.java.codeaction;
import java.util.List;
@@ -22,13 +21,20 @@
import org.eclipse.lsp4j.Diagnostic;
/**
- * Java codeAction participants API. reused from
- * https://github.com/eclipse/lsp4mp/blob/b88710cc54170844717f655b9bff8bb4c4649a8d/microprofile.jdt/org.eclipse.lsp4mp.jdt.core/src/main/java/org/eclipse/lsp4mp/jdt/core/java/codeaction/IJavaCodeActionParticipant.java
+ * Java codeAction participants API.
*
- * @author credit to Angelo ZERR
+ * @author Angelo ZERR
*
*/
public interface IJavaCodeActionParticipant {
+
+ /**
+ * Returns the unique identifier of this code action participant.
+ *
+ * @return the unique identifier of this code action participant
+ */
+ String getParticipantId();
+
/**
* Returns true if the code actions are adaptable for the given context and
* false otherwise.
@@ -43,20 +49,27 @@ public interface IJavaCodeActionParticipant {
* @return true if adaptable and false otherwise.
*
*/
- default boolean isAdaptedForCodeAction(JavaCodeActionContext context, IProgressMonitor monitor)
- throws CoreException {
+ default boolean isAdaptedForCodeAction(JavaCodeActionContext context, IProgressMonitor monitor) throws CoreException {
return true;
}
/**
* Return the code action list for a given compilation unit and null otherwise.
*
- * @param context the java code action context.
+ * @param context the java code action context.
* @param diagnostic the diagnostic which must be fixed and null otherwise.
- * @param monitor the progress monitor
+ * @param monitor the progress monitor
* @return the code action list for a given compilation unit and null otherwise.
* @throws CoreException
*/
List extends CodeAction> getCodeActions(JavaCodeActionContext context, Diagnostic diagnostic,
- IProgressMonitor monitor) throws CoreException;
+ IProgressMonitor monitor) throws CoreException;
+
+ /**
+ * Returns the code action with the TextEdits filled in.
+ *
+ * @param unresolved the code action to resolve
+ * @return the code action with the TextEdits filled in
+ */
+ CodeAction resolveCodeAction(JavaCodeActionResolveContext context);
}
diff --git a/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/core/java/codeaction/InsertAnnotationAttributeQuickFix.java b/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/core/java/codeaction/InsertAnnotationAttributeQuickFix.java
new file mode 100644
index 00000000..939a97d1
--- /dev/null
+++ b/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/core/java/codeaction/InsertAnnotationAttributeQuickFix.java
@@ -0,0 +1,95 @@
+/*******************************************************************************
+* Copyright (c) 2021 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 org.eclipse.lsp4jakarta.jdt.core.java.codeaction;
+
+import java.text.MessageFormat;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.jdt.core.dom.ASTNode;
+import org.eclipse.jdt.core.dom.Annotation;
+import org.eclipse.lsp4j.CodeAction;
+import org.eclipse.lsp4j.CodeActionKind;
+import org.eclipse.lsp4j.Diagnostic;
+import org.eclipse.lsp4jakarta.commons.codeaction.CodeActionResolveData;
+import org.eclipse.lsp4jakarta.commons.codeaction.ICodeActionId;
+import org.eclipse.lsp4jakarta.jdt.core.java.corrections.proposal.ChangeCorrectionProposal;
+import org.eclipse.lsp4jakarta.jdt.core.java.corrections.proposal.InsertAnnotationAttributeProposal;
+
+/**
+ * QuickFix for inserting attribute of a given annotation.
+ *
+ * @author Angelo ZERR
+ *
+ */
+public abstract class InsertAnnotationAttributeQuickFix implements IJavaCodeActionParticipant {
+
+ private static final Logger LOGGER = Logger.getLogger(InsertAnnotationAttributeQuickFix.class.getName());
+
+ private static final String CODE_ACTION_LABEL = "Insert ''{0}'' attribute";
+
+ private final String attributeName;
+
+ /**
+ * Constructor for inserting attribute annotation quick fix.
+ *
+ * @param attribute name list of annotation to insert.
+ */
+ public InsertAnnotationAttributeQuickFix(String attributeName) {
+ this.attributeName = attributeName;
+ }
+
+ @Override
+ public List extends CodeAction> getCodeActions(JavaCodeActionContext context, Diagnostic diagnostic,
+ IProgressMonitor monitor) throws CoreException {
+ ExtendedCodeAction codeAction = new ExtendedCodeAction(getLabel(attributeName));
+ codeAction.setRelevance(0);
+ codeAction.setKind(CodeActionKind.QuickFix);
+ codeAction.setDiagnostics(Arrays.asList(diagnostic));
+ codeAction.setData(new CodeActionResolveData(context.getUri(), getParticipantId(), context.getParams().getRange(), null, context.getParams().isResourceOperationSupported(), context.getParams().isCommandConfigurationUpdateSupported(), getCodeActionId()));
+ return Collections.singletonList(codeAction);
+ }
+
+ @Override
+ public CodeAction resolveCodeAction(JavaCodeActionResolveContext context) {
+ CodeAction toResolve = context.getUnresolved();
+ ASTNode selectedNode = context.getCoveringNode();
+ Annotation annotation = (Annotation) selectedNode.getParent().getParent();
+ String name = getLabel(attributeName);
+ ChangeCorrectionProposal proposal = new InsertAnnotationAttributeProposal(name, context.getCompilationUnit(), annotation, 0, attributeName);
+ try {
+ toResolve.setEdit(context.convertToWorkspaceEdit(proposal));
+ } catch (CoreException e) {
+ LOGGER.log(Level.SEVERE, "Unable to resolve code action edit for inserting an attribute value", e);
+ }
+ return toResolve;
+ }
+
+ /**
+ * Returns the id for this code action.
+ *
+ * @return the id for this code action
+ */
+ protected abstract ICodeActionId getCodeActionId();
+
+ private static String getLabel(String memberName) {
+ return MessageFormat.format(CODE_ACTION_LABEL, memberName);
+ }
+
+}
diff --git a/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/core/java/codeaction/InsertAnnotationAttributesQuickFix.java b/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/core/java/codeaction/InsertAnnotationAttributesQuickFix.java
new file mode 100644
index 00000000..d4569fdd
--- /dev/null
+++ b/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/core/java/codeaction/InsertAnnotationAttributesQuickFix.java
@@ -0,0 +1,149 @@
+/*******************************************************************************
+* Copyright (c) 2023 IBM Corporation 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.
+*
+* SPDX-License-Identifier: EPL-2.0
+*
+* Contributors:
+* IBM Corporation - initial implementation
+*******************************************************************************/
+package org.eclipse.lsp4jakarta.jdt.core.java.codeaction;
+
+import java.text.MessageFormat;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.jdt.core.dom.ASTNode;
+import org.eclipse.jdt.core.dom.IBinding;
+import org.eclipse.jdt.core.dom.VariableDeclarationFragment;
+import org.eclipse.lsp4j.CodeAction;
+import org.eclipse.lsp4j.CodeActionKind;
+import org.eclipse.lsp4j.Diagnostic;
+import org.eclipse.lsp4jakarta.commons.codeaction.CodeActionResolveData;
+import org.eclipse.lsp4jakarta.commons.codeaction.ICodeActionId;
+import org.eclipse.lsp4jakarta.jdt.core.java.corrections.proposal.ChangeCorrectionProposal;
+import org.eclipse.lsp4jakarta.jdt.core.java.corrections.proposal.ModifyAnnotationProposal;
+
+/**
+ * Inserts the specified set of attributes the the specified annotation.
+ */
+public abstract class InsertAnnotationAttributesQuickFix implements IJavaCodeActionParticipant {
+ /** Logger object to record events for this class. */
+ private static final Logger LOGGER = Logger.getLogger(InsertAnnotationAttributesQuickFix.class.getName());
+
+ /** Code action label template. */
+ private static final String CODE_ACTION_LABEL = "Insert ''{0}'' attribute{1} to @{2}";
+
+ /** The annotation to which attributes are added. */
+ private final String annotation;
+
+ /** The attributes the add to the annotation. */
+ private final String[] attributes;
+
+ /**
+ * Constructor.
+ *
+ * @param annotation The fully qualified annotation to modify.
+ * @param attributes The attribute names to add to given annotation.
+ */
+ public InsertAnnotationAttributesQuickFix(String annotation, String... attributes) {
+ this.annotation = annotation;
+ this.attributes = attributes;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public String getParticipantId() {
+ return InsertAnnotationAttributesQuickFix.class.getName();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public List extends CodeAction> getCodeActions(JavaCodeActionContext context, Diagnostic diagnostic,
+ IProgressMonitor monitor) throws CoreException {
+ List codeActions = new ArrayList<>();
+ String name = getLabel(annotation, attributes);
+ ExtendedCodeAction codeAction = new ExtendedCodeAction(name);
+ codeAction.setRelevance(0);
+ codeAction.setDiagnostics(Collections.singletonList(diagnostic));
+ codeAction.setKind(CodeActionKind.QuickFix);
+
+ codeAction.setData(new CodeActionResolveData(context.getUri(), getParticipantId(), context.getParams().getRange(), null, context.getParams().isResourceOperationSupported(), context.getParams().isCommandConfigurationUpdateSupported(), getCodeActionId()));
+ codeActions.add(codeAction);
+
+ return codeActions;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public CodeAction resolveCodeAction(JavaCodeActionResolveContext context) {
+ CodeAction toResolve = context.getUnresolved();
+ String label = getLabel(annotation, attributes);
+ ASTNode node = context.getCoveringNode();
+ IBinding parentType = getBinding(node);
+ ChangeCorrectionProposal proposal = new ModifyAnnotationProposal(label, context.getCompilationUnit(), context.getASTRoot(), parentType, 0, Arrays.asList(attributes), annotation);
+
+ try {
+ toResolve.setEdit(context.convertToWorkspaceEdit(proposal));
+ } catch (CoreException e) {
+ LOGGER.log(Level.SEVERE,
+ "Unable to resolve code action edit for inserting an anotation with attributes",
+ e);
+ }
+
+ return toResolve;
+ }
+
+ /**
+ * Returns the id for this code action.
+ *
+ * @return The id for this code action.
+ */
+ protected abstract ICodeActionId getCodeActionId();
+
+ /**
+ * Returns the code action label.
+ *
+ * @param annotaiton The annotation name.
+ * @param attributes The attribute names.
+ *
+ * @return The code action label.
+ */
+ protected String getLabel(String annotation, String[] attributes) {
+ String[] parts = annotation.split("\\.");
+ String AnnotationName = (parts.length > 1) ? parts[parts.length - 1] : annotation;
+ String atributeNames = String.join(",", attributes);
+ String pluralSuffix = (attributes.length > 1) ? "s" : "";
+ return MessageFormat.format(CODE_ACTION_LABEL, atributeNames, pluralSuffix, AnnotationName);
+ }
+
+ /**
+ * Returns the named entity associated to the given node.
+ *
+ * @param node The AST Node
+ *
+ * @return The named entity associated to the given node.
+ */
+ @SuppressWarnings("restriction")
+ protected IBinding getBinding(ASTNode node) {
+ if (node.getParent() instanceof VariableDeclarationFragment) {
+ return ((VariableDeclarationFragment) node.getParent()).resolveBinding();
+ }
+ return org.eclipse.jdt.internal.corext.dom.Bindings.getBindingOfParentType(node);
+ }
+}
\ No newline at end of file
diff --git a/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/core/java/codeaction/InsertAnnotationMissingQuickFix.java b/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/core/java/codeaction/InsertAnnotationMissingQuickFix.java
new file mode 100644
index 00000000..9638edc0
--- /dev/null
+++ b/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/core/java/codeaction/InsertAnnotationMissingQuickFix.java
@@ -0,0 +1,182 @@
+/*******************************************************************************
+* Copyright (c) 2020 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 org.eclipse.lsp4jakarta.jdt.core.java.codeaction;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.jdt.core.dom.ASTNode;
+import org.eclipse.jdt.core.dom.IBinding;
+import org.eclipse.jdt.core.dom.VariableDeclarationFragment;
+import org.eclipse.jdt.internal.corext.dom.Bindings;
+import org.eclipse.lsp4j.CodeAction;
+import org.eclipse.lsp4j.CodeActionKind;
+import org.eclipse.lsp4j.Diagnostic;
+import org.eclipse.lsp4jakarta.commons.codeaction.CodeActionResolveData;
+import org.eclipse.lsp4jakarta.commons.codeaction.ICodeActionId;
+import org.eclipse.lsp4jakarta.jdt.core.java.corrections.proposal.ChangeCorrectionProposal;
+import org.eclipse.lsp4jakarta.jdt.core.java.corrections.proposal.InsertAnnotationProposal;
+
+/**
+ * QuickFix for inserting annotations.
+ *
+ * Based on:
+ * https://github.com/eclipse/lsp4mp/blob/0.9.0/microprofile.jdt/org.eclipse.lsp4mp.jdt.core/src/main/java/org/eclipse/lsp4mp/jdt/core/java/codeaction/InsertAnnotationMissingQuickFix.java
+ *
+ * @author Angelo ZERR
+ *
+ */
+public abstract class InsertAnnotationMissingQuickFix implements IJavaCodeActionParticipant {
+
+ private static final Logger LOGGER = Logger.getLogger(InsertAnnotationMissingQuickFix.class.getName());
+
+ protected static final String ANNOTATION_KEY = "annotation";
+
+ private final String[] annotations;
+
+ private final boolean generateOnlyOneCodeAction;
+
+ /**
+ * Constructor for insert annotation quick fix.
+ *
+ *
+ * The participant will generate a CodeAction per annotation.
+ *
+ *
+ * @param annotations list of annotation to insert.
+ */
+ public InsertAnnotationMissingQuickFix(String... annotations) {
+ this(false, annotations);
+ }
+
+ /**
+ * Constructor for insert annotation quick fix.
+ *
+ * @param generateOnlyOneCodeAction true if the participant must generate a
+ * CodeAction which insert the list of
+ * annotation and false otherwise.
+ * @param annotations list of annotation to insert.
+ */
+ public InsertAnnotationMissingQuickFix(boolean generateOnlyOneCodeAction, String... annotations) {
+ this.generateOnlyOneCodeAction = generateOnlyOneCodeAction;
+ this.annotations = annotations;
+ }
+
+ @Override
+ public List extends CodeAction> getCodeActions(JavaCodeActionContext context, Diagnostic diagnostic,
+ IProgressMonitor monitor) throws CoreException {
+ List codeActions = new ArrayList<>();
+ insertAnnotations(diagnostic, context, codeActions);
+ return codeActions;
+ }
+
+ @Override
+ public CodeAction resolveCodeAction(JavaCodeActionResolveContext context) {
+ CodeAction toResolve = context.getUnresolved();
+ CodeActionResolveData data = (CodeActionResolveData) toResolve.getData();
+ List resolveAnnotations = (List) data.getExtendedDataEntry(ANNOTATION_KEY);
+ String[] resolveAnnotationsArray = resolveAnnotations.toArray(String[]::new);
+ String name = getLabel(resolveAnnotationsArray);
+ ASTNode node = context.getCoveringNode();
+ IBinding parentType = getBinding(node);
+
+ ChangeCorrectionProposal proposal = new InsertAnnotationProposal(name, context.getCompilationUnit(), context.getASTRoot(), parentType, 0, resolveAnnotationsArray);
+ try {
+ toResolve.setEdit(context.convertToWorkspaceEdit(proposal));
+ } catch (CoreException e) {
+ LOGGER.log(Level.SEVERE, "Unable to create workspace edit for code action to insert missing annotation", e);
+ }
+
+ return toResolve;
+ }
+
+ protected IBinding getBinding(ASTNode node) {
+ if (node.getParent() instanceof VariableDeclarationFragment) {
+ return ((VariableDeclarationFragment) node.getParent()).resolveBinding();
+ }
+ return Bindings.getBindingOfParentType(node);
+ }
+
+ protected String[] getAnnotations() {
+ return this.annotations;
+ }
+
+ protected void insertAnnotations(Diagnostic diagnostic, JavaCodeActionContext context, List codeActions) throws CoreException {
+ if (generateOnlyOneCodeAction) {
+ insertAnnotation(diagnostic, context, codeActions, annotations);
+ } else {
+ for (String annotation : annotations) {
+ insertAnnotation(diagnostic, context, codeActions, annotation);
+ }
+ }
+ }
+
+ protected void insertAnnotation(Diagnostic diagnostic, JavaCodeActionContext context, List codeActions,
+ String... annotations) throws CoreException {
+ String name = getLabel(annotations);
+ ExtendedCodeAction codeAction = new ExtendedCodeAction(name);
+ codeAction.setRelevance(0);
+ codeAction.setDiagnostics(Collections.singletonList(diagnostic));
+ codeAction.setKind(CodeActionKind.QuickFix);
+
+ Map extendedData = new HashMap<>();
+ extendedData.put(ANNOTATION_KEY, Arrays.asList(annotations));
+ codeAction.setData(new CodeActionResolveData(context.getUri(), getParticipantId(), context.getParams().getRange(), extendedData, context.getParams().isResourceOperationSupported(), context.getParams().isCommandConfigurationUpdateSupported(), getCodeActionId()));
+
+ codeActions.add(codeAction);
+ }
+
+ private static String getLabel(String[] annotations) {
+ StringBuilder name = new StringBuilder("Insert ");
+ for (int i = 0; i < annotations.length; i++) {
+ String annotation = annotations[i];
+ String annotationName = annotation.substring(annotation.lastIndexOf('.') + 1, annotation.length());
+ if (i > 0) {
+ name.append(", ");
+ }
+ name.append("@");
+ name.append(annotationName);
+ }
+ return name.toString();
+ }
+
+ /**
+ * Returns the id for this code action.
+ *
+ * @return the id for this code action
+ */
+ protected abstract ICodeActionId getCodeActionId();
+
+ /**
+ * Returns true if all the listed annotations should be added in one code
+ * action, and false if separate code actions should be generated for each
+ * annotation.
+ *
+ * @return true if all the listed annotations should be added in one code
+ * action, and false if separate code actions should be generated for
+ * each annotation
+ */
+ protected boolean isGenerateOnlyOneCodeAction() {
+ return this.generateOnlyOneCodeAction;
+ }
+
+}
diff --git a/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/core/java/codeaction/InsertDefaultConstructorToClassQuickFix.java b/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/core/java/codeaction/InsertDefaultConstructorToClassQuickFix.java
new file mode 100644
index 00000000..c721a7fb
--- /dev/null
+++ b/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/core/java/codeaction/InsertDefaultConstructorToClassQuickFix.java
@@ -0,0 +1,130 @@
+package org.eclipse.lsp4jakarta.jdt.core.java.codeaction;
+
+import java.text.MessageFormat;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.jdt.core.dom.ASTNode;
+import org.eclipse.jdt.core.dom.IBinding;
+import org.eclipse.jdt.core.dom.VariableDeclarationFragment;
+import org.eclipse.lsp4j.CodeAction;
+import org.eclipse.lsp4j.CodeActionKind;
+import org.eclipse.lsp4j.Diagnostic;
+import org.eclipse.lsp4jakarta.commons.codeaction.CodeActionResolveData;
+import org.eclipse.lsp4jakarta.commons.codeaction.ICodeActionId;
+import org.eclipse.lsp4jakarta.jdt.core.java.corrections.proposal.AddConstructorProposal;
+import org.eclipse.lsp4jakarta.jdt.core.java.corrections.proposal.ChangeCorrectionProposal;
+
+/**
+ * Inserts default constructor to the active class.
+ */
+public abstract class InsertDefaultConstructorToClassQuickFix implements IJavaCodeActionParticipant {
+ /** Logger object to record events for this class. */
+ private static final Logger LOGGER = Logger.getLogger(InsertDefaultConstructorToClassQuickFix.class.getName());
+
+ /** Code action label template. */
+ private static final String CODE_ACTION_LABEL = "Add a default ''{0}'' constructor to this class";
+
+ /**
+ * Access modifier for the new constructor.
+ */
+ private final String accessModifier;
+
+ /**
+ * Constructor.
+ *
+ * @param accessModifier The access modifier to use.
+ */
+ public InsertDefaultConstructorToClassQuickFix(String accessModifier) {
+ this.accessModifier = accessModifier;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public String getParticipantId() {
+ return InsertDefaultConstructorToClassQuickFix.class.getName();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public List extends CodeAction> getCodeActions(JavaCodeActionContext context, Diagnostic diagnostic,
+ IProgressMonitor monitor) throws CoreException {
+ ASTNode node = context.getCoveredNode();
+ IBinding parentType = getBinding(node);
+ List codeActions = new ArrayList<>();
+ if (parentType != null) {
+ ExtendedCodeAction codeAction = new ExtendedCodeAction(getLabel(accessModifier));
+ codeAction.setRelevance(0);
+ codeAction.setKind(CodeActionKind.QuickFix);
+ codeAction.setDiagnostics(Arrays.asList(diagnostic));
+ codeAction.setData(new CodeActionResolveData(context.getUri(), getParticipantId(), context.getParams().getRange(), null, context.getParams().isResourceOperationSupported(), context.getParams().isCommandConfigurationUpdateSupported(), getCodeActionId()));
+ codeActions.add(codeAction);
+ }
+
+ return codeActions;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public CodeAction resolveCodeAction(JavaCodeActionResolveContext context) {
+ CodeAction toResolve = context.getUnresolved();
+ ASTNode node = context.getCoveredNode();
+ IBinding parentType = getBinding(node);
+ String label = getLabel(accessModifier);
+
+ ChangeCorrectionProposal proposal = new AddConstructorProposal(label, context.getCompilationUnit(), context.getASTRoot(), parentType, 0, accessModifier);
+ try {
+ toResolve.setEdit(context.convertToWorkspaceEdit(proposal));
+ } catch (CoreException e) {
+ LOGGER.log(Level.SEVERE, "Unable to resolve code action to insert a default constructor to class",
+ e);
+ }
+
+ return toResolve;
+ }
+
+ /**
+ * Returns the id for this code action.
+ *
+ * @return the id for this code action
+ */
+ protected abstract ICodeActionId getCodeActionId();
+
+ /**
+ * Returns the code action label.
+ *
+ * @param am The access modifier name.
+ *
+ * @return The code action label.
+ */
+ protected String getLabel(String am) {
+ return MessageFormat.format(CODE_ACTION_LABEL, am);
+ }
+
+ /**
+ * Returns the named entity associated to the given node.
+ *
+ * @param node The AST Node
+ *
+ * @return The named entity associated to the given node.
+ */
+ @SuppressWarnings("restriction")
+ protected IBinding getBinding(ASTNode node) {
+ if (node.getParent() instanceof VariableDeclarationFragment) {
+ return ((VariableDeclarationFragment) node.getParent()).resolveBinding();
+ }
+
+ return org.eclipse.jdt.internal.corext.dom.Bindings.getBindingOfParentType(node);
+ }
+}
diff --git a/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/codeAction/JavaCodeActionContext.java b/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/core/java/codeaction/JavaCodeActionContext.java
similarity index 70%
rename from jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/codeAction/JavaCodeActionContext.java
rename to jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/core/java/codeaction/JavaCodeActionContext.java
index f0d5e004..439ae6f2 100644
--- a/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/codeAction/JavaCodeActionContext.java
+++ b/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/core/java/codeaction/JavaCodeActionContext.java
@@ -11,8 +11,7 @@
* Contributors:
* Red Hat Inc. - initial API and implementation
*******************************************************************************/
-
-package org.eclipse.lsp4jakarta.jdt.codeAction;
+package org.eclipse.lsp4jakarta.jdt.core.java.codeaction;
import java.util.Arrays;
@@ -25,15 +24,15 @@
import org.eclipse.lsp4j.Diagnostic;
import org.eclipse.lsp4j.WorkspaceEdit;
import org.eclipse.lsp4jakarta.commons.JakartaJavaCodeActionParams;
-import org.eclipse.lsp4jakarta.jdt.core.JDTUtils;
-import org.eclipse.lsp4jakarta.jdt.codeAction.proposal.ChangeCorrectionProposal;
-import org.eclipse.lsp4jakarta.jdt.core.ChangeUtil;
+import org.eclipse.lsp4jakarta.jdt.core.java.AbstractJavaContext;
+import org.eclipse.lsp4jakarta.jdt.core.java.corrections.proposal.ChangeCorrectionProposal;
+import org.eclipse.lsp4jakarta.jdt.core.utils.IJDTUtils;
+import org.eclipse.lsp4jakarta.jdt.internal.core.java.ChangeUtil;
/**
- * Java codeAction context for a given compilation unit. Reused from
- * https://github.com/eclipse/lsp4mp/blob/b88710cc54170844717f655b9bff8bb4c4649a8d/microprofile.jdt/org.eclipse.lsp4mp.jdt.core/src/main/java/org/eclipse/lsp4mp/jdt/core/java/codeaction/JavaCodeActionContext.java
- *
- * @author credit to Angelo ZERR
+ * Java codeAction context for a given compilation unit.
+ *
+ * @author Angelo ZERR
*
*/
public class JavaCodeActionContext extends AbstractJavaContext implements IInvocationContext {
@@ -44,8 +43,8 @@ public class JavaCodeActionContext extends AbstractJavaContext implements IInvoc
private final JakartaJavaCodeActionParams params;
private NodeFinder fNodeFinder;
- public JavaCodeActionContext(ITypeRoot typeRoot, int selectionOffset, int selectionLength, JDTUtils utils,
- JakartaJavaCodeActionParams params) {
+ public JavaCodeActionContext(ITypeRoot typeRoot, int selectionOffset, int selectionLength, IJDTUtils utils,
+ JakartaJavaCodeActionParams params) {
super(params.getUri(), typeRoot, utils);
this.selectionOffset = selectionOffset;
this.selectionLength = selectionLength;
@@ -97,20 +96,28 @@ public ASTNode getCoveredNode() {
return fNodeFinder.getCoveredNode();
}
- public CodeAction convertToCodeAction(ChangeCorrectionProposal proposal, Diagnostic... diagnostics)
- throws CoreException {
+ public CodeAction convertToCodeAction(ChangeCorrectionProposal proposal, Diagnostic... diagnostics) throws CoreException {
String name = proposal.getName();
WorkspaceEdit edit = ChangeUtil.convertToWorkspaceEdit(proposal.getChange(), getUri(), getUtils(),
- params.isResourceOperationSupported());
+ params.isResourceOperationSupported());
if (!ChangeUtil.hasChanges(edit)) {
return null;
}
- CodeAction codeAction = new CodeAction();
- codeAction.setTitle(name);
+ ExtendedCodeAction codeAction = new ExtendedCodeAction(name);
+ codeAction.setRelevance(proposal.getRelevance());
codeAction.setKind(proposal.getKind());
codeAction.setEdit(edit);
codeAction.setDiagnostics(Arrays.asList(diagnostics));
return codeAction;
}
+ public WorkspaceEdit convertToWorkspaceEdit(ChangeCorrectionProposal proposal) throws CoreException {
+ WorkspaceEdit edit = ChangeUtil.convertToWorkspaceEdit(proposal.getChange(), getUri(), getUtils(),
+ params.isResourceOperationSupported());
+ if (!ChangeUtil.hasChanges(edit)) {
+ return null;
+ }
+ return edit;
+ }
+
}
diff --git a/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/core/java/codeaction/JavaCodeActionResolveContext.java b/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/core/java/codeaction/JavaCodeActionResolveContext.java
new file mode 100644
index 00000000..a99c6a0f
--- /dev/null
+++ b/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/core/java/codeaction/JavaCodeActionResolveContext.java
@@ -0,0 +1,39 @@
+/*******************************************************************************
+* Copyright (c) 2022 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 org.eclipse.lsp4jakarta.jdt.core.java.codeaction;
+
+import org.eclipse.jdt.core.ITypeRoot;
+import org.eclipse.lsp4j.CodeAction;
+import org.eclipse.lsp4jakarta.commons.JakartaJavaCodeActionParams;
+import org.eclipse.lsp4jakarta.jdt.core.utils.IJDTUtils;
+
+/**
+ * Similar to {@see JavaCodeActionContext}, but includes additional information
+ * needed for code action resolve.
+ *
+ * @auhtod datho7561
+ */
+public class JavaCodeActionResolveContext extends JavaCodeActionContext {
+
+ private final CodeAction unresolved;
+
+ public JavaCodeActionResolveContext(ITypeRoot typeRoot, int selectionOffset, int selectionLength, IJDTUtils utils,
+ JakartaJavaCodeActionParams params, CodeAction unresolved) {
+ super(typeRoot, selectionOffset, selectionLength, utils, params);
+ this.unresolved = unresolved;
+ }
+
+ public CodeAction getUnresolved() {
+ return this.unresolved;
+ }
+
+}
diff --git a/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/core/java/codeaction/RemoveAnnotationConflictQuickFix.java b/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/core/java/codeaction/RemoveAnnotationConflictQuickFix.java
new file mode 100644
index 00000000..fb765655
--- /dev/null
+++ b/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/core/java/codeaction/RemoveAnnotationConflictQuickFix.java
@@ -0,0 +1,213 @@
+/*******************************************************************************
+* Copyright (c) 2021, 2023 IBM Corporation 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:
+* IBM Corporation - initial API and implementation
+*******************************************************************************/
+package org.eclipse.lsp4jakarta.jdt.core.java.codeaction;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.jdt.core.dom.ASTNode;
+import org.eclipse.jdt.core.dom.IBinding;
+import org.eclipse.jdt.core.dom.VariableDeclarationFragment;
+import org.eclipse.lsp4j.CodeAction;
+import org.eclipse.lsp4j.CodeActionKind;
+import org.eclipse.lsp4j.Diagnostic;
+import org.eclipse.lsp4jakarta.commons.codeaction.CodeActionResolveData;
+import org.eclipse.lsp4jakarta.commons.codeaction.ICodeActionId;
+import org.eclipse.lsp4jakarta.jdt.core.java.corrections.proposal.ChangeCorrectionProposal;
+import org.eclipse.lsp4jakarta.jdt.core.java.corrections.proposal.RemoveAnnotationProposal;
+
+/**
+ * Removes annotations.
+ */
+public abstract class RemoveAnnotationConflictQuickFix implements IJavaCodeActionParticipant {
+
+ /** Logger object to record events for this class. */
+ private static final Logger LOGGER = Logger.getLogger(RemoveAnnotationConflictQuickFix.class.getName());
+
+ /** Annotations to be removed. */
+ private final String[] annotations;
+
+ /**
+ * Indicator to generate a single action for a list of annotations or one for
+ * each annotation in the list.
+ */
+ protected final boolean generateOnlyOneCodeAction;
+
+ /** Map key to retrieve a list of annotations. */
+ public static final String ANNOTATIONS_KEY = "annotations";
+
+ /**
+ * Constructor.
+ *
+ * @param annotations The list of annotations to be removed.
+ */
+ public RemoveAnnotationConflictQuickFix(String... annotations) {
+ this(false, annotations);
+ }
+
+ /**
+ * Constructor.
+ *
+ * @param generateOnlyOneCodeAction The single action creation indicator. If
+ * true, a single code action is created to
+ * remove the specified set of annotations;
+ * otherwise, a code action is created per
+ * annotation to delete.
+ */
+ public RemoveAnnotationConflictQuickFix(boolean generateOnlyOneCodeAction, String... annotations) {
+ this.generateOnlyOneCodeAction = generateOnlyOneCodeAction;
+ this.annotations = annotations;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public List extends CodeAction> getCodeActions(JavaCodeActionContext context, Diagnostic diagnostic,
+ IProgressMonitor monitor) throws CoreException {
+ List codeActions = new ArrayList<>();
+ ASTNode node = context.getCoveredNode();
+ IBinding parentType = getBinding(node);
+ if (parentType != null) {
+ createCodeActions(diagnostic, context, parentType, codeActions);
+ }
+ return codeActions;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public CodeAction resolveCodeAction(JavaCodeActionResolveContext context) {
+ CodeAction toResolve = context.getUnresolved();
+ ASTNode node = context.getCoveredNode();
+ IBinding parentType = getBinding(node);
+ CodeActionResolveData data = (CodeActionResolveData) toResolve.getData();
+ List annotationToRemoveList = (List) data.getExtendedDataEntry(ANNOTATIONS_KEY);
+ String[] annotationToRemove = annotationToRemoveList.toArray(String[]::new);
+ String label = getLabel(annotationToRemove);
+ ChangeCorrectionProposal proposal = new RemoveAnnotationProposal(label, context.getCompilationUnit(), context.getASTRoot(), parentType, 0, context.getCoveredNode().getParent(), annotationToRemove);
+
+ try {
+ toResolve.setEdit(context.convertToWorkspaceEdit(proposal));
+ } catch (CoreException e) {
+ LOGGER.log(Level.SEVERE, "Unable to resolve code action to remove annotation", e);
+ }
+
+ return toResolve;
+ }
+
+ /**
+ * Creates one or more code actions for the given annotations.
+ *
+ * @param diagnostic The code diagnostic associated with the action to be
+ * created.
+ * @param context The context.
+ * @param parentType The parent type.
+ * @param codeActions The list of code actions.
+ *
+ * @throws CoreException
+ */
+ protected void createCodeActions(Diagnostic diagnostic, JavaCodeActionContext context, IBinding parentType,
+ List codeActions) throws CoreException {
+ if (generateOnlyOneCodeAction) {
+ createCodeAction(diagnostic, context, parentType, codeActions, annotations);
+ } else {
+ for (String annotation : annotations) {
+ createCodeAction(diagnostic, context, parentType, codeActions, annotation);
+ }
+ }
+ }
+
+ /**
+ * Creates a code action to remove the input annotations.
+ *
+ * @param diagnostic The code diagnostic associated with the action to be
+ * created.
+ * @param context The context.
+ * @param parentType The parent type.
+ * @param codeActions The list of code actions.
+ * @param annotations The annotations to remove.
+ *
+ *
+ * @throws CoreException
+ */
+ protected void createCodeAction(Diagnostic diagnostic, JavaCodeActionContext context, IBinding parentType,
+ List codeActions, String... annotations) throws CoreException {
+ String label = getLabel(annotations);
+
+ ExtendedCodeAction codeAction = new ExtendedCodeAction(label);
+ codeAction.setRelevance(0);
+ codeAction.setKind(CodeActionKind.QuickFix);
+ codeAction.setDiagnostics(Arrays.asList(diagnostic));
+ Map extendedData = new HashMap();
+ extendedData.put(ANNOTATIONS_KEY, Arrays.asList(annotations));
+ codeAction.setData(new CodeActionResolveData(context.getUri(), getParticipantId(), context.getParams().getRange(), extendedData, context.getParams().isResourceOperationSupported(), context.getParams().isCommandConfigurationUpdateSupported(), getCodeActionId()));
+
+ codeActions.add(codeAction);
+ }
+
+ /**
+ * Returns the named entity associated to the given node.
+ *
+ * @param node The AST Node
+ *
+ * @return The named entity associated to the given node.
+ */
+ @SuppressWarnings("restriction")
+ protected IBinding getBinding(ASTNode node) {
+ if (node.getParent() instanceof VariableDeclarationFragment) {
+ return ((VariableDeclarationFragment) node.getParent()).resolveBinding();
+ }
+ return org.eclipse.jdt.internal.corext.dom.Bindings.getBindingOfParentType(node);
+ }
+
+ protected String[] getAnnotations() {
+ return this.annotations;
+ }
+
+ /**
+ * Returns the label associated with the input annotations.
+ *
+ * @param annotations The annotations to remove.
+ * @return The label associated with the input annotations.
+ */
+ protected String getLabel(String[] annotations) {
+ StringBuilder name = new StringBuilder("Remove ");
+ for (int i = 0; i < annotations.length; i++) {
+ String annotation = annotations[i];
+ String annotationName = annotation.substring(annotation.lastIndexOf('.') + 1, annotation.length());
+ if (i > 0) {
+ name.append(", "); // assume comma list is ok: @A, @B, @C
+ }
+ name.append("@"); // Java syntax
+ name.append(annotationName);
+ }
+ return name.toString();
+ }
+
+ /**
+ * Returns the id for this code action.
+ *
+ * @return the id for this code action
+ */
+ protected abstract ICodeActionId getCodeActionId();
+}
diff --git a/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/core/java/codeaction/RemoveModifierConflictQuickFix.java b/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/core/java/codeaction/RemoveModifierConflictQuickFix.java
new file mode 100644
index 00000000..d3ec9bf1
--- /dev/null
+++ b/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/core/java/codeaction/RemoveModifierConflictQuickFix.java
@@ -0,0 +1,207 @@
+/*******************************************************************************
+* Copyright (c) 2021, 2023 IBM Corporation 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.
+*
+* SPDX-License-Identifier: EPL-2.0
+*
+* Contributors:
+* Himanshu Chotwani - initial API and implementation
+*******************************************************************************/
+
+package org.eclipse.lsp4jakarta.jdt.core.java.codeaction;
+
+import java.text.MessageFormat;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.jdt.core.dom.ASTNode;
+import org.eclipse.jdt.core.dom.IBinding;
+import org.eclipse.jdt.core.dom.MethodDeclaration;
+import org.eclipse.jdt.core.dom.VariableDeclarationFragment;
+import org.eclipse.lsp4j.CodeAction;
+import org.eclipse.lsp4j.CodeActionKind;
+import org.eclipse.lsp4j.Diagnostic;
+import org.eclipse.lsp4jakarta.commons.codeaction.CodeActionResolveData;
+import org.eclipse.lsp4jakarta.commons.codeaction.ICodeActionId;
+import org.eclipse.lsp4jakarta.jdt.core.java.corrections.proposal.ModifyModifiersProposal;
+
+/**
+ * Removes modifiers from the declaring element.
+ */
+public abstract class RemoveModifierConflictQuickFix implements IJavaCodeActionParticipant {
+
+ /** Logger object to record events for this class. */
+ private static final Logger LOGGER = Logger.getLogger(RemoveAnnotationConflictQuickFix.class.getName());
+
+ /** Map key to retrieve a list of modifiers. */
+ public static final String MODIFIERS_KEY = "modifiers";
+
+ /** Code action label template. */
+ private static final String CODE_ACTION_LABEL = "Remove the ''{0}'' modifier";
+
+ /**
+ * Array of modifiers to remove.
+ */
+ private final String[] modifiers;
+
+ /**
+ * Single action creation indicator. If true, a single code action is created to
+ * remove the specified set of modifiers; otherwise, a code action is created
+ * per modifier to delete.
+ */
+ protected final boolean generateOnlyOneCodeAction;
+
+ /**
+ * Constructor.
+ *
+ * @param modifiers The modifiers to remove.
+ */
+ public RemoveModifierConflictQuickFix(String... modifiers) {
+ this(false, modifiers);
+ }
+
+ /**
+ * Constructor.
+ *
+ * @param generateOnlyOneCodeAction The single action creation indicator. If
+ * true, a single code action is created to
+ * remove the specified set of modifiers;
+ * otherwise, a code action is created per
+ * modifier to delete.
+ * @param modifiers list of modifiers to remove.
+ */
+ public RemoveModifierConflictQuickFix(boolean generateOnlyOneCodeAction, String... modifiers) {
+ this.generateOnlyOneCodeAction = generateOnlyOneCodeAction;
+ this.modifiers = modifiers;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public List extends CodeAction> getCodeActions(JavaCodeActionContext context, Diagnostic diagnostic,
+ IProgressMonitor monitor) throws CoreException {
+ List codeActions = new ArrayList<>();
+ ASTNode node = context.getCoveredNode();
+ IBinding parentType = getBinding(node);
+ if (parentType != null) {
+ createCodeActions(diagnostic, context, codeActions);
+ }
+
+ return codeActions;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public CodeAction resolveCodeAction(JavaCodeActionResolveContext context) {
+ CodeAction toResolve = context.getUnresolved();
+ ASTNode coveredParentNode = context.getCoveredNode().getParent();
+ IBinding parentType = getBinding(context.getCoveredNode());
+ CodeActionResolveData data = (CodeActionResolveData) toResolve.getData();
+ List modifiersToDeleteList = (List) data.getExtendedDataEntry(MODIFIERS_KEY);
+ String[] modifiersToDelete = modifiersToDeleteList.toArray(String[]::new);
+ String label = getLabel(modifiersToDelete);
+ ModifyModifiersProposal proposal = new ModifyModifiersProposal(label, context.getCompilationUnit(), context.getASTRoot(), parentType, 0, coveredParentNode, new ArrayList<>(), Arrays.asList(modifiers));
+
+ try {
+ toResolve.setEdit(context.convertToWorkspaceEdit(proposal));
+ } catch (CoreException e) {
+ LOGGER.log(Level.SEVERE, "Unable to resolve code action to remove annotation", e);
+ }
+
+ return toResolve;
+ }
+
+ /**
+ * Creates one or more code actions to remove one or more modifiers.
+ *
+ * @param diagnostic The code diagnostic associated with the action to be
+ * created.
+ * @param context The context.
+ * @param codeActions The list of code action to update.
+ *
+ * @throws CoreException
+ */
+ protected void createCodeActions(Diagnostic diagnostic, JavaCodeActionContext context,
+ List codeActions) throws CoreException {
+ if (generateOnlyOneCodeAction) {
+ createCodeAction(diagnostic, context, codeActions, modifiers);
+ } else {
+ for (String modifier : modifiers) {
+ createCodeAction(diagnostic, context, codeActions, modifier);
+ }
+ }
+ }
+
+ /**
+ * Creates a code action to remove the input modifiers.
+ *
+ * @param diagnostic The code diagnostic associated with the action to be
+ * created.
+ * @param context The context.
+ * @param codeActions The list of code actions.
+ * @param modifiers The modifiers to remove.
+ *
+ *
+ * @throws CoreException
+ */
+ protected void createCodeAction(Diagnostic diagnostic, JavaCodeActionContext context,
+ List codeActions, String... modifiers) throws CoreException {
+ String label = getLabel(modifiers);
+ ExtendedCodeAction codeAction = new ExtendedCodeAction(label);
+ codeAction.setRelevance(0);
+ codeAction.setKind(CodeActionKind.QuickFix);
+ codeAction.setDiagnostics(Arrays.asList(diagnostic));
+ Map extendedData = new HashMap();
+ extendedData.put(MODIFIERS_KEY, Arrays.asList(modifiers));
+ codeAction.setData(new CodeActionResolveData(context.getUri(), getParticipantId(), context.getParams().getRange(), extendedData, context.getParams().isResourceOperationSupported(), context.getParams().isCommandConfigurationUpdateSupported(), getCodeActionId()));
+
+ codeActions.add(codeAction);
+ }
+
+ /**
+ * Returns the label associated with the input modifier.
+ *
+ * @param modifier The modifier to remove.
+ * @return The label associated with the input modifier.
+ */
+ protected String getLabel(String... modifier) {
+ return MessageFormat.format(CODE_ACTION_LABEL, modifier[0]);
+ }
+
+ /**
+ * Returns the named entity associated to the given node.
+ *
+ * @param node The AST Node
+ *
+ * @return The named entity associated to the given node.
+ */
+ @SuppressWarnings("restriction")
+ protected IBinding getBinding(ASTNode node) {
+ if (node.getParent() instanceof VariableDeclarationFragment) {
+ return ((VariableDeclarationFragment) node.getParent()).resolveBinding();
+ } else if (node.getParent() instanceof MethodDeclaration) {
+ return ((MethodDeclaration) node.getParent()).resolveBinding();
+ }
+ return org.eclipse.jdt.internal.corext.dom.Bindings.getBindingOfParentType(node);
+ }
+
+ /**
+ * Returns the id for this code action.
+ *
+ * @return the id for this code action
+ */
+ protected abstract ICodeActionId getCodeActionId();
+}
diff --git a/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/core/java/completion/IJavaCompletionParticipant.java b/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/core/java/completion/IJavaCompletionParticipant.java
new file mode 100644
index 00000000..e2f4d71f
--- /dev/null
+++ b/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/core/java/completion/IJavaCompletionParticipant.java
@@ -0,0 +1,51 @@
+/*******************************************************************************
+* Copyright (c) 2021 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 org.eclipse.lsp4jakarta.jdt.core.java.completion;
+
+import java.util.List;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.lsp4j.CompletionItem;
+
+/**
+ * The API for a completion feature
+ *
+ * @author datho7561
+ */
+public interface IJavaCompletionParticipant {
+
+ /**
+ * Returns true if this completion feature should be active in this context, and false otherwise
+ *
+ * @param context the context of where completion is triggered
+ * @param monitor the progress monitor
+ * @return true if this completion feature should be active in this context, and false otherwise
+ * @throws CoreException
+ */
+ default boolean isAdaptedForCompletion(JavaCompletionContext context, IProgressMonitor monitor) throws CoreException {
+ return true;
+ }
+
+ /**
+ * Returns the completion items for the given completion context
+ *
+ * @param context the completion context
+ * @param monitor the progress monitor
+ * @return the completion items for the given completion context
+ * @throws CoreException
+ */
+ List extends CompletionItem> collectCompletionItems(JavaCompletionContext context, IProgressMonitor monitor) throws CoreException;
+
+}
diff --git a/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/core/java/completion/JavaCompletionContext.java b/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/core/java/completion/JavaCompletionContext.java
new file mode 100644
index 00000000..2c7e7dbf
--- /dev/null
+++ b/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/core/java/completion/JavaCompletionContext.java
@@ -0,0 +1,45 @@
+/*******************************************************************************
+* Copyright (c) 2021 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 org.eclipse.lsp4jakarta.jdt.core.java.completion;
+
+import org.eclipse.jdt.core.ITypeRoot;
+import org.eclipse.lsp4jakarta.jdt.core.java.AbstractJavaContext;
+import org.eclipse.lsp4jakarta.jdt.core.utils.IJDTUtils;
+
+/**
+ * Represents the context of where completion was triggered
+ *
+ * @author datho7561
+ */
+public class JavaCompletionContext extends AbstractJavaContext {
+
+ private int offset;
+
+ public JavaCompletionContext(String uri, ITypeRoot typeRoot, IJDTUtils utils, int offset) {
+ super(uri, typeRoot, utils);
+ this.offset = offset;
+ }
+
+ /**
+ * Returns the offset from the beginning of the document where completion was
+ * triggered
+ *
+ * @return the offset from the beginning of the document where completion was
+ * triggered
+ */
+ public int getOffset() {
+ return offset;
+ }
+
+}
diff --git a/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/core/java/corrections/proposal/ASTRewriteCorrectionProposal.java b/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/core/java/corrections/proposal/ASTRewriteCorrectionProposal.java
new file mode 100644
index 00000000..5ed1ee1b
--- /dev/null
+++ b/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/core/java/corrections/proposal/ASTRewriteCorrectionProposal.java
@@ -0,0 +1,123 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2014 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License 2.0
+ * which accompanies this distribution, and is available at
+ * https://www.eclipse.org/legal/epl-2.0/
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ * Copied from /org.eclipse.jdt.ui/src/org/eclipse/jdt/ui/text/java/correction/ASTRewriteCorrectionProposal.java
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.lsp4jakarta.jdt.core.java.corrections.proposal;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.jdt.core.ICompilationUnit;
+import org.eclipse.jdt.core.dom.CompilationUnit;
+import org.eclipse.jdt.core.dom.rewrite.ASTRewrite;
+import org.eclipse.jdt.core.dom.rewrite.ImportRewrite;
+import org.eclipse.jdt.core.manipulation.CodeStyleConfiguration;
+import org.eclipse.jdt.ls.core.internal.StatusFactory;
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.text.edits.TextEdit;
+
+/**
+ * A proposal for quick fixes and quick assists that works on an AST rewrite.
+ * Either a rewrite is directly passed in the constructor or the method
+ * {@link #getRewrite()} is overridden to provide the AST rewrite that is
+ * evaluated on the document when the proposal is applied.
+ */
+public class ASTRewriteCorrectionProposal extends CUCorrectionProposal {
+
+ private ASTRewrite fRewrite;
+ private ImportRewrite fImportRewrite;
+
+ /**
+ * Constructs an AST rewrite correction proposal.
+ *
+ * @param name the display name of the proposal
+ * @param cu the compilation unit that is modified
+ * @param rewrite the AST rewrite that is invoked when the proposal is applied
+ * or null
if {@link #getRewrite()} is overridden
+ * @param relevance the relevance of this proposal
+ */
+ public ASTRewriteCorrectionProposal(String name, String kind, ICompilationUnit cu, ASTRewrite rewrite,
+ int relevance) {
+ super(name, kind, cu, null, relevance);
+ fRewrite = rewrite;
+ }
+
+ /**
+ * Returns the import rewrite used for this compilation unit.
+ *
+ * @return the import rewrite or null
if no import rewrite has been
+ * set
+ * @nooverride This method is not intended to be re-implemented or extended by
+ * clients.
+ */
+ public ImportRewrite getImportRewrite() {
+ return fImportRewrite;
+ }
+
+ /**
+ * Sets the import rewrite used for this compilation unit.
+ *
+ * @param rewrite the import rewrite
+ * @nooverride This method is not intended to be re-implemented or extended by
+ * clients.
+ */
+ public void setImportRewrite(ImportRewrite rewrite) {
+ fImportRewrite = rewrite;
+ }
+
+ /**
+ * Creates and sets the import rewrite used for this compilation unit.
+ *
+ * @param astRoot the AST for the current CU
+ * @return the created import rewrite
+ * @nooverride This method is not intended to be re-implemented or extended by
+ * clients.
+ */
+ public ImportRewrite createImportRewrite(CompilationUnit astRoot) {
+ fImportRewrite = CodeStyleConfiguration.createImportRewrite(astRoot, true);
+ return fImportRewrite;
+ }
+
+ @Override
+ protected void addEdits(IDocument document, TextEdit editRoot) throws CoreException {
+ super.addEdits(document, editRoot);
+ ASTRewrite rewrite = getRewrite();
+ if (rewrite != null) {
+ try {
+ TextEdit edit = rewrite.rewriteAST();
+ editRoot.addChild(edit);
+ } catch (IllegalArgumentException e) {
+ throw new CoreException(StatusFactory.newErrorStatus("Invalid AST rewriter", e));
+ }
+ }
+ if (fImportRewrite != null) {
+ editRoot.addChild(fImportRewrite.rewriteImports(new NullProgressMonitor()));
+ }
+ }
+
+ /**
+ * Returns the rewrite that has been passed in the constructor. Implementors can
+ * override this method to create the rewrite lazily. This method will only be
+ * called once.
+ *
+ * @return the rewrite to be used
+ * @throws CoreException when the rewrite could not be created
+ */
+ protected ASTRewrite getRewrite() throws CoreException {
+ if (fRewrite == null) {
+ IStatus status = StatusFactory.newErrorStatus("Rewrite not initialized", null); //$NON-NLS-1$
+ throw new CoreException(status);
+ }
+ return fRewrite;
+ }
+}
diff --git a/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/codeAction/proposal/AddConstructorProposal.java b/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/core/java/corrections/proposal/AddConstructorProposal.java
similarity index 86%
rename from jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/codeAction/proposal/AddConstructorProposal.java
rename to jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/core/java/corrections/proposal/AddConstructorProposal.java
index 2d0b8f5a..054e372f 100644
--- a/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/codeAction/proposal/AddConstructorProposal.java
+++ b/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/core/java/corrections/proposal/AddConstructorProposal.java
@@ -10,8 +10,7 @@
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
-package org.eclipse.lsp4jakarta.jdt.codeAction.proposal;
-
+package org.eclipse.lsp4jakarta.jdt.core.java.corrections.proposal;
import java.util.List;
@@ -24,7 +23,6 @@
import org.eclipse.jdt.core.dom.IBinding;
import org.eclipse.jdt.core.dom.MethodDeclaration;
import org.eclipse.jdt.core.dom.Modifier;
-import org.eclipse.jdt.core.dom.Modifier.ModifierKeyword;
import org.eclipse.jdt.core.dom.SimpleName;
import org.eclipse.jdt.core.dom.TypeDeclaration;
import org.eclipse.jdt.core.dom.rewrite.ASTRewrite;
@@ -34,36 +32,37 @@
/**
* Code action proposal for adding a no-arg constructor to a class
- *
- * @author Leslie Dawson
- * @see PersistenceEntityQuickFix
- *
+ *
+ * @author Leslie Dawson
+ * @see PersistenceEntityQuickFix
+ *
*/
-public class AddConstructorProposal extends ChangeCorrectionProposal {
+public class AddConstructorProposal extends ASTRewriteCorrectionProposal {
private final CompilationUnit invocationNode;
private final IBinding binding;
private final String visibility;
-
+
/**
* Constructor for AddMethodProposal
- *
+ *
*/
public AddConstructorProposal(String label, ICompilationUnit targetCU, CompilationUnit invocationNode,
- IBinding binding, int relevance) {
+ IBinding binding, int relevance) {
super(label, CodeActionKind.QuickFix, targetCU, null, relevance);
this.invocationNode = invocationNode;
this.binding = binding;
this.visibility = "protected";
}
-
+
/**
* Constructor for AddMethodProposal
- *
- * @param visibility a valid visibility modifier for the constructor, defaults to protected
+ *
+ * @param visibility a valid visibility modifier for the constructor, defaults
+ * to protected
*/
public AddConstructorProposal(String label, ICompilationUnit targetCU, CompilationUnit invocationNode,
- IBinding binding, int relevance, String visibility) {
+ IBinding binding, int relevance, String visibility) {
super(label, CodeActionKind.QuickFix, targetCU, null, relevance);
this.invocationNode = invocationNode;
this.binding = binding;
@@ -76,14 +75,14 @@ protected ASTRewrite getRewrite() throws CoreException {
ASTNode declNode = null;
ASTNode boundNode = invocationNode.findDeclaringNode(binding);
CompilationUnit newRoot = invocationNode;
-
+
if (boundNode != null) {
declNode = boundNode;
} else {
newRoot = ASTResolving.createQuickFixAST(getCompilationUnit(), null);
declNode = newRoot.findDeclaringNode(binding.getKey());
- }
-
+ }
+
AST ast = declNode.getAST();
ASTRewrite rewrite = ASTRewrite.create(ast);
ListRewrite list = rewrite.getListRewrite(declNode, TypeDeclaration.BODY_DECLARATIONS_PROPERTY);
@@ -93,12 +92,12 @@ protected ASTRewrite getRewrite() throws CoreException {
SimpleName name = ast.newSimpleName(declNode.getStructuralProperty(TypeDeclaration.NAME_PROPERTY).toString());
Block methodBody = ast.newBlock();
List modifiers = md.modifiers();
-
+
modifiers.add(ast.newModifier(Modifier.ModifierKeyword.toKeyword(visibility)));
md.setName(name);
md.setConstructor(true);
md.setBody(methodBody);
-
+
// insert method
list.insertFirst(md, null);
return rewrite;
diff --git a/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/core/java/corrections/proposal/CUCorrectionProposal.java b/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/core/java/corrections/proposal/CUCorrectionProposal.java
new file mode 100644
index 00000000..78d54264
--- /dev/null
+++ b/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/core/java/corrections/proposal/CUCorrectionProposal.java
@@ -0,0 +1,157 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2012 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License 2.0
+ * which accompanies this distribution, and is available at
+ * https://www.eclipse.org/legal/epl-2.0/
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ * Copied from /org.eclipse.jdt.ui/src/org/eclipse/jdt/ui/text/java/correction/CUCorrectionProposal.java
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.lsp4jakarta.jdt.core.java.corrections.proposal;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.jdt.core.ICompilationUnit;
+import org.eclipse.jdt.core.manipulation.CUCorrectionProposalCore;
+import org.eclipse.jdt.core.manipulation.ICUCorrectionProposal;
+import org.eclipse.jdt.core.refactoring.CompilationUnitChange;
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.ltk.core.refactoring.Change;
+import org.eclipse.ltk.core.refactoring.TextChange;
+import org.eclipse.text.edits.TextEdit;
+
+/**
+ * A proposal for quick fixes and quick assists that work on a single
+ * compilation unit. Either a {@link TextChange text change} is directly passed
+ * in the constructor or method {@link #addEdits(IDocument, TextEdit)} is
+ * overridden to provide the text edits that are applied to the document when
+ * the proposal is evaluated.
+ *
+ * The proposal takes care of the preview of the changes as proposal
+ * information.
+ *
+ */
+public class CUCorrectionProposal extends ChangeCorrectionProposal implements ICUCorrectionProposal {
+
+ private CUCorrectionProposalCore fProposalCore;
+
+ /**
+ * Constructs a correction proposal working on a compilation unit with a given
+ * text change.
+ *
+ * @param name the name that is displayed in the proposal selection dialog
+ * @param kind the kind of the correction type that the proposal performs
+ * @param cu the compilation unit to which the change can be applied
+ * @param change the change that is executed when the proposal is applied or
+ * null
if implementors override
+ * {@link #addEdits(IDocument, TextEdit)} to provide the text
+ * edits or {@link #createTextChange()} to provide a text
+ * change
+ * @param relevance the relevance of this proposal
+ */
+ public CUCorrectionProposal(String name, String kind, ICompilationUnit cu, TextChange change, int relevance) {
+ super(name, kind, change, relevance);
+ if (cu == null) {
+ throw new IllegalArgumentException("Compilation unit must not be null"); //$NON-NLS-1$
+ }
+ fProposalCore = new CUCorrectionProposalCore(name, cu, change, relevance);
+ }
+
+ /**
+ * Called when the {@link CompilationUnitChange} is initialized. Subclasses can
+ * override to add text edits to the root edit of the change. Implementors must
+ * not access the proposal, e.g. not call {@link #getChange()}.
+ *
+ * The default implementation does not add any edits
+ *
+ *
+ * @param document content of the underlying compilation unit. To be accessed
+ * read only.
+ * @param editRoot The root edit to add all edits to
+ * @throws CoreException can be thrown if adding the edits is failing.
+ */
+ protected void addEdits(IDocument document, TextEdit editRoot) throws CoreException {
+ // empty default implementation
+ }
+
+ @Override
+ public Object getAdditionalProposalInfo(IProgressMonitor monitor) {
+ return fProposalCore.getAdditionalProposalInfo(monitor);
+ }
+
+ @Override
+ public void apply() throws CoreException {
+ performChange();
+ }
+
+ /**
+ * Creates the text change for this proposal. This method is only called once
+ * and only when no text change has been passed in
+ * {@link #CUCorrectionProposal(String, ICompilationUnit, TextChange, int)}.
+ *
+ * @return the created text change
+ * @throws CoreException if the creation of the text change failed
+ */
+ protected TextChange createTextChange() throws CoreException {
+ TextChange change = fProposalCore.getNewChange();
+ // initialize text change
+ IDocument document = change.getCurrentDocument(new NullProgressMonitor());
+ addEdits(document, change.getEdit());
+ return change;
+ }
+
+ @Override
+ protected final Change createChange() throws CoreException {
+ return createTextChange(); // make sure that only text changes are allowed here
+ }
+
+ /**
+ * Returns the text change that is invoked when the change is applied.
+ *
+ * @return the text change that is invoked when the change is applied
+ * @throws CoreException if accessing the change failed
+ */
+ @Override
+ public final TextChange getTextChange() throws CoreException {
+ return (TextChange) getChange();
+ }
+
+ /**
+ * The compilation unit on which the change works.
+ *
+ * @return the compilation unit on which the change works
+ */
+ public final ICompilationUnit getCompilationUnit() {
+ return fProposalCore.getCompilationUnit();
+ }
+
+ /**
+ * Creates a preview of the content of the compilation unit after applying the
+ * change.
+ *
+ * @return the preview of the changed compilation unit
+ * @throws CoreException if the creation of the change failed
+ *
+ * @noreference This method is not intended to be referenced by clients.
+ */
+ public String getPreviewContent() throws CoreException {
+ return getTextChange().getPreviewContent(new NullProgressMonitor());
+ }
+
+ @Override
+ public String toString() {
+ try {
+ return getPreviewContent();
+ } catch (CoreException e) {
+ // didn't work out
+ }
+ return super.toString();
+ }
+
+}
diff --git a/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/core/java/corrections/proposal/ChangeCorrectionProposal.java b/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/core/java/corrections/proposal/ChangeCorrectionProposal.java
new file mode 100644
index 00000000..c7fa62c4
--- /dev/null
+++ b/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/core/java/corrections/proposal/ChangeCorrectionProposal.java
@@ -0,0 +1,106 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2014 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License 2.0
+ * which accompanies this distribution, and is available at
+ * https://www.eclipse.org/legal/epl-2.0/
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ * Copied from /org.eclipse.jdt.ui/src/org/eclipse/jdt/ui/text/java/correction/ChangeCorrectionProposal.java
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.lsp4jakarta.jdt.core.java.corrections.proposal;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.jdt.core.manipulation.ChangeCorrectionProposalCore;
+import org.eclipse.lsp4jakarta.jdt.core.JakartaCorePlugin;
+import org.eclipse.ltk.core.refactoring.Change;
+import org.eclipse.ltk.core.refactoring.IUndoManager;
+import org.eclipse.ltk.core.refactoring.RefactoringCore;
+import org.eclipse.ltk.core.refactoring.RefactoringStatus;
+
+public class ChangeCorrectionProposal extends ChangeCorrectionProposalCore {
+ // LSP: Code Action Kind
+ private String fKind;
+
+ /**
+ * Constructs a change correction proposal.
+ *
+ * @param name the name that is displayed in the proposal selection dialog
+ * @param change the change that is executed when the proposal is applied or
+ * null
if the change will be created by
+ * implementors of {@link #createChange()}
+ * @param relevance the relevance of this proposal
+ */
+ public ChangeCorrectionProposal(String name, String kind, Change change, int relevance) {
+ super(name, change, relevance);
+ fKind = kind;
+ }
+
+ /**
+ * Performs the change associated with this proposal.
+ *
+ * Subclasses may extend, but must call the super implementation.
+ *
+ * @throws CoreException when the invocation of the change failed
+ */
+ @Override
+ protected void performChange() throws CoreException {
+
+ Change change = null;
+ try {
+ change = getChange();
+ if (change != null) {
+
+ change.initializeValidationData(new NullProgressMonitor());
+ RefactoringStatus valid = change.isValid(new NullProgressMonitor());
+ if (valid.hasFatalError()) {
+ IStatus status = new Status(IStatus.ERROR, JakartaCorePlugin.PLUGIN_ID, IStatus.ERROR, valid.getMessageMatchingSeverity(RefactoringStatus.FATAL), null);
+ throw new CoreException(status);
+ } else {
+ IUndoManager manager = RefactoringCore.getUndoManager();
+ Change undoChange;
+ boolean successful = false;
+ try {
+ manager.aboutToPerformChange(change);
+ undoChange = change.perform(new NullProgressMonitor());
+ successful = true;
+ } finally {
+ manager.changePerformed(change, successful);
+ }
+ if (undoChange != null) {
+ undoChange.initializeValidationData(new NullProgressMonitor());
+ manager.addUndo(getName(), undoChange);
+ }
+ }
+ }
+ } finally {
+
+ if (change != null) {
+ change.dispose();
+ }
+ }
+ }
+
+ /**
+ * Returns the kind of the proposal.
+ *
+ * @return the kind of the proposal
+ */
+ public String getKind() {
+ return fKind;
+ }
+
+ /**
+ * @param codeActionKind the Code Action Kind to set
+ */
+ public void setKind(String codeActionKind) {
+ this.fKind = codeActionKind;
+ }
+}
diff --git a/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/codeAction/proposal/ExtendClassProposal.java b/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/core/java/corrections/proposal/ExtendClassProposal.java
similarity index 92%
rename from jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/codeAction/proposal/ExtendClassProposal.java
rename to jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/core/java/corrections/proposal/ExtendClassProposal.java
index 7613f0be..112c5f83 100644
--- a/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/codeAction/proposal/ExtendClassProposal.java
+++ b/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/core/java/corrections/proposal/ExtendClassProposal.java
@@ -12,7 +12,7 @@
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
-package org.eclipse.lsp4jakarta.jdt.codeAction.proposal;
+package org.eclipse.lsp4jakarta.jdt.core.java.corrections.proposal;
import org.eclipse.core.runtime.Assert;
import org.eclipse.core.runtime.CoreException;
@@ -28,19 +28,18 @@
import org.eclipse.jdt.core.dom.rewrite.ImportRewrite;
import org.eclipse.jdt.core.dom.rewrite.ImportRewrite.ImportRewriteContext;
import org.eclipse.jdt.internal.core.manipulation.dom.ASTResolving;
-import org.eclipse.jdt.internal.core.manipulation.util.BasicElementLabels;
import org.eclipse.jdt.internal.corext.codemanipulation.ContextSensitiveImportRewriteContext;
import org.eclipse.jdt.internal.corext.dom.Bindings;
import org.eclipse.lsp4j.CodeActionKind;
-public class ExtendClassProposal extends ChangeCorrectionProposal {
+public class ExtendClassProposal extends ASTRewriteCorrectionProposal {
private IBinding fBinding;
private CompilationUnit fAstRoot;
private String interfaceType;
public ExtendClassProposal(String name, ICompilationUnit targetCU, ITypeBinding binding, CompilationUnit astRoot,
- String interfaceType, int relevance) {
+ String interfaceType, int relevance) {
super(name, CodeActionKind.QuickFix, targetCU, null, relevance);
Assert.isTrue(binding != null && Bindings.isDeclarationBinding(binding));
diff --git a/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/codeAction/proposal/ImplementInterfaceProposal.java b/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/core/java/corrections/proposal/ImplementInterfaceProposal.java
similarity index 73%
rename from jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/codeAction/proposal/ImplementInterfaceProposal.java
rename to jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/core/java/corrections/proposal/ImplementInterfaceProposal.java
index a2512882..049978f7 100644
--- a/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/codeAction/proposal/ImplementInterfaceProposal.java
+++ b/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/core/java/corrections/proposal/ImplementInterfaceProposal.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2023 IBM Corporation and others.
+ * Copyright (c) 2000, 2016 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
@@ -12,7 +12,9 @@
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
-package org.eclipse.lsp4jakarta.jdt.codeAction.proposal;
+package org.eclipse.lsp4jakarta.jdt.core.java.corrections.proposal;
+
+import java.text.MessageFormat;
import org.eclipse.core.runtime.Assert;
import org.eclipse.core.runtime.CoreException;
@@ -34,29 +36,42 @@
import org.eclipse.jdt.internal.corext.dom.Bindings;
import org.eclipse.lsp4j.CodeActionKind;
-/**
- * QuickFix for implementing interface
- *
- * copied from
- * /org.eclipse.jdt.ui/src/org/eclipse/jdt/internal/ui/text/correction/proposals/ImplementInterfaceProposal.java
- */
-public class ImplementInterfaceProposal extends ChangeCorrectionProposal {
+public class ImplementInterfaceProposal extends ASTRewriteCorrectionProposal {
+
+ private static final String TITLE_MESSAGE = "Let ''{0}'' implement ''{1}''";
private IBinding fBinding;
private CompilationUnit fAstRoot;
private String interfaceType;
public ImplementInterfaceProposal(String name, ICompilationUnit targetCU, ITypeBinding binding,
- CompilationUnit astRoot, String interfaceType, int relevance) {
- super(name, CodeActionKind.QuickFix, targetCU, null, relevance);
+ CompilationUnit astRoot,
+ String interfaceType, int relevance) {
+ super(name, CodeActionKind.QuickFix, targetCU, null, relevance); // $NON-NLS-1$
+
+ Assert.isTrue(binding != null && Bindings.isDeclarationBinding(binding));
+
+ fBinding = binding;
+ fAstRoot = astRoot;
+ this.interfaceType = interfaceType;
+ }
+
+ public ImplementInterfaceProposal(ICompilationUnit targetCU, ITypeBinding binding, CompilationUnit astRoot,
+ String interfaceType, int relevance) {
+ super("", CodeActionKind.QuickFix, targetCU, null, relevance); //$NON-NLS-1$
Assert.isTrue(binding != null && Bindings.isDeclarationBinding(binding));
fBinding = binding;
fAstRoot = astRoot;
this.interfaceType = interfaceType;
+
+ String[] args = { BasicElementLabels.getJavaElementName(binding.getName()),
+ BasicElementLabels.getJavaElementName(interfaceType) };
+ setDisplayName(MessageFormat.format(TITLE_MESSAGE, args));
}
+ @Override
protected ASTRewrite getRewrite() throws CoreException {
ASTNode boundNode = fAstRoot.findDeclaringNode(fBinding);
ASTNode declNode = null;
@@ -77,13 +92,11 @@ protected ASTRewrite getRewrite() throws CoreException {
Type newInterface = ast.newSimpleType(ast.newName(name));
ASTRewrite rewrite = ASTRewrite.create(ast);
-
ListRewrite listRewrite = rewrite.getListRewrite(declNode, TypeDeclaration.SUPER_INTERFACE_TYPES_PROPERTY);
listRewrite.insertLast(newInterface, null);
-
return rewrite;
}
return null;
}
-}
\ No newline at end of file
+}
diff --git a/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/core/java/corrections/proposal/InsertAnnotationAttributeProposal.java b/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/core/java/corrections/proposal/InsertAnnotationAttributeProposal.java
new file mode 100644
index 00000000..0c4effc4
--- /dev/null
+++ b/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/core/java/corrections/proposal/InsertAnnotationAttributeProposal.java
@@ -0,0 +1,134 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2016 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License 2.0
+ * which accompanies this distribution, and is available at
+ * https://www.eclipse.org/legal/epl-2.0/
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ * Copied from /org.eclipse.jdt.ui/src/org/eclipse/jdt/internal/ui/text/correction/proposals/MissingAnnotationAttributesProposal.java
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.lsp4jakarta.jdt.core.java.corrections.proposal;
+
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.jdt.core.ICompilationUnit;
+import org.eclipse.jdt.core.dom.AST;
+import org.eclipse.jdt.core.dom.ASTNode;
+import org.eclipse.jdt.core.dom.Annotation;
+import org.eclipse.jdt.core.dom.ArrayInitializer;
+import org.eclipse.jdt.core.dom.CompilationUnit;
+import org.eclipse.jdt.core.dom.Expression;
+import org.eclipse.jdt.core.dom.IMethodBinding;
+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.Name;
+import org.eclipse.jdt.core.dom.NormalAnnotation;
+import org.eclipse.jdt.core.dom.SingleMemberAnnotation;
+import org.eclipse.jdt.core.dom.rewrite.ASTRewrite;
+import org.eclipse.jdt.core.dom.rewrite.ImportRewrite.ImportRewriteContext;
+import org.eclipse.jdt.core.dom.rewrite.ListRewrite;
+import org.eclipse.jdt.internal.core.manipulation.dom.ASTResolving;
+import org.eclipse.jdt.internal.corext.codemanipulation.ContextSensitiveImportRewriteContext;
+import org.eclipse.lsp4j.CodeActionKind;
+
+public class InsertAnnotationAttributeProposal extends LinkedCorrectionProposal {
+
+ private final Annotation fAnnotation;
+ private final Set attributes;
+
+ public InsertAnnotationAttributeProposal(String label, ICompilationUnit targetCU, Annotation annotation,
+ int relevance, String... attributes) {
+ super(label, CodeActionKind.QuickFix, targetCU, null, relevance);
+ this.fAnnotation = annotation;
+ this.attributes = new HashSet<>(Arrays.asList(attributes));
+ }
+
+ @Override
+ protected ASTRewrite getRewrite() throws CoreException {
+ AST ast = fAnnotation.getAST();
+
+ ASTRewrite rewrite = ASTRewrite.create(ast);
+ createImportRewrite((CompilationUnit) fAnnotation.getRoot());
+
+ ListRewrite listRewrite;
+ if (fAnnotation instanceof NormalAnnotation) {
+ listRewrite = rewrite.getListRewrite(fAnnotation, NormalAnnotation.VALUES_PROPERTY);
+ } else {
+ NormalAnnotation newAnnotation = ast.newNormalAnnotation();
+ newAnnotation.setTypeName((Name) rewrite.createMoveTarget(fAnnotation.getTypeName()));
+ rewrite.replace(fAnnotation, newAnnotation, null);
+
+ listRewrite = rewrite.getListRewrite(newAnnotation, NormalAnnotation.VALUES_PROPERTY);
+ }
+ addDefinedAtributes(fAnnotation.resolveTypeBinding(), listRewrite);
+
+ return rewrite;
+ }
+
+ private void addDefinedAtributes(ITypeBinding binding, ListRewrite listRewriter) {
+ Set implementedAttribs = new HashSet();
+ if (fAnnotation instanceof NormalAnnotation) {
+ List list = ((NormalAnnotation) fAnnotation).values();
+ for (int i = 0; i < list.size(); i++) {
+ MemberValuePair curr = list.get(i);
+ implementedAttribs.add(curr.getName().getIdentifier());
+ }
+ } else if (fAnnotation instanceof SingleMemberAnnotation) {
+ implementedAttribs.add("value"); //$NON-NLS-1$
+ }
+ ASTRewrite rewriter = listRewriter.getASTRewrite();
+ AST ast = rewriter.getAST();
+ ImportRewriteContext context = null;
+ ASTNode bodyDeclaration = ASTResolving.findParentBodyDeclaration(listRewriter.getParent());
+ if (bodyDeclaration != null) {
+ context = new ContextSensitiveImportRewriteContext(bodyDeclaration, getImportRewrite());
+ }
+
+ IMethodBinding[] declaredMethods = binding.getDeclaredMethods();
+ for (int i = 0; i < declaredMethods.length; i++) {
+ IMethodBinding curr = declaredMethods[i];
+ if (!implementedAttribs.contains(curr.getName()) && attributes.contains(curr.getName())) {
+ MemberValuePair pair = ast.newMemberValuePair();
+ pair.setName(ast.newSimpleName(curr.getName()));
+ pair.setValue(newDefaultExpression(ast, curr.getReturnType(), context));
+ listRewriter.insertLast(pair, null);
+ }
+ }
+ }
+
+ private Expression newDefaultExpression(AST ast, ITypeBinding type, ImportRewriteContext context) {
+ if (type.isPrimitive()) {
+ String name = type.getName();
+ if ("boolean".equals(name)) { //$NON-NLS-1$
+ return ast.newBooleanLiteral(false);
+ } else {
+ return ast.newNumberLiteral("0"); //$NON-NLS-1$
+ }
+ }
+ if (type == ast.resolveWellKnownType("java.lang.String")) { //$NON-NLS-1$
+ return ast.newStringLiteral();
+ }
+ if (type.isArray()) {
+ ArrayInitializer initializer = ast.newArrayInitializer();
+ initializer.expressions().add(newDefaultExpression(ast, type.getElementType(), context));
+ return initializer;
+ }
+ if (type.isAnnotation()) {
+ MarkerAnnotation annotation = ast.newMarkerAnnotation();
+ annotation.setTypeName(ast.newName(getImportRewrite().addImport(type, context)));
+ return annotation;
+ }
+ return ast.newNullLiteral();
+ }
+
+}
diff --git a/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/codeAction/proposal/NewAnnotationProposal.java b/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/core/java/corrections/proposal/InsertAnnotationProposal.java
similarity index 80%
rename from jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/codeAction/proposal/NewAnnotationProposal.java
rename to jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/core/java/corrections/proposal/InsertAnnotationProposal.java
index 789e3aef..b5a351dc 100644
--- a/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/codeAction/proposal/NewAnnotationProposal.java
+++ b/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/core/java/corrections/proposal/InsertAnnotationProposal.java
@@ -7,12 +7,12 @@
*
* SPDX-License-Identifier: EPL-2.0
*
- * Copied from https://github.com/eclipse/lsp4mp/blob/6f2d700a88a3262e39cc2ba04beedb429e162246/microprofile.jdt/org.eclipse.lsp4mp.jdt.core/src/main/java/org/eclipse/lsp4mp/jdt/core/java/corrections/proposal/NewAnnotationProposal.java
+ * Copied from /org.eclipse.jdt.ui/src/org/eclipse/jdt/internal/ui/text/correction/proposals/NewAnnotationMemberProposal.java
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
-package org.eclipse.lsp4jakarta.jdt.codeAction.proposal;
+package org.eclipse.lsp4jakarta.jdt.core.java.corrections.proposal;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.jdt.core.ICompilationUnit;
@@ -32,19 +32,15 @@
import org.eclipse.jdt.internal.corext.codemanipulation.ContextSensitiveImportRewriteContext;
import org.eclipse.lsp4j.CodeActionKind;
-/**
- * Code action proposal for annotation reused from
- * https://github.com/eclipse/lsp4mp/blob/6f2d700a88a3262e39cc2ba04beedb429e162246/microprofile.jdt/org.eclipse.lsp4mp.jdt.core/src/main/java/org/eclipse/lsp4mp/jdt/core/java/corrections/proposal/NewAnnotationProposal.java
- */
-public class NewAnnotationProposal extends ChangeCorrectionProposal {
+public class InsertAnnotationProposal extends ASTRewriteCorrectionProposal {
private final CompilationUnit fInvocationNode;
private final IBinding fBinding;
- protected final String[] annotations;
+ private final String[] annotations;
- public NewAnnotationProposal(String label, ICompilationUnit targetCU, CompilationUnit invocationNode,
- IBinding binding, int relevance, String... annotations) {
+ public InsertAnnotationProposal(String label, ICompilationUnit targetCU, CompilationUnit invocationNode,
+ IBinding binding, int relevance, String... annotations) {
super(label, CodeActionKind.QuickFix, targetCU, null, relevance);
fInvocationNode = invocationNode;
fBinding = binding;
@@ -82,7 +78,7 @@ protected ASTRewrite getRewrite() throws CoreException {
} else if (declNode instanceof MethodDeclaration) {
rewrite.getListRewrite(declNode, MethodDeclaration.MODIFIERS2_PROPERTY).insertFirst(marker, null);
} else if (declNode instanceof TypeDeclaration) {
- rewrite.getListRewrite(declNode,TypeDeclaration.MODIFIERS2_PROPERTY).insertFirst(marker, null);
+ rewrite.getListRewrite(declNode, TypeDeclaration.MODIFIERS2_PROPERTY).insertFirst(marker, null);
}
}
@@ -93,7 +89,7 @@ protected ASTRewrite getRewrite() throws CoreException {
/**
* Returns the Compilation Unit node
- *
+ *
* @return the invocation node for the Compilation Unit
*/
protected CompilationUnit getInvocationNode() {
@@ -102,7 +98,7 @@ protected CompilationUnit getInvocationNode() {
/**
* Returns the Binding object associated with the new annotation change
- *
+ *
* @return the binding object
*/
protected IBinding getBinding() {
@@ -111,10 +107,10 @@ protected IBinding getBinding() {
/**
* Returns the annotations list
- *
+ *
* @return the list of new annotations to add
*/
protected String[] getAnnotations() {
return this.annotations;
}
-}
\ No newline at end of file
+}
diff --git a/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/core/java/corrections/proposal/LinkedCorrectionProposal.java b/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/core/java/corrections/proposal/LinkedCorrectionProposal.java
new file mode 100644
index 00000000..e44fb44f
--- /dev/null
+++ b/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/core/java/corrections/proposal/LinkedCorrectionProposal.java
@@ -0,0 +1,173 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2012 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License 2.0
+ * which accompanies this distribution, and is available at
+ * https://www.eclipse.org/legal/epl-2.0/
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ * Originally copied from org.eclipse.jdt.internal.corrections.proposals.LinkedCorrectionProposal;
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.lsp4jakarta.jdt.core.java.corrections.proposal;
+
+import org.eclipse.jdt.core.ICompilationUnit;
+import org.eclipse.jdt.core.dom.ITypeBinding;
+import org.eclipse.jdt.core.dom.rewrite.ASTRewrite;
+import org.eclipse.jdt.core.dom.rewrite.ITrackedNodePosition;
+import org.eclipse.jdt.internal.corext.fix.LinkedProposalModelCore;
+
+/**
+ * A proposal for quick fixes and quick assists that works on a AST rewriter and
+ * enters the linked mode when the proposal is set up. Either a rewriter is
+ * directly passed in the constructor or method {@link #getRewrite()} is
+ * overridden to provide the AST rewriter that is evaluated to the document when
+ * the proposal is applied.
+ *
+ * @since 3.0
+ */
+public class LinkedCorrectionProposal extends ASTRewriteCorrectionProposal {
+
+ private LinkedProposalModelCore fLinkedProposalModel;
+
+ /**
+ * Constructs a linked correction proposal.
+ *
+ * @param name The display name of the proposal.
+ * @param cu The compilation unit that is modified.
+ * @param rewrite The AST rewrite that is invoked when the proposal is applied
+ * null
can be passed if {@link #getRewrite()} is
+ * overridden.
+ * @param relevance The relevance of this proposal.
+ * @param image The image that is displayed for this proposal or
+ * null
if no image is desired.
+ */
+ public LinkedCorrectionProposal(String name, String kind, ICompilationUnit cu, ASTRewrite rewrite, int relevance) {
+ super(name, kind, cu, rewrite, relevance);
+ fLinkedProposalModel = null;
+ }
+
+ public LinkedProposalModelCore getLinkedProposalModel() {
+ if (fLinkedProposalModel == null) {
+ fLinkedProposalModel = new LinkedProposalModelCore();
+ }
+ return fLinkedProposalModel;
+ }
+
+ public void setLinkedProposalModel(LinkedProposalModelCore model) {
+ fLinkedProposalModel = model;
+ }
+
+ /**
+ * Adds a linked position to be shown when the proposal is applied. All
+ * positions with the same group id are linked.
+ *
+ * @param position The position to add.
+ * @param isFirst If set, the proposal is jumped to first.
+ * @param groupID The id of the group the proposal belongs to. All proposals in
+ * the same group are linked.
+ */
+ public void addLinkedPosition(ITrackedNodePosition position, boolean isFirst, String groupID) {
+ getLinkedProposalModel().getPositionGroup(groupID, true).addPosition(position, isFirst);
+ }
+
+ /**
+ * Adds a linked position to be shown when the proposal is applied. All
+ * positions with the same group id are linked.
+ *
+ * @param position The position to add.
+ * @param sequenceRank The sequence rank, see TODO.
+ * @param groupID The id of the group the proposal belongs to. All
+ * proposals in the same group are linked.
+ */
+ public void addLinkedPosition(ITrackedNodePosition position, int sequenceRank, String groupID) {
+ getLinkedProposalModel().getPositionGroup(groupID, true).addPosition(position, sequenceRank);
+ }
+
+ /**
+ * Sets the end position of the linked mode to the end of the passed range.
+ *
+ * @param position The position that describes the end position of the linked
+ * mode.
+ */
+ public void setEndPosition(ITrackedNodePosition position) {
+ getLinkedProposalModel().setEndPosition(position);
+ }
+
+ /**
+ * Adds a linked position proposal to the group with the given id.
+ *
+ * @param groupID The id of the group that should present the proposal
+ * @param proposal The string to propose.
+ * @param image The image to show for the position proposal or
+ * null
if no image is desired.
+ */
+ public void addLinkedPositionProposal(String groupID, String proposal) {
+ getLinkedProposalModel().getPositionGroup(groupID, true).addProposal(proposal, 10);
+ }
+
+ // /**
+ // * Adds a linked position proposal to the group with the given id.
+ // *
+ // * @param groupID
+ // * The id of the group that should present the proposal
+ // * @param displayString
+ // * The name of the proposal
+ // * @param proposal
+ // * The string to insert.
+ // * @param image
+ // * The image to show for the position proposal or
+ // * null
if no image is desired.
+ // * @deprecated use {@link #addLinkedPositionProposal(String, String, Image)}
+ // * instead
+ // */
+ // @Deprecated
+ // public void addLinkedPositionProposal(String groupID, String displayString,
+ // String proposal, Image image) {
+ // addLinkedPositionProposal(groupID, proposal, image);
+ // }
+
+ /**
+ * Adds a linked position proposal to the group with the given id.
+ *
+ * @param groupID The id of the group that should present the proposal
+ * @param type The binding to use as type name proposal.
+ */
+ public void addLinkedPositionProposal(String groupID, ITypeBinding type) {
+ getLinkedProposalModel().getPositionGroup(groupID, true).addProposal(type, getCompilationUnit(), 10);
+ }
+
+ // @Override
+ // protected void performChange(IEditorPart part, IDocument document) throws
+ // CoreException {
+ // try {
+ // super.performChange(part, document);
+ // if (part == null) {
+ // return;
+ // }
+ //
+ // if (fLinkedProposalModel != null) {
+ // if (fLinkedProposalModel.hasLinkedPositions() && part instanceof JavaEditor)
+ // {
+ // // enter linked mode
+ // ITextViewer viewer = ((JavaEditor) part).getViewer();
+ // new LinkedProposalModelPresenter().enterLinkedMode(viewer, part,
+ // didOpenEditor(), fLinkedProposalModel);
+ // } else if (part instanceof ITextEditor) {
+ // LinkedProposalPositionGroup.PositionInformation endPosition =
+ // fLinkedProposalModel.getEndPosition();
+ // if (endPosition != null) {
+ // // select a result
+ // int pos = endPosition.getOffset() + endPosition.getLength();
+ // ((ITextEditor) part).selectAndReveal(pos, 0);
+ // }
+ // }
+ // }
+ // } catch (BadLocationException e) {
+ // throw new CoreException(JavaUIStatus.createError(IStatus.ERROR, e));
+ // }
+ // }
+}
diff --git a/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/codeAction/proposal/ModifyAnnotationProposal.java b/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/core/java/corrections/proposal/ModifyAnnotationProposal.java
similarity index 84%
rename from jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/codeAction/proposal/ModifyAnnotationProposal.java
rename to jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/core/java/corrections/proposal/ModifyAnnotationProposal.java
index fef7f91f..8d8b40dd 100644
--- a/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/codeAction/proposal/ModifyAnnotationProposal.java
+++ b/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/core/java/corrections/proposal/ModifyAnnotationProposal.java
@@ -1,16 +1,16 @@
-/*******************************************************************************
- * Copyright (c) 2021, 2022 IBM Corporation and others.
- *
+/*******************************************************************************
+ * Copyright (c) 2021, 2022 IBM Corporation 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.
*
* SPDX-License-Identifier: EPL-2.0
- *
- * Contributors:
+ *
+ * Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
-package org.eclipse.lsp4jakarta.jdt.codeAction.proposal;
+package org.eclipse.lsp4jakarta.jdt.core.java.corrections.proposal;
import static java.util.stream.Collectors.toList;
@@ -29,10 +29,10 @@
import org.eclipse.jdt.core.dom.IBinding;
import org.eclipse.jdt.core.dom.MemberValuePair;
import org.eclipse.jdt.core.dom.NormalAnnotation;
+import org.eclipse.jdt.core.dom.SingleVariableDeclaration;
import org.eclipse.jdt.core.dom.StringLiteral;
import org.eclipse.jdt.core.dom.TypeDeclaration;
import org.eclipse.jdt.core.dom.VariableDeclarationFragment;
-import org.eclipse.jdt.core.dom.SingleVariableDeclaration;
import org.eclipse.jdt.core.dom.rewrite.ASTRewrite;
import org.eclipse.jdt.core.dom.rewrite.ImportRewrite;
import org.eclipse.jdt.core.dom.rewrite.ImportRewrite.ImportRewriteContext;
@@ -40,15 +40,15 @@
import org.eclipse.jdt.internal.corext.codemanipulation.ContextSensitiveImportRewriteContext;
/**
- *
+ *
* Code action proposal for modifying an existing annotation. Option for adding
* additional string attributes and option for removing string attributes from
* specified annotation.
- *
+ *
* @author Kathryn Kodama
*
*/
-public class ModifyAnnotationProposal extends NewAnnotationProposal {
+public class ModifyAnnotationProposal extends InsertAnnotationProposal {
// list of attributes to add to the annotations
private final List attributesToAdd;
@@ -57,20 +57,22 @@ public class ModifyAnnotationProposal extends NewAnnotationProposal {
private final List attributesToRemove;
public ModifyAnnotationProposal(String label, ICompilationUnit targetCU, CompilationUnit invocationNode,
- IBinding binding, int relevance, String annotation, List attributesToAdd,
- List attributesToRemove) {
+ IBinding binding, int relevance, String annotation, List attributesToAdd,
+ List attributesToRemove) {
super(label, targetCU, invocationNode, binding, relevance, annotation);
this.attributesToAdd = attributesToAdd;
this.attributesToRemove = attributesToRemove;
}
+
public ModifyAnnotationProposal(String label, ICompilationUnit targetCU, CompilationUnit invocationNode,
- IBinding binding, int relevance, String annotation, List attributesToAdd) {
+ IBinding binding, int relevance, String annotation, List attributesToAdd) {
super(label, targetCU, invocationNode, binding, relevance, annotation);
this.attributesToAdd = attributesToAdd;
this.attributesToRemove = new ArrayList<>();
}
+
public ModifyAnnotationProposal(String label, ICompilationUnit targetCU, CompilationUnit invocationNode,
- IBinding binding, int relevance, List attributesToAdd, String... annotations) {
+ IBinding binding, int relevance, List attributesToAdd, String... annotations) {
super(label, targetCU, invocationNode, binding, relevance, annotations);
this.attributesToAdd = attributesToAdd;
this.attributesToRemove = new ArrayList<>();
@@ -115,26 +117,22 @@ protected ASTRewrite getRewrite() throws CoreException {
ImportRewriteContext importRewriteContext = new ContextSensitiveImportRewriteContext(declNode, imports);
List existingAnnotations = new ArrayList();
- List extends ASTNode> children = (List extends ASTNode>) declNode
- .getStructuralProperty(FieldDeclaration.MODIFIERS2_PROPERTY);
+ List extends ASTNode> children = (List extends ASTNode>) declNode.getStructuralProperty(FieldDeclaration.MODIFIERS2_PROPERTY);
// for all existing annotations (that are the annotation we want)
for (ASTNode child : children) {
if (child instanceof Annotation) {
Annotation annotation = (Annotation) child;
- boolean containsAnnotation = Arrays.stream(annotationShortNames)
- .anyMatch(annotation.getTypeName().toString()::contains);
-
- // check if current child annotation has all attributes to add already or any to remove
+ boolean containsAnnotation = Arrays.stream(annotationShortNames).anyMatch(annotation.getTypeName().toString()::contains);
+
+ // check if current child annotation has all attributes to add already or any to
+ // remove
if (containsAnnotation && child instanceof NormalAnnotation) {
- List existingValues = (List) ((NormalAnnotation) child).values().stream()
- .map(mvp -> ((MemberValuePair) mvp).getName().toString()).collect(toList());
-
- boolean containsAllToAdd = this.attributesToAdd.stream()
- .allMatch(attr -> existingValues.stream().anyMatch(v -> v.equals(attr)));
- boolean containsAnyToRemove = this.attributesToRemove.stream()
- .anyMatch(attr -> existingValues.stream().anyMatch(v -> v.equals(attr)));
-
+ List existingValues = (List) ((NormalAnnotation) child).values().stream().map(mvp -> ((MemberValuePair) mvp).getName().toString()).collect(toList());
+
+ boolean containsAllToAdd = this.attributesToAdd.stream().allMatch(attr -> existingValues.stream().anyMatch(v -> v.equals(attr)));
+ boolean containsAnyToRemove = this.attributesToRemove.stream().anyMatch(attr -> existingValues.stream().anyMatch(v -> v.equals(attr)));
+
if (!containsAllToAdd || containsAnyToRemove) {
existingAnnotations.add(annotation);
rewrite.remove(child, null);
@@ -143,20 +141,19 @@ protected ASTRewrite getRewrite() throws CoreException {
}
}
-
// add new annotations to proposal (restoring those that were removed)
for (Annotation a : existingAnnotations) {
if (a instanceof NormalAnnotation) {
NormalAnnotation marker = ast.newNormalAnnotation();
- marker.setTypeName(ast.newName(imports.addImport(a.getTypeName().toString(), importRewriteContext)));
+ marker.setTypeName(
+ ast.newName(imports.addImport(a.getTypeName().toString(), importRewriteContext)));
List values = marker.values();
-
+
// add existing attributes to annotation
List existingValues = ((NormalAnnotation) a).values();
for (MemberValuePair mvp : existingValues) {
- boolean removeAttribute = this.attributesToRemove
- .contains(mvp.getName().getFullyQualifiedName());
-
+ boolean removeAttribute = this.attributesToRemove.contains(mvp.getName().getFullyQualifiedName());
+
// do not add attributes to be removed
if (!removeAttribute) {
MemberValuePair memberValuePair = ast.newMemberValuePair();
@@ -173,7 +170,7 @@ protected ASTRewrite getRewrite() throws CoreException {
values.add(memberValuePair);
}
}
-
+
// add new attributes
for (String newAttr : this.attributesToAdd) {
// dont add duplicate attributes to an annotation
@@ -186,50 +183,46 @@ protected ASTRewrite getRewrite() throws CoreException {
values.add(memberValuePair);
}
}
-
+
rewrite.getListRewrite(declNode,
- isField ? FieldDeclaration.MODIFIERS2_PROPERTY : TypeDeclaration.MODIFIERS2_PROPERTY)
- .insertFirst(marker, null);
- }
+ isField ? FieldDeclaration.MODIFIERS2_PROPERTY : TypeDeclaration.MODIFIERS2_PROPERTY).insertFirst(marker, null);
+ }
}
-
+
return rewrite;
} else if (declNode instanceof TypeDeclaration || isField || isSingleVarDecl) {
AST ast = declNode.getAST();
ASTRewrite rewrite = ASTRewrite.create(ast);
-
+
ImportRewriteContext importRewriteContext = new ContextSensitiveImportRewriteContext(declNode, imports);
List existingAnnotations = new ArrayList();
ChildListPropertyDescriptor property = isSingleVarDecl ? SingleVariableDeclaration.MODIFIERS2_PROPERTY : TypeDeclaration.MODIFIERS2_PROPERTY;
- List extends ASTNode> children = (List extends ASTNode>) declNode
- .getStructuralProperty(property);
+ List extends ASTNode> children = (List extends ASTNode>) declNode.getStructuralProperty(property);
// find and save existing annotation, then remove it from ast
for (ASTNode child : children) {
if (child instanceof Annotation) {
Annotation annotation = (Annotation) child;
- boolean containsAnnotation = Arrays.stream(annotationShortNames)
- .anyMatch(annotation.getTypeName().toString()::contains);
+ boolean containsAnnotation = Arrays.stream(annotationShortNames).anyMatch(annotation.getTypeName().toString()::contains);
if (containsAnnotation) {
existingAnnotations.add(annotation);
rewrite.remove(child, null);
}
}
}
-
+
// add new annotation with fields from existing annotation
for (String annotation : annotations) {
NormalAnnotation marker = ast.newNormalAnnotation();
marker.setTypeName(ast.newName(imports.addImport(annotation, importRewriteContext)));
List values = marker.values();
-
+
if (!existingAnnotations.isEmpty()) {
for (Annotation a : existingAnnotations) {
if (a instanceof NormalAnnotation) {
List existingValues = ((NormalAnnotation) a).values();
for (MemberValuePair mvp : existingValues) {
- boolean removeAttribute = this.attributesToRemove
- .contains(mvp.getName().getFullyQualifiedName());
+ boolean removeAttribute = this.attributesToRemove.contains(mvp.getName().getFullyQualifiedName());
// do not add attribute to be removed
if (!removeAttribute) {
@@ -260,7 +253,7 @@ protected ASTRewrite getRewrite() throws CoreException {
memberValuePair.setValue(stringValue);
values.add(memberValuePair);
}
-
+
ChildListPropertyDescriptor newRewrite;
if (isSingleVarDecl) {
newRewrite = SingleVariableDeclaration.MODIFIERS2_PROPERTY;
@@ -270,8 +263,7 @@ protected ASTRewrite getRewrite() throws CoreException {
newRewrite = TypeDeclaration.MODIFIERS2_PROPERTY;
}
- rewrite.getListRewrite(declNode, newRewrite)
- .insertFirst(marker, null);
+ rewrite.getListRewrite(declNode, newRewrite).insertFirst(marker, null);
}
return rewrite;
}
diff --git a/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/codeAction/proposal/ModifyModifiersProposal.java b/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/core/java/corrections/proposal/ModifyModifiersProposal.java
similarity index 59%
rename from jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/codeAction/proposal/ModifyModifiersProposal.java
rename to jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/core/java/corrections/proposal/ModifyModifiersProposal.java
index a54635d3..982b0e94 100644
--- a/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/codeAction/proposal/ModifyModifiersProposal.java
+++ b/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/core/java/corrections/proposal/ModifyModifiersProposal.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2021 IBM Corporation, Matthew Shocrylas and others.
+* Copyright (c) 2021, 2023 IBM Corporation 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
@@ -11,17 +11,15 @@
* IBM Corporation, Matthew Shocrylas - initial API and implementation
*******************************************************************************/
-package org.eclipse.lsp4jakarta.jdt.codeAction.proposal;
+package org.eclipse.lsp4jakarta.jdt.core.java.corrections.proposal;
import java.util.ArrayList;
-import java.util.Arrays;
import java.util.List;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.jdt.core.ICompilationUnit;
import org.eclipse.jdt.core.dom.AST;
import org.eclipse.jdt.core.dom.ASTNode;
-import org.eclipse.jdt.core.dom.AnonymousClassDeclaration;
import org.eclipse.jdt.core.dom.CompilationUnit;
import org.eclipse.jdt.core.dom.FieldDeclaration;
import org.eclipse.jdt.core.dom.IBinding;
@@ -33,30 +31,28 @@
import org.eclipse.jdt.core.dom.TypeDeclaration;
import org.eclipse.jdt.core.dom.VariableDeclarationFragment;
import org.eclipse.jdt.core.dom.rewrite.ASTRewrite;
-import org.eclipse.jdt.core.dom.rewrite.ImportRewrite;
import org.eclipse.jdt.core.dom.rewrite.ListRewrite;
-import org.eclipse.jdt.core.dom.rewrite.ImportRewrite.ImportRewriteContext;
import org.eclipse.jdt.internal.core.manipulation.dom.ASTResolving;
-import org.eclipse.jdt.internal.corext.codemanipulation.ContextSensitiveImportRewriteContext;
import org.eclipse.lsp4j.CodeActionKind;
+import org.eclipse.lsp4jakarta.jdt.internal.jaxrs.InsertDefaultPublicConstructorQuickFix;
/**
- * Code action proposal for changing the visibility modifier of a method, field, or type.
- * Used by JAX-RS NonPublicResourceMethodQuickFix.
- *
- * @author Matthew Shocrylas
- * @author Leslie Dawson
- * @see CodeActionHandler
- * @see NonPublicResourceMethodQuickFix
- * @see PersistenceEntityQuickFix
- *
+ * Code action proposal for changing the visibility modifier of a method, field,
+ * or type. Used by JAX-RS NonPublicResourceMethodQuickFix.
+ *
+ * @author Matthew Shocrylas
+ * @author Leslie Dawson
+ * @see CodeActionHandler
+ * @see InsertDefaultPublicConstructorQuickFix
+ * @see PersistenceEntityQuickFix
+ *
*/
-public class ModifyModifiersProposal extends ChangeCorrectionProposal {
+public class ModifyModifiersProposal extends ASTRewriteCorrectionProposal {
private final CompilationUnit invocationNode;
private final IBinding binding;
private final ASTNode coveredNode;
-
+
// list of modifiers to add
private final List modifiersToAdd;
@@ -64,43 +60,46 @@ public class ModifyModifiersProposal extends ChangeCorrectionProposal {
private final List modifiersToRemove;
/**
- * Constructor for ModifyModifiersProposal that accepts both a list of modifiers to remove as well as to add
- *
- * @param modifiersToAdd list of valid modifiers as strings to be added
- * @param modifiersToRemove list of modifiers as strings to be removed
+ * Constructor for ModifyModifiersProposal that accepts both a list of modifiers
+ * to remove as well as to add
+ *
+ * @param modifiersToAdd list of valid modifiers as strings to be added
+ * @param modifiersToRemove list of modifiers as strings to be removed
*/
public ModifyModifiersProposal(String label, ICompilationUnit targetCU, CompilationUnit invocationNode,
- IBinding binding, int relevance, ASTNode coveredNode, List modifiersToAdd, List modifiersToRemove) {
+ IBinding binding, int relevance, ASTNode coveredNode, List modifiersToAdd,
+ List modifiersToRemove) {
super(label, CodeActionKind.QuickFix, targetCU, null, relevance);
this.invocationNode = invocationNode;
this.binding = binding;
this.coveredNode = coveredNode;
- this.modifiersToAdd = modifiersToAdd;
+ this.modifiersToAdd = modifiersToAdd;
this.modifiersToRemove = modifiersToRemove;
}
-
+
/**
- * Constructor for ModifyModifiersProposal that accepts only a list of modifiers to add
- * If a visibility modifier is specified to be added, existing visibility modifiers will be removed
+ * Constructor for ModifyModifiersProposal that accepts only a list of modifiers
+ * to add If a visibility modifier is specified to be added, existing visibility
+ * modifiers will be removed
*
- * @param modifiersToAdd list of valid modifiers as strings to be added
+ * @param modifiersToAdd list of valid modifiers as strings to be added
*/
public ModifyModifiersProposal(String label, ICompilationUnit targetCU, CompilationUnit invocationNode,
- IBinding binding, int relevance, ASTNode coveredNode, List modifiersToAdd) {
+ IBinding binding, int relevance, ASTNode coveredNode, List modifiersToAdd) {
super(label, CodeActionKind.QuickFix, targetCU, null, relevance);
this.invocationNode = invocationNode;
this.binding = binding;
this.coveredNode = coveredNode;
- this.modifiersToAdd = modifiersToAdd;
+ this.modifiersToAdd = modifiersToAdd;
this.modifiersToRemove = new ArrayList<>();
}
-
+
@Override
protected ASTRewrite getRewrite() throws CoreException {
ASTNode declNode = null;
ASTNode boundNode = invocationNode.findDeclaringNode(binding);
CompilationUnit newRoot = invocationNode;
-
+
if (boundNode != null) {
declNode = boundNode;
} else {
@@ -116,33 +115,32 @@ protected ASTRewrite getRewrite() throws CoreException {
declNode = declNode.getParent();
}
-
AST ast = declNode.getAST();
ASTRewrite rewrite = ASTRewrite.create(ast);
ListRewrite modifiersList = null;
List modifiers = new ArrayList();
- switch(declNode.getNodeType()) {
- case ASTNode.METHOD_DECLARATION:
- modifiersList = rewrite.getListRewrite(declNode, MethodDeclaration.MODIFIERS2_PROPERTY);
- modifiers = (List) declNode.getStructuralProperty(MethodDeclaration.MODIFIERS2_PROPERTY);
- break;
- case ASTNode.FIELD_DECLARATION:
- modifiersList = rewrite.getListRewrite(declNode, FieldDeclaration.MODIFIERS2_PROPERTY);
- modifiers = (List) declNode.getStructuralProperty(FieldDeclaration.MODIFIERS2_PROPERTY);
- break;
- case ASTNode.TYPE_DECLARATION:
- modifiersList = rewrite.getListRewrite(declNode, TypeDeclaration.MODIFIERS2_PROPERTY);
- modifiers = (List) declNode.getStructuralProperty(TypeDeclaration.MODIFIERS2_PROPERTY);
- break;
- case ASTNode.SINGLE_VARIABLE_DECLARATION:
- modifiersList = rewrite.getListRewrite(declNode, SingleVariableDeclaration.MODIFIERS2_PROPERTY);
- modifiers = (List) declNode.getStructuralProperty(SingleVariableDeclaration.MODIFIERS2_PROPERTY);
- break;
- default:
- modifiersList = null;
- }
+ switch (declNode.getNodeType()) {
+ case ASTNode.METHOD_DECLARATION:
+ modifiersList = rewrite.getListRewrite(declNode, MethodDeclaration.MODIFIERS2_PROPERTY);
+ modifiers = (List) declNode.getStructuralProperty(MethodDeclaration.MODIFIERS2_PROPERTY);
+ break;
+ case ASTNode.FIELD_DECLARATION:
+ modifiersList = rewrite.getListRewrite(declNode, FieldDeclaration.MODIFIERS2_PROPERTY);
+ modifiers = (List) declNode.getStructuralProperty(FieldDeclaration.MODIFIERS2_PROPERTY);
+ break;
+ case ASTNode.TYPE_DECLARATION:
+ modifiersList = rewrite.getListRewrite(declNode, TypeDeclaration.MODIFIERS2_PROPERTY);
+ modifiers = (List) declNode.getStructuralProperty(TypeDeclaration.MODIFIERS2_PROPERTY);
+ break;
+ case ASTNode.SINGLE_VARIABLE_DECLARATION:
+ modifiersList = rewrite.getListRewrite(declNode, SingleVariableDeclaration.MODIFIERS2_PROPERTY);
+ modifiers = (List) declNode.getStructuralProperty(SingleVariableDeclaration.MODIFIERS2_PROPERTY);
+ break;
+ default:
+ modifiersList = null;
+ }
for (ASTNode modifier : modifiers) {
if (modifier instanceof MarkerAnnotation) {
@@ -153,8 +151,7 @@ protected ASTRewrite getRewrite() throws CoreException {
modifiersList.remove(markAnno, null);
continue;
}
- }
- else if (modifier instanceof Modifier) {
+ } else if (modifier instanceof Modifier) {
Modifier.ModifierKeyword modKeyword = ((Modifier) modifier).getKeyword();
// Check if modifier is in toRemove list
@@ -164,14 +161,14 @@ else if (modifier instanceof Modifier) {
}
// Otherwise check if the existing modifier is private, public or protected
- if (modKeyword.equals(Modifier.ModifierKeyword.PRIVATE_KEYWORD) ||
- modKeyword.equals(Modifier.ModifierKeyword.PUBLIC_KEYWORD) ||
- modKeyword.equals(Modifier.ModifierKeyword.PROTECTED_KEYWORD)) {
+ if (modKeyword.equals(Modifier.ModifierKeyword.PRIVATE_KEYWORD)
+ || modKeyword.equals(Modifier.ModifierKeyword.PUBLIC_KEYWORD)
+ || modKeyword.equals(Modifier.ModifierKeyword.PROTECTED_KEYWORD)) {
// if adding a visibility modifier, need to remove the existing one
- if (modifiersToAdd.stream().anyMatch(m -> (m.equals(Modifier.ModifierKeyword.PRIVATE_KEYWORD.toString()) ||
- m.equals(Modifier.ModifierKeyword.PUBLIC_KEYWORD.toString()) ||
- m.equals(Modifier.ModifierKeyword.PROTECTED_KEYWORD.toString())))) {
+ if (modifiersToAdd.stream().anyMatch(m -> (m.equals(Modifier.ModifierKeyword.PRIVATE_KEYWORD.toString())
+ || m.equals(Modifier.ModifierKeyword.PUBLIC_KEYWORD.toString())
+ || m.equals(Modifier.ModifierKeyword.PROTECTED_KEYWORD.toString())))) {
modifiersList.remove(modifier, null);
}
}
diff --git a/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/codeAction/proposal/ModifyReturnTypeProposal.java b/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/core/java/corrections/proposal/ModifyReturnTypeProposal.java
similarity index 83%
rename from jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/codeAction/proposal/ModifyReturnTypeProposal.java
rename to jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/core/java/corrections/proposal/ModifyReturnTypeProposal.java
index ac94b9fd..1f43095f 100644
--- a/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/codeAction/proposal/ModifyReturnTypeProposal.java
+++ b/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/core/java/corrections/proposal/ModifyReturnTypeProposal.java
@@ -10,7 +10,7 @@
* Contributors:
* Yijia Jing
*******************************************************************************/
-package org.eclipse.lsp4jakarta.jdt.codeAction.proposal;
+package org.eclipse.lsp4jakarta.jdt.core.java.corrections.proposal;
import org.eclipse.jdt.core.ICompilationUnit;
import org.eclipse.jdt.core.dom.AST;
@@ -22,48 +22,50 @@
import org.eclipse.jdt.core.dom.rewrite.ASTRewrite;
import org.eclipse.jdt.internal.core.manipulation.dom.ASTResolving;
import org.eclipse.lsp4j.CodeActionKind;
+import org.eclipse.lsp4jakarta.jdt.internal.annotations.ModifyConstructReturnTypeQuickFix;
/**
* Code action proposal for changing the return type of a method.
- *
+ *
* @author Yijia Jing
* @see CodeActionHandler
- * @see PostConstructReturnTypeQuickFix
+ * @see ModifyConstructReturnTypeQuickFix
*
*/
-public class ModifyReturnTypeProposal extends ChangeCorrectionProposal {
-
+public class ModifyReturnTypeProposal extends ASTRewriteCorrectionProposal {
+
private final CompilationUnit invocationNode;
private final IBinding binding;
private final Type newReturnType;
/**
- * Constructor for ModifyReturnTypeProposal that accepts the new return type of a method.
- *
+ * Constructor for ModifyReturnTypeProposal that accepts the new return type of
+ * a method.
+ *
* @param newReturnType the new return type to change to
*/
- public ModifyReturnTypeProposal(String label, ICompilationUnit targetCU, CompilationUnit invocationNode,
- IBinding binding, int relevance, Type newReturnType) {
+ public ModifyReturnTypeProposal(String label, ICompilationUnit targetCU, CompilationUnit invocationNode,
+ IBinding binding, int relevance, Type newReturnType) {
super(label, CodeActionKind.QuickFix, targetCU, null, relevance);
this.invocationNode = invocationNode;
this.binding = binding;
this.newReturnType = newReturnType;
}
-
+
@SuppressWarnings("restriction")
@Override
protected ASTRewrite getRewrite() {
ASTNode declNode = null;
ASTNode boundNode = invocationNode.findDeclaringNode(binding);
CompilationUnit newRoot = invocationNode;
-
+
if (boundNode != null) {
declNode = boundNode;
} else {
newRoot = ASTResolving.createQuickFixAST(getCompilationUnit(), null);
declNode = newRoot.findDeclaringNode(binding.getKey());
}
-
+
if (declNode.getNodeType() == ASTNode.METHOD_DECLARATION) {
AST ast = declNode.getAST();
ASTRewrite rewrite = ASTRewrite.create(ast);
diff --git a/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/codeAction/proposal/DeleteAnnotationProposal.java b/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/core/java/corrections/proposal/RemoveAnnotationProposal.java
similarity index 82%
rename from jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/codeAction/proposal/DeleteAnnotationProposal.java
rename to jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/core/java/corrections/proposal/RemoveAnnotationProposal.java
index bfe265eb..35efd8ab 100644
--- a/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/codeAction/proposal/DeleteAnnotationProposal.java
+++ b/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/core/java/corrections/proposal/RemoveAnnotationProposal.java
@@ -11,7 +11,7 @@
* Contributors:
* IBM Corporation, Jianing Xu - initial API and implementation
*******************************************************************************/
-package org.eclipse.lsp4jakarta.jdt.codeAction.proposal;
+package org.eclipse.lsp4jakarta.jdt.core.java.corrections.proposal;
import java.util.Arrays;
import java.util.List;
@@ -23,7 +23,6 @@
import org.eclipse.jdt.core.dom.Annotation;
import org.eclipse.jdt.core.dom.CompilationUnit;
import org.eclipse.jdt.core.dom.FieldDeclaration;
-import org.eclipse.jdt.core.dom.IAnnotationBinding;
import org.eclipse.jdt.core.dom.IBinding;
import org.eclipse.jdt.core.dom.MethodDeclaration;
import org.eclipse.jdt.core.dom.TypeDeclaration;
@@ -36,14 +35,14 @@
import org.eclipse.lsp4j.CodeActionKind;
/**
- *
+ *
* Code action proposal for deleting an existing annotation for
* MethodDeclaration/Field.
- *
+ *
* Author: Jianing Xu
*
*/
-public class DeleteAnnotationProposal extends ChangeCorrectionProposal {
+public class RemoveAnnotationProposal extends ASTRewriteCorrectionProposal {
private final CompilationUnit fInvocationNode;
private final IBinding fBinding;
@@ -52,18 +51,18 @@ public class DeleteAnnotationProposal extends ChangeCorrectionProposal {
/**
* Constructor for DeleteAnnotationProposal
- *
- * @param label - annotation label
- * @param targetCU - the entire Java compilation unit
+ *
+ * @param label - annotation label
+ * @param targetCU - the entire Java compilation unit
* @param invocationNode
* @param binding
* @param relevance
- * @param declaringNode - declaringNode covered node of diagnostic
+ * @param declaringNode - declaringNode covered node of diagnostic
* @param annotations
- *
+ *
*/
- public DeleteAnnotationProposal(String label, ICompilationUnit targetCU, CompilationUnit invocationNode,
- IBinding binding, int relevance, ASTNode declaringNode, String... annotations) {
+ public RemoveAnnotationProposal(String label, ICompilationUnit targetCU, CompilationUnit invocationNode,
+ IBinding binding, int relevance, ASTNode declaringNode, String... annotations) {
super(label, CodeActionKind.QuickFix, targetCU, null, relevance);
this.fInvocationNode = invocationNode;
this.fBinding = binding;
@@ -107,14 +106,11 @@ protected ASTRewrite getRewrite() throws CoreException {
@SuppressWarnings("unchecked")
List extends ASTNode> children;
if (isMethod) {
- children = (List extends ASTNode>) declNode
- .getStructuralProperty(MethodDeclaration.MODIFIERS2_PROPERTY);
+ children = (List extends ASTNode>) declNode.getStructuralProperty(MethodDeclaration.MODIFIERS2_PROPERTY);
} else if (isType) {
- children = (List extends ASTNode>) declNode
- .getStructuralProperty(TypeDeclaration.MODIFIERS2_PROPERTY);
+ children = (List extends ASTNode>) declNode.getStructuralProperty(TypeDeclaration.MODIFIERS2_PROPERTY);
} else {
- children = (List extends ASTNode>) declNode
- .getStructuralProperty(FieldDeclaration.MODIFIERS2_PROPERTY);
+ children = (List extends ASTNode>) declNode.getStructuralProperty(FieldDeclaration.MODIFIERS2_PROPERTY);
}
// find and save existing annotation, then remove it from ast
@@ -123,8 +119,7 @@ protected ASTRewrite getRewrite() throws CoreException {
Annotation annotation = (Annotation) child;
// IAnnotationBinding annotationBinding = annotation.resolveAnnotationBinding();
- boolean containsAnnotation = Arrays.stream(annotationShortNames)
- .anyMatch(annotation.getTypeName().toString()::equals);
+ boolean containsAnnotation = Arrays.stream(annotationShortNames).anyMatch(annotation.getTypeName().toString()::equals);
if (containsAnnotation) {
rewrite.remove(child, null);
}
@@ -148,7 +143,7 @@ protected CompilationUnit getInvocationNode() {
/**
* Returns the Binding object associated with the new annotation change
- *
+ *
* @return the binding object
*/
protected IBinding getBinding() {
@@ -157,7 +152,7 @@ protected IBinding getBinding() {
/**
* Returns the annotations list
- *
+ *
* @return the list of new annotations to add
*/
protected String[] getAnnotations() {
diff --git a/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/codeAction/proposal/RemoveParamsProposal.java b/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/core/java/corrections/proposal/RemoveParamsProposal.java
similarity index 84%
rename from jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/codeAction/proposal/RemoveParamsProposal.java
rename to jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/core/java/corrections/proposal/RemoveParamsProposal.java
index 5766a387..05f5fda2 100644
--- a/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/codeAction/proposal/RemoveParamsProposal.java
+++ b/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/core/java/corrections/proposal/RemoveParamsProposal.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2021 IBM Corporation, Bera Sogut and others.
+* Copyright (c) 2021, 2023 IBM Corporation 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
@@ -11,7 +11,7 @@
* IBM Corporation, Bera Sogut - initial API and implementation
*******************************************************************************/
-package org.eclipse.lsp4jakarta.jdt.codeAction.proposal;
+package org.eclipse.lsp4jakarta.jdt.core.java.corrections.proposal;
import java.util.List;
@@ -27,6 +27,7 @@
import org.eclipse.jdt.core.dom.rewrite.ListRewrite;
import org.eclipse.jdt.internal.core.manipulation.dom.ASTResolving;
import org.eclipse.lsp4j.CodeActionKind;
+import org.eclipse.lsp4jakarta.jdt.internal.jaxrs.RemoveMethodEntityParamsWithExclusionQuickFix;
/**
* Code action proposal for removing parameters of a method except one. Used by
@@ -34,10 +35,10 @@
*
* @author Bera Sogut
* @see CodeActionHandler
- * @see ResourceMethodMultipleEntityParamsQuickFix
+ * @see RemoveMethodEntityParamsWithExclusionQuickFix
*
*/
-public class RemoveParamsProposal extends ChangeCorrectionProposal {
+public class RemoveParamsProposal extends ASTRewriteCorrectionProposal {
private final CompilationUnit invocationNode;
private final IBinding binding;
@@ -52,12 +53,12 @@ public class RemoveParamsProposal extends ChangeCorrectionProposal {
* Constructor for RemoveParamsProposal that accepts parameters to remove and a
* parameter to keep.
*
- * @param params the parameters of the function to remove
+ * @param params the parameters of the function to remove
* @param paramToKeep the parameter of the function to keep
*/
public RemoveParamsProposal(String label, ICompilationUnit targetCU, CompilationUnit invocationNode,
- IBinding binding, int relevance, List params,
- SingleVariableDeclaration paramToKeep) {
+ IBinding binding, int relevance, List params,
+ SingleVariableDeclaration paramToKeep) {
super(label, CodeActionKind.QuickFix, targetCU, null, relevance);
this.invocationNode = invocationNode;
this.binding = binding;
diff --git a/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/core/java/corrections/proposal/ReplaceAnnotationProposal.java b/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/core/java/corrections/proposal/ReplaceAnnotationProposal.java
new file mode 100644
index 00000000..a16d45f0
--- /dev/null
+++ b/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/core/java/corrections/proposal/ReplaceAnnotationProposal.java
@@ -0,0 +1,107 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2016 IBM Corporation 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
+ *
+ * Copied from /org.eclipse.jdt.ui/src/org/eclipse/jdt/internal/ui/text/correction/proposals/NewAnnotationMemberProposal.java
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.lsp4jakarta.jdt.core.java.corrections.proposal;
+
+import java.util.Arrays;
+import java.util.List;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.jdt.core.ICompilationUnit;
+import org.eclipse.jdt.core.dom.AST;
+import org.eclipse.jdt.core.dom.ASTNode;
+import org.eclipse.jdt.core.dom.Annotation;
+import org.eclipse.jdt.core.dom.CompilationUnit;
+import org.eclipse.jdt.core.dom.FieldDeclaration;
+import org.eclipse.jdt.core.dom.IAnnotationBinding;
+import org.eclipse.jdt.core.dom.IBinding;
+import org.eclipse.jdt.core.dom.TypeDeclaration;
+import org.eclipse.jdt.core.dom.VariableDeclarationFragment;
+import org.eclipse.jdt.core.dom.rewrite.ASTRewrite;
+import org.eclipse.jdt.core.dom.rewrite.ImportRewrite;
+import org.eclipse.jdt.core.dom.rewrite.ImportRewrite.ImportRewriteContext;
+import org.eclipse.jdt.internal.core.manipulation.dom.ASTResolving;
+import org.eclipse.jdt.internal.corext.codemanipulation.ContextSensitiveImportRewriteContext;
+
+/**
+ * Similar functionality as NewAnnotationProposal. The main difference is that
+ * first removes specified annotations before adding a new annotation.
+ *
+ * Note: This class only accepts one new annotation to add.
+ *
+ * @author Kathryn Kodama
+ */
+public class ReplaceAnnotationProposal extends InsertAnnotationProposal {
+
+ private final String[] removeAnnotations;
+
+ public ReplaceAnnotationProposal(String label, ICompilationUnit targetCU, CompilationUnit invocationNode,
+ IBinding binding, int relevance, String annotation, String... removeAnnotations) {
+ super(label, targetCU, invocationNode, binding, relevance, annotation);
+ this.removeAnnotations = removeAnnotations;
+ }
+
+ @Override
+ protected ASTRewrite getRewrite() throws CoreException {
+ CompilationUnit fInvocationNode = getInvocationNode();
+ IBinding fBinding = getBinding();
+ String[] annotations = getAnnotations();
+
+ ASTNode declNode = null;
+ ASTNode boundNode = fInvocationNode.findDeclaringNode(fBinding);
+ CompilationUnit newRoot = fInvocationNode;
+ if (boundNode != null) {
+ declNode = boundNode; // is same CU
+ } else {
+ newRoot = ASTResolving.createQuickFixAST(getCompilationUnit(), null);
+ declNode = newRoot.findDeclaringNode(fBinding.getKey());
+ }
+ ImportRewrite imports = createImportRewrite(newRoot);
+
+ boolean isField = declNode instanceof VariableDeclarationFragment;
+ if (isField) {
+ declNode = declNode.getParent();
+ }
+ if (declNode instanceof TypeDeclaration || isField) {
+ AST ast = declNode.getAST();
+ ASTRewrite rewrite = ASTRewrite.create(ast);
+
+ ImportRewriteContext importRewriteContext = new ContextSensitiveImportRewriteContext(declNode, imports);
+
+ // remove annotations in the removeAnnotations list
+ @SuppressWarnings("unchecked")
+ List extends ASTNode> children = (List extends ASTNode>) declNode.getStructuralProperty(TypeDeclaration.MODIFIERS2_PROPERTY);
+ for (ASTNode child : children) {
+ if (child instanceof Annotation) {
+ Annotation annotation = (Annotation) child;
+ IAnnotationBinding annotationBinding = annotation.resolveAnnotationBinding();
+ boolean containsAnnotation = Arrays.stream(removeAnnotations).anyMatch(annotationBinding.getName()::contains);
+ if (containsAnnotation) {
+ rewrite.remove(child, null);
+ }
+ }
+ }
+ for (String annotation : annotations) {
+ Annotation marker = ast.newMarkerAnnotation();
+ marker.setTypeName(ast.newName(imports.addImport(annotation, importRewriteContext))); // $NON-NLS-1$
+ rewrite.getListRewrite(declNode,
+ isField ? FieldDeclaration.MODIFIERS2_PROPERTY : TypeDeclaration.MODIFIERS2_PROPERTY).insertFirst(marker, null);
+ }
+
+ return rewrite;
+ }
+ return null;
+ }
+
+}
\ No newline at end of file
diff --git a/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/core/java/definition/JavaDefinitionContext.java b/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/core/java/definition/JavaDefinitionContext.java
new file mode 100644
index 00000000..6a8c25cf
--- /dev/null
+++ b/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/core/java/definition/JavaDefinitionContext.java
@@ -0,0 +1,59 @@
+/*******************************************************************************
+* Copyright (c) 2020 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 org.eclipse.lsp4jakarta.jdt.core.java.definition;
+
+import org.eclipse.jdt.core.IJavaElement;
+import org.eclipse.jdt.core.ITypeRoot;
+import org.eclipse.lsp4j.Position;
+import org.eclipse.lsp4jakarta.jdt.core.java.AbstractJavaContext;
+import org.eclipse.lsp4jakarta.jdt.core.utils.IJDTUtils;
+
+/**
+ * Java definition context for a given compilation unit.
+ *
+ * @author Angelo ZERR
+ *
+ */
+public class JavaDefinitionContext extends AbstractJavaContext {
+
+ private final IJavaElement hyperlinkedElement;
+
+ private final Position hyperlinkedPosition;
+
+ public JavaDefinitionContext(String uri, ITypeRoot typeRoot, IJDTUtils utils, IJavaElement hyperlinkeElement,
+ Position hyperlinkePosition) {
+ super(uri, typeRoot, utils);
+ this.hyperlinkedElement = hyperlinkeElement;
+ this.hyperlinkedPosition = hyperlinkePosition;
+ }
+
+ /**
+ * Returns the hyperlinked Java element.
+ *
+ * @return the hyperlinked Java element.
+ */
+ public IJavaElement getHyperlinkedElement() {
+ return hyperlinkedElement;
+ }
+
+ /**
+ * Returns the hyperlinked position.
+ *
+ * @return the hyperlinked position.
+ */
+ public Position getHyperlinkedPosition() {
+ return hyperlinkedPosition;
+ }
+
+}
diff --git a/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/core/java/diagnostics/IJavaDiagnosticsParticipant.java b/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/core/java/diagnostics/IJavaDiagnosticsParticipant.java
new file mode 100644
index 00000000..fa3c07cf
--- /dev/null
+++ b/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/core/java/diagnostics/IJavaDiagnosticsParticipant.java
@@ -0,0 +1,84 @@
+/*******************************************************************************
+* Copyright (c) 2020 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 org.eclipse.lsp4jakarta.jdt.core.java.diagnostics;
+
+import java.util.List;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.lsp4j.Diagnostic;
+
+/**
+ * Java diagnostics participants API.
+ *
+ * @author Angelo ZERR
+ *
+ */
+public interface IJavaDiagnosticsParticipant {
+
+ /**
+ * Returns true if diagnostics must be collected for the given context and false
+ * otherwise.
+ *
+ *
+ * Collection is done by default. Participants can override this to check if
+ * some classes are on the classpath before deciding to process the collection.
+ *
+ *
+ * @param the java diagnostics context
+ * @param monitor the progress monitor
+ * @return true if diagnostics must be collected for the given context and false
+ * otherwise.
+ *
+ */
+ default boolean isAdaptedForDiagnostics(JavaDiagnosticsContext context, IProgressMonitor monitor) throws CoreException {
+ return true;
+ }
+
+ /**
+ * Begin diagnostics collection.
+ *
+ * @param context the java diagnostics context
+ * @param monitor the progress monitor
+ *
+ * @throws CoreException
+ */
+ default void beginDiagnostics(JavaDiagnosticsContext context, IProgressMonitor monitor) throws CoreException {
+
+ }
+
+ /**
+ * Collect diagnostics according to the context.
+ *
+ * @param context the java diagnostics context
+ * @param monitor the progress monitor
+ *
+ * @return diagnostics list and null otherwise.
+ *
+ * @throws CoreException
+ */
+ List collectDiagnostics(JavaDiagnosticsContext context, IProgressMonitor monitor) throws CoreException;
+
+ /**
+ * End diagnostics collection.
+ *
+ * @param context the java diagnostics context
+ * @param monitor the progress monitor
+ *
+ * @throws CoreException
+ */
+ default void endDiagnostics(JavaDiagnosticsContext context, IProgressMonitor monitor) throws CoreException {
+
+ }
+}
diff --git a/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/core/java/diagnostics/IJavaErrorCode.java b/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/core/java/diagnostics/IJavaErrorCode.java
new file mode 100644
index 00000000..de5af0ce
--- /dev/null
+++ b/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/core/java/diagnostics/IJavaErrorCode.java
@@ -0,0 +1,25 @@
+/*******************************************************************************
+* Copyright (c) 2020 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 org.eclipse.lsp4jakarta.jdt.core.java.diagnostics;
+
+/**
+ * Diagnostics Java error code API.
+ *
+ * @author Angelo ZERR
+ *
+ */
+public interface IJavaErrorCode {
+
+ String getCode();
+}
diff --git a/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/core/java/diagnostics/JavaDiagnosticsContext.java b/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/core/java/diagnostics/JavaDiagnosticsContext.java
new file mode 100644
index 00000000..4f017f79
--- /dev/null
+++ b/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/core/java/diagnostics/JavaDiagnosticsContext.java
@@ -0,0 +1,92 @@
+/*******************************************************************************
+* Copyright (c) 2020 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 org.eclipse.lsp4jakarta.jdt.core.java.diagnostics;
+
+import java.util.Collections;
+
+import org.eclipse.jdt.core.ITypeRoot;
+import org.eclipse.lsp4j.Diagnostic;
+import org.eclipse.lsp4j.DiagnosticSeverity;
+import org.eclipse.lsp4j.Range;
+import org.eclipse.lsp4jakarta.commons.DocumentFormat;
+import org.eclipse.lsp4jakarta.commons.JakartaJavaDiagnosticsSettings;
+import org.eclipse.lsp4jakarta.jdt.core.java.AbstractJavaContext;
+import org.eclipse.lsp4jakarta.jdt.core.utils.IJDTUtils;
+
+/**
+ * Java diagnostics context for a given compilation unit.
+ *
+ * @author Angelo ZERR
+ *
+ */
+public class JavaDiagnosticsContext extends AbstractJavaContext {
+
+ private final DocumentFormat documentFormat;
+
+ private final JakartaJavaDiagnosticsSettings settings;
+
+ public JavaDiagnosticsContext(String uri, ITypeRoot typeRoot, IJDTUtils utils, DocumentFormat documentFormat,
+ JakartaJavaDiagnosticsSettings settings) {
+ super(uri, typeRoot, utils);
+ this.documentFormat = documentFormat;
+ if (settings == null) {
+ this.settings = new JakartaJavaDiagnosticsSettings(Collections.emptyList());
+ } else {
+ this.settings = settings;
+ }
+ }
+
+ public DocumentFormat getDocumentFormat() {
+ return documentFormat;
+ }
+
+ /**
+ * Returns the JakartaJavaDiagnosticsSettings.
+ *
+ * Should not be null.
+ *
+ * @return the JakartaJavaDiagnosticsSettings
+ */
+ public JakartaJavaDiagnosticsSettings getSettings() {
+ return this.settings;
+ }
+
+ public Diagnostic createDiagnostic(String uri, String message, Range range, String source, IJavaErrorCode code) {
+ return createDiagnostic(uri, message, range, source, code, DiagnosticSeverity.Warning);
+ }
+
+ public Diagnostic createDiagnostic(String uri, String message, Range range, String source, IJavaErrorCode code,
+ DiagnosticSeverity severity) {
+ return createDiagnostic(uri, message, range, source, null, code, severity);
+
+ }
+
+ public Diagnostic createDiagnostic(String uri, String message, Range range, String source, Object data,
+ IJavaErrorCode code,
+ DiagnosticSeverity severity) {
+ Diagnostic diagnostic = new Diagnostic();
+ diagnostic.setSource(source);
+ diagnostic.setMessage(message);
+ diagnostic.setSeverity(severity);
+ diagnostic.setRange(range);
+ if (code != null) {
+ diagnostic.setCode(code.getCode());
+ }
+ if (data != null) {
+ diagnostic.setData(data);
+ }
+ return diagnostic;
+ }
+
+}
diff --git a/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/core/jax_rs/Jax_RSClassDiagnosticsCollector.java b/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/core/jax_rs/Jax_RSClassDiagnosticsCollector.java
deleted file mode 100644
index a1be3f2d..00000000
--- a/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/core/jax_rs/Jax_RSClassDiagnosticsCollector.java
+++ /dev/null
@@ -1,137 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2021, 2023 IBM Corporation, Matthew Shocrylas 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.
- *
- * SPDX-License-Identifier: EPL-2.0
- *
- * Contributors:
- * IBM Corporation, Matthew Shocrylas - initial API and implementation
- *******************************************************************************/
-
-package org.eclipse.lsp4jakarta.jdt.core.jax_rs;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import org.eclipse.jdt.core.Flags;
-import org.eclipse.jdt.core.IAnnotation;
-import org.eclipse.jdt.core.ICompilationUnit;
-import org.eclipse.jdt.core.IMethod;
-import org.eclipse.jdt.core.IType;
-import org.eclipse.jdt.core.JavaModelException;
-import org.eclipse.lsp4j.Diagnostic;
-import org.eclipse.lsp4j.DiagnosticSeverity;
-import org.eclipse.lsp4jakarta.jdt.core.AbstractDiagnosticsCollector;
-import org.eclipse.lsp4jakarta.jdt.core.JakartaCorePlugin;
-import org.eclipse.lsp4jakarta.jdt.core.Messages;
-
-/**
- * Diagnostic collector for root resource classes with multiple constructors
- *
- * @author Matthew Shocrylas
- *
- */
-public class Jax_RSClassDiagnosticsCollector extends AbstractDiagnosticsCollector {
-
- public Jax_RSClassDiagnosticsCollector() {
- super();
- }
-
- @Override
- protected String getDiagnosticSource() {
- return Jax_RSConstants.DIAGNOSTIC_SOURCE;
- }
-
- @Override
- public void collectDiagnostics(ICompilationUnit unit, List diagnostics) {
-
- if (unit != null) {
- IType[] alltypes;
-
- try {
- alltypes = unit.getAllTypes();
- for (IType type : alltypes) {
- boolean isRootResource = false;
- boolean isProviderResource = false;
- IAnnotation[] annotationList = type.getAnnotations();
-
- for (IAnnotation annotation : annotationList) {
- String matchedAnnotation = getMatchedJavaElementName(type, annotation.getElementName(),
- Jax_RSConstants.SET_OF_JAXRS_ANNOTATIONS1);
- if (matchedAnnotation != null) {
- if (Jax_RSConstants.PATH_ANNOTATION.equals(matchedAnnotation)) {
- isRootResource = true;
- } else if (Jax_RSConstants.PROVIDER_ANNOTATION.equals(matchedAnnotation)) {
- isProviderResource = true;
- }
- }
- }
-
- if (isRootResource || isProviderResource) { // annotated class
- List nonPublicConstructors = new ArrayList();
- boolean hasPublicConstructor = false;
- int maxParams = 0;
- Map constructorParamsMap = new HashMap();
- IMethod[] methods = type.getMethods();
- for (IMethod method : methods) {
- if (isConstructorMethod(method)) {
- if (Flags.isPublic(method.getFlags())) {
- hasPublicConstructor = true;
- nonPublicConstructors.clear(); // ignore all non-public constructors
- if (isRootResource) {
- int numParams = method.getNumberOfParameters();
- if (numParams > maxParams) {
- maxParams = numParams;
- }
- constructorParamsMap.put(method, numParams);
- }
- } else if (!hasPublicConstructor) {
- nonPublicConstructors.add(method);
- }
- }
- }
- // no public constructor defined
- if (nonPublicConstructors.size() > 0) {
- String diagnosticMessage = isRootResource ?
- Messages.getMessage("RootResourceClasses") :
- Messages.getMessage("ProviderClasses");
- for (IMethod constructor : nonPublicConstructors) {
- diagnostics.add(createDiagnostic(constructor, unit, diagnosticMessage,
- Jax_RSConstants.DIAGNOSTIC_CODE_NO_PUBLIC_CONSTRUCTORS, null,
- DiagnosticSeverity.Error));
- }
- }
- // check public constructors' parameters
- ArrayList equalMaxParamMethods = new ArrayList();
- for (Map.Entry entry : constructorParamsMap.entrySet()) {
- if (entry.getValue() == maxParams) {
- equalMaxParamMethods.add(entry.getKey());
- } else if (entry.getValue() < maxParams) {
- IMethod method = entry.getKey();
- diagnostics.add(createDiagnostic(method, unit,
- Messages.getMessage("ConstructorIsUnused"),
- Jax_RSConstants.DIAGNOSTIC_CODE_UNUSED_CONSTRUCTOR, null,
- DiagnosticSeverity.Warning));
- }
- }
- if (equalMaxParamMethods.size() > 1) { // more than one
- for (IMethod method : equalMaxParamMethods) {
- diagnostics.add(createDiagnostic(method, unit,
- Messages.getMessage("MultipleConstructorsNumberOfParameters"),
- Jax_RSConstants.DIAGNOSTIC_CODE_AMBIGUOUS_CONSTRUCTORS, null,
- DiagnosticSeverity.Warning));
- }
- }
- }
- }
- } catch (JavaModelException e) {
- JakartaCorePlugin.logException("Cannot calculate JAX-RS diagnostics", e);
- }
- }
- }
-}
diff --git a/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/core/jax_rs/Jax_RSConstants.java b/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/core/jax_rs/Jax_RSConstants.java
deleted file mode 100644
index c5e2136b..00000000
--- a/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/core/jax_rs/Jax_RSConstants.java
+++ /dev/null
@@ -1,52 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2021, 2022 IBM Corporation, Matthew Shocrylas 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.
- *
- * SPDX-License-Identifier: EPL-2.0
- *
- * Contributors:
- * IBM Corporation, Matthew Shocrylas - initial API and implementation, Bera Sogut
- *******************************************************************************/
-
-package org.eclipse.lsp4jakarta.jdt.core.jax_rs;
-
-import java.util.ArrayList;
-import java.util.List;
-
-public class Jax_RSConstants {
-
- public static final String RESOURCE_METHOD = "ResourceMethod";
-
- /* Annotation Constants */
- public static final ArrayList METHOD_DESIGNATORS = new ArrayList(
- List.of("GET", "POST", "PUT", "DELETE", "PATCH", "HEAD", "OPTIONS"));
-
- /* Annotations which make a resource method parameter a non entity parameter. */
- public static final ArrayList NON_ENTITY_PARAM_ANNOTATIONS = new ArrayList(
- List.of("FormParam", "MatrixParam", "QueryParam", "PathParam", "CookieParam", "HeaderParam", "Context"));
-
- public static final String PATH_ANNOTATION = "jakarta.ws.rs.Path";
- public static final String PROVIDER_ANNOTATION = "jakarta.ws.rs.ext.Provider";
-
- /* Source */
- public static final String DIAGNOSTIC_SOURCE = "jakarta-jax_rs";
-
- /* Diagnostics fields constants */
- public static final String DIAGNOSTIC_CODE_NON_PUBLIC = "NonPublicResourceMethod";
- public static final String DIAGNOSTIC_CODE_MULTIPLE_ENTITY_PARAMS = "ResourceMethodMultipleEntityParams";
- public static final String DIAGNOSTIC_CODE_UNUSED_CONSTRUCTOR = "UnusedConstructor";
- public static final String DIAGNOSTIC_CODE_AMBIGUOUS_CONSTRUCTORS = "AmbiguousConstructors";
- public static final String DIAGNOSTIC_CODE_NO_PUBLIC_CONSTRUCTORS = "NoPublicConstructors";
-
- public final static String[] SET_OF_METHOD_DESIGNATORS_ANNOTATIONS = { "jakarta.ws.rs.GET", "jakarta.ws.rs.POST",
- "jakarta.ws.rs.PUT", "jakarta.ws.rs.DELETE", "jakarta.ws.rs.PATCH", "jakarta.ws.rs.HEAD",
- "jakarta.ws.rs.OPTIONS" };
- public final static String[] SET_OF_NON_ENTITY_PARAM_ANNOTATIONS = { "jakarta.ws.rs.FormParam",
- "jakarta.ws.rs.MatrixParam", "jakarta.ws.rs.QueryParam", "jakarta.ws.rs.PathParam",
- "jakarta.ws.rs.CookieParam", "jakarta.ws.rs.HeaderParam", "jakarta.ws.rs.core.Context" };
- public final static String[] SET_OF_JAXRS_ANNOTATIONS1 = { PATH_ANNOTATION, PROVIDER_ANNOTATION };
-
-}
diff --git a/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/core/jax_rs/NoResourcePublicConstructorQuickFix.java b/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/core/jax_rs/NoResourcePublicConstructorQuickFix.java
deleted file mode 100644
index 01c86902..00000000
--- a/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/core/jax_rs/NoResourcePublicConstructorQuickFix.java
+++ /dev/null
@@ -1,87 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2021, 2023 IBM Corporation, Shaunak Tulshibagwale 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.
- *
- * SPDX-License-Identifier: EPL-2.0
- *
- * Contributors:
- * IBM Corporation, Shaunak Tulshibagwale
- *******************************************************************************/
-
-
-package org.eclipse.lsp4jakarta.jdt.core.jax_rs;
-
-
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
-
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.jdt.core.dom.ASTNode;
-import org.eclipse.jdt.core.dom.IBinding;
-import org.eclipse.jdt.core.dom.IMethodBinding;
-import org.eclipse.jdt.internal.corext.dom.Bindings;
-import org.eclipse.jdt.core.dom.MethodDeclaration;
-import org.eclipse.jdt.core.dom.VariableDeclarationFragment;
-import org.eclipse.lsp4j.CodeAction;
-import org.eclipse.lsp4j.Diagnostic;
-import org.eclipse.lsp4jakarta.jdt.codeAction.IJavaCodeActionParticipant;
-import org.eclipse.lsp4jakarta.jdt.codeAction.JavaCodeActionContext;
-import org.eclipse.lsp4jakarta.jdt.codeAction.proposal.AddConstructorProposal;
-import org.eclipse.lsp4jakarta.jdt.codeAction.proposal.ChangeCorrectionProposal;
-import org.eclipse.lsp4jakarta.jdt.codeAction.proposal.ModifyModifiersProposal;
-import org.eclipse.lsp4jakarta.jdt.core.Messages;
-
-/**
- * Quick fix for NoResourcePublicConstructorQuickFix that uses
- * ModifyModifiersProposal.
- *
- * @author Shaunak Tulshibagwale
- *
- */
-public class NoResourcePublicConstructorQuickFix implements IJavaCodeActionParticipant {
-
- @Override
- public List extends CodeAction> getCodeActions(JavaCodeActionContext context, Diagnostic diagnostic,
- IProgressMonitor monitor) throws CoreException {
- List codeActions = new ArrayList<>();
- ASTNode node = context.getCoveredNode();
- MethodDeclaration parentNode = (MethodDeclaration) node.getParent();
- IMethodBinding parentMethod = parentNode.resolveBinding();
- IBinding parentType = getBinding(node);
-
- if (parentMethod != null) {
-
- final String TITLE_MESSAGE = Messages.getMessage("MakeConstructorPublic");
-
- ChangeCorrectionProposal proposal = new ModifyModifiersProposal(TITLE_MESSAGE, context.getCompilationUnit(),
- context.getASTRoot(), parentMethod, 0, null, Arrays.asList("public"));
-
- // Convert the proposal to LSP4J CodeAction
- CodeAction codeAction = context.convertToCodeAction(proposal, diagnostic);
- codeAction.setTitle(TITLE_MESSAGE);
- codeActions.add(codeAction);
-
- // option for public constructor
- String name = Messages.getMessage("NoargPublicConstructor");
- proposal = new AddConstructorProposal(name,
- context.getCompilationUnit(), context.getASTRoot(), parentType, 0, "public");
- codeAction = context.convertToCodeAction(proposal, diagnostic);
- codeActions.add(codeAction);
-
- }
- return codeActions;
- }
-
- protected static IBinding getBinding(ASTNode node) {
- if (node.getParent() instanceof VariableDeclarationFragment) {
- VariableDeclarationFragment fragment = (VariableDeclarationFragment) node.getParent();
- return ((VariableDeclarationFragment) node.getParent()).resolveBinding();
- }
- return Bindings.getBindingOfParentType(node);
- }
-}
diff --git a/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/core/jax_rs/NonPublicResourceMethodQuickFix.java b/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/core/jax_rs/NonPublicResourceMethodQuickFix.java
deleted file mode 100644
index 4a5d4d84..00000000
--- a/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/core/jax_rs/NonPublicResourceMethodQuickFix.java
+++ /dev/null
@@ -1,65 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2021, 2023 IBM Corporation, Matthew Shocrylas 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.
- *
- * SPDX-License-Identifier: EPL-2.0
- *
- * Contributors:
- * IBM Corporation, Matthew Shocrylas - initial API and implementation
- *******************************************************************************/
-
-package org.eclipse.lsp4jakarta.jdt.core.jax_rs;
-
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
-
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.jdt.core.dom.ASTNode;
-import org.eclipse.jdt.core.dom.IMethodBinding;
-import org.eclipse.jdt.core.dom.MethodDeclaration;
-import org.eclipse.lsp4j.CodeAction;
-import org.eclipse.lsp4j.Diagnostic;
-import org.eclipse.lsp4jakarta.jdt.codeAction.IJavaCodeActionParticipant;
-import org.eclipse.lsp4jakarta.jdt.codeAction.JavaCodeActionContext;
-import org.eclipse.lsp4jakarta.jdt.codeAction.proposal.ChangeCorrectionProposal;
-import org.eclipse.lsp4jakarta.jdt.codeAction.proposal.ModifyModifiersProposal;
-import org.eclipse.lsp4jakarta.jdt.core.Messages;
-
-/**
- * Quick fix for ResourceMethodDiagnosticsCollector that uses
- * ModifyModifiersProposal.
- *
- * @author Matthew Shocrylas
- *
- */
-public class NonPublicResourceMethodQuickFix implements IJavaCodeActionParticipant {
-
- @Override
- public List extends CodeAction> getCodeActions(JavaCodeActionContext context, Diagnostic diagnostic,
- IProgressMonitor monitor) throws CoreException {
- List codeActions = new ArrayList<>();
- ASTNode node = context.getCoveredNode();
- MethodDeclaration parentNode = (MethodDeclaration) node.getParent();
- IMethodBinding parentMethod = parentNode.resolveBinding();
-
- if (parentMethod != null) {
-
- final String TITLE_MESSAGE = Messages.getMessage("MakeMethodPublic");
-
- ChangeCorrectionProposal proposal = new ModifyModifiersProposal(TITLE_MESSAGE, context.getCompilationUnit(),
- context.getASTRoot(), parentMethod, 0, null, Arrays.asList("public"));
-
- // Convert the proposal to LSP4J CodeAction
- CodeAction codeAction = context.convertToCodeAction(proposal, diagnostic);
- codeAction.setTitle(TITLE_MESSAGE);
- codeActions.add(codeAction);
- }
- return codeActions;
- }
-
-}
diff --git a/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/core/jax_rs/ResourceMethodDiagnosticsCollector.java b/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/core/jax_rs/ResourceMethodDiagnosticsCollector.java
deleted file mode 100644
index 703f021f..00000000
--- a/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/core/jax_rs/ResourceMethodDiagnosticsCollector.java
+++ /dev/null
@@ -1,114 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2021, 2023 IBM Corporation, Matthew Shocrylas 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.
- *
- * SPDX-License-Identifier: EPL-2.0
- *
- * Contributors:
- * IBM Corporation, Matthew Shocrylas - initial API and implementation, Bera Sogut
- *******************************************************************************/
-
-package org.eclipse.lsp4jakarta.jdt.core.jax_rs;
-
-import java.util.List;
-
-import org.apache.commons.lang3.ArrayUtils;
-import org.eclipse.jdt.core.Flags;
-import org.eclipse.jdt.core.IAnnotation;
-import org.eclipse.jdt.core.ICompilationUnit;
-import org.eclipse.jdt.core.ILocalVariable;
-import org.eclipse.jdt.core.IMethod;
-import org.eclipse.jdt.core.IType;
-import org.eclipse.jdt.core.JavaModelException;
-import org.eclipse.lsp4j.Diagnostic;
-import org.eclipse.lsp4j.DiagnosticSeverity;
-import org.eclipse.lsp4jakarta.jdt.core.AbstractDiagnosticsCollector;
-import org.eclipse.lsp4jakarta.jdt.core.JakartaCorePlugin;
-import org.eclipse.lsp4jakarta.jdt.core.Messages;
-
-public class ResourceMethodDiagnosticsCollector extends AbstractDiagnosticsCollector {
-
- public ResourceMethodDiagnosticsCollector() {
- super();
- }
-
- @Override
- protected String getDiagnosticSource() {
- return Jax_RSConstants.DIAGNOSTIC_SOURCE;
- }
-
- @Override
- public void collectDiagnostics(ICompilationUnit unit, List