Search in sources :

Example 1 with SourceInformation

use of org.finos.legend.pure.m4.coreinstance.SourceInformation in project legend-pure by finos.

the class PrintTypeInferenceObserver method startProcessingFunction.

@Override
public void startProcessingFunction(CoreInstance functionDefinition, CoreInstance functionType) {
    printTab().print("Process function '").print(((FunctionDefinition<?>) functionDefinition)._name());
    SourceInformation sourceInfo = functionDefinition.getSourceInformation();
    if (sourceInfo != null) {
        sourceInfo.appendM4String(this.appendable);
    }
    print(" '(");
    FunctionType.print(this.appendable, functionType, this.processorSupport);
    print(')').printNewline();
}
Also used : SourceInformation(org.finos.legend.pure.m4.coreinstance.SourceInformation)

Example 2 with SourceInformation

use of org.finos.legend.pure.m4.coreinstance.SourceInformation in project legend-pure by finos.

the class TestTypeInferenceObserver method startProcessingFunction.

@Override
public void startProcessingFunction(CoreInstance functionDefinition, CoreInstance functionType) {
    SourceInformation sourceInfo = functionDefinition.getSourceInformation();
    stack.push(sourceInfo != null && sourceInfo.getSourceId().equals("inferenceTest.pure") ? printObserver : stack.peek());
    activeObserver().startProcessingFunction(functionDefinition, functionType);
}
Also used : SourceInformation(org.finos.legend.pure.m4.coreinstance.SourceInformation)

Example 3 with SourceInformation

use of org.finos.legend.pure.m4.coreinstance.SourceInformation in project legend-pure by finos.

the class ReferenceUsage method addReferenceUsage_internal.

private static void addReferenceUsage_internal(CoreInstance used, CoreInstance user, String propertyName, int offset, ModelRepository repository, ProcessorSupport processorSupport, SourceInformation sourceInformationForUsage) {
    CoreInstance usageReference = createReferenceUsage(user, propertyName, offset, repository, processorSupport);
    usageReference.setSourceInformation(sourceInformationForUsage);
    Instance.addValueToProperty(used, M3Properties.referenceUsages, usageReference, processorSupport);
}
Also used : CoreInstance(org.finos.legend.pure.m4.coreinstance.CoreInstance)

Example 4 with SourceInformation

use of org.finos.legend.pure.m4.coreinstance.SourceInformation in project legend-pure by finos.

the class ReferenceUsage method referenceUsagesSimilar.

/**
 * Return whether two reference usages are similar to each other. This is true
 * if the reference usages are equal to each other in terms of property values
 * or if the offsets and property names are equal and the owners are either the
 * same or are equal in terms of classifier and non-null source information. This
 * can be useful for comparing reference usages across different compilations.
 *
 * @param referenceUsage1 one reference usage
 * @param referenceUsage2 another reference usage
 * @return whether reference usages are similar
 */
public static boolean referenceUsagesSimilar(CoreInstance referenceUsage1, CoreInstance referenceUsage2) {
    if (referenceUsage1 == referenceUsage2) {
        return true;
    }
    int offset1 = PrimitiveUtilities.getIntegerValue(referenceUsage1.getValueForMetaPropertyToOne(M3Properties.offset)).intValue();
    int offset2 = PrimitiveUtilities.getIntegerValue(referenceUsage2.getValueForMetaPropertyToOne(M3Properties.offset)).intValue();
    if (offset1 != offset2) {
        return false;
    }
    String propertyName1 = PrimitiveUtilities.getStringValue(referenceUsage1.getValueForMetaPropertyToOne(M3Properties.propertyName));
    String propertyName2 = PrimitiveUtilities.getStringValue(referenceUsage2.getValueForMetaPropertyToOne(M3Properties.propertyName));
    if (!propertyName1.equals(propertyName2)) {
        return false;
    }
    CoreInstance owner1 = referenceUsage1.getValueForMetaPropertyToOne(M3Properties.owner);
    CoreInstance owner2 = referenceUsage2.getValueForMetaPropertyToOne(M3Properties.owner);
    if (owner1 == owner2) {
        return true;
    }
    CoreInstance owner1Classifier = owner1.getClassifier();
    CoreInstance owner2Classifier = owner2.getClassifier();
    if ((owner1Classifier != owner2Classifier) && !PackageableElement.getUserPathForPackageableElement(owner1Classifier).equals(PackageableElement.getUserPathForPackageableElement(owner2Classifier))) {
        return false;
    }
    SourceInformation owner1SourceInfo = owner1.getSourceInformation();
    SourceInformation owner2SourceInfo = owner2.getSourceInformation();
    return (owner1SourceInfo != null) && (owner2SourceInfo != null) && owner1SourceInfo.equals(owner2SourceInfo);
}
Also used : CoreInstance(org.finos.legend.pure.m4.coreinstance.CoreInstance) SourceInformation(org.finos.legend.pure.m4.coreinstance.SourceInformation)

Example 5 with SourceInformation

use of org.finos.legend.pure.m4.coreinstance.SourceInformation in project legend-pure by finos.

the class ConcreteFunctionDefinitionNameProcessor method process.

public static void process(Function<?> function, ModelRepository repository, ProcessorSupport processorSupport) throws PureCompilationException {
    Package parent = function._package();
    if (parent != null) {
        // Make sure we have a unique name for overloaded functions.
        String signature = getSignatureAndResolveImports(function, repository, processorSupport);
        parent._childrenRemove(function);
        function.setName(signature);
        parent._childrenAdd(function);
        if (function._name() == null) {
            function._name(signature);
        }
        if (parent._children().count(c -> signature.equals(c.getName())) > 1) {
            ListIterable<SourceInformation> sourceInfos = parent._children().collectIf(c -> signature.equals(c.getName()), CoreInstance::getSourceInformation, Lists.mutable.empty()).sortThis();
            String pkg = PackageableElement.getUserPathForPackageableElement(parent);
            if (M3Paths.Root.equals(pkg)) {
                pkg = "::";
            }
            StringBuilder message = new StringBuilder("The function '").append(signature).append("' is defined more than once in the package '").append(pkg).append("' at: ");
            boolean first = true;
            for (SourceInformation sourceInfo : sourceInfos) {
                if (first) {
                    first = false;
                } else {
                    message.append(", ");
                }
                message.append(sourceInfo.getSourceId()).append(" (line:").append(sourceInfo.getLine()).append(" column:").append(sourceInfo.getColumn()).append(')');
            }
            throw new PureCompilationException(function.getSourceInformation(), message.toString());
        }
    }
}
Also used : Multiplicity(org.finos.legend.pure.m3.navigation.multiplicity.Multiplicity) VariableExpression(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.valuespecification.VariableExpression) PackageableElement(org.finos.legend.pure.m3.navigation.PackageableElement.PackageableElement) ModelRepository(org.finos.legend.pure.m4.ModelRepository) SourceInformation(org.finos.legend.pure.m4.coreinstance.SourceInformation) Lists(org.eclipse.collections.api.factory.Lists) CoreInstance(org.finos.legend.pure.m4.coreinstance.CoreInstance) MutableList(org.eclipse.collections.api.list.MutableList) Type(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.Type) M3Paths(org.finos.legend.pure.m3.navigation.M3Paths) ProcessorSupport(org.finos.legend.pure.m3.navigation.ProcessorSupport) FunctionType(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.FunctionType) Function(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.function.Function) GenericType(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.generics.GenericType) ImportStub(org.finos.legend.pure.m3.navigation.importstub.ImportStub) Package(org.finos.legend.pure.m3.coreinstance.Package) ListIterable(org.eclipse.collections.api.list.ListIterable) PureCompilationException(org.finos.legend.pure.m4.exception.PureCompilationException) Package(org.finos.legend.pure.m3.coreinstance.Package) SourceInformation(org.finos.legend.pure.m4.coreinstance.SourceInformation) PureCompilationException(org.finos.legend.pure.m4.exception.PureCompilationException)

Aggregations

SourceInformation (org.finos.legend.pure.m4.coreinstance.SourceInformation)127 CoreInstance (org.finos.legend.pure.m4.coreinstance.CoreInstance)117 AntlrSourceInformation (org.finos.legend.pure.m4.serialization.grammar.antlr.AntlrSourceInformation)38 PureCompilationException (org.finos.legend.pure.m4.exception.PureCompilationException)26 PureParserException (org.finos.legend.pure.m4.serialization.grammar.antlr.PureParserException)25 RichIterable (org.eclipse.collections.api.RichIterable)22 GenericType (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.generics.GenericType)21 ProcessorSupport (org.finos.legend.pure.m3.navigation.ProcessorSupport)21 PureExecutionException (org.finos.legend.pure.m3.exception.PureExecutionException)20 ListIterable (org.eclipse.collections.api.list.ListIterable)19 PrimitiveCoreInstance (org.finos.legend.pure.m4.coreinstance.primitive.PrimitiveCoreInstance)19 MutableList (org.eclipse.collections.api.list.MutableList)18 PureException (org.finos.legend.pure.m4.exception.PureException)18 Test (org.junit.Test)18 Package (org.finos.legend.pure.m3.coreinstance.Package)17 Type (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.Type)16 FunctionType (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.FunctionType)15 VariableExpression (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.valuespecification.VariableExpression)15 MutableSet (org.eclipse.collections.api.set.MutableSet)14 ValueSpecification (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.valuespecification.ValueSpecification)14