commons-bcel icon indicating copy to clipboard operation
commons-bcel copied to clipboard

added accessors to model and unit tests, javadoc comments

Open nbauma109 opened this issue 2 years ago • 6 comments
trafficstars

  • Added accessors to the module classes. Until now, the fields could only be accessed by reflection and by calling setAccessible(true). The getters return the values from the constant pool as opposed to indexes for more convenient usage.
  • Added getter for the local variable type table, similarly to local variable table. They go together, it makes sense to have both instead of one of them.
  • Added getAttribute to search attribute by tag. It will avoid iterating through attributes find an attribute or streaming the attributes like this Stream.of(getAttributes()).filter(MyAttribute.class::isInstance).findFirst()

nbauma109 avatar Dec 05 '22 16:12 nbauma109

Unable to resolve action actions/[email protected], unable to find version v3.7.0

nbauma109 avatar Dec 05 '22 16:12 nbauma109

Codecov Report

Attention: Patch coverage is 94.44444% with 4 lines in your changes missing coverage. Please review.

Project coverage is 65.88%. Comparing base (f32c53c) to head (fa99fd0). Report is 166 commits behind head on master.

Files Patch % Lines
...rc/main/java/org/apache/bcel/classfile/Module.java 86.66% 1 Missing and 1 partial :warning:
...java/org/apache/bcel/classfile/ModuleProvides.java 84.61% 1 Missing and 1 partial :warning:
Additional details and impacted files
@@             Coverage Diff              @@
##             master     #183      +/-   ##
============================================
+ Coverage     65.10%   65.88%   +0.77%     
- Complexity     3893     3995     +102     
============================================
  Files           364      366       +2     
  Lines         15657    15801     +144     
  Branches       1956     1969      +13     
============================================
+ Hits          10194    10410     +216     
+ Misses         4549     4465      -84     
- Partials        914      926      +12     

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

codecov-commenter avatar Dec 06 '22 06:12 codecov-commenter

Hi @garydgregory Please help moving forward with this PR Thanks !

nbauma109 avatar Apr 02 '23 09:04 nbauma109

This PR has no description, why is it needed?

garydgregory avatar Apr 07 '23 23:04 garydgregory

That's a lot of new APIs for one PR, are ALL of these new APIs actually used? If not, let's split this up since a PR where APIs are actually used from main, and another for the other APIs, otherwise this feels like we would be adding APIs for the sake of adding APIs. TY!

I want to avoid reflection hacks (i.e., setAccessible(true)), example here: https://github.com/nbauma109/jd-core/blob/0bcbf35f700f0cc48e1ef79456c37f9168f527ff/src/main/java/org/jd/core/v1/service/converter/classfiletojavasyntax/processor/ConvertClassFileProcessor.java#L375

I want to avoid recycling this boilerplate pattern for every single attribute:

MyAttribute attr = (MyAttribute) Stream.of(fieldOrMethod.getAttributes()).filter(MyAttribute.class::isInstance).findAny().orElse(null);

I have lots of them in that same class ConvertClassFileProcessor and in LocalVariableMaker.

Other example for local variable type table: https://github.com/nbauma109/jd-core/blob/0bcbf35f700f0cc48e1ef79456c37f9168f527ff/src/main/java/org/jd/core/v1/service/converter/classfiletojavasyntax/util/ByteCodeWriter.java#L525

Also not sure what you mean by "are these new APIs actually used?", as far as I understand, they can't be used until they're published. I happen to create SNAPSHOTs of my forked BCEL for myself to check everything works as I want but that's it.

nbauma109 avatar Apr 08 '23 17:04 nbauma109

@nbauma109 Thank you for the reply and please accept my apologies for the delay, I'll come back around to this PR this week.

garydgregory avatar Sep 05 '23 11:09 garydgregory

Hi, any chance to get this in ? What version should I use for the @since tags ?

nbauma109 avatar May 26 '24 19:05 nbauma109

Hi @nbauma109

I apologize for the delay.

  • The next version for new APIs should be @since 6.10.0
  • Please rebase on git master
  • Run mvn (by itself) and make sure the build passes. It may not if there are not enough tests to cover the new code. All new public and protected methods should have matching tests

garydgregory avatar Jun 15 '24 01:06 garydgregory

Hi @garydgregory

Can you enable the workflows ?

Thanks.

nbauma109 avatar Jun 15 '24 08:06 nbauma109

Hi @markro49 Would you have any issues on your end with this PR? Looks good to me.

garydgregory avatar Jun 15 '24 11:06 garydgregory

Merged, TY @markro49 !

garydgregory avatar Jun 21 '24 21:06 garydgregory