1 11 package org.eclipse.jdt.internal.core.util; 12 13 import org.eclipse.jdt.internal.core.JavaElement; 14 15 public class MementoTokenizer { 16 private static final String COUNT = Character.toString(JavaElement.JEM_COUNT); 17 private static final String JAVAPROJECT = Character.toString(JavaElement.JEM_JAVAPROJECT); 18 private static final String PACKAGEFRAGMENTROOT = Character.toString(JavaElement.JEM_PACKAGEFRAGMENTROOT); 19 private static final String PACKAGEFRAGMENT = Character.toString(JavaElement.JEM_PACKAGEFRAGMENT); 20 private static final String FIELD = Character.toString(JavaElement.JEM_FIELD); 21 private static final String METHOD = Character.toString(JavaElement.JEM_METHOD); 22 private static final String INITIALIZER = Character.toString(JavaElement.JEM_INITIALIZER); 23 private static final String COMPILATIONUNIT = Character.toString(JavaElement.JEM_COMPILATIONUNIT); 24 private static final String CLASSFILE = Character.toString(JavaElement.JEM_CLASSFILE); 25 private static final String TYPE = Character.toString(JavaElement.JEM_TYPE); 26 private static final String PACKAGEDECLARATION = Character.toString(JavaElement.JEM_PACKAGEDECLARATION); 27 private static final String IMPORTDECLARATION = Character.toString(JavaElement.JEM_IMPORTDECLARATION); 28 private static final String LOCALVARIABLE = Character.toString(JavaElement.JEM_LOCALVARIABLE); 29 private static final String TYPE_PARAMETER = Character.toString(JavaElement.JEM_TYPE_PARAMETER); 30 31 private final char[] memento; 32 private final int length; 33 private int index = 0; 34 35 public MementoTokenizer(String memento) { 36 this.memento = memento.toCharArray(); 37 this.length = this.memento.length; 38 } 39 40 public boolean hasMoreTokens() { 41 return this.index < this.length; 42 } 43 44 public String nextToken() { 45 int start = this.index; 46 StringBuffer buffer = null; 47 switch (this.memento[this.index++]) { 48 case JavaElement.JEM_ESCAPE: 49 buffer = new StringBuffer (); 50 buffer.append(this.memento[this.index]); 51 start = ++this.index; 52 break; 53 case JavaElement.JEM_COUNT: 54 return COUNT; 55 case JavaElement.JEM_JAVAPROJECT: 56 return JAVAPROJECT; 57 case JavaElement.JEM_PACKAGEFRAGMENTROOT: 58 return PACKAGEFRAGMENTROOT; 59 case JavaElement.JEM_PACKAGEFRAGMENT: 60 return PACKAGEFRAGMENT; 61 case JavaElement.JEM_FIELD: 62 return FIELD; 63 case JavaElement.JEM_METHOD: 64 return METHOD; 65 case JavaElement.JEM_INITIALIZER: 66 return INITIALIZER; 67 case JavaElement.JEM_COMPILATIONUNIT: 68 return COMPILATIONUNIT; 69 case JavaElement.JEM_CLASSFILE: 70 return CLASSFILE; 71 case JavaElement.JEM_TYPE: 72 return TYPE; 73 case JavaElement.JEM_PACKAGEDECLARATION: 74 return PACKAGEDECLARATION; 75 case JavaElement.JEM_IMPORTDECLARATION: 76 return IMPORTDECLARATION; 77 case JavaElement.JEM_LOCALVARIABLE: 78 return LOCALVARIABLE; 79 case JavaElement.JEM_TYPE_PARAMETER: 80 return TYPE_PARAMETER; 81 } 82 loop: while (this.index < this.length) { 83 switch (this.memento[this.index]) { 84 case JavaElement.JEM_ESCAPE: 85 if (buffer == null) buffer = new StringBuffer (); 86 buffer.append(this.memento, start, this.index - start); 87 start = ++this.index; 88 break; 89 case JavaElement.JEM_COUNT: 90 case JavaElement.JEM_JAVAPROJECT: 91 case JavaElement.JEM_PACKAGEFRAGMENTROOT: 92 case JavaElement.JEM_PACKAGEFRAGMENT: 93 case JavaElement.JEM_FIELD: 94 case JavaElement.JEM_METHOD: 95 case JavaElement.JEM_INITIALIZER: 96 case JavaElement.JEM_COMPILATIONUNIT: 97 case JavaElement.JEM_CLASSFILE: 98 case JavaElement.JEM_TYPE: 99 case JavaElement.JEM_PACKAGEDECLARATION: 100 case JavaElement.JEM_IMPORTDECLARATION: 101 case JavaElement.JEM_LOCALVARIABLE: 102 case JavaElement.JEM_TYPE_PARAMETER: 103 break loop; 104 } 105 this.index++; 106 } 107 if (buffer != null) { 108 buffer.append(this.memento, start, this.index - start); 109 return buffer.toString(); 110 } else { 111 return new String (this.memento, start, this.index - start); 112 } 113 } 114 115 } 116 | Popular Tags |