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.
- Loading branch information
Valerii
committed
Dec 5, 2023
1 parent
2b32e3a
commit b0f3619
Showing
5 changed files
with
97 additions
and
0 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,18 @@ | ||
import com.intellij.openapi.command.WriteCommandAction | ||
import com.intellij.psi.PsiFile | ||
import com.intellij.psi.util.PsiTreeUtil | ||
import org.jetbrains.kotlin.psi.KtNamedFunction | ||
|
||
|
||
fun editFunctionName(psiFile: PsiFile, currentName: String, newName: String) { | ||
val project = psiFile.project | ||
|
||
WriteCommandAction.runWriteCommandAction(project) { | ||
val functions = PsiTreeUtil.findChildrenOfType(psiFile, KtNamedFunction::class.java) | ||
for (function in functions) { | ||
if (function.name == currentName) { | ||
function.setName(newName) | ||
} | ||
} | ||
} | ||
} |
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,6 @@ | ||
type: edu | ||
files: | ||
- name: src/Task.kt | ||
visible: true | ||
- name: test/Tests.kt | ||
visible: false |
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,48 @@ | ||
|
||
This is a task description file. | ||
Its content will be displayed to a learner | ||
in the **Task Description** window. | ||
|
||
It supports both Markdown and HTML. | ||
To toggle the format, you can rename **task.md** | ||
to **task.html**, or vice versa. | ||
The default task description format can be changed | ||
in **Preferences | Tools | Education**, | ||
but this will not affect any existing task description files. | ||
|
||
The following features are available in | ||
**task.md/task.html** which are specific to the JetBrains Academy plugin: | ||
|
||
- Hints can be added anywhere in the task text. | ||
Type "hint" and press Tab. | ||
Hints should be added to an empty line in the task text. | ||
In hints you can use both HTML and Markdown. | ||
<div class="hint"> | ||
|
||
Text of your hint | ||
|
||
</div> | ||
|
||
- You may need to refer your learners to a particular lesson, | ||
task, or file. To achieve this, you can use the in-course links. | ||
Specify the path using the `[link_text](course://lesson1/task1/file1)` format. | ||
|
||
- You can insert shortcuts in the task description. | ||
While **task.html/task.md** is open, right-click anywhere | ||
on the **Editor** tab and choose the **Insert shortcut** option | ||
from the context menu. | ||
For example: &shortcut:FileStructurePopup;. | ||
|
||
- Insert the %`IDE_NAME`% macro, | ||
which will be replaced by the actual IDE name. | ||
For example, **%IDE_NAME%**. | ||
|
||
- Insert PSI elements, by using links like | ||
`[element_description](psi_element://link.to.element)`. | ||
To get such a link, right-click the class or method | ||
and select **Copy Reference**. | ||
Then press &shortcut:EditorPaste; to insert the link where appropriate. | ||
For example, a [link to the "contains" method](psi_element://java.lang.String#contains). | ||
|
||
- You can add link to file using **full path** like this: | ||
`[file_link](file://lesson1/task1/file.txt)`. |
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,24 @@ | ||
import com.intellij.psi.util.PsiTreeUtil | ||
import com.intellij.testFramework.fixtures.BasePlatformTestCase | ||
import org.jetbrains.kotlin.psi.KtNamedFunction | ||
|
||
class Test : BasePlatformTestCase() { | ||
|
||
fun testSolution() { | ||
var file = myFixture.configureByText("MyClass.kt", """ | ||
fun sayHello() { | ||
println("Hello") | ||
} | ||
fun sayGoodbye() { | ||
println("Goodbye") | ||
} | ||
""".trimIndent()) | ||
|
||
editFunctionName(file, "sayHello", "greetings") | ||
|
||
val functions = PsiTreeUtil.findChildrenOfType(file, KtNamedFunction::class.java) | ||
val hasNewFunction = functions.any { it.name == "greetings" } | ||
assertTrue(hasNewFunction) | ||
} | ||
} |
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 |
---|---|---|
|
@@ -4,3 +4,4 @@ content: | |
- Try PSI Viewer | ||
- Accessing PSI Elements | ||
- Count number of classes | ||
- editPSI |