@@ -328,6 +328,7 @@ private Java2ScriptVisitor setInnerGlobals(Java2ScriptVisitor parent, ASTNode no
328328 private boolean class_isAnonymousOrLocal ;
329329 private boolean inNewLambdaExpression ;
330330
331+
331332 /**
332333 * default constructor found by visit(MethodDeclaration)
333334 */
@@ -407,6 +408,11 @@ public boolean visit(CompilationUnit node) {
407408
408409 public boolean visit (PackageDeclaration node ) {
409410 setMapJavaDoc (node );
411+ List annotations = node .annotations ();
412+ if (annotations != null && annotations .size () > 0 ) {
413+ for (int i = 0 ; i < annotations .size (); i ++)
414+ addAnnotation ((Annotation ) annotations .get (i ), node , CHECK_ANNOTATIONS_ONLY );
415+ }
410416 setPackage (node .getName ().toString ());
411417 return false ;
412418 }
@@ -2076,8 +2082,11 @@ && checkAnnotations(element, CHECK_J2S_IGNORE_AND_ANNOTATIONS)) {
20762082 // add any recently defined static field definitions, assert strings
20772083 // and Enum constants
20782084
2079- if (class_jaxbAccessorType != JAXB_TYPE_UNKNOWN )
2085+ if (class_jaxbAccessorType != JAXB_TYPE_UNKNOWN ) {
20802086 ClassAnnotation .addClassAnnotations (class_jaxbAccessorType , class_annotations , fields , methods , trailingBuffer );
2087+ class_annotations = null ;
2088+ class_jaxbAccessorType = JAXB_TYPE_UNKNOWN ;
2089+ }
20812090
20822091 buffer .append (trailingBuffer ); // also writes the assert string
20832092 if (isAnonymous ) {
@@ -5366,42 +5375,47 @@ private boolean checkAnnotations(BodyDeclaration node, int mode) {
53665375 for (Iterator <?> iter = modifiers .iterator (); iter .hasNext ();) {
53675376 Object obj = iter .next ();
53685377 if (obj instanceof Annotation ) {
5369- Annotation annotation = (Annotation ) obj ;
5370- String qName = annotation .getTypeName ().getFullyQualifiedName ();
5371- int idx = qName .indexOf ("J2S" );
5372- if (idx >= 0 ) {
5373- if (mode == CHECK_ANNOTATIONS_ONLY )
5374- continue ;
5375- String annName = qName .substring (idx );
5376- if (annName .startsWith ("J2SIgnore" )) {
5377- return false ;
5378- }
5379- } else if (qName .equals ("Override" )
5380- || qName .equals ("Deprecated" )
5381- || qName .startsWith ("Suppress" )
5382- || qName .startsWith ("ConstructorProperties" )) {
5383- // see java\awt\ScrollPane.js @ConstructorProperties({"scrollbarDisplayPolicy"})
5384- // ignore
5385- } else {
5386- if (class_annotations == null )
5387- class_annotations = new ArrayList <ClassAnnotation >();
5388- ClassAnnotation ann = new ClassAnnotation (qName , annotation , node );
5389- class_annotations .add (ann );
5390- if ("XmlAccessorType" .equals (qName )) {
5391- String s = annotation .toString ();
5392- class_jaxbAccessorType = (
5393- s .contains ("FIELD" ) ? JAXB_TYPE_FIELD
5394- : s .contains ("PUBLIC" ) ? JAXB_TYPE_PUBLIC_MEMBER
5395- : s .contains ("PROPERTY" ) ? JAXB_TYPE_PROPERTY
5396- : JAXB_TYPE_NONE );
5397- }
5398- }
5378+ if (!addAnnotation ((Annotation ) obj , node , mode ))
5379+ return false ;
53995380 }
54005381 }
54015382 }
54025383 return true ;
54035384 }
54045385
5386+ private boolean addAnnotation (Annotation annotation , ASTNode node , int mode ) {
5387+ String qName = annotation .getTypeName ().getFullyQualifiedName ();
5388+ int idx = qName .indexOf ("J2S" );
5389+ if (idx >= 0 ) {
5390+ if (mode == CHECK_ANNOTATIONS_ONLY )
5391+ return true ;
5392+ String annName = qName .substring (idx );
5393+ if (annName .startsWith ("J2SIgnore" )) {
5394+ return false ;
5395+ }
5396+ } else if (qName .equals ("Override" )
5397+ || qName .equals ("Deprecated" )
5398+ || qName .startsWith ("Suppress" )
5399+ || qName .startsWith ("ConstructorProperties" )) {
5400+ // see java\awt\ScrollPane.js @ConstructorProperties({"scrollbarDisplayPolicy"})
5401+ // ignore
5402+ } else {
5403+ if (class_annotations == null )
5404+ class_annotations = new ArrayList <ClassAnnotation >();
5405+ ClassAnnotation ann = new ClassAnnotation (qName , annotation , node );
5406+ class_annotations .add (ann );
5407+ if ("XmlAccessorType" .equals (qName )) {
5408+ String s = annotation .toString ();
5409+ class_jaxbAccessorType = (
5410+ s .contains ("FIELD" ) ? JAXB_TYPE_FIELD
5411+ : s .contains ("PUBLIC" ) ? JAXB_TYPE_PUBLIC_MEMBER
5412+ : s .contains ("PROPERTY" ) ? JAXB_TYPE_PROPERTY
5413+ : JAXB_TYPE_NONE );
5414+ }
5415+ }
5416+ return true ;
5417+ }
5418+
54055419 /////////////////////////////
54065420
54075421 /**
@@ -5491,6 +5505,10 @@ private void appendElementKey(String className) {
54915505 * @return List {elementName, js, elementName, js, ....}
54925506 */
54935507 public List <String > getElementList () {
5508+ if (class_jaxbAccessorType != JAXB_TYPE_UNKNOWN ) {
5509+ addDummyClassForPackageOnlyFile ();
5510+ }
5511+
54945512 String trailer = ";Clazz.setTVer('" + VERSION + "');//Created "
54955513 + new SimpleDateFormat ("yyyy-MM-dd HH:mm:ss" ).format (new Date ()) + " Java2ScriptVisitor version "
54965514 + VERSION + " net.sf.j2s.core.jar version " + CorePlugin .VERSION + "\n " ;
@@ -5516,6 +5534,14 @@ public List<String> getElementList() {
55165534 return elements ;
55175535 }
55185536
5537+ private void addDummyClassForPackageOnlyFile () {
5538+ appendElementKey ("_$" );
5539+ buffer .append ("var C$=Clazz.newClass(\" _$\" );\n C$.$clinit$ = function() {Clazz.load(C$, 1)};\n " );
5540+ ClassAnnotation .addClassAnnotations (class_jaxbAccessorType , class_annotations , null , null , trailingBuffer );
5541+ buffer .append (trailingBuffer );
5542+ addDefaultConstructor ();
5543+ }
5544+
55195545 public boolean visit (AnnotationTypeDeclaration node ) {
55205546 return false ;
55215547 }
@@ -6163,14 +6189,14 @@ static boolean fieldNameCoversMethod(String fieldName) {
61636189
61646190 static class ClassAnnotation {
61656191
6166- protected BodyDeclaration node ;
6192+ protected ASTNode node ;
61676193 protected Annotation annotation ;
61686194 private String qName ;
61696195
6170- protected ClassAnnotation (String qName , Annotation annotation , BodyDeclaration node ) {
6171- System .out .println (">>>>" + qName + " "
6196+ protected ClassAnnotation (String qName , Annotation annotation , ASTNode node ) {
6197+ // System.out.println(">>>>" + qName + " "
61726198 //+ annotation.getClass().getName()
6173- + " " + annotation );
6199+ // + " " + annotation);
61746200 this .qName = qName ;
61756201 this .annotation = annotation ;
61766202 this .node = node ;
@@ -6287,7 +6313,7 @@ private static IMethodBinding getJAXBGetMethod(IMethodBinding var, List<IMethodB
62876313
62886314 private static void addImplicitJAXBFieldsAndMethods (int accessType , TrailingBuffer trailingBuffer ,
62896315 List <FieldDeclaration > fields , List <IMethodBinding > methods , String propOrder ) {
6290- if (accessType == JAXB_TYPE_NONE )
6316+ if (accessType == JAXB_TYPE_NONE || fields == null )
62916317 return ;
62926318 boolean publicOnly = (accessType == JAXB_TYPE_PUBLIC_MEMBER );
62936319 if (accessType != JAXB_TYPE_PROPERTY ) {
0 commit comments