From 6a2d0bf9d60a369afa771bb2eb34574dc5bc579f Mon Sep 17 00:00:00 2001 From: ilya Date: Tue, 15 Feb 2022 15:03:19 +0300 Subject: [PATCH 1/2] isBlank method fixed --- .../parse/antlr/java/AntlrJavaFunctionInfo.kt | 7 ++++++- .../antlr/java/JavaFunctionSplitterTest.kt | 20 +++++++++++++++---- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/src/main/kotlin/astminer/parse/antlr/java/AntlrJavaFunctionInfo.kt b/src/main/kotlin/astminer/parse/antlr/java/AntlrJavaFunctionInfo.kt index 82149e03..169da590 100644 --- a/src/main/kotlin/astminer/parse/antlr/java/AntlrJavaFunctionInfo.kt +++ b/src/main/kotlin/astminer/parse/antlr/java/AntlrJavaFunctionInfo.kt @@ -37,7 +37,11 @@ class AntlrJavaFunctionInfo(override val root: AntlrNode, override val filePath: override val body: AntlrNode? = root.children.find { it.typeLabel == METHOD_BODY_NODE } - override fun isBlank() = body == null || body.children.size <= 2 + override fun isBlank(): Boolean { + if (body == null) return true + val block = body.getChildOfType(METHOD_BLOCK_NODE) ?: return true + return block.children.size <= 2 + } private fun collectNameNode(): AntlrNode? = root.getChildOfType(IDENTIFIER_NODE) @@ -87,6 +91,7 @@ class AntlrJavaFunctionInfo(override val root: AntlrNode, override val filePath: private const val ANNOTATION_NAME = "qualifiedName" private const val IDENTIFIER_NODE = "IDENTIFIER" private const val METHOD_BODY_NODE = "methodBody" + private const val METHOD_BLOCK_NODE = "block" private const val CLASS_DECLARATION_NODE = "classDeclaration" private const val ENUM_DECLARATION_NODE = "enumDeclaration" diff --git a/src/test/kotlin/astminer/parse/antlr/java/JavaFunctionSplitterTest.kt b/src/test/kotlin/astminer/parse/antlr/java/JavaFunctionSplitterTest.kt index ef060293..1c2ecc3d 100644 --- a/src/test/kotlin/astminer/parse/antlr/java/JavaFunctionSplitterTest.kt +++ b/src/test/kotlin/astminer/parse/antlr/java/JavaFunctionSplitterTest.kt @@ -4,10 +4,7 @@ import astminer.common.model.FunctionInfo import astminer.parse.antlr.AntlrNode import org.junit.Test import java.io.File -import kotlin.test.BeforeTest -import kotlin.test.assertEquals -import kotlin.test.assertNotNull -import kotlin.test.assertTrue +import kotlin.test.* class JavaFunctionSplitterTest { @@ -30,6 +27,7 @@ class JavaFunctionSplitterTest { val methodVoid = functionInfos.find { it.name == "functionReturningVoid" } assertNotNull(methodVoid) assertEquals("void", methodVoid.returnType) + assertTrue(methodVoid.isBlank()) } @Test @@ -37,6 +35,7 @@ class JavaFunctionSplitterTest { val methodInt = functionInfos.find { it.name == "functionReturningInt" } assertNotNull(methodInt) assertEquals("int", methodInt.returnType) + assertFalse(methodInt.isBlank()) } @Test @@ -44,6 +43,7 @@ class JavaFunctionSplitterTest { val methodStrings = functionInfos.find { it.name == "functionReturningStrings" } assertNotNull(methodStrings) assertEquals("String[]", methodStrings.returnType) + assertFalse(methodStrings.isBlank()) } @Test @@ -51,6 +51,7 @@ class JavaFunctionSplitterTest { val methodClass = functionInfos.find { it.name == "functionReturningClass" } assertNotNull(methodClass) assertEquals("Class1", methodClass.returnType) + assertFalse(methodClass.isBlank()) } @Test @@ -58,6 +59,7 @@ class JavaFunctionSplitterTest { val methodClass = functionInfos.find { it.name == "functionInClass1" } assertNotNull(methodClass) assertEquals("Class1", methodClass.enclosingElement?.name) + assertTrue(methodClass.isBlank()) } @Test @@ -65,6 +67,7 @@ class JavaFunctionSplitterTest { val methodClass = functionInfos.find { it.name == "functionInClass2" } assertNotNull(methodClass) assertEquals("Class2", methodClass.enclosingElement?.name) + assertTrue(methodClass.isBlank()) } @Test @@ -72,6 +75,7 @@ class JavaFunctionSplitterTest { val methodNoParameters = functionInfos.find { it.name == "functionWithNoParameters" } assertNotNull(methodNoParameters) assertEquals(0, methodNoParameters.parameters?.size) + assertTrue(methodNoParameters.isBlank()) } @Test @@ -82,6 +86,7 @@ class JavaFunctionSplitterTest { val parameter = methodOneParameter.parameters?.get(0) assertEquals("p1", parameter?.name) assertEquals("int", parameter?.type) + assertTrue(methodOneParameter.isBlank()) } @Test @@ -95,6 +100,7 @@ class JavaFunctionSplitterTest { assertEquals("p${i + 1}", parameter?.name) assertEquals(methodTypes[i], parameter?.type) } + assertTrue(methodThreeParameters.isBlank()) } @Test @@ -105,6 +111,7 @@ class JavaFunctionSplitterTest { val weirdParameter = methodWeirdArrayParameter.parameters?.get(0) assertEquals(weirdParameter?.name, "arr[]") assertEquals(weirdParameter?.type, "int") + assertTrue(methodWeirdArrayParameter.isBlank()) } @Test @@ -114,6 +121,7 @@ class JavaFunctionSplitterTest { val modifiers = methodWithOneModifier.modifiers assertNotNull(modifiers) assertEquals("abstract", modifiers.first()) + assertTrue(methodWithOneModifier.isBlank()) } @Test @@ -123,6 +131,7 @@ class JavaFunctionSplitterTest { val modifiers = methodWithMultipleModifiers.modifiers assertNotNull(modifiers) assertEquals(setOf("static", "public", "final"), modifiers.toSet()) + assertFalse(methodWithMultipleModifiers.isBlank()) } @Test @@ -132,6 +141,7 @@ class JavaFunctionSplitterTest { val annotations = methodWithOneAnnotation.annotations assertNotNull(annotations) assertEquals(setOf("Deprecated"), annotations.toSet()) + assertTrue(methodWithOneAnnotation.isBlank()) } @Test @@ -141,6 +151,7 @@ class JavaFunctionSplitterTest { val annotations = methodWithOneAnnotation.annotations assertNotNull(annotations) assertEquals(setOf("Deprecated", "SuppressWarnings"), annotations.toSet()) + assertTrue(methodWithOneAnnotation.isBlank()) } @Test @@ -153,6 +164,7 @@ class JavaFunctionSplitterTest { assertNotNull(annotations) assertEquals(setOf("public", "static"), modifiers.toSet()) assertEquals(setOf("Deprecated"), annotations.toSet()) + assertTrue(methodWithModifierAndAnnotation.isBlank()) } @Test From 2c849f59bb9f9ada2b329ad0340f74e6c153d3aa Mon Sep 17 00:00:00 2001 From: ilya Date: Tue, 15 Feb 2022 15:03:29 +0300 Subject: [PATCH 2/2] pipeline holdout fix --- src/main/kotlin/astminer/pipeline/Pipeline.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/kotlin/astminer/pipeline/Pipeline.kt b/src/main/kotlin/astminer/pipeline/Pipeline.kt index 3206df15..a5333cd4 100644 --- a/src/main/kotlin/astminer/pipeline/Pipeline.kt +++ b/src/main/kotlin/astminer/pipeline/Pipeline.kt @@ -64,8 +64,8 @@ class Pipeline(private val config: PipelineConfig) { if (config.compressBeforeSaving) { results.toStructurallyNormalized() } else { results } } synchronized(this) { - storage.store(labeledResults) - metaStorage?.store(labeledResults) + storage.store(labeledResults, holdoutType) + metaStorage?.store(labeledResults, holdoutType) } progressBar.step() }