descriptor name cannot be empty string
* add assertion * fix tests * #KT-1748 Fixed
This commit is contained in:
@@ -263,6 +263,14 @@ public class JetTypeMapper {
|
|||||||
return getFQName(descriptor.getContainingDeclaration());
|
return getFQName(descriptor.getContainingDeclaration());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (descriptor.getContainingDeclaration() instanceof ModuleDescriptor) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (descriptor instanceof ModuleDescriptor) {
|
||||||
|
throw new IllegalStateException("missed something");
|
||||||
|
}
|
||||||
|
|
||||||
DeclarationDescriptor container = descriptor.getContainingDeclaration();
|
DeclarationDescriptor container = descriptor.getContainingDeclaration();
|
||||||
String name = descriptor.getName();
|
String name = descriptor.getName();
|
||||||
if(JetPsiUtil.NO_NAME_PROVIDED.equals(name)) {
|
if(JetPsiUtil.NO_NAME_PROVIDED.equals(name)) {
|
||||||
@@ -271,12 +279,6 @@ public class JetTypeMapper {
|
|||||||
if(name.contains("/"))
|
if(name.contains("/"))
|
||||||
return name;
|
return name;
|
||||||
if (container != null) {
|
if (container != null) {
|
||||||
if (container.getContainingDeclaration() instanceof ModuleDescriptor) {
|
|
||||||
return name;
|
|
||||||
}
|
|
||||||
if (container instanceof ModuleDescriptor) {
|
|
||||||
throw new IllegalStateException("missed something");
|
|
||||||
}
|
|
||||||
String baseName = getFQName(container);
|
String baseName = getFQName(container);
|
||||||
if (!baseName.isEmpty()) {
|
if (!baseName.isEmpty()) {
|
||||||
return baseName + (container instanceof NamespaceDescriptor ? "/" : "$") + name;
|
return baseName + (container instanceof NamespaceDescriptor ? "/" : "$") + name;
|
||||||
|
|||||||
+5
-1
@@ -29,7 +29,11 @@ import java.util.List;
|
|||||||
public abstract class AbstractNamespaceDescriptorImpl extends DeclarationDescriptorImpl implements NamespaceDescriptor {
|
public abstract class AbstractNamespaceDescriptorImpl extends DeclarationDescriptorImpl implements NamespaceDescriptor {
|
||||||
private NamespaceType namespaceType;
|
private NamespaceType namespaceType;
|
||||||
|
|
||||||
public AbstractNamespaceDescriptorImpl(@NotNull NamespaceDescriptorParent containingDeclaration, List<AnnotationDescriptor> annotations, String name) {
|
public AbstractNamespaceDescriptorImpl(
|
||||||
|
@NotNull NamespaceDescriptorParent containingDeclaration,
|
||||||
|
List<AnnotationDescriptor> annotations,
|
||||||
|
@NotNull String name) {
|
||||||
|
|
||||||
super(containingDeclaration, annotations, name);
|
super(containingDeclaration, annotations, name);
|
||||||
|
|
||||||
boolean rootAccordingToContainer = containingDeclaration instanceof ModuleDescriptor;
|
boolean rootAccordingToContainer = containingDeclaration instanceof ModuleDescriptor;
|
||||||
|
|||||||
+5
@@ -34,6 +34,11 @@ public abstract class DeclarationDescriptorImpl extends AnnotatedImpl implements
|
|||||||
|
|
||||||
public DeclarationDescriptorImpl(@Nullable DeclarationDescriptor containingDeclaration, @NotNull List<AnnotationDescriptor> annotations, @NotNull String name) {
|
public DeclarationDescriptorImpl(@Nullable DeclarationDescriptor containingDeclaration, @NotNull List<AnnotationDescriptor> annotations, @NotNull String name) {
|
||||||
super(annotations);
|
super(annotations);
|
||||||
|
|
||||||
|
if (name.length() == 0) {
|
||||||
|
throw new IllegalArgumentException("descriptor name cannot be empty string");
|
||||||
|
}
|
||||||
|
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.containingDeclaration = containingDeclaration;
|
this.containingDeclaration = containingDeclaration;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -72,9 +72,14 @@ public class JetNamespaceHeader extends JetReferenceExpression {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@NotNull
|
||||||
public String getName() {
|
public String getName() {
|
||||||
PsiElement nameIdentifier = getNameIdentifier();
|
PsiElement nameIdentifier = getNameIdentifier();
|
||||||
return nameIdentifier == null ? "" : nameIdentifier.getText();
|
return nameIdentifier == null ? "" : nameIdentifier.getText();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isRoot() {
|
||||||
|
return getName().length() == 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ import org.jetbrains.annotations.NotNull;
|
|||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.jetbrains.jet.lang.ModuleConfiguration;
|
import org.jetbrains.jet.lang.ModuleConfiguration;
|
||||||
import org.jetbrains.jet.lang.descriptors.ModuleDescriptor;
|
import org.jetbrains.jet.lang.descriptors.ModuleDescriptor;
|
||||||
|
import org.jetbrains.jet.lang.descriptors.NamespaceDescriptor;
|
||||||
import org.jetbrains.jet.lang.descriptors.NamespaceDescriptorImpl;
|
import org.jetbrains.jet.lang.descriptors.NamespaceDescriptorImpl;
|
||||||
import org.jetbrains.jet.lang.descriptors.NamespaceDescriptorParent;
|
import org.jetbrains.jet.lang.descriptors.NamespaceDescriptorParent;
|
||||||
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
|
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
|
||||||
@@ -85,12 +86,20 @@ public class NamespaceFactoryImpl implements NamespaceFactory {
|
|||||||
currentOwner = namespaceDescriptor;
|
currentOwner = namespaceDescriptor;
|
||||||
}
|
}
|
||||||
|
|
||||||
String name = JetPsiUtil.safeName(namespaceHeader.getName());
|
NamespaceDescriptorImpl namespaceDescriptor;
|
||||||
NamespaceDescriptorImpl namespaceDescriptor = createNamespaceDescriptorIfNeeded(file, currentOwner, name, false,
|
String name;
|
||||||
namespaceHeader.getLastPartExpression());
|
if (namespaceHeader.isRoot()) {
|
||||||
|
// again to register file in trace
|
||||||
|
namespaceDescriptor = createNamespaceDescriptorIfNeeded(file, moduleDescriptor, "<root>", true, null);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
name = namespaceHeader.getName();
|
||||||
|
namespaceDescriptor = createNamespaceDescriptorIfNeeded(file, currentOwner, name, namespaceHeader.isRoot(),
|
||||||
|
namespaceHeader.getLastPartExpression());
|
||||||
|
|
||||||
trace.record(BindingContext.NAMESPACE_IS_SRC, namespaceDescriptor, true);
|
trace.record(BindingContext.NAMESPACE_IS_SRC, namespaceDescriptor, true);
|
||||||
trace.record(RESOLUTION_SCOPE, namespaceHeader, outerScope);
|
trace.record(RESOLUTION_SCOPE, namespaceHeader, outerScope);
|
||||||
|
}
|
||||||
|
|
||||||
return namespaceDescriptor;
|
return namespaceDescriptor;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,11 +8,11 @@ var v6 : Int.(String, Int) -> Unit
|
|||||||
var v7 : ExtensionFunction1<Int, String, Boolean>
|
var v7 : ExtensionFunction1<Int, String, Boolean>
|
||||||
|
|
||||||
|
|
||||||
//internal final var v1 : () -> Unit defined in <module>.<root>.
|
//internal final var v1 : () -> Unit defined in <module>.<root>
|
||||||
//internal final var v2 : (jet.Int) -> jet.Int defined in <module>.<root>.
|
//internal final var v2 : (jet.Int) -> jet.Int defined in <module>.<root>
|
||||||
//internal final var v3 : (jet.Int, #(jet.String, jet.String)) -> jet.String defined in <module>.<root>.
|
//internal final var v3 : (jet.Int, #(jet.String, jet.String)) -> jet.String defined in <module>.<root>
|
||||||
//internal final var v4 : (jet.Int) -> jet.String defined in <module>.<root>.
|
//internal final var v4 : (jet.Int) -> jet.String defined in <module>.<root>
|
||||||
//internal final var v4 : (() -> jet.Int, (#(jet.String, jet.String)) -> Unit) -> jet.String defined in <module>.<root>.
|
//internal final var v4 : (() -> jet.Int, (#(jet.String, jet.String)) -> Unit) -> jet.String defined in <module>.<root>
|
||||||
//internal final var v5 : jet.Int.() -> jet.Int defined in <module>.<root>.
|
//internal final var v5 : jet.Int.() -> jet.Int defined in <module>.<root>
|
||||||
//internal final var v6 : jet.Int.(jet.String, jet.Int) -> Unit defined in <module>.<root>.
|
//internal final var v6 : jet.Int.(jet.String, jet.Int) -> Unit defined in <module>.<root>
|
||||||
//internal final var v7 : jet.Int.(jet.String) -> jet.Boolean defined in <module>.<root>.
|
//internal final var v7 : jet.Int.(jet.String) -> jet.Boolean defined in <module>.<root>
|
||||||
|
|||||||
@@ -9,13 +9,13 @@ var v8 : #(Int, String, String)
|
|||||||
var v9 : Tuple2<Int, String>
|
var v9 : Tuple2<Int, String>
|
||||||
var v10 : Tuple3<Int, Int, Int>?
|
var v10 : Tuple3<Int, Int, Int>?
|
||||||
|
|
||||||
//internal final var v1 : Unit defined in <module>.<root>.
|
//internal final var v1 : Unit defined in <module>.<root>
|
||||||
//internal final var v2 : Unit? defined in <module>.<root>.
|
//internal final var v2 : Unit? defined in <module>.<root>
|
||||||
//internal final var v3 : Unit defined in <module>.<root>.
|
//internal final var v3 : Unit defined in <module>.<root>
|
||||||
//internal final var v4 : Unit? defined in <module>.<root>.
|
//internal final var v4 : Unit? defined in <module>.<root>
|
||||||
//internal final var v5 : Unit defined in <module>.<root>.
|
//internal final var v5 : Unit defined in <module>.<root>
|
||||||
//internal final var v6 : #(jet.Int) defined in <module>.<root>.
|
//internal final var v6 : #(jet.Int) defined in <module>.<root>
|
||||||
//internal final var v7 : #(jet.Int)? defined in <module>.<root>.
|
//internal final var v7 : #(jet.Int)? defined in <module>.<root>
|
||||||
//internal final var v8 : #(jet.Int, jet.String, jet.String) defined in <module>.<root>.
|
//internal final var v8 : #(jet.Int, jet.String, jet.String) defined in <module>.<root>
|
||||||
//internal final var v9 : #(jet.Int, jet.String) defined in <module>.<root>.
|
//internal final var v9 : #(jet.Int, jet.String) defined in <module>.<root>
|
||||||
//internal final var v10 : #(jet.Int, jet.Int, jet.Int)? defined in <module>.<root>.
|
//internal final var v10 : #(jet.Int, jet.Int, jet.Int)? defined in <module>.<root>
|
||||||
|
|||||||
+3
-3
@@ -95,7 +95,7 @@ public final class NamespaceDeclarationTranslator extends AbstractTranslator {
|
|||||||
@NotNull
|
@NotNull
|
||||||
private List<NamespaceTranslator> getTranslatorsForNonEmptyNamespaces() {
|
private List<NamespaceTranslator> getTranslatorsForNonEmptyNamespaces() {
|
||||||
List<NamespaceTranslator> namespaceTranslators = Lists.newArrayList();
|
List<NamespaceTranslator> namespaceTranslators = Lists.newArrayList();
|
||||||
for (NamespaceDescriptor descriptor : filterNonEmptyNamespaces(filterTopLevelNamespaces(namespaceDescriptors))) {
|
for (NamespaceDescriptor descriptor : filterNonEmptyNamespaces(filterTopLevelAndRootNamespaces(namespaceDescriptors))) {
|
||||||
namespaceTranslators.add(new NamespaceTranslator(descriptor, classDeclarationTranslator, context()));
|
namespaceTranslators.add(new NamespaceTranslator(descriptor, classDeclarationTranslator, context()));
|
||||||
}
|
}
|
||||||
return namespaceTranslators;
|
return namespaceTranslators;
|
||||||
@@ -123,10 +123,10 @@ public final class NamespaceDeclarationTranslator extends AbstractTranslator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
private static List<NamespaceDescriptor> filterTopLevelNamespaces(@NotNull List<NamespaceDescriptor> namespaceDescriptors) {
|
private static List<NamespaceDescriptor> filterTopLevelAndRootNamespaces(@NotNull List<NamespaceDescriptor> namespaceDescriptors) {
|
||||||
List<NamespaceDescriptor> result = Lists.newArrayList();
|
List<NamespaceDescriptor> result = Lists.newArrayList();
|
||||||
for (NamespaceDescriptor descriptor : namespaceDescriptors) {
|
for (NamespaceDescriptor descriptor : namespaceDescriptors) {
|
||||||
if (JsDescriptorUtils.isTopLevelNamespace(descriptor)) {
|
if (JsDescriptorUtils.isTopLevelNamespace(descriptor) || JsDescriptorUtils.isRootNamespace(descriptor)) {
|
||||||
result.add(descriptor);
|
result.add(descriptor);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ import com.google.dart.compiler.backend.js.ast.*;
|
|||||||
import com.google.dart.compiler.util.AstUtil;
|
import com.google.dart.compiler.util.AstUtil;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.jet.lang.descriptors.NamespaceDescriptor;
|
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.context.TranslationContext;
|
||||||
import org.jetbrains.k2js.translate.general.AbstractTranslator;
|
import org.jetbrains.k2js.translate.general.AbstractTranslator;
|
||||||
import org.jetbrains.k2js.translate.general.Translation;
|
import org.jetbrains.k2js.translate.general.Translation;
|
||||||
@@ -96,6 +97,9 @@ public final class NamespaceTranslator extends AbstractTranslator {
|
|||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
private List<JsPropertyInitializer> getNestedNamespaceDeclarations() {
|
private List<JsPropertyInitializer> getNestedNamespaceDeclarations() {
|
||||||
|
if (JsDescriptorUtils.isRootNamespace(descriptor)) {
|
||||||
|
return Lists.newArrayList();
|
||||||
|
}
|
||||||
List<JsPropertyInitializer> result = Lists.newArrayList();
|
List<JsPropertyInitializer> result = Lists.newArrayList();
|
||||||
List<NamespaceDescriptor> nestedNamespaces = JsDescriptorUtils.getNestedNamespaces(descriptor);
|
List<NamespaceDescriptor> nestedNamespaces = JsDescriptorUtils.getNestedNamespaces(descriptor);
|
||||||
for (NamespaceDescriptor nestedNamespace : nestedNamespaces) {
|
for (NamespaceDescriptor nestedNamespace : nestedNamespaces) {
|
||||||
|
|||||||
@@ -152,10 +152,7 @@ public final class JsDescriptorUtils {
|
|||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public static String getNameForNamespace(@NotNull NamespaceDescriptor descriptor) {
|
public static String getNameForNamespace(@NotNull NamespaceDescriptor descriptor) {
|
||||||
//if (descriptor.getContainingDeclaration() instanceof ModuleDescriptor) {
|
if (descriptor.getContainingDeclaration() instanceof ModuleDescriptor) {
|
||||||
// return Namer.getAnonymousNamespaceName();
|
|
||||||
//} else
|
|
||||||
if (descriptor.getName().isEmpty()) {
|
|
||||||
return Namer.getAnonymousNamespaceName();
|
return Namer.getAnonymousNamespaceName();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@@ -240,12 +237,12 @@ public final class JsDescriptorUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isTopLevelNamespace(@NotNull NamespaceDescriptor namespaceDescriptor) {
|
public static boolean isTopLevelNamespace(@NotNull NamespaceDescriptor namespaceDescriptor) {
|
||||||
NamespaceDescriptorParent containingDeclaration = namespaceDescriptor.getContainingDeclaration();
|
return namespaceDescriptor.getContainingDeclaration() instanceof NamespaceDescriptor
|
||||||
boolean containedInModule = !(containingDeclaration instanceof NamespaceDescriptor);
|
&& namespaceDescriptor.getContainingDeclaration().getContainingDeclaration() instanceof ModuleDescriptor;
|
||||||
if (containedInModule) {
|
}
|
||||||
return true;
|
|
||||||
}
|
public static boolean isRootNamespace(@NotNull NamespaceDescriptor namespaceDescriptor) {
|
||||||
return containingDeclaration.getContainingDeclaration() instanceof ModuleDescriptor;
|
return namespaceDescriptor.getContainingDeclaration() instanceof ModuleDescriptor;
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
|
|||||||
Reference in New Issue
Block a user