Skip to content

Commit

Permalink
Fix complexity for empty constructors.
Browse files Browse the repository at this point in the history
  • Loading branch information
gchallen committed Jun 17, 2021
1 parent bb4b00a commit 2645695
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 6 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ allprojects {
}
subprojects {
group = "com.github.cs125-illinois.jeed"
version = "2021.6.1"
version = "2021.6.2"
tasks.withType<Test> {
useJUnitPlatform()
enableAssertions = true
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
version=2021.6.1
version=2021.6.2
4 changes: 2 additions & 2 deletions core/src/main/kotlin/JavaComplexity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,9 @@ class JavaComplexityListener(val source: Source, entry: Map.Entry<String, String
override fun enterConstructorDeclaration(ctx: JavaParser.ConstructorDeclarationContext) {
assert(complexityStack.isNotEmpty())
val currentClass = currentComplexity as ClassComplexity
val parameters = ctx.formalParameters().formalParameterList().formalParameter().joinToString(",") {
val parameters = ctx.formalParameters().formalParameterList()?.formalParameter()?.joinToString(",") {
it.typeType().text
}
} ?: ""
enterMethodOrConstructor(
"${currentClass.name}($parameters)",
Location(ctx.start.line, ctx.start.charPositionInLine),
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
version=2021.6.1
version=2021.6.2
10 changes: 10 additions & 0 deletions core/src/test/kotlin/TestJavaComplexity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,16 @@ public class Example {
int[] array = new int[] {1, 2, 4};
System.out.println("ran");
}
}""".trim()
).complexity().also {
it.lookup("Example", "").complexity shouldBe 1
}
}
"should parse empty constructors properly" {
Source.fromSnippet(
"""
public class Example {
public Example() { }
}""".trim()
).complexity().also {
it.lookup("Example", "").complexity shouldBe 1
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
version=2021.6.1
version=2021.6.2

0 comments on commit 2645695

Please sign in to comment.