use of org.finos.legend.pure.m3.tools.matcher.MatcherState in project legend-pure by finos.
the class ClassProjectionUnloaderWalk method run.
@Override
public void run(ClassProjection classProjection, MatcherState state, Matcher matcher, ModelRepository modelRepository, Context context) throws PureCompilationException {
RootRouteNode treeRoot = classProjection._projectionSpecification();
matcher.fullMatch(treeRoot, state);
}
use of org.finos.legend.pure.m3.tools.matcher.MatcherState in project legend-pure by finos.
the class InstanceValueUnbind method run.
@Override
public void run(InstanceValue instanceValue, MatcherState state, Matcher matcher, ModelRepository modelRepository, Context context) throws PureCompilationException {
ProcessorSupport processorSupport = state.getProcessorSupport();
for (CoreInstance value : instanceValue._valuesCoreInstance()) {
if (!(value instanceof Property)) {
((UnbindState) state).freeProcessedAndValidated(value);
}
Shared.cleanUpReferenceUsage(value, instanceValue, processorSupport);
// TODO replace call to Instance.instanceOf once we resolve issue with Path not being available in this module - circular dependency
if (value instanceof LambdaFunction || value instanceof SimpleFunctionExpression || Instance.instanceOf(value, M3Paths.Path, processorSupport) || value instanceof RootRouteNode) {
matcher.fullMatch(value, state);
} else if (Instance.instanceOf(value, M3Paths.RootGraphFetchTree, processorSupport)) {
matcher.fullMatch(value, state);
} else if (value instanceof KeyExpression) {
((UnbindState) state).freeProcessedAndValidated(modelRepository.newBooleanCoreInstance(((KeyExpression) value)._add()));
((UnbindState) state).freeProcessedAndValidated(((KeyExpression) value)._key());
matcher.fullMatch(((KeyExpression) value)._expression(), state);
} else {
Shared.cleanImportStub(value, processorSupport);
}
if (value instanceof ValueSpecification) {
matcher.fullMatch(value, state);
((ValueSpecification) value)._usageContextRemove();
}
}
}
use of org.finos.legend.pure.m3.tools.matcher.MatcherState in project legend-pure by finos.
the class SimpleFunctionExpressionUnbind method cleanAutoMapPropertyIfNecessary.
private static void cleanAutoMapPropertyIfNecessary(FunctionExpression functionExpression, MatcherState state, Matcher matcher) {
ValueSpecification possiblePropertySfe = (ValueSpecification) Automap.getAutoMapExpressionSequence(functionExpression);
if (possiblePropertySfe != null) {
functionExpression._functionNameRemove();
ListIterable<? extends ValueSpecification> params = functionExpression._parametersValues().toList();
ValueSpecification firstParam = params.get(0);
ValueSpecification secondParam = params.get(1);
matcher.fullMatch(secondParam, state);
RichIterable<? extends ValueSpecification> possiblePropertySfeParams = possiblePropertySfe instanceof FunctionExpression ? ((FunctionExpression) possiblePropertySfe)._parametersValues() : // params may have changed after unbinding for the Lambda
Lists.fixedSize.empty();
((UnbindState) state).freeProcessedAndValidated(secondParam);
GenericType secondParamGenericType = secondParam._genericType();
if (secondParamGenericType != null) {
((UnbindState) state).freeValidated(secondParamGenericType);
}
functionExpression._parametersValuesRemove();
MutableList<ValueSpecification> allVars = Lists.mutable.with(firstParam);
// add back qualified properties params
allVars.addAllIterable(possiblePropertySfeParams.toList().subList(1, possiblePropertySfeParams.size()));
functionExpression._parametersValues(allVars);
InstanceValue propertyName = possiblePropertySfe instanceof FunctionExpression ? ((FunctionExpression) possiblePropertySfe)._propertyName() : null;
if (propertyName == null) {
InstanceValue qualifiedPropertyName = possiblePropertySfe instanceof FunctionExpression ? ((FunctionExpression) possiblePropertySfe)._qualifiedPropertyName() : null;
functionExpression._qualifiedPropertyName(qualifiedPropertyName);
} else {
functionExpression._propertyName(propertyName);
}
}
}
use of org.finos.legend.pure.m3.tools.matcher.MatcherState in project legend-pure by finos.
the class SimpleFunctionExpressionUnbind method run.
@Override
public void run(SimpleFunctionExpression functionExpression, MatcherState state, Matcher matcher, ModelRepository modelRepository, Context context) throws PureCompilationException {
ProcessorSupport processorSupport = state.getProcessorSupport();
Function<?> function = (Function<?>) ImportStub.withImportStubByPass(functionExpression._funcCoreInstance(), processorSupport);
if (function != null) {
function._applicationsRemove(functionExpression);
if (function._applications().isEmpty()) {
function._applicationsRemove();
}
}
cleanAutoMapPropertyIfNecessary(functionExpression, state, matcher);
MilestoningDatesPropagationFunctions.undoAutoGenMilestonedQualifier(functionExpression, modelRepository, processorSupport);
functionExpression._funcRemove();
functionExpression._resolvedTypeParametersRemove();
functionExpression._resolvedMultiplicityParametersRemove();
functionExpression._parametersValues().forEach(pv -> matcher.fullMatch(pv, state));
}
use of org.finos.legend.pure.m3.tools.matcher.MatcherState in project legend-pure by finos.
the class TypeUnbind method run.
@Override
public void run(Type type, MatcherState state, Matcher matcher, ModelRepository modelRepository, Context context) throws PureCompilationException {
ProcessorSupport processorSupport = state.getProcessorSupport();
for (Generalization generalization : type._generalizations()) {
GenericType general = generalization._general();
Type generalRawType = null;
try {
generalRawType = (Type) ImportStub.withImportStubByPass(general._rawTypeCoreInstance(), processorSupport);
} catch (PureCompilationException ex) {
// Ignore - if we can't resolve this type was probably already unbound
}
if (generalRawType != null) {
ListIterable<? extends CoreInstance> specializationsToRemove = generalRawType.getValueInValueForMetaPropertyToManyByIndex(M3Properties.specializations, IndexSpecifications.getPropertyValueIndexSpec(M3Properties.specific), type);
for (CoreInstance specialization : specializationsToRemove.toList()) {
generalRawType._specializationsRemove((Generalization) specialization);
}
if (generalRawType.getValueForMetaPropertyToMany(M3Properties.specializations).isEmpty()) {
generalRawType._specializationsRemove();
}
}
Shared.cleanUpGenericType(general, (UnbindState) state, processorSupport);
}
}
Aggregations