TokenMap tokenMap = new TokenMap(true); // Ignore case. int reservedWord = Token.RESERVED_WORD; tokenMap.put("goto", reservedWord); tokenMap.put("if", reservedWord); tokenMap.put("shift", reservedWord); tokenMap.put("start", reservedWord); tokenMap.put("ansi.sys", reservedWord); tokenMap.put("append", reservedWord); tokenMap.put("arp", reservedWord); tokenMap.put("assign", reservedWord); tokenMap.put("assoc", reservedWord); tokenMap.put("at", reservedWord); tokenMap.put("attrib", reservedWord); tokenMap.put("break", reservedWord); tokenMap.put("cacls", reservedWord); tokenMap.put("call", reservedWord); tokenMap.put("cd", reservedWord); tokenMap.put("chcp", reservedWord); tokenMap.put("chdir", reservedWord); tokenMap.put("chkdsk", reservedWord); tokenMap.put("chknfts", reservedWord); tokenMap.put("choice", reservedWord); tokenMap.put("cls", reservedWord); tokenMap.put("cmd", reservedWord); tokenMap.put("color", reservedWord); tokenMap.put("comp", reservedWord); tokenMap.put("compact", reservedWord);
/** * Returns the token type associated with the given text, if the given * text is in this token map. If it isn't, <code>-1</code> is returned. * * @param text The segment from which to get the text to compare. * @param start The starting index in the segment of the text. * @param end The ending index in the segment of the text. * @return The token type associated with the given text, or * <code>-1</code> if this token was not specified in this map. */ public int get(Segment text, int start, int end) { return get(text.array, start, end); }
/** * Adds a string to this token map. The char array passed-in will be used * as the actual data for the token, so it may well be modified (such as * lower-casing it if <code>ignoreCase</code> is <code>true</code>). This * shouldn't be an issue though as this method is only called from the * public <code>put</code> method, which allocates a new char array. * * @param string The string to add. * @param tokenType The type of token the string is. */ private void put(char[] string, int tokenType) { int hashCode = getHashCode(string, 0, string.length); addTokenToBucket(hashCode, new TokenMapToken(string, tokenType)); }
/** * Adds a string to this token map. * * @param string The string to add. * @param tokenType The type of token the string is. */ public void put(final String string, final int tokenType) { if (isIgnoringCase()) { put(string.toLowerCase().toCharArray(), tokenType); } else { put(string.toCharArray(), tokenType); } }
int hash = getHashCode(array1, start, length1); TokenMapToken token = tokenMap[hash];
/** * Adds a string to this token map. * * @param string The string to add. * @param tokenType The type of token the string is. */ public void put(final String string, final int tokenType) { if (isIgnoringCase()) put(string.toLowerCase().toCharArray(), tokenType); else put(string.toCharArray(), tokenType); }
int hash = getHashCode(array1, start, length1); TokenMapToken token = tokenMap[hash];
TokenMap tokenMap = new TokenMap(); tokenMap.put("case", reservedWord); tokenMap.put("do", reservedWord); tokenMap.put("done", reservedWord); tokenMap.put("elif", reservedWord); tokenMap.put("else", reservedWord); tokenMap.put("esac", reservedWord); tokenMap.put("fi", reservedWord); tokenMap.put("for", reservedWord); tokenMap.put("if", reservedWord); tokenMap.put("in", reservedWord); tokenMap.put("select", reservedWord); tokenMap.put("then", reservedWord); tokenMap.put("until", reservedWord); tokenMap.put("while", reservedWord); tokenMap.put("addbib", function); tokenMap.put("admin", function); tokenMap.put("alias", function); tokenMap.put("apropos", function); tokenMap.put("ar", function); tokenMap.put("at", function); tokenMap.put("awk", function); tokenMap.put("banner", function); tokenMap.put("basename", function); tokenMap.put("batch", function); tokenMap.put("bg", function); tokenMap.put("biff", function);
/** * Checks the token to give it the exact ID it deserves before * being passed up to the super method. * * @param segment <code>Segment</code> to get text from. * @param start Start offset in <code>segment</code> of token. * @param end End offset in <code>segment</code> of token. * @param tokenType The token's type. * @param startOffset The offset in the document at which the token occurs. */ @Override public void addToken(Segment segment, int start, int end, int tokenType, int startOffset) { switch (tokenType) { // Since reserved words, functions, and data types are all passed // into here as "identifiers," we have to see what the token // really is... case Token.IDENTIFIER: int value = wordsToHighlight.get(segment, start,end); if (value!=-1) tokenType = value; break; } super.addToken(segment, start, end, tokenType, startOffset); }
/** * Adds a string to this token map. * * @param string The string to add. * @param tokenType The type of token the string is. */ public void put(final String string, final int tokenType) { if (isIgnoringCase()) put(string.toLowerCase().toCharArray(), tokenType); else put(string.toCharArray(), tokenType); }
/** * Adds a string to this token map. The char array passed-in will be used * as the actual data for the token, so it may well be modified (such as * lower-casing it if <code>ignoreCase</code> is <code>true</code>). This * shouldn't be an issue though as this method is only called from the * public <code>put</code> method, which allocates a new char array. * * @param string The string to add. * @param tokenType The type of token the string is. */ private void put(char[] string, int tokenType) { int hashCode = getHashCode(string, 0, string.length); addTokenToBucket(hashCode, new TokenMapToken(string, tokenType)); }
int hash = getHashCode(array1, start, length1); TokenMapToken token = tokenMap[hash];
TokenMap tokenMap = new TokenMap(52); tokenMap.put("abstract", reservedWord); tokenMap.put("as", reservedWord); tokenMap.put("break", reservedWord); tokenMap.put("case", reservedWord); tokenMap.put("catch", reservedWord); tokenMap.put("class", reservedWord); tokenMap.put("const", reservedWord); tokenMap.put("continue", reservedWord); tokenMap.put("debugger", reservedWord); tokenMap.put("default", reservedWord); tokenMap.put("delete", reservedWord); tokenMap.put("do", reservedWord); tokenMap.put("else", reservedWord); tokenMap.put("enum", reservedWord); tokenMap.put("export", reservedWord); tokenMap.put("extends", reservedWord); tokenMap.put("final", reservedWord); tokenMap.put("finally", reservedWord); tokenMap.put("for", reservedWord); tokenMap.put("function", reservedWord); tokenMap.put("goto", reservedWord); tokenMap.put("if", reservedWord); tokenMap.put("implements", reservedWord); tokenMap.put("import", reservedWord); tokenMap.put("in", reservedWord); tokenMap.put("instanceof", reservedWord); tokenMap.put("interface", reservedWord);
int value = wordsToHighlight.get(segment, start,end); if (value!=-1) tokenType = value;
/** * Adds a string to this token map. * * @param string The string to add. * @param tokenType The type of token the string is. */ public void put(final String string, final int tokenType) { if (isIgnoringCase()) { put(string.toLowerCase().toCharArray(), tokenType); } else { put(string.toCharArray(), tokenType); } }
/** * Adds a string to this token map. The char array passed-in will be used * as the actual data for the token, so it may well be modified (such as * lower-casing it if <code>ignoreCase</code> is <code>true</code>). This * shouldn't be an issue though as this method is only called from the * public <code>put</code> method, which allocates a new char array. * * @param string The string to add. * @param tokenType The type of token the string is. */ private void put(char[] string, int tokenType) { int hashCode = getHashCode(string, 0, string.length); addTokenToBucket(hashCode, new TokenMapToken(string, tokenType)); }
int hash = getHashCode(array1, start, length1); TokenMapToken token = tokenMap[hash];
TokenMap tokenMap = new TokenMap(52); tokenMap.put("abstract", reservedWord); tokenMap.put("as", reservedWord); tokenMap.put("break", reservedWord); tokenMap.put("case", reservedWord); tokenMap.put("catch", reservedWord); tokenMap.put("class", reservedWord); tokenMap.put("const", reservedWord); tokenMap.put("continue", reservedWord); tokenMap.put("debugger", reservedWord); tokenMap.put("default", reservedWord); tokenMap.put("delete", reservedWord); tokenMap.put("do", reservedWord); tokenMap.put("else", reservedWord); tokenMap.put("enum", reservedWord); tokenMap.put("export", reservedWord); tokenMap.put("extends", reservedWord); tokenMap.put("final", reservedWord); tokenMap.put("finally", reservedWord); tokenMap.put("for", reservedWord); tokenMap.put("function", reservedWord); tokenMap.put("goto", reservedWord); tokenMap.put("if", reservedWord); tokenMap.put("implements", reservedWord); tokenMap.put("import", reservedWord); tokenMap.put("in", reservedWord); tokenMap.put("instanceof", reservedWord); tokenMap.put("interface", reservedWord);
/** * Checks for a token in a token map, and makes sure it is mapped to the * expected token type. * * @param tm The token map. * @param token The token. * @param tokenType The expected token type. */ private void assertTokenMapContains(TokenMap tm, String token, int tokenType) { int actualType = tm.get(token.toCharArray(), 0, token.length() - 1); Assert.assertEquals("Token mapped to unexpected type: " + token, tokenType, actualType); }
/** * Adds a string to this token map. The char array passed-in will be used * as the actual data for the token, so it may well be modified (such as * lower-casing it if <code>ignoreCase</code> is <code>true</code>). This * shouldn't be an issue though as this method is only called from the * public <code>put</code> method, which allocates a new char array. * * @param string The string to add. * @param tokenType The type of token the string is. */ private void put(char[] string, int tokenType) { int hashCode = getHashCode(string, 0, string.length); addTokenToBucket(hashCode, new TokenMapToken(string, tokenType)); }