Skip to content
This repository was archived by the owner on Mar 18, 2024. It is now read-only.

Commit 22f1e22

Browse files
Update examples with the new plugins (#53)
1 parent 9868284 commit 22f1e22

File tree

36 files changed

+553
-601
lines changed

36 files changed

+553
-601
lines changed

.github/workflows/build.yml

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,17 @@ jobs:
1515
echo "$JAVA_HOME_8_X64/bin" >> $GITHUB_PATH
1616
echo "JAVA_HOME=$JAVA_HOME_8_X64" >> $GITHUB_ENV
1717
- uses: actions/checkout@v2
18-
- name: "Build example: Hello World"
19-
working-directory: hello-world
18+
- name: "Refined Types compile demo"
19+
working-directory: demos
2020
run: |
21-
./gradlew clean build
22-
java -jar use-plugin/build/libs/use-plugin.jar
23-
- name: "Build example: use of Arrow Meta Compiler Plugin with Gradle Plugin"
24-
working-directory: use-arrow-meta-compiler-plugins
25-
run: ./gradlew clean build
26-
- name: "Build example: create new plugin to generate sources"
21+
./gradlew :refined-types-compiler-plugin-demo:assemble 2> error.log || echo "Compilation failed as expected!"
22+
grep -e "-1 should be even" error.log
23+
- name: "Refined Types runtime demo"
24+
working-directory: demos
25+
run: ./gradlew :refined-types-library-demo:build
26+
- name: "Optics Compiler Plugin demo"
27+
working-directory: demos
28+
run: ./gradlew :optics-compiler-plugin-demo:build
29+
- name: "Create new plugin to generate sources"
2730
working-directory: generate-sources
2831
run: ./gradlew clean build

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@
33
*.iml
44
build
55
*.meta
6+
*.log

README.md

Lines changed: 6 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -4,73 +4,23 @@
44

55
Some examples for [Λrrow Meta](https://github.com/arrow-kt/arrow-meta/) the functional companion to Kotlin's Compiler & IDE.
66

7-
## Hello World Compiler Plugin
8-
9-
![Hello World Compiler Plugin Demo](https://github.com/arrow-kt/arrow-meta/raw/main/docs/docs/img/demos/hello-world-compiler-plugin.gif)
10-
11-
The following example shows a Hello World Compiler Plugin.
12-
The Hello World plugin auto implements the `helloWorld` function by rewriting the Kotlin AST before the compiler proceeds.
13-
14-
```kotlin
15-
val Meta.helloWorld: CliPlugin
16-
get() =
17-
"Hello World" {
18-
meta(
19-
namedFunction(this, { element.name == "helloWorld" }) { (c, _) ->
20-
Transform.replace(
21-
replacing = c,
22-
newDeclaration =
23-
"""|fun helloWorld(): Unit =
24-
| println("Hello ΛRROW Meta!")
25-
|""".function(descriptor).syntheticScope
26-
)
27-
}
28-
)
29-
}
30-
```
31-
32-
For any user code whose function name is `helloWorld` our compiler plugin will replace the matching function for a
33-
function that returns Unit and prints our message.
34-
35-
```diff
36-
- fun helloWorld(): Unit = TODO()
37-
+ fun helloWorld(): Unit =
38-
+ println("Hello ΛRROW Meta!")
39-
```
40-
41-
### How to run it from IDE
42-
43-
1. Create a new project from existing sources: `hello-world` directory
44-
2. Open `use-plugin/src/main/kotlin/io/arrowkt/example/HelloWorld.kt`
45-
3. Run `main` function
46-
47-
### How to run it from command line
48-
49-
```
50-
cd hello-world
51-
./gradlew clean build
52-
java -jar use-plugin/build/libs/use-plugin.jar
53-
```
54-
55-
## Use of Λrrow Meta Compiler Plugin
56-
57-
Λrrow Meta Compiler Plugin can be used through Λrrow Meta Gradle Plugin.
7+
## Use of Compiler Plugins created with Arrow Meta
588

599
### How to run it from IDE
6010

61-
1. Create a new project from existing sources: `use-arrow-meta-compiler-plugins` directory
62-
2. Build project to run the test
11+
1. Create a new project from existing sources: `demos` directory
12+
2. Build root project
6313

6414
### How to run it from command line
6515

6616
```
67-
cd use-arrow-meta-compiler-plugins
17+
cd demos
6818
./gradlew clean build
6919
```
7020

71-
## Other examples
21+
## Use of Λrrow Meta to create other Compiler Plugins
7222

73-
* Create a new plugin to generate sources: `generate-sources` directory
23+
* Create a new compiler plugin to generate sources: `generate-sources` directory
7424

7525
## License
7626

demos/build.gradle

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/*
2+
* Copyright (C) 2021 The Arrow Authors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
plugins {
18+
id "org.jetbrains.kotlin.jvm" version "$KOTLIN_VERSION"
19+
}
20+
21+
subprojects {
22+
compileKotlin {
23+
kotlinOptions {
24+
jvmTarget = "$JVM_TARGET_VERSION"
25+
}
26+
}
27+
28+
compileTestKotlin {
29+
kotlinOptions {
30+
jvmTarget = "$JVM_TARGET_VERSION"
31+
}
32+
}
33+
}
34+
35+
allprojects {
36+
repositories {
37+
mavenCentral()
38+
maven { url 'https://oss.sonatype.org/content/repositories/snapshots/' }
39+
}
40+
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)