mirror of
https://github.com/cincheo/jsweet.git
synced 2025-12-15 15:29:22 +00:00
support @Erased on package + fixed @Root package issues
This commit is contained in:
parent
45c532f0c5
commit
f02b7f7ee5
@ -34,7 +34,7 @@ import java.lang.annotation.Target;
|
|||||||
* @author Renaud Pawlak
|
* @author Renaud Pawlak
|
||||||
*/
|
*/
|
||||||
@Retention(RetentionPolicy.RUNTIME)
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
@Target({ ElementType.TYPE, ElementType.METHOD, ElementType.CONSTRUCTOR, ElementType.FIELD })
|
@Target({ ElementType.PACKAGE, ElementType.TYPE, ElementType.METHOD, ElementType.CONSTRUCTOR, ElementType.FIELD })
|
||||||
@Documented
|
@Documented
|
||||||
public @interface Erased {
|
public @interface Erased {
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1244,4 +1244,19 @@ public class JSweetContext extends Context {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns true if the given package is erased (it could be erased because a
|
||||||
|
* parent package is erased).
|
||||||
|
*/
|
||||||
|
public boolean isPackageErased(PackageSymbol pkg) {
|
||||||
|
if (pkg == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (hasAnnotationType(pkg, JSweetConfig.ANNOTATION_ERASED)) {
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
return isPackageErased((PackageSymbol) pkg.getEnclosingElement());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -195,6 +195,10 @@ public class Java2TypeScriptTranslator<C extends JSweetContext> extends Abstract
|
|||||||
|
|
||||||
private boolean isDefinitionScope = false;
|
private boolean isDefinitionScope = false;
|
||||||
|
|
||||||
|
private boolean isTopLevelScope() {
|
||||||
|
return getIndent() == 0;
|
||||||
|
}
|
||||||
|
|
||||||
private ClassScope getScope() {
|
private ClassScope getScope() {
|
||||||
return scope.peek();
|
return scope.peek();
|
||||||
}
|
}
|
||||||
@ -261,8 +265,6 @@ public class Java2TypeScriptTranslator<C extends JSweetContext> extends Abstract
|
|||||||
|
|
||||||
private JCMethodDecl mainMethod;
|
private JCMethodDecl mainMethod;
|
||||||
|
|
||||||
private boolean globalModule = false;
|
|
||||||
|
|
||||||
private PackageSymbol topLevelPackage;
|
private PackageSymbol topLevelPackage;
|
||||||
|
|
||||||
private void useModule(boolean require, PackageSymbol targetPackage, JCTree sourceTree, String targetName,
|
private void useModule(boolean require, PackageSymbol targetPackage, JCTree sourceTree, String targetName,
|
||||||
@ -318,6 +320,9 @@ public class Java2TypeScriptTranslator<C extends JSweetContext> extends Abstract
|
|||||||
@Override
|
@Override
|
||||||
public void visitTopLevel(JCCompilationUnit topLevel) {
|
public void visitTopLevel(JCCompilationUnit topLevel) {
|
||||||
|
|
||||||
|
if (context.isPackageErased(topLevel.packge)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
boolean noDefs = true;
|
boolean noDefs = true;
|
||||||
for (JCTree def : topLevel.defs) {
|
for (JCTree def : topLevel.defs) {
|
||||||
if (def instanceof JCClassDecl) {
|
if (def instanceof JCClassDecl) {
|
||||||
@ -369,7 +374,7 @@ public class Java2TypeScriptTranslator<C extends JSweetContext> extends Abstract
|
|||||||
|
|
||||||
String packge = topLevel.packge.toString();
|
String packge = topLevel.packge.toString();
|
||||||
|
|
||||||
globalModule = JSweetConfig.GLOBALS_PACKAGE_NAME.equals(packge)
|
boolean globalModule = JSweetConfig.GLOBALS_PACKAGE_NAME.equals(packge)
|
||||||
|| packge.endsWith("." + JSweetConfig.GLOBALS_PACKAGE_NAME);
|
|| packge.endsWith("." + JSweetConfig.GLOBALS_PACKAGE_NAME);
|
||||||
String rootRelativePackageName = "";
|
String rootRelativePackageName = "";
|
||||||
if (!globalModule) {
|
if (!globalModule) {
|
||||||
@ -760,7 +765,7 @@ public class Java2TypeScriptTranslator<C extends JSweetContext> extends Abstract
|
|||||||
}
|
}
|
||||||
printDocComment(classdecl, false);
|
printDocComment(classdecl, false);
|
||||||
print(classdecl.mods);
|
print(classdecl.mods);
|
||||||
if (!globalModule || context.useModules || isAnonymousClass() || isInnerClass() || isLocalClass()) {
|
if (!isTopLevelScope() || context.useModules || isAnonymousClass() || isInnerClass() || isLocalClass()) {
|
||||||
print("export ");
|
print("export ");
|
||||||
}
|
}
|
||||||
if (context.isInterface(classdecl.sym)) {
|
if (context.isInterface(classdecl.sym)) {
|
||||||
@ -1147,7 +1152,7 @@ public class Java2TypeScriptTranslator<C extends JSweetContext> extends Abstract
|
|||||||
if (!nameSpace) {
|
if (!nameSpace) {
|
||||||
nameSpace = true;
|
nameSpace = true;
|
||||||
println().println().printIndent();
|
println().println().printIndent();
|
||||||
if (!globalModule || context.useModules) {
|
if (!isTopLevelScope() || context.useModules) {
|
||||||
print("export ");
|
print("export ");
|
||||||
} else {
|
} else {
|
||||||
if (isDefinitionScope) {
|
if (isDefinitionScope) {
|
||||||
@ -1166,7 +1171,7 @@ public class Java2TypeScriptTranslator<C extends JSweetContext> extends Abstract
|
|||||||
if (!nameSpace) {
|
if (!nameSpace) {
|
||||||
nameSpace = true;
|
nameSpace = true;
|
||||||
println().println().printIndent();
|
println().println().printIndent();
|
||||||
if (!globalModule || context.useModules) {
|
if (!isTopLevelScope() || context.useModules) {
|
||||||
print("export ");
|
print("export ");
|
||||||
}
|
}
|
||||||
print("namespace ").print(name).print(" {").startIndent();
|
print("namespace ").print(name).print(" {").startIndent();
|
||||||
@ -1180,7 +1185,7 @@ public class Java2TypeScriptTranslator<C extends JSweetContext> extends Abstract
|
|||||||
if (!nameSpace) {
|
if (!nameSpace) {
|
||||||
nameSpace = true;
|
nameSpace = true;
|
||||||
println().println().printIndent();
|
println().println().printIndent();
|
||||||
if (!globalModule || context.useModules) {
|
if (!isTopLevelScope() || context.useModules) {
|
||||||
print("export ");
|
print("export ");
|
||||||
}
|
}
|
||||||
print("namespace ").print(name).print(" {").startIndent();
|
print("namespace ").print(name).print(" {").startIndent();
|
||||||
@ -1466,7 +1471,7 @@ public class Java2TypeScriptTranslator<C extends JSweetContext> extends Abstract
|
|||||||
print("export ");
|
print("export ");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (!globalModule) {
|
if (!isTopLevelScope()) {
|
||||||
print("export ");
|
print("export ");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1965,16 +1970,6 @@ public class Java2TypeScriptTranslator<C extends JSweetContext> extends Abstract
|
|||||||
JCNewClass newClass = (JCNewClass) varDecl.init;
|
JCNewClass newClass = (JCNewClass) varDecl.init;
|
||||||
if (newClass.def != null) {
|
if (newClass.def != null) {
|
||||||
initAnonymousClass(newClass);
|
initAnonymousClass(newClass);
|
||||||
// print("new ").print(getScope().name + "." +
|
|
||||||
// getScope().name + ANONYMOUS_PREFIX +
|
|
||||||
// anonymousClassIndex);
|
|
||||||
// if
|
|
||||||
// (newClass.def.getModifiers().getFlags().contains(Modifier.STATIC))
|
|
||||||
// {
|
|
||||||
// printAnonymousClassTypeArgs(newClass);
|
|
||||||
// }
|
|
||||||
// print("(").printConstructorArgList(newClass).print(")");
|
|
||||||
// return;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -2073,11 +2068,11 @@ public class Java2TypeScriptTranslator<C extends JSweetContext> extends Abstract
|
|||||||
print("export ");
|
print("export ");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (!globalModule) {
|
if (!isTopLevelScope()) {
|
||||||
print("export ");
|
print("export ");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (ambient || (getIndent() == 0 && isDefinitionScope)) {
|
if (ambient || (isTopLevelScope() && isDefinitionScope)) {
|
||||||
print("declare ");
|
print("declare ");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -2137,7 +2132,7 @@ public class Java2TypeScriptTranslator<C extends JSweetContext> extends Abstract
|
|||||||
}
|
}
|
||||||
print("; ");
|
print("; ");
|
||||||
if (globals) {
|
if (globals) {
|
||||||
if (!globalModule) {
|
if (!isTopLevelScope()) {
|
||||||
print("export ");
|
print("export ");
|
||||||
}
|
}
|
||||||
print("function ");
|
print("function ");
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user