Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Java Model Decorators (beta) #217

Merged
merged 1 commit into from
Jun 14, 2019

Conversation

RicoYao
Copy link
Contributor

@RicoYao RicoYao commented Jun 6, 2019

Adds the ability to pass in an accompanying decorations file for:

  • Extending a class
  • Implementing interfaces
  • Adding annotations to the class, property variables, property getters, other methods
  • Specifying additional imports

Example usage:
plank --lang=java --java_decorations_beta=decorations.json my_model.json

decorations.json:

{
    "class": {
        "extends": "BaseModel",
        "implements": ["ModelInterface"],
        "annotations": ["CustomAnnotation"]
    },
    "constructor" : {
        "annotations": ["CustomAnnotation"]
    },
    "properties": {
        "my_property": {
            "variable": {
                "annotations": ["CustomAnnotation"]
            },
            "getter": {
                "annotations": ["CustomAnnotation"]
            }
        }
    },
    "methods": {
        "mergeFrom": {
            "annotations": ["CustomAnnotation"]
        }
    },
    "imports": [
        "com.test.package.BaseModel",
        "com.test.package.ModelInterface",
        "com.test.package.CustomAnnotation"
    ]
}

@rahul-malik
Copy link
Collaborator

@RicoYao - Why would we do extension in the decorators file vs the schema? We have support for extends which I assume would be sufficient here

@RicoYao
Copy link
Contributor Author

RicoYao commented Jun 6, 2019

@RicoYao - Why would we do extension in the decorators file vs the schema? We have support for extends which I assume would be sufficient here

@rahul-malik Perhaps I misunderstood our last discussion, but I believe extends in the schema is meant to be used for inheriting properties, but not to actually define class extension. That was a design decision that predates my involvement, but I agree with it FWIW, as we don't want to encourage class extension.

@RicoYao RicoYao force-pushed the java_model_decorations branch 2 times, most recently from 018e2c8 to 5c765b9 Compare June 13, 2019 20:38
@@ -128,7 +141,7 @@ public struct JavaModelRenderer: JavaFileRenderer {
"this." + Languages.java.snakeCaseToPropertyName(param) + " = value;",
] }
}
return setters + [JavaIR.method([], "set_bits(int bits)") { [
return setters + [JavaIR.method([], "void set_bits(boolean[] bits)") { [
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had fixed this in a local branch, and didn't realized I hadn't pushed it any PRs. I can split out into a separate PR if we prefer.

@RicoYao RicoYao merged commit bc8c8fd into pinterest:master Jun 14, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants