本文整理汇总了Java中com.intellij.psi.tree.java.IKeywordElementType类的典型用法代码示例。如果您正苦于以下问题:Java IKeywordElementType类的具体用法?Java IKeywordElementType怎么用?Java IKeywordElementType使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
IKeywordElementType类属于com.intellij.psi.tree.java包,在下文中一共展示了IKeywordElementType类的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: validateAndroidPackageName
import com.intellij.psi.tree.java.IKeywordElementType; //导入依赖的package包/类
/**
* Validates a potential package name and returns null if the package name is valid, and otherwise
* returns a description for why it is not valid.
* <p>
* Note that Android package names are more restrictive than general Java package names;
* we require at least two segments, limit the character set to [a-zA-Z0-9_] (Java allows any
* {@link Character#isLetter(char)} and require that each segment start with a letter (Java allows
* underscores at the beginning).
* <p>
* For details, see core/java/android/content/pm/PackageParser.java#validateName
*
* @param name the package name
* @return null if the package is valid as an Android package name, and otherwise a description for why not
*/
@Nullable
public static String validateAndroidPackageName(@NotNull String name) {
if (name.isEmpty()) {
return "Package name is missing";
}
String packageManagerCheck = validateName(name, true);
if (packageManagerCheck != null) {
return packageManagerCheck;
}
// In addition, we have to check that none of the segments are Java identifiers, since
// that will lead to compilation errors, which the package manager doesn't need to worry about
// (the code wouldn't have compiled)
ApplicationManager.getApplication().assertReadAccessAllowed();
Lexer lexer = JavaParserDefinition.createLexer(LanguageLevel.JDK_1_5);
int index = 0;
while (true) {
int index1 = name.indexOf('.', index);
if (index1 < 0) {
index1 = name.length();
}
String segment = name.substring(index, index1);
lexer.start(segment);
if (lexer.getTokenType() != JavaTokenType.IDENTIFIER) {
if (lexer.getTokenType() instanceof IKeywordElementType) {
return "Package names cannot contain Java keywords like '" + segment + "'";
}
if (segment.isEmpty()) {
return "Package segments must be of non-zero length";
}
return segment + " is not a valid identifier";
}
if (index1 == name.length()) {
break;
}
index = index1 + 1;
}
return null;
}