Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resolve JBRes-2606 and JBRes-2609 #429

Merged
merged 1 commit into from
Dec 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import com.intellij.psi.PsiElementFactory
import com.intellij.psi.PsiFile
import com.intellij.psi.PsiJavaFile
import com.intellij.psi.PsiManager
import com.intellij.refactoring.suggested.startOffset
import com.intellij.util.containers.stream
import org.jetbrains.research.testspark.bundles.plugin.PluginLabelsBundle
import org.jetbrains.research.testspark.data.UIContext
Expand Down Expand Up @@ -202,7 +201,7 @@ class JavaDisplayUtils : DisplayUtils {

// insert imports to a code
PsiDocumentManager.getInstance(project).getDocument(outputFile)!!.insertString(
outputFile.importList?.startOffset ?: outputFile.packageStatement?.startOffset ?: 0,
outputFile.importList?.startOffsetInParent ?: outputFile.packageStatement?.startOffsetInParent ?: 0,
uiContext.testGenerationOutput.importsCode.joinToString("\n") + "\n\n",
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,11 @@ import com.intellij.psi.PsiDocumentManager
import com.intellij.psi.PsiFile
import com.intellij.psi.PsiJavaFile
import com.intellij.psi.PsiManager
import com.intellij.refactoring.suggested.endOffset
import com.intellij.refactoring.suggested.startOffset
import com.intellij.util.containers.stream
import org.jetbrains.kotlin.psi.KtClass
import org.jetbrains.kotlin.psi.KtFile
import org.jetbrains.kotlin.psi.KtPsiFactory
import org.jetbrains.kotlin.psi.psiUtil.pureEndOffset
import org.jetbrains.research.testspark.bundles.plugin.PluginLabelsBundle
import org.jetbrains.research.testspark.data.UIContext
import org.jetbrains.research.testspark.display.utils.ErrorMessageManager
Expand Down Expand Up @@ -213,8 +212,8 @@ class KotlinDisplayUtils : DisplayUtils {
val importsString = uiContext.testGenerationOutput.importsCode.joinToString("\n") + "\n\n"

// Find the insertion offset
val insertionOffset = outputFile.importList?.startOffset
?: outputFile.packageDirective?.endOffset
val insertionOffset = outputFile.importList?.startOffsetInParent
?: outputFile.packageDirective?.pureEndOffset
?: 0

// Insert the imports into the document
Expand Down
Loading