-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #513 from ajm01/issue-190
add quickfix fn to handle composite annotations
- Loading branch information
Showing
12 changed files
with
469 additions
and
90 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
302 changes: 225 additions & 77 deletions
302
.../org/eclipse/lsp4jakarta/jdt/core/java/corrections/proposal/ModifyAnnotationProposal.java
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
...akarta/jdt/internal/annotations/InsertDefaultResourceAnnotationToResourcesAnnotation.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2024 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.internal.annotations; | ||
|
||
import org.eclipse.lsp4jakarta.commons.codeaction.ICodeActionId; | ||
import org.eclipse.lsp4jakarta.commons.codeaction.JakartaCodeActionId; | ||
import org.eclipse.lsp4jakarta.jdt.core.java.codeaction.InsertAnnotationAttributesQuickFix; | ||
|
||
/** | ||
* Inserts the name attribute to the @Resource annotation to the active element. | ||
*/ | ||
public class InsertDefaultResourceAnnotationToResourcesAnnotation extends InsertAnnotationAttributesQuickFix { | ||
|
||
/** | ||
* Constructor. | ||
*/ | ||
public InsertDefaultResourceAnnotationToResourcesAnnotation() { | ||
super("jakarta.annotation.Resource", "name", "type"); | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
@Override | ||
public String getParticipantId() { | ||
return InsertDefaultResourceAnnotationToResourcesAnnotation.class.getName(); | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
@Override | ||
protected ICodeActionId getCodeActionId() { | ||
return JakartaCodeActionId.InsertDefaultResourceAnnotationToResourcesAnnotation; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 4 additions & 4 deletions
8
...ta-sample/src/main/java/io/openliberty/sample/jakarta/annotations/ResourceAnnotation.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
...a-sample/src/main/java/io/openliberty/sample/jakarta/annotations/ResourcesAnnotation.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2024 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 io.openliberty.sample.jakarta.annotations; | ||
|
||
import jakarta.annotation.Resource; | ||
import jakarta.annotation.Resources; | ||
|
||
@Resources ({ @Resource(name = "aaa"), @Resource(type = Object.class) }) | ||
public class ResourcesAnnotation { | ||
} | ||
|
||
@Resources ({}) | ||
class ResourcesAnnotationEmpty { | ||
} | ||
|
||
@Resource(name = "aa", type = Object.class) | ||
class DoctoralStudent { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 78 additions & 0 deletions
78
...t.test/src/main/java/org/eclipse/lsp4jakarta/jdt/annotations/ResourcesAnnotationTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2024 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.annotations; | ||
|
||
import static org.eclipse.lsp4jakarta.jdt.core.JakartaForJavaAssert.assertJavaCodeAction; | ||
import static org.eclipse.lsp4jakarta.jdt.core.JakartaForJavaAssert.assertJavaDiagnostics; | ||
import static org.eclipse.lsp4jakarta.jdt.core.JakartaForJavaAssert.ca; | ||
import static org.eclipse.lsp4jakarta.jdt.core.JakartaForJavaAssert.createCodeActionParams; | ||
import static org.eclipse.lsp4jakarta.jdt.core.JakartaForJavaAssert.d; | ||
import static org.eclipse.lsp4jakarta.jdt.core.JakartaForJavaAssert.te; | ||
|
||
import java.util.Arrays; | ||
|
||
import org.eclipse.core.resources.IFile; | ||
import org.eclipse.core.runtime.Path; | ||
import org.eclipse.jdt.core.IJavaProject; | ||
import org.eclipse.lsp4j.CodeAction; | ||
import org.eclipse.lsp4j.Diagnostic; | ||
import org.eclipse.lsp4j.DiagnosticSeverity; | ||
import org.eclipse.lsp4j.TextEdit; | ||
import org.eclipse.lsp4jakarta.commons.JakartaJavaCodeActionParams; | ||
import org.eclipse.lsp4jakarta.commons.JakartaJavaDiagnosticsParams; | ||
import org.eclipse.lsp4jakarta.jdt.core.BaseJakartaTest; | ||
import org.eclipse.lsp4jakarta.jdt.core.utils.IJDTUtils; | ||
import org.eclipse.lsp4jakarta.jdt.internal.core.ls.JDTUtilsLSImpl; | ||
import org.junit.Test; | ||
|
||
public class ResourcesAnnotationTest extends BaseJakartaTest { | ||
|
||
protected static IJDTUtils IJDT_UTILS = JDTUtilsLSImpl.getInstance(); | ||
|
||
@Test | ||
public void GeneratedAnnotation() throws Exception { | ||
IJavaProject javaProject = loadJavaProject("jakarta-sample", ""); | ||
IFile javaFile = javaProject.getProject().getFile(new Path("src/main/java/io/openliberty/sample/jakarta/annotations/ResourcesAnnotation.java")); | ||
String uri = javaFile.getLocation().toFile().toURI().toString(); | ||
|
||
JakartaJavaDiagnosticsParams diagnosticsParams = new JakartaJavaDiagnosticsParams(); | ||
diagnosticsParams.setUris(Arrays.asList(uri)); | ||
|
||
// expected annotations | ||
Diagnostic d1 = d(17, 14, 37, "The @Resource annotation must define the attribute 'type'.", | ||
DiagnosticSeverity.Error, "jakarta-annotations", "MissingResourceTypeAttribute"); | ||
|
||
Diagnostic d2 = d(17, 39, 69, "The @Resource annotation must define the attribute 'name'.", | ||
DiagnosticSeverity.Error, "jakarta-annotations", "MissingResourceNameAttribute"); | ||
|
||
Diagnostic d3 = d(21, 0, 15, "The @Resources annotation must define at least one sub-annotation '@Resource'.", | ||
DiagnosticSeverity.Error, "jakarta-annotations", "MissingResourceAnnotation"); | ||
|
||
assertJavaDiagnostics(diagnosticsParams, IJDT_UTILS, d1, d2, d3); | ||
|
||
JakartaJavaCodeActionParams codeActionParams = createCodeActionParams(uri, d1); | ||
TextEdit te1 = te(17, 0, 18, 0, "@Resources({ @Resource(name = \"aaa\", type = \"\"), @Resource(type = Object.class) })\n"); | ||
CodeAction ca1 = ca(uri, "Insert 'type' attribute to @Resource", d1, te1); | ||
assertJavaCodeAction(codeActionParams, IJDT_UTILS, ca1); | ||
|
||
JakartaJavaCodeActionParams codeActionParams1 = createCodeActionParams(uri, d2); | ||
TextEdit te2 = te(17, 0, 18, 0, "@Resources({ @Resource(name = \"aaa\"), @Resource(type = Object.class, name = \"\") })\n"); | ||
CodeAction ca2 = ca(uri, "Insert 'name' attribute to @Resource", d2, te2); | ||
assertJavaCodeAction(codeActionParams1, IJDT_UTILS, ca2); | ||
|
||
JakartaJavaCodeActionParams codeActionParams2 = createCodeActionParams(uri, d3); | ||
TextEdit te3 = te(21, 0, 21, 15, "@Resources({ @Resource(name = \"\", type = \"\") })"); | ||
CodeAction ca3 = ca(uri, "Insert 'name,type' attributes to @Resource", d3, te3); | ||
assertJavaCodeAction(codeActionParams2, IJDT_UTILS, ca3); | ||
} | ||
} |