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();
}
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);
}
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);
}
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);
}
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());
}
}
}
Aggregations