1 11 package org.eclipse.jdt.internal.ui.text; 12 13 14 import java.util.ArrayList ; 15 import java.util.List ; 16 17 import org.eclipse.jface.text.rules.EndOfLineRule; 18 import org.eclipse.jface.text.rules.ICharacterScanner; 19 import org.eclipse.jface.text.rules.IPredicateRule; 20 import org.eclipse.jface.text.rules.IToken; 21 import org.eclipse.jface.text.rules.IWordDetector; 22 import org.eclipse.jface.text.rules.MultiLineRule; 23 import org.eclipse.jface.text.rules.RuleBasedPartitionScanner; 24 import org.eclipse.jface.text.rules.SingleLineRule; 25 import org.eclipse.jface.text.rules.Token; 26 import org.eclipse.jface.text.rules.WordRule; 27 28 import org.eclipse.jdt.ui.text.IJavaPartitions; 29 30 31 34 public class JavaPartitionScanner extends RuleBasedPartitionScanner implements IJavaPartitions { 35 36 39 static class EmptyCommentDetector implements IWordDetector { 40 41 44 public boolean isWordStart(char c) { 45 return (c == '/'); 46 } 47 48 51 public boolean isWordPart(char c) { 52 return (c == '*' || c == '/'); 53 } 54 } 55 56 57 60 static class EmptyCommentRule extends WordRule implements IPredicateRule { 61 62 private IToken fSuccessToken; 63 67 public EmptyCommentRule(IToken successToken) { 68 super(new EmptyCommentDetector()); 69 fSuccessToken= successToken; 70 addWord("/**/", fSuccessToken); } 72 73 76 public IToken evaluate(ICharacterScanner scanner, boolean resume) { 77 return evaluate(scanner); 78 } 79 80 83 public IToken getSuccessToken() { 84 return fSuccessToken; 85 } 86 } 87 88 89 90 93 public JavaPartitionScanner() { 94 super(); 95 96 IToken string= new Token(JAVA_STRING); 97 IToken character= new Token(JAVA_CHARACTER); 98 IToken javaDoc= new Token(JAVA_DOC); 99 IToken multiLineComment= new Token(JAVA_MULTI_LINE_COMMENT); 100 IToken singleLineComment= new Token(JAVA_SINGLE_LINE_COMMENT); 101 102 List rules= new ArrayList (); 103 104 rules.add(new EndOfLineRule("//", singleLineComment)); 107 rules.add(new SingleLineRule("\"", "\"", string, '\\')); 110 rules.add(new SingleLineRule("'", "'", character, '\\')); 113 EmptyCommentRule wordRule= new EmptyCommentRule(multiLineComment); 115 rules.add(wordRule); 116 117 rules.add(new MultiLineRule("/**", "*/", javaDoc)); rules.add(new MultiLineRule("/*", "*/", multiLineComment)); 121 IPredicateRule[] result= new IPredicateRule[rules.size()]; 122 rules.toArray(result); 123 setPredicateRules(result); 124 } 125 } 126 | Popular Tags |