Skip to content

Commit

Permalink
Support properties from inheritance and associations
Browse files Browse the repository at this point in the history
  • Loading branch information
aziemchawdhary-gs committed Jul 30, 2024
1 parent a9b0ff1 commit 0413c08
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -242,4 +242,26 @@ public void testReactivateNewOverrideDefaultValues()
"}\n");
execute("test::f1():Boolean[1]");
}

@Test
public void testReactivateNewDefaultValueInheritance()
{
compileTestSource("testSource.pure",
"Class test::A\n" +
"{\n" +
" a:Boolean[1] = true;\n" +
"}\n" +
"\n" +
"Class test::B extends test::A\n" +
"{\n" +
" b:Boolean[1] = true;\n" +
"}\n" +
"function test::f():Boolean[1]\n" +
"{\n" +
" let l = {| ^test::B()};\n" +
" let b = $l.expressionSequence->evaluateAndDeactivate()->toOne()->reactivate()->cast(@test::B)->toOne();\n" +
" assert($b.a, | 'Default value for property b set to wrong value');\n" +
"}\n");
execute("test::f():Boolean[1]");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
import org.finos.legend.pure.m3.navigation.Instance;
import org.finos.legend.pure.m3.navigation.M3Paths;
import org.finos.legend.pure.m3.navigation.ProcessorSupport;
import org.finos.legend.pure.m3.navigation._class._Class;
import org.finos.legend.pure.m3.navigation.generictype.GenericType;
import org.finos.legend.pure.m4.coreinstance.CoreInstance;
import org.finos.legend.pure.m4.coreinstance.SourceInformation;
Expand Down Expand Up @@ -718,23 +719,28 @@ public static Object newObject(Bridge bridge, org.finos.legend.pure.m3.coreinsta
Class<?> c = ((CompiledExecutionSupport) es).getClassLoader().loadClass(JavaPackageAndImportBuilder.platformJavaPackage() + "." + Pure.elementToPath(aClass, "_", true) + "_Impl");
Any result = (Any) c.getConstructor(String.class).newInstance(name);
// Set default values
aClass._properties().forEach(new CheckedProcedure<Property<?, ?>>()
RichIterable<CoreInstance> classProperties = _Class.getSimpleProperties(aClass, ((CompiledExecutionSupport) es).getProcessorSupport());
classProperties.forEach(new CheckedProcedure<CoreInstance>()
{
@Override
public void safeValue(Property<?, ?> p) throws Exception
public void safeValue(CoreInstance p) throws Exception
{
DefaultValue defaultValue = p._defaultValue();
if (defaultValue != null)
if (p instanceof Property<?, ?>)
{
Object res = reactivate(defaultValue._functionDefinition()._expressionSequence().getFirst(), new PureMap(Maps.fixedSize.empty()), bridge, es);
Method method = c.getMethod("_" + p._name(), RichIterable.class);
if (res instanceof RichIterable)
Property<?, ?> prop = (Property<?, ?>) p;
DefaultValue defaultValue = prop._defaultValue();
if (defaultValue != null)
{
method.invoke(result, res);
}
else
{
method.invoke(result, Lists.fixedSize.of(res));
Object res = reactivate(defaultValue._functionDefinition()._expressionSequence().getFirst(), new PureMap(Maps.fixedSize.empty()), bridge, es);
Method method = c.getMethod("_" + prop._name(), RichIterable.class);
if (res instanceof RichIterable)
{
method.invoke(result, res);
}
else
{
method.invoke(result, Lists.fixedSize.of(res));
}
}
}
}
Expand Down

0 comments on commit 0413c08

Please sign in to comment.