Skip to content

Commit

Permalink
[ICTL-975] Adjusting the plugin structure to enable different languag…
Browse files Browse the repository at this point in the history
…es dependency (#264)

* New level of abstraction for Psi Components

* klint and documentation

* klint

* fixed elephant logo by deleting the plugin depandancy on Kotlin

* fix: changes after the review

* fix: deleted validate line + klint

* fix: changed log

* fix: reordering of classes

* Delete src/main/kotlin/org/jetbrains/research/testspark/helpers/psiHelpers/KotlinPsiHelper.kt

* feat: implemented and integrated ClassType

* fix: getSurroundingLine function

* separated Psi classes to different files

* last refactoring

* merge conflict solved

* first version of Kotlin PSI implementation

* klint

* bugs fixed

* ktint

* merge

* preliminary changes

* changing the plugin.xml structure

* something is still bad

* something is working

* added gradle

* fix: working gradle, project can run, but plugin.xml does not work

* new version of plugin.xml

* the version that should work but it is not

* deleted unnecessary imports

* implementationClass

* DONE! Thanks god

* feat: documentation

* klint

* merge

* small fix

* fix: gradle tasks failure

* fix: verification only for rootProject

* small fix

* disable verification

* fixed verification

* deleted unnecessary line

* fix: after thr review

* klint

* deleted unnecessary elvis operator

* fixed the pluginid

* Update OpenAIRequestManager.kt

* resolved

---------

Co-authored-by: Arkadii Sapozhnikov <[email protected]>
Co-authored-by: Arkadii Sapozhnikov <[email protected]>
  • Loading branch information
3 people authored Jun 27, 2024
1 parent 404b88e commit 58895eb
Show file tree
Hide file tree
Showing 40 changed files with 409 additions and 171 deletions.
7 changes: 5 additions & 2 deletions .run/Run IDE for UI Tests.run.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,21 @@
<option name="executionName" />
<option name="externalProjectPath" value="$PROJECT_DIR$" />
<option name="externalSystemIdString" value="GRADLE" />
<option name="scriptParameters" value="runIdeForUiTests" />
<option name="scriptParameters" value="" />
<option name="taskDescriptions">
<list />
</option>
<option name="taskNames">
<list />
<list>
<option value=":runIdeForUiTests" />
</list>
</option>
<option name="vmOptions" />
</ExternalSystemSettings>
<ExternalSystemDebugServerProcess>true</ExternalSystemDebugServerProcess>
<ExternalSystemReattachDebugProcess>true</ExternalSystemReattachDebugProcess>
<DebugAllEnabled>false</DebugAllEnabled>
<RunAsTest>false</RunAsTest>
<method v="2" />
</configuration>
</component>
4 changes: 4 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,9 @@ dependencies {
implementation(files("lib/JUnitRunner.jar"))

implementation(project(":core"))
implementation(project(":langwrappers")) // Needed to use Psi related interfaces and load proper implementation
implementation(project(":kotlin")) // Needed to load the testspark-kotlin.xml
implementation(project(":java")) // Needed to load the testspark-java.xml
if (spaceCredentialsProvided()) {
"hasGrazieAccessCompileOnly"(project(":core"))
}
Expand Down Expand Up @@ -204,6 +207,7 @@ tasks {
dependsOn("copyJUnitRunnerLib")
dependsOn(":core:compileKotlin")
}

// Set the JVM compatibility versions
properties("javaVersion").let {
withType<JavaCompile> {
Expand Down
2 changes: 1 addition & 1 deletion core/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ tasks.test {
useJUnitPlatform()
}
kotlin {
jvmToolchain(17)
jvmToolchain(rootProject.properties["jvmToolchainVersion"].toString().toInt())
}

publishing {
Expand Down
2 changes: 2 additions & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,5 @@ gradleVersion = 8.2.1
# See https://plugins.jetbrains.com/docs/intellij/kotlin.html#kotlin-standard-library for details.
# suppress inspection "UnusedProperty"
kotlin.stdlib.default.dependency = false

jvmToolchainVersion = 17
34 changes: 34 additions & 0 deletions java/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
plugins {
kotlin("jvm")
id("org.jetbrains.intellij")
}

repositories {
mavenCentral()
}

dependencies {
implementation(kotlin("stdlib"))

implementation(project(":langwrappers")) // Interfaces that cover language-specific logic
implementation(project(":core"))
}

intellij {
rootProject.properties["platformVersion"]?.let { version.set(it.toString()) }
plugins.set(listOf("java"))
}

tasks.named("verifyPlugin") { enabled = false }
tasks.named("runIde") { enabled = false }
tasks.named("runPluginVerifier") { enabled = false }

tasks {
buildSearchableOptions {
enabled = false
}
}

kotlin {
jvmToolchain(rootProject.properties["jvmToolchainVersion"].toString().toInt())
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.jetbrains.research.testspark.helpers.psi.java
package org.jetbrains.research.testspark.java

import com.intellij.openapi.project.Project
import com.intellij.openapi.vfs.VirtualFile
Expand All @@ -12,8 +12,8 @@ import com.intellij.psi.util.PsiTypesUtil
import org.jetbrains.research.testspark.core.data.ClassType
import org.jetbrains.research.testspark.core.utils.importPattern
import org.jetbrains.research.testspark.core.utils.packagePattern
import org.jetbrains.research.testspark.helpers.psi.PsiClassWrapper
import org.jetbrains.research.testspark.helpers.psi.PsiMethodWrapper
import org.jetbrains.research.testspark.langwrappers.PsiClassWrapper
import org.jetbrains.research.testspark.langwrappers.PsiMethodWrapper

class JavaPsiClassWrapper(private val psiClass: PsiClass) : PsiClassWrapper {
override val name: String get() = psiClass.name ?: ""
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.jetbrains.research.testspark.helpers.psi.java
package org.jetbrains.research.testspark.java

import com.intellij.openapi.actionSystem.AnActionEvent
import com.intellij.openapi.actionSystem.CommonDataKeys
Expand All @@ -13,11 +13,10 @@ import com.intellij.psi.PsiFile
import com.intellij.psi.PsiMethod
import com.intellij.psi.util.PsiTreeUtil
import com.intellij.psi.util.PsiTypesUtil
import org.jetbrains.research.testspark.helpers.psi.Language
import org.jetbrains.research.testspark.helpers.psi.PsiClassWrapper
import org.jetbrains.research.testspark.helpers.psi.PsiHelper
import org.jetbrains.research.testspark.helpers.psi.PsiMethodWrapper
import org.jetbrains.research.testspark.tools.llm.SettingsArguments
import org.jetbrains.research.testspark.langwrappers.Language
import org.jetbrains.research.testspark.langwrappers.PsiClassWrapper
import org.jetbrains.research.testspark.langwrappers.PsiHelper
import org.jetbrains.research.testspark.langwrappers.PsiMethodWrapper

class JavaPsiHelper(private val psiFile: PsiFile) : PsiHelper {

Expand Down Expand Up @@ -85,10 +84,8 @@ class JavaPsiHelper(private val psiFile: PsiFile) : PsiHelper {
project: Project,
classesToTest: MutableList<PsiClassWrapper>,
caretOffset: Int,
maxPolymorphismDepth: Int, // check if cut has any non-java super class
) {
// check if cut has any none java super class
val maxPolymorphismDepth = SettingsArguments(project).maxPolyDepth(0)

val cutPsiClass = getSurroundingClass(caretOffset)!!
var currentPsiClass = cutPsiClass
for (index in 0 until maxPolymorphismDepth) {
Expand All @@ -110,13 +107,14 @@ class JavaPsiHelper(private val psiFile: PsiFile) : PsiHelper {
project: Project,
classesToTest: List<PsiClassWrapper>,
polyDepthReducing: Int,
maxInputParamsDepth: Int,
): MutableSet<PsiClassWrapper> {
val interestingPsiClasses: MutableSet<JavaPsiClassWrapper> = mutableSetOf()

var currentLevelClasses =
mutableListOf<PsiClassWrapper>().apply { addAll(classesToTest) }

repeat(SettingsArguments(project).maxInputParamsDepth(polyDepthReducing)) {
repeat(maxInputParamsDepth) {
val tempListOfClasses = mutableSetOf<JavaPsiClassWrapper>()

currentLevelClasses.forEach { classIt ->
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package org.jetbrains.research.testspark.java

import com.intellij.psi.PsiFile
import org.jetbrains.research.testspark.langwrappers.PsiHelperProvider

class JavaPsiHelperProvider : PsiHelperProvider {
override fun getPsiHelper(file: PsiFile) = JavaPsiHelper(file)
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.jetbrains.research.testspark.helpers.psi.java
package org.jetbrains.research.testspark.java

import com.intellij.psi.PsiClassType
import com.intellij.psi.PsiDocumentManager
Expand All @@ -7,8 +7,8 @@ import com.intellij.psi.PsiMethod
import com.intellij.psi.PsiSubstitutor
import com.intellij.psi.PsiType
import com.intellij.util.containers.stream
import org.jetbrains.research.testspark.helpers.psi.PsiClassWrapper
import org.jetbrains.research.testspark.helpers.psi.PsiMethodWrapper
import org.jetbrains.research.testspark.langwrappers.PsiClassWrapper
import org.jetbrains.research.testspark.langwrappers.PsiMethodWrapper
import java.util.stream.Collectors

class JavaPsiMethodWrapper(private val psiMethod: PsiMethod) : PsiMethodWrapper {
Expand Down
9 changes: 9 additions & 0 deletions java/src/main/resources/META-INF/testgenie-java.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<!--Register the extension point, to specify a custom PsiHelperProvider for the Java language.-->
<idea-plugin>
<extensions defaultExtensionNs="org.jetbrains.research.testgenie">
<psiHelperProvider
language="JAVA"
implementationClass="org.jetbrains.research.testspark.java.JavaPsiHelperProvider"
/>
</extensions>
</idea-plugin>
34 changes: 34 additions & 0 deletions kotlin/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
plugins {
kotlin("jvm")
id("org.jetbrains.intellij")
}

repositories {
mavenCentral()
}

dependencies {
implementation(kotlin("stdlib"))

implementation(project(":langwrappers")) // Interfaces that cover language-specific logic
implementation(project(":core"))
}

intellij {
rootProject.properties["platformVersion"]?.let { version.set(it.toString()) }
plugins.set(listOf("java", "org.jetbrains.kotlin"))
}

tasks.named("verifyPlugin") { enabled = false }
tasks.named("runIde") { enabled = false }
tasks.named("runPluginVerifier") { enabled = false }

tasks {
buildSearchableOptions {
enabled = false
}
}

kotlin {
jvmToolchain(rootProject.properties["jvmToolchainVersion"].toString().toInt())
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.jetbrains.research.testspark.helpers.psi.kotlin
package org.jetbrains.research.testspark.kotlin

import com.intellij.openapi.project.Project
import com.intellij.openapi.vfs.VirtualFile
Expand All @@ -19,13 +19,13 @@ import org.jetbrains.kotlin.resolve.DescriptorToSourceUtils
import org.jetbrains.research.testspark.core.data.ClassType
import org.jetbrains.research.testspark.core.utils.importPattern
import org.jetbrains.research.testspark.core.utils.packagePattern
import org.jetbrains.research.testspark.helpers.psi.PsiClassWrapper
import org.jetbrains.research.testspark.helpers.psi.PsiMethodWrapper
import org.jetbrains.research.testspark.langwrappers.PsiClassWrapper
import org.jetbrains.research.testspark.langwrappers.PsiMethodWrapper

class KotlinPsiClassWrapper(private val psiClass: KtClassOrObject) : PsiClassWrapper {
override val name: String get() = psiClass.name ?: ""

override val qualifiedName: String get() = psiClass.fqName!!.asString() ?: ""
override val qualifiedName: String get() = psiClass.fqName!!.asString()

override val text: String? get() = psiClass.text

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.jetbrains.research.testspark.helpers.psi.kotlin
package org.jetbrains.research.testspark.kotlin

import com.intellij.openapi.actionSystem.AnActionEvent
import com.intellij.openapi.actionSystem.CommonDataKeys
Expand All @@ -21,11 +21,10 @@ import org.jetbrains.kotlin.psi.KtTypeReference
import org.jetbrains.kotlin.resolve.BindingContext
import org.jetbrains.kotlin.resolve.DescriptorToSourceUtils
import org.jetbrains.kotlin.resolve.lazy.BodyResolveMode
import org.jetbrains.research.testspark.helpers.psi.Language
import org.jetbrains.research.testspark.helpers.psi.PsiClassWrapper
import org.jetbrains.research.testspark.helpers.psi.PsiHelper
import org.jetbrains.research.testspark.helpers.psi.PsiMethodWrapper
import org.jetbrains.research.testspark.tools.llm.SettingsArguments
import org.jetbrains.research.testspark.langwrappers.Language
import org.jetbrains.research.testspark.langwrappers.PsiClassWrapper
import org.jetbrains.research.testspark.langwrappers.PsiHelper
import org.jetbrains.research.testspark.langwrappers.PsiMethodWrapper

class KotlinPsiHelper(private val psiFile: PsiFile) : PsiHelper {

Expand Down Expand Up @@ -86,8 +85,8 @@ class KotlinPsiHelper(private val psiFile: PsiFile) : PsiHelper {
project: Project,
classesToTest: MutableList<PsiClassWrapper>,
caretOffset: Int,
maxPolymorphismDepth: Int, // check if cut has any non-java super class
) {
val maxPolymorphismDepth = SettingsArguments(project).maxPolyDepth(polyDepthReducing = 0)
val cutPsiClass = getSurroundingClass(caretOffset)!!
var currentPsiClass = cutPsiClass
for (index in 0 until maxPolymorphismDepth) {
Expand All @@ -109,12 +108,13 @@ class KotlinPsiHelper(private val psiFile: PsiFile) : PsiHelper {
project: Project,
classesToTest: List<PsiClassWrapper>,
polyDepthReducing: Int,
maxInputParamsDepth: Int,
): MutableSet<PsiClassWrapper> {
val interestingPsiClasses: MutableSet<KotlinPsiClassWrapper> = mutableSetOf()

var currentLevelClasses = mutableListOf<PsiClassWrapper>().apply { addAll(classesToTest) }

repeat(SettingsArguments(project).maxInputParamsDepth(polyDepthReducing)) {
repeat(maxInputParamsDepth) {
val tempListOfClasses = mutableSetOf<KotlinPsiClassWrapper>()

currentLevelClasses.forEach { classIt ->
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package org.jetbrains.research.testspark.kotlin

import com.intellij.psi.PsiFile
import org.jetbrains.research.testspark.langwrappers.PsiHelperProvider

class KotlinPsiHelperProvider : PsiHelperProvider {
override fun getPsiHelper(file: PsiFile) = KotlinPsiHelper(file)
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.jetbrains.research.testspark.helpers.psi.kotlin
package org.jetbrains.research.testspark.kotlin

import com.intellij.psi.PsiDocumentManager
import com.intellij.psi.PsiFile
Expand All @@ -12,8 +12,8 @@ import org.jetbrains.kotlin.psi.KtPrimaryConstructor
import org.jetbrains.kotlin.psi.KtSecondaryConstructor
import org.jetbrains.kotlin.psi.KtTypeReference
import org.jetbrains.kotlin.psi.psiUtil.containingClassOrObject
import org.jetbrains.research.testspark.helpers.psi.PsiClassWrapper
import org.jetbrains.research.testspark.helpers.psi.PsiMethodWrapper
import org.jetbrains.research.testspark.langwrappers.PsiClassWrapper
import org.jetbrains.research.testspark.langwrappers.PsiMethodWrapper

class KotlinPsiMethodWrapper(val psiFunction: KtFunction) : PsiMethodWrapper {

Expand Down
8 changes: 8 additions & 0 deletions kotlin/src/main/resources/META-INF/testgenie-kotlin.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<!--Register the extension point, to specify a custom PsiHelperProvider for the Kotlin language.-->
<idea-plugin>
<extensions defaultExtensionNs="org.jetbrains.research.testgenie">
<psiHelperProvider
implementationClass="org.jetbrains.research.testspark.kotlin.KotlinPsiHelperProvider"
language="kotlin"/>
</extensions>
</idea-plugin>
29 changes: 29 additions & 0 deletions langwrappers/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
plugins {
kotlin("jvm")
id("org.jetbrains.intellij")
}

repositories {
mavenCentral()
// Add any other repositories you need
}

dependencies {
implementation(kotlin("stdlib"))

implementation(project(":core"))
}

intellij {
rootProject.properties["platformVersion"]?.let { version.set(it.toString()) }
plugins.set(listOf("java"))
downloadSources.set(true)
}

tasks.named("verifyPlugin") { enabled = false }
tasks.named("runIde") { enabled = false }
tasks.named("runPluginVerifier") { enabled = false }

kotlin {
jvmToolchain(rootProject.properties["jvmToolchainVersion"].toString().toInt())
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.jetbrains.research.testspark.helpers.psi
package org.jetbrains.research.testspark.langwrappers

import com.intellij.openapi.actionSystem.AnActionEvent
import com.intellij.openapi.project.Project
Expand Down Expand Up @@ -125,6 +125,7 @@ interface PsiHelper {
project: Project,
classesToTest: List<PsiClassWrapper>,
polyDepthReducing: Int,
maxInputParamsDepth: Int,
): MutableSet<PsiClassWrapper>

/**
Expand Down Expand Up @@ -169,6 +170,7 @@ interface PsiHelper {
project: Project,
classesToTest: MutableList<PsiClassWrapper>,
caretOffset: Int,
maxPolymorphismDepth: Int,
)

/**
Expand Down
Loading

0 comments on commit 58895eb

Please sign in to comment.