-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
ICodeAnnotation
positions sometimes don't take code comments into account
#2141
Comments
ICodeAnnotation
positions in CodeInfo
sometimes don't adjust to code commentsICodeAnnotation
positions sometimes don't take code comments into account
@NebelNidas looks like something not updated or cached. |
Sure thing! The code is here: FabricMC/Enigma#522 |
I found the issue. ...
JavaClass cls = jadx.getClasses().get(0);
AtomicReference<ICodeInfo> codeInfoRef = new AtomicReference<>();
runWithFixedLineSeparator(() -> {
ICodeInfo codeInfo = cls.getCodeInfo(); // decompilation done here
codeInfoRef.set(codeInfo);
index = new SourceIndex(codeInfo.getCodeStr());
});
// Tokens
ICodeInfo codeInfo = codeInfoRef.get();
codeInfo.getCodeMetadata().searchDown(0, (pos, ann) -> {
processAnnotatedElement(pos, ann, codeInfo);
return null;
}); I use Long version: |
Thanks for the fix, seems to work fine!
I think caching the result is the best solution for this specific situation, decompiling every time would be a waste of resources :) |
Running
javaClass.getCodeInfo().getCodeMetadata().searchDown
for the following decompilation result:results in the token positions 81, 125, 176, 228 (expand to see highlights generated by Enigma).
Then I used this code to add comments to classes/fields/methods:
token positions correctly offset by 25 (char count of
//
+ comment + LF): 106, 150, 201, 253The janky approach above was necessary because JADX 1.4 didn't offer better APIs. After having upgraded to the latest master build, I wanted to make this cleaner, so I switched to using a plugin instead (more or less a 1:1 copy of the
rename-mappings
plugin, reduced to just the code-comment providing code). Surprisingly however, this results in JADX reporting misplaced token positions, they don't seem to take into account the additional offset caused by the comments:token positions unchanged at 81, 125, 176, 228
The text was updated successfully, but these errors were encountered: