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 4ecd5529c64..a5956e7bcb3 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 @@ -90,7 +90,6 @@ CSearchResultLabelProvider.potentialMatch= \ (inexact) CSearchOperation.operationUnavailable.title= Operation Unavailable CSearchOperation.operationUnavailable.message= The operation is unavailable on the current selection. -CSearchOperation.tooManyNames.message= The operation is unavailable on the current selection (too many different names selected). CSearchOperation.noNamesSelected.message= The operation is unavailable on the current selection (no name selected). CSearchOperation.noDefinitionFound.message= No definition was found. CSearchOperation.noDeclarationFound.message= No declaration was found. diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/DOMQuery.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/DOMQuery.java index fa6d4b96355..5f9b0de81ba 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/DOMQuery.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/DOMQuery.java @@ -71,12 +71,14 @@ public class DOMQuery extends CSearchQuery implements ISearchQuery { private IASTName searchName=null; private LimitTo limitTo=null; private ICSearchScope scope=null; - - public DOMQuery(String displaySearchPattern, IASTName name, LimitTo limitTo, ICSearchScope scope) { + private String searchPattern=null; + + public DOMQuery(String displaySearchPattern, IASTName name, LimitTo limitTo, ICSearchScope scope, String searchPattern) { super(CUIPlugin.getWorkspace(), displaySearchPattern, false, null, null, null, displaySearchPattern); this.searchName = name; this.limitTo = limitTo; this.scope = scope; + this.searchPattern = searchPattern; } /* (non-Javadoc) @@ -91,6 +93,7 @@ public class DOMQuery extends CSearchQuery implements ISearchQuery { // fix for 43128 Set matches=null; + IASTName[] foundNames=null; if (!isLocal()) matches = DOMSearchUtil.getMatchesFromSearchEngine(scope, searchName, limitTo); @@ -107,7 +110,7 @@ public class DOMQuery extends CSearchQuery implements ISearchQuery { } } } else { // only search against the DOM if the index failed to get results... i.e. don't want duplicates - IASTName[] foundNames = DOMSearchUtil.getNamesFromDOM(searchName, limitTo); + foundNames = DOMSearchUtil.getNamesFromDOM(searchName, limitTo); for (int i=0; i 1) { // too many names selected - operationNotAvailable(CSEARCH_OPERATION_TOO_MANY_NAMES_MESSAGE); - return; } foundName = (IASTName)names.get(0); diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/actions/OpenDeclarationsAction.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/actions/OpenDeclarationsAction.java index ee7c51c9479..be0d249c76e 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/actions/OpenDeclarationsAction.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/actions/OpenDeclarationsAction.java @@ -72,7 +72,7 @@ public class OpenDeclarationsAction extends SelectionParseAction implements IUpd } final Storage storage = new Storage(); - + IRunnableWithProgress runnable = new IRunnableWithProgress() { // steps: @@ -82,152 +82,136 @@ public class OpenDeclarationsAction extends SelectionParseAction implements IUpd public void run(IProgressMonitor monitor) { int selectionStart = selNode.selStart; int selectionLength = selNode.selEnd - selNode.selStart; - - IASTName[] selectedNames = BLANK_NAME_ARRAY; - IASTTranslationUnit tu=null; - ParserLanguage lang=null; - ICElement project=null; - - if (fEditor.getEditorInput() instanceof ExternalEditorInput) { - ExternalEditorInput input = (ExternalEditorInput)fEditor.getEditorInput(); - try { - // get the project for the external editor input's translation unit - project = input.getTranslationUnit(); - while (!(project instanceof ICProject) && project != null) { - project = project.getParent(); - } - - if (project instanceof ICProject) { - tu = CDOM.getInstance().getASTService().getTranslationUnit(input.getStorage(), ((ICProject)project).getProject()); - lang = DOMSearchUtil.getLanguage(input.getStorage().getFullPath(), ((ICProject)project).getProject()); - projectName = ((ICProject)project).getElementName(); - } - } catch (UnsupportedDialectException e) { - operationNotAvailable(CSEARCH_OPERATION_OPERATION_UNAVAILABLE_MESSAGE); - return; - } - } else { - IFile resourceFile = null; - resourceFile = fEditor.getInputFile(); - project = new CProject(null, resourceFile.getProject()); - - try { - tu = CDOM.getInstance().getASTService().getTranslationUnit( - resourceFile, - CDOM.getInstance().getCodeReaderFactory( - CDOM.PARSE_WORKING_COPY_WHENEVER_POSSIBLE)); - } catch (IASTServiceProvider.UnsupportedDialectException e) { - operationNotAvailable(CSEARCH_OPERATION_OPERATION_UNAVAILABLE_MESSAGE); - return; - } - lang = DOMSearchUtil.getLanguageFromFile(resourceFile); - projectName = resourceFile.getProject().getName(); - } - - // step 1 starts here - selectedNames = DOMSearchUtil.getSelectedNamesFrom(tu, selectionStart, selectionLength, lang); - - if (selectedNames.length > 0 && selectedNames[0] != null) { // just right, only one name selected - IASTName searchName = selectedNames[0]; - // step 2 starts here - IASTName[] domNames = DOMSearchUtil.getNamesFromDOM(searchName, ICSearchConstants.DECLARATIONS_DEFINITIONS); - - // make sure the names are clean (fix for 95202) - boolean modified=false; - for(int i=0; i 0 && domNames[0] != null) { - String fileName=null; - int start=0; - int end=0; - - if ( domNames[0].getTranslationUnit() != null ) { - IASTFileLocation location = domNames[0].getFileLocation(); - if( location != null ) - { - fileName = location.getFileName(); - start = location.getNodeOffset(); - end = location.getNodeOffset() + location.getNodeLength(); - } - } - - if (fileName != null) { - storage.setFileName(fileName); - storage.setLocatable(new OffsetLocatable(start,end)); - storage.setResource(ParserUtil.getResourceForFilename( fileName )); - } else { - operationNotAvailable(CSEARCH_OPERATION_NO_DECLARATION_MESSAGE); - } - } else { - // step 3 starts here - ICElement[] scope = new ICElement[1]; - scope[0] = project; - Set matches = DOMSearchUtil.getMatchesFromSearchEngine(SearchEngine.createCSearchScope(scope), searchName, ICSearchConstants.DECLARATIONS_DEFINITIONS); - - if (matches != null && matches.size() > 0) { - Iterator itr = matches.iterator(); - while(itr.hasNext()) { - Object match = itr.next(); - if (match instanceof IMatch) { - IMatch theMatch = (IMatch)match; - storage.setFileName(theMatch.getLocation().toOSString()); - storage.setLocatable(theMatch.getLocatable()); - storage.setResource(ParserUtil.getResourceForFilename(theMatch.getLocation().toOSString())); - break; - } - } - } else { - operationNotAvailable(CSEARCH_OPERATION_NO_DECLARATION_MESSAGE); - } + + IASTName[] selectedNames = BLANK_NAME_ARRAY; + IASTTranslationUnit tu=null; + ParserLanguage lang=null; + ICElement project=null; + + if (fEditor.getEditorInput() instanceof ExternalEditorInput) { + ExternalEditorInput input = (ExternalEditorInput)fEditor.getEditorInput(); + try { + // get the project for the external editor input's translation unit + project = input.getTranslationUnit(); + while (!(project instanceof ICProject) && project != null) { + project = project.getParent(); + } + + if (project instanceof ICProject) { + tu = CDOM.getInstance().getASTService().getTranslationUnit(input.getStorage(), ((ICProject)project).getProject()); + lang = DOMSearchUtil.getLanguage(input.getStorage().getFullPath(), ((ICProject)project).getProject()); + projectName = ((ICProject)project).getElementName(); + } + } catch (UnsupportedDialectException e) { + operationNotAvailable(CSEARCH_OPERATION_OPERATION_UNAVAILABLE_MESSAGE); + return; } - } else if (selectedNames.length == 0){ - // last try: search the index for the selected string, even if no name was found for that selection - ICElement[] scope = new ICElement[1]; - scope[0] = project; - Set matches = DOMSearchUtil.getMatchesFromSearchEngine( SearchEngine.createCSearchScope(scope), selNode.selText, ICSearchConstants.DECLARATIONS_DEFINITIONS ); - - if (matches != null && matches.size() > 0) { - Iterator itr = matches.iterator(); - while(itr.hasNext()) { - Object match = itr.next(); - if (match instanceof IMatch) { - IMatch theMatch = (IMatch)match; - storage.setFileName(theMatch.getLocation().toOSString()); - storage.setLocatable(theMatch.getLocatable()); - storage.setResource(ParserUtil.getResourceForFilename(theMatch.getLocation().toOSString())); - break; - } - } - } else { - operationNotAvailable(CSEARCH_OPERATION_NO_DECLARATION_MESSAGE); - return; - } } else { - operationNotAvailable(CSEARCH_OPERATION_TOO_MANY_NAMES_MESSAGE); - return; + IFile resourceFile = null; + resourceFile = fEditor.getInputFile(); + project = new CProject(null, resourceFile.getProject()); + + try { + tu = CDOM.getInstance().getASTService().getTranslationUnit( + resourceFile, + CDOM.getInstance().getCodeReaderFactory( + CDOM.PARSE_WORKING_COPY_WHENEVER_POSSIBLE)); + } catch (IASTServiceProvider.UnsupportedDialectException e) { + operationNotAvailable(CSEARCH_OPERATION_OPERATION_UNAVAILABLE_MESSAGE); + return; + } + lang = DOMSearchUtil.getLanguageFromFile(resourceFile); + projectName = resourceFile.getProject().getName(); } - return; + // step 1 starts here + selectedNames = DOMSearchUtil.getSelectedNamesFrom(tu, selectionStart, selectionLength, lang); + + try { + if (selectedNames.length > 0 && selectedNames[0] != null) { // just right, only one name selected + IASTName searchName = selectedNames[0]; + // step 2 starts here + IASTName[] domNames = DOMSearchUtil.getNamesFromDOM(searchName, ICSearchConstants.DECLARATIONS_DEFINITIONS); + + // make sure the names are clean (fix for 95202) + boolean modified=false; + for(int i=0; i 0 && domNames[0] != null) { + String fileName=null; + int start=0; + int end=0; + + if ( domNames[0].getTranslationUnit() != null ) { + IASTFileLocation location = domNames[0].getFileLocation(); + if( location != null ) + { + fileName = location.getFileName(); + start = location.getNodeOffset(); + end = location.getNodeOffset() + location.getNodeLength(); + } + } + + if (fileName != null) { + storage.setFileName(fileName); + storage.setLocatable(new OffsetLocatable(start,end)); + storage.setResource(ParserUtil.getResourceForFilename( fileName )); + return; + } + } else { + // step 3 starts here + ICElement[] scope = new ICElement[1]; + scope[0] = project; + Set matches = DOMSearchUtil.getMatchesFromSearchEngine(SearchEngine.createCSearchScope(scope), searchName, ICSearchConstants.DECLARATIONS_DEFINITIONS); + + if (matches != null && matches.size() > 0) { + Iterator itr = matches.iterator(); + while(itr.hasNext()) { + Object match = itr.next(); + if (match instanceof IMatch) { + IMatch theMatch = (IMatch)match; + storage.setFileName(theMatch.getLocation().toOSString()); + storage.setLocatable(theMatch.getLocatable()); + storage.setResource(ParserUtil.getResourceForFilename(theMatch.getLocation().toOSString())); + break; + } + } + return; + } + } + } + } catch(Exception e) {} // catch all exceptions from DOM so the indexer can still be tried + + // last try: search the index for the selected string, even if no name was found for that selection + ICElement[] scope = new ICElement[1]; + scope[0] = project; + Set matches = DOMSearchUtil.getMatchesFromSearchEngine( SearchEngine.createCSearchScope(scope), selNode.selText, ICSearchConstants.DECLARATIONS_DEFINITIONS ); + + if (matches != null && matches.size() > 0) { + Iterator itr = matches.iterator(); + while(itr.hasNext()) { + Object match = itr.next(); + if (match instanceof IMatch) { + IMatch theMatch = (IMatch)match; + storage.setFileName(theMatch.getLocation().toOSString()); + storage.setLocatable(theMatch.getLocatable()); + storage.setResource(ParserUtil.getResourceForFilename(theMatch.getLocation().toOSString())); + break; + } + } + } else { + operationNotAvailable(CSEARCH_OPERATION_NO_DECLARATION_MESSAGE); + return; + } } - -// private String findProjectName(IFile resourceFile) { -// if( resourceFile == null ) return ""; //$NON-NLS-1$ -// IProject[] projects = ResourcesPlugin.getWorkspace().getRoot().getProjects(); -// for( int i = 0; i < projects.length; ++i ) -// { -// if( projects[i].contains(resourceFile) ) -// return projects[i].getName(); -// } -// return ""; //$NON-NLS-1$ -// } - }; + }; try { ProgressMonitorDialog progressMonitor = new ProgressMonitorDialog(getShell()); diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/actions/OpenDefinitionAction.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/actions/OpenDefinitionAction.java index c2510eb45a2..46272eb1e51 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/actions/OpenDefinitionAction.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/actions/OpenDefinitionAction.java @@ -35,8 +35,6 @@ import org.eclipse.cdt.internal.ui.editor.CEditorMessages; import org.eclipse.cdt.internal.ui.util.ExternalEditorInput; import org.eclipse.cdt.ui.CUIPlugin; import org.eclipse.core.resources.IFile; -import org.eclipse.core.resources.IProject; -import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.jface.dialogs.ProgressMonitorDialog; import org.eclipse.jface.operation.IRunnableWithProgress; @@ -79,166 +77,153 @@ public class OpenDefinitionAction extends SelectionParseAction implements * @see org.eclipse.jface.action.IAction#run() */ public void run() { - final SelSearchNode selNode = getSelectedStringFromEditor(); - - if(selNode == null) { - return; - } - - final Storage storage = new Storage(); - - IRunnableWithProgress runnable = new IRunnableWithProgress() - { - // steps: - // 1- parse and get the best selected name based on the offset/length into that TU - // 2- based on the IASTName selected, find the best definition of it in the TU - // 3- if no IASTName is found for a definition, then search the Index - public void run(IProgressMonitor monitor) { - int selectionStart = selNode.selStart; - int selectionLength = selNode.selEnd - selNode.selStart; - - IASTName[] selectedNames = BLANK_NAME_ARRAY; - IASTTranslationUnit tu=null; - ParserLanguage lang=null; - ICElement project=null; - - if (fEditor.getEditorInput() instanceof ExternalEditorInput) { - ExternalEditorInput input = (ExternalEditorInput)fEditor.getEditorInput(); - try { - // get the project for the external editor input's translation unit - project = input.getTranslationUnit(); - while (!(project instanceof ICProject) && project != null) { - project = project.getParent(); - } - - if (project instanceof ICProject) { - tu = CDOM.getInstance().getASTService().getTranslationUnit(input.getStorage(), ((ICProject)project).getProject()); - lang = DOMSearchUtil.getLanguage(input.getStorage().getFullPath(), ((ICProject)project).getProject()); - projectName = ((ICProject)project).getElementName(); - } - } catch (UnsupportedDialectException e) { - operationNotAvailable(CSEARCH_OPERATION_OPERATION_UNAVAILABLE_MESSAGE); - return; - } - } else { - IFile resourceFile = null; - resourceFile = fEditor.getInputFile(); - project = new CProject(null, resourceFile.getProject()); - - try { - tu = CDOM.getInstance().getASTService().getTranslationUnit( - resourceFile, - CDOM.getInstance().getCodeReaderFactory( - CDOM.PARSE_WORKING_COPY_WHENEVER_POSSIBLE)); - } catch (IASTServiceProvider.UnsupportedDialectException e) { - operationNotAvailable(CSEARCH_OPERATION_OPERATION_UNAVAILABLE_MESSAGE); - return; - } - lang = DOMSearchUtil.getLanguageFromFile(resourceFile); - projectName = findProjectName(resourceFile); - } - - // step 1 starts here - selectedNames = DOMSearchUtil.getSelectedNamesFrom(tu, selectionStart, selectionLength, lang); - - if (selectedNames.length > 0 && selectedNames[0] != null) { // just right, only one name selected - IASTName searchName = selectedNames[0]; - // step 2 starts here - IASTName[] domNames = DOMSearchUtil.getNamesFromDOM(searchName, ICSearchConstants.DEFINITIONS); - - // make sure the names are clean (fix for 95202) - boolean modified=false; - for(int i=0; i 0 && domNames[0] != null) { - String fileName=null; - int start=0; - int end=0; - - if ( domNames[0].getTranslationUnit() != null ) { - IASTFileLocation location = domNames[0].getFileLocation(); - fileName = location.getFileName(); - start = location.getNodeOffset(); - end = location.getNodeOffset() + location.getNodeLength(); - } - - if (fileName != null) { - storage.setFileName(fileName); - storage.setLocatable(new OffsetLocatable(start,end)); - storage.setResource(ParserUtil.getResourceForFilename( fileName )); - } else { - operationNotAvailable(CSEARCH_OPERATION_NO_DEFINITION_MESSAGE); - } - } else { - // step 3 starts here - ICElement[] scope = new ICElement[1]; - scope[0] = project; - Set matches = DOMSearchUtil.getMatchesFromSearchEngine(SearchEngine.createCSearchScope(scope), searchName, ICSearchConstants.DEFINITIONS); - - if (matches != null && matches.size() > 0) { - Iterator itr = matches.iterator(); - while(itr.hasNext()) { - Object match = itr.next(); - if (match instanceof IMatch) { - IMatch theMatch = (IMatch)match; - storage.setFileName(theMatch.getLocation().toOSString()); - storage.setLocatable(theMatch.getLocatable()); - storage.setResource(ParserUtil.getResourceForFilename(theMatch.getLocation().toOSString())); - break; - } - } - } else { - operationNotAvailable(CSEARCH_OPERATION_NO_DEFINITION_MESSAGE); - } - } - } else if (selectedNames.length == 0){ - // last try: search the index for the selected string, even if no name was found for that selection - ICElement[] scope = new ICElement[1]; - scope[0] = project; - Set matches = DOMSearchUtil.getMatchesFromSearchEngine( SearchEngine.createCSearchScope(scope), selNode.selText, ICSearchConstants.DEFINITIONS ); - - if (matches != null && matches.size() > 0) { - Iterator itr = matches.iterator(); - while(itr.hasNext()) { - Object match = itr.next(); - if (match instanceof IMatch) { - IMatch theMatch = (IMatch)match; - storage.setFileName(theMatch.getLocation().toOSString()); - storage.setLocatable(theMatch.getLocatable()); - storage.setResource(ParserUtil.getResourceForFilename(theMatch.getLocation().toOSString())); - break; - } - } - } else { - operationNotAvailable(CSEARCH_OPERATION_NO_DEFINITION_MESSAGE); - return; - } - } else { - operationNotAvailable(CSEARCH_OPERATION_TOO_MANY_NAMES_MESSAGE); - return; - } - - return; - } - - private String findProjectName(IFile resourceFile) { - if( resourceFile == null ) return ""; //$NON-NLS-1$ - IProject[] projects = ResourcesPlugin.getWorkspace().getRoot().getProjects(); - for( int i = 0; i < projects.length; ++i ) - { - if( projects[i].contains(resourceFile) ) - return projects[i].getName(); - } - return ""; //$NON-NLS-1$ - } - }; + final SelSearchNode selNode = getSelectedStringFromEditor(); + + if(selNode == null) { + return; + } + + final Storage storage = new Storage(); + + IRunnableWithProgress runnable = new IRunnableWithProgress() + { + // steps: + // 1- parse and get the best selected name based on the offset/length into that TU + // 2- based on the IASTName selected, find the best definition of it in the TU + // 3- if no IASTName is found for a definition, then search the Index + public void run(IProgressMonitor monitor) { + int selectionStart = selNode.selStart; + int selectionLength = selNode.selEnd - selNode.selStart; + + IASTName[] selectedNames = BLANK_NAME_ARRAY; + IASTTranslationUnit tu=null; + ParserLanguage lang=null; + ICElement project=null; + + if (fEditor.getEditorInput() instanceof ExternalEditorInput) { + ExternalEditorInput input = (ExternalEditorInput)fEditor.getEditorInput(); + try { + // get the project for the external editor input's translation unit + project = input.getTranslationUnit(); + while (!(project instanceof ICProject) && project != null) { + project = project.getParent(); + } + + if (project instanceof ICProject) { + tu = CDOM.getInstance().getASTService().getTranslationUnit(input.getStorage(), ((ICProject)project).getProject()); + lang = DOMSearchUtil.getLanguage(input.getStorage().getFullPath(), ((ICProject)project).getProject()); + projectName = ((ICProject)project).getElementName(); + } + } catch (UnsupportedDialectException e) { + operationNotAvailable(CSEARCH_OPERATION_OPERATION_UNAVAILABLE_MESSAGE); + return; + } + } else { + IFile resourceFile = null; + resourceFile = fEditor.getInputFile(); + project = new CProject(null, resourceFile.getProject()); + + try { + tu = CDOM.getInstance().getASTService().getTranslationUnit( + resourceFile, + CDOM.getInstance().getCodeReaderFactory( + CDOM.PARSE_WORKING_COPY_WHENEVER_POSSIBLE)); + } catch (IASTServiceProvider.UnsupportedDialectException e) { + operationNotAvailable(CSEARCH_OPERATION_OPERATION_UNAVAILABLE_MESSAGE); + return; + } + lang = DOMSearchUtil.getLanguageFromFile(resourceFile); + project = new CProject(null, resourceFile.getProject()); + } + + // step 1 starts here + selectedNames = DOMSearchUtil.getSelectedNamesFrom(tu, selectionStart, selectionLength, lang); + + try { + if (selectedNames.length > 0 && selectedNames[0] != null) { + IASTName searchName = selectedNames[0]; + // step 2 starts here + IASTName[] domNames = DOMSearchUtil.getNamesFromDOM(searchName, ICSearchConstants.DEFINITIONS); + + // make sure the names are clean (fix for 95202) + boolean modified=false; + for(int i=0; i 0 && domNames[0] != null) { + String fileName=null; + int start=0; + int end=0; + + if ( domNames[0].getTranslationUnit() != null ) { + IASTFileLocation location = domNames[0].getFileLocation(); + if (location != null) + { + fileName = location.getFileName(); + start = location.getNodeOffset(); + end = location.getNodeOffset() + location.getNodeLength(); + } + } + + if (fileName != null) { + storage.setFileName(fileName); + storage.setLocatable(new OffsetLocatable(start,end)); + storage.setResource(ParserUtil.getResourceForFilename( fileName )); + return; + } + } else { + // step 3 starts here + ICElement[] scope = new ICElement[1]; + scope[0] = project; + Set matches = DOMSearchUtil.getMatchesFromSearchEngine(SearchEngine.createCSearchScope(scope), searchName, ICSearchConstants.DEFINITIONS); + + if (matches != null && matches.size() > 0) { + Iterator itr = matches.iterator(); + while(itr.hasNext()) { + Object match = itr.next(); + if (match instanceof IMatch) { + IMatch theMatch = (IMatch)match; + storage.setFileName(theMatch.getLocation().toOSString()); + storage.setLocatable(theMatch.getLocatable()); + storage.setResource(ParserUtil.getResourceForFilename(theMatch.getLocation().toOSString())); + break; + } + } + return; + } + } + } + } catch (Exception e) {} // catch all exceptions from DOM so the indexer can still be tried + + // last try: search the index for the selected string, even if no name was found for that selection + ICElement[] scope = new ICElement[1]; + scope[0] = project; + Set matches = DOMSearchUtil.getMatchesFromSearchEngine( SearchEngine.createCSearchScope(scope), selNode.selText, ICSearchConstants.DEFINITIONS ); + + if (matches != null && matches.size() > 0) { + Iterator itr = matches.iterator(); + while(itr.hasNext()) { + Object match = itr.next(); + if (match instanceof IMatch) { + IMatch theMatch = (IMatch)match; + storage.setFileName(theMatch.getLocation().toOSString()); + storage.setLocatable(theMatch.getLocatable()); + storage.setResource(ParserUtil.getResourceForFilename(theMatch.getLocation().toOSString())); + break; + } + } + } else { + operationNotAvailable(CSEARCH_OPERATION_NO_DEFINITION_MESSAGE); + return; + } + } + }; try { ProgressMonitorDialog progressMonitor = new ProgressMonitorDialog(getShell()); diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/actions/SelectionParseAction.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/actions/SelectionParseAction.java index 6c748ef86a4..9d1f76c7890 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/actions/SelectionParseAction.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/actions/SelectionParseAction.java @@ -68,7 +68,6 @@ import org.eclipse.ui.texteditor.IDocumentProvider; */ public class SelectionParseAction extends Action { private static final String OPERATOR = "operator"; //$NON-NLS-1$ - protected static final String CSEARCH_OPERATION_TOO_MANY_NAMES_MESSAGE = "CSearchOperation.tooManyNames.message"; //$NON-NLS-1$ protected static final String CSEARCH_OPERATION_NO_NAMES_SELECTED_MESSAGE = "CSearchOperation.noNamesSelected.message"; //$NON-NLS-1$ protected static final String CSEARCH_OPERATION_OPERATION_UNAVAILABLE_MESSAGE = "CSearchOperation.operationUnavailable.message"; //$NON-NLS-1$ protected static final String CSEARCH_OPERATION_NO_DEFINITION_MESSAGE = "CSearchOperation.noDefinitionFound.message"; //$NON-NLS-1$