Skip to content

Commit

Permalink
More optimization. Spotless.
Browse files Browse the repository at this point in the history
  • Loading branch information
lukedegruchy committed Aug 27, 2024
1 parent 94c82c7 commit 0b99e23
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 52 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<ParameterDef> optParameterDef =
resolvedIdentifierContext.getElementOfType(ParameterDef.class);
// if (contextElement instanceof ParameterDef) {
if (optParameterDef.isPresent()) {
// ParameterDef contextParameter = (ParameterDef) contextElement;
final ParameterDef contextParameter = optParameterDef.get();

checkLiteralContext();
Expand Down Expand Up @@ -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<Element> 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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,14 +79,14 @@ public <T extends Element> Optional<T> getElementOfType(Class<T> 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;
Expand Down

0 comments on commit 0b99e23

Please sign in to comment.