mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-09-10 12:03:16 +02:00
Bug 536201 Add a highlighting for enum classes
Change-Id: I6b16efbbb268f9fdc4a884e96c30192dd64c5db1 Signed-off-by: Bassem Girgis <brgirgis@gmail.com>
This commit is contained in:
parent
ceb44294ad
commit
8d8324ae14
6 changed files with 117 additions and 22 deletions
|
@ -81,7 +81,7 @@ public class SemanticHighlightingTest extends TestCase {
|
||||||
private IASTTranslationUnit fAST;
|
private IASTTranslationUnit fAST;
|
||||||
|
|
||||||
// The highlighted positions stored in the document don't store any information
|
// The highlighted positions stored in the document don't store any information
|
||||||
// that directly identifies which highligting they are for. To recover this
|
// that directly identifies which highlighting they are for. To recover this
|
||||||
// information, we assign a different color to each highlighting, and then
|
// information, we assign a different color to each highlighting, and then
|
||||||
// look up the highlighting's preference key based on the color.
|
// look up the highlighting's preference key based on the color.
|
||||||
private Map<RGB, String> fColorToPreferenceKeyMap;
|
private Map<RGB, String> fColorToPreferenceKeyMap;
|
||||||
|
@ -260,7 +260,7 @@ public class SemanticHighlightingTest extends TestCase {
|
||||||
|
|
||||||
// void SDKFunction();
|
// void SDKFunction();
|
||||||
// class SDKClass { public: void SDKMethod(); };\n\n";
|
// class SDKClass { public: void SDKMethod(); };\n\n";
|
||||||
|
|
||||||
//#define INT int //$macroDefinition
|
//#define INT int //$macroDefinition
|
||||||
//#define FUNCTION_MACRO(arg) globalFunc(arg) //$macroDefinition
|
//#define FUNCTION_MACRO(arg) globalFunc(arg) //$macroDefinition
|
||||||
//#define EMPTY_MACRO(arg) //$macroDefinition
|
//#define EMPTY_MACRO(arg) //$macroDefinition
|
||||||
|
@ -430,6 +430,30 @@ public class SemanticHighlightingTest extends TestCase {
|
||||||
public void testVariousHighlightings() throws Exception {
|
public void testVariousHighlightings() throws Exception {
|
||||||
makeAssertions();
|
makeAssertions();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//enum class EnumerationClass { //$enumClass
|
||||||
|
// enumerator //$enumerator
|
||||||
|
//};
|
||||||
|
//
|
||||||
|
//class Base1 {}; //$class
|
||||||
|
//class Base2 {}; //$class
|
||||||
|
//
|
||||||
|
//class ClassContainer : Base1, Base2 { //$class,class,class
|
||||||
|
//
|
||||||
|
//public:
|
||||||
|
// enum class pubEnumerationClass {pubEnum}; //$enumClass,enumerator
|
||||||
|
//
|
||||||
|
//protected:
|
||||||
|
// enum class protEnumerationClass {protEnum}; //$enumClass,enumerator
|
||||||
|
//
|
||||||
|
//private:
|
||||||
|
// enum class privEnumerationClass {privEnum}; //$enumClass,enumerator
|
||||||
|
//
|
||||||
|
//};
|
||||||
|
//
|
||||||
|
public void testEnumClassHighlightings() throws Exception {
|
||||||
|
makeAssertions();
|
||||||
|
}
|
||||||
|
|
||||||
// class C { //$class
|
// class C { //$class
|
||||||
// template <typename T> void bar(T); //$templateParameter,methodDeclaration,templateParameter
|
// template <typename T> void bar(T); //$templateParameter,methodDeclaration,templateParameter
|
||||||
|
@ -488,12 +512,17 @@ public class SemanticHighlightingTest extends TestCase {
|
||||||
// namespace N { //$namespace
|
// namespace N { //$namespace
|
||||||
// class C { //$class
|
// class C { //$class
|
||||||
// enum E1 {}; //$enum
|
// enum E1 {}; //$enum
|
||||||
|
// enum class EC1 {}; //$enumClass
|
||||||
// };
|
// };
|
||||||
// C::E1 e1; //$class,enum,globalVariable
|
// C::E1 e1; //$class,enum,globalVariable
|
||||||
|
// C::EC1 ec1; //$class,enumClass,globalVariable
|
||||||
// enum E2 {}; //$enum
|
// enum E2 {}; //$enum
|
||||||
|
// enum class EC2 {}; //$enumClass
|
||||||
// }
|
// }
|
||||||
// N::C::E1 e1; //$namespace,class,enum,globalVariable
|
// N::C::E1 e1; //$namespace,class,enum,globalVariable
|
||||||
|
// N::C::EC1 ec1; //$namespace,class,enumClass,globalVariable
|
||||||
// N::E2 e2; //$namespace,enum,globalVariable
|
// N::E2 e2; //$namespace,enum,globalVariable
|
||||||
|
// N::EC2 ec2; //$namespace,enumClass,globalVariable
|
||||||
public void testQualifiedEnum_485709() throws Exception {
|
public void testQualifiedEnum_485709() throws Exception {
|
||||||
makeAssertions();
|
makeAssertions();
|
||||||
}
|
}
|
||||||
|
@ -517,14 +546,14 @@ public class SemanticHighlightingTest extends TestCase {
|
||||||
// template <typename T> //$templateParameter
|
// template <typename T> //$templateParameter
|
||||||
// struct Base { //$class
|
// struct Base { //$class
|
||||||
// enum E { A }; //$enum,enumerator
|
// enum E { A }; //$enum,enumerator
|
||||||
// enum class F { B }; //$enum,enumerator
|
// enum class F { B }; //$enumClass,enumerator
|
||||||
// };
|
// };
|
||||||
// template <typename T> //$templateParameter
|
// template <typename T> //$templateParameter
|
||||||
// struct Derived : Base<T> { //$class,class,templateParameter
|
// struct Derived : Base<T> { //$class,class,templateParameter
|
||||||
// static typename Base<T>::E x //$class,templateParameter,enum,staticField
|
// static typename Base<T>::E x //$class,templateParameter,enum,staticField
|
||||||
// = Base<T>::A; //$class,templateParameter,enumerator
|
// = Base<T>::A; //$class,templateParameter,enumerator
|
||||||
// static typename Base<T>::F y //$class,templateParameter,enum,staticField
|
// static typename Base<T>::F y //$class,templateParameter,enumClass,staticField
|
||||||
// = Base<T>::F::B; //$class,templateParameter,enum,enumerator
|
// = Base<T>::F::B; //$class,templateParameter,enumClass,enumerator
|
||||||
// };
|
// };
|
||||||
public void testDependentEnum_486688() throws Exception {
|
public void testDependentEnum_486688() throws Exception {
|
||||||
makeAssertions();
|
makeAssertions();
|
||||||
|
|
|
@ -835,6 +835,12 @@
|
||||||
label="%Dummy.label"
|
label="%Dummy.label"
|
||||||
value="100, 70, 50">
|
value="100, 70, 50">
|
||||||
</colorDefinition>
|
</colorDefinition>
|
||||||
|
<colorDefinition
|
||||||
|
id="org.eclipse.cdt.ui.enumClassHighlighting"
|
||||||
|
isEditable="false"
|
||||||
|
label="%Dummy.label"
|
||||||
|
value="0, 80, 50">
|
||||||
|
</colorDefinition>
|
||||||
<colorDefinition
|
<colorDefinition
|
||||||
id="org.eclipse.cdt.ui.macroSubstitutionHighlighting"
|
id="org.eclipse.cdt.ui.macroSubstitutionHighlighting"
|
||||||
isEditable="false"
|
isEditable="false"
|
||||||
|
|
|
@ -94,6 +94,7 @@ public final class CEditorMessages extends NLS {
|
||||||
public static String SemanticHighlighting_method;
|
public static String SemanticHighlighting_method;
|
||||||
public static String SemanticHighlighting_classes;
|
public static String SemanticHighlighting_classes;
|
||||||
public static String SemanticHighlighting_enums;
|
public static String SemanticHighlighting_enums;
|
||||||
|
public static String SemanticHighlighting_enumClasses;
|
||||||
public static String SemanticHighlighting_enumerator;
|
public static String SemanticHighlighting_enumerator;
|
||||||
public static String SemanticHighlighting_templateArguments;
|
public static String SemanticHighlighting_templateArguments;
|
||||||
public static String SemanticHighlighting_templateParameter;
|
public static String SemanticHighlighting_templateParameter;
|
||||||
|
|
|
@ -91,6 +91,7 @@ SemanticHighlighting_parameterVariable= Parameter variables
|
||||||
SemanticHighlighting_method= Methods
|
SemanticHighlighting_method= Methods
|
||||||
SemanticHighlighting_classes= Classes, Structs, Unions
|
SemanticHighlighting_classes= Classes, Structs, Unions
|
||||||
SemanticHighlighting_enums= Enums
|
SemanticHighlighting_enums= Enums
|
||||||
|
SemanticHighlighting_enumClasses= Enum Classes
|
||||||
SemanticHighlighting_enumerator= Enumerators
|
SemanticHighlighting_enumerator= Enumerators
|
||||||
SemanticHighlighting_templateArguments= Template arguments
|
SemanticHighlighting_templateArguments= Template arguments
|
||||||
SemanticHighlighting_templateParameter= Template parameters
|
SemanticHighlighting_templateParameter= Template parameters
|
||||||
|
|
|
@ -76,6 +76,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespace;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPReferenceType;
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPReferenceType;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateNonTypeParameter;
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateNonTypeParameter;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameter;
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameter;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPEnumeration;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPUsingDeclaration;
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPUsingDeclaration;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.SemanticQueries;
|
import org.eclipse.cdt.core.dom.ast.cpp.SemanticQueries;
|
||||||
import org.eclipse.cdt.core.index.IIndex;
|
import org.eclipse.cdt.core.index.IIndex;
|
||||||
|
@ -176,6 +177,11 @@ public class SemanticHighlightings {
|
||||||
*/
|
*/
|
||||||
public static final String ENUM= "enum"; //$NON-NLS-1$
|
public static final String ENUM= "enum"; //$NON-NLS-1$
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A named preference part that controls the highlighting of enum classes.
|
||||||
|
*/
|
||||||
|
public static final String ENUM_CLASS= "enumClass"; //$NON-NLS-1$
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A named preference part that controls the highlighting of macro references.
|
* A named preference part that controls the highlighting of macro references.
|
||||||
*/
|
*/
|
||||||
|
@ -343,7 +349,7 @@ public class SemanticHighlightings {
|
||||||
IBinding binding= token.getBinding();
|
IBinding binding= token.getBinding();
|
||||||
if (binding instanceof IField) {
|
if (binding instanceof IField) {
|
||||||
if (binding instanceof ICPPUnknownBinding) {
|
if (binding instanceof ICPPUnknownBinding) {
|
||||||
if (heuristicallyResolvesToEnumerator((ICPPUnknownBinding) binding)) {
|
if (heuristicallyResolve((ICPPUnknownBinding) binding) instanceof IEnumerator) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1065,7 +1071,7 @@ public class SemanticHighlightings {
|
||||||
IBinding binding= token.getBinding();
|
IBinding binding= token.getBinding();
|
||||||
if (binding instanceof ICompositeType && !(binding instanceof ICPPTemplateParameter)) {
|
if (binding instanceof ICompositeType && !(binding instanceof ICPPTemplateParameter)) {
|
||||||
if (binding instanceof ICPPUnknownBinding) {
|
if (binding instanceof ICPPUnknownBinding) {
|
||||||
if (heuristicallyResolvesToEnumeration((ICPPUnknownBinding) binding)) {
|
if (heuristicallyResolve((ICPPUnknownBinding) binding) instanceof IEnumeration) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1118,13 +1124,67 @@ public class SemanticHighlightings {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
IBinding binding= token.getBinding();
|
IBinding binding= token.getBinding();
|
||||||
|
if (binding instanceof ICPPUnknownBinding) {
|
||||||
|
binding= heuristicallyResolve((ICPPUnknownBinding) binding);
|
||||||
|
}
|
||||||
if (binding instanceof IEnumeration) {
|
if (binding instanceof IEnumeration) {
|
||||||
|
if (binding instanceof ICPPEnumeration) {
|
||||||
|
return !((ICPPEnumeration) binding).isScoped();
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Semantic highlighting for enum classes.
|
||||||
|
*/
|
||||||
|
private static final class EnumClassHighlighting extends SemanticHighlightingWithOwnPreference {
|
||||||
|
@Override
|
||||||
|
public String getPreferenceKey() {
|
||||||
|
return ENUM_CLASS;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public RGB getDefaultDefaultTextColor() {
|
||||||
|
return new RGB(0, 80, 50);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isBoldByDefault() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isItalicByDefault() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isEnabledByDefault() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getDisplayName() {
|
||||||
|
return CEditorMessages.SemanticHighlighting_enumClasses;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean consumes(ISemanticToken token) {
|
||||||
|
IASTNode node= token.getNode();
|
||||||
|
if (node instanceof IASTName) {
|
||||||
|
if (node instanceof ICPPASTQualifiedName) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
IBinding binding= token.getBinding();
|
||||||
if (binding instanceof ICPPUnknownBinding) {
|
if (binding instanceof ICPPUnknownBinding) {
|
||||||
if (heuristicallyResolvesToEnumeration((ICPPUnknownBinding) binding)) {
|
binding= heuristicallyResolve((ICPPUnknownBinding) binding);
|
||||||
return true;
|
}
|
||||||
}
|
if (binding instanceof ICPPEnumeration) {
|
||||||
|
return ((ICPPEnumeration) binding).isScoped();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
@ -1419,14 +1479,12 @@ public class SemanticHighlightings {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
IBinding binding= token.getBinding();
|
IBinding binding= token.getBinding();
|
||||||
|
if (binding instanceof ICPPUnknownBinding) {
|
||||||
|
binding= heuristicallyResolve((ICPPUnknownBinding) binding);
|
||||||
|
}
|
||||||
if (binding instanceof IEnumerator) {
|
if (binding instanceof IEnumerator) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (binding instanceof ICPPUnknownBinding) {
|
|
||||||
if (heuristicallyResolvesToEnumerator((ICPPUnknownBinding) binding)) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -1852,14 +1910,12 @@ public class SemanticHighlightings {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean heuristicallyResolvesToEnumeration(ICPPUnknownBinding binding) {
|
private static IBinding heuristicallyResolve(ICPPUnknownBinding binding) {
|
||||||
IBinding[] resolved = HeuristicResolver.resolveUnknownBinding(binding);
|
IBinding[] resolved = HeuristicResolver.resolveUnknownBinding(binding);
|
||||||
return resolved.length == 1 && resolved[0] instanceof IEnumeration;
|
if (resolved.length == 1) {
|
||||||
}
|
return resolved[0];
|
||||||
|
}
|
||||||
private static boolean heuristicallyResolvesToEnumerator(ICPPUnknownBinding binding) {
|
return binding;
|
||||||
IBinding[] resolved = HeuristicResolver.resolveUnknownBinding(binding);
|
|
||||||
return resolved.length == 1 && resolved[0] instanceof IEnumerator;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Note on the get___PreferenceKey() functions below:
|
// Note on the get___PreferenceKey() functions below:
|
||||||
|
@ -2024,6 +2080,7 @@ public class SemanticHighlightings {
|
||||||
highlightings.put(new Key(230), new EnumeratorHighlighting());
|
highlightings.put(new Key(230), new EnumeratorHighlighting());
|
||||||
highlightings.put(new Key(240), new ContextSensitiveKeywordHighlighting());
|
highlightings.put(new Key(240), new ContextSensitiveKeywordHighlighting());
|
||||||
highlightings.put(new Key(250), new VariablePassedByNonconstRefHighlighting());
|
highlightings.put(new Key(250), new VariablePassedByNonconstRefHighlighting());
|
||||||
|
highlightings.put(new Key(260), new EnumClassHighlighting());
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final String ExtensionPoint = "semanticHighlighting"; //$NON-NLS-1$
|
private static final String ExtensionPoint = "semanticHighlighting"; //$NON-NLS-1$
|
||||||
|
|
|
@ -21,6 +21,7 @@ template <typename Item>
|
||||||
class MyClass {
|
class MyClass {
|
||||||
public:
|
public:
|
||||||
enum Number { ZERO, ONE, TWO };
|
enum Number { ZERO, ONE, TWO };
|
||||||
|
enum class NumberClass { ZERO, ONE, TWO };
|
||||||
static char staticField;
|
static char staticField;
|
||||||
int field;
|
int field;
|
||||||
virtual Number vmethod() const;
|
virtual Number vmethod() const;
|
||||||
|
|
Loading…
Add table
Reference in a new issue