@@ -201,17 +201,49 @@ public static final class Transform {
201
201
private static synchronized void init (ClassLoader prepend ) {
202
202
if (TRANSFORM != null ) return ;
203
203
204
- Main .prependClassLoader (prepend );
204
+ prependClassLoader (prepend );
205
+ if (!prepend .toString ().contains ("org.eclipse.jdt.core:" )) {
206
+ ClassLoader jdtCoreClassLoader = findJdtCoreClassLoader (prepend );
207
+ prependClassLoader (jdtCoreClassLoader );
208
+ }
209
+ Class <?> shadowed = Util .shadowLoadClass ("lombok.eclipse.TransformEclipseAST" );
210
+ TRANSFORM = Util .findMethodAnyArgs (shadowed , "transform" );
211
+ TRANSFORM_SWAPPED = Util .findMethodAnyArgs (shadowed , "transform_swapped" );
212
+ }
213
+
214
+ private static void prependClassLoader (ClassLoader classLoader ) {
215
+ Main .prependClassLoader (classLoader );
205
216
try {
206
217
ClassLoader currentClassLoader = Transform .class .getClassLoader ();
218
+
207
219
Method prependParentMethod = Permit .getMethod (currentClassLoader .getClass (), "prependParent" , ClassLoader .class );
208
- Permit .invoke (prependParentMethod , currentClassLoader , prepend );
220
+ Permit .invoke (prependParentMethod , currentClassLoader , classLoader );
209
221
} catch (Throwable t ) {
210
222
// Ignore
211
223
}
212
- Class <?> shadowed = Util .shadowLoadClass ("lombok.eclipse.TransformEclipseAST" );
213
- TRANSFORM = Util .findMethodAnyArgs (shadowed , "transform" );
214
- TRANSFORM_SWAPPED = Util .findMethodAnyArgs (shadowed , "transform_swapped" );
224
+ }
225
+
226
+ private static ClassLoader findJdtCoreClassLoader (ClassLoader classLoader ) {
227
+ try {
228
+ Method getBundleMethod = Permit .getMethod (classLoader .getClass (), "getBundle" );
229
+ Object bundle = Permit .invoke (getBundleMethod , classLoader );
230
+
231
+ Method getBundleContextMethod = Permit .getMethod (bundle .getClass (), "getBundleContext" );
232
+ Object bundleContext = Permit .invoke (getBundleContextMethod , bundle );
233
+
234
+ Method getBundlesMethod = Permit .getMethod (bundleContext .getClass (), "getBundles" );
235
+ Object [] bundles = (Object []) Permit .invoke (getBundlesMethod , bundleContext );
236
+
237
+ for (Object searchBundle : bundles ) {
238
+ if (searchBundle .toString ().startsWith ("org.eclipse.jdt.core_" )) {
239
+ Method getModuleClassLoaderMethod = Permit .getMethod (searchBundle .getClass (), "getModuleClassLoader" , boolean .class );
240
+ return (ClassLoader ) Permit .invoke (getModuleClassLoaderMethod , searchBundle , false );
241
+ }
242
+ }
243
+ } catch (Throwable t ) {
244
+ // Ignore
245
+ }
246
+ return null ;
215
247
}
216
248
217
249
public static void transform (Object parser , Object ast ) throws IOException {
0 commit comments