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