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


Java ImportRewrite.removeStaticImport方法代码示例

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


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

示例1: rewriteImports

import org.eclipse.jdt.core.dom.rewrite.ImportRewrite; //导入方法依赖的package包/类
public void rewriteImports(TextChangeManager changeManager, IProgressMonitor pm)
    throws CoreException {
  for (Iterator<Entry<ICompilationUnit, ImportChange>> iter =
          fImportChanges.entrySet().iterator();
      iter.hasNext(); ) {
    Entry<ICompilationUnit, ImportChange> entry = iter.next();
    ICompilationUnit cu = entry.getKey();
    ImportChange importChange = entry.getValue();

    ImportRewrite importRewrite = StubUtility.createImportRewrite(cu, true);
    importRewrite.setFilterImplicitImports(false);
    for (Iterator<String> iterator = importChange.fStaticToRemove.iterator();
        iterator.hasNext(); ) {
      importRewrite.removeStaticImport(iterator.next());
    }
    for (Iterator<String> iterator = importChange.fToRemove.iterator(); iterator.hasNext(); ) {
      importRewrite.removeImport(iterator.next());
    }
    for (Iterator<String[]> iterator = importChange.fStaticToAdd.iterator();
        iterator.hasNext(); ) {
      String[] toAdd = iterator.next();
      importRewrite.addStaticImport(toAdd[0], toAdd[1], true);
    }
    for (Iterator<String> iterator = importChange.fToAdd.iterator(); iterator.hasNext(); ) {
      importRewrite.addImport(iterator.next());
    }

    if (importRewrite.hasRecordedChanges()) {
      TextEdit importEdit = importRewrite.rewriteImports(pm);
      String name = RefactoringCoreMessages.RenamePackageRefactoring_update_imports;
      try {
        TextChangeCompatibility.addTextEdit(changeManager.get(cu), name, importEdit);
      } catch (MalformedTreeException e) {
        JavaPlugin.logErrorMessage(
            "MalformedTreeException while processing cu " + cu); // $NON-NLS-1$
        throw e;
      }
    }
  }
}
 
开发者ID:eclipse,项目名称:che,代码行数:41,代码来源:RenamePackageProcessor.java

示例2: addReferenceUpdates

import org.eclipse.jdt.core.dom.rewrite.ImportRewrite; //导入方法依赖的package包/类
private void addReferenceUpdates(
    TextChangeManager changeManager,
    ICompilationUnit movedUnit,
    IProgressMonitor pm,
    RefactoringStatus status)
    throws JavaModelException, CoreException {
  List<ICompilationUnit> cuList = Arrays.asList(fCus);
  SearchResultGroup[] references = getReferences(movedUnit, pm, status);
  for (int i = 0; i < references.length; i++) {
    SearchResultGroup searchResultGroup = references[i];
    ICompilationUnit referencingCu = searchResultGroup.getCompilationUnit();
    if (referencingCu == null) continue;

    boolean simpleReferencesNeedNewImport =
        simpleReferencesNeedNewImport(movedUnit, referencingCu, cuList);
    SearchMatch[] results = searchResultGroup.getSearchResults();
    for (int j = 0; j < results.length; j++) {
      // TODO: should update type references with results from addImport
      TypeReference reference = (TypeReference) results[j];
      if (reference.isImportDeclaration()) {
        ImportRewrite rewrite = getImportRewrite(referencingCu);
        IImportDeclaration importDecl =
            (IImportDeclaration) SearchUtils.getEnclosingJavaElement(results[j]);
        if (Flags.isStatic(importDecl.getFlags())) {
          rewrite.removeStaticImport(importDecl.getElementName());
          addStaticImport(movedUnit, importDecl, rewrite);
        } else {
          rewrite.removeImport(importDecl.getElementName());
          rewrite.addImport(createStringForNewImport(movedUnit, importDecl));
        }
      } else if (reference.isQualified()) {
        TextChange textChange = changeManager.get(referencingCu);
        String changeName = RefactoringCoreMessages.MoveCuUpdateCreator_update_references;
        TextEdit replaceEdit =
            new ReplaceEdit(
                reference.getOffset(),
                reference.getSimpleNameStart() - reference.getOffset(),
                fNewPackage);
        TextChangeCompatibility.addTextEdit(textChange, changeName, replaceEdit);
      } else if (simpleReferencesNeedNewImport) {
        ImportRewrite importEdit = getImportRewrite(referencingCu);
        String typeName = reference.getSimpleName();
        importEdit.addImport(getQualifiedType(fDestination.getElementName(), typeName));
      }
    }
  }
}
 
开发者ID:eclipse,项目名称:che,代码行数:48,代码来源:MoveCuUpdateCreator.java


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