1 11 12 package org.eclipse.jface.text.rules; 13 14 import org.eclipse.core.runtime.Assert; 15 16 17 20 public class NumberRule implements IRule { 21 22 23 protected static final int UNDEFINED= -1; 24 25 protected IToken fToken; 26 27 protected int fColumn= UNDEFINED; 28 29 35 public NumberRule(IToken token) { 36 Assert.isNotNull(token); 37 fToken= token; 38 } 39 40 48 public void setColumnConstraint(int column) { 49 if (column < 0) 50 column= UNDEFINED; 51 fColumn= column; 52 } 53 54 57 public IToken evaluate(ICharacterScanner scanner) { 58 int c= scanner.read(); 59 if (Character.isDigit((char)c)) { 60 if (fColumn == UNDEFINED || (fColumn == scanner.getColumn() - 1)) { 61 do { 62 c= scanner.read(); 63 } while (Character.isDigit((char) c)); 64 scanner.unread(); 65 return fToken; 66 } 67 } 68 69 scanner.unread(); 70 return Token.UNDEFINED; 71 } 72 } 73 | Popular Tags |