1 11 package org.eclipse.pde.internal.ui.editor.text; 12 13 import org.eclipse.jface.text.rules.ICharacterScanner; 14 import org.eclipse.jface.text.rules.IToken; 15 import org.eclipse.jface.text.rules.IWordDetector; 16 import org.eclipse.jface.text.rules.WordPatternRule; 17 18 public class ArgumentRule extends WordPatternRule { 19 20 21 private static class ArgumentDetector implements IWordDetector { 22 23 26 public boolean isWordStart(char c) { 27 return '{' == c; 28 } 29 30 33 public boolean isWordPart(char c) { 34 return c == '}' || Character.isDigit(c); 35 } 36 } 37 38 39 private int fCount= 0; 40 41 46 public ArgumentRule(IToken token) { 47 super(new ArgumentDetector(), "{", "}", token); } 49 50 53 protected boolean endSequenceDetected(ICharacterScanner scanner) { 54 fCount++; 55 56 if (scanner.read() == '}') 57 return fCount > 2; 58 59 scanner.unread(); 60 return super.endSequenceDetected(scanner); 61 } 62 63 66 protected boolean sequenceDetected(ICharacterScanner scanner, char[] sequence, boolean eofAllowed) { 67 fCount= 0; 68 return super.sequenceDetected(scanner, sequence, eofAllowed); 69 } 70 } 71 | Popular Tags |