JetPsiCheckerTest and its testdata moved back to plugin tests
This commit is contained in:
@@ -0,0 +1,121 @@
|
||||
import java.util.*
|
||||
|
||||
namespace html {
|
||||
|
||||
abstract class Factory<T> {
|
||||
abstract fun create() : T
|
||||
}
|
||||
|
||||
abstract class Element
|
||||
|
||||
class TextElement(val text : String) : Element
|
||||
|
||||
abstract class Tag(val name : String) : Element {
|
||||
val children = ArrayList<Element>()
|
||||
val attributes = HashMap<String, String>()
|
||||
|
||||
protected fun initTag<T : Element>(init : fun T.() : Unit) : T
|
||||
where class object T : Factory<T>{
|
||||
val tag = T.create()
|
||||
tag.init()
|
||||
children.add(tag)
|
||||
return tag
|
||||
}
|
||||
}
|
||||
|
||||
abstract class TagWithText(name : String) : Tag(name) {
|
||||
fun String.plus() {
|
||||
children.add(TextElement(this))
|
||||
}
|
||||
}
|
||||
|
||||
class HTML() : TagWithText("html") {
|
||||
class object : Factory<HTML> {
|
||||
override fun create() = HTML()
|
||||
}
|
||||
|
||||
fun head(init : fun Head.() : Unit) = initTag<Head>(init)
|
||||
|
||||
fun body(init : fun Body.() : Unit) = initTag<Body>(init)
|
||||
}
|
||||
|
||||
class Head() : TagWithText("head") {
|
||||
class object : Factory<Head> {
|
||||
override fun create() = Head()
|
||||
}
|
||||
|
||||
fun title(init : fun Title.() : Unit) = initTag<Title>(init)
|
||||
}
|
||||
|
||||
class Title() : TagWithText("title")
|
||||
|
||||
abstract class BodyTag(name : String) : TagWithText(name) {
|
||||
}
|
||||
|
||||
class Body() : BodyTag("body") {
|
||||
class object : Factory<Body> {
|
||||
override fun create() = Body()
|
||||
}
|
||||
|
||||
fun b(init : fun B.() : Unit) = initTag<B>(init)
|
||||
fun p(init : fun P.() : Unit) = initTag<P>(init)
|
||||
fun h1(init : fun H1.() : Unit) = initTag<H1>(init)
|
||||
fun a(href : String, init : fun A.() : Unit) {
|
||||
val a = initTag<A>(init)
|
||||
a.href = href
|
||||
}
|
||||
}
|
||||
|
||||
class B() : BodyTag("b")
|
||||
class P() : BodyTag("p")
|
||||
class H1() : BodyTag("h1")
|
||||
class A() : BodyTag("a") {
|
||||
var href : String
|
||||
get() = attributes["href"]
|
||||
set(value) { attributes["href"] = value }
|
||||
}
|
||||
|
||||
fun Map<String, String>.set(key : String, value : String) = this.put(key, value)
|
||||
|
||||
fun html(init : fun HTML.() : Unit) : HTML {
|
||||
val html = HTML()
|
||||
html.init()
|
||||
return html
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
namespace foo {
|
||||
|
||||
import html.*
|
||||
|
||||
fun result(args : Array<String>) =
|
||||
html {
|
||||
head {
|
||||
title {+"XML encoding with Groovy"}
|
||||
}
|
||||
body {
|
||||
h1 {+"XML encoding with Groovy"}
|
||||
p {+"this format can be used as an alternative markup to XML"}
|
||||
|
||||
// an element with attributes and text content
|
||||
a(href = "http://groovy.codehaus.org") {+"Groovy"}
|
||||
|
||||
// mixed content
|
||||
p {
|
||||
+"This is some"
|
||||
b {+"mixed"}
|
||||
+"text. For more see the"
|
||||
a(href = "http://groovy.codehaus.org") {+"Groovy"}
|
||||
+"project"
|
||||
}
|
||||
p {+"some text"}
|
||||
|
||||
// content generated by
|
||||
p {
|
||||
for (arg in args)
|
||||
+arg
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user