diff --git a/Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/LibraryBuilder.java b/Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/LibraryBuilder.java index e94e937fa..276f0d414 100644 --- a/Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/LibraryBuilder.java +++ b/Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/LibraryBuilder.java @@ -2531,14 +2531,9 @@ private static String lookupElementWarning(Object element) { public ParameterRef resolveImplicitContext() { if (!inLiteralContext() && inSpecificContext()) { ResolvedIdentifierContext resolvedIdentifierContext = resolve(currentExpressionContext()); - // LUKETODO: better pattern? - final Element contextElement = - resolvedIdentifierContext.getExactMatchElement().orElse(null); final Optional optParameterDef = resolvedIdentifierContext.getElementOfType(ParameterDef.class); - // if (contextElement instanceof ParameterDef) { if (optParameterDef.isPresent()) { - // ParameterDef contextParameter = (ParameterDef) contextElement; final ParameterDef contextParameter = optParameterDef.get(); checkLiteralContext(); @@ -2918,55 +2913,60 @@ public Expression resolveAccessor(Expression left, String memberIdentifier) { ResolvedIdentifierContext resolvedIdentifierContext = referencedLibrary.resolve(memberIdentifier); - // LUKETODO: better pattern? - final Element element = - resolvedIdentifierContext.getExactMatchElement().orElse(null); + final Optional optElement = resolvedIdentifierContext.getExactMatchElement(); - if (element instanceof ExpressionDef) { - checkAccessLevel(libraryName, memberIdentifier, ((ExpressionDef) element).getAccessLevel()); - Expression result = - of.createExpressionRef().withLibraryName(libraryName).withName(memberIdentifier); - result.setResultType(getExpressionDefResultType((ExpressionDef) element)); - return result; - } + if (optElement.isPresent()) { + final Element element = optElement.get(); - if (element instanceof ParameterDef) { - checkAccessLevel(libraryName, memberIdentifier, ((ParameterDef) element).getAccessLevel()); - Expression result = - of.createParameterRef().withLibraryName(libraryName).withName(memberIdentifier); - result.setResultType(element.getResultType()); - return result; - } + if (element instanceof ExpressionDef) { + checkAccessLevel(libraryName, memberIdentifier, ((ExpressionDef) element).getAccessLevel()); + Expression result = of.createExpressionRef() + .withLibraryName(libraryName) + .withName(memberIdentifier); + result.setResultType(getExpressionDefResultType((ExpressionDef) element)); + return result; + } - if (element instanceof ValueSetDef) { - checkAccessLevel(libraryName, memberIdentifier, ((ValueSetDef) element).getAccessLevel()); - ValueSetRef result = - of.createValueSetRef().withLibraryName(libraryName).withName(memberIdentifier); - result.setResultType(element.getResultType()); - return result; - } + if (element instanceof ParameterDef) { + checkAccessLevel(libraryName, memberIdentifier, ((ParameterDef) element).getAccessLevel()); + Expression result = + of.createParameterRef().withLibraryName(libraryName).withName(memberIdentifier); + result.setResultType(element.getResultType()); + return result; + } - if (element instanceof CodeSystemDef) { - checkAccessLevel(libraryName, memberIdentifier, ((CodeSystemDef) element).getAccessLevel()); - CodeSystemRef result = - of.createCodeSystemRef().withLibraryName(libraryName).withName(memberIdentifier); - result.setResultType(element.getResultType()); - return result; - } + if (element instanceof ValueSetDef) { + checkAccessLevel(libraryName, memberIdentifier, ((ValueSetDef) element).getAccessLevel()); + ValueSetRef result = + of.createValueSetRef().withLibraryName(libraryName).withName(memberIdentifier); + result.setResultType(element.getResultType()); + return result; + } - if (element instanceof CodeDef) { - checkAccessLevel(libraryName, memberIdentifier, ((CodeDef) element).getAccessLevel()); - CodeRef result = of.createCodeRef().withLibraryName(libraryName).withName(memberIdentifier); - result.setResultType(element.getResultType()); - return result; - } + if (element instanceof CodeSystemDef) { + checkAccessLevel(libraryName, memberIdentifier, ((CodeSystemDef) element).getAccessLevel()); + CodeSystemRef result = of.createCodeSystemRef() + .withLibraryName(libraryName) + .withName(memberIdentifier); + result.setResultType(element.getResultType()); + return result; + } - if (element instanceof ConceptDef) { - checkAccessLevel(libraryName, memberIdentifier, ((ConceptDef) element).getAccessLevel()); - ConceptRef result = - of.createConceptRef().withLibraryName(libraryName).withName(memberIdentifier); - result.setResultType(element.getResultType()); - return result; + if (element instanceof CodeDef) { + checkAccessLevel(libraryName, memberIdentifier, ((CodeDef) element).getAccessLevel()); + CodeRef result = + of.createCodeRef().withLibraryName(libraryName).withName(memberIdentifier); + result.setResultType(element.getResultType()); + return result; + } + + if (element instanceof ConceptDef) { + checkAccessLevel(libraryName, memberIdentifier, ((ConceptDef) element).getAccessLevel()); + ConceptRef result = + of.createConceptRef().withLibraryName(libraryName).withName(memberIdentifier); + result.setResultType(element.getResultType()); + return result; + } } // ERROR: diff --git a/Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/model/ResolvedIdentifierContext.java b/Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/model/ResolvedIdentifierContext.java index c1bfd3823..e52878447 100644 --- a/Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/model/ResolvedIdentifierContext.java +++ b/Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/model/ResolvedIdentifierContext.java @@ -79,14 +79,14 @@ public Optional getElementOfType(Class clazz) { } @Override - public boolean equals(Object theO) { - if (this == theO) { + public boolean equals(Object other) { + if (this == other) { return true; } - if (theO == null || getClass() != theO.getClass()) { + if (other == null || getClass() != other.getClass()) { return false; } - ResolvedIdentifierContext that = (ResolvedIdentifierContext) theO; + ResolvedIdentifierContext that = (ResolvedIdentifierContext) other; return Objects.equals(identifier, that.identifier) && Objects.equals(nullableElement, that.nullableElement) && matchType == that.matchType;