Skip to content

Commit

Permalink
Merge branch 'master' into ja_20230610_servlet_migration
Browse files Browse the repository at this point in the history
  • Loading branch information
JPercival authored Nov 1, 2023
2 parents 4fb9b32 + 28538e0 commit 9948449
Show file tree
Hide file tree
Showing 49 changed files with 5,045 additions and 492 deletions.
14 changes: 13 additions & 1 deletion Src/java/.vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"java.configuration.updateBuildConfiguration": "automatic",
"java.debug.settings.onBuildFailureProceed": true,
"java.compile.nullAnalysis.mode": "automatic",
"java.jdt.ls.vmargs": "-noverify -Xmx8G -XX:+UseG1GC -XX:+UseStringDeduplication",
"cSpell.words": [
Expand All @@ -12,5 +13,16 @@
"testng",
"trackback"
],
"java.debug.settings.onBuildFailureProceed": true
"cSpell.enabledLanguageIds": [
"java",
"json",
"xml",
"markdown",
"cql"
],
"cSpell.ignorePaths": [
".git",
"**/*.gradle",
"**/test/resources/**"
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,6 @@

public class Cql2ElmVisitor extends CqlPreprocessorElmCommonVisitor {
static final Logger logger = LoggerFactory.getLogger(Cql2ElmVisitor.class);
private boolean locate = false;
private boolean resultTypes = false;
private boolean dateRangeOptimization = false;
private boolean detailedErrors = false;
private boolean methodInvocation = true;
private boolean includeDeprecatedElements = false;
private boolean fromKeywordRequired = false;

private final SystemMethodResolver systemMethodResolver;

public void setLibraryInfo(LibraryInfo libraryInfo) {
Expand Down Expand Up @@ -65,91 +57,6 @@ public Cql2ElmVisitor(LibraryBuilder libraryBuilder) {
this.systemMethodResolver = new SystemMethodResolver(this, libraryBuilder);
}

public void enableLocators() {
locate = true;
}

public void disableLocators() {
locate = false;
}

public void enableResultTypes() {
resultTypes = true;
}

public void disableResultTypes() {
resultTypes = false;
}

public void enableDateRangeOptimization() {
dateRangeOptimization = true;
}

public void disableDateRangeOptimization() {
dateRangeOptimization = false;
}

public boolean getDateRangeOptimization() {
return dateRangeOptimization;
}

public void enableDetailedErrors() {
detailedErrors = true;
}

public void disableDetailedErrors() {
detailedErrors = false;
}

public boolean isDetailedErrorsEnabled() {
return detailedErrors;
}

public void enableMethodInvocation() {
methodInvocation = true;
}

public void disableMethodInvocation() {
methodInvocation = false;
}

public boolean isFromKeywordRequired() {
return fromKeywordRequired;
}

public void enableFromKeywordRequired() {
fromKeywordRequired = true;
}

public void disableFromKeywordRequired() {
fromKeywordRequired = false;
}

public void setTranslatorOptions(CqlCompilerOptions options) {
if (options.getOptions().contains(CqlCompilerOptions.Options.EnableDateRangeOptimization)) {
this.enableDateRangeOptimization();
}
if (options.getOptions().contains(CqlCompilerOptions.Options.EnableAnnotations)) {
this.enableAnnotations();
}
if (options.getOptions().contains(CqlCompilerOptions.Options.EnableLocators)) {
this.enableLocators();
}
if (options.getOptions().contains(CqlCompilerOptions.Options.EnableResultTypes)) {
this.enableResultTypes();
}
if (options.getOptions().contains(CqlCompilerOptions.Options.EnableDetailedErrors)) {
this.enableDetailedErrors();
}
if (options.getOptions().contains(CqlCompilerOptions.Options.DisableMethodInvocation)) {
this.disableMethodInvocation();
}
if (options.getOptions().contains(CqlCompilerOptions.Options.RequireFromKeyword)) {
this.enableFromKeywordRequired();
}
libraryBuilder.setCompatibilityLevel(options.getCompatibilityLevel());
}

public List<Retrieve> getRetrieves() {
return retrieves;
}
Expand Down Expand Up @@ -335,7 +242,7 @@ public TupleElementDefinition visitTupleElementDefinition(cqlParser.TupleElement
.withName(parseString(ctx.referentialIdentifier()))
.withElementType(parseTypeSpecifier(ctx.typeSpecifier()));

if (includeDeprecatedElements) {
if (getIncludeDeprecatedElements()) {
result.setType(result.getElementType());
}

Expand Down Expand Up @@ -3123,7 +3030,7 @@ else if (libraryBuilder.isCompatibleWith("1.5")) {
@Override
public Object visitSourceClause(cqlParser.SourceClauseContext ctx) {
boolean hasFrom = "from".equals(ctx.getChild(0).getText());
if (!hasFrom && fromKeywordRequired) {
if (!hasFrom && isFromKeywordRequired()) {
throw new IllegalArgumentException("The from keyword is required for queries.");
}

Expand Down Expand Up @@ -3177,7 +3084,7 @@ public Object visitQuery(cqlParser.QueryContext ctx) {
}

Expression where = ctx.whereClause() != null ? (Expression) visit(ctx.whereClause()) : null;
if (dateRangeOptimization && where != null) {
if (getDateRangeOptimization() && where != null) {
for (AliasedQuerySource aqs : sources) {
where = optimizeDateRangeInQuery(where, aqs);
}
Expand Down Expand Up @@ -3960,10 +3867,13 @@ public Expression resolveFunctionOrQualifiedFunction(String identifier, cqlParse

// NOTE: FHIRPath method invocation
// If the target is an expression, resolve as a method invocation
if (target instanceof Expression && methodInvocation) {
if (target instanceof Expression && isMethodInvocationEnabled()) {
return systemMethodResolver.resolveMethod((Expression)target, identifier, paramListCtx, true);
}

if (!isMethodInvocationEnabled()) {
throw new CqlCompilerException(String.format("The identifier %s could not be resolved as an invocation because method-style invocation is disabled.", identifier), CqlCompilerException.ErrorSeverity.Error);
}
throw new IllegalArgumentException(String.format("Invalid invocation target: %s", target.getClass().getName()));
}
finally {
Expand Down Expand Up @@ -4219,11 +4129,11 @@ private TrackBack getTrackBack(ParserRuleContext ctx) {
}

private void decorate(Element element, TrackBack tb) {
if (locate && tb != null) {
if (locatorsEnabled() && tb != null) {
element.setLocator(tb.toLocator());
}

if (resultTypes && element.getResultType() != null) {
if (resultTypesEnabled() && element.getResultType() != null) {
if (element.getResultType() instanceof NamedType) {
element.setResultTypeName(libraryBuilder.dataTypeToQName(element.getResultType()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ public class CqlPreprocessorElmCommonVisitor extends cqlBaseVisitor {
private int nextLocalId = 1;
private boolean locate = false;
private boolean resultTypes = false;
private boolean dateRangeOptimization = false;
private boolean methodInvocation = true;
private boolean fromKeywordRequired = false;

private final List<Expression> expressions = new ArrayList<>();
private boolean includeDeprecatedElements = false;

Expand Down Expand Up @@ -782,4 +786,110 @@ public static String normalizeWhitespace(String input) {
public static boolean isStartingWithDigit(String header, int index) {
return (index < header.length()) && Character.isDigit(header.charAt(index));
}


public void enableLocators() {
locate = true;
}

public boolean locatorsEnabled() {
return locate;
}

public void disableLocators() {
locate = false;
}

public void enableResultTypes() {
resultTypes = true;
}

public void disableResultTypes() {
resultTypes = false;
}

public boolean resultTypesEnabled() {
return resultTypes;
}

public void enableDateRangeOptimization() {
dateRangeOptimization = true;
}

public void disableDateRangeOptimization() {
dateRangeOptimization = false;
}

public boolean getDateRangeOptimization() {
return dateRangeOptimization;
}

public void enableDetailedErrors() {
detailedErrors = true;
}

public void disableDetailedErrors() {
detailedErrors = false;
}

public boolean isDetailedErrorsEnabled() {
return detailedErrors;
}

public void enableMethodInvocation() {
methodInvocation = true;
}

public void disableMethodInvocation() {
methodInvocation = false;
}

public boolean isMethodInvocationEnabled() {
return methodInvocation;
}

public boolean isFromKeywordRequired() {
return fromKeywordRequired;
}

public void enableFromKeywordRequired() {
fromKeywordRequired = true;
}

public void disableFromKeywordRequired() {
fromKeywordRequired = false;
}

public boolean getIncludeDeprecatedElements() {
return includeDeprecatedElements;
}

public void setIncludeDeprecatedElements(boolean includeDeprecatedElements) {
this.includeDeprecatedElements = includeDeprecatedElements;
}

public void setTranslatorOptions(CqlCompilerOptions options) {
if (options.getOptions().contains(CqlCompilerOptions.Options.EnableDateRangeOptimization)) {
this.enableDateRangeOptimization();
}
if (options.getOptions().contains(CqlCompilerOptions.Options.EnableAnnotations)) {
this.enableAnnotations();
}
if (options.getOptions().contains(CqlCompilerOptions.Options.EnableLocators)) {
this.enableLocators();
}
if (options.getOptions().contains(CqlCompilerOptions.Options.EnableResultTypes)) {
this.enableResultTypes();
}
if (options.getOptions().contains(CqlCompilerOptions.Options.EnableDetailedErrors)) {
this.enableDetailedErrors();
}
if (options.getOptions().contains(CqlCompilerOptions.Options.DisableMethodInvocation)) {
this.disableMethodInvocation();
}
if (options.getOptions().contains(CqlCompilerOptions.Options.RequireFromKeyword)) {
this.enableFromKeywordRequired();
}
libraryBuilder.setCompatibilityLevel(options.getCompatibilityLevel());
}
}
Loading

0 comments on commit 9948449

Please sign in to comment.