private void organizeImports(ICompilationUnit cu) throws OperationCanceledException, CoreException { cu.becomeWorkingCopy(null); CompilationUnit unit = cu.reconcile(AST.JLS4, false, null, pm); NullProgressMonitor pm = new NullProgressMonitor(); OrganizeImportsOperation op = new OrganizeImportsOperation(cu, unit, true, true, true, null); TextEdit edit = op.createTextEdit(pm); if (edit == null) { return; } JavaModelUtil.applyEdit(cu, edit, true, pm); cu.commitWorkingCopy(true, pm); cu.save(pm, true); }
private void saveChanges(ICompilationUnit copy, CompilationUnit unit) throws JavaModelException, MalformedTreeException, BadLocationException { Document document= new Document(copy.getBuffer().getContents()); TextEdit edits = unit.rewrite(document, copy.getJavaProject().getOptions(true)); edits.apply(document); copy.getBuffer().setContents(document.get()); copy.save(null, false); }
private void saveContent(PackageFragment dest, String destName, TextEdit edits, String sourceEncoding, IFile destFile) throws JavaModelException { try { // TODO (frederic) remove when bug 67606 will be fixed (bug 67823) // fix bug 66898 if (sourceEncoding != null) destFile.setCharset(sourceEncoding, this.progressMonitor); // end todo } catch (CoreException ce) { // use no encoding } // when the file was copied, its read-only flag was preserved -> temporary set it to false // note this doesn't interfere with repository providers as this is a new resource that cannot be under // version control yet Util.setReadOnly(destFile, false); ICompilationUnit destCU = dest.getCompilationUnit(destName); applyTextEdit(destCU, edits); destCU.save(getSubProgressMonitor(1), this.force); } /**
/** * Applies an text edit to a compilation unit. Filed bug 117694 against jdt.core. * @param cu the compilation unit to apply the edit to * @param edit the edit to apply * @param save is set, save the CU after the edit has been applied * @param monitor the progress monitor to use * @throws CoreException Thrown when the access to the CU failed * @throws ValidateEditException if validate edit fails */ public static void applyEdit(ICompilationUnit cu, TextEdit edit, boolean save, IProgressMonitor monitor) throws CoreException, ValidateEditException { IFile file= (IFile) cu.getResource(); if (!save || !file.exists()) { cu.applyTextEdit(edit, monitor); } else { if (monitor == null) { monitor= new NullProgressMonitor(); } monitor.beginTask(CorextMessages.JavaModelUtil_applyedit_operation, 2); try { IStatus status= Resources.makeCommittable(file, null); if (!status.isOK()) { throw new ValidateEditException(status); } cu.applyTextEdit(edit, new SubProgressMonitor(monitor, 1)); cu.save(new SubProgressMonitor(monitor, 1), true); } finally { monitor.done(); } } }
private void saveContent(PackageFragment dest, String destName, TextEdit edits, String sourceEncoding, IFile destFile) throws JavaModelException { try { // TODO (frederic) remove when bug 67606 will be fixed (bug 67823) // fix bug 66898 if (sourceEncoding != null) destFile.setCharset(sourceEncoding, this.progressMonitor); // end todo } catch (CoreException ce) { // use no encoding } // when the file was copied, its read-only flag was preserved -> temporary set it to false // note this doesn't interfere with repository providers as this is a new resource that cannot be under // version control yet Util.setReadOnly(destFile, false); ICompilationUnit destCU = dest.getCompilationUnit(destName); applyTextEdit(destCU, edits); destCU.save(getSubProgressMonitor(1), this.force); } /**
private void saveContent(PackageFragment dest, String destName, TextEdit edits, String sourceEncoding, IFile destFile) throws JavaModelException { try { // TODO (frederic) remove when bug 67606 will be fixed (bug 67823) // fix bug 66898 if (sourceEncoding != null) destFile.setCharset(sourceEncoding, this.progressMonitor); // end todo } catch (CoreException ce) { // use no encoding } // when the file was copied, its read-only flag was preserved -> temporary set it to false // note this doesn't interfere with repository providers as this is a new resource that cannot be under // version control yet Util.setReadOnly(destFile, false); ICompilationUnit destCU = dest.getCompilationUnit(destName); applyTextEdit(destCU, edits); destCU.save(getSubProgressMonitor(1), this.force); } /**
private void saveContent(PackageFragment dest, String destName, TextEdit edits, String sourceEncoding, IFile destFile) throws JavaModelException { try { // TODO (frederic) remove when bug 67606 will be fixed (bug 67823) // fix bug 66898 if (sourceEncoding != null) destFile.setCharset(sourceEncoding, this.progressMonitor); // end todo } catch (CoreException ce) { // use no encoding } // when the file was copied, its read-only flag was preserved -> temporary set it to false // note this doesn't interfere with repository providers as this is a new resource that cannot be under // version control yet Util.setReadOnly(destFile, false); ICompilationUnit destCU = dest.getCompilationUnit(destName); applyTextEdit(destCU, edits); destCU.save(getSubProgressMonitor(1), this.force); } /**
private void saveContent(PackageFragment dest, String destName, TextEdit edits, String sourceEncoding, IFile destFile) throws JavaModelException { try { // TODO (frederic) remove when bug 67606 will be fixed (bug 67823) // fix bug 66898 if (sourceEncoding != null) destFile.setCharset(sourceEncoding, this.progressMonitor); // end todo } catch (CoreException ce) { // use no encoding } // when the file was copied, its read-only flag was preserved -> temporary set it to false // note this doesn't interfere with repository providers as this is a new resource that cannot be under // version control yet Util.setReadOnly(destFile, false); ICompilationUnit destCU = dest.getCompilationUnit(destName); applyTextEdit(destCU, edits); destCU.save(getSubProgressMonitor(1), this.force); } /**
private void saveContent(PackageFragment dest, String destName, TextEdit edits, String sourceEncoding, IFile destFile) throws JavaModelException { try { // TODO (frederic) remove when bug 67606 will be fixed (bug 67823) // fix bug 66898 if (sourceEncoding != null) destFile.setCharset(sourceEncoding, this.progressMonitor); // end todo } catch (CoreException ce) { // use no encoding } // when the file was copied, its read-only flag was preserved -> temporary set it to false // note this doesn't interfere with repository providers as this is a new resource that cannot be under // version control yet Util.setReadOnly(destFile, false); ICompilationUnit destCU = dest.getCompilationUnit(destName); applyTextEdit(destCU, edits); destCU.save(getSubProgressMonitor(1), this.force); } /**
cu.save(getSubProgressMonitor(1), this.force); if (!cu.isWorkingCopy()) { // if unit is working copy, then save will have already fired the delta addDelta(delta);
cu.save(getSubProgressMonitor(1), this.force); if (!cu.isWorkingCopy()) { // if unit is working copy, then save will have already fired the delta addDelta(delta);
cu.save(getSubProgressMonitor(1), this.force); if (!cu.isWorkingCopy()) { // if unit is working copy, then save will have already fired the delta addDelta(delta);
cu.save(getSubProgressMonitor(1), this.force); if (!cu.isWorkingCopy()) { // if unit is working copy, then save will have already fired the delta addDelta(delta);
cu.save(getSubProgressMonitor(1), this.force); if (!cu.isWorkingCopy()) { // if unit is working copy, then save will have already fired the delta addDelta(delta);
/** * Applies a text edit to a compilation unit. * * @param cu the compilation unit to apply the edit to * @param edit the edit to apply * @param save is set, save the CU after the edit has been applied * @param monitor the progress monitor to use * @throws CoreException Thrown when the access to the CU failed * @throws ValidateEditException if validate edit fails */ public static void applyEdit(ICompilationUnit cu, TextEdit edit, boolean save, IProgressMonitor monitor) throws CoreException, ValidateEditException { SubMonitor subMonitor= SubMonitor.convert(monitor, JavaManipulationMessages.JavaModelUtil_applyedit_operation, 2); IFile file= (IFile) cu.getResource(); if (!save || !file.exists()) { cu.applyTextEdit(edit, subMonitor.split(2)); } else { IStatus status= Resources.makeCommittable(new IResource [] {file}, null); if (!status.isOK()) { throw new ValidateEditException(status); } cu.applyTextEdit(edit, subMonitor.split(1)); cu.save(subMonitor.split(1), true); } } }
if (this.creationOccurred) { unit.save(null, false); boolean isWorkingCopy = unit.isWorkingCopy(); if (!isWorkingCopy)
if (this.creationOccurred) { unit.save(null, false); boolean isWorkingCopy = unit.isWorkingCopy(); if (!isWorkingCopy)
if (this.creationOccurred) { unit.save(null, false); boolean isWorkingCopy = unit.isWorkingCopy(); if (!isWorkingCopy)
if (this.creationOccurred) { unit.save(null, false); boolean isWorkingCopy = unit.isWorkingCopy(); if (!isWorkingCopy)
if (this.creationOccurred) { unit.save(null, false); boolean isWorkingCopy = unit.isWorkingCopy(); if (!isWorkingCopy)