generated from jetbrains-academy/kotlin-course-template
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add theory to PSI access and edit lessons
- Loading branch information
1 parent
03ad6ac
commit 047b1f0
Showing
8 changed files
with
63 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
id: 1521434296 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
id: 2136442658 |
3 changes: 1 addition & 2 deletions
3
...ion/accessingPsiElementsLesson/accessingPsiElementsClassProgrammingTask/task.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
...ElementsTheoryTask/src/main/kotlin/org/jetbrains/academy/plugin/course/dev/access/Task.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
package org.jetbrains.academy.plugin.course.dev.access | ||
|
||
fun main() { | ||
TODO() | ||
} |
23 changes: 22 additions & 1 deletion
23
psiSection/editingPsiElementsLesson/editingPsiElementsTheoryTask/task.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,22 @@ | ||
TODO | ||
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 | ||
} | ||
``` |
28 changes: 27 additions & 1 deletion
28
psiSection/editingPsiElementsLesson/renameFunctionProgrammingTask/task.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,27 @@ | ||
TODO | ||
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<Int>) {...} | ||
``` | ||
|
||
**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<Int>) {...} | ||
``` | ||
but after | ||
```Kotlin | ||
fun sortValues(values: List<Int>) {...} | ||
``` | ||
|
||
<div class="hint" title="How to get project for WriteActionCommand?"> | ||
|
||
Every PSI element has link to project, just try `psiElement.project` | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 9 additions & 1 deletion
10
psiSection/editingPsiElementsLesson/sortMethodsProgrammingTask/task.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,9 @@ | ||
TODO | ||
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. | ||
|
||
|
||
<div class="hint" title="Where to start?"> | ||
|
||
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. | ||
</div> |