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.
39 * a prefix to be prepended to the various resource keys
40 * (described in <code>ResourceAction</code> constructor), or
41 * <code>null</code> if none
45 public RemoveBlockCommentAction(ResourceBundle bundle, String prefix,
47 super(bundle, prefix, editor);
51 * @see net.sourceforge.phpdt.internal.ui.actions.AddBlockCommentAction#runInternal(org.eclipse.jface.text.ITextSelection,
52 * org.eclipse.jface.text.IDocumentExtension3,
53 * net.sourceforge.phpdt.internal.ui.actions.AddBlockCommentAction.Edit.EditFactory)
55 protected void runInternal(ITextSelection selection,
56 IDocumentExtension3 docExtension, Edit.EditFactory factory)
57 throws BadPartitioningException, BadLocationException {
58 List edits = new LinkedList();
59 int tokenLength = getCommentStart().length();
61 int offset = selection.getOffset();
62 int endOffset = offset + selection.getLength();
64 ITypedRegion partition = docExtension.getPartition(
65 IPHPPartitions.PHP_PARTITIONING, offset, false);
66 int partOffset = partition.getOffset();
67 int partEndOffset = partOffset + partition.getLength();
69 while (partEndOffset < endOffset) {
71 if (partition.getType() == IPHPPartitions.PHP_MULTILINE_COMMENT) {
72 edits.add(factory.createEdit(partOffset, tokenLength, "")); //$NON-NLS-1$
73 edits.add(factory.createEdit(partEndOffset - tokenLength,
74 tokenLength, "")); //$NON-NLS-1$
77 partition = docExtension.getPartition(
78 IPHPPartitions.PHP_PARTITIONING, partEndOffset, false);
79 partOffset = partition.getOffset();
80 partEndOffset = partOffset + partition.getLength();
83 if (partition.getType() == IPHPPartitions.PHP_MULTILINE_COMMENT) {
84 edits.add(factory.createEdit(partOffset, tokenLength, "")); //$NON-NLS-1$
85 edits.add(factory.createEdit(partEndOffset - tokenLength,
86 tokenLength, "")); //$NON-NLS-1$
93 * @see net.sourceforge.phpdt.internal.ui.actions.AddBlockCommentAction#validSelection(org.eclipse.jface.text.ITextSelection)
95 protected boolean isValidSelection(ITextSelection selection) {
96 return selection != null && !selection.isEmpty();