JS backend: drop ClassAliasingMap from ClassTranslator
This commit is contained in:
@@ -1,26 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2010-2013 JetBrains s.r.o.
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package org.jetbrains.k2js.translate.declaration;
|
|
||||||
|
|
||||||
import com.google.dart.compiler.backend.js.ast.JsNameRef;
|
|
||||||
import org.jetbrains.annotations.Nullable;
|
|
||||||
import org.jetbrains.jet.lang.descriptors.ClassDescriptor;
|
|
||||||
|
|
||||||
public interface ClassAliasingMap {
|
|
||||||
@Nullable
|
|
||||||
JsNameRef get(ClassDescriptor descriptor, ClassDescriptor referencedDescriptor);
|
|
||||||
}
|
|
||||||
+1
-36
@@ -17,10 +17,7 @@
|
|||||||
package org.jetbrains.k2js.translate.declaration;
|
package org.jetbrains.k2js.translate.declaration;
|
||||||
|
|
||||||
import com.google.dart.compiler.backend.js.ast.JsExpression;
|
import com.google.dart.compiler.backend.js.ast.JsExpression;
|
||||||
import com.google.dart.compiler.backend.js.ast.JsNameRef;
|
|
||||||
import com.google.dart.compiler.backend.js.ast.JsPropertyInitializer;
|
import com.google.dart.compiler.backend.js.ast.JsPropertyInitializer;
|
||||||
import gnu.trove.THashMap;
|
|
||||||
import gnu.trove.TObjectObjectProcedure;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.jetbrains.jet.lang.descriptors.ClassDescriptor;
|
import org.jetbrains.jet.lang.descriptors.ClassDescriptor;
|
||||||
@@ -35,46 +32,14 @@ import static org.jetbrains.k2js.translate.utils.BindingUtils.getClassDescriptor
|
|||||||
*/
|
*/
|
||||||
public final class ClassDeclarationTranslator extends AbstractTranslator {
|
public final class ClassDeclarationTranslator extends AbstractTranslator {
|
||||||
|
|
||||||
private final THashMap<ClassDescriptor, JsNameRef> openClassDescriptorToQualifiedLabel = new THashMap<ClassDescriptor, JsNameRef>();
|
|
||||||
|
|
||||||
private final ClassAliasingMap classDescriptorToQualifiedLabel = new ClassAliasingMap() {
|
|
||||||
@NotNull
|
|
||||||
@Override
|
|
||||||
public JsNameRef get(ClassDescriptor descriptor, ClassDescriptor referencedDescriptor) {
|
|
||||||
JsNameRef ref = openClassDescriptorToQualifiedLabel.get(descriptor);
|
|
||||||
if (ref != null) {
|
|
||||||
return ref;
|
|
||||||
}
|
|
||||||
|
|
||||||
// will be resolved later
|
|
||||||
ref = new JsNameRef("<unresolved class>");
|
|
||||||
openClassDescriptorToQualifiedLabel.put(descriptor, ref);
|
|
||||||
return ref;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
public ClassDeclarationTranslator(@NotNull TranslationContext context) {
|
public ClassDeclarationTranslator(@NotNull TranslationContext context) {
|
||||||
super(context);
|
super(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void fixUnresolvedClassReferences() {
|
|
||||||
openClassDescriptorToQualifiedLabel.forEachEntry(new TObjectObjectProcedure<ClassDescriptor, JsNameRef>() {
|
|
||||||
@Override
|
|
||||||
public boolean execute(ClassDescriptor descriptor, JsNameRef ref) {
|
|
||||||
if (ref.getName() == null) {
|
|
||||||
// from library
|
|
||||||
ref.resolve(context().getNameForDescriptor(descriptor));
|
|
||||||
ref.setQualifier(context().getQualifierForDescriptor(descriptor));
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
public JsPropertyInitializer translate(@NotNull JetClassOrObject declaration, TranslationContext context) {
|
public JsPropertyInitializer translate(@NotNull JetClassOrObject declaration, TranslationContext context) {
|
||||||
ClassDescriptor descriptor = getClassDescriptor(context().bindingContext(), declaration);
|
ClassDescriptor descriptor = getClassDescriptor(context().bindingContext(), declaration);
|
||||||
JsExpression value = new ClassTranslator(declaration, classDescriptorToQualifiedLabel, context).translate();
|
JsExpression value = new ClassTranslator(declaration, context).translate();
|
||||||
|
|
||||||
return new JsPropertyInitializer(context.getNameForDescriptor(descriptor).makeRef(), value);
|
return new JsPropertyInitializer(context.getNameForDescriptor(descriptor).makeRef(), value);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,7 +21,6 @@ import com.intellij.openapi.util.NotNullLazyValue;
|
|||||||
import com.intellij.openapi.util.Trinity;
|
import com.intellij.openapi.util.Trinity;
|
||||||
import com.intellij.util.SmartList;
|
import com.intellij.util.SmartList;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
|
||||||
import org.jetbrains.jet.lang.descriptors.ClassDescriptor;
|
import org.jetbrains.jet.lang.descriptors.ClassDescriptor;
|
||||||
import org.jetbrains.jet.lang.descriptors.ClassKind;
|
import org.jetbrains.jet.lang.descriptors.ClassKind;
|
||||||
import org.jetbrains.jet.lang.descriptors.PropertyDescriptor;
|
import org.jetbrains.jet.lang.descriptors.PropertyDescriptor;
|
||||||
@@ -58,19 +57,16 @@ public final class ClassTranslator extends AbstractTranslator {
|
|||||||
@NotNull
|
@NotNull
|
||||||
private final ClassDescriptor descriptor;
|
private final ClassDescriptor descriptor;
|
||||||
|
|
||||||
@Nullable
|
|
||||||
private final ClassAliasingMap aliasingMap;
|
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public static JsInvocation generateClassCreation(@NotNull JetClassOrObject classDeclaration, @NotNull TranslationContext context) {
|
public static JsInvocation generateClassCreation(@NotNull JetClassOrObject classDeclaration, @NotNull TranslationContext context) {
|
||||||
return new ClassTranslator(classDeclaration, null, context).translate();
|
return new ClassTranslator(classDeclaration, context).translate();
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public static JsInvocation generateClassCreation(@NotNull JetClassOrObject classDeclaration,
|
public static JsInvocation generateClassCreation(@NotNull JetClassOrObject classDeclaration,
|
||||||
@NotNull ClassDescriptor descriptor,
|
@NotNull ClassDescriptor descriptor,
|
||||||
@NotNull TranslationContext context) {
|
@NotNull TranslationContext context) {
|
||||||
return new ClassTranslator(classDeclaration, descriptor, null, context).translate();
|
return new ClassTranslator(classDeclaration, descriptor, context).translate();
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@@ -78,7 +74,7 @@ public final class ClassTranslator extends AbstractTranslator {
|
|||||||
@NotNull JetObjectDeclaration objectDeclaration,
|
@NotNull JetObjectDeclaration objectDeclaration,
|
||||||
@NotNull TranslationContext context
|
@NotNull TranslationContext context
|
||||||
) {
|
) {
|
||||||
return new ClassTranslator(objectDeclaration, null, context).translateObjectLiteralExpression();
|
return new ClassTranslator(objectDeclaration, context).translateObjectLiteralExpression();
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@@ -87,23 +83,22 @@ public final class ClassTranslator extends AbstractTranslator {
|
|||||||
@NotNull ClassDescriptor descriptor,
|
@NotNull ClassDescriptor descriptor,
|
||||||
@NotNull TranslationContext context
|
@NotNull TranslationContext context
|
||||||
) {
|
) {
|
||||||
return new ClassTranslator(objectDeclaration, descriptor, null, context).translateObjectLiteralExpression();
|
return new ClassTranslator(objectDeclaration, descriptor, context).translateObjectLiteralExpression();
|
||||||
}
|
}
|
||||||
|
|
||||||
ClassTranslator(
|
ClassTranslator(
|
||||||
@NotNull JetClassOrObject classDeclaration,
|
@NotNull JetClassOrObject classDeclaration,
|
||||||
@Nullable ClassAliasingMap aliasingMap,
|
|
||||||
@NotNull TranslationContext context
|
@NotNull TranslationContext context
|
||||||
) {
|
) {
|
||||||
this(classDeclaration, getClassDescriptor(context.bindingContext(), classDeclaration), aliasingMap, context);
|
this(classDeclaration, getClassDescriptor(context.bindingContext(), classDeclaration), context);
|
||||||
}
|
}
|
||||||
|
|
||||||
ClassTranslator(@NotNull JetClassOrObject classDeclaration,
|
ClassTranslator(
|
||||||
|
@NotNull JetClassOrObject classDeclaration,
|
||||||
@NotNull ClassDescriptor descriptor,
|
@NotNull ClassDescriptor descriptor,
|
||||||
@Nullable ClassAliasingMap aliasingMap,
|
@NotNull TranslationContext context
|
||||||
@NotNull TranslationContext context) {
|
) {
|
||||||
super(context);
|
super(context);
|
||||||
this.aliasingMap = aliasingMap;
|
|
||||||
this.descriptor = descriptor;
|
this.descriptor = descriptor;
|
||||||
this.classDeclaration = classDeclaration;
|
this.classDeclaration = classDeclaration;
|
||||||
}
|
}
|
||||||
@@ -259,15 +254,6 @@ public final class ClassTranslator extends AbstractTranslator {
|
|||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
private JsNameRef getClassReference(@NotNull ClassDescriptor superClassDescriptor) {
|
private JsNameRef getClassReference(@NotNull ClassDescriptor superClassDescriptor) {
|
||||||
// aliasing here is needed for the declaration generation step
|
|
||||||
if (aliasingMap != null) {
|
|
||||||
JsNameRef name = aliasingMap.get(superClassDescriptor, descriptor);
|
|
||||||
if (name != null) {
|
|
||||||
return name;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// from library
|
|
||||||
return context().getQualifiedReference(superClassDescriptor);
|
return context().getQualifiedReference(superClassDescriptor);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
-1
@@ -72,7 +72,6 @@ public final class NamespaceDeclarationTranslator extends AbstractTranslator {
|
|||||||
return Collections.emptyList();
|
return Collections.emptyList();
|
||||||
}
|
}
|
||||||
|
|
||||||
context().classDeclarationTranslator().fixUnresolvedClassReferences();
|
|
||||||
for (NamespaceTranslator translator : descriptorToTranslator.values()) {
|
for (NamespaceTranslator translator : descriptorToTranslator.values()) {
|
||||||
translator.add(descriptorToDefineInvocation);
|
translator.add(descriptorToDefineInvocation);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user