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:
parent
c338788697
commit
d5663f5134
6 changed files with 238 additions and 91 deletions
|
@ -50,6 +50,7 @@ import org.eclipse.cdt.core.search.ICSearchConstants.SearchFor;
|
|||
import org.eclipse.cdt.internal.core.search.matching.CSearchPattern;
|
||||
import org.eclipse.core.resources.IFile;
|
||||
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.
|
||||
|
@ -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;
|
||||
* 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 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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1226,6 +1226,11 @@ public class DOMAST extends ViewPart {
|
|||
IFile aFile = ((CEditor)editor).getInputFile();
|
||||
|
||||
// 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();
|
||||
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);
|
||||
|
@ -1247,6 +1252,10 @@ public class DOMAST extends ViewPart {
|
|||
}
|
||||
|
||||
public static ParserLanguage getLanguageFromFile(IFile file) {
|
||||
if (file == null) { // assume CPP
|
||||
return ParserLanguage.CPP;
|
||||
}
|
||||
|
||||
IProject project = file.getProject();
|
||||
ICFileType type = CCorePlugin.getDefault().getFileType(project, file.getFullPath().lastSegment());
|
||||
String lid = type.getLanguage().getId();
|
||||
|
|
|
@ -19,6 +19,7 @@ import org.eclipse.cdt.core.CCorePlugin;
|
|||
import org.eclipse.cdt.core.ICLogConstants;
|
||||
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.ASTTypeUtil;
|
||||
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
|
||||
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.c.ICExternalBinding;
|
||||
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.ParserLanguage;
|
||||
import org.eclipse.cdt.core.search.DOMSearchUtil;
|
||||
|
@ -148,9 +150,10 @@ public abstract class FindAction extends SelectionParseAction {
|
|||
if( obj == null || !(obj instanceof ICElement ) ){
|
||||
operationNotAvailable(CSEARCH_OPERATION_OPERATION_UNAVAILABLE_MESSAGE);
|
||||
return;
|
||||
} else {
|
||||
clearStatusLine();
|
||||
}
|
||||
|
||||
clearStatusLine();
|
||||
|
||||
ICElement element = (ICElement) obj;
|
||||
|
||||
CSearchQuery job = createSearchQuery( element.getElementName(), CSearchUtil.getSearchForFromElement(element));
|
||||
|
@ -191,23 +194,18 @@ public abstract class FindAction extends SelectionParseAction {
|
|||
|
||||
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;
|
||||
}
|
||||
IASTNode foundNode = null;
|
||||
IASTTranslationUnit tu = null;
|
||||
ParserLanguage lang = null;
|
||||
String file = null;
|
||||
|
||||
resourceFile = fEditor.getInputFile();
|
||||
|
||||
IASTTranslationUnit tu = null;
|
||||
IASTNode foundNode = null;
|
||||
|
||||
ParseWithProgress runnable = new ParseWithProgress(resourceFile);
|
||||
ParseWithProgress runnable = new ParseWithProgress();
|
||||
ProgressMonitorDialog progressMonitor = new ProgressMonitorDialog(fEditor.getSite().getShell());
|
||||
try {
|
||||
progressMonitor.run(true, true, runnable);
|
||||
tu = runnable.getTu();
|
||||
file = runnable.getFile();
|
||||
lang = runnable.getLang();
|
||||
} catch (InvocationTargetException e1) {
|
||||
operationNotAvailable(CSEARCH_OPERATION_OPERATION_UNAVAILABLE_MESSAGE);
|
||||
return;
|
||||
|
@ -215,15 +213,7 @@ public abstract class FindAction extends SelectionParseAction {
|
|||
operationNotAvailable(CSEARCH_OPERATION_OPERATION_UNAVAILABLE_MESSAGE);
|
||||
return;
|
||||
}
|
||||
|
||||
String file=null;
|
||||
if( resourceFile != null )
|
||||
file = resourceFile.getLocation().toOSString();
|
||||
else
|
||||
{
|
||||
if( resourceFile instanceof ExternalEditorInput )
|
||||
file = ((ExternalEditorInput)resourceFile).getStorage().getFullPath().toOSString();
|
||||
}
|
||||
|
||||
try{
|
||||
foundNode = tu.selectNodeForLocation(file, selNode.selStart, selNode.selEnd - selNode.selStart);
|
||||
}
|
||||
|
@ -231,7 +221,7 @@ public abstract class FindAction extends SelectionParseAction {
|
|||
catch (Exception ex){}
|
||||
catch ( VirtualMachineError vmErr){
|
||||
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;
|
||||
} else {
|
||||
ASTVisitor collector = null;
|
||||
if (DOMSearchUtil.getLanguageFromFile(resourceFile) == ParserLanguage.CPP) {
|
||||
if (lang == ParserLanguage.CPP) {
|
||||
collector = new DOMSearchUtil.CPPNameCollector();
|
||||
} else {
|
||||
collector = new DOMSearchUtil.CNameCollector();
|
||||
|
@ -289,28 +279,62 @@ public abstract class FindAction extends SelectionParseAction {
|
|||
|
||||
private class ParseWithProgress implements IRunnableWithProgress
|
||||
{
|
||||
private IFile file=null;
|
||||
private IASTTranslationUnit tu = null;
|
||||
private String file=null;
|
||||
private ParserLanguage lang=null;
|
||||
|
||||
public ParseWithProgress(IFile file) {
|
||||
this.file = file;
|
||||
}
|
||||
public ParseWithProgress() {}
|
||||
|
||||
public void run(IProgressMonitor monitor) {
|
||||
try {
|
||||
tu = CDOM.getInstance().getASTService().getTranslationUnit(
|
||||
file,
|
||||
CDOM.getInstance().getCodeReaderFactory(
|
||||
CDOM.PARSE_WORKING_COPY_WHENEVER_POSSIBLE));
|
||||
} catch (IASTServiceProvider.UnsupportedDialectException e) {
|
||||
operationNotAvailable(CSEARCH_OPERATION_OPERATION_UNAVAILABLE_MESSAGE);
|
||||
return;
|
||||
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 {
|
||||
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;
|
||||
}
|
||||
|
||||
file = resourceFile.getLocation().toOSString();
|
||||
lang = DOMSearchUtil.getLanguageFromFile(resourceFile);
|
||||
}
|
||||
}
|
||||
|
||||
public IASTTranslationUnit getTu() {
|
||||
return tu;
|
||||
}
|
||||
|
||||
public String getFile() {
|
||||
return file;
|
||||
}
|
||||
|
||||
public ParserLanguage getLang() {
|
||||
return lang;
|
||||
}
|
||||
};
|
||||
|
||||
abstract protected String getScopeDescription();
|
||||
|
|
|
@ -10,15 +10,12 @@
|
|||
******************************************************************************/
|
||||
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.ICSearchScope;
|
||||
import org.eclipse.cdt.core.search.SearchEngine;
|
||||
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.search.CSearchMessages;
|
||||
import org.eclipse.core.resources.IProject;
|
||||
import org.eclipse.ui.IWorkbenchSite;
|
||||
|
||||
|
||||
|
|
|
@ -14,9 +14,15 @@ package org.eclipse.cdt.internal.ui.search.actions;
|
|||
import java.util.Iterator;
|
||||
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.IASTName;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
|
||||
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.search.DOMSearchUtil;
|
||||
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.ui.editor.CEditor;
|
||||
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.ui.CUIPlugin;
|
||||
import org.eclipse.core.resources.IFile;
|
||||
import org.eclipse.core.resources.IProject;
|
||||
import org.eclipse.core.resources.IResource;
|
||||
import org.eclipse.core.resources.ResourcesPlugin;
|
||||
import org.eclipse.core.runtime.IProgressMonitor;
|
||||
import org.eclipse.jface.dialogs.ProgressMonitorDialog;
|
||||
|
@ -79,34 +83,47 @@ public class OpenDeclarationsAction extends SelectionParseAction implements IUpd
|
|||
int selectionStart = selNode.selStart;
|
||||
int selectionLength = selNode.selEnd - selNode.selStart;
|
||||
|
||||
IFile resourceFile = null;
|
||||
|
||||
IASTName[] selectedNames = BLANK_NAME_ARRAY;
|
||||
if (fEditor.getEditorInput() instanceof ExternalEditorInput) {
|
||||
if( fEditor.getEditorInput() instanceof ITranslationUnitEditorInput )
|
||||
{
|
||||
ITranslationUnitEditorInput ip = (ITranslationUnitEditorInput) fEditor.getEditorInput();
|
||||
IResource r = ip.getTranslationUnit().getUnderlyingResource();
|
||||
if( r.getType() == IResource.FILE )
|
||||
resourceFile = (IFile) r;
|
||||
else
|
||||
{
|
||||
operationNotAvailable(CSEARCH_OPERATION_OPERATION_UNAVAILABLE_MESSAGE);
|
||||
return;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
resourceFile = fEditor.getInputFile();
|
||||
IASTTranslationUnit tu=null;
|
||||
ParserLanguage lang=null;
|
||||
|
||||
|
||||
if (resourceFile != null)
|
||||
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());
|
||||
projectName = ((ICProject)project).getElementName();
|
||||
}
|
||||
} catch (UnsupportedDialectException e) {
|
||||
operationNotAvailable(CSEARCH_OPERATION_OPERATION_UNAVAILABLE_MESSAGE);
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
IFile resourceFile = null;
|
||||
resourceFile = fEditor.getInputFile();
|
||||
|
||||
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
|
||||
if (resourceFile != null)
|
||||
selectedNames = DOMSearchUtil.getSelectedNamesFrom(resourceFile, selectionStart, selectionLength);
|
||||
selectedNames = DOMSearchUtil.getSelectedNamesFrom(tu, selectionStart, selectionLength, lang);
|
||||
|
||||
if (selectedNames.length > 0 && selectedNames[0] != null) { // just right, only one name selected
|
||||
IASTName searchName = selectedNames[0];
|
||||
|
|
|
@ -13,9 +13,15 @@ package org.eclipse.cdt.internal.ui.search.actions;
|
|||
import java.util.Iterator;
|
||||
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.IASTName;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
|
||||
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.search.DOMSearchUtil;
|
||||
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.ui.editor.CEditor;
|
||||
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.ui.CUIPlugin;
|
||||
import org.eclipse.core.resources.IFile;
|
||||
import org.eclipse.core.resources.IProject;
|
||||
import org.eclipse.core.resources.IResource;
|
||||
import org.eclipse.core.resources.ResourcesPlugin;
|
||||
import org.eclipse.core.runtime.IProgressMonitor;
|
||||
import org.eclipse.jface.dialogs.ProgressMonitorDialog;
|
||||
|
@ -91,34 +95,47 @@ public class OpenDefinitionAction extends SelectionParseAction implements
|
|||
int selectionStart = selNode.selStart;
|
||||
int selectionLength = selNode.selEnd - selNode.selStart;
|
||||
|
||||
IFile resourceFile = null;
|
||||
|
||||
IASTName[] selectedNames = BLANK_NAME_ARRAY;
|
||||
if (fEditor.getEditorInput() instanceof ExternalEditorInput) {
|
||||
if( fEditor.getEditorInput() instanceof ITranslationUnitEditorInput )
|
||||
{
|
||||
ITranslationUnitEditorInput ip = (ITranslationUnitEditorInput) fEditor.getEditorInput();
|
||||
IResource r = ip.getTranslationUnit().getUnderlyingResource();
|
||||
if( r.getType() == IResource.FILE )
|
||||
resourceFile = (IFile) r;
|
||||
else
|
||||
{
|
||||
operationNotAvailable(CSEARCH_OPERATION_OPERATION_UNAVAILABLE_MESSAGE);
|
||||
return;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
resourceFile = fEditor.getInputFile();
|
||||
IASTTranslationUnit tu=null;
|
||||
ParserLanguage lang=null;
|
||||
|
||||
|
||||
if (resourceFile != null)
|
||||
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());
|
||||
projectName = ((ICProject)project).getElementName();
|
||||
}
|
||||
} catch (UnsupportedDialectException e) {
|
||||
operationNotAvailable(CSEARCH_OPERATION_OPERATION_UNAVAILABLE_MESSAGE);
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
IFile resourceFile = null;
|
||||
resourceFile = fEditor.getInputFile();
|
||||
|
||||
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
|
||||
if (resourceFile != null)
|
||||
selectedNames = DOMSearchUtil.getSelectedNamesFrom(resourceFile, selectionStart, selectionLength);
|
||||
selectedNames = DOMSearchUtil.getSelectedNamesFrom(tu, selectionStart, selectionLength, lang);
|
||||
|
||||
if (selectedNames.length > 0 && selectedNames[0] != null) { // just right, only one name selected
|
||||
IASTName searchName = selectedNames[0];
|
||||
|
|
Loading…
Add table
Reference in a new issue