From 08eb1c00e5d68fec992c04778388ad6b957a62ee Mon Sep 17 00:00:00 2001 From: Bogdan Gheorghe Date: Mon, 20 Jun 2005 17:14:04 +0000 Subject: [PATCH] Fix for 100640 Fix for 96286 --- .../core/index/cindexstorage/WordEntry.java | 10 ++++-- .../core/search/matching/CSearchPattern.java | 31 +++++++++++++++++++ .../matching/ClassDeclarationPattern.java | 15 ++------- .../matching/FieldDeclarationPattern.java | 15 ++------- .../core/search/matching/IncludePattern.java | 16 ++-------- .../matching/MacroDeclarationPattern.java | 16 ++-------- .../matching/MethodDeclarationPattern.java | 16 ++-------- .../matching/NamespaceDeclarationPattern.java | 16 ++-------- .../ui/text/c/hover/CSourceHover.java | 4 ++- 9 files changed, 60 insertions(+), 79 deletions(-) diff --git a/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/cindexstorage/WordEntry.java b/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/cindexstorage/WordEntry.java index 31a2724e98d..44e39137098 100644 --- a/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/cindexstorage/WordEntry.java +++ b/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/cindexstorage/WordEntry.java @@ -236,8 +236,14 @@ public class WordEntry { * @return */ private int getEncodedNumber(int offsetType, int offset) { - String offsetString = Integer.toString(offsetType) + Integer.toString(offset); - return Integer.parseInt(offsetString); + /* String offsetString = Integer.toString(offsetType) + Integer.toString(offset); + return Integer.parseInt(offsetString);*/ + + int m = 10; + while (m <= offset) { + m = m * 10; + } + return m * offsetType + offset; } /** * @param filePosition diff --git a/core/org.eclipse.cdt.core/search/org/eclipse/cdt/internal/core/search/matching/CSearchPattern.java b/core/org.eclipse.cdt.core/search/org/eclipse/cdt/internal/core/search/matching/CSearchPattern.java index 25a33db700f..28f140df1bc 100644 --- a/core/org.eclipse.cdt.core/search/org/eclipse/cdt/internal/core/search/matching/CSearchPattern.java +++ b/core/org.eclipse.cdt.core/search/org/eclipse/cdt/internal/core/search/matching/CSearchPattern.java @@ -39,6 +39,9 @@ import org.eclipse.cdt.core.parser.ScannerInfo; import org.eclipse.cdt.core.search.ICSearchConstants; import org.eclipse.cdt.core.search.ICSearchPattern; import org.eclipse.cdt.core.search.ICSearchScope; +import org.eclipse.cdt.core.search.IMatchLocatable; +import org.eclipse.cdt.core.search.LineLocatable; +import org.eclipse.cdt.core.search.OffsetLocatable; import org.eclipse.cdt.core.search.OrPattern; import org.eclipse.cdt.internal.core.CharOperation; import org.eclipse.cdt.internal.core.dom.parser.ISourceCodeParser; @@ -638,6 +641,34 @@ public abstract class CSearchPattern implements ICSearchConstants, ICSearchPatte } } + /** + * Decodes the passed in offset and returns an IMatchLocatable object of the appropriate type + * (either IOffsetLocatable or ILineLocatable) + */ + public static IMatchLocatable getMatchLocatable(int offset, int offsetLength){ + // pull off the first digit for the offset type + int encodedVal = offset; + int offsetType = encodedVal; + int m = 1; + while (offsetType >= 10) { + offsetType = offsetType / 10; + m *= 10; + } + + int startOffset = encodedVal - offsetType * m; + int endOffset = startOffset + offsetLength; + + IMatchLocatable locatable = null; + + if (offsetType==IIndex.LINE){ + locatable = new LineLocatable(startOffset,0); + }else if (offsetType==IIndex.OFFSET){ + locatable = new OffsetLocatable(startOffset, endOffset); + } + + return locatable; + } + /** * Feed the requestor according to the current search pattern */ diff --git a/core/org.eclipse.cdt.core/search/org/eclipse/cdt/internal/core/search/matching/ClassDeclarationPattern.java b/core/org.eclipse.cdt.core/search/org/eclipse/cdt/internal/core/search/matching/ClassDeclarationPattern.java index fd989966b4e..ec685fcc919 100644 --- a/core/org.eclipse.cdt.core/search/org/eclipse/cdt/internal/core/search/matching/ClassDeclarationPattern.java +++ b/core/org.eclipse.cdt.core/search/org/eclipse/cdt/internal/core/search/matching/ClassDeclarationPattern.java @@ -27,8 +27,6 @@ import org.eclipse.cdt.core.parser.ast.IASTQualifiedNameElement; import org.eclipse.cdt.core.parser.ast.IASTTypedefDeclaration; import org.eclipse.cdt.core.search.BasicSearchMatch; import org.eclipse.cdt.core.search.ICSearchScope; -import org.eclipse.cdt.core.search.LineLocatable; -import org.eclipse.cdt.core.search.OffsetLocatable; import org.eclipse.cdt.internal.core.CharOperation; import org.eclipse.cdt.internal.core.index.IEntryResult; import org.eclipse.cdt.internal.core.index.IIndex; @@ -175,16 +173,9 @@ public class ClassDeclarationPattern extends CSearchPattern { } match.setQualifiedName(qualifiedName); } - //Don't forget that offsets are encoded ICIndexStorageConstants - //Offsets can either be LINE or OFFSET - int offsetType = Integer.valueOf(String.valueOf(offsets[i][j]).substring(0,1)).intValue(); - if (offsetType==IIndex.LINE){ - match.setLocatable(new LineLocatable(Integer.valueOf(String.valueOf(offsets[i][j]).substring(1)).intValue(),0)); - }else if (offsetType==IIndex.OFFSET){ - int startOffset=Integer.valueOf(String.valueOf(offsets[i][j]).substring(1)).intValue(); - int endOffset= startOffset + offsetLengths[i][j]; - match.setLocatable(new OffsetLocatable(startOffset, endOffset)); - } + //Decode the offsetse + //Offsets can either be IIndex.LINE or IIndex.OFFSET + match.setLocatable(getMatchLocatable(offsets[i][j],offsetLengths[i][j])); match.setParentName(""); //$NON-NLS-1$ diff --git a/core/org.eclipse.cdt.core/search/org/eclipse/cdt/internal/core/search/matching/FieldDeclarationPattern.java b/core/org.eclipse.cdt.core/search/org/eclipse/cdt/internal/core/search/matching/FieldDeclarationPattern.java index 5a054200d45..f33c050dbeb 100644 --- a/core/org.eclipse.cdt.core/search/org/eclipse/cdt/internal/core/search/matching/FieldDeclarationPattern.java +++ b/core/org.eclipse.cdt.core/search/org/eclipse/cdt/internal/core/search/matching/FieldDeclarationPattern.java @@ -28,8 +28,6 @@ import org.eclipse.cdt.core.parser.ast.IASTTemplateParameter; import org.eclipse.cdt.core.parser.ast.IASTVariable; import org.eclipse.cdt.core.search.BasicSearchMatch; import org.eclipse.cdt.core.search.ICSearchScope; -import org.eclipse.cdt.core.search.LineLocatable; -import org.eclipse.cdt.core.search.OffsetLocatable; import org.eclipse.cdt.internal.core.index.IEntryResult; import org.eclipse.cdt.internal.core.index.cindexstorage.Index; import org.eclipse.cdt.internal.core.index.cindexstorage.IndexedFileEntry; @@ -156,16 +154,9 @@ public class FieldDeclarationPattern extends CSearchPattern { for (int j=0; j