17
17
import java .util .regex .Pattern ;
18
18
19
19
import org .eclipse .jdt .core .dom .ASTNode ;
20
+ import org .eclipse .jdt .core .dom .Annotation ;
20
21
import org .eclipse .jdt .core .dom .Block ;
21
22
import org .eclipse .jdt .core .dom .BodyDeclaration ;
22
23
import org .eclipse .jdt .core .dom .CatchClause ;
23
24
import org .eclipse .jdt .core .dom .Comment ;
24
25
import org .eclipse .jdt .core .dom .CompilationUnit ;
26
+ import org .eclipse .jdt .core .dom .IAnnotationBinding ;
27
+ import org .eclipse .jdt .core .dom .IMemberValuePairBinding ;
25
28
import org .eclipse .jdt .core .dom .IMethodBinding ;
26
29
import org .eclipse .jdt .core .dom .ITypeBinding ;
27
30
import org .eclipse .jdt .core .dom .IfStatement ;
@@ -193,6 +196,82 @@ private void visitJavadocJ2SSource(TagElement tagEl) {
193
196
}
194
197
buffer .append (fixCommentBlock (buf .toString ()));
195
198
}
199
+ /*
200
+ * Read JavaScript sources from @j2sNative, @J2SPrefix or others
201
+ */
202
+ boolean readSources (BodyDeclaration node , String tagName , String prefix , String suffix , boolean both ) {
203
+ boolean existed = false ;
204
+ Javadoc javadoc = node .getJavadoc ();
205
+ if (javadoc != null ) {
206
+ List tags = javadoc .tags ();
207
+ if (tags .size () != 0 ) {
208
+ for (Iterator iter = tags .iterator (); iter .hasNext ();) {
209
+ TagElement tagEl = (TagElement ) iter .next ();
210
+ if (tagName .equals (tagEl .getTagName ())) {
211
+ if (tagEl != null ) {
212
+ List fragments = tagEl .fragments ();
213
+ StringBuffer buf = new StringBuffer ();
214
+ boolean isFirstLine = true ;
215
+ for (Iterator iterator = fragments .iterator (); iterator
216
+ .hasNext ();) {
217
+ TextElement commentEl = (TextElement ) iterator .next ();
218
+ String text = commentEl .getText ().trim ();
219
+ if (isFirstLine ) {
220
+ if (text .length () == 0 ) {
221
+ continue ;
222
+ }
223
+ }
224
+ buf .append (text );
225
+ buf .append ("\r \n " );
226
+ }
227
+ buffer .append (prefix + buf .toString ().trim () + suffix );
228
+ existed = true ;
229
+ }
230
+ }
231
+ }
232
+ }
233
+ }
234
+ if (existed && !both ) {
235
+ return existed ;
236
+ }
237
+ List modifiers = node .modifiers ();
238
+ for (Iterator iter = modifiers .iterator (); iter .hasNext ();) {
239
+ Object obj = (Object ) iter .next ();
240
+ if (obj instanceof Annotation ) {
241
+ Annotation annotation = (Annotation ) obj ;
242
+ String qName = annotation .getTypeName ().getFullyQualifiedName ();
243
+ int index = qName .indexOf ("J2S" );
244
+ if (index != -1 ) {
245
+ String annName = qName .substring (index );
246
+ annName = annName .replaceFirst ("J2S" , "@j2s" );
247
+ if (annName .startsWith (tagName )) {
248
+ StringBuffer buf = new StringBuffer ();
249
+ IAnnotationBinding annotationBinding = annotation .resolveAnnotationBinding ();
250
+ if (annotationBinding != null ) {
251
+ IMemberValuePairBinding [] valuePairs = annotationBinding .getAllMemberValuePairs ();
252
+ if (valuePairs != null && valuePairs .length > 0 ) {
253
+ for (int i = 0 ; i < valuePairs .length ; i ++) {
254
+ Object value = valuePairs [i ].getValue ();
255
+ if (value != null ) {
256
+ if (value instanceof Object []) {
257
+ Object [] lines = (Object []) value ;
258
+ for (int j = 0 ; j < lines .length ; j ++) {
259
+ buf .append (lines [j ]);
260
+ buf .append ("\r \n " );
261
+ }
262
+ }
263
+ }
264
+ }
265
+ }
266
+ }
267
+ buffer .append (prefix + buf .toString ().trim () + suffix );
268
+ existed = true ;
269
+ }
270
+ }
271
+ }
272
+ }
273
+ return existed ;
274
+ }
196
275
197
276
private String fixCommentBlock (String text ) {
198
277
if (text == null || text .length () == 0 ) {
@@ -274,14 +353,13 @@ private int getPreviousStartPosition(Block node) {
274
353
return previousStart ;
275
354
}
276
355
277
-
278
356
/**
279
357
* Method with "j2s*" tag.
280
358
*
281
359
* @param node
282
360
* @return
283
361
*/
284
- protected TagElement getJ2SDocTag (BodyDeclaration node , String tagName ) {
362
+ protected Object getJ2STag (BodyDeclaration node , String tagName ) {
285
363
Javadoc javadoc = node .getJavadoc ();
286
364
if (javadoc != null ) {
287
365
List tags = javadoc .tags ();
@@ -294,6 +372,24 @@ protected TagElement getJ2SDocTag(BodyDeclaration node, String tagName) {
294
372
}
295
373
}
296
374
}
375
+ List modifiers = node .modifiers ();
376
+ if (modifiers != null && modifiers .size () > 0 ) {
377
+ for (Iterator iter = modifiers .iterator (); iter .hasNext ();) {
378
+ Object obj = (Object ) iter .next ();
379
+ if (obj instanceof Annotation ) {
380
+ Annotation annotation = (Annotation ) obj ;
381
+ String qName = annotation .getTypeName ().getFullyQualifiedName ();
382
+ int idx = qName .indexOf ("J2S" );
383
+ if (idx != -1 ) {
384
+ String annName = qName .substring (idx );
385
+ annName = annName .replaceFirst ("J2S" , "@j2s" );
386
+ if (annName .startsWith (tagName )) {
387
+ return annotation ;
388
+ }
389
+ }
390
+ }
391
+ }
392
+ }
297
393
return null ;
298
394
}
299
395
@@ -306,10 +402,10 @@ protected TagElement getJ2SDocTag(BodyDeclaration node, String tagName) {
306
402
*/
307
403
protected boolean isMethodNativeIgnored (MethodDeclaration node ) {
308
404
if ((node .getModifiers () & Modifier .NATIVE ) != 0 ) {
309
- if (isDebugging () && getJ2SDocTag (node , "@j2sDebug" ) != null ) {
405
+ if (isDebugging () && getJ2STag (node , "@j2sDebug" ) != null ) {
310
406
return false ;
311
407
}
312
- if (getJ2SDocTag (node , "@j2sNative" ) != null ) {
408
+ if (getJ2STag (node , "@j2sNative" ) != null ) {
313
409
return false ;
314
410
}
315
411
return true ;
0 commit comments