Skip to content

Commit

Permalink
Merge pull request #200 from FlintMC/bugfix/remove-field-class-prefix
Browse files Browse the repository at this point in the history
Remove class name in front of fields in the same class
  • Loading branch information
zortax committed May 27, 2021
2 parents 66e85fe + 6e50339 commit ac226ea
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
Expand Up @@ -98,10 +98,13 @@ public CtMethod generateInjector(
target.addField(injectorField);

String getterName = "getMethodInjector_" + injectorName;
String fieldAccessor =
(moved ? injectorField.getDeclaringClass().getName() + "." : "") + injectorName;

String generate =
String.format(
"if (%s == null) { %1$s = %s.generate(%s.getDefault().getMethod(\"%s\", \"%s\"), %s.class); }",
injectorField.getDeclaringClass().getName() + "." + injectorName,
fieldAccessor,
injectedFactory.getName(),
ClassPool.class.getName(),
targetClass,
Expand All @@ -111,7 +114,7 @@ public CtMethod generateInjector(
CtMethod.make(
String.format(
"public static %s %s() { %s return %s; }",
ifc.getName(), getterName, generate, injectorName),
ifc.getName(), getterName, generate, fieldAccessor),
target);

try {
Expand Down
Expand Up @@ -143,12 +143,17 @@ private void insert(
.get()
.generateInjector(target.getDeclaringClass(), hookMethod, HookInjector.class);

String getterDeclaringName = getter.getDeclaringClass().equals(target.getDeclaringClass())
? ""
: getter.getDeclaringClass().getName();
String getterSrc =
(getterDeclaringName.isEmpty() ? "" : getterDeclaringName + ".") + getter.getName();

// getMethodInjector().notifyHook(instance, args, executionTime)
String notify =
String.format(
"%s.%s().notifyHook(%s, $args, net.flintmc.transform.hook.Hook.ExecutionTime.%s);",
getter.getDeclaringClass().getName(),
getter.getName(),
"%s().notifyHook(%s, $args, net.flintmc.transform.hook.Hook.ExecutionTime.%s);",
getterSrc,
Modifier.isStatic(target.getModifiers()) ? "null" : "$0",
executionTime);
String varName = "hookNotifyResult";
Expand Down

0 comments on commit ac226ea

Please sign in to comment.