Skip to content

Commit

Permalink
Fix source info for mappingTest StoreTestData store and add source in…
Browse files Browse the repository at this point in the history
…fo to profile tags and stereotypes
  • Loading branch information
yash0024 committed Jul 1, 2024
1 parent d4d645d commit 377c9d3
Show file tree
Hide file tree
Showing 15 changed files with 175 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -556,13 +556,13 @@ static Root_meta_pure_data_StoreTestData processMappingElementTestData(StoreTest
.filter(Objects::nonNull)
.findFirst()
.orElseThrow(() -> new UnsupportedOperationException("Unsupported data")));
if (testData.store.equals("ModelStore"))
if (testData.store.path.equals("ModelStore"))
{
mappingStoreTestData._store(new Root_meta_external_store_model_ModelStore_Impl(""));
}
else
{
mappingStoreTestData._store(context.resolveStore(testData.store));
mappingStoreTestData._store(context.resolveStore(testData.store.path, testData.store.sourceInformation));
}
return mappingStoreTestData;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,8 @@ public PackageableElement visit(Profile profile)
this.context.pureModel.profilesIndex.put(fullPath, targetProfile);
setNameAndPackage(targetProfile, profile);
return targetProfile
._p_stereotypes(ListIterate.collect(profile.stereotypes, st -> newStereotype(targetProfile, st)))
._p_tags(ListIterate.collect(profile.tags, t -> newTag(targetProfile, t)));
._p_stereotypes(ListIterate.collect(profile.stereotypes, st -> newStereotype(targetProfile, st.value, st.sourceInformation)))
._p_tags(ListIterate.collect(profile.tags, t -> newTag(targetProfile, t.value, t.sourceInformation)));
}

@Override
Expand Down Expand Up @@ -281,16 +281,16 @@ private GenericType newGenericType(Type rawType, RichIterable<? extends GenericT
return newGenericType(rawType)._typeArguments(typeArguments);
}

private Stereotype newStereotype(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.extension.Profile profile, String name)
private Stereotype newStereotype(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.extension.Profile profile, String name, SourceInformation sourceInformation)
{
return new Root_meta_pure_metamodel_extension_Stereotype_Impl(name, null, this.context.pureModel.getClass("meta::pure::metamodel::extension::Stereotype"))
return new Root_meta_pure_metamodel_extension_Stereotype_Impl(name, SourceInformationHelper.toM3SourceInformation(sourceInformation), this.context.pureModel.getClass("meta::pure::metamodel::extension::Stereotype"))
._value(name)
._profile(profile);
}

private Tag newTag(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.extension.Profile profile, String name)
private Tag newTag(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.extension.Profile profile, String name, SourceInformation sourceInformation)
{
return new Root_meta_pure_metamodel_extension_Tag_Impl(name, null, this.context.pureModel.getClass("meta::pure::metamodel::extension::Tag"))
return new Root_meta_pure_metamodel_extension_Tag_Impl(name, SourceInformationHelper.toM3SourceInformation(sourceInformation), this.context.pureModel.getClass("meta::pure::metamodel::extension::Tag"))
._value(name)
._profile(profile);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

import java.util.LinkedHashMap;
import java.util.Map;
import java.util.stream.Collectors;

public class ProfileValidator
{
Expand All @@ -43,7 +44,7 @@ private void validateTags(PureModel pureModel, Map<String, Profile> elements)
{
elements.values().forEach(el ->
{
MutableMultimap<String, String> tags = Iterate.groupBy(el.tags, p -> p);
MutableMultimap<String, String> tags = Iterate.groupBy(el.tags.stream().map(t -> t.value).collect(Collectors.toList()), p -> p);
pureModel.addWarnings(tags.multiValuesView().flatCollect(a -> a.size() > 1 ? Lists.mutable.with(new Warning(el.sourceInformation, "Found duplicated tag '" + a.getFirst() + "' in profile '" + pureModel.buildPackageString(el._package, el.name) + "'")) : Lists.mutable.empty()));
});
}
Expand All @@ -52,7 +53,7 @@ private void validateStereotypes(PureModel pureModel, Map<String, Profile> eleme
{
elements.values().forEach(el ->
{
MutableMultimap<String, String> stereotypes = Iterate.groupBy(el.stereotypes, p -> p);
MutableMultimap<String, String> stereotypes = Iterate.groupBy(el.stereotypes.stream().map(st -> st.value).collect(Collectors.toList()), p -> p);
pureModel.addWarnings(stereotypes.multiValuesView().flatCollect(a -> a.size() > 1 ? Lists.mutable.with(new Warning(el.sourceInformation, "Found duplicated stereotype '" + a.getFirst() + "' in profile '" + pureModel.buildPackageString(el._package, el.name) + "'")) : Lists.mutable.empty()));
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2857,7 +2857,7 @@ public void testCompilationForGraphFetchTreeWithSubTypeTreeAtRootLevel()
" }\n" +
" }\n" +
" }#\n" +
"}\n", "COMPILATION error at [16:7-18:7]: The type Street is not a subtype of Address"
"}\n", "COMPILATION error at [16:18-29]: The type Street is not a subtype of Address"
);

test("Class test::Address\n" +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@
import org.finos.legend.engine.protocol.pure.v1.model.packageableElement.domain.Multiplicity;
import org.finos.legend.engine.protocol.pure.v1.model.packageableElement.domain.ParameterValue;
import org.finos.legend.engine.protocol.pure.v1.model.packageableElement.domain.Profile;
import org.finos.legend.engine.protocol.pure.v1.model.packageableElement.domain.ProfileStereotype;
import org.finos.legend.engine.protocol.pure.v1.model.packageableElement.domain.ProfileTag;
import org.finos.legend.engine.protocol.pure.v1.model.packageableElement.domain.Property;
import org.finos.legend.engine.protocol.pure.v1.model.packageableElement.domain.QualifiedProperty;
import org.finos.legend.engine.protocol.pure.v1.model.packageableElement.domain.StereotypePtr;
Expand Down Expand Up @@ -175,11 +177,11 @@ private Profile visitProfile(DomainParserGrammar.ProfileContext ctx)

// stereotypes
DomainParserGrammar.StereotypeDefinitionsContext stereotypeDefinitionsContext = PureGrammarParserUtility.validateAndExtractOptionalField(ctx.stereotypeDefinitions(), "stereotypes", profile.sourceInformation);
profile.stereotypes = stereotypeDefinitionsContext != null ? ListIterate.collect(stereotypeDefinitionsContext.identifier(), PureGrammarParserUtility::fromIdentifier) : Lists.mutable.empty();
profile.stereotypes = stereotypeDefinitionsContext != null ? ListIterate.collect(stereotypeDefinitionsContext.identifier(), identifierContext -> new ProfileStereotype(PureGrammarParserUtility.fromIdentifier(identifierContext), this.walkerSourceInformation.getSourceInformation(identifierContext))) : Lists.mutable.empty();

// tags
DomainParserGrammar.TagDefinitionsContext tagDefinitionsContext = PureGrammarParserUtility.validateAndExtractOptionalField(ctx.tagDefinitions(), "tags", profile.sourceInformation);
profile.tags = tagDefinitionsContext != null ? ListIterate.collect(tagDefinitionsContext.identifier(), PureGrammarParserUtility::fromIdentifier) : Lists.mutable.empty();
profile.tags = tagDefinitionsContext != null ? ListIterate.collect(tagDefinitionsContext.identifier(), identifierContext -> new ProfileTag(PureGrammarParserUtility.fromIdentifier(identifierContext), this.walkerSourceInformation.getSourceInformation(identifierContext))) : Lists.mutable.empty();

return profile;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ private SubTypeGraphFetchTree visitSubTypeGraphPathContext(GraphFetchTreeParserG
}

SubTypeGraphFetchTree result = new SubTypeGraphFetchTree();
result.sourceInformation = walkerSourceInformation.getSourceInformation(subTypeGraphPathContext);
result.sourceInformation = walkerSourceInformation.getSourceInformation(subTypeGraphPathContext.subtype().qualifiedName());
result.subTrees = subTrees;
result.subTypeClass = PureGrammarParserUtility.fromIdentifier(subTypeGraphPathContext.subtype().qualifiedName());
return result;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import org.finos.legend.engine.language.pure.grammar.from.test.assertion.HelperTestAssertionGrammarParser;
import org.finos.legend.engine.protocol.pure.v1.model.SourceInformation;
import org.finos.legend.engine.protocol.pure.v1.model.context.EngineErrorType;
import org.finos.legend.engine.protocol.pure.v1.model.context.PackageableElementType;
import org.finos.legend.engine.protocol.pure.v1.model.packageableElement.PackageableElement;
import org.finos.legend.engine.protocol.pure.v1.model.packageableElement.mapping.AssociationMapping;
import org.finos.legend.engine.protocol.pure.v1.model.packageableElement.mapping.ClassMapping;
Expand All @@ -43,6 +44,7 @@
import org.finos.legend.engine.protocol.pure.v1.model.packageableElement.mapping.mappingTest.MappingTest_Legacy;
import org.finos.legend.engine.protocol.pure.v1.model.packageableElement.mapping.mappingTest.StoreTestData;
import org.finos.legend.engine.protocol.pure.v1.model.packageableElement.section.ImportAwareCodeSection;
import org.finos.legend.engine.protocol.pure.v1.model.packageableElement.store.StoreProviderPointer;
import org.finos.legend.engine.protocol.pure.v1.model.test.assertion.TestAssertion;
import org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.ValueSpecification;
import org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.raw.Lambda;
Expand Down Expand Up @@ -184,7 +186,9 @@ private StoreTestData visitMappingStoreTestData(MappingParserGrammar.MappingTest
{
StoreTestData testData = new StoreTestData();
testData.data = HelperEmbeddedDataGrammarParser.parseEmbeddedData(ctx.embeddedData(), this.walkerSourceInformation, this.parserContext.getPureGrammarParserExtensions());
testData.store = ctx.qualifiedName().packagePath() == null ? ctx.qualifiedName().getText() : PureGrammarParserUtility.fromQualifiedName(ctx.qualifiedName().packagePath().identifier(), ctx.qualifiedName().identifier()); //build store
String path = ctx.qualifiedName().packagePath() == null ? ctx.qualifiedName().getText() : PureGrammarParserUtility.fromQualifiedName(ctx.qualifiedName().packagePath().identifier(), ctx.qualifiedName().identifier()); //build store
testData.store = new StoreProviderPointer(PackageableElementType.STORE, path, this.walkerSourceInformation.getSourceInformation(ctx.qualifiedName()));
testData.sourceInformation = this.walkerSourceInformation.getSourceInformation(ctx);
return testData;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -319,11 +319,11 @@ public String visit(Profile profile)
builder.append("Profile ").append(PureGrammarComposerUtility.convertPath(profile.getPath())).append("\n").append("{\n");
if (profile.stereotypes != null && !profile.stereotypes.isEmpty())
{
builder.append(getTabString()).append("stereotypes: [").append(Lists.mutable.withAll(profile.stereotypes).collect(PureGrammarComposerUtility::convertIdentifier).makeString(", ")).append("];\n");
builder.append(getTabString()).append("stereotypes: [").append(Lists.mutable.withAll(profile.stereotypes).collect(profileStereoType -> PureGrammarComposerUtility.convertIdentifier(profileStereoType.value)).makeString(", ")).append("];\n");
}
if (profile.tags != null && !profile.tags.isEmpty())
{
builder.append(getTabString()).append("tags: [").append(Lists.mutable.withAll(profile.tags).collect(PureGrammarComposerUtility::convertIdentifier).makeString(", ")).append("];\n");
builder.append(getTabString()).append("tags: [").append(Lists.mutable.withAll(profile.tags).collect(profileTag -> PureGrammarComposerUtility.convertIdentifier(profileTag.value)).makeString(", ")).append("];\n");
}
return builder.append("}").toString();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ public static String renderStoreTestData(List<StoreTestData> storeTestData, DEPR
public static String renderStoreElementTestData(StoreTestData mappingStoreTestData, DEPRECATED_PureGrammarComposerCore transformer, int baseIndentation)
{
StringBuilder str = new StringBuilder();
str.append(getTabString(baseIndentation)).append(mappingStoreTestData.store).append(":\n");
str.append(getTabString(baseIndentation)).append(mappingStoreTestData.store.path).append(":\n");
str.append(HelperEmbeddedDataGrammarComposer.composeEmbeddedData(mappingStoreTestData.data, PureGrammarComposerContext.Builder.newInstance(transformer.toContext()).withIndentationString(getTabString(baseIndentation + 1)).build()));
return str.toString();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.finos.legend.engine.protocol.pure.v1.model.context.PureModelContextData;
import org.finos.legend.engine.protocol.pure.v1.model.packageableElement.PackageableElement;
import org.finos.legend.engine.protocol.pure.v1.model.packageableElement.domain.Class;
import org.finos.legend.engine.protocol.pure.v1.model.packageableElement.domain.Profile;
import org.junit.Assert;
import org.junit.Test;

Expand Down Expand Up @@ -114,4 +115,52 @@ public void testClass()
Assert.assertEquals(1, aClass.superTypes.get(0).sourceInformation.startLine);
Assert.assertEquals(71, aClass.superTypes.get(0).sourceInformation.startColumn);
}

@Test
public void testProfile()
{
PureModelContextData pureModelContextData = test("Profile test::A\n" +
"{\n" +
" tags : [tag1, tag2];\n" +
" stereotypes : [stereotype1, stereotype2];\n" +
"}\n");

Map<String, PackageableElement> elementMap = pureModelContextData.getElements().stream().collect(Collectors.toMap(x -> x.getPath(), Function.identity()));

Profile profile = (Profile) elementMap.get("test::A");

Assert.assertNotNull(profile.sourceInformation);
Assert.assertEquals(1, profile.sourceInformation.startLine);
Assert.assertEquals(5, profile.sourceInformation.endLine);
Assert.assertEquals(1, profile.sourceInformation.startColumn);
Assert.assertEquals(1, profile.sourceInformation.endColumn);
Assert.assertEquals(2, profile.stereotypes.size());
Assert.assertEquals(2, profile.tags.size());

Assert.assertEquals("stereotype1", profile.stereotypes.get(0).value);
Assert.assertEquals("stereotype2", profile.stereotypes.get(1).value);

Assert.assertNotNull(profile.stereotypes.get(0).sourceInformation);
Assert.assertEquals(4, profile.stereotypes.get(0).sourceInformation.startLine);
Assert.assertEquals(4, profile.stereotypes.get(0).sourceInformation.endLine);
Assert.assertEquals(19, profile.stereotypes.get(0).sourceInformation.startColumn);
Assert.assertEquals(29, profile.stereotypes.get(0).sourceInformation.endColumn);
Assert.assertEquals(4, profile.stereotypes.get(1).sourceInformation.startLine);
Assert.assertEquals(4, profile.stereotypes.get(1).sourceInformation.endLine);
Assert.assertEquals(32, profile.stereotypes.get(1).sourceInformation.startColumn);
Assert.assertEquals(42, profile.stereotypes.get(1).sourceInformation.endColumn);

Assert.assertEquals("tag1", profile.tags.get(0).value);
Assert.assertEquals("tag2", profile.tags.get(1).value);

Assert.assertNotNull(profile.tags.get(0).sourceInformation);
Assert.assertEquals(3, profile.tags.get(0).sourceInformation.startLine);
Assert.assertEquals(3, profile.tags.get(0).sourceInformation.endLine);
Assert.assertEquals(12, profile.tags.get(0).sourceInformation.startColumn);
Assert.assertEquals(15, profile.tags.get(0).sourceInformation.endColumn);
Assert.assertEquals(3, profile.tags.get(1).sourceInformation.startLine);
Assert.assertEquals(3, profile.tags.get(1).sourceInformation.endLine);
Assert.assertEquals(18, profile.tags.get(1).sourceInformation.startColumn);
Assert.assertEquals(21, profile.tags.get(1).sourceInformation.endColumn);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

package org.finos.legend.engine.protocol.pure.v1.model.packageableElement.domain;

import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import org.finos.legend.engine.protocol.pure.v1.model.packageableElement.PackageableElement;
import org.finos.legend.engine.protocol.pure.v1.model.packageableElement.PackageableElementVisitor;

Expand All @@ -22,8 +23,10 @@

public class Profile extends PackageableElement
{
public List<String> stereotypes = Collections.emptyList();
public List<String> tags = Collections.emptyList();
@JsonSerialize(contentConverter = ProfileStereotype.ToPathSerializerConverter.class)
public List<ProfileStereotype> stereotypes = Collections.emptyList();
@JsonSerialize(contentConverter = ProfileTag.ToPathSerializerConverter.class)
public List<ProfileTag> tags = Collections.emptyList();

@Override
public <T> T accept(PackageableElementVisitor<T> visitor)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// Copyright 2024 Goldman Sachs
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package org.finos.legend.engine.protocol.pure.v1.model.packageableElement.domain;

import com.fasterxml.jackson.databind.util.StdConverter;
import org.finos.legend.engine.protocol.pure.v1.model.SourceInformation;

public class ProfileStereotype
{
public String value;
public SourceInformation sourceInformation;

public ProfileStereotype(String value, SourceInformation sourceInformation)
{
this.value = value;
this.sourceInformation = sourceInformation;
}

public ProfileStereotype(String value)
{
this.value = value;
this.sourceInformation = null;
}

public static class ToPathSerializerConverter extends StdConverter<ProfileStereotype, String>
{
@Override
public String convert(ProfileStereotype stereotype)
{
return stereotype.value;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// Copyright 2024 Goldman Sachs
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package org.finos.legend.engine.protocol.pure.v1.model.packageableElement.domain;

import com.fasterxml.jackson.databind.util.StdConverter;
import org.finos.legend.engine.protocol.pure.v1.model.SourceInformation;

public class ProfileTag
{
public String value;
public SourceInformation sourceInformation;

public ProfileTag(String value, SourceInformation sourceInformation)
{
this.value = value;
this.sourceInformation = sourceInformation;
}

public ProfileTag(String value)
{
this.value = value;
this.sourceInformation = null;
}

public static class ToPathSerializerConverter extends StdConverter<ProfileTag, String>
{
@Override
public String convert(ProfileTag tag)
{
return tag.value;
}
}
}
Loading

0 comments on commit 377c9d3

Please sign in to comment.