From b63158e98945c106580460edc653f224b560b8d0 Mon Sep 17 00:00:00 2001 From: Jake Kim <60619826+jake-kim1@users.noreply.github.com> Date: Mon, 4 Nov 2024 14:18:39 -0500 Subject: [PATCH] Delete deprecated compiler pass builders (#3229) --- .../PackageableElementFirstPassBuilder.java | 309 ------------------ .../PackageableElementSecondPassBuilder.java | 297 ----------------- .../PackageableElementThirdPassBuilder.java | 231 ------------- .../pure/compiler/toPureGraph/PureModel.java | 132 -------- 4 files changed, 969 deletions(-) delete mode 100644 legend-engine-core/legend-engine-core-base/legend-engine-core-language-pure/legend-engine-language-pure-compiler/src/main/java/org/finos/legend/engine/language/pure/compiler/toPureGraph/PackageableElementFirstPassBuilder.java delete mode 100644 legend-engine-core/legend-engine-core-base/legend-engine-core-language-pure/legend-engine-language-pure-compiler/src/main/java/org/finos/legend/engine/language/pure/compiler/toPureGraph/PackageableElementSecondPassBuilder.java delete mode 100644 legend-engine-core/legend-engine-core-base/legend-engine-core-language-pure/legend-engine-language-pure-compiler/src/main/java/org/finos/legend/engine/language/pure/compiler/toPureGraph/PackageableElementThirdPassBuilder.java diff --git a/legend-engine-core/legend-engine-core-base/legend-engine-core-language-pure/legend-engine-language-pure-compiler/src/main/java/org/finos/legend/engine/language/pure/compiler/toPureGraph/PackageableElementFirstPassBuilder.java b/legend-engine-core/legend-engine-core-base/legend-engine-core-language-pure/legend-engine-language-pure-compiler/src/main/java/org/finos/legend/engine/language/pure/compiler/toPureGraph/PackageableElementFirstPassBuilder.java deleted file mode 100644 index 8ed24e2c1fe..00000000000 --- a/legend-engine-core/legend-engine-core-base/legend-engine-core-language-pure/legend-engine-language-pure-compiler/src/main/java/org/finos/legend/engine/language/pure/compiler/toPureGraph/PackageableElementFirstPassBuilder.java +++ /dev/null @@ -1,309 +0,0 @@ -// Copyright 2020 Goldman Sachs -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package org.finos.legend.engine.language.pure.compiler.toPureGraph; - -import org.eclipse.collections.api.RichIterable; -import org.eclipse.collections.api.factory.Lists; -import org.eclipse.collections.impl.utility.ListIterate; -import org.finos.legend.engine.language.pure.compiler.toPureGraph.handlers.UserDefinedFunctionHandler; -import org.finos.legend.engine.language.pure.compiler.toPureGraph.handlers.inference.TypeAndMultiplicity; -import org.finos.legend.engine.protocol.pure.v1.model.SourceInformation; -import org.finos.legend.engine.protocol.pure.v1.model.context.EngineErrorType; -import org.finos.legend.engine.protocol.pure.v1.model.packageableElement.PackageableElementVisitor; -import org.finos.legend.engine.protocol.pure.v1.model.packageableElement.connection.PackageableConnection; -import org.finos.legend.engine.protocol.pure.v1.model.packageableElement.data.DataElement; -import org.finos.legend.engine.protocol.pure.v1.model.packageableElement.domain.Association; -import org.finos.legend.engine.protocol.pure.v1.model.packageableElement.domain.Class; -import org.finos.legend.engine.protocol.pure.v1.model.packageableElement.domain.Enumeration; -import org.finos.legend.engine.protocol.pure.v1.model.packageableElement.domain.Function; -import org.finos.legend.engine.protocol.pure.v1.model.packageableElement.domain.Measure; -import org.finos.legend.engine.protocol.pure.v1.model.packageableElement.domain.Profile; -import org.finos.legend.engine.protocol.pure.v1.model.packageableElement.domain.StereotypePtr; -import org.finos.legend.engine.protocol.pure.v1.model.packageableElement.domain.TagPtr; -import org.finos.legend.engine.protocol.pure.v1.model.packageableElement.mapping.Mapping; -import org.finos.legend.engine.protocol.pure.v1.model.packageableElement.runtime.PackageableRuntime; -import org.finos.legend.engine.protocol.pure.v1.model.packageableElement.section.SectionIndex; -import org.finos.legend.engine.shared.core.operational.errorManagement.EngineException; -import org.finos.legend.pure.generated.Root_meta_core_runtime_EngineRuntime; -import org.finos.legend.pure.generated.Root_meta_core_runtime_EngineRuntime_Impl; -import org.finos.legend.pure.generated.Root_meta_pure_data_DataElement; -import org.finos.legend.pure.generated.Root_meta_pure_data_DataElement_Impl; -import org.finos.legend.pure.generated.Root_meta_pure_mapping_Mapping_Impl; -import org.finos.legend.pure.generated.Root_meta_pure_metamodel_extension_Profile_Impl; -import org.finos.legend.pure.generated.Root_meta_pure_metamodel_extension_Stereotype_Impl; -import org.finos.legend.pure.generated.Root_meta_pure_metamodel_extension_Tag_Impl; -import org.finos.legend.pure.generated.Root_meta_pure_metamodel_extension_TaggedValue_Impl; -import org.finos.legend.pure.generated.Root_meta_pure_metamodel_function_ConcreteFunctionDefinition_Impl; -import org.finos.legend.pure.generated.Root_meta_pure_metamodel_relationship_Association_Impl; -import org.finos.legend.pure.generated.Root_meta_pure_metamodel_section_SectionIndex; -import org.finos.legend.pure.generated.Root_meta_pure_metamodel_section_SectionIndex_Impl; -import org.finos.legend.pure.generated.Root_meta_pure_metamodel_type_Class_Impl; -import org.finos.legend.pure.generated.Root_meta_pure_metamodel_type_Enum_Impl; -import org.finos.legend.pure.generated.Root_meta_pure_metamodel_type_Enumeration_Impl; -import org.finos.legend.pure.generated.Root_meta_pure_metamodel_type_Measure_Impl; -import org.finos.legend.pure.generated.Root_meta_pure_metamodel_type_generics_GenericType_Impl; -import org.finos.legend.pure.generated.Root_meta_core_runtime_Connection; -import org.finos.legend.pure.generated.Root_meta_pure_runtime_PackageableConnection; -import org.finos.legend.pure.generated.Root_meta_pure_runtime_PackageableConnection_Impl; -import org.finos.legend.pure.generated.Root_meta_pure_runtime_PackageableRuntime; -import org.finos.legend.pure.generated.Root_meta_pure_runtime_PackageableRuntime_Impl; -import org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.PackageableElement; -import org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.extension.Stereotype; -import org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.extension.Tag; -import org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.extension.TaggedValue; -import org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.Type; -import org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.generics.GenericType; -import org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.valuespecification.ValueSpecification; -import org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.valuespecification.VariableExpression; -import org.finos.legend.pure.m3.navigation.M3Paths; - -import java.util.List; - -public class PackageableElementFirstPassBuilder implements PackageableElementVisitor -{ - private final CompileContext context; - - public PackageableElementFirstPassBuilder(CompileContext context) - { - this.context = context; - } - - @Override - public PackageableElement visit(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.PackageableElement element) - { - return setNameAndPackage(this.context.getExtraProcessorOrThrow(element).processFirstPass(element, this.context), element); - } - - @Override - public PackageableElement visit(Profile profile) - { - org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.extension.Profile targetProfile = new Root_meta_pure_metamodel_extension_Profile_Impl(profile.name, SourceInformationHelper.toM3SourceInformation(profile.sourceInformation), this.context.pureModel.getClass("meta::pure::metamodel::extension::Profile")); - setNameAndPackage(targetProfile, profile); - return targetProfile - ._p_stereotypes(ListIterate.collect(profile.stereotypes, st -> newStereotype(targetProfile, st.value, st.sourceInformation))) - ._p_tags(ListIterate.collect(profile.tags, t -> newTag(targetProfile, t.value, t.sourceInformation))); - } - - @Override - public PackageableElement visit(Enumeration _enum) - { - String fullPath = this.context.pureModel.buildPackageString(_enum._package, _enum.name); - org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.Enumeration en = new Root_meta_pure_metamodel_type_Enumeration_Impl<>(_enum.name, SourceInformationHelper.toM3SourceInformation(_enum.sourceInformation), this.context.pureModel.getClass("meta::pure::metamodel::type::Enumeration")); - this.context.pureModel.typesIndex.put(fullPath, en); - GenericType genericType = newGenericType(en); - this.context.pureModel.typesGenericTypeIndex.put(fullPath, genericType); - setNameAndPackage(en, _enum); - return en._classifierGenericType(newGenericType(this.context.pureModel.getClass("meta::pure::metamodel::type::Enumeration"), genericType)) - ._stereotypes(ListIterate.collect(_enum.stereotypes, this::resolveStereotype)) - ._taggedValues(ListIterate.collect(_enum.taggedValues, this::newTaggedValue)) - ._values(ListIterate.collect(_enum.values, v -> new Root_meta_pure_metamodel_type_Enum_Impl(v.value, SourceInformationHelper.toM3SourceInformation(v.sourceInformation), null) - ._classifierGenericType(genericType) - ._stereotypes(ListIterate.collect(v.stereotypes, this::resolveStereotype)) - ._taggedValues(ListIterate.collect(v.taggedValues, this::newTaggedValue)) - ._name(v.value))); - } - - @Override - public PackageableElement visit(Class _class) - { - String fullPath = this.context.pureModel.buildPackageString(_class._package, _class.name); - org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.Class targetClass = new Root_meta_pure_metamodel_type_Class_Impl<>(_class.name, SourceInformationHelper.toM3SourceInformation(_class.sourceInformation), this.context.pureModel.getClass("meta::pure::metamodel::type::Class")); - this.context.pureModel.typesIndex.put(fullPath, targetClass); - GenericType genericType = newGenericType(targetClass); - this.context.pureModel.typesGenericTypeIndex.put(fullPath, genericType); - setNameAndPackage(targetClass, _class); - return targetClass._classifierGenericType(newGenericType(this.context.pureModel.getType("meta::pure::metamodel::type::Class"), genericType)) - ._stereotypes(ListIterate.collect(_class.stereotypes, this::resolveStereotype)) - ._taggedValues(ListIterate.collect(_class.taggedValues, this::newTaggedValue)); - } - - @Override - public PackageableElement visit(Measure measure) - { - String fullPath = this.context.pureModel.buildPackageString(measure._package, measure.name); - org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.Measure targetMeasure = new Root_meta_pure_metamodel_type_Measure_Impl(measure.name, SourceInformationHelper.toM3SourceInformation(measure.sourceInformation), null); - this.context.pureModel.typesIndex.put(fullPath, targetMeasure); - GenericType genericType = newGenericType(targetMeasure); - this.context.pureModel.typesGenericTypeIndex.put(fullPath, genericType); - targetMeasure._classifierGenericType(newGenericType(this.context.pureModel.getType(M3Paths.Measure))); - if (measure.canonicalUnit != null) - { - HelperMeasureBuilder.processUnitPackageableElementFirstPass(measure.canonicalUnit, this.context); - } - measure.nonCanonicalUnits.forEach(ncu -> HelperMeasureBuilder.processUnitPackageableElementFirstPass(ncu, this.context)); - return setNameAndPackage(targetMeasure, measure); - } - - @Override - public PackageableElement visit(Association srcAssociation) - { - String packageString = this.context.pureModel.buildPackageString(srcAssociation._package, srcAssociation.name); - org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.relationship.Association association = new Root_meta_pure_metamodel_relationship_Association_Impl(srcAssociation.name, null, this.context.pureModel.getClass("meta::pure::metamodel::relationship::Association")); - - if (srcAssociation.properties.size() != 2) - { - throw new EngineException("Expected 2 properties for an association '" + packageString + "'", srcAssociation.sourceInformation, EngineErrorType.COMPILATION); - } - setNameAndPackage(association, srcAssociation); - return association._stereotypes(ListIterate.collect(srcAssociation.stereotypes, this::resolveStereotype)) - ._taggedValues(ListIterate.collect(srcAssociation.taggedValues, this::newTaggedValue)); - } - - @Override - public PackageableElement visit(Function function) - { - // NOTE: in the protocol, we still store the function name as is, but in the function index, we will store the function based on its function signature - String functionSignature = HelperModelBuilder.getSignature(function); - String functionFullName = this.context.pureModel.buildPackageString(function._package, functionSignature); - String functionName = this.context.pureModel.buildPackageString(function._package, HelperModelBuilder.getFunctionNameWithoutSignature(function)); - org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.function.ConcreteFunctionDefinition targetFunc = new Root_meta_pure_metamodel_function_ConcreteFunctionDefinition_Impl<>(functionSignature, SourceInformationHelper.toM3SourceInformation(function.sourceInformation), null); - - ProcessingContext ctx = new ProcessingContext("Function '" + functionFullName + "' First Pass"); - - this.context.pureModel.setNameAndPackage(targetFunc, functionSignature, function._package, function.sourceInformation) - ._functionName(functionName) // function name to be used in the handler map -> meta::pure::functions::date::isAfterDay - ._classifierGenericType(newGenericType(this.context.pureModel.getType("meta::pure::metamodel::function::ConcreteFunctionDefinition"), PureModel.buildFunctionType(ListIterate.collect(function.parameters, p -> (VariableExpression) p.accept(new ValueSpecificationBuilder(this.context, Lists.mutable.empty(), ctx))), this.context.resolveGenericType(function.returnType, function.sourceInformation), this.context.pureModel.getMultiplicity(function.returnMultiplicity), this.context.pureModel))) - ._stereotypes(ListIterate.collect(function.stereotypes, this::resolveStereotype)) - ._taggedValues(ListIterate.collect(function.taggedValues, this::newTaggedValue)); - HelperModelBuilder.processFunctionConstraints(function, this.context, targetFunc, ctx); - - this.context.pureModel.handlers.register(new UserDefinedFunctionHandler(this.context.pureModel, functionFullName, targetFunc, - ps -> new TypeAndMultiplicity(this.context.resolveGenericType(function.returnType, function.sourceInformation), this.context.pureModel.getMultiplicity(function.returnMultiplicity)), - ps -> - { - List vs = ListIterate.collect(function.parameters, p -> p.accept(new ValueSpecificationBuilder(this.context, Lists.mutable.empty(), ctx))); - if (ps.size() == function.parameters.size()) - { - int size = ps.size(); - // TODO clean up the check.... - try - { - for (int i = 0; i < size; i++) - { - HelperModelBuilder.checkCompatibility(this.context, ps.get(i)._genericType()._rawType(), ps.get(i)._multiplicity(), vs.get(i)._genericType()._rawType(), vs.get(i)._multiplicity(), "Error in function '" + functionFullName + "'", function.body.get(function.body.size() - 1).sourceInformation); - } - } - catch (Exception e) - { - return false; - } - return true; - } - return false; - })); - return targetFunc; - } - - @Override - public PackageableElement visit(Mapping mapping) - { - org.finos.legend.pure.m3.coreinstance.meta.pure.mapping.Mapping pureMapping = new Root_meta_pure_mapping_Mapping_Impl(mapping.name, SourceInformationHelper.toM3SourceInformation(mapping.sourceInformation), this.context.pureModel.getClass("meta::pure::mapping::Mapping")); - GenericType mappingGenericType = newGenericType(this.context.pureModel.getType("meta::pure::mapping::Mapping")); - pureMapping._classifierGenericType(mappingGenericType); - return setNameAndPackage(pureMapping, mapping); - } - - @Override - public PackageableElement visit(PackageableRuntime packageableRuntime) - { - Root_meta_pure_runtime_PackageableRuntime metamodel = new Root_meta_pure_runtime_PackageableRuntime_Impl(packageableRuntime.name, SourceInformationHelper.toM3SourceInformation(packageableRuntime.sourceInformation), this.context.pureModel.getClass("meta::pure::runtime::PackageableRuntime")); - GenericType packageableRuntimeGenericType = newGenericType(this.context.pureModel.getType("meta::pure::runtime::PackageableRuntime")); - metamodel._classifierGenericType(packageableRuntimeGenericType); - - Root_meta_core_runtime_EngineRuntime pureRuntime = new Root_meta_core_runtime_EngineRuntime_Impl("Root::meta::core::runtime::Runtime", SourceInformationHelper.toM3SourceInformation(packageableRuntime.sourceInformation), this.context.pureModel.getClass("meta::core::runtime::Runtime")); - metamodel._runtimeValue(pureRuntime); - - return setNameAndPackage(metamodel, packageableRuntime); - } - - @Override - public PackageableElement visit(PackageableConnection packageableConnection) - { - Root_meta_pure_runtime_PackageableConnection metamodel = new Root_meta_pure_runtime_PackageableConnection_Impl(packageableConnection.name, SourceInformationHelper.toM3SourceInformation(packageableConnection.sourceInformation), this.context.pureModel.getClass("meta::pure::runtime::PackageableConnection")); - Root_meta_core_runtime_Connection connection = packageableConnection.connectionValue.accept(new ConnectionFirstPassBuilder(this.context)); - metamodel._connectionValue(connection); - return setNameAndPackage(metamodel, packageableConnection); - } - - @Override - public PackageableElement visit(SectionIndex sectionIndex) - { - Root_meta_pure_metamodel_section_SectionIndex stub = new Root_meta_pure_metamodel_section_SectionIndex_Impl(sectionIndex.name, SourceInformationHelper.toM3SourceInformation(sectionIndex.sourceInformation), this.context.pureModel.getClass("meta::pure::metamodel::section::SectionIndex")); - return setNameAndPackage(stub, sectionIndex); - } - - @Override - public PackageableElement visit(DataElement dataElement) - { - Root_meta_pure_data_DataElement compiled = new Root_meta_pure_data_DataElement_Impl(dataElement.name, SourceInformationHelper.toM3SourceInformation(dataElement.sourceInformation), null); - GenericType mappingGenericType = newGenericType(this.context.pureModel.getType("meta::pure::data::DataElement")); - setNameAndPackage(compiled, dataElement); - return compiled._classifierGenericType(mappingGenericType) - ._stereotypes(ListIterate.collect(dataElement.stereotypes, this::resolveStereotype)) - ._taggedValues(ListIterate.collect(dataElement.taggedValues, this::newTaggedValue)); - } - - private GenericType newGenericType(Type rawType) - { - return new Root_meta_pure_metamodel_type_generics_GenericType_Impl("", null, this.context.pureModel.getClass("meta::pure::metamodel::type::generics::GenericType")) - ._rawType(rawType); - } - - private GenericType newGenericType(Type rawType, GenericType typeArgument) - { - return newGenericType(rawType, Lists.fixedSize.with(typeArgument)); - } - - private GenericType newGenericType(Type rawType, RichIterable typeArguments) - { - return newGenericType(rawType)._typeArguments(typeArguments); - } - - private Stereotype newStereotype(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.extension.Profile profile, String name, SourceInformation sourceInformation) - { - return new Root_meta_pure_metamodel_extension_Stereotype_Impl(name, SourceInformationHelper.toM3SourceInformation(sourceInformation), this.context.pureModel.getClass("meta::pure::metamodel::extension::Stereotype")) - ._value(name) - ._profile(profile); - } - - private Tag newTag(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.extension.Profile profile, String name, SourceInformation sourceInformation) - { - return new Root_meta_pure_metamodel_extension_Tag_Impl(name, SourceInformationHelper.toM3SourceInformation(sourceInformation), this.context.pureModel.getClass("meta::pure::metamodel::extension::Tag")) - ._value(name) - ._profile(profile); - } - - private TaggedValue newTaggedValue(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.domain.TaggedValue taggedValue) - { - return new Root_meta_pure_metamodel_extension_TaggedValue_Impl("", null, this.context.pureModel.getClass("meta::pure::metamodel::extension::TaggedValue")) - ._tag(resolveTag(taggedValue.tag)) - ._value(taggedValue.value); - } - - private Tag resolveTag(TagPtr tagPointer) - { - return this.context.resolveTag(tagPointer.profile, tagPointer.value, tagPointer.profileSourceInformation, tagPointer.sourceInformation); - } - - private Stereotype resolveStereotype(StereotypePtr stereotypePointer) - { - return this.context.resolveStereotype(stereotypePointer.profile, stereotypePointer.value, stereotypePointer.profileSourceInformation, stereotypePointer.sourceInformation); - } - - private T setNameAndPackage(T pureElement, org.finos.legend.engine.protocol.pure.v1.model.packageableElement.PackageableElement sourceElement) - { - return this.context.pureModel.setNameAndPackage(pureElement, sourceElement.name, sourceElement._package, sourceElement.sourceInformation); - } -} diff --git a/legend-engine-core/legend-engine-core-base/legend-engine-core-language-pure/legend-engine-language-pure-compiler/src/main/java/org/finos/legend/engine/language/pure/compiler/toPureGraph/PackageableElementSecondPassBuilder.java b/legend-engine-core/legend-engine-core-base/legend-engine-core-language-pure/legend-engine-language-pure-compiler/src/main/java/org/finos/legend/engine/language/pure/compiler/toPureGraph/PackageableElementSecondPassBuilder.java deleted file mode 100644 index abf8481232f..00000000000 --- a/legend-engine-core/legend-engine-core-base/legend-engine-core-language-pure/legend-engine-language-pure-compiler/src/main/java/org/finos/legend/engine/language/pure/compiler/toPureGraph/PackageableElementSecondPassBuilder.java +++ /dev/null @@ -1,297 +0,0 @@ -// Copyright 2020 Goldman Sachs -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package org.finos.legend.engine.language.pure.compiler.toPureGraph; - -import org.eclipse.collections.api.RichIterable; -import org.eclipse.collections.api.factory.Lists; -import org.eclipse.collections.api.factory.Sets; -import org.eclipse.collections.api.list.ListIterable; -import org.eclipse.collections.api.list.MutableList; -import org.eclipse.collections.impl.utility.ListIterate; -import org.finos.legend.engine.language.pure.compiler.toPureGraph.data.EmbeddedDataFirstPassBuilder; -import org.finos.legend.engine.language.pure.compiler.toPureGraph.extension.CompilerExtensions; -import org.finos.legend.engine.language.pure.compiler.toPureGraph.handlers.IncludedMappingHandler; -import org.finos.legend.engine.protocol.pure.v1.model.context.EngineErrorType; -import org.finos.legend.engine.protocol.pure.v1.model.packageableElement.PackageableElementVisitor; -import org.finos.legend.engine.protocol.pure.v1.model.packageableElement.connection.PackageableConnection; -import org.finos.legend.engine.protocol.pure.v1.model.packageableElement.data.DataElement; -import org.finos.legend.engine.protocol.pure.v1.model.packageableElement.domain.Association; -import org.finos.legend.engine.protocol.pure.v1.model.packageableElement.domain.Class; -import org.finos.legend.engine.protocol.pure.v1.model.packageableElement.domain.Enumeration; -import org.finos.legend.engine.protocol.pure.v1.model.packageableElement.domain.Function; -import org.finos.legend.engine.protocol.pure.v1.model.packageableElement.domain.Measure; -import org.finos.legend.engine.protocol.pure.v1.model.packageableElement.domain.Profile; -import org.finos.legend.engine.protocol.pure.v1.model.packageableElement.mapping.Mapping; -import org.finos.legend.engine.protocol.pure.v1.model.packageableElement.runtime.PackageableRuntime; -import org.finos.legend.engine.protocol.pure.v1.model.packageableElement.section.SectionIndex; -import org.finos.legend.engine.shared.core.operational.errorManagement.EngineException; -import org.finos.legend.pure.generated.Root_meta_core_runtime_Connection; -import org.finos.legend.pure.generated.Root_meta_pure_data_DataElement; -import org.finos.legend.pure.generated.Root_meta_pure_data_DataElementReference; -import org.finos.legend.pure.generated.Root_meta_pure_data_EmbeddedData; -import org.finos.legend.pure.generated.Root_meta_pure_metamodel_relationship_Generalization_Impl; -import org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.PackageableElement; -import org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.function.property.QualifiedProperty; -import org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.relationship.Generalization; -import org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.Type; -import org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.generics.GenericType; -import org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.valuespecification.ValueSpecification; - -import java.util.Set; - -public class PackageableElementSecondPassBuilder implements PackageableElementVisitor -{ - private final CompileContext context; - - public PackageableElementSecondPassBuilder(CompileContext context) - { - this.context = context; - } - - @Override - public PackageableElement visit(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.PackageableElement element) - { - this.context.getExtraProcessorOrThrow(element).processSecondPass(element, this.context); - return null; - } - - @Override - public PackageableElement visit(Profile profile) - { - return null; - } - - @Override - public PackageableElement visit(Enumeration _enum) - { - org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.Enumeration targetEnum = (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.Enumeration)this.context.pureModel.getType(this.context.pureModel.buildPackageString(_enum._package, _enum.name), _enum.sourceInformation); - - if (targetEnum._generalizations().isEmpty()) - { - Generalization g = new Root_meta_pure_metamodel_relationship_Generalization_Impl("", null, this.context.pureModel.getClass("meta::pure::metamodel::relationship::Generalization")) - ._general(this.context.pureModel.getGenericType("meta::pure::metamodel::type::Any")) - ._specific(targetEnum); - targetEnum._generalizationsAdd(g); - } - - return targetEnum; - } - - @SuppressWarnings({"unchecked", "rawtypes"}) - @Override - public PackageableElement visit(Class srcClass) - { - String fullPath = this.context.pureModel.buildPackageString(srcClass._package, srcClass.name); - org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.Class _class = this.context.pureModel.getClass(fullPath, srcClass.sourceInformation); - GenericType _classGenericType = this.context.resolveGenericType(fullPath, srcClass.sourceInformation); - Set uniqueSuperTypes = Sets.mutable.empty(); - MutableList generalization = ListIterate.collect(srcClass.superTypes, superTypePtr -> - { - String superType = superTypePtr.path; - // validate no duplicated class supertype - if (!uniqueSuperTypes.add(superType)) - { - throw new EngineException("Duplicated super type '" + superType + "' in class '" + this.context.pureModel.buildPackageString(srcClass._package, srcClass.name) + "'", srcClass.sourceInformation, EngineErrorType.COMPILATION); - } - Generalization g = new Root_meta_pure_metamodel_relationship_Generalization_Impl("", SourceInformationHelper.toM3SourceInformation(superTypePtr.sourceInformation), this.context.pureModel.getClass("meta::pure::metamodel::relationship::Generalization"))._general(this.context.resolveGenericType(superType, superTypePtr.sourceInformation))._specific(_class); - if (!this.context.pureModel.isImmutable(superType)) - { - org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.Class superTypeClass; - Type type = this.context.resolveType(superType, superTypePtr.sourceInformation); - try - { - superTypeClass = (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.Class) type; - } - catch (ClassCastException e) - { - throw new EngineException("Invalid supertype: '" + srcClass.name + "' cannot extend '" + superType + "' as it is not a class.", srcClass.sourceInformation, EngineErrorType.COMPILATION); - } - synchronized (superTypeClass) - { - superTypeClass._specializationsAdd(g); - } - } - return g; - }); - - MutableList> properties = ListIterate.collect(srcClass.properties, HelperModelBuilder.processProperty(this.context, _classGenericType, _class)); - MutableList> restrictedMilestoningProperties = Milestoning.restrictedMilestoningProperties(_class, srcClass, properties, this.context.pureModel); - MutableList> withMilestoningProperties = properties.select(p -> !restrictedMilestoningProperties.contains(p)).withAll(Milestoning.generateMilestoningProperties(_class, this.context)); - - ProcessingContext ctx = new ProcessingContext("Class '" + this.context.pureModel.buildPackageString(srcClass._package, srcClass.name) + "' Second Pass"); - ValueSpecification thisVariable = HelperModelBuilder.createThisVariableForClass(this.context, this.context.pureModel.buildPackageString(srcClass._package, srcClass.name)); - ctx.addInferredVariables("this", thisVariable); - - RichIterable> qualifiedProperties = ListIterate.collect(srcClass.qualifiedProperties, HelperModelBuilder.processQualifiedPropertyFirstPass(this.context, _class, this.context.pureModel.buildPackageString(srcClass._package, srcClass.name), ctx)); - _class._originalMilestonedProperties(ListIterate.collect(srcClass.originalMilestonedProperties, HelperModelBuilder.processProperty(this.context, _classGenericType, _class))) - ._generalizations(generalization) - ._qualifiedProperties(qualifiedProperties) - ._properties(withMilestoningProperties); - if (_class._generalizations().isEmpty()) - { - Generalization g = new Root_meta_pure_metamodel_relationship_Generalization_Impl("", null, this.context.pureModel.getClass("meta::pure::metamodel::relationship::Generalization")) - ._general(this.context.pureModel.getGenericType("meta::pure::metamodel::type::Any")) - ._specific(_class); - _class._generalizationsAdd(g); - } - ctx.flushVariable("this"); - return _class; - } - - @Override - public PackageableElement visit(Association srcAssociation) - { - String packageString = this.context.pureModel.buildPackageString(srcAssociation._package, srcAssociation.name); - org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.relationship.Association association = this.context.pureModel.getAssociation(packageString, srcAssociation.sourceInformation); - org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.Class source = this.context.resolveClass(srcAssociation.properties.get(0).type, srcAssociation.properties.get(0).sourceInformation); - org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.Class target = this.context.resolveClass(srcAssociation.properties.get(1).type, srcAssociation.properties.get(1).sourceInformation); - - String property0Ref = this.context.pureModel.addPrefixToTypeReference(HelperModelBuilder.getElementFullPath(source, this.context.pureModel.getExecutionSupport())); - String property1Ref = this.context.pureModel.addPrefixToTypeReference(HelperModelBuilder.getElementFullPath(target, this.context.pureModel.getExecutionSupport())); - - // TODO generalize this validation to all platform/core types - if ("meta::pure::metamodel::type::Any".equals(org.finos.legend.pure.m3.navigation.PackageableElement.PackageableElement.getUserPathForPackageableElement(source)) || - "meta::pure::metamodel::type::Any".equals(org.finos.legend.pure.m3.navigation.PackageableElement.PackageableElement.getUserPathForPackageableElement(target))) - { - throw new EngineException("Associations to Any are not allowed. Found in '" + packageString + "'", srcAssociation.sourceInformation, EngineErrorType.COMPILATION); - } - - org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.function.property.Property property1 = HelperModelBuilder.processProperty(this.context, this.context.pureModel.getGenericTypeFromIndex(property1Ref), association).valueOf(srcAssociation.properties.get(0)); - org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.function.property.Property property2 = HelperModelBuilder.processProperty(this.context, this.context.pureModel.getGenericTypeFromIndex(property0Ref), association).valueOf(srcAssociation.properties.get(1)); - - synchronized (source) - { - source._propertiesFromAssociationsAdd(property2); - } - synchronized (target) - { - target._propertiesFromAssociationsAdd(property1); - } - - ProcessingContext ctx = new ProcessingContext("Association " + packageString + " (second pass)"); - - org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.valuespecification.ValueSpecification thisVariable = HelperModelBuilder.createThisVariableForClass(this.context, property1Ref); - ctx.addInferredVariables("this", thisVariable); - - ListIterable> qualifiedProperties = ListIterate.collect(srcAssociation.qualifiedProperties, p -> - { - org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.Class cl = this.context.resolveGenericType(p.returnType, p.sourceInformation)._rawType() == source ? target : source; - return HelperModelBuilder.processQualifiedPropertyFirstPass(this.context, association, org.finos.legend.pure.m3.navigation.PackageableElement.PackageableElement.getUserPathForPackageableElement(cl), ctx).valueOf(p); - }); - qualifiedProperties.forEach(q -> - { - org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.Class _class = q._genericType()._rawType() == source ? target : source; - synchronized (_class) - { - _class._qualifiedPropertiesFromAssociationsAdd(q); - } - }); - ctx.flushVariable("this"); - return association._originalMilestonedProperties(ListIterate.collect(srcAssociation.originalMilestonedProperties, HelperModelBuilder.processProperty(this.context, this.context.pureModel.getGenericTypeFromIndex(srcAssociation.properties.get(0).type), association))) - ._properties(Lists.mutable.with(property1, property2)) - ._qualifiedProperties(qualifiedProperties); - } - - @Override - public PackageableElement visit(Function function) - { - return null; - } - - @Override - public PackageableElement visit(Measure measure) - { - org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.Measure targetMeasure = this.context.pureModel.getMeasure(this.context.pureModel.buildPackageString(measure._package, measure.name), measure.sourceInformation); - if (measure.canonicalUnit != null) - { - targetMeasure._canonicalUnit(HelperMeasureBuilder.processUnitPackageableElementSecondPass(measure.canonicalUnit, this.context)); - } - targetMeasure._nonCanonicalUnits(ListIterate.collect(measure.nonCanonicalUnits, ncu -> HelperMeasureBuilder.processUnitPackageableElementSecondPass(ncu, this.context))); - return targetMeasure; - } - - @Override - public PackageableElement visit(Mapping mapping) - { - final org.finos.legend.pure.m3.coreinstance.meta.pure.mapping.Mapping pureMapping = this.context.pureModel.getMapping(this.context.pureModel.buildPackageString(mapping._package, mapping.name), mapping.sourceInformation); - RichIterable> enumerationMappings = ListIterate.collect(mapping.enumerationMappings, em -> HelperMappingBuilder.processEnumMapping(em, pureMapping, this.context)); - if (enumerationMappings.isEmpty() && mapping.includedMappings.isEmpty()) - { - return pureMapping; - } - if (!mapping.includedMappings.isEmpty()) - { - CompilerExtensions extensions = context.pureModel.extensions; - RichIterable mappingIncludes = - ListIterate.collect(mapping.includedMappings, i -> - { - IncludedMappingHandler handler = extensions.getExtraIncludedMappingHandlers(i.getClass().getName()); - return handler.processMappingInclude(i, this.context, pureMapping, - handler.resolveMapping(i, this.context)); - }); - pureMapping._includesAddAll(mappingIncludes); - // validate no duplicated included mappings - Set uniqueMappingIncludes = Sets.mutable.empty(); - mappingIncludes.forEach(includedMapping -> - { - String mappingName = IncludedMappingHandler.parseIncludedMappingNameRecursively(includedMapping); - if (!uniqueMappingIncludes.add(mappingName)) - { - throw new EngineException("Duplicated mapping include '" + mappingName + - "' in " + "mapping " + - "'" + this.context.pureModel.buildPackageString(mapping._package, mapping.name) + "'", mapping.sourceInformation, EngineErrorType.COMPILATION); - } - }); - } - pureMapping._enumerationMappings(enumerationMappings); - return pureMapping; - } - - @Override - public PackageableElement visit(PackageableRuntime packageableRuntime) - { - return null; - } - - @Override - public PackageableElement visit(PackageableConnection packageableConnection) - { - final Root_meta_core_runtime_Connection pureConnection = this.context.pureModel.getConnection(this.context.pureModel.buildPackageString(packageableConnection._package, packageableConnection.name), packageableConnection.sourceInformation); - packageableConnection.connectionValue.accept(new ConnectionSecondPassBuilder(this.context, pureConnection)); - return null; - } - - @Override - public PackageableElement visit(SectionIndex sectionIndex) - { - return null; - } - - @Override - public PackageableElement visit(DataElement dataElement) - { - String fullPath = context.pureModel.buildPackageString(dataElement._package, dataElement.name); - Root_meta_pure_data_DataElement compiled = (Root_meta_pure_data_DataElement) context.pureModel.getPackageableElement(fullPath); - - ProcessingContext processingContext = new ProcessingContext("Data '" + fullPath + "' Second Pass"); - Root_meta_pure_data_EmbeddedData compiledData = dataElement.data.accept(new EmbeddedDataFirstPassBuilder(context, processingContext)); - if (compiledData instanceof Root_meta_pure_data_DataElementReference) - { - throw new EngineException("Cannot use Data element reference in a Data element", dataElement.data.sourceInformation, EngineErrorType.COMPILATION); - } - compiled._data(compiledData); - return null; - } -} diff --git a/legend-engine-core/legend-engine-core-base/legend-engine-core-language-pure/legend-engine-language-pure-compiler/src/main/java/org/finos/legend/engine/language/pure/compiler/toPureGraph/PackageableElementThirdPassBuilder.java b/legend-engine-core/legend-engine-core-base/legend-engine-core-language-pure/legend-engine-language-pure-compiler/src/main/java/org/finos/legend/engine/language/pure/compiler/toPureGraph/PackageableElementThirdPassBuilder.java deleted file mode 100644 index f19303df564..00000000000 --- a/legend-engine-core/legend-engine-core-base/legend-engine-core-language-pure/legend-engine-language-pure-compiler/src/main/java/org/finos/legend/engine/language/pure/compiler/toPureGraph/PackageableElementThirdPassBuilder.java +++ /dev/null @@ -1,231 +0,0 @@ -// Copyright 2020 Goldman Sachs -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package org.finos.legend.engine.language.pure.compiler.toPureGraph; - -import org.eclipse.collections.api.RichIterable; -import org.eclipse.collections.api.list.MutableList; -import org.eclipse.collections.api.tuple.Pair; -import org.eclipse.collections.impl.factory.Lists; -import org.eclipse.collections.impl.utility.ListIterate; -import org.finos.legend.engine.language.pure.compiler.toPureGraph.test.TestBuilderHelper; -import org.finos.legend.engine.protocol.pure.v1.model.context.EngineErrorType; -import org.finos.legend.engine.protocol.pure.v1.model.packageableElement.PackageableElementVisitor; -import org.finos.legend.engine.protocol.pure.v1.model.packageableElement.connection.PackageableConnection; -import org.finos.legend.engine.protocol.pure.v1.model.packageableElement.data.DataElement; -import org.finos.legend.engine.protocol.pure.v1.model.packageableElement.domain.Association; -import org.finos.legend.engine.protocol.pure.v1.model.packageableElement.domain.Class; -import org.finos.legend.engine.protocol.pure.v1.model.packageableElement.domain.Enumeration; -import org.finos.legend.engine.protocol.pure.v1.model.packageableElement.domain.Function; -import org.finos.legend.engine.protocol.pure.v1.model.packageableElement.domain.Measure; -import org.finos.legend.engine.protocol.pure.v1.model.packageableElement.domain.Profile; -import org.finos.legend.engine.protocol.pure.v1.model.packageableElement.mapping.Mapping; -import org.finos.legend.engine.protocol.pure.v1.model.packageableElement.runtime.PackageableRuntime; -import org.finos.legend.engine.protocol.pure.v1.model.packageableElement.section.SectionIndex; -import org.finos.legend.engine.shared.core.identity.Identity; -import org.finos.legend.engine.shared.core.operational.errorManagement.EngineException; -import org.finos.legend.engine.shared.core.operational.logs.LogInfo; -import org.finos.legend.engine.shared.core.operational.logs.LoggingEventType; -import org.finos.legend.pure.generated.Root_meta_pure_runtime_PackageableRuntime; -import org.finos.legend.pure.m3.coreinstance.meta.pure.mapping.AssociationImplementation; -import org.finos.legend.pure.m3.coreinstance.meta.pure.mapping.EmbeddedSetImplementation; -import org.finos.legend.pure.m3.coreinstance.meta.pure.mapping.SetImplementation; -import org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.PackageableElement; -import org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.FunctionType; -import org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.valuespecification.ValueSpecification; -import org.slf4j.Logger; - -public class PackageableElementThirdPassBuilder implements PackageableElementVisitor -{ - private static final Logger LOGGER = org.slf4j.LoggerFactory.getLogger(PackageableElementThirdPassBuilder.class); - private final CompileContext context; - - public PackageableElementThirdPassBuilder(CompileContext context) - { - this.context = context; - } - - @Override - public PackageableElement visit(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.PackageableElement element) - { - this.context.getExtraProcessorOrThrow(element).processThirdPass(element, this.context); - return null; - } - - @Override - public PackageableElement visit(Profile profile) - { - return null; - } - - @Override - public PackageableElement visit(Enumeration _enum) - { - return null; - } - - @Override - public PackageableElement visit(Class srcClass) - { - org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.Class targetClass = this.context.pureModel.getClass(this.context.pureModel.buildPackageString(srcClass._package, srcClass.name), srcClass.sourceInformation); - - ProcessingContext ctx = new ProcessingContext("Class '" + this.context.pureModel.buildPackageString(srcClass._package, srcClass.name) + "' Third Pass"); - org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.valuespecification.ValueSpecification thisVariable = HelperModelBuilder.createThisVariableForClass(this.context, this.context.pureModel.buildPackageString(srcClass._package, srcClass.name)); - - ListIterate.collect(srcClass.qualifiedProperties, property -> - { - ctx.push("Qualified Property " + property.name); - ctx.addInferredVariables("this", thisVariable); - MutableList body; - try - { - property.parameters.forEach(p -> p.accept(new ValueSpecificationBuilder(this.context, org.eclipse.collections.api.factory.Lists.mutable.empty(), ctx))); - body = ListIterate.collect(property.body, expression -> expression.accept(new ValueSpecificationBuilder(this.context, org.eclipse.collections.api.factory.Lists.mutable.empty(), ctx))); - } - catch (Exception e) - { - LOGGER.warn(new LogInfo(Identity.getAnonymousIdentity().getName(), LoggingEventType.GRAPH_EXPRESSION_ERROR, "Can't build derived property '" + property.name + " of class '" + this.context.pureModel.buildPackageString(srcClass._package, srcClass.name) + "' - stack: " + ctx.getStack()).toString()); - if (e instanceof EngineException) - { - throw e; - } - e.printStackTrace(); - throw new EngineException(e.getMessage(), property.sourceInformation, EngineErrorType.COMPILATION); - } - ctx.flushVariable("this"); - org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.function.property.QualifiedProperty prop = targetClass._qualifiedProperties().detect(o -> HelperModelBuilder.isCompatibleDerivedProperty(o, property)); - HelperModelBuilder.checkCompatibility(this.context, body.getLast()._genericType()._rawType(), body.getLast()._multiplicity(), prop._genericType()._rawType(), prop._multiplicity(), "Error in derived property '" + srcClass.name + "." + property.name + "'", property.body.get(property.body.size() - 1).sourceInformation); - ctx.pop(); - return prop._expressionSequence(body); - }); - - HelperModelBuilder.processClassConstraints(srcClass, this.context, targetClass, ctx, thisVariable); - - return targetClass; - } - - @Override - public PackageableElement visit(Association srcAssociation) - { - String property0Ref = this.context.pureModel.addPrefixToTypeReference(srcAssociation.properties.get(0).type); - String property1Ref = this.context.pureModel.addPrefixToTypeReference(srcAssociation.properties.get(1).type); - - org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.relationship.Association association = this.context.pureModel.getAssociation(this.context.pureModel.buildPackageString(srcAssociation._package, srcAssociation.name), srcAssociation.sourceInformation); - ProcessingContext ctx = new ProcessingContext("Association " + this.context.pureModel.buildPackageString(srcAssociation._package, srcAssociation.name) + " (third pass)"); - - ListIterate.collect(srcAssociation.qualifiedProperties, property -> - { - org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.valuespecification.ValueSpecification thisVariable = HelperModelBuilder.createThisVariableForClass(this.context, srcAssociation.properties.get(0).type.equals(property.returnType) ? property1Ref : property0Ref); - ctx.addInferredVariables("this", thisVariable); - ctx.push("Qualified Property " + property.name); - ListIterate.collect(property.parameters, expression -> expression.accept(new ValueSpecificationBuilder(this.context, org.eclipse.collections.api.factory.Lists.mutable.empty(), ctx))); - MutableList body = ListIterate.collect(property.body, expression -> expression.accept(new ValueSpecificationBuilder(this.context, org.eclipse.collections.api.factory.Lists.mutable.empty(), ctx))); - org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.function.property.QualifiedProperty prop = association._qualifiedProperties().detect(o -> o._name().equals(property.name)); - ctx.pop(); - ctx.flushVariable("this"); - return prop._expressionSequence(body); - }); - - return association; - } - - @Override - public PackageableElement visit(Function function) - { - String packageString = this.context.pureModel.buildPackageString(function._package, HelperModelBuilder.getSignature(function)); - org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.function.ConcreteFunctionDefinition targetFunc = this.context.pureModel.getConcreteFunctionDefinition(packageString, function.sourceInformation); - ProcessingContext ctx = new ProcessingContext("Function '" + packageString + "' Third Pass"); - MutableList body; - try - { - function.parameters.forEach(p -> p.accept(new ValueSpecificationBuilder(this.context, org.eclipse.collections.api.factory.Lists.mutable.empty(), ctx))); - body = ListIterate.collect(function.body, expression -> expression.accept(new ValueSpecificationBuilder(this.context, org.eclipse.collections.api.factory.Lists.mutable.empty(), ctx))); - } - catch (Exception e) - { - LOGGER.warn(new LogInfo(Identity.getAnonymousIdentity().getName(), LoggingEventType.GRAPH_EXPRESSION_ERROR, "Can't build function '" + packageString + "' - stack: " + ctx.getStack()).toString()); - throw e; - } - FunctionType fType = ((FunctionType) targetFunc._classifierGenericType()._typeArguments().getFirst()._rawType()); - HelperModelBuilder.checkCompatibility(this.context, body.getLast()._genericType()._rawType(), body.getLast()._multiplicity(), fType._returnType()._rawType(), fType._returnMultiplicity(), "Error in function '" + packageString + "'", function.body.get(function.body.size() - 1).sourceInformation); - ctx.pop(); - targetFunc._expressionSequence(body); - HelperFunctionBuilder.processFunctionSuites(function, targetFunc, this.context, ctx); - return targetFunc; - } - - @Override - public PackageableElement visit(Measure measure) - { - return null; - } - - @Override - public PackageableElement visit(Mapping mapping) - { - final org.finos.legend.pure.m3.coreinstance.meta.pure.mapping.Mapping pureMapping = this.context.pureModel.getMapping(this.context.pureModel.buildPackageString(mapping._package, mapping.name), mapping.sourceInformation); - if (mapping.classMappings != null && pureMapping._classMappings().isEmpty()) - { - RichIterable>> setImplementations = ListIterate.collect(mapping.classMappings, cm -> cm.accept(new ClassMappingFirstPassBuilder(this.context, pureMapping))); - pureMapping._classMappingsAddAll(setImplementations.flatCollect(p -> Lists.mutable.with(p.getOne()).withAll(p.getTwo()))); - } - if (!mapping.tests.isEmpty()) - { - mapping.tests.forEach(t -> HelperMappingBuilder.processMappingTest(t, this.context)); - } - if (mapping.testSuites != null) - { - TestBuilderHelper.validateTestSuiteIdsList(mapping.testSuites, mapping.sourceInformation); - pureMapping._tests(ListIterate.collect(mapping.testSuites, suite -> HelperMappingBuilder.processMappingTestAndTestSuite(suite, pureMapping, this.context))); - } - if (mapping.associationMappings != null) - { - RichIterable associationImplementations = ListIterate.collect(mapping.associationMappings, cm -> HelperMappingBuilder.processAssociationImplementation(cm, this.context, pureMapping)); - pureMapping._associationMappings(associationImplementations); - } - if (mapping.classMappings != null) - { - mapping.classMappings.forEach(cm -> cm.accept(new ClassMappingSecondPassBuilder(this.context, pureMapping))); - mapping.classMappings.forEach(cm -> cm.accept(new ClassMappingThirdPassBuilder(this.context, pureMapping))); - } - return pureMapping; - } - - @Override - public PackageableElement visit(PackageableRuntime packageableRuntime) - { - String fullPath = this.context.pureModel.buildPackageString(packageableRuntime._package, packageableRuntime.name); - Root_meta_pure_runtime_PackageableRuntime metamodel = this.context.pureModel.getPackageableRuntime(fullPath, packageableRuntime.sourceInformation); - HelperRuntimeBuilder.buildEngineRuntime(packageableRuntime.runtimeValue, metamodel._runtimeValue(), this.context); - return metamodel; - } - - @Override - public PackageableElement visit(PackageableConnection packageableConnection) - { - return null; - } - - @Override - public PackageableElement visit(SectionIndex sectionIndex) - { - return null; - } - - @Override - public PackageableElement visit(DataElement dataElement) - { - return null; - } -} diff --git a/legend-engine-core/legend-engine-core-base/legend-engine-core-language-pure/legend-engine-language-pure-compiler/src/main/java/org/finos/legend/engine/language/pure/compiler/toPureGraph/PureModel.java b/legend-engine-core/legend-engine-core-base/legend-engine-core-language-pure/legend-engine-language-pure-compiler/src/main/java/org/finos/legend/engine/language/pure/compiler/toPureGraph/PureModel.java index ca0bc746e7f..81c22411eb0 100644 --- a/legend-engine-core/legend-engine-core-base/legend-engine-core-language-pure/legend-engine-language-pure-compiler/src/main/java/org/finos/legend/engine/language/pure/compiler/toPureGraph/PureModel.java +++ b/legend-engine-core/legend-engine-core-base/legend-engine-core-language-pure/legend-engine-language-pure-compiler/src/main/java/org/finos/legend/engine/language/pure/compiler/toPureGraph/PureModel.java @@ -48,11 +48,6 @@ import org.finos.legend.engine.protocol.pure.v1.model.SourceInformation; import org.finos.legend.engine.protocol.pure.v1.model.context.EngineErrorType; import org.finos.legend.engine.protocol.pure.v1.model.context.PureModelContextData; -import org.finos.legend.engine.protocol.pure.v1.model.packageableElement.connection.PackageableConnection; -import org.finos.legend.engine.protocol.pure.v1.model.packageableElement.data.DataElement; -import org.finos.legend.engine.protocol.pure.v1.model.packageableElement.domain.Association; -import org.finos.legend.engine.protocol.pure.v1.model.packageableElement.domain.Class; -import org.finos.legend.engine.protocol.pure.v1.model.packageableElement.domain.Function; import org.finos.legend.engine.protocol.pure.v1.model.packageableElement.domain.Profile; import org.finos.legend.engine.protocol.pure.v1.model.packageableElement.section.Section; import org.finos.legend.engine.protocol.pure.v1.model.packageableElement.section.SectionIndex; @@ -114,7 +109,6 @@ import java.lang.reflect.Field; import java.util.Collection; import java.util.List; -import java.util.Map; import java.util.Objects; import java.util.Optional; import java.util.concurrent.Callable; @@ -256,13 +250,6 @@ public PureModel(PureModelContextData pureModelContextData, CompilerExtensions e LOGGER.info("{}", new LogInfo(user, "GRAPH_PRE_VALIDATION_COMPLETED", nanosDurationToMillis(preValidationStart, preValidationEnd))); span.log("GRAPH_PRE_VALIDATION_COMPLETED"); - // Processing - long indexStart = System.nanoTime(); - PureModelContextDataIndex pureModelContextDataIndex = index(pureModelContextData); - long indexEnd = System.nanoTime(); - LOGGER.info("{}", new LogInfo(user, "GRAPH_INDEX_INPUT", pureModelContextDataIndex, nanosDurationToMillis(indexStart, indexEnd))); - span.log("GRAPH_INDEX_INPUT"); - List elements = pureModelContextData.getElements(); DependencyManagement dependencyManagement = new DependencyManagement(); FastListMultimap, DependencyManagement.PackageableElementsByDependencyLevel> classToElements = FastListMultimap.newMultimap(); @@ -1457,125 +1444,6 @@ public Handlers getHandlers() return handlers; } - private PureModelContextDataIndex index(PureModelContextData pureModelContextData) - { - PureModelContextDataIndex index = new PureModelContextDataIndex(); - MutableMap, - MutableList> stores = Maps.mutable.empty(); - - MutableMap, - MutableList> otherElementsByClass = Maps.mutable.empty(); - pureModelContextData.getElements().forEach(e -> - { - if (e instanceof Association) - { - index.associations.add((Association) e); - } - else if (e instanceof Class) - { - index.classes.add((Class) e); - } - else if (e instanceof org.finos.legend.engine.protocol.pure.v1.model.packageableElement.domain.Enumeration) - { - index.enumerations.add((org.finos.legend.engine.protocol.pure.v1.model.packageableElement.domain.Enumeration) e); - } - else if (e instanceof Function) - { - index.functions.add((Function) e); - } - else if (e instanceof org.finos.legend.engine.protocol.pure.v1.model.packageableElement.mapping.Mapping) - { - index.mappings.add((org.finos.legend.engine.protocol.pure.v1.model.packageableElement.mapping.Mapping) e); - } - else if (e instanceof org.finos.legend.engine.protocol.pure.v1.model.packageableElement.domain.Measure) - { - index.measures.add((org.finos.legend.engine.protocol.pure.v1.model.packageableElement.domain.Measure) e); - } - else if (e instanceof PackageableConnection) - { - index.connections.add((PackageableConnection) e); - } - else if (e instanceof org.finos.legend.engine.protocol.pure.v1.model.packageableElement.runtime.PackageableRuntime) - { - index.runtimes.add((org.finos.legend.engine.protocol.pure.v1.model.packageableElement.runtime.PackageableRuntime) e); - } - else if (e instanceof Profile) - { - index.profiles.add((Profile) e); - } - else if (e instanceof SectionIndex) - { - index.sectionIndices.add((SectionIndex) e); - } - else if (e instanceof DataElement) - { - index.dataElements.add((DataElement) e); - } - // TODO eliminate special handling for stores - else if (e instanceof org.finos.legend.engine.protocol.pure.v1.model.packageableElement.store.Store) - { - stores.getIfAbsentPut(e.getClass(), Lists.mutable::empty).add((org.finos.legend.engine.protocol.pure.v1.model.packageableElement.store.Store) e); - } - else - { - otherElementsByClass.getIfAbsentPut(e.getClass(), Lists.mutable::empty).add(e); - } - }); - stores.forEach((cls, elements) -> index.stores.getIfAbsentPut(this.extensions.getExtraProcessorOrThrow(cls), Lists.mutable::empty).addAll(elements)); - otherElementsByClass.forEach((cls, elements) -> index.otherElementsByProcessor.getIfAbsentPut(this.extensions.getExtraProcessorOrThrow(cls), Lists.mutable::empty).addAll(elements)); - return index; - } - - private static class PureModelContextDataIndex - { - private final MutableList associations = Lists.mutable.empty(); - private final MutableList classes = Lists.mutable.empty(); - private final MutableList enumerations = Lists.mutable.empty(); - private final MutableList functions = Lists.mutable.empty(); - private final MutableList mappings = Lists.mutable.empty(); - private final MutableList measures = Lists.mutable.empty(); - private final MutableList connections = Lists.mutable.empty(); - private final MutableList runtimes = Lists.mutable.empty(); - private final MutableList profiles = Lists.mutable.empty(); - private final MutableList sectionIndices = Lists.mutable.empty(); - private final MutableList dataElements = Lists.mutable.empty(); - private final MutableMap, MutableList> stores = Maps.mutable.empty(); - private final MutableMap, MutableList> otherElementsByProcessor = Maps.mutable.empty(); - - public Map getStats() - { - MutableMap result = Maps.mutable.empty(); - possiblyAddStats(result, "associations", this.associations); - possiblyAddStats(result, "classes", this.classes); - possiblyAddStats(result, "enumerations", this.enumerations); - possiblyAddStats(result, "functions", this.functions); - possiblyAddStats(result, "mappings", this.mappings); - possiblyAddStats(result, "measures", this.measures); - possiblyAddStats(result, "connections", this.connections); - possiblyAddStats(result, "runtimes", this.runtimes); - possiblyAddStats(result, "profiles", this.profiles); - possiblyAddStats(result, "sectionIndices", this.sectionIndices); - possiblyAddStats(result, "dataElements", this.dataElements); - if (this.stores.notEmpty()) - { - result.put("stores", this.stores.valuesView().sumOfInt(MutableList::size)); - } - if (this.otherElementsByProcessor.notEmpty()) - { - result.put("otherElements", this.otherElementsByProcessor.valuesView().sumOfInt(MutableList::size)); - } - return result; - } - - private static void possiblyAddStats(MutableMap stats, String name, MutableList list) - { - if (list.notEmpty()) - { - stats.put(name, list.size()); - } - } - } - private static double nanosDurationToMillis(long startNanos, long endNanos) { return (endNanos - startNanos) / 1_000_000.0d;