mirror of
https://github.com/cincheo/jsweet.git
synced 2025-12-15 15:29:22 +00:00
force import of interface when using a static field (even when through an implementing class)
This commit is contained in:
parent
d9d136d1aa
commit
8248832d59
@ -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);
|
||||
}
|
||||
|
||||
@ -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));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -0,0 +1,5 @@
|
||||
package source.statics.interface_import.definitions;
|
||||
|
||||
public class AClass implements AnInterface {
|
||||
|
||||
}
|
||||
@ -0,0 +1,7 @@
|
||||
package source.statics.interface_import.definitions;
|
||||
|
||||
public interface AnInterface {
|
||||
|
||||
public final static int I = 1;
|
||||
|
||||
}
|
||||
@ -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;
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user