From 98ac994722ac5cbd9b593e4fb23f533d2b5db701 Mon Sep 17 00:00:00 2001 From: Bogdan Gheorghe Date: Thu, 2 Jun 2005 05:44:46 +0000 Subject: [PATCH] Refactored CIndexStorage to persist modifier bit fields and function signatures Updated method search pattern to make use of the newly stored info --- .../indexer/tests/IndexerOffsetTests.java | 12 +- .../eclipse/cdt/core/index/ICDTIndexer.java | 9 +- .../internal/core/index/FunctionEntry.java | 2 +- .../internal/core/index/IFunctionEntry.java | 4 +- .../internal/core/index/IIndexerOutput.java | 7 +- .../ICIndexStorageConstants.java | 4 +- .../index/cindexstorage/InMemoryIndex.java | 12 +- .../core/index/cindexstorage/Index.java | 11 +- .../IndexEntryNotSupportedException.java | 11 + .../index/cindexstorage/IndexerOutput.java | 203 +++++++++++++----- .../core/index/cindexstorage/WordEntry.java | 66 +++++- .../io/GammaCompressedIndexBlock.java | 14 ++ .../index/cindexstorage/io/MergeFactory.java | 2 +- .../core/index/nullindexer/NullIndexer.java | 6 + .../matching/MethodDeclarationPattern.java | 72 ++++++- 15 files changed, 353 insertions(+), 82 deletions(-) create mode 100644 core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/cindexstorage/IndexEntryNotSupportedException.java diff --git a/core/org.eclipse.cdt.core.tests/indexer/org/eclipse/cdt/core/indexer/tests/IndexerOffsetTests.java b/core/org.eclipse.cdt.core.tests/indexer/org/eclipse/cdt/core/indexer/tests/IndexerOffsetTests.java index 097860c80a6..67bb73fa185 100644 --- a/core/org.eclipse.cdt.core.tests/indexer/org/eclipse/cdt/core/indexer/tests/IndexerOffsetTests.java +++ b/core/org.eclipse.cdt.core.tests/indexer/org/eclipse/cdt/core/indexer/tests/IndexerOffsetTests.java @@ -52,34 +52,44 @@ public class IndexerOffsetTests extends TestCase { word.addOffset(512,3,2,IIndex.OFFSET); word.addOffset(512,3,2,IIndex.OFFSET); word.addOffset(512,3,2,IIndex.OFFSET); + word.addModifiers(18,2); word.addRef(5); word.addOffset(43,6,5,IIndex.OFFSET); word.addOffset(2,3,5,IIndex.LINE); word.addOffset(89,8,5,IIndex.OFFSET); word.addOffset(63,2,5,IIndex.LINE); word.addOffset(124,7,5,IIndex.OFFSET); + word.addModifiers(4,5); word.addRef(9); word.addOffset(433,5,9,IIndex.OFFSET); word.addOffset(234,3,9,IIndex.OFFSET); + word.addModifiers(1,9); word.addRef(11); word.addOffset(4233,2,11,IIndex.OFFSET); word.addOffset(2314,7,11,IIndex.OFFSET); + word.addModifiers(8,11); word.addRef(17); word.addOffset(2,7,17,IIndex.OFFSET); word.addOffset(52,8,17,IIndex.OFFSET); + word.addModifiers(32,17); + int[] test =word.getOffsets(1); + int[] modifierTest=word.getModifiers(); + WordEntry word2 = new WordEntry("typeDecl/C/Test".toCharArray()); word2.addRef(4); word2.addOffset(13,4,4, IIndex.OFFSET); word2.addOffset(17,3,4, IIndex.OFFSET); word2.addOffset(20,6,4,IIndex.OFFSET); + word2.addModifiers(64,4); word2.addRef(7); word2.addOffset(21,2,7, IIndex.OFFSET); word2.addOffset(24,3,7, IIndex.OFFSET); word2.addOffset(28,7,7,IIndex.OFFSET); + word2.addModifiers(128,7); - word.addWordInfo(word2.getRefs(), word2.getOffsets(), word2.getOffsetLengths(), word2.getOffsetCount()); + word.addWordInfo(word2.getRefs(), word2.getOffsets(), word2.getOffsetLengths(), word2.getOffsetCount(),word2.getModifiers()); word.mapRefs(new int[]{-1, 1, 17, 3, 4, 11, 6, 7, 8, 24, 10, 5, 12, 13, 14, 15, 16, 2}); diff --git a/core/org.eclipse.cdt.core/index/org/eclipse/cdt/core/index/ICDTIndexer.java b/core/org.eclipse.cdt.core/index/org/eclipse/cdt/core/index/ICDTIndexer.java index 08d40041c1d..ed3c8680be0 100644 --- a/core/org.eclipse.cdt.core/index/org/eclipse/cdt/core/index/ICDTIndexer.java +++ b/core/org.eclipse.cdt.core/index/org/eclipse/cdt/core/index/ICDTIndexer.java @@ -12,6 +12,7 @@ package org.eclipse.cdt.core.index; import org.eclipse.cdt.internal.core.index.IIndex; import org.eclipse.cdt.internal.core.index.IIndexer; +import org.eclipse.cdt.internal.core.index.impl.IndexDelta; import org.eclipse.cdt.internal.core.search.processing.IIndexJob; import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IResourceDelta; @@ -104,7 +105,13 @@ public interface ICDTIndexer extends IIndexer { */ public void notifyIndexerChange(IProject project); - + /** + * Called by the index manager when a project has switched indexers to this + * type of indexer - can be used by the indexer to schedule initial jobs + * @param project - the project that has changed indexers + */ + public void notifyListeners(IndexDelta indexDelta); + /** * Returns if this indexer is enabled * @param project diff --git a/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/FunctionEntry.java b/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/FunctionEntry.java index a6c8982fe57..509c4611983 100644 --- a/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/FunctionEntry.java +++ b/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/FunctionEntry.java @@ -39,5 +39,5 @@ public class FunctionEntry extends NamedEntry implements IFunctionEntry { public void serialize(IIndexerOutput output) { output.addIndexEntry(this); } - + } diff --git a/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/IFunctionEntry.java b/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/IFunctionEntry.java index 1b7a49ba721..34e5613e599 100644 --- a/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/IFunctionEntry.java +++ b/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/IFunctionEntry.java @@ -15,7 +15,5 @@ package org.eclipse.cdt.internal.core.index; public interface IFunctionEntry extends INamedEntry { public char[][] getSignature(); - - public char[] getReturnType(); - + public char[] getReturnType(); } diff --git a/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/IIndexerOutput.java b/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/IIndexerOutput.java index 604e7b73cc8..f5f7ac027e6 100644 --- a/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/IIndexerOutput.java +++ b/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/IIndexerOutput.java @@ -10,6 +10,7 @@ *******************************************************************************/ package org.eclipse.cdt.internal.core.index; +import org.eclipse.cdt.internal.core.index.cindexstorage.IndexEntryNotSupportedException; import org.eclipse.cdt.internal.core.index.cindexstorage.IndexedFileEntry; /** @@ -19,7 +20,11 @@ import org.eclipse.cdt.internal.core.index.cindexstorage.IndexedFileEntry; public interface IIndexerOutput { - public void addIndexEntry(IIndexEntry indexEntry); + public void addIndexEntry(IIndexEntry indexEntry) throws IndexEntryNotSupportedException; + + public void addIndexEntry(ITypeEntry indexEntry); + public void addIndexEntry(INamedEntry indexEntry); + public void addIndexEntry(IFunctionEntry indexEntry); public IndexedFileEntry getIndexedFile(String path); public IndexedFileEntry addIndexedFile(String path); diff --git a/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/cindexstorage/ICIndexStorageConstants.java b/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/cindexstorage/ICIndexStorageConstants.java index 40e3c9c3762..7fbed8938c9 100644 --- a/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/cindexstorage/ICIndexStorageConstants.java +++ b/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/cindexstorage/ICIndexStorageConstants.java @@ -17,7 +17,7 @@ public interface ICIndexStorageConstants { * The signature of the index file. */ - public static final String SIGNATURE= "INDEX FILE 0.016"; //$NON-NLS-1$ + public static final String SIGNATURE= "INDEX FILE 0.017"; //$NON-NLS-1$ /** * The size of a block for a Block. @@ -86,7 +86,7 @@ public interface ICIndexStorageConstants { "FWD Union" //$NON-NLS-1$ }; - final static String[] allSpecifiers = { + final static String[] allSpecifiers = {"", //not used //$NON-NLS-1$ "private", // private //$NON-NLS-1$ "public", // public //$NON-NLS-1$ "protected", // protected //$NON-NLS-1$ diff --git a/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/cindexstorage/InMemoryIndex.java b/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/cindexstorage/InMemoryIndex.java index 167e375d3c8..fb300fcd2fb 100644 --- a/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/cindexstorage/InMemoryIndex.java +++ b/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/cindexstorage/InMemoryIndex.java @@ -103,28 +103,30 @@ public class InMemoryIndex { * If the word does not exist, it adds it in the index. * @param indexFlags */ - protected void addRef(char[] word, int fileNum, int offset, int offsetLength, int offsetType) { + protected void addRef(char[] word, int fileNum, int offset, int offsetLength, int offsetType, int modifiers) { WordEntry entry= this.words.get(word); if (entry == null) { entry= new WordEntry(word); entry.addRef(fileNum); entry.addOffset(offset, offsetLength, fileNum, offsetType); + entry.addModifiers(modifiers, fileNum); this.words.add(entry); this.sortedWordEntries= null; this.footprint += entry.footprint(); } else { this.footprint += entry.addRef(fileNum); entry.addOffset(offset, offsetLength, fileNum, offsetType); + entry.addModifiers(modifiers, fileNum); } } - public void addRef(IndexedFileEntry indexedFile, char[] word, int offset, int offsetLength, int offsetType) { - addRef(word, indexedFile.getFileID(), offset, offsetLength, offsetType); + public void addRef(IndexedFileEntry indexedFile, char[] word, int offset, int offsetLength, int offsetType, int modifiers) { + addRef(word, indexedFile.getFileID(), offset, offsetLength, offsetType, modifiers); } - public void addRef(IndexedFileEntry indexedFile, String word, int offset, int offsetLength, int offsetType) { - addRef(word.toCharArray(), indexedFile.getFileID(), offset, offsetLength, offsetType); + public void addRef(IndexedFileEntry indexedFile, String word, int offset, int offsetLength, int offsetType, int modifiers) { + addRef(word.toCharArray(), indexedFile.getFileID(), offset, offsetLength, offsetType, modifiers); } public void addRelatives(int fileNumber, String inclusion, String parent) { diff --git a/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/cindexstorage/Index.java b/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/cindexstorage/Index.java index d0783ab2b4c..400a6c716cd 100644 --- a/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/cindexstorage/Index.java +++ b/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/cindexstorage/Index.java @@ -32,10 +32,8 @@ import org.eclipse.cdt.internal.core.index.cindexstorage.io.IndexInput; import org.eclipse.cdt.internal.core.index.cindexstorage.io.IndexOutput; import org.eclipse.cdt.internal.core.index.cindexstorage.io.MergeFactory; import org.eclipse.cdt.internal.core.index.cindexstorage.io.SimpleIndexInput; -import org.eclipse.cdt.internal.core.index.ctagsindexer.CTagsIndexer; import org.eclipse.cdt.internal.core.index.impl.IndexDelta; import org.eclipse.cdt.internal.core.index.impl.Int; -import org.eclipse.cdt.internal.core.index.sourceindexer.SourceIndexer; import org.eclipse.core.resources.IFile; import org.eclipse.core.runtime.IPath; @@ -313,13 +311,8 @@ public class Index implements IIndex, ICIndexStorageConstants, ICSearchConstants CCorePlugin.getDefault().cdtLog.flushLog(); //Send out notification to listeners; - if (indexer instanceof SourceIndexer){ - IndexDelta indexDelta = new IndexDelta(null,null,IIndexDelta.MERGE_DELTA); - ((SourceIndexer) indexer).notifyListeners(indexDelta); - } else if (indexer instanceof CTagsIndexer) { - IndexDelta indexDelta = new IndexDelta(null,null,IIndexDelta.MERGE_DELTA); - ((CTagsIndexer) indexer).notifyListeners(indexDelta); - } + IndexDelta indexDelta = new IndexDelta(null,null,IIndexDelta.MERGE_DELTA); + indexer.notifyListeners(indexDelta); } } diff --git a/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/cindexstorage/IndexEntryNotSupportedException.java b/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/cindexstorage/IndexEntryNotSupportedException.java new file mode 100644 index 00000000000..39942da7d59 --- /dev/null +++ b/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/cindexstorage/IndexEntryNotSupportedException.java @@ -0,0 +1,11 @@ +package org.eclipse.cdt.internal.core.index.cindexstorage; + +public class IndexEntryNotSupportedException extends Exception { + + public IndexEntryNotSupportedException(String string) { + super(string); + } + + private static final long serialVersionUID = 3257002138168211513L; + +} diff --git a/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/cindexstorage/IndexerOutput.java b/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/cindexstorage/IndexerOutput.java index c5c115c2936..79deeeced9a 100644 --- a/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/cindexstorage/IndexerOutput.java +++ b/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/cindexstorage/IndexerOutput.java @@ -32,7 +32,7 @@ public class IndexerOutput implements ICIndexStorageConstants, IIndexerOutput { this.index= index; } - protected void addRef(int indexedFileNumber, char [][] name, char suffix, int type, int offset, int offsetLength, int offsetType) { + protected void addRef(int indexedFileNumber, char [][] name, char suffix, int type, int offset, int offsetLength, int offsetType, int modifiers) { if (indexedFileNumber == 0) { throw new IllegalStateException(); } @@ -40,12 +40,15 @@ public class IndexerOutput implements ICIndexStorageConstants, IIndexerOutput { if (offsetLength <= 0) offsetLength = 1; + if (modifiers <=0) + modifiers = 1; + index.addRef( encodeTypeEntry(name, suffix, type), - indexedFileNumber, offset, offsetLength, offsetType); + indexedFileNumber, offset, offsetLength, offsetType, modifiers); } - protected void addRef(int indexedFileNumber, char[][] name, int meta_kind, int ref, int offset, int offsetLength, int offsetType) { + protected void addRef(int indexedFileNumber, char[][] name, int meta_kind, int ref, int offset, int offsetLength, int offsetType, int modifiers) { if (indexedFileNumber == 0) { throw new IllegalStateException(); } @@ -53,9 +56,12 @@ public class IndexerOutput implements ICIndexStorageConstants, IIndexerOutput { if (offsetLength <= 0) offsetLength = 1; + if (modifiers <=0) + modifiers = 1; + index.addRef( encodeEntry(name, meta_kind, ref), - indexedFileNumber, offset, offsetLength, offsetType); + indexedFileNumber, offset, offsetLength, offsetType, modifiers); } @@ -90,7 +96,7 @@ public class IndexerOutput implements ICIndexStorageConstants, IIndexerOutput { } public void addIncludeRef(int indexedFileNumber, char[][] name, int offset, int offsetLength, int offsetType) { - addRef(indexedFileNumber, name, IIndex.INCLUDE, IIndex.REFERENCE, offset,offsetLength, offsetType); + addRef(indexedFileNumber, name, IIndex.INCLUDE, IIndex.REFERENCE, offset,offsetLength, offsetType,1); } /** @@ -183,59 +189,150 @@ public class IndexerOutput implements ICIndexStorageConstants, IIndexerOutput { return result; } - public void addIndexEntry(IIndexEntry indexEntry) { + public void addIndexEntry(IIndexEntry indexEntry) throws IndexEntryNotSupportedException { if (indexEntry == null) return; - if (indexEntry instanceof ITypeEntry){ - ITypeEntry typeEntry = (ITypeEntry) indexEntry; - int indexedFileNumber=typeEntry.getFileNumber(); - int meta_type = typeEntry.getMetaKind(); - int type_kind = typeEntry.getTypeKind(); - int entryType = typeEntry.getEntryType(); - int modifiers = typeEntry.getModifiers(); - - char[][]name=typeEntry.getFullName(); - - int nameOffset=typeEntry.getNameOffset(); - int nameOffsetLength=typeEntry.getNameLength(); - int nameOffsetType=typeEntry.getNameOffsetType(); - - int elementOffset=typeEntry.getElementOffset(); - int elementOffsetLength=typeEntry.getElementLength(); - int elementOffsetType=typeEntry.getElementOffsetType(); - - addRef(indexedFileNumber, name, ICIndexStorageConstants.typeConstants[type_kind], entryType, nameOffset,nameOffsetLength, nameOffsetType); - - } else if (indexEntry instanceof IFunctionEntry) { - IFunctionEntry functionEntry = (IFunctionEntry) indexEntry; - int indexedFileNumber=functionEntry.getFileNumber(); - int meta_type = functionEntry.getMetaKind(); - int entryType = functionEntry.getEntryType(); - int modifiers = functionEntry.getModifiers(); - char[][] sig=functionEntry.getSignature(); - char[][]name=functionEntry.getFullName(); - int nameOffset=functionEntry.getNameOffset(); - int nameOffsetLength=functionEntry.getNameLength(); - int nameOffsetType=functionEntry.getNameOffsetType(); - addRef(indexedFileNumber, name, meta_type, entryType, nameOffset,nameOffsetLength, nameOffsetType); - } - else if (indexEntry instanceof INamedEntry){ - INamedEntry nameEntry = (INamedEntry) indexEntry; - int indexedFileNumber=nameEntry.getFileNumber(); - int meta_type = nameEntry.getMetaKind(); - int entryType = nameEntry.getEntryType(); - int modifiers = nameEntry.getModifiers(); - char[][]name=nameEntry.getFullName(); - int nameOffset=nameEntry.getNameOffset(); - int nameOffsetLength=nameEntry.getNameLength(); - int nameOffsetType=nameEntry.getNameOffsetType(); - int elementOffset=nameEntry.getElementOffset(); - int elementOffsetLength=nameEntry.getElementLength(); - int elementOffsetType=nameEntry.getElementOffsetType(); - addRef(indexedFileNumber, name, meta_type, entryType, nameOffset,nameOffsetLength, nameOffsetType); + throw new IndexEntryNotSupportedException("Index Entry type not supported - need to add handler"); //$NON-NLS-1$ + } + + public void addIndexEntry(ITypeEntry typeEntry) { + int indexedFileNumber=typeEntry.getFileNumber(); + int meta_type = typeEntry.getMetaKind(); + int type_kind = typeEntry.getTypeKind(); + int entryType = typeEntry.getEntryType(); + int modifiers = typeEntry.getModifiers(); + + char[][]name=typeEntry.getFullName(); + + int nameOffset=typeEntry.getNameOffset(); + int nameOffsetLength=typeEntry.getNameLength(); + int nameOffsetType=typeEntry.getNameOffsetType(); + + int elementOffset=typeEntry.getElementOffset(); + int elementOffsetLength=typeEntry.getElementLength(); + int elementOffsetType=typeEntry.getElementOffsetType(); + + if (modifiers <= 0) + modifiers = 1; + + addRef(indexedFileNumber, name, ICIndexStorageConstants.typeConstants[type_kind], entryType, nameOffset,nameOffsetLength, nameOffsetType, modifiers); + + IIndexEntry[] baseClasses = typeEntry.getBaseTypes(); + if (baseClasses != null && + baseClasses.length > 0){ + for (int i=0; i