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


Java GroovyFile.removeImport方法代码示例

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


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

示例1: removeRedundantImports

import org.jetbrains.plugins.groovy.lang.psi.GroovyFile; //导入方法依赖的package包/类
@Override
public void removeRedundantImports(PsiFile targetClassFile) {
  if (targetClassFile instanceof GroovyFile) {
    GroovyFile file = (GroovyFile)targetClassFile;
    final Set<GrImportStatement> usedImports = GroovyImportUtil.findUsedImports(file);
    final List<GrImportStatement> validImports = org.jetbrains.plugins.groovy.lang.psi.util.PsiUtil.getValidImportStatements(file);
    for (GrImportStatement importStatement : validImports) {
      if (!usedImports.contains(importStatement)) {
        file.removeImport(importStatement);
      }
    }
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:14,代码来源:GroovyMoveClassToInnerHandler.java

示例2: run

import org.jetbrains.plugins.groovy.lang.psi.GroovyFile; //导入方法依赖的package包/类
@Override
public void run() {
  if (!(myFile instanceof GroovyFile)) return;

  GroovyFile file = ((GroovyFile)myFile);
  final PsiDocumentManager documentManager = PsiDocumentManager.getInstance(file.getProject());
  final Document document = documentManager.getDocument(file);
  if (document != null) {
    documentManager.commitDocument(document);
  }
  final Set<String> simplyImportedClasses = new LinkedHashSet<String>();
  final Set<String> staticallyImportedMembers = new LinkedHashSet<String>();
  final Set<GrImportStatement> usedImports = new HashSet<GrImportStatement>();
  final Set<GrImportStatement> unresolvedOnDemandImports = new HashSet<GrImportStatement>();
  final Set<String> implicitlyImportedClasses = new LinkedHashSet<String>();
  final Set<String> innerClasses = new HashSet<String>();
  Map<String, String> aliasImported = ContainerUtil.newHashMap();
  Map<String, String> annotatedImports = ContainerUtil.newHashMap();

  GroovyImportUtil.processFile(myFile, simplyImportedClasses, staticallyImportedMembers, usedImports, unresolvedOnDemandImports,
                               implicitlyImportedClasses, innerClasses,
                               aliasImported, annotatedImports);
  final List<GrImportStatement> oldImports = PsiUtil.getValidImportStatements(file);
  if (myRemoveUnusedOnly) {
    for (GrImportStatement oldImport : oldImports) {
      if (!usedImports.contains(oldImport)) {
        file.removeImport(oldImport);
      }
    }
    return;
  }

  // Add new import statements
  GrImportStatement[] newImports =
    prepare(usedImports, simplyImportedClasses, staticallyImportedMembers, implicitlyImportedClasses, innerClasses, aliasImported,
            annotatedImports, unresolvedOnDemandImports);
  if (oldImports.isEmpty() && newImports.length == 0 && aliasImported.isEmpty()) {
    return;
  }

  GroovyPsiElementFactory factory = GroovyPsiElementFactory.getInstance(file.getProject());

  GroovyFile tempFile = factory.createGroovyFile("", false, null);

  for (GrImportStatement newImport : newImports) {
    tempFile.addImport(newImport);
  }

  if (!oldImports.isEmpty()) {
    final int startOffset = oldImports.get(0).getTextRange().getStartOffset();
    final int endOffset = oldImports.get(oldImports.size() - 1).getTextRange().getEndOffset();
    String oldText = oldImports.isEmpty() ? "" : myFile.getText().substring(startOffset, endOffset);
    if (tempFile.getText().trim().equals(oldText)) {
      return;
    }
  }

  for (GrImportStatement statement : tempFile.getImportStatements()) {
    file.addImport(statement);
  }

  for (GrImportStatement importStatement : oldImports) {
    file.removeImport(importStatement);
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:66,代码来源:GroovyImportOptimizer.java


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