@@ -95,22 +95,24 @@ public static IDictionary<Class, IReadOnlyDictionary<string, string>> ExtractJav
95
95
si . Arguments = arguments ;
96
96
97
97
process = Process . Start ( si ) ;
98
- TimeSpan initial = process . TotalProcessorTime ;
98
+ TimeSpan initialTotalProcessorTime = process . TotalProcessorTime ;
99
99
int cycles = 0 ;
100
100
while ( ( exited = process . WaitForExit ( 100 ) ) == false )
101
101
{
102
102
process . Refresh ( ) ;
103
- TimeSpan current = process . TotalProcessorTime ;
104
- if ( ( current - initial ) < TimeSpan . FromMilliseconds ( 10 ) ) break ; // process is idle???
103
+ TimeSpan currentTotalProcessorTime = process . TotalProcessorTime ;
104
+ if ( ( currentTotalProcessorTime - initialTotalProcessorTime ) < TimeSpan . FromMilliseconds ( 10 ) ) break ; // process is idle???
105
105
if ( ++ cycles > toBeAnalyzed . Count ) break ; // elapsed max cycles
106
106
}
107
107
if ( exited && process . ExitCode != 0 ) throw new InvalidOperationException ( $ "javap falied with error { process . ExitCode } ") ;
108
+
108
109
Dictionary < string , string > map = new Dictionary < string , string > ( ) ;
109
110
string line ;
110
111
int classCounter = - 1 ;
111
112
string methodName = string . Empty ;
112
113
string className = string . Empty ;
113
114
bool nextLineIsDescriptor = false ;
115
+ #if OLD_ALGORITHM
114
116
while ( ( line = process . StandardOutput . ReadLine ( ) ) != null )
115
117
{
116
118
if ( line . Contains ( "Compiled from" ) )
@@ -136,6 +138,59 @@ public static IDictionary<Class, IReadOnlyDictionary<string, string>> ExtractJav
136
138
methodName = methodName . AddClassNameToSignature ( className ) ;
137
139
}
138
140
}
141
+ #else
142
+ int endCounter = 0 ;
143
+ int cycleCounter = 0 ;
144
+ do
145
+ {
146
+ line = process . StandardOutput . ReadLine ( ) ;
147
+ if ( line == null )
148
+ {
149
+ if ( endCounter != toBeAnalyzed . Count )
150
+ {
151
+ // wait a while
152
+ cycleCounter ++ ;
153
+ System . Threading . Thread . Sleep ( 1 ) ;
154
+ continue ;
155
+ }
156
+ else break ;
157
+ }
158
+ else
159
+ {
160
+ if ( line . Contains ( "Compiled from" ) )
161
+ {
162
+ if ( classCounter != - 1 ) { dict . TryAdd ( toBeAnalyzed [ classCounter ] , map ) ; }
163
+ classCounter ++ ;
164
+ className = toBeAnalyzed [ classCounter ] . Name ;
165
+ map = new Dictionary < string , string > ( ) ;
166
+ }
167
+ if ( nextLineIsDescriptor )
168
+ {
169
+ nextLineIsDescriptor = false ;
170
+ string signature = line . TrimStart ( ) . TrimEnd ( ) ;
171
+ signature = signature . Remove ( 0 , "descriptor: " . Length ) ;
172
+ map . Add ( methodName , signature ) ;
173
+ }
174
+ bool isInterfaceOrClassLine = line . Contains ( "class" ) || line . Contains ( "interface" ) ;
175
+ if ( line . Contains ( "public" ) && ! isInterfaceOrClassLine )
176
+ {
177
+ nextLineIsDescriptor = true ;
178
+ methodName = line . TrimStart ( ) . TrimEnd ( ) ;
179
+ methodName = methodName . RemoveThrowsAndCleanupSignature ( ) ;
180
+ methodName = methodName . AddClassNameToSignature ( className ) ;
181
+ }
182
+
183
+ cycleCounter = 0 ;
184
+ }
185
+
186
+ if ( line . TrimEnd ( ) == "}" )
187
+ {
188
+ endCounter ++ ;
189
+ }
190
+ if ( endCounter == toBeAnalyzed . Count ) break ;
191
+ }
192
+ while ( cycleCounter < 100 ) ;
193
+ #endif
139
194
dict . TryAdd ( toBeAnalyzed [ classCounter ] , map ) ;
140
195
}
141
196
catch { }
0 commit comments