16
16
*/
17
17
package org .apache .dubbo .common .compiler .support ;
18
18
19
- import org .apache .dubbo .common .utils .ClassHelper ;
20
19
21
20
import javassist .CtClass ;
22
21
@@ -49,25 +48,25 @@ public Class<?> doCompile(String name, String source) throws Throwable {
49
48
while (matcher .find ()) {
50
49
builder .addImports (matcher .group (1 ).trim ());
51
50
}
52
-
51
+
53
52
// process extended super class
54
53
matcher = EXTENDS_PATTERN .matcher (source );
55
54
if (matcher .find ()) {
56
55
builder .setSuperClassName (matcher .group (1 ).trim ());
57
56
}
58
-
57
+
59
58
// process implemented interfaces
60
59
matcher = IMPLEMENTS_PATTERN .matcher (source );
61
60
if (matcher .find ()) {
62
61
String [] ifaces = matcher .group (1 ).trim ().split ("\\ ," );
63
62
Arrays .stream (ifaces ).forEach (i -> builder .addInterface (i .trim ()));
64
63
}
65
-
64
+
66
65
// process constructors, fields, methods
67
66
String body = source .substring (source .indexOf ('{' ) + 1 , source .length () - 1 );
68
67
String [] methods = METHODS_PATTERN .split (body );
69
68
String className = ClassUtils .getSimpleClassName (name );
70
- Arrays .stream (methods ).map (String ::trim ).filter (m -> !m .isEmpty ()).forEach (method -> {
69
+ Arrays .stream (methods ).map (String ::trim ).filter (m -> !m .isEmpty ()).forEach (method -> {
71
70
if (method .startsWith (className )) {
72
71
builder .addConstructor ("public " + method );
73
72
} else if (FIELD_PATTERN .matcher (method ).matches ()) {
@@ -76,9 +75,9 @@ public Class<?> doCompile(String name, String source) throws Throwable {
76
75
builder .addMethod ("public " + method );
77
76
}
78
77
});
79
-
78
+
80
79
// compile
81
- ClassLoader classLoader = ClassHelper .getCallerClassLoader (getClass ());
80
+ ClassLoader classLoader = org . apache . dubbo . common . utils . ClassUtils .getCallerClassLoader (getClass ());
82
81
CtClass cls = builder .build (classLoader );
83
82
return cls .toClass (classLoader , JavassistCompiler .class .getProtectionDomain ());
84
83
}
0 commit comments