/** * Formats the document specified in the formatting context with the * formatting strategy registered for the content type. * <p> * For this formatting type only slave strategies are used. The region to be * formatted is aligned on partition boundaries of the underlying content * type. The exact formatting strategy is determined by the underlying * content type of the document partitioning. * * @param context The formatting context to use * @param document The document to operate on * @param offset The offset of the region to format * @param length The length of the region to format * @param type The content type of the region to format */ protected void formatSlave(final IFormattingContext context, final IDocument document, final int offset, final int length, final String type) { final IFormattingStrategyExtension strategy= (IFormattingStrategyExtension)fSlaves.get(type); if (strategy != null) { context.setProperty(FormattingContextProperties.CONTEXT_PARTITION, new TypedPosition(offset, length, type)); strategy.formatterStarts(context); strategy.format(); strategy.formatterStops(); } }
/** * Formats the document specified in the formatting context with the * formatting strategy registered for the content type. * <p> * For this formatting type only slave strategies are used. The region to be * formatted is aligned on partition boundaries of the underlying content * type. The exact formatting strategy is determined by the underlying * content type of the document partitioning. * * @param context The formatting context to use * @param document The document to operate on * @param offset The offset of the region to format * @param length The length of the region to format * @param type The content type of the region to format */ protected void formatSlave(final IFormattingContext context, final IDocument document, final int offset, final int length, final String type) { final IFormattingStrategyExtension strategy= (IFormattingStrategyExtension)fSlaves.get(type); if (strategy != null) { context.setProperty(FormattingContextProperties.CONTEXT_PARTITION, new TypedPosition(offset, length, type)); strategy.formatterStarts(context); strategy.format(); strategy.formatterStops(); } }
public void documentAboutToBeChanged(DocumentEvent e) { fDocumentChanging= true; if (fCachedRedrawState) { try { int offset= e.getOffset() + e.getLength(); ITypedRegion region= getPartition(e.getDocument(), offset); fRememberedPosition= new TypedPosition(region); e.getDocument().addPosition(fPositionCategory, fRememberedPosition); } catch (BadLocationException x) { // can not happen } catch (BadPositionCategoryException x) { // should not happen on input elements } } }
@Override public void documentAboutToBeChanged(DocumentEvent e) { fDocumentChanging= true; if (fCachedRedrawState) { try { int offset= e.getOffset() + e.getLength(); ITypedRegion region= getPartition(e.getDocument(), offset); fRememberedPosition= new TypedPosition(region); e.getDocument().addPosition(fPositionCategory, fRememberedPosition); } catch (BadLocationException x) { // can not happen } catch (BadPositionCategoryException x) { // should not happen on input elements } } }
@Override public void documentAboutToBeChanged(DocumentEvent e) { fDocumentChanging= true; if (fCachedRedrawState) { try { int offset= e.getOffset() + e.getLength(); ITypedRegion region= getPartition(e.getDocument(), offset); fRememberedPosition= new TypedPosition(region); e.getDocument().addPosition(fPositionCategory, fRememberedPosition); } catch (BadLocationException x) { // can not happen } catch (BadPositionCategoryException x) { // should not happen on input elements } } }
/** * Returns the partitioning of the given region of the document to be formatted. * As one partition after the other will be formatted and formatting will * probably change the length of the formatted partition, it must be kept * track of the modifications in order to submit the correct partition to all * formatting strategies. For this, all partitions are remembered as positions * in a dedicated position category. (As formatting strategies might rely on each * other, calling them in reversed order is not an option.) * * @param region the region for which the partitioning must be determined * @return the partitioning of the specified region * @exception BadLocationException of region is invalid in the document * @since 3.0 */ private TypedPosition[] getPartitioning(IRegion region) throws BadLocationException { ITypedRegion[] regions= TextUtilities.computePartitioning(fDocument, fPartitioning, region.getOffset(), region.getLength(), false); TypedPosition[] positions= new TypedPosition[regions.length]; for (int i= 0; i < regions.length; i++) { positions[i]= new TypedPosition(regions[i]); try { fDocument.addPosition(PARTITIONING, positions[i]); } catch (BadPositionCategoryException x) { // should not happen } } return positions; }
/** * Returns the partitioning of the given region of the document to be formatted. * As one partition after the other will be formatted and formatting will * probably change the length of the formatted partition, it must be kept * track of the modifications in order to submit the correct partition to all * formatting strategies. For this, all partitions are remembered as positions * in a dedicated position category. (As formatting strategies might rely on each * other, calling them in reversed order is not an option.) * * @param region the region for which the partitioning must be determined * @return the partitioning of the specified region * @exception BadLocationException of region is invalid in the document * @since 3.0 */ private TypedPosition[] getPartitioning(IRegion region) throws BadLocationException { ITypedRegion[] regions= TextUtilities.computePartitioning(fDocument, fPartitioning, region.getOffset(), region.getLength(), false); TypedPosition[] positions= new TypedPosition[regions.length]; for (int i= 0; i < regions.length; i++) { positions[i]= new TypedPosition(regions[i]); try { fDocument.addPosition(PARTITIONING, positions[i]); } catch (BadPositionCategoryException x) { // should not happen } } return positions; }
/** * Formats the given region with the strategy registered for the default * content type. The strategy is informed about the start, the process, and * the termination of the formatting session. * * @param region the region to be formatted * @since 3.0 */ private void formatRegion(IRegion region) { IFormattingStrategy strategy= getFormattingStrategy(IDocument.DEFAULT_CONTENT_TYPE); if (strategy != null) { strategy.formatterStarts(getIndentation(region.getOffset())); format(strategy, new TypedPosition(region.getOffset(), region.getLength(), IDocument.DEFAULT_CONTENT_TYPE)); strategy.formatterStops(); } }
/** * Formats the given region with the strategy registered for the default * content type. The strategy is informed about the start, the process, and * the termination of the formatting session. * * @param region the region to be formatted * @since 3.0 */ private void formatRegion(IRegion region) { IFormattingStrategy strategy= getFormattingStrategy(IDocument.DEFAULT_CONTENT_TYPE); if (strategy != null) { strategy.formatterStarts(getIndentation(region.getOffset())); format(strategy, new TypedPosition(region.getOffset(), region.getLength(), IDocument.DEFAULT_CONTENT_TYPE)); strategy.formatterStops(); } }
context.setProperty(FormattingContextProperties.CONTEXT_PARTITION, new TypedPosition(offset, length, fType));
private static TextEdit format(ITypedRegion region, IFormattingContext context, CommentFormattingStrategy formattingStrategy, String content) { TypedPosition typedPosition= new TypedPosition(region.getOffset(), region.getLength(), region.getType()); context.setProperty(FormattingContextProperties.CONTEXT_PARTITION, typedPosition); formattingStrategy.formatterStarts(context);
/** * Performs the initial partitioning of the partitioner's document. */ protected void initialize() { fIsInitialized= true; fScanner.setRange(fDocument, 0, fDocument.getLength()); try { IToken token= fScanner.nextToken(); while (!token.isEOF()) { String contentType= getTokenContentType(token); if (isSupportedContentType(contentType)) { TypedPosition p= new TypedPosition(fScanner.getTokenOffset(), fScanner.getTokenLength(), contentType); fDocument.addPosition(fPositionCategory, p); } token= fScanner.nextToken(); } } catch (BadLocationException x) { // cannot happen as offsets come from scanner } catch (BadPositionCategoryException x) { // cannot happen if document has been connected before } }
/** * Performs the initial partitioning of the partitioner's document. */ protected void initialize() { fScanner.setRange(fDocument, 0, fDocument.getLength()); try { IToken token= fScanner.nextToken(); while (!token.isEOF()) { String contentType= getTokenContentType(token); if (isSupportedContentType(contentType)) { TypedPosition p= new TypedPosition(fScanner.getTokenOffset(), fScanner.getTokenLength(), contentType); fDocument.addPosition(fPositionCategory, p); } token= fScanner.nextToken(); } } catch (BadLocationException x) { // cannot happen as offsets come from scanner } catch (BadPositionCategoryException x) { // cannot happen if document has been connected before } }
/** * Performs the initial partitioning of the partitioner's document. */ protected void initialize() { fScanner.setRange(fDocument, 0, fDocument.getLength()); try { IToken token= fScanner.nextToken(); while (!token.isEOF()) { String contentType= getTokenContentType(token); if (isSupportedContentType(contentType)) { TypedPosition p= new TypedPosition(fScanner.getTokenOffset(), fScanner.getTokenLength(), contentType); fDocument.addPosition(fPositionCategory, p); } token= fScanner.nextToken(); } } catch (BadLocationException x) { // cannot happen as offsets come from scanner } catch (BadPositionCategoryException x) { // cannot happen if document has been connected before } }
/** * Performs the initial partitioning of the partitioner's document. */ protected void initialize() { fIsInitialized= true; fScanner.setRange(fDocument, 0, fDocument.getLength()); try { IToken token= fScanner.nextToken(); while (!token.isEOF()) { String contentType= getTokenContentType(token); if (isSupportedContentType(contentType)) { TypedPosition p= new TypedPosition(fScanner.getTokenOffset(), fScanner.getTokenLength(), contentType); fDocument.addPosition(fPositionCategory, p); } token= fScanner.nextToken(); } } catch (BadLocationException x) { // cannot happen as offsets come from scanner } catch (BadPositionCategoryException x) { // cannot happen if document has been connected before } }
/** * Performs the initial partitioning of the partitioner's document. * <p> * May be extended by subclasses. * </p> */ protected void initialize() { fIsInitialized= true; clearPositionCache(); fScanner.setRange(fDocument, 0, fDocument.getLength()); try { IToken token= fScanner.nextToken(); while (!token.isEOF()) { String contentType= getTokenContentType(token); if (isSupportedContentType(contentType)) { TypedPosition p= new TypedPosition(fScanner.getTokenOffset(), fScanner.getTokenLength(), contentType); fDocument.addPosition(fPositionCategory, p); } token= fScanner.nextToken(); } } catch (BadLocationException x) { // cannot happen as offsets come from scanner } catch (BadPositionCategoryException x) { // cannot happen if document has been connected before } }
/** * Performs the initial partitioning of the partitioner's document. * <p> * May be extended by subclasses. * </p> */ protected void initialize() { fIsInitialized= true; clearPositionCache(); fScanner.setRange(fDocument, 0, fDocument.getLength()); try { IToken token= fScanner.nextToken(); while (!token.isEOF()) { String contentType= getTokenContentType(token); if (isSupportedContentType(contentType)) { TypedPosition p= new TypedPosition(fScanner.getTokenOffset(), fScanner.getTokenLength(), contentType); fDocument.addPosition(fPositionCategory, p); } token= fScanner.nextToken(); } } catch (BadLocationException x) { // cannot happen as offsets come from scanner } catch (BadPositionCategoryException x) { // cannot happen if document has been connected before } }
/** * Performs the initial partitioning of the partitioner's document. * <p> * May be extended by subclasses. * </p> */ protected void initialize() { fIsInitialized= true; clearPositionCache(); fScanner.setRange(fDocument, 0, fDocument.getLength()); try { IToken token= fScanner.nextToken(); while (!token.isEOF()) { String contentType= getTokenContentType(token); if (isSupportedContentType(contentType)) { TypedPosition p= new TypedPosition(fScanner.getTokenOffset(), fScanner.getTokenLength(), contentType); fDocument.addPosition(fPositionCategory, p); } token= fScanner.nextToken(); } } catch (BadLocationException x) { // cannot happen as offsets come from scanner } catch (BadPositionCategoryException x) { // cannot happen if document has been connected before } }
/** * Performs the initial partitioning of the partitioner's document. * <p> * May be extended by subclasses. * </p> */ protected void initialize() { fIsInitialized= true; clearPositionCache(); fScanner.setRange(fDocument, 0, fDocument.getLength()); try { IToken token= fScanner.nextToken(); while (!token.isEOF()) { String contentType= getTokenContentType(token); if (isSupportedContentType(contentType)) { TypedPosition p= new TypedPosition(fScanner.getTokenOffset(), fScanner.getTokenLength(), contentType); fDocument.addPosition(fPositionCategory, p); } token= fScanner.nextToken(); } } catch (BadLocationException x) { // cannot happen as offsets come from scanner } catch (BadPositionCategoryException x) { // cannot happen if document has been connected before } }
/** * Performs the initial partitioning of the partitioner's document. * <p> * May be extended by subclasses. * </p> * * @since 2.2 */ protected void initialize() { fIsInitialized = true; clearPositionCache(); fScanner.setRange(fDocument, 0, fDocument.getLength()); try { IToken token = fScanner.nextToken(); while (!token.isEOF()) { String contentType = getTokenContentType(token); if (isSupportedContentType(contentType)) { TypedPosition p = new TypedPosition(fScanner.getTokenOffset(), fScanner.getTokenLength(), contentType); fDocument.addPosition(fPositionCategory, p); } token = fScanner.nextToken(); } } catch (BadLocationException x) { // cannot happen as offsets come from scanner } catch (BadPositionCategoryException x) { // cannot happen if document has been connected before } }