1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-08-01 13:25:45 +02:00

Cosmetics.

This commit is contained in:
Sergey Prigogin 2015-01-07 11:39:03 -08:00
parent 4a2b680255
commit 509d7cd337
3 changed files with 53 additions and 59 deletions

View file

@ -50,7 +50,7 @@ public class CreateWorkingCopyOperation extends CModelOperation {
} else { } else {
workingCopy= new WorkingCopy(tu.getParent(), tu.getLocationURI(), tu.getContentTypeId(), this.factory); workingCopy= new WorkingCopy(tu.getParent(), tu.getLocationURI(), tu.getContentTypeId(), this.factory);
} }
// open the working copy now to ensure contents are that of the current state of this element // Open the working copy now to ensure contents are that of the current state of this element.
// Alain: Actually no, delay the parsing 'till it is really needed. Doing the parsing here // Alain: Actually no, delay the parsing 'till it is really needed. Doing the parsing here
// really slows down the opening of the CEditor. // really slows down the opening of the CEditor.
//workingCopy.open(this.fMonitor); //workingCopy.open(this.fMonitor);
@ -62,7 +62,7 @@ public class CreateWorkingCopyOperation extends CModelOperation {
//} //}
} }
// report added java delta // Report added C delta.
CElementDelta delta = new CElementDelta(this.getCModel()); CElementDelta delta = new CElementDelta(this.getCModel());
delta.added(workingCopy); delta.added(workingCopy);
addDelta(delta); addDelta(delta);

View file

@ -43,23 +43,23 @@ public class WorkingCopy extends TranslationUnit implements IWorkingCopy {
*/ */
protected IBufferFactory bufferFactory; protected IBufferFactory bufferFactory;
/** /**
* A counter of the number of time clients have asked for this * A counter of the number of time clients have asked for this working copy.
* working copy. It is set to 1, if the working * It is set to 1, if the working copy is not managed. When destroyed, this
* copy is not managed. When destroyed, this counter is * counter is set to 0. Once destroyed, this working copy cannot be opened
* set to 0. Once destroyed, this working copy cannot be opened * and non-handle info can not be accessed. This is never true if this
* and non-handle info can not be accessed. This is * translation unit is not a working copy.
* never true if this translation unit is not a working copy.
*/ */
protected int useCount = 1; protected int useCount = 1;
/** /**
* Creates a working copy of this element * Creates a working copy of this element.
*/ */
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 = bufferFactory == null ? getBufferManager() : bufferFactory; this.bufferFactory = bufferFactory == null ? getBufferManager() : bufferFactory;
problemRequestor = requestor; problemRequestor = requestor;
@ -170,7 +170,7 @@ public class WorkingCopy extends TranslationUnit implements IWorkingCopy {
// Look for it. // Look for it.
ICElement element = workingCopyElement; ICElement element = workingCopyElement;
ArrayList<ICElement> children = new ArrayList<ICElement>(); ArrayList<ICElement> children = new ArrayList<>();
while (element != null && element.getElementType() != ICElement.C_UNIT) { while (element != null && element.getElementType() != ICElement.C_UNIT) {
children.add(element); children.add(element);
element = element.getParent(); element = element.getParent();
@ -232,7 +232,7 @@ public class WorkingCopy extends TranslationUnit implements IWorkingCopy {
return false; return false;
} }
try { try {
// If resource got deleted, then #getModificationStamp() will answer // If resource got deleted, then getModificationStamp() will answer
// IResource.NULL_STAMP, which is always different from the cached timestamp. // IResource.NULL_STAMP, which is always different from the cached timestamp.
return ((TranslationUnitInfo) getElementInfo()).fTimestamp == ((IFile) resource).getModificationStamp(); return ((TranslationUnitInfo) getElementInfo()).fTimestamp == ((IFile) resource).getModificationStamp();
} catch (CModelException e) { } catch (CModelException e) {
@ -272,19 +272,19 @@ public class WorkingCopy extends TranslationUnit implements IWorkingCopy {
if (this.useCount == 0) if (this.useCount == 0)
throw newNotPresentException(); throw newNotPresentException();
// Create buffer - working copies may use custom buffer factory // Create buffer - working copies may use custom buffer factory.
IBuffer buffer = getBufferFactory().createBuffer(this); IBuffer buffer = getBufferFactory().createBuffer(this);
if (buffer == null) if (buffer == null)
return null; return null;
// Set the buffer source if needed // Set the buffer source if needed.
if (buffer.getContents() == null) { if (buffer.getContents() == null) {
ITranslationUnit original= this.getOriginalElement(); ITranslationUnit original= this.getOriginalElement();
IBuffer originalBuffer = null; IBuffer originalBuffer = null;
try { try {
originalBuffer = original.getBuffer(); originalBuffer = original.getBuffer();
} catch (CModelException e) { } catch (CModelException e) {
// Original element does not exist: create an empty working copy // Original element does not exist: create an empty working copy.
if (!e.getCModelStatus().doesNotExist()) { if (!e.getCModelStatus().doesNotExist()) {
throw e; throw e;
} }
@ -295,15 +295,15 @@ public class WorkingCopy extends TranslationUnit implements IWorkingCopy {
buffer.setContents(originalContents.clone()); buffer.setContents(originalContents.clone());
} }
} else { } else {
// Initialize buffer // Initialize buffer.
buffer.setContents(new char[0]); buffer.setContents(new char[0]);
} }
} }
// Add buffer to buffer cache // Add buffer to buffer cache.
this.getBufferManager().addBuffer(buffer); this.getBufferManager().addBuffer(buffer);
// Listen to buffer changes // Listen to buffer changes.
buffer.addBufferChangedListener(this); buffer.addBufferChangedListener(this);
return buffer; return buffer;
@ -323,7 +323,7 @@ public class WorkingCopy extends TranslationUnit implements IWorkingCopy {
@Override @Override
public void restore() throws CModelException{ public void restore() throws CModelException{
if (this.useCount == 0) if (this.useCount == 0)
throw newNotPresentException(); // Was destroyed throw newNotPresentException(); // Was destroyed.
TranslationUnit original = (TranslationUnit) getOriginalElement(); TranslationUnit original = (TranslationUnit) getOriginalElement();
IBuffer buffer = this.getBuffer(); IBuffer buffer = this.getBuffer();
@ -338,15 +338,11 @@ public class WorkingCopy extends TranslationUnit implements IWorkingCopy {
if (isReadOnly()) { if (isReadOnly()) {
throw new CModelException(new CModelStatus(ICModelStatusConstants.READ_ONLY, this)); throw new CModelException(new CModelStatus(ICModelStatusConstants.READ_ONLY, this));
} }
// Computes fine-grain deltas in case the working copy is being reconciled already // Compute fine-grain deltas in case the working copy is being reconciled already
// (if not it would miss one iteration of deltas). // (if not it would miss one iteration of deltas).
this.reconcile(); this.reconcile();
} }
/**
* @param original
* @throws CModelException
*/
protected void updateTimeStamp(TranslationUnit original) throws CModelException { protected void updateTimeStamp(TranslationUnit original) throws CModelException {
long timeStamp = ((IFile) original.getResource()).getModificationStamp(); long timeStamp = ((IFile) original.getResource()).getModificationStamp();
if (timeStamp == IResource.NULL_STAMP) { if (timeStamp == IResource.NULL_STAMP) {
@ -356,12 +352,13 @@ public class WorkingCopy extends TranslationUnit implements IWorkingCopy {
} }
@Override @Override
public IASTTranslationUnit reconcile(boolean computeAST, boolean forceProblemDetection, IProgressMonitor monitor) public IASTTranslationUnit reconcile(boolean computeAST, boolean forceProblemDetection,
throws CModelException { IProgressMonitor monitor) throws CModelException {
if (this.useCount == 0) if (this.useCount == 0)
throw newNotPresentException(); // was destroyed throw newNotPresentException(); // Was destroyed.
ReconcileWorkingCopyOperation op = new ReconcileWorkingCopyOperation(this, computeAST, forceProblemDetection); ReconcileWorkingCopyOperation op =
new ReconcileWorkingCopyOperation(this, computeAST, forceProblemDetection);
op.runOperation(monitor); op.runOperation(monitor);
return op.fAST; return op.fAST;
} }

View file

@ -14,10 +14,8 @@ package org.eclipse.cdt.internal.ui.editor;
import java.net.URI; import java.net.URI;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Map;
import org.eclipse.core.filebuffers.ITextFileBuffer; import org.eclipse.core.filebuffers.ITextFileBuffer;
import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IFile;
@ -79,7 +77,6 @@ import org.eclipse.ui.texteditor.MarkerUtilities;
import org.eclipse.ui.texteditor.ResourceMarkerAnnotationModel; import org.eclipse.ui.texteditor.ResourceMarkerAnnotationModel;
import org.eclipse.ui.texteditor.spelling.SpellingAnnotation; import org.eclipse.ui.texteditor.spelling.SpellingAnnotation;
import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.dom.ast.IASTNode; import org.eclipse.cdt.core.dom.ast.IASTNode;
import org.eclipse.cdt.core.model.CoreModel; import org.eclipse.cdt.core.model.CoreModel;
import org.eclipse.cdt.core.model.ICModelMarker; import org.eclipse.cdt.core.model.ICModelMarker;
@ -168,7 +165,7 @@ public class CDocumentProvider extends TextFileDocumentProvider {
@Override @Override
public void addOverlaid(ICAnnotation annotation) { public void addOverlaid(ICAnnotation annotation) {
if (fOverlaids == null) if (fOverlaids == null)
fOverlaids= new ArrayList<ICAnnotation>(1); fOverlaids= new ArrayList<>(1);
fOverlaids.add(annotation); fOverlaids.add(annotation);
} }
@ -206,14 +203,13 @@ public class CDocumentProvider extends TextFileDocumentProvider {
* on hash value. * on hash value.
*/ */
protected static class ReverseMap { protected static class ReverseMap {
static class Entry { static class Entry {
Position fPosition; Position fPosition;
Object fValue; Object fValue;
} }
private List<Entry> fList= new ArrayList<Entry>(2); private List<Entry> fList= new ArrayList<>(2);
private int fAnchor= 0; private int fAnchor;
public ReverseMap() { public ReverseMap() {
} }
@ -324,17 +320,17 @@ public class CDocumentProvider extends TextFileDocumentProvider {
List<IProblem> fReportedProblems; List<IProblem> fReportedProblems;
} }
private ThreadLocal<ProblemRequestorState> fProblemRequestorState= new ThreadLocal<ProblemRequestorState>(); private final ThreadLocal<ProblemRequestorState> fProblemRequestorState= new ThreadLocal<>();
private int fStateCount= 0; private int fStateCount;
private ITranslationUnit fTranslationUnit; private ITranslationUnit fTranslationUnit;
private List<ProblemAnnotation> fGeneratedAnnotations; private List<ProblemAnnotation> fGeneratedAnnotations;
private IProgressMonitor fProgressMonitor; private IProgressMonitor fProgressMonitor;
private boolean fIsActive; private boolean fIsActive;
private ReverseMap fReverseMap= new ReverseMap(); private final ReverseMap fReverseMap= new ReverseMap();
private List<CMarkerAnnotation> fPreviouslyOverlaid; private List<CMarkerAnnotation> fPreviouslyOverlaid;
private List<CMarkerAnnotation> fCurrentlyOverlaid= new ArrayList<CMarkerAnnotation>(); private List<CMarkerAnnotation> fCurrentlyOverlaid= new ArrayList<>();
public TranslationUnitAnnotationModel(IResource resource) { public TranslationUnitAnnotationModel(IResource resource) {
super(resource); super(resource);
@ -430,7 +426,7 @@ public class CDocumentProvider extends TextFileDocumentProvider {
if (fTranslationUnit != null) { if (fTranslationUnit != null) {
ProblemRequestorState state= new ProblemRequestorState(); ProblemRequestorState state= new ProblemRequestorState();
state.fInsideReportingSequence= insideReportingSequence; state.fInsideReportingSequence= insideReportingSequence;
state.fReportedProblems= new ArrayList<IProblem>(); state.fReportedProblems= new ArrayList<>();
synchronized (getLockObject()) { synchronized (getLockObject()) {
fProblemRequestorState.set(state); fProblemRequestorState.set(state);
++fStateCount; ++fStateCount;
@ -497,7 +493,7 @@ public class CDocumentProvider extends TextFileDocumentProvider {
boolean isCanceled= false; boolean isCanceled= false;
fPreviouslyOverlaid= fCurrentlyOverlaid; fPreviouslyOverlaid= fCurrentlyOverlaid;
fCurrentlyOverlaid= new ArrayList<CMarkerAnnotation>(); fCurrentlyOverlaid= new ArrayList<>();
if (fGeneratedAnnotations.size() > 0) { if (fGeneratedAnnotations.size() > 0) {
temporaryProblemsChanged= true; temporaryProblemsChanged= true;
@ -579,7 +575,7 @@ public class CDocumentProvider extends TextFileDocumentProvider {
* Tells this annotation model to collect temporary problems from now on. * Tells this annotation model to collect temporary problems from now on.
*/ */
private void startCollectingProblems() { private void startCollectingProblems() {
fGeneratedAnnotations= new ArrayList<ProblemAnnotation>(); fGeneratedAnnotations= new ArrayList<>();
} }
/** /**
@ -631,7 +627,7 @@ public class CDocumentProvider extends TextFileDocumentProvider {
List<Annotation> list= (List<Annotation>) cached; List<Annotation> list= (List<Annotation>) cached;
list.add(annotation); list.add(annotation);
} else if (cached instanceof Annotation) { } else if (cached instanceof Annotation) {
List<Object> list= new ArrayList<Object>(2); List<Object> list= new ArrayList<>(2);
list.add(cached); list.add(cached);
list.add(annotation); list.add(annotation);
fReverseMap.put(position, list); fReverseMap.put(position, list);
@ -812,7 +808,8 @@ public class CDocumentProvider extends TextFileDocumentProvider {
if (location != null) { if (location != null) {
IResource markerResource = CUIPlugin.getWorkspace().getRoot(); IResource markerResource = CUIPlugin.getWorkspace().getRoot();
IAnnotationModel originalModel = tuInfo.fModel; IAnnotationModel originalModel = tuInfo.fModel;
ExternalSearchAnnotationModel externalSearchModel = new ExternalSearchAnnotationModel(markerResource, location, IResource.DEPTH_ONE); ExternalSearchAnnotationModel externalSearchModel =
new ExternalSearchAnnotationModel(markerResource, location, IResource.DEPTH_ONE);
tuInfo.fModel= externalSearchModel; tuInfo.fModel= externalSearchModel;
IAnnotationModel fileBufferModel= tuInfo.fTextFileBuffer.getAnnotationModel(); IAnnotationModel fileBufferModel= tuInfo.fTextFileBuffer.getAnnotationModel();
if (fileBufferModel != null) { if (fileBufferModel != null) {
@ -850,7 +847,7 @@ public class CDocumentProvider extends TextFileDocumentProvider {
/** /**
* Tries to synthesize an ITranslationUnit out of thin air. * Tries to synthesize an ITranslationUnit out of thin air.
* @param uri the URU of the file in question * @param uri the URI of the file in question
* @return a translation unit or <code>null</code> * @return a translation unit or <code>null</code>
*/ */
private ITranslationUnit createTranslationUnit(URI uri) { private ITranslationUnit createTranslationUnit(URI uri) {