1 19 24 25 package org.netbeans.modules.javacore.parser; 26 27 import org.netbeans.lib.java.parser.Token; 28 import org.netbeans.lib.java.parser.Factory; 29 import org.netbeans.lib.java.parser.JScanner; 30 import java.io.IOException ; 31 import java.io.InputStream ; 32 import java.io.InputStreamReader ; 33 import java.io.Reader ; 34 35 39 public class TokenIterator { 40 JScanner scanner; 41 ASTProvider provider; 42 int tokenIndex; 43 Token currentToken; 44 45 public TokenIterator(InputStream stream,String sourceLevel) { 46 this(new InputStreamReader (stream),sourceLevel); 47 } 48 49 public TokenIterator(Reader reader,String sourceLevel) { 50 this(reader, sourceLevel, false); 51 } 52 53 public TokenIterator(InputStream stream,String sourceLevel, boolean liteScan) { 54 this(new InputStreamReader (stream),sourceLevel,liteScan); 55 } 56 57 public TokenIterator(Reader reader,String sourceLevel, boolean liteScan) { 58 scanner=Factory.getDefault().getScanner(reader,sourceLevel,liteScan); 59 } 60 61 public TokenIterator(ASTProvider p) { 62 provider=p; 63 } 64 65 public int getNextTokenType() throws IOException { 66 if (scanner!=null) 67 return scanner.yylex(); 68 try { 69 currentToken=provider.getToken(tokenIndex++); 70 return currentToken != null ? currentToken.getType() : 0; 71 } catch (IndexOutOfBoundsException ex) { 72 return 0; 74 } 75 } 76 77 public String getIdentifierText() { 78 if (scanner!=null) 79 return scanner.yytext(); 80 return (String )currentToken.getValue(); 81 } 82 83 public int getIdentifierHash() { 84 if (scanner!=null) 85 return scanner.yyhash(); 86 return currentToken.getValue().hashCode(); 87 } 88 89 92 public boolean isDeprecated() { 93 if (scanner != null) { 94 boolean b = scanner.isDeprecated(); 95 scanner.resetDeprecatedFlag(); 96 return b; 97 } 98 return currentToken.getDeprecatedFlag(); 99 } 100 } 101 | Popular Tags |