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());
|
||||
}
|
||||
|
||||
if (descriptor.getContainingDeclaration() instanceof ModuleDescriptor) {
|
||||
return "";
|
||||
}
|
||||
|
||||
if (descriptor instanceof ModuleDescriptor) {
|
||||
throw new IllegalStateException("missed something");
|
||||
}
|
||||
|
||||
DeclarationDescriptor container = descriptor.getContainingDeclaration();
|
||||
String name = descriptor.getName();
|
||||
if(JetPsiUtil.NO_NAME_PROVIDED.equals(name)) {
|
||||
@@ -271,12 +279,6 @@ public class JetTypeMapper {
|
||||
if(name.contains("/"))
|
||||
return name;
|
||||
if (container != null) {
|
||||
if (container.getContainingDeclaration() instanceof ModuleDescriptor) {
|
||||
return name;
|
||||
}
|
||||
if (container instanceof ModuleDescriptor) {
|
||||
throw new IllegalStateException("missed something");
|
||||
}
|
||||
String baseName = getFQName(container);
|
||||
if (!baseName.isEmpty()) {
|
||||
return baseName + (container instanceof NamespaceDescriptor ? "/" : "$") + name;
|
||||
|
||||
+5
-1
@@ -29,7 +29,11 @@ import java.util.List;
|
||||
public abstract class AbstractNamespaceDescriptorImpl extends DeclarationDescriptorImpl implements NamespaceDescriptor {
|
||||
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);
|
||||
|
||||
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) {
|
||||
super(annotations);
|
||||
|
||||
if (name.length() == 0) {
|
||||
throw new IllegalArgumentException("descriptor name cannot be empty string");
|
||||
}
|
||||
|
||||
this.name = name;
|
||||
this.containingDeclaration = containingDeclaration;
|
||||
}
|
||||
|
||||
@@ -72,9 +72,14 @@ public class JetNamespaceHeader extends JetReferenceExpression {
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public String getName() {
|
||||
PsiElement nameIdentifier = getNameIdentifier();
|
||||
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.jet.lang.ModuleConfiguration;
|
||||
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.NamespaceDescriptorParent;
|
||||
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
|
||||
@@ -85,12 +86,20 @@ public class NamespaceFactoryImpl implements NamespaceFactory {
|
||||
currentOwner = namespaceDescriptor;
|
||||
}
|
||||
|
||||
String name = JetPsiUtil.safeName(namespaceHeader.getName());
|
||||
NamespaceDescriptorImpl namespaceDescriptor = createNamespaceDescriptorIfNeeded(file, currentOwner, name, false,
|
||||
namespaceHeader.getLastPartExpression());
|
||||
NamespaceDescriptorImpl namespaceDescriptor;
|
||||
String name;
|
||||
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(RESOLUTION_SCOPE, namespaceHeader, outerScope);
|
||||
trace.record(BindingContext.NAMESPACE_IS_SRC, namespaceDescriptor, true);
|
||||
trace.record(RESOLUTION_SCOPE, namespaceHeader, outerScope);
|
||||
}
|
||||
|
||||
return namespaceDescriptor;
|
||||
}
|
||||
|
||||
@@ -8,11 +8,11 @@ var v6 : Int.(String, Int) -> Unit
|
||||
var v7 : ExtensionFunction1<Int, String, Boolean>
|
||||
|
||||
|
||||
//internal final var v1 : () -> Unit 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 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 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 v7 : jet.Int.(jet.String) -> jet.Boolean 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 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, jet.String)) -> Unit) -> jet.String 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 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 v10 : Tuple3<Int, Int, Int>?
|
||||
|
||||
//internal final var v1 : 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 v4 : 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 v7 : #(jet.Int)? 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 v10 : #(jet.Int, jet.Int, jet.Int)? 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 v3 : 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 v6 : #(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 v9 : #(jet.Int, jet.String) 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
|
||||
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