Search in sources :

Example 1 with NoCommentSourceRangeComputer

use of org.eclipse.jdt.internal.corext.refactoring.util.NoCommentSourceRangeComputer in project che by eclipse.

the class LocalCorrectionsSubProcessor method addCasesOmittedProposals.

public static void addCasesOmittedProposals(IInvocationContext context, IProblemLocation problem, Collection<ICommandAccess> proposals) {
    ASTNode selectedNode = problem.getCoveringNode(context.getASTRoot());
    if (selectedNode instanceof Expression && selectedNode.getLocationInParent() == SwitchStatement.EXPRESSION_PROPERTY) {
        AST ast = selectedNode.getAST();
        SwitchStatement parent = (SwitchStatement) selectedNode.getParent();
        for (Statement statement : (List<Statement>) parent.statements()) {
            if (statement instanceof SwitchCase && ((SwitchCase) statement).isDefault()) {
                // insert //$CASES-OMITTED$:
                ASTRewrite rewrite = ASTRewrite.create(ast);
                rewrite.setTargetSourceRangeComputer(new NoCommentSourceRangeComputer());
                ListRewrite listRewrite = rewrite.getListRewrite(parent, SwitchStatement.STATEMENTS_PROPERTY);
                ASTNode casesOmittedComment = //$NON-NLS-1$
                rewrite.createStringPlaceholder("//$CASES-OMITTED$", ASTNode.EMPTY_STATEMENT);
                listRewrite.insertBefore(casesOmittedComment, statement, null);
                String label = CorrectionMessages.LocalCorrectionsSubProcessor_insert_cases_omitted;
                Image image = JavaPluginImages.get(JavaPluginImages.IMG_CORRECTION_CHANGE);
                ASTRewriteCorrectionProposal proposal = new ASTRewriteCorrectionProposal(label, context.getCompilationUnit(), rewrite, IProposalRelevance.INSERT_CASES_OMITTED, image);
                proposals.add(proposal);
                break;
            }
        }
    }
}
Also used : ListRewrite(org.eclipse.jdt.core.dom.rewrite.ListRewrite) Image(org.eclipse.swt.graphics.Image) NoCommentSourceRangeComputer(org.eclipse.jdt.internal.corext.refactoring.util.NoCommentSourceRangeComputer) ASTRewriteCorrectionProposal(org.eclipse.jdt.ui.text.java.correction.ASTRewriteCorrectionProposal) ASTRewrite(org.eclipse.jdt.core.dom.rewrite.ASTRewrite) List(java.util.List) ArrayList(java.util.ArrayList)

Example 2 with NoCommentSourceRangeComputer

use of org.eclipse.jdt.internal.corext.refactoring.util.NoCommentSourceRangeComputer in project che by eclipse.

the class LocalCorrectionsSubProcessor method addFallThroughProposals.

public static void addFallThroughProposals(IInvocationContext context, IProblemLocation problem, Collection<ICommandAccess> proposals) {
    ASTNode selectedNode = problem.getCoveringNode(context.getASTRoot());
    if (selectedNode instanceof SwitchCase && selectedNode.getLocationInParent() == SwitchStatement.STATEMENTS_PROPERTY) {
        AST ast = selectedNode.getAST();
        ASTNode parent = selectedNode.getParent();
        // insert break:
        ASTRewrite rewrite = ASTRewrite.create(ast);
        ListRewrite listRewrite = rewrite.getListRewrite(parent, SwitchStatement.STATEMENTS_PROPERTY);
        listRewrite.insertBefore(ast.newBreakStatement(), selectedNode, null);
        String label = CorrectionMessages.LocalCorrectionsSubProcessor_insert_break_statement;
        Image image = JavaPluginImages.get(JavaPluginImages.IMG_CORRECTION_CHANGE);
        ASTRewriteCorrectionProposal proposal = new ASTRewriteCorrectionProposal(label, context.getCompilationUnit(), rewrite, IProposalRelevance.INSERT_BREAK_STATEMENT, image);
        proposals.add(proposal);
        // insert //$FALL-THROUGH$:
        rewrite = ASTRewrite.create(ast);
        rewrite.setTargetSourceRangeComputer(new NoCommentSourceRangeComputer());
        listRewrite = rewrite.getListRewrite(parent, SwitchStatement.STATEMENTS_PROPERTY);
        //$NON-NLS-1$
        ASTNode fallThroughComment = rewrite.createStringPlaceholder("//$FALL-THROUGH$", ASTNode.EMPTY_STATEMENT);
        listRewrite.insertBefore(fallThroughComment, selectedNode, null);
        label = CorrectionMessages.LocalCorrectionsSubProcessor_insert_fall_through;
        image = JavaPluginImages.get(JavaPluginImages.IMG_CORRECTION_CHANGE);
        proposal = new ASTRewriteCorrectionProposal(label, context.getCompilationUnit(), rewrite, IProposalRelevance.INSERT_FALL_THROUGH, image);
        proposals.add(proposal);
    }
}
Also used : ASTRewriteCorrectionProposal(org.eclipse.jdt.ui.text.java.correction.ASTRewriteCorrectionProposal) NoCommentSourceRangeComputer(org.eclipse.jdt.internal.corext.refactoring.util.NoCommentSourceRangeComputer) ASTRewrite(org.eclipse.jdt.core.dom.rewrite.ASTRewrite) ListRewrite(org.eclipse.jdt.core.dom.rewrite.ListRewrite) Image(org.eclipse.swt.graphics.Image)

Example 3 with NoCommentSourceRangeComputer

use of org.eclipse.jdt.internal.corext.refactoring.util.NoCommentSourceRangeComputer in project che by eclipse.

the class ExtractTempRefactoring method checkFinalConditions.

@Override
public RefactoringStatus checkFinalConditions(IProgressMonitor pm) throws CoreException {
    try {
        pm.beginTask(RefactoringCoreMessages.ExtractTempRefactoring_checking_preconditions, 4);
        fCURewrite = new CompilationUnitRewrite(fCu, fCompilationUnitNode);
        fCURewrite.getASTRewrite().setTargetSourceRangeComputer(new NoCommentSourceRangeComputer());
        doCreateChange(new SubProgressMonitor(pm, 2));
        fChange = fCURewrite.createChange(RefactoringCoreMessages.ExtractTempRefactoring_change_name, true, new SubProgressMonitor(pm, 1));
        RefactoringStatus result = new RefactoringStatus();
        if (Arrays.asList(getExcludedVariableNames()).contains(fTempName))
            result.addWarning(Messages.format(RefactoringCoreMessages.ExtractTempRefactoring_another_variable, BasicElementLabels.getJavaElementName(fTempName)));
        result.merge(checkMatchingFragments());
        fChange.setKeepPreviewEdits(true);
        if (fCheckResultForCompileProblems) {
            checkNewSource(new SubProgressMonitor(pm, 1), result);
        }
        return result;
    } finally {
        pm.done();
    }
}
Also used : CompilationUnitRewrite(org.eclipse.jdt.internal.corext.refactoring.structure.CompilationUnitRewrite) NoCommentSourceRangeComputer(org.eclipse.jdt.internal.corext.refactoring.util.NoCommentSourceRangeComputer) RefactoringStatus(org.eclipse.ltk.core.refactoring.RefactoringStatus) SubProgressMonitor(org.eclipse.core.runtime.SubProgressMonitor)

Aggregations

NoCommentSourceRangeComputer (org.eclipse.jdt.internal.corext.refactoring.util.NoCommentSourceRangeComputer)3 ASTRewrite (org.eclipse.jdt.core.dom.rewrite.ASTRewrite)2 ListRewrite (org.eclipse.jdt.core.dom.rewrite.ListRewrite)2 ASTRewriteCorrectionProposal (org.eclipse.jdt.ui.text.java.correction.ASTRewriteCorrectionProposal)2 Image (org.eclipse.swt.graphics.Image)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 SubProgressMonitor (org.eclipse.core.runtime.SubProgressMonitor)1 CompilationUnitRewrite (org.eclipse.jdt.internal.corext.refactoring.structure.CompilationUnitRewrite)1 RefactoringStatus (org.eclipse.ltk.core.refactoring.RefactoringStatus)1