1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-23 06:32:10 +02:00

Fix for 185221 by Ed Swartz, show errors when navigation fails.

This commit is contained in:
Markus Schorn 2007-05-03 13:33:21 +00:00
parent b98e65a84c
commit c44c95ce01
5 changed files with 77 additions and 13 deletions

View file

@ -147,3 +147,7 @@ PDOMSearch.query.defs.label = Find definitions of
PDOMSearch.query.decls.label = Find declarations of
PDOMSearchPatternQuery.PatternQuery_labelPatternInScope={0} {1} in {2}
PDOMSearch.query.pattern.error = Illegal Search String
SelectionParseAction.FileOpenFailure.format=Could not open file ''{0}'', verify index is up-to-date
SelectionParseAction.SelectedTextNotSymbol.message=Selected text cannot be mapped to a symbol name
SelectionParseAction.SymbolNotFoundInIndex.format=Could not find symbol ''{0}'' in index
SelectionParseAction.IncludeNotFound.format=Could not find include file ''{0}'' on include paths

View file

@ -15,6 +15,7 @@ import org.eclipse.cdt.core.model.ICElement;
import org.eclipse.cdt.core.model.ISourceReference;
import org.eclipse.cdt.core.model.ITranslationUnit;
import org.eclipse.cdt.internal.ui.editor.CEditor;
import org.eclipse.cdt.internal.ui.search.CSearchMessages;
import org.eclipse.cdt.internal.ui.search.PDOMSearchElementQuery;
import org.eclipse.cdt.internal.ui.search.PDOMSearchTextSelectionQuery;
import org.eclipse.jface.text.ITextSelection;
@ -57,7 +58,7 @@ public abstract class FindAction extends SelectionParseAction {
}
if (searchJob == null) {
operationNotAvailable(CSEARCH_OPERATION_OPERATION_UNAVAILABLE_MESSAGE);
showStatusLineMessage(CSearchMessages.getString(CSEARCH_OPERATION_OPERATION_UNAVAILABLE_MESSAGE));
return;
}

View file

@ -64,6 +64,8 @@ public class OpenDeclarationsAction extends SelectionParseAction {
protected IStatus run(IProgressMonitor monitor) {
try {
clearStatusLine();
int selectionStart = selNode.getOffset();
int selectionLength = selNode.getLength();
@ -80,6 +82,7 @@ public class OpenDeclarationsAction extends SelectionParseAction {
return Status.CANCEL_STATUS;
}
try {
IASTTranslationUnit ast=
ASTProvider.getASTProvider().getAST(
@ -87,6 +90,7 @@ public class OpenDeclarationsAction extends SelectionParseAction {
IASTName[] selectedNames = workingCopy.getLanguage().getSelectedNames(ast, selectionStart, selectionLength);
if (selectedNames.length > 0 && selectedNames[0] != null) { // just right, only one name selected
boolean found = false;
IASTName searchName = selectedNames[0];
boolean isDefinition= searchName.isDefinition();
IBinding binding = searchName.resolveBinding();
@ -105,6 +109,8 @@ public class OpenDeclarationsAction extends SelectionParseAction {
for (int i = 0; i < declNames.length; i++) {
IASTFileLocation fileloc = declNames[i].getFileLocation();
if (fileloc != null) {
found = true;
final IPath path = new Path(fileloc.getFileName());
final int offset = fileloc.getNodeOffset();
final int length = fileloc.getNodeLength();
@ -122,22 +128,29 @@ public class OpenDeclarationsAction extends SelectionParseAction {
}
}
}
if (!found) {
reportSymbolLookupFailure(new String(searchName.toCharArray()));
}
} else {
// Check if we're in an include statement
IASTPreprocessorStatement[] preprocs = ast.getAllPreprocessorStatements();
boolean foundInInclude = false;
for (int i = 0; i < preprocs.length; ++i) {
if (!(preprocs[i] instanceof IASTPreprocessorIncludeStatement))
continue;
IASTPreprocessorIncludeStatement incStmt = (IASTPreprocessorIncludeStatement)preprocs[i];
if (!incStmt.isResolved())
continue;
IASTFileLocation loc = preprocs[i].getFileLocation();
if (loc != null
&& loc.getFileName().equals(ast.getFilePath())
&& loc.getNodeOffset() < selectionStart
&& loc.getNodeOffset() + loc.getNodeLength() > selectionStart) {
// Got it
String name = incStmt.getPath();
foundInInclude = true;
String name = null;
if (incStmt.isResolved())
name = incStmt.getPath();
if (name != null) {
final IPath path = new Path(name);
runInUIThread(new Runnable() {
@ -149,9 +162,15 @@ public class OpenDeclarationsAction extends SelectionParseAction {
}
}
});
} else {
reportIncludeLookupFailure(new String(incStmt.getName().toCharArray()));
}
break;
}
if (!foundInInclude) {
reportSelectionMatchFailure();
}
}
}
} finally {

View file

@ -65,6 +65,8 @@ public class OpenDefinitionAction extends SelectionParseAction {
protected IStatus run(IProgressMonitor monitor) {
try {
clearStatusLine();
int selectionStart = selNode.getOffset();
int selectionLength = selNode.getLength();
@ -83,6 +85,7 @@ public class OpenDefinitionAction extends SelectionParseAction {
IASTTranslationUnit ast = workingCopy.getAST(index, ITranslationUnit.AST_SKIP_ALL_HEADERS);
IASTName[] selectedNames = workingCopy.getLanguage().getSelectedNames(ast, selectionStart, selectionLength);
boolean found = false;
if (selectedNames.length > 0 && selectedNames[0] != null) { // just right, only one name selected
IASTName searchName = selectedNames[0];
@ -91,8 +94,9 @@ public class OpenDefinitionAction extends SelectionParseAction {
final IName[] declNames = ast.getDefinitions(binding);
for (int i = 0; i < declNames.length; i++) {
IASTFileLocation fileloc = declNames[i].getFileLocation();
// no source location - TODO spit out an error in the status bar
if (fileloc != null) {
found = true;
final IPath path = new Path(fileloc.getFileName());
final int offset = fileloc.getNodeOffset();
final int length = fileloc.getNodeLength();
@ -110,12 +114,18 @@ public class OpenDefinitionAction extends SelectionParseAction {
}
}
}
if (!found) {
reportSymbolLookupFailure(new String(searchName.toCharArray()));
}
} else {
reportSelectionMatchFailure();
}
}
finally {
index.releaseReadLock();
}
return Status.OK_STATUS;
} catch (CoreException e) {
return e.getStatus();

View file

@ -8,10 +8,13 @@
* Contributors:
* IBM Corp. - Rational Software - initial implementation
* Markus Schorn (Wind River Systems)
* Ed Swartz (Nokia)
*******************************************************************************/
package org.eclipse.cdt.internal.ui.search.actions;
import java.text.MessageFormat;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;
@ -70,7 +73,7 @@ public class SelectionParseAction extends Action {
return fSite;
}
protected void operationNotAvailable(final String message) {
protected void showStatusLineMessage(final String message) {
// run the code to update the status line on the Display thread
// this way any other thread can invoke operationNotAvailable(String)
CUIPlugin.getStandardDisplay().asyncExec(new Runnable(){
@ -86,7 +89,7 @@ public class SelectionParseAction extends Action {
statusManager = ((IEditorSite) fSite).getActionBars().getStatusLineManager();
}
if( statusManager != null )
statusManager.setErrorMessage(CSearchMessages.getString(message));
statusManager.setErrorMessage(message);
}
});
}
@ -226,10 +229,13 @@ public class SelectionParseAction extends Action {
* @param name
*/
protected void open(IName name) throws CoreException {
clearStatusLine();
IASTFileLocation fileloc = name.getFileLocation();
if (fileloc == null)
// no source location - TODO spit out an error in the status bar
if (fileloc == null) {
reportSymbolLookupFailure(new String(name.toCharArray()));
return;
}
IPath path = new Path(fileloc.getFileName());
int currentOffset = fileloc.getNodeOffset();
@ -239,12 +245,14 @@ public class SelectionParseAction extends Action {
}
protected void open(IPath path, int currentOffset, int currentLength) throws CoreException {
clearStatusLine();
IEditorPart editor = EditorUtility.openInEditor(path, fEditor.getInputCElement());
if (editor instanceof ITextEditor) {
ITextEditor textEditor = (ITextEditor)editor;
textEditor.selectAndReveal(currentOffset, currentLength);
} else {
// TODO: report error
reportSourceFileOpenFailure(path);
}
}
@ -252,4 +260,26 @@ public class SelectionParseAction extends Action {
setEnabled(getSelectedStringFromEditor() != null);
}
protected void reportSourceFileOpenFailure(IPath path) {
showStatusLineMessage(MessageFormat.format(
CSearchMessages.getString("SelectionParseAction.FileOpenFailure.format"), //$NON-NLS-1$
new String[] { path.toOSString() }));
}
protected void reportSelectionMatchFailure() {
showStatusLineMessage(CSearchMessages.getString("SelectionParseAction.SelectedTextNotSymbol.message")); //$NON-NLS-1$
}
protected void reportSymbolLookupFailure(String symbol) {
showStatusLineMessage(MessageFormat.format(
CSearchMessages.getString("SelectionParseAction.SymbolNotFoundInIndex.format"), //$NON-NLS-1$
new String[] { symbol }));
}
protected void reportIncludeLookupFailure(String filename) {
showStatusLineMessage(MessageFormat.format(
CSearchMessages.getString("SelectionParseAction.IncludeNotFound.format"), //$NON-NLS-1$
new String[] { filename }));
}
}