Skip to content

Commit

Permalink
Merge pull request #23 from jetbrains-academy/stephen-hero-patch-1
Browse files Browse the repository at this point in the history
Update task.md
  • Loading branch information
Geravant authored Aug 5, 2024
2 parents ba98048 + 67f7749 commit f326849
Show file tree
Hide file tree
Showing 20 changed files with 104 additions and 104 deletions.
24 changes: 12 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
[![Gradle Build With Detekt](https://github.com/jetbrains-academy/kotlin-course-template/actions/workflows/gradle-build-with-detekt.yml/badge.svg)](https://github.com/jetbrains-academy/kotlin-course-template/actions/workflows/gradle-build-with-detekt.yml)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)

This course is designed for novices in plugin development for JetBrains IDEs. It covers the basics of plugin development and provides a hands-on experience in working with PSI (Program Structure Interface) elements.
The main goal of the course is not to rewrite the existing documentation, but rather to cover popular topics and provide links to the official documentation, so that the students can get used to reading the documentation and searching for the necessary information.
This course is designed for novices in plugin development for JetBrains IDEs. It covers the basics of plugin development and provides hands-on experience in working with PSI (Program Structure Interface) elements.
The main goal of the course is not to rewrite the existing documentation but rather to cover popular topics and provide links to the official documentation so that students can get used to reading the documentation and searching for necessary information.

Each lesson of the course consist of a theoretical task and a few programming tasks. The theoretical tasks are designed to help you understand the topic, while the programming tasks aim to apply the acquired knowledge.
At the end of each chapter, an additional final project will be offered. It includes all the topics of the lesson but does not contain theory part. It is divided into multiple tasks, and by completing them step by step, you will get a finished small project in the end.
Each lesson of the course consists of a theoretical task and a few programming tasks. The theoretical tasks are designed to help you understand the topic, while the programming tasks aim to apply the acquired knowledge.
At the end of each chapter, an additional final project will be offered. It includes all the topics of the lesson but does not contain a theory part. It is divided into multiple tasks, and by completing them step by step, you will get a finished small project in the end.

Topics covered:
* Accessing PSI elements
Expand All @@ -18,14 +18,14 @@ Topics covered:

## Technical requirements

Before starting this course, check the following requirements.
Before starting this course, please check the following requirements:

1. Your computer needs to have a stable internet connection.
2. Git version control system needs to be installed on your computer (link to the git site: https://git-scm.com/).
3. Make sure that the path to the root folder of the course does not contain spaces, special characters, or non-Latin characters.
4. Make sure that you use the [Intellij IDEA](https://www.jetbrains.com/idea/download/?_ga=2.189310830.494255415.1682514714-1823138827.1669894241&_gac=1.83806948.1682684894.Cj0KCQjw3a2iBhCFARIsAD4jQB3QkDU43KtbIx2HzEz02KvcN7Ma3QGzkIbyX4KS3H4x8b2bl9p4EfYaAvWsEALw_wcB&_gl=1*1h13lr8*_ga*MTgyMzEzODgyNy4xNjY5ODk0MjQx*_ga_9J976DJZ68*MTY4MjY5NDIyMy4xMjUuMS4xNjgyNjk0MjM4LjQ1LjAuMA..#section=windows) with version at least `2023.1.1`.
5. Make sure that you use the [JetBrains Academy](https://plugins.jetbrains.com/plugin/10081-jetbrains-academy) plugin with version at least `2023.1`.
1. Ensure that your computer has a stable internet connection.
2. Install the Git version control system on your computer (link to the Git site: https://git-scm.com/).
3. Ensure that the path to the root folder of the course does not contain spaces, special characters, or non-Latin characters.
4. Make sure you are using [IntelliJ IDEA](https://www.jetbrains.com/idea/download/?_ga=2.189310830.494255415.1682514714-1823138827.1669894241&_gac=1.83806948.1682684894.Cj0KCQjw3a2iBhCFARIsAD4jQB3QkDU43KtbIx2HzEz02KvcN7Ma3QGzkIbyX4KS3H4x8b2bl9p4EfYaAvWsEALw_wcB&_gl=1*1h13lr8*_ga*MTgyMzEzODgyNy4xNjY5ODk0MjQx*_ga_9J976DJZ68*MTY4MjY5NDIyMy4xMjUuMS4xNjgyNjk0MjM4LjQ1LjAuMA..#section=windows) with a version of at least `2023.1.1`.
5. Ensure that you are using the [JetBrains Academy](https://plugins.jetbrains.com/plugin/10081-jetbrains-academy) plugin with a version of at least `2023.1`.

The course is integrated into the [Intellij Idea IDE](https://www.jetbrains.com/idea/), which has a free Community license.
The course is integrated into the [IntelliJ IDEA IDE](https://www.jetbrains.com/idea/), which has a free Community license.
You can use this license to complete the course.
If you have some troubles with the course installation, feel free to contact us by email at [email protected].
If you encounter any issues with the course installation, feel free to contact us by email at [email protected].
8 changes: 4 additions & 4 deletions introductionSection/setupLesson/internalModeSetupTask/task.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# Setup

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.
To access some internal actions, you need to enable `Internal Mode`.
Please follow the steps in the internal mode instruction configuration [at this link](https://plugins.jetbrains.com/docs/intellij/enabling-internal.html) and enable it in your IDE.

**Do not forget to restart you IDE after changing idea.properties file!!!**
**Do not forget to restart you IDE after changing the idea.properties file!!!**

Also, following gif will show you how Helena done this in her IDE.
Also, the following GIF will show you how Helena did this in her IDE.


8 changes: 4 additions & 4 deletions introductionSection/welcomeLesson/helloHelenaTask/task.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Say hello to Helena! Add implementation to method `helloHelena` method which should return “Hello, Helena!” given number of times, separated by new line.
Say hello to Helena! Add an implementation to the `helloHelena` method, which should return “Hello, Helena!” a given number of times. Each greeting should be separated by a newline.

<div class="hint" title="How to get platform-specific new line symbol?">
<div class="hint" title="How to get a platform-specific newline symbol?">

Use `System.lineSeparator()` to get platform-specific new line symbol
</div>
Use `System.lineSeparator()` to get a platform-specific newline symbol.
</div>
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
Hi! My name is Helena. I’m working in the Plugin Development Team. We have just hired a new young developer, Jonsi, so I’ve prepared lots of amazing projects for him to do.
Hi! My name is Helena. I’m working in the Plugin Development Team. We have just hired a new young developer, Jonsi, so I’ve prepared lots of amazing projects for him to tackle.

But wait, he has never worked with IntelliJ Platform before?! So well, I’ll try to teach him all important things during one week of his probation.
But wait, he has never worked with the IntelliJ Platform before?! Well, I’ll try to teach him all the important things during the one week of his probation.
4 changes: 2 additions & 2 deletions introductionSection/welcomeLesson/helpJonsiTask/task.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Hi! My name is Jonsi! It’s my first day at JetBrains, and I’m ready to start! But I’m really nervous of my probation week as I have no idea, how IDE works behind and what is more, how to write plugins for it.
Hi! My name is Jonsi! It’s my first day at JetBrains, and I’m ready to get started! But I’m really nervous about my probation week, since I have no idea how an IDE works behind the scenes, and what's more, I don't know how to write plugins for it.

So I really need someone's help!!!
So, I really need someone's help!!!

Maybe you can help me?
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
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.
Using your newly gained knowledge about the `PsiTreeUtil.findChildrenOfType` method, implement the functions `countKtClasses` and `countKtFunctions`. These functions will
count the number of Kotlin classes and functions, respectively, declared in the given Kotlin PSI file.

<div class="hint" title="Which class should I use as aClass parameter?">
<div class="hint" title="Which class should I use as the aClass parameter?">

Try to use `KtClass::class.java` for classes and `KtNamedFunction::class.java` for functions value for aClass parameter for `findChildrenOfType`
Try using `KtClass::class.java` for classes and `KtNamedFunction::class.java` for functions as the aClass parameter values for `findChildrenOfType`.
</div>

**Run Plugin**

To see your implemented methods in action within a UI, run the following command in your project's root directory:
To see your implemented methods in action within the UI, run the following command in your project's root directory:

* ` ./gradlew :psiSection-accessingPsiElementsLesson-task:runIde
` on Linux or MacOS
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
is a utility class in the IntelliJ Platform SDK that provides methods for navigating and querying the PSI tree of a project.

The [com.intellij.psi.util.PsiTreeUtil.findChildrenOfType](https://github.com/JetBrains/intellij-community/blob/30cfa651ac2b9c50163368b56ee87ce1944543ec/platform/core-api/src/com/intellij/psi/util/PsiTreeUtil.java#L197C64-L197C64) method is used to find all children of a specified type within a given PSI element.
It's particularly useful when you need to locate all instances of a particular element type, such as classes, methods, or variables, within a file or a code block.
It's particularly useful when you need to locate all instances of a specified element type, such as classes, methods, or variables, within a file or a code block.

**Syntax:**
```java
Expand All @@ -11,4 +11,4 @@ public static @Unmodifiable @NotNull <T extends PsiElement> Collection<T> findCh

**Parameters:**
* **element**: The PSI element within which to search for children. This could be a PsiFile, a PsiClass, or any other PSI element.
* **aClass**: The class type of the elements you are searching for. For example, PsiClass.class to find all classes.
* **aClass**: The class type of the elements you are searching for. For example, if you're looking for all classes, you would use PsiClass.class.
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ They are a form of syntactic metadata that can be added to the code but do not d

The `@Deprecated` annotation marks a program element as deprecated, indicating that the element should no longer be used.

**Task**
**Task**:
Implement the function
```kotlin
fun addDeprecatedAnnotations(psiFile: PsiFile)
```

This function should iterate over all Kotlin functions (`KtFunction`) in the given PSI file.
For each function that does not already have a `@Deprecated` annotation, you will add one with a message indicating that the method is deprecated.
For each function that lacks a `@Deprecated` annotation, one should be added, accompanied by a message that signifies the method's deprecation.

<div class="hint" title="How to find all function declarations">

Expand All @@ -19,11 +19,11 @@ Use `PsiTreeUtil.findChildrenOfType` to find all Kotlin function declarations (`

<div class="hint" title="Creating annotations">

Use `KtPsiFactory` to create a new annotation entry. Look into how to instantiate KtPsiFactory and use it to create annotations.
Use `KtPsiFactory` to create a new annotation entry. Learn how to instantiate `KtPsiFactory` and use it to create annotations.
</div>

<div class="hint" title="Checking for existing annotations">

Implement a helper method to check if a `KtFunction` already has a `@Deprecated` annotation.
You might find KtFunction’s `annotationEntries` property useful for this.
</div>
The `annotationEntries` property of `KtFunction` might be useful for this.
</div>
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
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.
All operations involving code modifications, such as adding, deleting, or moving methods, renaming variables, etc., are implemented as PSI edits.
Please review the [Modify the PSI](https://plugins.jetbrains.com/docs/intellij/modifying-psi.html) documentation.

Common methods to edit PSI Element:
* [`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
* [`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
* [`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:add`](https://github.com/JetBrains/intellij-community/blob/19d9a1cc2d9c14df9c3bdee391e9e4795ac25cb9/platform/core-api/src/com/intellij/psi/PsiElement.java#L302) - to add a child into the PSI Element subtree
* [`PsiElement:addBefore`](https://github.com/JetBrains/intellij-community/blob/19d9a1cc2d9c14df9c3bdee391e9e4795ac25cb9/platform/core-api/src/com/intellij/psi/PsiElement.java#L312C14-L312C23) / [`PsiElement:addAfter`](https://github.com/JetBrains/intellij-community/blob/19d9a1cc2d9c14df9c3bdee391e9e4795ac25cb9/platform/core-api/src/com/intellij/psi/PsiElement.java#L322) - to add a child into the PSI Element subtree before / after the specified anchor element
* [`PsiElement:addRange`](https://github.com/JetBrains/intellij-community/blob/19d9a1cc2d9c14df9c3bdee391e9e4795ac25cb9/platform/core-api/src/com/intellij/psi/PsiElement.java#L343) - to add a list of children into the PSI Element subtree
* [`PsiElement:addRangeBefore`](https://github.com/JetBrains/intellij-community/blob/19d9a1cc2d9c14df9c3bdee391e9e4795ac25cb9/platform/core-api/src/com/intellij/psi/PsiElement.java#L354) / [`PsiElement:addRangeAfter`](https://github.com/JetBrains/intellij-community/blob/19d9a1cc2d9c14df9c3bdee391e9e4795ac25cb9/platform/core-api/src/com/intellij/psi/PsiElement.java#L365)- to add a list of children into the PSI Element subtree before / after the specified anchor element
Common methods to edit PSI elements include:
* [`PsiElement.copy()`](https://github.com/JetBrains/intellij-community/blob/19d9a1cc2d9c14df9c3bdee391e9e4795ac25cb9/platform/core-api/src/com/intellij/psi/PsiElement.java#L293) - Copies the PSI element subtree.
* [`PsiElement.replace()`](https://github.com/JetBrains/intellij-community/blob/19d9a1cc2d9c14df9c3bdee391e9e4795ac25cb9/platform/core-api/src/com/intellij/psi/PsiElement.java#L402) - Replaces the PSI element in the tree.
* [`PsiElement.delete()`](https://github.com/JetBrains/intellij-community/blob/19d9a1cc2d9c14df9c3bdee391e9e4795ac25cb9/platform/core-api/src/com/intellij/psi/PsiElement.java#L373) - Deletes the PSI element from the tree.
* [`PsiElement:add`](https://github.com/JetBrains/intellij-community/blob/19d9a1cc2d9c14df9c3bdee391e9e4795ac25cb9/platform/core-api/src/com/intellij/psi/PsiElement.java#L302) - Adds a child to the PSI element subtree.
* [`PsiElement:addBefore`](https://github.com/JetBrains/intellij-community/blob/19d9a1cc2d9c14df9c3bdee391e9e4795ac25cb9/platform/core-api/src/com/intellij/psi/PsiElement.java#L312C14-L312C23) / [`PsiElement:addAfter`](https://github.com/JetBrains/intellij-community/blob/19d9a1cc2d9c14df9c3bdee391e9e4795ac25cb9/platform/core-api/src/com/intellij/psi/PsiElement.java#L322) - Adds a child to the PSI element subtree before/after the specified anchor element.
* [`PsiElement:addRange`](https://github.com/JetBrains/intellij-community/blob/19d9a1cc2d9c14df9c3bdee391e9e4795ac25cb9/platform/core-api/src/com/intellij/psi/PsiElement.java#L343) - Adds a list of children to the PSI element subtree.
* [`PsiElement:addRangeBefore`](https://github.com/JetBrains/intellij-community/blob/19d9a1cc2d9c14df9c3bdee391e9e4795ac25cb9/platform/core-api/src/com/intellij/psi/PsiElement.java#L354) / [`PsiElement:addRangeAfter`](https://github.com/JetBrains/intellij-community/blob/19d9a1cc2d9c14df9c3bdee391e9e4795ac25cb9/platform/core-api/src/com/intellij/psi/PsiElement.java#L365)- Adds a list of children to the PSI element subtree before/after the specified anchor element.


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) or as well as all `PsiNamedElement` inheritors.
Moreover, there are some PsiElement-specific methods like [`KtNamedFunction:setName`](https://github.com/JetBrains/intellij-community/blob/bf3083ca66771e038eb1c64128b4e508f52acfad/platform/core-api/src/com/intellij/psi/PsiNamedElement.java#L39) and methods available to 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)
Every PSI modification needs to be wrapped in a [write action and 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
// Here you can modify PSI elements
}
```
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
Sometimes, switching between Python and Kotlin leeds to following code style mistake:
Sometimes, switching between Python and Kotlin leads to the following code style mistake:

Python developers usually use `snake_case` for methods naming like
Python developers usually use `snake_case` for method naming, like:
```python
def sort_values(values):
```
While in Kotlin or Java `camelCase` is commonly used
In contrast, Kotlin and Java commonly use `camelCase`:
```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`.
**Your task will be** to assist multi-language programmers by
implementing a method that renames `snake_case` methods to `camelCase`.

So before your method invocation method looked like:
Before your method invocation, the method might look like:
```Kotlin
fun sort_values(values: List<Int>) {...}
```
but after
After:
```Kotlin
fun sortValues(values: List<Int>) {...}
```

<div class="hint" title="How to get project for WriteActionCommand?">
<div class="hint" title="How to get the project for WriteActionCommand?">

Every PSI element has link to project, just try `psiElement.project`
Every PSI element has a link to the project; just try `psiElement.project`.
</div>
Loading

0 comments on commit f326849

Please sign in to comment.