9090// BH 8/13/2017 -- includes native code calls in System.err
9191// BH 7/31/2017 -- extensively reworked for fully qualified method names and no SAEM
9292
93- // DONE: type def, including inner classes and anonymous classes
94- // DONE: fully encapsulated C$ variable
95- // DONE: proper <init> processing
96- // DONE: non-final variables for anonymous class definition
97- // DONE: array handling in instanceof and reflection
98- // DONE: String + double/float/Double/Float --> new Double/Float().toString()
99- // TODO: Q: Good assumption that generic parameterization can be ignored? put<K,V> vs put<K>?
10093/*
10194 *
10295
@@ -110,42 +103,6 @@ interface Editable {
110103class EditDialog extends Dialog implements AdjustmentListener, ActionListener, ItemListener {
111104...
112105
113- TODO #16 when an inner public class is called by another class using instanceOf, that inner class becomes an optional load.
114- but optional loads must still be loaded, and unless declared in package.js, J2S will look for xxx.xxx.Outer/Inner.js
115- because the inner classes are not fully declared.
116-
117- Solution is to switch to requiring the outer class, not the inner class:
118-
119- @J2SRequireImport(NumberFormat.class)
120- @J2SIgnoreImport(NumberFormat.Field.class)
121- public class NumberFormatter extends InternationalFormatter...
122-
123-
124-
125- TODO #14 in java.awt.image.Raster, we have a static block that
126- creates new Objects. In that case, we need to add the annotation:
127-
128- @J2SRequireImport({ jsjava.awt.image.SinglePixelPackedSampleModel.class, jssun.awt.image.IntegerInterleavedRaster.class, jssun.awt.image.ByteInterleavedRaster.class })
129-
130-
131- TODO #12 Inner classes must not call other inner classes defined after them in a file.
132- This showed up in java.awt.geom.Path2D.Float.CopyIterator, which extends
133- java.awt.geom.Path2D.Iterator. Since the Iterator is in the code after CopyIterator,
134- the reference to java.awt.geom.Path2D.Iterator in
135-
136- c$ = Clazz.decorateAsClass (function () {
137- this.floatCoords = null;
138- Clazz.instantialize (this, arguments);
139- }, java.awt.geom.Path2D.Float, "CopyIterator", java.awt.geom.Path2D.Iterator);
140-
141- is null, and then CopyIterator does not extend Iterator.
142-
143- TODO #4 @J2SRequireImport({jsjava.util.PropertyResourceBundle.class})
144-
145- is required for public abstract class ResourceBundle because the inner class
146- ResourceBundle.Control requires it, but for some reason it is not included in the
147- MUST list in the Clazz.load() call.
148-
149106
150107 */
151108
@@ -247,7 +204,7 @@ public boolean visit(PackageDeclaration node) {
247204 if (isBasePackage ()) {
248205 buffer .append (name );
249206 } else {
250- buffer .append ("Clazz.newPackage$ (\" " ).append (name ).append ("\" )" );
207+ buffer .append ("Clazz.newPackage(\" " ).append (name ).append ("\" )" );
251208 }
252209 buffer .append (",I$=[];\r \n " );
253210 return false ;
@@ -370,22 +327,22 @@ public boolean visit(ClassInstanceCreation node) {
370327 (constructorBinding == null ? null : constructorBinding .getMethodDeclaration ()), null );
371328 return false ;
372329 }
330+ String className = TypeAdapter .getTypeStringName (node .getType ());
331+ String fqName = getShortenedQualifiedName (className );
332+ if ("Object" .equals (fqName )) {
333+ buffer .append (" Clazz.new()" );
334+ return false ;
335+ }
373336 String prefix = null , postfix = null ;
374337 IMethodBinding methodDeclaration = null ;
375338 IMethodBinding constructorBinding = node .resolveConstructorBinding ();
376- String className = TypeAdapter .getTypeStringName (node .getType ());
377- String fqName = getShortenedQualifiedName (className );
378339 if (constructorBinding != null ) {
379340 methodDeclaration = constructorBinding .getMethodDeclaration ();
380341 }
381342 boolean isDefault = false ;
382343 if ("String" .equals (fqName )) {
383344 // special treatment for String -- see j2sSwingJS.js
384345 buffer .append (" String.instantialize(" );
385- } else if ("Object" .equals (fqName )) {
386- // For discussion, please visit
387- // http://groups.google.com/group/java2script/browse_thread/thread/3d6deb9c3c0a0cda
388- buffer .append (" new Clazz._O(" ); // BH removing window.JavaObject
389346 } else if (noConstructorNames .indexOf (fqName ) >= 0 ) {
390347 // look out for java.lang.Integer and the like -- just pass it
391348 // directly
@@ -608,7 +565,7 @@ public boolean visit(MethodDeclaration node) {
608565 // names here
609566 if (name .equals ("'main'" ))
610567 addApplication ();
611- buffer .append ("\r \n Clazz.newMethod$ (C$, " ).append (name ).append (", function (" );
568+ buffer .append ("\r \n Clazz.newMeth (C$, " ).append (name ).append (", function (" );
612569 @ SuppressWarnings ("unchecked" )
613570 List <ASTNode > parameters = node .parameters ();
614571 visitList (parameters , ", " );
@@ -721,7 +678,7 @@ public boolean visit(MethodInvocation node) {
721678 if (MethodAdapter .isMethodRegistered (methodName )) {
722679 String j2sName = MethodAdapter .translate (className , methodName );
723680 if (j2sName != null ) {
724- // Array.newInstance --> Clazz.newArray$
681+ // Array.newInstance --> Clazz.array
725682 if (j2sName .startsWith ("Clazz." )) {
726683 buffer .setLength (pt );
727684 buffer .append (j2sName );
@@ -1057,7 +1014,7 @@ private void addCallInit() {
10571014 }
10581015
10591016 /**
1060- * Add Clazz.newInterface$ (...) or Clazz.newClass$ (...) for all classes and
1017+ * Add Clazz.newInterface(...) or Clazz.newClass(...) for all classes and
10611018 * interfaces, including Enum and anonymous.
10621019 *
10631020 * If this is an inner class, then iterate, just adding its definition to
@@ -1128,7 +1085,7 @@ private boolean addClassOrInterface(ASTNode node, ITypeBinding binding, List<?>
11281085
11291086 // begin the class or interface definition
11301087
1131- buffer .append ("var C$=" + (isInterface ? "Clazz.newInterface$ (" : "Clazz.newClass$ (" ));
1088+ buffer .append ("var C$=" + (isInterface ? "Clazz.newInterface(" : "Clazz.newClass(" ));
11321089
11331090 // arg1 is the package name
11341091 // arg2 is the full class name in quotes
@@ -1170,7 +1127,7 @@ private boolean addClassOrInterface(ASTNode node, ITypeBinding binding, List<?>
11701127 buffer .append (", " );
11711128 if (isAnonymous ) {
11721129 if (!(parent instanceof EnumConstantDeclaration ))
1173- func = "function(){Clazz.newInstance$ (this, arguments[0],1,C$);}" ;
1130+ func = "function(){Clazz.newInstance(this, arguments[0],1,C$);}" ;
11741131 superclassName = "" + getSuperclassNameQualified (binding );
11751132 ITypeBinding [] declaredTypes = binding .getInterfaces ();
11761133 if (declaredTypes != null && declaredTypes .length > 0 ) {
@@ -1210,7 +1167,7 @@ private boolean addClassOrInterface(ASTNode node, ITypeBinding binding, List<?>
12101167 // directly by the
12111168 // user using new Foo()
12121169 if (!isInterface ) {
1213- buffer .append ("Clazz.newInstance$ (this, arguments" )
1170+ buffer .append ("Clazz.newInstance(this, arguments" )
12141171 .append (isTopLevel ? ",0" : "[0]," + !isStatic (binding )).append (",C$);\r \n " );
12151172 }
12161173 buffer .append ("}" );
@@ -1387,7 +1344,7 @@ private boolean addClassOrInterface(ASTNode node, ITypeBinding binding, List<?>
13871344 init0Buffer = new StringBuffer ();
13881345
13891346 int len = buffer .length ();
1390- buffer .append ("\r \n Clazz.newMethod$ (C$, '$init$', function () {\r \n " );
1347+ buffer .append ("\r \n Clazz.newMeth (C$, '$init$', function () {\r \n " );
13911348 // we include all field definitions here and all nonstatic
13921349 // initializers
13931350 for (Iterator <?> iter = bodyDeclarations .iterator (); iter .hasNext ();) {
@@ -1405,7 +1362,7 @@ private boolean addClassOrInterface(ASTNode node, ITypeBinding binding, List<?>
14051362 if (init0Buffer .length () > 0 ) {
14061363 String buf = buffer .substring (len );
14071364 buffer .setLength (len );
1408- buffer .append ("\r \n Clazz.newMethod$ (C$, '$init0$', function () {\r \n " );
1365+ buffer .append ("\r \n Clazz.newMeth (C$, '$init0$', function () {\r \n " );
14091366 buffer .append ("var c;if((c = C$.superClazz) && (c = c.$init0$))c.apply(this);\r \n " );
14101367 buffer .append (init0Buffer );
14111368 buffer .append ("}, 1);\r \n " );
@@ -1486,7 +1443,7 @@ private boolean addClassOrInterface(ASTNode node, ITypeBinding binding, List<?>
14861443 }
14871444
14881445 /**
1489- * For Clazz.newClazz $ we want an array if there is an inner class
1446+ * For Clazz.newClass $ we want an array if there is an inner class
14901447 * so that the outer class is guarranteed to be loaded first.
14911448 *
14921449 * @param className
@@ -1518,7 +1475,7 @@ private void addDefaultConstructor() {
15181475 if (haveDefaultConstructor ) {
15191476 haveDefaultConstructor = false ;
15201477 } else {
1521- buffer .append ("\r \n Clazz.newMethod$ (C$);\r \n " );
1478+ buffer .append ("\r \n Clazz.newMeth (C$);\r \n " );
15221479 }
15231480 }
15241481
@@ -1540,7 +1497,7 @@ private void addEnumConstants(List<?> constants) {
15401497 anonName = getAnonymousName (anonDeclare .resolveBinding ());
15411498 buffer .append ("\r \n " );
15421499 }
1543- buffer .append ("Clazz.newEnumConst$ (vals, " ).append (getJ2SQualifiedName ("C$.c$" , null , binding , null , false ))
1500+ buffer .append ("Clazz.newEnumConst(vals, " ).append (getJ2SQualifiedName ("C$.c$" , null , binding , null , false ))
15441501 .append (", \" " );
15451502 enumConst .getName ().accept (this );
15461503 buffer .append ("\" , " + i );
@@ -1549,10 +1506,10 @@ private void addEnumConstants(List<?> constants) {
15491506 buffer .append (", " ).append (anonName );
15501507 buffer .append (");\r \n " );
15511508 }
1552- buffer .append ("Clazz.newMethod$ (C$, 'values', function() { return vals }, 1);\r \n " );
1509+ buffer .append ("Clazz.newMeth (C$, 'values', function() { return vals }, 1);\r \n " );
15531510 // this next just ensures we have the valueOf() method in Enum if it
15541511 // is not already there.
1555- buffer .append ("Clazz.newMethod$ (Enum, 'valueOf$Class$S', function(cl, name) { return cl[name] }, 1);\r \n " );
1512+ buffer .append ("Clazz.newMeth (Enum, 'valueOf$Class$S', function(cl, name) { return cl[name] }, 1);\r \n " );
15561513 }
15571514
15581515 /**
@@ -1602,7 +1559,7 @@ private boolean addFieldDeclaration(FieldDeclaration field, int mode) {
16021559 buffer .append (";\r \n " );
16031560 //
16041561 // $clinit$ -- statics; once only
1605- // $init0$ -- from within Clazz.newInstance$ , before any
1562+ // $init0$ -- from within Clazz.newInstance, before any
16061563 // constructors
16071564 // $init$ -- from the constructor, just after any super()
16081565 // call or whenever there is no this() call
0 commit comments