diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/CCodeScanner.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/CCodeScanner.java index 00b88130dc4..f21db72d873 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/CCodeScanner.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/CCodeScanner.java @@ -20,6 +20,7 @@ import org.eclipse.jface.text.rules.IWordDetector; import org.eclipse.jface.text.rules.PatternRule; import org.eclipse.jface.text.rules.SingleLineRule; import org.eclipse.jface.text.rules.Token; +import org.eclipse.jface.text.rules.WordRule; import org.eclipse.jface.util.Assert; import org.eclipse.jface.util.PropertyChangeEvent; @@ -29,115 +30,6 @@ import org.eclipse.jface.util.PropertyChangeEvent; */ public final class CCodeScanner extends AbstractCScanner { - private class CWordRule implements IRule { - - protected static final int UNDEFINED= -1; - - /** The word detector used by this rule */ - protected IWordDetector fDetector; - /** The default token to be returned on success and if nothing else has been specified. */ - protected IToken fDefaultToken; - /** The column constraint */ - protected int fColumn= UNDEFINED; - /** The table of predefined words and token for this rule */ - protected Map fWords= new HashMap(); - - private StringBuffer fBuffer= new StringBuffer(); - - /** - * Creates a rule which, with the help of an word detector, will return the token - * associated with the detected word. If no token has been associated, the scanner - * will be rolled back and an undefined token will be returned in order to allow - * any subsequent rules to analyze the characters. - * - * @param detector the word detector to be used by this rule, may not be null - * - * @see #addWord - */ - public CWordRule(IWordDetector detector) { - this(detector, Token.UNDEFINED); - } - /** - * Creates a rule which, with the help of an word detector, will return the token - * associated with the detected word. If no token has been associated, the - * specified default token will be returned. - * - * @param detector the word detector to be used by this rule, may not be null - * @param defaultToken the default token to be returned on success - * if nothing else is specified, may not be null - * - * @see #addWord - */ - public CWordRule(IWordDetector detector, IToken defaultToken) { - - Assert.isNotNull(detector); - Assert.isNotNull(defaultToken); - - fDetector= detector; - fDefaultToken= defaultToken; - } - /** - * Adds a word and the token to be returned if it is detected. - * - * @param word the word this rule will search for, may not be null - * @param token the token to be returned if the word has been found, may not be null - */ - public void addWord(String word, IToken token) { - Assert.isNotNull(word); - Assert.isNotNull(token); - - fWords.put(word, token); - } - /* - * @see IRule#evaluate - */ - public IToken evaluate(ICharacterScanner scanner) { - - int c= scanner.read(); - if (Character.isJavaIdentifierStart((char) c) || (c == '#' && scanner.getColumn() == 1)) { - fBuffer.setLength(0); - do { - fBuffer.append((char) c); - c= scanner.read(); - } while (Character.isJavaIdentifierPart((char) c)); - scanner.unread(); - - IToken token= (IToken) fWords.get(fBuffer.toString()); - if (token != null) - return token; - - //if (fDefaultToken.isUndefined()) - // unreadBuffer(scanner); - - return fDefaultToken; - } - - scanner.unread(); - return Token.UNDEFINED; - } - /** - * Sets a column constraint for this rule. If set, the rule's token - * will only be returned if the pattern is detected starting at the - * specified column. If the column is smaller then 0, the column - * constraint is considered removed. - * - * @param column the column in which the pattern starts - */ - public void setColumnConstraint(int column) { - if (column < 0) - column= UNDEFINED; - fColumn= column; - } - /** - * Returns the characters in the buffer to the scanner. - * - * @param scanner the scanner to be used - */ - protected void unreadBuffer(ICharacterScanner scanner) { - for (int i= fBuffer.length() - 1; i >= 0; i--) - scanner.unread(); - } - }; private static String[] fgKeywords= { "asm", "auto", @@ -198,7 +90,6 @@ public final class CCodeScanner extends AbstractCScanner { // Add rule for strings and character constants. rules.add(new SingleLineRule("'", "'", token, '\\')); - // Add generic whitespace rule. //rules.add(new WhitespaceRule(new CWhitespaceDetector())); @@ -206,7 +97,7 @@ public final class CCodeScanner extends AbstractCScanner { // Add word rule for keywords, types, and constants. token= getToken(ICColorConstants.C_DEFAULT); - CWordRule wordRule= new CWordRule(new CWordDetector(), token); + WordRule wordRule= new WordRule(new CWordDetector(), token); token= getToken(ICColorConstants.C_KEYWORD); for (int i=0; i