diff --git a/sources/net.sf.j2s.core/dist/dropins/net.sf.j2s.core.jar b/sources/net.sf.j2s.core/dist/dropins/net.sf.j2s.core.jar index 06d20c310..98a5641c9 100644 Binary files a/sources/net.sf.j2s.core/dist/dropins/net.sf.j2s.core.jar and b/sources/net.sf.j2s.core/dist/dropins/net.sf.j2s.core.jar differ diff --git a/sources/net.sf.j2s.core/dist/net.sf.j2s.core_3.1.1.jar b/sources/net.sf.j2s.core/dist/net.sf.j2s.core_3.1.1.jar index 06d20c310..98a5641c9 100644 Binary files a/sources/net.sf.j2s.core/dist/net.sf.j2s.core_3.1.1.jar and b/sources/net.sf.j2s.core/dist/net.sf.j2s.core_3.1.1.jar differ diff --git a/sources/net.sf.j2s.core/src/net/sf/j2s/core/astvisitors/Java2ScriptVisitor.java b/sources/net.sf.j2s.core/src/net/sf/j2s/core/astvisitors/Java2ScriptVisitor.java index 143dc927a..fd4e9546f 100644 --- a/sources/net.sf.j2s.core/src/net/sf/j2s/core/astvisitors/Java2ScriptVisitor.java +++ b/sources/net.sf.j2s.core/src/net/sf/j2s/core/astvisitors/Java2ScriptVisitor.java @@ -122,6 +122,7 @@ import org.eclipse.jdt.core.dom.WhileStatement; import org.eclipse.jdt.core.dom.WildcardType; +// BH 3/27/2018 -- fix for anonymous inner classes of inner classes not having this.this$0 // BH 1/5/2018 -- @j2sKeep removed; refactored into one class // BH 12/31/2017 -- competely rewritten for no run-time ambiguities @@ -252,7 +253,7 @@ private void setInnerGlobals(Java2ScriptVisitor parent, ASTNode node, String vis global_includes = parent.global_includes; global_j2sFlag_isDebugging = parent.global_j2sFlag_isDebugging; global_mapBlockJavadoc = parent.global_mapBlockJavadoc; - parentClassName = parent.getQualifiedClassName(); + this$0Name = parent.getQualifiedClassName(); innerTypeNode = node; setClassName(visitorClassName); @@ -1076,7 +1077,7 @@ private boolean addClassOrInterface(ASTNode node, ITypeBinding binding, List // definition in the static buffer and return String className; if (parent instanceof TypeDeclarationStatement) { - String anonClassName = assureQualifiedNameAllowP$(binding.isAnonymous() || binding.isLocal() + String anonClassName = assureQualifiedNameAllowP$(isAnonymous|| binding.isLocal() ? binding.getBinaryName() : binding.getQualifiedName()); className = anonClassName.substring(anonClassName.lastIndexOf('.') + 1); } else { @@ -1089,6 +1090,7 @@ private boolean addClassOrInterface(ASTNode node, ITypeBinding binding, List tempVisitor = new Java2ScriptVisitor(); // Default visitor } tempVisitor.setInnerGlobals(this, node, className); + node.accept(tempVisitor); trailingBuffer.append(tempVisitor.buffer.toString()); return false; @@ -1130,11 +1132,14 @@ private boolean addClassOrInterface(ASTNode node, ITypeBinding binding, List String oldClassName = null; String fullClassName, defaultPackageName; - + String this$0Name0 = this$0Name; if (isAnonymous) { oldClassName = typeAdapter.getClassName(); fullClassName = getAnonymousName(binding); // P$.Test_Enum$Planet$1 defaultPackageName = "null"; + // anonymous classes reference their package, not their outer class in Clazz.newClass, + // so clazz.$this$0 is not assigned. + this$0Name = null; } else { fullClassName = getQualifiedClassName(); // test.Test_Enum.Planet defaultPackageName = global_PackageName; @@ -1468,6 +1473,7 @@ private boolean addClassOrInterface(ASTNode node, ITypeBinding binding, List if (isAnonymous) { buffer.append(")"); typeAdapter.setClassName(oldClassName); + this$0Name = this$0Name0; } return false; } @@ -1838,7 +1844,7 @@ private static final String getPrimitiveTYPE(String name) { private int blockLevel = 0; private int currentBlockForVisit = -1; - public String parentClassName; + public String this$0Name; /** @@ -3542,7 +3548,7 @@ private void appendShortenedQualifiedName(String packageName, String name, boole } private String getSyntheticReference(String className) { - b$name = (className.equals(parentClassName) ? ".this$0" : ".b$['" + assureQualifiedNameNoC$(null, className) + "']"); + b$name = (className.equals(this$0Name) ? ".this$0" : ".b$['" + assureQualifiedNameNoC$(null, className) + "']"); return "this" + b$name; } diff --git a/sources/net.sf.j2s.java.core/src/javajs/api/ResettableStream.java b/sources/net.sf.j2s.java.core/src/javajs/api/ResettableStream.java deleted file mode 100644 index 5ded55f07..000000000 --- a/sources/net.sf.j2s.java.core/src/javajs/api/ResettableStream.java +++ /dev/null @@ -1,7 +0,0 @@ -package javajs.api; - -public interface ResettableStream { - - void resetStream(); - -} diff --git a/sources/net.sf.j2s.java.core/src/swingjs/JSAudio.java b/sources/net.sf.j2s.java.core/src/swingjs/JSAudio.java index 5ce2fab50..cc542a007 100644 --- a/sources/net.sf.j2s.java.core/src/swingjs/JSAudio.java +++ b/sources/net.sf.j2s.java.core/src/swingjs/JSAudio.java @@ -13,7 +13,6 @@ import javax.sound.sampled.Line; import javax.sound.sampled.UnsupportedAudioFileException; -import javajs.api.ResettableStream; import javajs.util.BC; import javajs.util.Base64; import javajs.util.OC; @@ -370,10 +369,9 @@ private static AudioFormat getAudioFormatForStreamOrBytes( Map props = new Hashtable(); String fmt = (stream == null ? getAudioTypeForBytes(header) : getAudioTypeForStream(stream)); - ResettableStream jsstream = (ResettableStream) stream; props.put("fileFormat", fmt); if (stream != null) - jsstream.resetStream(); + stream.reset(); Encoding encoding = null; float sampleRate = -1; int sampleSizeInBits = -1; @@ -423,7 +421,7 @@ private static AudioFormat getAudioFormatForStreamOrBytes( } catch (Throwable e) { } finally { if (stream != null) - jsstream.resetStream(); + stream.reset(); } return new AudioFormat(encoding, sampleRate, sampleSizeInBits, channels, frameSize, frameRate, bigEndian, props); @@ -431,15 +429,14 @@ private static AudioFormat getAudioFormatForStreamOrBytes( private static String getAudioTypeForStream(ByteArrayInputStream stream) throws UnsupportedAudioFileException { - ResettableStream jsstream = (ResettableStream) (Object) stream; - jsstream.resetStream(); + stream.reset(); byte[] b = new byte[12]; try { stream.read(b); } catch (IOException e) { // no problem } - jsstream.resetStream(); + stream.reset(); return getAudioTypeForBytes(b); }