Skip to content

Commit eb80dce

Browse files
authored
Merge pull request #136 from BobHanson/master
Byte.parseByte; Foo a = null; b = a.staticCall()
2 parents 3d5adb9 + 8b91832 commit eb80dce

File tree

18 files changed

+227
-181
lines changed

18 files changed

+227
-181
lines changed
208 Bytes
Binary file not shown.
93 Bytes
Binary file not shown.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
20191027191514
1+
20191031001912
208 Bytes
Binary file not shown.
93 Bytes
Binary file not shown.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
20191027191514
1+
20191031001912

sources/net.sf.j2s.core/src/net/sf/j2s/core/CorePlugin.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ public class CorePlugin extends Plugin {
2020
*
2121
*/
2222
public static String VERSION = "3.2.4.09";
23+
// BH 2019.10.30 -- 3.2.4.09 fixes problem with team...show history...compare having null project.getProject().getLocation()
2324
// BH 2019.10.27 -- 3.2.4.09 fixes problem with method of name c() becoming c$() -- constructor
2425
// BH 2019.10.25 -- 3.2.4.09 adds j2s.compiler.java.version (default 8)
2526
// BH 2019.10.25 -- 3.2.4.09 adds j2s.break.on.error (default false)

sources/net.sf.j2s.core/src/net/sf/j2s/core/Java2ScriptCompilationParticipant.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,12 @@ public Java2ScriptCompilationParticipant() {
4141
*/
4242
@Override
4343
public boolean isActive(IJavaProject project) {
44+
if (project.getProject().getLocation() == null) {
45+
// happens when comparing to team...show history item
46+
return false;
47+
}
4448
boolean isj2s = Java2ScriptCompiler.isActive(project);
45-
String loc = " " + project.getProject().getLocation().toString() + " ";
49+
String loc = " " + project.getProject().getLocation() + " ";
4650
// notify only if changed
4751
if (isActiveNotified.indexOf(isj2s + loc) < 0) {
4852
System.out.println("J2S isActive " + isj2s + loc);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,7 @@ boolean compileToJavaScript(IFile javaSource) {
391391
packageName = packageName.substring(0, pt);
392392
if (!copyResources.contains(packageName)) {
393393
copyResources.add(packageName);
394-
String sourceDir = sourceLocation.substring(0, sourceLocation.indexOf("/" + packageName + "/"));
394+
String sourceDir = sourceLocation.substring(0, sourceLocation.lastIndexOf("/" + packageName + "/"));
395395
File src = new File(sourceDir, packageName);
396396
File dest = new File(j2sPath, packageName);
397397
copySiteResources(src, dest);

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

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1204,9 +1204,11 @@ private void addMethodInvocation(SimpleName javaQualifier, List<?> arguments, IM
12041204
}
12051205
} else {
12061206
appendFinalMethodQualifier(expression, declaringClass, bname,
1207-
(isStatic && !isPrivate ? FINAL_ESCAPECACHE : FINAL_CACHE));
1207+
(isStatic && !isPrivate ? FINAL_ESCAPECACHE : FINAL_CACHE)
1208+
| (isStatic ? FINAL_STATIC : 0));
12081209
buffer.append(".");
12091210
}
1211+
12101212
// keep a pointer, because we may rewrite this
12111213
int ptLog = (doLog ? buffer.length() : 0);
12121214

@@ -1247,10 +1249,11 @@ private void addMethodInvocation(SimpleName javaQualifier, List<?> arguments, IM
12471249

12481250
String j2sName = getFinalDotQualifiedNameForMethod(javaQualifier, mBinding,
12491251
(expression == null ? METHOD_NULLEXPRESSION : 0) | METHOD_ISQUALIFIED
1250-
| (lambdaArity >= 0 ? LAMBDA_METHOD : 0));
1252+
| (lambdaArity >= 0 ? LAMBDA_METHOD : 0) | (isStatic ? FINAL_STATIC : 0));
12511253

12521254
String finalMethodNameWith$Params = getFinalMethodNameWith$Params(j2sName, declaringClassJavaClassName,
12531255
mBinding, null, true, METHOD_NOTSPECIAL);
1256+
12541257
if (lambdaArity >= 0) {
12551258
// The problem here is that we cannot apply a method from an interface
12561259
// because those methods are not present in JavaScript.
@@ -1323,8 +1326,12 @@ private void appendFinalMethodQualifier(Expression qualifier, ITypeBinding decla
13231326
}
13241327
} else if (qualifier instanceof Name && !isVariableBinding(qualifier)) {
13251328
buffer.append(getFinalJ2SClassNameQualifier((Name) qualifier, declaringClass, null, flags));
1329+
} else if ((flags & FINAL_STATIC) != 0) {
1330+
// ensure even if field.method(), as long as method is static, we use Class.method()
1331+
// otherwise a null value for field will throw an exception.
1332+
buffer.append(getFinalJ2SClassNameQualifier(null, declaringClass, null, flags));
13261333
} else {
1327-
// xxxx.field.foo()
1334+
// xxxx.field.foo() -- but only if foo is not static
13281335
// (x ? y : z).foo()
13291336
// xxx.this.foo()
13301337
qualifier.accept(this);
@@ -1593,7 +1600,7 @@ public boolean visit(WhileStatement node) {
15931600
private static final int FIELD_DECL_STATIC_NONDEFAULT = 1;
15941601
private static final int FIELD_DECL_STATIC_DEFAULTS = 2;
15951602
private static final int FIELD_DECL_NONSTATIC_ALL = 3;
1596-
1603+
15971604
private void addAnonymousFunctionWrapper(boolean isOpen) {
15981605
buffer.append(
15991606
isOpen ? (buffer.lastIndexOf(")") >= buffer.length() - 3 ? ";" : "") + "\r\n(function(){" : "})()\r\n");
@@ -4543,6 +4550,9 @@ private String getFinalNameForNode(SimpleName node, char lastBufferChar, IVariab
45434550

45444551
private static final int FINAL_LAMBDA = 32;
45454552

4553+
private static final int FINAL_STATIC = 64;
4554+
4555+
45464556
/**
45474557
* Provide access to C$.$clinit$ when a static method is called or a static
45484558
* field is accessed.
@@ -4565,9 +4575,9 @@ String getFinalJ2SClassNameQualifier(Name methodQualifier, ITypeBinding declarin
45654575

45664576
if (declaringJavaClassName == null)
45674577
declaringJavaClassName = getJavaClassNameQualified(declaringJavaClass);
4568-
boolean doEscape = ((flags & FINAL_ESCAPE) == FINAL_ESCAPE);
4578+
boolean isStatic = ((flags & FINAL_STATIC) == FINAL_STATIC);
4579+
boolean doEscape = isStatic || ((flags & FINAL_ESCAPE) == FINAL_ESCAPE);
45694580
boolean doCache = ((flags & FINAL_CACHE) == FINAL_CACHE);
4570-
45714581
String name = removeBracketsAndFixNullPackageName(declaringJavaClassName);
45724582
doEscape &= !NameMapper.isClassKnown(name);
45734583
if (!doEscape) {
@@ -4585,7 +4595,6 @@ String getFinalJ2SClassNameQualifier(Name methodQualifier, ITypeBinding declarin
45854595
// lambda classes will always be defined at this point. No need to cache them
45864596
if (name.indexOf("$lambda") >= 0)
45874597
return getFinalJ2SClassName(name, FINAL_P);
4588-
45894598
return getFinalClazzLoadI$Reference(declaringJavaClass, name, doCache);
45904599
}
45914600

0 commit comments

Comments
 (0)