Search in sources :

Example 1 with VariableDeclarationCleanUp

use of org.eclipse.jdt.internal.ui.fix.VariableDeclarationCleanUp in project che by eclipse.

the class QuickAssistProcessor method getMakeVariableDeclarationFinalProposals.

private static boolean getMakeVariableDeclarationFinalProposals(IInvocationContext context, Collection<ICommandAccess> resultingCollections) {
    SelectionAnalyzer analyzer = new SelectionAnalyzer(Selection.createFromStartLength(context.getSelectionOffset(), context.getSelectionLength()), false);
    context.getASTRoot().accept(analyzer);
    ASTNode[] selectedNodes = analyzer.getSelectedNodes();
    if (selectedNodes.length == 0)
        return false;
    IProposableFix fix = VariableDeclarationFix.createChangeModifierToFinalFix(context.getASTRoot(), selectedNodes);
    if (fix == null)
        return false;
    if (resultingCollections == null)
        return true;
    Image image = JavaPluginImages.get(JavaPluginImages.IMG_CORRECTION_CHANGE);
    Map<String, String> options = new Hashtable<String, String>();
    options.put(CleanUpConstants.VARIABLE_DECLARATIONS_USE_FINAL, CleanUpOptions.TRUE);
    options.put(CleanUpConstants.VARIABLE_DECLARATIONS_USE_FINAL_LOCAL_VARIABLES, CleanUpOptions.TRUE);
    options.put(CleanUpConstants.VARIABLE_DECLARATIONS_USE_FINAL_PARAMETERS, CleanUpOptions.TRUE);
    options.put(CleanUpConstants.VARIABLE_DECLARATIONS_USE_FINAL_PRIVATE_FIELDS, CleanUpOptions.TRUE);
    VariableDeclarationCleanUp cleanUp = new VariableDeclarationCleanUp(options);
    FixCorrectionProposal proposal = new FixCorrectionProposal(fix, cleanUp, IProposalRelevance.MAKE_VARIABLE_DECLARATION_FINAL, image, context);
    resultingCollections.add(proposal);
    return true;
}
Also used : SelectionAnalyzer(org.eclipse.jdt.internal.corext.dom.SelectionAnalyzer) FixCorrectionProposal(org.eclipse.jdt.internal.ui.text.correction.proposals.FixCorrectionProposal) Hashtable(java.util.Hashtable) IProposableFix(org.eclipse.jdt.internal.corext.fix.IProposableFix) Image(org.eclipse.swt.graphics.Image) VariableDeclarationCleanUp(org.eclipse.jdt.internal.ui.fix.VariableDeclarationCleanUp)

Aggregations

Hashtable (java.util.Hashtable)1 SelectionAnalyzer (org.eclipse.jdt.internal.corext.dom.SelectionAnalyzer)1 IProposableFix (org.eclipse.jdt.internal.corext.fix.IProposableFix)1 VariableDeclarationCleanUp (org.eclipse.jdt.internal.ui.fix.VariableDeclarationCleanUp)1 FixCorrectionProposal (org.eclipse.jdt.internal.ui.text.correction.proposals.FixCorrectionProposal)1 Image (org.eclipse.swt.graphics.Image)1