本文整理汇总了Java中com.intellij.lexer.JavaLexer类的典型用法代码示例。如果您正苦于以下问题:Java JavaLexer类的具体用法?Java JavaLexer怎么用?Java JavaLexer使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
JavaLexer类属于com.intellij.lexer包,在下文中一共展示了JavaLexer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: isParsable
import com.intellij.lexer.JavaLexer; //导入依赖的package包/类
@Override
public boolean isParsable(@NotNull PsiFile psiFile, CharSequence buffer, Language fileLanguage, final Project project)
{
if(!StringUtil.startsWith(buffer, "/**") || !StringUtil.endsWith(buffer, "*/"))
{
return false;
}
final Module moduleForPsiElement = ModuleUtilCore.findModuleForPsiElement(psiFile);
LanguageLevel languageLevel = moduleForPsiElement == null ? LanguageLevel.HIGHEST : EffectiveLanguageLevelUtil.getEffectiveLanguageLevel(moduleForPsiElement);
Lexer lexer = new JavaLexer(languageLevel);
lexer.start(buffer);
if(lexer.getTokenType() == DOC_COMMENT)
{
lexer.advance();
if(lexer.getTokenType() == null)
{
return true;
}
}
return false;
}
示例2: doCollectInformation
import com.intellij.lexer.JavaLexer; //导入依赖的package包/类
@RequiredReadAction
@Override
public void doCollectInformation(@NotNull ProgressIndicator progressIndicator)
{
LanguageLevel languageLevel = myFile.getLanguageLevel();
myFile.accept(new JavaRecursiveElementVisitor()
{
@Override
public void visitKeyword(PsiKeyword keyword)
{
if(JavaLexer.isSoftKeyword(keyword.getNode().getChars(), languageLevel))
{
ContainerUtil.addIfNotNull(myResults, HighlightInfo.newHighlightInfo(JavaHighlightInfoTypes.JAVA_KEYWORD).range(keyword).create());
}
}
});
}
示例3: createLexer
import com.intellij.lexer.JavaLexer; //导入依赖的package包/类
@Override
@NotNull
public Lexer createLexer(@NotNull LanguageVersion languageVersion)
{
JavaLanguageVersion wrapper = (JavaLanguageVersion) languageVersion;
return new JavaLexer(wrapper.getLanguageLevel());
}
示例4: createKeyword
import com.intellij.lexer.JavaLexer; //导入依赖的package包/类
@NotNull
@Override
public PsiKeyword createKeyword(@NotNull @NonNls String keyword, PsiElement context) throws IncorrectOperationException
{
LanguageLevel level = PsiUtil.getLanguageLevel(context);
if(!JavaLexer.isKeyword(keyword, level) && !JavaLexer.isSoftKeyword(keyword, level))
{
throw new IncorrectOperationException("\"" + keyword + "\" is not a keyword.");
}
return new LightKeyword(myManager, keyword);
}
示例5: getErrorsCount
import com.intellij.lexer.JavaLexer; //导入依赖的package包/类
@Override
public int getErrorsCount(final CharSequence seq, Language fileLanguage, final Project project)
{
final Lexer lexer = new JavaLexer(LanguageLevel.HIGHEST);
lexer.start(seq);
if(lexer.getTokenType() != JavaTokenType.LBRACE)
{
return IErrorCounterReparseableElementType.FATAL_ERROR;
}
lexer.advance();
int balance = 1;
while(true)
{
IElementType type = lexer.getTokenType();
if(type == null)
{
break;
}
if(balance == 0)
{
return IErrorCounterReparseableElementType.FATAL_ERROR;
}
if(type == JavaTokenType.LBRACE)
{
balance++;
}
else if(type == JavaTokenType.RBRACE)
{
balance--;
}
lexer.advance();
}
return balance;
}
示例6: canStickJavaTokens
import com.intellij.lexer.JavaLexer; //导入依赖的package包/类
private static boolean canStickJavaTokens(ASTNode token1, ASTNode token2)
{
IElementType type1 = token1.getElementType();
IElementType type2 = token2.getElementType();
Pair<IElementType, IElementType> pair = Pair.create(type1, type2);
Boolean res = myCanStickJavaTokensMatrix.get(pair);
if(res == null)
{
Lexer lexer = new JavaLexer(LanguageLevel.HIGHEST);
TokenCheckResult res1 = checkToken(token1, lexer), res2 = checkToken(token2, lexer);
if(res1 == TokenCheckResult.INCORRECT || res2 == TokenCheckResult.INCORRECT)
{
return true;
}
if(res1 == TokenCheckResult.RESTRICTED_KEYWORD || type1 == JavaTokenType.IDENTIFIER && res2 == TokenCheckResult.RESTRICTED_KEYWORD)
{
res = false;
}
else
{
lexer.start(token1.getText() + token2.getText());
boolean canMerge = lexer.getTokenType() == type1;
lexer.advance();
canMerge &= lexer.getTokenType() == type2;
res = canMerge;
}
myCanStickJavaTokensMatrix.put(pair, res);
}
return res.booleanValue();
}
示例7: getIndexingLexer
import com.intellij.lexer.JavaLexer; //导入依赖的package包/类
@Override
@Nullable
public Lexer getIndexingLexer(final PsiFile file) {
if (file instanceof PsiJavaFile /*&& !(file instanceof JspFile)*/) {
return new JavaLexer(((PsiJavaFile)file).getLanguageLevel());
}
return null;
}
示例8: lexemsEqual
import com.intellij.lexer.JavaLexer; //导入依赖的package包/类
private static boolean lexemsEqual(final PsiClass classToBind, final PsiClass newClass)
{
JavaLexer oldTextLexer = new JavaLexer(LanguageLevel.HIGHEST);
JavaLexer newTextLexer = new JavaLexer(LanguageLevel.HIGHEST);
final String oldBuffer = classToBind.getText();
final String newBuffer = newClass.getText();
oldTextLexer.start(oldBuffer);
newTextLexer.start(newBuffer);
while(true)
{
IElementType oldLexem = oldTextLexer.getTokenType();
IElementType newLexem = newTextLexer.getTokenType();
if(oldLexem == null || newLexem == null)
{
// must terminate at the same time
return oldLexem == null && newLexem == null;
}
if(oldLexem != newLexem)
{
return false;
}
if(oldLexem != TokenType.WHITE_SPACE && oldLexem != JavaDocElementType.DOC_COMMENT)
{
int oldStart = oldTextLexer.getTokenStart();
int newStart = newTextLexer.getTokenStart();
int oldLength = oldTextLexer.getTokenEnd() - oldTextLexer.getTokenStart();
int newLength = newTextLexer.getTokenEnd() - newTextLexer.getTokenStart();
if(oldLength != newLength)
{
return false;
}
for(int i = 0; i < oldLength; i++)
{
if(oldBuffer.charAt(oldStart + i) != newBuffer.charAt(newStart + i))
{
return false;
}
}
}
oldTextLexer.advance();
newTextLexer.advance();
}
}
示例9: _JspJavaLexer
import com.intellij.lexer.JavaLexer; //导入依赖的package包/类
public _JspJavaLexer(LanguageLevel languageLevel)
{
super(new JspLexer());
myJavaLexer = new JavaLexer(languageLevel);
}
示例10: getTokenType
import com.intellij.lexer.JavaLexer; //导入依赖的package包/类
@Override
public IElementType getTokenType(){
Lexer lexer = new JavaLexer(LanguageLevel.HIGHEST);
lexer.start(myText);
return lexer.getTokenType();
}
示例11: isJavaIdentifier
import com.intellij.lexer.JavaLexer; //导入依赖的package包/类
public static boolean isJavaIdentifier(@NotNull String identifier, @NotNull LanguageLevel level)
{
return StringUtil.isJavaIdentifier(identifier) && !JavaLexer.isKeyword(identifier, level);
}
示例12: isIdentifier
import com.intellij.lexer.JavaLexer; //导入依赖的package包/类
@Override
public boolean isIdentifier(@Nullable String text, @NotNull LanguageLevel languageLevel) {
return text != null && StringUtil.isJavaIdentifier(text) && !JavaLexer.isKeyword(text, languageLevel);
}
示例13: isKeyword
import com.intellij.lexer.JavaLexer; //导入依赖的package包/类
@Override
public boolean isKeyword(@Nullable String text) {
return text != null && JavaLexer.isKeyword(text, getLanguageLevel());
}
示例14: createIndexingLexer
import com.intellij.lexer.JavaLexer; //导入依赖的package包/类
public static Lexer createIndexingLexer(OccurrenceConsumer consumer)
{
Lexer javaLexer = new JavaLexer(LanguageLevel.JDK_1_3);
return new JavaFilterLexer(javaLexer, consumer);
}
示例15: getPackageName
import com.intellij.lexer.JavaLexer; //导入依赖的package包/类
@Nullable
public static String getPackageName(CharSequence text)
{
Lexer lexer = new JavaLexer(LanguageLevel.JDK_1_3);
lexer.start(text);
skipWhiteSpaceAndComments(lexer);
final IElementType firstToken = lexer.getTokenType();
if(firstToken != JavaTokenType.PACKAGE_KEYWORD)
{
if(JAVA_FILE_FIRST_TOKEN_SET.contains(firstToken))
{
return "";
}
return null;
}
lexer.advance();
skipWhiteSpaceAndComments(lexer);
final StringBuilder buffer = new StringBuilder();
while(true)
{
if(lexer.getTokenType() != JavaTokenType.IDENTIFIER)
{
break;
}
buffer.append(text, lexer.getTokenStart(), lexer.getTokenEnd());
lexer.advance();
skipWhiteSpaceAndComments(lexer);
if(lexer.getTokenType() != JavaTokenType.DOT)
{
break;
}
buffer.append('.');
lexer.advance();
skipWhiteSpaceAndComments(lexer);
}
String packageName = buffer.toString();
if(packageName.length() == 0 || StringUtil.endsWithChar(packageName, '.'))
{
return null;
}
return packageName;
}