edits.add(factory.createEdit(partEndOffset - tokenLength, tokenLength, "")); //$NON-NLS-1$ edits.add(factory.createEdit(partition.getOffset(), 0, getCommentStart())); edits.add(factory.createEdit(partition.getOffset(), 0, getCommentEnd())); } else if (partType == IJavaPartitions.JAVA_MULTI_LINE_COMMENT) { edits.add(factory.createEdit(partition.getOffset(), getCommentStart().length(), "")); //$NON-NLS-1$
edits.add(factory.createEdit(partEndOffset - tokenLength, tokenLength, "")); //$NON-NLS-1$ edits.add(factory.createEdit(partition.getOffset(), 0, getCommentStart())); edits.add(factory.createEdit(partition.getOffset(), 0, getCommentEnd())); } else if (partType == IJavaPartitions.JAVA_MULTI_LINE_COMMENT) { edits.add(factory.createEdit(partition.getOffset(), getCommentStart().length(), "")); //$NON-NLS-1$
edits.add(factory.createEdit(partEndOffset - tokenLength, tokenLength, "")); //$NON-NLS-1$ edits.add(factory.createEdit(partition.getOffset(), 0, getCommentStart())); edits.add(factory.createEdit(partition.getOffset(), 0, getCommentEnd())); } else if (partType == IJavaPartitions.JAVA_MULTI_LINE_COMMENT) { edits.add(factory.createEdit(partition.getOffset(), getCommentStart().length(), "")); //$NON-NLS-1$
Edit.EditFactory factory= new Edit.EditFactory(document); factory.release();
Edit.EditFactory factory= new Edit.EditFactory(document); factory.release();
Edit.EditFactory factory= new Edit.EditFactory(document); factory.release();
edits.add(factory.createEdit(partOffset, tokenLength, "")); //$NON-NLS-1$ edits.add(factory.createEdit(partEndOffset - tokenLength, tokenLength, "")); //$NON-NLS-1$ edits.add(factory.createEdit(partOffset, tokenLength, "")); //$NON-NLS-1$ edits.add(factory.createEdit(partEndOffset - tokenLength, tokenLength, "")); //$NON-NLS-1$
@Override protected void runInternal(ITextSelection selection, IDocumentExtension3 docExtension, Edit.EditFactory factory) throws BadPartitioningException, BadLocationException { List<Edit> edits= new LinkedList<>(); int tokenLength= getCommentStart().length(); int offset= selection.getOffset(); int endOffset= offset + selection.getLength(); ITypedRegion partition= docExtension.getPartition(IJavaPartitions.JAVA_PARTITIONING, offset, false); int partOffset= partition.getOffset(); int partEndOffset= partOffset + partition.getLength(); while (partEndOffset < endOffset) { if (partition.getType() == IJavaPartitions.JAVA_MULTI_LINE_COMMENT) { edits.add(factory.createEdit(partOffset, tokenLength, "")); //$NON-NLS-1$ edits.add(factory.createEdit(partEndOffset - tokenLength, tokenLength, "")); //$NON-NLS-1$ } partition= docExtension.getPartition(IJavaPartitions.JAVA_PARTITIONING, partEndOffset, false); partOffset= partition.getOffset(); partEndOffset= partOffset + partition.getLength(); } if (partition.getType() == IJavaPartitions.JAVA_MULTI_LINE_COMMENT) { edits.add(factory.createEdit(partOffset, tokenLength, "")); //$NON-NLS-1$ edits.add(factory.createEdit(partEndOffset - tokenLength, tokenLength, "")); //$NON-NLS-1$ } executeEdits(edits); }
private void removeToken(final ITypedRegion partition, int partOffset, final Edit.EditFactory factory, final List<Edit> edits) throws BadLocationException { IEditorInput editorInput = getTextEditor().getEditorInput(); IDocument document = getTextEditor().getDocumentProvider().getDocument(editorInput); int startLine = document.getLineOfOffset(partOffset); int lines = document.getNumberOfLines(partOffset, partition.getLength()); for(int line = startLine; line < startLine + lines; line++) { int lineOffset = document.getLineOffset(line); int lineLength = document.getLineLength(line); char ch1 = document.getChar(lineOffset); int pos = 0; // skip all character codes <= 0x20 from start of line while(pos < lineLength && ((ch1 = document.getChar(lineOffset + pos)) <= 0x20)) { pos++; } if(ch1 == '*') { /* next char after '*' must NOT be a '/', this is handled separately */ if(pos + 1 < lineLength) { char ch2 = document.getChar(lineOffset + pos + 1); if(ch2 == '/') { continue; // do next line } } Edit edit= factory.createEdit(lineOffset + pos, 1, ""); //$NON-NLS-1$ edits.add(edit); } } }
protected void runInternal(ITextSelection selection, IDocumentExtension3 docExtension, Edit.EditFactory factory) throws BadPartitioningException, BadLocationException { List edits= new LinkedList(); int tokenLength= getCommentStart().length(); int offset= selection.getOffset(); int endOffset= offset + selection.getLength(); ITypedRegion partition= docExtension.getPartition(IJavaPartitions.JAVA_PARTITIONING, offset, false); int partOffset= partition.getOffset(); int partEndOffset= partOffset + partition.getLength(); while (partEndOffset < endOffset) { if (partition.getType() == IJavaPartitions.JAVA_MULTI_LINE_COMMENT) { edits.add(factory.createEdit(partOffset, tokenLength, "")); //$NON-NLS-1$ edits.add(factory.createEdit(partEndOffset - tokenLength, tokenLength, "")); //$NON-NLS-1$ } partition= docExtension.getPartition(IJavaPartitions.JAVA_PARTITIONING, partEndOffset, false); partOffset= partition.getOffset(); partEndOffset= partOffset + partition.getLength(); } if (partition.getType() == IJavaPartitions.JAVA_MULTI_LINE_COMMENT) { edits.add(factory.createEdit(partOffset, tokenLength, "")); //$NON-NLS-1$ edits.add(factory.createEdit(partEndOffset - tokenLength, tokenLength, "")); //$NON-NLS-1$ } executeEdits(edits); }
/** * Handle the partition under the start offset of the selection. * * @param partition the partition under the start of the selection * @param edits the list of edits to later execute * @param factory the factory for edits * @param offset the start of the selection, which must lie inside * <code>partition</code> */ private void handleFirstPartition(ITypedRegion partition, List<Edit> edits, Edit.EditFactory factory, int offset) throws BadLocationException { int partOffset= partition.getOffset(); String partType= partition.getType(); Assert.isTrue(partOffset <= offset, "illegal partition"); //$NON-NLS-1$ // first partition: mark start of comment if (partType == IDocument.DEFAULT_CONTENT_TYPE) { // Java code: right where selection starts edits.add(factory.createEdit(offset, 0, getCommentStart())); } else if (isSpecialPartition(partType)) { // special types: include the entire partition edits.add(factory.createEdit(partOffset, 0, getCommentStart())); } // javadoc: no mark, will only start after comment }
/** * Handle the partition under the start offset of the selection. * * @param partition the partition under the start of the selection * @param edits the list of edits to later execute * @param factory the factory for edits * @param offset the start of the selection, which must lie inside * <code>partition</code> */ private void handleFirstPartition(ITypedRegion partition, List edits, Edit.EditFactory factory, int offset) throws BadLocationException { int partOffset= partition.getOffset(); String partType= partition.getType(); Assert.isTrue(partOffset <= offset, "illegal partition"); //$NON-NLS-1$ // first partition: mark start of comment if (partType == IDocument.DEFAULT_CONTENT_TYPE) { // Java code: right where selection starts edits.add(factory.createEdit(offset, 0, getCommentStart())); } else if (isSpecialPartition(partType)) { // special types: include the entire partition edits.add(factory.createEdit(partOffset, 0, getCommentStart())); } // javadoc: no mark, will only start after comment }
/** * Handles the partition under the end of the selection. For normal java code, the comment end token * is inserted at the selection end; if the selection ends inside a special (i.e. string, character, * line comment) partition, the entire partition is included inside the comment. * * @param partition the partition under the selection end offset * @param edits the list of edits to add to * @param factory the edit factory * @param endOffset the end offset of the selection * @throws BadLocationException if accessing the document fails - this can only happen if the * document gets modified concurrently */ private void handleLastPartition(ITypedRegion partition, List<Edit> edits, Edit.EditFactory factory, int endOffset) throws BadLocationException { String partType= partition.getType(); if (partType == IDocument.DEFAULT_CONTENT_TYPE) { // normal java: end comment where selection ends edits.add(factory.createEdit(endOffset, 0, getCommentEnd())); } else if (isSpecialPartition(partType)) { // special types: consume entire partition edits.add(factory.createEdit(partition.getOffset() + partition.getLength(), 0, getCommentEnd())); } }
/** * Handles the partition under the end of the selection. For normal java * code, the comment end token is inserted at the selection end; if the * selection ends inside a special (i.e. string, character, line comment) * partition, the entire partition is included inside the comment. * * @param partition the partition under the selection end offset * @param edits the list of edits to add to * @param factory the edit factory * @param endOffset the end offset of the selection */ private void handleLastPartition(ITypedRegion partition, List edits, Edit.EditFactory factory, int endOffset) throws BadLocationException { String partType= partition.getType(); if (partType == IDocument.DEFAULT_CONTENT_TYPE) { // normal java: end comment where selection ends edits.add(factory.createEdit(endOffset, 0, getCommentEnd())); } else if (isSpecialPartition(partType)) { // special types: consume entire partition edits.add(factory.createEdit(partition.getOffset() + partition.getLength(), 0, getCommentEnd())); } }
/** * Handle the partition under the start offset of the selection. * * @param partition the partition under the start of the selection * @param edits the list of edits to later execute * @param factory the factory for edits * @param offset the start of the selection, which must lie inside <code>partition</code> * @throws BadLocationException if accessing the document fails - this can only happen if the * document gets modified concurrently */ private void handleFirstPartition(ITypedRegion partition, List<Edit> edits, Edit.EditFactory factory, int offset) throws BadLocationException { int partOffset= partition.getOffset(); String partType= partition.getType(); Assert.isTrue(partOffset <= offset, "illegal partition"); //$NON-NLS-1$ // first partition: mark start of comment if (partType == IDocument.DEFAULT_CONTENT_TYPE) { // Java code: right where selection starts edits.add(factory.createEdit(offset, 0, getCommentStart())); } else if (isSpecialPartition(partType)) { // special types: include the entire partition edits.add(factory.createEdit(partOffset, 0, getCommentStart())); } // javadoc: no mark, will only start after comment }
/** * Handles the partition under the end of the selection. For normal java * code, the comment end token is inserted at the selection end; if the * selection ends inside a special (i.e. string, character, line comment) * partition, the entire partition is included inside the comment. * * @param partition the partition under the selection end offset * @param edits the list of edits to add to * @param factory the edit factory * @param endOffset the end offset of the selection */ private void handleLastPartition(ITypedRegion partition, List<Edit> edits, Edit.EditFactory factory, int endOffset) throws BadLocationException { String partType= partition.getType(); if (partType == IDocument.DEFAULT_CONTENT_TYPE) { // normal java: end comment where selection ends edits.add(factory.createEdit(endOffset, 0, getCommentEnd())); } else if (isSpecialPartition(partType)) { // special types: consume entire partition edits.add(factory.createEdit(partition.getOffset() + partition.getLength(), 0, getCommentEnd())); } }