Search in sources :

Example 1 with ReplaceFileContentChange

use of org.eclipse.xtext.ui.refactoring2.ReplaceFileContentChange in project xtext-eclipse by eclipse.

the class ChangeConverter method _handleReplacements.

protected void _handleReplacements(final IEmfResourceChange change) {
    final ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
    final Procedure0 _function = () -> {
        try {
            final IFile file = this.resourceUriConverter.toFile(change.getResource().getURI());
            boolean _canWrite = this.canWrite(file);
            boolean _not = (!_canWrite);
            if (_not) {
                StringConcatenation _builder = new StringConcatenation();
                _builder.append("Affected file \'");
                IPath _fullPath = file.getFullPath();
                _builder.append(_fullPath);
                _builder.append("\' is read-only");
                this.issues.add(RefactoringIssueAcceptor.Severity.ERROR, _builder.toString());
            }
            this.checkDerived(file);
            change.getResource().save(outputStream, null);
            final byte[] newContent = outputStream.toByteArray();
            String _lastSegment = change.getOldURI().lastSegment();
            final ReplaceFileContentChange ltkChange = new ReplaceFileContentChange(_lastSegment, file, newContent);
            this.addChange(ltkChange);
        } catch (Throwable _e) {
            throw Exceptions.sneakyThrow(_e);
        }
    };
    TryWithResource.tryWith(outputStream, _function);
}
Also used : IFile(org.eclipse.core.resources.IFile) Procedure0(org.eclipse.xtext.xbase.lib.Procedures.Procedure0) IPath(org.eclipse.core.runtime.IPath) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ReplaceFileContentChange(org.eclipse.xtext.ui.refactoring2.ReplaceFileContentChange)

Aggregations

ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 IFile (org.eclipse.core.resources.IFile)1 IPath (org.eclipse.core.runtime.IPath)1 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)1 ReplaceFileContentChange (org.eclipse.xtext.ui.refactoring2.ReplaceFileContentChange)1 Procedure0 (org.eclipse.xtext.xbase.lib.Procedures.Procedure0)1