diff --git a/core/org.eclipse.cdt.core.tests/indexer/org/eclipse/cdt/core/indexer/tests/DependencyTests.java b/core/org.eclipse.cdt.core.tests/indexer/org/eclipse/cdt/core/indexer/tests/DependencyTests.java index 2dfd006bdda..b25d15f3685 100644 --- a/core/org.eclipse.cdt.core.tests/indexer/org/eclipse/cdt/core/indexer/tests/DependencyTests.java +++ b/core/org.eclipse.cdt.core.tests/indexer/org/eclipse/cdt/core/indexer/tests/DependencyTests.java @@ -14,10 +14,15 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.Iterator; import java.util.Set; + import junit.framework.Test; import junit.framework.TestCase; import junit.framework.TestSuite; + import org.eclipse.cdt.core.CCorePlugin; +import org.eclipse.cdt.core.index.IIndexChangeListener; +import org.eclipse.cdt.core.index.IIndexDelta; +import org.eclipse.cdt.core.index.IndexChangeEvent; import org.eclipse.cdt.core.model.ICProject; import org.eclipse.cdt.core.search.BasicSearchResultCollector; import org.eclipse.cdt.core.search.ICSearchConstants; @@ -89,6 +94,11 @@ import org.eclipse.core.runtime.Platform; super.setUp(); //Create temp project testProject = createProject("DepTestProject"); + IPath pathLoc = CCorePlugin.getDefault().getStateLocation(); + + File indexFile = new File(pathLoc.append("281274758.index").toOSString()); + if (indexFile.exists()) + indexFile.delete(); testProject.setSessionProperty(IndexManager.activationKey,new Boolean(true)); @@ -208,7 +218,6 @@ import org.eclipse.core.runtime.Platform; public void testDepTable() throws Exception{ //Add a file to the project - IFile cH = importFile("c.h","resources/dependency/c.h"); IFile aH = importFile("a.h","resources/dependency/a.h"); IFile Inc1H = importFile("Inc1.h","resources/dependency/Inc1.h"); @@ -220,7 +229,7 @@ import org.eclipse.core.runtime.Platform; PathCollector pathCollector = new PathCollector(); getTableRefs(dH, pathCollector); - + String[] dHModel = {IPath.SEPARATOR + "DepTestProject" + IPath.SEPARATOR + "DepTest2.cpp", IPath.SEPARATOR + "DepTestProject" + IPath.SEPARATOR + "DepTest.cpp", IPath.SEPARATOR + "DepTestProject" + IPath.SEPARATOR + "DepTest2.h"}; String[] iPath = pathCollector.getPaths(); diff --git a/core/org.eclipse.cdt.core.tests/indexer/org/eclipse/cdt/core/indexer/tests/IndexManagerTests.java b/core/org.eclipse.cdt.core.tests/indexer/org/eclipse/cdt/core/indexer/tests/IndexManagerTests.java index 18352cc1c5e..a4261154ae2 100644 --- a/core/org.eclipse.cdt.core.tests/indexer/org/eclipse/cdt/core/indexer/tests/IndexManagerTests.java +++ b/core/org.eclipse.cdt.core.tests/indexer/org/eclipse/cdt/core/indexer/tests/IndexManagerTests.java @@ -14,12 +14,18 @@ import java.io.File; import java.io.FileInputStream; import java.io.FileWriter; import java.io.IOException; +import java.nio.ByteBuffer; +import java.nio.channels.FileChannel; +import java.security.MessageDigest; import junit.framework.Test; import junit.framework.TestCase; import junit.framework.TestSuite; import org.eclipse.cdt.core.CCorePlugin; +import org.eclipse.cdt.core.index.IIndexChangeListener; +import org.eclipse.cdt.core.index.IIndexDelta; +import org.eclipse.cdt.core.index.IndexChangeEvent; import org.eclipse.cdt.core.model.ICProject; import org.eclipse.cdt.internal.core.index.IEntryResult; import org.eclipse.cdt.internal.core.index.IIndex; @@ -41,14 +47,15 @@ import org.eclipse.core.runtime.Path; /** * @author bgheorgh */ -public class IndexManagerTests extends TestCase { +public class IndexManagerTests extends TestCase implements IIndexChangeListener { IFile file; IFileDocument fileDoc; IProject testProject; NullProgressMonitor monitor; IndexManager indexManager; - - public static final int TIMEOUT = 5000; + boolean fileIndexed; + + public static final int TIMEOUT = 50; /** * Constructor for IndexManagerTest. * @param name @@ -69,6 +76,12 @@ public class IndexManagerTests extends TestCase { //Create temp project testProject = createProject("IndexerTestProject"); + IPath pathLoc = CCorePlugin.getDefault().getStateLocation(); + + File indexFile = new File(pathLoc.append("3915980774.index").toOSString()); + if (indexFile.exists()) + indexFile.delete(); + testProject.setSessionProperty(IndexManager.activationKey,new Boolean(true)); @@ -77,6 +90,7 @@ public class IndexManagerTests extends TestCase { indexManager = CCorePlugin.getDefault().getCoreModel().getIndexManager(); indexManager.reset(); + indexManager.addIndexChangeListener(this); } /* * @see TestCase#tearDown() @@ -84,6 +98,7 @@ public class IndexManagerTests extends TestCase { protected void tearDown() { try { super.tearDown(); + indexManager.removeIndexChangeListener(this); } catch (Exception e1) { } //Delete project @@ -120,6 +135,7 @@ public class IndexManagerTests extends TestCase { suite.addTest(new IndexManagerTests("testIndexContents")); suite.addTest(new IndexManagerTests("testMacros")); suite.addTest(new IndexManagerTests("testRefs")); + suite.addTest(new IndexManagerTests("testExactDeclarations")); suite.addTest(new IndexManagerTests("testRemoveFileFromIndex")); suite.addTest(new IndexManagerTests("testRemoveProjectFromIndex")); suite.addTest(new IndexManagerTests("testIndexShutdown")); @@ -153,9 +169,12 @@ public class IndexManagerTests extends TestCase { * Start of tests */ public void testIndexAll() throws Exception { + //Add a file to the project + fileIndexed = false; importFile("mail.cpp","resources/indexer/mail.cpp"); - Thread.sleep(5000); + while (fileIndexed != true){ Thread.sleep(TIMEOUT);} + IIndex ind = indexManager.getIndex(testProject.getFullPath(),true,true); assertTrue("Index exists for project",ind != null); @@ -188,27 +207,32 @@ public class IndexManagerTests extends TestCase { } public void testAddNewFileToIndex() throws Exception{ - //Add a file to the project - importFile("mail.cpp","resources/indexer/mail.cpp"); - //Enable indexing on the created project - //By doing this, we force the Index Manager to indexAll() - Thread.sleep(10000); + + //Add a file to the project + fileIndexed = false; + importFile("mail.cpp","resources/indexer/mail.cpp"); + while (fileIndexed != true){ Thread.sleep(TIMEOUT);} + //Make sure project got added to index IPath testProjectPath = testProject.getFullPath(); IIndex ind = indexManager.getIndex(testProjectPath,true,true); assertTrue("Index exists for project",ind != null); //Add a new file to the project, give it some time to index + fileIndexed = false; importFile("DocumentManager.h","resources/indexer/DocumentManager.h"); + while (fileIndexed != true){ Thread.sleep(TIMEOUT);} + + fileIndexed = false; importFile("DocumentManager.cpp","resources/indexer/DocumentManager.cpp"); - - Thread.sleep(10000); + while (fileIndexed != true){ Thread.sleep(TIMEOUT);} + ind = indexManager.getIndex(testProjectPath,true,true); char[] prefix = "typeDecl/C/CDocumentManager".toCharArray(); - String [] entryResultModel ={"EntryResult: word=typeDecl/C/CDocumentManager, refs={ 1, 2 }"}; + String [] entryResultModel ={"EntryResult: word=typeDecl/C/CDocumentManager, refs={ 2 }"}; IEntryResult[] eresults =ind.queryEntries(prefix); - + IEntryResult[] bogRe = ind.queryEntries(IIndexConstants.TYPE_DECL); assertTrue("Entry Result exists", eresults != null); if (eresults.length != entryResultModel.length) @@ -221,10 +245,13 @@ public class IndexManagerTests extends TestCase { } public void testRemoveProjectFromIndex() throws Exception{ - //Add a file to the project - importFile("mail.cpp","resources/indexer/mail.cpp"); - Thread.sleep(TIMEOUT); + + //Add a file to the project + fileIndexed = false; + importFile("mail.cpp","resources/indexer/mail.cpp"); + while (fileIndexed != true){ Thread.sleep(TIMEOUT);} + //Make sure project got added to index IPath testProjectPath = testProject.getFullPath(); IIndex ind = indexManager.getIndex(testProjectPath,true,true); @@ -253,25 +280,34 @@ public class IndexManagerTests extends TestCase { } public void testRemoveFileFromIndex() throws Exception{ - //Add a file to the project - importFile("mail.cpp","resources/indexer/mail.cpp"); - - Thread.sleep(TIMEOUT); - //Make sure project got added to index - IPath testProjectPath = testProject.getFullPath(); - IIndex ind = indexManager.getIndex(testProjectPath,true,true); - assertTrue("Index exists for project",ind != null); - //Add a new file to the project - importFile("DocumentManager.h","resources/indexer/DocumentManager.h"); - importFile("DocumentManager.cpp","resources/indexer/DocumentManager.cpp"); - Thread.sleep(10000); + + //Add a file to the project + fileIndexed = false; + importFile("mail.cpp","resources/indexer/mail.cpp"); + while (fileIndexed != true){ Thread.sleep(TIMEOUT);} + + //Make sure project got added to index + IPath testProjectPath = testProject.getFullPath(); + IIndex ind = indexManager.getIndex(testProjectPath,true,true); + assertTrue("Index exists for project",ind != null); + //Add a new file to the project, give it some time to index + fileIndexed = false; + importFile("DocumentManager.h","resources/indexer/DocumentManager.h"); + while (fileIndexed != true){ Thread.sleep(TIMEOUT);} + + fileIndexed = false; + importFile("DocumentManager.cpp","resources/indexer/DocumentManager.cpp"); + while (fileIndexed != true){ Thread.sleep(TIMEOUT);} + + ind = indexManager.getIndex(testProjectPath,true,true); + //Do a "before" deletion comparison - ind = indexManager.getIndex(testProjectPath,true,true); + //ind = indexManager.getIndex(testProjectPath,true,true); char[] prefix = "typeDecl/".toCharArray(); IEntryResult[] eresults = ind.queryEntries(prefix); assertTrue("Entry result found for typdeDecl/", eresults != null); - String [] entryResultBeforeModel ={"EntryResult: word=typeDecl/C/CDocumentManager, refs={ 1, 2 }", "EntryResult: word=typeDecl/C/Mail, refs={ 3 }", "EntryResult: word=typeDecl/C/Unknown, refs={ 3 }", "EntryResult: word=typeDecl/C/container, refs={ 3 }", "EntryResult: word=typeDecl/C/first_class, refs={ 3 }", "EntryResult: word=typeDecl/C/postcard, refs={ 3 }", "EntryResult: word=typeDecl/D/Mail, refs={ 3 }", "EntryResult: word=typeDecl/D/first_class, refs={ 3 }", "EntryResult: word=typeDecl/D/postcard, refs={ 3 }", "EntryResult: word=typeDecl/V/, refs={ 1, 2 }", "EntryResult: word=typeDecl/V/PO_Box, refs={ 3 }", "EntryResult: word=typeDecl/V/index, refs={ 3 }", "EntryResult: word=typeDecl/V/mail, refs={ 3 }", "EntryResult: word=typeDecl/V/size, refs={ 3 }", "EntryResult: word=typeDecl/V/temp, refs={ 3 }", "EntryResult: word=typeDecl/V/x, refs={ 3 }"}; + String [] entryResultBeforeModel ={"EntryResult: word=typeDecl/C/CDocumentManager, refs={ 2 }", "EntryResult: word=typeDecl/C/Mail, refs={ 3 }", "EntryResult: word=typeDecl/C/Unknown, refs={ 3 }", "EntryResult: word=typeDecl/C/container, refs={ 3 }", "EntryResult: word=typeDecl/C/first_class, refs={ 3 }", "EntryResult: word=typeDecl/C/postcard, refs={ 3 }", "EntryResult: word=typeDecl/D/Mail, refs={ 3 }", "EntryResult: word=typeDecl/D/first_class, refs={ 3 }", "EntryResult: word=typeDecl/D/postcard, refs={ 3 }", "EntryResult: word=typeDecl/V/, refs={ 1, 2 }", "EntryResult: word=typeDecl/V/PO_Box, refs={ 3 }", "EntryResult: word=typeDecl/V/index, refs={ 3 }", "EntryResult: word=typeDecl/V/mail, refs={ 3 }", "EntryResult: word=typeDecl/V/size, refs={ 3 }", "EntryResult: word=typeDecl/V/temp, refs={ 3 }", "EntryResult: word=typeDecl/V/x, refs={ 3 }"}; if (eresults.length != entryResultBeforeModel.length) fail("Entry Result length different from model"); @@ -291,7 +327,7 @@ public class IndexManagerTests extends TestCase { eresults = ind.queryEntries(prefix); assertTrue("Entry exists", eresults != null); - String [] entryResultAfterModel ={"EntryResult: word=typeDecl/C/CDocumentManager, refs={ 1, 2 }", "EntryResult: word=typeDecl/V/, refs={ 1, 2 }"}; + String [] entryResultAfterModel ={"EntryResult: word=typeDecl/C/CDocumentManager, refs={ 2 }", "EntryResult: word=typeDecl/V/, refs={ 1, 2 }"}; if (eresults.length != entryResultAfterModel.length) fail("Entry Result length different from model"); @@ -302,10 +338,12 @@ public class IndexManagerTests extends TestCase { } public void testIndexContents() throws Exception{ + //Add a new file to the project, give it some time to index + fileIndexed = false; importFile("extramail.cpp","resources/indexer/extramail.cpp"); - - Thread.sleep(TIMEOUT); + while (fileIndexed != true){ Thread.sleep(TIMEOUT);} + //Make sure project got added to index IPath testProjectPath = testProject.getFullPath(); IIndex ind = indexManager.getIndex(testProjectPath,true,true); @@ -416,10 +454,11 @@ public class IndexManagerTests extends TestCase { } public void testRefs() throws Exception{ - //Add a new file to the project, give it some time to index + //Add a new file to the project, give it some time to index + fileIndexed = false; importFile("reftest.cpp","resources/indexer/reftest.cpp"); - - Thread.sleep(TIMEOUT); + while (fileIndexed != true){ Thread.sleep(TIMEOUT);} + //Make sure project got added to index IPath testProjectPath = testProject.getFullPath(); IIndex ind = indexManager.getIndex(testProjectPath,true,true); @@ -486,12 +525,95 @@ public class IndexManagerTests extends TestCase { } } + public void testExactDeclarations() throws Exception + { + + fileIndexed = false; + importFile("a.h","resources/dependency/a.h"); + while (fileIndexed != true){ Thread.sleep(TIMEOUT);} + + //Make sure project got added to index + IPath testProjectPath = testProject.getFullPath(); + IIndex ind = indexManager.getIndex(testProjectPath,true,true); + assertTrue("Index exists for project",ind != null); + + fileIndexed = false; + importFile("DepTest3.h","resources/dependency/DepTest3.h"); + while (fileIndexed != true){ Thread.sleep(TIMEOUT);} + + fileIndexed = false; + importFile("DepTest3.cpp","resources/dependency/DepTest3.cpp"); + while (fileIndexed != true){ Thread.sleep(TIMEOUT);} + + + IEntryResult[] eResult = ind.queryEntries(IIndexConstants.CLASS_DECL); + IQueryResult[] qResult = ind.queryPrefix(IIndexConstants.CLASS_DECL); + + assertTrue("Expected 2 files indexed", qResult.length == 2); + assertTrue("Checking DepTest3.h location", qResult[0].getPath().equals("/IndexerTestProject/DepTest3.h")); + assertTrue("Checking a.h location", qResult[1].getPath().equals("/IndexerTestProject/a.h")); + + assertTrue("Expect 2 class declaration entries", eResult.length == 2); + + int[] DepTest3FileRefs = {2}; + + int[] fileRefs = eResult[0].getFileReferences(); + + assertTrue("Check DepTest3 File Refs number", fileRefs.length == 1); + + for (int i=0; i"); //$NON-NLS-1$ return tempBuffer.toString(); } + + /** + * @return + */ + public long footprint() { + //Size of Object + (number of fields * size of Fields) + + //(Size of ArrayListObject + (Number of Nodes * sizeof Node)) + (Size of ArrayObject + (Number of fFile * sizeof char)) + + //(Size of ArrayListObject + (Number of Nodes * sizeof Node)) + + //(Size of ArrayObject + (Number of refs * sizeof int)) + return 8 + (8 * 4) + + (8 + fChild.size() * (8 + 2 * 4)) + (8 + fFile.length * 2) + + (8 + fParent.size() * (8 + 2 * 4)) + (8 + fRefs.length * 4); + } } diff --git a/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/impl/Index.java b/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/impl/Index.java index 5724f318b5d..69841fbb7c9 100644 --- a/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/impl/Index.java +++ b/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/impl/Index.java @@ -18,6 +18,7 @@ import java.util.List; import java.util.Map; import org.eclipse.cdt.core.CCorePlugin; +import org.eclipse.cdt.core.index.IIndexDelta; import org.eclipse.cdt.internal.core.index.IDocument; import org.eclipse.cdt.internal.core.index.IEntryResult; import org.eclipse.cdt.internal.core.index.IIndex; @@ -275,6 +276,10 @@ public class Index implements IIndex { state= MERGED; //flush the CDT log CCorePlugin.getDefault().cdtLog.flushLog(); + + //Send out notification to listeners; + IndexDelta indexDelta = new IndexDelta(null,null,IIndexDelta.MERGE_DELTA); + CCorePlugin.getDefault().getCoreModel().getIndexManager().notifyListeners(indexDelta); } } /** diff --git a/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/impl/IndexDelta.java b/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/impl/IndexDelta.java index 3aa52ce80df..f5f571965c6 100644 --- a/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/impl/IndexDelta.java +++ b/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/impl/IndexDelta.java @@ -19,6 +19,7 @@ public class IndexDelta implements IIndexDelta { private ArrayList files = null; private IProject project = null; + private IndexDeltaType deltaType = null; /** * @param filesTrav @@ -26,10 +27,20 @@ public class IndexDelta implements IIndexDelta { * */ public IndexDelta(IProject project, ArrayList filesTrav) { - this.project = project; - this.files = filesTrav; + this(project,filesTrav,null); } + /** + * @param filesTrav + * @param project + * + */ + public IndexDelta(IProject project, ArrayList filesTrav, IndexDeltaType indexDeltaType) { + this.project = project; + this.files = filesTrav; + this.deltaType = indexDeltaType; + } + /** * @return Returns the files. */ @@ -42,4 +53,11 @@ public class IndexDelta implements IIndexDelta { public IProject getProject() { return project; } + + /** + * @see org.eclipse.cdt.core.index.IIndexDelta#getDeltaType() + */ + public IndexDeltaType getDeltaType() { + return deltaType; + } } diff --git a/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/impl/IndexedFileHashedArray.java b/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/impl/IndexedFileHashedArray.java index 713b9761b3a..024cc42da0c 100644 --- a/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/impl/IndexedFileHashedArray.java +++ b/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/impl/IndexedFileHashedArray.java @@ -35,6 +35,10 @@ public IndexedFile add(IDocument document) { return add(new IndexedFile(document, ++lastId)); } +public IndexedFile add(String path){ + return add(new IndexedFile(path, ++lastId)); +} + private IndexedFile add(IndexedFile file) { int length = elements.length; String path = file.getPath(); diff --git a/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/impl/IndexerOutput.java b/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/impl/IndexerOutput.java index 396761894ce..d50be9d3802 100644 --- a/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/impl/IndexerOutput.java +++ b/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/impl/IndexerOutput.java @@ -43,17 +43,17 @@ public class IndexerOutput implements IIndexerOutput { /** * Adds a reference to the given word to the inMemoryIndex. */ - public void addRef(char[] word) { + public void addRef(char[] word, int indexFlags) { if (indexedFile == null) { throw new IllegalStateException(); } - index.addRef(indexedFile, word); + index.addRef(indexedFile, word, indexFlags); } /** * Adds a reference to the given word to the inMemoryIndex. */ - public void addRef(String word) { - addRef(word.toCharArray()); + public void addRef(String word, int indexFlags) { + addRef(word.toCharArray(), indexFlags); } public void addRelatives(String inclusion, String parent) { @@ -74,4 +74,26 @@ public class IndexerOutput implements IIndexerOutput { addIncludeRef(word.toCharArray()); } + public IndexedFile getIndexedFile(String path) { + return index.getIndexedFile(path); + } + + /** + * Adds a file to the InMemoryIndex but does not supplant the current + * file being indexed. This method is to be used if the current file being indexed + * needs to make reference to a file that has not been added to the index as of yet. + */ + public IndexedFile addSecondaryIndexedFile(IDocument document) { + return index.addDocument(document); + } + + /** + * Adds a file to the InMemoryIndex but does not supplant the current + * file being indexed. This method is to be used if the current file being indexed + * needs to make reference to an external file that has not been added to the index as of yet. + */ + public IndexedFile addSecondaryExternalIndexedFile(String path) { + return index.addExternalFilePath(path); + } + } diff --git a/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/impl/MergeFactory.java b/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/impl/MergeFactory.java index 6bddc463ac5..f7e83c14969 100644 --- a/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/impl/MergeFactory.java +++ b/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/impl/MergeFactory.java @@ -199,17 +199,20 @@ public class MergeFactory { else compare= Util.compare(word1.getWord(), word2.getWord()); if (compare < 0) { + word1.catRefs(word1); word1.mapRefs(mappingOld); mergeOutput.addWord(word1); oldInput.moveToNextWordEntry(); } else if (compare > 0) { + word2.catRefs(word2); word2.mapRefs(mappingAdds); mergeOutput.addWord(word2); addsInput.moveToNextWordEntry(); } else { + word1.catRefs(word1); word1.mapRefs(mappingOld); word2.mapRefs(mappingAdds); - word1.addRefs(word2.getRefs()); + word1.addRefs(word2.getRefs(),word2.getRefsIndexFlags()); mergeOutput.addWord(word1); addsInput.moveToNextWordEntry(); oldInput.moveToNextWordEntry(); @@ -223,7 +226,7 @@ public class MergeFactory { */ protected void mergeIncludes() throws IOException { int compare; - + while (oldInput.hasMoreIncludes() || addsInput.hasMoreIncludes()) { IncludeEntry inc1= oldInput.getCurrentIncludeEntry(); IncludeEntry inc2= addsInput.getCurrentIncludeEntry(); diff --git a/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/impl/Util.java b/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/impl/Util.java index 3ff79dcf8bc..76cfb43cf40 100644 --- a/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/impl/Util.java +++ b/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/impl/Util.java @@ -91,7 +91,14 @@ public class Util { quickSort(list, left, original_right); } } - private static void quickSort(int[] list, int left, int right) { + private static void quickSort(int[] list, int left, int right, int[] dependentList) { + + //If we are sorting 2 arrays, make sure that they are the same length + if (dependentList != null){ + if (list.length != dependentList.length) + return; + } + int original_left= left; int original_right= right; int mid= list[(left + right) / 2]; @@ -106,15 +113,22 @@ public class Util { int tmp= list[left]; list[left]= list[right]; list[right]= tmp; + + if (dependentList != null){ + int depTmp = dependentList[left]; + dependentList[left]=dependentList[right]; + dependentList[right]=depTmp; + } + left++; right--; } } while (left <= right); if (original_left < right) { - quickSort(list, original_left, right); + quickSort(list, original_left, right, dependentList); } if (left < original_right) { - quickSort(list, left, original_right); + quickSort(list, left, original_right, dependentList); } } private static void quickSort(String[] list, int left, int right) { @@ -303,7 +317,11 @@ public class Util { } public static void sort(int[] list) { if (list.length > 1) - quickSort(list, 0, list.length - 1); + quickSort(list, 0, list.length - 1, null); + } + public static void sort(int[] list, int[] dependentList) { + if (list.length > 1) + quickSort(list, 0, list.length - 1, dependentList); } public static void sort(String[] list) { if (list.length > 1) diff --git a/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/impl/WordEntry.java b/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/impl/WordEntry.java index 7b09ff2df9f..dfd0e293a56 100644 --- a/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/impl/WordEntry.java +++ b/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/impl/WordEntry.java @@ -10,12 +10,15 @@ *******************************************************************************/ package org.eclipse.cdt.internal.core.index.impl; +import org.eclipse.cdt.core.parser.util.ObjectSet; import org.eclipse.cdt.internal.core.CharOperation; public class WordEntry { protected char[] fWord; protected int fNumRefs; protected int[] fRefs; + protected int[] fRefsIndexFlags; + public WordEntry() { this(CharOperation.NO_CHAR); } @@ -23,55 +26,75 @@ public class WordEntry { fWord= word; fNumRefs= 0; fRefs= new int[1]; + fRefsIndexFlags = new int[1]; } /** * Adds a reference and records the change in footprint. */ - public int addRef(int fileNum) { + public int addRef(int fileNum, int indexFlags) { if (fNumRefs > 0 && fRefs[fNumRefs - 1] == fileNum) { return 0; } if (fNumRefs < fRefs.length) { + int tempNumRefs = fNumRefs; fRefs[fNumRefs++]= fileNum; + //Add index flags + fRefsIndexFlags[tempNumRefs]=indexFlags; return 0; } // For rt.jar, 73265 word entries are created. 51997 have 1 ref, then 9438, 3738, 1980, 1214, 779, 547, 429, 371 etc. int newSize= fNumRefs < 4 ? 4 : fNumRefs * 2; // so will start @ 1, grow to 4, 8, 16, 32, 64 etc. System.arraycopy(fRefs, 0, fRefs= new int[newSize], 0, fNumRefs); + // Resize the index flags array at this time as well + System.arraycopy(fRefsIndexFlags,0,fRefsIndexFlags=new int[newSize],0,fNumRefs); + + int tempNumRefs=fNumRefs; fRefs[fNumRefs++]= fileNum; + fRefsIndexFlags[tempNumRefs]=indexFlags; + return (newSize - fNumRefs + 1) * 4; } /** * Adds a set of references and records the change in footprint. */ - public void addRefs(int[] refs) { + public void addRefs(int[] refs, int[] indexRefs) { int[] newRefs= new int[fNumRefs + refs.length]; + int[] newIndexRefs = new int[fNumRefs + indexRefs.length]; int pos1= 0; int pos2= 0; int posNew= 0; int compare; int r1= 0; int r2= 0; + int i1=0; + int i2=0; while (pos1 < fNumRefs || pos2 < refs.length) { if (pos1 >= fNumRefs) { r2= refs[pos2]; + i2= indexRefs[pos2]; compare= -1; } else if (pos2 >= refs.length) { compare= 1; r1= fRefs[pos1]; + i1= fRefsIndexFlags[pos1]; } else { r1= fRefs[pos1]; r2= refs[pos2]; + + i1=fRefsIndexFlags[pos1]; + i2=indexRefs[pos2]; compare= r2 - r1; } if (compare > 0) { newRefs[posNew]= r1; + newIndexRefs[posNew]=i1; posNew++; pos1++; } else { if (r2 != 0) { newRefs[posNew]= r2; + newIndexRefs[posNew]=i2; posNew++; } pos2++; @@ -79,18 +102,15 @@ public class WordEntry { } fRefs= newRefs; fNumRefs= posNew; - /*for (int i = 0; i < refs.length; i++) - addRef(refs[i]); - int[] newRefs = new int[fNumRefs]; - System.arraycopy(fRefs, 0, newRefs, 0, fNumRefs); - fRefs = newRefs; - Util.sort(fRefs);*/ + fRefsIndexFlags=newIndexRefs; } /** * Returns the size of the wordEntry */ public int footprint() { - return 8 + (3 * 4) + (8 + fWord.length * 2) + (8 + fRefs.length * 4); + //Size of Object + (number of fields * size of Fields) + (Size of ArrayObject + (Number of chars * sizeof Chars)) + + //(Size of ArrayObject + (Number of refs * sizeof int)) + (Size of ArrayObject + (Number of indexRefs * sizeof int)) + return 8 + (4 * 4) + (8 + fWord.length * 2) + (8 + fRefs.length * 4) + (8 + fRefsIndexFlags.length * 4); } /** * Returns the number of references, e.g. the number of files this word appears in. @@ -105,6 +125,13 @@ public class WordEntry { if (i < fNumRefs) return fRefs[i]; throw new IndexOutOfBoundsException(); } + /** + * returns the index bit field in the i position + */ + public int getIndexFlag(int i) { + if (i < fNumRefs) return fRefsIndexFlags[i]; + throw new IndexOutOfBoundsException(); + } /** * Returns the references of the wordEntry (the number of the files it appears in). */ @@ -113,6 +140,14 @@ public class WordEntry { System.arraycopy(fRefs, 0, result, 0, fNumRefs); return result; } + /** + * Returns the wordEntry's references index flags + */ + public int[] getRefsIndexFlags() { + int[] result= new int[fNumRefs]; + System.arraycopy(fRefsIndexFlags, 0, result, 0, fNumRefs); + return result; + } /** * returns the word of the wordEntry. */ @@ -128,20 +163,31 @@ public class WordEntry { */ public void mapRefs(int[] mappings) { int position= 0; - + int position2= 0; + for (int i= 0; i < fNumRefs; i++) { //Take care that the reference is actually within the bounds of the mapping int map= -1; + int map2= -1; + if(fRefs[i] >= 0 && fRefs[i] < mappings.length) map= mappings[fRefs[i]]; if (map != -1 && map != 0) fRefs[position++]= map; + + if (fRefsIndexFlags[i] >= 0 && fRefsIndexFlags[i] < mappings.length) + map2 = mappings[fRefsIndexFlags[i]]; + if (map2 != -1 && map2 != 0) + fRefsIndexFlags[position2++] = map2; + } fNumRefs= position; //to be changed! System.arraycopy(fRefs, 0, (fRefs= new int[fNumRefs]), 0, fNumRefs); - Util.sort(fRefs); + System.arraycopy(fRefsIndexFlags, 0, (fRefsIndexFlags = new int[fNumRefs]),0,fNumRefs); + + Util.sort(fRefs, fRefsIndexFlags); } /** * Clears the wordEntry. @@ -149,6 +195,7 @@ public class WordEntry { public void reset(char[] word) { for (int i= fNumRefs; i-- > 0;) { fRefs[i]= 0; + fRefsIndexFlags[i]=0; } fNumRefs= 0; fWord= word; @@ -156,5 +203,30 @@ public class WordEntry { public String toString() { return new String(fWord); } + /** + * @param word + */ + public void catRefs(WordEntry word) { + int[] wordFileRefs = word.fRefs; + int[] wordIndexFlags=word.fRefsIndexFlags; + ObjectSet set = new ObjectSet(4); + + for (int i=0; i