本文整理汇总了Java中com.intellij.psi.util.PsiUtil.checkIsIdentifier方法的典型用法代码示例。如果您正苦于以下问题:Java PsiUtil.checkIsIdentifier方法的具体用法?Java PsiUtil.checkIsIdentifier怎么用?Java PsiUtil.checkIsIdentifier使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.intellij.psi.util.PsiUtil
的用法示例。
在下文中一共展示了PsiUtil.checkIsIdentifier方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createField
import com.intellij.psi.util.PsiUtil; //导入方法依赖的package包/类
@NotNull
@Override
public PsiField createField(@NotNull final String name, @NotNull final PsiType type) throws IncorrectOperationException {
PsiUtil.checkIsIdentifier(myManager, name);
if (PsiType.NULL.equals(type)) {
throw new IncorrectOperationException("Cannot create field with type \"null\".");
}
@NonNls final String text = "class _Dummy_ { private " + type.getCanonicalText(true) + " " + name + "; }";
final PsiJavaFile aFile = createDummyJavaFile(text);
final PsiClass[] classes = aFile.getClasses();
if (classes.length < 1) {
throw new IncorrectOperationException("Class was not created " + text);
}
final PsiClass psiClass = classes[0];
final PsiField[] fields = psiClass.getFields();
if (fields.length < 1) {
throw new IncorrectOperationException("Field was not created " + text);
}
PsiField field = fields[0];
field = (PsiField)JavaCodeStyleManager.getInstance(myManager.getProject()).shortenClassReferences(field);
return (PsiField)CodeStyleManager.getInstance(myManager.getProject()).reformat(field);
}
示例2: createMethod
import com.intellij.psi.util.PsiUtil; //导入方法依赖的package包/类
@NotNull
@Override
public PsiMethod createMethod(@NotNull final String name, final PsiType returnType) throws IncorrectOperationException {
PsiUtil.checkIsIdentifier(myManager, name);
if (PsiType.NULL.equals(returnType)) {
throw new IncorrectOperationException("Cannot create method with type \"null\".");
}
final String canonicalText = returnType.getCanonicalText(true);
final PsiJavaFile aFile = createDummyJavaFile("class _Dummy_ { public " + canonicalText + " " + name + "() {} }");
final PsiClass[] classes = aFile.getClasses();
if (classes.length < 1) {
throw new IncorrectOperationException("Class was not created. Method name: " + name + "; return type: " + canonicalText);
}
final PsiMethod[] methods = classes[0].getMethods();
if (methods.length < 1) {
throw new IncorrectOperationException("Method was not created. Method name: " + name + "; return type: " + canonicalText);
}
PsiMethod method = methods[0];
method = (PsiMethod)JavaCodeStyleManager.getInstance(myManager.getProject()).shortenClassReferences(method);
return (PsiMethod)CodeStyleManager.getInstance(myManager.getProject()).reformat(method);
}
示例3: createParameter
import com.intellij.psi.util.PsiUtil; //导入方法依赖的package包/类
@NotNull
@Override
public PsiParameter createParameter(@NotNull final String name, @NotNull final PsiType type) throws IncorrectOperationException {
PsiUtil.checkIsIdentifier(myManager, name);
if (PsiType.NULL.equals(type)) {
throw new IncorrectOperationException("Cannot create parameter with type \"null\".");
}
final String text = type.getCanonicalText(true) + " " + name;
PsiParameter parameter = createParameterFromText(text, null);
final CodeStyleManager codeStyleManager = CodeStyleManager.getInstance(myManager.getProject());
PsiUtil.setModifierProperty(parameter, PsiModifier.FINAL,
JavaCodeStyleSettingsFacade.getInstance(myManager.getProject()).isGenerateFinalParameters());
GeneratedMarkerVisitor.markGenerated(parameter);
parameter = (PsiParameter)JavaCodeStyleManager.getInstance(myManager.getProject()).shortenClassReferences(parameter);
return (PsiParameter)codeStyleManager.reformat(parameter);
}
示例4: createClassInner
import com.intellij.psi.util.PsiUtil; //导入方法依赖的package包/类
private PsiClass createClassInner(@NonNls final String type, @NonNls String name) {
PsiUtil.checkIsIdentifier(myManager, name);
final PsiJavaFile aFile = createDummyJavaFile("public " + type + " " + name + " { }");
final PsiClass[] classes = aFile.getClasses();
if (classes.length != 1) {
throw new IncorrectOperationException("Incorrect " + type + " name \"" + name + "\".");
}
return classes[0];
}
示例5: checkCreateClassOrInterface
import com.intellij.psi.util.PsiUtil; //导入方法依赖的package包/类
public static void checkCreateClassOrInterface(@NotNull PsiDirectory directory, String name) throws IncorrectOperationException {
PsiUtil.checkIsIdentifier(directory.getManager(), name);
String fileName = name + "." + StdFileTypes.JAVA.getDefaultExtension();
directory.checkCreateFile(fileName);
PsiNameHelper helper = PsiNameHelper.getInstance(directory.getProject());
PsiPackage aPackage = JavaDirectoryService.getInstance().getPackage(directory);
String qualifiedName = aPackage == null ? null : aPackage.getQualifiedName();
if (!StringUtil.isEmpty(qualifiedName) && !helper.isQualifiedName(qualifiedName)) {
throw new IncorrectOperationException("Cannot create class in invalid package: '"+qualifiedName+"'");
}
}
示例6: createIdentifier
import com.intellij.psi.util.PsiUtil; //导入方法依赖的package包/类
@NotNull
@Override
public PsiIdentifier createIdentifier(@NotNull final String text) throws IncorrectOperationException {
PsiUtil.checkIsIdentifier(myManager, text);
return new LightIdentifier(myManager, text);
}