-
Notifications
You must be signed in to change notification settings - Fork 65
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 a builder-style utility class for injecting static method invocation instructions #132
Add a builder-style utility class for injecting static method invocation instructions #132
Conversation
|
Certainly. Done, and rebased. |
private int initOffset = -1; | ||
|
||
public int getConstructorCallOffset() { | ||
assert initOffset != -1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why so many asserts?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is to prevent requesting for the results (i.e., offset) before this visitor has a chance to visit any methods
base/src/main/java/proguard/classfile/util/ConstructorInvocationOffsetFinder.java
Show resolved
Hide resolved
new InternalTypeEnumeration(method.getDescriptor(clazz)); | ||
Iterator<InjectedArgument> argumentsIterator = Arrays.stream(arguments).iterator(); | ||
|
||
while (parametersIterator.hasNext() || argumentsIterator.hasNext()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
while (parametersIterator.hasNext() || argumentsIterator.hasNext()) { | |
while (parametersIterator.hasNext() && argumentsIterator.hasNext()) { |
Shouldnt this be an && to be safe? If somehow we erroneously have a difference in the size of parameters and arguments the next call would fail. Maybe we can properly handle that though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The ||
is rather intentional. Suppose we the parameterIterator
and argumentsIterator
has different length, we would fall through this loop so long the first part matche If we used &&
. With ||
, we can prevent this.
@Override | ||
public void visitCodeAttribute( | ||
Clazz clazz, Method method, CodeAttribute codeAttribute) { | ||
editor.reset(codeAttribute.u4codeLength); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is more of a style preference, so consider this as a nit: I prefer this to be an explicit class even if it's only used here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I personally like the asserts but I am not sure if they are really idiomatic here, we also have @NotNull
annotations here so maybe you can use those in some places?
Add an api for injecting a call to any static methods (with or without parameters) into the first block of any target methods.
2e3f84a
to
392a1f1
Compare
@@ -0,0 +1,107 @@ | |||
package proguard.classfile.util; | |||
|
|||
import proguard.classfile.*; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Expand imports.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok aside from nit.
Add an api for injecting a call to any static methods (with or without parameters) into the first block of any target methods.