mirror of
https://github.com/cincheo/jsweet.git
synced 2025-12-15 15:29:22 +00:00
handle hidden global function with fully qualified names
This commit is contained in:
parent
5e17a74bae
commit
1e93140e24
@ -61,12 +61,14 @@ import com.sun.tools.javac.code.Symbol;
|
|||||||
import com.sun.tools.javac.code.Symbol.MethodSymbol;
|
import com.sun.tools.javac.code.Symbol.MethodSymbol;
|
||||||
import com.sun.tools.javac.code.Symbol.PackageSymbol;
|
import com.sun.tools.javac.code.Symbol.PackageSymbol;
|
||||||
import com.sun.tools.javac.code.Symbol.TypeSymbol;
|
import com.sun.tools.javac.code.Symbol.TypeSymbol;
|
||||||
|
import com.sun.tools.javac.code.Symbol.VarSymbol;
|
||||||
import com.sun.tools.javac.tree.JCTree;
|
import com.sun.tools.javac.tree.JCTree;
|
||||||
import com.sun.tools.javac.tree.JCTree.JCClassDecl;
|
import com.sun.tools.javac.tree.JCTree.JCClassDecl;
|
||||||
import com.sun.tools.javac.tree.JCTree.JCExpression;
|
import com.sun.tools.javac.tree.JCTree.JCExpression;
|
||||||
import com.sun.tools.javac.tree.JCTree.JCFieldAccess;
|
import com.sun.tools.javac.tree.JCTree.JCFieldAccess;
|
||||||
import com.sun.tools.javac.tree.JCTree.JCIdent;
|
import com.sun.tools.javac.tree.JCTree.JCIdent;
|
||||||
import com.sun.tools.javac.tree.JCTree.JCImport;
|
import com.sun.tools.javac.tree.JCTree.JCImport;
|
||||||
|
import com.sun.tools.javac.tree.JCTree.JCMethodDecl;
|
||||||
import com.sun.tools.javac.tree.JCTree.JCMethodInvocation;
|
import com.sun.tools.javac.tree.JCTree.JCMethodInvocation;
|
||||||
import com.sun.tools.javac.tree.JCTree.JCNewClass;
|
import com.sun.tools.javac.tree.JCTree.JCNewClass;
|
||||||
import com.sun.tools.javac.tree.JCTree.JCTypeApply;
|
import com.sun.tools.javac.tree.JCTree.JCTypeApply;
|
||||||
@ -389,6 +391,11 @@ public class Java2TypeScriptAdapter extends AbstractPrinterAdapter {
|
|||||||
getPrinter().print(JSweetConfig.GLOBALS_PACKAGE_NAME).print(".");
|
getPrinter().print(JSweetConfig.GLOBALS_PACKAGE_NAME).print(".");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Map<String, VarSymbol> vars = new HashMap<>();
|
||||||
|
Util.fillAllVariablesInScope(vars, getPrinter().getStack(), invocation, getPrinter().getParent(JCMethodDecl.class));
|
||||||
|
if(vars.containsKey(targetMethodName)) {
|
||||||
|
report(invocation, JSweetProblem.HIDDEN_INVOCATION, targetMethodName);
|
||||||
|
}
|
||||||
getPrinter().printIdentifier(targetMethodName).print("(").printArgList(invocation.args).print(")");
|
getPrinter().printIdentifier(targetMethodName).print("(").printArgList(invocation.args).print(")");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -69,7 +69,7 @@ public class StructuralTests extends AbstractTest {
|
|||||||
@Test
|
@Test
|
||||||
public void testVariableMethodNameClashes() {
|
public void testVariableMethodNameClashes() {
|
||||||
transpile(logHandler -> {
|
transpile(logHandler -> {
|
||||||
logHandler.assertReportedProblems(JSweetProblem.HIDDEN_INVOCATION, JSweetProblem.HIDDEN_INVOCATION);
|
logHandler.assertReportedProblems(JSweetProblem.HIDDEN_INVOCATION, JSweetProblem.HIDDEN_INVOCATION, JSweetProblem.HIDDEN_INVOCATION);
|
||||||
} , getSourceFile(NameClashesWithMethodInvocations.class));
|
} , getSourceFile(NameClashesWithMethodInvocations.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -30,12 +30,19 @@ public class NameClashesWithMethodInvocations {
|
|||||||
String alert = "test";
|
String alert = "test";
|
||||||
alert(alert);
|
alert(alert);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void m3() {
|
public void m3() {
|
||||||
// name clash between local variable and method call
|
// not a name clash
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
String m2 = "test";
|
String m2 = "test";
|
||||||
m2();
|
m2();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void m4(boolean alert) {
|
||||||
|
// name clash between local variable and qualified method call
|
||||||
|
//String alert = "test";
|
||||||
|
jsweet.dom.Globals.alert(alert);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user