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

Skip synthetic methods #79

Closed
jose opened this issue May 17, 2016 · 1 comment
Closed

Skip synthetic methods #79

jose opened this issue May 17, 2016 · 1 comment

Comments

@jose
Copy link

jose commented May 17, 2016

Hi,

I've been trying to write some code to skip synthetic methods, however does not seem to be working.
suppose I have the following class:

public class SyntheticExample {
  public static void main(String[] args) {
    System.out.println(SyntheticExample.class);
  }
}

Compiling it with Java 1.4 (yeah, it has to be 1.4) I get the following bytecode:

$ javac -source 1.4 -target 1.4 SyntheticExample.java
$ javap -v SyntheticExample

public class SyntheticExample
  flags: ACC_PUBLIC, ACC_SUPER

  public static void main(java.lang.String[]);
    flags: ACC_PUBLIC, ACC_STATIC

  static java.lang.Class class$(java.lang.String);
    flags: ACC_STATIC
    Synthetic: true

and here the code to skip synthetic methods:

for (CtMethod cb : ct.getDeclaredMethods()) {
  if ( (cb.getMethodInfo().getAccessFlags() & AccessFlag.SYNTHETIC) != 0 ) {
     continue;
  }
  // do stuff
}

it seems that cb.getMethodInfo().getAccessFlags() is returning 8 (i.e., AccessFlag.STATIC) and cb.getMethodInfo().getAccessFlags() & AccessFlag.SYNTHETIC returns 0, for method "class$".

am I doing something wrong? how can I identify (and skip) synthetic methods?

-- Thanks in advance.

@jose
Copy link
Author

jose commented May 17, 2016

answered in #39 .

To do that, you have to check the existence of the Synthetic attribute.
Check MethodInfo#getAttribute(SyntheticAttribute.tag) != null

-- Thanks @chibash

@jose jose closed this as completed May 17, 2016
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

No branches or pull requests

1 participant