descriptor name cannot be empty string
* add assertion * fix tests * #KT-1748 Fixed
This commit is contained in:
+3
-3
@@ -95,7 +95,7 @@ public final class NamespaceDeclarationTranslator extends AbstractTranslator {
|
||||
@NotNull
|
||||
private List<NamespaceTranslator> getTranslatorsForNonEmptyNamespaces() {
|
||||
List<NamespaceTranslator> namespaceTranslators = Lists.newArrayList();
|
||||
for (NamespaceDescriptor descriptor : filterNonEmptyNamespaces(filterTopLevelNamespaces(namespaceDescriptors))) {
|
||||
for (NamespaceDescriptor descriptor : filterNonEmptyNamespaces(filterTopLevelAndRootNamespaces(namespaceDescriptors))) {
|
||||
namespaceTranslators.add(new NamespaceTranslator(descriptor, classDeclarationTranslator, context()));
|
||||
}
|
||||
return namespaceTranslators;
|
||||
@@ -123,10 +123,10 @@ public final class NamespaceDeclarationTranslator extends AbstractTranslator {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static List<NamespaceDescriptor> filterTopLevelNamespaces(@NotNull List<NamespaceDescriptor> namespaceDescriptors) {
|
||||
private static List<NamespaceDescriptor> filterTopLevelAndRootNamespaces(@NotNull List<NamespaceDescriptor> namespaceDescriptors) {
|
||||
List<NamespaceDescriptor> result = Lists.newArrayList();
|
||||
for (NamespaceDescriptor descriptor : namespaceDescriptors) {
|
||||
if (JsDescriptorUtils.isTopLevelNamespace(descriptor)) {
|
||||
if (JsDescriptorUtils.isTopLevelNamespace(descriptor) || JsDescriptorUtils.isRootNamespace(descriptor)) {
|
||||
result.add(descriptor);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,6 +21,7 @@ import com.google.dart.compiler.backend.js.ast.*;
|
||||
import com.google.dart.compiler.util.AstUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lang.descriptors.NamespaceDescriptor;
|
||||
import org.jetbrains.jet.lang.resolve.DescriptorUtils;
|
||||
import org.jetbrains.k2js.translate.context.TranslationContext;
|
||||
import org.jetbrains.k2js.translate.general.AbstractTranslator;
|
||||
import org.jetbrains.k2js.translate.general.Translation;
|
||||
@@ -96,6 +97,9 @@ public final class NamespaceTranslator extends AbstractTranslator {
|
||||
|
||||
@NotNull
|
||||
private List<JsPropertyInitializer> getNestedNamespaceDeclarations() {
|
||||
if (JsDescriptorUtils.isRootNamespace(descriptor)) {
|
||||
return Lists.newArrayList();
|
||||
}
|
||||
List<JsPropertyInitializer> result = Lists.newArrayList();
|
||||
List<NamespaceDescriptor> nestedNamespaces = JsDescriptorUtils.getNestedNamespaces(descriptor);
|
||||
for (NamespaceDescriptor nestedNamespace : nestedNamespaces) {
|
||||
|
||||
@@ -152,10 +152,7 @@ public final class JsDescriptorUtils {
|
||||
|
||||
@NotNull
|
||||
public static String getNameForNamespace(@NotNull NamespaceDescriptor descriptor) {
|
||||
//if (descriptor.getContainingDeclaration() instanceof ModuleDescriptor) {
|
||||
// return Namer.getAnonymousNamespaceName();
|
||||
//} else
|
||||
if (descriptor.getName().isEmpty()) {
|
||||
if (descriptor.getContainingDeclaration() instanceof ModuleDescriptor) {
|
||||
return Namer.getAnonymousNamespaceName();
|
||||
}
|
||||
else {
|
||||
@@ -240,12 +237,12 @@ public final class JsDescriptorUtils {
|
||||
}
|
||||
|
||||
public static boolean isTopLevelNamespace(@NotNull NamespaceDescriptor namespaceDescriptor) {
|
||||
NamespaceDescriptorParent containingDeclaration = namespaceDescriptor.getContainingDeclaration();
|
||||
boolean containedInModule = !(containingDeclaration instanceof NamespaceDescriptor);
|
||||
if (containedInModule) {
|
||||
return true;
|
||||
}
|
||||
return containingDeclaration.getContainingDeclaration() instanceof ModuleDescriptor;
|
||||
return namespaceDescriptor.getContainingDeclaration() instanceof NamespaceDescriptor
|
||||
&& namespaceDescriptor.getContainingDeclaration().getContainingDeclaration() instanceof ModuleDescriptor;
|
||||
}
|
||||
|
||||
public static boolean isRootNamespace(@NotNull NamespaceDescriptor namespaceDescriptor) {
|
||||
return namespaceDescriptor.getContainingDeclaration() instanceof ModuleDescriptor;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
Reference in New Issue
Block a user