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;
}
}
}
}
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);
}
}
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();
}
}
Aggregations