Skip to content

Commit c250bae

Browse files
authored
Resolve inner classes from byte code in source code (#10)
1 parent 0bf0625 commit c250bae

File tree

5 files changed

+36
-1
lines changed

5 files changed

+36
-1
lines changed

src/main/java/org/minimallycorrect/javatransformer/internal/ResolutionContext.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,10 +246,16 @@ private Type resolveClassType(String name) {
246246
// inner class in imported class
247247
if (preDotName != null && importName.endsWith(preDotName)) {
248248
String fullName = importName + postDotName;
249+
// TODO: we can either resolve with $ or . here depending on if in source or byte code
250+
// should make consistent by always using $ for inner class names
249251
Type type = resolveIfExists(fullName);
250252
if (type != null) {
251253
return type;
252254
}
255+
type = resolveIfExists(importName + postDotName.replace('.', '$'));
256+
if (type != null) {
257+
return type;
258+
}
253259
}
254260
}
255261

src/main/java/org/minimallycorrect/javatransformer/internal/util/JVMUtil.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,9 @@ public static int accessStringToInt(String access) {
137137
case "synthetic":
138138
a |= AccessFlags.ACC_SYNTHETIC;
139139
break;
140+
case "final":
141+
a |= AccessFlags.ACC_FINAL;
142+
break;
140143
default:
141144
throw new TransformationException("Unknown access string " + access);
142145
}

src/test/java/org/minimallycorrect/javatransformer/api/JavaTransformerTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ public void testTransform() throws Exception {
9393
c.getMembers().collect(Collectors.toList());
9494
c.getConstructors().collect(Collectors.toList());
9595
c.getMethods().forEach(it -> {
96-
it.getReturnType();
96+
val rt = it.getReturnType();
9797

9898
val cf = it.getCodeFragment();
9999

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package org.minimallycorrect.javatransformer.transform;
2+
3+
public @interface AnnotationInnerClassExample {
4+
enum TestEnum {
5+
ONE,
6+
TWO
7+
}
8+
}

src/test/java/org/minimallycorrect/javatransformer/transform/InnerClassReferencer.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package org.minimallycorrect.javatransformer.transform;
22

3+
import java.lang.invoke.MethodHandles;
4+
35
public class InnerClassReferencer {
46
public InnerClassExample.Inner test1() {
57
throw new UnsupportedOperationException();
@@ -8,4 +10,20 @@ public InnerClassExample.Inner test1() {
810
public org.minimallycorrect.javatransformer.transform.InnerClassExample.Inner2 test2() {
911
throw new UnsupportedOperationException();
1012
}
13+
14+
public AnnotationInnerClassExample.TestEnum test3() {
15+
throw new UnsupportedOperationException();
16+
}
17+
18+
public org.minimallycorrect.javatransformer.transform.AnnotationInnerClassExample.TestEnum test4() {
19+
throw new UnsupportedOperationException();
20+
}
21+
22+
public MethodHandles.Lookup test5() {
23+
throw new UnsupportedOperationException();
24+
}
25+
26+
public java.lang.invoke.MethodHandles.Lookup test6() {
27+
throw new UnsupportedOperationException();
28+
}
1129
}

0 commit comments

Comments
 (0)