mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
Support for extern "C" in toggle header, search, source hover and semantic highlighting.
This commit is contained in:
parent
c835ad9217
commit
e07c2eaac5
7 changed files with 17 additions and 190 deletions
|
@ -1867,11 +1867,6 @@ public class CEditor extends TextEditor implements ISelectionChangedListener, IC
|
||||||
action.setActionDefinitionId(ICEditorActionDefinitionIds.OPEN_DECL);
|
action.setActionDefinitionId(ICEditorActionDefinitionIds.OPEN_DECL);
|
||||||
setAction("OpenDeclarations", action); //$NON-NLS-1$
|
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 = new TextOperationAction(CEditorMessages.getResourceBundle(), "OpenOutline.", this, CSourceViewer.SHOW_OUTLINE, true); //$NON-NLS-1$
|
||||||
action.setActionDefinitionId(ICEditorActionDefinitionIds.OPEN_OUTLINE);
|
action.setActionDefinitionId(ICEditorActionDefinitionIds.OPEN_OUTLINE);
|
||||||
setAction("OpenOutline", action); //$NON-NLS-1$*/
|
setAction("OpenOutline", action); //$NON-NLS-1$*/
|
||||||
|
|
|
@ -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.IScope;
|
||||||
import org.eclipse.cdt.core.dom.ast.ITypedef;
|
import org.eclipse.cdt.core.dom.ast.ITypedef;
|
||||||
import org.eclipse.cdt.core.dom.ast.IVariable;
|
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.c.ICFunctionScope;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier;
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionDeclarator;
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionDeclarator;
|
||||||
|
@ -1711,27 +1712,25 @@ public class SemanticHighlightings {
|
||||||
}
|
}
|
||||||
if (name.isReference()) {
|
if (name.isReference()) {
|
||||||
IBinding binding= token.getBinding();
|
IBinding binding= token.getBinding();
|
||||||
if (binding instanceof IIndexBinding) {
|
|
||||||
IIndex index= token.getRoot().getIndex();
|
IIndex index= token.getRoot().getIndex();
|
||||||
return isExternalSDKReference((IIndexBinding)binding, index);
|
return isExternalSDKReference(binding, index);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isExternalSDKReference(IIndexBinding binding, IIndex index) {
|
private boolean isExternalSDKReference(IBinding binding, IIndex index) {
|
||||||
if (binding instanceof IFunction) {
|
if (binding instanceof IFunction) {
|
||||||
// unwrap binding from composite binding
|
|
||||||
// IIndexBinding binding2= (IIndexBinding)binding.getAdapter(IIndexBinding.class);
|
|
||||||
// if (binding2 != null) {
|
|
||||||
// binding= binding2;
|
|
||||||
// }
|
|
||||||
try {
|
try {
|
||||||
if (binding.isFileLocal()) {
|
if (binding instanceof IIndexBinding) {
|
||||||
|
if (((IIndexBinding) binding).isFileLocal()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
IIndexName[] decls= index.findDeclarations(binding);
|
}
|
||||||
|
else if (!(binding instanceof ICExternalBinding)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
IIndexName[] decls= index.findNames(binding, IIndex.FIND_DECLARATIONS | IIndex.SEARCH_ACCROSS_LANGUAGE_BOUNDARIES);
|
||||||
for (int i = 0; i < decls.length; i++) {
|
for (int i = 0; i < decls.length; i++) {
|
||||||
IIndexFile indexFile= decls[i].getFile();
|
IIndexFile indexFile= decls[i].getFile();
|
||||||
if (indexFile != null && indexFile.getLocation().getFullPath() != null) {
|
if (indexFile != null && indexFile.getLocation().getFullPath() != null) {
|
||||||
|
|
|
@ -133,9 +133,9 @@ public class ToggleSourceAndHeaderAction extends TextEditorAction {
|
||||||
final IIndexName[] partnerNames;
|
final IIndexName[] partnerNames;
|
||||||
try {
|
try {
|
||||||
if (isDefinition) {
|
if (isDefinition) {
|
||||||
partnerNames= fIndex.findNames(binding, IIndex.FIND_DECLARATIONS);
|
partnerNames= fIndex.findNames(binding, IIndex.FIND_DECLARATIONS | IIndex.SEARCH_ACCROSS_LANGUAGE_BOUNDARIES);
|
||||||
} else {
|
} else {
|
||||||
partnerNames= fIndex.findNames(binding, IIndex.FIND_DEFINITIONS);
|
partnerNames= fIndex.findNames(binding, IIndex.FIND_DEFINITIONS | IIndex.SEARCH_ACCROSS_LANGUAGE_BOUNDARIES);
|
||||||
}
|
}
|
||||||
if (partnerNames.length == 0) {
|
if (partnerNames.length == 0) {
|
||||||
++fSuspect;
|
++fSuspect;
|
||||||
|
|
|
@ -34,7 +34,7 @@ public class PDOMSearchElementQuery extends PDOMSearchQuery {
|
||||||
private ISourceReference element;
|
private ISourceReference element;
|
||||||
|
|
||||||
public PDOMSearchElementQuery(ICElement[] scope, ISourceReference element, int flags) {
|
public PDOMSearchElementQuery(ICElement[] scope, ISourceReference element, int flags) {
|
||||||
super(scope, flags);
|
super(scope, flags | IIndex.SEARCH_ACCROSS_LANGUAGE_BOUNDARIES);
|
||||||
this.element = element;
|
this.element = element;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -40,7 +40,7 @@ public class PDOMSearchTextSelectionQuery extends PDOMSearchQuery {
|
||||||
private ITextSelection selection;
|
private ITextSelection selection;
|
||||||
|
|
||||||
public PDOMSearchTextSelectionQuery(ICElement[] scope, ITranslationUnit tu, ITextSelection selection, int flags) {
|
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.tu = tu;
|
||||||
this.selection = selection;
|
this.selection = selection;
|
||||||
}
|
}
|
||||||
|
|
|
@ -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());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -517,7 +517,7 @@ public class CSourceHover extends AbstractCEditorTextHover implements ITextHover
|
||||||
IName[] declNames= ast.getDefinitionsInAST(binding);
|
IName[] declNames= ast.getDefinitionsInAST(binding);
|
||||||
if (declNames.length == 0 && ast.getIndex() != null) {
|
if (declNames.length == 0 && ast.getIndex() != null) {
|
||||||
// search definitions in index
|
// search definitions in index
|
||||||
declNames = ast.getIndex().findDefinitions(binding);
|
declNames = ast.getIndex().findNames(binding, IIndex.FIND_DEFINITIONS | IIndex.SEARCH_ACCROSS_LANGUAGE_BOUNDARIES);
|
||||||
}
|
}
|
||||||
return declNames;
|
return declNames;
|
||||||
}
|
}
|
||||||
|
@ -535,7 +535,7 @@ public class CSourceHover extends AbstractCEditorTextHover implements ITextHover
|
||||||
IName[] declNames= ast.getDeclarationsInAST(binding);
|
IName[] declNames= ast.getDeclarationsInAST(binding);
|
||||||
if (declNames.length == 0 && ast.getIndex() != null) {
|
if (declNames.length == 0 && ast.getIndex() != null) {
|
||||||
// search declarations in index
|
// 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;
|
return declNames;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue