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

Add annotations to field getters, param getters and instance getters #22

Open
1 of 3 tasks
Mingun opened this issue Jan 9, 2020 · 2 comments
Open
1 of 3 tasks

Comments

@Mingun
Copy link
Contributor

Mingun commented Jan 9, 2020

If you want to build visualizer, you must rely on that fact, that internal fields begins with underscore. You can use the static field _seqFields to distinguish between parameters and structure fields. To distinguish between parameters and instances of the structure, you can see that there is a field with the same name, as getter method. If there is no field, it is an instance. No, this not work, instances also has backing field in class

But all these methods are fragile. I suggest introduce 3 annotations instead:

@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
@Documented
public @interface Parameter {
  String doc();// documentation
}

@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
@Documented
public @interface Field {
  String doc();// documentation
}

@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
@Documented
public @interface Instance {
  String doc();// documentation
}

List of all related issues/PRs:

@Mingun Mingun changed the title Add annotations to field getters, parem getters and instances getters Add annotations to field getters, param getters and instance getters Jan 9, 2020
Mingun added a commit to Mingun/kaitai_struct_java_runtime that referenced this issue Jan 11, 2020
Mingun added a commit to Mingun/kaitai_struct_java_runtime that referenced this issue Jan 11, 2020
@GreyCat
Copy link
Member

GreyCat commented Jan 11, 2020

From what I understand, adding these annotations would allow to use reflection in runtime to determine if given member is:

  • a "parameter" (understandable)
  • a "field" (what is a "field", actually? an attribute in a seq?)
  • an "instance" (probably you'll want to distinguish between "parse instances" and "value instances"?).

Which problems does that solve and how does that help with the questions that you've outlined above, i.e.:

  • determining whether a member is internal field or not
  • determining sequence of seq attributes

?

@Mingun
Copy link
Contributor Author

Mingun commented Jan 12, 2020

a "field" (what is a "field", actually? an attribute in a seq?)

Yes

an "instance" (probably you'll want to distinguish between "parse instances" and "value instances"?).

No, I think not. I just want to mark fields/getters/[setters], that generated from instances map. If I understand correctly, you mean

determining whether a member is internal field or not

Right now you are forced to use dirty haks to exclude fields, that is not fields, like checking name of field for leading underscore. With annotation you just go through all fields with these annotations

determining sequence of seq attributes

Initially, I hoped, that field sequence in the class will reflect order in seq. But, unfortunally, Java does not guaranties, that method or field will in some order (for example, in Java 10, this is the reverse order of defining fields in a class), so in actual proposal I included index parameter

Mingun added a commit to Mingun/kaitai_struct_java_runtime that referenced this issue Jan 14, 2020
Mingun added a commit to Mingun/kaitai_struct_java_runtime that referenced this issue Aug 14, 2020
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 a pull request may close this issue.

2 participants