mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
Bug Fixing
This commit is contained in:
parent
889a492487
commit
395aab5426
3 changed files with 46 additions and 9 deletions
|
@ -1,3 +1,9 @@
|
||||||
|
2004-06-21 Hoda Amer
|
||||||
|
Fix for PR 67696: [I18N] - New Class Wizard does not take project encoding into account when creating files
|
||||||
|
Now the encoding is taken into consideration when committing a working copy contents to a file.
|
||||||
|
* model/org/eclipse/cdt/internal/core/model/Buffer.java
|
||||||
|
* model/org/eclipse/cdt/internal/core/model/WorkingCopy.java
|
||||||
|
|
||||||
2004-06-18 Alain Magloire
|
2004-06-18 Alain Magloire
|
||||||
|
|
||||||
Fix for PR 66108
|
Fix for PR 66108
|
||||||
|
|
|
@ -12,11 +12,15 @@ package org.eclipse.cdt.internal.core.model;
|
||||||
***********************************************************************/
|
***********************************************************************/
|
||||||
|
|
||||||
import java.io.ByteArrayInputStream;
|
import java.io.ByteArrayInputStream;
|
||||||
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
import org.eclipse.cdt.core.ICLogConstants;
|
import org.eclipse.cdt.core.ICLogConstants;
|
||||||
import org.eclipse.cdt.core.model.*;
|
import org.eclipse.cdt.core.model.BufferChangedEvent;
|
||||||
import org.eclipse.cdt.core.model.CModelException;
|
import org.eclipse.cdt.core.model.CModelException;
|
||||||
|
import org.eclipse.cdt.core.model.IBuffer;
|
||||||
|
import org.eclipse.cdt.core.model.IBufferChangedListener;
|
||||||
|
import org.eclipse.cdt.core.model.ICModelStatusConstants;
|
||||||
import org.eclipse.cdt.core.model.IOpenable;
|
import org.eclipse.cdt.core.model.IOpenable;
|
||||||
import org.eclipse.core.resources.IFile;
|
import org.eclipse.core.resources.IFile;
|
||||||
import org.eclipse.core.resources.IResource;
|
import org.eclipse.core.resources.IResource;
|
||||||
|
@ -300,15 +304,30 @@ public class Buffer implements IBuffer {
|
||||||
|
|
||||||
// use a platform operation to update the resource contents
|
// use a platform operation to update the resource contents
|
||||||
try {
|
try {
|
||||||
|
String encoding = null;
|
||||||
|
try {
|
||||||
|
encoding = this.file.getCharset();
|
||||||
|
}
|
||||||
|
catch (CoreException ce) {
|
||||||
|
// use no encoding
|
||||||
|
}
|
||||||
String contents = this.getContents();
|
String contents = this.getContents();
|
||||||
if (contents == null) return;
|
if (contents == null) return;
|
||||||
byte[] bytes = contents.getBytes();
|
byte[] bytes = encoding == null
|
||||||
|
? contents.getBytes()
|
||||||
|
: contents.getBytes(encoding);
|
||||||
ByteArrayInputStream stream = new ByteArrayInputStream(bytes);
|
ByteArrayInputStream stream = new ByteArrayInputStream(bytes);
|
||||||
|
|
||||||
|
if (this.file.exists()) {
|
||||||
this.file.setContents(
|
this.file.setContents(
|
||||||
stream,
|
stream,
|
||||||
force ? IResource.FORCE | IResource.KEEP_HISTORY : IResource.KEEP_HISTORY,
|
force ? IResource.FORCE | IResource.KEEP_HISTORY : IResource.KEEP_HISTORY,
|
||||||
null);
|
null);
|
||||||
|
} else {
|
||||||
|
this.file.create(stream, force, null);
|
||||||
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new CModelException(e, ICModelStatusConstants.IO_EXCEPTION);
|
||||||
}
|
}
|
||||||
catch (CoreException e) {
|
catch (CoreException e) {
|
||||||
throw new CModelException(e);
|
throw new CModelException(e);
|
||||||
|
|
|
@ -12,6 +12,7 @@ package org.eclipse.cdt.internal.core.model;
|
||||||
***********************************************************************/
|
***********************************************************************/
|
||||||
|
|
||||||
import java.io.ByteArrayInputStream;
|
import java.io.ByteArrayInputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
import org.eclipse.cdt.core.model.CModelException;
|
import org.eclipse.cdt.core.model.CModelException;
|
||||||
import org.eclipse.cdt.core.model.IBuffer;
|
import org.eclipse.cdt.core.model.IBuffer;
|
||||||
|
@ -83,9 +84,18 @@ public class WorkingCopy extends TranslationUnit implements IWorkingCopy {
|
||||||
String contents = this.getSource();
|
String contents = this.getSource();
|
||||||
if (contents == null) return;
|
if (contents == null) return;
|
||||||
try {
|
try {
|
||||||
byte[] bytes = contents.getBytes();
|
|
||||||
ByteArrayInputStream stream = new ByteArrayInputStream(bytes);
|
|
||||||
IFile originalRes = (IFile)original.getResource();
|
IFile originalRes = (IFile)original.getResource();
|
||||||
|
String encoding = null;
|
||||||
|
try {
|
||||||
|
encoding = originalRes.getCharset();
|
||||||
|
}
|
||||||
|
catch (CoreException ce) {
|
||||||
|
// use no encoding
|
||||||
|
}
|
||||||
|
byte[] bytes = encoding == null
|
||||||
|
? contents.getBytes()
|
||||||
|
: contents.getBytes(encoding);
|
||||||
|
ByteArrayInputStream stream = new ByteArrayInputStream(bytes);
|
||||||
if (originalRes.exists()) {
|
if (originalRes.exists()) {
|
||||||
originalRes.setContents(
|
originalRes.setContents(
|
||||||
stream,
|
stream,
|
||||||
|
@ -97,6 +107,8 @@ public class WorkingCopy extends TranslationUnit implements IWorkingCopy {
|
||||||
force,
|
force,
|
||||||
monitor);
|
monitor);
|
||||||
}
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new CModelException(e, ICModelStatusConstants.IO_EXCEPTION);
|
||||||
} catch (CoreException e) {
|
} catch (CoreException e) {
|
||||||
throw new CModelException(e);
|
throw new CModelException(e);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue