mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-06-30 21:55:31 +02:00
Cosmetics.
This commit is contained in:
parent
4a2b680255
commit
509d7cd337
3 changed files with 53 additions and 59 deletions
|
@ -46,11 +46,11 @@ public class CreateWorkingCopyOperation extends CModelOperation {
|
|||
WorkingCopy workingCopy;
|
||||
|
||||
if (tu.getResource() != null) {
|
||||
workingCopy= new WorkingCopy(tu.getParent(), (IFile)tu.getResource(), tu.getContentTypeId(), this.factory, this.problemRequestor);
|
||||
workingCopy= new WorkingCopy(tu.getParent(), (IFile) tu.getResource(), tu.getContentTypeId(), this.factory, this.problemRequestor);
|
||||
} else {
|
||||
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
|
||||
// really slows down the opening of the CEditor.
|
||||
//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());
|
||||
delta.added(workingCopy);
|
||||
addDelta(delta);
|
||||
|
|
|
@ -43,23 +43,23 @@ public class WorkingCopy extends TranslationUnit implements IWorkingCopy {
|
|||
*/
|
||||
protected IBufferFactory bufferFactory;
|
||||
/**
|
||||
* A counter of the number of time clients have asked for this
|
||||
* working copy. It is set to 1, if the working
|
||||
* copy is not managed. When destroyed, this counter is
|
||||
* 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 translation unit is not a working copy.
|
||||
* A counter of the number of time clients have asked for this working copy.
|
||||
* It is set to 1, if the working copy is not managed. When destroyed, this
|
||||
* counter is 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
|
||||
* translation unit is not a working copy.
|
||||
*/
|
||||
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) {
|
||||
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);
|
||||
this.bufferFactory = bufferFactory == null ? getBufferManager() : bufferFactory;
|
||||
problemRequestor = requestor;
|
||||
|
@ -156,7 +156,7 @@ public class WorkingCopy extends TranslationUnit implements IWorkingCopy {
|
|||
public ICElement getOriginal(ICElement workingCopyElement) {
|
||||
// It has to come from the same workingCopy, meaning ours.
|
||||
if (workingCopyElement instanceof ISourceReference) {
|
||||
ITranslationUnit wunit = ((ISourceReference)workingCopyElement).getTranslationUnit();
|
||||
ITranslationUnit wunit = ((ISourceReference) workingCopyElement).getTranslationUnit();
|
||||
if (!wunit.equals(this)) {
|
||||
return null;
|
||||
}
|
||||
|
@ -170,7 +170,7 @@ public class WorkingCopy extends TranslationUnit implements IWorkingCopy {
|
|||
|
||||
// Look for it.
|
||||
ICElement element = workingCopyElement;
|
||||
ArrayList<ICElement> children = new ArrayList<ICElement>();
|
||||
ArrayList<ICElement> children = new ArrayList<>();
|
||||
while (element != null && element.getElementType() != ICElement.C_UNIT) {
|
||||
children.add(element);
|
||||
element = element.getParent();
|
||||
|
@ -180,7 +180,7 @@ public class WorkingCopy extends TranslationUnit implements IWorkingCopy {
|
|||
ICElement child = children.get(i);
|
||||
if (current instanceof IParent) {
|
||||
try {
|
||||
ICElement[] celems = ((IParent)current).getChildren();
|
||||
ICElement[] celems = ((IParent) current).getChildren();
|
||||
current = null;
|
||||
for (int j = 0; j < celems.length; ++j) {
|
||||
if (celems[j].getElementName().equals(child.getElementName()) &&
|
||||
|
@ -232,7 +232,7 @@ public class WorkingCopy extends TranslationUnit implements IWorkingCopy {
|
|||
return false;
|
||||
}
|
||||
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.
|
||||
return ((TranslationUnitInfo) getElementInfo()).fTimestamp == ((IFile) resource).getModificationStamp();
|
||||
} catch (CModelException e) {
|
||||
|
@ -250,8 +250,8 @@ public class WorkingCopy extends TranslationUnit implements IWorkingCopy {
|
|||
* @see IWorkingCopy
|
||||
*
|
||||
* @exception CModelException attempting to open a read only element for
|
||||
* something other than navigation, or if this is a working copy being
|
||||
* opened after it has been destroyed.
|
||||
* something other than navigation, or if this is a working copy being
|
||||
* opened after it has been destroyed.
|
||||
*/
|
||||
@Override
|
||||
public void open(IProgressMonitor monitor) throws CModelException {
|
||||
|
@ -272,19 +272,19 @@ public class WorkingCopy extends TranslationUnit implements IWorkingCopy {
|
|||
if (this.useCount == 0)
|
||||
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);
|
||||
if (buffer == null)
|
||||
return null;
|
||||
|
||||
// Set the buffer source if needed
|
||||
// Set the buffer source if needed.
|
||||
if (buffer.getContents() == null) {
|
||||
ITranslationUnit original= this.getOriginalElement();
|
||||
IBuffer originalBuffer = null;
|
||||
try {
|
||||
originalBuffer = original.getBuffer();
|
||||
} 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()) {
|
||||
throw e;
|
||||
}
|
||||
|
@ -295,15 +295,15 @@ public class WorkingCopy extends TranslationUnit implements IWorkingCopy {
|
|||
buffer.setContents(originalContents.clone());
|
||||
}
|
||||
} else {
|
||||
// Initialize buffer
|
||||
// Initialize buffer.
|
||||
buffer.setContents(new char[0]);
|
||||
}
|
||||
}
|
||||
|
||||
// Add buffer to buffer cache
|
||||
// Add buffer to buffer cache.
|
||||
this.getBufferManager().addBuffer(buffer);
|
||||
|
||||
// Listen to buffer changes
|
||||
// Listen to buffer changes.
|
||||
buffer.addBufferChangedListener(this);
|
||||
|
||||
return buffer;
|
||||
|
@ -323,7 +323,7 @@ public class WorkingCopy extends TranslationUnit implements IWorkingCopy {
|
|||
@Override
|
||||
public void restore() throws CModelException{
|
||||
if (this.useCount == 0)
|
||||
throw newNotPresentException(); // Was destroyed
|
||||
throw newNotPresentException(); // Was destroyed.
|
||||
|
||||
TranslationUnit original = (TranslationUnit) getOriginalElement();
|
||||
IBuffer buffer = this.getBuffer();
|
||||
|
@ -338,15 +338,11 @@ public class WorkingCopy extends TranslationUnit implements IWorkingCopy {
|
|||
if (isReadOnly()) {
|
||||
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).
|
||||
this.reconcile();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param original
|
||||
* @throws CModelException
|
||||
*/
|
||||
protected void updateTimeStamp(TranslationUnit original) throws CModelException {
|
||||
long timeStamp = ((IFile) original.getResource()).getModificationStamp();
|
||||
if (timeStamp == IResource.NULL_STAMP) {
|
||||
|
@ -356,12 +352,13 @@ public class WorkingCopy extends TranslationUnit implements IWorkingCopy {
|
|||
}
|
||||
|
||||
@Override
|
||||
public IASTTranslationUnit reconcile(boolean computeAST, boolean forceProblemDetection, IProgressMonitor monitor)
|
||||
throws CModelException {
|
||||
public IASTTranslationUnit reconcile(boolean computeAST, boolean forceProblemDetection,
|
||||
IProgressMonitor monitor) throws CModelException {
|
||||
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);
|
||||
return op.fAST;
|
||||
}
|
||||
|
|
|
@ -14,10 +14,8 @@ package org.eclipse.cdt.internal.ui.editor;
|
|||
|
||||
import java.net.URI;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.eclipse.core.filebuffers.ITextFileBuffer;
|
||||
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.spelling.SpellingAnnotation;
|
||||
|
||||
import org.eclipse.cdt.core.CCorePlugin;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTNode;
|
||||
import org.eclipse.cdt.core.model.CoreModel;
|
||||
import org.eclipse.cdt.core.model.ICModelMarker;
|
||||
|
@ -168,7 +165,7 @@ public class CDocumentProvider extends TextFileDocumentProvider {
|
|||
@Override
|
||||
public void addOverlaid(ICAnnotation annotation) {
|
||||
if (fOverlaids == null)
|
||||
fOverlaids= new ArrayList<ICAnnotation>(1);
|
||||
fOverlaids= new ArrayList<>(1);
|
||||
fOverlaids.add(annotation);
|
||||
}
|
||||
|
||||
|
@ -206,14 +203,13 @@ public class CDocumentProvider extends TextFileDocumentProvider {
|
|||
* on hash value.
|
||||
*/
|
||||
protected static class ReverseMap {
|
||||
|
||||
static class Entry {
|
||||
Position fPosition;
|
||||
Object fValue;
|
||||
}
|
||||
|
||||
private List<Entry> fList= new ArrayList<Entry>(2);
|
||||
private int fAnchor= 0;
|
||||
private List<Entry> fList= new ArrayList<>(2);
|
||||
private int fAnchor;
|
||||
|
||||
public ReverseMap() {
|
||||
}
|
||||
|
@ -324,17 +320,17 @@ public class CDocumentProvider extends TextFileDocumentProvider {
|
|||
List<IProblem> fReportedProblems;
|
||||
}
|
||||
|
||||
private ThreadLocal<ProblemRequestorState> fProblemRequestorState= new ThreadLocal<ProblemRequestorState>();
|
||||
private int fStateCount= 0;
|
||||
private final ThreadLocal<ProblemRequestorState> fProblemRequestorState= new ThreadLocal<>();
|
||||
private int fStateCount;
|
||||
|
||||
private ITranslationUnit fTranslationUnit;
|
||||
private List<ProblemAnnotation> fGeneratedAnnotations;
|
||||
private IProgressMonitor fProgressMonitor;
|
||||
private boolean fIsActive;
|
||||
|
||||
private ReverseMap fReverseMap= new ReverseMap();
|
||||
private final ReverseMap fReverseMap= new ReverseMap();
|
||||
private List<CMarkerAnnotation> fPreviouslyOverlaid;
|
||||
private List<CMarkerAnnotation> fCurrentlyOverlaid= new ArrayList<CMarkerAnnotation>();
|
||||
private List<CMarkerAnnotation> fCurrentlyOverlaid= new ArrayList<>();
|
||||
|
||||
public TranslationUnitAnnotationModel(IResource resource) {
|
||||
super(resource);
|
||||
|
@ -430,7 +426,7 @@ public class CDocumentProvider extends TextFileDocumentProvider {
|
|||
if (fTranslationUnit != null) {
|
||||
ProblemRequestorState state= new ProblemRequestorState();
|
||||
state.fInsideReportingSequence= insideReportingSequence;
|
||||
state.fReportedProblems= new ArrayList<IProblem>();
|
||||
state.fReportedProblems= new ArrayList<>();
|
||||
synchronized (getLockObject()) {
|
||||
fProblemRequestorState.set(state);
|
||||
++fStateCount;
|
||||
|
@ -497,7 +493,7 @@ public class CDocumentProvider extends TextFileDocumentProvider {
|
|||
boolean isCanceled= false;
|
||||
|
||||
fPreviouslyOverlaid= fCurrentlyOverlaid;
|
||||
fCurrentlyOverlaid= new ArrayList<CMarkerAnnotation>();
|
||||
fCurrentlyOverlaid= new ArrayList<>();
|
||||
|
||||
if (fGeneratedAnnotations.size() > 0) {
|
||||
temporaryProblemsChanged= true;
|
||||
|
@ -579,7 +575,7 @@ public class CDocumentProvider extends TextFileDocumentProvider {
|
|||
* Tells this annotation model to collect temporary problems from now on.
|
||||
*/
|
||||
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.add(annotation);
|
||||
} else if (cached instanceof Annotation) {
|
||||
List<Object> list= new ArrayList<Object>(2);
|
||||
List<Object> list= new ArrayList<>(2);
|
||||
list.add(cached);
|
||||
list.add(annotation);
|
||||
fReverseMap.put(position, list);
|
||||
|
@ -773,16 +769,16 @@ public class CDocumentProvider extends TextFileDocumentProvider {
|
|||
protected FileInfo createFileInfo(Object element) throws CoreException {
|
||||
ITranslationUnit original = null;
|
||||
if (element instanceof IFileEditorInput) {
|
||||
IFileEditorInput input = (IFileEditorInput)element;
|
||||
IFileEditorInput input = (IFileEditorInput) element;
|
||||
original = createTranslationUnit(input.getFile());
|
||||
} else if (element instanceof ITranslationUnitEditorInput) {
|
||||
ITranslationUnitEditorInput input = (ITranslationUnitEditorInput)element;
|
||||
ITranslationUnitEditorInput input = (ITranslationUnitEditorInput) element;
|
||||
original = input.getTranslationUnit();
|
||||
} else if (element instanceof IAdaptable) {
|
||||
IAdaptable adaptable= (IAdaptable)element;
|
||||
ILocationProvider locationProvider= (ILocationProvider)adaptable.getAdapter(ILocationProvider.class);
|
||||
IAdaptable adaptable= (IAdaptable) element;
|
||||
ILocationProvider locationProvider= (ILocationProvider) adaptable.getAdapter(ILocationProvider.class);
|
||||
if (locationProvider instanceof ILocationProviderExtension) {
|
||||
URI uri= ((ILocationProviderExtension)locationProvider).getURI(element);
|
||||
URI uri= ((ILocationProviderExtension) locationProvider).getURI(element);
|
||||
original= createTranslationUnit(uri);
|
||||
}
|
||||
if (original == null && locationProvider != null) {
|
||||
|
@ -812,7 +808,8 @@ public class CDocumentProvider extends TextFileDocumentProvider {
|
|||
if (location != null) {
|
||||
IResource markerResource = CUIPlugin.getWorkspace().getRoot();
|
||||
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;
|
||||
IAnnotationModel fileBufferModel= tuInfo.fTextFileBuffer.getAnnotationModel();
|
||||
if (fileBufferModel != null) {
|
||||
|
@ -826,7 +823,7 @@ public class CDocumentProvider extends TextFileDocumentProvider {
|
|||
if (tuInfo.fModel != null)
|
||||
tuInfo.fModel.addAnnotationModelListener(fGlobalAnnotationModelListener);
|
||||
if (requestor instanceof IProblemRequestorExtension) {
|
||||
IProblemRequestorExtension extension= (IProblemRequestorExtension)requestor;
|
||||
IProblemRequestorExtension extension= (IProblemRequestorExtension) requestor;
|
||||
extension.setIsActive(isHandlingTemporaryProblems());
|
||||
}
|
||||
return tuInfo;
|
||||
|
@ -843,14 +840,14 @@ public class CDocumentProvider extends TextFileDocumentProvider {
|
|||
}
|
||||
IEditorInput input= EditorUtility.getEditorInputForLocation(location, null);
|
||||
if (input instanceof ITranslationUnitEditorInput) {
|
||||
return ((ITranslationUnitEditorInput)input).getTranslationUnit();
|
||||
return ((ITranslationUnitEditorInput) input).getTranslationUnit();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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>
|
||||
*/
|
||||
private ITranslationUnit createTranslationUnit(URI uri) {
|
||||
|
@ -859,7 +856,7 @@ public class CDocumentProvider extends TextFileDocumentProvider {
|
|||
}
|
||||
IEditorInput input= EditorUtility.getEditorInputForLocation(uri, null);
|
||||
if (input instanceof ITranslationUnitEditorInput) {
|
||||
return ((ITranslationUnitEditorInput)input).getTranslationUnit();
|
||||
return ((ITranslationUnitEditorInput) input).getTranslationUnit();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
@ -991,7 +988,7 @@ public class CDocumentProvider extends TextFileDocumentProvider {
|
|||
IDocumentExtension4 extension= (IDocumentExtension4) document;
|
||||
extension.stopRewriteSession(fRewriteSession);
|
||||
} else {
|
||||
IDocumentExtension extension= (IDocumentExtension)document;
|
||||
IDocumentExtension extension= (IDocumentExtension) document;
|
||||
extension.stopSequentialRewrite();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue