Skip to content

Commit

Permalink
Minor cleanups/modernizations (#1354)
Browse files Browse the repository at this point in the history
* WIP cleanup

* More cleanup
  • Loading branch information
JPercival committed Apr 19, 2024
1 parent fe5c101 commit 67bb03a
Show file tree
Hide file tree
Showing 10 changed files with 83 additions and 108 deletions.
2 changes: 1 addition & 1 deletion Src/java/cql-to-elm-cli/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ dependencies {
implementation project(':elm-jaxb')
implementation 'net.sf.jopt-simple:jopt-simple:4.7'
implementation 'org.slf4j:slf4j-simple:1.7.36'
implementation 'org.glassfish.jaxb:jaxb-runtime:4.0.3'
implementation 'org.glassfish.jaxb:jaxb-runtime:4.0.5'
implementation 'org.eclipse.persistence:org.eclipse.persistence.moxy:4.0.2'
testImplementation project(':model-jaxb')
testImplementation project(':model-jackson')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,8 @@ public NamedTypeSpecifier visitNamedTypeSpecifier(cqlParser.NamedTypeSpecifierCo
DataType resultType = libraryBuilder.resolveTypeName(modelIdentifier, identifier);
if (null == resultType) {
throw new CqlCompilerException(
String.format("Could not find type for model: %s and name: %s", modelIdentifier, identifier));
String.format("Could not find type for model: %s and name: %s", modelIdentifier, identifier),
getTrackBack(ctx));
}
NamedTypeSpecifier result = of.createNamedTypeSpecifier().withName(libraryBuilder.dataTypeToQName(resultType));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,41 +21,31 @@ public static boolean hasErrors(List<CqlCompilerException> exceptions) {
}

public CqlCompilerException(String message) {
super(message);
this.severity = ErrorSeverity.Error;
this(message, ErrorSeverity.Error, null, null);
}

public CqlCompilerException(String message, ErrorSeverity severity) {
super(message);
this.severity = severity;
this(message, severity, null, null);
}

public CqlCompilerException(String message, Throwable cause) {
super(message, cause);
this.severity = ErrorSeverity.Error;
this(message, ErrorSeverity.Error, null, cause);
}

public CqlCompilerException(String message, ErrorSeverity severity, Throwable cause) {
super(message, cause);
this.severity = severity;
this(message, severity, null, cause);
}

public CqlCompilerException(String message, TrackBack locator) {
super(message);
this.severity = ErrorSeverity.Error;
this.locator = locator;
this(message, ErrorSeverity.Error, locator, null);
}

public CqlCompilerException(String message, ErrorSeverity severity, TrackBack locator) {
super(message);
this.severity = severity;
this.locator = locator;
this(message, severity, locator, null);
}

public CqlCompilerException(String message, TrackBack locator, Throwable cause) {
super(message, cause);
this.severity = ErrorSeverity.Error;
this.locator = locator;
this(message, ErrorSeverity.Error, locator, cause);
}

public CqlCompilerException(String message, ErrorSeverity severity, TrackBack locator, Throwable cause) {
Expand All @@ -70,13 +60,9 @@ public ErrorSeverity getSeverity() {
return severity;
}

private TrackBack locator;
private final transient TrackBack locator;

public TrackBack getLocator() {
return locator;
}

public void setLocator(TrackBack locator) {
this.locator = locator;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,6 @@ public void setPath(Path path) {
this.path = path;
}

private void checkPath() {
if (path == null || path.equals("")) {
throw new IllegalArgumentException("Path is required for DefaultLibrarySourceProvider implementation");
}
}

@Override
public InputStream getLibrarySource(VersionedIdentifier libraryIdentifier) {
if (path != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -705,7 +705,7 @@ public void addInclude(IncludeDef includeDef) {
.withId(NamespaceManager.getNamePart(includeDef.getPath()))
.withVersion(includeDef.getVersion());

ArrayList<CqlCompilerException> errors = new ArrayList<CqlCompilerException>();
var errors = new ArrayList<CqlCompilerException>();
CompiledLibrary referencedLibrary = libraryManager.resolveLibrary(libraryIdentifier, errors);
for (CqlCompilerException error : errors) {
this.recordParsingException(error);
Expand Down Expand Up @@ -1240,14 +1240,13 @@ public CallContext buildCallContext(
dataTypes.add(operand.getResultType());
}

CallContext callContext = new CallContext(
return new CallContext(
libraryName,
operatorName,
allowPromotionAndDemotion,
allowFluent,
mustResolve,
dataTypes.toArray(new DataType[dataTypes.size()]));
return callContext;
}

public Invocation resolveInvocation(
Expand Down Expand Up @@ -1344,7 +1343,7 @@ public Operator resolveFunctionDefinition(FunctionDef fd) {
compiledLibrary.getIdentifier().getId(),
fd.getName(),
false,
fd.isFluent() == null ? false : fd.isFluent(),
fd.isFluent() != null && fd.isFluent(),
false,
dataTypes.toArray(new DataType[dataTypes.size()]));
// Resolve exact, no conversion map
Expand All @@ -1364,9 +1363,9 @@ public OperatorResolution resolveCall(CallContext callContext) {
if (result == null && callContext.getAllowFluent()) {
// attempt to resolve in each non-system included library, in order of inclusion, first resolution
// wins
for (CompiledLibrary library : libraries.values()) {
if (!library.equals(getSystemLibrary())) {
result = library.resolveCall(callContext, conversionMap);
for (var lib : libraries.values()) {
if (!lib.equals(getSystemLibrary())) {
result = lib.resolveCall(callContext, conversionMap);
if (result != null) {
break;
}
Expand Down Expand Up @@ -1655,7 +1654,7 @@ public Expression resolveToInterval(Expression expression) {
private Expression convertIntervalExpression(Expression expression, Conversion conversion) {
IntervalType fromType = (IntervalType) conversion.getFromType();
IntervalType toType = (IntervalType) conversion.getToType();
Interval interval = (Interval) of.createInterval()
return (Interval) of.createInterval()
.withLow(convertExpression(
(Property) of.createProperty()
.withSource(expression)
Expand All @@ -1677,7 +1676,6 @@ private Expression convertIntervalExpression(Expression expression, Conversion c
.withPath("highClosed")
.withResultType(resolveTypeName("System", "Boolean")))
.withResultType(toType);
return interval;
}

public As buildAs(Expression expression, DataType asType) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public QName dataTypeToQName(DataType type) {
}

public Iterable<TypeSpecifier> dataTypesToTypeSpecifiers(Iterable<DataType> types) {
ArrayList<TypeSpecifier> result = new ArrayList<TypeSpecifier>();
var result = new ArrayList<TypeSpecifier>();
for (DataType type : types) {
result.add(dataTypeToTypeSpecifier(type));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,18 +86,18 @@ public ModelContext resolveContextName(String contextName, boolean mustResolve)

// Resolve to a "default" context definition if the context name matches a type name exactly
DataType contextType = resolveTypeName(contextName);
if (contextType != null && contextType instanceof ClassType) {
if (contextType instanceof ClassType) {
ClassType contextClassType = (ClassType) contextType;
String keyName = null;
for (ClassTypeElement cte : ((ClassType) contextType).getElements()) {
for (ClassTypeElement cte : contextClassType.getElements()) {
if (cte.getName().equals("id")) {
keyName = cte.getName();
break;
}
}
ModelContext modelContext = new ModelContext(

return new ModelContext(
contextName, (ClassType) contextType, keyName != null ? Arrays.asList(keyName) : null, null);
return modelContext;
}

if (mustResolve) {
Expand Down
Loading

0 comments on commit 67bb03a

Please sign in to comment.