Config.java 3.0 KB
Newer Older
P
Pavel Talanov 已提交
1
/*
A
Andrey Breslav 已提交
2
 * Copyright 2010-2012 JetBrains s.r.o.
P
Pavel Talanov 已提交
3 4 5 6 7 8 9 10 11 12 13 14 15 16
 *
 * 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.
 */

P
Pavel Talanov 已提交
17 18 19 20
package org.jetbrains.k2js.config;

import com.intellij.openapi.project.Project;
import org.jetbrains.annotations.NotNull;
21
import org.jetbrains.annotations.Nullable;
P
Pavel Talanov 已提交
22 23
import org.jetbrains.jet.lang.psi.JetFile;

P
pTalanov 已提交
24
import java.util.Arrays;
P
pTalanov 已提交
25
import java.util.Collections;
P
Pavel Talanov 已提交
26
import java.util.List;
P
Pavel Talanov 已提交
27 28 29

/**
 * @author Pavel Talanov
P
Pavel Talanov 已提交
30
 *         <p/>
P
Pavel V. Talanov 已提交
31
 *         Base class representing a configuration of translator.
P
Pavel Talanov 已提交
32
 */
P
Pavel Talanov 已提交
33 34
public abstract class Config {

P
pTalanov 已提交
35
    @NotNull
P
pTalanov 已提交
36 37
    public static Config getEmptyConfig(@NotNull Project project, @NotNull EcmaVersion ecmaVersion) {
        return new Config(project, ecmaVersion) {
P
pTalanov 已提交
38 39 40 41 42 43 44 45
            @NotNull
            @Override
            protected List<JetFile> generateLibFiles() {
                return Collections.emptyList();
            }
        };
    }

P
pTalanov 已提交
46 47 48 49 50 51 52
    //NOTE: used by mvn build
    @SuppressWarnings("UnusedDeclaration")
    @NotNull
    public static Config getEmptyConfig(@NotNull Project project) {
        return getEmptyConfig(project, EcmaVersion.defaultVersion());
    }

P
Pavel Talanov 已提交
53
    @NotNull
54
    public static final List<String> LIB_FILE_NAMES = Arrays.asList(
P
pTalanov 已提交
55 56 57 58 59 60 61 62 63 64
            "/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",
P
Pavel V. Talanov 已提交
65 66
            "/stdlib/JUMaps.kt",
            "/stdlib/browser.kt",
67 68 69 70
            "/core/dom.kt",
            "/dom/domcore.kt",
            "/dom/html/htmlcore.kt",
            "/dom/html5/canvas.kt",
71
            "/dom/html/window.kt"
P
pTalanov 已提交
72 73
    );

74
    public static final String LIBRARIES_LOCATION = "js/js.libraries/src";
P
Pavel Talanov 已提交
75 76

    @NotNull
P
pTalanov 已提交
77
    private final Project project;
78 79
    @Nullable
    private List<JetFile> libFiles = null;
80 81
    @NotNull
    private final EcmaVersion target;
P
Pavel Talanov 已提交
82

83
    public Config(@NotNull Project project, @NotNull EcmaVersion ecmaVersion) {
P
pTalanov 已提交
84
        this.project = project;
85
        this.target = ecmaVersion;
P
pTalanov 已提交
86 87 88 89 90 91 92
    }

    @NotNull
    public Project getProject() {
        return project;
    }

93 94 95 96 97
    @NotNull
    public EcmaVersion getTarget() {
        return target;
    }

P
pTalanov 已提交
98
    @NotNull
99 100 101 102 103 104 105 106 107
    protected abstract List<JetFile> generateLibFiles();

    @NotNull
    public final List<JetFile> getLibFiles() {
        if (libFiles == null) {
            libFiles = generateLibFiles();
        }
        return libFiles;
    }
P
Pavel Talanov 已提交
108
}