1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +02:00

Patch for Devin Steffler.

FIXED 72716- [Search] Search actions in "magic" include files do not work.
This commit is contained in:
John Camelon 2005-05-03 18:48:24 +00:00
parent c338788697
commit d5663f5134
6 changed files with 238 additions and 91 deletions

View file

@ -50,6 +50,7 @@ import org.eclipse.cdt.core.search.ICSearchConstants.SearchFor;
import org.eclipse.cdt.internal.core.search.matching.CSearchPattern; import org.eclipse.cdt.internal.core.search.matching.CSearchPattern;
import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.IPath;
/** /**
* Utility class to have commonly used algorithms in one place for searching with the DOM. * Utility class to have commonly used algorithms in one place for searching with the DOM.
@ -171,7 +172,75 @@ public class DOMSearchUtil {
} }
/** /**
* This is used to get a List of selected names in an IFile based on the offset and length into that IFile. * This is used to get an array of selected names in an IASTTranslationUnit based on the offset
* and length into that IASTTranslationUnit.
*
* ex: IASTTranslationUnit contains: int foo;
* then getSelectedNamesFrom(file, 4, 3) will return the IASTName corresponding to foo
*
* @param tu
* @param offset
* @param length
* @param lang
* @return
*/
public static IASTName[] getSelectedNamesFrom(IASTTranslationUnit tu, int offset, int length, ParserLanguage lang) {
IASTNode node = null;
try{
node = tu.selectNodeForLocation(tu.getFilePath(), offset, length); // TODO Devin untested tu.getContainingFilename() ...
}
catch (ParseError er){}
catch ( VirtualMachineError vmErr){
if (vmErr instanceof OutOfMemoryError){
org.eclipse.cdt.internal.core.model.Util.log(null, "Open Declarations Out Of Memory error: " + vmErr.getMessage() + " on File: " + tu.getContainingFilename(), ICLogConstants.CDT); //$NON-NLS-1$ //$NON-NLS-2$
}
}
catch (Exception ex){}
finally{
if (node == null){
return EMPTY_NAME_LIST;
}
}
if (node instanceof IASTName) {
IASTName[] results = new IASTName[1];
results[0] = (IASTName)node;
return results;
}
ASTVisitor collector = null;
if (lang == ParserLanguage.CPP) {
collector = new CPPNameCollector();
} else {
collector = new CNameCollector();
}
node.accept( collector );
List names = null;
if (collector instanceof CPPNameCollector) {
names = ((CPPNameCollector)collector).nameList;
} else {
names = ((CNameCollector)collector).nameList;
}
IASTName[] results = new IASTName[names.size()];
for(int i=0; i<names.size(); i++) {
if (names.get(i) instanceof IASTName)
results[i] = (IASTName)names.get(i);
}
return results;
}
/**
* This is used to get an array of selected names in an IFile based on the offset and length
* into that IFile.
*
* NOTE: Invoking this method causes a parse, if an IASTTranslationUnit is already obtained then
* invoke getSelectedNamesFrom(IASTTranslationUnit, int, int, ParserLanguage) instead.
* *
* ex: IFile contains: int foo; * ex: IFile contains: int foo;
* then getSelectedNamesFrom(file, 4, 3) will return the IASTName corresponding to foo * then getSelectedNamesFrom(file, 4, 3) will return the IASTName corresponding to foo
@ -340,4 +409,18 @@ public class DOMSearchUtil {
} }
public int size() { return nameList.size(); } public int size() { return nameList.size(); }
} }
public static ParserLanguage getLanguage( IPath path, IProject project )
{
ICFileType type = CCorePlugin.getDefault().getFileType(project, path.lastSegment());
boolean isHeader= type.isHeader();
if( isHeader )
return ParserLanguage.CPP; // assumption
String lid = type.getLanguage().getId();
if( lid.equals(ICFileTypeConstants.LANG_CXX))
return ParserLanguage.CPP;
if( lid.equals( ICFileTypeConstants.LANG_C ) )
return ParserLanguage.C;
return ParserLanguage.CPP;
}
} }

View file

@ -1226,6 +1226,11 @@ public class DOMAST extends ViewPart {
IFile aFile = ((CEditor)editor).getInputFile(); IFile aFile = ((CEditor)editor).getInputFile();
// check if the file is a valid "compilation unit" (based on file extension) // check if the file is a valid "compilation unit" (based on file extension)
if (aFile == null) {
MessageDialog.openInformation(shell, DOMAST.VIEW_NAME, NOT_VALID_COMPILATION_UNIT);
return null;
}
String ext = aFile.getFileExtension().toUpperCase(); String ext = aFile.getFileExtension().toUpperCase();
if (!(ext.equals(EXTENSION_C) || ext.equals(EXTENSION_CC) || ext.equals(EXTENSION_CPP) || ext.equals(EXTENSION_CXX))) { if (!(ext.equals(EXTENSION_C) || ext.equals(EXTENSION_CC) || ext.equals(EXTENSION_CPP) || ext.equals(EXTENSION_CXX))) {
MessageDialog.openInformation(shell, DOMAST.VIEW_NAME, NOT_VALID_COMPILATION_UNIT); MessageDialog.openInformation(shell, DOMAST.VIEW_NAME, NOT_VALID_COMPILATION_UNIT);
@ -1247,6 +1252,10 @@ public class DOMAST extends ViewPart {
} }
public static ParserLanguage getLanguageFromFile(IFile file) { public static ParserLanguage getLanguageFromFile(IFile file) {
if (file == null) { // assume CPP
return ParserLanguage.CPP;
}
IProject project = file.getProject(); IProject project = file.getProject();
ICFileType type = CCorePlugin.getDefault().getFileType(project, file.getFullPath().lastSegment()); ICFileType type = CCorePlugin.getDefault().getFileType(project, file.getFullPath().lastSegment());
String lid = type.getLanguage().getId(); String lid = type.getLanguage().getId();

View file

@ -19,6 +19,7 @@ import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.ICLogConstants; import org.eclipse.cdt.core.ICLogConstants;
import org.eclipse.cdt.core.dom.CDOM; import org.eclipse.cdt.core.dom.CDOM;
import org.eclipse.cdt.core.dom.IASTServiceProvider; import org.eclipse.cdt.core.dom.IASTServiceProvider;
import org.eclipse.cdt.core.dom.IASTServiceProvider.UnsupportedDialectException;
import org.eclipse.cdt.core.dom.ast.ASTTypeUtil; import org.eclipse.cdt.core.dom.ast.ASTTypeUtil;
import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.ASTVisitor;
import org.eclipse.cdt.core.dom.ast.DOMException; import org.eclipse.cdt.core.dom.ast.DOMException;
@ -31,6 +32,7 @@ import org.eclipse.cdt.core.dom.ast.IFunctionType;
import org.eclipse.cdt.core.dom.ast.IType; import org.eclipse.cdt.core.dom.ast.IType;
import org.eclipse.cdt.core.dom.ast.c.ICExternalBinding; import org.eclipse.cdt.core.dom.ast.c.ICExternalBinding;
import org.eclipse.cdt.core.model.ICElement; import org.eclipse.cdt.core.model.ICElement;
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;
@ -148,9 +150,10 @@ public abstract class FindAction extends SelectionParseAction {
if( obj == null || !(obj instanceof ICElement ) ){ if( obj == null || !(obj instanceof ICElement ) ){
operationNotAvailable(CSEARCH_OPERATION_OPERATION_UNAVAILABLE_MESSAGE); operationNotAvailable(CSEARCH_OPERATION_OPERATION_UNAVAILABLE_MESSAGE);
return; return;
} else {
clearStatusLine();
} }
clearStatusLine();
ICElement element = (ICElement) obj; ICElement element = (ICElement) obj;
CSearchQuery job = createSearchQuery( element.getElementName(), CSearchUtil.getSearchForFromElement(element)); CSearchQuery job = createSearchQuery( element.getElementName(), CSearchUtil.getSearchForFromElement(element));
@ -191,23 +194,18 @@ public abstract class FindAction extends SelectionParseAction {
SelSearchNode selNode = getSelection( sel ); SelSearchNode selNode = getSelection( sel );
IFile resourceFile = null;
if (fEditor.getEditorInput() instanceof ExternalEditorInput) {
// TODO Devin should be able to implement this somehow, see PR 78118
operationNotAvailable(CSEARCH_OPERATION_OPERATION_UNAVAILABLE_MESSAGE);
return;
}
resourceFile = fEditor.getInputFile();
IASTTranslationUnit tu = null;
IASTNode foundNode = null; IASTNode foundNode = null;
IASTTranslationUnit tu = null;
ParserLanguage lang = null;
String file = null;
ParseWithProgress runnable = new ParseWithProgress(resourceFile); ParseWithProgress runnable = new ParseWithProgress();
ProgressMonitorDialog progressMonitor = new ProgressMonitorDialog(fEditor.getSite().getShell()); ProgressMonitorDialog progressMonitor = new ProgressMonitorDialog(fEditor.getSite().getShell());
try { try {
progressMonitor.run(true, true, runnable); progressMonitor.run(true, true, runnable);
tu = runnable.getTu(); tu = runnable.getTu();
file = runnable.getFile();
lang = runnable.getLang();
} catch (InvocationTargetException e1) { } catch (InvocationTargetException e1) {
operationNotAvailable(CSEARCH_OPERATION_OPERATION_UNAVAILABLE_MESSAGE); operationNotAvailable(CSEARCH_OPERATION_OPERATION_UNAVAILABLE_MESSAGE);
return; return;
@ -216,14 +214,6 @@ public abstract class FindAction extends SelectionParseAction {
return; return;
} }
String file=null;
if( resourceFile != null )
file = resourceFile.getLocation().toOSString();
else
{
if( resourceFile instanceof ExternalEditorInput )
file = ((ExternalEditorInput)resourceFile).getStorage().getFullPath().toOSString();
}
try{ try{
foundNode = tu.selectNodeForLocation(file, selNode.selStart, selNode.selEnd - selNode.selStart); foundNode = tu.selectNodeForLocation(file, selNode.selStart, selNode.selEnd - selNode.selStart);
} }
@ -231,7 +221,7 @@ public abstract class FindAction extends SelectionParseAction {
catch (Exception ex){} catch (Exception ex){}
catch ( VirtualMachineError vmErr){ catch ( VirtualMachineError vmErr){
if (vmErr instanceof OutOfMemoryError){ if (vmErr instanceof OutOfMemoryError){
org.eclipse.cdt.internal.core.model.Util.log(null, "Selection Search Out Of Memory error: " + vmErr.getMessage() + " on File: " + resourceFile.getName(), ICLogConstants.CDT); //$NON-NLS-1$ //$NON-NLS-2$ org.eclipse.cdt.internal.core.model.Util.log(null, "Selection Search Out Of Memory error: " + vmErr.getMessage() + " on File: " + file, ICLogConstants.CDT); //$NON-NLS-1$ //$NON-NLS-2$
} }
} }
@ -240,7 +230,7 @@ public abstract class FindAction extends SelectionParseAction {
foundName = (IASTName)foundNode; foundName = (IASTName)foundNode;
} else { } else {
ASTVisitor collector = null; ASTVisitor collector = null;
if (DOMSearchUtil.getLanguageFromFile(resourceFile) == ParserLanguage.CPP) { if (lang == ParserLanguage.CPP) {
collector = new DOMSearchUtil.CPPNameCollector(); collector = new DOMSearchUtil.CPPNameCollector();
} else { } else {
collector = new DOMSearchUtil.CNameCollector(); collector = new DOMSearchUtil.CNameCollector();
@ -289,28 +279,62 @@ public abstract class FindAction extends SelectionParseAction {
private class ParseWithProgress implements IRunnableWithProgress private class ParseWithProgress implements IRunnableWithProgress
{ {
private IFile file=null;
private IASTTranslationUnit tu = null; private IASTTranslationUnit tu = null;
private String file=null;
private ParserLanguage lang=null;
public ParseWithProgress(IFile file) { public ParseWithProgress() {}
this.file = file;
}
public void run(IProgressMonitor monitor) { public void run(IProgressMonitor monitor) {
if (fEditor.getEditorInput() instanceof ExternalEditorInput) {
ExternalEditorInput input = (ExternalEditorInput)fEditor.getEditorInput();
try {
// get the project for the external editor input's translation unit
ICElement 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());
}
} catch (UnsupportedDialectException e) {
operationNotAvailable(CSEARCH_OPERATION_OPERATION_UNAVAILABLE_MESSAGE);
return;
}
file = input.getStorage().getFullPath().toOSString();
} else {
IFile resourceFile = null;
resourceFile = fEditor.getInputFile();
try { try {
tu = CDOM.getInstance().getASTService().getTranslationUnit( tu = CDOM.getInstance().getASTService().getTranslationUnit(
file, 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;
} }
file = resourceFile.getLocation().toOSString();
lang = DOMSearchUtil.getLanguageFromFile(resourceFile);
}
} }
public IASTTranslationUnit getTu() { public IASTTranslationUnit getTu() {
return tu; return tu;
} }
public String getFile() {
return file;
}
public ParserLanguage getLang() {
return lang;
}
}; };
abstract protected String getScopeDescription(); abstract protected String getScopeDescription();

View file

@ -10,15 +10,12 @@
******************************************************************************/ ******************************************************************************/
package org.eclipse.cdt.internal.ui.search.actions; package org.eclipse.cdt.internal.ui.search.actions;
import org.eclipse.cdt.core.model.ICElement;
import org.eclipse.cdt.core.search.ICSearchConstants; 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.SearchEngine; import org.eclipse.cdt.core.search.SearchEngine;
import org.eclipse.cdt.core.search.ICSearchConstants.LimitTo; import org.eclipse.cdt.core.search.ICSearchConstants.LimitTo;
import org.eclipse.cdt.internal.core.model.CProject;
import org.eclipse.cdt.internal.ui.editor.CEditor; import org.eclipse.cdt.internal.ui.editor.CEditor;
import org.eclipse.cdt.internal.ui.search.CSearchMessages; import org.eclipse.cdt.internal.ui.search.CSearchMessages;
import org.eclipse.core.resources.IProject;
import org.eclipse.ui.IWorkbenchSite; import org.eclipse.ui.IWorkbenchSite;

View file

@ -14,9 +14,15 @@ package org.eclipse.cdt.internal.ui.search.actions;
import java.util.Iterator; import java.util.Iterator;
import java.util.Set; import java.util.Set;
import org.eclipse.cdt.core.dom.CDOM;
import org.eclipse.cdt.core.dom.IASTServiceProvider;
import org.eclipse.cdt.core.dom.IASTServiceProvider.UnsupportedDialectException;
import org.eclipse.cdt.core.dom.ast.IASTFileLocation; import org.eclipse.cdt.core.dom.ast.IASTFileLocation;
import org.eclipse.cdt.core.dom.ast.IASTName; import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
import org.eclipse.cdt.core.model.ICElement; import org.eclipse.cdt.core.model.ICElement;
import org.eclipse.cdt.core.model.ICProject;
import org.eclipse.cdt.core.parser.ParserLanguage;
import org.eclipse.cdt.core.parser.ParserUtil; import org.eclipse.cdt.core.parser.ParserUtil;
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.ICSearchConstants;
@ -25,12 +31,10 @@ import org.eclipse.cdt.core.search.SearchEngine;
import org.eclipse.cdt.internal.core.model.CProject; import org.eclipse.cdt.internal.core.model.CProject;
import org.eclipse.cdt.internal.ui.editor.CEditor; import org.eclipse.cdt.internal.ui.editor.CEditor;
import org.eclipse.cdt.internal.ui.editor.CEditorMessages; import org.eclipse.cdt.internal.ui.editor.CEditorMessages;
import org.eclipse.cdt.internal.ui.editor.ITranslationUnitEditorInput;
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.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.ResourcesPlugin; 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;
@ -79,34 +83,47 @@ 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;
IFile resourceFile = null;
IASTName[] selectedNames = BLANK_NAME_ARRAY; IASTName[] selectedNames = BLANK_NAME_ARRAY;
IASTTranslationUnit tu=null;
ParserLanguage lang=null;
if (fEditor.getEditorInput() instanceof ExternalEditorInput) { if (fEditor.getEditorInput() instanceof ExternalEditorInput) {
if( fEditor.getEditorInput() instanceof ITranslationUnitEditorInput ) ExternalEditorInput input = (ExternalEditorInput)fEditor.getEditorInput();
{ try {
ITranslationUnitEditorInput ip = (ITranslationUnitEditorInput) fEditor.getEditorInput(); // get the project for the external editor input's translation unit
IResource r = ip.getTranslationUnit().getUnderlyingResource(); ICElement project = input.getTranslationUnit();
if( r.getType() == IResource.FILE ) while (!(project instanceof ICProject) && project != null) {
resourceFile = (IFile) r; project = project.getParent();
else }
{
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); operationNotAvailable(CSEARCH_OPERATION_OPERATION_UNAVAILABLE_MESSAGE);
return; return;
} }
} } else {
} IFile resourceFile = null;
else
resourceFile = fEditor.getInputFile(); resourceFile = fEditor.getInputFile();
try {
if (resourceFile != null) 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); projectName = findProjectName(resourceFile);
}
// step 1 starts here // step 1 starts here
if (resourceFile != null) selectedNames = DOMSearchUtil.getSelectedNamesFrom(tu, selectionStart, selectionLength, lang);
selectedNames = DOMSearchUtil.getSelectedNamesFrom(resourceFile, selectionStart, selectionLength);
if (selectedNames.length > 0 && selectedNames[0] != null) { // just right, only one name selected if (selectedNames.length > 0 && selectedNames[0] != null) { // just right, only one name selected
IASTName searchName = selectedNames[0]; IASTName searchName = selectedNames[0];

View file

@ -13,9 +13,15 @@ package org.eclipse.cdt.internal.ui.search.actions;
import java.util.Iterator; import java.util.Iterator;
import java.util.Set; import java.util.Set;
import org.eclipse.cdt.core.dom.CDOM;
import org.eclipse.cdt.core.dom.IASTServiceProvider;
import org.eclipse.cdt.core.dom.IASTServiceProvider.UnsupportedDialectException;
import org.eclipse.cdt.core.dom.ast.IASTFileLocation; import org.eclipse.cdt.core.dom.ast.IASTFileLocation;
import org.eclipse.cdt.core.dom.ast.IASTName; import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
import org.eclipse.cdt.core.model.ICElement; import org.eclipse.cdt.core.model.ICElement;
import org.eclipse.cdt.core.model.ICProject;
import org.eclipse.cdt.core.parser.ParserLanguage;
import org.eclipse.cdt.core.parser.ParserUtil; import org.eclipse.cdt.core.parser.ParserUtil;
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.ICSearchConstants;
@ -24,12 +30,10 @@ import org.eclipse.cdt.core.search.SearchEngine;
import org.eclipse.cdt.internal.core.model.CProject; import org.eclipse.cdt.internal.core.model.CProject;
import org.eclipse.cdt.internal.ui.editor.CEditor; import org.eclipse.cdt.internal.ui.editor.CEditor;
import org.eclipse.cdt.internal.ui.editor.CEditorMessages; import org.eclipse.cdt.internal.ui.editor.CEditorMessages;
import org.eclipse.cdt.internal.ui.editor.ITranslationUnitEditorInput;
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.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.ResourcesPlugin; 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;
@ -91,34 +95,47 @@ public class OpenDefinitionAction extends SelectionParseAction implements
int selectionStart = selNode.selStart; int selectionStart = selNode.selStart;
int selectionLength = selNode.selEnd - selNode.selStart; int selectionLength = selNode.selEnd - selNode.selStart;
IFile resourceFile = null;
IASTName[] selectedNames = BLANK_NAME_ARRAY; IASTName[] selectedNames = BLANK_NAME_ARRAY;
IASTTranslationUnit tu=null;
ParserLanguage lang=null;
if (fEditor.getEditorInput() instanceof ExternalEditorInput) { if (fEditor.getEditorInput() instanceof ExternalEditorInput) {
if( fEditor.getEditorInput() instanceof ITranslationUnitEditorInput ) ExternalEditorInput input = (ExternalEditorInput)fEditor.getEditorInput();
{ try {
ITranslationUnitEditorInput ip = (ITranslationUnitEditorInput) fEditor.getEditorInput(); // get the project for the external editor input's translation unit
IResource r = ip.getTranslationUnit().getUnderlyingResource(); ICElement project = input.getTranslationUnit();
if( r.getType() == IResource.FILE ) while (!(project instanceof ICProject) && project != null) {
resourceFile = (IFile) r; project = project.getParent();
else }
{
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); operationNotAvailable(CSEARCH_OPERATION_OPERATION_UNAVAILABLE_MESSAGE);
return; return;
} }
} } else {
} IFile resourceFile = null;
else
resourceFile = fEditor.getInputFile(); resourceFile = fEditor.getInputFile();
try {
if (resourceFile != null) 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); projectName = findProjectName(resourceFile);
}
// step 1 starts here // step 1 starts here
if (resourceFile != null) selectedNames = DOMSearchUtil.getSelectedNamesFrom(tu, selectionStart, selectionLength, lang);
selectedNames = DOMSearchUtil.getSelectedNamesFrom(resourceFile, selectionStart, selectionLength);
if (selectedNames.length > 0 && selectedNames[0] != null) { // just right, only one name selected if (selectedNames.length > 0 && selectedNames[0] != null) { // just right, only one name selected
IASTName searchName = selectedNames[0]; IASTName searchName = selectedNames[0];