1
0
Fork 0
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:
Markus Schorn 2007-11-29 12:37:11 +00:00
parent c835ad9217
commit e07c2eaac5
7 changed files with 17 additions and 190 deletions

View file

@ -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$*/

View file

@ -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) {

View file

@ -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;

View file

@ -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;
}

View file

@ -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;
}

View file

@ -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());
}
}
}

View file

@ -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;
}