Skip to content

Commit

Permalink
Ensure source information is present in pkg elements after parsing (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
rafaelbey authored Jul 26, 2024
1 parent fdd3b40 commit 811ed0f
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,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.Function;
import org.finos.legend.engine.protocol.pure.v1.model.packageableElement.section.SectionIndex;
import org.finos.legend.engine.shared.core.ObjectMapperFactory;
import org.finos.legend.engine.shared.core.identity.Identity;
import org.finos.legend.engine.shared.core.identity.factory.*;
Expand Down Expand Up @@ -92,7 +93,15 @@ public void testParserGrammarIdentifierInclusion()

protected static PureModelContextData test(String val)
{
return PureGrammarParser.newInstance().parseModel(val);
PureModelContextData pureModelContextData = PureGrammarParser.newInstance().parseModel(val);
for (PackageableElement element : pureModelContextData.getElements())
{
if (!(element instanceof SectionIndex))
{
Assert.assertNotNull("Missing source information: " + element.getClass().getName() + '(' + element.getPath() + ')', element.sourceInformation);
}
}
return pureModelContextData;
}

protected static void test(String val, String expectedErrorMsg)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ private AuthenticationDemo visitAuthenticationDemo(AuthenticationParserGrammar.E
AuthenticationParserGrammar.AuthenticationDemoContext ctx = elementDefinitionContext.authenticationDemo();
authenticationDemo.name = PureGrammarParserUtility.fromIdentifier(ctx.qualifiedName().identifier());
authenticationDemo._package = ctx.qualifiedName().packagePath() == null ? "" : PureGrammarParserUtility.fromPath(ctx.qualifiedName().packagePath().identifier());
authenticationDemo.sourceInformation = walkerSourceInformation.getSourceInformation(ctx);

// authentication
AuthenticationParserGrammar.AuthenticationContext authenticationContext = PureGrammarParserUtility.validateAndExtractRequiredField(ctx.authentication(), "authentication", authenticationDemo.sourceInformation);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, property = "_type")
public class AuthenticationDemo extends PackageableElement
{
public SourceInformation sourceInformation;

public AuthenticationSpecification authenticationSpecification;

public <T> T accept(PackageableElementVisitor<T> visitor)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ private ExecutionEnvironmentInstance visitExecutionEnvironment(HostedServicePars
ExecutionEnvironmentInstance execEnv = new ExecutionEnvironmentInstance();
execEnv.name = PureGrammarParserUtility.fromIdentifier(ctx.qualifiedName().identifier());
execEnv._package = ctx.qualifiedName().packagePath() == null ? "" : PureGrammarParserUtility.fromPath(ctx.qualifiedName().packagePath().identifier());
execEnv.sourceInformation = walkerSourceInformation.getSourceInformation(ctx);
List<HostedServiceParserGrammar.ExecParamsContext> execEnvCtxList = PureGrammarParserUtility.validateRequiredListField(ctx.executions().execParams(), "executions", walkerSourceInformation.getSourceInformation(ctx.executions()));
if (execEnvCtxList.stream().anyMatch(x -> x.singleExecEnv() != null))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -554,6 +554,7 @@ private ExecutionEnvironmentInstance visitExecutionEnvironment(ServiceParserGram
ExecutionEnvironmentInstance execEnv = new ExecutionEnvironmentInstance();
execEnv.name = PureGrammarParserUtility.fromIdentifier(ctx.qualifiedName().identifier());
execEnv._package = ctx.qualifiedName().packagePath() == null ? "" : PureGrammarParserUtility.fromPath(ctx.qualifiedName().packagePath().identifier());
execEnv.sourceInformation = walkerSourceInformation.getSourceInformation(ctx);
List<ServiceParserGrammar.ExecParamsContext> execEnvCtxList = PureGrammarParserUtility.validateRequiredListField(ctx.executions().execParams(), "executions", walkerSourceInformation.getSourceInformation(ctx.executions()));
if (execEnvCtxList.stream().anyMatch(x -> x.singleExecEnv() != null))
{
Expand Down

0 comments on commit 811ed0f

Please sign in to comment.