From 01ead0227aedb9130c37f7e6e756bb6dbd1bf3df Mon Sep 17 00:00:00 2001 From: Nathan Ridge Date: Sat, 21 Jan 2017 16:10:01 -0500 Subject: [PATCH] Bug 510788 - Syntax coloring for template arguments in function template specialization Previously, the arguments shared the color of the template-name. Now, the arguments get their own colors. Change-Id: I27af4146717a19095f1ac22188eedb8a71d9466c --- .../tests/text/SemanticHighlightingTest.java | 9 +++++++ .../ui/editor/SemanticHighlightings.java | 24 ++++++++++++++++++- 2 files changed, 32 insertions(+), 1 deletion(-) 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 84eaf335357..0ff961b323b 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 @@ -634,4 +634,13 @@ public class SemanticHighlightingTest extends TestCase { public void testReferenceToConstPointer_509619() throws Exception { makeAssertions(); } + + // struct S {}; //$class + // template + // void waldo() {} //$functionDeclaration + // template <> + // void waldo() {} //$functionDeclaration,class + public void testArgumentsOfFunctionTemplateSpecialization_510788() throws Exception { + makeAssertions(); + } } 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 0142dae25c3..1a3d992348c 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 @@ -606,6 +606,20 @@ public class SemanticHighlightings { return CEditorMessages.SemanticHighlighting_functionDeclaration; } + private boolean isDeclaration(IASTName name) { + if (name.isDeclaration()) { + return true; + } + // The template-name in a template-id is never a declaration, it's a reference + // to the template. However, if the template-id itself is a declaration, we want + // to color the template-name part of it as a declaration. + if (name.getParent() instanceof ICPPASTTemplateId && + name.getPropertyInParent() == ICPPASTTemplateId.TEMPLATE_NAME) { + return ((IASTName) name.getParent()).isDeclaration(); + } + return false; + } + @Override public boolean consumes(ISemanticToken token) { IASTNode node= token.getNode(); @@ -613,8 +627,12 @@ public class SemanticHighlightings { return false; if (node instanceof IASTName) { + // Do not color an entire template-id; color its constituent parts separately. + if (node instanceof ICPPASTTemplateId) { + return false; + } IASTName name= (IASTName) node; - if (name.isDeclaration()) { + if (isDeclaration(name)) { IBinding binding= token.getBinding(); if (binding instanceof IFunction && !(binding instanceof ICPPMethod)) { return true; @@ -687,6 +705,10 @@ public class SemanticHighlightings { if (name instanceof ICPPASTQualifiedName && name.isReference()) { return false; } + // Do not color an entire template-id; color its constituent parts separately. + if (name instanceof ICPPASTTemplateId) { + return false; + } IBinding binding= token.getBinding(); if (binding instanceof IFunction && !(binding instanceof ICPPMethod)) { return true;