Skip to content

Commit

Permalink
QuickFix for annotation missing attributes
Browse files Browse the repository at this point in the history
Requires eclipse-jdt/eclipse.jdt.ui#335

Closes eclipse-jdtls#1806

Signed-off-by: David Thompson <davthomp@redhat.com>
  • Loading branch information
datho7561 committed Dec 7, 2022
1 parent bdeb481 commit 35a0be9
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -300,10 +300,9 @@ private void process(IInvocationContext context, IProblemLocationCore problem, C
// LocalCorrectionsSubProcessor.addMissingHashCodeProposals(context,
// problem, proposals);
// break;
// case IProblem.MissingValueForAnnotationMember:
// LocalCorrectionsSubProcessor.addValueForAnnotationProposals(context,
// problem, proposals);
// break;
case IProblem.MissingValueForAnnotationMember:
LocalCorrectionsSubProcessor.addValueForAnnotationProposals(context, problem, proposals);
break;
// case IProblem.BodyForNativeMethod:
// ModifierCorrectionSubProcessor.addNativeMethodProposals(context,
// problem, proposals);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ public interface IProposalRelevance {
public static final int REMOVE_REDUNDANT_NULLNESS_ANNOTATION= 5;
public static final int REPLACE_WITH_UNQUALIFIED_ENUM_CONSTANT= 5;
public static final int OVERRIDE_DEFAULT_METHOD= 5;
public static final int ADD_MISSING_ANNOTATION_ATTRIBUTES = 5;

public static final int ADD_MISSING_TAG= 4;
public static final int INSERT_FALL_THROUGH= 4;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@
import org.eclipse.jdt.internal.corext.fix.CleanUpConstants;
import org.eclipse.jdt.internal.corext.fix.CodeStyleFixCore;
import org.eclipse.jdt.internal.corext.fix.IProposableFix;
import org.eclipse.jdt.internal.corext.fix.MissingAnnotationAttributesFixCore;
import org.eclipse.jdt.internal.corext.fix.SealedClassFixCore;
import org.eclipse.jdt.internal.corext.fix.UnimplementedCodeFixCore;
import org.eclipse.jdt.internal.corext.fix.UnusedCodeFixCore;
Expand Down Expand Up @@ -1104,4 +1105,19 @@ public static void addSealedAsDirectSuperTypeProposal(IInvocationContext context
}
}

public static void addValueForAnnotationProposals(IInvocationContext context, IProblemLocationCore problem, Collection<ChangeCorrectionProposal> proposals) {
MissingAnnotationAttributesFixCore fix = MissingAnnotationAttributesFixCore.addMissingAnnotationAttributesProposal(context.getASTRoot(), problem);
if (fix != null) {
String label = fix.getDisplayString();
CompilationUnitChange change;
try {
change = fix.createChange(null);
CUCorrectionProposal proposal = new CUCorrectionProposal(label, CodeActionKind.QuickFix, context.getCompilationUnit(), change, IProposalRelevance.ADD_MISSING_ANNOTATION_ATTRIBUTES);
proposals.add(proposal);
} catch (CoreException e) {
// do nothing
}
}
}

}
2 changes: 1 addition & 1 deletion org.eclipse.jdt.ls.target/org.eclipse.jdt.ls.tp.target
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
<unit id="org.eclipse.jdt.source.feature.group" version="0.0.0"/>
<unit id="org.eclipse.sdk.feature.group" version="0.0.0"/>
<unit id="org.mockito.mockito-core" version="0.0.0"/>
<repository location="https://download.eclipse.org/eclipse/updates/4.26-I-builds/I20221027-1800"/>
<repository location="https://download.eclipse.org/eclipse/updates/4.27-I-builds/I20221206-1800"/>
</location>
<location includeAllPlatforms="false" includeConfigurePhase="false" includeMode="planner" includeSource="true" type="InstallableUnit">
<unit id="org.eclipse.xtend.sdk.feature.group" version="0.0.0"/>
Expand Down

0 comments on commit 35a0be9

Please sign in to comment.