@@ -84,17 +84,12 @@ public boolean visit(PackageDeclaration node) {
8484
8585 public boolean visit (Block node ) {
8686 blockLevel ++;
87- if (buffer != null ) {
88- buffer .append ("{\r \n " );
89- }
9087 ASTNode parent = node .getParent ();
9188 if (parent instanceof MethodDeclaration ) {
9289 MethodDeclaration method = (MethodDeclaration ) parent ;
9390 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.
9893 if (!processJ2STags (javadoc , node , true )) {
9994 return false ;
10095 }
@@ -118,10 +113,10 @@ public boolean visit(Block node) {
118113 superclass = superclass .getSuperclass ();
119114 }
120115 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 " );
125120 }
126121 }
127122 }
@@ -244,8 +239,24 @@ protected boolean processJ2STags(Javadoc javadoc, Block node, boolean superVisit
244239 if ("@j2sNative" .equals (tagEl .getTagName ())) {
245240 if (superVisit )
246241 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+ }
249260 return false ;
250261 }
251262 }
@@ -254,25 +265,6 @@ protected boolean processJ2STags(Javadoc javadoc, Block node, boolean superVisit
254265 return true ;
255266 }
256267
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-
276268 private String fixCommentBlock (String text ) {
277269 if (text == null || text .length () == 0 ) {
278270 return text ;
@@ -284,16 +276,19 @@ private String fixCommentBlock(String text) {
284276
285277 /**
286278 * Write JavaScript source from @j2sNative and @J2SIgnore
279+ *
280+ * @return true if JavaScript was written
287281 */
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 }" : "" );
290285 Javadoc javadoc = node .getJavadoc ();
291286 if (javadoc != null ) {
292287 List <?> tags = javadoc .tags ();
293288 if (tags .size () != 0 ) {
294289 for (Iterator <?> iter = tags .iterator (); iter .hasNext ();) {
295290 TagElement tagEl = (TagElement ) iter .next ();
296- if (tagName .equals (tagEl .getTagName ())) {
291+ if ("@j2sNative" .equals (tagEl .getTagName ())) {
297292 List <?> fragments = tagEl .fragments ();
298293 StringBuffer buf = new StringBuffer ();
299294 boolean isFirstLine = true ;
@@ -306,19 +301,16 @@ protected boolean writeJ2SSources(BodyDeclaration node, String tagName, String p
306301 }
307302 }
308303 buf .append (text );
309- buf .append ("\r \ n " );
304+ buf .append ("\n " );
310305 }
311306 String sources = buf .toString ().trim ();
312307 sources = sources .replaceAll ("(\\ /)-\\ *|\\ *-(\\ /)" , "$1*$2" ).replaceAll ("<@>" , "@" );
313308 buffer .append (prefix + sources + suffix );
314- existed = true ;
309+ return true ;
315310 }
316311 }
317312 }
318313 }
319- if (existed && !both ) {
320- return existed ;
321- }
322314 List <?> modifiers = node .modifiers ();
323315 for (Iterator <?> iter = modifiers .iterator (); iter .hasNext ();) {
324316 Object obj = iter .next ();
@@ -327,9 +319,7 @@ protected boolean writeJ2SSources(BodyDeclaration node, String tagName, String p
327319 String qName = annotation .getTypeName ().getFullyQualifiedName ();
328320 int index = qName .indexOf ("J2S" );
329321 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" )) {
333323 StringBuffer buf = new StringBuffer ();
334324 IAnnotationBinding annotationBinding = annotation .resolveAnnotationBinding ();
335325 if (annotationBinding != null ) {
@@ -342,23 +332,23 @@ protected boolean writeJ2SSources(BodyDeclaration node, String tagName, String p
342332 Object [] lines = (Object []) value ;
343333 for (int j = 0 ; j < lines .length ; j ++) {
344334 buf .append (lines [j ]);
345- buf .append ("\r \ n " );
335+ buf .append ("\n " );
346336 }
347337 } else if (value instanceof String ) {
348338 buf .append (value );
349- buf .append ("\r \ n " );
339+ buf .append ("\n " );
350340 }
351341 }
352342 }
353343 }
354344 }
355345 buffer .append (prefix + buf .toString ().trim () + suffix );
356- existed = true ;
346+ return true ;
357347 }
358348 }
359349 }
360350 }
361- return existed ;
351+ return false ;
362352 }
363353
364354}
0 commit comments