btc-ag / service-idl

Xtext-based Service IDL (Interface Definition Language) and Code Generators for Protobuf, C++, Java and .NET
Eclipse Public License 2.0
8 stars 8 forks source link

Error if struct member name contains underscore #67

Closed sebastianhaberey closed 6 years ago

sebastianhaberey commented 6 years ago

The error below was thrown during compilation of the generated source code. Removing the underscores in member names fixed it.

[INFO] Compiling 22 source files to D:\Diverse\Idea\netcalc\target\netcalc-generated\java\btc.cab.netcalc\target\classes
[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] /D:/Diverse/Idea/netcalc/target/netcalc-generated/java/btc.cab.netcalc/src/main/java/com/btc/cab/netcalc/protobuf/TypesCodec.java:[236,17] cannot find symbol
  symbol:   method setP_mw(java.lang.Double)
  location: variable builder of type com.btc.cab.netcalc.protobuf.Types.ComplexPower.Builder
[ERROR] /D:/Diverse/Idea/netcalc/target/netcalc-generated/java/btc.cab.netcalc/src/main/java/com/btc/cab/netcalc/protobuf/TypesCodec.java:[237,17] cannot find symbol
  symbol:   method setQ_mvar(java.lang.Double)
  location: variable builder of type com.btc.cab.netcalc.protobuf.Types.ComplexPower.Builder
[ERROR] /D:/Diverse/Idea/netcalc/target/netcalc-generated/java/btc.cab.netcalc/src/main/java/com/btc/cab/netcalc/protobuf/TypesCodec.java:[246,17] cannot find symbol
  symbol:   method setMagnitude_kv(java.lang.Double)
  location: variable builder of type com.btc.cab.netcalc.protobuf.Types.ComplexVoltage.Builder
[ERROR] /D:/Diverse/Idea/netcalc/target/netcalc-generated/java/btc.cab.netcalc/src/main/java/com/btc/cab/netcalc/protobuf/TypesCodec.java:[247,17] cannot find symbol
  symbol:   method setAngle_degree(java.lang.Double)
  location: variable builder of type com.btc.cab.netcalc.protobuf.Types.ComplexVoltage.Builder
[ERROR] /D:/Diverse/Idea/netcalc/target/netcalc-generated/java/btc.cab.netcalc/src/main/java/com/btc/cab/netcalc/protobuf/TypesCodec.java:[775,33] cannot find symbol
  symbol:   method getP_mw()
  location: variable typedData of type com.btc.cab.netcalc.protobuf.Types.ComplexPower
[ERROR] /D:/Diverse/Idea/netcalc/target/netcalc-generated/java/btc.cab.netcalc/src/main/java/com/btc/cab/netcalc/protobuf/TypesCodec.java:[776,35] cannot find symbol
  symbol:   method getQ_mvar()
  location: variable typedData of type com.btc.cab.netcalc.protobuf.Types.ComplexPower
[ERROR] /D:/Diverse/Idea/netcalc/target/netcalc-generated/java/btc.cab.netcalc/src/main/java/com/btc/cab/netcalc/protobuf/TypesCodec.java:[786,41] cannot find symbol
  symbol:   method getMagnitude_kv()
  location: variable typedData of type com.btc.cab.netcalc.protobuf.Types.ComplexVoltage
[ERROR] /D:/Diverse/Idea/netcalc/target/netcalc-generated/java/btc.cab.netcalc/src/main/java/com/btc/cab/netcalc/protobuf/TypesCodec.java:[787,41] cannot find symbol
  symbol:   method getAngle_degree()
  location: variable typedData of type com.btc.cab.netcalc.protobuf.Types.ComplexVoltage
sigiesec commented 6 years ago

Please include a (minimalized) IDL file that triggers the error.

sebastianhaberey commented 6 years ago

The following IDL generates ok but throws the above error on compilation of the Java module:

module foo
{
    struct ComplexPower
    {
        double p_MW;
        double q_Mvar;
    };
}
sigiesec commented 6 years ago

Reproduced this here: https://ci.bop-dev.de/job/cab/job/BF/job/serviceidl-integrationtests/job/sigiesec%252Fadd-test-case-with-underscore/2/

sigiesec commented 6 years ago

This is due to assumptions of the Protobuf Compiler on naming conventions. Cf. https://developers.google.com/protocol-buffers/docs/javatutorial:

Notice how these accessor methods use camel-case naming, even though the .proto file uses lowercase-with-underscores. This transformation is done automatically by the protocol buffer compiler so that the generated classes match standard Java style conventions.

sigiesec commented 6 years ago

com.google.common.base.CaseFormat can be used for converting

sigiesec commented 6 years ago

See also #90

Note that the names in your example do not follow any common naming convention (camelCase, PascalCase, lower_snake_case, UPPER_SNAKE_CASE). This might be impossible to support properly, even if we allow using SnakeCase in the IDL file.

I will try to fix this anyway.

sigiesec commented 6 years ago

Fixed by #96

sigiesec commented 6 years ago

There are still some issues, e.g. with the BTC.GA.FieldLink test case.