diff --git a/core/org.eclipse.cdt.core.tests/search/org/eclipse/cdt/core/search/tests/BaseSearchTest.java b/core/org.eclipse.cdt.core.tests/search/org/eclipse/cdt/core/search/tests/BaseSearchTest.java index 12c73c0bd60..d958e8b12c4 100644 --- a/core/org.eclipse.cdt.core.tests/search/org/eclipse/cdt/core/search/tests/BaseSearchTest.java +++ b/core/org.eclipse.cdt.core.tests/search/org/eclipse/cdt/core/search/tests/BaseSearchTest.java @@ -84,7 +84,7 @@ public class BaseSearchTest extends TestCase implements ICSearchConstants { IndexManager indexManager = CCorePlugin.getDefault().getCoreModel().getIndexManager(); indexManager.setEnabled(testProject,true); - resultCollector = new CSearchResultCollector( true ); + resultCollector = new CSearchResultCollector(); resultCollector.setProgressMonitor( monitor ); searchEngine = new SearchEngine(); diff --git a/core/org.eclipse.cdt.core.tests/search/org/eclipse/cdt/core/search/tests/ClassDeclarationPatternTests.java b/core/org.eclipse.cdt.core.tests/search/org/eclipse/cdt/core/search/tests/ClassDeclarationPatternTests.java index eaf1c7311bd..d39649ea700 100644 --- a/core/org.eclipse.cdt.core.tests/search/org/eclipse/cdt/core/search/tests/ClassDeclarationPatternTests.java +++ b/core/org.eclipse.cdt.core.tests/search/org/eclipse/cdt/core/search/tests/ClassDeclarationPatternTests.java @@ -14,15 +14,16 @@ package org.eclipse.cdt.core.search.tests; import java.util.Iterator; -import java.util.Set; +import java.util.List; import org.eclipse.cdt.core.search.ICSearchConstants; import org.eclipse.cdt.core.search.ICSearchPattern; +import org.eclipse.cdt.core.search.IMatch; import org.eclipse.cdt.core.search.SearchEngine; import org.eclipse.cdt.internal.core.search.CharOperation; 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.Match; +//import org.eclipse.cdt.internal.ui.search.Match; /** @@ -48,7 +49,7 @@ public class ClassDeclarationPatternTests extends BaseSearchTest implements ICSe search( workspace, pattern, scope, resultCollector ); - Set matches = resultCollector.getMatches(); + List matches = resultCollector.getSearchResults(); assertEquals( matches.size(), 2 ); } @@ -65,7 +66,7 @@ public class ClassDeclarationPatternTests extends BaseSearchTest implements ICSe search( workspace, pattern, scope, resultCollector ); - Set matches = resultCollector.getMatches(); + List matches = resultCollector.getSearchResults(); assertEquals( matches.size(), 1 ); } @@ -73,7 +74,7 @@ public class ClassDeclarationPatternTests extends BaseSearchTest implements ICSe ICSearchPattern pattern = SearchEngine.createSearchPattern( "A::B", TYPE, DECLARATIONS, true ); search( workspace, pattern, scope, resultCollector ); - Set matches = resultCollector.getMatches(); + List matches = resultCollector.getSearchResults(); /* Test should find 1 match */ assertTrue( matches != null ); @@ -82,13 +83,13 @@ public class ClassDeclarationPatternTests extends BaseSearchTest implements ICSe pattern = SearchEngine.createSearchPattern( "NS::NS2::a", TYPE, DECLARATIONS, true ); search( workspace, pattern, scope, resultCollector ); - matches = resultCollector.getMatches(); + matches = resultCollector.getSearchResults(); assertTrue( matches != null ); pattern = SearchEngine.createSearchPattern( "NS::B::A", TYPE, DECLARATIONS, true ); search( workspace, pattern, scope, resultCollector ); - matches = resultCollector.getMatches(); + matches = resultCollector.getSearchResults(); assertTrue( matches != null ); } @@ -99,38 +100,38 @@ public class ClassDeclarationPatternTests extends BaseSearchTest implements ICSe search( workspace, pattern, scope, resultCollector ); - Set matches = resultCollector.getMatches(); + List matches = resultCollector.getSearchResults(); assertEquals( matches.size(), 1 ); pattern = SearchEngine.createSearchPattern( "NS::B::A", TYPE, DECLARATIONS, true ); search( workspace, pattern, scope, resultCollector ); - Set matches2 = resultCollector.getMatches(); + List matches2 = resultCollector.getSearchResults(); assertTrue( matches2 != null ); assertEquals( matches2.size(), 1 ); Iterator iter = matches.iterator(); Iterator iter2 = matches2.iterator(); - Match match = (Match)iter.next(); - Match match2 = (Match)iter2.next(); + IMatch match = (IMatch)iter.next(); + IMatch match2 = (IMatch)iter2.next(); //assertTrue( match.path.equals( match2.path ) ); - assertEquals( match.start, match2.start ); - assertEquals( match.end, match2.end ); + assertEquals( match.getStartOffset(), match2.getStartOffset() ); + assertEquals( match.getEndOffset(), match2.getEndOffset() ); } public void testWildcardQualification() { ICSearchPattern pattern = SearchEngine.createSearchPattern( "::*::A", TYPE, DECLARATIONS, true ); search( workspace, pattern, scope, resultCollector ); - Set matches = resultCollector.getMatches(); + List matches = resultCollector.getSearchResults(); assertEquals( matches.size(), 0 ); pattern = SearchEngine.createSearchPattern( "NS::*::A", TYPE, DECLARATIONS, false ); search( workspace, pattern, scope, resultCollector ); - matches = resultCollector.getMatches(); + matches = resultCollector.getSearchResults(); assertEquals( matches.size(), 2 ); } @@ -138,19 +139,19 @@ public class ClassDeclarationPatternTests extends BaseSearchTest implements ICSe ICSearchPattern pattern = SearchEngine.createSearchPattern( "struct A", TYPE, DECLARATIONS, true ); search( workspace, pattern, scope, resultCollector ); - Set matches = resultCollector.getMatches(); + List matches = resultCollector.getSearchResults(); assertEquals( matches.size(), 1 ); pattern = SearchEngine.createSearchPattern( "union u", TYPE, DECLARATIONS, true ); search( workspace, pattern, scope, resultCollector ); - matches = resultCollector.getMatches(); + matches = resultCollector.getSearchResults(); assertEquals( matches.size(), 2 ); pattern = SearchEngine.createSearchPattern( "union ::*::u", TYPE, DECLARATIONS, true ); search( workspace, pattern, scope, resultCollector ); - matches = resultCollector.getMatches(); + matches = resultCollector.getSearchResults(); assertEquals( matches.size(), 1 ); } @@ -177,7 +178,7 @@ public class ClassDeclarationPatternTests extends BaseSearchTest implements ICSe search( workspace, pattern, scope, resultCollector ); - Set matches = resultCollector.getMatches(); + List matches = resultCollector.getSearchResults(); assertEquals( matches.size(), 1 ); @@ -186,7 +187,7 @@ public class ClassDeclarationPatternTests extends BaseSearchTest implements ICSe search( workspace, pattern, scope, resultCollector ); - matches = resultCollector.getMatches(); + matches = resultCollector.getSearchResults(); assertEquals( matches.size(), 1 ); } @@ -196,7 +197,7 @@ public class ClassDeclarationPatternTests extends BaseSearchTest implements ICSe search( workspace, pattern, scope, resultCollector ); - Set matches = resultCollector.getMatches(); + List matches = resultCollector.getSearchResults(); assertEquals( matches.size(), 3 ); } @@ -205,22 +206,22 @@ public class ClassDeclarationPatternTests extends BaseSearchTest implements ICSe search( workspace, pattern, scope, resultCollector ); - Set matches = resultCollector.getMatches(); + List matches = resultCollector.getSearchResults(); assertEquals( matches.size(), 1 ); - Match match = (Match) matches.iterator().next(); - assertTrue( match.parent.equals( "NS::B" ) ); + IMatch match = (IMatch) matches.iterator().next(); + assertTrue( match.getParentName().equals( "NS::B" ) ); } public void testTypeReferenceVisibleByUsingDirective(){ ICSearchPattern pattern = SearchEngine.createSearchPattern( "::NS::NS2::a", STRUCT, REFERENCES, true ); search( workspace, pattern, scope, resultCollector ); - Set matches = resultCollector.getMatches(); + List matches = resultCollector.getSearchResults(); assertEquals( matches.size(), 1 ); - Match match = (Match) matches.iterator().next(); - assertTrue( match.parent.equals( "NS::B" ) ); + IMatch match = (IMatch) matches.iterator().next(); + assertTrue( match.getParentName().equals( "NS::B" ) ); } public void testEnumerationReferenceVisibleByInheritance(){ @@ -228,11 +229,11 @@ public class ClassDeclarationPatternTests extends BaseSearchTest implements ICSe search( workspace, pattern, scope, resultCollector ); - Set matches = resultCollector.getMatches(); + List matches = resultCollector.getSearchResults(); assertEquals( matches.size(), 1 ); - Match match = (Match) matches.iterator().next(); - assertTrue( match.parent.equals( "NS3::C" ) ); + IMatch match = (IMatch) matches.iterator().next(); + assertTrue( match.getParentName().equals( "NS3::C" ) ); } } diff --git a/core/org.eclipse.cdt.core.tests/search/org/eclipse/cdt/core/search/tests/FunctionMethodPatternTests.java b/core/org.eclipse.cdt.core.tests/search/org/eclipse/cdt/core/search/tests/FunctionMethodPatternTests.java index 0e7e11103f8..2e4d18a5be9 100644 --- a/core/org.eclipse.cdt.core.tests/search/org/eclipse/cdt/core/search/tests/FunctionMethodPatternTests.java +++ b/core/org.eclipse.cdt.core.tests/search/org/eclipse/cdt/core/search/tests/FunctionMethodPatternTests.java @@ -13,7 +13,7 @@ */ package org.eclipse.cdt.core.search.tests; -import java.util.Set; +import java.util.List; import org.eclipse.cdt.core.search.ICSearchPattern; import org.eclipse.cdt.core.search.SearchEngine; @@ -73,7 +73,7 @@ public class FunctionMethodPatternTests extends BaseSearchTest { search( workspace, pattern, scope, resultCollector ); - Set matches = resultCollector.getMatches(); + List matches = resultCollector.getSearchResults(); assertEquals( matches.size(), 1 ); } @@ -83,7 +83,7 @@ public class FunctionMethodPatternTests extends BaseSearchTest { search( workspace, pattern, scope, resultCollector ); - Set matches = resultCollector.getMatches(); + List matches = resultCollector.getSearchResults(); assertEquals( matches.size(), 1 ); } } diff --git a/core/org.eclipse.cdt.core.tests/search/org/eclipse/cdt/core/search/tests/OtherPatternTests.java b/core/org.eclipse.cdt.core.tests/search/org/eclipse/cdt/core/search/tests/OtherPatternTests.java index aa73578ebe4..0e100ea1586 100644 --- a/core/org.eclipse.cdt.core.tests/search/org/eclipse/cdt/core/search/tests/OtherPatternTests.java +++ b/core/org.eclipse.cdt.core.tests/search/org/eclipse/cdt/core/search/tests/OtherPatternTests.java @@ -13,15 +13,15 @@ */ package org.eclipse.cdt.core.search.tests; -import java.util.Set; +import java.util.List; import org.eclipse.cdt.core.search.ICSearchPattern; +import org.eclipse.cdt.core.search.IMatch; import org.eclipse.cdt.core.search.SearchEngine; import org.eclipse.cdt.internal.core.search.CharOperation; import org.eclipse.cdt.internal.core.search.matching.FieldDeclarationPattern; import org.eclipse.cdt.internal.core.search.matching.NamespaceDeclarationPattern; import org.eclipse.cdt.internal.core.search.matching.VariableDeclarationPattern; -import org.eclipse.cdt.internal.ui.search.Match; /** * @author aniefer @@ -95,7 +95,7 @@ public class OtherPatternTests extends BaseSearchTest { search( workspace, pattern, scope, resultCollector ); - Set matches = resultCollector.getMatches(); + List matches = resultCollector.getSearchResults(); assertEquals( matches.size(), 3 ); } @@ -105,12 +105,12 @@ public class OtherPatternTests extends BaseSearchTest { search( workspace, pattern, scope, resultCollector ); - Set matches = resultCollector.getMatches(); + List matches = resultCollector.getSearchResults(); assertEquals( matches.size(), 1 ); - Match match = (Match) matches.iterator().next(); - assertTrue( match.parent.equals( "NS::B" ) ); + IMatch match = (IMatch) matches.iterator().next(); + assertTrue( match.getParentName().equals( "NS::B" ) ); } public void testNamespaceReferenceInClassBaseClause(){ @@ -118,7 +118,7 @@ public class OtherPatternTests extends BaseSearchTest { search( workspace, pattern, scope, resultCollector ); - Set matches = resultCollector.getMatches(); + List matches = resultCollector.getSearchResults(); assertEquals( matches.size(), 2 ); } @@ -127,11 +127,11 @@ public class OtherPatternTests extends BaseSearchTest { search( workspace, pattern, scope, resultCollector ); - Set matches = resultCollector.getMatches(); + List matches = resultCollector.getSearchResults(); assertEquals( matches.size(), 2 ); - Match match = (Match) matches.iterator().next(); - assertTrue( match.parent.equals( "NS::B" ) ); + IMatch match = (IMatch) matches.iterator().next(); + assertTrue( match.getParentName().equals( "NS::B" ) ); } public void testVariableDeclaration(){ @@ -139,11 +139,11 @@ public class OtherPatternTests extends BaseSearchTest { search( workspace, pattern, scope, resultCollector ); - Set matches = resultCollector.getMatches(); + List matches = resultCollector.getSearchResults(); assertEquals( matches.size(), 2 ); - Match match = (Match) matches.iterator().next(); - assertTrue( match.parent.equals( "" ) ); + IMatch match = (IMatch) matches.iterator().next(); + assertTrue( match.getParentName().equals( "" ) ); } } diff --git a/core/org.eclipse.cdt.core/search/ChangeLog b/core/org.eclipse.cdt.core/search/ChangeLog index 51e6c6499d7..e2bf3307f11 100644 --- a/core/org.eclipse.cdt.core/search/ChangeLog +++ b/core/org.eclipse.cdt.core/search/ChangeLog @@ -1,3 +1,11 @@ +2003-07-29 Andrew Niefer + Refactoring Search result collection: + - Modified ICSearchResultCollector + - Modified IMatch + - Modified MatchLocator to reflect changes in ICSearchResultCollector + - Created BasicSearchMatch implements IMatch + - Created BasicSearchResultCollector implements ICSearchResultCollector + 2003-07-28 Andrew Niefer - added abstract CSearchPattern.resetIndexInfo fix bug with searching with globally qualified names diff --git a/core/org.eclipse.cdt.core/search/org/eclipse/cdt/core/search/BasicSearchMatch.java b/core/org.eclipse.cdt.core/search/org/eclipse/cdt/core/search/BasicSearchMatch.java new file mode 100644 index 00000000000..5a72c048613 --- /dev/null +++ b/core/org.eclipse.cdt.core/search/org/eclipse/cdt/core/search/BasicSearchMatch.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 Jul 29, 2003 + */ +package org.eclipse.cdt.core.search; + +import org.eclipse.core.resources.IResource; +import org.eclipse.core.runtime.IPath; + +/** + * @author aniefer + * + * To change the template for this generated type comment go to + * Window>Preferences>Java>Code Generation>Code and Comments + */ +public class BasicSearchMatch implements IMatch { + + public BasicSearchMatch() { + } + + public BasicSearchMatch(BasicSearchMatch basicMatch) { + name = basicMatch.name; + parentName = basicMatch.parentName; + resource = basicMatch.resource; + path = basicMatch.path; + startOffset = basicMatch.startOffset; + endOffset = basicMatch.endOffset; + } + + public String name = null; + public String parentName = null; + + public IResource resource = null; + public IPath path = null; + + public int startOffset = 0; + public int endOffset = 0; + + public int type = 0; + public int visibility = 0; + + boolean isConst = false; + boolean isVolatile = false; + boolean isStatic = false; + + public int getElementType() { + return type; + } + + public int getVisibility() { + return visibility; + } + + public String getName() { + return name; + } + + public String getParentName() { + return parentName; + } + + public IResource getResource() { + return resource; + } + + public int getStartOffset() { + return startOffset; + } + + public int getEndOffset() { + return endOffset; + } + + public boolean isStatic() { + return isStatic; + } + public boolean isConst() { + return isConst; + } + + public boolean isVolatile() { + return isVolatile; + } +} diff --git a/core/org.eclipse.cdt.core/search/org/eclipse/cdt/core/search/BasicSearchResultCollector.java b/core/org.eclipse.cdt.core/search/org/eclipse/cdt/core/search/BasicSearchResultCollector.java new file mode 100644 index 00000000000..f8a2788d623 --- /dev/null +++ b/core/org.eclipse.cdt.core/search/org/eclipse/cdt/core/search/BasicSearchResultCollector.java @@ -0,0 +1,145 @@ +/******************************************************************************* + * 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 29, 2003 + */ +package org.eclipse.cdt.core.search; + +import java.util.LinkedList; +import java.util.List; + +import org.eclipse.cdt.core.model.ICElement; +import org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate; +import org.eclipse.cdt.core.parser.ast.*; +import org.eclipse.core.resources.IResource; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.IProgressMonitor; + +/** + * @author aniefer + * + * To change the template for this generated type comment go to + * Window>Preferences>Java>Code Generation>Code and Comments + */ +public class BasicSearchResultCollector implements ICSearchResultCollector { + + public void aboutToStart() { + results = new LinkedList(); + } + + public void done() { + } + + public IProgressMonitor getProgressMonitor() { + return null; + } + + public IMatch createMatch(Object fileResource, int start, int end, ISourceElementCallbackDelegate node, IASTScope parent) throws CoreException { + BasicSearchMatch result = new BasicSearchMatch(); + + if( fileResource instanceof IResource ) + result.resource = (IResource) fileResource; + else if( fileResource instanceof IPath ) + result.path = (IPath) fileResource; + + result.startOffset = start; + result.endOffset = end; + + result.parentName = ""; + if( parent instanceof IASTQualifiedNameElement ){ + String [] names = ((IASTQualifiedNameElement)parent).getFullyQualifiedName(); + for( int i = 0; i < names.length; i++ ){ + if( i > 0 ) + result.parentName += "::"; + + result.parentName += names[ i ]; + } + } + + IASTOffsetableNamedElement offsetable = null; + + if( node instanceof IASTReference ){ + offsetable = (IASTOffsetableNamedElement) ((IASTReference)node).getReferencedElement(); + result.name = ((IASTReference)node).getName(); + } else if( node instanceof IASTOffsetableNamedElement ){ + offsetable = (IASTOffsetableNamedElement)node; + result.name = offsetable.getName(); + } + + setElementInfo( result, offsetable ); + + return result; + } + + + public void acceptMatch(IMatch match) throws CoreException { + results.add( match ); + } + + public List getSearchResults(){ + return results; + } + + private void setElementInfo( BasicSearchMatch match, IASTOffsetableElement node ){ + //ImageDescriptor imageDescriptor = null; + if( node instanceof IASTClassSpecifier ){ + ASTClassKind kind = ((IASTClassSpecifier)node).getClassKind(); + if( kind == ASTClassKind.CLASS ){ + match.type = ICElement.C_CLASS; + } else if ( kind == ASTClassKind.STRUCT ){ + match.type = ICElement.C_STRUCT; + } else if ( kind == ASTClassKind.UNION ){ + match.type = ICElement.C_UNION; + } + } else if ( node instanceof IASTNamespaceDefinition ){ + match.type = ICElement.C_NAMESPACE; + } else if ( node instanceof IASTEnumerationSpecifier ){ + match.type = ICElement.C_ENUMERATION; + } else if ( node instanceof IASTField ){ + match.type = ICElement.C_FIELD; + IASTField field = (IASTField)node; + ASTAccessVisibility visibility = field.getVisiblity(); + if( visibility == ASTAccessVisibility.PUBLIC ){ + match.visibility = ICElement.CPP_PUBLIC; + } else if ( visibility == ASTAccessVisibility.PRIVATE ) { + match.visibility = ICElement.CPP_PRIVATE; + } // else protected, there is no ICElement.CPP_PROTECTED + match.isConst = field.getAbstractDeclaration().isConst(); + match.isStatic = field.isStatic(); + } else if ( node instanceof IASTVariable ){ + match.type = ICElement.C_VARIABLE; + IASTVariable variable = (IASTVariable)node; + match.isConst = variable.getAbstractDeclaration().isConst(); + } else if ( node instanceof IASTEnumerator ){ + match.type = ICElement.C_ENUMERATOR; + } else if ( node instanceof IASTMethod ){ + match.type = ICElement.C_METHOD; + IASTMethod method = (IASTMethod) node; + ASTAccessVisibility visibility = method.getVisiblity(); + if( visibility == ASTAccessVisibility.PUBLIC ){ + match.visibility = ICElement.CPP_PUBLIC; + } else if ( visibility == ASTAccessVisibility.PRIVATE ) { + match.visibility = ICElement.CPP_PRIVATE; + } // else protected, there is no ICElement.CPP_PROTECTED + match.isConst = method.isConst(); + match.isVolatile = method.isVolatile(); + match.isStatic = method.isStatic(); + } else if ( node instanceof IASTFunction ){ + match.type = ICElement.C_FUNCTION; + IASTFunction function = (IASTFunction)node; + match.isStatic = function.isStatic(); + } + } + + private List results; + +} 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 0320a9c53bd..7278bfe88ca 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 @@ -15,9 +15,7 @@ package org.eclipse.cdt.core.search; import org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate; 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; import org.eclipse.core.runtime.IProgressMonitor; /** @@ -43,6 +41,12 @@ public interface ICSearchResultCollector { * Called before the actual search starts. */ public void aboutToStart(); + + /** + * Called when the search has ended. + */ + public void done(); + /** * Accepts the given search result. * @@ -58,36 +62,18 @@ public interface ICSearchResultCollector { * EXACT_MATCH or POTENTIAL_MATCH * @exception CoreException if this collector had a problem accepting the search result */ - public void accept( - IResource resource, - int start, - int end, - IMatch enclosingObject, - int accuracy) - throws CoreException; - - /** - * Called when the search has ended. - */ - public void done(); + public IMatch createMatch( Object fileResource, int start, int end, + ISourceElementCallbackDelegate node, IASTScope parent) throws CoreException; + + public void acceptMatch( IMatch match ) throws CoreException; + /** * Returns the progress monitor used to report progress. * * @return a progress monitor or null if no progress monitor is provided */ public IProgressMonitor getProgressMonitor(); - /** - * @param currentPath - * @param start - * @param end - * @param object - * @param accuracyLevel - */ - public void accept(IPath currentPath, - int start, - int end, - IMatch enclosingObject, - int accuracyLevel) throws CoreException; + /** * returns an IMatch object that contains any information the client cared @@ -97,5 +83,5 @@ public interface ICSearchResultCollector { * @param node * @return */ - public IMatch createMatch(ISourceElementCallbackDelegate node, IASTScope parent ); + //public IMatch createMatch(ISourceElementCallbackDelegate node, IASTScope parent ); } diff --git a/core/org.eclipse.cdt.core/search/org/eclipse/cdt/core/search/IMatch.java b/core/org.eclipse.cdt.core/search/org/eclipse/cdt/core/search/IMatch.java index 85e89524113..cd32956d7cb 100644 --- a/core/org.eclipse.cdt.core/search/org/eclipse/cdt/core/search/IMatch.java +++ b/core/org.eclipse.cdt.core/search/org/eclipse/cdt/core/search/IMatch.java @@ -13,6 +13,8 @@ */ package org.eclipse.cdt.core.search; +import org.eclipse.core.resources.IResource; + /** * @author aniefer * @@ -21,4 +23,21 @@ package org.eclipse.cdt.core.search; */ public interface IMatch { + int getElementType(); + + int getVisibility(); + + String getName(); + + String getParentName(); + + IResource getResource(); + + int getStartOffset(); + + int getEndOffset(); + + boolean isStatic(); + boolean isConst(); + boolean isVolatile(); } 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 34728918242..218d9749e03 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 @@ -34,6 +34,7 @@ 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; +import org.eclipse.cdt.core.search.IMatch; import org.eclipse.cdt.internal.core.model.IWorkingCopy; import org.eclipse.cdt.internal.core.parser.ScannerInfo; import org.eclipse.core.resources.IFile; @@ -323,23 +324,17 @@ public class MatchLocator implements ISourceElementRequestor, ICSearchConstants : offsetableElement.getStartingOffset(); length = offsetableElement.getName().length(); } - + + IMatch match = null; if( currentResource != null ){ - - resultCollector.accept( currentResource, - offset, - offset + length, - resultCollector.createMatch( node, currentScope ), - accuracyLevel ); - + match = resultCollector.createMatch( currentResource, offset, offset + length, node, currentScope ); } else if( currentPath != null ){ - - resultCollector.accept( currentPath, - offset, - offset + length, - resultCollector.createMatch( node, currentScope ), - accuracyLevel ); + match = resultCollector.createMatch( currentPath, offset, offset + length, node, currentScope ); } + if( match != null ){ + resultCollector.acceptMatch( match ); + } + } catch (CoreException e) { } } diff --git a/core/org.eclipse.cdt.ui/ChangeLog b/core/org.eclipse.cdt.ui/ChangeLog index 64600fafefc..6f14a60b8d0 100644 --- a/core/org.eclipse.cdt.ui/ChangeLog +++ b/core/org.eclipse.cdt.ui/ChangeLog @@ -1,3 +1,10 @@ +2003-07-29 Andrew Niefer + - Refactoring Search Result Collecting: + * CSearchResultCollector now extends BasicSearchResultCollector + * CSearchResultLabelProvider moved to org.eclipse.cdt.ui + * CSearchResultLabelProvider modified to reflect changes to IMatch interface + * Deleted the class Match + 2003-07-28 Sean Evoy In order to meet certain internal guidelines and to test the makefile generator, the build model replied to some answers with hard-coded information. 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 a1e8b3df842..c90b957f5d1 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 @@ -15,24 +15,17 @@ package org.eclipse.cdt.internal.ui.search; import java.text.MessageFormat; import java.util.HashMap; -import java.util.HashSet; -import java.util.Set; -import org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate; -import org.eclipse.cdt.core.parser.ast.*; -import org.eclipse.cdt.core.search.ICSearchResultCollector; +import org.eclipse.cdt.core.search.BasicSearchMatch; +import org.eclipse.cdt.core.search.BasicSearchResultCollector; import org.eclipse.cdt.core.search.IMatch; -import org.eclipse.cdt.internal.ui.CPluginImages; -import org.eclipse.cdt.ui.CElementImageDescriptor; +import org.eclipse.cdt.ui.*; 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.jface.resource.ImageDescriptor; import org.eclipse.search.ui.ISearchResultView; import org.eclipse.search.ui.SearchUI; -import org.eclipse.swt.graphics.Point; + /** * @author aniefer @@ -40,10 +33,9 @@ import org.eclipse.swt.graphics.Point; * To change the template for this generated type comment go to * Window>Preferences>Java>Code Generation>Code and Comments */ -public class CSearchResultCollector implements ICSearchResultCollector { +public class CSearchResultCollector extends BasicSearchResultCollector{ public static final String IMATCH = "IMatchObject"; - private static final Point SMALL_SIZE= new Point(16, 16); /** * @@ -51,20 +43,20 @@ public class CSearchResultCollector implements ICSearchResultCollector { public CSearchResultCollector() { super(); } - - public CSearchResultCollector( boolean maintain ){ - this(); - _maintainOwnCollection = maintain; - } /* (non-Javadoc) * @see org.eclipse.cdt.core.search.ICSearchResultCollector#aboutToStart() */ public void aboutToStart() { + super.aboutToStart(); + _matchCount = 0; _view = SearchUI.getSearchResultView(); + CSearchResultLabelProvider labelProvider = new CSearchResultLabelProvider(); + labelProvider.setOrder( CSearchResultLabelProvider.SHOW_ELEMENT_CONTAINER ); + if( _view != null ){ _view.searchStarted( null,//new ActionGroupFactory(), @@ -72,7 +64,7 @@ public class CSearchResultCollector implements ICSearchResultCollector { _operation.getPluralLabelPattern(), _operation.getImageDescriptor(), CSearchPage.EXTENSION_POINT_ID, - new CSearchResultLabelProvider(), + labelProvider, new GotoMarkerAction(), new GroupByKeyComputer(), _operation @@ -82,161 +74,36 @@ public class CSearchResultCollector implements ICSearchResultCollector { if( getProgressMonitor() != null && !getProgressMonitor().isCanceled() ){ getProgressMonitor().subTask( SEARCHING ); } - - if( _maintainOwnCollection ){ - _matches = new HashSet(); - } } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.search.ICSearchResultCollector#accept(org.eclipse.core.resources.IResource, int, int, java.lang.Object, int) - */ - public void accept( - IResource resource, - int start, - int end, - IMatch enclosingObject, - int accuracy) - throws CoreException + public void acceptMatch( IMatch match ) throws CoreException { - IMarker marker = resource.createMarker( SearchUI.SEARCH_MARKER ); + super.acceptMatch( match ); - Match match = (Match) enclosingObject; + BasicSearchMatch searchMatch = (BasicSearchMatch) match; + if( searchMatch.resource == null ) + return; + + + IMarker marker = searchMatch.resource.createMarker( SearchUI.SEARCH_MARKER ); 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 ); + markerAttributes.put( IMarker.CHAR_START, new Integer( Math.max( searchMatch.startOffset, 0 ) ) ); + markerAttributes.put( IMarker.CHAR_END, new Integer( Math.max( searchMatch.endOffset, 0 ) ) ); + markerAttributes.put( IMATCH, searchMatch ); marker.setAttributes( markerAttributes ); if( _view != null ) - _view.addMatch( match.name, groupKey, resource, marker ); + _view.addMatch( searchMatch.name, groupKey, searchMatch.resource, marker ); - if( _maintainOwnCollection ){ - _matches.add( enclosingObject ); - } _matchCount++; } - public void accept( - IPath path, - int start, - int end, - IMatch match, - int accuracy) - throws CoreException - { - if( _maintainOwnCollection ) - _matches.add( match ); - } - - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.search.ICSearchResultCollector#createMatch(org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement) - */ - public IMatch createMatch(ISourceElementCallbackDelegate node, IASTScope parent ) { - String name = null; - String parentName = ""; - IASTOffsetableNamedElement offsetable = null; - - if( parent instanceof IASTQualifiedNameElement ){ - String [] names = ((IASTQualifiedNameElement)parent).getFullyQualifiedName(); - for( int i = 0; i < names.length; i++ ){ - if( i > 0 ) - parentName += "::"; - - parentName += names[ i ]; - } - } - - if( node instanceof IASTReference ){ - offsetable = (IASTOffsetableNamedElement) ((IASTReference)node).getReferencedElement(); - name = ((IASTReference)node).getName(); - } else if( node instanceof IASTOffsetableNamedElement ){ - offsetable = (IASTOffsetableNamedElement)node; - name = offsetable.getName(); - } else { - return null; - } - - ImageDescriptor image = getImageDescriptor( offsetable ); - int adornmentFlags = computeAdornmentFlags( offsetable ); - IMatch match = new Match(name, parentName, image );//, node.getNameOffset(), name.length() ); - - return match; - } - - private ImageDescriptor getImageDescriptor( IASTOffsetableElement node ){ - 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; - } else if ( node instanceof IASTField ){ - IASTField field = (IASTField)node; - ASTAccessVisibility visibility = field.getVisiblity(); - if( visibility == ASTAccessVisibility.PUBLIC ){ - imageDescriptor = CPluginImages.DESC_OBJS_PUBLIC_FIELD; - } else if ( visibility == ASTAccessVisibility.PROTECTED) { - imageDescriptor = CPluginImages.DESC_OBJS_PROTECTED_FIELD; - } else if ( visibility == ASTAccessVisibility.PRIVATE ) { - imageDescriptor = CPluginImages.DESC_OBJS_PRIVATE_FIELD; - } - } else if ( node instanceof IASTVariable ){ - imageDescriptor = CPluginImages.DESC_OBJS_FIELD; - } else if ( node instanceof IASTEnumerator ){ - imageDescriptor = CPluginImages.DESC_OBJS_ENUMERATOR; - } else if ( node instanceof IASTMethod ){ - IASTMethod method = (IASTMethod) node; - ASTAccessVisibility visibility = method.getVisiblity(); - if( visibility == ASTAccessVisibility.PUBLIC ){ - imageDescriptor = CPluginImages.DESC_OBJS_PUBLIC_METHOD; - } else if ( visibility == ASTAccessVisibility.PROTECTED) { - imageDescriptor = CPluginImages.DESC_OBJS_PROTECTED_METHOD; - } else if ( visibility == ASTAccessVisibility.PRIVATE ) { - imageDescriptor = CPluginImages.DESC_OBJS_PRIVATE_METHOD; - } - } else if ( node instanceof IASTFunction ){ - imageDescriptor = CPluginImages.DESC_OBJS_FUNCTION; - } - - if( imageDescriptor != null) { - int adornmentFlags = computeAdornmentFlags( node ); - return new CElementImageDescriptor( imageDescriptor, adornmentFlags, SMALL_SIZE ); - } - return imageDescriptor; - } - - private int computeAdornmentFlags(IASTOffsetableElement element ) { - int flags = 0; - - if( element instanceof IASTVariable ){ - flags |= ((IASTVariable) element).isStatic() ? 0 : CElementImageDescriptor.STATIC; - } else if ( element instanceof IASTMethod ){ - flags |= ((IASTMethod) element).isStatic() ? 0 : CElementImageDescriptor.STATIC; - flags |= ((IASTMethod) element).isConst() ? 0 : CElementImageDescriptor.CONSTANT; - flags |= ((IASTMethod) element).isVolatile() ? 0 : CElementImageDescriptor.VOLATILE; - } else if( element instanceof IASTFunction ){ - flags |= ((IASTFunction) element).isStatic() ? 0 : CElementImageDescriptor.STATIC; - } - - return flags; - } - /* (non-Javadoc) * @see org.eclipse.cdt.core.search.ICSearchResultCollector#done() */ @@ -275,10 +142,6 @@ public class CSearchResultCollector implements ICSearchResultCollector { _operation = operation; } - public Set getMatches(){ - return _matches; - } - 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$ @@ -288,6 +151,4 @@ public class CSearchResultCollector implements ICSearchResultCollector { private CSearchOperation _operation; private ISearchResultView _view; private int _matchCount; - private Set _matches; - private boolean _maintainOwnCollection = false; } \ No newline at end of file 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 deleted file mode 100644 index 96290268023..00000000000 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/CSearchResultLabelProvider.java +++ /dev/null @@ -1,133 +0,0 @@ -/******************************************************************************* - * 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.internal.ui.CElementImageProvider; -import org.eclipse.cdt.ui.CElementLabelProvider; -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.jface.resource.ImageDescriptor; -import org.eclipse.jface.viewers.LabelProvider; -import org.eclipse.search.ui.ISearchResultViewEntry; -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 CSearchResultLabelProvider(){ - _sortOrder = SHOW_ELEMENT_CONTAINER; - //_imageProvider = new CElementImageProvider(); - //_labelProvider = new CElementLabelProvider(); - } - - public Image getImage( Object element ) { - 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; - } - - ImageDescriptor imageDescriptor = match.imageDesc; - - Image image = CUIPlugin.getImageDescriptorRegistry().get( imageDescriptor ); - - return image; - } - - public String getText( Object element ) { - 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; - } - - IResource resource = marker.getResource(); - - String result = null; - String path = (resource != null ) ? resource.getFullPath().toString() : ""; - - switch( getOrder() ){ - case SHOW_ELEMENT_CONTAINER: - result = match.name + " - " + match.parent + " ( " + path + " )"; - break; - case SHOW_PATH: - result = path + " - " + match.parent + "::" + match.name; - break; - case SHOW_CONTAINER_ELEMENT: - result = match.parent + "::" + match.name + " ( " + path + " )"; - break; - } - - return result; - } - - public int getOrder(){ - return _sortOrder; - } - public void setOrder(int orderFlag) { - _sortOrder = orderFlag; - } - - protected IMarker getMarker( Object o ){ - if( !( o instanceof ISearchResultViewEntry ) ){ - return null; - } - - return ( (ISearchResultViewEntry)o ).getSelectedMarker(); - } - - - private CElementImageProvider _imageProvider; - private CElementLabelProvider _labelProvider; - - private int _sortOrder; - private int _textFlags; - private int _imageFlags; - -} 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 index de7a8912b4b..c81e37d2992 100644 --- 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 @@ -13,6 +13,7 @@ */ package org.eclipse.cdt.internal.ui.search; +import org.eclipse.cdt.ui.*; import org.eclipse.jface.viewers.ILabelProvider; import org.eclipse.jface.viewers.Viewer; import org.eclipse.jface.viewers.ViewerSorter; 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 index 23a5e0a7613..ab17bcf1a10 100644 --- 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 @@ -13,6 +13,7 @@ */ package org.eclipse.cdt.internal.ui.search; +import org.eclipse.cdt.core.search.IMatch; import org.eclipse.core.resources.IMarker; import org.eclipse.core.runtime.CoreException; import org.eclipse.search.ui.IGroupByKeyComputer; @@ -34,13 +35,13 @@ public class GroupByKeyComputer implements IGroupByKeyComputer { return null; } - Match match = null; + IMatch match = null; try { - match = (Match) marker.getAttribute(CSearchResultCollector.IMATCH); + match = (IMatch) marker.getAttribute(CSearchResultCollector.IMATCH); } catch (CoreException e) { } - return match.parent; + return match.getParentName(); } } diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/Match.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/Match.java deleted file mode 100644 index 4427c5692ec..00000000000 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/Match.java +++ /dev/null @@ -1,45 +0,0 @@ -/******************************************************************************* - * 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.jface.resource.ImageDescriptor; - -/** - * @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 ImageDescriptor imageDesc; - public int start; - public int end; - - public Match( String name, String parent, ImageDescriptor image ){ - this.name = name; - this.parent = parent; - this.imageDesc = image; - } - - public Match( String name, String parent, ImageDescriptor image, int start, int end ){ - this( name, parent, image ); - this.start = start; - this.end = end; - } - -} \ No newline at end of file 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 index 01681683b6f..8c968ae22d4 100644 --- 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 @@ -13,6 +13,7 @@ */ package org.eclipse.cdt.internal.ui.search; +import org.eclipse.cdt.ui.*; import org.eclipse.jface.viewers.ILabelProvider; import org.eclipse.jface.viewers.Viewer; import org.eclipse.jface.viewers.ViewerSorter; 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 index eb9443044a0..3c214917b15 100644 --- 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 @@ -13,6 +13,7 @@ */ package org.eclipse.cdt.internal.ui.search; +import org.eclipse.cdt.ui.*; import org.eclipse.core.resources.IMarker; import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IResource; diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/CSearchResultLabelProvider.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/CSearchResultLabelProvider.java new file mode 100644 index 00000000000..4ebc2e08937 --- /dev/null +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/CSearchResultLabelProvider.java @@ -0,0 +1,165 @@ +/******************************************************************************* + * 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.ui; + +import org.eclipse.cdt.core.model.ICElement; +import org.eclipse.cdt.core.search.IMatch; +import org.eclipse.cdt.internal.ui.CPluginImages; +import org.eclipse.cdt.internal.ui.search.CSearchMessages; +import org.eclipse.cdt.internal.ui.search.CSearchResultCollector; +import org.eclipse.core.resources.IMarker; +import org.eclipse.core.resources.IResource; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.jface.viewers.LabelProvider; +import org.eclipse.search.ui.ISearchResultViewEntry; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.graphics.Point; + +/** + * @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_NAME_ONLY = 0; //default + public static final int SHOW_ELEMENT_CONTAINER = 1; + public static final int SHOW_CONTAINER_ELEMENT = 2; + public static final int SHOW_PATH = 3; + + public static final String POTENTIAL_MATCH = CSearchMessages.getString("CSearchResultLabelProvider.potentialMatch"); //$NON-NLS-1$ + + public CSearchResultLabelProvider(){ + _sortOrder = SHOW_NAME_ONLY; + } + + public Image getImage( Object element ) { + IMatch match = null; + + if( element instanceof ISearchResultViewEntry ){ + ISearchResultViewEntry viewEntry = (ISearchResultViewEntry)element; + IMarker marker = viewEntry.getSelectedMarker(); + try { + match = (IMatch) marker.getAttribute( CSearchResultCollector.IMATCH ); + } catch (CoreException e) { + return null; + } + } else if ( element instanceof IMatch ){ + match = (IMatch) element; + } + + if( match == null ) + return null; + + ImageDescriptor imageDescriptor = null; + + switch( match.getElementType() ){ + case ICElement.C_CLASS: imageDescriptor = CPluginImages.DESC_OBJS_CLASS; break; + case ICElement.C_STRUCT: imageDescriptor = CPluginImages.DESC_OBJS_STRUCT; break; + case ICElement.C_UNION: imageDescriptor = CPluginImages.DESC_OBJS_UNION; break; + case ICElement.C_NAMESPACE: imageDescriptor = CPluginImages.DESC_OBJS_CONTAINER; break; + case ICElement.C_ENUMERATION: imageDescriptor = CPluginImages.DESC_OBJS_ENUMERATION; break; + case ICElement.C_FUNCTION: imageDescriptor = CPluginImages.DESC_OBJS_FUNCTION; break; + case ICElement.C_VARIABLE: imageDescriptor = CPluginImages.DESC_OBJS_FIELD; break; + case ICElement.C_ENUMERATOR: imageDescriptor = CPluginImages.DESC_OBJS_ENUMERATOR; break; + case ICElement.C_FIELD: + { + switch( match.getVisibility() ){ + case ICElement.CPP_PUBLIC: imageDescriptor = CPluginImages.DESC_OBJS_PUBLIC_FIELD; break; + case ICElement.CPP_PRIVATE: imageDescriptor = CPluginImages.DESC_OBJS_PRIVATE_FIELD; break; + default: imageDescriptor = CPluginImages.DESC_OBJS_PROTECTED_FIELD; break; + } + break; + } + case ICElement.C_METHOD: + { + switch( match.getVisibility() ){ + case ICElement.CPP_PUBLIC: imageDescriptor = CPluginImages.DESC_OBJS_PUBLIC_METHOD; break; + case ICElement.CPP_PRIVATE: imageDescriptor = CPluginImages.DESC_OBJS_PRIVATE_METHOD; break; + default: imageDescriptor = CPluginImages.DESC_OBJS_PROTECTED_METHOD; break; + } + break; + } + } + + int flags = 0; + if( match.isStatic() ) flags |= CElementImageDescriptor.STATIC; + if( match.isConst() ) flags |= CElementImageDescriptor.CONSTANT; + if( match.isVolatile() ) flags |= CElementImageDescriptor.VOLATILE; + + imageDescriptor = new CElementImageDescriptor( imageDescriptor, flags, SMALL_SIZE ); + + Image image = CUIPlugin.getImageDescriptorRegistry().get( imageDescriptor ); + + return image; + } + + public String getText( Object element ) { + IMatch match = null; + + if( element instanceof ISearchResultViewEntry ){ + ISearchResultViewEntry viewEntry = (ISearchResultViewEntry) element; + + IMarker marker = viewEntry.getSelectedMarker(); + + try { + match = (IMatch) marker.getAttribute(CSearchResultCollector.IMATCH); + } catch (CoreException e) { + return null; + } + } else if( element instanceof IMatch ){ + match = (IMatch) element; + } + + if( match == null ) + return null; + + IResource resource = match.getResource(); + + String result = null; + String path = (resource != null ) ? resource.getFullPath().toString() : ""; + + switch( getOrder() ){ + case SHOW_NAME_ONLY: + result = match.getName(); + case SHOW_ELEMENT_CONTAINER: + result = match.getName() + " - " + match.getParentName() + " ( " + path + " )"; + break; + case SHOW_PATH: + result = path + " - " + match.getParentName()+ "::" + match.getName(); + break; + case SHOW_CONTAINER_ELEMENT: + result = match.getParentName() + "::" + match.getName() + " ( " + path + " )"; + break; + } + + return result; + } + + public int getOrder(){ + return _sortOrder; + } + public void setOrder(int orderFlag) { + _sortOrder = orderFlag; + } + + private int _sortOrder; + private int _textFlags; + private int _imageFlags; + + private static final Point SMALL_SIZE= new Point(16, 16); + +} \ No newline at end of file