Skip to content

Commit

Permalink
Merge pull request #1091 from dessina-devasia/1025-dependent-quickfix…
Browse files Browse the repository at this point in the history
…-inconsistency

Resolved inconsistent behaviour of @dependency quickfix
  • Loading branch information
dessina-devasia authored Nov 13, 2024
2 parents 0c6faa2 + 768307d commit 14e0597
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public void collectDiagnostics(PsiJavaFile unit, List<Diagnostic> diagnostics) {
if (isManagedBean
&& field.hasModifierProperty(PsiModifier.PUBLIC)
&& !field.hasModifierProperty(PsiModifier.STATIC)
&& (fieldScopes.size() != 1 || !fieldScopes.get(0).equals(DEPENDENT_FQ_NAME))) {
&& !managedBeanAnnotations.contains(DEPENDENT_FQ_NAME)) {
diagnostics.add(createDiagnostic(field, unit,
Messages.getMessage("ManagedBeanWithNonStaticPublicField"),
DIAGNOSTIC_CODE, null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@

import com.intellij.openapi.progress.ProcessCanceledException;
import com.intellij.openapi.project.IndexNotReadyException;
import com.intellij.psi.PsiClass;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiModifierListOwner;
import com.intellij.psi.util.PsiTreeUtil;
import io.openliberty.tools.intellij.lsp4jakarta.lsp4ij.JDTUtils;
import io.openliberty.tools.intellij.lsp4jakarta.lsp4ij.Messages;
import io.openliberty.tools.intellij.lsp4jakarta.lsp4ij.codeAction.proposal.quickfix.InsertAnnotationMissingQuickFix;
Expand Down Expand Up @@ -69,7 +71,7 @@ public CodeAction resolveCodeAction(JavaCodeActionResolveContext context) {
final CodeAction toResolve = context.getUnresolved();
String name = toResolve.getTitle();
PsiElement node = context.getCoveringNode();
PsiModifierListOwner parentType = getBinding(node);
PsiModifierListOwner parentType = PsiTreeUtil.getParentOfType(node, PsiClass.class);
ChangeCorrectionProposal proposal = new ReplaceAnnotationProposal(name, context.getCompilationUnit(),
context.getASTRoot(), parentType, 0, ADD_ANNOTATION, context.getSource().getCompilationUnit(),
REMOVE_ANNOTATION_NAMES);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ public void managedBeanAnnotations() throws Exception {
assertJavaDiagnostics(diagnosticsParams, utils, d1, d2);
String newText1 = "package io.openliberty.sample.jakarta.cdi;\n\n" +
"import jakarta.enterprise.context.*;\n\n" +
"@RequestScoped\npublic class ManagedBean<T> {\n " +
"@Dependent\n public int a;\n\n\n " +
"@Dependent\npublic class ManagedBean<T> {\n " +
"public int a;\n\n\n " +
"public ManagedBean() {\n this.a = 10;\n }\n}\n";
String newText2 = "package io.openliberty.sample.jakarta.cdi;\n\n" +
"import jakarta.enterprise.context.*;\n\n" +
Expand Down

0 comments on commit 14e0597

Please sign in to comment.