1 19 20 package org.netbeans.editor; 21 22 27 28 29 public class AcceptorFactory { 30 31 public static final Acceptor TRUE = new Fixed(true); 32 33 public static final Acceptor FALSE = new Fixed(false); 34 35 public static final Acceptor NL = new Char('\n'); 36 37 public static final Acceptor SPACE_NL = new TwoChar(' ', '\n'); 38 39 public static final Acceptor WHITESPACE 40 = new Acceptor() { 41 public final boolean accept(char ch) { 42 return Character.isWhitespace(ch); 43 } 44 }; 45 46 public static final Acceptor LETTER_DIGIT 47 = new Acceptor() { 48 public final boolean accept(char ch) { 49 return Character.isLetterOrDigit(ch); 50 } 51 }; 52 53 public static final Acceptor JAVA_IDENTIFIER 54 = new Acceptor() { 55 public final boolean accept(char ch) { 56 return Character.isJavaIdentifierPart(ch); 57 } 58 }; 59 60 public static final Acceptor NON_JAVA_IDENTIFIER 61 = new Acceptor() { 62 public final boolean accept(char ch) { 63 return !Character.isJavaIdentifierPart(ch); 64 } 65 }; 66 67 private static final class Fixed implements Acceptor { 68 private boolean state; 69 70 public Fixed(boolean state) { 71 this.state = state; 72 } 73 74 public final boolean accept(char ch) { 75 return state; 76 } 77 } 78 79 private static final class Char implements Acceptor { 80 private char hit; 81 82 public Char(char hit) { 83 this.hit = hit; 84 } 85 86 public final boolean accept(char ch) { 87 return ch == hit; 88 } 89 } 90 91 private static final class TwoChar implements Acceptor { 92 private char hit1, hit2; 93 94 public TwoChar(char hit1, char hit2) { 95 this.hit1 = hit1; 96 this.hit2 = hit2; 97 } 98 99 public final boolean accept(char ch) { 100 return ch == hit1 || ch == hit2; 101 } 102 } 103 104 105 } 106 | Popular Tags |