use of org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.Enumeration in project legend-pure by finos.
the class CompiledProcessorSupport method valueSpecification_instanceOf.
@Override
public boolean valueSpecification_instanceOf(CoreInstance valueSpecification, String type) {
try {
ValueSpecification valueSpec = ValueSpecificationCoreInstanceWrapper.toValueSpecification(valueSpecification);
org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.Type rawType = valueSpec._genericType()._rawType();
Class<?> valueSpecType = (rawType instanceof Enumeration) ? this.globalClassLoader.loadClass(FullJavaPaths.Enum) : this.pureClassToJavaClass(fullName(rawType));
Class<?> typeCl = this.pureClassToJavaClass(type);
return typeCl.isAssignableFrom(valueSpecType);
} catch (ClassNotFoundException e) {
throw new RuntimeException(e);
}
}
use of org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.Enumeration in project legend-pure by finos.
the class TestPureRuntimeClass_FunctionExpressionParam method testPureRuntimeClassProperty_NestedGenericsModify.
@Test
public void testPureRuntimeClassProperty_NestedGenericsModify() throws Exception {
String sourceId2 = "import meta::relational::tests::mapping::enumeration::model::domain::*;\n" + "\n" + "Class meta::pure::functions::collection::AggregateValue<T,V,U>\n" + "{\n" + " mapFn : FunctionDefinition<{T[1]->V[*]}>[1];\n" + " aggregateFn : FunctionDefinition<{V[*]->U[0..1]}>[1];\n" + "}\n" + "\n" + "function meta::pure::functions::collection::count(s:Any[*]):Integer[1]\n" + "{\n" + " $s->size();\n" + "}" + "function meta::pure::functions::collection::agg<T,V,U>(mapFn:FunctionDefinition<{T[1]->V[*]}>[1], aggregateFn:FunctionDefinition<{V[*]->U[0..1]}>[1]):meta::pure::functions::collection::AggregateValue<T,V,U>[1]\n" + "{\n" + " ^meta::pure::functions::collection::AggregateValue<T,V,U>(mapFn=$mapFn, aggregateFn=$aggregateFn);\n" + "}\n" + "\n" + "function meta::pure::functions::collection::groupBy<T,V,U>(set:T[*], functions:meta::pure::metamodel::function::Function<{T[1]->Any[*]}>[*], aggValues:meta::pure::functions::collection::AggregateValue<T,V,U>[*], ids:String[*]):String[1]\n" + "{\n" + "\n" + " 'hello';\n" + "}\n" + "function go():String[*]\n" + "{\n" + " ProductSynonym.all()->groupBy([p | $p.value]\n" + " ,agg(x|$x.value,y|$y->count())\n" + " ,['syn', 'count']);\n" + "}\n";
String source = "import meta::relational::tests::mapping::enumeration::model::domain::*;\n" + "\n" + "Class meta::relational::tests::mapping::enumeration::model::domain::ProductSynonym\n" + "{\n" + " value:String[1];\n" + "}\n" + "\n";
RuntimeVerifier.verifyOperationIsStable(new RuntimeTestScriptBuilder().createInMemorySource("sourceId.pure", source).compile().createInMemorySource("sourceId2.pure", sourceId2).compile(), new RuntimeTestScriptBuilder().updateSource("sourceId.pure", "////Comment\n" + source).compile(), this.runtime, this.functionExecution, this.getAdditionalVerifiers());
}
use of org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.Enumeration in project legend-pure by finos.
the class TestPureRuntimeClass_FunctionExpressionParam method testPureRuntimeClassProperty_NestedGenericsModifyProject.
@Test
public void testPureRuntimeClassProperty_NestedGenericsModifyProject() throws Exception {
String sourceId2 = "import meta::relational::tests::mapping::enumeration::model::domain::*;\n" + "Class meta::pure::tds::TabularDataSet\n" + "{\n" + " rows : TDSRow[*];\n" + "}\n" + "Class meta::pure::tds::TDSRow\n" + "{\n" + " parent : TabularDataSet[0..1];\n" + " values : Any[*];\n" + "}\n" + " Class meta::pure::tds::ColumnSpecification<T>\n" + " {\n" + " func : Function<{T[1]->Any[*]}>[1];\n" + " name : String[1];\n" + " documentation : String[0..1];\n" + " }\n" + " \n" + " function meta::pure::tds::col<T>(func : Function<{T[1]->Any[*]}>[1], name : String[1]):meta::pure::tds::ColumnSpecification<T>[1]\n" + " {\n" + " ^ColumnSpecification<T>\n" + " (\n" + " func = $func,\n" + " name = $name\n" + " )\n" + " }\n" + " function meta::pure::tds::project<T>(set:T[*], columnSpecifications:ColumnSpecification<T>[*]):TabularDataSet[1]" + " {" + " ^TabularDataSet();\n" + " }\n" + "function go():Any[*]\n" + "{\n" + "let synoynms = [^ProductSynonym(value='ABC'), ^ProductSynonym(value='DEF')];\n" + " assert([] == $synoynms->project(col(p|$p.value, 'Syn')).rows->map(r|$r.values), |'');\n" + "}\n";
String source = "import meta::relational::tests::mapping::enumeration::model::domain::*;\n" + "\n" + "Class meta::relational::tests::mapping::enumeration::model::domain::ProductSynonym\n" + "{\n" + " value:String[1];\n" + "}\n" + "\n";
RuntimeVerifier.verifyOperationIsStable(new RuntimeTestScriptBuilder().createInMemorySource("sourceId.pure", source).compile().createInMemorySource("sourceId2.pure", sourceId2).compile(), new RuntimeTestScriptBuilder().updateSource("sourceId.pure", "////Comment\n" + source).compile(), this.runtime, this.functionExecution, this.getAdditionalVerifiers());
}
use of org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.Enumeration in project legend-pure by finos.
the class RelationalOperationElementProcessor method processJoinTreeNode.
static void processJoinTreeNode(JoinTreeNode joinTreeNode, CoreInstance implementation, Matcher matcher, ProcessorState state, ModelRepository repository, ProcessorSupport processorSupport) {
String joinName = joinTreeNode._joinName();
Database database = (Database) ImportStub.withImportStubByPass(joinTreeNode._databaseCoreInstance(), processorSupport);
if (database == null) {
throw new PureCompilationException(joinTreeNode.getSourceInformation(), "The system can't figure out which database to use.");
}
PostProcessor.processElement(matcher, database, state, processorSupport);
CoreInstance joinType = joinTreeNode._joinTypeCoreInstance();
if (joinType != null) {
StringCoreInstance joinTypeString = (StringCoreInstance) joinType;
String type = "INNER".equals(joinTypeString.getValue()) ? "INNER" : "LEFT_OUTER";
Enumeration joinTypeEnumeration = (Enumeration) processorSupport.package_getByUserPath(M2RelationalPaths.JoinType);
Enum joinTypeEnumInstance = (Enum) org.finos.legend.pure.m3.navigation.enumeration.Enumeration.findEnum(joinTypeEnumeration, type);
if (joinTypeEnumInstance == null) {
throw new PureCompilationException(joinTreeNode.getSourceInformation(), "The enum value '" + type + "' can't be found in the enumeration " + PackageableElement.getUserPathForPackageableElement(joinTypeEnumeration, "::"));
}
joinTreeNode._joinTypeCoreInstance(joinTypeEnumInstance);
}
Join join = findJoin(joinTreeNode, database, joinName, processorSupport);
joinTreeNode._join(join);
PropertyMappingsImplementation owner = joinTreeNode._setMappingOwner();
if (owner == null && implementation != null) {
joinTreeNode._setMappingOwner((PropertyMappingsImplementation) implementation);
}
for (TreeNode child : joinTreeNode._childrenData()) {
processJoinTreeNode((JoinTreeNode) child, implementation, matcher, state, repository, processorSupport);
}
}
use of org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.Enumeration in project legend-pure by finos.
the class AntlrContextToM3CoreInstance method simpleProperty.
private void simpleProperty(PropertyContext ctx, MutableList<Property<? extends CoreInstance, ?>> properties, MutableList<String> typeParameterNames, MutableList<String> multiplicityParameterNames, ImportStub isOwner, ImportGroup importId, boolean addLines) {
ListIterable<CoreInstance> stereotypes = null;
ListIterable<TaggedValue> tags = null;
DefaultValue defaultValue = null;
GenericType genericType;
Multiplicity multiplicity;
String aggregation;
String propertyName = ctx.identifier().getText();
if (ctx.stereotypes() != null) {
stereotypes = this.stereotypes(ctx.stereotypes(), importId);
}
if (ctx.taggedValues() != null) {
tags = this.taggedValues(ctx.taggedValues(), importId);
}
if (ctx.aggregation() != null) {
if ("(composite)".equals(ctx.aggregation().getText())) {
aggregation = "Composite";
} else if ("(shared)".equals(ctx.aggregation().getText())) {
aggregation = "Shared";
} else {
aggregation = "None";
}
} else {
aggregation = "None";
}
if (ctx.defaultValue() != null) {
defaultValue = defaultValue(ctx.defaultValue(), importId, propertyName);
}
genericType = this.type(ctx.propertyReturnType().type(), typeParameterNames, "", importId, addLines);
multiplicity = this.buildMultiplicity(ctx.propertyReturnType().multiplicity().multiplicityArgument());
Enumeration<?> agg = (Enumeration<?>) this.processorSupport.package_getByUserPath(M3Paths.AggregationKind);
Enum aggKind = (Enum) agg._values().detect(v -> aggregation.equals(((Enum) v).getName()));
SourceInformation propertySourceInfo = this.sourceInformation.getPureSourceInformation(ctx.identifier().getStart(), ctx.identifier().getStart(), ctx.getStop());
PropertyInstance propertyInstance = PropertyInstance.createPersistent(this.repository, propertyName, propertySourceInfo, aggKind, genericType, multiplicity, null);
propertyInstance._stereotypesCoreInstance(stereotypes);
propertyInstance._taggedValues(tags);
propertyInstance._name(propertyName);
propertyInstance._defaultValue(defaultValue);
GenericTypeInstance classifierGT = GenericTypeInstance.createPersistent(this.repository, propertySourceInfo);
ClassInstance propertyType = (ClassInstance) this.processorSupport.package_getByUserPath(M3Paths.Property);
classifierGT._rawTypeCoreInstance(propertyType);
classifierGT._multiplicityArguments(Lists.mutable.of(multiplicity));
GenericTypeInstance classifierGTTA = GenericTypeInstance.createPersistent(this.repository);
classifierGTTA._rawTypeCoreInstance(isOwner);
if (!typeParameterNames.isEmpty()) {
MutableList<GenericType> typeArgs = Lists.mutable.of();
for (String typeParamName : typeParameterNames) {
TypeParameterInstance tp = TypeParameterInstance.createPersistent(this.repository, typeParamName);
GenericTypeInstance gt = GenericTypeInstance.createPersistent(this.repository);
gt._typeParameter(tp);
typeArgs.add(gt);
}
classifierGTTA._typeArguments(typeArgs);
}
if (!multiplicityParameterNames.isEmpty()) {
MutableList<Multiplicity> multParameters = Lists.mutable.of();
for (String multiplicityParam : multiplicityParameterNames) {
MultiplicityInstance mult = MultiplicityInstance.createPersistent(this.repository, null, null);
mult._multiplicityParameter(multiplicityParam);
multParameters.add(mult);
}
classifierGTTA._multiplicityArguments(multParameters);
}
// Clone generic type
// TODO - do we need a deep clone?
GenericTypeInstance ngt = GenericTypeInstance.createPersistent(this.repository, genericType.getSourceInformation());
CoreInstance rawType = genericType._rawTypeCoreInstance();
if (rawType != null) {
if (rawType instanceof ImportStub) {
ImportStub gtis = (ImportStub) rawType;
ImportStubInstance is = ImportStubInstance.createPersistent(this.repository, gtis.getSourceInformation(), gtis._idOrPath(), gtis._importGroup());
// ImportStubInstance is = ImportStubInstance.createPersistent(this.repository, gtis.getSourceInformation(), ((ImportStubInstance)gtis)._idOrPathAsCoreInstance().getName(), (ImportGroup)gtis._importGroup());
ngt._rawTypeCoreInstance(is);
} else {
ngt._rawTypeCoreInstance(rawType);
}
}
if (!genericType._typeArguments().isEmpty()) {
ngt._typeArguments(genericType._typeArguments());
}
ngt._typeParameter(genericType._typeParameter());
if (!genericType._multiplicityArguments().isEmpty()) {
ngt._multiplicityArguments(genericType._multiplicityArguments());
}
classifierGT._typeArguments(Lists.mutable.<GenericType>of(classifierGTTA, ngt));
propertyInstance._classifierGenericType(classifierGT);
properties.add(propertyInstance);
}
Aggregations