JS backend: inline ClassDeclarationTranslator

This commit is contained in:
Erokhin Stanislav
2013-10-23 15:01:11 +04:00
parent 961c5fc0df
commit 1a1c2902f0
4 changed files with 4 additions and 66 deletions
@@ -30,7 +30,6 @@ import org.jetbrains.k2js.config.EcmaVersion;
import org.jetbrains.k2js.config.LibrarySourcesConfig;
import org.jetbrains.k2js.translate.context.generator.Generator;
import org.jetbrains.k2js.translate.context.generator.Rule;
import org.jetbrains.k2js.translate.declaration.ClassDeclarationTranslator;
import org.jetbrains.k2js.translate.expression.LiteralFunctionTranslator;
import org.jetbrains.k2js.translate.intrinsic.Intrinsics;
import org.jetbrains.k2js.translate.utils.AnnotationsUtils;
@@ -93,8 +92,6 @@ public final class StaticContext {
@NotNull
private LiteralFunctionTranslator literalFunctionTranslator;
@NotNull
private ClassDeclarationTranslator classDeclarationTranslator;
//TODO: too many parameters in constructor
private StaticContext(@NotNull JsProgram program, @NotNull BindingContext bindingContext,
@@ -111,7 +108,6 @@ public final class StaticContext {
public void initTranslators(TranslationContext programContext) {
literalFunctionTranslator = new LiteralFunctionTranslator(programContext);
classDeclarationTranslator = new ClassDeclarationTranslator(programContext);
}
@NotNull
@@ -119,11 +115,6 @@ public final class StaticContext {
return literalFunctionTranslator;
}
@NotNull
public ClassDeclarationTranslator getClassDeclarationTranslator() {
return classDeclarationTranslator;
}
public boolean isEcma5() {
return ecmaVersion == EcmaVersion.v5;
}
@@ -24,7 +24,6 @@ import org.jetbrains.jet.lang.descriptors.CallableDescriptor;
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
import org.jetbrains.jet.lang.psi.JetExpression;
import org.jetbrains.jet.lang.resolve.BindingContext;
import org.jetbrains.k2js.translate.declaration.ClassDeclarationTranslator;
import org.jetbrains.k2js.translate.expression.LiteralFunctionTranslator;
import org.jetbrains.k2js.translate.intrinsic.Intrinsics;
@@ -242,11 +241,6 @@ public class TranslationContext {
return staticContext.getLiteralFunctionTranslator();
}
@NotNull
public ClassDeclarationTranslator classDeclarationTranslator() {
return staticContext.getClassDeclarationTranslator();
}
@NotNull
public JsFunction getFunctionObject(@NotNull CallableDescriptor descriptor) {
return staticContext.getFunctionWithScope(descriptor);
@@ -1,46 +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.JsExpression;
import com.google.dart.compiler.backend.js.ast.JsPropertyInitializer;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.lang.descriptors.ClassDescriptor;
import org.jetbrains.jet.lang.psi.JetClassOrObject;
import org.jetbrains.k2js.translate.context.TranslationContext;
import org.jetbrains.k2js.translate.general.AbstractTranslator;
import static org.jetbrains.k2js.translate.utils.BindingUtils.getClassDescriptor;
/**
* Generates a big block where are all the classes(objects representing them) are created.
*/
public final class ClassDeclarationTranslator extends AbstractTranslator {
public ClassDeclarationTranslator(@NotNull TranslationContext context) {
super(context);
}
@Nullable
public JsPropertyInitializer translate(@NotNull JetClassOrObject declaration, TranslationContext context) {
ClassDescriptor descriptor = getClassDescriptor(context().bindingContext(), declaration);
JsExpression value = new ClassTranslator(declaration, context).translate();
return new JsPropertyInitializer(context.getNameForDescriptor(descriptor).makeRef(), value);
}
}
@@ -48,11 +48,10 @@ class FileDeclarationVisitor(val context: TranslationContext) : DeclarationBodyV
}
public override fun visitClass(expression: JetClass, context: TranslationContext?): Void? {
val entry = context!!.classDeclarationTranslator().translate(expression, context)
if (entry != null) {
result.add(entry)
}
val classDescriptor = getClassDescriptor(context!!.bindingContext(), expression)
val value = ClassTranslator(expression, context).translate()
val entry = JsPropertyInitializer(context.getNameForDescriptor(classDescriptor).makeRef()!!, value)
result.add(entry)
return null
}