Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 179657 Details for
Bug 325385
The C++ search results have duplicate matches for one spot.
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read
this important communication.
[patch]
testcase + fix
325385.txt (text/plain), 11.69 KB, created by
Markus Schorn
on 2010-09-27 11:13:37 EDT
(
hide
)
Description:
testcase + fix
Filename:
MIME Type:
Creator:
Markus Schorn
Created:
2010-09-27 11:13:37 EDT
Size:
11.69 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.cdt.ui >Index: src/org/eclipse/cdt/internal/ui/search/LineSearchElement.java >=================================================================== >RCS file: /cvsroot/tools/org.eclipse.cdt-core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/LineSearchElement.java,v >retrieving revision 1.7 >diff -u -r1.7 LineSearchElement.java >--- src/org/eclipse/cdt/internal/ui/search/LineSearchElement.java 13 May 2010 07:32:10 -0000 1.7 >+++ src/org/eclipse/cdt/internal/ui/search/LineSearchElement.java 27 Sep 2010 15:12:12 -0000 >@@ -77,7 +77,10 @@ > > private static final class MatchesComparator implements Comparator<Match> { > public int compare(Match m1, Match m2) { >- return m1.getOffset() - m2.getOffset(); >+ int diff= m1.getOffset() - m2.getOffset(); >+ if (diff == 0) >+ diff= m2.getLength() -m1.getLength(); >+ return diff; > } > } > >@@ -158,47 +161,88 @@ > > public static LineSearchElement[] createElements(IIndexFileLocation fileLocation, Match[] matches, > IDocument document) { >- // sort matches according to their offsets >+ // Sort matches according to their offsets > Arrays.sort(matches, MATCHES_COMPARATOR); >- // group all matches by lines and create LineSearchElements >+ // Group all matches by lines and create LineSearchElements > List<LineSearchElement> result = new ArrayList<LineSearchElement>(); >- int firstMatch = 0; >- while (firstMatch < matches.length) { >- try { >- int lineNumber = document.getLineOfOffset(matches[firstMatch].getOffset()); >- int lineOffset = document.getLineOffset(lineNumber); >- int lineLength = document.getLineLength(lineNumber); >- int nextlineOffset = lineOffset + lineLength; >- int nextMatch = firstMatch; >- int nextMatchOffset = matches[nextMatch].getOffset(); >- while (nextMatch < matches.length && nextMatchOffset < nextlineOffset) { >- nextMatch++; >- if (nextMatch < matches.length) >- nextMatchOffset = matches[nextMatch].getOffset(); >- } >- int lineMatchesCount = nextMatch - firstMatch; >- Match[] lineMatches = new Match[lineMatchesCount]; >- System.arraycopy(matches, firstMatch, lineMatches, 0, lineMatchesCount); >+ List<Match> matchCollector= new ArrayList<Match>(); >+ int minOffset = 0; >+ int lineNumber = 0; >+ int lineOffset = 0; >+ int lineLength = 0; >+ int lineEndOffset = 0; >+ >+ try { >+ for (final Match match : matches) { >+ final int offset= match.getOffset(); >+ if (offset < lineEndOffset) { >+ // Match on same line >+ if (offset < minOffset) { >+ // Match is not overlapped by previous one. >+ matchCollector.add(match); >+ minOffset= offset + match.getLength(); >+ } >+ } else { >+ // Match is on a new line >+ if (!matchCollector.isEmpty()) { >+ // Complete a line >+ String content = document.get(lineOffset, lineLength); >+ Match[] lineMatches= matchCollector.toArray(new Match[matchCollector.size()]); >+ result.add(new LineSearchElement(fileLocation, lineMatches, lineNumber + 1, content, lineOffset)); >+ matchCollector.clear(); >+ } >+ // Setup next line >+ lineNumber = document.getLineOfOffset(offset); >+ lineOffset = document.getLineOffset(lineNumber); >+ lineLength = document.getLineLength(lineNumber); >+ lineEndOffset = lineOffset + lineLength; >+ matchCollector.add(match); >+ } >+ } >+ if (!matchCollector.isEmpty()) { >+ // Complete a line > String content = document.get(lineOffset, lineLength); >+ Match[] lineMatches= matchCollector.toArray(new Match[matchCollector.size()]); > result.add(new LineSearchElement(fileLocation, lineMatches, lineNumber + 1, content, lineOffset)); >- firstMatch = nextMatch; >- } catch (BadLocationException e) { >- CUIPlugin.log(e); >+ matchCollector.clear(); > } >+ } catch (BadLocationException e) { >+ CUIPlugin.log(e); > } > return result.toArray(new LineSearchElement[result.size()]); > } > > private static LineSearchElement[] collectLineElements(AbstractCharArray buf, Match[] matches, > IIndexFileLocation fileLocation) { >+ > List<LineSearchElement> result = new ArrayList<LineSearchElement>(); >+ List<Match> matchCollector= new ArrayList<Match>(); >+ > boolean skipLF = false; > int lineNumber = 1; > int lineOffset = 0; >- int lineFirstMatch = -1; // not matched >- int nextMatch = 0; >- int nextMatchOffset = matches[nextMatch].getOffset(); >+ int i = 0; >+ Match match= matches[i]; >+ int matchOffset = match.getOffset(); > for (int pos = 0; buf.isValidOffset(pos); pos++) { >+ if (matchOffset <= pos && match != null) { >+ // We are on the line of the match, store it. >+ matchCollector.add(match); >+ final int minOffset= matchOffset + match.getLength(); >+ match= null; >+ matchOffset= Integer.MAX_VALUE; >+ for(i=i+1; i<matches.length; i++) { >+ // Advance to next match that is not overlapped >+ final Match nextMatch= matches[i]; >+ final int nextOffset= nextMatch.getOffset(); >+ if (nextOffset >= minOffset) { >+ match= nextMatch; >+ matchOffset= nextOffset; >+ break; >+ } >+ } >+ } >+ > char c = buf.get(pos); > // consider '\n' and '\r' > if (skipLF) { >@@ -209,22 +253,18 @@ > } > } > if (c == '\n' || c == '\r') { >- // create new LineElement if there were matches >- if (lineFirstMatch != -1) { >+ // Create new LineElement for collected matches on this line >+ if (!matchCollector.isEmpty()) { > int lineLength = pos - lineOffset; >- int lineMatchesCount = nextMatch - lineFirstMatch; >- Match[] lineMatches = new Match[lineMatchesCount]; >- System.arraycopy(matches, lineFirstMatch, lineMatches, 0, lineMatchesCount); >+ Match[] lineMatches= matchCollector.toArray(new Match[matchCollector.size()]); > char[] lineChars= new char[lineLength]; > buf.arraycopy(lineOffset, lineChars, 0, lineLength); > String lineContent = new String(lineChars); > result.add(new LineSearchElement(fileLocation, lineMatches, lineNumber, lineContent, > lineOffset)); >- lineFirstMatch = -1; >- if (nextMatch >= matches.length) >+ matchCollector.clear(); >+ if (match == null) > break; >- if (matches[nextMatch].getOffset() < pos) >- lineFirstMatch = nextMatch; > } > lineNumber++; > lineOffset = pos + 1; >@@ -232,31 +272,16 @@ > skipLF = true; > continue; > } >- // compare offset of next match with current position >- if (nextMatchOffset > pos || nextMatch >= matches.length) >- continue; >- // next match was reached >- // check if this match is the first for current line >- if (lineFirstMatch == -1) >- lineFirstMatch = nextMatch; >- // goto to next match >- nextMatch++; >- if (nextMatch < matches.length) { >- // update offset of next match >- nextMatchOffset = matches[nextMatch].getOffset(); >- } > } >- // check if there were matches on the last line >- if (lineFirstMatch != -1) { >+ // Create new LineElement for matches on the last line >+ if (!matchCollector.isEmpty()) { > int lineLength = buf.getLength() - lineOffset; >- int lineMatchesCount = nextMatch - lineFirstMatch; >- Match[] lineMatches = new Match[lineMatchesCount]; >- System.arraycopy(matches, lineFirstMatch, lineMatches, 0, lineMatchesCount); >- >+ Match[] lineMatches= matchCollector.toArray(new Match[matchCollector.size()]); > char[] lineChars= new char[lineLength]; > buf.arraycopy(lineOffset, lineChars, 0, lineLength); > String lineContent = new String(lineChars); >- result.add(new LineSearchElement(fileLocation, lineMatches, lineNumber, lineContent, lineOffset)); >+ result.add(new LineSearchElement(fileLocation, lineMatches, lineNumber, lineContent, >+ lineOffset)); > } > return result.toArray(new LineSearchElement[result.size()]); > } >Index: src/org/eclipse/cdt/internal/ui/search/PDOMSearchPatternQuery.java >=================================================================== >RCS file: /cvsroot/tools/org.eclipse.cdt-core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/PDOMSearchPatternQuery.java,v >retrieving revision 1.32 >diff -u -r1.32 PDOMSearchPatternQuery.java >--- src/org/eclipse/cdt/internal/ui/search/PDOMSearchPatternQuery.java 27 Aug 2010 09:01:10 -0000 1.32 >+++ src/org/eclipse/cdt/internal/ui/search/PDOMSearchPatternQuery.java 27 Sep 2010 15:12:12 -0000 >@@ -145,11 +145,7 @@ > for (int i = 0; i < bindings.length; ++i) { > IIndexBinding pdomBinding = bindings[i]; > >- //check for the element type of this binding and create matches if >- //the element type checkbox is checked in the C/C++ Search Page >- >- //TODO search for macro >- >+ // Select the requested bindings > boolean matches= false; > if ((flags & FIND_ALL_TYPES) == FIND_ALL_TYPES) { > matches= true; >Index: src/org/eclipse/cdt/internal/ui/search/PDOMSearchQuery.java >=================================================================== >RCS file: /cvsroot/tools/org.eclipse.cdt-core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/PDOMSearchQuery.java,v >retrieving revision 1.28 >diff -u -r1.28 PDOMSearchQuery.java >--- src/org/eclipse/cdt/internal/ui/search/PDOMSearchQuery.java 2 Jun 2010 19:10:22 -0000 1.28 >+++ src/org/eclipse/cdt/internal/ui/search/PDOMSearchQuery.java 27 Sep 2010 15:12:12 -0000 >@@ -21,8 +21,8 @@ > import java.util.HashSet; > import java.util.List; > import java.util.Map; >-import java.util.Set; > import java.util.Map.Entry; >+import java.util.Set; > > import org.eclipse.core.runtime.CoreException; > import org.eclipse.core.runtime.IPath; >@@ -310,14 +310,20 @@ > return; > List<IIndexName> names= new ArrayList<IIndexName>(); > List<IIndexName> polymorphicNames= null; >+ HashSet<IBinding> handled= new HashSet<IBinding>(); >+ > for (IBinding binding : bindings) { >- if (binding != null) { >+ if (binding != null && handled.add(binding)) { > createMatches1(index, binding, names); >- >- if ((flags & FIND_REFERENCES) != 0) { >+ } >+ } >+ >+ if ((flags & FIND_REFERENCES) != 0) { >+ for (IBinding binding : bindings) { >+ if (binding != null) { > List<? extends IBinding> specializations = IndexUI.findSpecializations(binding); >- if (!specializations.isEmpty()) { >- for (IBinding spec : specializations) { >+ for (IBinding spec : specializations) { >+ if (spec != null && handled.add(spec)) { > createMatches1(index, spec, names); > } > } >@@ -331,7 +337,9 @@ > polymorphicNames= new ArrayList<IIndexName>(); > } > for (ICPPMethod mInBase : msInBases) { >- createMatches1(index, mInBase, polymorphicNames); >+ if (mInBase != null && handled.add(mInBase)) { >+ createMatches1(index, mInBase, polymorphicNames); >+ } > } > } > } catch (DOMException e) { >#P org.eclipse.cdt.ui.tests >Index: ui/org/eclipse/cdt/ui/tests/search/BasicSearchTest.java >=================================================================== >RCS file: /cvsroot/tools/org.eclipse.cdt-core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/search/BasicSearchTest.java,v >retrieving revision 1.12 >diff -u -r1.12 BasicSearchTest.java >--- ui/org/eclipse/cdt/ui/tests/search/BasicSearchTest.java 17 May 2010 14:16:13 -0000 1.12 >+++ ui/org/eclipse/cdt/ui/tests/search/BasicSearchTest.java 27 Sep 2010 15:12:13 -0000 >@@ -357,4 +357,28 @@ > PDOMSearchResult result= (PDOMSearchResult) query.getSearchResult(); > assertEquals(expected, result.getMatchCount()); > } >+ >+ // template<typename T> class CT {}; >+ // template<typename T> class CT<T*> {}; >+ // template<typename T> void f(T) {}; >+ // template<typename T> void f(T*) {}; >+ >+ // void a() { >+ // CT<int>* r1; >+ // CT<char>* r2; >+ // CT<int*>* r3; >+ // >+ // int a; >+ // f(a); >+ // f(&a); >+ // f<int>(a); >+ // f<int>(&a); >+ // } >+ public void testSearchAndTemplateIDs() throws Exception { >+ PDOMSearchQuery query= makeProjectQuery("CT"); >+ assertOccurrences(query, 5); >+ query= makeProjectQuery("f"); >+ assertOccurrences(query, 6); >+ } >+ > }
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Flags:
mschorn.eclipse
:
iplog-
Actions:
View
|
Diff
Attachments on
bug 325385
:
178977
| 179657