1 /*******************************************************************************
2 * Copyright (c) 2000, 2004 IBM Corporation and others.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Common Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/cpl-v10.html
9 * IBM Corporation - initial API and implementation
10 *******************************************************************************/
11 package net.sourceforge.phpdt.internal.ui.actions;
13 import java.util.LinkedList;
14 import java.util.List;
15 import java.util.ResourceBundle;
17 import org.eclipse.jface.text.BadLocationException;
18 import org.eclipse.jface.text.BadPartitioningException;
19 import org.eclipse.jface.text.IDocumentExtension3;
20 import org.eclipse.jface.text.ITextSelection;
21 import org.eclipse.jface.text.ITypedRegion;
23 import org.eclipse.ui.texteditor.ITextEditor;
25 import net.sourceforge.phpdt.internal.ui.text.IPHPPartitions;
28 * Action that removes the enclosing comment marks from a Java block comment.
32 public class RemoveBlockCommentAction extends BlockCommentAction {
35 * Creates a new instance.
37 * @param bundle the resource bundle
38 * @param prefix a prefix to be prepended to the various resource keys
39 * (described in <code>ResourceAction</code> constructor), or
40 * <code>null</code> if none
41 * @param editor the text editor
43 public RemoveBlockCommentAction(ResourceBundle bundle, String prefix, ITextEditor editor) {
44 super(bundle, prefix, editor);
48 * @see net.sourceforge.phpdt.internal.ui.actions.AddBlockCommentAction#runInternal(org.eclipse.jface.text.ITextSelection, org.eclipse.jface.text.IDocumentExtension3, net.sourceforge.phpdt.internal.ui.actions.AddBlockCommentAction.Edit.EditFactory)
50 protected void runInternal(ITextSelection selection, IDocumentExtension3 docExtension, Edit.EditFactory factory) throws BadPartitioningException, BadLocationException {
51 List edits= new LinkedList();
52 int tokenLength= getCommentStart().length();
54 int offset= selection.getOffset();
55 int endOffset= offset + selection.getLength();
57 ITypedRegion partition= docExtension.getPartition(IPHPPartitions.PHP_PARTITIONING, offset, false);
58 int partOffset= partition.getOffset();
59 int partEndOffset= partOffset + partition.getLength();
61 while (partEndOffset < endOffset) {
63 if (partition.getType() == IPHPPartitions.PHP_MULTILINE_COMMENT) {
64 edits.add(factory.createEdit(partOffset, tokenLength, "")); //$NON-NLS-1$
65 edits.add(factory.createEdit(partEndOffset - tokenLength, tokenLength, "")); //$NON-NLS-1$
68 partition= docExtension.getPartition(IPHPPartitions.PHP_PARTITIONING, partEndOffset, false);
69 partOffset= partition.getOffset();
70 partEndOffset= partOffset + partition.getLength();
73 if (partition.getType() == IPHPPartitions.PHP_MULTILINE_COMMENT) {
74 edits.add(factory.createEdit(partOffset, tokenLength, "")); //$NON-NLS-1$
75 edits.add(factory.createEdit(partEndOffset - tokenLength, tokenLength, "")); //$NON-NLS-1$
82 * @see net.sourceforge.phpdt.internal.ui.actions.AddBlockCommentAction#validSelection(org.eclipse.jface.text.ITextSelection)
84 protected boolean isValidSelection(ITextSelection selection) {
85 return selection != null && !selection.isEmpty();