diff --git a/java/java-features-trainer/src/com/intellij/java/ift/lesson/basic/JavaSurroundAndUnwrapLesson.kt b/java/java-features-trainer/src/com/intellij/java/ift/lesson/basic/JavaSurroundAndUnwrapLesson.kt index a5afc0dc0235..605f65381fb9 100644 --- a/java/java-features-trainer/src/com/intellij/java/ift/lesson/basic/JavaSurroundAndUnwrapLesson.kt +++ b/java/java-features-trainer/src/com/intellij/java/ift/lesson/basic/JavaSurroundAndUnwrapLesson.kt @@ -1,6 +1,7 @@ // Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.java.ift.lesson.basic +import com.intellij.codeInsight.CodeInsightBundle import training.dsl.LessonSample import training.dsl.parseLessonSample import training.learn.lesson.general.SurroundAndUnwrapLesson @@ -17,4 +18,6 @@ class JavaSurroundAndUnwrapLesson : SurroundAndUnwrapLesson() { override val surroundItems = arrayOf("try", "catch", "finally") override val lineShiftBeforeUnwrap = -2 + + override val unwrapTryText = CodeInsightBundle.message("unwrap.try") } diff --git a/plugins/ide-features-trainer/src/training/learn/lesson/general/SurroundAndUnwrapLesson.kt b/plugins/ide-features-trainer/src/training/learn/lesson/general/SurroundAndUnwrapLesson.kt index 84de6afb0caa..a539c562fbc2 100644 --- a/plugins/ide-features-trainer/src/training/learn/lesson/general/SurroundAndUnwrapLesson.kt +++ b/plugins/ide-features-trainer/src/training/learn/lesson/general/SurroundAndUnwrapLesson.kt @@ -15,6 +15,7 @@ abstract class SurroundAndUnwrapLesson protected abstract val surroundItems: Array protected abstract val lineShiftBeforeUnwrap: Int + protected abstract val unwrapTryText: String protected open val surroundItemName: String get() = surroundItems.joinToString(separator = "/") @@ -60,9 +61,7 @@ abstract class SurroundAndUnwrapLesson editor.caretModel.currentCaret.logicalPosition.line != previous.position.line } text(LessonsBundle.message("surround.and.unwrap.invoke.unwrap", action(it))) - triggerByListItemAndHighlight { item -> - wordIsPresent(item.toNullableString(), surroundItems[0]) - } + triggerByListItemAndHighlight { item -> item.toNullableString() == unwrapTryText } test { actions(it) } } task { diff --git a/plugins/kotlin/features-trainer/resources/data/modules/kotlin/EditorBasics/Collapse.kt.sample b/plugins/kotlin/features-trainer/resources/data/modules/kotlin/EditorBasics/Collapse.kt.sample new file mode 100644 index 000000000000..4b2936635ed4 --- /dev/null +++ b/plugins/kotlin/features-trainer/resources/data/modules/kotlin/EditorBasics/Collapse.kt.sample @@ -0,0 +1,26 @@ +import kotlin.math.abs + +@Throws(CheckEngineException::class) +fun Engine.startEngineAndLog() { + callStarter() + println("Engine started!") +} + +fun Wheel.rotateWheel(angle: Float) { + if (angle > 0) { + rotateClockwise(angle) + } else { + rotateCounterClockwise(abs(angle)) + } +} + +interface Engine { + fun callStarter() +} + +interface Wheel { + fun rotateClockwise(angle: Float) + fun rotateCounterClockwise(angle: Float) +} + +class CheckEngineException : Exception() \ No newline at end of file diff --git a/plugins/kotlin/features-trainer/resources/data/modules/kotlin/EditorBasics/Comment.kt.sample b/plugins/kotlin/features-trainer/resources/data/modules/kotlin/EditorBasics/Comment.kt.sample new file mode 100644 index 000000000000..0d75fe0fde8c --- /dev/null +++ b/plugins/kotlin/features-trainer/resources/data/modules/kotlin/EditorBasics/Comment.kt.sample @@ -0,0 +1,12 @@ +import java.awt.Color; + +fun main() { + val hue = 5f + val saturation = 10f + val brightness = 10f + + val rgb = Color.HSBtoRGB(hue, saturation, brightness) + val red = rgb shr 16 and 0xFF + val green = rgb shr 8 and 0xFF + val blue = rgb and 0xFF +} \ No newline at end of file diff --git a/plugins/kotlin/features-trainer/resources/data/modules/kotlin/EditorBasics/Duplicate.kt.sample b/plugins/kotlin/features-trainer/resources/data/modules/kotlin/EditorBasics/Duplicate.kt.sample new file mode 100644 index 000000000000..f9247a1fd187 --- /dev/null +++ b/plugins/kotlin/features-trainer/resources/data/modules/kotlin/EditorBasics/Duplicate.kt.sample @@ -0,0 +1,5 @@ + +fun main(args: Array) { + println("Hello world!") + println("Hello world!") +} \ No newline at end of file diff --git a/plugins/kotlin/features-trainer/resources/data/modules/kotlin/EditorBasics/Move.kt.sample b/plugins/kotlin/features-trainer/resources/data/modules/kotlin/EditorBasics/Move.kt.sample new file mode 100644 index 000000000000..ce3a2ce961af --- /dev/null +++ b/plugins/kotlin/features-trainer/resources/data/modules/kotlin/EditorBasics/Move.kt.sample @@ -0,0 +1,17 @@ + +class MoveDemo : Thread() { + var started = false + + private fun printDebugMessage() { + println("Hello from a thread!") + } + + override fun run() { + started = true + printDebugMessage() + } +} + +fun main(args: Array) { + MoveDemo().start() +} \ No newline at end of file diff --git a/plugins/kotlin/features-trainer/src/org/jetbrains/kotlin/training/ift/KotlinLearningCourse.kt b/plugins/kotlin/features-trainer/src/org/jetbrains/kotlin/training/ift/KotlinLearningCourse.kt index af27c4fa3831..bd28fe64ec89 100644 --- a/plugins/kotlin/features-trainer/src/org/jetbrains/kotlin/training/ift/KotlinLearningCourse.kt +++ b/plugins/kotlin/features-trainer/src/org/jetbrains/kotlin/training/ift/KotlinLearningCourse.kt @@ -5,6 +5,7 @@ import org.jetbrains.kotlin.idea.KotlinLanguage import org.jetbrains.kotlin.training.ift.lesson.basic.KotlinBasicCompletionLesson import org.jetbrains.kotlin.training.ift.lesson.basic.KotlinContextActionsLesson import org.jetbrains.kotlin.training.ift.lesson.basic.KotlinSelectLesson +import org.jetbrains.kotlin.training.ift.lesson.basic.KotlinSurroundAndUnwrapLesson import org.jetbrains.kotlin.training.ift.lesson.navigation.KotlinFileStructureLesson import org.jetbrains.kotlin.training.ift.lesson.navigation.KotlinSearchEverywhereLesson import training.dsl.LessonUtil @@ -12,7 +13,7 @@ import training.learn.LessonsBundle import training.learn.course.LearningCourseBase import training.learn.course.LearningModule import training.learn.course.LessonType -import training.learn.lesson.general.GotoActionLesson +import training.learn.lesson.general.* class KotlinLearningCourse : LearningCourseBase(KotlinLanguage.INSTANCE.id) { override fun modules() = stableModules() @@ -40,7 +41,16 @@ class KotlinLearningCourse : LearningCourseBase(KotlinLanguage.INSTANCE.id) { primaryLanguage = langSupport, moduleType = LessonType.SCRATCH ) { - listOf(KotlinSelectLesson()) + fun ls(sampleName: String) = loadSample("EditorBasics/$sampleName") + listOf( + KotlinSelectLesson(), + CommentUncommentLesson(ls("Comment.kt.sample"), blockCommentsAvailable = true), + DuplicateLesson(ls("Duplicate.kt.sample")), + MoveLesson("run()", ls("Move.kt.sample")), + CollapseLesson(ls("Collapse.kt.sample")), + KotlinSurroundAndUnwrapLesson(), + MultipleSelectionHtmlLesson(), + ) }, LearningModule( id = "Kotlin.CodeCompletion", diff --git a/plugins/kotlin/features-trainer/src/org/jetbrains/kotlin/training/ift/lesson/basic/KotlinSurroundAndUnwrapLesson.kt b/plugins/kotlin/features-trainer/src/org/jetbrains/kotlin/training/ift/lesson/basic/KotlinSurroundAndUnwrapLesson.kt new file mode 100644 index 000000000000..b5763777b2e5 --- /dev/null +++ b/plugins/kotlin/features-trainer/src/org/jetbrains/kotlin/training/ift/lesson/basic/KotlinSurroundAndUnwrapLesson.kt @@ -0,0 +1,22 @@ +// Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. +package org.jetbrains.kotlin.training.ift.lesson.basic + +import org.jetbrains.kotlin.idea.KotlinBundle +import training.dsl.LessonSample +import training.dsl.parseLessonSample +import training.learn.lesson.general.SurroundAndUnwrapLesson + +class KotlinSurroundAndUnwrapLesson : SurroundAndUnwrapLesson() { + override val sample: LessonSample = parseLessonSample(""" + + fun main(args: Array) { + + } + """.trimIndent()) + + override val surroundItems = arrayOf("try", "catch", "finally") + + override val lineShiftBeforeUnwrap = -2 + + override val unwrapTryText = KotlinBundle.message("unwrap.expression", "try {...}") +} \ No newline at end of file diff --git a/python/python-features-trainer/src/com/jetbrains/python/ift/lesson/basic/PythonSurroundAndUnwrapLesson.kt b/python/python-features-trainer/src/com/jetbrains/python/ift/lesson/basic/PythonSurroundAndUnwrapLesson.kt index e9bf88a6013e..14e509454a65 100644 --- a/python/python-features-trainer/src/com/jetbrains/python/ift/lesson/basic/PythonSurroundAndUnwrapLesson.kt +++ b/python/python-features-trainer/src/com/jetbrains/python/ift/lesson/basic/PythonSurroundAndUnwrapLesson.kt @@ -1,6 +1,7 @@ // Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.jetbrains.python.ift.lesson.basic +import com.jetbrains.python.PyBundle import training.dsl.LessonSample import training.dsl.parseLessonSample import training.learn.lesson.general.SurroundAndUnwrapLesson @@ -16,4 +17,6 @@ class PythonSurroundAndUnwrapLesson : SurroundAndUnwrapLesson() { override val surroundItems = arrayOf("try", "except") override val lineShiftBeforeUnwrap = -2 + + override val unwrapTryText = PyBundle.message("unwrap.try") }