diff --git a/core/org.eclipse.cdt.ui/ChangeLog b/core/org.eclipse.cdt.ui/ChangeLog index 543eff60f62..576164e7541 100644 --- a/core/org.eclipse.cdt.ui/ChangeLog +++ b/core/org.eclipse.cdt.ui/ChangeLog @@ -1,3 +1,13 @@ +2004-05-10 Andrew Niefer + - fixing bug 60493: + - created CSearchUtil.getSearchForFromElement and CSearchUtil.getSearchForFromNode + - modified FindAction to use working copies if editor is dirty + - modified FindAction to use CElement information if available instead of parsing. + + * src/org/eclipse/cdt/internal/ui/search/CSearchPage.java + * src/org/eclipse/cdt/internal/ui/search/CSearchUtil.jav + * src/org/eclipse/cdt/internal/ui/search/actions/FindAction.java + 2004-05-07 Andrew Niefer - handle content assist for function references so that the function is not inserted if we are just getting signature info for the popup 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 e08a4e83518..b61f9bf2c1f 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 @@ -518,40 +518,9 @@ public class CSearchPage extends DialogPage implements ISearchPage, ICSearchCons return null; List searchFor = new LinkedList(); + searchFor.add( CSearchUtil.getSearchForFromElement( element ) ); - //outliune view will confuse methods with functions, so if the - //name contains a "::", treat it as a method String pattern = element.getElementName(); - boolean forceMethod = ( pattern.indexOf("::") != -1 ); //$NON-NLS-1$ - - switch ( element.getElementType() ){ - case ICElement.C_TEMPLATE_FUNCTION: /*fall through to function */ - case ICElement.C_FUNCTION_DECLARATION: /*fall through to function */ - case ICElement.C_FUNCTION: if( forceMethod ) searchFor.add( METHOD ); - else searchFor.add( FUNCTION ); - break; - - case ICElement.C_VARIABLE: searchFor.add( VAR ); break; - - case ICElement.C_TEMPLATE_CLASS:/* fall through to CLASS */ - case ICElement.C_STRUCT: /* fall through to CLASS */ - case ICElement.C_CLASS: searchFor.add( CLASS_STRUCT ); break; - - case ICElement.C_UNION: searchFor.add( UNION ); break; - - case ICElement.C_ENUMERATOR: /* fall through to FIELD */ - case ICElement.C_FIELD: searchFor.add( FIELD ); break; - - case ICElement.C_TEMPLATE_METHOD : /*fall through to METHOD */ - case ICElement.C_METHOD_DECLARATION : /*fall through to METHOD */ - case ICElement.C_METHOD: searchFor.add( METHOD ); break; - - case ICElement.C_NAMESPACE: searchFor.add( NAMESPACE ); break; - - case ICElement.C_ENUMERATION: searchFor.add( ENUM ); break; - - default: searchFor.add( UNKNOWN_SEARCH_FOR ); break; - } LimitTo limitTo = ALL_OCCURRENCES; diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/CSearchUtil.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/CSearchUtil.java index 4d866b61527..d0f36d70fcf 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/CSearchUtil.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/CSearchUtil.java @@ -14,6 +14,19 @@ package org.eclipse.cdt.internal.ui.search; import org.eclipse.cdt.core.model.ICElement; +import org.eclipse.cdt.core.parser.ast.ASTClassKind; +import org.eclipse.cdt.core.parser.ast.IASTClassSpecifier; +import org.eclipse.cdt.core.parser.ast.IASTEnumerationSpecifier; +import org.eclipse.cdt.core.parser.ast.IASTEnumerator; +import org.eclipse.cdt.core.parser.ast.IASTField; +import org.eclipse.cdt.core.parser.ast.IASTFunction; +import org.eclipse.cdt.core.parser.ast.IASTMethod; +import org.eclipse.cdt.core.parser.ast.IASTNamespaceDefinition; +import org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement; +import org.eclipse.cdt.core.parser.ast.IASTTypedefDeclaration; +import org.eclipse.cdt.core.parser.ast.IASTVariable; +import org.eclipse.cdt.core.search.ICSearchConstants; +import org.eclipse.cdt.core.search.ICSearchConstants.SearchFor; import org.eclipse.core.resources.IMarker; import org.eclipse.swt.widgets.Shell; import org.eclipse.ui.IWorkingSet; @@ -79,4 +92,86 @@ public class CSearchUtil { return null; } + static public SearchFor getSearchForFromElement( ICElement element ) { + if( element == null ) + return null; + + SearchFor searchFor = null; + //outline view will confuse methods with functions, so if the + //name contains a "::", treat it as a method + String pattern = element.getElementName(); + boolean forceMethod = ( pattern.indexOf("::") != -1 ); //$NON-NLS-1$ + + switch ( element.getElementType() ){ + case ICElement.C_TEMPLATE_FUNCTION: /*fall through to function */ + case ICElement.C_FUNCTION_DECLARATION: /*fall through to function */ + case ICElement.C_FUNCTION: if( forceMethod ) searchFor = ICSearchConstants.METHOD; + else searchFor = ICSearchConstants.FUNCTION; + break; + + case ICElement.C_VARIABLE: searchFor = ICSearchConstants.VAR; break; + + case ICElement.C_TEMPLATE_CLASS:/* fall through to CLASS */ + case ICElement.C_STRUCT: /* fall through to CLASS */ + case ICElement.C_CLASS: searchFor = ICSearchConstants.CLASS_STRUCT; break; + + case ICElement.C_UNION: searchFor = ICSearchConstants.UNION; break; + + case ICElement.C_ENUMERATOR: /* fall through to FIELD */ + case ICElement.C_FIELD: searchFor = ICSearchConstants.FIELD; break; + + case ICElement.C_TEMPLATE_METHOD : /*fall through to METHOD */ + case ICElement.C_METHOD_DECLARATION : /*fall through to METHOD */ + case ICElement.C_METHOD: searchFor = ICSearchConstants.METHOD; break; + + case ICElement.C_NAMESPACE: searchFor = ICSearchConstants.NAMESPACE; break; + + case ICElement.C_ENUMERATION: searchFor = ICSearchConstants.ENUM; break; + + default: searchFor = ICSearchConstants.UNKNOWN_SEARCH_FOR; break; + } + return searchFor; + } + + static public SearchFor getSearchForFromNode(IASTOffsetableNamedElement node){ + SearchFor searchFor = null; + + if (node instanceof IASTClassSpecifier){ + //Find out if class, struct, union + IASTClassSpecifier tempNode = (IASTClassSpecifier) node; + if(tempNode.getClassKind().equals(ASTClassKind.CLASS)){ + searchFor = ICSearchConstants.CLASS; + } + else if (tempNode.getClassKind().equals(ASTClassKind.STRUCT)){ + searchFor = ICSearchConstants.STRUCT; + } + else if (tempNode.getClassKind().equals(ASTClassKind.UNION)){ + searchFor = ICSearchConstants.UNION; + } + } + else if (node instanceof IASTMethod){ + searchFor = ICSearchConstants.METHOD; + } + else if (node instanceof IASTFunction){ + searchFor = ICSearchConstants.FUNCTION; + } + else if (node instanceof IASTField){ + searchFor = ICSearchConstants.FIELD; + } + else if (node instanceof IASTVariable){ + searchFor = ICSearchConstants.VAR; + } + else if (node instanceof IASTEnumerationSpecifier){ + searchFor = ICSearchConstants.ENUM; + } + else if (node instanceof IASTNamespaceDefinition){ + searchFor = ICSearchConstants.NAMESPACE; + } + else if( node instanceof IASTTypedefDeclaration) + searchFor = ICSearchConstants.TYPEDEF; + else if( node instanceof IASTEnumerator ) + searchFor = ICSearchConstants.ENUMTOR; + + return searchFor; + } } diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/actions/FindAction.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/actions/FindAction.java index 3206fa223fe..464737ffd2e 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/actions/FindAction.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/actions/FindAction.java @@ -11,14 +11,18 @@ package org.eclipse.cdt.internal.ui.search.actions; +import java.io.CharArrayReader; import java.io.FileNotFoundException; import java.io.FileReader; +import java.io.Reader; import java.util.LinkedList; import java.util.List; import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.ICLogConstants; import org.eclipse.cdt.core.model.CoreModel; +import org.eclipse.cdt.core.model.ICElement; +import org.eclipse.cdt.core.model.IWorkingCopy; import org.eclipse.cdt.core.parser.IParser; import org.eclipse.cdt.core.parser.IScannerInfo; import org.eclipse.cdt.core.parser.IScannerInfoProvider; @@ -30,19 +34,8 @@ import org.eclipse.cdt.core.parser.ParserLanguage; import org.eclipse.cdt.core.parser.ParserMode; import org.eclipse.cdt.core.parser.ParserUtil; import org.eclipse.cdt.core.parser.ScannerInfo; -import org.eclipse.cdt.core.parser.ast.ASTClassKind; -import org.eclipse.cdt.core.parser.ast.IASTClassSpecifier; -import org.eclipse.cdt.core.parser.ast.IASTEnumerationSpecifier; -import org.eclipse.cdt.core.parser.ast.IASTEnumerator; -import org.eclipse.cdt.core.parser.ast.IASTField; -import org.eclipse.cdt.core.parser.ast.IASTFunction; -import org.eclipse.cdt.core.parser.ast.IASTMethod; -import org.eclipse.cdt.core.parser.ast.IASTNamespaceDefinition; import org.eclipse.cdt.core.parser.ast.IASTNode; import org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement; -import org.eclipse.cdt.core.parser.ast.IASTTypedefDeclaration; -import org.eclipse.cdt.core.parser.ast.IASTVariable; -import org.eclipse.cdt.core.search.ICSearchConstants; import org.eclipse.cdt.core.search.ICSearchScope; import org.eclipse.cdt.core.search.ICSearchConstants.LimitTo; import org.eclipse.cdt.core.search.ICSearchConstants.SearchFor; @@ -50,6 +43,8 @@ import org.eclipse.cdt.internal.ui.editor.CEditor; import org.eclipse.cdt.internal.ui.search.CSearchMessages; import org.eclipse.cdt.internal.ui.search.CSearchQuery; import org.eclipse.cdt.internal.ui.search.CSearchResultCollector; +import org.eclipse.cdt.internal.ui.search.CSearchUtil; +import org.eclipse.cdt.ui.CUIPlugin; import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IProject; import org.eclipse.jface.action.Action; @@ -58,7 +53,6 @@ import org.eclipse.jface.text.ITextSelection; import org.eclipse.jface.viewers.ISelection; import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.search.ui.NewSearchUI; -import org.eclipse.ui.IEditorPart; import org.eclipse.ui.IWorkbenchSite; @@ -91,10 +85,26 @@ public abstract class FindAction extends Action { //C or CPP? ParserLanguage language = CoreModel.hasCCNature(currentProject) ? ParserLanguage.CPP : ParserLanguage.C; + IWorkingCopy workingCopy = null; + if( fEditor.isDirty() ){ + IWorkingCopy [] workingCopies = CUIPlugin.getSharedWorkingCopies(); + if( workingCopies != null ){ + for( int i = 0; i < workingCopies.length; i++ ){ + if( workingCopies[i].getUnderlyingResource().equals( resourceFile ) ){ + workingCopy = workingCopies[i]; + break; + } + } + } + } + IParser parser = null; - FileReader reader = null; + Reader reader = null; try { - reader = new FileReader(resourceFile.getLocation().toFile()); + if( workingCopy == null ) + reader = new FileReader(resourceFile.getLocation().toFile()); + else + reader = new CharArrayReader( workingCopy.getContents() ); } catch (FileNotFoundException e) { e.printStackTrace(); } @@ -150,22 +160,17 @@ public abstract class FindAction extends Action { } public void run(IStructuredSelection sel){ - IEditorPart temp = fSite.getPage().getActiveEditor(); - CEditor cTemp = null; - if (temp instanceof CEditor){ - cTemp = (CEditor) temp; - } + Object obj = sel.getFirstElement(); + if( obj == null || !(obj instanceof ICElement ) ){ + operationNotAvailableDialog(); + return; + } + ICElement element = (ICElement) obj; - if (cTemp == null || - cTemp.getSelectionProvider() == null){ - operationNotAvailableDialog(); - return; - } + CSearchQuery job = createSearchQuery( element.getElementName(), CSearchUtil.getSearchForFromElement(element)); + NewSearchUI.activateSearchResultView(); - fEditor=cTemp; - ITextSelection selection= (ITextSelection) fEditor.getSelectionProvider().getSelection(); - - run(selection); + NewSearchUI.runQuery(job); } public void run(ITextSelection sel){ @@ -200,54 +205,12 @@ public abstract class FindAction extends Action { return; } - CSearchQuery job = createSearchQuery(selectedText.getText(),getSearchForFromNode(node)); + CSearchQuery job = createSearchQuery(selectedText.getText(), CSearchUtil.getSearchForFromNode(node)); NewSearchUI.activateSearchResultView(); NewSearchUI.runQuery(job); } - private SearchFor getSearchForFromNode(IASTOffsetableNamedElement node){ - SearchFor searchFor = null; - - if (node instanceof IASTClassSpecifier){ - //Find out if class, struct, union - IASTClassSpecifier tempNode = (IASTClassSpecifier) node; - if(tempNode.getClassKind().equals(ASTClassKind.CLASS)){ - searchFor = ICSearchConstants.CLASS; - } - else if (tempNode.getClassKind().equals(ASTClassKind.STRUCT)){ - searchFor = ICSearchConstants.STRUCT; - } - else if (tempNode.getClassKind().equals(ASTClassKind.UNION)){ - searchFor = ICSearchConstants.UNION; - } - } - else if (node instanceof IASTMethod){ - searchFor = ICSearchConstants.METHOD; - } - else if (node instanceof IASTFunction){ - searchFor = ICSearchConstants.FUNCTION; - } - else if (node instanceof IASTField){ - searchFor = ICSearchConstants.FIELD; - } - else if (node instanceof IASTVariable){ - searchFor = ICSearchConstants.VAR; - } - else if (node instanceof IASTEnumerationSpecifier){ - searchFor = ICSearchConstants.ENUM; - } - else if (node instanceof IASTNamespaceDefinition){ - searchFor = ICSearchConstants.NAMESPACE; - } - else if( node instanceof IASTTypedefDeclaration) - searchFor = ICSearchConstants.TYPEDEF; - else if( node instanceof IASTEnumerator ) - searchFor = ICSearchConstants.ENUMTOR; - - return searchFor; - } - private void operationNotAvailableDialog(){ MessageDialog.openInformation(fEditor.getSite().getShell(),CSearchMessages.getString("CSearchOperation.operationUnavailable.title"), CSearchMessages.getString("CSearchOperation.operationUnavailable.message")); //$NON-NLS-1$ //$NON-NLS-2$ }