diff --git a/common/sampleProject/src/main/kotlin/AccessingPsiElements/FunctionCounter/ComplexMethods.kt b/common/sampleProject/src/main/kotlin/AccessingPsiElements/FunctionCounter/ComplexMethods.kt new file mode 100644 index 0000000..eecc9b6 --- /dev/null +++ b/common/sampleProject/src/main/kotlin/AccessingPsiElements/FunctionCounter/ComplexMethods.kt @@ -0,0 +1,19 @@ +class ComplexMethods { + + fun calculate(value: Int): Int { + fun innerFunction(x: Int): Int { + return x * x + } + return innerFunction(value) + } + + companion object { + fun staticMethod() { + println("Static method in companion object") + } + } +} + +fun anotherTopLevelFunction() { + println("Another top-level function") +} diff --git a/courseSection/accessingPsiElementsLesson/accessingPsiElementsClassProgrammingTask/src/main/kotlin/org/jetbrains/academy/plugin/course/dev/access/AuthorElementsCounter.kt b/courseSection/accessingPsiElementsLesson/accessingPsiElementsClassProgrammingTask/src/main/kotlin/org/jetbrains/academy/plugin/course/dev/access/AuthorElementsCounter.kt new file mode 100644 index 0000000..291a311 --- /dev/null +++ b/courseSection/accessingPsiElementsLesson/accessingPsiElementsClassProgrammingTask/src/main/kotlin/org/jetbrains/academy/plugin/course/dev/access/AuthorElementsCounter.kt @@ -0,0 +1,8 @@ +package org.jetbrains.academy.plugin.course.dev.access + +import com.intellij.psi.PsiFile +import com.intellij.psi.util.PsiTreeUtil +import org.jetbrains.kotlin.psi.KtClass + +fun authorCountKtClasses(psiFile: PsiFile) = + PsiTreeUtil.findChildrenOfType(psiFile, KtClass::class.java).toList().size \ No newline at end of file diff --git a/courseSection/accessingPsiElementsLesson/accessingPsiElementsClassProgrammingTask/src/main/kotlin/org/jetbrains/academy/plugin/course/dev/ui/DemoPanelFactory.kt b/courseSection/accessingPsiElementsLesson/accessingPsiElementsClassProgrammingTask/src/main/kotlin/org/jetbrains/academy/plugin/course/dev/ui/DemoPanelFactory.kt index c68e2e3..2a84228 100644 --- a/courseSection/accessingPsiElementsLesson/accessingPsiElementsClassProgrammingTask/src/main/kotlin/org/jetbrains/academy/plugin/course/dev/ui/DemoPanelFactory.kt +++ b/courseSection/accessingPsiElementsLesson/accessingPsiElementsClassProgrammingTask/src/main/kotlin/org/jetbrains/academy/plugin/course/dev/ui/DemoPanelFactory.kt @@ -12,6 +12,7 @@ import com.intellij.ui.components.JBScrollPane import com.intellij.ui.table.JBTable import com.intellij.util.ui.JBUI import org.jetbrains.academy.plugin.course.dev.access.countKtClasses +import org.jetbrains.academy.plugin.course.dev.access.authorCountKtClasses import java.awt.BorderLayout import java.awt.FlowLayout import java.awt.event.ActionListener @@ -68,10 +69,11 @@ class DemoPanelFactory : ToolWindowFactory { psiFile?.let { val result = countKtClasses(it) + val authorResult = authorCountKtClasses(it) // Display the result in the table tableModel.setRowCount(0) - tableModel.addRow(arrayOf("Class", result.toString(), 2)) + tableModel.addRow(arrayOf("Class", result.toString(), authorResult.toString())) } } } diff --git a/courseSection/accessingPsiElementsLesson/accessingPsiElementsClassProgrammingTask/task-info.yaml b/courseSection/accessingPsiElementsLesson/accessingPsiElementsClassProgrammingTask/task-info.yaml index aed3f3f..fe54108 100644 --- a/courseSection/accessingPsiElementsLesson/accessingPsiElementsClassProgrammingTask/task-info.yaml +++ b/courseSection/accessingPsiElementsLesson/accessingPsiElementsClassProgrammingTask/task-info.yaml @@ -13,3 +13,5 @@ files: visible: false - name: src/main/resources/META-INF/plugin.xml visible: false + - name: src/main/kotlin/org/jetbrains/academy/plugin/course/dev/access/AuthorElementsCounter.kt + visible: false diff --git a/courseSection/accessingPsiElementsLesson/accessingPsiElementsClassProgrammingTask/test/org/jetbrains/academy/plugin/course/dev/access/Tests.kt b/courseSection/accessingPsiElementsLesson/accessingPsiElementsClassProgrammingTask/test/org/jetbrains/academy/plugin/course/dev/access/Tests.kt index bc2b835..35587b2 100644 --- a/courseSection/accessingPsiElementsLesson/accessingPsiElementsClassProgrammingTask/test/org/jetbrains/academy/plugin/course/dev/access/Tests.kt +++ b/courseSection/accessingPsiElementsLesson/accessingPsiElementsClassProgrammingTask/test/org/jetbrains/academy/plugin/course/dev/access/Tests.kt @@ -16,6 +16,7 @@ class Test : BasePlatformTestCase() { val file = myFixture.configureByText("MyClass.kt", fileContent) val psiClassesCount = countKtClasses(file) - assertEquals("For the Kotlin file with content $fileContent the function countKtClasses should return 2, but currently it returns $psiClassesCount", 2, psiClassesCount) + val authorClassesCount = authorCountKtClasses(file) + assertEquals("For the Kotlin file with content $fileContent the function countKtClasses should return 2, but currently it returns $psiClassesCount", authorClassesCount, psiClassesCount) } } diff --git a/courseSection/accessingPsiElementsLesson/accessingPsiElementsFunctionProgrammingTask/src/main/kotlin/org/jetbrains/academy/plugin/course/dev/access/AuthorElementsCounter.kt b/courseSection/accessingPsiElementsLesson/accessingPsiElementsFunctionProgrammingTask/src/main/kotlin/org/jetbrains/academy/plugin/course/dev/access/AuthorElementsCounter.kt new file mode 100644 index 0000000..81c8e58 --- /dev/null +++ b/courseSection/accessingPsiElementsLesson/accessingPsiElementsFunctionProgrammingTask/src/main/kotlin/org/jetbrains/academy/plugin/course/dev/access/AuthorElementsCounter.kt @@ -0,0 +1,8 @@ +package org.jetbrains.academy.plugin.course.dev.access + +import com.intellij.psi.PsiFile +import com.intellij.psi.util.PsiTreeUtil +import org.jetbrains.kotlin.psi.KtNamedFunction + +fun authorCountKtFunctions(psiFile: PsiFile) = + PsiTreeUtil.findChildrenOfType(psiFile, KtNamedFunction::class.java).toList().size \ No newline at end of file diff --git a/courseSection/accessingPsiElementsLesson/accessingPsiElementsFunctionProgrammingTask/src/main/kotlin/org/jetbrains/academy/plugin/course/dev/ui/DemoPanelFactory.kt b/courseSection/accessingPsiElementsLesson/accessingPsiElementsFunctionProgrammingTask/src/main/kotlin/org/jetbrains/academy/plugin/course/dev/ui/DemoPanelFactory.kt index f4b026e..800bfd3 100644 --- a/courseSection/accessingPsiElementsLesson/accessingPsiElementsFunctionProgrammingTask/src/main/kotlin/org/jetbrains/academy/plugin/course/dev/ui/DemoPanelFactory.kt +++ b/courseSection/accessingPsiElementsLesson/accessingPsiElementsFunctionProgrammingTask/src/main/kotlin/org/jetbrains/academy/plugin/course/dev/ui/DemoPanelFactory.kt @@ -11,6 +11,7 @@ import com.intellij.ui.components.JBPanel import com.intellij.ui.components.JBScrollPane import com.intellij.ui.table.JBTable import com.intellij.util.ui.JBUI +import org.jetbrains.academy.plugin.course.dev.access.authorCountKtFunctions import org.jetbrains.academy.plugin.course.dev.access.countKtFunctions import java.awt.BorderLayout import java.awt.FlowLayout @@ -67,10 +68,10 @@ class DemoPanelFactory : ToolWindowFactory { psiFile?.let { val result = countKtFunctions(it) - + val authorResult = authorCountKtFunctions(it) // Display the result in the table tableModel.setRowCount(0) - tableModel.addRow(arrayOf("Class", result.toString(), 2)) + tableModel.addRow(arrayOf("Function", result.toString(), authorResult.toString())) } } } diff --git a/courseSection/accessingPsiElementsLesson/accessingPsiElementsFunctionProgrammingTask/task-info.yaml b/courseSection/accessingPsiElementsLesson/accessingPsiElementsFunctionProgrammingTask/task-info.yaml index e5deeac..f1a2e58 100644 --- a/courseSection/accessingPsiElementsLesson/accessingPsiElementsFunctionProgrammingTask/task-info.yaml +++ b/courseSection/accessingPsiElementsLesson/accessingPsiElementsFunctionProgrammingTask/task-info.yaml @@ -12,3 +12,5 @@ files: visible: false - name: test/org/jetbrains/academy/plugin/course/dev/access/Tests.kt visible: false + - name: src/main/kotlin/org/jetbrains/academy/plugin/course/dev/access/AuthorElementsCounter.kt + visible: false diff --git a/courseSection/accessingPsiElementsLesson/accessingPsiElementsFunctionProgrammingTask/test/org/jetbrains/academy/plugin/course/dev/access/Tests.kt b/courseSection/accessingPsiElementsLesson/accessingPsiElementsFunctionProgrammingTask/test/org/jetbrains/academy/plugin/course/dev/access/Tests.kt index cdb4272..c032faa 100644 --- a/courseSection/accessingPsiElementsLesson/accessingPsiElementsFunctionProgrammingTask/test/org/jetbrains/academy/plugin/course/dev/access/Tests.kt +++ b/courseSection/accessingPsiElementsLesson/accessingPsiElementsFunctionProgrammingTask/test/org/jetbrains/academy/plugin/course/dev/access/Tests.kt @@ -40,6 +40,7 @@ object MyObject { val file = myFixture.configureByText("MyClass.kt", fileContent) val psiFunctionsCount = countKtFunctions(file) - assertEquals("For the Kotlin file with content $fileContent the function countKtClasses should return 6, but currently it returns $psiFunctionsCount", 6, psiFunctionsCount) + val authorFunctionsCount = authorCountKtFunctions(file) + assertEquals("For the Kotlin file with content $fileContent the function countKtClasses should return 6, but currently it returns $psiFunctionsCount", authorFunctionsCount, psiFunctionsCount) } } diff --git a/courseSection/editingPsiElementsLesson/sortMethodsProgrammingTask/test/org/jetbrains/academy/plugin/course/dev/access/Tests.kt b/courseSection/editingPsiElementsLesson/sortMethodsProgrammingTask/test/org/jetbrains/academy/plugin/course/dev/access/Tests.kt index ada1050..bcd6445 100644 --- a/courseSection/editingPsiElementsLesson/sortMethodsProgrammingTask/test/org/jetbrains/academy/plugin/course/dev/access/Tests.kt +++ b/courseSection/editingPsiElementsLesson/sortMethodsProgrammingTask/test/org/jetbrains/academy/plugin/course/dev/access/Tests.kt @@ -28,6 +28,7 @@ class Test : BasePlatformTestCase() { val file = myFixture.configureByText("Person.kt", fileContent) 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(