mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[LME-328] Unify exptractPredictedAPICalls
Removed `extractPredictedApiCallsEnsureMethodProperty` and updated references to use `extractPredictedApiCalls` directly. Replaced TokenProperties with ExtractionOptions when invoking `extractApiCalls` Merge-request: IJ-MR-156572 Merged-by: Berkay Özerbay <berkay.ozerbay@jetbrains.com> GitOrigin-RevId: 1bea737a57068936bc667f62a11ce26e32f5068a
This commit is contained in:
committed by
intellij-monorepo-bot
parent
8b08093bda
commit
8e6bbbf1e1
@@ -0,0 +1,19 @@
|
||||
package com.intellij.cce.core
|
||||
|
||||
import com.intellij.cce.evaluable.METHOD_NAME_PROPERTY
|
||||
|
||||
/**
|
||||
* ExtractionOptions decouples language-specific details from the API call extraction logic.
|
||||
* For example:
|
||||
* In static languages (e.g., Java/PHP), the method name narrows the search to a specific function.
|
||||
* In dynamic languages (e.g., Python), the extraction may ignore the method name entirely.
|
||||
*/
|
||||
data class ExtractionOptions(
|
||||
val methodName: String? = null
|
||||
)
|
||||
|
||||
fun TokenProperties.extractionOptions(): ExtractionOptions {
|
||||
return ExtractionOptions(
|
||||
methodName = this.additionalProperty(METHOD_NAME_PROPERTY)
|
||||
)
|
||||
}
|
||||
@@ -1,12 +1,12 @@
|
||||
package com.intellij.cce.metric
|
||||
|
||||
import com.intellij.cce.core.ExtractionOptions
|
||||
import com.intellij.cce.core.Language
|
||||
import com.intellij.cce.core.TokenProperties
|
||||
import com.intellij.openapi.extensions.ExtensionPointName
|
||||
import com.intellij.openapi.project.Project
|
||||
|
||||
interface ApiCallExtractor {
|
||||
suspend fun extractApiCalls(code: String, project: Project, tokenProperties: TokenProperties): List<String>
|
||||
suspend fun extractApiCalls(code: String, project: Project, extractionOptions: ExtractionOptions): List<String>
|
||||
}
|
||||
|
||||
interface ApiCallExtractorProvider {
|
||||
|
||||
+4
-5
@@ -1,14 +1,13 @@
|
||||
package com.intellij.cce.java.chat
|
||||
|
||||
import com.intellij.cce.core.ExtractionOptions
|
||||
import com.intellij.cce.core.Language
|
||||
import com.intellij.cce.core.TokenProperties
|
||||
import com.intellij.cce.evaluable.METHOD_NAME_PROPERTY
|
||||
import com.intellij.cce.metric.ApiCallExtractor
|
||||
import com.intellij.cce.metric.ApiCallExtractorProvider
|
||||
import com.intellij.ide.actions.QualifiedNameProviderUtil
|
||||
import com.intellij.openapi.application.edtWriteAction
|
||||
import com.intellij.openapi.application.readAction
|
||||
import com.intellij.openapi.application.smartReadActionBlocking
|
||||
import com.intellij.openapi.application.edtWriteAction
|
||||
import com.intellij.openapi.fileEditor.FileEditorManager
|
||||
import com.intellij.openapi.project.Project
|
||||
import com.intellij.openapi.roots.ProjectFileIndex
|
||||
@@ -32,8 +31,8 @@ class InEditorGeneratedCodeIntegrator : GeneratedCodeIntegrator {
|
||||
}
|
||||
|
||||
class JavaApiCallExtractor(private val generatedCodeIntegrator: GeneratedCodeIntegrator) : ApiCallExtractor {
|
||||
override suspend fun extractApiCalls(code: String, project: Project, tokenProperties: TokenProperties): List<String> {
|
||||
val methodName = tokenProperties.additionalProperty(METHOD_NAME_PROPERTY)!!
|
||||
override suspend fun extractApiCalls(code: String, project: Project, extractionOptions: ExtractionOptions): List<String> {
|
||||
val methodName = extractionOptions.methodName ?: return emptyList()
|
||||
val psiFileWithGeneratedCode = edtWriteAction { createPsiFile(code, project, "dummy1.java") }
|
||||
val method = extractMethodFromGeneratedSnippet(project, psiFileWithGeneratedCode, methodName) ?: return emptyList()
|
||||
|
||||
|
||||
+17
-22
@@ -3,6 +3,7 @@ package com.intellij.cce.evaluable.chat
|
||||
import com.intellij.cce.core.SymbolLocation
|
||||
import com.intellij.cce.core.TokenProperties
|
||||
import com.intellij.cce.core.TypeProperty
|
||||
import com.intellij.cce.core.extractionOptions
|
||||
import com.intellij.cce.evaluable.METHOD_NAME_PROPERTY
|
||||
import com.intellij.cce.java.chat.InEditorGeneratedCodeIntegrator
|
||||
import com.intellij.cce.java.chat.JavaApiCallExtractor
|
||||
@@ -57,7 +58,7 @@ class JavaApiCallExtractorTest : BasePlatformTestCase() {
|
||||
|
||||
runBlocking {
|
||||
val extractor = JavaApiCallExtractor { project, _ -> code }
|
||||
val apiCalls = extractor.extractApiCalls(code, project, tokenProperties)
|
||||
val apiCalls = extractor.extractApiCalls(code, project, tokenProperties.extractionOptions())
|
||||
assertEquals(listOf("MyClass#bar"), apiCalls)
|
||||
}
|
||||
}
|
||||
@@ -83,7 +84,7 @@ class JavaApiCallExtractorTest : BasePlatformTestCase() {
|
||||
|
||||
runBlocking {
|
||||
val extractor = JavaApiCallExtractor { project, _ -> code }
|
||||
val apiCalls = extractor.extractApiCalls(code, project, tokenProperties)
|
||||
val apiCalls = extractor.extractApiCalls(code, project, tokenProperties.extractionOptions())
|
||||
assertEquals(listOf("MyClass#bar", "MyClass#baz"), apiCalls)
|
||||
}
|
||||
}
|
||||
@@ -102,7 +103,7 @@ class JavaApiCallExtractorTest : BasePlatformTestCase() {
|
||||
|
||||
runBlocking {
|
||||
val extractor = JavaApiCallExtractor { project, _ -> code }
|
||||
val apiCalls = extractor.extractApiCalls(code, project, tokenProperties)
|
||||
val apiCalls = extractor.extractApiCalls(code, project, tokenProperties.extractionOptions())
|
||||
assertTrue(apiCalls.isEmpty())
|
||||
}
|
||||
}
|
||||
@@ -121,7 +122,7 @@ class JavaApiCallExtractorTest : BasePlatformTestCase() {
|
||||
|
||||
val code = """
|
||||
public void bar() {
|
||||
foo()
|
||||
foo();
|
||||
}
|
||||
""".trimIndent()
|
||||
|
||||
@@ -130,11 +131,8 @@ class JavaApiCallExtractorTest : BasePlatformTestCase() {
|
||||
|
||||
runBlocking {
|
||||
val extractor = JavaApiCallExtractor(InEditorGeneratedCodeIntegrator())
|
||||
val apiCalls = extractor.extractApiCalls(code, project, tokenProperties)
|
||||
assertEquals(
|
||||
listOf("MyClass#foo"),
|
||||
apiCalls
|
||||
)
|
||||
val apiCalls = extractor.extractApiCalls(code, project, tokenProperties.extractionOptions())
|
||||
assertEquals(listOf("MyClass#foo"), apiCalls)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -146,7 +144,7 @@ class JavaApiCallExtractorTest : BasePlatformTestCase() {
|
||||
}
|
||||
|
||||
public void bar(Integer t) {
|
||||
bar()
|
||||
bar();
|
||||
}
|
||||
<caret>
|
||||
}
|
||||
@@ -156,7 +154,7 @@ class JavaApiCallExtractorTest : BasePlatformTestCase() {
|
||||
|
||||
val code = """
|
||||
public void bar() {
|
||||
foo()
|
||||
foo();
|
||||
}
|
||||
""".trimIndent()
|
||||
|
||||
@@ -165,11 +163,8 @@ class JavaApiCallExtractorTest : BasePlatformTestCase() {
|
||||
|
||||
runBlocking {
|
||||
val extractor = JavaApiCallExtractor(InEditorGeneratedCodeIntegrator())
|
||||
val apiCalls = extractor.extractApiCalls(code, project, tokenProperties)
|
||||
assertEquals(
|
||||
listOf("MyClass#foo"),
|
||||
apiCalls
|
||||
)
|
||||
val apiCalls = extractor.extractApiCalls(code, project, tokenProperties.extractionOptions())
|
||||
assertEquals(listOf("MyClass#foo"), apiCalls)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -177,7 +172,7 @@ class JavaApiCallExtractorTest : BasePlatformTestCase() {
|
||||
val code = """
|
||||
public class MyClass {
|
||||
public void foo() {
|
||||
something()
|
||||
something();
|
||||
}
|
||||
}
|
||||
""".trimIndent()
|
||||
@@ -187,7 +182,7 @@ class JavaApiCallExtractorTest : BasePlatformTestCase() {
|
||||
|
||||
runBlocking {
|
||||
val extractor = JavaApiCallExtractor { project, _ -> code }
|
||||
val apiCalls = extractor.extractApiCalls(code, project, tokenProperties)
|
||||
val apiCalls = extractor.extractApiCalls(code, project, tokenProperties.extractionOptions())
|
||||
assertTrue(apiCalls.isEmpty())
|
||||
}
|
||||
}
|
||||
@@ -239,9 +234,9 @@ public class MySubClass extends SuperClass {
|
||||
// Assuming Velocity is another class defined elsewhere
|
||||
class Velocity {
|
||||
private float length;
|
||||
|
||||
|
||||
// Constructor and other methods
|
||||
|
||||
|
||||
public float getLength() {
|
||||
return length;
|
||||
}
|
||||
@@ -260,11 +255,11 @@ class SuperClass {
|
||||
|
||||
runBlocking {
|
||||
val extractor = JavaApiCallExtractor { project, _ -> code }
|
||||
val apiCalls = extractor.extractApiCalls(code, project, tokenProperties)
|
||||
val apiCalls = extractor.extractApiCalls(code, project, tokenProperties.extractionOptions())
|
||||
assertEquals(
|
||||
listOf("MySubClass#isTargetingSuccessful", "Velocity#getLength", "MySubClass#onTargetingFailOrLowVelocity"),
|
||||
apiCalls
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+3
-3
@@ -1,11 +1,11 @@
|
||||
package com.intellij.cce.python.chat
|
||||
|
||||
import com.intellij.cce.core.ExtractionOptions
|
||||
import com.intellij.cce.core.Language
|
||||
import com.intellij.cce.core.TokenProperties
|
||||
import com.intellij.cce.metric.ApiCallExtractor
|
||||
import com.intellij.cce.metric.ApiCallExtractorProvider
|
||||
import com.intellij.openapi.application.readAction
|
||||
import com.intellij.openapi.application.edtWriteAction
|
||||
import com.intellij.openapi.application.readAction
|
||||
import com.intellij.openapi.project.Project
|
||||
import com.intellij.psi.PsiFile
|
||||
import com.intellij.psi.PsiFileFactory
|
||||
@@ -14,7 +14,7 @@ import com.jetbrains.python.psi.PyRecursiveElementVisitor
|
||||
import com.intellij.lang.Language as PlatformLanguage
|
||||
|
||||
class PythonApiCallExtractor : ApiCallExtractor {
|
||||
override suspend fun extractApiCalls(code: String, project: Project, tokenProperties: TokenProperties): List<String> {
|
||||
override suspend fun extractApiCalls(code: String, project: Project, extractionOptions: ExtractionOptions): List<String> {
|
||||
val psiFile = edtWriteAction { parsePsiFile(project, code) }
|
||||
return readAction { extractApiCalls(psiFile) }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user