Search in sources :

Example 1 with IProposableFix

use of org.eclipse.jdt.ls.core.internal.corext.fix.IProposableFix in project eclipse.jdt.ls by eclipse.

the class ReorgCorrectionsSubProcessor method removeImportStatementProposals.

public static void removeImportStatementProposals(IInvocationContext context, IProblemLocation problem, Collection<CUCorrectionProposal> proposals) {
    IProposableFix fix = UnusedCodeFix.createRemoveUnusedImportFix(context.getASTRoot(), problem);
    if (fix != null) {
        try {
            CompilationUnitChange change = fix.createChange(null);
            CUCorrectionProposal proposal = new CUCorrectionProposal(change.getName(), change.getCompilationUnit(), change, IProposalRelevance.REMOVE_UNUSED_IMPORT);
            proposals.add(proposal);
        } catch (CoreException e) {
            JavaLanguageServerPlugin.log(e);
        }
    }
    final ICompilationUnit cu = context.getCompilationUnit();
    String name = CorrectionMessages.ReorgCorrectionsSubProcessor_organizeimports_description;
    CUCorrectionProposal proposal = new CUCorrectionProposal(name, cu, IProposalRelevance.ORGANIZE_IMPORTS) {

        @Override
        protected void addEdits(IDocument document, TextEdit editRoot) throws CoreException {
            CompilationUnit astRoot = context.getASTRoot();
            OrganizeImportsOperation op = new OrganizeImportsOperation(cu, astRoot, true, false, true, null);
            editRoot.addChild(op.createTextEdit(null));
        }
    };
    proposals.add(proposal);
}
Also used : ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) CompilationUnit(org.eclipse.jdt.core.dom.CompilationUnit) ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) OrganizeImportsOperation(org.eclipse.jdt.core.manipulation.OrganizeImportsOperation) CoreException(org.eclipse.core.runtime.CoreException) TextEdit(org.eclipse.text.edits.TextEdit) IProposableFix(org.eclipse.jdt.ls.core.internal.corext.fix.IProposableFix) IDocument(org.eclipse.jface.text.IDocument) CompilationUnitChange(org.eclipse.jdt.core.refactoring.CompilationUnitChange)

Example 2 with IProposableFix

use of org.eclipse.jdt.ls.core.internal.corext.fix.IProposableFix in project eclipse.jdt.ls by eclipse.

the class LocalCorrectionsSubProcessor method addUnimplementedMethodsProposals.

public static void addUnimplementedMethodsProposals(IInvocationContext context, IProblemLocation problem, Collection<CUCorrectionProposal> proposals) {
    IProposableFix fix = UnimplementedCodeFix.createAddUnimplementedMethodsFix(context.getASTRoot(), problem);
    if (fix != null) {
        try {
            CompilationUnitChange change = fix.createChange(null);
            CUCorrectionProposal proposal = new CUCorrectionProposal(change.getName(), change.getCompilationUnit(), change, IProposalRelevance.ADD_UNIMPLEMENTED_METHODS);
            proposals.add(proposal);
        } catch (CoreException e) {
            JavaLanguageServerPlugin.log(e);
        }
    }
}
Also used : CoreException(org.eclipse.core.runtime.CoreException) IProposableFix(org.eclipse.jdt.ls.core.internal.corext.fix.IProposableFix) CompilationUnitChange(org.eclipse.jdt.core.refactoring.CompilationUnitChange)

Example 3 with IProposableFix

use of org.eclipse.jdt.ls.core.internal.corext.fix.IProposableFix in project eclipse.jdt.ls by eclipse.

the class SerialVersionSubProcessor method getSerialVersionProposals.

/**
 * Determines the serial version quickfix proposals.
 *
 * @param context
 *            the invocation context
 * @param location
 *            the problem location
 * @param proposals
 *            the proposal collection to extend
 */
public static final void getSerialVersionProposals(final IInvocationContext context, final IProblemLocation location, final Collection<CUCorrectionProposal> proposals) {
    Assert.isNotNull(context);
    Assert.isNotNull(location);
    Assert.isNotNull(proposals);
    IProposableFix[] fixes = PotentialProgrammingProblemsFix.createMissingSerialVersionFixes(context.getASTRoot(), location);
    if (fixes != null) {
        proposals.add(new SerialVersionProposal(fixes[0], IProposalRelevance.MISSING_SERIAL_VERSION_DEFAULT, context, true));
        ICompilationUnit unit = context.getCompilationUnit();
        if (unit != null && unit.getJavaProject() != null && !ProjectsManager.DEFAULT_PROJECT_NAME.equals(unit.getJavaProject().getProject().getName())) {
            proposals.add(new SerialVersionProposal(fixes[1], IProposalRelevance.MISSING_SERIAL_VERSION, context, false));
        }
    }
}
Also used : ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) IProposableFix(org.eclipse.jdt.ls.core.internal.corext.fix.IProposableFix)

Aggregations

IProposableFix (org.eclipse.jdt.ls.core.internal.corext.fix.IProposableFix)3 CoreException (org.eclipse.core.runtime.CoreException)2 ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)2 CompilationUnitChange (org.eclipse.jdt.core.refactoring.CompilationUnitChange)2 CompilationUnit (org.eclipse.jdt.core.dom.CompilationUnit)1 OrganizeImportsOperation (org.eclipse.jdt.core.manipulation.OrganizeImportsOperation)1 IDocument (org.eclipse.jface.text.IDocument)1 TextEdit (org.eclipse.text.edits.TextEdit)1