Skip to content

Commit

Permalink
Avoid dropping source information
Browse files Browse the repository at this point in the history
  • Loading branch information
rafaelbey committed Nov 26, 2024
1 parent 598321b commit 99285a5
Show file tree
Hide file tree
Showing 18 changed files with 26 additions and 145 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public void testNewConstructorWithMissingTypeArgumentsCompiles()
" {\n" +
// ---------- type to construct, no type arguments
" \"_type\": \"packageableElementPtr\",\n" +
" \"fullPath\": \"BasicColumnSpecification\"\n" +
" \"fullPath\": \"TdsOlapRank\"\n" +
// ---------- type to construct, no type arguments
" },\n" +
" {\n" +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public void testProtocolGeneration()
@Test
public void testImportParsing()
{
test(getJsonString("pureImportParsingTest.json"), "{\"isolatedLambdas\":{\"lambdas\":{}},\"modelDataContext\":{\"_type\":\"data\",\"elements\":[{\"_type\":\"class\",\"constraints\":[],\"name\":\"Person\",\"originalMilestonedProperties\":[],\"package\":\"model\",\"properties\":[{\"genericType\":{\"multiplicityArguments\":[],\"rawType\":{\"_type\":\"packageableType\",\"fullPath\":\"TargetA\",\"sourceInformation\":{\"endColumn\":18,\"endLine\":4,\"sourceId\":\"\",\"startColumn\":12,\"startLine\":4}},\"typeArguments\":[],\"typeVariableValues\":[]},\"multiplicity\":{\"lowerBound\":1,\"upperBound\":1},\"name\":\"targetA\",\"sourceInformation\":{\"endColumn\":22,\"endLine\":4,\"sourceId\":\"\",\"startColumn\":3,\"startLine\":4},\"stereotypes\":[],\"taggedValues\":[]}],\"qualifiedProperties\":[],\"sourceInformation\":{\"endColumn\":1,\"endLine\":5,\"sourceId\":\"\",\"startColumn\":1,\"startLine\":2},\"stereotypes\":[],\"superTypes\":[\"VersionClass\"],\"taggedValues\":[{\"sourceInformation\":{\"endColumn\":20,\"endLine\":2,\"sourceId\":\"\",\"startColumn\":8,\"startLine\":2},\"tag\":{\"profile\":\"doc\",\"profileSourceInformation\":{\"endColumn\":10,\"endLine\":2,\"sourceId\":\"\",\"startColumn\":8,\"startLine\":2},\"sourceInformation\":{\"endColumn\":14,\"endLine\":2,\"sourceId\":\"\",\"startColumn\":12,\"startLine\":2},\"value\":\"doc\"},\"value\":\"a\"}]},{\"_type\":\"sectionIndex\",\"name\":\"SectionIndex\",\"package\":\"__internal__\",\"sections\":[{\"_type\":\"importAware\",\"elements\":[\"model::Person\"],\"imports\":[\"projectA\"],\"parserName\":\"Pure\",\"sourceInformation\":{\"endColumn\":2,\"endLine\":7,\"sourceId\":\"\",\"startColumn\":1,\"startLine\":1}}]}]},\"renderStyle\":\"STANDARD\"}");
test(getJsonString("pureImportParsingTest.json"), "{\"isolatedLambdas\":{\"lambdas\":{}},\"modelDataContext\":{\"_type\":\"data\",\"elements\":[{\"_type\":\"class\",\"constraints\":[],\"name\":\"Person\",\"originalMilestonedProperties\":[],\"package\":\"model\",\"properties\":[{\"genericType\":{\"multiplicityArguments\":[],\"rawType\":{\"_type\":\"packageableType\",\"fullPath\":\"TargetA\",\"sourceInformation\":{\"endColumn\":18,\"endLine\":4,\"sourceId\":\"\",\"startColumn\":12,\"startLine\":4}},\"typeArguments\":[],\"typeVariableValues\":[]},\"multiplicity\":{\"lowerBound\":1,\"upperBound\":1},\"name\":\"targetA\",\"sourceInformation\":{\"endColumn\":22,\"endLine\":4,\"sourceId\":\"\",\"startColumn\":3,\"startLine\":4},\"stereotypes\":[],\"taggedValues\":[]}],\"qualifiedProperties\":[],\"sourceInformation\":{\"endColumn\":1,\"endLine\":5,\"sourceId\":\"\",\"startColumn\":1,\"startLine\":2},\"stereotypes\":[],\"superTypes\":[{\"path\":\"VersionClass\",\"sourceInformation\":{\"endColumn\":56,\"endLine\":2,\"sourceId\":\"\",\"startColumn\":45,\"startLine\":2},\"type\":\"CLASS\"}],\"taggedValues\":[{\"sourceInformation\":{\"endColumn\":20,\"endLine\":2,\"sourceId\":\"\",\"startColumn\":8,\"startLine\":2},\"tag\":{\"profile\":\"doc\",\"profileSourceInformation\":{\"endColumn\":10,\"endLine\":2,\"sourceId\":\"\",\"startColumn\":8,\"startLine\":2},\"sourceInformation\":{\"endColumn\":14,\"endLine\":2,\"sourceId\":\"\",\"startColumn\":12,\"startLine\":2},\"value\":\"doc\"},\"value\":\"a\"}]},{\"_type\":\"sectionIndex\",\"name\":\"SectionIndex\",\"package\":\"__internal__\",\"sections\":[{\"_type\":\"importAware\",\"elements\":[\"model::Person\"],\"imports\":[\"projectA\"],\"parserName\":\"Pure\",\"sourceInformation\":{\"endColumn\":2,\"endLine\":7,\"sourceId\":\"\",\"startColumn\":1,\"startLine\":1}}]}]},\"renderStyle\":\"STANDARD\"}");
}

@Test
Expand Down Expand Up @@ -96,7 +96,7 @@ public void testMappingIncludeSerialization()
@Test
public void testEnumerationMappingWithStructuredSourceValueSerialization()
{
test("{\"code\": \"###Mapping\\nMapping a::mapping\\n(test::IncType : EnumerationMapping a\\n{ CORP : [1], LLC : [2] })\"}", "{\"isolatedLambdas\":{\"lambdas\":{}},\"modelDataContext\":{\"_type\":\"data\",\"elements\":[{\"_type\":\"mapping\",\"associationMappings\":[],\"classMappings\":[],\"enumerationMappings\":[{\"enumValueMappings\":[{\"enumValue\":\"CORP\",\"sourceValues\":[{\"_type\":\"integerSourceValue\",\"value\":1}]},{\"enumValue\":\"LLC\",\"sourceValues\":[{\"_type\":\"integerSourceValue\",\"value\":2}]}],\"enumeration\":\"test::IncType\",\"id\":\"a\",\"sourceInformation\":{\"endColumn\":25,\"endLine\":4,\"sourceId\":\"\",\"startColumn\":2,\"startLine\":3}}],\"includedMappings\":[],\"name\":\"mapping\",\"package\":\"a\",\"sourceInformation\":{\"endColumn\":26,\"endLine\":4,\"sourceId\":\"\",\"startColumn\":1,\"startLine\":2},\"tests\":[]},{\"_type\":\"sectionIndex\",\"name\":\"SectionIndex\",\"package\":\"__internal__\",\"sections\":[{\"_type\":\"importAware\",\"elements\":[],\"imports\":[],\"parserName\":\"Pure\",\"sourceInformation\":{\"endColumn\":8,\"endLine\":1,\"sourceId\":\"\",\"startColumn\":1,\"startLine\":1}},{\"_type\":\"importAware\",\"elements\":[\"a::mapping\"],\"imports\":[],\"parserName\":\"Mapping\",\"sourceInformation\":{\"endColumn\":26,\"endLine\":6,\"sourceId\":\"\",\"startColumn\":8,\"startLine\":2}}]}]},\"renderStyle\":\"STANDARD\"}");
test("{\"code\": \"###Mapping\\nMapping a::mapping\\n(test::IncType : EnumerationMapping a\\n{ CORP : [1], LLC : [2] })\"}", "{\"isolatedLambdas\":{\"lambdas\":{}},\"modelDataContext\":{\"_type\":\"data\",\"elements\":[{\"_type\":\"mapping\",\"associationMappings\":[],\"classMappings\":[],\"enumerationMappings\":[{\"enumValueMappings\":[{\"enumValue\":\"CORP\",\"sourceValues\":[{\"_type\":\"integerSourceValue\",\"value\":1}]},{\"enumValue\":\"LLC\",\"sourceValues\":[{\"_type\":\"integerSourceValue\",\"value\":2}]}],\"enumeration\":{\"path\":\"test::IncType\",\"sourceInformation\":{\"endColumn\":14,\"endLine\":3,\"sourceId\":\"\",\"startColumn\":2,\"startLine\":3},\"type\":\"ENUMERATION\"},\"id\":\"a\",\"sourceInformation\":{\"endColumn\":25,\"endLine\":4,\"sourceId\":\"\",\"startColumn\":2,\"startLine\":3}}],\"includedMappings\":[],\"name\":\"mapping\",\"package\":\"a\",\"sourceInformation\":{\"endColumn\":26,\"endLine\":4,\"sourceId\":\"\",\"startColumn\":1,\"startLine\":2},\"tests\":[]},{\"_type\":\"sectionIndex\",\"name\":\"SectionIndex\",\"package\":\"__internal__\",\"sections\":[{\"_type\":\"importAware\",\"elements\":[],\"imports\":[],\"parserName\":\"Pure\",\"sourceInformation\":{\"endColumn\":8,\"endLine\":1,\"sourceId\":\"\",\"startColumn\":1,\"startLine\":1}},{\"_type\":\"importAware\",\"elements\":[\"a::mapping\"],\"imports\":[],\"parserName\":\"Mapping\",\"sourceInformation\":{\"endColumn\":26,\"endLine\":6,\"sourceId\":\"\",\"startColumn\":8,\"startLine\":2}}]}]},\"renderStyle\":\"STANDARD\"}");
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.util.StdConverter;
import java.util.Objects;
import org.finos.legend.engine.protocol.pure.v1.model.SourceInformation;

Expand Down Expand Up @@ -81,15 +80,6 @@ public int hashCode()
{
return Objects.hash(type, path);
}

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


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,58 +14,9 @@

package org.finos.legend.engine.protocol.pure.v1.model.data;

import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.ObjectCodec;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonDeserializer;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import java.io.IOException;
import java.util.Objects;
import org.finos.legend.engine.protocol.pure.v1.model.SourceInformation;
import org.finos.legend.engine.protocol.pure.v1.model.context.PackageableElementPointer;
import org.finos.legend.engine.protocol.pure.v1.model.context.PackageableElementType;

@JsonDeserialize(using = DataElementReference.DataElementReferenceDeserializer.class)
public class DataElementReference extends EmbeddedData
{
public PackageableElementPointer dataElement;

public static class DataElementReferenceDeserializer extends JsonDeserializer<DataElementReference>
{
@Override
public DataElementReference deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException
{
ObjectCodec codec = jsonParser.getCodec();
JsonNode node = codec.readTree(jsonParser);
JsonNode dataElementNode = node.get("dataElement");
DataElementReference dataElementReference = new DataElementReference();
if (dataElementNode != null)
{
if (dataElementNode.isTextual())
{
dataElementReference.dataElement = new PackageableElementPointer(
PackageableElementType.DATA,
dataElementNode.textValue(),
Objects.isNull(node.get("sourceInformation")) ? null : codec.treeToValue(node.get("sourceInformation"), SourceInformation.class)
);
}
else if (dataElementNode.isObject())
{
dataElementReference.dataElement = codec.treeToValue(dataElementNode, PackageableElementPointer.class);
}
else
{
throw new IOException("DataElementReference expects property 'dataElement' to be a PackageableElementPointer");
}
}
// for backward compatability
else
{
throw new IOException("DataElementReference requires attribute dataElement.");
}
return dataElementReference;
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,14 @@

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

import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import java.util.Collections;
import java.util.List;
import org.finos.legend.engine.protocol.pure.v1.model.context.PackageableElementPointer;
import org.finos.legend.engine.protocol.pure.v1.model.packageableElement.PackageableElement;
import org.finos.legend.engine.protocol.pure.v1.model.packageableElement.PackageableElementVisitor;

import java.util.Collections;
import java.util.List;

public class Class extends PackageableElement
{
@JsonSerialize(contentConverter = PackageableElementPointer.ToPathSerializerConverter.class)
public List<PackageableElementPointer> superTypes = Collections.emptyList();
public List<Property> originalMilestonedProperties = Collections.emptyList();
public List<Property> properties = Collections.emptyList();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,14 @@

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;

import java.util.Collections;
import java.util.List;
import org.finos.legend.engine.protocol.pure.v1.model.packageableElement.PackageableElement;
import org.finos.legend.engine.protocol.pure.v1.model.packageableElement.PackageableElementVisitor;

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

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,32 +14,26 @@

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

import com.fasterxml.jackson.databind.util.StdConverter;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
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)
@JsonCreator(mode = JsonCreator.Mode.PROPERTIES)
public ProfileStereotype(@JsonProperty("value") String value, @JsonProperty("sourceInformation") SourceInformation sourceInformation)
{
this.value = value;
this.sourceInformation = sourceInformation;
}

@JsonCreator(mode = JsonCreator.Mode.DELEGATING)
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
Expand Up @@ -14,32 +14,26 @@

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

import com.fasterxml.jackson.databind.util.StdConverter;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
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)
@JsonCreator(mode = JsonCreator.Mode.PROPERTIES)
public ProfileTag(@JsonProperty("value") String value, @JsonProperty("sourceInformation") SourceInformation sourceInformation)
{
this.value = value;
this.sourceInformation = sourceInformation;
}

@JsonCreator(mode = JsonCreator.Mode.DELEGATING)
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;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,19 @@

import com.fasterxml.jackson.annotation.JsonSubTypes;
import com.fasterxml.jackson.annotation.JsonTypeInfo;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import java.util.Collections;
import java.util.List;
import org.finos.legend.engine.protocol.pure.v1.model.SourceInformation;
import org.finos.legend.engine.protocol.pure.v1.model.context.PackageableElementPointer;
import org.finos.legend.engine.protocol.pure.v1.model.packageableElement.mapping.xStore.XStoreAssociationMapping;

import java.util.Collections;
import java.util.List;

@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, property = "_type")
@JsonSubTypes({
@JsonSubTypes.Type(value = XStoreAssociationMapping.class, name = "xStore")
})
public abstract class AssociationMapping
{
public String id;
@JsonSerialize(converter = PackageableElementPointer.ToPathSerializerConverter.class)
public PackageableElementPointer association;
public List<String> stores = Collections.emptyList();
public SourceInformation sourceInformation;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,13 @@
package org.finos.legend.engine.protocol.pure.v1.model.packageableElement.mapping;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import java.util.List;
import org.finos.legend.engine.protocol.pure.v1.model.SourceInformation;
import org.finos.legend.engine.protocol.pure.v1.model.context.PackageableElementPointer;

import java.util.List;

public class EnumerationMapping
{
public String id;
@JsonSerialize(converter = PackageableElementPointer.ToPathSerializerConverter.class)
public PackageableElementPointer enumeration;
public List<EnumValueMapping> enumValueMappings;
@Deprecated
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,13 @@

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

import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import org.finos.legend.engine.protocol.pure.v1.model.SourceInformation;
import org.finos.legend.engine.protocol.pure.v1.model.context.PackageableElementPointer;
import org.finos.legend.engine.protocol.pure.v1.model.data.EmbeddedData;
import org.finos.legend.engine.protocol.pure.v1.model.packageableElement.store.StoreProviderPointer;

public class StoreTestData
{
public String doc;
@JsonSerialize(converter = PackageableElementPointer.ToPathSerializerConverter.class)
public StoreProviderPointer store;
public EmbeddedData data;
public SourceInformation sourceInformation;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,12 @@

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

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

import java.util.Collections;
import java.util.List;
import org.finos.legend.engine.protocol.pure.v1.model.context.PackageableElementPointer;
import org.finos.legend.engine.protocol.pure.v1.model.packageableElement.PackageableElement;

public abstract class Store extends PackageableElement
{
@JsonSerialize(contentConverter = PackageableElementPointer.ToPathSerializerConverter.class)
public List<PackageableElementPointer> includedStores = Collections.emptyList();
}
Loading

0 comments on commit 99285a5

Please sign in to comment.