1 11 12 package org.eclipse.jdt.internal.ui.propertiesfileeditor; 13 14 import java.util.ArrayList ; 15 import java.util.List ; 16 17 import org.eclipse.jface.preference.IPreferenceStore; 18 19 import org.eclipse.jface.text.BadLocationException; 20 import org.eclipse.jface.text.IRegion; 21 import org.eclipse.jface.text.rules.IToken; 22 import org.eclipse.jface.text.rules.IWordDetector; 23 import org.eclipse.jface.text.rules.WhitespaceRule; 24 import org.eclipse.jface.text.rules.WordRule; 25 26 import org.eclipse.jdt.ui.PreferenceConstants; 27 import org.eclipse.jdt.ui.text.IColorManager; 28 29 import org.eclipse.jdt.internal.ui.text.AbstractJavaScanner; 30 import org.eclipse.jdt.internal.ui.text.JavaWhitespaceDetector; 31 32 33 38 public final class PropertyValueScanner extends AbstractJavaScanner { 39 40 public class AssignmentDetector implements IWordDetector { 41 42 45 public boolean isWordStart(char c) { 46 if ('=' != c && ':' != c || fDocument == null) 47 return false; 48 49 try { 50 IRegion lineInfo= fDocument.getLineInformationOfOffset(fOffset); 52 int offset= lineInfo.getOffset(); 53 String line= fDocument.get(offset, lineInfo.getLength()); 54 int i= line.indexOf(c); 55 return i != -1 && i + lineInfo.getOffset() + 1 == fOffset; 56 } catch (BadLocationException ex) { 57 return false; 58 } 59 } 60 61 64 public boolean isWordPart(char c) { 65 return false; 66 } 67 } 68 69 70 private static String [] fgTokenProperties= { 71 PreferenceConstants.PROPERTIES_FILE_COLORING_VALUE, 72 PreferenceConstants.PROPERTIES_FILE_COLORING_ARGUMENT, 73 PreferenceConstants.PROPERTIES_FILE_COLORING_ASSIGNMENT 74 }; 75 76 77 83 public PropertyValueScanner(IColorManager manager, IPreferenceStore store) { 84 super(manager, store); 85 initialize(); 86 } 87 88 91 protected String [] getTokenProperties() { 92 return fgTokenProperties; 93 } 94 95 98 protected List createRules() { 99 setDefaultReturnToken(getToken(PreferenceConstants.PROPERTIES_FILE_COLORING_VALUE)); 100 List rules= new ArrayList (); 101 102 IToken token= getToken(PreferenceConstants.PROPERTIES_FILE_COLORING_ARGUMENT); 104 rules.add(new ArgumentRule(token)); 105 106 token= getToken(PreferenceConstants.PROPERTIES_FILE_COLORING_ASSIGNMENT); 108 WordRule wordRule= new WordRule(new AssignmentDetector(), token); 109 rules.add(wordRule); 110 111 rules.add(new WhitespaceRule(new JavaWhitespaceDetector())); 113 114 return rules; 115 } 116 } 117 | Popular Tags |