1 /*******************************************************************************
2 * Copyright (c) 2000, 2003 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;
28 * Action that removes the enclosing comment marks from a Java block comment.
32 public class RemoveBlockCommentAction extends BlockCommentAction {
33 final static String DEFAULT_PARTITIONING_CONTENT_TYPE = "__dftl_partition_content_type"; //$NON-NLS-1$
36 * Creates a new instance.
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
44 public RemoveBlockCommentAction(ResourceBundle bundle, String prefix, ITextEditor editor) {
45 super(bundle, prefix, editor);
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)
51 protected void runInternal(ITextSelection selection, IDocumentExtension3 docExtension, Edit.EditFactory factory) throws BadPartitioningException, BadLocationException {
52 List edits= new LinkedList();
53 int tokenLength= getCommentStart().length();
55 int offset= selection.getOffset();
56 int endOffset= offset + selection.getLength();
58 // ITypedRegion partition= docExtension.getPartition(IPHPPartitions.PHP_PARTITIONING, offset, false);
59 ITypedRegion partition= docExtension.getPartition(IDocumentExtension3.DEFAULT_PARTITIONING, offset, false);
61 int partOffset= partition.getOffset();
62 int partEndOffset= partOffset + partition.getLength();
64 while (partEndOffset < endOffset) {
66 if (partition.getType() == IPHPPartitions.PHP_PHPDOC_COMMENT) {
67 edits.add(factory.createEdit(partOffset, tokenLength, "")); //$NON-NLS-1$
68 edits.add(factory.createEdit(partEndOffset - tokenLength, tokenLength, "")); //$NON-NLS-1$
71 // partition= docExtension.getPartition(IPHPPartitions.PHP_PARTITIONING, partEndOffset, false);
72 partition= docExtension.getPartition(IDocumentExtension3.DEFAULT_PARTITIONING, partEndOffset, false);
74 partOffset= partition.getOffset();
75 partEndOffset= partOffset + partition.getLength();
78 // if (partition.getType() == IPHPPartitions.PHP_PHPDOC_COMMENT) {
79 if (partition.getType() == DEFAULT_PARTITIONING_CONTENT_TYPE) {
80 edits.add(factory.createEdit(partOffset, tokenLength, "")); //$NON-NLS-1$
81 edits.add(factory.createEdit(partEndOffset - tokenLength, tokenLength, "")); //$NON-NLS-1$
88 * @see org.eclipse.jdt.internal.ui.actions.AddBlockCommentAction#validSelection(org.eclipse.jface.text.ITextSelection)
90 protected boolean isValidSelection(ITextSelection selection) {
91 return selection != null && !selection.isEmpty();