Skip to content

Commit

Permalink
ModelAwareGradleLintRule: handle receiver exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
rpalcolea committed Jan 7, 2025
1 parent bd25f24 commit 5b03c88
Showing 1 changed file with 21 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,25 +36,29 @@ abstract class ModelAwareGradleLintRule extends GradleLintRule {
Map<String, List<String>> projectDefaultImports = null

TypeInformation receiver(MethodCallExpression call) {
List<Expression> fullCallStack = typedDslStack(callStack + call)
List<TypeInformation> typedStack = []
for (Expression currentMethod in fullCallStack) {
if (typedStack.empty) {
typedStack.add(new TypeInformation(project))
}
while (!typedStack.empty) {
def current = typedStack.last()
def candidate = findDirectCandidate(current, currentMethod)
if (candidate != null) {
typedStack.add(candidate)
break
try {
List<Expression> fullCallStack = typedDslStack(callStack + call)
List<TypeInformation> typedStack = []
for (Expression currentMethod in fullCallStack) {
if (typedStack.empty) {
typedStack.add(new TypeInformation(project))
}
while (!typedStack.empty) {
def current = typedStack.last()
def candidate = findDirectCandidate(current, currentMethod)
if (candidate != null) {
typedStack.add(candidate)
break
}
typedStack.removeLast()
}
typedStack.removeLast()
}
}
if (typedStack.size() >= 2) { //there should be the method return type and the receiver at least
return typedStack[-2]
} else {
if (typedStack.size() >= 2) { //there should be the method return type and the receiver at least
return typedStack[-2]
} else {
return null
}
} catch (Exception e) {
return null
}
}
Expand Down

0 comments on commit 5b03c88

Please sign in to comment.