use of org.finos.legend.pure.m3.coreinstance.meta.pure.tools.GrammarInfoStub in project legend-pure by finos.
the class PureInstanceSetImplementationProcessor method process.
@Override
public void process(PureInstanceSetImplementation classMapping, ProcessorState state, Matcher matcher, ModelRepository repository, Context context, ProcessorSupport processorSupport) {
Type srcClass = (Type) ImportStub.withImportStubByPass(classMapping._srcClassCoreInstance(), processorSupport);
SourceInformation srcGenericTypeSourceInfo = null;
LambdaFunction<?> filter = classMapping._filter();
if (filter != null) {
state.pushVariableContext();
if (srcClass != null) {
FunctionType fType = getFunctionType(filter, processorSupport);
fType._parameters(Lists.mutable.<VariableExpression>withAll(fType._parameters()).with(createSrcParameter(srcClass, srcGenericTypeSourceInfo, filter.getSourceInformation(), processorSupport)));
}
matcher.fullMatch(filter, state);
state.popVariableContext();
}
int i = 0;
for (PropertyMapping propertyMapping : classMapping._propertyMappings()) {
state.pushVariableContext();
if (((PurePropertyMapping) propertyMapping)._transformerCoreInstance() != null) {
GrammarInfoStub transformerStub = (GrammarInfoStub) ((PurePropertyMapping) propertyMapping)._transformerCoreInstance();
EnumerationMappingProcessor.processsEnumerationTransformer(transformerStub, propertyMapping, processorSupport);
}
LambdaFunction<?> transform = ((PurePropertyMapping) propertyMapping)._transform();
if (srcClass != null) {
FunctionType fType = getFunctionType(transform, processorSupport);
fType._parameters(Lists.mutable.<VariableExpression>withAll(fType._parameters()).with(createSrcParameter(srcClass, srcGenericTypeSourceInfo, propertyMapping.getSourceInformation(), processorSupport)));
}
matcher.fullMatch(transform, state);
ValueSpecification expressionSequence = transform._expressionSequence().getFirst();
if (expressionSequence != null) {
PropertyMappingValueSpecificationContext usageContext = (PropertyMappingValueSpecificationContext) processorSupport.newAnonymousCoreInstance(null, M2MappingPaths.PropertyMappingValueSpecificationContext);
usageContext._offset(i);
usageContext._propertyMapping(propertyMapping);
expressionSequence._usageContext(usageContext);
}
i++;
state.popVariableContext();
}
}
use of org.finos.legend.pure.m3.coreinstance.meta.pure.tools.GrammarInfoStub in project legend-pure by finos.
the class EnumerationMappingProcessor method processsEnumerationTransformer.
public static void processsEnumerationTransformer(GrammarInfoStub enumerationTransformer, PropertyMapping propertyMapping, ProcessorSupport processorSupport) {
if (enumerationTransformer != null) {
String transformerString = (String) enumerationTransformer._value();
String mappingName = StringIterate.getFirstToken(transformerString, ",");
String transformerName = StringIterate.getLastToken(transformerString, ",");
Mapping mapping = (Mapping) processorSupport.package_getByUserPath(mappingName);
if (mapping == null) {
throw new PureCompilationException(propertyMapping.getSourceInformation(), "The mapping '" + mappingName + "' is unknown'. Likely a parser error");
}
EnumerationMapping<?> transformer = org.finos.legend.pure.m2.dsl.mapping.Mapping.getEnumerationMappingByName(mapping, transformerName, processorSupport);
if (transformer == null) {
throw new PureCompilationException(propertyMapping.getSourceInformation(), "The transformer '" + transformerName + "' is unknown or is not of type EnumerationMapping in the Mapping '" + mappingName + "' for property " + ImportStub.withImportStubByPass(propertyMapping._propertyCoreInstance(), processorSupport).getName());
}
enumerationTransformer._original(enumerationTransformer._value());
enumerationTransformer._value(transformer);
}
}
use of org.finos.legend.pure.m3.coreinstance.meta.pure.tools.GrammarInfoStub in project legend-pure by finos.
the class PureInstanceSetImplementationUnbind method run.
@Override
public void run(PureInstanceSetImplementation pureInstanceSetImplementation, MatcherState state, Matcher matcher, ModelRepository modelRepository, Context context) throws PureCompilationException {
ImportStub srcClass = (ImportStub) pureInstanceSetImplementation._srcClassCoreInstance();
if (srcClass != null) {
Shared.cleanUpReferenceUsage(srcClass, pureInstanceSetImplementation, state.getProcessorSupport());
Shared.cleanImportStub(srcClass, state.getProcessorSupport());
}
LambdaFunction filter = pureInstanceSetImplementation._filter();
if (filter != null) {
matcher.fullMatch(filter, state);
((FunctionType) org.finos.legend.pure.m3.navigation.importstub.ImportStub.withImportStubByPass(filter._classifierGenericType()._typeArguments().toList().get(0)._rawTypeCoreInstance(), state.getProcessorSupport()))._parametersRemove();
}
for (PropertyMapping propertyMapping : pureInstanceSetImplementation._propertyMappings()) {
Shared.cleanPropertyStub(propertyMapping._propertyCoreInstance(), state.getProcessorSupport());
LambdaFunction transform = ((PurePropertyMapping) propertyMapping)._transform();
matcher.fullMatch(transform, state);
FunctionType functionType = (FunctionType) org.finos.legend.pure.m3.navigation.importstub.ImportStub.withImportStubByPass(transform._classifierGenericType()._typeArguments().toList().get(0)._rawTypeCoreInstance(), state.getProcessorSupport());
functionType._parametersRemove();
functionType._functionRemove();
if (((PurePropertyMapping) propertyMapping)._transformerCoreInstance() != null) {
GrammarInfoStub transformerStub = (GrammarInfoStub) ((PurePropertyMapping) propertyMapping)._transformerCoreInstance();
transformerStub._value(transformerStub._original());
transformerStub._originalRemove();
}
}
}
use of org.finos.legend.pure.m3.coreinstance.meta.pure.tools.GrammarInfoStub in project legend-pure by finos.
the class DiagramProcessor method resolvePathViewSourceAndTarget.
private void resolvePathViewSourceAndTarget(AbstractPathView view, MapIterable<String, CoreInstance> viewsById, ProcessorState state, ModelRepository repository, ProcessorSupport processorSupport) {
GrammarInfoStub sourceViewStub = view._sourceCoreInstance() != null ? (GrammarInfoStub) repository.newAnonymousCoreInstance(view._sourceCoreInstance().getSourceInformation(), _Package.getByUserPath("meta::pure::tools::GrammarInfoStub", state.getProcessorSupport())) : null;
GrammarInfoStub targetViewStub = view._targetCoreInstance() != null ? (GrammarInfoStub) repository.newAnonymousCoreInstance(view._targetCoreInstance().getSourceInformation(), _Package.getByUserPath("meta::pure::tools::GrammarInfoStub", state.getProcessorSupport())) : null;
String sourceViewId = view._sourceCoreInstance() != null ? view._sourceCoreInstance().getName() : null;
String targetViewId = view._targetCoreInstance() != null ? view._targetCoreInstance().getName() : null;
CoreInstance sourceView = viewsById.get(sourceViewId);
CoreInstance targetView = viewsById.get(targetViewId);
// source view
if (sourceView == null) {
state.getSourceMutation().delete(view);
return;
}
if (!(sourceView instanceof TypeView)) {
throw new PureCompilationException(view.getSourceInformation(), "Object with id '" + sourceViewId + "' is not a TypeView");
}
if (sourceViewStub != null) {
sourceViewStub._original(view._sourceCoreInstance());
sourceViewStub._value(sourceView);
}
view._sourceCoreInstance(sourceViewStub);
// target view
if (targetView == null) {
state.getSourceMutation().delete(view);
return;
}
if (!(targetView instanceof TypeView)) {
throw new PureCompilationException(view.getSourceInformation(), "Object with id '" + targetViewId + "' is not a TypeView");
}
if (targetViewStub != null) {
targetViewStub._original(view._targetCoreInstance());
targetViewStub._value(targetView);
}
view._targetCoreInstance(targetViewStub);
}
use of org.finos.legend.pure.m3.coreinstance.meta.pure.tools.GrammarInfoStub in project legend-pure by finos.
the class DiagramValidator method validatePropertyView.
private void validatePropertyView(PropertyView propertyView, ProcessorSupport processorSupport) {
AbstractProperty property = (AbstractProperty) ImportStub.withImportStubByPass(propertyView._propertyCoreInstance(), processorSupport);
FunctionType functionType = (FunctionType) processorSupport.function_getFunctionType(property);
// Check that source type matches property source type
Type source = (Type) ImportStub.withImportStubByPass(((TypeView) ((GrammarInfoStub) propertyView._sourceCoreInstance())._value())._typeCoreInstance(), processorSupport);
PropertyOwner propertySource = property._owner();
if (propertySource != source) {
StringBuilder message = new StringBuilder("Source type for PropertyView ");
message.append(propertyView._id());
message.append(" (");
PackageableElement.writeUserPathForPackageableElement(message, source, "::");
message.append(") does not match the owner of the property ");
PackageableElement.writeUserPathForPackageableElement(message, propertySource, "::");
message.append('.');
message.append(Property.getPropertyName(property));
message.append(" (");
PackageableElement.writeUserPathForPackageableElement(message, propertySource, "::");
message.append(')');
throw new PureCompilationException(propertyView.getSourceInformation(), message.toString());
}
// Check that target type matches property target type
Type target = (Type) ImportStub.withImportStubByPass(((TypeView) ((GrammarInfoStub) propertyView._targetCoreInstance())._value())._typeCoreInstance(), processorSupport);
Type propertyTarget = (Type) ImportStub.withImportStubByPass(functionType._returnType()._rawTypeCoreInstance(), processorSupport);
if (propertyTarget != target) {
StringBuilder message = new StringBuilder("Target type for PropertyView ");
message.append(propertyView._id());
message.append(" (");
PackageableElement.writeUserPathForPackageableElement(message, target, "::");
message.append(") does not match the target type of the property ");
PackageableElement.writeUserPathForPackageableElement(message, propertySource, "::");
message.append('.');
message.append(Property.getPropertyName(property));
message.append(" (");
PackageableElement.writeUserPathForPackageableElement(message, propertyTarget, "::");
message.append(')');
throw new PureCompilationException(propertyView.getSourceInformation(), message.toString());
}
}
Aggregations