Skip to content

Commit

Permalink
Merge pull request #1 from jetbrains-academy/fix-tests
Browse files Browse the repository at this point in the history
Remove JUnit5
  • Loading branch information
nbirillo authored Jan 3, 2024
2 parents e8eb3d4 + fd56d76 commit 0d7bf74
Show file tree
Hide file tree
Showing 47 changed files with 448 additions and 238 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ In the `.github/workflows` directory, you can find definitions for the following
[file:gradle.properties]: ./gradle.properties
[file:course-info.yaml]: ./course-info.yaml
[file:courseignore]: .courseignore
[file:course.lesson.tests]: ./courseSection/courseLesson/programmingTask/test/Tests.kt
[file:course.lesson.tests]: courseSection/psi/programmingTask/test/Tests.kt
[file:course.framework.lesson.tests]: ./courseSection/courseFrameworkLesson/programmingTask/test/Tests.kt

[gradle]: https://gradle.org
Expand Down
8 changes: 0 additions & 8 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,6 @@ configure(subprojects) {
// By default, only the core module is included
implementation("org.jetbrains.academy.test.system:core:2.0.5")

val junitJupiterVersion = "5.9.0"
implementation("org.junit.jupiter:junit-jupiter-api:$junitJupiterVersion")
runtimeOnly("org.junit.jupiter:junit-jupiter-engine:$junitJupiterVersion")
implementation("org.junit.jupiter:junit-jupiter-params:$junitJupiterVersion")
runtimeOnly("org.junit.platform:junit-platform-console:1.9.0")

val detektVersion = "1.22.0"
implementation("io.gitlab.arturbosch.detekt:detekt-gradle-plugin:$detektVersion")
implementation("io.gitlab.arturbosch.detekt:detekt-formatting:$detektVersion")
Expand All @@ -95,8 +89,6 @@ configure(subprojects) {

// This part is necessary for the JetBrains Academy plugin
withType<Test> {
useJUnitPlatform()

outputs.upToDateWhen { false }

addTestListener(object : TestListener {
Expand Down

This file was deleted.

6 changes: 0 additions & 6 deletions courseSection/courseLesson/findNumberOfClassesTask/task.md

This file was deleted.

4 changes: 0 additions & 4 deletions courseSection/courseLesson/introductionToPsiTask/src/Main.kt

This file was deleted.

This file was deleted.

33 changes: 0 additions & 33 deletions courseSection/courseLesson/introductionToPsiTask/task.md

This file was deleted.

7 changes: 0 additions & 7 deletions courseSection/courseLesson/lesson-info.yaml

This file was deleted.

This file was deleted.

This file was deleted.

20 changes: 0 additions & 20 deletions courseSection/courseLesson/programmingTask/task-info.yaml

This file was deleted.

6 changes: 0 additions & 6 deletions courseSection/courseLesson/programmingTask/task.md

This file was deleted.

This file was deleted.

8 changes: 0 additions & 8 deletions courseSection/courseLesson/programmingTask/test/MainClass.kt

This file was deleted.

58 changes: 0 additions & 58 deletions courseSection/courseLesson/programmingTask/test/Tests.kt

This file was deleted.

This file was deleted.

12 changes: 0 additions & 12 deletions courseSection/courseLesson/quizTask/task-info.yaml

This file was deleted.

2 changes: 0 additions & 2 deletions courseSection/courseLesson/quizTask/task.md

This file was deleted.

This file was deleted.

7 changes: 0 additions & 7 deletions courseSection/courseLesson/theoryTask/task-info.yaml

This file was deleted.

14 changes: 0 additions & 14 deletions courseSection/courseLesson/theoryTask/task.md

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.jetbrains.academy.kotlin.template
package jetbrains.plugindev.course.access

fun main() {
// Write your solution here
Expand Down
5 changes: 5 additions & 0 deletions courseSection/psi/AccessingPsiElements/task-info.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
type: theory
custom_name: Accessing PSI Elements
files:
- name: src/jetbrains/plugindev/course/access/Main.kt
visible: true
17 changes: 17 additions & 0 deletions courseSection/psi/AccessingPsiElements/task.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Accessing PSI Elements

---
[com.intellij.psi.util.PsiTreeUtil](https://github.com/JetBrains/intellij-community/blob/master/platform/core-api/src/com/intellij/psi/util/PsiTreeUtil.java)
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.

**Syntax:**
```java
public static @Unmodifiable @NotNull <T extends PsiElement> Collection<T> findChildrenOfType(@Nullable PsiElement element, @NotNull Class<? extends T> aClass)
```

**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.
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package org.jetbrains.academy.ij.plugin.course.annotations

import com.intellij.openapi.command.WriteCommandAction
import com.intellij.openapi.project.Project
import com.intellij.psi.JavaPsiFacade
import com.intellij.psi.PsiFile
import com.intellij.psi.PsiMethod
import com.intellij.psi.PsiType
import com.intellij.psi.util.PsiTreeUtil
import com.intellij.psi.util.TypeConversionUtil

fun addAnnotations(psiFile: PsiFile){
val project = psiFile.project
WriteCommandAction.runWriteCommandAction(project) {
val psiMethods = PsiTreeUtil.findChildrenOfType(psiFile, PsiMethod::class.java)

for (psiMethod in psiMethods) {
if (shouldAddOverrideAnnotation(psiMethod)) {
addOverrideAnnotation(psiMethod, project)
}
}
}
}

private fun addOverrideAnnotation(psiMethod: PsiMethod, project: Project) {
val psiElementFactory = JavaPsiFacade.getElementFactory(project)
val overrideAnnotation = psiElementFactory.createAnnotationFromText("@Override", null)
psiMethod.modifierList.addBefore(overrideAnnotation, psiMethod.modifierList.firstChild)
}

private fun shouldAddOverrideAnnotation(psiMethod: PsiMethod): Boolean {
// Logic to determine if this method overrides a method from its superclass
val containingClass = psiMethod.containingClass ?: return false

val superClasses = containingClass.supers
val methodName = psiMethod.name
val parameterTypes = psiMethod.parameterList.parameters.map { it.type }

for (superClass in superClasses) {
val superMethods = superClass.methods
for (superMethod in superMethods) {
if (superMethod.name == methodName
&& superMethod.parameterList.parameters.map { it.type } == parameterTypes
&& isReturnTypeCompatible(superMethod.returnType, psiMethod.returnType)
) {
return true
}
}
}
return false
}

private fun isReturnTypeCompatible(superReturnType: PsiType?, subReturnType: PsiType?): Boolean {
if (superReturnType == null || subReturnType == null) return false
return TypeConversionUtil.isAssignable(superReturnType, subReturnType)
}
11 changes: 11 additions & 0 deletions courseSection/psi/AddAnnotations/task-info.yaml
Original file line number Diff line number Diff line change
@@ -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
Loading

0 comments on commit 0d7bf74

Please sign in to comment.