KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > freemarker > eclipse > editors > XmlCommentScanner


1 /*
2  * Copyright (c) 2003 The Visigoth Software Society. All rights
3  * reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * 1. Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  *
12  * 2. Redistributions in binary form must reproduce the above copyright
13  * notice, this list of conditions and the following disclaimer in
14  * the documentation and/or other materials provided with the
15  * distribution.
16  *
17  * 3. The end-user documentation included with the redistribution, if
18  * any, must include the following acknowledgement:
19  * "This product includes software developed by the
20  * Visigoth Software Society (http://www.visigoths.org/)."
21  * Alternately, this acknowledgement may appear in the software
22  * itself, if and wherever such third-party acknowledgements
23  * normally appear.
24  *
25  * 4. Neither the name "FreeMarker", "Visigoth", nor any of the names
26  * of the project contributors may be used to endorse or promote
27  * products derived from this software without prior written
28  * permission. For written permission, please contact
29  * visigoths@visigoths.org.
30  *
31  * 5. Products derived from this software may not be called
32  * "FreeMarker" or "Visigoth" nor may "FreeMarker" or "Visigoth"
33  * appear in their names without prior written permission of the
34  * Visigoth Software Society.
35  *
36  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
37  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
38  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
39  * DISCLAIMED. IN NO EVENT SHALL THE VISIGOTH SOFTWARE SOCIETY OR
40  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
42  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
43  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
44  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
45  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
46  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
47  * SUCH DAMAGE.
48  * ====================================================================
49  *
50  * This software consists of voluntary contributions made by many
51  * individuals on behalf of the Visigoth Software Society. For more
52  * information on the Visigoth Software Society, please see
53  * http://www.visigoths.org/
54  */

55
56 package freemarker.eclipse.editors;
57
58 import java.util.ArrayList JavaDoc;
59
60 import org.eclipse.jface.text.rules.IRule;
61 import org.eclipse.jface.text.rules.IToken;
62 import org.eclipse.jface.text.rules.MultiLineRule;
63 import org.eclipse.jface.text.rules.RuleBasedScanner;
64 import org.eclipse.swt.graphics.Color;
65
66 /**
67  * The XML comment scanner. This class handles the lexical scanning
68  * of the XML comments, separating out FreeMarker constructs into
69  * their own tokens (with their own colors).
70  *
71  * @version $Id: XmlCommentScanner.java,v 1.2 2004/02/05 00:16:23 stephanmueller Exp $
72  * @author <a HREF="mailto:per&#64;percederberg.net">Per Cederberg</a>
73  */

74 public class XmlCommentScanner extends RuleBasedScanner {
75
76     /**
77      * Creates a new XML comment scanner.
78      *
79      * @param manager the token manager to use
80      */

81     public XmlCommentScanner(ITokenManager manager) {
82         ArrayList JavaDoc rules = new ArrayList JavaDoc();
83         IRule[] result;
84         IToken comment;
85         IToken directive;
86         IToken interpolation;
87         Color color;
88
89         // Retrieve tokens
90
comment = manager.getCommentToken();
91         directive = manager.getDirectiveToken();
92         interpolation = manager.getInterpolationToken();
93
94         // Create rules for FreeMarker constructs
95
rules.add(new MultiLineRule("<#--", "-->", comment));
96         rules.add(new DirectiveRule(directive));
97         rules.add(new InterpolationRule(interpolation));
98
99         // Set scanner rules
100
result = new IRule[rules.size()];
101         rules.toArray(result);
102         setRules(result);
103     }
104 }
105
Popular Tags