mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-06-09 10:46:02 +02:00
Patch for Andrew Niefer:
Patch for C++ Search to support searching for class declarations Interface changes: - modified search Interfaces : - ICSearchConstants - changed SearchFor instantiations to more closely match what we can search for. - ICSearchPattern - added getLimitTo() - ICSearchResultCollector - added createMatch(), which should return an object implementing the new IMatch interface, these store the any data needed to keep found matches. These interfaces are still new and its too early for anyone other than search and the indexer to be using them. - added search interface IMatch. Changes to core.search had to do with keeping track of the current scope during the search, as well as other modifications for matching class declarations, and the start of the patterns for matching other things. Changes to ui.search had to do with creating IMatch objects to store the information needed by the label provider to display icons and sort the results.
This commit is contained in:
parent
2c445a38b7
commit
0c232fa416
25 changed files with 941 additions and 249 deletions
|
@ -9,5 +9,10 @@ namespace NS {
|
|||
}
|
||||
class B {
|
||||
struct A {};
|
||||
enum e {};
|
||||
};
|
||||
union u{ } ;
|
||||
}
|
||||
|
||||
union u{
|
||||
};
|
|
@ -17,11 +17,14 @@ import java.util.Iterator;
|
|||
import java.util.Set;
|
||||
|
||||
import org.eclipse.cdt.core.search.ICSearchConstants;
|
||||
import org.eclipse.cdt.core.search.ICSearchPattern;
|
||||
import org.eclipse.cdt.core.search.SearchEngine;
|
||||
import org.eclipse.cdt.internal.core.search.CharOperation;
|
||||
import org.eclipse.cdt.internal.core.search.matching.CSearchPattern;
|
||||
import org.eclipse.cdt.internal.core.search.matching.ClassDeclarationPattern;
|
||||
import org.eclipse.cdt.internal.core.search.matching.MatchLocator;
|
||||
import org.eclipse.cdt.internal.ui.search.CSearchResultCollector;
|
||||
import org.eclipse.cdt.internal.ui.search.Match;
|
||||
import org.eclipse.core.runtime.Path;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
@ -42,7 +45,7 @@ public class ClassDeclarationPatternTests extends TestCase implements ICSearchCo
|
|||
super(name);
|
||||
}
|
||||
|
||||
private void initialize( CSearchPattern pattern ){
|
||||
private void initialize( ICSearchPattern pattern ){
|
||||
cppPath = org.eclipse.core.runtime.Platform.getPlugin("org.eclipse.cdt.core.tests").find(new Path("/")).getFile();
|
||||
cppPath += "resources/search/classDecl.cpp";
|
||||
|
||||
|
@ -51,7 +54,7 @@ public class ClassDeclarationPatternTests extends TestCase implements ICSearchCo
|
|||
}
|
||||
|
||||
public void testMatchSimpleDeclaration(){
|
||||
CSearchPattern pattern = CSearchPattern.createPattern( "A", TYPE, DECLARATIONS, EXACT_MATCH, true );
|
||||
ICSearchPattern pattern = SearchEngine.createSearchPattern( "A", TYPE, DECLARATIONS, true );
|
||||
|
||||
assertTrue( pattern instanceof ClassDeclarationPattern );
|
||||
|
||||
|
@ -64,7 +67,7 @@ public class ClassDeclarationPatternTests extends TestCase implements ICSearchCo
|
|||
}
|
||||
|
||||
public void testMatchNamespaceNestedDeclaration(){
|
||||
CSearchPattern pattern = CSearchPattern.createPattern( "NS::B", TYPE, DECLARATIONS, EXACT_MATCH, true );
|
||||
ICSearchPattern pattern = SearchEngine.createSearchPattern( "NS::B", TYPE, DECLARATIONS, true );
|
||||
|
||||
assertTrue( pattern instanceof ClassDeclarationPattern );
|
||||
|
||||
|
@ -83,7 +86,7 @@ public class ClassDeclarationPatternTests extends TestCase implements ICSearchCo
|
|||
}
|
||||
|
||||
public void testBug39652() {
|
||||
CSearchPattern pattern = CSearchPattern.createPattern( "A::B", TYPE, DECLARATIONS, EXACT_MATCH, true );
|
||||
ICSearchPattern pattern = SearchEngine.createSearchPattern( "A::B", TYPE, DECLARATIONS, true );
|
||||
|
||||
initialize( pattern );
|
||||
matchLocator.locateMatches( new String[] { cppPath }, null, null );
|
||||
|
@ -92,21 +95,21 @@ public class ClassDeclarationPatternTests extends TestCase implements ICSearchCo
|
|||
assertTrue( matches != null );
|
||||
assertTrue( matches.size() == 1 );
|
||||
|
||||
pattern = CSearchPattern.createPattern( "NS::NS2::a", TYPE, DECLARATIONS, EXACT_MATCH, true );
|
||||
pattern = SearchEngine.createSearchPattern( "NS::NS2::a", TYPE, DECLARATIONS, true );
|
||||
initialize( pattern );
|
||||
matchLocator.locateMatches( new String[] { cppPath }, null, null );
|
||||
matches = resultCollector.getMatches();
|
||||
assertTrue( matches != null );
|
||||
|
||||
pattern = CSearchPattern.createPattern( "NS::B::A", TYPE, DECLARATIONS, EXACT_MATCH, true );
|
||||
pattern = SearchEngine.createSearchPattern( "NS::B::A", TYPE, DECLARATIONS, true );
|
||||
initialize( pattern );
|
||||
matchLocator.locateMatches( new String[] { cppPath }, null, null );
|
||||
matches = resultCollector.getMatches();
|
||||
assertTrue( matches != null );
|
||||
}
|
||||
|
||||
public void failingtestMatchStruct(){
|
||||
CSearchPattern pattern = CSearchPattern.createPattern( "A", STRUCT, DECLARATIONS, EXACT_MATCH, true );
|
||||
public void testMatchStruct(){
|
||||
ICSearchPattern pattern = SearchEngine.createSearchPattern( "A", STRUCT, DECLARATIONS, true );
|
||||
|
||||
assertTrue( pattern instanceof ClassDeclarationPattern );
|
||||
|
||||
|
@ -119,7 +122,7 @@ public class ClassDeclarationPatternTests extends TestCase implements ICSearchCo
|
|||
Set matches = resultCollector.getMatches();
|
||||
assertEquals( matches.size(), 1 );
|
||||
|
||||
pattern = CSearchPattern.createPattern( "NS::B::A", TYPE, DECLARATIONS, EXACT_MATCH, true );
|
||||
pattern = SearchEngine.createSearchPattern( "NS::B::A", TYPE, DECLARATIONS, true );
|
||||
|
||||
initialize( pattern );
|
||||
matchLocator.locateMatches( new String[] { cppPath }, null, null );
|
||||
|
@ -131,12 +134,48 @@ public class ClassDeclarationPatternTests extends TestCase implements ICSearchCo
|
|||
Iterator iter = matches.iterator();
|
||||
Iterator iter2 = matches2.iterator();
|
||||
|
||||
CSearchResultCollector.Match match = (CSearchResultCollector.Match)iter.next();
|
||||
CSearchResultCollector.Match match2 = (CSearchResultCollector.Match)iter2.next();
|
||||
Match match = (Match)iter.next();
|
||||
Match match2 = (Match)iter2.next();
|
||||
|
||||
assertTrue( match.path.equals( match2.path ) );
|
||||
//assertTrue( match.path.equals( match2.path ) );
|
||||
assertEquals( match.start, match2.start );
|
||||
assertEquals( match.end, match2.end );
|
||||
}
|
||||
|
||||
public void testWildcardQualification() {
|
||||
ICSearchPattern pattern = SearchEngine.createSearchPattern( "::*::A", TYPE, DECLARATIONS, true );
|
||||
initialize( pattern );
|
||||
matchLocator.locateMatches( new String [] { cppPath }, null, null );
|
||||
|
||||
Set matches = resultCollector.getMatches();
|
||||
assertEquals( matches, null );
|
||||
|
||||
pattern = SearchEngine.createSearchPattern( "NS::*::A", TYPE, DECLARATIONS, false );
|
||||
initialize( pattern );
|
||||
matchLocator.locateMatches( new String [] { cppPath }, null, null );
|
||||
|
||||
matches = resultCollector.getMatches();
|
||||
assertEquals( matches.size(), 2 );
|
||||
}
|
||||
|
||||
public void testElaboratedType(){
|
||||
ICSearchPattern pattern = SearchEngine.createSearchPattern( "struct A", TYPE, DECLARATIONS, true );
|
||||
initialize( pattern );
|
||||
matchLocator.locateMatches( new String [] { cppPath }, null, null );
|
||||
Set matches = resultCollector.getMatches();
|
||||
assertEquals( matches.size(), 1 );
|
||||
|
||||
pattern = SearchEngine.createSearchPattern( "union u", TYPE, DECLARATIONS, true );
|
||||
initialize( pattern );
|
||||
matchLocator.locateMatches( new String [] { cppPath }, null, null );
|
||||
matches = resultCollector.getMatches();
|
||||
assertEquals( matches.size(), 2 );
|
||||
|
||||
pattern = SearchEngine.createSearchPattern( "union ::*::u", TYPE, DECLARATIONS, true );
|
||||
initialize( pattern );
|
||||
matchLocator.locateMatches( new String [] { cppPath }, null, null );
|
||||
matches = resultCollector.getMatches();
|
||||
assertEquals( matches.size(), 1 );
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,3 +1,19 @@
|
|||
2003-07-14 Andrew Niefer
|
||||
-Modified SearchFor instances in ICSearchConstants to more closely match what we are searching for
|
||||
-added IMatch interface, it represents matches found by the search engine, implementors can store
|
||||
whatever information they like, see ICSearchResultCollector::createMatch
|
||||
-added createMatch to the ICSearchResultCollector interface, the result collector is responsible for
|
||||
implementing IMatch to store whatever data they want out of the AST nodes.
|
||||
-added skeleton patterns:
|
||||
search/org/eclipse/cdt/internal/core/search/matching/FieldDeclarationPattern.java
|
||||
search/org/eclipse/cdt/internal/core/search/matching/FunctionDeclarationPattern.java
|
||||
search/org/eclipse/cdt/internal/core/search/matching/MethodDeclarationPattern.java
|
||||
search/org/eclipse/cdt/internal/core/search/matching/NamespaceDeclarationPattern.java
|
||||
search/org/eclipse/cdt/internal/core/search/matching/VariableDeclarationPattern.java
|
||||
-added beginnings of CSearchPattern::create*Pattern functions
|
||||
-modifications to MatchLocator to keep track of current scope
|
||||
-added CSearchPattern::matchQualifications
|
||||
|
||||
2003-07-10 Bogdan Gheorghe
|
||||
Provided implementation for ICSearchScope.java, CSearchScope.java
|
||||
|
||||
|
|
|
@ -54,14 +54,14 @@ public interface ICSearchConstants {
|
|||
public static final SearchFor NAMESPACE = new SearchFor( 2 );
|
||||
|
||||
/**
|
||||
* The searched element is a constructor.
|
||||
* The searched element is a method (member function).
|
||||
*/
|
||||
public static final SearchFor CONSTRUCTOR = new SearchFor( 3 );
|
||||
public static final SearchFor METHOD = new SearchFor( 3 );
|
||||
|
||||
/**
|
||||
* The searched element is a member.
|
||||
* The searched element is a field (member variable).
|
||||
*/
|
||||
public static final SearchFor MEMBER = new SearchFor( 4 );
|
||||
public static final SearchFor FIELD = new SearchFor( 4 );
|
||||
|
||||
/**
|
||||
* The searched element is a variable.
|
||||
|
|
|
@ -21,7 +21,7 @@ import org.eclipse.cdt.core.parser.ast.IASTOffsetableElement;
|
|||
* To change the template for this generated type comment go to
|
||||
* Window>Preferences>Java>Code Generation>Code and Comments
|
||||
*/
|
||||
public interface ICSearchPattern {
|
||||
public interface ICSearchPattern extends ICSearchConstants{
|
||||
|
||||
public static final int IMPOSSIBLE_MATCH = 0;
|
||||
public static final int POSSIBLE_MATCH = 1;
|
||||
|
@ -34,4 +34,5 @@ public interface ICSearchPattern {
|
|||
*/
|
||||
int matchLevel( IASTOffsetableElement node );
|
||||
|
||||
LimitTo getLimitTo();
|
||||
}
|
||||
|
|
|
@ -14,6 +14,8 @@
|
|||
package org.eclipse.cdt.core.search;
|
||||
|
||||
import org.eclipse.cdt.core.model.ICElement;
|
||||
import org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement;
|
||||
import org.eclipse.cdt.core.parser.ast.IASTScope;
|
||||
import org.eclipse.core.resources.IResource;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.core.runtime.IPath;
|
||||
|
@ -50,9 +52,9 @@ public interface ICSearchResultCollector {
|
|||
* @param end the end position of the match, -1 if it is unknown;
|
||||
* the ending offset is exclusive, meaning that the actual range of characters
|
||||
* covered is <code>[start, end]</code>
|
||||
* @param enclosingElement the Java element that contains the character range
|
||||
* @param enclosingObject an object that contains the character range
|
||||
* <code>[start, end]</code>; the value can be <code>null</code> indicating that
|
||||
* no enclosing Java element has been found
|
||||
* no enclosing object has been found
|
||||
* @param accuracy the level of accuracy the search result has; either
|
||||
* <code>EXACT_MATCH</code> or <code>POTENTIAL_MATCH</code>
|
||||
* @exception CoreException if this collector had a problem accepting the search result
|
||||
|
@ -61,7 +63,7 @@ public interface ICSearchResultCollector {
|
|||
IResource resource,
|
||||
int start,
|
||||
int end,
|
||||
ICElement enclosingElement,
|
||||
IMatch enclosingObject,
|
||||
int accuracy)
|
||||
throws CoreException;
|
||||
|
||||
|
@ -85,7 +87,16 @@ public interface ICSearchResultCollector {
|
|||
public void accept(IPath currentPath,
|
||||
int start,
|
||||
int end,
|
||||
ICElement enclosingElement,
|
||||
IMatch enclosingObject,
|
||||
int accuracyLevel) throws CoreException;
|
||||
|
||||
/**
|
||||
* returns an IMatch object that contains any information the client cared
|
||||
* to extract from the IAST node.
|
||||
* Note that clients should not reference information in the node itself so
|
||||
* that it can be garbage collected
|
||||
* @param node
|
||||
* @return
|
||||
*/
|
||||
public IMatch createMatch(IASTOffsetableNamedElement node, IASTScope parent );
|
||||
}
|
||||
|
|
|
@ -0,0 +1,24 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2003 IBM Corporation and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Common Public License v0.5
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/cpl-v05.html
|
||||
*
|
||||
* Contributors:
|
||||
* IBM Corp. - Rational Software - initial implementation
|
||||
******************************************************************************/
|
||||
/*
|
||||
* Created on Jul 10, 2003
|
||||
*/
|
||||
package org.eclipse.cdt.core.search;
|
||||
|
||||
/**
|
||||
* @author aniefer
|
||||
*
|
||||
* To change the template for this generated type comment go to
|
||||
* Window>Preferences>Java>Code Generation>Code and Comments
|
||||
*/
|
||||
public interface IMatch {
|
||||
|
||||
}
|
|
@ -52,9 +52,14 @@ public abstract class CSearchPattern implements ICSearchConstants, ICSearchPatte
|
|||
* @param matchMode
|
||||
* @param caseSensitive
|
||||
*/
|
||||
public CSearchPattern(int matchMode, boolean caseSensitive) {
|
||||
public CSearchPattern(int matchMode, boolean caseSensitive, LimitTo limitTo ) {
|
||||
_matchMode = matchMode;
|
||||
_caseSensitive = caseSensitive;
|
||||
_limitTo = limitTo;
|
||||
}
|
||||
|
||||
public LimitTo getLimitTo(){
|
||||
return _limitTo;
|
||||
}
|
||||
|
||||
public CSearchPattern() {
|
||||
|
@ -69,14 +74,18 @@ public abstract class CSearchPattern implements ICSearchConstants, ICSearchPatte
|
|||
CSearchPattern pattern = null;
|
||||
if( searchFor == TYPE || searchFor == CLASS || searchFor == STRUCT || searchFor == ENUM || searchFor == UNION ){
|
||||
pattern = createClassPattern( patternString, searchFor, limitTo, matchMode, caseSensitive );
|
||||
} else if ( searchFor == MEMBER ){
|
||||
// pattern = createMethodPattern( patternString, limitTo, matchMode, caseSensitive );
|
||||
} else if ( searchFor == CONSTRUCTOR ){
|
||||
pattern = createConstructorPattern( patternString, limitTo, matchMode, caseSensitive );
|
||||
} else if ( searchFor == METHOD ){
|
||||
pattern = createMethodPattern( patternString, limitTo, matchMode, caseSensitive );
|
||||
} else if ( searchFor == FIELD){
|
||||
pattern = createFieldPattern( patternString, limitTo, matchMode, caseSensitive );
|
||||
} else if ( searchFor == VAR ){
|
||||
pattern = createVariablePattern( patternString, limitTo, matchMode, caseSensitive );
|
||||
} else if ( searchFor == FUNCTION ){
|
||||
pattern = createFunctionPattern( patternString, limitTo, matchMode, caseSensitive );
|
||||
} else if ( searchFor == NAMESPACE ){
|
||||
pattern = createNamespacePattern( patternString, limitTo, matchMode, caseSensitive );
|
||||
}
|
||||
//case ICSearchConstants.FIELD:
|
||||
// pattern = createFieldPattern( patternString, limitTo, matchMode, caseSensitive );
|
||||
// break;
|
||||
|
||||
return pattern;
|
||||
}
|
||||
|
||||
|
@ -87,11 +96,57 @@ public abstract class CSearchPattern implements ICSearchConstants, ICSearchPatte
|
|||
* @param caseSensitive
|
||||
* @return
|
||||
*/
|
||||
private static CSearchPattern createFieldPattern(String patternString, LimitTo limitTo, int matchMode, boolean caseSensitive) {
|
||||
private static CSearchPattern createNamespacePattern(String patternString, LimitTo limitTo, int matchMode, boolean caseSensitive) {
|
||||
IScanner scanner = ParserFactory.createScanner( new StringReader( patternString ), "TEXT", new ScannerInfo(), ParserMode.QUICK_PARSE );
|
||||
LinkedList list = scanForNames( scanner, null );
|
||||
|
||||
char [] name = (char []) list.removeLast();
|
||||
char [][] qualifications = new char [0][];
|
||||
|
||||
return new NamespaceDeclarationPattern( name, (char[][]) list.toArray( qualifications ), matchMode, limitTo, caseSensitive );
|
||||
}
|
||||
|
||||
/**
|
||||
* @param patternString
|
||||
* @param limitTo
|
||||
* @param matchMode
|
||||
* @param caseSensitive
|
||||
* @return
|
||||
*/
|
||||
private static CSearchPattern createFunctionPattern(String patternString, LimitTo limitTo, int matchMode, boolean caseSensitive) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param patternString
|
||||
* @param limitTo
|
||||
* @param matchMode
|
||||
* @param caseSensitive
|
||||
* @return
|
||||
*/
|
||||
private static CSearchPattern createVariablePattern(String patternString, LimitTo limitTo, int matchMode, boolean caseSensitive) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param patternString
|
||||
* @param limitTo
|
||||
* @param matchMode
|
||||
* @param caseSensitive
|
||||
* @return
|
||||
*/
|
||||
private static CSearchPattern createFieldPattern(String patternString, LimitTo limitTo, int matchMode, boolean caseSensitive) {
|
||||
IScanner scanner = ParserFactory.createScanner( new StringReader( patternString ), "TEXT", new ScannerInfo(), ParserMode.QUICK_PARSE );
|
||||
LinkedList list = scanForNames( scanner, null );
|
||||
|
||||
char [] name = (char []) list.removeLast();
|
||||
char [][] qualifications = new char[0][];
|
||||
|
||||
return new FieldDeclarationPattern( name, (char[][]) list.toArray( qualifications ), matchMode, limitTo, caseSensitive );
|
||||
}
|
||||
|
||||
/**
|
||||
* @param patternString
|
||||
* @param limitTo
|
||||
|
@ -100,21 +155,9 @@ public abstract class CSearchPattern implements ICSearchConstants, ICSearchPatte
|
|||
* @return
|
||||
*/
|
||||
private static CSearchPattern createMethodPattern(String patternString, LimitTo limitTo, int matchMode, boolean caseSensitive) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param patternString
|
||||
* @param limitTo
|
||||
* @param matchMode
|
||||
* @param caseSensitive
|
||||
* @return
|
||||
*/
|
||||
private static CSearchPattern createConstructorPattern(String patternString, LimitTo limitTo, int matchMode, boolean caseSensitive) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param patternString
|
||||
|
@ -126,41 +169,81 @@ public abstract class CSearchPattern implements ICSearchConstants, ICSearchPatte
|
|||
private static CSearchPattern createClassPattern(String patternString, SearchFor searchFor, LimitTo limitTo, int matchMode, boolean caseSensitive) {
|
||||
IScanner scanner = ParserFactory.createScanner( new StringReader( patternString ), "TEXT", new ScannerInfo(), ParserMode.QUICK_PARSE );
|
||||
|
||||
LinkedList list = new LinkedList();
|
||||
IToken token = null;
|
||||
String name = new String("");
|
||||
IToken token = null;
|
||||
ASTClassKind kind = null;
|
||||
|
||||
try {
|
||||
token = scanner.nextToken();
|
||||
} catch (EndOfFile e) {
|
||||
} catch (ScannerException e) {
|
||||
}
|
||||
|
||||
if( token != null ){
|
||||
if( token.getType() == IToken.t_class ){
|
||||
kind = ASTClassKind.CLASS;
|
||||
} else if ( token.getType() == IToken.t_struct ){
|
||||
kind = ASTClassKind.STRUCT;
|
||||
} else if ( token.getType() == IToken.t_union ){
|
||||
kind = ASTClassKind.UNION;
|
||||
} else if ( token.getType() == IToken.t_enum ){
|
||||
kind = ASTClassKind.ENUM;
|
||||
}
|
||||
if( kind != null ){
|
||||
token = null;
|
||||
} else {
|
||||
if( searchFor == CLASS ){
|
||||
kind = ASTClassKind.CLASS;
|
||||
} else if( searchFor == STRUCT ) {
|
||||
kind = ASTClassKind.STRUCT;
|
||||
} else if ( searchFor == ENUM ) {
|
||||
kind = ASTClassKind.ENUM;
|
||||
} else if ( searchFor == UNION ) {
|
||||
kind = ASTClassKind.UNION;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
LinkedList list = scanForNames( scanner, token );
|
||||
|
||||
char[] name = (char [])list.removeLast();
|
||||
char [][] qualifications = new char[0][];
|
||||
|
||||
return new ClassDeclarationPattern( name, (char[][])list.toArray( qualifications ), kind, matchMode, limitTo, caseSensitive );
|
||||
}
|
||||
|
||||
static private LinkedList scanForNames( IScanner scanner, IToken unusedToken ){
|
||||
LinkedList list = new LinkedList();
|
||||
|
||||
String name = new String("");
|
||||
|
||||
try {
|
||||
IToken token = ( unusedToken != null ) ? unusedToken : scanner.nextToken();
|
||||
|
||||
while( true ){
|
||||
token = scanner.nextToken();
|
||||
|
||||
switch( token.getType() ){
|
||||
case IToken.tCOLONCOLON :
|
||||
list.addLast( name.toCharArray() );
|
||||
name = new String("");
|
||||
break;
|
||||
default:
|
||||
if( token.getType() != IToken.tSTAR &&
|
||||
token.getType() != IToken.tQUESTION &&
|
||||
name.length() > 0 )
|
||||
{
|
||||
name += " ";
|
||||
}
|
||||
name += token.getImage();
|
||||
break;
|
||||
}
|
||||
|
||||
token = scanner.nextToken();
|
||||
}
|
||||
} catch (EndOfFile e) {
|
||||
list.addLast( name.toCharArray() );
|
||||
} catch (ScannerException e) {
|
||||
}
|
||||
|
||||
ASTClassKind kind = null;
|
||||
if( searchFor == CLASS ){
|
||||
kind = ASTClassKind.CLASS;
|
||||
} else if( searchFor == STRUCT ) {
|
||||
kind = ASTClassKind.STRUCT;
|
||||
} else if ( searchFor == ENUM ) {
|
||||
kind = ASTClassKind.ENUM;
|
||||
} else if ( searchFor == UNION ) {
|
||||
kind = ASTClassKind.UNION;
|
||||
}
|
||||
|
||||
char [][] qualifications = new char[0][];
|
||||
return new ClassDeclarationPattern( name.toCharArray(), (char[][])list.toArray( qualifications ), kind, matchMode, caseSensitive );
|
||||
return list;
|
||||
}
|
||||
|
||||
protected boolean matchesName( char[] pattern, char[] name ){
|
||||
|
@ -185,6 +268,32 @@ public abstract class CSearchPattern implements ICSearchConstants, ICSearchPatte
|
|||
return false;
|
||||
}
|
||||
|
||||
protected boolean matchQualifications( char[][] qualifications, String [] fullyQualifiedName ){
|
||||
|
||||
int qualLen = qualifications != null ? qualifications.length : 0;
|
||||
int fullLen = fullyQualifiedName != null ? fullyQualifiedName.length : 0;
|
||||
|
||||
if( qualLen == 0 ){
|
||||
return true;
|
||||
}
|
||||
|
||||
int root = ( qualifications[0].length == 0 ) ? 1 : 0;
|
||||
|
||||
if( (root == 1 && fullLen - 1 != qualLen - 1 ) ||
|
||||
(root == 0 && fullLen - 1 < qualLen ) )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
for( int i = 1; i <= qualLen - root; i++ ){
|
||||
if( !matchesName( qualifications[ qualLen - i - root ], fullyQualifiedName[ fullLen - i - 1 ].toCharArray() ) ){
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Query a given index for matching entries.
|
||||
*/
|
||||
|
@ -208,7 +317,10 @@ public abstract class CSearchPattern implements ICSearchConstants, ICSearchPatte
|
|||
if (progressMonitor != null && progressMonitor.isCanceled()) throw new OperationCanceledException();
|
||||
|
||||
/* narrow down a set of entries using prefix criteria */
|
||||
IEntryResult[] entries = input.queryEntriesPrefixedBy(indexEntryPrefix());
|
||||
char [] prefix = indexEntryPrefix();
|
||||
if( prefix == null ) return;
|
||||
|
||||
IEntryResult[] entries = input.queryEntriesPrefixedBy( prefix );
|
||||
if (entries == null) return;
|
||||
|
||||
/* only select entries which actually match the entire search pattern */
|
||||
|
@ -247,4 +359,5 @@ public abstract class CSearchPattern implements ICSearchConstants, ICSearchPatte
|
|||
|
||||
protected int _matchMode;
|
||||
protected boolean _caseSensitive;
|
||||
protected LimitTo _limitTo;
|
||||
}
|
||||
|
|
|
@ -17,7 +17,9 @@ import java.io.IOException;
|
|||
|
||||
import org.eclipse.cdt.core.parser.ast.ASTClassKind;
|
||||
import org.eclipse.cdt.core.parser.ast.IASTClassSpecifier;
|
||||
import org.eclipse.cdt.core.parser.ast.IASTEnumerationSpecifier;
|
||||
import org.eclipse.cdt.core.parser.ast.IASTOffsetableElement;
|
||||
import org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement;
|
||||
import org.eclipse.cdt.core.search.ICSearchScope;
|
||||
import org.eclipse.cdt.internal.core.index.IEntryResult;
|
||||
import org.eclipse.cdt.internal.core.index.impl.IndexInput;
|
||||
|
@ -26,6 +28,7 @@ import org.eclipse.cdt.internal.core.search.CharOperation;
|
|||
import org.eclipse.cdt.internal.core.search.IIndexSearchRequestor;
|
||||
import org.eclipse.cdt.internal.core.search.indexing.AbstractIndexer;
|
||||
|
||||
|
||||
/**
|
||||
* @author aniefer
|
||||
*/
|
||||
|
@ -33,11 +36,12 @@ import org.eclipse.cdt.internal.core.search.indexing.AbstractIndexer;
|
|||
public class ClassDeclarationPattern extends CSearchPattern {
|
||||
|
||||
public ClassDeclarationPattern( int matchMode, boolean caseSensitive ){
|
||||
super( matchMode, caseSensitive );
|
||||
super( matchMode, caseSensitive, DECLARATIONS );
|
||||
}
|
||||
|
||||
public ClassDeclarationPattern( char[] name, char[][] containers, ASTClassKind kind, int mode, boolean caseSensitive ){
|
||||
super( mode, caseSensitive );
|
||||
public ClassDeclarationPattern( char[] name, char[][] containers, ASTClassKind kind, int mode, LimitTo limit, boolean caseSensitive ){
|
||||
super( mode, caseSensitive, limit );
|
||||
|
||||
simpleName = caseSensitive ? name : CharOperation.toLowerCase( name );
|
||||
if( caseSensitive || containers == null ){
|
||||
containingTypes = containers;
|
||||
|
@ -48,41 +52,45 @@ public class ClassDeclarationPattern extends CSearchPattern {
|
|||
this.containingTypes[i] = CharOperation.toLowerCase( containers[i] );
|
||||
}
|
||||
}
|
||||
|
||||
classKind = kind;
|
||||
limitTo = limit;
|
||||
}
|
||||
|
||||
public int matchLevel( IASTOffsetableElement node ){
|
||||
if( !( node instanceof IASTClassSpecifier ) )
|
||||
|
||||
if( !( node instanceof IASTClassSpecifier ) && !( node instanceof IASTEnumerationSpecifier ) )
|
||||
return IMPOSSIBLE_MATCH;
|
||||
|
||||
IASTClassSpecifier clsSpec = (IASTClassSpecifier) node;
|
||||
String nodeName = clsSpec.getName();
|
||||
|
||||
String nodeName = ((IASTOffsetableNamedElement)node).getName();
|
||||
|
||||
//check name, if simpleName == null, its treated the same as "*"
|
||||
if( simpleName != null && !matchesName( simpleName, clsSpec.getName().toCharArray() ) ){
|
||||
if( simpleName != null && !matchesName( simpleName, nodeName.toCharArray() ) ){
|
||||
return IMPOSSIBLE_MATCH;
|
||||
}
|
||||
|
||||
String [] fullyQualifiedName = null;
|
||||
|
||||
if( node instanceof IASTClassSpecifier ){
|
||||
IASTClassSpecifier clsSpec = (IASTClassSpecifier) node;
|
||||
fullyQualifiedName = clsSpec.getFullyQualifiedName();
|
||||
} else {
|
||||
//TODO fully qualified names for enums
|
||||
}
|
||||
|
||||
//check containing scopes
|
||||
String [] qualifications = clsSpec.getFullyQualifiedName();
|
||||
if( qualifications != null ){
|
||||
|
||||
int size = containingTypes.length;
|
||||
if( qualifications.length < size )
|
||||
return IMPOSSIBLE_MATCH;
|
||||
|
||||
for( int i = 0; i < containingTypes.length; i++ ){
|
||||
if( !matchesName( containingTypes[i], qualifications[i].toCharArray() ) ){
|
||||
return IMPOSSIBLE_MATCH;
|
||||
}
|
||||
}
|
||||
} else if( containingTypes.length > 0 ) {
|
||||
if( !matchQualifications( containingTypes, fullyQualifiedName ) ){
|
||||
return IMPOSSIBLE_MATCH;
|
||||
}
|
||||
|
||||
//check type
|
||||
if( classKind != null && classKind != clsSpec.getClassKind() ){
|
||||
return IMPOSSIBLE_MATCH;
|
||||
if( classKind != null ){
|
||||
if( node instanceof IASTClassSpecifier ){
|
||||
IASTClassSpecifier clsSpec = (IASTClassSpecifier) node;
|
||||
return ( classKind == clsSpec.getClassKind() ) ? ACCURATE_MATCH : IMPOSSIBLE_MATCH;
|
||||
} else {
|
||||
return ( classKind == ASTClassKind.ENUM ) ? ACCURATE_MATCH : IMPOSSIBLE_MATCH;
|
||||
}
|
||||
}
|
||||
|
||||
return ACCURATE_MATCH;
|
||||
|
@ -94,10 +102,14 @@ public class ClassDeclarationPattern extends CSearchPattern {
|
|||
public char[] [] getContainingTypes () {
|
||||
return containingTypes;
|
||||
}
|
||||
|
||||
public ASTClassKind getKind(){
|
||||
return classKind;
|
||||
}
|
||||
|
||||
private char[] simpleName;
|
||||
private char[][] containingTypes;
|
||||
private ASTClassKind classKind;
|
||||
private LimitTo limitTo;
|
||||
|
||||
protected char[] decodedSimpleName;
|
||||
private char[][] decodedContainingTypes;
|
||||
|
|
|
@ -0,0 +1,37 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2003 IBM Corporation and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Common Public License v0.5
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/cpl-v05.html
|
||||
*
|
||||
* Contributors:
|
||||
* IBM Corp. - Rational Software - initial implementation
|
||||
******************************************************************************/
|
||||
/*
|
||||
* Created on Jul 11, 2003
|
||||
*/
|
||||
package org.eclipse.cdt.internal.core.search.matching;
|
||||
|
||||
|
||||
/**
|
||||
* @author aniefer
|
||||
*
|
||||
* To change the template for this generated type comment go to
|
||||
* Window>Preferences>Java>Code Generation>Code and Comments
|
||||
*/
|
||||
public class FieldDeclarationPattern extends VariableDeclarationPattern {
|
||||
|
||||
/**
|
||||
* @param name
|
||||
* @param cs
|
||||
* @param matchMode
|
||||
* @param limitTo
|
||||
* @param caseSensitive
|
||||
*/
|
||||
public FieldDeclarationPattern(char[] name, char[][] cs, int matchMode, LimitTo limitTo, boolean caseSensitive) {
|
||||
super( name, matchMode, limitTo, caseSensitive );
|
||||
// TODO Auto-generated constructor stub
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,72 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2003 IBM Corporation and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Common Public License v0.5
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/cpl-v05.html
|
||||
*
|
||||
* Contributors:
|
||||
* IBM Corp. - Rational Software - initial implementation
|
||||
******************************************************************************/
|
||||
/*
|
||||
* Created on Jul 11, 2003
|
||||
*/
|
||||
package org.eclipse.cdt.internal.core.search.matching;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.eclipse.cdt.core.parser.ast.IASTOffsetableElement;
|
||||
import org.eclipse.cdt.core.search.ICSearchScope;
|
||||
import org.eclipse.cdt.internal.core.index.IEntryResult;
|
||||
import org.eclipse.cdt.internal.core.index.impl.IndexInput;
|
||||
import org.eclipse.cdt.internal.core.search.IIndexSearchRequestor;
|
||||
|
||||
/**
|
||||
* @author aniefer
|
||||
*
|
||||
* To change the template for this generated type comment go to
|
||||
* Window>Preferences>Java>Code Generation>Code and Comments
|
||||
*/
|
||||
public class FunctionDeclarationPattern extends CSearchPattern {
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.search.ICSearchPattern#matchLevel(org.eclipse.cdt.core.parser.ast.IASTOffsetableElement)
|
||||
*/
|
||||
public int matchLevel(IASTOffsetableElement node) {
|
||||
// TODO Auto-generated method stub
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.core.search.matching.CSearchPattern#feedIndexRequestor(org.eclipse.cdt.internal.core.search.IIndexSearchRequestor, int, int[], org.eclipse.cdt.internal.core.index.impl.IndexInput, org.eclipse.cdt.core.search.ICSearchScope)
|
||||
*/
|
||||
public void feedIndexRequestor(IIndexSearchRequestor requestor, int detailLevel, int[] references, IndexInput input, ICSearchScope scope) throws IOException {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.core.search.matching.CSearchPattern#decodeIndexEntry(org.eclipse.cdt.internal.core.index.IEntryResult)
|
||||
*/
|
||||
protected void decodeIndexEntry(IEntryResult entryResult) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.core.search.matching.CSearchPattern#indexEntryPrefix()
|
||||
*/
|
||||
public char[] indexEntryPrefix() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.core.search.matching.CSearchPattern#matchIndexEntry()
|
||||
*/
|
||||
protected boolean matchIndexEntry() {
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
|
@ -27,6 +27,7 @@ import org.eclipse.cdt.core.parser.IScanner;
|
|||
import org.eclipse.cdt.core.parser.ISourceElementRequestor;
|
||||
import org.eclipse.cdt.core.parser.ParserFactory;
|
||||
import org.eclipse.cdt.core.parser.ParserMode;
|
||||
import org.eclipse.cdt.core.parser.ast.ASTClassKind;
|
||||
import org.eclipse.cdt.core.parser.ast.IASTASMDefinition;
|
||||
import org.eclipse.cdt.core.parser.ast.IASTClassReference;
|
||||
import org.eclipse.cdt.core.parser.ast.IASTClassSpecifier;
|
||||
|
@ -42,6 +43,7 @@ import org.eclipse.cdt.core.parser.ast.IASTMacro;
|
|||
import org.eclipse.cdt.core.parser.ast.IASTMethod;
|
||||
import org.eclipse.cdt.core.parser.ast.IASTNamespaceDefinition;
|
||||
import org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement;
|
||||
import org.eclipse.cdt.core.parser.ast.IASTScope;
|
||||
import org.eclipse.cdt.core.parser.ast.IASTTemplateDeclaration;
|
||||
import org.eclipse.cdt.core.parser.ast.IASTTemplateInstantiation;
|
||||
import org.eclipse.cdt.core.parser.ast.IASTTemplateSpecialization;
|
||||
|
@ -49,6 +51,7 @@ import org.eclipse.cdt.core.parser.ast.IASTTypedef;
|
|||
import org.eclipse.cdt.core.parser.ast.IASTUsingDeclaration;
|
||||
import org.eclipse.cdt.core.parser.ast.IASTUsingDirective;
|
||||
import org.eclipse.cdt.core.parser.ast.IASTVariable;
|
||||
import org.eclipse.cdt.core.search.ICSearchConstants;
|
||||
import org.eclipse.cdt.core.search.ICSearchPattern;
|
||||
import org.eclipse.cdt.core.search.ICSearchResultCollector;
|
||||
import org.eclipse.cdt.core.search.ICSearchScope;
|
||||
|
@ -71,7 +74,7 @@ import org.eclipse.core.runtime.Path;
|
|||
* To change the template for this generated type comment go to
|
||||
* Window>Preferences>Java>Code Generation>Code and Comments
|
||||
*/
|
||||
public class MatchLocator implements ISourceElementRequestor {
|
||||
public class MatchLocator implements ISourceElementRequestor, ICSearchConstants {
|
||||
|
||||
|
||||
/**
|
||||
|
@ -94,28 +97,79 @@ public class MatchLocator implements ISourceElementRequestor {
|
|||
public void acceptASMDefinition(IASTASMDefinition asmDefinition) { }
|
||||
public void acceptTypedef(IASTTypedef typedef) { }
|
||||
public void acceptEnumerator(IASTEnumerator enumerator) { }
|
||||
public void acceptEnumerationSpecifier(IASTEnumerationSpecifier enumeration){ }
|
||||
|
||||
public void acceptEnumerationSpecifier(IASTEnumerationSpecifier enumeration){
|
||||
if( searchPattern.getLimitTo() == DECLARATIONS || searchPattern.getLimitTo() == ALL_OCCURRENCES ){
|
||||
if( searchPattern instanceof ClassDeclarationPattern ){
|
||||
ClassDeclarationPattern classPattern = (ClassDeclarationPattern)searchPattern;
|
||||
if( classPattern.getKind() == null || classPattern.getKind() == ASTClassKind.ENUM ){
|
||||
int level = searchPattern.matchLevel( enumeration );
|
||||
if( level != ICSearchPattern.IMPOSSIBLE_MATCH ){
|
||||
report( enumeration, level );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void acceptClassReference(IASTClassReference reference) { }
|
||||
public void acceptElaboratedTypeSpecifier(IASTElaboratedTypeSpecifier elaboratedTypeSpec){ }
|
||||
public void acceptMethodDeclaration(IASTMethod method) { }
|
||||
public void acceptField(IASTField field) { }
|
||||
public void enterFunctionBody(IASTFunction function) { }
|
||||
public void enterCompilationUnit(IASTCompilationUnit compilationUnit) { }
|
||||
public void enterNamespaceDefinition(IASTNamespaceDefinition namespaceDefinition) { }
|
||||
|
||||
public void enterFunctionBody(IASTFunction function){
|
||||
pushScope( function );
|
||||
}
|
||||
|
||||
public void enterCompilationUnit(IASTCompilationUnit compilationUnit) {
|
||||
pushScope( compilationUnit );
|
||||
}
|
||||
|
||||
public void enterNamespaceDefinition(IASTNamespaceDefinition namespaceDefinition) {
|
||||
if( searchPattern.getLimitTo() == DECLARATIONS || searchPattern.getLimitTo() == ALL_OCCURRENCES ){
|
||||
if( searchPattern instanceof NamespaceDeclarationPattern ){
|
||||
int level = searchPattern.matchLevel( namespaceDefinition );
|
||||
if( level != ICSearchPattern.IMPOSSIBLE_MATCH ){
|
||||
report( namespaceDefinition, level );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pushScope( namespaceDefinition );
|
||||
}
|
||||
|
||||
public void enterLinkageSpecification(IASTLinkageSpecification linkageSpec) { }
|
||||
public void enterTemplateDeclaration(IASTTemplateDeclaration declaration) { }
|
||||
public void enterTemplateSpecialization(IASTTemplateSpecialization specialization) { }
|
||||
public void enterTemplateExplicitInstantiation(IASTTemplateInstantiation instantiation) { }
|
||||
public void enterMethodBody(IASTMethod method) { }
|
||||
public void exitFunctionBody(IASTFunction function) { }
|
||||
public void exitMethodBody(IASTMethod method) { }
|
||||
public void exitTemplateDeclaration(IASTTemplateDeclaration declaration) { }
|
||||
|
||||
public void enterMethodBody(IASTMethod method) {
|
||||
pushScope( method );
|
||||
}
|
||||
|
||||
public void exitFunctionBody(IASTFunction function) {
|
||||
popScope();
|
||||
}
|
||||
public void exitMethodBody(IASTMethod method) {
|
||||
popScope();
|
||||
}
|
||||
|
||||
public void exitTemplateDeclaration(IASTTemplateDeclaration declaration) {}
|
||||
public void exitTemplateSpecialization(IASTTemplateSpecialization specialization) { }
|
||||
public void exitTemplateExplicitInstantiation(IASTTemplateInstantiation instantiation) { }
|
||||
public void exitLinkageSpecification(IASTLinkageSpecification linkageSpec) { }
|
||||
public void exitClassSpecifier(IASTClassSpecifier classSpecification) { }
|
||||
public void exitNamespaceDefinition(IASTNamespaceDefinition namespaceDefinition) { }
|
||||
public void exitCompilationUnit(IASTCompilationUnit compilationUnit) { }
|
||||
|
||||
public void exitClassSpecifier(IASTClassSpecifier classSpecification) {
|
||||
popScope();
|
||||
}
|
||||
|
||||
public void exitNamespaceDefinition(IASTNamespaceDefinition namespaceDefinition) {
|
||||
popScope();
|
||||
}
|
||||
|
||||
public void exitCompilationUnit(IASTCompilationUnit compilationUnit){
|
||||
popScope();
|
||||
}
|
||||
|
||||
public void enterInclusion(IASTInclusion inclusion) {
|
||||
String includePath = inclusion.getFullFileName();
|
||||
|
@ -154,12 +208,15 @@ public class MatchLocator implements ISourceElementRequestor {
|
|||
}
|
||||
|
||||
public void enterClassSpecifier(IASTClassSpecifier classSpecification) {
|
||||
if( searchPattern instanceof ClassDeclarationPattern ){
|
||||
int level = searchPattern.matchLevel( classSpecification );
|
||||
if( level != ICSearchPattern.IMPOSSIBLE_MATCH ){
|
||||
report( classSpecification, level );
|
||||
if( searchPattern.getLimitTo() == DECLARATIONS || searchPattern.getLimitTo() == ALL_OCCURRENCES ){
|
||||
if( searchPattern instanceof ClassDeclarationPattern ){
|
||||
int level = searchPattern.matchLevel( classSpecification );
|
||||
if( level != ICSearchPattern.IMPOSSIBLE_MATCH ){
|
||||
report( classSpecification, level );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
pushScope( classSpecification );
|
||||
}
|
||||
|
||||
public void locateMatches( String [] paths, IWorkspace workspace, IWorkingCopy[] workingCopies ){
|
||||
|
@ -244,17 +301,30 @@ public class MatchLocator implements ISourceElementRequestor {
|
|||
|
||||
protected void report( IASTOffsetableNamedElement node, int accuracyLevel ){
|
||||
try {
|
||||
if( progressMonitor != null ) {
|
||||
if( progressMonitor.isCanceled() ) {
|
||||
throw new OperationCanceledException();
|
||||
} else {
|
||||
progressMonitor.worked( 1 );
|
||||
}
|
||||
}
|
||||
|
||||
int offset = node.getElementNameOffset();
|
||||
if( offset == 0 )
|
||||
offset = node.getElementStartingOffset();
|
||||
|
||||
if( currentResource != null ){
|
||||
|
||||
resultCollector.accept( currentResource,
|
||||
node.getElementNameOffset(),
|
||||
node.getElementNameOffset() + node.getName().length(),
|
||||
null,
|
||||
offset,
|
||||
offset + node.getName().length(),
|
||||
resultCollector.createMatch( node, currentScope ),
|
||||
accuracyLevel );
|
||||
} else if( currentPath != null ){
|
||||
resultCollector.accept( currentPath,
|
||||
node.getElementStartingOffset(),
|
||||
node.getElementEndingOffset(),
|
||||
null,
|
||||
offset,
|
||||
offset + node.getName().length(),
|
||||
resultCollector.createMatch( node, currentScope ),
|
||||
accuracyLevel );
|
||||
}
|
||||
} catch (CoreException e) {
|
||||
|
@ -263,12 +333,27 @@ public class MatchLocator implements ISourceElementRequestor {
|
|||
}
|
||||
}
|
||||
|
||||
private void pushScope( IASTScope scope ){
|
||||
scopeStack.addFirst( currentScope );
|
||||
currentScope = scope;
|
||||
}
|
||||
|
||||
private IASTScope popScope(){
|
||||
IASTScope oldScope = currentScope;
|
||||
currentScope = (scopeStack.size() > 0 ) ? (IASTScope) scopeStack.removeFirst() : null;
|
||||
return oldScope;
|
||||
}
|
||||
|
||||
private ICSearchPattern searchPattern;
|
||||
private ICSearchResultCollector resultCollector;
|
||||
private IProgressMonitor progressMonitor;
|
||||
private IResource currentResource = null;
|
||||
private IPath currentPath = null;
|
||||
private ICSearchScope searchScope;
|
||||
private LinkedList resourceStack = new LinkedList();
|
||||
private ICSearchScope searchScope;
|
||||
private IWorkspaceRoot workspaceRoot;
|
||||
|
||||
private IResource currentResource = null;
|
||||
private LinkedList resourceStack = new LinkedList();
|
||||
|
||||
private IASTScope currentScope = null;
|
||||
private LinkedList scopeStack = new LinkedList();
|
||||
}
|
||||
|
|
|
@ -0,0 +1,24 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2003 IBM Corporation and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Common Public License v0.5
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/cpl-v05.html
|
||||
*
|
||||
* Contributors:
|
||||
* IBM Corp. - Rational Software - initial implementation
|
||||
******************************************************************************/
|
||||
/*
|
||||
* Created on Jul 11, 2003
|
||||
*/
|
||||
package org.eclipse.cdt.internal.core.search.matching;
|
||||
|
||||
/**
|
||||
* @author aniefer
|
||||
*
|
||||
* To change the template for this generated type comment go to
|
||||
* Window>Preferences>Java>Code Generation>Code and Comments
|
||||
*/
|
||||
public class MethodDeclarationPattern extends FunctionDeclarationPattern {
|
||||
|
||||
}
|
|
@ -0,0 +1,102 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2003 IBM Corporation and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Common Public License v0.5
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/cpl-v05.html
|
||||
*
|
||||
* Contributors:
|
||||
* IBM Corp. - Rational Software - initial implementation
|
||||
******************************************************************************/
|
||||
/*
|
||||
* Created on Jul 11, 2003
|
||||
*/
|
||||
package org.eclipse.cdt.internal.core.search.matching;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.eclipse.cdt.core.parser.ast.IASTNamespaceDefinition;
|
||||
import org.eclipse.cdt.core.parser.ast.IASTOffsetableElement;
|
||||
import org.eclipse.cdt.core.search.ICSearchScope;
|
||||
import org.eclipse.cdt.internal.core.index.IEntryResult;
|
||||
import org.eclipse.cdt.internal.core.index.impl.IndexInput;
|
||||
import org.eclipse.cdt.internal.core.search.IIndexSearchRequestor;
|
||||
|
||||
/**
|
||||
* @author aniefer
|
||||
*
|
||||
* To change the template for this generated type comment go to
|
||||
* Window>Preferences>Java>Code Generation>Code and Comments
|
||||
*/
|
||||
public class NamespaceDeclarationPattern extends CSearchPattern {
|
||||
|
||||
|
||||
/**
|
||||
* @param name
|
||||
* @param cs
|
||||
* @param matchMode
|
||||
* @param limitTo
|
||||
* @param caseSensitive
|
||||
*/
|
||||
public NamespaceDeclarationPattern(char[] name, char[][] qualifications, int matchMode, LimitTo limitTo, boolean caseSensitive) {
|
||||
super( matchMode, caseSensitive, limitTo );
|
||||
|
||||
_name = name;
|
||||
_qualifications = qualifications;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.search.ICSearchPattern#matchLevel(org.eclipse.cdt.core.parser.ast.IASTOffsetableElement)
|
||||
*/
|
||||
public int matchLevel(IASTOffsetableElement node) {
|
||||
if( !( node instanceof IASTNamespaceDefinition ) )
|
||||
return IMPOSSIBLE_MATCH;
|
||||
|
||||
IASTNamespaceDefinition namespace = (IASTNamespaceDefinition)node;
|
||||
|
||||
if( _name != null && !matchesName( _name, namespace.getName().toCharArray() ) ){
|
||||
return IMPOSSIBLE_MATCH;
|
||||
}
|
||||
|
||||
if( !matchQualifications( _qualifications, namespace.getFullyQualifiedName() ) ){
|
||||
return IMPOSSIBLE_MATCH;
|
||||
}
|
||||
|
||||
return ACCURATE_MATCH;
|
||||
}
|
||||
|
||||
private char[][] _qualifications;
|
||||
private char[] _name;
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.core.search.matching.CSearchPattern#feedIndexRequestor(org.eclipse.cdt.internal.core.search.IIndexSearchRequestor, int, int[], org.eclipse.cdt.internal.core.index.impl.IndexInput, org.eclipse.cdt.core.search.ICSearchScope)
|
||||
*/
|
||||
public void feedIndexRequestor(IIndexSearchRequestor requestor, int detailLevel, int[] references, IndexInput input, ICSearchScope scope) throws IOException {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.core.search.matching.CSearchPattern#decodeIndexEntry(org.eclipse.cdt.internal.core.index.IEntryResult)
|
||||
*/
|
||||
protected void decodeIndexEntry(IEntryResult entryResult) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.core.search.matching.CSearchPattern#indexEntryPrefix()
|
||||
*/
|
||||
public char[] indexEntryPrefix() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.core.search.matching.CSearchPattern#matchIndexEntry()
|
||||
*/
|
||||
protected boolean matchIndexEntry() {
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,83 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2003 IBM Corporation and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Common Public License v0.5
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/cpl-v05.html
|
||||
*
|
||||
* Contributors:
|
||||
* IBM Corp. - Rational Software - initial implementation
|
||||
******************************************************************************/
|
||||
/*
|
||||
* Created on Jul 11, 2003
|
||||
*/
|
||||
package org.eclipse.cdt.internal.core.search.matching;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.eclipse.cdt.core.parser.ast.IASTOffsetableElement;
|
||||
import org.eclipse.cdt.core.search.ICSearchScope;
|
||||
import org.eclipse.cdt.internal.core.index.IEntryResult;
|
||||
import org.eclipse.cdt.internal.core.index.impl.IndexInput;
|
||||
import org.eclipse.cdt.internal.core.search.IIndexSearchRequestor;
|
||||
|
||||
/**
|
||||
* @author aniefer
|
||||
*
|
||||
* To change the template for this generated type comment go to
|
||||
* Window>Preferences>Java>Code Generation>Code and Comments
|
||||
*/
|
||||
public class VariableDeclarationPattern extends CSearchPattern {
|
||||
|
||||
/**
|
||||
* @param name
|
||||
* @param matchMode
|
||||
* @param limitTo
|
||||
* @param caseSensitive
|
||||
*/
|
||||
public VariableDeclarationPattern(char[] name, int matchMode, LimitTo limitTo, boolean caseSensitive) {
|
||||
super( matchMode, caseSensitive, limitTo );
|
||||
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.search.ICSearchPattern#matchLevel(org.eclipse.cdt.core.parser.ast.IASTOffsetableElement)
|
||||
*/
|
||||
public int matchLevel(IASTOffsetableElement node) {
|
||||
// TODO Auto-generated method stub
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.core.search.matching.CSearchPattern#feedIndexRequestor(org.eclipse.cdt.internal.core.search.IIndexSearchRequestor, int, int[], org.eclipse.cdt.internal.core.index.impl.IndexInput, org.eclipse.cdt.core.search.ICSearchScope)
|
||||
*/
|
||||
public void feedIndexRequestor(IIndexSearchRequestor requestor, int detailLevel, int[] references, IndexInput input, ICSearchScope scope) throws IOException {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.core.search.matching.CSearchPattern#decodeIndexEntry(org.eclipse.cdt.internal.core.index.IEntryResult)
|
||||
*/
|
||||
protected void decodeIndexEntry(IEntryResult entryResult) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.core.search.matching.CSearchPattern#indexEntryPrefix()
|
||||
*/
|
||||
public char[] indexEntryPrefix() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.core.search.matching.CSearchPattern#matchIndexEntry()
|
||||
*/
|
||||
protected boolean matchIndexEntry() {
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,3 +1,9 @@
|
|||
2003-07-14 Andrew Niefer
|
||||
-modified plugin.xml entry for search's PathNameSorter
|
||||
-added src/org/eclipse/cdt/internal/ui/search/Match.java which implements IMatch to store
|
||||
information used by CSearchResultLabelProvider
|
||||
-Modified CSearchResultCollector and CSearchResultLabelProvider to use Match
|
||||
|
||||
2003-07-11 Bogdan Gheorghe
|
||||
Added new C/C++ Search menu item.
|
||||
|
||||
|
|
BIN
core/org.eclipse.cdt.ui/icons/full/clcl16/search_sortmatch.gif
Normal file
BIN
core/org.eclipse.cdt.ui/icons/full/clcl16/search_sortmatch.gif
Normal file
Binary file not shown.
After Width: | Height: | Size: 160 B |
|
@ -973,8 +973,8 @@
|
|||
class="org.eclipse.cdt.internal.ui.search.ParentNameSorter"
|
||||
id="org.eclipse.search.internal.ui.ParentNameSorter">
|
||||
</sorter>
|
||||
<sorter
|
||||
pageId="org.eclipse.cdt.ui.JavaSearchPage"
|
||||
<sorter
|
||||
pageId="org.eclipse.cdt.ui.CSearchPage"
|
||||
label="%PathNameSorter.label"
|
||||
icon="icons/full/clcl16/search_sortmatch.gif"
|
||||
tooltip="%PathNameSorter.tooltip"
|
||||
|
|
|
@ -50,10 +50,11 @@ Search.potentialMatchDialog.message= Inexact matches were found and will be disp
|
|||
|
||||
CSearchPage.searchFor.label= Search For
|
||||
CSearchPage.searchFor.type= &Type
|
||||
CSearchPage.searchFor.method= &Method
|
||||
CSearchPage.searchFor.field= &Field
|
||||
CSearchPage.searchFor.namespace= N&amespace
|
||||
CSearchPage.searchFor.constructor= Co&nstructor
|
||||
CSearchPage.searchFor.method= &Method
|
||||
CSearchPage.searchFor.function= F&unction
|
||||
CSearchPage.searchFor.field= &Field
|
||||
CSearchPage.searchFor.variable= &Variable
|
||||
|
||||
CSearchPage.limitTo.label= Limit To
|
||||
CSearchPage.limitTo.declarations= Dec&larations
|
||||
|
|
|
@ -20,7 +20,9 @@ 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.SearchEngine;
|
||||
import org.eclipse.cdt.internal.core.model.IWorkingCopy;
|
||||
import org.eclipse.cdt.internal.ui.CPluginImages;
|
||||
|
||||
import org.eclipse.core.resources.IWorkspace;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.core.runtime.IProgressMonitor;
|
||||
|
@ -63,7 +65,7 @@ public class CSearchOperation extends WorkspaceModifyOperation implements ICSear
|
|||
throws CoreException, InvocationTargetException, InterruptedException
|
||||
{
|
||||
_collector.setProgressMonitor( monitor );
|
||||
|
||||
IWorkingCopy copy = null;
|
||||
SearchEngine engine = new SearchEngine( );
|
||||
if( _elementPattern != null ){
|
||||
engine.search( _workspace, _elementPattern, _limitTo, _scope, _collector );
|
||||
|
|
|
@ -25,7 +25,6 @@ import org.eclipse.cdt.core.model.ICElement;
|
|||
import org.eclipse.cdt.core.search.ICSearchConstants;
|
||||
import org.eclipse.cdt.core.search.ICSearchScope;
|
||||
import org.eclipse.cdt.core.search.SearchEngine;
|
||||
//import org.eclipse.cdt.core.search.SearchFor;
|
||||
import org.eclipse.cdt.ui.CUIPlugin;
|
||||
import org.eclipse.core.resources.IWorkspace;
|
||||
import org.eclipse.core.runtime.IAdaptable;
|
||||
|
@ -271,20 +270,12 @@ public class CSearchPage extends DialogPage implements ISearchPage, ICSearchCons
|
|||
private void setLimitTo( SearchFor searchFor ) {
|
||||
HashSet set = new HashSet();
|
||||
|
||||
if( searchFor == TYPE ){
|
||||
set.add( DECLARATIONS );
|
||||
set.add( REFERENCES );
|
||||
} else if ( searchFor == FUNCTION || searchFor == CONSTRUCTOR ) {
|
||||
set.add( DECLARATIONS );
|
||||
if ( searchFor == FUNCTION || searchFor == METHOD ) {
|
||||
set.add( DEFINITIONS );
|
||||
//set.add( REFERENCES );
|
||||
} else if( searchFor == NAMESPACE ) {
|
||||
set.add( DECLARATIONS );
|
||||
set.add( REFERENCES );
|
||||
} else if( searchFor == MEMBER ) {
|
||||
set.add( DECLARATIONS );
|
||||
set.add( REFERENCES );
|
||||
}
|
||||
|
||||
set.add( DECLARATIONS );
|
||||
set.add( REFERENCES );
|
||||
set.add( ALL_OCCURRENCES );
|
||||
|
||||
for( int i = 0; i < fLimitTo.length; i++ )
|
||||
|
@ -306,10 +297,10 @@ public class CSearchPage extends DialogPage implements ISearchPage, ICSearchCons
|
|||
}
|
||||
|
||||
// Fill with dummy radio buttons
|
||||
Button filler= new Button(result, SWT.RADIO);
|
||||
filler.setVisible(false);
|
||||
filler= new Button(result, SWT.RADIO);
|
||||
filler.setVisible(false);
|
||||
//Button filler= new Button(result, SWT.RADIO);
|
||||
//filler.setVisible(false);
|
||||
//filler= new Button(result, SWT.RADIO);
|
||||
//filler.setVisible(false);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
@ -567,13 +558,14 @@ public class CSearchPage extends DialogPage implements ISearchPage, ICSearchCons
|
|||
private static List fgPreviousSearchPatterns = new ArrayList(20);
|
||||
|
||||
private Button[] fSearchFor;
|
||||
private SearchFor[] fSearchForValues = { TYPE, FUNCTION, NAMESPACE, CONSTRUCTOR, MEMBER };
|
||||
private SearchFor[] fSearchForValues = { TYPE, NAMESPACE, METHOD, FUNCTION, FIELD, VAR };
|
||||
private String[] fSearchForText= {
|
||||
CSearchMessages.getString("CSearchPage.searchFor.type"), //$NON-NLS-1$
|
||||
CSearchMessages.getString("CSearchPage.searchFor.method"), //$NON-NLS-1$
|
||||
CSearchMessages.getString("CSearchPage.searchFor.namespace"), //$NON-NLS-1$
|
||||
CSearchMessages.getString("CSearchPage.searchFor.constructor"), //$NON-NLS-1$
|
||||
CSearchMessages.getString("CSearchPage.searchFor.field")}; //$NON-NLS-1$
|
||||
CSearchMessages.getString("CSearchPage.searchFor.method"), //$NON-NLS-1$
|
||||
CSearchMessages.getString("CSearchPage.searchFor.function"),
|
||||
CSearchMessages.getString("CSearchPage.searchFor.field"),
|
||||
CSearchMessages.getString("CSearchPage.searchFor.variable") }; //$NON-NLS-1$
|
||||
|
||||
private Button[] fLimitTo;
|
||||
private LimitTo[] fLimitToValues = { DECLARATIONS, DEFINITIONS, REFERENCES, ALL_OCCURRENCES };
|
||||
|
|
|
@ -18,17 +18,28 @@ import java.util.HashMap;
|
|||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import org.eclipse.cdt.core.model.ICElement;
|
||||
import org.eclipse.cdt.core.parser.ast.ASTClassKind;
|
||||
import org.eclipse.cdt.core.parser.ast.IASTClassSpecifier;
|
||||
import org.eclipse.cdt.core.parser.ast.IASTEnumerationSpecifier;
|
||||
import org.eclipse.cdt.core.parser.ast.IASTNamespaceDefinition;
|
||||
import org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement;
|
||||
import org.eclipse.cdt.core.parser.ast.IASTQualifiedNameElement;
|
||||
import org.eclipse.cdt.core.parser.ast.IASTScope;
|
||||
import org.eclipse.cdt.core.search.ICSearchResultCollector;
|
||||
import org.eclipse.cdt.core.search.IMatch;
|
||||
import org.eclipse.cdt.internal.ui.CPluginImages;
|
||||
import org.eclipse.cdt.ui.CUIPlugin;
|
||||
import org.eclipse.core.resources.IMarker;
|
||||
import org.eclipse.core.resources.IResource;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.core.runtime.IPath;
|
||||
import org.eclipse.core.runtime.IProgressMonitor;
|
||||
import org.eclipse.search.ui.IActionGroupFactory;
|
||||
import org.eclipse.jface.resource.ImageDescriptor;
|
||||
//import org.eclipse.search.ui.IActionGroupFactory;
|
||||
import org.eclipse.search.ui.ISearchResultView;
|
||||
import org.eclipse.search.ui.SearchUI;
|
||||
import org.eclipse.ui.actions.ActionGroup;
|
||||
import org.eclipse.swt.graphics.Image;
|
||||
//import org.eclipse.ui.actions.ActionGroup;
|
||||
|
||||
/**
|
||||
* @author aniefer
|
||||
|
@ -37,6 +48,9 @@ import org.eclipse.ui.actions.ActionGroup;
|
|||
* Window>Preferences>Java>Code Generation>Code and Comments
|
||||
*/
|
||||
public class CSearchResultCollector implements ICSearchResultCollector {
|
||||
|
||||
public static final String IMATCH = "IMatchObject";
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
|
@ -53,7 +67,7 @@ public class CSearchResultCollector implements ICSearchResultCollector {
|
|||
_matchCount = 0;
|
||||
if( _view != null ){
|
||||
_view.searchStarted(
|
||||
new ActionGroupFactory(),
|
||||
null,//new ActionGroupFactory(),
|
||||
_operation.getSingularLabel(),
|
||||
_operation.getPluralLabelPattern(),
|
||||
_operation.getImageDescriptor(),
|
||||
|
@ -76,23 +90,26 @@ public class CSearchResultCollector implements ICSearchResultCollector {
|
|||
IResource resource,
|
||||
int start,
|
||||
int end,
|
||||
ICElement enclosingElement,
|
||||
IMatch enclosingObject,
|
||||
int accuracy)
|
||||
throws CoreException
|
||||
{
|
||||
IMarker marker = resource.createMarker( SearchUI.SEARCH_MARKER );
|
||||
|
||||
Object groupKey = enclosingElement;
|
||||
Match match = (Match) enclosingObject;
|
||||
|
||||
Object groupKey = match;
|
||||
|
||||
HashMap markerAttributes = new HashMap( 2 );
|
||||
|
||||
//we can hang any other info we want off the marker
|
||||
markerAttributes.put( IMarker.CHAR_START, new Integer( Math.max( start, 0 ) ) );
|
||||
markerAttributes.put( IMarker.CHAR_END, new Integer( Math.max( end, 0 ) ) );
|
||||
markerAttributes.put( IMATCH, enclosingObject );
|
||||
|
||||
marker.setAttributes( markerAttributes );
|
||||
|
||||
_view.addMatch( enclosingElement.getElementName(), groupKey, resource, marker );
|
||||
_view.addMatch( match.name, groupKey, resource, marker );
|
||||
_matchCount++;
|
||||
}
|
||||
|
||||
|
@ -100,7 +117,7 @@ public class CSearchResultCollector implements ICSearchResultCollector {
|
|||
IPath path,
|
||||
int start,
|
||||
int end,
|
||||
ICElement enclosingElement,
|
||||
IMatch match,
|
||||
int accuracy)
|
||||
throws CoreException
|
||||
{
|
||||
|
@ -108,9 +125,49 @@ public class CSearchResultCollector implements ICSearchResultCollector {
|
|||
_matches = new HashSet();
|
||||
}
|
||||
|
||||
_matches.add( new Match( path.toString(), start, end ) );
|
||||
_matches.add( match );
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.search.ICSearchResultCollector#createMatch(org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement)
|
||||
*/
|
||||
public IMatch createMatch(IASTOffsetableNamedElement node, IASTScope parent ) {
|
||||
String name = node.getName();
|
||||
|
||||
String parentName = "";
|
||||
if( parent instanceof IASTQualifiedNameElement ){
|
||||
String [] names = ((IASTQualifiedNameElement)parent).getFullyQualifiedName();
|
||||
for( int i = 0; i < names.length; i++ ){
|
||||
if( i > 0 )
|
||||
parentName += "::";
|
||||
|
||||
parentName += names[ i ];
|
||||
}
|
||||
}
|
||||
|
||||
ImageDescriptor imageDescriptor = null;
|
||||
if( node instanceof IASTClassSpecifier ){
|
||||
ASTClassKind kind = ((IASTClassSpecifier)node).getClassKind();
|
||||
if( kind == ASTClassKind.CLASS ){
|
||||
imageDescriptor = CPluginImages.DESC_OBJS_CLASS;
|
||||
} else if ( kind == ASTClassKind.STRUCT ){
|
||||
imageDescriptor = CPluginImages.DESC_OBJS_STRUCT;
|
||||
} else if ( kind == ASTClassKind.UNION ){
|
||||
imageDescriptor = CPluginImages.DESC_OBJS_UNION;
|
||||
}
|
||||
} else if ( node instanceof IASTNamespaceDefinition ){
|
||||
imageDescriptor = CPluginImages.DESC_OBJS_CONTAINER;
|
||||
} else if ( node instanceof IASTEnumerationSpecifier ){
|
||||
imageDescriptor = CPluginImages.DESC_OBJS_ENUMERATION;
|
||||
}
|
||||
|
||||
Image image = CUIPlugin.getImageDescriptorRegistry().get( imageDescriptor );
|
||||
IMatch match = new Match(name, parentName, image, node.getElementNameOffset(), name.length() );
|
||||
|
||||
return match;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.search.ICSearchResultCollector#done()
|
||||
*/
|
||||
|
@ -153,13 +210,13 @@ public class CSearchResultCollector implements ICSearchResultCollector {
|
|||
return _matches;
|
||||
}
|
||||
|
||||
private class ActionGroupFactory implements IActionGroupFactory {
|
||||
public ActionGroup createActionGroup( ISearchResultView part ){
|
||||
return new CSearchViewActionGroup( part );
|
||||
}
|
||||
}
|
||||
//private class ActionGroupFactory implements IActionGroupFactory {
|
||||
// public ActionGroup createActionGroup( ISearchResultView part ){
|
||||
// return new CSearchViewActionGroup( part );
|
||||
// }
|
||||
//}
|
||||
|
||||
public static class Match {
|
||||
/*public static class Match impl{
|
||||
public Match( String path, int start, int end ){
|
||||
this.path = path;
|
||||
this.start = start;
|
||||
|
@ -170,7 +227,7 @@ public class CSearchResultCollector implements ICSearchResultCollector {
|
|||
public int start;
|
||||
public int end;
|
||||
}
|
||||
|
||||
*/
|
||||
private static final String SEARCHING = CSearchMessages.getString("CSearchResultCollector.searching"); //$NON-NLS-1$
|
||||
private static final String MATCH = CSearchMessages.getString("CSearchResultCollector.match"); //$NON-NLS-1$
|
||||
private static final String MATCHES = CSearchMessages.getString("CSearchResultCollector.matches"); //$NON-NLS-1$
|
||||
|
@ -183,4 +240,4 @@ public class CSearchResultCollector implements ICSearchResultCollector {
|
|||
private ISearchResultView _view;
|
||||
private int _matchCount;
|
||||
private Set _matches;
|
||||
}
|
||||
}
|
|
@ -13,11 +13,13 @@
|
|||
*/
|
||||
package org.eclipse.cdt.internal.ui.search;
|
||||
|
||||
import org.eclipse.cdt.core.model.ICElement;
|
||||
import org.eclipse.cdt.internal.ui.CElementImageProvider;
|
||||
import org.eclipse.cdt.ui.CElementLabelProvider;
|
||||
import org.eclipse.core.resources.IMarker;
|
||||
import org.eclipse.core.resources.IResource;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.jface.viewers.LabelProvider;
|
||||
import org.eclipse.search.ui.ISearchResultViewEntry;
|
||||
import org.eclipse.search.ui.SearchUI;
|
||||
import org.eclipse.swt.graphics.Image;
|
||||
|
||||
/**
|
||||
|
@ -39,55 +41,70 @@ public class CSearchResultLabelProvider extends LabelProvider {
|
|||
|
||||
public static final String POTENTIAL_MATCH = CSearchMessages.getString("CSearchResultLabelProvider.potentialMatch"); //$NON-NLS-1$
|
||||
|
||||
public CSearchResultLabelProvider(){
|
||||
//_imageProvider = new CElementImageProvider();
|
||||
//_labelProvider = new CElementLabelProvider();
|
||||
}
|
||||
|
||||
public Image getImage( Object element ) {
|
||||
return null;
|
||||
if( !( element instanceof ISearchResultViewEntry ) ){
|
||||
return null;
|
||||
}
|
||||
|
||||
ISearchResultViewEntry viewEntry = (ISearchResultViewEntry)element;
|
||||
IMarker marker = viewEntry.getSelectedMarker();
|
||||
Match match = null;
|
||||
try {
|
||||
match = (Match) marker.getAttribute( CSearchResultCollector.IMATCH );
|
||||
} catch (CoreException e) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return match.image;
|
||||
}
|
||||
|
||||
public String getText( Object element ) {
|
||||
_lastMarker = null;
|
||||
|
||||
ICElement cElement = getCElement( element );
|
||||
|
||||
boolean isPotentialMatch = _lastMarker != null && _lastMarker.getAttribute( SearchUI.POTENTIAL_MATCH, false );
|
||||
|
||||
if( cElement == null ){
|
||||
if( _lastMarker != null ){
|
||||
if( isPotentialMatch )
|
||||
return super.getText( _lastMarker.getResource() ) + POTENTIAL_MATCH;
|
||||
else
|
||||
return super.getText( _lastMarker.getResource() );
|
||||
} else {
|
||||
return "";
|
||||
}
|
||||
if( ! (element instanceof ISearchResultViewEntry ) ){
|
||||
return null;
|
||||
}
|
||||
|
||||
String text = "";
|
||||
if( isPotentialMatch ){
|
||||
text = CElementLabels.getTextLabel( element, _textFlags ) + POTENTIAL_MATCH;
|
||||
} else {
|
||||
text = CElementLabels.getTextLabel( element, _textFlags );
|
||||
ISearchResultViewEntry viewEntry = (ISearchResultViewEntry) element;
|
||||
|
||||
IMarker marker = viewEntry.getSelectedMarker();
|
||||
|
||||
Match match = null;
|
||||
|
||||
try {
|
||||
match = (Match) marker.getAttribute(CSearchResultCollector.IMATCH);
|
||||
} catch (CoreException e) {
|
||||
return null;
|
||||
}
|
||||
//if( cElement instanceof )
|
||||
|
||||
return element == null ? "" : element.toString();//$NON-NLS-1$
|
||||
}
|
||||
|
||||
public void setOrder(int orderFlag) {
|
||||
int flags = DEFAULT_TEXTFLAGS | CElementLabels.P_COMPRESSED;
|
||||
IResource resource = marker.getResource();
|
||||
|
||||
switch( orderFlag ){
|
||||
String result = null;
|
||||
String path = (resource != null ) ? resource.getFullPath().toString() : "";
|
||||
|
||||
switch( getOrder() ){
|
||||
case SHOW_ELEMENT_CONTAINER:
|
||||
flags |= CElementLabels.ALL_POST_QUALIFIED | CElementLabels.M_PARAMETER_TYPES;
|
||||
result = match.name + " - " + match.parent + " ( " + path + " )";
|
||||
break;
|
||||
case SHOW_PATH:
|
||||
flags |= CElementLabels.PREPEND_ROOT_PATH;
|
||||
/*fall through to SHOW_CONTAINER_ELEMENT*/
|
||||
result = path + " - " + match.parent + "::" + match.name;
|
||||
break;
|
||||
case SHOW_CONTAINER_ELEMENT:
|
||||
flags |= CElementLabels.ALL_FULLY_QUALIFIED | CElementLabels.M_PARAMETER_TYPES;
|
||||
result = match.parent + "::" + match.name + " ( " + path + " )";
|
||||
break;
|
||||
}
|
||||
|
||||
_textFlags = flags;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public int getOrder(){
|
||||
return _sortOrder;
|
||||
}
|
||||
public void setOrder(int orderFlag) {
|
||||
_sortOrder = orderFlag;
|
||||
}
|
||||
|
||||
protected IMarker getMarker( Object o ){
|
||||
|
@ -98,35 +115,11 @@ public class CSearchResultLabelProvider extends LabelProvider {
|
|||
return ( (ISearchResultViewEntry)o ).getSelectedMarker();
|
||||
}
|
||||
|
||||
private ICElement getCElement( Object o ){
|
||||
if( o instanceof ICElement )
|
||||
return (ICElement) o;
|
||||
|
||||
IMarker marker = getMarker( o );
|
||||
if( marker == null )
|
||||
return null;
|
||||
|
||||
return getCElement( marker, (ISearchResultViewEntry) o );
|
||||
}
|
||||
|
||||
private ICElement getCElement( IMarker marker, ISearchResultViewEntry entry ) {
|
||||
if( _lastMarker != marker ){
|
||||
boolean canUseGroupByKey = false;
|
||||
|
||||
if( canUseGroupByKey && entry.getGroupByKey() instanceof ICElement ){
|
||||
_lastCElement = (ICElement) entry.getGroupByKey();
|
||||
} else {
|
||||
_lastCElement = CSearchUtil.getCElement( marker );
|
||||
}
|
||||
|
||||
_lastMarker = marker;
|
||||
}
|
||||
return _lastCElement;
|
||||
}
|
||||
|
||||
private IMarker _lastMarker;
|
||||
private ICElement _lastCElement;
|
||||
private CElementImageProvider _imageProvider;
|
||||
private CElementLabelProvider _labelProvider;
|
||||
|
||||
private int _sortOrder;
|
||||
private int _textFlags;
|
||||
private int _imageFlags;
|
||||
|
||||
|
|
|
@ -13,8 +13,8 @@
|
|||
*/
|
||||
package org.eclipse.cdt.internal.ui.search;
|
||||
|
||||
import org.eclipse.cdt.core.model.ICElement;
|
||||
import org.eclipse.core.resources.IMarker;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.search.ui.IGroupByKeyComputer;
|
||||
|
||||
/**
|
||||
|
@ -34,37 +34,13 @@ public class GroupByKeyComputer implements IGroupByKeyComputer {
|
|||
return null;
|
||||
}
|
||||
|
||||
// ICElement element = getCElement( marker );
|
||||
// if( element != null && element.exists() ){
|
||||
// return _lastHandle;
|
||||
// }
|
||||
Match match = null;
|
||||
|
||||
return null;
|
||||
}
|
||||
/*
|
||||
private String getJavaElementHandleId(IMarker marker) {
|
||||
try {
|
||||
return (String)marker.getAttribute(ICSearchUIConstants.ATT_JE_HANDLE_ID);
|
||||
} catch (CoreException ex) {
|
||||
ExceptionHandler.handle(ex, CSearchMessages.getString("Search.Error.markerAttributeAccess.title"), CSearchMessages.getString("Search.Error.markerAttributeAccess.message")); //$NON-NLS-2$ //$NON-NLS-1$
|
||||
return null;
|
||||
match = (Match) marker.getAttribute(CSearchResultCollector.IMATCH);
|
||||
} catch (CoreException e) {
|
||||
}
|
||||
|
||||
return match.parent;
|
||||
}
|
||||
|
||||
private ICElement getCElement( IMarker marker ){
|
||||
String handle = getCElementHandleId( marker );
|
||||
if( handle == null ){
|
||||
_lastHandle = null;
|
||||
_lastElement = null;
|
||||
return null;
|
||||
}
|
||||
if( !handle.equals( _lastHandle ) ){
|
||||
_lastElement = SearchUtil
|
||||
}
|
||||
return _lastElement;
|
||||
}*/
|
||||
|
||||
private String _lastHandle = null;
|
||||
private ICElement _lastElement = null;
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,41 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2003 IBM Corporation and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Common Public License v0.5
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/cpl-v05.html
|
||||
*
|
||||
* Contributors:
|
||||
* IBM Corp. - Rational Software - initial implementation
|
||||
******************************************************************************/
|
||||
/*
|
||||
* Created on Jul 10, 2003
|
||||
*/
|
||||
package org.eclipse.cdt.internal.ui.search;
|
||||
|
||||
import org.eclipse.cdt.core.search.IMatch;
|
||||
import org.eclipse.swt.graphics.Image;
|
||||
|
||||
/**
|
||||
* @author aniefer
|
||||
*
|
||||
* To change the template for this generated type comment go to
|
||||
* Window>Preferences>Java>Code Generation>Code and Comments
|
||||
*/
|
||||
public class Match implements IMatch{
|
||||
|
||||
public String name;
|
||||
public String parent;
|
||||
public Image image;
|
||||
public int start;
|
||||
public int end;
|
||||
|
||||
public Match( String name, String parent, Image image, int start, int end ){
|
||||
this.name = name;
|
||||
this.parent = parent;
|
||||
this.image = image;
|
||||
this.start = start;
|
||||
this.end = end;
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Reference in a new issue