Skip to content

Bindings for selected fields only #6

@ghost

Description

Hi,
Im very interested in using bindgen in my project but I have one problem.

Now when I annotate my class with @bindable Bindgen generates binding for all fields, methods etc.
I would like to limit this to only few fields. I know that I can do this with "scope" or "skip attribute" in binding.properties but this solution has two issues:

1)its hard to "synchronize" class source file with this file. Every time I add field or method to the class which should not be bindable I have to modify binding.properties file. With a lot of bindable classes binding.properties could be quite large and messy.
2)attribute names in binding.properties are strings, when your refactor your code (move or change attribute name) you have to change binding.properties file as well. As I understand purpose of Bindgen it was created to not put attribute/method names in strings.

I have an idea how to limit bindings without using binding.properties file.

First I propose to add "scope"attribute to Bindable anotation. It could have values: ALL, FIELDS, METHODS, NONE...
Default value could be ALL

So @bindable is equivalent to @bindable(scope=ALL) - backward comability

@bindable(scope=FIELDS) generates bindings just for fields, METHOS for methods etc.
If you would like to generate bindings just for few (from many) fields you could use:

@bindable(scope=NONE)

and put @bindable (or simillar) annotation next to field:

@bindable int age;

For me(and probably not only for me) @bindable(scope=NONE) is prefered way of work, so it would be nice to add to binding.properties setting like "defaultScope" - when you add to the binding.properties something like:
defaultScope=NONE
than
@binding is equivalent to @binding(scope=NONE).

@binding (scope=NONE) has adventage because it allows you to fully control behaviour of framework - you could select (by annotating them with @bindable or similar) fields or methos which should be annotated.

It is only an idea, implementation details could vary, for example it could also looks like this:
@bindable(fields=true, methods=true)

Going futher it would be nice to have more control over field/method selection, for example:
@bindable(fields=PROTECTED, methods=PUBLIC)

Going more further it would be nice to have AspectJ(or regexp) like expressions:

@bindable(fields="public int " methods=" int bindbale_(_)")
this means:
genrate bindings for all public int fields
and generate bindings for all methods returning int where method name starts with bindable

Im very interested in Bindgen, so If you need any help in extending this framework I could help.

Regards Daniel

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions