diff --git a/courseSection/psi/Accessing PSI Elements/src/jetbrains/plugindev/course/access/Main.kt b/courseSection/psi/AccessingPsiElements/src/jetbrains/plugindev/course/access/Main.kt similarity index 100% rename from courseSection/psi/Accessing PSI Elements/src/jetbrains/plugindev/course/access/Main.kt rename to courseSection/psi/AccessingPsiElements/src/jetbrains/plugindev/course/access/Main.kt diff --git a/courseSection/psi/Accessing PSI Elements/task-info.yaml b/courseSection/psi/AccessingPsiElements/task-info.yaml similarity index 72% rename from courseSection/psi/Accessing PSI Elements/task-info.yaml rename to courseSection/psi/AccessingPsiElements/task-info.yaml index 49a98d6..6daedda 100644 --- a/courseSection/psi/Accessing PSI Elements/task-info.yaml +++ b/courseSection/psi/AccessingPsiElements/task-info.yaml @@ -1,4 +1,5 @@ type: theory +custom_name: Accessing PSI Elements files: - name: src/jetbrains/plugindev/course/access/Main.kt visible: true diff --git a/courseSection/psi/Accessing PSI Elements/task.md b/courseSection/psi/AccessingPsiElements/task.md similarity index 100% rename from courseSection/psi/Accessing PSI Elements/task.md rename to courseSection/psi/AccessingPsiElements/task.md diff --git a/courseSection/psi/addPSI/src/jetbrains/plugindev/course/addpsi/Task.kt b/courseSection/psi/AddAnnotations/src/org/jetbrains/academy/ij/plugin/course/annotations/Task.kt similarity index 74% rename from courseSection/psi/addPSI/src/jetbrains/plugindev/course/addpsi/Task.kt rename to courseSection/psi/AddAnnotations/src/org/jetbrains/academy/ij/plugin/course/annotations/Task.kt index 7265ff7..ee0e83d 100644 --- a/courseSection/psi/addPSI/src/jetbrains/plugindev/course/addpsi/Task.kt +++ b/courseSection/psi/AddAnnotations/src/org/jetbrains/academy/ij/plugin/course/annotations/Task.kt @@ -1,4 +1,4 @@ -package jetbrains.plugindev.course.addpsi +package org.jetbrains.academy.ij.plugin.course.annotations import com.intellij.openapi.command.WriteCommandAction import com.intellij.openapi.project.Project @@ -8,27 +8,6 @@ import com.intellij.psi.PsiMethod import com.intellij.psi.PsiType import com.intellij.psi.util.PsiTreeUtil import com.intellij.psi.util.TypeConversionUtil -import org.jetbrains.kotlin.psi.KtClass -import org.jetbrains.kotlin.psi.KtNamedFunction - - -// type your solution here - -fun sortMethods(psiFile: PsiFile) { - val project = psiFile.project - WriteCommandAction.runWriteCommandAction(project) { - val classes = PsiTreeUtil.findChildrenOfType(psiFile, KtClass::class.java) - - for (ktClass in classes){ - val methods = ktClass.declarations.filterIsInstance() - val sortedMethods = methods.sortedBy { it.name }.map { it.copy() as KtNamedFunction } - - methods.zip(sortedMethods).forEach { (original, sortedCopy) -> - original.replace(sortedCopy) - } - } - } -} fun addAnnotations(psiFile: PsiFile){ val project = psiFile.project diff --git a/courseSection/psi/AddAnnotations/task-info.yaml b/courseSection/psi/AddAnnotations/task-info.yaml new file mode 100644 index 0000000..ec87197 --- /dev/null +++ b/courseSection/psi/AddAnnotations/task-info.yaml @@ -0,0 +1,11 @@ +type: edu +custom_name: Psi Manipulation Advanced +files: + - name: src/org/jetbrains/academy/ij/plugin/course/annotations/Task.kt + visible: true + placeholders: + - offset: 871 + length: 247 + placeholder_text: TODO() + - name: test/org/jetbrains/academy/ij/plugin/course/annotations/Tests.kt + visible: false diff --git a/courseSection/psi/addPSI/task.md b/courseSection/psi/AddAnnotations/task.md similarity index 100% rename from courseSection/psi/addPSI/task.md rename to courseSection/psi/AddAnnotations/task.md diff --git a/courseSection/psi/addPSI/test/jetbrains/plugindev/course/addpsi/Tests.kt b/courseSection/psi/AddAnnotations/test/org/jetbrains/academy/ij/plugin/course/annotations/Tests.kt similarity index 55% rename from courseSection/psi/addPSI/test/jetbrains/plugindev/course/addpsi/Tests.kt rename to courseSection/psi/AddAnnotations/test/org/jetbrains/academy/ij/plugin/course/annotations/Tests.kt index c5b7fff..e9fac4e 100644 --- a/courseSection/psi/addPSI/test/jetbrains/plugindev/course/addpsi/Tests.kt +++ b/courseSection/psi/AddAnnotations/test/org/jetbrains/academy/ij/plugin/course/annotations/Tests.kt @@ -1,42 +1,14 @@ -package jetbrains.plugindev.course.addpsi +package org.jetbrains.academy.ij.plugin.course.annotations + import com.intellij.ide.highlighter.JavaFileType import com.intellij.psi.PsiClass import com.intellij.psi.PsiMethod import com.intellij.psi.util.PsiTreeUtil import com.intellij.testFramework.fixtures.BasePlatformTestCase -import org.jetbrains.kotlin.psi.KtClass -import org.jetbrains.kotlin.psi.KtNamedFunction - -class Test : BasePlatformTestCase() { - - fun testSolution() { - var file = myFixture.configureByText("MyClass.kt", """ - class MyClass { - fun abcd() { - println("Hello") - } - - fun zhas() { - println("Goodbye") - } - - fun mid() { - println("Goodbye") - } - } - - """.trimIndent()) - sortMethods(file) - val classes = PsiTreeUtil.findChildrenOfType(file, KtClass::class.java) - for (ktClass in classes){ - val methods = ktClass.declarations.filterIsInstance() - val sorted = methods.sortedBy { it.name } - assertEquals(sorted, methods) - } - } +class Test : BasePlatformTestCase() { fun testAnnotation() { val javaFile = myFixture.configureByText( @@ -46,7 +18,6 @@ class Test : BasePlatformTestCase() { } class SubClass extends SuperClass { - public void testMethod() {} } """.trimIndent()) diff --git a/courseSection/psi/classCounter/src/jetbrains/plugindev/course/classcounter/Task.kt b/courseSection/psi/ClassCounter/src/jetbrains/plugindev/course/classcounter/Task.kt similarity index 100% rename from courseSection/psi/classCounter/src/jetbrains/plugindev/course/classcounter/Task.kt rename to courseSection/psi/ClassCounter/src/jetbrains/plugindev/course/classcounter/Task.kt diff --git a/courseSection/psi/classCounter/task-info.yaml b/courseSection/psi/ClassCounter/task-info.yaml similarity index 75% rename from courseSection/psi/classCounter/task-info.yaml rename to courseSection/psi/ClassCounter/task-info.yaml index 2736283..0ab9c53 100644 --- a/courseSection/psi/classCounter/task-info.yaml +++ b/courseSection/psi/ClassCounter/task-info.yaml @@ -1,10 +1,11 @@ type: edu +custom_name: Count number of classes files: - name: src/jetbrains/plugindev/course/classcounter/Task.kt visible: true placeholders: - - offset: 160 - length: 85 + - offset: 211 + length: 81 placeholder_text: TODO() - name: test/jetbrains/plugindev/course/classcounter/Tests.kt visible: false diff --git a/courseSection/psi/Count number of classes/task.md b/courseSection/psi/ClassCounter/task.md similarity index 99% rename from courseSection/psi/Count number of classes/task.md rename to courseSection/psi/ClassCounter/task.md index c75a7d2..60b833d 100644 --- a/courseSection/psi/Count number of classes/task.md +++ b/courseSection/psi/ClassCounter/task.md @@ -1,6 +1,7 @@ You need to implement a function `countKtClasses` which will count number of kotlin classes declared in the given kotlin PSI file.
+ Try to use `KtClass::class.java` value for aClass parameter for `findChildrenOfType`
diff --git a/courseSection/psi/classCounter/test/jetbrains/plugindev/course/classcounter/Tests.kt b/courseSection/psi/ClassCounter/test/jetbrains/plugindev/course/classcounter/Tests.kt similarity index 100% rename from courseSection/psi/classCounter/test/jetbrains/plugindev/course/classcounter/Tests.kt rename to courseSection/psi/ClassCounter/test/jetbrains/plugindev/course/classcounter/Tests.kt diff --git a/courseSection/psi/EditPSI/src/jetbrains/plugindev/course/editpsi/Task.kt b/courseSection/psi/EditPSI/src/jetbrains/plugindev/course/editpsi/Task.kt new file mode 100644 index 0000000..ed209f2 --- /dev/null +++ b/courseSection/psi/EditPSI/src/jetbrains/plugindev/course/editpsi/Task.kt @@ -0,0 +1,13 @@ +package jetbrains.plugindev.course.editpsi + +import com.intellij.openapi.command.WriteCommandAction +import org.jetbrains.kotlin.psi.KtNamedFunction + + +fun editFunctionName(function: KtNamedFunction, newName: String) { + val project = function.project + + WriteCommandAction.runWriteCommandAction(project) { + function.setName(newName) + } +} \ No newline at end of file diff --git a/courseSection/psi/editPSI/task-info.yaml b/courseSection/psi/EditPSI/task-info.yaml similarity index 56% rename from courseSection/psi/editPSI/task-info.yaml rename to courseSection/psi/EditPSI/task-info.yaml index f551a04..a079302 100644 --- a/courseSection/psi/editPSI/task-info.yaml +++ b/courseSection/psi/EditPSI/task-info.yaml @@ -1,6 +1,11 @@ type: edu +custom_name: Rename function using PSI files: - name: src/jetbrains/plugindev/course/editpsi/Task.kt visible: true + placeholders: + - offset: 220 + length: 127 + placeholder_text: TODO() - name: test/jetbrains/plugindev/course/editpsi/Tests.kt visible: false diff --git a/courseSection/psi/editPSI/test/jetbrains/plugindev/course/editpsi/Tests.kt b/courseSection/psi/EditPSI/test/jetbrains/plugindev/course/editpsi/Tests.kt similarity index 79% rename from courseSection/psi/editPSI/test/jetbrains/plugindev/course/editpsi/Tests.kt rename to courseSection/psi/EditPSI/test/jetbrains/plugindev/course/editpsi/Tests.kt index 9cf7146..fbbd25d 100644 --- a/courseSection/psi/editPSI/test/jetbrains/plugindev/course/editpsi/Tests.kt +++ b/courseSection/psi/EditPSI/test/jetbrains/plugindev/course/editpsi/Tests.kt @@ -17,9 +17,12 @@ class Test : BasePlatformTestCase() { } """.trimIndent()) - editFunctionName(file, "sayHello", "greetings") - val functions = PsiTreeUtil.findChildrenOfType(file, KtNamedFunction::class.java) + val functionToRename = functions.find { it.name == "sayHello" } + if (functionToRename != null) { + editFunctionName(functionToRename, "greetings") + } + val hasNewFunction = functions.any { it.name == "greetings" } assertTrue(hasNewFunction) } diff --git a/courseSection/psi/What is PSI/src/Person.kt b/courseSection/psi/IntroToPsi/src/Person.kt similarity index 100% rename from courseSection/psi/What is PSI/src/Person.kt rename to courseSection/psi/IntroToPsi/src/Person.kt diff --git a/courseSection/psi/What is PSI/task-info.yaml b/courseSection/psi/IntroToPsi/task-info.yaml similarity index 70% rename from courseSection/psi/What is PSI/task-info.yaml rename to courseSection/psi/IntroToPsi/task-info.yaml index f50926e..e5fdfa5 100644 --- a/courseSection/psi/What is PSI/task-info.yaml +++ b/courseSection/psi/IntroToPsi/task-info.yaml @@ -1,4 +1,5 @@ type: theory +custom_name: What is PSI? files: - name: src/Person.kt visible: true diff --git a/courseSection/psi/What is PSI/task.md b/courseSection/psi/IntroToPsi/task.md similarity index 100% rename from courseSection/psi/What is PSI/task.md rename to courseSection/psi/IntroToPsi/task.md diff --git a/courseSection/psi/addPSI/task-info.yaml b/courseSection/psi/SortMethods/task-info.yaml similarity index 56% rename from courseSection/psi/addPSI/task-info.yaml rename to courseSection/psi/SortMethods/task-info.yaml index 6927d9a..19e1c16 100644 --- a/courseSection/psi/addPSI/task-info.yaml +++ b/courseSection/psi/SortMethods/task-info.yaml @@ -1,6 +1,11 @@ type: edu +custom_name: Psi Manipulation Basics files: - name: src/jetbrains/plugindev/course/addpsi/Task.kt visible: true + placeholders: + - offset: 228 + length: 387 + placeholder_text: TODO() - name: test/jetbrains/plugindev/course/addpsi/Tests.kt visible: false diff --git a/courseSection/psi/SortMethods/test/jetbrains/plugindev/course/addpsi/Tests.kt b/courseSection/psi/SortMethods/test/jetbrains/plugindev/course/addpsi/Tests.kt new file mode 100644 index 0000000..3c54bdd --- /dev/null +++ b/courseSection/psi/SortMethods/test/jetbrains/plugindev/course/addpsi/Tests.kt @@ -0,0 +1,42 @@ +package jetbrains.plugindev.course.addpsi + +import com.intellij.ide.highlighter.JavaFileType +import com.intellij.psi.PsiClass +import com.intellij.psi.PsiMethod +import com.intellij.psi.util.PsiTreeUtil +import com.intellij.testFramework.fixtures.BasePlatformTestCase +import org.jetbrains.kotlin.psi.KtClass +import org.jetbrains.kotlin.psi.KtNamedFunction + +class Test : BasePlatformTestCase() { + + fun testSolution() { + var file = myFixture.configureByText("Person.kt", """ + class Person { + fun name() { + println("My name is John") + } + + fun surname() { + println("My surname is Johnson") + } + + fun age() { + println("I am 18 years old") + } + } + + """.trimIndent()) + + val classes = PsiTreeUtil.findChildrenOfType(file, KtClass::class.java) + for (ktClass in classes){ + sortMethods(ktClass) + + val methods = ktClass.declarations.filterIsInstance() + val sorted = methods.sortedBy { it.name } + assertEquals(sorted, methods) + } + } + + +} \ No newline at end of file diff --git a/courseSection/psi/Try PSI Viewer/src/Person.kt b/courseSection/psi/TryPsiViewer/src/Person.kt similarity index 100% rename from courseSection/psi/Try PSI Viewer/src/Person.kt rename to courseSection/psi/TryPsiViewer/src/Person.kt diff --git a/courseSection/psi/Try PSI Viewer/task-info.yaml b/courseSection/psi/TryPsiViewer/task-info.yaml similarity index 93% rename from courseSection/psi/Try PSI Viewer/task-info.yaml rename to courseSection/psi/TryPsiViewer/task-info.yaml index 1cd6521..765a56a 100644 --- a/courseSection/psi/Try PSI Viewer/task-info.yaml +++ b/courseSection/psi/TryPsiViewer/task-info.yaml @@ -1,4 +1,5 @@ type: choice +custom_name: Try Psi Viewer is_multiple_choice: true options: - text: org.jetbrains.kotlin.psi.KtClass @@ -13,3 +14,4 @@ files: - name: src/Person.kt visible: true local_check: true + diff --git a/courseSection/psi/Try PSI Viewer/task.md b/courseSection/psi/TryPsiViewer/task.md similarity index 100% rename from courseSection/psi/Try PSI Viewer/task.md rename to courseSection/psi/TryPsiViewer/task.md diff --git a/courseSection/psi/editPSI/src/jetbrains/plugindev/course/editpsi/Task.kt b/courseSection/psi/editPSI/src/jetbrains/plugindev/course/editpsi/Task.kt deleted file mode 100644 index 357abf5..0000000 --- a/courseSection/psi/editPSI/src/jetbrains/plugindev/course/editpsi/Task.kt +++ /dev/null @@ -1,20 +0,0 @@ -package jetbrains.plugindev.course.editpsi - -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) - } - } - } -} \ No newline at end of file diff --git a/courseSection/psi/lesson-info.yaml b/courseSection/psi/lesson-info.yaml index d2cfc68..3aed340 100644 --- a/courseSection/psi/lesson-info.yaml +++ b/courseSection/psi/lesson-info.yaml @@ -1,8 +1,9 @@ custom_name: PSI content: - - What is PSI - - Try PSI Viewer - - Accessing PSI Elements - - classCounter - - editPSI - - addPSI + - IntroToPsi + - TryPsiViewer + - AccessingPsiElements + - ClassCounter + - EditPSI + - SortMethods + - AddAnnotations