Skip to content

Commit 189b565

Browse files
committed
put ClassInfo into cache earlier to allow referencing from its members
1 parent 8965d08 commit 189b565

File tree

4 files changed

+11
-10
lines changed

4 files changed

+11
-10
lines changed

src/main/java/com/probejs/info/clazz/BaseMemberInfo.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
@Data
99
@AllArgsConstructor
10-
@NoArgsConstructor
1110
public class BaseMemberInfo {
1211
protected String name;
1312
protected IType type;

src/main/java/com/probejs/info/clazz/ClassInfo.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,11 @@ public static ClassInfo ofCache(Class<?> clazz) {
2828
}
2929
//No computeIfAbsent because new ClassInfo will call ofCache for superclass lookup
3030
//This will cause a CME because multiple updates occurred in one computeIfAbsent
31-
ClassInfo cInfo = ALL.get(clazz);
31+
val cInfo = ALL.get(clazz);
3232
if (cInfo != null) {
3333
return cInfo;
3434
}
35-
cInfo = new ClassInfo(clazz);
36-
ALL.put(clazz, cInfo);
37-
return cInfo;
35+
return new ClassInfo(clazz, true);
3836
}
3937

4038
private final Class<?> raw;
@@ -50,7 +48,10 @@ public static ClassInfo ofCache(Class<?> clazz) {
5048
private final IType superType;
5149
private final List<IType> interfaces;
5250

53-
private ClassInfo(Class<?> clazz) {
51+
private ClassInfo(Class<?> clazz, boolean putInCache) {
52+
if (putInCache) {
53+
ALL.put(clazz, this);
54+
}
5455
this.raw = clazz;
5556
this.name = raw.getName();
5657
this.modifiers = raw.getModifiers();

src/main/java/com/probejs/info/clazz/FieldInfo.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ public class FieldInfo extends BaseMemberInfo implements Comparable<FieldInfo> {
1616
private final int modifiers;
1717
private final boolean shouldHide;
1818
private final Object staticValue;
19+
private final ClassInfo from;
1920

2021
private static String getRemappedOrDefault(Field field, Class<?> clazz) {
2122
String mapped = RemapperBridge.getRemapper().getMappedField(clazz, field);
@@ -28,6 +29,7 @@ private static String getRemappedOrDefault(Field field, Class<?> clazz) {
2829
public FieldInfo(Field field, Class<?> clazz) {
2930
super(getRemappedOrDefault(field, clazz), TypeResolver.resolveType(field.getGenericType()));
3031
this.raw = field;
32+
this.from = ClassInfo.ofCache(clazz);
3133
this.modifiers = field.getModifiers();
3234
this.shouldHide = field.getAnnotation(HideFromJS.class) != null;
3335
this.staticValue = PUtil.tryOrDefault(() -> isStatic() ? field.get(null) : null, null);

src/main/java/com/probejs/info/clazz/MethodInfo.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public class MethodInfo extends BaseMemberInfo {
2323
/**
2424
* the classInfo that the method belongs to is NOT in info cache when MethodInfo is being constructed
2525
*/
26-
private final Class<?> from;
26+
private final ClassInfo from;
2727
@Setter
2828
private List<ParamInfo> params;
2929
@Setter
@@ -43,7 +43,7 @@ public MethodInfo(Method method, Class<?> from) {
4343
super(getRemappedOrDefault(method, from), TypeResolver.resolveType(method.getGenericReturnType()));
4444
this.raw = method;
4545
this.shouldHide = method.getAnnotation(HideFromJS.class) != null;
46-
this.from = from;
46+
this.from = ClassInfo.ofCache(from);
4747
this.modifiers = method.getModifiers();
4848
this.params = Arrays.stream(method.getParameters()).map(ParamInfo::new).collect(Collectors.toList());
4949
this.typeVariables = Arrays.stream(method.getTypeParameters())
@@ -65,8 +65,7 @@ public static class ParamInfo extends BaseMemberInfo {
6565
private final boolean isVarArgs;
6666

6767
public ParamInfo(Parameter parameter) {
68-
this.name = parameter.getName();
69-
this.type = TypeResolver.resolveType(parameter.getParameterizedType());
68+
super(parameter.getName(), TypeResolver.resolveType(parameter.getParameterizedType()));
7069
this.isVarArgs = parameter.isVarArgs();
7170
}
7271
}

0 commit comments

Comments
 (0)