force import of interface when using a static field (even when through an implementing class)

This commit is contained in:
Renaud Pawlak 2020-02-12 07:32:50 +01:00
parent d9d136d1aa
commit 8248832d59
5 changed files with 45 additions and 4 deletions

View File

@ -4095,6 +4095,17 @@ public class Java2TypeScriptTranslator extends AbstractTreePrinter {
} else {
if (!varSym.owner.getSimpleName().toString().equals(GLOBALS_PACKAGE_NAME)) {
print(varSym.owner.getSimpleName().toString());
if(context.useModules) {
if (varSym.owner instanceof TypeElement) {
ModuleImportDescriptor moduleImport = getAdapter().getModuleImportDescriptor(
new CompilationUnitElementSupport(compilationUnit),
varSym.owner.getSimpleName().toString(), (TypeElement) varSym.owner);
if (moduleImport != null) {
useModule(moduleImport);
}
}
}
if (lazyInitializedStatic && varSym.owner.isEnum()) {
print(ENUM_WRAPPER_CLASS_SUFFIX);
}

View File

@ -16,18 +16,20 @@
*/
package org.jsweet.test.transpiler;
import org.junit.Assert;
import org.junit.Ignore;
import org.junit.Test;
import source.statics.AnonymousClasses;
import source.statics.Classes;
import source.statics.DefaultValues;
import source.statics.InnerClasses;
import source.statics.StaticsInInterfaces;
import source.statics.StaticInitializer;
import source.statics.StaticInitializerWithNoFields;
import org.junit.Assert;
import org.junit.Ignore;
import source.statics.StaticsInInterfaces;
import source.statics.interface_import.definitions.AClass;
import source.statics.interface_import.definitions.AnInterface;
import source.statics.interface_import.uses.Using;
public class StaticsTests extends AbstractTest {
@ -88,4 +90,10 @@ public class StaticsTests extends AbstractTest {
}, getSourceFile(DefaultValues.class));
}
@Test
public void testImportInterface() {
transpile(TestTranspilationHandler::assertNoProblems, getSourceFile(AClass.class),
getSourceFile(AnInterface.class), getSourceFile(Using.class));
}
}

View File

@ -0,0 +1,5 @@
package source.statics.interface_import.definitions;
public class AClass implements AnInterface {
}

View File

@ -0,0 +1,7 @@
package source.statics.interface_import.definitions;
public interface AnInterface {
public final static int I = 1;
}

View File

@ -0,0 +1,10 @@
package source.statics.interface_import.uses;
import source.statics.interface_import.definitions.AClass;
public class Using extends AClass {
public int m() {
return I;
}
}