Move EcmaVersion class to upper level

Extract EcmaVersion#fromString static method
This commit is contained in:
pTalanov
2012-05-15 18:32:53 +04:00
parent b9b9e46275
commit b75b60f710
4 changed files with 54 additions and 26 deletions
@@ -17,7 +17,6 @@
package org.jetbrains.k2js.config;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.text.StringUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.lang.psi.JetFile;
@@ -26,8 +25,6 @@ import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import static org.jetbrains.k2js.translate.general.Translation.EcmaVersion;
/**
* @author Pavel Talanov
* <p/>
@@ -48,20 +45,20 @@ public abstract class Config {
@NotNull
protected static final List<String> LIB_FILE_NAMES = Arrays.asList(
"/core/annotations.kt",
"/jquery/common.kt",
"/jquery/ui.kt",
"/core/javautil.kt",
"/core/javalang.kt",
"/core/date.kt",
"/core/core.kt",
"/core/math.kt",
"/core/json.kt",
"/raphael/raphael.kt",
"/html5/canvas.kt",
"/html5/files.kt",
"/html5/image.kt",
"/stdlib/JUMaps.kt"
"/core/annotations.kt",
"/jquery/common.kt",
"/jquery/ui.kt",
"/core/javautil.kt",
"/core/javalang.kt",
"/core/date.kt",
"/core/core.kt",
"/core/math.kt",
"/core/json.kt",
"/raphael/raphael.kt",
"/html5/canvas.kt",
"/html5/files.kt",
"/html5/image.kt",
"/stdlib/JUMaps.kt"
);
protected static final String LIBRARIES_LOCATION = "js/js.libraries/src";
@@ -75,7 +72,7 @@ public abstract class Config {
public Config(@NotNull Project project, @Nullable String target) {
this.project = project;
this.target = StringUtil.compareVersionNumbers(target, "5") >= 0 ? EcmaVersion.v5 : EcmaVersion.v3;
this.target = EcmaVersion.fromString(target);
}
@NotNull
@@ -0,0 +1,33 @@
/*
* Copyright 2010-2012 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.config;
import com.intellij.openapi.util.text.StringUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
/**
* @author Pavel Talanov
*/
public enum EcmaVersion {
v3, v5;
@NotNull
static EcmaVersion fromString(@Nullable String target) {
return StringUtil.compareVersionNumbers(target, "5") >= 0 ? v5 : v3;
}
}
@@ -24,9 +24,9 @@ import org.jetbrains.jet.lang.descriptors.*;
import org.jetbrains.jet.lang.resolve.BindingContext;
import org.jetbrains.jet.lang.resolve.DescriptorUtils;
import org.jetbrains.jet.lang.types.lang.JetStandardLibrary;
import org.jetbrains.k2js.config.EcmaVersion;
import org.jetbrains.k2js.translate.context.generator.Generator;
import org.jetbrains.k2js.translate.context.generator.Rule;
import org.jetbrains.k2js.translate.general.Translation;
import org.jetbrains.k2js.translate.intrinsic.Intrinsics;
import org.jetbrains.k2js.translate.utils.AnnotationsUtils;
import org.jetbrains.k2js.translate.utils.JsAstUtils;
@@ -46,7 +46,7 @@ public final class StaticContext {
public static StaticContext generateStaticContext(@NotNull JetStandardLibrary library,
@NotNull BindingContext bindingContext,
@NotNull Translation.EcmaVersion ecmaVersion) {
@NotNull EcmaVersion ecmaVersion) {
JsProgram program = new JsProgram("main");
JsRootScope jsRootScope = program.getRootScope();
Namer namer = Namer.newInstance(jsRootScope);
@@ -85,12 +85,12 @@ public final class StaticContext {
private final Map<NamingScope, JsFunction> scopeToFunction = Maps.newHashMap();
@NotNull
private final Translation.EcmaVersion ecmaVersion;
private final EcmaVersion ecmaVersion;
//TODO: too many parameters in constructor
private StaticContext(@NotNull JsProgram program, @NotNull BindingContext bindingContext,
@NotNull Namer namer, @NotNull Intrinsics intrinsics,
@NotNull StandardClasses standardClasses, @NotNull NamingScope rootScope, @NotNull Translation.EcmaVersion ecmaVersion) {
@NotNull StandardClasses standardClasses, @NotNull NamingScope rootScope, @NotNull EcmaVersion ecmaVersion) {
this.program = program;
this.bindingContext = bindingContext;
this.namer = namer;
@@ -101,7 +101,7 @@ public final class StaticContext {
}
public boolean isEcma5() {
return ecmaVersion == Translation.EcmaVersion.v5;
return ecmaVersion == EcmaVersion.v5;
}
@NotNull
@@ -25,6 +25,7 @@ import org.jetbrains.jet.lang.descriptors.NamespaceDescriptor;
import org.jetbrains.jet.lang.psi.*;
import org.jetbrains.jet.lang.resolve.BindingContext;
import org.jetbrains.jet.lang.types.lang.JetStandardLibrary;
import org.jetbrains.k2js.config.EcmaVersion;
import org.jetbrains.k2js.facade.MainCallParameters;
import org.jetbrains.k2js.facade.exceptions.MainFunctionNotFoundException;
import org.jetbrains.k2js.facade.exceptions.TranslationException;
@@ -61,9 +62,6 @@ import static org.jetbrains.k2js.translate.utils.dangerous.DangerousData.collect
* Goal is to simplify interaction between translators.
*/
public final class Translation {
public enum EcmaVersion {
v3, v5
}
private Translation() {
}