From 6fa5a87930361469316b7851a2b6e66eea81d0a3 Mon Sep 17 00:00:00 2001 From: John Camelon Date: Sat, 28 Jun 2003 19:56:54 +0000 Subject: [PATCH] Patch for Andrew Niefer Further work on C/C++ Search framework. --- core/org.eclipse.cdt.core/search/ChangeLog | 14 + .../cdt/core/search/ICSearchPattern.java | 13 + .../core/search/ICSearchResultCollector.java | 5 +- .../eclipse/cdt/core/search/SearchEngine.java | 22 +- .../core/search/matching/CSearchPattern.java | 59 ++- .../matching/ClassDeclarationPattern.java | 54 +++ .../core/search/matching/MatchLocator.java | 378 +++++------------- core/org.eclipse.cdt.ui/ChangeLog | 22 + .../icons/full/obj16/search_decl_obj.gif | Bin 0 -> 157 bytes .../icons/full/obj16/search_ref_obj.gif | Bin 0 -> 151 bytes .../icons/full/obj16/search_sortmatch.gif | Bin 0 -> 160 bytes core/org.eclipse.cdt.ui/plugin.properties | 10 + core/org.eclipse.cdt.ui/plugin.xml | 29 +- .../cdt/internal/ui/CPluginImages.java | 7 + .../internal/ui/search/CElementLabels.java | 362 +++++++++++++++++ .../ui/search/CSearchMessages.properties | 68 ++-- .../internal/ui/search/CSearchOperation.java | 64 ++- .../cdt/internal/ui/search/CSearchPage.java | 44 +- .../ui/search/CSearchResultCollector.java | 91 ++++- .../ui/search/CSearchResultLabelProvider.java | 133 ++++++ .../ui/search/CSearchViewActionGroup.java | 35 ++ .../internal/ui/search/ElementNameSorter.java | 68 ++++ .../internal/ui/search/GotoMarkerAction.java | 93 +++++ .../ui/search/GroupByKeyComputer.java | 70 ++++ .../internal/ui/search/ParentNameSorter.java | 75 ++++ .../internal/ui/search/PathNameSorter.java | 108 +++++ 26 files changed, 1449 insertions(+), 375 deletions(-) create mode 100644 core/org.eclipse.cdt.ui/icons/full/obj16/search_decl_obj.gif create mode 100644 core/org.eclipse.cdt.ui/icons/full/obj16/search_ref_obj.gif create mode 100644 core/org.eclipse.cdt.ui/icons/full/obj16/search_sortmatch.gif create mode 100644 core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/CElementLabels.java create mode 100644 core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/CSearchResultLabelProvider.java create mode 100644 core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/CSearchViewActionGroup.java create mode 100644 core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/ElementNameSorter.java create mode 100644 core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/GotoMarkerAction.java create mode 100644 core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/GroupByKeyComputer.java create mode 100644 core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/ParentNameSorter.java create mode 100644 core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/PathNameSorter.java diff --git a/core/org.eclipse.cdt.core/search/ChangeLog b/core/org.eclipse.cdt.core/search/ChangeLog index c95b5629843..5861bff8efa 100644 --- a/core/org.eclipse.cdt.core/search/ChangeLog +++ b/core/org.eclipse.cdt.core/search/ChangeLog @@ -1,3 +1,17 @@ +2003-06-27 Andrew Niefer +Modified: + search/org.eclipse.cdt.core.search.matching/MatchLocator.java + - enter/exitInclusion + - enterClassSpecifier + search/org.eclipse.cdt.core.search.matching/CSearchPattern.java + - createClassPattern + - matchesName + search/org.eclipse.cdt.core.search.matching/ClassDeclarationPattern.java + - matchLevel + search/org.eclipse.cdt.core.search/ICSearchPattern.java + search/org.eclipse.cdt.core.search/ICSearchResultCollector.java + search/org.eclipse.cdt.core.search/SearchEngine.java + 2003-06-25 Bogdan Gheorghe Modified: diff --git a/core/org.eclipse.cdt.core/search/org/eclipse/cdt/core/search/ICSearchPattern.java b/core/org.eclipse.cdt.core/search/org/eclipse/cdt/core/search/ICSearchPattern.java index 3a120b1dec1..fb96925b91d 100644 --- a/core/org.eclipse.cdt.core/search/org/eclipse/cdt/core/search/ICSearchPattern.java +++ b/core/org.eclipse.cdt.core/search/org/eclipse/cdt/core/search/ICSearchPattern.java @@ -13,6 +13,8 @@ */ package org.eclipse.cdt.core.search; +import org.eclipse.cdt.core.parser.ast.IASTOffsetableElement; + /** * @author aniefer * @@ -21,4 +23,15 @@ package org.eclipse.cdt.core.search; */ public interface ICSearchPattern { + public static final int IMPOSSIBLE_MATCH = 0; + public static final int POSSIBLE_MATCH = 1; + public static final int ACCURATE_MATCH = 2; + public static final int INACCURATE_MATCH = 3; + + /** + * @param node + * @return + */ + int matchLevel( IASTOffsetableElement node ); + } diff --git a/core/org.eclipse.cdt.core/search/org/eclipse/cdt/core/search/ICSearchResultCollector.java b/core/org.eclipse.cdt.core/search/org/eclipse/cdt/core/search/ICSearchResultCollector.java index f3f1ce1a783..96955788165 100644 --- a/core/org.eclipse.cdt.core/search/org/eclipse/cdt/core/search/ICSearchResultCollector.java +++ b/core/org.eclipse.cdt.core/search/org/eclipse/cdt/core/search/ICSearchResultCollector.java @@ -13,6 +13,7 @@ */ package org.eclipse.cdt.core.search; +import org.eclipse.cdt.core.model.ICElement; import org.eclipse.core.resources.IResource; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IProgressMonitor; @@ -59,9 +60,10 @@ public interface ICSearchResultCollector { IResource resource, int start, int end, - /*IJavaElement*/ Object enclosingElement, + ICElement enclosingElement, int accuracy) throws CoreException; + /** * Called when the search has ended. */ @@ -72,4 +74,5 @@ public interface ICSearchResultCollector { * @return a progress monitor or null if no progress monitor is provided */ public IProgressMonitor getProgressMonitor(); + } diff --git a/core/org.eclipse.cdt.core/search/org/eclipse/cdt/core/search/SearchEngine.java b/core/org.eclipse.cdt.core/search/org/eclipse/cdt/core/search/SearchEngine.java index a7ff2c77742..e6b0ae7f9a2 100644 --- a/core/org.eclipse.cdt.core/search/org/eclipse/cdt/core/search/SearchEngine.java +++ b/core/org.eclipse.cdt.core/search/org/eclipse/cdt/core/search/SearchEngine.java @@ -14,12 +14,16 @@ package org.eclipse.cdt.core.search; import org.eclipse.cdt.core.model.ICElement; -import org.eclipse.cdt.internal.core.index.IndexManager; +import org.eclipse.cdt.internal.core.search.indexing.IndexManager; import org.eclipse.cdt.internal.core.model.CModelManager; +import org.eclipse.cdt.internal.core.search.PatternSearchJob; import org.eclipse.cdt.internal.core.search.Util; import org.eclipse.cdt.internal.core.search.matching.CSearchPattern; +import org.eclipse.cdt.internal.core.search.matching.MatchLocator; import org.eclipse.core.resources.IWorkspace; import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.OperationCanceledException; +import org.eclipse.core.runtime.SubProgressMonitor; /** * @author aniefer @@ -94,9 +98,23 @@ public class SearchEngine { } CModelManager modelManager = CModelManager.getDefault(); - IndexManager indexManager = null; //modelManager.getIndexManager(); + IndexManager indexManager = modelManager.getIndexManager(); + SubProgressMonitor subMonitor = (progressMonitor == null ) ? null : new SubProgressMonitor( progressMonitor, 5 ); + indexManager.performConcurrentJob( + new PatternSearchJob(), + ICSearchConstants.WAIT_UNTIL_READY_TO_SEARCH, + subMonitor ); + + subMonitor = (progressMonitor == null ) ? null : new SubProgressMonitor( progressMonitor, 95 ); + + MatchLocator matchLocator = new MatchLocator( pattern, collector, scope, subMonitor ); + + if( progressMonitor != null && progressMonitor.isCanceled() ) + throw new OperationCanceledException(); + + //matchLocator.locateMatches( pathCollector.getPaths(), workspace, workingCopies ); } finally { collector.done(); } 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 59b8b10f297..69e0b217f08 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 @@ -13,8 +13,18 @@ */ package org.eclipse.cdt.internal.core.search.matching; +import java.io.StringReader; +import java.util.LinkedList; + +import org.eclipse.cdt.core.parser.EndOfFile; +import org.eclipse.cdt.core.parser.IScanner; +import org.eclipse.cdt.core.parser.IToken; +import org.eclipse.cdt.core.parser.ParserFactory; +import org.eclipse.cdt.core.parser.ParserMode; +import org.eclipse.cdt.core.parser.ScannerException; import org.eclipse.cdt.core.search.ICSearchConstants; import org.eclipse.cdt.core.search.ICSearchPattern; +import org.eclipse.cdt.internal.core.search.CharOperation; /** * @author aniefer @@ -22,8 +32,12 @@ import org.eclipse.cdt.core.search.ICSearchPattern; * To change the template for this generated type comment go to * Window>Preferences>Java>Code Generation>Code and Comments */ -public abstract class CSearchPattern - implements ICSearchConstants, ICSearchPattern { +public abstract class CSearchPattern implements ICSearchConstants, ICSearchPattern { + + public static final int IMPOSSIBLE_MATCH = 0; + public static final int POSSIBLE_MATCH = 1; + public static final int ACCURATE_MATCH = 2; + public static final int INACCURATE_MATCH = 3; /** * @param matchMode @@ -50,7 +64,7 @@ public abstract class CSearchPattern CSearchPattern pattern = null; switch( searchFor ){ case ICSearchConstants.TYPE: - pattern = createTypePattern( patternString, limitTo, matchMode, caseSensitive ); + pattern = createClassPattern( patternString, limitTo, matchMode, caseSensitive ); break; //case ICSearchConstants.METHOD: // pattern = createMethodPattern( patternString, limitTo, matchMode, caseSensitive ); @@ -109,9 +123,33 @@ public abstract class CSearchPattern * @param caseSensitive * @return */ - private static CSearchPattern createTypePattern(String patternString, int limitTo, int matchMode, boolean caseSensitive) { - // TODO Auto-generated method stub - return null; + private static CSearchPattern createClassPattern(String patternString, int limitTo, int matchMode, boolean caseSensitive) { + IScanner scanner = ParserFactory.createScanner( new StringReader( patternString ), "TEXT", null, null, ParserMode.QUICK_PARSE ); + + LinkedList list = new LinkedList(); + IToken token = null; + String name = new String(""); + + try { + while( true ){ + token = scanner.nextToken(); + + switch( token.getType() ){ + case IToken.tCOLONCOLON : + list.addLast( name.toCharArray() ); + name = new String(""); + break; + default: + name += token.getImage(); + break; + } + } + } catch (EndOfFile e) { + } catch (ScannerException e) { + } + + char [][] qualifications = new char[1][]; + return new ClassDeclarationPattern( name.toCharArray(), (char[][])list.toArray( qualifications ), null, matchMode, caseSensitive ); } protected boolean matchesName( char[] pattern, char[] name ){ @@ -122,14 +160,15 @@ public abstract class CSearchPattern if( name != null ){ switch( _matchMode ){ case EXACT_MATCH: - //return CharOperation.equals( pattern, name, _caseSensitive ); + return CharOperation.equals( pattern, name, _caseSensitive ); case PREFIX_MATCH: - //return CharOperation.prefixEquals( pattern, name, _caseSensitive ); + return CharOperation.prefixEquals( pattern, name, _caseSensitive ); case PATTERN_MATCH: if( !_caseSensitive ){ - //pattern = CharOperation.toLowerCase( pattern ); + pattern = CharOperation.toLowerCase( pattern ); } - //return CharOperation.match( pattern, name, _caseSensitive ); + + return CharOperation.match( pattern, name, _caseSensitive ); } } return false; 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 91c1c41cde9..97935a1d37a 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 @@ -13,6 +13,11 @@ */ package org.eclipse.cdt.internal.core.search.matching; +import org.eclipse.cdt.core.parser.ast.ClassKind; +import org.eclipse.cdt.core.parser.ast.IASTClassSpecifier; +import org.eclipse.cdt.core.parser.ast.IASTOffsetableElement; +import org.eclipse.cdt.internal.core.search.CharOperation; + /** * @author aniefer * @@ -25,5 +30,54 @@ public class ClassDeclarationPattern extends CSearchPattern { super( matchMode, caseSensitive ); } + public ClassDeclarationPattern( char[] name, char[][] containers, ClassKind kind, int mode, boolean caseSensitive ){ + super( mode, caseSensitive ); + simpleName = caseSensitive ? name : CharOperation.toLowerCase( name ); + if( caseSensitive || containers == null ){ + containingTypes = containers; + } else { + int len = containers.length; + this.containingTypes = new char[ len ][]; + for( int i = 0; i < len; i++ ){ + this.containingTypes[i] = CharOperation.toLowerCase( containers[i] ); + } + } + classKind = kind; + } + + public int matchLevel( IASTOffsetableElement node ){ + if( !( node instanceof IASTClassSpecifier ) ) + return IMPOSSIBLE_MATCH; + + IASTClassSpecifier clsSpec = (IASTClassSpecifier) node; + + //check name, if simpleName == null, its treated the same as "*" + if( simpleName != null && !matchesName( simpleName, clsSpec.getName().toCharArray() ) ){ + return IMPOSSIBLE_MATCH; + } + + //check containing scopes + String [] qualifications = clsSpec.getFullyQualifiedName(); + 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; + } + } + + //check type + if( classKind != clsSpec.getClassKind() ){ + return IMPOSSIBLE_MATCH; + } + + return ACCURATE_MATCH; + } + + private char[] simpleName; + private char[][] containingTypes; + private ClassKind classKind; } diff --git a/core/org.eclipse.cdt.core/search/org/eclipse/cdt/internal/core/search/matching/MatchLocator.java b/core/org.eclipse.cdt.core/search/org/eclipse/cdt/internal/core/search/matching/MatchLocator.java index 0ba6a368afb..cb0a7ec53ac 100644 --- a/core/org.eclipse.cdt.core/search/org/eclipse/cdt/internal/core/search/matching/MatchLocator.java +++ b/core/org.eclipse.cdt.core/search/org/eclipse/cdt/internal/core/search/matching/MatchLocator.java @@ -13,9 +13,23 @@ */ package org.eclipse.cdt.internal.core.search.matching; +import java.util.LinkedList; + import org.eclipse.cdt.core.parser.IProblem; import org.eclipse.cdt.core.parser.ISourceElementRequestor; import org.eclipse.cdt.core.parser.ast.*; +import org.eclipse.cdt.core.search.ICSearchPattern; +import org.eclipse.cdt.core.search.ICSearchResultCollector; +import org.eclipse.cdt.core.search.ICSearchScope; +import org.eclipse.cdt.internal.core.model.IWorkingCopy; +import org.eclipse.core.resources.IResource; +import org.eclipse.core.resources.IWorkspace; +import org.eclipse.core.resources.IWorkspaceRoot; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.Path; + /** * @author aniefer @@ -25,309 +39,97 @@ import org.eclipse.cdt.core.parser.ast.*; */ public class MatchLocator implements ISourceElementRequestor { + /** * */ - public MatchLocator() { + public MatchLocator( ICSearchPattern pattern, ICSearchResultCollector collector, ICSearchScope scope, IProgressMonitor monitor) { super(); - // TODO Auto-generated constructor stub + searchPattern = pattern; + resultCollector = collector; + searchScope = scope; + progressMonitor = monitor; } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#acceptProblem(org.eclipse.cdt.core.parser.IProblem) - */ - public void acceptProblem(IProblem problem) { - // TODO Auto-generated method stub + public void acceptProblem(IProblem problem) { } + public void acceptMacro(IASTMacro macro) { } + public void acceptVariable(IASTVariable variable) { } + public void acceptFunctionDeclaration(IASTFunction function) { } + public void acceptUsingDirective(IASTUsingDirective usageDirective) { } + public void acceptUsingDeclaration(IASTUsingDeclaration usageDeclaration) { } + public void acceptASMDefinition(IASTASMDefinition asmDefinition) { } + public void acceptTypedef(IASTTypedef typedef) { } + public void acceptEnumerator(IASTEnumerator enumerator) { } + public void acceptEnumerationSpecifier(IASTEnumerationSpecifier enumeration){ } + public void acceptClassReference(IASTClassSpecifier classSpecifier, int referenceOffset) { } + public void acceptElaboratedTypeSpecifier(IASTElaboratedTypeSpecifier elaboratedTypeSpec){ } + public void acceptMethodDeclaration(IASTMethod method) { } + public void acceptField(IASTField field) { } + public void acceptConstructor(IASTConstructor constructor) { } + public void enterFunctionBody(IASTFunction function) { } + public void enterCompilationUnit(IASTCompilationUnit compilationUnit) { } + public void enterNamespaceDefinition(IASTNamespaceDefinition 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 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) { } - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#acceptMacro(org.eclipse.cdt.core.parser.ast.IASTMacro) - */ - public void acceptMacro(IASTMacro macro) { - // TODO Auto-generated method stub - - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#acceptVariable(org.eclipse.cdt.core.parser.ast.IASTVariable) - */ - public void acceptVariable(IASTVariable variable) { - // TODO Auto-generated method stub - - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#acceptFunctionDeclaration(org.eclipse.cdt.core.parser.ast.IASTFunction) - */ - public void acceptFunctionDeclaration(IASTFunction function) { - // TODO Auto-generated method stub - - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#acceptUsingDirective(org.eclipse.cdt.core.parser.ast.IASTUsingDirective) - */ - public void acceptUsingDirective(IASTUsingDirective usageDirective) { - // TODO Auto-generated method stub - - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#acceptUsingDeclaration(org.eclipse.cdt.core.parser.ast.IASTUsingDeclaration) - */ - public void acceptUsingDeclaration(IASTUsingDeclaration usageDeclaration) { - // TODO Auto-generated method stub - - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#acceptASMDefinition(org.eclipse.cdt.core.parser.ast.IASTASMDefinition) - */ - public void acceptASMDefinition(IASTASMDefinition asmDefinition) { - // TODO Auto-generated method stub - - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#acceptTypedef(org.eclipse.cdt.core.parser.ast.IASTTypedef) - */ - public void acceptTypedef(IASTTypedef typedef) { - // TODO Auto-generated method stub - - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#enterEnumSpecifier(org.eclipse.cdt.core.parser.ast.IASTEnumSpecifier) - */ - //public void enterEnumSpecifier(IASTEnumSpecifier enumSpec) { - // TODO Auto-generated method stub - - //} - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#acceptEnumerator(org.eclipse.cdt.core.parser.ast.IASTEnumerator) - */ - public void acceptEnumerator(IASTEnumerator enumerator) { - // TODO Auto-generated method stub - - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#exitEnumSpecifier(org.eclipse.cdt.core.parser.ast.IASTEnumSpecifier) - */ - //public void exitEnumSpecifier(IASTEnumSpecifier enumSpec) { - // TODO Auto-generated method stub - - //} - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#enterFunctionBody(org.eclipse.cdt.core.parser.ast.IASTFunction) - */ - public void enterFunctionBody(IASTFunction function) { - // TODO Auto-generated method stub - - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#exitFunctionBody(org.eclipse.cdt.core.parser.ast.IASTFunction) - */ - public void exitFunctionBody(IASTFunction function) { - // TODO Auto-generated method stub - - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#enterCompilationUnit(org.eclipse.cdt.core.parser.ast.IASTCompilationUnit) - */ - public void enterCompilationUnit(IASTCompilationUnit compilationUnit) { - // TODO Auto-generated method stub - - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#enterInclusion(org.eclipse.cdt.core.parser.ast.IASTInclusion) - */ public void enterInclusion(IASTInclusion inclusion) { - // TODO Auto-generated method stub + String includePath = inclusion.getFullFileName(); + IPath path = new Path( includePath ); + IResource resource = workspaceRoot.findMember( path, true ); + if( resource != null ){ + resourceStack.addFirst( currentResource ); + currentResource = resource; + } } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#enterNamespaceDefinition(org.eclipse.cdt.core.parser.ast.IASTNamespaceDefinition) - */ - public void enterNamespaceDefinition(IASTNamespaceDefinition namespaceDefinition) { - // TODO Auto-generated method stub - - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#enterClassSpecifier(org.eclipse.cdt.core.parser.ast.IASTClassSpecifier) - */ - public void enterClassSpecifier(IASTClassSpecifier classSpecification) { - // TODO Auto-generated method stub - - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#enterLinkageSpecification(org.eclipse.cdt.core.parser.ast.IASTLinkageSpecification) - */ - public void enterLinkageSpecification(IASTLinkageSpecification linkageSpec) { - // TODO Auto-generated method stub - - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#enterTemplateDeclaration(org.eclipse.cdt.core.parser.ast.IASTTemplateDeclaration) - */ - public void enterTemplateDeclaration(IASTTemplateDeclaration declaration) { - // TODO Auto-generated method stub - - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#enterTemplateSpecialization(org.eclipse.cdt.core.parser.ast.IASTTemplateSpecialization) - */ - public void enterTemplateSpecialization(IASTTemplateSpecialization specialization) { - // TODO Auto-generated method stub - - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#enterTemplateExplicitInstantiation(org.eclipse.cdt.core.parser.ast.IASTTemplateInstantiation) - */ - public void enterTemplateExplicitInstantiation(IASTTemplateInstantiation instantiation) { - // TODO Auto-generated method stub - - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#acceptMethodDeclaration(org.eclipse.cdt.core.parser.ast.IASTMethod) - */ - public void acceptMethodDeclaration(IASTMethod method) { - // TODO Auto-generated method stub - - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#enterMethodBody(org.eclipse.cdt.core.parser.ast.IASTMethod) - */ - public void enterMethodBody(IASTMethod method) { - // TODO Auto-generated method stub - - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#exitMethodBody(org.eclipse.cdt.core.parser.ast.IASTMethod) - */ - public void exitMethodBody(IASTMethod method) { - // TODO Auto-generated method stub - - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#acceptField(org.eclipse.cdt.core.parser.ast.IASTField) - */ - public void acceptField(IASTField field) { - // TODO Auto-generated method stub - - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#acceptConstructor(org.eclipse.cdt.core.parser.ast.IASTConstructor) - */ - public void acceptConstructor(IASTConstructor constructor) { - // TODO Auto-generated method stub - - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#exitTemplateDeclaration(org.eclipse.cdt.core.parser.ast.IASTTemplateDeclaration) - */ - public void exitTemplateDeclaration(IASTTemplateDeclaration declaration) { - // TODO Auto-generated method stub - - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#exitTemplateSpecialization(org.eclipse.cdt.core.parser.ast.IASTTemplateSpecialization) - */ - public void exitTemplateSpecialization(IASTTemplateSpecialization specialization) { - // TODO Auto-generated method stub - - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#exitTemplateExplicitInstantiation(org.eclipse.cdt.core.parser.ast.IASTTemplateInstantiation) - */ - public void exitTemplateExplicitInstantiation(IASTTemplateInstantiation instantiation) { - // TODO Auto-generated method stub - - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#exitLinkageSpecification(org.eclipse.cdt.core.parser.ast.IASTLinkageSpecification) - */ - public void exitLinkageSpecification(IASTLinkageSpecification linkageSpec) { - // TODO Auto-generated method stub - - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#exitClassSpecifier(org.eclipse.cdt.core.parser.ast.IASTClassSpecifier) - */ - public void exitClassSpecifier(IASTClassSpecifier classSpecification) { - // TODO Auto-generated method stub - - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#exitNamespaceDefinition(org.eclipse.cdt.core.parser.ast.IASTNamespaceDefinition) - */ - public void exitNamespaceDefinition(IASTNamespaceDefinition namespaceDefinition) { - // TODO Auto-generated method stub - - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#exitInclusion(org.eclipse.cdt.core.parser.ast.IASTInclusion) - */ public void exitInclusion(IASTInclusion inclusion) { - // TODO Auto-generated method stub - + currentResource = (IResource) resourceStack.removeFirst(); } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#exitCompilationUnit(org.eclipse.cdt.core.parser.ast.IASTCompilationUnit) - */ - public void exitCompilationUnit(IASTCompilationUnit compilationUnit) { - // TODO Auto-generated method stub - - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#acceptEnumerationSpecifier(org.eclipse.cdt.core.parser.ast.IASTEnumerationSpecifier) - */ - public void acceptEnumerationSpecifier(IASTEnumerationSpecifier enumeration) { - // TODO Auto-generated method stub + public void enterClassSpecifier(IASTClassSpecifier classSpecification) { + if( searchPattern instanceof ClassDeclarationPattern ){ + int level = searchPattern.matchLevel( classSpecification ); + if( level != ICSearchPattern.IMPOSSIBLE_MATCH ){ + report( classSpecification, level ); + } + } } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#acceptClassReference(org.eclipse.cdt.core.parser.ast.IASTClassSpecifier, int) - */ - public void acceptClassReference(IASTClassSpecifier classSpecifier, int referenceOffset) { - // TODO Auto-generated method stub - + public void locateMatches( String [] paths, IWorkspace workspace, IWorkingCopy[] workingCopies ){ + workspaceRoot = workspace.getRoot(); } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#acceptElaboratedTypeSpecifier(org.eclipse.cdt.core.parser.ast.IASTElaboratedTypeSpecifier) - */ - public void acceptElaboratedTypeSpecifier(IASTElaboratedTypeSpecifier elaboratedTypeSpec) - { - // TODO Auto-generated method stub - - } - + + protected void report( IASTOffsetableElement node, int accuracyLevel ){ + try { + resultCollector.accept( currentResource, + node.getElementStartingOffset(), + node.getElementEndingOffset(), + null, + accuracyLevel ); + } catch (CoreException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + private ICSearchPattern searchPattern; + private ICSearchResultCollector resultCollector; + private IProgressMonitor progressMonitor; + private IResource currentResource; + private ICSearchScope searchScope; + private LinkedList resourceStack; + private IWorkspaceRoot workspaceRoot; } diff --git a/core/org.eclipse.cdt.ui/ChangeLog b/core/org.eclipse.cdt.ui/ChangeLog index 26f0a650eaf..503237c09f1 100644 --- a/core/org.eclipse.cdt.ui/ChangeLog +++ b/core/org.eclipse.cdt.ui/ChangeLog @@ -1,3 +1,25 @@ +2003-06-27 Andrew Niefer + Changes for C/C++ Search: + Added: + * src/org/eclipse/cdt/internal/ui/search/CElementLabels.java + * src/org/eclipse/cdt/internal/ui/search/CSearchResultLabelProvider.java + * src/org/eclipse/cdt/internal/ui/search/CSearchViewActionGroup.java + * src/org/eclipse/cdt/internal/ui/search/ElementNameSorter.java + * src/org/eclipse/cdt/internal/ui/search/GotoMarkerAction.java + * src/org/eclipse/cdt/internal/ui/search/GroupByKeyComputer.java + * src/org/eclipse/cdt/internal/ui/search/ParentNameSorter.java + * src/org/eclipse/cdt/internal/ui/search/PathNameSorter.java + * icons/full/clcl16/search_sortmatch.gif + * icons/full/obj16/search_decl_obj.gif + * icons/full/obj16/search_ref_obj.gif + Modified: + * src/org/eclipse/cdt/internal/ui/search/CSearchOperation.java + * src/org/eclipse/cdt/internal/ui/search/CSearchPage.java + * src/org/eclipse/cdt/internal/ui/search/CSearchResultCollector.java + * src/org/eclipse/cdt/internal/ui/search/CSearchMessages.properties.java + * plugin.xml + * plugin.properties + 2003-06-26 Sean Evoy Added a tab to the new standard make project wizard and CNature project property page. User interacts with two list controls to add include paths diff --git a/core/org.eclipse.cdt.ui/icons/full/obj16/search_decl_obj.gif b/core/org.eclipse.cdt.ui/icons/full/obj16/search_decl_obj.gif new file mode 100644 index 0000000000000000000000000000000000000000..3eddefd94eacb17ec5f6c73c2c9df48327c0080b GIT binary patch literal 157 zcmZ?wbhEHb6krfw*v!CSZy*2v|NQ^IKm5Nx|NeaY{q^?s@%I1!|37fxKtn@Ae0)3u z0|Sr?Bq2cYCkrD30}q1^hzl}@{3buu*M2LD5y9cGUI$k_bwqu25SJI CpFBhW literal 0 HcmV?d00001 diff --git a/core/org.eclipse.cdt.ui/icons/full/obj16/search_ref_obj.gif b/core/org.eclipse.cdt.ui/icons/full/obj16/search_ref_obj.gif new file mode 100644 index 0000000000000000000000000000000000000000..1b0c43bc1ee15f1379b5534101a8dbf6770e007d GIT binary patch literal 151 zcmZ?wbhEHb6krfw*v!CSZy$gE{{H{>=l}oz|Gz%6Q MI_KRELqP^>0L*zkegFUf literal 0 HcmV?d00001 diff --git a/core/org.eclipse.cdt.ui/plugin.properties b/core/org.eclipse.cdt.ui/plugin.properties index d863eaaca54..696721737ba 100644 --- a/core/org.eclipse.cdt.ui/plugin.properties +++ b/core/org.eclipse.cdt.ui/plugin.properties @@ -93,3 +93,13 @@ ToolName.compiler = Compiler ToolName.archiver = Archiver ToolName.linker = Linker ToolName.command = Command Line + +#C/C++ Search +CSearchPage.label= C/C++ Search +ElementNameSorter.label= &Name +ElementNameSorter.tooltip= Sort the view by C Element Name +ParentNameSorter.label= &Parent Name +ParentNameSorter.tooltip= Sort the view by C Element Parent Name +PathNameSorter.label= P&ath +PathNameSorter.tooltip= Sort the view by Resource Path + diff --git a/core/org.eclipse.cdt.ui/plugin.xml b/core/org.eclipse.cdt.ui/plugin.xml index 600d322a47b..5cd156a5904 100644 --- a/core/org.eclipse.cdt.ui/plugin.xml +++ b/core/org.eclipse.cdt.ui/plugin.xml @@ -946,12 +946,39 @@ point="org.eclipse.search.searchPages"> + + + + + + + + diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/CPluginImages.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/CPluginImages.java index 84e82d37077..030317a17cd 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/CPluginImages.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/CPluginImages.java @@ -164,6 +164,13 @@ public class CPluginImages { public static final String IMG_BUILD_TOOL = NAME_PREFIX + "config-tool.gif"; public static final ImageDescriptor DESC_BUILD_TOOL = createManaged(T_BUILD, IMG_BUILD_TOOL); + //for search + public static final String IMG_OBJS_SEARCH_REF = NAME_PREFIX + "search_ref_obj.gif"; + public static final String IMG_OBJS_SEARCH_DECL = NAME_PREFIX + "search_decl_obj.gif"; + + public static final ImageDescriptor DESC_OBJS_SEARCH_DECL = createManaged(T_OBJ, IMG_OBJS_SEARCH_DECL); + public static final ImageDescriptor DESC_OBJS_SEARCH_REF = createManaged(T_OBJ, IMG_OBJS_SEARCH_REF); + public static void initialize() { //createManaged(registry, T_OBJ, IMG_OBJS_TUNIT); //createManaged(registry, T_OBJ, IMG_OBJS_FIELD); diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/CElementLabels.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/CElementLabels.java new file mode 100644 index 00000000000..d9b4137ad13 --- /dev/null +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/CElementLabels.java @@ -0,0 +1,362 @@ +/******************************************************************************* + * 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 Jun 24, 2003 + */ +package org.eclipse.cdt.internal.ui.search; + +import org.eclipse.cdt.core.model.ICElement; +import org.eclipse.cdt.core.model.IMethod; +import org.eclipse.cdt.core.model.IStructure; +import org.eclipse.core.runtime.IAdaptable; +import org.eclipse.ui.model.IWorkbenchAdapter; + +/** + * @author aniefer + * + * To change the template for this generated type comment go to + * Window>Preferences>Java>Code Generation>Code and Comments + */ +public class CElementLabels { + + /** + * Method names contain parameter types. + * e.g. foo(int) + */ + public final static int M_PARAMETER_TYPES= 1 << 0; + + /** + * Method names contain parameter names. + * e.g. foo(index) + */ + public final static int M_PARAMETER_NAMES= 1 << 1; + + /** + * Method names contain thrown exceptions. + * e.g. foo throw( IOException ) + */ + public final static int M_EXCEPTIONS= 1 << 2; + + /** + * Method names contain return type (appended) + * e.g. foo : int + */ + public final static int M_APP_RETURNTYPE= 1 << 3; + + /** + * Method names contain return type (appended) + * e.g. int foo + */ + public final static int M_PRE_RETURNTYPE= 1 << 4; + + /** + * Method names are fully qualified. + * e.g. java.util.Vector.size + */ + public final static int M_FULLY_QUALIFIED= 1 << 5; + + /** + * Method names are post qualified. + * e.g. size - java.util.Vector + */ + public final static int M_POST_QUALIFIED= 1 << 6; + + /** + * Initializer names are fully qualified. + * e.g. java.util.Vector.{ ... } + */ + public final static int I_FULLY_QUALIFIED= 1 << 7; + + /** + * Type names are post qualified. + * e.g. { ... } - java.util.Map + */ + public final static int I_POST_QUALIFIED= 1 << 8; + + /** + * Field names contain the declared type (appended) + * e.g. int fHello + */ + public final static int F_APP_TYPE_SIGNATURE= 1 << 9; + + /** + * Field names contain the declared type (prepended) + * e.g. fHello : int + */ + public final static int F_PRE_TYPE_SIGNATURE= 1 << 10; + + /** + * Fields names are fully qualified. + * e.g. java.lang.System.out + */ + public final static int F_FULLY_QUALIFIED= 1 << 11; + + /** + * Fields names are post qualified. + * e.g. out - java.lang.System + */ + public final static int F_POST_QUALIFIED= 1 << 12; + + /** + * Type names are fully qualified. + * e.g. java.util.Map.MapEntry + */ + public final static int T_FULLY_QUALIFIED= 1 << 13; + + /** + * Type names are type container qualified. + * e.g. Map.MapEntry + */ + public final static int T_CONTAINER_QUALIFIED= 1 << 14; + + /** + * Type names are post qualified. + * e.g. MapEntry - java.util.Map + */ + public final static int T_POST_QUALIFIED= 1 << 15; + + /** + * Declarations (import container / declarartion, package declarartion) are qualified. + * e.g. java.util.Vector.class/import container + */ + public final static int D_QUALIFIED= 1 << 16; + + /** + * Declarations (import container / declarartion, package declarartion) are post qualified. + * e.g. import container - java.util.Vector.class + */ + public final static int D_POST_QUALIFIED= 1 << 17; + + /** + * Class file names are fully qualified. + * e.g. java.util.Vector.class + */ + public final static int CF_QUALIFIED= 1 << 18; + + /** + * Class file names are post qualified. + * e.g. Vector.class - java.util + */ + public final static int CF_POST_QUALIFIED= 1 << 19; + + /** + * Compilation unit names are fully qualified. + * e.g. java.util.Vector.java + */ + public final static int CU_QUALIFIED= 1 << 20; + + /** + * Compilation unit names are post qualified. + * e.g. Vector.java - java.util + */ + public final static int CU_POST_QUALIFIED= 1 << 21; + + /** + * Package names are qualified. + * e.g. MyProject/src/java.util + */ + public final static int P_QUALIFIED= 1 << 22; + + /** + * Package names are post qualified. + * e.g. java.util - MyProject/src + */ + public final static int P_POST_QUALIFIED= 1 << 23; + + /** + * Package Fragment Roots contain variable name if from a variable. + * e.g. JRE_LIB - c:\java\lib\rt.jar + */ + public final static int ROOT_VARIABLE= 1 << 24; + + /** + * Package Fragment Roots contain the project name if not an archive (prepended). + * e.g. MyProject/src + */ + public final static int ROOT_QUALIFIED= 1 << 25; + + /** + * Package Fragment Roots contain the project name if not an archive (appended). + * e.g. src - MyProject + */ + public final static int ROOT_POST_QUALIFIED= 1 << 26; + + /** + * Add root path to all elements except Package Fragment Roots and Java projects. + * e.g. java.lang.Vector - c:\java\lib\rt.jar + * Option only applies to getElementLabel + */ + public final static int APPEND_ROOT_PATH= 1 << 27; + + /** + * Add root path to all elements except Package Fragment Roots and Java projects. + * e.g. java.lang.Vector - c:\java\lib\rt.jar + * Option only applies to getElementLabel + */ + public final static int PREPEND_ROOT_PATH= 1 << 28; + + /** + * Package names are compressed. + * e.g. o*.e*.search + */ + public final static int P_COMPRESSED= 1 << 29; + + /** + * Post qualify referenced package fragement roots. For example + * jdt.jar - org.eclipse.jdt.ui if the jar is referenced + * from another project. + */ + public final static int REFERENCED_ROOT_POST_QUALIFIED= 1 << 30; + + /** + * Qualify all elements + */ + public final static int ALL_FULLY_QUALIFIED= F_FULLY_QUALIFIED | M_FULLY_QUALIFIED | I_FULLY_QUALIFIED | T_FULLY_QUALIFIED | D_QUALIFIED | CF_QUALIFIED | CU_QUALIFIED | P_QUALIFIED | ROOT_QUALIFIED; + + /** + * Post qualify all elements + */ + public final static int ALL_POST_QUALIFIED= F_POST_QUALIFIED | M_POST_QUALIFIED | I_POST_QUALIFIED | T_POST_QUALIFIED | D_POST_QUALIFIED | CF_POST_QUALIFIED | CU_POST_QUALIFIED | P_POST_QUALIFIED | ROOT_POST_QUALIFIED; + + /** + * Default options (M_PARAMETER_TYPES enabled) + */ + public final static int ALL_DEFAULT= M_PARAMETER_TYPES; + + /** + * Default qualify options (All except Root and Package) + */ + public final static int DEFAULT_QUALIFIED= F_FULLY_QUALIFIED | M_FULLY_QUALIFIED | I_FULLY_QUALIFIED | T_FULLY_QUALIFIED | D_QUALIFIED | CF_QUALIFIED | CU_QUALIFIED; + + /** + * Default post qualify options (All except Root and Package) + */ + public final static int DEFAULT_POST_QUALIFIED= F_POST_QUALIFIED | M_POST_QUALIFIED | I_POST_QUALIFIED | T_POST_QUALIFIED | D_POST_QUALIFIED | CF_POST_QUALIFIED | CU_POST_QUALIFIED; + + + public final static String CONCAT_STRING= CSearchMessages.getString("CElementLabels.concat_string"); // " - "; //$NON-NLS-1$ + public final static String COMMA_STRING = CSearchMessages.getString("CElementLabels.comma_string"); // ", "; //$NON-NLS-1$ + public final static String DECL_STRING = CSearchMessages.getString("CElementLabels.declseparator_string"); // " "; // use for return type //$NON-NLS-1$ + + public static String getTextLabel(Object obj, int flags) { + if (obj instanceof ICElement) { + return getElementLabel((ICElement) obj, flags); + } else if (obj instanceof IAdaptable) { + IWorkbenchAdapter wbadapter= (IWorkbenchAdapter) ((IAdaptable)obj).getAdapter(IWorkbenchAdapter.class); + if (wbadapter != null) { + return wbadapter.getLabel(obj); + } + } + return ""; //$NON-NLS-1$ + } + + public static String getElementLabel(ICElement element, int flags) { + StringBuffer buf= new StringBuffer(60); + getElementLabel(element, flags, buf); + return buf.toString(); + } + + public static void getElementLabel(ICElement element, int flags, StringBuffer buf) { + int type= element.getElementType(); + + switch( type ){ + case ICElement.C_METHOD : + getMethodLabel( (IMethod) element, flags, buf ); + break; + case ICElement.C_CLASS: + case ICElement.C_STRUCT: + case ICElement.C_UNION: + case ICElement.C_ENUMERATION: + // getTypeLabel( (IType) element, flags, buf ); + } + } + + public static void getMethodLabel( IMethod method, int flags, StringBuffer buf ) { + //return type + if( getFlag( flags, M_PRE_RETURNTYPE ) && method.exists() && !method.isConstructor() ) { + buf.append( method.getReturnType() ); + buf.append( ' ' ); + } + + //qualification + if( getFlag( flags, M_FULLY_QUALIFIED ) ){ + getTypeLabel( method.getParent(), T_FULLY_QUALIFIED | (flags & P_COMPRESSED), buf ); + buf.append( "::" ); + } + + buf.append( method.getElementName() ); + + //parameters + if( getFlag( flags, M_PARAMETER_TYPES | M_PARAMETER_NAMES ) ) { + buf.append('('); + + String[] types = getFlag(flags, M_PARAMETER_TYPES) ? method.getParameterTypes() : null; + String[] names = null;//(getFlag(flags, M_PARAMETER_NAMES) && method.exists()) ? method.getParameterNames() : null; + + int nParams = ( types != null ) ? types.length : names.length; + + for (int i= 0; i < nParams; i++) { + if (i > 0) { + buf.append( COMMA_STRING ); //$NON-NLS-1$ + } + + if (types != null) { + buf.append( types[i] ); + } + + if (names != null) { + if (types != null) { + buf.append(' '); + } + buf.append( names[i] ); + } + } + buf.append(')'); + } + + //exceptions + if( getFlag( flags, M_EXCEPTIONS ) && method.exists() ){ + String [] types = method.getExceptions(); + if (types.length > 0) { + buf.append(" throw( "); //$NON-NLS-1$ + for (int i= 0; i < types.length; i++) { + if (i > 0) { + buf.append(COMMA_STRING); + } + buf.append( types[i] ); + } + buf.append( " )" ); + } + } + + if( getFlag( flags, M_APP_RETURNTYPE ) && method.exists() && !method.isConstructor()) { + buf.append( DECL_STRING ); + buf.append( method.getReturnType() ); + } + + // post qualification + if( getFlag(flags, M_POST_QUALIFIED)) { + buf.append( CONCAT_STRING ); + getTypeLabel( method.getParent(), T_FULLY_QUALIFIED | (flags & P_COMPRESSED), buf ); + } + } + + public static void getTypeLabel(ICElement type, int flags, StringBuffer buf) { + if( !(type instanceof IStructure) ){ + return; + } + } + + + private static boolean getFlag(int flags, int flag) { + return (flags & flag) != 0; + } +} diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/CSearchMessages.properties b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/CSearchMessages.properties index 8f5d952d56c..5d86b689bed 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/CSearchMessages.properties +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/CSearchMessages.properties @@ -39,32 +39,32 @@ Search.Error.setDescription.message=Cannot save workspace description SearchElementSelectionDialog.title=Search SearchElementSelectionDialog.message=Select the element to search for. -SearchResultCollector.match= 1 match -SearchResultCollector.matches= {0} matches -SearchResultCollector.done= Search done: {0}. -SearchResultCollector.searching= Searching... +CSearchResultCollector.match= 1 match +CSearchResultCollector.matches= {0} matches +CSearchResultCollector.done= Search done: {0}. +CSearchResultCollector.searching= Searching... Search.potentialMatchDialog.title.foundPotentialMatch= Search: Found 1 Inexact Match Search.potentialMatchDialog.title.foundPotentialMatches= Search: Found {0} Inexact Matches Search.potentialMatchDialog.message= Inexact matches were found and will be displayed with a different\nforeground color. This can be configured on the Search preference page. -SearchPage.searchFor.label= Search For -SearchPage.searchFor.type= &Type -SearchPage.searchFor.method= &Method -SearchPage.searchFor.field= &Field -SearchPage.searchFor.package= &Package -SearchPage.searchFor.constructor= Co&nstructor +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 -SearchPage.limitTo.label= Limit To -SearchPage.limitTo.declarations= Dec&larations -SearchPage.limitTo.implementors= &Implementors -SearchPage.limitTo.references= &References -SearchPage.limitTo.allOccurrences= All &Occurrences -SearchPage.limitTo.readReferences= Read A&ccess -SearchPage.limitTo.writeReferences= Writ&e Access +CSearchPage.limitTo.label= Limit To +CSearchPage.limitTo.declarations= Dec&larations +CSearchPage.limitTo.implementors= &Implementors +CSearchPage.limitTo.references= &References +CSearchPage.limitTo.allOccurrences= All &Occurrences +CSearchPage.limitTo.readReferences= Read A&ccess +CSearchPage.limitTo.writeReferences= Writ&e Access -SearchPage.expression.label= Se&arch string (* = any string, ? = any character): -SearchPage.expression.caseSensitive= Case sens&itive +CSearchPage.expression.label= Se&arch string (* = any string, ? = any character): +CSearchPage.expression.caseSensitive= Case sens&itive # Concatenate two working set names e.g. "Source, Lib" SearchUtil.workingSetConcatenation= {0}, {1} @@ -125,20 +125,20 @@ FindOccurrencesEngine.cannotParse.text= Cannot analyze the compilation unit or c JavaSearchOperation.default_package=(default package) # The first argument will be replaced by the pattern and the second by the scope -JavaSearchOperation.singularDeclarationsPostfix={0} - 1 Declaration in {1} -JavaSearchOperation.singularReferencesPostfix={0} - 1 Reference in {1} -JavaSearchOperation.singularReadReferencesPostfix={0} - 1 Read Reference in {1} -JavaSearchOperation.singularWriteReferencesPostfix={0} - 1 Write Reference in {1} -JavaSearchOperation.singularImplementorsPostfix={0} - 1 Implementor in {1} -JavaSearchOperation.singularOccurrencesPostfix={0} - 1 Occurrence in {1} +CSearchOperation.singularDeclarationsPostfix={0} - 1 Declaration in {1} +CSearchOperation.singularReferencesPostfix={0} - 1 Reference in {1} +CSearchOperation.singularReadReferencesPostfix={0} - 1 Read Reference in {1} +CSearchOperation.singularWriteReferencesPostfix={0} - 1 Write Reference in {1} +CSearchOperation.singularImplementorsPostfix={0} - 1 Implementor in {1} +CSearchOperation.singularOccurrencesPostfix={0} - 1 Occurrence in {1} # The first argument will be replaced by the pattern, the second by the count and the last by the scope -JavaSearchOperation.pluralDeclarationsPostfix={0} - {1} Declarations in {2} -JavaSearchOperation.pluralReferencesPostfix={0} - {1} References in {2} -JavaSearchOperation.pluralReadReferencesPostfix={0} - {1} Read References in {2} -JavaSearchOperation.pluralWriteReferencesPostfix={0} - {1} Write References in {2} -JavaSearchOperation.pluralImplementorsPostfix={0} - {1} Implementors in {2} -JavaSearchOperation.pluralOccurrencesPostfix={0} - {1} Occurrences in {2} +CSearchOperation.pluralDeclarationsPostfix={0} - {1} Declarations in {2} +CSearchOperation.pluralReferencesPostfix={0} - {1} References in {2} +CSearchOperation.pluralReadReferencesPostfix={0} - {1} Read References in {2} +CSearchOperation.pluralWriteReferencesPostfix={0} - {1} Write References in {2} +CSearchOperation.pluralImplementorsPostfix={0} - {1} Implementors in {2} +CSearchOperation.pluralOccurrencesPostfix={0} - {1} Occurrences in {2} # The first argument will be replaced by the element name and the second one by the file name JavaSearchInFile.singularPostfix={0} - 1 Occurrence in {1} @@ -154,9 +154,13 @@ JavaElementAction.operationUnavailable.generic= The operation is unavailable on JavaElementAction.operationUnavailable.field= The operation is unavailable on the current selection. Please select the name of a field. JavaElementAction.operationUnavailable.interface= The operation is unavailable on the current selection. Please select the name of an interface. -JavaSearchResultLabelProvider.potentialMatch= \ (inexact) +CSearchResultLabelProvider.potentialMatch= \ (inexact) WorkspaceScope= Workspace WorkingSetScope= Working Set - {0} SelectionScope= Selection HierarchyScope= Hierarchy - {0} + +CElementLabels.concat_string=\ -\ +CElementLabels.comma_string=,\ +CElementLabels.declseparator_string=\ :\ \ No newline at end of file diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/CSearchOperation.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/CSearchOperation.java index 20191987a2f..8088974b781 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/CSearchOperation.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/CSearchOperation.java @@ -16,12 +16,15 @@ package org.eclipse.cdt.internal.ui.search; import java.lang.reflect.InvocationTargetException; import org.eclipse.cdt.core.model.ICElement; +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.ui.CPluginImages; import org.eclipse.core.resources.IWorkspace; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.jface.resource.ImageDescriptor; import org.eclipse.ui.actions.WorkspaceModifyOperation; /** @@ -48,7 +51,7 @@ public class CSearchOperation extends WorkspaceModifyOperation { _workspace = workspace; _limitTo = limitTo; _scope = scope; - _scopeDecsription = scopeDescription; + _scopeDescription = scopeDescription; _collector = collector; _collector.setOperation( this ); } @@ -70,16 +73,73 @@ public class CSearchOperation extends WorkspaceModifyOperation { } } + + /** + * @return + */ + public String getSingularLabel() { + String desc = null; + + if( _elementPattern != null ){ + desc = _elementPattern.getElementName(); + } else { + desc = _stringPattern; + } + + String [] args = new String [] { desc, _scopeDescription }; + switch( _limitTo ){ + case ICSearchConstants.DECLARATIONS : + return CSearchMessages.getFormattedString( "CSearchOperation.singularDeclarationsPostfix", args ); //$NON_NLS-1$ + case ICSearchConstants.REFERENCES : + return CSearchMessages.getFormattedString( "CSearchOperation.singularReferencesPostfix", args ); //$NON_NLS-1$ + default: + return CSearchMessages.getFormattedString( "CSearchOperation.singularOccurencesPostfix", args ); //$NON_NLS-1$ + } + } + /** + * @return + */ + public String getPluralLabelPattern() { + String desc = null; + + if( _elementPattern != null ){ + desc = _elementPattern.getElementName(); + } else { + desc = _stringPattern; + } + + String [] args = new String [] { desc, "{0}", _scopeDescription }; + switch( _limitTo ){ + case ICSearchConstants.DECLARATIONS : + return CSearchMessages.getFormattedString( "CSearchOperation.pluralDeclarationsPostfix", args ); //$NON_NLS-1$ + case ICSearchConstants.REFERENCES : + return CSearchMessages.getFormattedString( "CSearchOperation.pluralReferencesPostfix", args ); //$NON_NLS-1$ + default: + return CSearchMessages.getFormattedString( "CSearchOperation.pluralOccurencesPostfix", args ); //$NON_NLS-1$ + } + } + + /** + * @return + */ + public ImageDescriptor getImageDescriptor() { + if( _limitTo == ICSearchConstants.DECLARATIONS ){ + return CPluginImages.DESC_OBJS_SEARCH_DECL; + } else { + return CPluginImages.DESC_OBJS_SEARCH_REF; + } + } private CSearchResultCollector _collector; private IWorkspace _workspace; private ICElement _elementPattern; private ICSearchScope _scope; private String _stringPattern; - private String _scopeDecsription; + private String _scopeDescription; private boolean _caseSensitive; private int _limitTo; private int _searchFor; + } diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/CSearchPage.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/CSearchPage.java index 9610d13c4cf..2e1671ec405 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/CSearchPage.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/CSearchPage.java @@ -160,11 +160,9 @@ public class CSearchPage extends DialogPage implements ISearchPage, ICSearchCons } }; - fSearchFor[ TYPE ].addSelectionListener(cElementInitializer); - fSearchFor[ FUNCTION ].addSelectionListener(cElementInitializer); - fSearchFor[ MEMBER ].addSelectionListener(cElementInitializer); - fSearchFor[CONSTRUCTOR].addSelectionListener(cElementInitializer); - //fSearchFor[ PACKAGE ].addSelectionListener(cElementInitializer); + for( int i = 0; i < fSearchFor.length; i++ ){ + fSearchFor[ i ].addSelectionListener( cElementInitializer ); + } setControl( result ); @@ -183,7 +181,7 @@ public class CSearchPage extends DialogPage implements ISearchPage, ICSearchCons // Pattern text + info Label label = new Label( result, SWT.LEFT ); - label.setText( CSearchMessages.getString( "SearchPage.expression.label" ) ); //$NON-NLS-1$ + label.setText( CSearchMessages.getString( "CSearchPage.expression.label" ) ); //$NON-NLS-1$ gd = new GridData( GridData.BEGINNING ); gd.horizontalSpan = 2; label.setLayoutData( gd ); @@ -210,7 +208,7 @@ public class CSearchPage extends DialogPage implements ISearchPage, ICSearchCons // Ignore case checkbox fCaseSensitive= new Button(result, SWT.CHECK); - fCaseSensitive.setText(CSearchMessages.getString("SearchPage.expression.caseSensitive")); //$NON-NLS-1$ + fCaseSensitive.setText(CSearchMessages.getString("CSearchPage.expression.caseSensitive")); //$NON-NLS-1$ gd= new GridData(); fCaseSensitive.setLayoutData(gd); fCaseSensitive.addSelectionListener( new SelectionAdapter() { @@ -259,7 +257,7 @@ public class CSearchPage extends DialogPage implements ISearchPage, ICSearchCons private Control createLimitTo( Composite parent ) { Group result = new Group(parent, SWT.NONE); - result.setText( CSearchMessages.getString("SearchPage.limitTo.label") ); //$NON-NLS-1$ + result.setText( CSearchMessages.getString("CSearchPage.limitTo.label") ); //$NON-NLS-1$ GridLayout layout = new GridLayout(); layout.numColumns = 2; result.setLayout( layout ); @@ -315,7 +313,7 @@ public class CSearchPage extends DialogPage implements ISearchPage, ICSearchCons private Control createSearchFor(Composite parent) { Group result= new Group(parent, SWT.NONE); - result.setText(CSearchMessages.getString("SearchPage.searchFor.label")); //$NON-NLS-1$ + result.setText(CSearchMessages.getString("CSearchPage.searchFor.label")); //$NON-NLS-1$ GridLayout layout= new GridLayout(); layout.numColumns= 3; result.setLayout(layout); @@ -566,8 +564,8 @@ public class CSearchPage extends DialogPage implements ISearchPage, ICSearchCons pattern= p; isCaseSensitive= i; cElement= element; - this.scope= scope; - this.workingSets= workingSets; + this.scope = scope; + this.workingSets = workingSets; } } @@ -579,20 +577,20 @@ public class CSearchPage extends DialogPage implements ISearchPage, ICSearchCons private Button[] fSearchFor; private String[] fSearchForText= { - CSearchMessages.getString("SearchPage.searchFor.type"), //$NON-NLS-1$ - CSearchMessages.getString("SearchPage.searchFor.method"), //$NON-NLS-1$ - //CSearchMessages.getString("SearchPage.searchFor.package"), //$NON-NLS-1$ - CSearchMessages.getString("SearchPage.searchFor.constructor"), //$NON-NLS-1$ - CSearchMessages.getString("SearchPage.searchFor.field")}; //$NON-NLS-1$ - + 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$ + private Button[] fLimitTo; private String[] fLimitToText= { - CSearchMessages.getString("SearchPage.limitTo.declarations"), //$NON-NLS-1$ - CSearchMessages.getString("SearchPage.limitTo.implementors"), //$NON-NLS-1$ - CSearchMessages.getString("SearchPage.limitTo.references"), //$NON-NLS-1$ - CSearchMessages.getString("SearchPage.limitTo.allOccurrences"), //$NON-NLS-1$ - CSearchMessages.getString("SearchPage.limitTo.readReferences"), //$NON-NLS-1$ - CSearchMessages.getString("SearchPage.limitTo.writeReferences")}; //$NON-NLS-1$ + CSearchMessages.getString("CSearchPage.limitTo.declarations"), //$NON-NLS-1$ + CSearchMessages.getString("CSearchPage.limitTo.implementors"), //$NON-NLS-1$ + CSearchMessages.getString("CSearchPage.limitTo.references"), //$NON-NLS-1$ + CSearchMessages.getString("CSearchPage.limitTo.allOccurrences"), //$NON-NLS-1$ + CSearchMessages.getString("CSearchPage.limitTo.readReferences"), //$NON-NLS-1$ + CSearchMessages.getString("CSearchPage.limitTo.writeReferences")}; //$NON-NLS-1$ private SearchPatternData fInitialData; private IStructuredSelection fStructuredSelection; diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/CSearchResultCollector.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/CSearchResultCollector.java index cecf8eea2fb..47390cc1b56 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/CSearchResultCollector.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/CSearchResultCollector.java @@ -13,10 +13,19 @@ */ package org.eclipse.cdt.internal.ui.search; +import java.text.MessageFormat; +import java.util.HashMap; + +import org.eclipse.cdt.core.model.ICElement; import org.eclipse.cdt.core.search.ICSearchResultCollector; +import org.eclipse.core.resources.IMarker; import org.eclipse.core.resources.IResource; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.search.ui.IActionGroupFactory; +import org.eclipse.search.ui.ISearchResultView; +import org.eclipse.search.ui.SearchUI; +import org.eclipse.ui.actions.ActionGroup; /** * @author aniefer @@ -38,8 +47,24 @@ public class CSearchResultCollector implements ICSearchResultCollector { * @see org.eclipse.cdt.core.search.ICSearchResultCollector#aboutToStart() */ public void aboutToStart() { - // TODO Auto-generated method stub - + _view = SearchUI.getSearchResultView(); + _matchCount = 0; + if( _view != null ){ + _view.searchStarted( + new ActionGroupFactory(), + _operation.getSingularLabel(), + _operation.getPluralLabelPattern(), + _operation.getImageDescriptor(), + CSearchPage.EXTENSION_POINT_ID, + new CSearchResultLabelProvider(), + new GotoMarkerAction(), + new GroupByKeyComputer(), + _operation + ); + } + if( !getProgressMonitor().isCanceled() ){ + getProgressMonitor().subTask( SEARCHING ); + } } /* (non-Javadoc) @@ -49,19 +74,47 @@ public class CSearchResultCollector implements ICSearchResultCollector { IResource resource, int start, int end, - Object enclosingElement, + ICElement enclosingElement, int accuracy) - throws CoreException { - // TODO Auto-generated method stub - + throws CoreException + { + IMarker marker = resource.createMarker( SearchUI.SEARCH_MARKER ); + + Object groupKey = enclosingElement; + + 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 ) ) ); + + marker.setAttributes( markerAttributes ); + + _view.addMatch( enclosingElement.getElementName(), groupKey, resource, marker ); + _matchCount++; } /* (non-Javadoc) * @see org.eclipse.cdt.core.search.ICSearchResultCollector#done() */ public void done() { - // TODO Auto-generated method stub + if( !getProgressMonitor().isCanceled() ){ + String matchesString; + if( _matchCount == 1 ){ + matchesString = MATCH; + } else { + matchesString = MessageFormat.format( MATCHES, new Integer[]{ new Integer(_matchCount) } ); + } + + getProgressMonitor().setTaskName( MessageFormat.format( DONE, new String[]{ matchesString } ) ); + } + if( _view != null ){ + _view.searchFinished(); + } + + _view = null; + _monitor = null; } /* (non-Javadoc) @@ -71,22 +124,28 @@ public class CSearchResultCollector implements ICSearchResultCollector { return _monitor; } - /** - * @param monitor - */ public void setProgressMonitor(IProgressMonitor monitor) { this._monitor = monitor; } - private IProgressMonitor _monitor; - - /** - * @param operation - */ public void setOperation( CSearchOperation operation ) { _operation = operation; } + private class ActionGroupFactory implements IActionGroupFactory { + public ActionGroup createActionGroup( ISearchResultView part ){ + return new CSearchViewActionGroup( part ); + } + } - private CSearchOperation _operation; + 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$ + private static final String DONE = CSearchMessages.getString("CSearchResultCollector.done"); //$NON-NLS-1$ + + + private IProgressMonitor _monitor; + private CSearchOperation _operation; + private ISearchResultView _view; + private int _matchCount; } diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/CSearchResultLabelProvider.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/CSearchResultLabelProvider.java new file mode 100644 index 00000000000..982de6b2a7f --- /dev/null +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/CSearchResultLabelProvider.java @@ -0,0 +1,133 @@ +/******************************************************************************* + * 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 Jun 18, 2003 + */ +package org.eclipse.cdt.internal.ui.search; + +import org.eclipse.cdt.core.model.ICElement; +import org.eclipse.core.resources.IMarker; +import org.eclipse.jface.viewers.LabelProvider; +import org.eclipse.search.ui.ISearchResultViewEntry; +import org.eclipse.search.ui.SearchUI; +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 CSearchResultLabelProvider extends LabelProvider { + + public static final int SHOW_ELEMENT_CONTAINER = 1; //default + public static final int SHOW_CONTAINER_ELEMENT = 2; + public static final int SHOW_PATH = 3; + + public final static int DEFAULT_TEXTFLAGS = CElementLabels.ROOT_VARIABLE | + CElementLabels.M_PARAMETER_TYPES | + CElementLabels.M_APP_RETURNTYPE | + CElementLabels.REFERENCED_ROOT_POST_QUALIFIED; + + public static final String POTENTIAL_MATCH = CSearchMessages.getString("CSearchResultLabelProvider.potentialMatch"); //$NON-NLS-1$ + + public Image getImage( Object element ) { + return null; + } + + 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 ""; + } + } + + String text = ""; + if( isPotentialMatch ){ + text = CElementLabels.getTextLabel( element, _textFlags ) + POTENTIAL_MATCH; + } else { + text = CElementLabels.getTextLabel( element, _textFlags ); + } + //if( cElement instanceof ) + + return element == null ? "" : element.toString();//$NON-NLS-1$ + } + + public void setOrder(int orderFlag) { + int flags = DEFAULT_TEXTFLAGS | CElementLabels.P_COMPRESSED; + + switch( orderFlag ){ + case SHOW_ELEMENT_CONTAINER: + flags |= CElementLabels.ALL_POST_QUALIFIED | CElementLabels.M_PARAMETER_TYPES; + break; + case SHOW_PATH: + flags |= CElementLabels.PREPEND_ROOT_PATH; + /*fall through to SHOW_CONTAINER_ELEMENT*/ + case SHOW_CONTAINER_ELEMENT: + flags |= CElementLabels.ALL_FULLY_QUALIFIED | CElementLabels.M_PARAMETER_TYPES; + break; + } + + _textFlags = flags; + } + + protected IMarker getMarker( Object o ){ + if( !( o instanceof ISearchResultViewEntry ) ){ + return null; + } + + 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 int _textFlags; + private int _imageFlags; + +} diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/CSearchViewActionGroup.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/CSearchViewActionGroup.java new file mode 100644 index 00000000000..c6083e4dc49 --- /dev/null +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/CSearchViewActionGroup.java @@ -0,0 +1,35 @@ +/******************************************************************************* + * 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 Jun 18, 2003 + */ +package org.eclipse.cdt.internal.ui.search; + +import org.eclipse.search.ui.ISearchResultView; +import org.eclipse.ui.actions.ActionGroup; + +/** + * @author aniefer + * + * To change the template for this generated type comment go to + * Window>Preferences>Java>Code Generation>Code and Comments + */ +public class CSearchViewActionGroup extends ActionGroup { + + /** + * @param part + */ + public CSearchViewActionGroup(ISearchResultView part) { + + // TODO Auto-generated constructor stub + } + +} diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/ElementNameSorter.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/ElementNameSorter.java new file mode 100644 index 00000000000..de7a8912b4b --- /dev/null +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/ElementNameSorter.java @@ -0,0 +1,68 @@ +/******************************************************************************* + * 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 Jun 24, 2003 + */ +package org.eclipse.cdt.internal.ui.search; + +import org.eclipse.jface.viewers.ILabelProvider; +import org.eclipse.jface.viewers.Viewer; +import org.eclipse.jface.viewers.ViewerSorter; +import org.eclipse.search.ui.ISearchResultView; +import org.eclipse.search.ui.ISearchResultViewEntry; +import org.eclipse.search.ui.SearchUI; + +/** + * @author aniefer + * + * To change the template for this generated type comment go to + * Window>Preferences>Java>Code Generation>Code and Comments + */ +public class ElementNameSorter extends ViewerSorter { + + public int compare( Viewer viewer, Object e1, Object e2 ){ + String name1 = null, name2 = null; + + if (e1 instanceof ISearchResultViewEntry) + name1= _labelProvider.getText( e1 ); + + if (e2 instanceof ISearchResultViewEntry) + name2= _labelProvider.getText( e2 ); + + if (name1 == null) + name1= ""; //$NON-NLS-1$ + + if (name2 == null) + name2= ""; //$NON-NLS-1$ + + return getCollator().compare(name1, name2); + } + + public boolean isSorterProperty( Object element, String property ){ + return true; + } + + public void sort( Viewer viewer, Object[] elements ) { + // Set label provider to show "element - path" + ISearchResultView view = SearchUI.getSearchResultView(); + if (view == null) + return; + + _labelProvider = view.getLabelProvider(); + + if( _labelProvider instanceof CSearchResultLabelProvider ) { + ((CSearchResultLabelProvider)_labelProvider).setOrder( CSearchResultLabelProvider.SHOW_ELEMENT_CONTAINER ); + super.sort( viewer, elements ); + } + } + + private ILabelProvider _labelProvider; +} diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/GotoMarkerAction.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/GotoMarkerAction.java new file mode 100644 index 00000000000..539f211cbf0 --- /dev/null +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/GotoMarkerAction.java @@ -0,0 +1,93 @@ +/******************************************************************************* + * 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 Jun 18, 2003 + */ +package org.eclipse.cdt.internal.ui.search; + +import org.eclipse.cdt.core.model.ICElement; +import org.eclipse.cdt.internal.ui.util.EditorUtility; +import org.eclipse.cdt.internal.ui.util.SelectionUtil; +import org.eclipse.cdt.ui.CUIPlugin; +import org.eclipse.core.resources.IFile; +import org.eclipse.core.resources.IMarker; +import org.eclipse.core.resources.IResource; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.jface.action.Action; +import org.eclipse.search.ui.ISearchResultView; +import org.eclipse.search.ui.ISearchResultViewEntry; +import org.eclipse.search.ui.SearchUI; +import org.eclipse.ui.IEditorPart; +import org.eclipse.ui.IWorkbenchPage; + +/** + * @author aniefer + * + * To change the template for this generated type comment go to + * Window>Preferences>Java>Code Generation>Code and Comments + */ +public class GotoMarkerAction extends Action { + + public GotoMarkerAction(){ + + } + + public void run() { + ISearchResultView view = SearchUI.getSearchResultView(); + Object element = SelectionUtil.getSingleElement( view.getSelection() ); + if( element instanceof ISearchResultViewEntry ) { + ISearchResultViewEntry entry = (ISearchResultViewEntry) element; + show( entry.getSelectedMarker() ); + } + } + + private void show( IMarker marker ){ + IResource resource = marker.getResource(); + if( resource == null || !resource.exists() ){ + return; + } + + IWorkbenchPage page = CUIPlugin.getActivePage(); + ICElement element = CSearchUtil.getCElement( marker ); + + if( SearchUI.reuseEditor() ){ + showWithReuse( marker, resource, element, page ); + } else { + showWithoutReuse( marker, element, page ); + } + } + + private void showWithoutReuse( IMarker marker, ICElement element, IWorkbenchPage page ){ + IEditorPart editor = null; + try{ + Object objectToOpen = ( element != null ) ? (Object) element : (Object) marker.getResource(); + editor = EditorUtility.openInEditor( objectToOpen, false ); + } catch ( CoreException e ) { + //boo + } + if( editor != null ){ + editor.gotoMarker( marker ); + } + } + + private void showWithReuse( IMarker marker, IResource resource, ICElement element, IWorkbenchPage page ) { + if( !(resource instanceof IFile) ){ + return; + } + + IEditorPart editor = EditorUtility.isOpenInEditor( element ); + if( editor != null ){ + page.bringToTop( editor ); + } else { + + } + } +} diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/GroupByKeyComputer.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/GroupByKeyComputer.java new file mode 100644 index 00000000000..1f6fe1ae961 --- /dev/null +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/GroupByKeyComputer.java @@ -0,0 +1,70 @@ +/******************************************************************************* + * 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 Jun 18, 2003 + */ +package org.eclipse.cdt.internal.ui.search; + +import org.eclipse.cdt.core.model.ICElement; +import org.eclipse.core.resources.IMarker; +import org.eclipse.search.ui.IGroupByKeyComputer; + +/** + * @author aniefer + * + * To change the template for this generated type comment go to + * Window>Preferences>Java>Code Generation>Code and Comments + */ +public class GroupByKeyComputer implements IGroupByKeyComputer { + + /* (non-Javadoc) + * @see org.eclipse.search.ui.IGroupByKeyComputer#computeGroupByKey(org.eclipse.core.resources.IMarker) + */ + + public Object computeGroupByKey(IMarker marker) { + if( marker == null ){ + return null; + } + + // ICElement element = getCElement( marker ); + // if( element != null && element.exists() ){ + // return _lastHandle; + // } + + 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; + } + } + + 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; + +} diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/ParentNameSorter.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/ParentNameSorter.java new file mode 100644 index 00000000000..01681683b6f --- /dev/null +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/ParentNameSorter.java @@ -0,0 +1,75 @@ +/******************************************************************************* + * 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 Jun 24, 2003 + */ +package org.eclipse.cdt.internal.ui.search; + +import org.eclipse.jface.viewers.ILabelProvider; +import org.eclipse.jface.viewers.Viewer; +import org.eclipse.jface.viewers.ViewerSorter; +import org.eclipse.search.ui.ISearchResultView; +import org.eclipse.search.ui.ISearchResultViewEntry; +import org.eclipse.search.ui.SearchUI; + +/** + * @author aniefer + * + * To change the template for this generated type comment go to + * Window>Preferences>Java>Code Generation>Code and Comments + */ +public class ParentNameSorter extends ViewerSorter { + + public int compare(Viewer viewer, Object e1, Object e2) { + String name1= null; + String name2= null; + + if (e1 instanceof ISearchResultViewEntry) + name1= _labelProvider.getText(e1); + + if (e2 instanceof ISearchResultViewEntry) + name2= _labelProvider.getText(e2); + + if (name1 == null) + name1= ""; //$NON-NLS-1$ + + if (name2 == null) + name2= ""; //$NON-NLS-1$ + + return getCollator().compare(name1, name2); + } + + /* + * Overrides method from ViewerSorter + */ + public boolean isSorterProperty(Object element, String property) { + return true; + } + + /* + * Overrides method from ViewerSorter + */ + public void sort(Viewer viewer, Object[] elements) { + // Set label provider to show "path - resource" + ISearchResultView view = SearchUI.getSearchResultView(); + if (view == null) + return; + + _labelProvider = view.getLabelProvider(); + + if( _labelProvider instanceof CSearchResultLabelProvider ) + ((CSearchResultLabelProvider)_labelProvider).setOrder( CSearchResultLabelProvider.SHOW_CONTAINER_ELEMENT ); + + super.sort( viewer, elements ); + } + + private ILabelProvider _labelProvider; +} diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/PathNameSorter.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/PathNameSorter.java new file mode 100644 index 00000000000..eb9443044a0 --- /dev/null +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/PathNameSorter.java @@ -0,0 +1,108 @@ +/******************************************************************************* + * 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 Jun 24, 2003 + */ +package org.eclipse.cdt.internal.ui.search; + +import org.eclipse.core.resources.IMarker; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.IResource; +import org.eclipse.jface.viewers.ILabelProvider; +import org.eclipse.jface.viewers.Viewer; +import org.eclipse.jface.viewers.ViewerSorter; +import org.eclipse.search.ui.ISearchResultView; +import org.eclipse.search.ui.ISearchResultViewEntry; +import org.eclipse.search.ui.SearchUI; + +/** + * @author aniefer + * + * To change the template for this generated type comment go to + * Window>Preferences>Java>Code Generation>Code and Comments + */ +public class PathNameSorter extends ViewerSorter { + + /* + * Overrides method from ViewerSorter + */ + public int compare(Viewer viewer, Object e1, Object e2) { + String name1 = null; + String name2 = null; + ISearchResultViewEntry entry1 = null; + ISearchResultViewEntry entry2 = null; + + if( e1 instanceof ISearchResultViewEntry ) { + entry1 = (ISearchResultViewEntry)e1; + name1 = _labelProvider.getText( e1 ); + } + if( e2 instanceof ISearchResultViewEntry ) { + entry2 = (ISearchResultViewEntry)e2; + name2 = _labelProvider.getText( e2 ); + } + + if( name1 == null ) + name1 = ""; //$NON-NLS-1$ + + if( name2 == null ) + name2 = ""; //$NON-NLS-1$ + + IResource resource = null; + if( entry1 != null) + resource = entry1.getResource(); + + if( resource != null && entry2 != null && resource == entry2.getResource() ) { + + if( resource instanceof IProject || resource.getFileExtension().equalsIgnoreCase("jar") || resource.getFileExtension().equalsIgnoreCase("zip") ) //$NON-NLS-2$ //$NON-NLS-1$ + // binary archives + return getCollator().compare(name1, name2); + + // Sort by marker start position if resource is equal. + int startPos1 = -1; + int startPos2 = -1; + IMarker marker1 = entry1.getSelectedMarker(); + IMarker marker2 = entry2.getSelectedMarker(); + + if (marker1 != null) + startPos1 = marker1.getAttribute( IMarker.CHAR_START, -1 ); + if (marker2 != null) + startPos2 = marker2.getAttribute( IMarker.CHAR_START, -1 ); + + return startPos1 - startPos2; + } + + return getCollator().compare(name1, name2); + } + + /* + * Overrides method from ViewerSorter + */ + public boolean isSorterProperty(Object element, String property) { + return true; + } + + /* + * Overrides method from ViewerSorter + */ + public void sort( Viewer viewer, Object[] elements ) { + // Set label provider to show "path - resource" + ISearchResultView view = SearchUI.getSearchResultView(); + if( view == null ) + return; + + _labelProvider = view.getLabelProvider(); + if( _labelProvider instanceof CSearchResultLabelProvider ) + ((CSearchResultLabelProvider)_labelProvider).setOrder( CSearchResultLabelProvider.SHOW_PATH ); + super.sort( viewer, elements ); + } + + private ILabelProvider _labelProvider; +} \ No newline at end of file