1 11 package org.eclipse.jdt.internal.ui.actions; 12 13 import java.util.LinkedList ; 14 import java.util.List ; 15 import java.util.ResourceBundle ; 16 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; 22 23 import org.eclipse.ui.texteditor.ITextEditor; 24 25 import org.eclipse.jdt.ui.text.IJavaPartitions; 26 27 28 33 public class RemoveBlockCommentAction extends BlockCommentAction { 34 35 44 public RemoveBlockCommentAction(ResourceBundle bundle, String prefix, ITextEditor editor) { 45 super(bundle, prefix, editor); 46 } 47 48 51 protected void runInternal(ITextSelection selection, IDocumentExtension3 docExtension, Edit.EditFactory factory) throws BadPartitioningException, BadLocationException { 52 List edits= new LinkedList (); 53 int tokenLength= getCommentStart().length(); 54 55 int offset= selection.getOffset(); 56 int endOffset= offset + selection.getLength(); 57 58 ITypedRegion partition= docExtension.getPartition(IJavaPartitions.JAVA_PARTITIONING, offset, false); 59 int partOffset= partition.getOffset(); 60 int partEndOffset= partOffset + partition.getLength(); 61 62 while (partEndOffset < endOffset) { 63 64 if (partition.getType() == IJavaPartitions.JAVA_MULTI_LINE_COMMENT) { 65 edits.add(factory.createEdit(partOffset, tokenLength, "")); edits.add(factory.createEdit(partEndOffset - tokenLength, tokenLength, "")); } 68 69 partition= docExtension.getPartition(IJavaPartitions.JAVA_PARTITIONING, partEndOffset, false); 70 partOffset= partition.getOffset(); 71 partEndOffset= partOffset + partition.getLength(); 72 } 73 74 if (partition.getType() == IJavaPartitions.JAVA_MULTI_LINE_COMMENT) { 75 edits.add(factory.createEdit(partOffset, tokenLength, "")); edits.add(factory.createEdit(partEndOffset - tokenLength, tokenLength, "")); } 78 79 executeEdits(edits); 80 } 81 82 85 protected boolean isValidSelection(ITextSelection selection) { 86 return selection != null && !selection.isEmpty(); 87 } 88 89 } 90 | Popular Tags |