KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > lib > lexer > test > simple > SimpleLanguageProvider


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-2007 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.lib.lexer.test.simple;
21
22 import java.util.Collection JavaDoc;
23 import java.util.Collections JavaDoc;
24 import org.netbeans.api.lexer.InputAttributes;
25 import org.netbeans.api.lexer.Language;
26 import org.netbeans.api.lexer.LanguagePath;
27 import org.netbeans.api.lexer.Token;
28 import org.netbeans.api.lexer.TokenId;
29 import org.netbeans.lib.lexer.*;
30 import org.netbeans.spi.lexer.LanguageEmbedding;
31 import org.netbeans.spi.lexer.LanguageHierarchy;
32 import org.netbeans.spi.lexer.LanguageProvider;
33 import org.netbeans.spi.lexer.Lexer;
34 import org.netbeans.spi.lexer.LexerRestartInfo;
35
36 /**
37  *
38  * @author vita
39  */

40 public class SimpleLanguageProvider extends LanguageProvider {
41     
42     private static SimpleLanguageProvider instance = null;
43     
44     public static void fireLanguageChange() {
45         assert instance != null : "There is no SimpleLanguageProvider instance.";
46         instance.firePropertyChange(PROP_LANGUAGE);
47     }
48     
49     public static void fireTokenLanguageChange() {
50         assert instance != null : "There is no SimpleLanguageProvider instance.";
51         instance.firePropertyChange(PROP_EMBEDDED_LANGUAGE);
52     }
53     
54     /** Creates a new instance of SimpleLanguageProvider */
55     public SimpleLanguageProvider() {
56         assert instance == null : "Multiple instances of DummyLanguageProvider detected";
57         instance = this;
58     }
59
60     public Language<? extends TokenId> findLanguage(String JavaDoc mimePath) {
61         if (LanguageManagerTest.MIME_TYPE_KNOWN.equals(mimePath)) {
62             return new LH().language();
63         } else {
64             return null;
65         }
66     }
67
68     public LanguageEmbedding<? extends TokenId> findLanguageEmbedding(
69     Token<? extends TokenId> token, LanguagePath languagePath, InputAttributes inputAttributes) {
70         if ("text/x-simple-plain".equals(languagePath.mimePath()) && token.id().name().equals("WORD")) {
71             return LanguageEmbedding.create(SimpleCharTokenId.language(), 0, 0);
72         } else {
73             return null;
74         }
75     }
76     
77     private static final class LH extends LanguageHierarchy<TokenId> {
78         protected Collection JavaDoc<TokenId> createTokenIds() {
79             return Collections.emptyList();
80         }
81
82         protected Lexer<TokenId> createLexer(LexerRestartInfo<TokenId> info) {
83             return null;
84         }
85
86         protected String JavaDoc mimeType() {
87             return LanguageManagerTest.MIME_TYPE_KNOWN;
88         }
89
90     } // End of LD class
91
}
92
Popular Tags