Skip to content

Commit

Permalink
Fixing message name that should not take a capital first letter autom…
Browse files Browse the repository at this point in the history
…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
peifeng-unity committed Jul 15, 2021
1 parent 2b31119 commit e3860b9
Showing 1 changed file with 11 additions and 13 deletions.
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");
Expand All @@ -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
{
Expand Down Expand Up @@ -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
{
Expand All @@ -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
Expand Down Expand Up @@ -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>
Expand All @@ -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(""))
Expand All @@ -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(
Expand All @@ -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(
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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";
}
Expand Down Expand Up @@ -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";
}
Expand Down

0 comments on commit e3860b9

Please sign in to comment.