1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-23 14:42:11 +02:00

Bug 285126 - Added capability to show enum's integer value instead of

its constant name. 

Change-Id: Iacda2b19dc22497db60f88cf301d01d8654ca0ad
Signed-off-by: Paulo Garcia <pgarcia@qnx.com>
Reviewed-on: https://git.eclipse.org/r/31807
Reviewed-by: Sergey Prigogin <eclipse.sprigogin@gmail.com>
Tested-by: Sergey Prigogin <eclipse.sprigogin@gmail.com>
This commit is contained in:
Paulo Garcia 2014-08-17 15:02:42 -04:00 committed by Sergey Prigogin
parent 9e13f237de
commit 3bfe2d21a7

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2002, 2012 QNX Software Systems and others.
* Copyright (c) 2002, 2014 QNX Software Systems 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
@ -9,6 +9,7 @@
* QNX Software Systems - Initial API and implementation
* Anton Leherbauer (Wind River Systems)
* Sergey Prigogin (Google)
* Paulo Garcia (BlackBerry)
*******************************************************************************/
package org.eclipse.cdt.internal.ui.text.c.hover;
@ -209,6 +210,9 @@ public class CSourceHover extends AbstractCEditorTextHover {
}
} else if (binding instanceof IMacroBinding) {
fSource= computeSourceForMacro(ast, name, binding);
} else if (binding instanceof IEnumerator) {
// Show integer value for enumerators (bug 285126).
fSource= computeSourceForEnumerator(ast, (IEnumerator) binding);
} else {
fSource= computeSourceForBinding(ast, binding);
}
@ -249,6 +253,34 @@ public class CSourceHover extends AbstractCEditorTextHover {
return null;
}
/**
* Computes the source for a enumerator. If the value of the enumerator can be retrieved,
* the method will return a string with the value, otherwise it will fall back showing
* the enumerator constant.
*
* @param ast the AST of the translation unit
* @param binding the binding of the enumerator name
* @return the enumerator value, source or <code>null</code>
* @throws CoreException
*/
private String computeSourceForEnumerator(IASTTranslationUnit ast, IEnumerator binding)
throws CoreException {
Long numValue = binding.getValue().numericalValue();
if (numValue != null) {
return numValue.toString();
} else {
// Search for the enumerator definition
IName[] defs = ast.getDefinitions(binding);
for (IName def : defs) {
String source= computeSourceForName(def, binding);
if (source != null) {
return source;
}
}
}
return null;
}
/**
* Find a definition or declaration for the given binding and returns the source for it.
* Definitions are preferred over declarations. In case of multiple definitions or declarations,