@@ -84,17 +84,12 @@ public boolean visit(PackageDeclaration node) {
84
84
85
85
public boolean visit (Block node ) {
86
86
blockLevel ++;
87
- if (buffer != null ) {
88
- buffer .append ("{\r \n " );
89
- }
90
87
ASTNode parent = node .getParent ();
91
88
if (parent instanceof MethodDeclaration ) {
92
89
MethodDeclaration method = (MethodDeclaration ) parent ;
93
90
Javadoc javadoc = method .getJavadoc ();
94
- /*
95
- * if comment contains "@j2sNative", then output the given native JavaScript
96
- * codes directly.
97
- */
91
+ // if comment contains "@j2sNative", then output the given native JavaScript
92
+ // codes directly.
98
93
if (!processJ2STags (javadoc , node , true )) {
99
94
return false ;
100
95
}
@@ -118,10 +113,10 @@ public boolean visit(Block node) {
118
113
superclass = superclass .getSuperclass ();
119
114
}
120
115
if (containsSuperPrivateMethod ) {
121
- buffer .append ("var $private = Clazz.checkPrivateMethod (arguments);\r \ n " );
122
- buffer .append ("if ($private != null) {\r \ n " );
123
- buffer .append ("return $private.apply (this, arguments);\r \ n " );
124
- buffer .append ("}\r \ n " );
116
+ buffer .append ("var $private = Clazz.checkPrivateMethod (arguments);\n " );
117
+ buffer .append ("if ($private != null) {\n " );
118
+ buffer .append ("return $private.apply (this, arguments);\n " );
119
+ buffer .append ("}\n " );
125
120
}
126
121
}
127
122
}
@@ -244,8 +239,24 @@ protected boolean processJ2STags(Javadoc javadoc, Block node, boolean superVisit
244
239
if ("@j2sNative" .equals (tagEl .getTagName ())) {
245
240
if (superVisit )
246
241
super .visit (node );
247
- if (buffer != null )
248
- writeJavaScript (tagEl );
242
+ if (buffer != null ) {
243
+ List <?> fragments = tagEl .fragments ();
244
+ boolean isFirstLine = true ;
245
+ StringBuffer buf = new StringBuffer ();
246
+ for (Iterator <?> iterator = fragments .iterator (); iterator
247
+ .hasNext ();) {
248
+ TextElement commentEl = (TextElement ) iterator .next ();
249
+ String text = commentEl .getText ().trim ();
250
+ if (isFirstLine ) {
251
+ if (text .length () == 0 ) {
252
+ continue ;
253
+ }
254
+ }
255
+ buf .append (text );
256
+ buf .append ("\n " );
257
+ }
258
+ buffer .append (fixCommentBlock (buf .toString ()));
259
+ }
249
260
return false ;
250
261
}
251
262
}
@@ -254,25 +265,6 @@ protected boolean processJ2STags(Javadoc javadoc, Block node, boolean superVisit
254
265
return true ;
255
266
}
256
267
257
- private void writeJavaScript (TagElement tagEl ) {
258
- List <?> fragments = tagEl .fragments ();
259
- boolean isFirstLine = true ;
260
- StringBuffer buf = new StringBuffer ();
261
- for (Iterator <?> iterator = fragments .iterator (); iterator
262
- .hasNext ();) {
263
- TextElement commentEl = (TextElement ) iterator .next ();
264
- String text = commentEl .getText ().trim ();
265
- if (isFirstLine ) {
266
- if (text .length () == 0 ) {
267
- continue ;
268
- }
269
- }
270
- buf .append (text );
271
- buf .append ("\r \n " );
272
- }
273
- buffer .append (fixCommentBlock (buf .toString ()));
274
- }
275
-
276
268
private String fixCommentBlock (String text ) {
277
269
if (text == null || text .length () == 0 ) {
278
270
return text ;
@@ -284,16 +276,19 @@ private String fixCommentBlock(String text) {
284
276
285
277
/**
286
278
* Write JavaScript source from @j2sNative and @J2SIgnore
279
+ *
280
+ * @return true if JavaScript was written
287
281
*/
288
- protected boolean writeJ2SSources (BodyDeclaration node , String tagName , String prefix , String suffix , boolean both ) {
289
- boolean existed = false ;
282
+ protected boolean writeJ2STags (BodyDeclaration node , boolean needScope ) {
283
+ String prefix = (needScope ? "{\n " : "" );
284
+ String suffix = (needScope ? "\n }" : "" );
290
285
Javadoc javadoc = node .getJavadoc ();
291
286
if (javadoc != null ) {
292
287
List <?> tags = javadoc .tags ();
293
288
if (tags .size () != 0 ) {
294
289
for (Iterator <?> iter = tags .iterator (); iter .hasNext ();) {
295
290
TagElement tagEl = (TagElement ) iter .next ();
296
- if (tagName .equals (tagEl .getTagName ())) {
291
+ if ("@j2sNative" .equals (tagEl .getTagName ())) {
297
292
List <?> fragments = tagEl .fragments ();
298
293
StringBuffer buf = new StringBuffer ();
299
294
boolean isFirstLine = true ;
@@ -306,19 +301,16 @@ protected boolean writeJ2SSources(BodyDeclaration node, String tagName, String p
306
301
}
307
302
}
308
303
buf .append (text );
309
- buf .append ("\r \ n " );
304
+ buf .append ("\n " );
310
305
}
311
306
String sources = buf .toString ().trim ();
312
307
sources = sources .replaceAll ("(\\ /)-\\ *|\\ *-(\\ /)" , "$1*$2" ).replaceAll ("<@>" , "@" );
313
308
buffer .append (prefix + sources + suffix );
314
- existed = true ;
309
+ return true ;
315
310
}
316
311
}
317
312
}
318
313
}
319
- if (existed && !both ) {
320
- return existed ;
321
- }
322
314
List <?> modifiers = node .modifiers ();
323
315
for (Iterator <?> iter = modifiers .iterator (); iter .hasNext ();) {
324
316
Object obj = iter .next ();
@@ -327,9 +319,7 @@ protected boolean writeJ2SSources(BodyDeclaration node, String tagName, String p
327
319
String qName = annotation .getTypeName ().getFullyQualifiedName ();
328
320
int index = qName .indexOf ("J2S" );
329
321
if (index != -1 ) {
330
- String annName = qName .substring (index );
331
- annName = annName .replaceFirst ("J2S" , "@j2s" );
332
- if (annName .startsWith (tagName )) {
322
+ if (qName .substring (index ).startsWith ("J2SNative" )) {
333
323
StringBuffer buf = new StringBuffer ();
334
324
IAnnotationBinding annotationBinding = annotation .resolveAnnotationBinding ();
335
325
if (annotationBinding != null ) {
@@ -342,23 +332,23 @@ protected boolean writeJ2SSources(BodyDeclaration node, String tagName, String p
342
332
Object [] lines = (Object []) value ;
343
333
for (int j = 0 ; j < lines .length ; j ++) {
344
334
buf .append (lines [j ]);
345
- buf .append ("\r \ n " );
335
+ buf .append ("\n " );
346
336
}
347
337
} else if (value instanceof String ) {
348
338
buf .append (value );
349
- buf .append ("\r \ n " );
339
+ buf .append ("\n " );
350
340
}
351
341
}
352
342
}
353
343
}
354
344
}
355
345
buffer .append (prefix + buf .toString ().trim () + suffix );
356
- existed = true ;
346
+ return true ;
357
347
}
358
348
}
359
349
}
360
350
}
361
- return existed ;
351
+ return false ;
362
352
}
363
353
364
354
}
0 commit comments