diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CreateWorkingCopyOperation.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CreateWorkingCopyOperation.java index a49be3711bd..9afc6c94247 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CreateWorkingCopyOperation.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CreateWorkingCopyOperation.java @@ -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); 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 f0a306046bf..f29a06152e6 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 @@ -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 children = new ArrayList(); + ArrayList 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; } diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/CDocumentProvider.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/CDocumentProvider.java index 6692ac7fad9..40eeb77362c 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/CDocumentProvider.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/CDocumentProvider.java @@ -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(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 fList= new ArrayList(2); - private int fAnchor= 0; + private List fList= new ArrayList<>(2); + private int fAnchor; public ReverseMap() { } @@ -324,17 +320,17 @@ public class CDocumentProvider extends TextFileDocumentProvider { List fReportedProblems; } - private ThreadLocal fProblemRequestorState= new ThreadLocal(); - private int fStateCount= 0; + private final ThreadLocal fProblemRequestorState= new ThreadLocal<>(); + private int fStateCount; private ITranslationUnit fTranslationUnit; private List fGeneratedAnnotations; private IProgressMonitor fProgressMonitor; private boolean fIsActive; - private ReverseMap fReverseMap= new ReverseMap(); + private final ReverseMap fReverseMap= new ReverseMap(); private List fPreviouslyOverlaid; - private List fCurrentlyOverlaid= new ArrayList(); + private List 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(); + 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(); + 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(); + fGeneratedAnnotations= new ArrayList<>(); } /** @@ -631,7 +627,7 @@ public class CDocumentProvider extends TextFileDocumentProvider { List list= (List) cached; list.add(annotation); } else if (cached instanceof Annotation) { - List list= new ArrayList(2); + List 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 null */ 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(); } }