139139// as a need to recompile automatically
140140// TODO: Create a j2s configuration tag "j2s.jaxb.packages= package;package;package..."
141141// that will direct the transpiler to create __ANN__ in any class within this package.
142- // BH 11/4/2018 -- 3.2.4.02 broad JAXB support
143- // BH 10/27/2018 -- 3.2.4.01 support for JAXB FIELD+propOrder and NONE types
144- // BH 9/28/2018 -- 3.2.4.00 adds minimal support for JAXB
145- // BH 9/23/2018 -- 3.2.3.00 adds support for java.applet.Applet and java.awt.* controls without use of a2s.*
146- // BH 9/16/2018 -- 3.2.2.06 removes "$" in JApplet public method alternative name
147- // BH 8/20/2018 -- fix for return (short)++;
148- // BH 8/19/2018 -- refactored to simplify $finals$
149- // BH 8/12/2018 -- refactored to simplify naming issues
150- // BH 8/6/2018 -- additional Java 8 fixes; enum $valueOf$S to valueOf$S
151- // BH 8/1/2018 -- adds interface default methods as C$.$defaults$(C$)
152- // BH 7/29/2018 -- java.util.stream.Collectors is returning java.util.Collectionthis.b$['java.util.Collection'].add
153-
154- // BH 7/25/2018 -- allows for direct private function calls in inner and anonymous classes using var p$, p$$, p$$$, etc
155- // BH 7/22/2018 -- fixes improper use of charCodeAt() to replace charCode().$c() when not java.lang.String.charAt
156- // BH 7/20/2018 -- removes qualifications for single-abstract method overrides
157- // BH 7/19/2018 -- fixes Enum.Enum
158- // BH 7/18/2018 -- addw Java 8 try without catch or finally
159- // BH 7/16/2018 -- adds Java 8 :: operator
160- // BH 7/15/2018 -- adds Java 8 lambda expressions
161- // BH 7/14/2018 -- removes java2scriptbuilder; uses CompilationParticipant instead
162- // BH 7/5/2018 -- fixes int | char
163- // BH 7/3/2018 -- adds tryWithResource
164- // BH 7/3/2018 -- adds effectively final -- FINAL keyword no longer necessary
165- // BH 6/27/2018 -- fix for a[Integer] not becoming a[Integer.valueOf]
166- // BH 6/26/2018 -- method logging via j2s.log.methods.called and j2s.log.methods.declared
167- // BH 6/24/2018 -- synchronized(a = new Object()) {...} ---> ...; only if an assignment or not a simple function call to Object.getTreeLock()
168- // BH 6/23/2018 -- synchronized(a = new Object()) {...} ---> if(!(a = new Object()) {throw new NullPointerException()}else{...}
169- // BH 6/21/2018 -- CharSequence.subSequence() should be defined both subSequence$I$I and subSequence
170- // BH 6/20/2018 -- fixes for (int var : new int[] {3,4,5}) becoming for var var
171- // BH 6/19/2018 -- adds .j2s j2s.class.replacements=org.apache.log4j.->jalview.javascript.log4j.;
172- // BH 5/15/2018 -- fix for a[pt++] |= 3 incrementing pt twice and disregarding a[][] (see test/Test_Or.java)
173- // BH 3/27/2018 -- fix for anonymous inner classes of inner classes not having this.this$0
174- // BH 1/5/2018 -- @j2sKeep removed; refactored into one class
175-
176- // BH 12/31/2017 -- competely rewritten for no run-time ambiguities
177- // BH 9/10/2017 -- adds full byte, short, and int distinction using class-level local fields $b$, $s$, and $i$, which are IntXArray[1]. (See ASTKeywordVisitor)
178- // BH 9/7/2017 -- primitive casting for *=,/=,+=,-=,&=,|=,^=
179- // BH 9/7/2017 -- primitive numeric casting -- (byte) was ignored so that (byte) 0xFF remained 0xFF.
180- // BH 9/7/2017 -- fixed multiple issues with char and Character
181- // BH 9/4/2017 -- java.awt, javax.swing, swingjs code added; additional fixes required
182- // BH 8/30/2017 -- all i/o working, including printf and FileOutputStream
183- // BH 8/19/2017 -- String must implement CharSequence, so all .length() -> .length$()
184- // BH 8/19/2017 -- varargs logic fixed for missing argument
185- // BH 8/18/2017 -- array instanceof, reflection, componentType fixes
186- // BH 8/16/2017 -- JSE8-UnionType catch (Exception... | Exception...) {...}
187- // BH 8/13/2017 -- includes native code calls in System.err
188- // BH 7/31/2017 -- extensively reworked for fully qualified method names and no SAEM
189-
190142/**
191143 *
192144 * @author zhou renjian 2006-12-3
@@ -640,10 +592,6 @@ private String getClassJavaNameForType(Type type) {
640592 QualifiedType qualType = (QualifiedType ) type ;
641593 return getClassJavaNameForType (qualType .getQualifier ()) + "." + qualType .getName ().getIdentifier ();
642594 }
643- // if (type instanceof NameQualifiedType) {
644- // NameQualifiedType nType = (NameQualifiedType) type;
645- // return getClassJavaNameForClass(nType.getQualifier()) + "." + nType.getName().getIdentifier();
646- // }
647595 if (type instanceof ArrayType )
648596 return getClassJavaNameForType (((ArrayType ) type ).getElementType ());
649597 if (type instanceof ParameterizedType )
@@ -1174,30 +1122,19 @@ private void addMethodInvocation(SimpleName javaQualifier, List<?> arguments, IM
11741122 ITypeBinding declaringClass = mBinding .getDeclaringClass ();
11751123 String declaringClassJavaClassName = getJavaClassNameQualified (declaringClass );
11761124
1177- // System. out.println -- System.out is static, but println is not.
1178- // nonetheless, Modifier.isStatic() returns true.
1179-
1180- boolean isStatic = isStatic (mBinding );// || expression != null && isStatic(expression.resolveTypeBinding()));
1181- // if (!isStatic && expression instanceof Name) {
1182- // IBinding binding = ((Name) expression).resolveBinding();
1183- // // no, because sometimes these are not fully qualified className =
1184- // // expression.toString();
1185- // // because System.out is the name of a static field, not a class
1186- // isStatic |= isStatic(binding);
1187- // }
1125+ boolean isStatic = isStatic (mBinding );
11881126 boolean isPrivate = isPrivate (mBinding );
11891127 boolean isPrivateAndNotStatic = isPrivate && !isStatic ;
11901128 String privateVar = (isPrivateAndNotStatic ? getPrivateVar (declaringClass , false ) : null );
11911129 boolean doLog = (!isPrivate && global_htMethodsCalled != null );
1192-
1193- boolean needBname = (!isStatic && expression == null && lambdaArity < 0
1194- && !areEqual (declaringClass , class_typeBinding )
1195- && !class_typeBinding .isAssignmentCompatible (declaringClass ));
1196-
1130+ boolean needBname = (!isStatic && lambdaArity < 0 &&
1131+ (expression == null
1132+ ? !areEqual (declaringClass , class_typeBinding )
1133+ && !class_typeBinding .isAssignmentCompatible (declaringClass )
1134+ : expression instanceof ThisExpression && ((ThisExpression ) expression ).getQualifier () != null )
1135+ );
11971136 String bname = (needBname ? getThisRefOrSyntheticReference (javaQualifier , declaringClass , null ) : null );
1198-
11991137 // add the qualifier
1200-
12011138 int pt = buffer .length ();
12021139 if (isPrivateAndNotStatic ) {
12031140 // note that the following expression will not work if the method is private:
@@ -1209,22 +1146,20 @@ private void addMethodInvocation(SimpleName javaQualifier, List<?> arguments, IM
12091146 doLog = false ;
12101147 if (bname != null )
12111148 allowClazzNewLambda = false ;
1212- } else {
1213- if (expression == null ) {
1214- doLog = false ;
1215- if (bname != null ) {
1216- buffer .append (bname );
1217- buffer .append ("." );
1218- } else if (!isStatic ) {
1219- buffer .append ("this." );
1220- } else {
1221- // this will be C$., I think.
1222- }
1223- } else {
1224- appendFinalMethodQualifier (expression , declaringClassJavaClassName , bname ,
1225- (isStatic && !isPrivate ? FINAL_ESCAPECACHE : FINAL_CACHE ));
1149+ } else if (expression == null ) {
1150+ doLog = false ;
1151+ if (bname != null ) {
1152+ buffer .append (bname );
12261153 buffer .append ("." );
1154+ } else if (!isStatic ) {
1155+ buffer .append ("this." );
1156+ } else {
1157+ // this will be C$., I think.
12271158 }
1159+ } else {
1160+ appendFinalMethodQualifier (expression , declaringClassJavaClassName , bname ,
1161+ (isStatic && !isPrivate ? FINAL_ESCAPECACHE : FINAL_CACHE ));
1162+ buffer .append ("." );
12281163 }
12291164 // keep a pointer, because we may rewrite this
12301165 int ptLog = (doLog ? buffer .length () : 0 );
@@ -1247,8 +1182,7 @@ private void addMethodInvocation(SimpleName javaQualifier, List<?> arguments, IM
12471182 && (methodName .equals ("indexOf" ) || methodName .equals ("lastIndexOf" ))) {
12481183 // indicate to boxer method to use method "q" not "p" here.
12491184 // This allows characters to be left as strings in String.indexOf$I and
1250- // String.lastIndexOf$I
1251- // for faster processing.
1185+ // String.lastIndexOf$I for faster processing.
12521186 isIndexOf = true ;
12531187 }
12541188 }
@@ -1344,6 +1278,7 @@ private void appendFinalMethodQualifier(Expression qualifier, String declaringCl
13441278 } else {
13451279 // xxxx.field.foo()
13461280 // (x ? y : z).foo()
1281+ // xxx.this.foo()
13471282 qualifier .accept (this );
13481283 }
13491284 }
@@ -3431,8 +3366,13 @@ public boolean visit(SuperFieldAccess node) {
34313366 *
34323367 */
34333368 public boolean visit (ThisExpression node ) {
3434- buffer .append (node .getQualifier () == null ? "this"
3435- : getThisRefOrSyntheticReference (node , node .resolveTypeBinding (), "this" ));
3369+ if (node .getQualifier () == null ) {
3370+ buffer .append ("this" );
3371+ return false ;
3372+ }
3373+ // xxxx.this.x
3374+ // xxxx.this.foo()
3375+ buffer .append (getThisRefOrSyntheticReference (node , node .resolveTypeBinding (), "this" ));
34363376 return false ;
34373377 }
34383378
0 commit comments