diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/TranslationUnit.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/TranslationUnit.java index 56921c2368c..3f74ba7243b 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/TranslationUnit.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/TranslationUnit.java @@ -447,14 +447,14 @@ public class TranslationUnit extends Openable implements ITranslationUnit { Map newElements, IResource underlyingResource) throws CModelException { TranslationUnitInfo unitInfo = (TranslationUnitInfo) info; - // generate structure + // Generate structure this.parse(newElements, pm); // ///////////////////////////////////////////////////////////// if (isWorkingCopy()) { ITranslationUnit original = ((IWorkingCopy)this).getOriginalElement(); - // might be IResource.NULL_STAMP if original does not exist + // Might be IResource.NULL_STAMP if original does not exist IResource r = original.getResource(); if (r != null && r instanceof IFile) { unitInfo.fTimestamp = ((IFile) r).getModificationStamp(); @@ -499,7 +499,7 @@ public class TranslationUnit extends Openable implements ITranslationUnit { } else { workingCopy= new WorkingCopy(getParent(), getLocationURI(), getContentTypeId(), 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 workingCopy.open(monitor); return workingCopy; } @@ -541,7 +541,7 @@ public class TranslationUnit extends Openable implements ITranslationUnit { return null; } - // create a new info and make it the current info + // Create a new info and make it the current info // (this will remove the info and its children just before storing the new infos) CModelManager manager = CModelManager.getDefault(); boolean hadTemporaryCache = manager.hasTemporaryCache(); @@ -555,7 +555,7 @@ public class TranslationUnit extends Openable implements ITranslationUnit { Map newElements = manager.getTemporaryCache(); openWhenClosed(info, monitor); if (newElements.get(this) == null) { - // close any buffer that was opened for the new elements + // Close any buffer that was opened for the new elements Iterator iterator = newElements.keySet().iterator(); while (iterator.hasNext()) { ICElement element = iterator.next(); @@ -593,13 +593,13 @@ public class TranslationUnit extends Openable implements ITranslationUnit { @Override protected IBuffer openBuffer(IProgressMonitor pm) throws CModelException { - // create buffer - translation units only use default buffer factory + // Create buffer - translation units only use default buffer factory BufferManager bufManager = getBufferManager(); IBuffer buffer = getBufferFactory().createBuffer(this); if (buffer == null) return null; - // set the buffer source + // Set the buffer source if (buffer.getCharacters() == null) { IResource resource = this.getResource(); if (resource != null && resource.getType() == IResource.FILE) { @@ -620,10 +620,10 @@ public class TranslationUnit extends Openable implements ITranslationUnit { } } - // add buffer to buffer cache + // Add buffer to buffer cache bufManager.addBuffer(buffer); - // listen to buffer changes + // Listen to buffer changes buffer.addBufferChangedListener(this); return buffer; @@ -889,6 +889,7 @@ public class TranslationUnit extends Openable implements ITranslationUnit { } private static final int[] CTX_LINKAGES= { ILinkage.CPP_LINKAGE_ID, ILinkage.C_LINKAGE_ID }; + public IIndexFile[] getContextToHeader(IIndex index, int style) { if (index != null && (style & AST_CONFIGURE_USING_SOURCE_CONTEXT) != 0) { try { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPVisitor.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPVisitor.java index 956fbad6d43..1975cd67965 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPVisitor.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPVisitor.java @@ -2125,7 +2125,7 @@ public class CPPVisitor extends ASTQueries { } IType type = expr.getExpressionType(); if (spec.getType() == IASTSimpleDeclSpecifier.t_decltype) { - switch((expr).getValueCategory()) { + switch (expr.getValueCategory()) { case XVALUE: type= new CPPReferenceType(type, true); break; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/CIndex.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/CIndex.java index 30fd9d70b74..7374440818d 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/CIndex.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/CIndex.java @@ -102,7 +102,7 @@ public class CIndex implements IIndex { public IIndexBinding[] findBindings(Pattern[] patterns, boolean isFullyQualified, IndexFilter filter, IProgressMonitor monitor) throws CoreException { if (SPECIALCASE_SINGLES && fFragments.length == 1) { - return fFragments[0].findBindings(patterns, isFullyQualified, filter, monitor); + return fFragments[0].findBindings(patterns, isFullyQualified, filter, monitor); } else { List result = new ArrayList(); ILinkage[] linkages = Linkage.getIndexerLinkages(); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/PDOM.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/PDOM.java index 435a9249e97..3ea6248527f 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/PDOM.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/PDOM.java @@ -469,6 +469,7 @@ public class PDOM extends PlatformObject implements IPDOM { public int compare(long record) throws CoreException { return 0; } + @Override public boolean visit(long record) throws CoreException { PDOMFile file = PDOMFile.recreateFile(PDOM.this, record); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/db/BTree.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/db/BTree.java index 4e88f118e6f..de9f0dd7871 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/db/BTree.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/db/BTree.java @@ -10,19 +10,17 @@ * Andrew Ferguson (Symbian) - Provide B-tree deletion routine * Markus Schorn (Wind River Systems) *******************************************************************************/ - package org.eclipse.cdt.internal.core.pdom.db; -import com.ibm.icu.text.MessageFormat; - import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Status; +import com.ibm.icu.text.MessageFormat; + /** * @author Doug Schaefer - * */ public class BTree { // Constants for internal deletion routine (see deleteImp doc) @@ -53,7 +51,7 @@ public class BTree { * @param rootPointer offset into database of the pointer to the root node */ public BTree(Database db, long rootPointer, int degree, IBTreeComparator cmp) { - if(degree<2) + if (degree < 2) throw new IllegalArgumentException(Messages.getString("BTree.IllegalDegree")); //$NON-NLS-1$ this.db = db; @@ -113,10 +111,10 @@ public class BTree { // if this node is full (last record isn't null), split it if (getRecord(chunk, node, MAX_RECORDS - 1) != 0) { long median = getRecord(chunk, node, MEDIAN_RECORD); - if (median == record) + if (median == record) { // found it, never mind return median; - else { + } else { // split it // create the new node and move the larger records over long newnode = allocateNode(); @@ -161,8 +159,8 @@ public class BTree { // binary search to find the insert point int lower= 0; - int upper= MAX_RECORDS-1; - while (lower < upper && getRecord(chunk, node, upper-1) == 0) { + int upper= MAX_RECORDS - 1; + while (lower < upper && getRecord(chunk, node, upper - 1) == 0) { upper--; } @@ -171,16 +169,13 @@ public class BTree { long checkRec= getRecord(chunk, node, middle); if (checkRec == 0) { upper= middle; - } - else { + } else { int compare= cmp.compare(checkRec, record); if (compare > 0) { upper= middle; - } - else if (compare < 0) { - lower= middle+1; - } - else { + } else if (compare < 0) { + lower= middle + 1; + } else { // found it, no insert, just return the record return record; } @@ -256,16 +251,16 @@ public class BTree { BTNode(long node) throws CoreException { this.node = node; this.chunk = db.getChunk(node); - int i=0; - while(i MIN_RECORDS) { + BTNode succ = node.getChild(keyIndexInNode + 1); + if (succ != null && succ.keyCount > MIN_RECORDS) { /* Case 2a: Delete key by overwriting it with its successor (which occurs in a leaf node) */ long subst = deleteImp(-1, succ.node, DELMODE_DELETE_MINIMUM); putRecord(node.chunk, node.node, keyIndexInNode, subst); @@ -334,7 +329,7 @@ public class BTree { } BTNode pred = node.getChild(keyIndexInNode); - if(pred!=null && pred.keyCount > MIN_RECORDS) { + if (pred != null && pred.keyCount > MIN_RECORDS) { /* Case 2b: Delete key by overwriting it with its predecessor (which occurs in a leaf node) */ long subst = deleteImp(-1, pred.node, DELMODE_DELETE_MAXIMUM); putRecord(node.chunk, node.node, keyIndexInNode, subst); @@ -342,7 +337,7 @@ public class BTree { } /* Case 2c: Merge successor and predecessor */ - // assert(pred!=null && succ!=null); + // assert(pred != null && succ != null); if (pred != null) { mergeNodes(succ, node, keyIndexInNode, pred); return deleteImp(key, pred.node, mode); @@ -356,8 +351,8 @@ public class BTree { switch(mode) { case DELMODE_NORMAL: subtreeIndex = node.keyCount; - for(int i=0; i0) { + for (int i= 0; i < node.keyCount; i++) + if (cmp.compare(getRecord(node.chunk, node.node, i), key)>0) { subtreeIndex = i; break; } @@ -368,15 +363,15 @@ public class BTree { } BTNode child = node.getChild(subtreeIndex); - if(child==null) { + if (child == null) { throw new CoreException(new Status(IStatus.ERROR, CCorePlugin.PLUGIN_ID, IStatus.OK, Messages.getString("BTree.IntegrityError"), null)); //$NON-NLS-1$ } - if(child.keyCount > MIN_RECORDS) { + if (child.keyCount > MIN_RECORDS) { return deleteImp(key, child.node, mode); } else { - BTNode sibR = node.getChild(subtreeIndex+1); - if(sibR!=null && sibR.keyCount > MIN_RECORDS) { + BTNode sibR = node.getChild(subtreeIndex + 1); + if (sibR != null && sibR.keyCount > MIN_RECORDS) { /* Case 3a (i): child will underflow upon deletion, take a key from rightSibling */ long rightKey = getRecord(node.chunk, node.node, subtreeIndex); long leftmostRightSiblingKey = getRecord(sibR.chunk, sibR.node, 0); @@ -386,26 +381,26 @@ public class BTree { return deleteImp(key, child.node, mode); } - BTNode sibL = node.getChild(subtreeIndex-1); - if(sibL!=null && sibL.keyCount > MIN_RECORDS) { + BTNode sibL = node.getChild(subtreeIndex - 1); + if (sibL != null && sibL.keyCount > MIN_RECORDS) { /* Case 3a (ii): child will underflow upon deletion, take a key from leftSibling */ - long leftKey = getRecord(node.chunk, node.node, subtreeIndex-1); + long leftKey = getRecord(node.chunk, node.node, subtreeIndex - 1); prepend(child, leftKey, getChild(sibL.chunk, sibL.node, sibL.keyCount)); - long rightmostLeftSiblingKey = getRecord(sibL.chunk, sibL.node, sibL.keyCount-1); - putRecord(sibL.chunk, sibL.node, sibL.keyCount-1, 0); + long rightmostLeftSiblingKey = getRecord(sibL.chunk, sibL.node, sibL.keyCount - 1); + putRecord(sibL.chunk, sibL.node, sibL.keyCount - 1, 0); putChild(sibL.chunk, sibL.node, sibL.keyCount, 0); - putRecord(node.chunk, node.node, subtreeIndex-1, rightmostLeftSiblingKey); + putRecord(node.chunk, node.node, subtreeIndex - 1, rightmostLeftSiblingKey); return deleteImp(key, child.node, mode); } /* Case 3b (i,ii): leftSibling, child, rightSibling all have minimum number of keys */ - if(sibL!=null) { // merge child into leftSibling - mergeNodes(child, node, subtreeIndex-1, sibL); + if (sibL != null) { // merge child into leftSibling + mergeNodes(child, node, subtreeIndex - 1, sibL); return deleteImp(key, sibL.node, mode); } - if(sibR!=null) { // merge rightSibling into child + if (sibR != null) { // merge rightSibling into child mergeNodes(sibR, node, subtreeIndex, child); return deleteImp(key, child.node, mode); } @@ -429,21 +424,21 @@ public class BTree { */ public void mergeNodes(BTNode src, BTNode keyProvider, int kIndex, BTNode dst) throws CoreException { - nodeContentCopy(src, 0, dst, dst.keyCount+1, src.keyCount+1); + nodeContentCopy(src, 0, dst, dst.keyCount + 1, src.keyCount + 1); long midKey = getRecord(keyProvider.chunk, keyProvider.node, kIndex); putRecord(dst.chunk, dst.node, dst.keyCount, midKey); - long keySucc = kIndex+1 == MAX_RECORDS ? 0 : getRecord(keyProvider.chunk, keyProvider.node, kIndex+1); - db.free(getChild(keyProvider.chunk, keyProvider.node, kIndex+1)); - nodeContentDelete(keyProvider, kIndex+1, 1); + long keySucc = kIndex + 1 == MAX_RECORDS ? 0 : getRecord(keyProvider.chunk, keyProvider.node, kIndex + 1); + db.free(getChild(keyProvider.chunk, keyProvider.node, kIndex + 1)); + nodeContentDelete(keyProvider, kIndex + 1, 1); putRecord(keyProvider.chunk, keyProvider.node, kIndex, keySucc); - if(kIndex == 0 && keySucc == 0) { + if (kIndex == 0 && keySucc == 0) { /* * The root node is excused from the property that a node must have a least MIN keys * This means we must special case it at the point when its had all of its keys deleted * entirely during merge operations (which push one of its keys down as a pivot) */ long rootNode = getRoot(); - if(rootNode == keyProvider.node) { + if (rootNode == keyProvider.node) { db.putRecPtr(rootPointer, dst.node); db.free(rootNode); } @@ -458,7 +453,7 @@ public class BTree { * @param child the new leftmost (least) subtree root */ private void prepend(BTNode node, long key, long child) { - nodeContentCopy(node, 0, node, 1, node.keyCount+1); + nodeContentCopy(node, 0, node, 1, node.keyCount + 1); putRecord(node.chunk, node.node, 0, key); putChild(node.chunk, node.node, 0, child); } @@ -487,15 +482,15 @@ public class BTree { * @param length the number of (key,(predecessor)child) nodes to write */ private void nodeContentCopy(BTNode src, int srcPos, BTNode dst, int dstPos, int length) { - for(int i=length-1; i>=0; i--) { // this order is important when src==dst! + for (int i=length - 1; i >= 0; i--) { // this order is important when src == dst! int srcIndex = srcPos + i; int dstIndex = dstPos + i; - if(srcIndex= 0) { upper= middle; - } - else { - lower= middle+1; + } else { + lower= middle + 1; } } } @@ -584,8 +577,7 @@ public class BTree { if (compare > 0) { // start point is to the left return accept(getChild(chunk, node, i), visitor); - } - else if (compare == 0) { + } else if (compare == 0) { if (!accept(getChild(chunk, node, i), visitor)) return false; if (!visitor.visit(record)) @@ -594,8 +586,8 @@ public class BTree { } return accept(getChild(chunk, node, i), visitor); } finally { - if(visitor instanceof IBTreeVisitor2) { - ((IBTreeVisitor2)visitor).postNode(node); + if (visitor instanceof IBTreeVisitor2) { + ((IBTreeVisitor2) visitor).postNode(node); } } } @@ -648,56 +640,56 @@ public class BTree { int keyCount = 0; int indexFirstBlankKey = MAX_RECORDS; int indexLastNonBlankKey = 0; - for(int i=0; i MAX_RECORDS) { + if (keyCount < MIN_RECORDS || keyCount > MAX_RECORDS) { valid = false; - msg += MessageFormat.format(Messages.getString("BTree.IntegrityErrorC"), new Object[]{new Long(node)}); //$NON-NLS-1$ + msg += MessageFormat.format(Messages.getString("BTree.IntegrityErrorC"), new Object[] { new Long(node) }); //$NON-NLS-1$ } // Check: All leaf nodes are at the same depth - if(childCount==0) { - if(leafDepth==null) { + if (childCount == 0) { + if (leafDepth == null) { leafDepth = new Integer(depth); } - if(depth!=leafDepth.intValue()) { + if (depth != leafDepth.intValue()) { valid = false; msg += Messages.getString("BTree.IntegrityErrorD"); //$NON-NLS-1$ }