From 9c930dfff34c4bda67fcc8bc686f3f7f078e6130 Mon Sep 17 00:00:00 2001 From: Sergey Prigogin Date: Tue, 17 May 2011 22:28:18 +0000 Subject: [PATCH] Cosmetics. --- .../cdt/internal/core/model/WorkingCopy.java | 74 +++++++++---------- 1 file changed, 36 insertions(+), 38 deletions(-) diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/WorkingCopy.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/WorkingCopy.java index 08346c670b4..7ffb7c117d2 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/WorkingCopy.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/WorkingCopy.java @@ -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);