Automatically 'camelCase' method names for Java targets

Hi Carlo & all,

We have a large base of Oxygene code, with a Pascal style naming convention used throughout. So far, our primary target for that code was .NET, hence the choice of the naming convention.

Now, we are looking to compile this code for Java targets as well. Our main concern are method names, which we want in this case to comply with Java best practices and so use camelCase and not PascalCase when compiled. Renaming the methods in code is not an option as we want to keep PascalCase for our .NET targets for the same methods.

Is there any hidden option available to achieve our goal? If not, would it be possible to have this feature in Elements compiler?

Thanks!

Ken

Good question… There’s no such option currently, however you could easily accomplish it with a simple aspect, something like:

namespace ClassLibrary1;

interface
uses 
  RemObjects.Elements.Cirrus.*;

type
  [AttributeUsage(AttributeTargets.Assembly or AttributeTargets.Class or AttributeTargets.Method)]
  MethodFormatterAspect = public class(Attribute, IMethodInterfaceDecorator)
  private
  protected
  public
    method HandleInterface(Services: IServices; aMethod: IMethodDefinition);
    begin 
      var lName := aMethod.Name;
      if (length(lName) > 2) and Char.IsUpper(lName[0]) and (Char.IsLower(lName[1])) then begin
        lName := lName.Substring(0, 1).ToLowerInvariant + lName.Substring(1);
        aMethod.Name := lName;
      end;
    end;
  end;

implementation

end.

(Seems there’s a bug in ebuild references to Cirrus libs which I’ve logged which makes this not work, once it’s fixed i’ll update this post)

Thanks Carlo, the Cirrus-based approach looks very interesting. We didn’t use Cirrus before, so my next question may be quite lame, but do I understand right that Cirrus is a fully build-time tool, i.e. using Cirrus aspects won’t make our compiled binaries dependent on Cirrus?

Thanks!

Ken

correct.

Cool, thanks Marc!

Hi Carlo,

Has the references issue been fixed yet? We are eager to try Cirrus :).

Thanks!

Ken

It’s fixed on the ebuild level (so building should be fine); It also works as project reference, but not regular reference in the VS ide yet (but is fine in the file); that part is still open.

Great, thanks! We’re building everything from command line, so should be ok for us. Is it included in build 10.0.0.2321?

yes 2321 should be fine.

No, .2323.

Hi Carlo, Marc,

So I’ve finally set up my ebuild-driven processes and am ready to continue with this goal. I started with writing a simple aspect as Carlo had suggested above, and packed that into an Elements .NET project, as suggested here. That compiles just fine into a tiny .NET assembly (MyCirrusAspects.dll).

Now, I want to plug that aspect in when compiling my Oxygene code for Java platform to camelise the names. This is where I’m stuck. What would be the right way to reference the aspect assembly in my Elements project? I tried referencing MyCirrusAspects.dll via “Reference Include=…” but that gives me “Reference 'MyCirrusAspects” could not be resolved for target ‘Cooper’ (Cooper Plain jvm)." I believe some special trick is needed here to pass a .NET assembly to the compiler when compiling a Java target, is that correct?

I tried to find an answer in the docs and samples but unfortunately without luck. Could you please help?

I am using EBuild version 10.0.0.2331.

Thanks!

Ken

No, this should just work as is, the was fixed a few weeks ago. Can you send me your solution so i can have a look at why it doesn’t;t work for you? Is this a project reference or a regular .dll reference?

thanx,
marc

something like:


    <Reference Include="ClassLibrary1.dll">
      <Private>True</Private>
      <Cirrus>True</Cirrus>
      <HintPath>..\ClassLibrary1\Bin\Debug\ClassLibrary1.dll</HintPath>
    </Reference>

should work for you. IsCirrusref is the key here.

Cirrus shouldn’t even matter, afaik.

Thanks for your quick replies guys! It was actually HintPath that I was missing. For some reason EBuild didn’t find the aspect DLL by its name, even though it was residing in one of AdditionalReferencePaths directories. I guess that should’ve been because building a Cooper target it was looking for .jars and not .dlls. Anyway, the things do compile just fine now.

On a side note, Marc, you were correct, the Cirrus flag didn’t matter.

Thanks!

Just a quick follow-up - I can confirm that the aspect is actually picked up and applied just as we expect it to. Thanks again for all your help!

Ken

1 Like

Let us know if you have some problems with the aspect logic.

Yeah, those are checked for platform references only. Cirrus references are only located directly or via the explicit CirrusReferences xml files. I suppose I could/should add an additional setting one can provide for cirrus search paths. I’ll log an issue.

Thanks, logged as bugs://81137

bugs://81137 got closed with status wontfix.