1 19 20 package org.netbeans.spi.lexer; 21 22 import org.netbeans.api.lexer.Language; 23 import org.netbeans.api.lexer.TokenId; 24 import org.netbeans.lib.lexer.LanguageOperation; 25 import org.netbeans.lib.lexer.LexerUtilsConstants; 26 27 35 36 public final class LanguageEmbedding<T extends TokenId> { 37 38 43 public static <T extends TokenId> LanguageEmbedding<T> create( 44 Language<T> language, int startSkipLength, int endSkipLength) { 45 return create(language, startSkipLength, endSkipLength, false); 46 } 47 48 73 public static <T extends TokenId> LanguageEmbedding<T> create( 74 Language<T> language, int startSkipLength, int endSkipLength, boolean joinSections) { 75 if (language == null) { 76 throw new IllegalArgumentException ("language may not be null"); } 78 if (startSkipLength < 0) { 79 throw new IllegalArgumentException ("startSkipLength=" + startSkipLength + " < 0"); 80 } 81 if (endSkipLength < 0) { 82 throw new IllegalArgumentException ("endSkipLength=" + endSkipLength + " < 0"); 83 } 84 85 LanguageOperation<T> op = LexerUtilsConstants.languageOperation(language); 86 return op.getEmbedding(startSkipLength, endSkipLength, joinSections); 87 } 88 89 private final Language<T> language; 90 91 private final int startSkipLength; 92 93 private final int endSkipLength; 94 95 private final boolean joinSections; 96 97 100 LanguageEmbedding(Language<T> language, 101 int startSkipLength, int endSkipLength, boolean joinSections) { 102 assert (language != null) : "Embedded language may not be null."; assert (startSkipLength >= 0 && endSkipLength >= 0); 104 this.language = language; 105 this.startSkipLength = startSkipLength; 106 this.endSkipLength = endSkipLength; 107 this.joinSections = joinSections; 108 } 109 110 115 public Language<T> language() { 116 return language; 117 } 118 119 129 public int startSkipLength() { 130 return startSkipLength; 131 } 132 133 143 public int endSkipLength() { 144 return endSkipLength; 145 } 146 147 154 public boolean joinSections() { 155 return joinSections; 156 } 157 158 public String toString() { 159 return "language: " + language() + ", skip[" + startSkipLength() + ", " + endSkipLength + "]"; } 162 163 } 164 | Popular Tags |