1 19 20 package org.netbeans.lib.lexer.test.simple; 21 22 import java.util.Collection ; 23 import java.util.Collections ; 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 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 55 public SimpleLanguageProvider() { 56 assert instance == null : "Multiple instances of DummyLanguageProvider detected"; 57 instance = this; 58 } 59 60 public Language<? extends TokenId> findLanguage(String 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 <TokenId> createTokenIds() { 79 return Collections.emptyList(); 80 } 81 82 protected Lexer<TokenId> createLexer(LexerRestartInfo<TokenId> info) { 83 return null; 84 } 85 86 protected String mimeType() { 87 return LanguageManagerTest.MIME_TYPE_KNOWN; 88 } 89 90 } } 92 | Popular Tags |