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 net.sourceforge.phpdt.internal.ui.text.IPHPPartitions;
19 import org.eclipse.jface.text.BadLocationException;
20 import org.eclipse.jface.text.BadPartitioningException;
21 import org.eclipse.jface.text.IDocumentExtension3;
22 import org.eclipse.jface.text.ITextSelection;
23 import org.eclipse.jface.text.ITypedRegion;
24 import org.eclipse.ui.texteditor.ITextEditor;
27 * Action that removes the enclosing comment marks from a Java block comment.
31 public class RemoveBlockCommentAction extends BlockCommentAction {
34 * Creates a new instance.
36 * @param bundle the resource bundle
37 * @param prefix a prefix to be prepended to the various resource keys
38 * (described in <code>ResourceAction</code> constructor), or
39 * <code>null</code> if none
40 * @param editor the text editor
42 public RemoveBlockCommentAction(ResourceBundle bundle, String prefix, ITextEditor editor) {
43 super(bundle, prefix, editor);
47 * @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)
49 protected void runInternal(ITextSelection selection, IDocumentExtension3 docExtension, Edit.EditFactory factory) throws BadPartitioningException, BadLocationException {
50 List edits= new LinkedList();
51 int tokenLength= getCommentStart().length();
53 int offset= selection.getOffset();
54 int endOffset= offset + selection.getLength();
56 ITypedRegion partition= docExtension.getPartition(IPHPPartitions.PHP_PARTITIONING, offset, false);
57 int partOffset= partition.getOffset();
58 int partEndOffset= partOffset + partition.getLength();
60 while (partEndOffset < endOffset) {
62 if (partition.getType() == IPHPPartitions.PHP_MULTILINE_COMMENT) {
63 edits.add(factory.createEdit(partOffset, tokenLength, "")); //$NON-NLS-1$
64 edits.add(factory.createEdit(partEndOffset - tokenLength, tokenLength, "")); //$NON-NLS-1$
67 partition= docExtension.getPartition(IPHPPartitions.PHP_PARTITIONING, partEndOffset, false);
68 partOffset= partition.getOffset();
69 partEndOffset= partOffset + partition.getLength();
72 if (partition.getType() == IPHPPartitions.PHP_MULTILINE_COMMENT) {
73 edits.add(factory.createEdit(partOffset, tokenLength, "")); //$NON-NLS-1$
74 edits.add(factory.createEdit(partEndOffset - tokenLength, tokenLength, "")); //$NON-NLS-1$
81 * @see net.sourceforge.phpdt.internal.ui.actions.AddBlockCommentAction#validSelection(org.eclipse.jface.text.ITextSelection)
83 protected boolean isValidSelection(ITextSelection selection) {
84 return selection != null && !selection.isEmpty();