use of org.eclipse.che.ide.ext.java.shared.dto.OrganizeImportResult in project che by eclipse.
the class CodeAssist method createOrganizeImportOperation.
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();
//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;
}
use of org.eclipse.che.ide.ext.java.shared.dto.OrganizeImportResult in project che by eclipse.
the class CodeAssist method applyChosenImports.
/**
* Applies chosen imports after resolving conflicts.
*
* @param project
* current java project
* @param fqn
* fully qualified name of the java file
* @param chosen
* list of chosen imports as result of resolving conflicts which needed to add to all imports.
*/
public List<Change> applyChosenImports(IJavaProject project, String fqn, List<String> chosen) throws CoreException, BadLocationException {
ICompilationUnit compilationUnit = prepareCompilationUnit(project, fqn);
OrganizeImportResult result = createOrganizeImportOperation(compilationUnit, chosen);
return result.getChanges();
}
Aggregations