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

Class/ function code getting APIs; Git related APIs #6

Open
wants to merge 81 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
81 commits
Select commit Hold shift + click to select a range
f0c619d
add test for a file class code getting api
diffitask Nov 14, 2023
c9a5f37
add test for a file function code api
diffitask Nov 14, 2023
a352692
add method for processing any server request parameter
diffitask Nov 14, 2023
fee0295
add file class code api server request, add error throwing to the cla…
diffitask Nov 14, 2023
eaa4930
add error throwing to the function code getters
diffitask Nov 14, 2023
5dcbd70
add file function getting server request
diffitask Nov 14, 2023
9ecae0b
rename requests params constants
diffitask Nov 14, 2023
284d346
add json descriptions of the class/ function code getting apis
diffitask Nov 15, 2023
9819287
some class/ function code getting requests refactoring
diffitask Nov 15, 2023
4fb85d3
add Git4Idea to platform plugins list in gradle.properties
diffitask Nov 16, 2023
f6a3a4c
add base version of the GitStatus api
diffitask Nov 16, 2023
27d71b0
add getGitStatus server request
diffitask Nov 16, 2023
0a0314e
move git repository and root getting from git status to ide state keeper
diffitask Nov 16, 2023
a2f70f2
add uncalled execute() error to file related apis
diffitask Nov 17, 2023
b18bc5e
add uncalled execute() error to file system related apis
diffitask Nov 17, 2023
e7b2c66
add uncalled execute() error to git status api
diffitask Nov 17, 2023
9005936
add uncalled execute() error to other git related apis methods
diffitask Nov 17, 2023
5ccc91f
replace error throwing with null returning for class/ func code getti…
diffitask Nov 17, 2023
5ce6e11
update server requests due to apis execution result getters updates
diffitask Nov 17, 2023
82cc204
update constants in the ide state keeper
diffitask Nov 17, 2023
82dd4b4
add git status json description
diffitask Nov 17, 2023
a0cd422
add git add api
diffitask Nov 17, 2023
692f57e
add git add server request
diffitask Nov 17, 2023
b0a0969
small refactoring of the git status server request
diffitask Nov 17, 2023
74ddf34
add fileName parameter to the git add server request
diffitask Nov 17, 2023
6bf4532
add git command error message returning in git related apis
diffitask Nov 17, 2023
37d4f75
add git commit api
diffitask Nov 17, 2023
9f0d758
add git commit server request
diffitask Nov 17, 2023
3c073e6
add git add json description
diffitask Nov 17, 2023
fbdaaa7
add git commit json description
diffitask Nov 17, 2023
b005a3b
update process req parameter function
diffitask Nov 17, 2023
6b794b4
add git branch api
diffitask Nov 17, 2023
2fd8b91
add git branch server request
diffitask Nov 17, 2023
6bc66ed
add git branch api json description
diffitask Nov 17, 2023
1d7735f
add git checkout api
diffitask Nov 17, 2023
1cea4c6
add git checkout server request
diffitask Nov 17, 2023
0cd8457
add some comments to git api reverse methods
diffitask Nov 17, 2023
cf8abf5
add git checkout api json description
diffitask Nov 17, 2023
4fd088d
create common function to execute git api method
diffitask Jan 3, 2024
4be157d
implement reverse() for the git add
diffitask Jan 3, 2024
4c53a58
implement reverse() for the git branch
diffitask Jan 3, 2024
302928f
implement reverse() for the git commit
diffitask Jan 3, 2024
7e5544e
implement reverse() for the git checkout
diffitask Jan 3, 2024
e51c824
create base GitApiMethod class
diffitask Jan 3, 2024
bc2a845
update git add due to inheritance from GitApiMethod base class
diffitask Jan 3, 2024
fa682bd
update git branch due to inheritance from GitApiMethod base class
diffitask Jan 3, 2024
e71b5bc
update git checkout due to inheritance from GitApiMethod base class
diffitask Jan 3, 2024
512e834
update git commit due to inheritance from GitApiMethod base class
diffitask Jan 3, 2024
3997896
update git status due to inheritance from GitApiMethod base class
diffitask Jan 3, 2024
abf8306
small log message fix
diffitask Jan 3, 2024
29b8ea7
add git command result saving, update git status
diffitask Jan 3, 2024
32f97d7
add git log
diffitask Jan 4, 2024
47d10af
add git rm
diffitask Jan 4, 2024
8ad7620
add git reset
diffitask Jan 5, 2024
c28f5e0
add json descriptions for recently created git apis
diffitask Jan 5, 2024
aeee12d
add git merge
diffitask Jan 5, 2024
dde8191
add 'create file' api
diffitask Jan 5, 2024
ea4a7b3
add 'create file' api
diffitask Jan 5, 2024
9a17881
add 'create directory' api
diffitask Jan 5, 2024
c2d0121
make file creating/ deleting methods separate functions
diffitask Jan 5, 2024
a02c2a1
update switching to a tread with a write access
diffitask Jan 5, 2024
343317b
add 'delete file' api
diffitask Jan 5, 2024
fb15e3d
add attempts to init git repo for test project
diffitask Jan 8, 2024
f3956fb
move find project base dir method from IdeStateKeeper to utils
diffitask Jan 8, 2024
6225cfa
fix bug so now file is saved to local disk after its text changing
diffitask Jan 8, 2024
d7c625c
add set file text api
diffitask Jan 8, 2024
c29df5e
update delete file api
diffitask Jan 9, 2024
5da1409
rename FileText -> GetFileText; move text file related apis to the se…
diffitask Jan 9, 2024
467ac9f
add set file text api json desc
diffitask Jan 9, 2024
80e12e3
add directory refreshing to all file system related apis
diffitask Jan 10, 2024
c29c4cc
set previous data to null when reverse is called in reversible file s…
diffitask Jan 10, 2024
041eb80
move create/ delete subdirectory functions to utils
diffitask Jan 10, 2024
073a2bf
add create file api json desc
diffitask Jan 10, 2024
6a97565
add create directory api json desc
diffitask Jan 10, 2024
204e404
add delete file api json desc
diffitask Jan 10, 2024
04ae619
add some comments todo
diffitask Jan 10, 2024
57f9777
add fileText parameter json desc to the set file text server request
diffitask Jan 15, 2024
cba5ee6
update regexps for fileName and fileText parameters
diffitask Jan 15, 2024
f2c481b
remove regexps for fileText parameter
diffitask Jan 16, 2024
459b234
add opportunity to call 'cd ..' -- change working directory to a pare…
diffitask Jan 16, 2024
9114db8
make parent directory searching recursive: move it to the right util …
diffitask Jan 16, 2024
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
2 changes: 1 addition & 1 deletion ide-former-plugin/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ platformVersion = 2023.2.4
# Plugin Dependencies -> https://plugins.jetbrains.com/docs/intellij/plugin-dependencies.html
# To find actual PythonCore version go to https://plugins.jetbrains.com/plugin/631-python/versions and check, which version is matched with platformVersion
# Example: platformPlugins = com.intellij.java, com.jetbrains.php:203.4449.22
platformPlugins = com.intellij.java, org.jetbrains.kotlin, PythonCore:232.10203.2
platformPlugins = com.intellij.java, org.jetbrains.kotlin, PythonCore:232.10203.2, Git4Idea

# Gradle Releases -> https://github.com/gradle/gradle/releases
gradleVersion = 8.3
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ package org.jetbrains.research.ideFormerPlugin.api.models.fileRelated.fileClasse
import org.jetbrains.research.ideFormerPlugin.api.models.IdeApiMethod

interface FileClasses : IdeApiMethod {
fun getClassesNames(): List<String>?
fun getClassesNames(): List<String>
fun getClassCode(className: String): String?
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package org.jetbrains.research.ideFormerPlugin.api.models.fileRelated.fileClasse

import com.intellij.psi.PsiClass
import com.intellij.psi.PsiDirectory
import org.jetbrains.research.ideFormerPlugin.api.models.utils.getFilePsiElementsOfType
import org.jetbrains.research.ideFormerPlugin.api.models.utils.*

class JavaFileClasses(
private val projectDirectory: PsiDirectory,
Expand All @@ -14,10 +14,15 @@ class JavaFileClasses(
javaClasses = getFilePsiElementsOfType<PsiClass>(projectDirectory, javaFileName)
}

override fun getClassesNames(): List<String>? =
javaClasses?.mapNotNull { it.name }
override fun getClassesNames(): List<String> {
if (javaClasses == null) error(UNCALLED_EXECUTE_BEFORE_RESULT_GETTING)
return javaClasses!!.mapNotNull { it.name }
}

override fun getClassCode(className: String): String? = javaClasses
?.firstOrNull { it.name == className }
?.text
override fun getClassCode(className: String): String? {
if (javaClasses == null) error(UNCALLED_EXECUTE_BEFORE_RESULT_GETTING)
return javaClasses!!
.firstOrNull { it.name == className }
?.text
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package org.jetbrains.research.ideFormerPlugin.api.models.fileRelated.fileClasse

import com.intellij.psi.PsiDirectory
import org.jetbrains.kotlin.psi.KtClass
import org.jetbrains.research.ideFormerPlugin.api.models.utils.UNCALLED_EXECUTE_BEFORE_RESULT_GETTING
import org.jetbrains.research.ideFormerPlugin.api.models.utils.getFilePsiElementsOfType

class KtFileClasses(
Expand All @@ -14,9 +15,15 @@ class KtFileClasses(
ktClasses = getFilePsiElementsOfType<KtClass>(projectDirectory, ktFileName)
}

override fun getClassesNames(): List<String>? = ktClasses?.mapNotNull { it.name }
override fun getClassesNames(): List<String> {
if (ktClasses == null) error(UNCALLED_EXECUTE_BEFORE_RESULT_GETTING)
return ktClasses!!.mapNotNull { it.name }
}

override fun getClassCode(className: String): String? = ktClasses
?.firstOrNull { it.name == className }
?.text
override fun getClassCode(className: String): String? {
if (ktClasses == null) error(UNCALLED_EXECUTE_BEFORE_RESULT_GETTING)
return ktClasses!!
.firstOrNull { it.name == className }
?.text
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package org.jetbrains.research.ideFormerPlugin.api.models.fileRelated.fileClasse

import com.intellij.psi.PsiDirectory
import com.jetbrains.python.psi.PyClass
import org.jetbrains.research.ideFormerPlugin.api.models.utils.UNCALLED_EXECUTE_BEFORE_RESULT_GETTING
import org.jetbrains.research.ideFormerPlugin.api.models.utils.getFilePsiElementsOfType

class PyFileClasses(
Expand All @@ -14,9 +15,15 @@ class PyFileClasses(
pyClasses = getFilePsiElementsOfType<PyClass>(projectDirectory, pyFileName)
}

override fun getClassesNames(): List<String>? = pyClasses?.mapNotNull { it.name }
override fun getClassesNames(): List<String> {
if (pyClasses == null) error(UNCALLED_EXECUTE_BEFORE_RESULT_GETTING)
return pyClasses!!.mapNotNull { it.name }
}

override fun getClassCode(className: String): String? = pyClasses
?.firstOrNull { it.name == className }
?.text
override fun getClassCode(className: String): String? {
if (pyClasses == null) error(UNCALLED_EXECUTE_BEFORE_RESULT_GETTING)
return pyClasses!!
.firstOrNull { it.name == className }
?.text
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ package org.jetbrains.research.ideFormerPlugin.api.models.fileRelated.fileFuncti
import org.jetbrains.research.ideFormerPlugin.api.models.IdeApiMethod

interface FileFunctions : IdeApiMethod {
fun getFunctionsNames(): List<String>?
fun getFunctionsNames(): List<String>
fun getFunctionCode(functionName: String): String?
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package org.jetbrains.research.ideFormerPlugin.api.models.fileRelated.fileFuncti

import com.intellij.psi.PsiDirectory
import com.intellij.psi.PsiMethod
import org.jetbrains.research.ideFormerPlugin.api.models.utils.UNCALLED_EXECUTE_BEFORE_RESULT_GETTING
import org.jetbrains.research.ideFormerPlugin.api.models.utils.getFilePsiElementsOfType

class JavaFileFunctions(
Expand All @@ -14,8 +15,15 @@ class JavaFileFunctions(
javaFunctions = getFilePsiElementsOfType<PsiMethod>(projectDirectory, javaFileName)
}

override fun getFunctionsNames(): List<String>? = javaFunctions?.map { it.name }
override fun getFunctionCode(functionName: String): String? = javaFunctions
?.firstOrNull { it.name == functionName }
?.text
override fun getFunctionsNames(): List<String> {
if (javaFunctions == null) error(UNCALLED_EXECUTE_BEFORE_RESULT_GETTING)
return javaFunctions!!.map { it.name }
}

override fun getFunctionCode(functionName: String): String? {
if (javaFunctions == null) error(UNCALLED_EXECUTE_BEFORE_RESULT_GETTING)
return javaFunctions!!
.firstOrNull { it.name == functionName }
?.text
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package org.jetbrains.research.ideFormerPlugin.api.models.fileRelated.fileFuncti

import com.intellij.psi.PsiDirectory
import org.jetbrains.kotlin.psi.KtFunction
import org.jetbrains.research.ideFormerPlugin.api.models.utils.UNCALLED_EXECUTE_BEFORE_RESULT_GETTING
import org.jetbrains.research.ideFormerPlugin.api.models.utils.getFilePsiElementsOfType

class KtFileFunctions(
Expand All @@ -14,8 +15,15 @@ class KtFileFunctions(
ktFunctions = getFilePsiElementsOfType<KtFunction>(projectDirectory, ktFileName)
}

override fun getFunctionsNames(): List<String>? = ktFunctions?.mapNotNull { it.name }
override fun getFunctionCode(functionName: String): String? = ktFunctions
?.firstOrNull { it.name == functionName }
?.text
override fun getFunctionsNames(): List<String> {
if (ktFunctions == null) error(UNCALLED_EXECUTE_BEFORE_RESULT_GETTING)
return ktFunctions!!.mapNotNull { it.name }
}

override fun getFunctionCode(functionName: String): String? {
if (ktFunctions == null) error(UNCALLED_EXECUTE_BEFORE_RESULT_GETTING)
return ktFunctions!!
.firstOrNull { it.name == functionName }
?.text
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package org.jetbrains.research.ideFormerPlugin.api.models.fileRelated.fileFuncti

import com.intellij.psi.PsiDirectory
import com.jetbrains.python.psi.PyFunction
import org.jetbrains.research.ideFormerPlugin.api.models.utils.UNCALLED_EXECUTE_BEFORE_RESULT_GETTING
import org.jetbrains.research.ideFormerPlugin.api.models.utils.getFilePsiElementsOfType

class PyFileFunctions(
Expand All @@ -14,8 +15,15 @@ class PyFileFunctions(
pyFunctions = getFilePsiElementsOfType<PyFunction>(projectDirectory, pyFileName)
}

override fun getFunctionsNames(): List<String>? = pyFunctions?.mapNotNull { it.name }
override fun getFunctionCode(functionName: String): String? = pyFunctions
?.firstOrNull { it.name == functionName }
?.text
override fun getFunctionsNames(): List<String> {
if (pyFunctions == null) error(UNCALLED_EXECUTE_BEFORE_RESULT_GETTING)
return pyFunctions!!.mapNotNull { it.name }
}

override fun getFunctionCode(functionName: String): String? {
if (pyFunctions == null) error(UNCALLED_EXECUTE_BEFORE_RESULT_GETTING)
return pyFunctions!!
.firstOrNull { it.name == functionName }
?.text
}
}
Original file line number Diff line number Diff line change
@@ -1,19 +1,23 @@
package org.jetbrains.research.ideFormerPlugin.api.models.fileRelated
package org.jetbrains.research.ideFormerPlugin.api.models.fileRelated.fileText

import com.intellij.psi.PsiDirectory
import org.jetbrains.research.ideFormerPlugin.api.models.IdeApiMethod
import org.jetbrains.research.ideFormerPlugin.api.models.utils.findFileRecursively
import org.jetbrains.research.ideFormerPlugin.api.models.utils.*

class FileText(
class GetFileText(
private val projectDirectory: PsiDirectory,
private val fileName: String
) : IdeApiMethod {
private var fileText: String? = null

override fun execute() {
projectDirectory.refresh()
val psiFile = projectDirectory.findFileRecursively(fileName)
fileText = psiFile.text
}

fun getFileText(): String? = fileText
fun getFileText(): String {
if (fileText == null) error(UNCALLED_EXECUTE_BEFORE_RESULT_GETTING)
return fileText!!
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package org.jetbrains.research.ideFormerPlugin.api.models.fileRelated.fileText

import com.intellij.psi.PsiDirectory
import org.jetbrains.research.ideFormerPlugin.api.models.ReversibleApiMethod
import org.jetbrains.research.ideFormerPlugin.api.models.utils.*

class SetFileText(
private val projectDirectory: PsiDirectory,
private val fileName: String,
private val newText: String
) : ReversibleApiMethod {
private var previousText: String? = null

override fun execute() {
projectDirectory.refresh()
val psiFile = projectDirectory.findFileRecursively(fileName)
previousText = psiFile.text
psiFile.setText(newText)
}

override fun reverse() {
if (previousText == null) error(UNCALLED_EXECUTE_BEFORE_RESULT_GETTING)

previousText!!.let {
val psiFile = projectDirectory.findFileRecursively(fileName)
psiFile.setText(it)
previousText = null
}
}
}
Original file line number Diff line number Diff line change
@@ -1,28 +1,32 @@
package org.jetbrains.research.ideFormerPlugin.api.models.fileSystemRelated

import com.intellij.psi.PsiDirectory
import org.jetbrains.research.ideFormerPlugin.api.models.utils.DEFAULT_DIRECTORY_NAME
import org.jetbrains.research.ideFormerPlugin.api.models.utils.findSubdirectoryRecursively
import org.jetbrains.research.ideFormerPlugin.api.models.ReversibleApiMethod
import org.jetbrains.research.ideFormerPlugin.api.models.utils.*
import org.jetbrains.research.ideFormerPlugin.stateKeeper.IdeStateKeeper

class ChangeDirectory(
private val ideStateKeeper: IdeStateKeeper,
private val targetDirectoryName: String = DEFAULT_DIRECTORY_NAME
) : ReversibleApiMethod {
private var prevDir: PsiDirectory? = null
private var previousDirectory: PsiDirectory? = null

override fun execute() {
val targetDir = ideStateKeeper.currentProjectDirectory.findSubdirectoryRecursively(targetDirectoryName)
val currentProjectDirectory = ideStateKeeper.currentProjectDirectory
currentProjectDirectory.refresh()

prevDir = ideStateKeeper.currentProjectDirectory
val targetDir = currentProjectDirectory.findDirectoryRecursively(targetDirectoryName)

previousDirectory = currentProjectDirectory
ideStateKeeper.currentProjectDirectory = targetDir
}

override fun reverse() {
prevDir?.let {
if (previousDirectory == null) error(UNCALLED_EXECUTE_BEFORE_RESULT_GETTING)

previousDirectory!!.let {
ideStateKeeper.currentProjectDirectory = it
prevDir = null
previousDirectory = null
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package org.jetbrains.research.ideFormerPlugin.api.models.fileSystemRelated

import com.intellij.psi.PsiDirectory
import org.jetbrains.research.ideFormerPlugin.api.models.ReversibleApiMethod
import org.jetbrains.research.ideFormerPlugin.api.models.utils.createSubdirectoryByName
import org.jetbrains.research.ideFormerPlugin.api.models.utils.deleteSubdirectoryByName

class CreateDirectory(
private val projectDirectory: PsiDirectory,
private val directoryName: String
) : ReversibleApiMethod {

override fun execute() {
projectDirectory.createSubdirectoryByName(directoryName)
}

override fun reverse() {
projectDirectory.deleteSubdirectoryByName(directoryName)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package org.jetbrains.research.ideFormerPlugin.api.models.fileSystemRelated

import com.intellij.psi.PsiDirectory
import org.jetbrains.research.ideFormerPlugin.api.models.ReversibleApiMethod
import org.jetbrains.research.ideFormerPlugin.api.models.utils.*

class CreateFile(
private val projectDirectory: PsiDirectory,
private val fileName: String
) : ReversibleApiMethod {

override fun execute() {
projectDirectory.refresh()
projectDirectory.createFileByName(fileName)
}

override fun reverse() {
projectDirectory.refresh()
projectDirectory.deleteFileByName(fileName)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package org.jetbrains.research.ideFormerPlugin.api.models.fileSystemRelated

import com.intellij.psi.PsiDirectory
import org.jetbrains.research.ideFormerPlugin.api.models.ReversibleApiMethod
import org.jetbrains.research.ideFormerPlugin.api.models.utils.*

class DeleteFile(
private val projectDirectory: PsiDirectory,
private val fileName: String
) : ReversibleApiMethod {
private var deletedFileText: String? = projectDirectory.findFileRecursively(fileName).text

override fun execute() {
projectDirectory.refresh()
// TODO: getting deleting file text should be here. when execute() is called it may be different
projectDirectory.deleteFileByName(fileName)
}

override fun reverse() {
projectDirectory.refresh()
val psiFile = projectDirectory.createFileByName(fileName)

deletedFileText!!.let {
psiFile.setText(it)
deletedFileText = null
}
}
}
Loading
Loading