001 /* 002 * Copyright 2010-2015 JetBrains s.r.o. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 017 package org.jetbrains.kotlin.js.config; 018 019 import com.intellij.openapi.project.Project; 020 import com.intellij.util.SmartList; 021 import org.jetbrains.annotations.NotNull; 022 import org.jetbrains.kotlin.psi.JetFile; 023 import org.jetbrains.kotlin.utils.KotlinJavascriptMetadata; 024 import org.jetbrains.kotlin.utils.PathUtil; 025 026 import java.util.Collections; 027 import java.util.List; 028 029 public class LibrarySourcesConfigWithCaching extends LibrarySourcesConfig { 030 public static final List<String> JS_STDLIB = 031 Collections.singletonList(PathUtil.getKotlinPathsForDistDirectory().getJsStdLibJarPath().getAbsolutePath()); 032 033 private static List<KotlinJavascriptMetadata> stdlibMetadata = null; 034 035 private final boolean isUnitTestConfig; 036 037 public LibrarySourcesConfigWithCaching( 038 @NotNull Project project, 039 @NotNull String moduleId, 040 @NotNull EcmaVersion ecmaVersion, 041 boolean sourcemap, 042 boolean inlineEnabled, 043 boolean isUnitTestConfig 044 ) { 045 super(project, moduleId, JS_STDLIB, ecmaVersion, sourcemap, inlineEnabled); 046 this.isUnitTestConfig = isUnitTestConfig; 047 } 048 049 @Override 050 protected void init(@NotNull List<JetFile> sourceFilesInLibraries, @NotNull List<KotlinJavascriptMetadata> metadata) { 051 if (stdlibMetadata == null) { 052 //noinspection AssignmentToStaticFieldFromInstanceMethod 053 stdlibMetadata = new SmartList<KotlinJavascriptMetadata>(); 054 super.init(sourceFilesInLibraries, stdlibMetadata); 055 } 056 057 metadata.addAll(stdlibMetadata); 058 } 059 060 @Override 061 public boolean isTestConfig() { 062 return isUnitTestConfig; 063 } 064 }