Coder Social home page Coder Social logo

arrow-kt / arrow-meta-examples Goto Github PK

View Code? Open in Web Editor NEW
58.0 9.0 20.0 157 KB

Some examples for Λrrow Meta the functional companion to Kotlin's Compiler & IDE.

License: Apache License 2.0

Kotlin 100.00%
metaprogramming quasiquote template-metaprogramming compiler-plugin kotlin-compiler kotlin kotlin-multiplatform typesystem macros linter

arrow-meta-examples's Introduction

Λrrow Meta examples

Build

Some examples for Λrrow Meta the functional companion to Kotlin's Compiler & IDE.

Use of Compiler Plugins created with Arrow Meta

How to run it from IDE

  1. Create a new project from existing sources: demos directory
  2. Build root project

How to run it from command line

cd demos
./gradlew clean build

Use of Λrrow Meta to create other Compiler Plugins

  • Create a new compiler plugin to generate sources: generate-sources directory

License

Copyright (C) 2019 The Λrrow Authors

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

arrow-meta-examples's People

Contributors

arturdryomov avatar danimontoya avatar rachelcarmena avatar raulraja avatar rcd27 avatar stabbylambda avatar toxyduck avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

arrow-meta-examples's Issues

avoid code generation in source folder

I tried the hello world example of arrow meta and I am so far convinced of what I see.

With one exception - after doing a ./gradlew clean build, I got a file "HelloWorld.kt.meta" in the src folder. That is nice for debug purpose, but bad in production.

Is there a way to avoid this file or at least to put it into the build folder? I didn't find a way to do that.

get complete qualifier for class

I'm using an annotation to detect a class where code creation should happen.

Now I did not find any possibility to detect the whole qualifier name.

The only thing I could find was:

fun KtAnnotationEntry.toName() = typeReference?.typeElement?.safeAs<KtUserType>()?.referencedName

But this what only give me the simple name.

Assuming, I have two annotations like: org.my.annotation.example1.FilterAnnotation and org.my.annotation.example2.FilterAnnotation.

How can be distinguished between this two?

Is there at least a possibility to get the imports of the file?

Would be thankful for some help.

Best regards

There's not too many times you get a chance to make a second first impression.

I follow the instruction on the readme.md at this address
https://github.com/arrow-kt/arrow-meta-examples

git clone https://github.com/arrow-kt/arrow-meta-examples


Cloning into 'arrow-meta-examples'...
remote: Enumerating objects: 684, done.
remote: Counting objects: 100% (162/162), done.
remote: Compressing objects: 100% (69/69), done.
remote: Total 684 (delta 107), reused 105 (delta 79), pack-reused 522
Receiving objects: 100% (684/684), 162.92 KiB | 156.00 KiB/s, done.
Resolving deltas: 100% (238/238), done.

so far so good.
Then
cd arrow-meta-examples/

(base) pascal@pascal-MS-7B79:~/code/github/arrow-meta-examples$ cd demos/
(base) pascal@pascal-MS-7B79:~/code/github/arrow-meta-examples/demos$ ./gradlew clean build
Downloading https://services.gradle.org/distributions/gradle-6.8.3-bin.zip
......................................................................................................

Welcome to Gradle 6.8.3!

Here are the highlights of this release:
 - Faster Kotlin DSL script compilation
 - Vendor selection for Java toolchains
 - Convenient execution of tasks in composite builds
 - Consistent dependency resolution

For more details see https://docs.gradle.org/6.8.3/release-notes.html

Starting a Gradle Daemon (subsequent builds will be faster)

> Configure project :optics-compiler-plugin-demo
Applying arrow-optics-plugin for optics-compiler-plugin-demo ...

> Configure project :refined-types-compiler-plugin-demo
Applying arrow-refined-types-plugin for refined-types-compiler-plugin-demo ...

> Task :optics-compiler-plugin-demo:compileKotlin
w: /home/pascal/code/github/arrow-meta-examples/demos/optics-compiler-plugin-demo/src/main/kotlin/io/arrowkt/example/Context.kt: (15, 14): Condition 'i != null' is always 'true'

> Task :optics-compiler-plugin-demo:test

LensTest > Lenses will be generated for data class() PASSED

> Task :refined-types-compiler-plugin-demo:compileKotlin FAILED
e: -1 should be > 0, -1 should be even : io.arrowkt.example.PositiveIntEven.Companion.invoke

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':refined-types-compiler-plugin-demo:compileKotlin'.
> Compilation error. See log for more details

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 1m 13s
12 actionable tasks: 8 executed, 4 up-to-date
(base) pascal@pascal-MS-7B79:~/code/github/arrow-meta-examples/demos$ 

I am just discovering your repository.
It feels that you're right -1 is not even and positive but we expect this to be caught don't we?

New samples since `qoutes` are removed.

There are outdated examples with slightly differenet API calls. Now we have IR backend, so it takes more time to figure out how Meta works.

I'm ready to rewrite the existing samples/create new one(for example, logging injection in the function call), just ping me here.

`syntheticScope`causes an error: `Unresolved reference: synthetic`

I have been playing with the generate source samples combined with the example in the docs to generate a local compiler plugin plus a consumer

When I run the project, I get this error:

Unresolved reference: synthetic

If I remove syntethicScope, it works:

val Meta.helloWorld: CliPlugin get() =
  "Hello World" {
    meta(
      namedFunction(this, { element.name == "helloWorld" }) { (c, _) ->  // <-- namedFunction(...) {...}
        Transform.replace(
          replacing = c,
          newDeclaration = """|fun helloWorld(): Unit =
                              |  println("Hello ΛRROW Meta!")
                              |""".function(descriptor)
								  .syntheticScope // delete this line
        )
      }
    )
  }

Is there any wrong with my setup?

I just copied the generate sources samples and I changed I bit the code to use replace instead of newSources.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.