From e07c2eaac5b7016e5e1c56d1cfb793e7aa0ad1a6 Mon Sep 17 00:00:00 2001 From: Markus Schorn Date: Thu, 29 Nov 2007 12:37:11 +0000 Subject: [PATCH] Support for extern "C" in toggle header, search, source hover and semantic highlighting. --- .../cdt/internal/ui/editor/CEditor.java | 5 - .../ui/editor/SemanticHighlightings.java | 23 ++- .../editor/ToggleSourceAndHeaderAction.java | 4 +- .../ui/search/PDOMSearchElementQuery.java | 2 +- .../search/PDOMSearchTextSelectionQuery.java | 2 +- .../search/actions/OpenDefinitionAction.java | 167 ------------------ .../ui/text/c/hover/CSourceHover.java | 4 +- 7 files changed, 17 insertions(+), 190 deletions(-) delete mode 100644 core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/actions/OpenDefinitionAction.java diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/CEditor.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/CEditor.java index b1270ee3c70..a01103acfc1 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/CEditor.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/CEditor.java @@ -1867,11 +1867,6 @@ public class CEditor extends TextEditor implements ISelectionChangedListener, IC action.setActionDefinitionId(ICEditorActionDefinitionIds.OPEN_DECL); setAction("OpenDeclarations", action); //$NON-NLS-1$ -// removed, see bug 167162 -// action = new OpenDefinitionAction(this); -// action.setActionDefinitionId(ICEditorActionDefinitionIds.OPEN_DEF); -// setAction("OpenDefinition", action); //$NON-NLS-1$ - action = new TextOperationAction(CEditorMessages.getResourceBundle(), "OpenOutline.", this, CSourceViewer.SHOW_OUTLINE, true); //$NON-NLS-1$ action.setActionDefinitionId(ICEditorActionDefinitionIds.OPEN_OUTLINE); setAction("OpenOutline", action); //$NON-NLS-1$*/ diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/SemanticHighlightings.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/SemanticHighlightings.java index 7cd44fd223f..a2afa30a309 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/SemanticHighlightings.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/SemanticHighlightings.java @@ -37,6 +37,7 @@ import org.eclipse.cdt.core.dom.ast.IProblemBinding; import org.eclipse.cdt.core.dom.ast.IScope; import org.eclipse.cdt.core.dom.ast.ITypedef; import org.eclipse.cdt.core.dom.ast.IVariable; +import org.eclipse.cdt.core.dom.ast.c.ICExternalBinding; import org.eclipse.cdt.core.dom.ast.c.ICFunctionScope; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionDeclarator; @@ -1711,27 +1712,25 @@ public class SemanticHighlightings { } if (name.isReference()) { IBinding binding= token.getBinding(); - if (binding instanceof IIndexBinding) { - IIndex index= token.getRoot().getIndex(); - return isExternalSDKReference((IIndexBinding)binding, index); - } + IIndex index= token.getRoot().getIndex(); + return isExternalSDKReference(binding, index); } } return false; } - private boolean isExternalSDKReference(IIndexBinding binding, IIndex index) { + private boolean isExternalSDKReference(IBinding binding, IIndex index) { if (binding instanceof IFunction) { - // unwrap binding from composite binding -// IIndexBinding binding2= (IIndexBinding)binding.getAdapter(IIndexBinding.class); -// if (binding2 != null) { -// binding= binding2; -// } try { - if (binding.isFileLocal()) { + if (binding instanceof IIndexBinding) { + if (((IIndexBinding) binding).isFileLocal()) { + return false; + } + } + else if (!(binding instanceof ICExternalBinding)) { return false; } - IIndexName[] decls= index.findDeclarations(binding); + IIndexName[] decls= index.findNames(binding, IIndex.FIND_DECLARATIONS | IIndex.SEARCH_ACCROSS_LANGUAGE_BOUNDARIES); for (int i = 0; i < decls.length; i++) { IIndexFile indexFile= decls[i].getFile(); if (indexFile != null && indexFile.getLocation().getFullPath() != null) { diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/ToggleSourceAndHeaderAction.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/ToggleSourceAndHeaderAction.java index be517f4ea53..60249b15b1f 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/ToggleSourceAndHeaderAction.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/ToggleSourceAndHeaderAction.java @@ -133,9 +133,9 @@ public class ToggleSourceAndHeaderAction extends TextEditorAction { final IIndexName[] partnerNames; try { if (isDefinition) { - partnerNames= fIndex.findNames(binding, IIndex.FIND_DECLARATIONS); + partnerNames= fIndex.findNames(binding, IIndex.FIND_DECLARATIONS | IIndex.SEARCH_ACCROSS_LANGUAGE_BOUNDARIES); } else { - partnerNames= fIndex.findNames(binding, IIndex.FIND_DEFINITIONS); + partnerNames= fIndex.findNames(binding, IIndex.FIND_DEFINITIONS | IIndex.SEARCH_ACCROSS_LANGUAGE_BOUNDARIES); } if (partnerNames.length == 0) { ++fSuspect; diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/PDOMSearchElementQuery.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/PDOMSearchElementQuery.java index 585bb8224a0..8f657c7118a 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/PDOMSearchElementQuery.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/PDOMSearchElementQuery.java @@ -34,7 +34,7 @@ public class PDOMSearchElementQuery extends PDOMSearchQuery { private ISourceReference element; public PDOMSearchElementQuery(ICElement[] scope, ISourceReference element, int flags) { - super(scope, flags); + super(scope, flags | IIndex.SEARCH_ACCROSS_LANGUAGE_BOUNDARIES); this.element = element; } diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/PDOMSearchTextSelectionQuery.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/PDOMSearchTextSelectionQuery.java index 72baaecb48f..878d41b818f 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/PDOMSearchTextSelectionQuery.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/PDOMSearchTextSelectionQuery.java @@ -40,7 +40,7 @@ public class PDOMSearchTextSelectionQuery extends PDOMSearchQuery { private ITextSelection selection; public PDOMSearchTextSelectionQuery(ICElement[] scope, ITranslationUnit tu, ITextSelection selection, int flags) { - super(scope, flags); + super(scope, flags | IIndex.SEARCH_ACCROSS_LANGUAGE_BOUNDARIES); this.tu = tu; this.selection = selection; } 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 deleted file mode 100644 index 8b9246a2354..00000000000 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/actions/OpenDefinitionAction.java +++ /dev/null @@ -1,167 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2005, 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * Markus Schorn (Wind River Systems) - * Ed Swartz (Nokia) - *******************************************************************************/ -package org.eclipse.cdt.internal.ui.search.actions; - -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IPath; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.NullProgressMonitor; -import org.eclipse.core.runtime.Path; -import org.eclipse.core.runtime.Status; -import org.eclipse.core.runtime.jobs.Job; -import org.eclipse.jface.text.ITextSelection; -import org.eclipse.swt.widgets.Display; - -import org.eclipse.cdt.core.CCorePlugin; -import org.eclipse.cdt.core.dom.IName; -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.dom.ast.IBinding; -import org.eclipse.cdt.core.index.IIndex; -import org.eclipse.cdt.core.index.IIndexManager; -import org.eclipse.cdt.core.model.ITranslationUnit; -import org.eclipse.cdt.core.model.IWorkingCopy; -import org.eclipse.cdt.ui.CUIPlugin; - -import org.eclipse.cdt.internal.ui.editor.CEditor; -import org.eclipse.cdt.internal.ui.editor.CEditorMessages; - -/** - * Open Definition Action (Ctrl+F3). - * - * @deprecated use {@link OpenDeclarationsAction}. - */ -public class OpenDefinitionAction extends SelectionParseAction { - - public static final IASTName[] BLANK_NAME_ARRAY = new IASTName[0]; - ITextSelection selNode; - - /** - * Creates a new action with the given editor - */ - public OpenDefinitionAction(CEditor editor) { - super( editor ); - setText(CEditorMessages.getString("OpenDefinition.label")); //$NON-NLS-1$ - setToolTipText(CEditorMessages.getString("OpenDefinition.tooltip")); //$NON-NLS-1$ - setDescription(CEditorMessages.getString("OpenDefinition.description")); //$NON-NLS-1$ - } - - private class Runner extends Job { - Runner() { - super(CEditorMessages.getString("OpenDeclarations.label")); //$NON-NLS-1$ - } - - protected IStatus run(IProgressMonitor monitor) { - try { - clearStatusLine(); - - int selectionStart = selNode.getOffset(); - int selectionLength = selNode.getLength(); - - IWorkingCopy workingCopy = CUIPlugin.getDefault().getWorkingCopyManager().getWorkingCopy(fEditor.getEditorInput()); - if (workingCopy == null) - return Status.CANCEL_STATUS; - - IIndex index= CCorePlugin.getIndexManager().getIndex(workingCopy.getCProject(), - IIndexManager.ADD_DEPENDENCIES | IIndexManager.ADD_DEPENDENT); - try { - index.acquireReadLock(); - } catch (InterruptedException e1) { - return Status.CANCEL_STATUS; - } - try { - 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]; - - IBinding binding = searchName.resolveBinding(); - if (binding != null) { - final IName[] declNames = ast.getDefinitions(binding); - 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(); - - runInUIThread(new Runnable() { - public void run() { - try { - open(path, offset, length); - } catch (CoreException e) { - CUIPlugin.getDefault().log(e); - } - } - }); - break; - } - } - } - if (!found) { - reportSymbolLookupFailure(new String(searchName.toCharArray())); - } - } else { - reportSelectionMatchFailure(); - } - } - finally { - index.releaseReadLock(); - } - - - return Status.OK_STATUS; - } catch (CoreException e) { - return e.getStatus(); - } - } - } - - public void run() { - selNode = getSelectedStringFromEditor(); - if (selNode != null) { - new Runner().schedule(); - } - } - - /** - * For the purpose of regression testing. - * @since 4.0 - */ - private void runInUIThread(Runnable runnable) { - if (Display.getCurrent() != null) { - runnable.run(); - } - else { - Display.getDefault().asyncExec(runnable); - } - } - - /** - * For the purpose of regression testing. - * @since 4.0 - */ - public void runSync() { - selNode = getSelectedStringFromEditor(); - if (selNode != null) { - new Runner().run(new NullProgressMonitor()); - } - } - -} diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/c/hover/CSourceHover.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/c/hover/CSourceHover.java index 5d8b7977983..bbb8189f10c 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/c/hover/CSourceHover.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/c/hover/CSourceHover.java @@ -517,7 +517,7 @@ public class CSourceHover extends AbstractCEditorTextHover implements ITextHover IName[] declNames= ast.getDefinitionsInAST(binding); if (declNames.length == 0 && ast.getIndex() != null) { // search definitions in index - declNames = ast.getIndex().findDefinitions(binding); + declNames = ast.getIndex().findNames(binding, IIndex.FIND_DEFINITIONS | IIndex.SEARCH_ACCROSS_LANGUAGE_BOUNDARIES); } return declNames; } @@ -535,7 +535,7 @@ public class CSourceHover extends AbstractCEditorTextHover implements ITextHover IName[] declNames= ast.getDeclarationsInAST(binding); if (declNames.length == 0 && ast.getIndex() != null) { // search declarations in index - declNames= ast.getIndex().findNames(binding, IIndex.FIND_DECLARATIONS); + declNames= ast.getIndex().findNames(binding, IIndex.FIND_DECLARATIONS | IIndex.SEARCH_ACCROSS_LANGUAGE_BOUNDARIES); } return declNames; }