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


Java PsiAdapter.addImportStatement方法代码示例

本文整理汇总了Java中org.jetbrains.java.generate.psi.PsiAdapter.addImportStatement方法的典型用法代码示例。如果您正苦于以下问题:Java PsiAdapter.addImportStatement方法的具体用法?Java PsiAdapter.addImportStatement怎么用?Java PsiAdapter.addImportStatement使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.jetbrains.java.generate.psi.PsiAdapter的用法示例。


在下文中一共展示了PsiAdapter.addImportStatement方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: autoImportPackages

import org.jetbrains.java.generate.psi.PsiAdapter; //导入方法依赖的package包/类
/**
 * Automatic import the packages.
 *
 * @param packageNames names of packages (must end with .* and be separated by ; or ,)
 * @throws IncorrectOperationException error adding imported package
 */
private static void autoImportPackages(PsiJavaFile psiJavaFile, String packageNames) throws IncorrectOperationException {
  StringTokenizer tok = new StringTokenizer(packageNames, ",");
  while (tok.hasMoreTokens()) {
    String packageName = tok.nextToken().trim(); // trim in case of space
    if (logger.isDebugEnabled()) logger.debug("Auto importing package: " + packageName);
    PsiAdapter.addImportStatement(psiJavaFile, packageName);
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:15,代码来源:GenerateToStringWorker.java

示例2: autoImportPackages

import org.jetbrains.java.generate.psi.PsiAdapter; //导入方法依赖的package包/类
/**
 * Automatic import the packages.
 *
 * @param packageNames names of packages (must end with .* and be separated by ; or ,)
 * @throws IncorrectOperationException error adding imported package
 */
private static void autoImportPackages(PsiJavaFile psiJavaFile, String packageNames) throws IncorrectOperationException
{
	StringTokenizer tok = new StringTokenizer(packageNames, ",");
	while(tok.hasMoreTokens())
	{
		String packageName = tok.nextToken().trim(); // trim in case of space
		if(logger.isDebugEnabled())
		{
			logger.debug("Auto importing package: " + packageName);
		}
		PsiAdapter.addImportStatement(psiJavaFile, packageName);
	}
}
 
开发者ID:consulo,项目名称:consulo-java,代码行数:20,代码来源:GenerateToStringWorker.java

示例3: applyFix

import org.jetbrains.java.generate.psi.PsiAdapter; //导入方法依赖的package包/类
/**
 * Add the {@link GctConstants.APP_ENGINE_ANNOTATION_NAMED} annotation to the {@link
 * PsiParameter} in <code>descriptor</code>. The query name in {@link
 * GctConstants.APP_ENGINE_ANNOTATION_NAMED} will be the name of the {@link PsiParameter} in
 * <code>descriptor</code>. If the {@link PsiElement} in <code>descriptor</code> is not of
 * {@link PsiParameter} type or if the {@link PsiParameter} in <code>descriptor</code> already
 * has {@link GctConstants.APP_ENGINE_ANNOTATION_NAMED} or javax.inject.Named, no annotation
 * will be added.
 */
@Override
public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) {
  PsiElement element = descriptor.getPsiElement();
  if (element == null) {
    return;
  }

  if (!(element instanceof PsiParameter)) {
    return;
  }
  PsiParameter parameter = (PsiParameter) element;

  PsiModifierList modifierList = parameter.getModifierList();
  if (modifierList == null) {
    return;
  }

  if (modifierList.findAnnotation(GctConstants.APP_ENGINE_ANNOTATION_NAMED) != null) {
    return;
  }

  if (modifierList.findAnnotation("") != null) {
    return;
  }

  String annotationString = "@Named(\"" + parameter.getName() + "\")";
  PsiAnnotation annotation =
      JavaPsiFacade.getElementFactory(project)
          .createAnnotationFromText(annotationString, element);
  modifierList.add(annotation);

  PsiFile file = parameter.getContainingFile();
  if (file == null) {
    return;
  }

  if (!(file instanceof PsiJavaFile)) {
    return;
  }

  PsiAdapter.addImportStatement((PsiJavaFile) file, GctConstants.APP_ENGINE_ANNOTATION_NAMED);
}
 
开发者ID:GoogleCloudPlatform,项目名称:google-cloud-intellij,代码行数:52,代码来源:ApiParameterInspection.java


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