Java 类com.intellij.lang.java.lexer.JavaLexer 实例源码

项目:intellij-ce-playground    文件:PsiElementFactoryImpl.java   
@NotNull
@Override
public PsiKeyword createKeyword(@NotNull @NonNls String keyword, PsiElement context) throws IncorrectOperationException {
  if (!JavaLexer.isKeyword(keyword, PsiUtil.getLanguageLevel(context))) {
    throw new IncorrectOperationException("\"" + keyword + "\" is not a keyword.");
  }
  return new LightKeyword(myManager, keyword);
}
项目:intellij-ce-playground    文件:ResourceNameConverter.java   
@Override
public String fromString(@Nullable @NonNls String s, ConvertContext context) {
  if (s == null) {
    return null;
  }
  String fieldName = AndroidResourceUtil.getFieldNameByResourceName(s);
  return StringUtil.isJavaIdentifier(fieldName) && !JavaLexer.isKeyword(fieldName, LanguageLevel.JDK_1_5) ? s : null;
}
项目:tools-idea    文件:PsiElementFactoryImpl.java   
@NotNull
@Override
public PsiKeyword createKeyword(@NotNull @NonNls String keyword, PsiElement context) throws IncorrectOperationException {
  if (!JavaLexer.isKeyword(keyword, PsiUtil.getLanguageLevel(context))) {
    throw new IncorrectOperationException("\"" + keyword + "\" is not a keyword.");
  }
  return new LightKeyword(myManager, keyword);
}
项目:intellij-ce-playground    文件:JavaParserDefinition.java   
@NotNull
public static Lexer createLexer(@NotNull LanguageLevel level) {
  return new JavaLexer(level);
}
项目:intellij-ce-playground    文件:ClsParsingUtil.java   
public static boolean isJavaIdentifier(@NotNull String identifier, @NotNull LanguageLevel level) {
  return StringUtil.isJavaIdentifier(identifier) && !JavaLexer.isKeyword(identifier, level);
}
项目:intellij-ce-playground    文件:PsiNameHelperImpl.java   
@Override
public boolean isIdentifier(@Nullable String text, @NotNull LanguageLevel languageLevel) {
  return text != null && StringUtil.isJavaIdentifier(text) && !JavaLexer.isKeyword(text, languageLevel);
}
项目:intellij-ce-playground    文件:PsiNameHelperImpl.java   
@Override
public boolean isKeyword(@Nullable String text) {
  return text != null && JavaLexer.isKeyword(text, getLanguageLevel());
}
项目:intellij-ce-playground    文件:ResourceValue.java   
@Nullable
public String getErrorMessage() {
  // @null is a valid resource reference, even though it is not otherwise a valid
  // resource url (it's missing a resource type, "null" is a Java keyword, etc)
  if ("null".equals(myResourceName) && myResourceType == null && myPrefix == '@') {
    return null;
  }

  if (myResourceName == null || myResourceName.isEmpty()) {
    if (myResourceType == null && (myPrefix == '@' || myPrefix == '?')) {
      return "Missing resource type";
    }
    return "Missing resource name";
  }

  ResourceType type;
  if (myResourceType == null) {
    if (myPrefix != '?') {
      if (myPrefix == '@' && myResourceName.indexOf('/') == -1) {
        return "Missing /";
      }
      return "Missing resource type";
    }
    type = ResourceType.ATTR;
  } else if (PLUS_ID.equals(myResourceType)) {
    type = ResourceType.ID;
  } else {
    type = ResourceType.getEnum(myResourceType);
    if (type == null) {
      return "Unknown resource type " + myResourceType;
    }
  }

  String name = myResourceName;
  if (FolderTypeRelationship.getRelatedFolders(type).contains(ResourceFolderType.VALUES)) {
    name = AndroidResourceUtil.getFieldNameByResourceName(name);
  }

  if (!AndroidUtils.isIdentifier(name)) {
    if (JavaLexer.isKeyword(name, LanguageLevel.JDK_1_5)) {
      return "Resource name cannot be a Java keyword (" + name + ")";
    }

    if (!Character.isJavaIdentifierStart(name.charAt(0))) {
      return "The resource name must begin with a character";
    }
    for (int i = 1, n = name.length(); i < n; i++) {
      char c = name.charAt(i);
      if (!Character.isJavaIdentifierPart(c)) {
        return String.format("'%1$c' is not a valid resource name character", c);
      }
    }

    return "Resource name '" + name + "' must be a valid Java identifier";
  }

  return null;
}
项目:intellij-ce-playground    文件:AndroidUtils.java   
public static boolean isIdentifier(@NotNull String candidate) {
  return StringUtil.isJavaIdentifier(candidate) && !JavaLexer.isKeyword(candidate, LanguageLevel.JDK_1_5);
}
项目:tools-idea    文件:JavaParserDefinition.java   
@NotNull
public static Lexer createLexer(@NotNull LanguageLevel level) {
  return new JavaLexer(level);
}
项目:tools-idea    文件:ClsParsingUtil.java   
public static boolean isJavaIdentifier(@NotNull String identifier, @NotNull LanguageLevel level) {
  return StringUtil.isJavaIdentifier(identifier) && !JavaLexer.isKeyword(identifier, level);
}
项目:tools-idea    文件:PsiNameHelperImpl.java   
@Override
public boolean isIdentifier(@Nullable String text, @NotNull LanguageLevel languageLevel) {
  return text != null && StringUtil.isJavaIdentifier(text) && !JavaLexer.isKeyword(text, languageLevel);
}
项目:tools-idea    文件:PsiNameHelperImpl.java   
@Override
public boolean isKeyword(@Nullable String text) {
  return text != null && JavaLexer.isKeyword(text, getLanguageLevel());
}
项目:embeddedlinux-jvmdebugger-intellij    文件:EmbeddedJavaModuleStep.java   
/**
 * Proper Identifier
 *
 * @param candidate
 * @return
 */
public static boolean isIdentifier(@NotNull String candidate) {
    return StringUtil.isJavaIdentifier(candidate) && !JavaLexer.isKeyword(candidate, LanguageLevel.JDK_1_6);
}