1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-06-09 10:46:02 +02:00

Cosmetics.

This commit is contained in:
Sergey Prigogin 2012-12-23 17:53:53 -08:00
parent 5c26443c41
commit 83d83c5165
5 changed files with 183 additions and 192 deletions

View file

@ -87,15 +87,15 @@ public class DBTest extends BaseTestCase {
try {
new Database(tmp, ChunkCache.getSharedInstance(), 0, false);
fail("A readonly file should not be openable with write-access");
} catch(CoreException ioe) {
} catch (CoreException e) {
// we expect to get a failure here
}
/* check opening a readonly file for read access does not fail */
try {
new Database(tmp, ChunkCache.getSharedInstance(), 0, true);
} catch(CoreException ce) {
fail("A readonly file should be readable by a permanently readonly database "+ce);
} catch (CoreException e) {
fail("A readonly file should be readable by a permanently readonly database "+e);
}
} finally {
tmp.delete(); // this may be pointless on some platforms
@ -150,7 +150,6 @@ public class DBTest extends BaseTestCase {
public long getRecord() {
return record;
}
}
public void testStringsInBTree() throws Exception {
@ -194,6 +193,7 @@ public class DBTest extends BaseTestCase {
return string1.compare(string2, true);
}
};
BTree btree = new BTree(db, Database.DATA_AREA, comparator);
for (int i = 0; i < names.length; ++i) {
String name = names[i];

View file

@ -8,7 +8,6 @@
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.internal.pdom.tests;
import java.util.regex.Pattern;
@ -32,8 +31,7 @@ import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.NullProgressMonitor;
/**
* Tests for verifying whether the PDOM correctly stores information about
* C++ namespaces.
* Tests for verifying whether the PDOM correctly stores information about C++ namespaces.
*
* @author Vivian Kong
*/
@ -65,7 +63,7 @@ public class NamespaceTests extends PDOMTestBase {
}
public void testAlias() throws Exception {
/* Find all the namespace */
// Find all the namespace
IBinding[] namespaces = pdom.findBindings(Pattern.compile("namespace1"), false, INDEX_FILTER, NULL_MONITOR);
assertEquals(1, namespaces.length);
assertTrue(namespaces[0] instanceof ICPPNamespace);
@ -88,18 +86,15 @@ public class NamespaceTests extends PDOMTestBase {
}
public void testNested() throws Exception {
/* Find deeply nested namespace */
// Find deeply nested namespace
Pattern[] patterns = {Pattern.compile("namespace1"), Pattern.compile("namespace2"), Pattern.compile("namespace3")};
IBinding[] namespaces = pdom.findBindings(patterns, false, INDEX_FILTER, NULL_MONITOR);
assertEquals(1, namespaces.length);
assertTrue(namespaces[0] instanceof ICPPNamespace);
}
public void testMemberDefinition() throws Exception {
/* Find the definition of a member declared in a namespace */
// Find the definition of a member declared in a namespace
Pattern[] patterns = {Pattern.compile("namespace1"), Pattern.compile("namespace2"), Pattern.compile("foo")};
IBinding[] members = pdom.findBindings(patterns, false, INDEX_FILTER, NULL_MONITOR);
assertEquals(1, members.length);
@ -114,12 +109,10 @@ public class NamespaceTests extends PDOMTestBase {
assertEquals(1, defs.length);
loc = defs[0].getFileLocation();
assertEquals(offset("namespace.cpp", "::foo()") + 2, loc.getNodeOffset()); // character offset
}
public void testExtend() throws Exception {
/* Extending a namespace */
// Extending a namespace
IBinding[] namespaces = pdom.findBindings(Pattern.compile("ns1"), false, INDEX_FILTER, NULL_MONITOR);
assertEquals(1, namespaces.length);
assertTrue(namespaces[0] instanceof ICPPNamespace);
@ -130,7 +123,6 @@ public class NamespaceTests extends PDOMTestBase {
}
public void testOverload() throws Exception {
// Function overloading in namespace
Pattern[] patterns = {Pattern.compile("ns3"), Pattern.compile("blah")};
IBinding[] functions = pdom.findBindings(patterns, false, INDEX_FILTER, NULL_MONITOR);
@ -152,12 +144,10 @@ public class NamespaceTests extends PDOMTestBase {
assertEquals(1, refs.length);
loc = refs[0].getFileLocation();
assertEquals(offset("overload.cpp", "blah('a')"), loc.getNodeOffset()); // character offset
}
public void testUnnamed() throws Exception {
// test case for Bugzilla 162226
/* Unnamed Namespace */
public void testUnnamed_162226() throws Exception {
// Unnamed Namespace
IBinding[] functions = pdom.findBindings(Pattern.compile("function1"), true, INDEX_FILTER, NULL_MONITOR);
assertEquals(1, functions.length);
assertTrue(functions[0] instanceof ICPPFunction);
@ -177,12 +167,10 @@ public class NamespaceTests extends PDOMTestBase {
assertEquals(1, refs.length);
loc = refs[0].getFileLocation();
assertEquals(offset("unnamed.cpp", "function1();"), loc.getNodeOffset()); // character offset
}
public void testFriend() throws Exception {
/* Friend in namespace - function2 is not in Class1*/
// Bugzilla 162011
public void testFriend_162011() throws Exception {
// Friend in namespace - function2 is not in Class1
IBinding[] functions = pdom.findBindings(Pattern.compile("function2"), false, INDEX_FILTER, NULL_MONITOR);
assertEquals(1, functions.length);
assertTrue(functions[0] instanceof ICPPFunction);
@ -202,7 +190,6 @@ public class NamespaceTests extends PDOMTestBase {
assertEquals(1, refs.length);
loc = refs[0].getFileLocation();
assertEquals(offset("friend.cpp", "ns4::function2(element)") + 5, loc.getNodeOffset()); // character offset
}
public void testUsingDirective() throws Exception {

View file

@ -65,7 +65,7 @@ import com.ibm.icu.text.MessageFormat;
*
*/
public class Database {
// public for tests only, you shouldn't need these
// Public for tests only, you shouldn't need these.
public static final int INT_SIZE = 4;
public static final int CHUNK_SIZE = 1024 * 4;
public static final int OFFSET_IN_CHUNK_MASK= CHUNK_SIZE-1;
@ -82,7 +82,6 @@ public class Database {
public static final int ARGUMENT_SIZE = TYPE_SIZE; // size of a template argument in the database in bytes
public static final long MAX_DB_SIZE= ((long) 1 << (Integer.SIZE + BLOCK_SIZE_DELTA_BITS));
public static final int VERSION_OFFSET = 0;
public static final int DATA_AREA = (CHUNK_SIZE / BLOCK_SIZE_DELTA - MIN_BLOCK_DELTAS + 2) * INT_SIZE;
@ -92,8 +91,8 @@ public class Database {
private final File fLocation;
private final boolean fReadOnly;
private RandomAccessFile fFile;
private boolean fExclusiveLock; // necessary for any write operation
private boolean fLocked; // necessary for any operation.
private boolean fExclusiveLock; // Necessary for any write operation.
private boolean fLocked; // Necessary for any operation.
private boolean fIsMarkedIncomplete;
private int fVersion;
@ -125,7 +124,7 @@ public class Database {
int nChunksOnDisk = (int) (fFile.length() / CHUNK_SIZE);
fHeaderChunk= new Chunk(this, 0);
fHeaderChunk.fLocked= true; // never makes it into the cache, needed to satisfy assertions
fHeaderChunk.fLocked= true; // Never makes it into the cache, needed to satisfy assertions.
if (nChunksOnDisk <= 0) {
fVersion= version;
fChunks= new Chunk[1];
@ -188,7 +187,7 @@ public class Database {
while (position < size) {
nRead = from.transferTo(position, 4096 * 16, target);
if (nRead == 0) {
break; // Should not happen
break; // Should not happen.
} else {
position+= nRead;
}
@ -214,14 +213,14 @@ public class Database {
removeChunksFromCache();
fVersion= version;
// clear the first chunk.
// Clear the first chunk.
fHeaderChunk.clear(0, CHUNK_SIZE);
// chunks have been removed from the cache, so we may just reset the array of chunks.
// Chunks have been removed from the cache, so we may just reset the array of chunks.
fChunks = new Chunk[] {null};
fChunksUsed = fChunksAllocated = fChunks.length;
try {
fHeaderChunk.flush(); // zero out header chunk
fFile.getChannel().truncate(CHUNK_SIZE); // truncate database
fHeaderChunk.flush(); // Zero out header chunk.
fFile.getChannel().truncate(CHUNK_SIZE); // Truncate database.
} catch (IOException e) {
CCorePlugin.log(e);
}
@ -303,7 +302,7 @@ public class Database {
needDeltas= MIN_BLOCK_DELTAS;
}
// Which block size
// Which block size.
long freeblock = 0;
int useDeltas;
for (useDeltas= needDeltas; useDeltas <= MAX_BLOCK_DELTAS; useDeltas++) {
@ -312,10 +311,10 @@ public class Database {
break;
}
// get the block
// Get the block.
Chunk chunk;
if (freeblock == 0) {
// allocate a new chunk
// Allocate a new chunk.
freeblock= createNewChunk();
useDeltas = MAX_BLOCK_DELTAS;
chunk = getChunk(freeblock);
@ -326,16 +325,16 @@ public class Database {
final int unusedDeltas = useDeltas-needDeltas;
if (unusedDeltas >= MIN_BLOCK_DELTAS) {
// Add in the unused part of our block
// Add in the unused part of our block.
addBlock(chunk, unusedDeltas*BLOCK_SIZE_DELTA, freeblock + needDeltas*BLOCK_SIZE_DELTA);
useDeltas= needDeltas;
}
// Make our size negative to show in use
// Make our size negative to show in use.
final int usedSize= useDeltas*BLOCK_SIZE_DELTA;
chunk.putShort(freeblock, (short) -usedSize);
// Clear out the block, lots of people are expecting this
// Clear out the block, lots of people are expecting this.
chunk.clear(freeblock + BLOCK_HEADER_SIZE, usedSize-BLOCK_HEADER_SIZE);
malloced+= usedSize;
@ -419,7 +418,7 @@ public class Database {
long nextblock = chunk.getFreeRecPtr(block + BLOCK_NEXT_OFFSET);
if (prevblock != 0) {
putFreeRecPtr(prevblock + BLOCK_NEXT_OFFSET, nextblock);
} else { // we were the head
} else { // We were the head.
setFirstBlock(blocksize, nextblock);
}
@ -432,7 +431,7 @@ public class Database {
// Mark our size
chunk.putShort(block, (short) blocksize);
// Add us to the head of the list
// Add us to the head of the list.
long prevfirst = getFirstBlock(blocksize);
chunk.putFreeRecPtr(block + BLOCK_PREV_OFFSET, 0);
chunk.putFreeRecPtr(block + BLOCK_NEXT_OFFSET, prevfirst);
@ -448,13 +447,14 @@ public class Database {
*/
public void free(long offset) throws CoreException {
assert fExclusiveLock;
// TODO - look for opportunities to merge blocks
// TODO Look for opportunities to merge blocks
long block = offset - BLOCK_HEADER_SIZE;
Chunk chunk = getChunk(block);
int blocksize = - chunk.getShort(block);
if (blocksize < 0) {
// already freed
throw new CoreException(new Status(IStatus.ERROR, CCorePlugin.PLUGIN_ID, 0, "Already Freed", new Exception())); //$NON-NLS-1$
// Already freed.
throw new CoreException(new Status(IStatus.ERROR, CCorePlugin.PLUGIN_ID, 0,
"Already freed", new Exception())); //$NON-NLS-1$
}
addBlock(chunk, blocksize, block);
freed += blocksize;
@ -614,7 +614,7 @@ public class Database {
flush();
removeChunksFromCache();
// chunks have been removed from the cache, so we are fine
// Chunks have been removed from the cache, so we are fine.
fHeaderChunk.clear(0, CHUNK_SIZE);
fHeaderChunk.fDirty= false;
fChunks= new Chunk[] { null };
@ -672,15 +672,15 @@ public class Database {
Chunk chunk= fChunks[i];
if (chunk != null) {
if (chunk.fCacheIndex < 0) {
// locked chunk that has been removed from cache.
// Locked chunk that has been removed from cache.
if (chunk.fDirty) {
dirtyChunks.add(chunk); // keep in fChunks until it is flushed.
dirtyChunks.add(chunk); // Keep in fChunks until it is flushed.
} else {
chunk.fLocked= false;
fChunks[i]= null;
}
} else if (chunk.fLocked) {
// locked chunk, still in cache.
// Locked chunk, still in cache.
if (chunk.fDirty) {
if (flush) {
dirtyChunks.add(chunk);
@ -689,12 +689,12 @@ public class Database {
chunk.fLocked= false;
}
} else {
assert !chunk.fDirty; // dirty chunks must be locked.
assert !chunk.fDirty; // Dirty chunks must be locked.
}
}
}
}
// also handles header chunk
// Also handles header chunk.
flushAndUnlockChunks(dirtyChunks, flush);
} finally {
fExclusiveLock= false;
@ -713,7 +713,7 @@ public class Database {
return;
}
// be careful as other readers may access chunks concurrently
// Be careful as other readers may access chunks concurrently.
ArrayList<Chunk> dirtyChunks= new ArrayList<Chunk>();
synchronized (fCache) {
for (int i= 1; i < fChunksUsed ; i++) {
@ -724,7 +724,7 @@ public class Database {
}
}
// also handles header chunk
// Also handles header chunk.
flushAndUnlockChunks(dirtyChunks, true);
}
@ -742,7 +742,7 @@ public class Database {
}
}
// only after the chunks are flushed we may unlock and release them.
// Only after the chunks are flushed we may unlock and release them.
synchronized (fCache) {
for (Chunk chunk : dirtyChunks) {
chunk.fLocked= false;

View file

@ -60,7 +60,8 @@ public class PDOMCPPClassTemplate extends PDOMCPPClassType
private volatile ICPPTemplateParameter[] params; // Cached template parameters.
public PDOMCPPClassTemplate(PDOMCPPLinkage linkage, PDOMNode parent, ICPPClassTemplate template) throws CoreException, DOMException {
public PDOMCPPClassTemplate(PDOMCPPLinkage linkage, PDOMNode parent, ICPPClassTemplate template)
throws CoreException, DOMException {
super(linkage, parent, template);
final Database db = getDB();
@ -127,7 +128,8 @@ public class PDOMCPPClassTemplate extends PDOMCPPClassType
}
}
private void updateTemplateParameters(PDOMLinkage linkage, ICPPTemplateParameter[] newParams) throws CoreException, DOMException {
private void updateTemplateParameters(PDOMLinkage linkage, ICPPTemplateParameter[] newParams)
throws CoreException, DOMException {
final Database db = getDB();
long rec= db.getRecPtr(record + PARAMETERS);
IPDOMCPPTemplateParameter[] allParams;

View file

@ -22,7 +22,7 @@ import org.eclipse.core.runtime.Assert;
import org.eclipse.core.runtime.CoreException;
/**
* Collects methods to store an argument list in the database
* Collects methods to store an argument list in the database.
*/
public class PDOMTemplateParameterArray {
/**
@ -67,7 +67,8 @@ public class PDOMTemplateParameterArray {
/**
* Creates template parameters in the pdom
*/
public static IPDOMCPPTemplateParameter[] createPDOMTemplateParameters(PDOMLinkage linkage, PDOMNode parent, ICPPTemplateParameter[] origParams) throws CoreException, DOMException {
public static IPDOMCPPTemplateParameter[] createPDOMTemplateParameters(PDOMLinkage linkage,
PDOMNode parent, ICPPTemplateParameter[] origParams) throws CoreException, DOMException {
IPDOMCPPTemplateParameter[] params= new IPDOMCPPTemplateParameter[origParams.length];
for (int i = 0; i < origParams.length; i++) {
params[i]= createPDOMTemplateParameter(linkage, parent, origParams[i]);
@ -78,7 +79,8 @@ public class PDOMTemplateParameterArray {
/**
* Creates a template parameter in the pdom
*/
public static IPDOMCPPTemplateParameter createPDOMTemplateParameter(PDOMLinkage linkage, PDOMNode parent, ICPPTemplateParameter origParam) throws CoreException, DOMException {
public static IPDOMCPPTemplateParameter createPDOMTemplateParameter(PDOMLinkage linkage,
PDOMNode parent, ICPPTemplateParameter origParam) throws CoreException, DOMException {
IPDOMCPPTemplateParameter param= null;
if (origParam instanceof ICPPTemplateNonTypeParameter) {
param= new PDOMCPPTemplateNonTypeParameter(linkage, parent, (ICPPTemplateNonTypeParameter) origParam);