@@ -427,87 +427,95 @@ boolean readStringSources(BodyDeclaration node, String tagName, String prefix, S
427427 }
428428
429429 /*
430- * Read JavaScript sources from @j2sNative, @J2SPrefix or others
430+ * Read JavaScript sources from @j2sNative, @j2sPrefix, etc, as well as
431+ * annotations
431432 */
432- boolean readSources (BodyDeclaration node , String tagName , String prefix , String suffix , boolean both ) {
433- boolean existed = false ;
433+ /**
434+ * for example, for classes only:
435+ *
436+ * @j2sPrefix /-* this is from <@>j2sPrefix added outside of just before
437+ * Clazz.decorateAsClass() *-/
438+ *
439+ *
440+ * @j2sSuffix /-* this is from <@>j2sSuffix added just after
441+ * Clazz.decorateAsClass() *-/
442+ */
443+ boolean readSources (BodyDeclaration node , String tagName , String prefix , String suffix , boolean allowBoth ) {
444+ boolean haveJ2SJavaDoc = false ;
434445 Javadoc javadoc = node .getJavadoc ();
435446 if (javadoc != null ) {
436447 List <?> tags = javadoc .tags ();
437- if (tags .size () != 0 ) {
448+ if (tags .size () > 0 ) {
438449 for (Iterator <?> iter = tags .iterator (); iter .hasNext ();) {
439450 TagElement tagEl = (TagElement ) iter .next ();
440- if (tagName .equals (tagEl .getTagName ())) {
441- if (tagEl != null ) {
442- List <?> fragments = tagEl .fragments ();
443- StringBuffer buf = new StringBuffer ();
444- boolean isFirstLine = true ;
445- for (Iterator <?> iterator = fragments .iterator (); iterator
446- .hasNext ();) {
447- TextElement commentEl = (TextElement ) iterator .next ();
448- String text = commentEl .getText ().trim ();
449- if (isFirstLine ) {
450- isFirstLine = false ;
451- if (text .length () == 0 ) {
452- continue ;
453- }
454- }
455- buf .append (text );
456- buf .append ("\r \n " );
451+ if (!tagName .equals (tagEl .getTagName ()))
452+ continue ;
453+ List <?> fragments = tagEl .fragments ();
454+ StringBuffer buf = new StringBuffer ();
455+ boolean isFirstLine = true ;
456+ for (Iterator <?> iterator = fragments .iterator (); iterator .hasNext ();) {
457+ TextElement commentEl = (TextElement ) iterator .next ();
458+ String text = commentEl .getText ().trim ();
459+ if (isFirstLine ) {
460+ isFirstLine = false ;
461+ if (text .length () == 0 ) {
462+ continue ;
457463 }
458- String sources = buf .toString ().trim ();
459- // embed block comments and Javadoc @
460- sources = sources .replaceAll ("(\\ /)-\\ *|\\ *-(\\ /)" , "$1*$2" ).replaceAll ("<@>" , "@" );
461- buffer .append (prefix + sources + suffix );
462- existed = true ;
463464 }
465+ buf .append (text );
466+ buf .append ("\r \n " );
464467 }
468+ // embed block comments and Javadoc @
469+ // /-* comment *-/ becomes /* comment */ and <@> becomes @
470+ String sources = buf .toString ().trim ().replaceAll ("(\\ /)-\\ *|\\ *-(\\ /)" , "$1*$2" ).replaceAll ("<@>" ,
471+ "@" );
472+ buffer .append (prefix ).append (sources ).append (suffix );
473+ haveJ2SJavaDoc = true ;
465474 }
466475 }
467476 }
468- if (existed && !both ) {
469- return existed ;
470- }
477+ // only classes allow both
478+ if (haveJ2SJavaDoc && !allowBoth )
479+ return haveJ2SJavaDoc ;
480+
481+ // now check annotations (class definitions only)
482+
471483 List <?> modifiers = node .modifiers ();
472484 for (Iterator <?> iter = modifiers .iterator (); iter .hasNext ();) {
473485 Object obj = (Object ) iter .next ();
474- if (obj instanceof Annotation ) {
475- Annotation annotation = (Annotation ) obj ;
476- String qName = annotation .getTypeName ().getFullyQualifiedName ();
477- int index = qName .indexOf ("J2S" );
478- if (index != -1 ) {
479- String annName = qName .substring (index );
480- annName = annName .replaceFirst ("J2S" , "@j2s" );
481- if (annName .startsWith (tagName )) {
482- StringBuffer buf = new StringBuffer ();
483- IAnnotationBinding annotationBinding = annotation .resolveAnnotationBinding ();
484- if (annotationBinding != null ) {
485- IMemberValuePairBinding [] valuePairs = annotationBinding .getAllMemberValuePairs ();
486- if (valuePairs != null && valuePairs .length > 0 ) {
487- for (int i = 0 ; i < valuePairs .length ; i ++) {
488- Object value = valuePairs [i ].getValue ();
489- if (value != null ) {
490- if (value instanceof Object []) {
491- Object [] lines = (Object []) value ;
492- for (int j = 0 ; j < lines .length ; j ++) {
493- buf .append (lines [j ]);
494- buf .append ("\r \n " );
495- }
496- } else if (value instanceof String ) {
497- buf .append (value );
498- buf .append ("\r \n " );
499- }
500- }
486+ if (!(obj instanceof Annotation ))
487+ continue ;
488+ Annotation annotation = (Annotation ) obj ;
489+ String qName = annotation .getTypeName ().getFullyQualifiedName ();
490+ int index = qName .indexOf ("J2S" );
491+ if (index < 0 || !qName .substring (index ).replaceFirst ("J2S" , "@j2s" ).startsWith (tagName ))
492+ continue ;
493+ haveJ2SJavaDoc = true ;
494+ StringBuffer buf = new StringBuffer ();
495+ IAnnotationBinding annotationBinding = annotation .resolveAnnotationBinding ();
496+ if (annotationBinding != null ) {
497+ IMemberValuePairBinding [] valuePairs = annotationBinding .getAllMemberValuePairs ();
498+ if (valuePairs != null && valuePairs .length > 0 ) {
499+ for (int i = 0 ; i < valuePairs .length ; i ++) {
500+ Object value = valuePairs [i ].getValue ();
501+ if (value != null ) {
502+ if (value instanceof Object []) {
503+ Object [] lines = (Object []) value ;
504+ for (int j = 0 ; j < lines .length ; j ++) {
505+ buf .append (lines [j ]);
506+ buf .append ("\r \n " );
501507 }
508+ } else if (value instanceof String ) {
509+ buf .append (value );
510+ buf .append ("\r \n " );
502511 }
503512 }
504- buffer .append (prefix + buf .toString ().trim () + suffix );
505- existed = true ;
506513 }
507514 }
508515 }
516+ buffer .append (prefix ).append (buf .toString ().trim ()).append (suffix );
509517 }
510- return existed ;
518+ return haveJ2SJavaDoc ;
511519 }
512520
513521 private String fixCommentBlock (String text ) {
0 commit comments