1 11 package org.eclipse.jdt.internal.ui.propertiesfileeditor; 12 13 import java.util.ArrayList ; 14 import java.util.List ; 15 16 import org.eclipse.jface.text.IDocument; 17 import org.eclipse.jface.text.rules.EndOfLineRule; 18 import org.eclipse.jface.text.rules.ICharacterScanner; 19 import org.eclipse.jface.text.rules.IPredicateRule; 20 import org.eclipse.jface.text.rules.IToken; 21 import org.eclipse.jface.text.rules.IWordDetector; 22 import org.eclipse.jface.text.rules.RuleBasedPartitionScanner; 23 import org.eclipse.jface.text.rules.SingleLineRule; 24 import org.eclipse.jface.text.rules.Token; 25 import org.eclipse.jface.text.rules.WordRule; 26 27 32 public class PropertiesFilePartitionScanner extends RuleBasedPartitionScanner implements IPropertiesFilePartitions { 33 34 37 static class EmptyCommentDetector implements IWordDetector { 38 39 42 public boolean isWordStart(char c) { 43 return (c == '#'); 44 } 45 46 49 public boolean isWordPart(char c) { 50 return (c == '#'); 51 } 52 } 53 54 55 58 static class EmptyCommentRule extends WordRule implements IPredicateRule { 59 60 private IToken fSuccessToken; 61 65 public EmptyCommentRule(IToken successToken) { 66 super(new EmptyCommentDetector()); 67 fSuccessToken= successToken; 68 addWord("#", fSuccessToken); } 70 71 74 public IToken evaluate(ICharacterScanner scanner, boolean resume) { 75 return evaluate(scanner); 76 } 77 78 81 public IToken getSuccessToken() { 82 return fSuccessToken; 83 } 84 } 85 86 87 90 public PropertiesFilePartitionScanner() { 91 super(); 92 93 IToken comment= new Token(COMMENT); 94 IToken propertyValue= new Token(PROPERTY_VALUE); 95 IToken key= new Token(IDocument.DEFAULT_CONTENT_TYPE); 96 97 List rules= new ArrayList (); 98 99 rules.add(new LeadingWhitespacePredicateRule(key, "\t")); rules.add(new LeadingWhitespacePredicateRule(key, " ")); 103 rules.add(new EndOfLineRule("#", comment, (char) 0, true)); rules.add(new EndOfLineRule("!", comment, (char) 0, true)); 107 rules.add(new SingleLineRule("=", null, propertyValue, '\\', true, true)); rules.add(new SingleLineRule(":", null, propertyValue, '\\', true, true)); rules.add(new SingleLineRule(" ", null, propertyValue, '\\', true, true)); rules.add(new SingleLineRule("\t", null, propertyValue, '\\', true, true)); 113 EmptyCommentRule wordRule= new EmptyCommentRule(comment); 115 rules.add(wordRule); 116 117 IPredicateRule[] result= new IPredicateRule[rules.size()]; 118 rules.toArray(result); 119 setPredicateRules(result); 120 } 121 } 122 | Popular Tags |