private List<TextEdit> handleSaveActionOrganizeImports(String documentUri, IProgressMonitor monitor) { String uri = ResourceUtils.fixURI(JDTUtils.toURI(documentUri)); if (monitor.isCanceled()) { return Collections.emptyList(); } WorkspaceEdit organizedResult = organizeImportsCommand.organizeImportsInFile(uri); List<TextEdit> edit = organizedResult.getChanges().get(uri); edit = edit == null ? Collections.emptyList() : edit; return edit; }
/** * Returns uri for a resource * @param resource * @return */ public static String getFileURI(IResource resource) { return ResourceUtils.fixURI(resource.getRawLocationURI() == null ? resource.getLocationURI() : resource.getRawLocationURI()); }
@Override public void elementChanged(ElementChangedEvent event) { final Set<IProject> projects = getAffectedProjects(event.getDelta(), new HashSet<IProject>()); if (projects.isEmpty()) { return; } try { final Set<String> projectLocations = new HashSet<String>(); for (final IProject project : projects) { projectLocations.add(ResourceUtils.fixURI(project.getLocationURI())); } final JDTLanguageServer ls = JavaLanguageServerPlugin.getInstance().getProtocol(); ls.getClientConnection().sendNotification(CLIENT_UPDATE_CLASSPATH, (Object[]) projectLocations.toArray(new String[projectLocations.size()])); } catch (final Exception e) { // Ignore. JavaLanguageServerPlugin.logException("An exception occured while reporting project CLASSPATH change", e); } }
private static void convertCUResourceChange(WorkspaceEdit edit, RenameCompilationUnitChange cuChange) { ICompilationUnit modifiedCU = (ICompilationUnit) cuChange.getModifiedElement(); RenameFile rf = new RenameFile(); String newCUName = cuChange.getNewName(); IPath currentPath = modifiedCU.getResource().getLocation(); rf.setOldUri(ResourceUtils.fixURI(modifiedCU.getResource().getRawLocationURI())); IPath newPath = currentPath.removeLastSegments(1).append(newCUName); rf.setNewUri(ResourceUtils.fixURI(newPath.toFile().toURI())); edit.getDocumentChanges().add(Either.forRight(rf)); }
renameFile.setNewUri(ResourceUtils.fixURI(newPackagePath.toFile().toURI())); renameFile.setOldUri(ResourceUtils.fixURI(pack.getResource().getRawLocationURI())); edit.getDocumentChanges().add(Either.forRight(renameFile)); } else { CreateFile createFile = new CreateFile(); createFile.setUri(ResourceUtils.fixURI(newPackagePath.append(TEMP_FILE_NAME).toFile().toURI())); createFile.setOptions(new CreateFileOptions(false, true)); edit.getDocumentChanges().add(Either.forRight(createFile)); cuResourceChange.setOldUri(ResourceUtils.fixURI(unit.getResource().getLocationURI())); IPath newCUPath = newPackagePath.append(unit.getPath().lastSegment()); cuResourceChange.setNewUri(ResourceUtils.fixURI(newCUPath.toFile().toURI())); edit.getDocumentChanges().add(Either.forRight(cuResourceChange)); deleteFile.setUri(ResourceUtils.fixURI(newPackagePath.append(TEMP_FILE_NAME).toFile().toURI())); deleteFile.setOptions(new DeleteFileOptions(false, true)); edit.getDocumentChanges().add(Either.forRight(deleteFile));