diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/SemanticHighlightingTest.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/SemanticHighlightingTest.java index 388986fb141..7ef4f2cfd95 100644 --- a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/SemanticHighlightingTest.java +++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/SemanticHighlightingTest.java @@ -465,7 +465,7 @@ public class SemanticHighlightingTest extends TestCase { // struct Duration {}; //$class // Duration operator "" _d(unsigned long long); //$class,functionDeclaration - // Duration dur = 1000_d; //$class,globalVariable,overloadedOperator + // Duration dur = 1000_d; //$class,globalVariable,udlSuffix public void testUserDefinedLiteralSuffix_484617() throws Exception { makeAssertions(); } @@ -697,35 +697,48 @@ public class SemanticHighlightingTest extends TestCase { makeAssertions(); } + // float operator""if(long double) { //$functionDeclaration + // return 1.6f; + // } + // int main() { //$functionDeclaration + // auto k = 1.3if; //$localVariableDeclaration,udlSuffix + // } + public void testUDLOperatorIfCall_527954() throws Exception { + makeAssertions(); + } + // float operator""if(long double) { //$functionDeclaration // return 1.6f; // } // int main() { //$functionDeclaration // auto k = 1.3if; //$localVariableDeclaration,overloadedOperator // } - public void testOverriddenUDLOperatorIfCall_527954() throws Exception { - makeAssertions(); + public void testOverriddenUDLOperatorIfCallnoUDL_539535() throws Exception { + Set ignoredHighlightings = new HashSet<>(); + ignoredHighlightings.add(SemanticHighlightings.UDL_SUFFIX); + makeAssertions(ignoredHighlightings); } // float operator""if(long double) { //$functionDeclaration // return 1.6f; // } // int main() { //$functionDeclaration - // auto k = 1.3if; //$localVariableDeclaration,c_default + // auto k = 1.3if; //$localVariableDeclaration // } - public void testUDLOperatorIfCall_527954() throws Exception { + public void testUDLOperatorIfCallnoUDLnoOperator_539535() throws Exception { Set ignoredHighlightings = new HashSet<>(); + ignoredHighlightings.add(SemanticHighlightings.UDL_SUFFIX); ignoredHighlightings.add(SemanticHighlightings.OVERLOADED_OPERATOR); makeAssertions(ignoredHighlightings); } - + // int operator""int(long double) { //$functionDeclaration // return -1; // } // int main() { //$functionDeclaration - // auto k = 1.3int; //$localVariableDeclaration,overloadedOperator + // auto k = 1.3int; //$localVariableDeclaration,udlSuffix // } - public void testOverriddenUDLOperatorIntCall_527954() throws Exception { + public void testUDLOperatorIntCall_527954() throws Exception { makeAssertions(); } @@ -733,10 +746,23 @@ public class SemanticHighlightingTest extends TestCase { // return -1; // } // int main() { //$functionDeclaration - // auto k = 1.3int; //$localVariableDeclaration,c_default + // auto k = 1.3int; //$localVariableDeclaration,overloadedOperator // } - public void testUDLOperatorIntCall_527954() throws Exception { + public void testUDLOperatorIntCallnoUDL_539535() throws Exception { Set ignoredHighlightings = new HashSet<>(); + ignoredHighlightings.add(SemanticHighlightings.UDL_SUFFIX); + makeAssertions(ignoredHighlightings); + } + + // int operator""int(long double) { //$functionDeclaration + // return -1; + // } + // int main() { //$functionDeclaration + // auto k = 1.3int; //$localVariableDeclaration + // } + public void testUDLOperatorIntCallnoUDLnoOperator_539535() throws Exception { + Set ignoredHighlightings = new HashSet<>(); + ignoredHighlightings.add(SemanticHighlightings.UDL_SUFFIX); ignoredHighlightings.add(SemanticHighlightings.OVERLOADED_OPERATOR); makeAssertions(ignoredHighlightings); } diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/CEditorMessages.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/CEditorMessages.java index 9fc67d1236b..7875844b469 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/CEditorMessages.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/CEditorMessages.java @@ -108,6 +108,7 @@ public final class CEditorMessages extends NLS { public static String SemanticHighlighting_problem; public static String SemanticHighlighting_externalSDK; public static String SemanticHighlighting_variablePassedByNonConstReference; + public static String SemanticHighlighting_udlSuffix; public static String CEditor_markOccurrences_job_name; public static String CEditorActionContributor_ExpandSelectionMenu_label; public static String IndexUpdateRequestor_job_name; diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/CEditorMessages.properties b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/CEditorMessages.properties index 94301175855..b632ad14e94 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/CEditorMessages.properties +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/CEditorMessages.properties @@ -105,6 +105,7 @@ SemanticHighlighting_label= Labels SemanticHighlighting_problem= Problems SemanticHighlighting_externalSDK= External SDK calls SemanticHighlighting_variablePassedByNonConstReference= Variables passed by non-const reference +SemanticHighlighting_udlSuffix= User-defined literal suffixes CEditor_markOccurrences_job_name= Occurrences Marker CEditorActionContributor_ExpandSelectionMenu_label=E&xpand Selection To diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/SemanticHighlightings.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/SemanticHighlightings.java index cf20d4668a8..f821724b0ad 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/SemanticHighlightings.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/SemanticHighlightings.java @@ -225,7 +225,12 @@ public class SemanticHighlightings { * A named preference part that controls the highlighting of variables passed by non-const reference. */ public static final String VARIABLE_PASSED_BY_NONCONST_REF= "variablePassedByNonconstRef"; //$NON-NLS-1$ - + + /** + * A named preference part that controls the highlighting UDL suffixes. + */ + public static final String UDL_SUFFIX = "udlSuffix"; //$NON-NLS-1$ + /** Init debugging mode */ private static final boolean DEBUG= Boolean.parseBoolean(Platform.getDebugOption("org.eclipse.cdt.ui/debug/SemanticHighlighting")); //$NON-NLS-1$ @@ -1813,19 +1818,16 @@ public class SemanticHighlightings { /** * Semantic highlighting for context-sensitive UDL like operator""if(...). - * - * This does not get its own color and style; rather, it uses - * the color and style of the 'Default' syntactic highlighting. */ - private static final class ContextSensitiveUDLHighlighting extends SemanticHighlighting { + private static final class ContextSensitiveUDLHighlighting extends SemanticHighlightingWithOwnPreference { @Override public String getPreferenceKey() { - return ICColorConstants.C_DEFAULT; + return UDL_SUFFIX; } @Override public boolean isEnabledByDefault() { - return true; + return false; } @Override @@ -1838,6 +1840,16 @@ public class SemanticHighlightings { IASTNode node = token.getNode(); return node instanceof IASTImplicitName && node.getParent() instanceof ICPPASTLiteralExpression; } + + @Override + public RGB getDefaultDefaultTextColor() { + return new RGB(92, 53, 102); // dark violet; + } + + @Override + public String getDisplayName() { + return CEditorMessages.SemanticHighlighting_udlSuffix; + } } private static boolean heuristicallyResolvesToEnumeration(ICPPUnknownBinding binding) { @@ -1999,6 +2011,7 @@ public class SemanticHighlightings { highlightings.put(new Key(110), new LocalVariableHighlighting()); highlightings.put(new Key(120), new GlobalVariableHighlighting()); highlightings.put(new Key(130), new TemplateParameterHighlighting()); // before template arguments! + highlightings.put(new Key(139), new ContextSensitiveUDLHighlighting()); // before overload operator highlightings.put(new Key(140), new OverloadedOperatorHighlighting()); // before both method and function highlightings.put(new Key(150), new MethodHighlighting()); // before types to get ctors highlightings.put(new Key(160), new EnumHighlighting()); @@ -2011,7 +2024,6 @@ public class SemanticHighlightings { highlightings.put(new Key(230), new EnumeratorHighlighting()); highlightings.put(new Key(240), new ContextSensitiveKeywordHighlighting()); highlightings.put(new Key(250), new VariablePassedByNonconstRefHighlighting()); - highlightings.put(new Key(260), new ContextSensitiveUDLHighlighting()); } private static final String ExtensionPoint = "semanticHighlighting"; //$NON-NLS-1$ diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/preferences/ColorSettingPreviewCode.txt b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/preferences/ColorSettingPreviewCode.txt index d563238f06f..19a3b6812b2 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/preferences/ColorSettingPreviewCode.txt +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/preferences/ColorSettingPreviewCode.txt @@ -1,12 +1,19 @@ /* This is sample C++ code */ #include +#include #define MACRO(x) x using namespace std; // This comment may span only this line typedef unsigned int uint; +double operator""_d(unsigned long long i) { + return static_cast(i); +} int static myfunc(uint parameter) { if (parameter == 0) fprintf(stdout, "zero\n"); cout << "hello\n"; + using std::complex_literals; + auto c = 13if; + auto k = 13_d; return parameter - 1; } void mutator(int&);