-
Notifications
You must be signed in to change notification settings - Fork 97
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixing message name that should not take a capital first letter autom…
…atically (#47) * Fixing message name that should not take a capital first letter automatically * Adding warning when a message file name starts with a lowercase character
- Loading branch information
1 parent
2b31119
commit e3860b9
Showing
1 changed file
with
11 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
/* | ||
/* | ||
© Siemens AG, 2019 | ||
Author: Sifan Ye ([email protected]) | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
|
@@ -13,11 +13,11 @@ limitations under the License. | |
*/ | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Collections.Generic; | ||
using UnityEngine; | ||
|
||
namespace Unity.Robotics.ROSTCPConnector.MessageGeneration | ||
namespace RosMessageGeneration | ||
{ | ||
public class MessageParser | ||
{ | ||
|
@@ -63,7 +63,7 @@ public MessageParser(List<MessageToken> tokens, string outPath, string rosPackag | |
|
||
if (className.Equals("")) | ||
{ | ||
this.className = MsgAutoGenUtilities.MessageClassPrefix + MsgAutoGenUtilities.CapitalizeFirstLetter(inFileName); | ||
this.className = MsgAutoGenUtilities.CapitalizeFirstLetter(inFileName); | ||
} | ||
else | ||
{ | ||
|
@@ -73,7 +73,7 @@ public MessageParser(List<MessageToken> tokens, string outPath, string rosPackag | |
if (rosMsgName.Equals("")) | ||
{ | ||
if (Char.IsLower(inFileName[0])) | ||
Debug.LogWarningFormat("File {0} starts with a lowercase character. Message file names should be PascalCased (see : http://wiki.ros.org/ROS/Patterns/Conventions#line-38)", inFileName); | ||
Debug.LogWarningFormat("File {0} starts with a lowercase character. Message file names should be CamelCased (see : http://wiki.ros.org/ROS/Patterns/Conventions#line-38)", inFileName); | ||
this.rosMsgName = inFileName; | ||
} | ||
else | ||
|
@@ -211,7 +211,7 @@ private void Declaration() | |
if (PeekType(MessageTokenType.BuiltInType)) | ||
{ | ||
type = builtInTypeMapping[MatchByType(MessageTokenType.BuiltInType)]; | ||
if (!type.Equals("MTime") && !type.Equals("MDuration")) | ||
if (!type.Equals("Time") && !type.Equals("Duration")) | ||
{ | ||
// Time and Duration can't have constant declaration | ||
// See <wiki.ros.org/msg> | ||
|
@@ -233,7 +233,6 @@ private void Declaration() | |
switch (hierarchy.Length) | ||
{ | ||
case 1: | ||
type = MsgAutoGenUtilities.MessageClassPrefix + type; | ||
break; | ||
case 2: | ||
if (hierarchy[0].Equals("") || hierarchy[1].Equals("")) | ||
|
@@ -244,8 +243,7 @@ private void Declaration() | |
} | ||
string package = MsgAutoGenUtilities.ResolvePackageName(hierarchy[0]); | ||
// Do not add package name if exists in current namespace | ||
type = package.Equals(rosPackageNamespace) ? MsgAutoGenUtilities.MessageClassPrefix + hierarchy[1] : | ||
package + "." + MsgAutoGenUtilities.MessageClassPrefix + hierarchy[1]; | ||
type = package.Equals(rosPackageNamespace) ? hierarchy[1] : package + "." + hierarchy[1]; | ||
break; | ||
default: | ||
throw new MessageParserException( | ||
|
@@ -255,7 +253,7 @@ private void Declaration() | |
} | ||
else | ||
{ | ||
type = MsgAutoGenUtilities.MessageClassPrefix + MatchByType(MessageTokenType.Header); | ||
type = MatchByType(MessageTokenType.Header); | ||
if (PeekType(MessageTokenType.FixedSizeArray) || PeekType(MessageTokenType.VariableSizeArray)) | ||
{ | ||
Warn( | ||
|
@@ -560,7 +558,7 @@ private string GenerateImports() | |
importsStr += "using System.Linq;\n"; | ||
importsStr += "using System.Collections.Generic;\n"; | ||
importsStr += "using System.Text;\n"; | ||
importsStr += "using Unity.Robotics.ROSTCPConnector.MessageGeneration;\n"; | ||
importsStr += "using RosMessageGeneration;\n"; | ||
|
||
if (imports.Count > 0) | ||
{ | ||
|
@@ -731,7 +729,7 @@ private string GenerateDeserializationStatements() | |
|
||
} | ||
// Message is a custom type and call it's serialization function. Time and duration are special cases | ||
else if (!MsgAutoGenUtilities.builtInTypesMapping.ContainsValue(type) || type.Equals("MTime") || type.Equals("MDuration")) | ||
else if (!MsgAutoGenUtilities.builtInTypesMapping.ContainsValue(type) || type.Equals("Time") || type.Equals("Duration")) | ||
{ | ||
function += MsgAutoGenUtilities.TWO_TABS + MsgAutoGenUtilities.ONE_TAB + "offset = this." + identifier + ".Deserialize(data, offset);\n"; | ||
} | ||
|
@@ -834,7 +832,7 @@ private string GenerateSerializationStatements() | |
"listOfSerializations.Add(new[]{(byte)this." + identifier + "});\n"; | ||
} | ||
// Message is a custom type and call it's serialization function | ||
else if (!MsgAutoGenUtilities.builtInTypesMapping.ContainsValue(type) || type.Equals("MTime") || type.Equals("MDuration")) | ||
else if (!MsgAutoGenUtilities.builtInTypesMapping.ContainsValue(type) || type.Equals("Time") || type.Equals("Duration")) | ||
{ | ||
function += MsgAutoGenUtilities.TWO_TABS + MsgAutoGenUtilities.ONE_TAB + "listOfSerializations.AddRange(" + identifier + ".SerializationStatements());\n"; | ||
} | ||
|