/** * @see org.eclipse.jface.text.source.SourceViewerConfiguration#getContentFormatter(org.eclipse.jface.text.source.ISourceViewer) */ public IContentFormatter getContentFormatter( ISourceViewer sourceViewer ) { if ( formattingStrategy == null ) { formattingStrategy = new FilterFormattingStrategy( sourceViewer, parser ); } if ( formatter == null ) { formatter = new ContentFormatter(); formatter.enablePartitionAwareFormatting( false ); formatter.setFormattingStrategy( formattingStrategy, IDocument.DEFAULT_CONTENT_TYPE ); } return formatter; }
/** * Determines the partitioning of the given region of the document. * Informs the formatting strategies of each partition about the start, * the process, and the termination of the formatting session. * * @param region the document region to be formatted * @since 3.0 */ private void formatPartitions(IRegion region) { addPartitioningUpdater(); try { TypedPosition[] ranges= getPartitioning(region); if (ranges != null) { start(ranges, getIndentation(region.getOffset())); format(ranges); stop(ranges); } } catch (BadLocationException x) { } removePartitioningUpdater(); }
@Override public void format(IDocument document, IRegion region) { fNeedsComputation= true; fDocument= document; try { if (fIsPartitionAware) formatPartitions(region); else formatRegion(region); } finally { fNeedsComputation= true; fDocument= null; } }
/** * 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(); } }
final int[] positions= getAffectedPositions(offset, length); String formatted= strategy.format(content, isLineStart(offset), getIndentation(offset), positions);
/** * Creates, configures, and returns the ContentFormatter to use. * * @see org.eclipse.jface.text.source.SourceViewerConfiguration#getContentFormatter(ISourceViewer) */ public IContentFormatter getContentFormatter(ISourceViewer sourceViewer) { ContentFormatter formatter = new ContentFormatter(); formatter.setDocumentPartitioning( SQLPartitionScanner.SQL_PARTITIONING ); SQLDevToolsConfiguration factory = SQLToolsFacade.getConfigurationByVendorIdentifier(getSQLEditor().getConnectionInfo().getDatabaseVendorDefinitionId()); IFormattingStrategy formattingStrategy = new SQLWordStrategy(factory.getSQLService().getSQLSyntax()); formatter.setFormattingStrategy( formattingStrategy, IDocument.DEFAULT_CONTENT_TYPE ); return formatter; }
/** * Formats one partition after the other using the formatter strategy registered for * the partition's content type. * * @param ranges the partitioning of the document region to be formatted * @since 3.0 */ private void format(TypedPosition[] ranges) { for (TypedPosition range : ranges) { IFormattingStrategy s= getFormattingStrategy(range.getType()); if (s != null) { format(s, range); } } }
/** * Fires <code>formatterStops</code> to all formatter strategies which were * involved in the formatting process which is about to terminate. * * @param regions the partitioning of the document which has been formatted */ private void stop(TypedPosition[] regions) { for (TypedPosition region : regions) { IFormattingStrategy s= getFormattingStrategy(region.getType()); if (s != null) s.formatterStops(); } }
/** * Determines whether the given document position category should be ignored * by this formatter's position updating. * * @param category the category to check * @return <code>true</code> if the category should be ignored, <code>false</code> otherwise */ private boolean ignoreCategory(String category) { if (PARTITIONING.equals(category)) return true; String[] categories= getPartitionManagingCategories(); if (categories != null) { for (int i= 0; i < categories.length; i++) { if (categories[i].equals(category)) return true; } } return false; }
/** * Returns all offset and the end offset of all positions overlapping with the * specified document range. * * @param offset the offset of the document region to be formatted * @param length the length of the document to be formatted * @return all character positions of the interleaving positions * @since 3.0 */ private int[] getAffectedPositions(int offset, int length) { fOverlappingPositionReferences= new ArrayList<>(); determinePositionsToUpdate(offset, length); Collections.sort(fOverlappingPositionReferences); int[] positions= new int[fOverlappingPositionReferences.size()]; for (int i= 0; i < positions.length; i++) { PositionReference r= fOverlappingPositionReferences.get(i); positions[i]= r.getCharacterPosition() - offset; } 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(); } }
final int[] positions= getAffectedPositions(offset, length); String formatted= strategy.format(content, isLineStart(offset), getIndentation(offset), positions);
/** * Formats one partition after the other using the formatter strategy registered for * the partition's content type. * * @param ranges the partitioning of the document region to be formatted * @since 3.0 */ private void format(TypedPosition[] ranges) { for (int i= 0; i < ranges.length; i++) { IFormattingStrategy s= getFormattingStrategy(ranges[i].getType()); if (s != null) { format(s, ranges[i]); } } }
/** * Fires <code>formatterStops</code> to all formatter strategies which were * involved in the formatting process which is about to terminate. * * @param regions the partitioning of the document which has been formatted */ private void stop(TypedPosition[] regions) { for (int i= 0; i < regions.length; i++) { IFormattingStrategy s= getFormattingStrategy(regions[i].getType()); if (s != null) s.formatterStops(); } }
/** * Determines whether the given document position category should be ignored * by this formatter's position updating. * * @param category the category to check * @return <code>true</code> if the category should be ignored, <code>false</code> otherwise */ private boolean ignoreCategory(String category) { if (PARTITIONING.equals(category)) { return true; } String[] categories= getPartitionManagingCategories(); if (categories != null) { for (String cat : categories) { if (cat.equals(category)) { return true; } } } return false; }
/** * Returns all offset and the end offset of all positions overlapping with the * specified document range. * * @param offset the offset of the document region to be formatted * @param length the length of the document to be formatted * @return all character positions of the interleaving positions * @since 3.0 */ private int[] getAffectedPositions(int offset, int length) { fOverlappingPositionReferences= new ArrayList<>(); determinePositionsToUpdate(offset, length); Collections.sort(fOverlappingPositionReferences); int[] positions= new int[fOverlappingPositionReferences.size()]; for (int i= 0; i < positions.length; i++) { PositionReference r= fOverlappingPositionReferences.get(i); positions[i]= r.getCharacterPosition() - offset; } return positions; }
/** * Determines the partitioning of the given region of the document. * Informs the formatting strategies of each partition about the start, * the process, and the termination of the formatting session. * * @param region the document region to be formatted * @since 3.0 */ private void formatPartitions(IRegion region) { addPartitioningUpdater(); try { TypedPosition[] ranges= getPartitioning(region); if (ranges != null) { start(ranges, getIndentation(region.getOffset())); format(ranges); stop(ranges); } } catch (BadLocationException x) { } removePartitioningUpdater(); }
@Override public void format(IDocument document, IRegion region) { fNeedsComputation= true; fDocument= document; try { if (fIsPartitionAware) formatPartitions(region); else formatRegion(region); } finally { fNeedsComputation= true; fDocument= null; } }
/** * Fires <code>formatterStarts</code> to all formatter strategies * which will be involved in the forthcoming formatting process. * * @param regions the partitioning of the document to be formatted * @param indentation the initial indentation */ private void start(TypedPosition[] regions, String indentation) { for (TypedPosition region : regions) { IFormattingStrategy s= getFormattingStrategy(region.getType()); if (s != null) s.formatterStarts(indentation); } }
/** * Fires <code>formatterStarts</code> to all formatter strategies * which will be involved in the forthcoming formatting process. * * @param regions the partitioning of the document to be formatted * @param indentation the initial indentation */ private void start(TypedPosition[] regions, String indentation) { for (int i= 0; i < regions.length; i++) { IFormattingStrategy s= getFormattingStrategy(regions[i].getType()); if (s != null) s.formatterStarts(indentation); } }