Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNathan Ridge2017-01-21 16:10:01 -0500
committerNathan Ridge2017-02-04 14:34:50 -0500
commit01ead0227aedb9130c37f7e6e756bb6dbd1bf3df (patch)
treec83ebae6a4b3660885000fa72001686533efa409
parentaeb39d63523f63ca996881acec9dc27f8ed38f2f (diff)
downloadorg.eclipse.cdt-01ead0227aedb9130c37f7e6e756bb6dbd1bf3df.tar.gz
org.eclipse.cdt-01ead0227aedb9130c37f7e6e756bb6dbd1bf3df.tar.xz
org.eclipse.cdt-01ead0227aedb9130c37f7e6e756bb6dbd1bf3df.zip
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
-rw-r--r--core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/SemanticHighlightingTest.java9
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/SemanticHighlightings.java24
2 files changed, 32 insertions, 1 deletions
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 84eaf33535..0ff961b323 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 <typename>
+ // void waldo() {} //$functionDeclaration
+ // template <>
+ // void waldo<S>() {} //$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 0142dae25c..1a3d992348 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;

Back to the top