当前位置: 首页>>代码示例>>Java>>正文


Java PsiUtil.checkIsIdentifier方法代码示例

本文整理汇总了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);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:24,代码来源:PsiElementFactoryImpl.java

示例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);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:23,代码来源:PsiElementFactoryImpl.java

示例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);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:18,代码来源:PsiElementFactoryImpl.java

示例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];
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:10,代码来源:PsiElementFactoryImpl.java

示例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+"'");
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:14,代码来源:JavaDirectoryServiceImpl.java

示例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);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:7,代码来源:PsiElementFactoryImpl.java


注:本文中的com.intellij.psi.util.PsiUtil.checkIsIdentifier方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。