1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +02:00

Cosmetics.

This commit is contained in:
Sergey Prigogin 2011-05-17 22:28:18 +00:00
parent 24d1fac035
commit 9c930dfff3

View file

@ -6,9 +6,9 @@
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Rational Software - Initial API and implementation
* Markus Schorn (Wind River Systems)
* Anton Leherbauer (Wind River Systems)
* Rational Software - Initial API and implementation
* Markus Schorn (Wind River Systems)
* Anton Leherbauer (Wind River Systems)
*******************************************************************************/
package org.eclipse.cdt.internal.core.model;
@ -59,6 +59,7 @@ public class WorkingCopy extends TranslationUnit implements IWorkingCopy {
public WorkingCopy(ICElement parent, IFile file, String id, IBufferFactory bufferFactory) {
this(parent, file, id, bufferFactory, null);
}
public WorkingCopy(ICElement parent, IFile file, String id, IBufferFactory bufferFactory, IProblemRequestor requestor) {
super(parent, file, id);
this.bufferFactory =
@ -79,45 +80,41 @@ public class WorkingCopy extends TranslationUnit implements IWorkingCopy {
/**
* @see org.eclipse.cdt.core.model.IWorkingCopy#commit(boolean, org.eclipse.core.runtime.IProgressMonitor)
*/
public void commit(boolean force, IProgressMonitor monitor)
throws CModelException {
ITranslationUnit original = this.getOriginalElement();
if (original.exists()) {
CommitWorkingCopyOperation op= new CommitWorkingCopyOperation(this, force);
op.runOperation(monitor);
} else {
String contents = this.getSource();
if (contents == null) return;
public void commit(boolean force, IProgressMonitor monitor) throws CModelException {
ITranslationUnit original = this.getOriginalElement();
if (original.exists()) {
CommitWorkingCopyOperation op= new CommitWorkingCopyOperation(this, force);
op.runOperation(monitor);
} else {
String contents = this.getSource();
if (contents == null) return;
try {
IFile originalRes = (IFile)original.getResource();
String encoding = null;
try {
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()) {
originalRes.setContents(
encoding = originalRes.getCharset();
} catch (CoreException e) {
// use no encoding
}
byte[] bytes = encoding == null ? contents.getBytes() : contents.getBytes(encoding);
ByteArrayInputStream stream = new ByteArrayInputStream(bytes);
if (originalRes.exists()) {
originalRes.setContents(
stream,
force ? IResource.FORCE | IResource.KEEP_HISTORY : IResource.KEEP_HISTORY,
null);
} else {
originalRes.create(
null);
} else {
originalRes.create(
stream,
force,
monitor);
}
} catch (IOException e) {
throw new CModelException(e, ICModelStatusConstants.IO_EXCEPTION);
} catch (CoreException e) {
throw new CModelException(e);
}
}
} catch (IOException e) {
throw new CModelException(e, ICModelStatusConstants.IO_EXCEPTION);
} catch (CoreException e) {
throw new CModelException(e);
}
}
}
/**
@ -271,6 +268,7 @@ public class WorkingCopy extends TranslationUnit implements IWorkingCopy {
return false;
}
}
/**
* @see org.eclipse.cdt.core.model.ITranslationUnit#isWorkingCopy()
*/
@ -394,8 +392,7 @@ public class WorkingCopy extends TranslationUnit implements IWorkingCopy {
long timeStamp =
((IFile) original.getResource()).getModificationStamp();
if (timeStamp == IResource.NULL_STAMP) {
throw new CModelException(
new CModelStatus(ICModelStatusConstants.INVALID_RESOURCE));
throw new CModelException(new CModelStatus(ICModelStatusConstants.INVALID_RESOURCE));
}
((TranslationUnitInfo) getElementInfo()).fTimestamp = timeStamp;
}
@ -405,7 +402,8 @@ public class WorkingCopy extends TranslationUnit implements IWorkingCopy {
*/
public IASTTranslationUnit reconcile(boolean computeAST, boolean forceProblemDetection, IProgressMonitor monitor)
throws CModelException {
if (this.useCount == 0) throw newNotPresentException(); // was destroyed
if (this.useCount == 0)
throw newNotPresentException(); // was destroyed
ReconcileWorkingCopyOperation op = new ReconcileWorkingCopyOperation(this, computeAST, forceProblemDetection);
op.runOperation(monitor);