Skip to content

Commit 37a6916

Browse files
authored
Merge pull request #35 from BobHanson/master
this.this$0 fix; ResettableStream interface removed
2 parents 2c26fcc + 66cf46d commit 37a6916

File tree

5 files changed

+15
-19
lines changed

5 files changed

+15
-19
lines changed
49 Bytes
Binary file not shown.
49 Bytes
Binary file not shown.

sources/net.sf.j2s.core/src/net/sf/j2s/core/astvisitors/Java2ScriptVisitor.java

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@
122122
import org.eclipse.jdt.core.dom.WhileStatement;
123123
import org.eclipse.jdt.core.dom.WildcardType;
124124

125+
// BH 3/27/2018 -- fix for anonymous inner classes of inner classes not having this.this$0
125126
// BH 1/5/2018 -- @j2sKeep removed; refactored into one class
126127

127128
// BH 12/31/2017 -- competely rewritten for no run-time ambiguities
@@ -252,7 +253,7 @@ private void setInnerGlobals(Java2ScriptVisitor parent, ASTNode node, String vis
252253
global_includes = parent.global_includes;
253254
global_j2sFlag_isDebugging = parent.global_j2sFlag_isDebugging;
254255
global_mapBlockJavadoc = parent.global_mapBlockJavadoc;
255-
parentClassName = parent.getQualifiedClassName();
256+
this$0Name = parent.getQualifiedClassName();
256257

257258
innerTypeNode = node;
258259
setClassName(visitorClassName);
@@ -1076,7 +1077,7 @@ private boolean addClassOrInterface(ASTNode node, ITypeBinding binding, List<?>
10761077
// definition in the static buffer and return
10771078
String className;
10781079
if (parent instanceof TypeDeclarationStatement) {
1079-
String anonClassName = assureQualifiedNameAllowP$(binding.isAnonymous() || binding.isLocal()
1080+
String anonClassName = assureQualifiedNameAllowP$(isAnonymous|| binding.isLocal()
10801081
? binding.getBinaryName() : binding.getQualifiedName());
10811082
className = anonClassName.substring(anonClassName.lastIndexOf('.') + 1);
10821083
} else {
@@ -1089,6 +1090,7 @@ private boolean addClassOrInterface(ASTNode node, ITypeBinding binding, List<?>
10891090
tempVisitor = new Java2ScriptVisitor(); // Default visitor
10901091
}
10911092
tempVisitor.setInnerGlobals(this, node, className);
1093+
10921094
node.accept(tempVisitor);
10931095
trailingBuffer.append(tempVisitor.buffer.toString());
10941096
return false;
@@ -1130,11 +1132,14 @@ private boolean addClassOrInterface(ASTNode node, ITypeBinding binding, List<?>
11301132

11311133
String oldClassName = null;
11321134
String fullClassName, defaultPackageName;
1133-
1135+
String this$0Name0 = this$0Name;
11341136
if (isAnonymous) {
11351137
oldClassName = typeAdapter.getClassName();
11361138
fullClassName = getAnonymousName(binding); // P$.Test_Enum$Planet$1
11371139
defaultPackageName = "null";
1140+
// anonymous classes reference their package, not their outer class in Clazz.newClass,
1141+
// so clazz.$this$0 is not assigned.
1142+
this$0Name = null;
11381143
} else {
11391144
fullClassName = getQualifiedClassName(); // test.Test_Enum.Planet
11401145
defaultPackageName = global_PackageName;
@@ -1468,6 +1473,7 @@ private boolean addClassOrInterface(ASTNode node, ITypeBinding binding, List<?>
14681473
if (isAnonymous) {
14691474
buffer.append(")");
14701475
typeAdapter.setClassName(oldClassName);
1476+
this$0Name = this$0Name0;
14711477
}
14721478
return false;
14731479
}
@@ -1838,7 +1844,7 @@ private static final String getPrimitiveTYPE(String name) {
18381844
private int blockLevel = 0;
18391845
private int currentBlockForVisit = -1;
18401846

1841-
public String parentClassName;
1847+
public String this$0Name;
18421848

18431849

18441850
/**
@@ -3542,7 +3548,7 @@ private void appendShortenedQualifiedName(String packageName, String name, boole
35423548
}
35433549

35443550
private String getSyntheticReference(String className) {
3545-
b$name = (className.equals(parentClassName) ? ".this$0" : ".b$['" + assureQualifiedNameNoC$(null, className) + "']");
3551+
b$name = (className.equals(this$0Name) ? ".this$0" : ".b$['" + assureQualifiedNameNoC$(null, className) + "']");
35463552
return "this" + b$name;
35473553
}
35483554

sources/net.sf.j2s.java.core/src/javajs/api/ResettableStream.java

Lines changed: 0 additions & 7 deletions
This file was deleted.

sources/net.sf.j2s.java.core/src/swingjs/JSAudio.java

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
import javax.sound.sampled.Line;
1414
import javax.sound.sampled.UnsupportedAudioFileException;
1515

16-
import javajs.api.ResettableStream;
1716
import javajs.util.BC;
1817
import javajs.util.Base64;
1918
import javajs.util.OC;
@@ -370,10 +369,9 @@ private static AudioFormat getAudioFormatForStreamOrBytes(
370369

371370
Map<String, Object> props = new Hashtable<String, Object>();
372371
String fmt = (stream == null ? getAudioTypeForBytes(header) : getAudioTypeForStream(stream));
373-
ResettableStream jsstream = (ResettableStream) stream;
374372
props.put("fileFormat", fmt);
375373
if (stream != null)
376-
jsstream.resetStream();
374+
stream.reset();
377375
Encoding encoding = null;
378376
float sampleRate = -1;
379377
int sampleSizeInBits = -1;
@@ -423,23 +421,22 @@ private static AudioFormat getAudioFormatForStreamOrBytes(
423421
} catch (Throwable e) {
424422
} finally {
425423
if (stream != null)
426-
jsstream.resetStream();
424+
stream.reset();
427425
}
428426
return new AudioFormat(encoding, sampleRate, sampleSizeInBits, channels,
429427
frameSize, frameRate, bigEndian, props);
430428
}
431429

432430

433431
private static String getAudioTypeForStream(ByteArrayInputStream stream) throws UnsupportedAudioFileException {
434-
ResettableStream jsstream = (ResettableStream) (Object) stream;
435-
jsstream.resetStream();
432+
stream.reset();
436433
byte[] b = new byte[12];
437434
try {
438435
stream.read(b);
439436
} catch (IOException e) {
440437
// no problem
441438
}
442-
jsstream.resetStream();
439+
stream.reset();
443440
return getAudioTypeForBytes(b);
444441
}
445442

0 commit comments

Comments
 (0)