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?
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?
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.
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?
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?
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.
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.