KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > api > languages > ParserManager


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19 package org.netbeans.api.languages;
20
21 import java.lang.ref.WeakReference JavaDoc;
22 import java.util.Map JavaDoc;
23 import java.util.WeakHashMap JavaDoc;
24 import javax.swing.text.Document JavaDoc;
25 import org.netbeans.modules.languages.ParserManagerImpl;
26
27
28 /**
29  * Represents parser implementation.
30  *
31  * @author Jan Jancura
32  */

33 public abstract class ParserManager {
34     
35     /**
36      * State of parser.
37      */

38     public static enum State {
39         /** Parser is running. */
40         PARSING,
41         /** Parsed witouut errors. */
42         OK,
43         /** Parser with errors. */
44         ERROR,
45         /** Parser has not been started yet. */
46         NOT_PARSED
47     }
48     
49     
50     private static Map JavaDoc<Document JavaDoc,WeakReference JavaDoc<ParserManager>> managers =
51         new WeakHashMap JavaDoc<Document JavaDoc,WeakReference JavaDoc<ParserManager>> ();
52     
53     /**
54      * Returns parser for given {@link javax.swing.text.Document}.
55      *
56      * @return parser for given {@link javax.swing.text.Document}
57      */

58     public static synchronized ParserManager get (Document JavaDoc doc) {
59         WeakReference JavaDoc<ParserManager> wr = managers.get (doc);
60         ParserManager pm = wr != null ? wr.get () : null;
61         if (pm == null) {
62             pm = new ParserManagerImpl (doc);
63             managers.put (doc, new WeakReference JavaDoc<ParserManager> (pm));
64             //Utils.startTest ("ParserManager.managers", managers);
65
}
66         return pm;
67     }
68
69     /**
70      * Returns state of parser.
71      *
72      * @retrun a state of parser
73      */

74     public abstract State getState ();
75     
76     /**
77      * Returns AST tree root node.
78      *
79      * @throws in the case of errors in document
80      * @retrun AST tree root node
81      */

82     public abstract ASTNode getAST () throws ParseException;
83     
84     /**
85      * Registers ParserManagerListener.
86      *
87      * @param l ParserManagerListener to be registerred
88      */

89     public abstract void addListener (ParserManagerListener l);
90     
91     /**
92      * Unregisters ParserManagerListener.
93      *
94      * @param l ParserManagerListener to be unregisterred
95      */

96     public abstract void removeListener (ParserManagerListener l);
97     
98     /**
99      * Registers ASTEvaluator.
100      *
101      * @param l ASTEvaluator to be unregisterred
102      */

103     public abstract void addASTEvaluator (ASTEvaluator e);
104     
105     /**
106      * Unregisters ASTEvaluator.
107      *
108      * @param l ASTEvaluator to be unregisterred
109      */

110     public abstract void removeASTEvaluator (ASTEvaluator e);
111 }
112
113
114
115
Popular Tags