1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-08-05 07:15:39 +02:00

Patch for Devin Steffler: Fix for Bug 102182 ([F3] Open Declaration on macro not working in particular project)

This commit is contained in:
Bogdan Gheorghe 2005-07-07 18:40:02 +00:00
parent f4b1edba07
commit c1c91403c4
6 changed files with 297 additions and 321 deletions

View file

@ -90,7 +90,6 @@ CSearchResultLabelProvider.potentialMatch= \ (inexact)
CSearchOperation.operationUnavailable.title= Operation Unavailable CSearchOperation.operationUnavailable.title= Operation Unavailable
CSearchOperation.operationUnavailable.message= The operation is unavailable on the current selection. 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.noNamesSelected.message= The operation is unavailable on the current selection (no name selected).
CSearchOperation.noDefinitionFound.message= No definition was found. CSearchOperation.noDefinitionFound.message= No definition was found.
CSearchOperation.noDeclarationFound.message= No declaration was found. CSearchOperation.noDeclarationFound.message= No declaration was found.

View file

@ -71,12 +71,14 @@ public class DOMQuery extends CSearchQuery implements ISearchQuery {
private IASTName searchName=null; private IASTName searchName=null;
private LimitTo limitTo=null; private LimitTo limitTo=null;
private ICSearchScope scope=null; private ICSearchScope scope=null;
private String searchPattern=null;
public DOMQuery(String displaySearchPattern, IASTName name, LimitTo limitTo, ICSearchScope scope) { public DOMQuery(String displaySearchPattern, IASTName name, LimitTo limitTo, ICSearchScope scope, String searchPattern) {
super(CUIPlugin.getWorkspace(), displaySearchPattern, false, null, null, null, displaySearchPattern); super(CUIPlugin.getWorkspace(), displaySearchPattern, false, null, null, null, displaySearchPattern);
this.searchName = name; this.searchName = name;
this.limitTo = limitTo; this.limitTo = limitTo;
this.scope = scope; this.scope = scope;
this.searchPattern = searchPattern;
} }
/* (non-Javadoc) /* (non-Javadoc)
@ -91,6 +93,7 @@ public class DOMQuery extends CSearchQuery implements ISearchQuery {
// fix for 43128 // fix for 43128
Set matches=null; Set matches=null;
IASTName[] foundNames=null;
if (!isLocal()) if (!isLocal())
matches = DOMSearchUtil.getMatchesFromSearchEngine(scope, searchName, limitTo); 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 } 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<foundNames.length; i++) { for (int i=0; i<foundNames.length; i++) {
try { try {
@ -138,6 +141,23 @@ public class DOMQuery extends CSearchQuery implements ISearchQuery {
} }
} }
if (searchPattern != null && matches.size() == 0 && (foundNames == null || foundNames.length == 0)) {
// last try: search the index for the selected string, even if no name was found for that selection
matches = DOMSearchUtil.getMatchesFromSearchEngine( scope, searchPattern, limitTo );
Iterator itr = matches.iterator();
while(itr.hasNext()) {
Object next = itr.next();
if (next instanceof IMatch) {
try {
collector.acceptMatch((IMatch)next);
} catch (CoreException e) {
// don't do anything if the match wasn't accepted
}
}
}
}
mainSearchPM.done(); mainSearchPM.done();
collector.done(); collector.done();

View file

@ -29,7 +29,6 @@ import org.eclipse.cdt.core.model.ICProject;
import org.eclipse.cdt.core.parser.ParseError; import org.eclipse.cdt.core.parser.ParseError;
import org.eclipse.cdt.core.parser.ParserLanguage; import org.eclipse.cdt.core.parser.ParserLanguage;
import org.eclipse.cdt.core.search.DOMSearchUtil; import org.eclipse.cdt.core.search.DOMSearchUtil;
import org.eclipse.cdt.core.search.ICSearchConstants;
import org.eclipse.cdt.core.search.ICSearchScope; import org.eclipse.cdt.core.search.ICSearchScope;
import org.eclipse.cdt.core.search.ICSearchConstants.LimitTo; import org.eclipse.cdt.core.search.ICSearchConstants.LimitTo;
import org.eclipse.cdt.core.search.ICSearchConstants.SearchFor; import org.eclipse.cdt.core.search.ICSearchConstants.SearchFor;
@ -74,14 +73,7 @@ public abstract class FindAction extends SelectionParseAction {
* @return * @return
*/ */
public CSearchQuery createDOMSearchQueryForName( IASTName name, LimitTo limitTo, ICSearchScope scope, String searchPattern){ public CSearchQuery createDOMSearchQueryForName( IASTName name, LimitTo limitTo, ICSearchScope scope, String searchPattern){
if (name != null) { return new DOMQuery(DOMSearchUtil.getSearchPattern(name), name, limitTo, scope, searchPattern);
return new DOMQuery(DOMSearchUtil.getSearchPattern(name), name, limitTo, scope);
} else {
if (searchPattern != null)
return createSearchQuery(searchPattern, ICSearchConstants.UNKNOWN_SEARCH_FOR);
else
return null;
}
} }
@ -216,9 +208,6 @@ public abstract class FindAction extends SelectionParseAction {
} else if (names.size() == 0) { // no names selected } else if (names.size() == 0) { // no names selected
operationNotAvailable(CSEARCH_OPERATION_NO_NAMES_SELECTED_MESSAGE); operationNotAvailable(CSEARCH_OPERATION_NO_NAMES_SELECTED_MESSAGE);
return; return;
} else if (names.size() > 1) { // too many names selected
operationNotAvailable(CSEARCH_OPERATION_TOO_MANY_NAMES_MESSAGE);
return;
} }
foundName = (IASTName)names.get(0); foundName = (IASTName)names.get(0);

View file

@ -83,151 +83,135 @@ public class OpenDeclarationsAction extends SelectionParseAction implements IUpd
int selectionStart = selNode.selStart; int selectionStart = selNode.selStart;
int selectionLength = selNode.selEnd - selNode.selStart; int selectionLength = selNode.selEnd - selNode.selStart;
IASTName[] selectedNames = BLANK_NAME_ARRAY; IASTName[] selectedNames = BLANK_NAME_ARRAY;
IASTTranslationUnit tu=null; IASTTranslationUnit tu=null;
ParserLanguage lang=null; ParserLanguage lang=null;
ICElement project=null; ICElement project=null;
if (fEditor.getEditorInput() instanceof ExternalEditorInput) { if (fEditor.getEditorInput() instanceof ExternalEditorInput) {
ExternalEditorInput input = (ExternalEditorInput)fEditor.getEditorInput(); ExternalEditorInput input = (ExternalEditorInput)fEditor.getEditorInput();
try { try {
// get the project for the external editor input's translation unit // get the project for the external editor input's translation unit
project = input.getTranslationUnit(); project = input.getTranslationUnit();
while (!(project instanceof ICProject) && project != null) { while (!(project instanceof ICProject) && project != null) {
project = project.getParent(); project = project.getParent();
} }
if (project instanceof ICProject) { if (project instanceof ICProject) {
tu = CDOM.getInstance().getASTService().getTranslationUnit(input.getStorage(), ((ICProject)project).getProject()); tu = CDOM.getInstance().getASTService().getTranslationUnit(input.getStorage(), ((ICProject)project).getProject());
lang = DOMSearchUtil.getLanguage(input.getStorage().getFullPath(), ((ICProject)project).getProject()); lang = DOMSearchUtil.getLanguage(input.getStorage().getFullPath(), ((ICProject)project).getProject());
projectName = ((ICProject)project).getElementName(); projectName = ((ICProject)project).getElementName();
} }
} catch (UnsupportedDialectException e) { } catch (UnsupportedDialectException e) {
operationNotAvailable(CSEARCH_OPERATION_OPERATION_UNAVAILABLE_MESSAGE); operationNotAvailable(CSEARCH_OPERATION_OPERATION_UNAVAILABLE_MESSAGE);
return; 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<domNames.length; i++) {
if (domNames[i].toCharArray().length == 0) {
domNames[i] = null;
modified=true;
}
}
if (modified)
domNames = (IASTName[])ArrayUtil.removeNulls(IASTName.class, domNames);
if (domNames != null && domNames.length > 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);
}
} }
} 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 { } else {
operationNotAvailable(CSEARCH_OPERATION_TOO_MANY_NAMES_MESSAGE); IFile resourceFile = null;
return; 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);
// private String findProjectName(IFile resourceFile) { try {
// if( resourceFile == null ) return ""; //$NON-NLS-1$ if (selectedNames.length > 0 && selectedNames[0] != null) { // just right, only one name selected
// IProject[] projects = ResourcesPlugin.getWorkspace().getRoot().getProjects(); IASTName searchName = selectedNames[0];
// for( int i = 0; i < projects.length; ++i ) // step 2 starts here
// { IASTName[] domNames = DOMSearchUtil.getNamesFromDOM(searchName, ICSearchConstants.DECLARATIONS_DEFINITIONS);
// if( projects[i].contains(resourceFile) )
// return projects[i].getName(); // make sure the names are clean (fix for 95202)
// } boolean modified=false;
// return ""; //$NON-NLS-1$ for(int i=0; i<domNames.length; i++) {
// } if (domNames[i].toCharArray().length == 0) {
}; domNames[i] = null;
modified=true;
}
}
if (modified)
domNames = (IASTName[])ArrayUtil.removeNulls(IASTName.class, domNames);
if (domNames != null && domNames.length > 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;
}
}
};
try { try {
ProgressMonitorDialog progressMonitor = new ProgressMonitorDialog(getShell()); ProgressMonitorDialog progressMonitor = new ProgressMonitorDialog(getShell());

View file

@ -35,8 +35,6 @@ import org.eclipse.cdt.internal.ui.editor.CEditorMessages;
import org.eclipse.cdt.internal.ui.util.ExternalEditorInput; import org.eclipse.cdt.internal.ui.util.ExternalEditorInput;
import org.eclipse.cdt.ui.CUIPlugin; import org.eclipse.cdt.ui.CUIPlugin;
import org.eclipse.core.resources.IFile; 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.core.runtime.IProgressMonitor;
import org.eclipse.jface.dialogs.ProgressMonitorDialog; import org.eclipse.jface.dialogs.ProgressMonitorDialog;
import org.eclipse.jface.operation.IRunnableWithProgress; import org.eclipse.jface.operation.IRunnableWithProgress;
@ -79,166 +77,153 @@ public class OpenDefinitionAction extends SelectionParseAction implements
* @see org.eclipse.jface.action.IAction#run() * @see org.eclipse.jface.action.IAction#run()
*/ */
public void run() { public void run() {
final SelSearchNode selNode = getSelectedStringFromEditor(); final SelSearchNode selNode = getSelectedStringFromEditor();
if(selNode == null) { if(selNode == null) {
return; return;
} }
final Storage storage = new Storage(); final Storage storage = new Storage();
IRunnableWithProgress runnable = new IRunnableWithProgress() IRunnableWithProgress runnable = new IRunnableWithProgress()
{ {
// steps: // steps:
// 1- parse and get the best selected name based on the offset/length into that TU // 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 // 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 // 3- if no IASTName is found for a definition, then search the Index
public void run(IProgressMonitor monitor) { public void run(IProgressMonitor monitor) {
int selectionStart = selNode.selStart; int selectionStart = selNode.selStart;
int selectionLength = selNode.selEnd - selNode.selStart; int selectionLength = selNode.selEnd - selNode.selStart;
IASTName[] selectedNames = BLANK_NAME_ARRAY; IASTName[] selectedNames = BLANK_NAME_ARRAY;
IASTTranslationUnit tu=null; IASTTranslationUnit tu=null;
ParserLanguage lang=null; ParserLanguage lang=null;
ICElement project=null; ICElement project=null;
if (fEditor.getEditorInput() instanceof ExternalEditorInput) { if (fEditor.getEditorInput() instanceof ExternalEditorInput) {
ExternalEditorInput input = (ExternalEditorInput)fEditor.getEditorInput(); ExternalEditorInput input = (ExternalEditorInput)fEditor.getEditorInput();
try { try {
// get the project for the external editor input's translation unit // get the project for the external editor input's translation unit
project = input.getTranslationUnit(); project = input.getTranslationUnit();
while (!(project instanceof ICProject) && project != null) { while (!(project instanceof ICProject) && project != null) {
project = project.getParent(); project = project.getParent();
} }
if (project instanceof ICProject) { if (project instanceof ICProject) {
tu = CDOM.getInstance().getASTService().getTranslationUnit(input.getStorage(), ((ICProject)project).getProject()); tu = CDOM.getInstance().getASTService().getTranslationUnit(input.getStorage(), ((ICProject)project).getProject());
lang = DOMSearchUtil.getLanguage(input.getStorage().getFullPath(), ((ICProject)project).getProject()); lang = DOMSearchUtil.getLanguage(input.getStorage().getFullPath(), ((ICProject)project).getProject());
projectName = ((ICProject)project).getElementName(); projectName = ((ICProject)project).getElementName();
} }
} catch (UnsupportedDialectException e) { } catch (UnsupportedDialectException e) {
operationNotAvailable(CSEARCH_OPERATION_OPERATION_UNAVAILABLE_MESSAGE); operationNotAvailable(CSEARCH_OPERATION_OPERATION_UNAVAILABLE_MESSAGE);
return; return;
} }
} else { } else {
IFile resourceFile = null; IFile resourceFile = null;
resourceFile = fEditor.getInputFile(); resourceFile = fEditor.getInputFile();
project = new CProject(null, resourceFile.getProject()); project = new CProject(null, resourceFile.getProject());
try { try {
tu = CDOM.getInstance().getASTService().getTranslationUnit( tu = CDOM.getInstance().getASTService().getTranslationUnit(
resourceFile, resourceFile,
CDOM.getInstance().getCodeReaderFactory( CDOM.getInstance().getCodeReaderFactory(
CDOM.PARSE_WORKING_COPY_WHENEVER_POSSIBLE)); CDOM.PARSE_WORKING_COPY_WHENEVER_POSSIBLE));
} catch (IASTServiceProvider.UnsupportedDialectException e) { } catch (IASTServiceProvider.UnsupportedDialectException e) {
operationNotAvailable(CSEARCH_OPERATION_OPERATION_UNAVAILABLE_MESSAGE); operationNotAvailable(CSEARCH_OPERATION_OPERATION_UNAVAILABLE_MESSAGE);
return; return;
} }
lang = DOMSearchUtil.getLanguageFromFile(resourceFile); lang = DOMSearchUtil.getLanguageFromFile(resourceFile);
projectName = findProjectName(resourceFile); project = new CProject(null, resourceFile.getProject());
} }
// step 1 starts here // step 1 starts here
selectedNames = DOMSearchUtil.getSelectedNamesFrom(tu, selectionStart, selectionLength, lang); selectedNames = DOMSearchUtil.getSelectedNamesFrom(tu, selectionStart, selectionLength, lang);
if (selectedNames.length > 0 && selectedNames[0] != null) { // just right, only one name selected try {
IASTName searchName = selectedNames[0]; if (selectedNames.length > 0 && selectedNames[0] != null) {
// step 2 starts here IASTName searchName = selectedNames[0];
IASTName[] domNames = DOMSearchUtil.getNamesFromDOM(searchName, ICSearchConstants.DEFINITIONS); // step 2 starts here
IASTName[] domNames = DOMSearchUtil.getNamesFromDOM(searchName, ICSearchConstants.DEFINITIONS);
// make sure the names are clean (fix for 95202) // make sure the names are clean (fix for 95202)
boolean modified=false; boolean modified=false;
for(int i=0; i<domNames.length; i++) { for(int i=0; i<domNames.length; i++) {
if (domNames[i].toCharArray().length == 0) { if (domNames[i].toCharArray().length == 0) {
domNames[i] = null; domNames[i] = null;
modified=true; modified=true;
} }
} }
if (modified) if (modified)
domNames = (IASTName[])ArrayUtil.removeNulls(IASTName.class, domNames); domNames = (IASTName[])ArrayUtil.removeNulls(IASTName.class, domNames);
if (domNames != null && domNames.length > 0 && domNames[0] != null) { if (domNames != null && domNames.length > 0 && domNames[0] != null) {
String fileName=null; String fileName=null;
int start=0; int start=0;
int end=0; int end=0;
if ( domNames[0].getTranslationUnit() != null ) { if ( domNames[0].getTranslationUnit() != null ) {
IASTFileLocation location = domNames[0].getFileLocation(); IASTFileLocation location = domNames[0].getFileLocation();
fileName = location.getFileName(); if (location != null)
start = location.getNodeOffset(); {
end = location.getNodeOffset() + location.getNodeLength(); fileName = location.getFileName();
} start = location.getNodeOffset();
end = location.getNodeOffset() + location.getNodeLength();
}
}
if (fileName != null) { if (fileName != null) {
storage.setFileName(fileName); storage.setFileName(fileName);
storage.setLocatable(new OffsetLocatable(start,end)); storage.setLocatable(new OffsetLocatable(start,end));
storage.setResource(ParserUtil.getResourceForFilename( fileName )); storage.setResource(ParserUtil.getResourceForFilename( fileName ));
} else { return;
operationNotAvailable(CSEARCH_OPERATION_NO_DEFINITION_MESSAGE); }
} } else {
} else { // step 3 starts here
// step 3 starts here ICElement[] scope = new ICElement[1];
ICElement[] scope = new ICElement[1]; scope[0] = project;
scope[0] = project; Set matches = DOMSearchUtil.getMatchesFromSearchEngine(SearchEngine.createCSearchScope(scope), searchName, ICSearchConstants.DEFINITIONS);
Set matches = DOMSearchUtil.getMatchesFromSearchEngine(SearchEngine.createCSearchScope(scope), searchName, ICSearchConstants.DEFINITIONS);
if (matches != null && matches.size() > 0) { if (matches != null && matches.size() > 0) {
Iterator itr = matches.iterator(); Iterator itr = matches.iterator();
while(itr.hasNext()) { while(itr.hasNext()) {
Object match = itr.next(); Object match = itr.next();
if (match instanceof IMatch) { if (match instanceof IMatch) {
IMatch theMatch = (IMatch)match; IMatch theMatch = (IMatch)match;
storage.setFileName(theMatch.getLocation().toOSString()); storage.setFileName(theMatch.getLocation().toOSString());
storage.setLocatable(theMatch.getLocatable()); storage.setLocatable(theMatch.getLocatable());
storage.setResource(ParserUtil.getResourceForFilename(theMatch.getLocation().toOSString())); storage.setResource(ParserUtil.getResourceForFilename(theMatch.getLocation().toOSString()));
break; break;
} }
} }
} else { return;
operationNotAvailable(CSEARCH_OPERATION_NO_DEFINITION_MESSAGE); }
} }
} }
} else if (selectedNames.length == 0){ } 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) { // last try: search the index for the selected string, even if no name was found for that selection
Iterator itr = matches.iterator(); ICElement[] scope = new ICElement[1];
while(itr.hasNext()) { scope[0] = project;
Object match = itr.next(); Set matches = DOMSearchUtil.getMatchesFromSearchEngine( SearchEngine.createCSearchScope(scope), selNode.selText, ICSearchConstants.DEFINITIONS );
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; if (matches != null && matches.size() > 0) {
} Iterator itr = matches.iterator();
while(itr.hasNext()) {
private String findProjectName(IFile resourceFile) { Object match = itr.next();
if( resourceFile == null ) return ""; //$NON-NLS-1$ if (match instanceof IMatch) {
IProject[] projects = ResourcesPlugin.getWorkspace().getRoot().getProjects(); IMatch theMatch = (IMatch)match;
for( int i = 0; i < projects.length; ++i ) storage.setFileName(theMatch.getLocation().toOSString());
{ storage.setLocatable(theMatch.getLocatable());
if( projects[i].contains(resourceFile) ) storage.setResource(ParserUtil.getResourceForFilename(theMatch.getLocation().toOSString()));
return projects[i].getName(); break;
} }
return ""; //$NON-NLS-1$ }
} } else {
}; operationNotAvailable(CSEARCH_OPERATION_NO_DEFINITION_MESSAGE);
return;
}
}
};
try { try {
ProgressMonitorDialog progressMonitor = new ProgressMonitorDialog(getShell()); ProgressMonitorDialog progressMonitor = new ProgressMonitorDialog(getShell());

View file

@ -68,7 +68,6 @@ import org.eclipse.ui.texteditor.IDocumentProvider;
*/ */
public class SelectionParseAction extends Action { public class SelectionParseAction extends Action {
private static final String OPERATOR = "operator"; //$NON-NLS-1$ 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_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_OPERATION_UNAVAILABLE_MESSAGE = "CSearchOperation.operationUnavailable.message"; //$NON-NLS-1$
protected static final String CSEARCH_OPERATION_NO_DEFINITION_MESSAGE = "CSearchOperation.noDefinitionFound.message"; //$NON-NLS-1$ protected static final String CSEARCH_OPERATION_NO_DEFINITION_MESSAGE = "CSearchOperation.noDefinitionFound.message"; //$NON-NLS-1$