diff options
| author | Paulo Garcia | 2014-08-17 19:02:42 +0000 |
|---|---|---|
| committer | Sergey Prigogin | 2014-08-26 18:54:11 +0000 |
| commit | 3bfe2d21a74cacf0bc45d83e805c95fe727f4543 (patch) | |
| tree | 159ed39561ee31b3b2c8a50e0186d14abb5620df | |
| parent | 9e13f237de4b6c1796b08d67ebf011dd36cdb344 (diff) | |
| download | org.eclipse.cdt-3bfe2d21a74cacf0bc45d83e805c95fe727f4543.tar.gz org.eclipse.cdt-3bfe2d21a74cacf0bc45d83e805c95fe727f4543.tar.xz org.eclipse.cdt-3bfe2d21a74cacf0bc45d83e805c95fe727f4543.zip | |
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>
| -rw-r--r-- | core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/c/hover/CSourceHover.java | 34 |
1 files changed, 33 insertions, 1 deletions
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 541357f797e..a39b43e203a 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 @@ -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); } @@ -250,6 +254,34 @@ public class CSourceHover extends AbstractCEditorTextHover { } /** + * 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, * and the first name which yields source is taken. |
