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