01: /*******************************************************************************
02: * Copyright (c) 2000, 2005 IBM Corporation and others.
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Eclipse Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/epl-v10.html
07: *
08: * Contributors:
09: * IBM Corporation - initial API and implementation
10: *******************************************************************************/package org.eclipse.ui.examples.javaeditor.javadoc;
11:
12: import java.util.ArrayList;
13: import java.util.List;
14:
15: import org.eclipse.jface.text.TextAttribute;
16: import org.eclipse.jface.text.rules.*;
17: import org.eclipse.ui.examples.javaeditor.util.JavaColorProvider;
18: import org.eclipse.ui.examples.javaeditor.util.JavaWhitespaceDetector;
19:
20: /**
21: * A rule based JavaDoc scanner.
22: */
23: public class JavaDocScanner extends RuleBasedScanner {
24:
25: /**
26: * A key word detector.
27: */
28: static class JavaDocWordDetector implements IWordDetector {
29:
30: /* (non-Javadoc)
31: * Method declared on IWordDetector
32: */
33: public boolean isWordStart(char c) {
34: return (c == '@');
35: }
36:
37: /* (non-Javadoc)
38: * Method declared on IWordDetector
39: */
40: public boolean isWordPart(char c) {
41: return Character.isLetter(c);
42: }
43: }
44:
45: private static String[] fgKeywords = {
46: "@author", "@deprecated", "@exception", "@param", "@return", "@see", "@serial", "@serialData", "@serialField", "@since", "@throws", "@version" }; //$NON-NLS-12$ //$NON-NLS-11$ //$NON-NLS-10$ //$NON-NLS-7$ //$NON-NLS-9$ //$NON-NLS-8$ //$NON-NLS-6$ //$NON-NLS-5$ //$NON-NLS-4$ //$NON-NLS-3$ //$NON-NLS-2$ //$NON-NLS-1$
47:
48: /**
49: * Create a new javadoc scanner for the given color provider.
50: *
51: * @param provider the color provider
52: */
53: public JavaDocScanner(JavaColorProvider provider) {
54: super ();
55:
56: IToken keyword = new Token(new TextAttribute(provider
57: .getColor(JavaColorProvider.JAVADOC_KEYWORD)));
58: IToken tag = new Token(new TextAttribute(provider
59: .getColor(JavaColorProvider.JAVADOC_TAG)));
60: IToken link = new Token(new TextAttribute(provider
61: .getColor(JavaColorProvider.JAVADOC_LINK)));
62:
63: List list = new ArrayList();
64:
65: // Add rule for tags.
66: list.add(new SingleLineRule("<", ">", tag)); //$NON-NLS-2$ //$NON-NLS-1$
67:
68: // Add rule for links.
69: list.add(new SingleLineRule("{", "}", link)); //$NON-NLS-2$ //$NON-NLS-1$
70:
71: // Add generic whitespace rule.
72: list.add(new WhitespaceRule(new JavaWhitespaceDetector()));
73:
74: // Add word rule for keywords.
75: WordRule wordRule = new WordRule(new JavaDocWordDetector());
76: for (int i = 0; i < fgKeywords.length; i++)
77: wordRule.addWord(fgKeywords[i], keyword);
78: list.add(wordRule);
79:
80: IRule[] result = new IRule[list.size()];
81: list.toArray(result);
82: setRules(result);
83: }
84: }
|