Mercurial > projects > dwt-addons
comparison dwtx/jface/text/rules/FastPartitioner.d @ 162:1a5b8f8129df
...
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Mon, 08 Sep 2008 00:51:37 +0200 |
parents | 3678e4f1a766 |
children | eb98a5cbfd78 |
comparison
equal
deleted
inserted
replaced
161:f8d52b926852 | 162:1a5b8f8129df |
---|---|
35 import dwtx.jface.text.rules.RuleBasedPartitioner; // packageimport | 35 import dwtx.jface.text.rules.RuleBasedPartitioner; // packageimport |
36 import dwtx.jface.text.rules.RuleBasedPartitionScanner; // packageimport | 36 import dwtx.jface.text.rules.RuleBasedPartitionScanner; // packageimport |
37 import dwtx.jface.text.rules.BufferedRuleBasedScanner; // packageimport | 37 import dwtx.jface.text.rules.BufferedRuleBasedScanner; // packageimport |
38 import dwtx.jface.text.rules.IWhitespaceDetector; // packageimport | 38 import dwtx.jface.text.rules.IWhitespaceDetector; // packageimport |
39 | 39 |
40 | |
41 import dwt.dwthelper.utils; | 40 import dwt.dwthelper.utils; |
42 | |
43 | |
44 import dwtx.dwtxhelper.Collection; | 41 import dwtx.dwtxhelper.Collection; |
45 | 42 import tango.text.convert.Format; |
46 | 43 |
47 import dwtx.core.runtime.Assert; | 44 import dwtx.core.runtime.Assert; |
48 import dwtx.core.runtime.Platform; | 45 import dwtx.core.runtime.Platform; |
49 import dwtx.jface.text.BadLocationException; | 46 import dwtx.jface.text.BadLocationException; |
50 import dwtx.jface.text.BadPositionCategoryException; | 47 import dwtx.jface.text.BadPositionCategoryException; |
122 * The cached positions from our document, so we don't create a new array every time | 119 * The cached positions from our document, so we don't create a new array every time |
123 * someone requests partition information. | 120 * someone requests partition information. |
124 */ | 121 */ |
125 private Position[] fCachedPositions= null; | 122 private Position[] fCachedPositions= null; |
126 /** Debug option for cache consistency checking. */ | 123 /** Debug option for cache consistency checking. */ |
127 private static const bool CHECK_CACHE_CONSISTENCY= "true".equalsIgnoreCase(Platform.getDebugOption("dwtx.jface.text/debug/FastPartitioner/PositionCache")); //$NON-NLS-1$//$NON-NLS-2$; | 124 private static bool CHECK_CACHE_CONSISTENCY_; |
125 private static bool CHECK_CACHE_CONSISTENCY_init; | |
126 private static bool CHECK_CACHE_CONSISTENCY(){ | |
127 if( !CHECK_CACHE_CONSISTENCY_init ){ | |
128 synchronized(FastPartitioner.classinfo ){ | |
129 if( !CHECK_CACHE_CONSISTENCY_init ){ | |
130 CHECK_CACHE_CONSISTENCY_init = true; | |
131 CHECK_CACHE_CONSISTENCY_ = "true".equalsIgnoreCase(Platform.getDebugOption("dwtx.jface.text/debug/FastPartitioner/PositionCache")); //$NON-NLS-1$//$NON-NLS-2$; | |
132 } | |
133 } | |
134 } | |
135 return CHECK_CACHE_CONSISTENCY_; | |
136 } | |
128 | 137 |
129 /** | 138 /** |
130 * Creates a new partitioner that uses the given scanner and may return | 139 * Creates a new partitioner that uses the given scanner and may return |
131 * partitions of the given legal content types. | 140 * partitions of the given legal content types. |
132 * | 141 * |
134 * @param legalContentTypes the legal content types of this partitioner | 143 * @param legalContentTypes the legal content types of this partitioner |
135 */ | 144 */ |
136 public this(IPartitionTokenScanner scanner, String[] legalContentTypes) { | 145 public this(IPartitionTokenScanner scanner, String[] legalContentTypes) { |
137 fScanner= scanner; | 146 fScanner= scanner; |
138 fLegalContentTypes= TextUtilities.copy(legalContentTypes); | 147 fLegalContentTypes= TextUtilities.copy(legalContentTypes); |
139 fPositionCategory= CONTENT_TYPES_CATEGORY + toHash(); | 148 fPositionCategory= CONTENT_TYPES_CATEGORY ~ Integer.toString(toHash()); |
140 fPositionUpdater= new DefaultPositionUpdater(fPositionCategory); | 149 fPositionUpdater= new DefaultPositionUpdater(fPositionCategory); |
141 } | 150 } |
142 | 151 |
143 /* | 152 /* |
144 * @see dwtx.jface.text.IDocumentPartitionerExtension2#getManagingPositionCategories() | 153 * @see dwtx.jface.text.IDocumentPartitionerExtension2#getManagingPositionCategories() |
159 * <p> | 168 * <p> |
160 * May be extended by subclasses. | 169 * May be extended by subclasses. |
161 * </p> | 170 * </p> |
162 */ | 171 */ |
163 public void connect(IDocument document, bool delayInitialization) { | 172 public void connect(IDocument document, bool delayInitialization) { |
164 Assert.isNotNull(document); | 173 Assert.isNotNull(cast(Object)document); |
165 Assert.isTrue(!document.containsPositionCategory(fPositionCategory)); | 174 Assert.isTrue(!document.containsPositionCategory(fPositionCategory)); |
166 | 175 |
167 fDocument= document; | 176 fDocument= document; |
168 fDocument.addPositionCategory(fPositionCategory); | 177 fDocument.addPositionCategory(fPositionCategory); |
169 | 178 |
592 * @param token the token whose content type is to be determined | 601 * @param token the token whose content type is to be determined |
593 * @return the token's content type | 602 * @return the token's content type |
594 */ | 603 */ |
595 protected String getTokenContentType(IToken token) { | 604 protected String getTokenContentType(IToken token) { |
596 Object data= token.getData(); | 605 Object data= token.getData(); |
597 if ( cast(String)data ) | 606 if ( auto str = cast(ArrayWrapperString)data ) |
598 return cast(String) data; | 607 return str.array; |
599 return null; | 608 return null; |
600 } | 609 } |
601 | 610 |
602 /* zero-length partition support */ | 611 /* zero-length partition support */ |
603 | 612 |
699 // Make sure we clear the cache | 708 // Make sure we clear the cache |
700 clearPositionCache(); | 709 clearPositionCache(); |
701 throw ex; | 710 throw ex; |
702 } | 711 } |
703 | 712 |
704 TypedRegion[] result= new TypedRegion[list.size()]; | 713 return arraycast!(ITypedRegion)(list.toArray()); |
705 list.toArray(result); | |
706 return result; | |
707 } | 714 } |
708 | 715 |
709 /** | 716 /** |
710 * Returns <code>true</code> if the given ranges overlap with or touch each other. | 717 * Returns <code>true</code> if the given ranges overlap with or touch each other. |
711 * | 718 * |
826 fCachedPositions= fDocument.getPositions(fPositionCategory); | 833 fCachedPositions= fDocument.getPositions(fPositionCategory); |
827 } else if (CHECK_CACHE_CONSISTENCY) { | 834 } else if (CHECK_CACHE_CONSISTENCY) { |
828 Position[] positions= fDocument.getPositions(fPositionCategory); | 835 Position[] positions= fDocument.getPositions(fPositionCategory); |
829 int len= Math.min(positions.length, fCachedPositions.length); | 836 int len= Math.min(positions.length, fCachedPositions.length); |
830 for (int i= 0; i < len; i++) { | 837 for (int i= 0; i < len; i++) { |
831 if (!positions[i].equals(fCachedPositions[i])) | 838 if (!positions[i].opEquals(fCachedPositions[i])) |
832 System.err.println("FastPartitioner.getPositions(): cached position is not up to date: from document: " + toString(positions[i]) + " in cache: " + toString(fCachedPositions[i])); //$NON-NLS-1$ //$NON-NLS-2$ | 839 System.err.println(Format("FastPartitioner.getPositions(): cached position is not up to date: from document: {} in cache: {}", toString(positions[i]), toString(fCachedPositions[i]))); //$NON-NLS-1$ //$NON-NLS-2$ |
833 } | 840 } |
834 for (int i= len; i < positions.length; i++) | 841 for (int i= len; i < positions.length; i++) |
835 System.err.println("FastPartitioner.getPositions(): new position in document: " + toString(positions[i])); //$NON-NLS-1$ | 842 System.err.println(Format("FastPartitioner.getPositions(): new position in document: {}", toString(positions[i]))); //$NON-NLS-1$ |
836 for (int i= len; i < fCachedPositions.length; i++) | 843 for (int i= len; i < fCachedPositions.length; i++) |
837 System.err.println("FastPartitioner.getPositions(): stale position in cache: " + toString(fCachedPositions[i])); //$NON-NLS-1$ | 844 System.err.println(Format("FastPartitioner.getPositions(): stale position in cache: {}", toString(fCachedPositions[i]))); //$NON-NLS-1$ |
838 } | 845 } |
839 return fCachedPositions; | 846 return fCachedPositions; |
840 } | 847 } |
841 | 848 |
842 /** | 849 /** |
844 * | 851 * |
845 * @param position the position to format | 852 * @param position the position to format |
846 * @return a formatted string | 853 * @return a formatted string |
847 */ | 854 */ |
848 private override String toString(Position position) { | 855 private override String toString(Position position) { |
849 return "P[" + position.getOffset() + "+" + position.getLength() + "]"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ | 856 return Format("P[{}+{}]", position.getOffset(), position.getLength() ); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ |
850 } | 857 } |
851 } | 858 } |