Skip to content

Commit

Permalink
Fix lambda bug.
Browse files Browse the repository at this point in the history
  • Loading branch information
gchallen committed Oct 22, 2022
1 parent fe36121 commit ed98133
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 5 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ allprojects {
}
subprojects {
group = "com.github.cs125-illinois.jeed"
version = "2022.10.4"
version = "2022.10.5"
tasks.withType<Test> {
useJUnitPlatform()
enableAssertions = true
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
version=2022.10.4
version=2022.10.5
2 changes: 1 addition & 1 deletion core/src/main/kotlin/JavaComplexity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ class JavaComplexityListener(val source: Source, entry: Map.Entry<String, String

override fun enterLambdaExpression(ctx: JavaParser.LambdaExpressionContext) {
assert(complexityStack.isNotEmpty())
(currentComplexity as MethodComplexity).complexity++
currentComplexity.complexity++
}

override fun enterStatement(ctx: JavaParser.StatementContext) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
version=2022.10.4
version=2022.10.5
12 changes: 12 additions & 0 deletions core/src/test/kotlin/TestJavaComplexity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -683,4 +683,16 @@ public static IWhichHemisphere create(Position p) {
}""".trim()
).complexity()
}
"should allow top-level lambda methods" {
Source.fromJavaSnippet(
"""
public interface Modify {
int modify(int value);
}
public class Modifier {
Modify modify = value -> value + 1;
}
""".trim()
).complexity()
}
})
14 changes: 14 additions & 0 deletions core/src/test/kotlin/TestJavaFeatures.kt
Original file line number Diff line number Diff line change
Expand Up @@ -985,4 +985,18 @@ public static IWhichHemisphere create(Position p) {
featureMap[FeatureName.ANONYMOUS_CLASSES] shouldBe 3
}
}
"should allow top-level lambda methods" {
Source.fromJavaSnippet(
"""
public interface Modify {
int modify(int value);
}
public class Modifier {
Modify modify = value -> value + 1;
}
""".trim()
).features().check("") {
featureMap[FeatureName.LAMBDA_EXPRESSIONS] shouldBe 1
}
}
})
12 changes: 12 additions & 0 deletions core/src/test/kotlin/TestKotlinComplexity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -759,4 +759,16 @@ class Main {
it.lookupFile("Main.kt") shouldBe 3
}
}
"should allow top-level lambda methods" {
Source.fromKotlinSnippet(
"""
fun interface Modify {
fun modify(value: Int): Int
}
class Modifier {
val modify = Modify { value -> value + 1 }
}
""".trim()
).complexity()
}
})
Original file line number Diff line number Diff line change
@@ -1 +1 @@
version=2022.10.4
version=2022.10.5

0 comments on commit ed98133

Please sign in to comment.