1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +02:00

Handling ambiguous enumerations in navigation, bug 209550.

This commit is contained in:
Markus Schorn 2008-03-05 13:15:13 +00:00
parent b4d5bb7a67
commit 4aa0c4245a
2 changed files with 294 additions and 254 deletions

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2003, 2007 IBM Corporation and others.
* Copyright (c) 2003, 2008 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
@ -10,20 +10,14 @@
* Markus Schorn (Wind River Systems)
* Gerhard Schaber (Wind River Systems)
*******************************************************************************/
/*
* Created on Jun 24, 2003
*/
package org.eclipse.cdt.core.model.util;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.IPath;
import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.model.CModelException;
import org.eclipse.cdt.core.model.IBinary;
import org.eclipse.cdt.core.model.ICContainer;
import org.eclipse.cdt.core.model.ICElement;
import org.eclipse.cdt.core.model.IEnumerator;
import org.eclipse.cdt.core.model.IField;
import org.eclipse.cdt.core.model.IFunctionDeclaration;
import org.eclipse.cdt.core.model.IInheritance;
@ -35,6 +29,9 @@ import org.eclipse.cdt.core.model.ITypeDef;
import org.eclipse.cdt.core.model.IVariableDeclaration;
import org.eclipse.cdt.core.parser.ast.ASTAccessVisibility;
import org.eclipse.cdt.internal.core.model.CoreModelMessages;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.IPath;
/**
* Creates labels for ICElement objects.
@ -258,6 +255,9 @@ public class CElementBaseLabels {
case ICElement.C_VARIABLE_DECLARATION:
getVariableLabel( (IVariableDeclaration) element, flags, buf);
break;
case ICElement.C_ENUMERATOR:
getEnumeratorLabel((IEnumerator) element, flags, buf);
break;
case ICElement.C_CLASS:
case ICElement.C_STRUCT:
case ICElement.C_UNION:
@ -505,6 +505,41 @@ public class CElementBaseLabels {
}
}
/**
* Appends the label for an enumerator to a StringBuffer.
* @param var an enumerator
* @param flags any of the F_* flags, and MF_POST_FILE_QUALIFIED
* @param buf the buffer to append the label
*/
public static void getEnumeratorLabel(IEnumerator var, int flags, StringBuffer buf ) {
//qualification
if( getFlag( flags, F_FULLY_QUALIFIED ) ){
ICElement parent = var.getParent();
if (parent != null && parent.exists() && parent.getElementType() == ICElement.C_NAMESPACE) {
getTypeLabel( parent, T_FULLY_QUALIFIED, buf );
buf.append( "::" ); //$NON-NLS-1$
}
}
buf.append( var.getElementName() );
// post qualification
if( getFlag(flags, F_POST_QUALIFIED)) {
ICElement parent = var.getParent();
if (parent != null && parent.exists() && parent.getElementType() == ICElement.C_NAMESPACE) {
buf.append( CONCAT_STRING );
getTypeLabel( var.getParent(), T_FULLY_QUALIFIED, buf );
}
}
if( getFlag(flags, MF_POST_FILE_QUALIFIED)) {
IPath path= var.getPath();
if (path != null) {
buf.append( CONCAT_STRING );
buf.append(path.toString());
}
}
}
/**
* Appends the label for a function declaration to a StringBuffer.
* @param func a function declaration

View file

@ -68,10 +68,32 @@ import org.eclipse.cdt.internal.ui.editor.CEditor;
import org.eclipse.cdt.internal.ui.editor.CEditorMessages;
import org.eclipse.cdt.internal.ui.viewsupport.IndexUI;
public class OpenDeclarationsAction extends SelectionParseAction {
public class OpenDeclarationsAction extends SelectionParseAction implements ASTRunnable {
public static boolean sIsJUnitTest = false;
public static final IASTName[] BLANK_NAME_ARRAY = new IASTName[0];
ITextSelection selNode;
private static final int KIND_OTHER = 0;
private static final int KIND_USING_DECL = 1;
private static final int KIND_DEFINITION = 2;
private class WrapperJob extends Job {
WrapperJob() {
super(CEditorMessages.getString("OpenDeclarations.dialog.title")); //$NON-NLS-1$
}
@Override
protected IStatus run(IProgressMonitor monitor) {
try {
return performNavigation(monitor);
}
catch (CoreException e) {
return e.getStatus();
}
}
}
ITextSelection fTextSelection;
private IWorkingCopy fWorkingCopy;
private IIndex fIndex;
/**
* Creates a new action with the given editor
@ -83,21 +105,8 @@ public class OpenDeclarationsAction extends SelectionParseAction {
setDescription(CEditorMessages.getString("OpenDeclarations.description")); //$NON-NLS-1$
}
private class Runner extends Job implements ASTRunnable {
private static final int KIND_OTHER = 0;
private static final int KIND_USING_DECL = 1;
private static final int KIND_DEFINITION = 2;
private IWorkingCopy fWorkingCopy;
private IIndex fIndex;
Runner() {
super(CEditorMessages.getString("OpenDeclarations.dialog.title")); //$NON-NLS-1$
}
@Override
protected IStatus run(IProgressMonitor monitor) {
try {
protected IStatus performNavigation(IProgressMonitor monitor) throws CoreException {
clearStatusLine();
fWorkingCopy = CUIPlugin.getDefault().getWorkingCopyManager().getWorkingCopy(fEditor.getEditorInput());
@ -118,17 +127,14 @@ public class OpenDeclarationsAction extends SelectionParseAction {
} finally {
fIndex.releaseReadLock();
}
} catch (CoreException e) {
return e.getStatus();
}
}
public IStatus runOnAST(ILanguage lang, IASTTranslationUnit ast) throws CoreException {
if (ast == null) {
return Status.OK_STATUS;
}
int selectionStart = selNode.getOffset();
int selectionLength = selNode.getLength();
int selectionStart = fTextSelection.getOffset();
int selectionLength = fTextSelection.getLength();
IASTName searchName= ast.getNodeSelector(null).findEnclosingName(selectionStart, selectionLength);
if (searchName != null) { // just right, only one name selected
@ -369,13 +375,12 @@ public class OpenDeclarationsAction extends SelectionParseAction {
}
return declNames;
}
}
@Override
public void run() {
selNode = getSelectedStringFromEditor();
if (selNode != null) {
new Runner().schedule();
fTextSelection = getSelectedStringFromEditor();
if (fTextSelection != null) {
new WrapperJob().schedule();
}
}
@ -392,10 +397,10 @@ public class OpenDeclarationsAction extends SelectionParseAction {
* For the purpose of regression testing.
* @since 4.0
*/
public void runSync() {
selNode = getSelectedStringFromEditor();
if (selNode != null) {
new Runner().run(new NullProgressMonitor());
public void runSync() throws CoreException {
fTextSelection = getSelectedStringFromEditor();
if (fTextSelection != null) {
performNavigation(new NullProgressMonitor());
}
}
}