Skip to content

Commit 2b20e97

Browse files
committed
moving JAudioThread to javajs; fix for Clazz.load(P$....)
1 parent def715e commit 2b20e97

4 files changed

Lines changed: 98 additions & 33 deletions

File tree

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

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -829,12 +829,18 @@ public boolean visit(QualifiedName node) {
829829
// avoid generate duplicated RadiusData
830830
className = typeBinding.getQualifiedName();
831831
if (allowExtensions)
832-
className = ExtendedAdapter.trimName(className, false); //?? probably should be true
832+
className = ExtendedAdapter.trimName(className, false); // ??
833+
// probably
834+
// should
835+
// be
836+
// true
833837
if (className.indexOf("java.lang.") == 0) {
834838
className = className.substring(10);
835839
}
836-
if (isStatic(nameBinding))
837-
className = getQualifiedStaticName(null, className, true, true, false); }
840+
if (isStatic(nameBinding)) {
841+
className = getQualifiedStaticName(null, className, true, true, false);
842+
}
843+
}
838844
}
839845
}
840846

@@ -1773,9 +1779,15 @@ protected String getQualifiedStaticName(Name methodQualifier, String className,
17731779
int nclass = 0;
17741780
for (int i = 0; i < parts.length; i++) {
17751781
String part = parts[i];
1776-
if (i == 0 && (part.equals("C$") || part.equals("P$"))) {
1777-
s += part;
1778-
continue;
1782+
if (i == 0) {
1783+
if (part.equals("C$")) {
1784+
s += part;
1785+
continue;
1786+
}
1787+
if (part.equals("P$")) {
1788+
// can't do this with Clazz.load
1789+
part = getPackageName();
1790+
}
17791791
}
17801792
s += (i == 0 ? "'" : ".");
17811793
s += part;
@@ -1894,7 +1906,6 @@ private void simpleNameInVarBinding(SimpleName node, char ch, IVariableBinding v
18941906
}
18951907
name = fixName(name);
18961908
if (name.length() != 0) {
1897-
18981909
getQualifiedStaticName(null, name, true,true,true);
18991910

19001911
// buffer.append(name);

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

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,8 @@
1212
import java.text.SimpleDateFormat;
1313
import java.util.ArrayList;
1414
import java.util.Date;
15-
import java.util.HashMap;
16-
import java.util.Hashtable;
1715
import java.util.Iterator;
1816
import java.util.List;
19-
import java.util.Map;
2017

2118
import org.eclipse.jdt.core.dom.ASTNode;
2219
import org.eclipse.jdt.core.dom.AbstractTypeDeclaration;
@@ -1012,7 +1009,6 @@ public boolean visit(TryStatement node) {
10121009
*
10131010
*/
10141011
public boolean visit(TypeDeclaration node) {
1015-
System.err.println("visit " + node.resolveBinding().getKey());
10161012
return addClassOrInterface(node, node.resolveBinding(), node.bodyDeclarations(), node.isInterface() ? 'i' :
10171013
node.isLocalTypeDeclaration() ? 'l' : 'c');
10181014
}
@@ -1123,6 +1119,7 @@ private boolean addClassOrInterface(ASTNode node, ITypeBinding binding, List<?>
11231119
staticBuffer.append(tempVisitor.getBuffer().toString());
11241120
return false;
11251121
}
1122+
System.err.println("visit " + binding.getKey());
11261123
boolean isTopLevel = binding.isTopLevel();
11271124
if (isTopLevel) {
11281125
typeAdapter.setClassName(binding.getName());

sources/net.sf.j2s.core/src/net/sf/j2s/core/compiler/Java2ScriptCompiler.java

Lines changed: 79 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,23 @@
22

33
import java.io.BufferedReader;
44
import java.io.File;
5+
import java.io.FileFilter;
56
import java.io.FileInputStream;
67
import java.io.FileNotFoundException;
78
import java.io.FileOutputStream;
89
import java.io.IOException;
910
import java.io.InputStreamReader;
11+
import java.nio.file.Files;
12+
import java.nio.file.StandardCopyOption;
1013
import java.util.ArrayList;
14+
import java.util.HashSet;
1115
import java.util.Iterator;
1216
import java.util.List;
1317
import java.util.Properties;
1418

1519
import org.eclipse.core.resources.IContainer;
1620
import org.eclipse.core.resources.IProject;
17-
import org.eclipse.jdt.core.IMethod;
18-
import org.eclipse.jdt.core.IType;
1921
import org.eclipse.jdt.core.JavaCore;
20-
import org.eclipse.jdt.core.JavaModelException;
2122
import org.eclipse.jdt.core.dom.AST;
2223
import org.eclipse.jdt.core.dom.ASTParser;
2324
import org.eclipse.jdt.core.dom.CompilationUnit;
@@ -40,14 +41,17 @@ public class Java2ScriptCompiler implements IExtendedCompiler {
4041

4142
// BH: added "true".equals(getProperty(props, "j2s.compiler.allow.compression")) to ensure compression only occurs when desired
4243
static final int JSL_LEVEL = AST.JLS8; // BH can we go to JSL 8?
43-
private static boolean showJ2SSettings = true; // BH adding this
44+
45+
private static boolean showJ2SSettings = true;
46+
private static HashSet<String> copyResources = new HashSet<String>();
47+
4448
private static Properties props;
4549
private static String htmlTemplate = null;
4650

4751
public void process(ICompilationUnit sourceUnit, IContainer binaryFolder) {
4852
final IProject project = binaryFolder.getProject();
4953

50-
54+
5155
bhTest(project);
5256

5357
/*
@@ -98,12 +102,22 @@ public void process(ICompilationUnit sourceUnit, IContainer binaryFolder) {
98102

99103
if (htmlTemplate == null) {
100104
String htmlTemplateFile = getProperty("template.html");
105+
//System.err.println("htmltemplate " + htmlTemplateFile);
101106
if (htmlTemplateFile == null)
102107
htmlTemplateFile = "template.html";
103-
file = new File(siteFolder, htmlTemplateFile);
104-
if (!file.exists())
105-
writeToFile(file, getDefaultHTMLTemplate());
108+
//System.err.println("htmltemplate " + htmlTemplateFile);
109+
file = new File(prjFolder, htmlTemplateFile);
110+
//System.err.println("htmltemplate " + htmlTemplateFile);
111+
if (!file.exists()) {
112+
String html = getDefaultHTMLTemplate();
113+
System.err.println("creating new htmltemplate\n" + html);
114+
writeToFile(file, html);
115+
}
106116
htmlTemplate = getFileContents(file);
117+
//System.err.println("htmltemplate:\n" + htmlTemplate);
118+
119+
if (showJ2SSettings)
120+
System.err.println("using HTML template " + file);
107121
}
108122

109123
CompilationUnit root;
@@ -241,8 +255,23 @@ public void process(ICompilationUnit sourceUnit, IContainer binaryFolder) {
241255
}
242256
}
243257
}
258+
String packageName = visitor.getPackageName();
259+
if (packageName != null) {
260+
int pt = packageName.indexOf(".");
261+
if (pt >= 0)
262+
packageName = packageName.substring(0, pt);
263+
if (!copyResources.contains(packageName)) {
264+
copyResources.add(packageName);
265+
File src = new File(prjFolder + "/src", packageName);
266+
File dest = new File(j2sPath, packageName);
267+
copySiteResources(src, dest);
268+
}
269+
}
244270
}
245271

272+
/**
273+
* @param project
274+
*/
246275
private void bhTest(IProject project) {
247276
// IJavaProject jp = JavaCore.create(project);
248277
// try {
@@ -266,20 +295,6 @@ private void bhTest(IProject project) {
266295
//
267296
}
268297

269-
private void showClass(IType t2c) throws JavaModelException {
270-
IMethod[] im = t2c.getMethods();
271-
if (im != null)
272-
for (int i = 0; i < im.length; i++) {
273-
IMethod m = im[i];
274-
System.err.print(m.getElementName() + " " + m.getSignature() + " ");
275-
String[] mt = m.getParameterTypes();
276-
if (mt != null)
277-
for (int j = 0; j < mt.length; j++)
278-
System.err.print("para " + mt[j]);
279-
System.err.println("\n\n");
280-
}
281-
}
282-
283298
/**
284299
* untested
285300
*
@@ -748,5 +763,47 @@ private static void addHTML(ArrayList<String> appList, String siteFolder, String
748763
}
749764
}
750765

766+
private static FileFilter filter = new FileFilter() {
767+
768+
@Override
769+
public boolean accept(File pathname) {
770+
return pathname.isDirectory() || !pathname.getName().endsWith(".java");
771+
}
772+
773+
};
774+
775+
private static void copySiteResources(File from, File dest) {
776+
copyNonclassFiles(from, dest);
777+
}
778+
779+
private static void copyNonclassFiles(File dir, File target) {
780+
if (dir.equals(target))
781+
return;
782+
File[] files = dir.listFiles(filter);
783+
File f = null;
784+
if (files != null)
785+
try {
786+
if (!target.exists())
787+
Files.createDirectories(target.toPath());
788+
for (int i = 0; i < files.length; i++) {
789+
f = files[i];
790+
if (f == null) {
791+
//
792+
} else if (f.isDirectory()) {
793+
copyNonclassFiles(f, new File(target, f.getName()));
794+
} else {
795+
Files.copy(f.toPath(), new File(target, f.getName()).toPath(),
796+
StandardCopyOption.REPLACE_EXISTING);
797+
System.err.println("copied " + f + " to " + target);
798+
}
799+
}
800+
} catch (IOException e1) {
801+
// TODO Auto-generated catch block
802+
System.err.println("error copying " + f + " to " + target);
803+
e1.printStackTrace();
804+
}
805+
}
806+
751807

752808
}
809+

sources/net.sf.j2s.java.core/src/swingjs/JSAudioThread.java renamed to sources/net.sf.j2s.java.core/src/javajs/util/JSAudioThread.java

File renamed without changes.

0 commit comments

Comments
 (0)