Skip to content

Commit

Permalink
Fix inappropriate source info in milestoning properties
Browse files Browse the repository at this point in the history
  • Loading branch information
kevin-m-knight-gs committed Nov 13, 2024
1 parent 685ac8c commit ece0f3b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,8 @@ public class M3ToJavaGenerator

public static boolean isPlatformClass(CoreInstance _class)
{
return !PLATFORM_EXCLUDED_FILES.contains(_class.getSourceInformation().getSourceId()) && !PLATFORM_EXCLUDED_CLASSES.contains(_class.getName());
return ((_class.getSourceInformation() == null) || !PLATFORM_EXCLUDED_FILES.contains(_class.getSourceInformation().getSourceId())) &&
!PLATFORM_EXCLUDED_CLASSES.contains(_class.getName());
}

public M3ToJavaGenerator(String outputDir, String factoryNamePrefix, boolean generateTypeFactoriesById)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,13 @@
import org.finos.legend.pure.m3.navigation.M3Properties;
import org.finos.legend.pure.m3.navigation.PackageableElement.PackageableElement;
import org.finos.legend.pure.m3.navigation.ProcessorSupport;
import org.finos.legend.pure.m3.navigation.imports.Imports;
import org.finos.legend.pure.m3.navigation.importstub.ImportStub;
import org.finos.legend.pure.m3.navigation.multiplicity.Multiplicity;
import org.finos.legend.pure.m3.serialization.grammar.m3parser.antlr.M3AntlrParser;
import org.finos.legend.pure.m3.serialization.runtime.Source;
import org.finos.legend.pure.m4.ModelRepository;
import org.finos.legend.pure.m4.coreinstance.CoreInstance;
import org.finos.legend.pure.m4.coreinstance.SourceInformation;

public class PropertyInstanceBuilder
{
Expand Down Expand Up @@ -67,13 +68,17 @@ private static String getMultiplicity(QualifiedProperty<?> property)

static ListIterable<AbstractProperty<?>> createMilestonedProperties(CoreInstance propertyOwner, ListIterable<MilestonePropertyCodeBlock> propertyCodeBlocks, Context context, ProcessorSupport processorSupport, ModelRepository modelRepository)
{
ImportGroup importId = (ImportGroup) PackageableElement.findPackageableElement("system::imports::" + getImportIdForOwner(propertyOwner), modelRepository);
ImportGroup importId = getImportIdForOwner(propertyOwner, processorSupport);
return createM3MilestonedProperties(propertyOwner, importId, propertyCodeBlocks, context, processorSupport, modelRepository);
}

private static String getImportIdForOwner(CoreInstance owner)
private static ImportGroup getImportIdForOwner(CoreInstance owner, ProcessorSupport processorSupport)
{
return Source.importForSourceName(owner.getSourceInformation().getSourceId()) + "_1";
SourceInformation sourceInfo = owner.getSourceInformation();
return (ImportGroup) Imports.getImportGroupsForSource(sourceInfo.getSourceId(), processorSupport)
.asLazy()
.select(ig -> ig.getSourceInformation().getStartLine() <= sourceInfo.getStartLine())
.maxBy(ig -> ig.getSourceInformation().getStartLine());
}


Expand All @@ -91,7 +96,7 @@ private static AbstractProperty<?> createM3Property(ImportGroup importId, Proper
String fileName = propertyOwner.getSourceInformation().getSourceId();
MutableList<QualifiedProperty<? extends CoreInstance>> qps = Lists.mutable.empty();
MutableList<Property<? extends CoreInstance, ?>> ps = Lists.mutable.empty();
new M3AntlrParser().parseProperties(propertyCodeBlock.getCodeBlock(), fileName, ps, qps, typeOwner, importId, true, modelRepository, context, startingQualifiedPropertyIndex);
new M3AntlrParser().parseProperties(propertyCodeBlock.getCodeBlock(), fileName, ps, qps, typeOwner, importId, false, modelRepository, context, startingQualifiedPropertyIndex);
AbstractProperty<?> property = ps.isEmpty() ? qps.getLast() : ps.getLast();
if (property != null)
{
Expand Down

0 comments on commit ece0f3b

Please sign in to comment.