diff --git a/common/src/main/resources/images/internal-mode-doc.gif b/common/src/main/resources/images/internal-mode-doc.gif new file mode 100644 index 0000000..8c56b0d Binary files /dev/null and b/common/src/main/resources/images/internal-mode-doc.gif differ diff --git a/common/src/main/resources/images/internal-mode-ide.gif b/common/src/main/resources/images/internal-mode-ide.gif new file mode 100644 index 0000000..731ef42 Binary files /dev/null and b/common/src/main/resources/images/internal-mode-ide.gif differ diff --git a/common/src/main/resources/images/psi-viewer-doc.gif b/common/src/main/resources/images/psi-viewer-doc.gif new file mode 100644 index 0000000..f638542 Binary files /dev/null and b/common/src/main/resources/images/psi-viewer-doc.gif differ diff --git a/common/src/main/resources/images/psi-viewer-ide.gif b/common/src/main/resources/images/psi-viewer-ide.gif new file mode 100644 index 0000000..edc82c9 Binary files /dev/null and b/common/src/main/resources/images/psi-viewer-ide.gif differ diff --git a/gradle.properties b/gradle.properties index 9728aac..d0ea9c0 100644 --- a/gradle.properties +++ b/gradle.properties @@ -4,4 +4,5 @@ courseVersion=1.1.0 gradleVersion=8.3 jvmVersion=17 -kotlin.code.style=official \ No newline at end of file +kotlin.code.style=official +org.gradle.jvmargs=-Xmx2048m \ No newline at end of file diff --git a/introductionSection/section-info.yaml b/introductionSection/section-info.yaml index 1b17de6..cfc71a4 100644 --- a/introductionSection/section-info.yaml +++ b/introductionSection/section-info.yaml @@ -1,3 +1,4 @@ custom_name: Introduction content: - - welcomeLesson \ No newline at end of file + - welcomeLesson + - setupLesson \ No newline at end of file diff --git a/introductionSection/section-remote-info.yaml b/introductionSection/section-remote-info.yaml index 0d98257..ca9026b 100644 --- a/introductionSection/section-remote-info.yaml +++ b/introductionSection/section-remote-info.yaml @@ -1 +1 @@ -id: 720914665 +id: 1117582364 diff --git a/introductionSection/setupLesson/internalModeSetupTask/src/main/kotlin/org/jetbrains/academy/plugin/course/dev/setup/Main.kt b/introductionSection/setupLesson/internalModeSetupTask/src/main/kotlin/org/jetbrains/academy/plugin/course/dev/setup/Main.kt new file mode 100644 index 0000000..47986e0 --- /dev/null +++ b/introductionSection/setupLesson/internalModeSetupTask/src/main/kotlin/org/jetbrains/academy/plugin/course/dev/setup/Main.kt @@ -0,0 +1,5 @@ +package org.jetbrains.academy.plugin.course.dev.setup + +fun main() { + print("Time to setup!") +} diff --git a/introductionSection/setupLesson/internalModeSetupTask/task-info.yaml b/introductionSection/setupLesson/internalModeSetupTask/task-info.yaml new file mode 100644 index 0000000..2b51101 --- /dev/null +++ b/introductionSection/setupLesson/internalModeSetupTask/task-info.yaml @@ -0,0 +1,5 @@ +type: theory +custom_name: Enable Internal Mode +files: + - name: src/main/kotlin/org/jetbrains/academy/plugin/course/dev/setup/Main.kt + visible: true diff --git a/introductionSection/setupLesson/internalModeSetupTask/task-remote-info.yaml b/introductionSection/setupLesson/internalModeSetupTask/task-remote-info.yaml new file mode 100644 index 0000000..3cac54a --- /dev/null +++ b/introductionSection/setupLesson/internalModeSetupTask/task-remote-info.yaml @@ -0,0 +1 @@ +id: 987794995 diff --git a/introductionSection/setupLesson/internalModeSetupTask/task.md b/introductionSection/setupLesson/internalModeSetupTask/task.md new file mode 100644 index 0000000..56ab90d --- /dev/null +++ b/introductionSection/setupLesson/internalModeSetupTask/task.md @@ -0,0 +1,12 @@ +To have access to some internal actions you need to enable `Internal Mode`. +Please, follow steps in internal mode instruction configuration [by this link](https://plugins.jetbrains.com/docs/intellij/enabling-internal.html) and enable it in your IDE. + +![Internal mode documentation](./../../../common/src/main/resources/images/internal-mode-doc.gif) + +**Do not forget to restart you IDE after changing idea.properties file!!!** + +Also, following gif will show you how Helena done this in her IDE. + +![Internal mode documentation](./../../../common/src/main/resources/images/internal-mode-ide.gif) + + diff --git a/introductionSection/setupLesson/lesson-info.yaml b/introductionSection/setupLesson/lesson-info.yaml new file mode 100644 index 0000000..adc511d --- /dev/null +++ b/introductionSection/setupLesson/lesson-info.yaml @@ -0,0 +1,3 @@ +custom_name: Setup before you start +content: + - internalModeSetupTask diff --git a/introductionSection/setupLesson/lesson-remote-info.yaml b/introductionSection/setupLesson/lesson-remote-info.yaml new file mode 100644 index 0000000..55911ce --- /dev/null +++ b/introductionSection/setupLesson/lesson-remote-info.yaml @@ -0,0 +1 @@ +id: 1262323620 diff --git a/introductionSection/welcomeLesson/helloHelenaTask/task-remote-info.yaml b/introductionSection/welcomeLesson/helloHelenaTask/task-remote-info.yaml index eab95a3..7dc273e 100644 --- a/introductionSection/welcomeLesson/helloHelenaTask/task-remote-info.yaml +++ b/introductionSection/welcomeLesson/helloHelenaTask/task-remote-info.yaml @@ -1 +1 @@ -id: 963422420 +id: 788265721 diff --git a/introductionSection/welcomeLesson/helpJonsiTask/task-remote-info.yaml b/introductionSection/welcomeLesson/helpJonsiTask/task-remote-info.yaml index fd3c643..c664385 100644 --- a/introductionSection/welcomeLesson/helpJonsiTask/task-remote-info.yaml +++ b/introductionSection/welcomeLesson/helpJonsiTask/task-remote-info.yaml @@ -1 +1 @@ -id: 1111659873 +id: 156535081 diff --git a/introductionSection/welcomeLesson/lesson-info.yaml b/introductionSection/welcomeLesson/lesson-info.yaml index bb9b410..b143729 100644 --- a/introductionSection/welcomeLesson/lesson-info.yaml +++ b/introductionSection/welcomeLesson/lesson-info.yaml @@ -1,4 +1,4 @@ -custom_name: Introduction to PSI +custom_name: Welcome and good luck! content: - helloHelenaTask - helpJonsiTask diff --git a/introductionSection/welcomeLesson/lesson-remote-info.yaml b/introductionSection/welcomeLesson/lesson-remote-info.yaml index 0664c1f..e2927af 100644 --- a/introductionSection/welcomeLesson/lesson-remote-info.yaml +++ b/introductionSection/welcomeLesson/lesson-remote-info.yaml @@ -1 +1 @@ -id: 272542520 +id: 536458692 diff --git a/psiSection/accessingPsiElementsLesson/accessingPsiElementsProgrammingTask/task.md b/psiSection/accessingPsiElementsLesson/accessingPsiElementsProgrammingTask/task.md index 4ef7908..77a0f67 100644 --- a/psiSection/accessingPsiElementsLesson/accessingPsiElementsProgrammingTask/task.md +++ b/psiSection/accessingPsiElementsLesson/accessingPsiElementsProgrammingTask/task.md @@ -1,9 +1,8 @@ - -You need to implement a function `countKtClasses` which will -count number of kotlin classes declared in the given kotlin PSI file. +Using your newly gained knowledge about `PsiTreeUtil.findChildrenOfType` method, implement functions `countKtClasses` and `countKtFunctions` which will +count number of kotlin classes of functions relatively declared in the given kotlin PSI file.
-Try to use `KtClass::class.java` value for aClass parameter for `findChildrenOfType` +Try to use `KtClass::class.java` for classes and `KtNamedFunction::class.java` for functions value for aClass parameter for `findChildrenOfType`
diff --git a/psiSection/editingPsiElementsLesson/editingPsiElementsTheoryTask/task.md b/psiSection/editingPsiElementsLesson/editingPsiElementsTheoryTask/task.md index 30404ce..b34e115 100644 --- a/psiSection/editingPsiElementsLesson/editingPsiElementsTheoryTask/task.md +++ b/psiSection/editingPsiElementsLesson/editingPsiElementsTheoryTask/task.md @@ -1 +1,22 @@ -TODO \ No newline at end of file +All operations with code like adding, deleting or moving methods, renaming variable, you name it, are implemented as PSI editions. +Please skim the [Modify the PSI](https://plugins.jetbrains.com/docs/intellij/modifying-psi.html) documentation. + +Methods to edit PSI Element: +* [`PsiElement.add()`](https://github.com/JetBrains/intellij-community/blob/19d9a1cc2d9c14df9c3bdee391e9e4795ac25cb9/platform/core-api/src/com/intellij/psi/PsiElement.java#L302) - to add a child to PSI Element into tree. To specify the place in children list use [`PsiElement.addBefore()`](https://github.com/JetBrains/intellij-community/blob/19d9a1cc2d9c14df9c3bdee391e9e4795ac25cb9/platform/core-api/src/com/intellij/psi/PsiElement.java#L312C14-L312C23) and [`PsiElement.addAfter()`](https://github.com/JetBrains/intellij-community/blob/19d9a1cc2d9c14df9c3bdee391e9e4795ac25cb9/platform/core-api/src/com/intellij/psi/PsiElement.java#L322) +* [`PsiElement.delete()`](https://github.com/JetBrains/intellij-community/blob/19d9a1cc2d9c14df9c3bdee391e9e4795ac25cb9/platform/core-api/src/com/intellij/psi/PsiElement.java#L373) - to delete PSI Element from tree +* [`PsiElement.replace()`](https://github.com/JetBrains/intellij-community/blob/19d9a1cc2d9c14df9c3bdee391e9e4795ac25cb9/platform/core-api/src/com/intellij/psi/PsiElement.java#L402) - to replace PSI Element in tree + +Also, you create PSI Elements by using: +* [`PsiElement.copy()`](https://github.com/JetBrains/intellij-community/blob/19d9a1cc2d9c14df9c3bdee391e9e4795ac25cb9/platform/core-api/src/com/intellij/psi/PsiElement.java#L293) - to copy PSI Element subtree + +Moreover, there are some PisElement-specific methods like [`KtNamedFunction.setName()`](https://github.com/JetBrains/intellij-community/blob/bf3083ca66771e038eb1c64128b4e508f52acfad/platform/core-api/src/com/intellij/psi/PsiNamedElement.java#L39) as well as all `PsiNamedElement` inheritors. + +**IMPORTANT!** + +Every PSI modifications need to be wrapped in a [write action and in command](https://github.com/JetBrains/intellij-community/blob/master/platform/core-api/src/com/intellij/openapi/command/WriteCommandAction.java) + +```kotlin +WriteCommandAction.runWriteCommandAction(project) { + // Here you can modify PSI Elements +} +``` diff --git a/psiSection/editingPsiElementsLesson/renameFunctionProgrammingTask/task.md b/psiSection/editingPsiElementsLesson/renameFunctionProgrammingTask/task.md index 30404ce..11dca22 100644 --- a/psiSection/editingPsiElementsLesson/renameFunctionProgrammingTask/task.md +++ b/psiSection/editingPsiElementsLesson/renameFunctionProgrammingTask/task.md @@ -1 +1,27 @@ -TODO \ No newline at end of file +Sometimes, switching between Python and Kotlin leeds to following code style mistake: + +Python developers usually use `snake_case` for methods naming like +```python +def sort_values(values): +``` +While in Kotlin or Java `camelCase` is commonly used +```Kotlin +fun sortValues(values: List) {...} +``` + +**Your task will be** to help such multi-language programmers and +implement method which renames `snake_case` named method to `camelCase`. + +So before your method invocation method looked like: +```Kotlin +fun sort_values(values: List) {...} +``` +but after +```Kotlin +fun sortValues(values: List) {...} +``` + +
+ +Every PSI element has link to project, just try `psiElement.project` +
diff --git a/psiSection/editingPsiElementsLesson/sortMethodsProgrammingTask/task.md b/psiSection/editingPsiElementsLesson/sortMethodsProgrammingTask/task.md index 30404ce..fd006d8 100644 --- a/psiSection/editingPsiElementsLesson/sortMethodsProgrammingTask/task.md +++ b/psiSection/editingPsiElementsLesson/sortMethodsProgrammingTask/task.md @@ -1 +1,9 @@ -TODO \ No newline at end of file +Sometimes, you want to make you code more searchable and sort methods by the alphabetical order. +Now you can do it automatically, just several lines of code! +Implement method which takes PSI class and orders all inner methods in alphabetical order. + + +
+ +Get list of class methods, **copy** them and sort list of copies by name. Then use **replace** original methods one by one with copy which should stand in this position in sorted order. +
\ No newline at end of file diff --git a/psiSection/introductionToPsiLesson/IntroToPsiLesson/task.md b/psiSection/introductionToPsiLesson/IntroToPsiLesson/task.md index c6210a7..f11de8c 100644 --- a/psiSection/introductionToPsiLesson/IntroToPsiLesson/task.md +++ b/psiSection/introductionToPsiLesson/IntroToPsiLesson/task.md @@ -1,24 +1,24 @@ -PSI stands for Program Structure Interface. It's a part of IntelliJ Platform SDK, please have a brief look into +PSI stands for Program Structure Interface. It's a part of IntelliJ Platform SDK, please have a brief look into [PSI Documentation](https://plugins.jetbrains.com/docs/intellij/psi.html) on IntelliJ Platform SDK Documentation web page. -As you probably read there, PSI represents the entire structure of the code in a project as a tree of elements, +As you probably read there, PSI represents the entire structure of the code in a project as a tree of elements, called a PSI tree. ### PSI Tree Structure -* The root is a [`PSI File`](https://plugins.jetbrains.com/docs/intellij/psi-files.html) element, representing an entire file. -* Each node or [`PSI Element`](https://plugins.jetbrains.com/docs/intellij/psi-elements.html) in the tree represents a syntactic or structural part of the code, like expressions, -* statements, and declarations. +* The root is a [`PSI File`](https://plugins.jetbrains.com/docs/intellij/psi-files.html) element, representing an entire file +* Each node or [`PSI Element`](https://plugins.jetbrains.com/docs/intellij/psi-elements.html) in the tree represents a syntactic or structural part of the code, like expressions, + statements, and declarations ### Types of PSI Elements -* PsiFile: Represents an entire file. -* PsiClass: Represents a class in the code. -* PsiMethod: Represents a method. -* PsiVariable: Represents a variable. -* PsiExpression: Represents an expression, and so on. +* PsiFile: Represents an entire file +* PsiClass: Represents a class in the code +* PsiMethod: Represents a method +* PsiVariable: Represents a variable +* PsiExpression: Represents an expression, and so on -Each language (Java/Kotlin/Python) has their own implementations of [`PsiElement`](https://github.com/JetBrains/intellij-community/blob/master/platform/core-api/src/com/intellij/psi/PsiElement.java), +Each language (Java, Kotlin, Python, etc.) has their own implementations of [`PsiElement`](https://github.com/JetBrains/intellij-community/blob/master/platform/core-api/src/com/intellij/psi/PsiElement.java), so for example for file abstraction there are following options: -* [`com.intellij.psi.PsiFile`](https://github.com/JetBrains/intellij-community/blob/idea/232.10227.8/platform/core-api/src/com/intellij/psi/PsiFile.java): Represents an Java file. -* [`org.jetbrains.kotlin.psi.KtFile`](https://github.com/JetBrains/kotlin/blob/master/compiler/psi/src/org/jetbrains/kotlin/psi/KtFile.kt): Represents a Kotlin file. -* [`com.jetbrains.python.psi.PyFile`](https://github.com/JetBrains/intellij-community/blob/master/python/python-psi-api/src/com/jetbrains/python/psi/PyFile.java#L28): Represents a Python file. +* [`com.intellij.psi.PsiFile`](https://github.com/JetBrains/intellij-community/blob/idea/232.10227.8/platform/core-api/src/com/intellij/psi/PsiFile.java): Represents an Java file +* [`org.jetbrains.kotlin.psi.KtFile`](https://github.com/JetBrains/kotlin/blob/master/compiler/psi/src/org/jetbrains/kotlin/psi/KtFile.kt): Represents a Kotlin file +* [`com.jetbrains.python.psi.PyFile`](https://github.com/JetBrains/intellij-community/blob/master/python/python-psi-api/src/com/jetbrains/python/psi/PyFile.java#L28): Represents a Python file diff --git a/psiSection/introductionToPsiLesson/TryPsiViewerLesson/task.md b/psiSection/introductionToPsiLesson/TryPsiViewerLesson/task.md index 5d12284..2da7238 100644 --- a/psiSection/introductionToPsiLesson/TryPsiViewerLesson/task.md +++ b/psiSection/introductionToPsiLesson/TryPsiViewerLesson/task.md @@ -1,6 +1,8 @@ Follow a `useful tools` link in [PSI Documentation main page](https://plugins.jetbrains.com/docs/intellij/psi.html) and find an action which provides an ability to see and analyze PSI tree of opened file. +![View PSI documentation](./../../../common/src/main/resources/images/psi-viewer-doc.gif) + Now, I’d want you, **Jonsi**, to look at to PSI tree of `Person.kt` file and select PSI elements presented in it? @@ -8,4 +10,6 @@ and select PSI elements presented in it? Use `Tools | View PSI Structure of Current File...` action to access PSI tree +![View PSI in IDE](./../../../common/src/main/resources/images/psi-viewer-ide.gif) + \ No newline at end of file