@@ -159,8 +159,6 @@ private void scanSources() {
159159 l .add (scanner );
160160 }
161161 }
162- EmbeddedClassFinder finder = new EmbeddedClassFinder ();
163- l .add (finder );
164162 Source source = source (className );
165163 String [] lines = source .code ().split ("[\\ n\\ r]+" );
166164 for (int i = 0 , j = lines .length ; i < j ; ++i ) {
@@ -169,22 +167,28 @@ private void scanSources() {
169167 scanner .visit (i , line , className );
170168 }
171169 }
172- if (!finder .embeddedClassNames .isEmpty ()) {
173- classesNeedByteCodeScan .addAll (finder .embeddedClassNames );
174- }
175170 }
176171
177172 if (classesNeedByteCodeScan .isEmpty ()) {
178173 return ;
179174 }
180175
181- // FIX ME: Embedded class is not scanned
176+ final Set < String > embeddedClassNames = C . newSet ();
182177 scanByteCode (classesNeedByteCodeScan , new _ .F1 <String , byte []>() {
183178 @ Override
184179 public byte [] apply (String s ) throws NotAppliedException , _ .Break {
185- return bytecodeFromSource (s , true );
180+ return bytecodeFromSource (s , embeddedClassNames );
186181 }
187182 });
183+
184+ if (!embeddedClassNames .isEmpty ()) {
185+ scanByteCode (embeddedClassNames , new _ .F1 <String , byte []>() {
186+ @ Override
187+ public byte [] apply (String s ) throws NotAppliedException , _ .Break {
188+ return bytecodeFromSource (s , embeddedClassNames );
189+ }
190+ });
191+ }
188192 }
189193
190194 private byte [] bytecodeFromSource (String name , boolean compile ) {
@@ -204,6 +208,24 @@ private byte[] bytecodeFromSource(String name, boolean compile) {
204208 return bytes ;
205209 }
206210
211+ private byte [] bytecodeFromSource (String name , Set <String > embeddedClassNames ) {
212+ Source source = source (name );
213+ if (null == source ) {
214+ return null ;
215+ }
216+ byte [] bytes = source .bytes ();
217+ if (null == bytes ) {
218+ compiler .compile (name );
219+ bytes = source .bytes ();
220+ embeddedClassNames .addAll (C .list (source .innerClassNames ()).map (S .F .prepend (name + "$" )));
221+ }
222+ if (name .contains ("$" )) {
223+ String innerClassName = S .afterFirst (name , "$" );
224+ return source .bytes (innerClassName );
225+ }
226+ return bytes ;
227+ }
228+
207229 @ Override
208230 public void detectChanges () {
209231 detectChanges (confChangeDetector );
@@ -294,34 +316,4 @@ public void on(FsEvent... events) {
294316 }
295317 };
296318
297- private static class EmbeddedClassFinder implements AppSourceCodeScanner {
298-
299- private List <String > embeddedClassNames = C .newList ();
300- private String className ;
301- private static final Pattern P = Pattern .compile ("\\ s*public\\ s+static\\ s+class\\ s+([_a-zA-Z][a-zA-Z_0-9]*).*" );
302-
303- @ Override
304- public void visit (int lineNumber , String line , String className ) {
305- Matcher m = P .matcher (line );
306- if (m .matches ()) {
307- embeddedClassNames .add (className + "$" + m .group (1 ));
308- }
309- }
310-
311- @ Override
312- public boolean triggerBytecodeScanning () {
313- return false ;
314- }
315-
316- @ Override
317- public void setApp (App app ) {
318-
319- }
320-
321- @ Override
322- public boolean start (String className ) {
323- this .className = className ;
324- return true ;
325- }
326- }
327319}
0 commit comments