1 11 12 package org.eclipse.jface.text.rules; 13 14 15 import org.eclipse.jface.text.IDocument; 16 17 18 22 public class RuleBasedPartitionScanner extends BufferedRuleBasedScanner implements IPartitionTokenScanner { 23 24 25 protected String fContentType; 26 27 protected int fPartitionOffset; 28 29 30 36 public void setRules(IRule[] rules) { 37 throw new UnsupportedOperationException (); 38 } 39 40 43 public void setPredicateRules(IPredicateRule[] rules) { 44 super.setRules(rules); 45 } 46 47 50 public void setRange(IDocument document, int offset, int length) { 51 setPartialRange(document, offset, length, null, -1); 52 } 53 54 57 public void setPartialRange(IDocument document, int offset, int length, String contentType, int partitionOffset) { 58 fContentType= contentType; 59 fPartitionOffset= partitionOffset; 60 if (partitionOffset > -1) { 61 int delta= offset - partitionOffset; 62 if (delta > 0) { 63 super.setRange(document, partitionOffset, length + delta); 64 fOffset= offset; 65 return; 66 } 67 } 68 super.setRange(document, offset, length); 69 } 70 71 74 public IToken nextToken() { 75 76 77 if (fContentType == null || fRules == null) { 78 return super.nextToken(); 80 } 81 82 84 fColumn= UNDEFINED; 85 boolean resume= (fPartitionOffset > -1 && fPartitionOffset < fOffset); 86 fTokenOffset= resume ? fPartitionOffset : fOffset; 87 88 IPredicateRule rule; 89 IToken token; 90 91 for (int i= 0; i < fRules.length; i++) { 92 rule= (IPredicateRule) fRules[i]; 93 token= rule.getSuccessToken(); 94 if (fContentType.equals(token.getData())) { 95 token= rule.evaluate(this, resume); 96 if (!token.isUndefined()) { 97 fContentType= null; 98 return token; 99 } 100 } 101 } 102 103 fContentType= null; 105 if (resume) 106 fOffset= fPartitionOffset; 107 return super.nextToken(); 108 } 109 } 110 | Popular Tags |