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

Cosmetics

Change-Id: I0ace660542038d2077fb9e989b1bb5ccc10b4ef2
This commit is contained in:
Sergey Prigogin 2016-07-29 18:19:34 -07:00 committed by Gerrit Code Review @ Eclipse.org
parent 06751579f3
commit d866664a92

View file

@ -6,11 +6,10 @@
* 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
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.internal.core.model; package org.eclipse.cdt.internal.core.model;
import java.util.Enumeration; import java.util.Enumeration;
import org.eclipse.cdt.core.model.IBuffer; import org.eclipse.cdt.core.model.IBuffer;
@ -19,40 +18,40 @@ import org.eclipse.cdt.core.model.IOpenable;
import org.eclipse.cdt.internal.core.util.OverflowingLRUCache; import org.eclipse.cdt.internal.core.util.OverflowingLRUCache;
import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IResource; import org.eclipse.core.resources.IResource;
/** /**
* The buffer manager manages the set of open buffers. * The buffer manager manages the set of open buffers.
* It implements an LRU cache of buffers. * It implements an LRU cache of buffers.
* *
* This class is similar to the JDT BufferManager class * This class is similar to the JDT BufferManager class.
*/ */
public class BufferManager implements IBufferFactory { public class BufferManager implements IBufferFactory {
/** /**
* An LRU cache of <code>IBuffers</code>. * An LRU cache of <code>IBuffers</code>.
*/ */
public class BufferCache<K> extends OverflowingLRUCache<K,IBuffer> { public class BufferCache<K> extends OverflowingLRUCache<K, IBuffer> {
/** /**
* Constructs a new buffer cache of the given size. * Constructs a new buffer cache of the given size.
*/ */
public BufferCache(int size) { public BufferCache(int size) {
super(size); super(size);
} }
/** /**
* Constructs a new buffer cache of the given size. * Constructs a new buffer cache of the given size.
*/ */
public BufferCache(int size, int overflow) { public BufferCache(int size, int overflow) {
super(size, overflow); super(size, overflow);
} }
/** /**
* Returns true if the buffer is successfully closed and * Returns true if the buffer is successfully closed and removed from the cache,
* removed from the cache, otherwise false. * otherwise false.
* *
* <p>NOTE: this triggers an external removal of this buffer * <p>NOTE: this triggers an external removal of this buffer by closing the buffer.
* by closing the buffer.
*/ */
@Override @Override
protected boolean close(LRUCacheEntry<K,IBuffer> entry) { protected boolean close(LRUCacheEntry<K, IBuffer> entry) {
IBuffer buffer= entry._fValue; IBuffer buffer= entry._fValue;
if (buffer.hasUnsavedChanges()) { if (buffer.hasUnsavedChanges()) {
return false; return false;
@ -60,8 +59,9 @@ public class BufferManager implements IBufferFactory {
buffer.close(); buffer.close();
return true; return true;
} }
/** /**
* Returns a new instance of the reciever. * Returns a new instance of the receiver.
*/ */
@Override @Override
protected OverflowingLRUCache<K, IBuffer> newInstance(int size, int overflow) { protected OverflowingLRUCache<K, IBuffer> newInstance(int size, int overflow) {
@ -72,16 +72,16 @@ public class BufferManager implements IBufferFactory {
protected static BufferManager DEFAULT_BUFFER_MANAGER; protected static BufferManager DEFAULT_BUFFER_MANAGER;
/** /**
* LRU cache of buffers. The key and value for an entry * LRU cache of buffers. The key and value for an entry in the table is the identical buffer.
* in the table is the identical buffer.
*/ */
protected OverflowingLRUCache<IOpenable, IBuffer> openBuffers = new BufferCache<IOpenable>(60); protected OverflowingLRUCache<IOpenable, IBuffer> openBuffers = new BufferCache<>(60);
/** /**
* Creates a new buffer manager. * Creates a new buffer manager.
*/ */
public BufferManager() { public BufferManager() {
} }
/** /**
* Adds a buffer to the table of open buffers. * Adds a buffer to the table of open buffers.
*/ */
@ -89,19 +89,11 @@ public class BufferManager implements IBufferFactory {
openBuffers.put(buffer.getOwner(), buffer); openBuffers.put(buffer.getOwner(), buffer);
} }
/**
* @see org.eclipse.cdt.internal.core.model.IBufferFactory#createBuffer(org.eclipse.cdt.core.model.IOpenable)
*/
@Override @Override
public IBuffer createBuffer(IOpenable owner) { public IBuffer createBuffer(IOpenable owner) {
ICElement element = (ICElement)owner; ICElement element = (ICElement) owner;
IResource resource = element.getResource(); IResource resource = element.getResource();
return return new Buffer(resource instanceof IFile ? (IFile) resource : null, owner, element.isReadOnly());
new Buffer(
resource instanceof IFile ? (IFile)resource : null,
owner,
element.isReadOnly());
} }
/** /**
@ -110,14 +102,16 @@ public class BufferManager implements IBufferFactory {
* buffer associated with it. * buffer associated with it.
*/ */
public IBuffer getBuffer(IOpenable owner) { public IBuffer getBuffer(IOpenable owner) {
return (IBuffer)openBuffers.get(owner); return (IBuffer) openBuffers.get(owner);
} }
/** /**
* Returns the default buffer factory. * Returns the default buffer factory.
*/ */
public IBufferFactory getDefaultBufferFactory() { public IBufferFactory getDefaultBufferFactory() {
return this; return this;
} }
/** /**
* Returns the default buffer manager. * Returns the default buffer manager.
*/ */
@ -127,6 +121,7 @@ public class BufferManager implements IBufferFactory {
} }
return DEFAULT_BUFFER_MANAGER; return DEFAULT_BUFFER_MANAGER;
} }
/** /**
* Returns an enumeration of all open buffers. * Returns an enumeration of all open buffers.
* <p> * <p>
@ -142,12 +137,10 @@ public class BufferManager implements IBufferFactory {
} }
} }
/** /**
* Removes a buffer from the table of open buffers. * Removes a buffer from the table of open buffers.
*/ */
protected void removeBuffer(IBuffer buffer) { protected void removeBuffer(IBuffer buffer) {
openBuffers.remove(buffer.getOwner()); openBuffers.remove(buffer.getOwner());
} }
} }