Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 5a5c934

Browse files
authored
Intellij IDEA IU plugin size fix (#1422)
1 parent ac22acd commit 5a5c934

25 files changed

+435
-286
lines changed

‎utbot-intellij-js/src/main/kotlin/org/utbot/intellij/plugin/language/js/JsTestsModel.kt‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import com.intellij.lang.javascript.psi.JSFile
44
import com.intellij.lang.javascript.refactoring.util.JSMemberInfo
55
import com.intellij.openapi.module.Module
66
import com.intellij.openapi.project.Project
7-
import org.utbot.framework.codegen.TestFramework
7+
import org.utbot.framework.codegen.domain.TestFramework
88
import org.utbot.intellij.plugin.models.BaseTestsModel
99
import service.CoverageMode
1010
import settings.JsTestGenerationSettings.defaultTimeout

‎utbot-js/build.gradle.kts‎

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -30,17 +30,8 @@ dependencies {
3030
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:5.8.1")
3131
api(project(":utbot-framework"))
3232
implementation(project(":utbot-fuzzers"))
33-
// https://mvnrepository.com/artifact/org.graalvm.js/js
34-
implementation(group = "org.graalvm.js", name = "js", version = "22.1.0.1")
35-
36-
// https://mvnrepository.com/artifact/org.graalvm.js/js-scriptengine
37-
implementation(group = "org.graalvm.js", name = "js-scriptengine", version = "22.1.0.1")
38-
39-
// https://mvnrepository.com/artifact/org.graalvm.truffle/truffle-api
40-
implementation(group = "org.graalvm.truffle", name = "truffle-api", version = "22.1.0.1")
41-
42-
// https://mvnrepository.com/artifact/org.graalvm.sdk/graal-sdk
43-
implementation(group = "org.graalvm.sdk", name = "graal-sdk", version = "22.1.0.1")
33+
// https://mvnrepository.com/artifact/com.google.javascript/closure-compiler
34+
implementation("com.google.javascript:closure-compiler:v20221102")
4435

4536
// https://mvnrepository.com/artifact/org.json/json
4637
implementation(group = "org.json", name = "json", version = "20220320")
@@ -52,4 +43,4 @@ dependencies {
5243
implementation("org.functionaljava:functionaljava-quickcheck:5.0")
5344
implementation("org.functionaljava:functionaljava-java-core:5.0")
5445
implementation(group = "org.apache.commons", name = "commons-text", version = apacheCommonsTextVersion)
55-
}
46+
}

‎utbot-js/src/main/kotlin/api/JsTestGenerator.kt‎

Lines changed: 34 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,18 @@
11
package api
22

33
import codegen.JsCodeGenerator
4-
import com.oracle.js.parser.ErrorManager
5-
import com.oracle.js.parser.Parser
6-
import com.oracle.js.parser.ScriptEnvironment
7-
import com.oracle.js.parser.Source
8-
import com.oracle.js.parser.ir.ClassNode
9-
import com.oracle.js.parser.ir.FunctionNode
4+
import com.google.javascript.jscomp.Compiler
5+
import com.google.javascript.jscomp.SourceFile
6+
import com.google.javascript.rhino.Node
107
import framework.api.js.JsClassId
118
import framework.api.js.JsMethodId
129
import framework.api.js.JsMultipleClassId
1310
import framework.api.js.util.isJsBasic
1411
import framework.api.js.util.jsErrorClassId
1512
import fuzzer.JsFuzzer
1613
import fuzzer.providers.JsObjectModelProvider
17-
import org.graalvm.polyglot.Context
18-
import org.utbot.framework.codegen.model.constructor.CgMethodTestSet
14+
import java.io.File
15+
import org.utbot.framework.codegen.domain.models.CgMethodTestSet
1916
import org.utbot.framework.plugin.api.EnvironmentModels
2017
import org.utbot.framework.plugin.api.ExecutableId
2118
import org.utbot.framework.plugin.api.UtAssembleModel
@@ -25,10 +22,8 @@ import org.utbot.framework.plugin.api.UtExecutionResult
2522
import org.utbot.framework.plugin.api.UtExecutionSuccess
2623
import org.utbot.framework.plugin.api.UtExplicitlyThrownException
2724
import org.utbot.framework.plugin.api.UtModel
28-
import org.utbot.framework.plugin.api.util.UtContext
2925
import org.utbot.framework.plugin.api.util.isStatic
3026
import org.utbot.framework.plugin.api.util.voidClassId
31-
import org.utbot.framework.plugin.api.util.withUtContext
3227
import org.utbot.fuzzer.FuzzedConcreteValue
3328
import org.utbot.fuzzer.FuzzedMethodDescription
3429
import org.utbot.fuzzer.FuzzedValue
@@ -37,6 +32,11 @@ import parser.JsClassAstVisitor
3732
import parser.JsFunctionAstVisitor
3833
import parser.JsFuzzerAstVisitor
3934
import parser.JsParserUtils
35+
import parser.JsParserUtils.getAbstractFunctionName
36+
import parser.JsParserUtils.getAbstractFunctionParams
37+
import parser.JsParserUtils.getClassMethods
38+
import parser.JsParserUtils.getClassName
39+
import parser.JsParserUtils.getParamName
4040
import parser.JsToplevelFunctionAstVisitor
4141
import service.CoverageServiceProvider
4242
import service.ServiceContext
@@ -46,7 +46,6 @@ import settings.JsTestGenerationSettings.dummyClassName
4646
import utils.PathResolver
4747
import utils.constructClass
4848
import utils.toJsAny
49-
import java.io.File
5049

5150

5251
class JsTestGenerator(
@@ -62,7 +61,7 @@ class JsTestGenerator(
6261

6362
private val exports = mutableSetOf<String>()
6463

65-
private lateinit var parsedFile: FunctionNode
64+
private lateinit var parsedFile: Node
6665

6766
private val utbotDir = "utbotJs"
6867

@@ -97,7 +96,7 @@ class JsTestGenerator(
9796
parsedFile = parsedFile,
9897
strict = selectedMethods?.isNotEmpty() ?: false
9998
)
100-
parentClassName = classNode?.ident?.name?.toString()
99+
parentClassName = classNode?.getClassName()
101100
val classId = makeJsClassId(classNode, ternService)
102101
val methods = makeMethodsToTest()
103102
if (methods.isEmpty()) throw IllegalArgumentException("No methods to test were found!")
@@ -115,14 +114,14 @@ class JsTestGenerator(
115114

116115
private fun makeTestsForMethod(
117116
classId: JsClassId,
118-
funcNode: FunctionNode,
119-
classNode: ClassNode?,
117+
funcNode: Node,
118+
classNode: Node?,
120119
context: ServiceContext,
121120
testSets: MutableList<CgMethodTestSet>,
122121
paramNames: MutableMap<ExecutableId, List<String>>
123122
) {
124123
val execId = classId.allMethods.find {
125-
it.name == funcNode.name.toString()
124+
it.name == funcNode.getAbstractFunctionName()
126125
} ?: throw IllegalStateException()
127126
manageExports(classNode, funcNode, execId)
128127
val (concreteValues, fuzzedValues) = runFuzzer(funcNode, execId)
@@ -167,7 +166,7 @@ class JsTestGenerator(
167166
executions = testsForGenerator,
168167
)
169168
testSets += testSet
170-
paramNames[execId] = funcNode.parameters.map { it.name.toString() }
169+
paramNames[execId] = funcNode.getAbstractFunctionParams().map { it.getParamName() }
171170
}
172171

173172
private fun makeImportPrefix(): String {
@@ -231,15 +230,15 @@ class JsTestGenerator(
231230
}
232231

233232
private fun runFuzzer(
234-
funcNode: FunctionNode,
233+
funcNode: Node,
235234
execId: JsMethodId
236235
): Pair<Set<FuzzedConcreteValue>, List<List<FuzzedValue>>> {
237236
val fuzzerVisitor = JsFuzzerAstVisitor()
238-
funcNode.body.accept(fuzzerVisitor)
237+
fuzzerVisitor.accept(funcNode)
239238
val methodUnderTestDescription =
240239
FuzzedMethodDescription(execId, fuzzerVisitor.fuzzedConcreteValues).apply {
241-
compilableName = funcNode.name.toString()
242-
val names = funcNode.parameters.map { it.name.toString() }
240+
compilableName = funcNode.getAbstractFunctionName()
241+
val names = funcNode.getAbstractFunctionParams().map { it.getParamName() }
243242
parameterNameMap = { index -> names.getOrNull(index) }
244243
}
245244
val fuzzedValues =
@@ -248,28 +247,27 @@ class JsTestGenerator(
248247
}
249248

250249
private fun manageExports(
251-
classNode: ClassNode?,
252-
funcNode: FunctionNode,
250+
classNode: Node?,
251+
funcNode: Node,
253252
execId: JsMethodId
254253
) {
255-
val obligatoryExport = (classNode?.ident?.name ?: funcNode.ident.name).toString()
254+
val obligatoryExport = (classNode?.getClassName() ?: funcNode.getAbstractFunctionName()).toString()
256255
val collectedExports = collectExports(execId)
257256
exports += (collectedExports + obligatoryExport)
258257
exportsManager(exports.toList())
259258
}
260259

261-
private fun makeMethodsToTest(): List<FunctionNode> {
260+
private fun makeMethodsToTest(): List<Node> {
262261
return selectedMethods?.map {
263262
getFunctionNode(
264263
focusedMethodName = it,
265264
parentClassName = parentClassName,
266-
fileText = fileText
267265
)
268266
} ?: getMethodsToTest()
269267
}
270268

271269
private fun makeJsClassId(
272-
classNode: ClassNode?,
270+
classNode: Node?,
273271
ternService: TernService
274272
): JsClassId {
275273
return classNode?.let {
@@ -280,21 +278,12 @@ class JsTestGenerator(
280278
)
281279
}
282280

283-
private fun runParser(fileText: String): FunctionNode {
284-
// Fixes problem with Graal.polyglot missing from classpath, resulting in error.
285-
withUtContext(UtContext(Context::class.java.classLoader)) {
286-
val parser = Parser(
287-
ScriptEnvironment.builder().build(),
288-
Source.sourceFor("jsFile", fileText),
289-
ErrorManager.ThrowErrorManager()
290-
)
291-
return parser.parse()
292-
}
293-
}
281+
private fun runParser(fileText: String): Node =
282+
Compiler().parse(SourceFile.fromCode("jsFile", fileText))
294283

295-
private fun extractToplevelFunctions(): List<FunctionNode> {
284+
private fun extractToplevelFunctions(): List<Node> {
296285
val visitor = JsToplevelFunctionAstVisitor()
297-
parsedFile.body.accept(visitor)
286+
visitor.accept(parsedFile)
298287
return visitor.extractedMethods
299288
}
300289

@@ -321,18 +310,12 @@ class JsTestGenerator(
321310
return resultList
322311
}
323312

324-
private fun getFunctionNode(focusedMethodName: String, parentClassName: String?, fileText: String): FunctionNode {
325-
val parser = Parser(
326-
ScriptEnvironment.builder().build(),
327-
Source.sourceFor("jsFile", fileText),
328-
ErrorManager.ThrowErrorManager()
329-
)
330-
val fileNode = parser.parse()
313+
private fun getFunctionNode(focusedMethodName: String, parentClassName: String?): Node {
331314
val visitor = JsFunctionAstVisitor(
332315
focusedMethodName,
333316
if (parentClassName != dummyClassName) parentClassName else null
334317
)
335-
fileNode.accept(visitor)
318+
visitor.accept(parsedFile)
336319
return visitor.targetFunctionNode
337320
}
338321

@@ -343,12 +326,10 @@ class JsTestGenerator(
343326
getClassMethods("")
344327
}
345328

346-
private fun getClassMethods(className: String): List<FunctionNode> {
329+
private fun getClassMethods(className: String): List<Node> {
347330
val visitor = JsClassAstVisitor(className)
348-
parsedFile.body.accept(visitor)
331+
visitor.accept(parsedFile)
349332
val classNode = JsParserUtils.searchForClassDecl(className, parsedFile)
350-
return classNode?.classElements?.filter {
351-
it.value is FunctionNode
352-
}?.map { it.value as FunctionNode } ?: throw IllegalStateException("Can't extract methods of class $className")
333+
return classNode?.getClassMethods() ?: throw IllegalStateException("Can't extract methods of class $className")
353334
}
354335
}

‎utbot-js/src/main/kotlin/codegen/JsCodeGenerator.kt‎

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,24 @@ package codegen
22

33
import framework.codegen.JsCgLanguageAssistant
44
import framework.codegen.Mocha
5-
import org.utbot.framework.codegen.ForceStaticMocking
6-
import org.utbot.framework.codegen.HangingTestsTimeout
7-
import org.utbot.framework.codegen.ParametrizedTestSource
8-
import org.utbot.framework.codegen.RegularImport
9-
import org.utbot.framework.codegen.RuntimeExceptionTestsBehaviour
10-
import org.utbot.framework.codegen.StaticsMocking
11-
import org.utbot.framework.codegen.TestFramework
12-
import org.utbot.framework.codegen.model.CodeGeneratorResult
13-
import org.utbot.framework.codegen.model.constructor.CgMethodTestSet
14-
import org.utbot.framework.codegen.model.constructor.TestClassModel
15-
import org.utbot.framework.codegen.model.constructor.context.CgContext
16-
import org.utbot.framework.codegen.model.constructor.tree.CgTestClassConstructor
17-
import org.utbot.framework.codegen.model.visitor.CgAbstractRenderer
185
import org.utbot.framework.plugin.api.CodegenLanguage
196
import org.utbot.framework.plugin.api.ExecutableId
207
import org.utbot.framework.plugin.api.MockFramework
218
import framework.api.js.JsClassId
9+
import org.utbot.framework.codegen.CodeGeneratorResult
10+
import org.utbot.framework.codegen.domain.ForceStaticMocking
11+
import org.utbot.framework.codegen.domain.HangingTestsTimeout
12+
import org.utbot.framework.codegen.domain.ParametrizedTestSource
13+
import org.utbot.framework.codegen.domain.RegularImport
14+
import org.utbot.framework.codegen.domain.RuntimeExceptionTestsBehaviour
15+
import org.utbot.framework.codegen.domain.StaticsMocking
16+
import org.utbot.framework.codegen.domain.TestFramework
17+
import org.utbot.framework.codegen.domain.context.CgContext
18+
import org.utbot.framework.codegen.domain.models.CgClassFile
19+
import org.utbot.framework.codegen.domain.models.CgMethodTestSet
20+
import org.utbot.framework.codegen.domain.models.TestClassModel
21+
import org.utbot.framework.codegen.renderer.CgAbstractRenderer
22+
import org.utbot.framework.codegen.tree.CgTestClassConstructor
2223
import settings.JsTestGenerationSettings.fileUnderTestAliases
2324

2425
class JsCodeGenerator(
@@ -60,8 +61,9 @@ class JsCodeGenerator(
6061
testClassCustomName: String? = null,
6162
): CodeGeneratorResult = withCustomContext(testClassCustomName) {
6263
val testClassModel = TestClassModel(classUnderTest, cgTestSets)
63-
val testClassFile = CgTestClassConstructor(context).construct(testClassModel)
64-
CodeGeneratorResult(renderClassFile(testClassFile), testClassFile.testsGenerationReport)
64+
val astConstructor = CgTestClassConstructor(context)
65+
val testClassFile = astConstructor.construct(testClassModel)
66+
CodeGeneratorResult(renderClassFile(testClassFile), astConstructor.testsGenerationReport)
6567
}
6668

6769
private fun <R> withCustomContext(testClassCustomName: String? = null, block: () -> R): R {

‎utbot-js/src/main/kotlin/framework/codegen/JsCgLanguageAssistant.kt‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@ import framework.codegen.model.constructor.tree.JsCgMethodConstructor
55
import framework.codegen.model.constructor.tree.JsCgStatementConstructor
66
import framework.codegen.model.constructor.tree.JsCgVariableConstructor
77
import framework.codegen.model.constructor.visitor.CgJsRenderer
8-
import org.utbot.framework.codegen.model.constructor.TestClassContext
9-
import org.utbot.framework.codegen.model.constructor.context.CgContext
10-
import org.utbot.framework.codegen.model.util.CgPrinter
11-
import org.utbot.framework.codegen.model.visitor.CgAbstractRenderer
12-
import org.utbot.framework.codegen.model.visitor.CgRendererContext
8+
import org.utbot.framework.codegen.domain.context.CgContext
9+
import org.utbot.framework.codegen.domain.context.TestClassContext
10+
import org.utbot.framework.codegen.renderer.CgAbstractRenderer
11+
import org.utbot.framework.codegen.renderer.CgPrinter
12+
import org.utbot.framework.codegen.renderer.CgRendererContext
13+
import org.utbot.framework.codegen.services.language.CgLanguageAssistant
1314
import org.utbot.framework.plugin.api.ClassId
14-
import org.utbot.framework.plugin.api.CgLanguageAssistant
1515
import org.utbot.framework.plugin.api.utils.testClassNameGenerator
1616

1717
object JsCgLanguageAssistant : CgLanguageAssistant() {

‎utbot-js/src/main/kotlin/framework/codegen/JsDomain.kt‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
package framework.codegen
22

3-
import org.utbot.framework.codegen.TestFramework
43
import org.utbot.framework.plugin.api.BuiltinClassId
54
import org.utbot.framework.plugin.api.BuiltinMethodId
65
import org.utbot.framework.plugin.api.ClassId
76
import framework.api.js.JsClassId
87
import framework.api.js.util.jsErrorClassId
98
import framework.api.js.util.jsUndefinedClassId
9+
import org.utbot.framework.codegen.domain.TestFramework
1010

1111

1212
object Mocha : TestFramework(id = "Mocha", displayName = "Mocha") {

‎utbot-js/src/main/kotlin/framework/codegen/JsTestFrameworkManager.kt‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
package framework.codegen
22

33
import framework.codegen.model.constructor.tree.MochaManager
4-
import org.utbot.framework.codegen.model.constructor.context.CgContext
5-
import org.utbot.framework.plugin.api.LanguageTestFrameworkManager
4+
import org.utbot.framework.codegen.domain.context.CgContext
5+
import org.utbot.framework.codegen.services.language.LanguageTestFrameworkManager
66

77
class JsTestFrameworkManager: LanguageTestFrameworkManager() {
88

‎utbot-js/src/main/kotlin/framework/codegen/model/constructor/tree/JsCgCallableAccessManager.kt‎

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
package framework.codegen.model.constructor.tree
22

3-
import org.utbot.framework.codegen.model.constructor.context.CgContext
4-
import org.utbot.framework.codegen.model.constructor.context.CgContextOwner
5-
import org.utbot.framework.codegen.model.constructor.tree.CgCallableAccessManager
6-
import org.utbot.framework.codegen.model.constructor.tree.CgIncompleteMethodCall
7-
import org.utbot.framework.codegen.model.tree.*
8-
import org.utbot.framework.codegen.model.util.resolve
3+
import org.utbot.framework.codegen.domain.context.CgContext
4+
import org.utbot.framework.codegen.domain.context.CgContextOwner
5+
import org.utbot.framework.codegen.domain.models.CgConstructorCall
6+
import org.utbot.framework.codegen.domain.models.CgExecutableCall
7+
import org.utbot.framework.codegen.domain.models.CgExpression
8+
import org.utbot.framework.codegen.domain.models.CgMethodCall
9+
import org.utbot.framework.codegen.domain.models.CgStaticFieldAccess
10+
import org.utbot.framework.codegen.services.access.CgCallableAccessManager
11+
import org.utbot.framework.codegen.services.access.CgIncompleteMethodCall
12+
import org.utbot.framework.codegen.util.resolve
913
import org.utbot.framework.plugin.api.ClassId
1014
import org.utbot.framework.plugin.api.ConstructorId
1115
import org.utbot.framework.plugin.api.FieldId

‎utbot-js/src/main/kotlin/framework/codegen/model/constructor/tree/JsCgMethodConstructor.kt‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,5 @@
11
package framework.codegen.model.constructor.tree
22

3-
import org.utbot.framework.codegen.model.constructor.context.CgContext
4-
import org.utbot.framework.codegen.model.constructor.tree.CgMethodConstructor
5-
import org.utbot.framework.codegen.model.tree.CgTestMethod
6-
import org.utbot.framework.codegen.model.tree.CgTestMethodType
7-
import org.utbot.framework.codegen.model.tree.CgValue
8-
import org.utbot.framework.codegen.model.tree.CgVariable
93
import org.utbot.framework.plugin.api.ConcreteExecutionFailureException
104
import org.utbot.framework.plugin.api.ConstructorId
115
import org.utbot.framework.plugin.api.ExecutableId
@@ -17,6 +11,12 @@ import org.utbot.framework.plugin.api.onSuccess
1711
import org.utbot.framework.plugin.api.util.voidClassId
1812
import org.utbot.framework.util.isUnit
1913
import java.security.AccessControlException
14+
import org.utbot.framework.codegen.domain.context.CgContext
15+
import org.utbot.framework.codegen.domain.models.CgTestMethod
16+
import org.utbot.framework.codegen.domain.models.CgTestMethodType
17+
import org.utbot.framework.codegen.domain.models.CgValue
18+
import org.utbot.framework.codegen.domain.models.CgVariable
19+
import org.utbot.framework.codegen.tree.CgMethodConstructor
2020

2121
class JsCgMethodConstructor(ctx: CgContext) : CgMethodConstructor(ctx) {
2222

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /