Universal SmartThings DTH/ Hubitat Driver logic

I need some sort of Java/Groovy dynamic compile time code generation to adjust a DTH/device’s communication logic.

When I worked with IBM Assembler, it was called a Macro. In Groovy I found compile and dynamic metacoding, but I fried many brain cells attempting to make sense of it.

I have a DTH/Device I want to make compatible with both HE and ST. The following code segment will not be executed in HE, but it does not compile (Save) in HE because HE does not support physicalgraph.
def hubAction = new physicalgraph.device.HubAction(

What I want to do is something at compile time that changes “physicalgraph” to “hubitat” on the HE platform, allowing it to compile, but my Groovy skills are not up to the task. I tried this but it throws an error on the def hubAction at Save in HE and ST. However, it provides an example of what I want to do
def getHubPlatform=(physicalgraph?.device?.HubAction ? 'physicalgraph' : 'hubitat')
def hubAction = new "${gethubPlatform}".device.HubAction(

A better way of doing this that I can’t figure out, is for something that would include or exclude chunks of code at compile time based upon the platform. So in some meta language

if ST
include SmartThings_Code
include Hubitat_Code

Any suggestions appreciated

Answering my own question. For anyone needing some guidance with this issue take a look at this