Git Product home page Git Product logo

javapoet-dsl's Introduction

Travis CI Codecov Maven Central Plugin Portal

Any nitwit can understand computers. Many do.

โ€” Ted Nelson (1974)

javapoet-dsl's People

Contributors

hendraanggrian avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

kevinherron

javapoet-dsl's Issues

Can't escape usage of '%' in code blocks

I don't see any way to escape usages of % in code blocks, e.g.:

appendln(
    """
    xmlDictionary.registerEnumCodec(
        new ${'$'}T.Codec().asXmlCodec(),
        String.format("//xs:element[@name='%s']", "$typeName"),
        $typeName.getTypeId().local(namespaceTable).orElseThrow(
            () -> new IllegalStateException("namespace not registered: " + NAMESPACE_URI))
    )
    """.trimIndent(),
    ClassName.get(enumTypePackageName, typeName)
)

will fail with:

Exception in thread "main" java.lang.IllegalArgumentException: index 2 for '$s' not in range (received 1 arguments)
	at com.squareup.javapoet.Util.checkArgument(Util.java:53)
	at com.squareup.javapoet.CodeBlock$Builder.add(CodeBlock.java:287)
	at com.squareup.javapoet.CodeBlock$Builder.addStatement(CodeBlock.java:402)
	at com.squareup.javapoet.MethodSpec$Builder.addStatement(MethodSpec.java:480)
	at com.hendraanggrian.javapoet.MethodSpecBuilder.appendln(MethodSpecs.kt:155)

because of my usage of %s.

`nativeBuilder` field should be visible

I'm slowly converting some code to use this DSL and have found that I need access to the underlying nativeBuilder field to ease the transition.

For example, whilst in the middle of defining a type using the DSL, I need to define another inner type. The DSL offers these functions:

    override fun type(name: String, builder: (TypeSpecBuilder.() -> Unit)?) {
        nativeBuilder.addType(buildTypeSpec(name, builder))
    }

    override fun type(className: ClassName, builder: (TypeSpecBuilder.() -> Unit)?) {
        nativeBuilder.addType(buildTypeSpec(className, builder))
    }

but these require me to rewrite the code for the type I'm trying to add in the DSL as well. What I'd rather do in the meantime is something like:

nativeBuilder.addType(generateFooTypeSpec())

where generateFooTypeSpec() is a method that returns a JavaPoet TypeSpec.

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.