]> git.uio.no Git - ifi-stolz-refaktor.git/blame - case-study/jdt-before/ui/org/eclipse/jdt/internal/ui/actions/RemoveBlockCommentAction.java
Case Study: adding data and statistics
[ifi-stolz-refaktor.git] / case-study / jdt-before / ui / org / eclipse / jdt / internal / ui / actions / RemoveBlockCommentAction.java
CommitLineData
1b2798f6
EK
1/*******************************************************************************
2 * Copyright (c) 2000, 2011 IBM Corporation and others.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/epl-v10.html
7 *
8 * Contributors:
9 * IBM Corporation - initial API and implementation
10 *******************************************************************************/
11package org.eclipse.jdt.internal.ui.actions;
12
13import java.util.LinkedList;
14import java.util.List;
15import java.util.ResourceBundle;
16
17import org.eclipse.jface.text.BadLocationException;
18import org.eclipse.jface.text.BadPartitioningException;
19import org.eclipse.jface.text.IDocumentExtension3;
20import org.eclipse.jface.text.ITextSelection;
21import org.eclipse.jface.text.ITypedRegion;
22
23import org.eclipse.ui.texteditor.ITextEditor;
24
25import org.eclipse.jdt.ui.text.IJavaPartitions;
26
27
28/**
29 * Action that removes the enclosing comment marks from a Java block comment.
30 *
31 * @since 3.0
32 */
33public class RemoveBlockCommentAction extends BlockCommentAction {
34
35 /**
36 * Creates a new instance.
37 *
38 * @param bundle the resource bundle
39 * @param prefix a prefix to be prepended to the various resource keys
40 * (described in <code>ResourceAction</code> constructor), or
41 * <code>null</code> if none
42 * @param editor the text editor
43 */
44 public RemoveBlockCommentAction(ResourceBundle bundle, String prefix, ITextEditor editor) {
45 super(bundle, prefix, editor);
46 }
47
48 /*
49 * @see org.eclipse.jdt.internal.ui.actions.AddBlockCommentAction#runInternal(org.eclipse.jface.text.ITextSelection, org.eclipse.jface.text.IDocumentExtension3, org.eclipse.jdt.internal.ui.actions.AddBlockCommentAction.Edit.EditFactory)
50 */
51 @Override
52 protected void runInternal(ITextSelection selection, IDocumentExtension3 docExtension, Edit.EditFactory factory) throws BadPartitioningException, BadLocationException {
53 List<Edit> edits= new LinkedList<Edit>();
54 int tokenLength= getCommentStart().length();
55
56 int offset= selection.getOffset();
57 int endOffset= offset + selection.getLength();
58
59 ITypedRegion partition= docExtension.getPartition(IJavaPartitions.JAVA_PARTITIONING, offset, false);
60 int partOffset= partition.getOffset();
61 int partEndOffset= partOffset + partition.getLength();
62
63 while (partEndOffset < endOffset) {
64
65 if (partition.getType() == IJavaPartitions.JAVA_MULTI_LINE_COMMENT) {
66 edits.add(factory.createEdit(partOffset, tokenLength, "")); //$NON-NLS-1$
67 edits.add(factory.createEdit(partEndOffset - tokenLength, tokenLength, "")); //$NON-NLS-1$
68 }
69
70 partition= docExtension.getPartition(IJavaPartitions.JAVA_PARTITIONING, partEndOffset, false);
71 partOffset= partition.getOffset();
72 partEndOffset= partOffset + partition.getLength();
73 }
74
75 if (partition.getType() == IJavaPartitions.JAVA_MULTI_LINE_COMMENT) {
76 edits.add(factory.createEdit(partOffset, tokenLength, "")); //$NON-NLS-1$
77 edits.add(factory.createEdit(partEndOffset - tokenLength, tokenLength, "")); //$NON-NLS-1$
78 }
79
80 executeEdits(edits);
81 }
82
83 /*
84 * @see org.eclipse.jdt.internal.ui.actions.AddBlockCommentAction#validSelection(org.eclipse.jface.text.ITextSelection)
85 */
86 @Override
87 protected boolean isValidSelection(ITextSelection selection) {
88 return selection != null && !selection.isEmpty();
89 }
90
91}