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


Java OrganizeImportsOperation.createTextEdit方法代码示例

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


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

示例1: createOrganizeImportOperation

import org.eclipse.jdt.internal.corext.codemanipulation.OrganizeImportsOperation; //导入方法依赖的package包/类
private OrganizeImportResult createOrganizeImportOperation(
    ICompilationUnit compilationUnit, List<String> chosen) throws CoreException {
  CodeGenerationSettings settings =
      JavaPreferencesSettings.getCodeGenerationSettings(compilationUnit.getJavaProject());

  OrganizeImportsOperation operation =
      new OrganizeImportsOperation(
          compilationUnit,
          null,
          settings.importIgnoreLowercase,
          !compilationUnit.isWorkingCopy(),
          true,
          chosen,
          null);

  NullProgressMonitor monitor = new NullProgressMonitor();
  TextEdit edit = operation.createTextEdit(monitor);
  OrganizeImportResult result = DtoFactory.newDto(OrganizeImportResult.class);
  TypeNameMatch[][] choices = operation.getChoices();
  // Apply organize import declarations if operation doesn't have conflicts (choices.length == 0)
  // or all conflicts were resolved (!chosen.isEmpty())
  if ((chosen != null && !chosen.isEmpty()) || choices == null || choices.length == 0) {
    IBuffer buffer = compilationUnit.getBuffer();
    IDocument document = new Document(buffer.getContents());
    DocumentChangeListener documentChangeListener = new DocumentChangeListener(document);
    try {
      edit.apply(document);
    } catch (BadLocationException e) {
      LOG.debug("Applying Organize import text edits goes wrong:", e);
    }
    result.setChanges(documentChangeListener.getChanges());
    return result;
  }

  result.setConflicts(createListOfDTOMatches(choices));
  return result;
}
 
开发者ID:eclipse,项目名称:che,代码行数:38,代码来源:CodeAssist.java

示例2: createCleanUp

import org.eclipse.jdt.internal.corext.codemanipulation.OrganizeImportsOperation; //导入方法依赖的package包/类
public static ICleanUpFix createCleanUp(final CompilationUnit cu, CodeGenerationSettings settings, boolean organizeImports, RefactoringStatus status) throws CoreException {
if (!organizeImports)
	return null;

final boolean hasAmbiguity[]= new boolean[] { false };
IChooseImportQuery query= new IChooseImportQuery() {
	public TypeNameMatch[] chooseImports(TypeNameMatch[][] openChoices, ISourceRange[] ranges) {
		hasAmbiguity[0]= true;
		return new TypeNameMatch[0];
	}
};

final ICompilationUnit unit= (ICompilationUnit)cu.getJavaElement();
OrganizeImportsOperation op= new OrganizeImportsOperation(unit, cu, settings.importIgnoreLowercase, false, false, query);
final TextEdit edit= op.createTextEdit(null);
if (hasAmbiguity[0]) {
	status.addInfo(Messages.format(ActionMessages.OrganizeImportsAction_multi_error_unresolvable, getLocationString(cu)));
}

if (op.getParseError() != null) {
	status.addInfo(Messages.format(ActionMessages.OrganizeImportsAction_multi_error_parse, getLocationString(cu)));
	return null;
}

if (edit == null || (edit instanceof MultiTextEdit && edit.getChildrenSize() == 0))
	return null;

return new ImportsFix(edit, unit, FixMessages.ImportsFix_OrganizeImports_Description);
  }
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:30,代码来源:ImportsFix.java


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