[IFT] Complete Editor Basics module for Kotlin

GitOrigin-RevId: 5149c76760979206dde31b6bb8d753b8754e419d
This commit is contained in:
Konstantin Hudyakov
2022-02-09 06:47:07 +00:00
committed by intellij-monorepo-bot
parent 8c4afdc7d4
commit 828cdf1ada
9 changed files with 102 additions and 5 deletions
@@ -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")
}
@@ -15,6 +15,7 @@ abstract class SurroundAndUnwrapLesson
protected abstract val surroundItems: Array<String>
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 {
@@ -0,0 +1,26 @@
import kotlin.math.abs
@Throws(CheckEngineException::class)
fun Engine.startEngineAndLog() {
callStarter()
println("Engine started!")
}
fun <caret>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()
@@ -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)
<caret>val red = rgb shr 16 and 0xFF
val green = rgb shr 8 and 0xFF
val blue = rgb and 0xFF
}
@@ -0,0 +1,5 @@
fun main(args: Array<String>) {
println("Hello world!")
println("Hello world!")<caret>
}
@@ -0,0 +1,17 @@
class MoveDemo : Thread() {
var started = false
private fun printDebugMessage() {
println("Hello from a thread!")
}
override fun run() {
<caret>started = true
printDebugMessage()
}
}
fun main(args: Array<String>) {
MoveDemo().start()
}
@@ -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",
@@ -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<String>) {
<select>println("Surround and Unwrap me!")</select>
}
""".trimIndent())
override val surroundItems = arrayOf("try", "catch", "finally")
override val lineShiftBeforeUnwrap = -2
override val unwrapTryText = KotlinBundle.message("unwrap.expression", "try {...}")
}
@@ -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")
}