Using custom CompilerConfigurationKey in CompilerConfiguration API.
This commit is contained in:
@@ -16,8 +16,8 @@
|
||||
|
||||
package org.jetbrains.jet.cli.common;
|
||||
|
||||
import com.intellij.openapi.util.Key;
|
||||
import org.jetbrains.jet.cli.common.messages.MessageCollector;
|
||||
import org.jetbrains.jet.config.CompilerConfigurationKey;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -26,8 +26,10 @@ import java.util.List;
|
||||
* @since 7/23/12
|
||||
*/
|
||||
public class CLIConfigurationKeys {
|
||||
public static final Key<MessageCollector> MESSAGE_COLLECTOR_KEY = Key.create("message collector");
|
||||
public static final Key<List<CompilerPlugin>> COMPILER_PLUGINS = Key.create("compiler plugins");
|
||||
public static final CompilerConfigurationKey<MessageCollector> MESSAGE_COLLECTOR_KEY =
|
||||
CompilerConfigurationKey.create("message collector");
|
||||
public static final CompilerConfigurationKey<List<CompilerPlugin>> COMPILER_PLUGINS =
|
||||
CompilerConfigurationKey.create("compiler plugins");
|
||||
|
||||
private CLIConfigurationKeys() {
|
||||
}
|
||||
|
||||
@@ -16,8 +16,8 @@
|
||||
|
||||
package org.jetbrains.jet.cli.jvm;
|
||||
|
||||
import com.intellij.openapi.util.Key;
|
||||
import org.jetbrains.jet.codegen.BuiltinToJavaTypesMapping;
|
||||
import org.jetbrains.jet.config.CompilerConfigurationKey;
|
||||
import org.jetbrains.jet.lang.BuiltinsScopeExtensionMode;
|
||||
import org.jetbrains.jet.lang.resolve.AnalyzerScriptParameter;
|
||||
|
||||
@@ -32,11 +32,13 @@ public class JVMConfigurationKeys {
|
||||
private JVMConfigurationKeys() {
|
||||
}
|
||||
|
||||
public static final Key<List<File>> CLASSPATH_KEY = Key.create("classpath");
|
||||
public static final Key<List<File>> ANNOTATIONS_PATH_KEY = Key.create("annotations path");
|
||||
public static final CompilerConfigurationKey<List<File>> CLASSPATH_KEY = CompilerConfigurationKey.create("classpath");
|
||||
public static final CompilerConfigurationKey<List<File>> ANNOTATIONS_PATH_KEY = CompilerConfigurationKey.create("annotations path");
|
||||
|
||||
public static final Key<List<AnalyzerScriptParameter>> SCRIPT_PARAMETERS = Key.create("script");
|
||||
public static final Key<BuiltinsScopeExtensionMode> BUILTINS_SCOPE_EXTENSION_MODE_KEY = Key.create("builtins scope extension mode");
|
||||
public static final Key<Boolean> STUBS = Key.create("stubs");
|
||||
public static final Key<BuiltinToJavaTypesMapping> BUILTIN_TO_JAVA_TYPES_MAPPING_KEY = Key.create("builtin to java types mapping");
|
||||
public static final CompilerConfigurationKey<List<AnalyzerScriptParameter>> SCRIPT_PARAMETERS = CompilerConfigurationKey.create("script");
|
||||
public static final CompilerConfigurationKey<BuiltinsScopeExtensionMode> BUILTINS_SCOPE_EXTENSION_MODE_KEY =
|
||||
CompilerConfigurationKey.create("builtins scope extension mode");
|
||||
public static final CompilerConfigurationKey<Boolean> STUBS = CompilerConfigurationKey.create("stubs");
|
||||
public static final CompilerConfigurationKey<BuiltinToJavaTypesMapping> BUILTIN_TO_JAVA_TYPES_MAPPING_KEY =
|
||||
CompilerConfigurationKey.create("builtin to java types mapping");
|
||||
}
|
||||
|
||||
@@ -16,11 +16,8 @@
|
||||
|
||||
package org.jetbrains.jet.config;
|
||||
|
||||
import com.intellij.openapi.util.Key;
|
||||
import org.jetbrains.jet.lang.parsing.JetScriptDefinition;
|
||||
import org.jetbrains.jet.lang.resolve.AnalyzerScriptParameter;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@@ -31,7 +28,7 @@ public class CommonConfigurationKeys {
|
||||
private CommonConfigurationKeys() {
|
||||
}
|
||||
|
||||
public static final Key<List<String>> SOURCE_ROOTS_KEY = Key.create("source roots");
|
||||
public static final CompilerConfigurationKey<List<String>> SOURCE_ROOTS_KEY = CompilerConfigurationKey.create("source roots");
|
||||
|
||||
public static final Key<List<JetScriptDefinition>> SCRIPT_DEFINITIONS_KEY = Key.create("script definitions");
|
||||
public static final CompilerConfigurationKey<List<JetScriptDefinition>> SCRIPT_DEFINITIONS_KEY = CompilerConfigurationKey.create("script definitions");
|
||||
}
|
||||
|
||||
@@ -31,20 +31,20 @@ public class CompilerConfiguration {
|
||||
private boolean readOnly = false;
|
||||
|
||||
@Nullable
|
||||
public <T> T get(@NotNull Key<T> key) {
|
||||
T data = (T) map.get(key);
|
||||
public <T> T get(@NotNull CompilerConfigurationKey<T> key) {
|
||||
T data = (T) map.get(key.ideaKey);
|
||||
return data == null ? null : unmodifiable(data);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public <T> T get(@NotNull Key<T> key, @NotNull T defaultValue) {
|
||||
T data = (T) map.get(key);
|
||||
public <T> T get(@NotNull CompilerConfigurationKey<T> key, @NotNull T defaultValue) {
|
||||
T data = (T) map.get(key.ideaKey);
|
||||
return data == null ? defaultValue : unmodifiable(data);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public <T> List<T> getList(@NotNull Key<List<T>> key) {
|
||||
List<T> data = (List<T>) map.get(key);
|
||||
public <T> List<T> getList(@NotNull CompilerConfigurationKey<List<T>> key) {
|
||||
List<T> data = (List<T>) map.get(key.ideaKey);
|
||||
if (data == null) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
@@ -53,26 +53,28 @@ public class CompilerConfiguration {
|
||||
}
|
||||
}
|
||||
|
||||
public <T> void put(@NotNull Key<T> key, @Nullable T value) {
|
||||
public <T> void put(@NotNull CompilerConfigurationKey<T> key, @Nullable T value) {
|
||||
checkReadOnly();
|
||||
map.put(key, value);
|
||||
map.put(key.ideaKey, value);
|
||||
}
|
||||
|
||||
public <T> void add(@NotNull Key<List<T>> key, @NotNull T value) {
|
||||
public <T> void add(@NotNull CompilerConfigurationKey<List<T>> key, @NotNull T value) {
|
||||
checkReadOnly();
|
||||
if (map.get(key) == null) {
|
||||
map.put(key, new ArrayList<T>());
|
||||
Key<List<T>> ideaKey = key.ideaKey;
|
||||
if (map.get(ideaKey) == null) {
|
||||
map.put(ideaKey, new ArrayList<T>());
|
||||
}
|
||||
List<T> list = (List<T>) map.get(key);
|
||||
List<T> list = (List<T>) map.get(ideaKey);
|
||||
list.add(value);
|
||||
}
|
||||
|
||||
public <T> void addAll(@NotNull Key<List<T>> key, @NotNull Collection<T> values) {
|
||||
public <T> void addAll(@NotNull CompilerConfigurationKey<List<T>> key, @NotNull Collection<T> values) {
|
||||
checkReadOnly();
|
||||
if (map.get(key) == null) {
|
||||
map.put(key, new ArrayList<T>());
|
||||
Key<List<T>> ideaKey = key.ideaKey;
|
||||
if (map.get(ideaKey) == null) {
|
||||
map.put(ideaKey, new ArrayList<T>());
|
||||
}
|
||||
List<T> list = (List<T>) map.get(key);
|
||||
List<T> list = (List<T>) map.get(ideaKey);
|
||||
list.addAll(values);
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* 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.jet.config;
|
||||
|
||||
import com.intellij.openapi.util.Key;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* @author Evgeny Gerashchenko
|
||||
* @since 7/24/12
|
||||
*/
|
||||
public class CompilerConfigurationKey<T> {
|
||||
Key<T> ideaKey;
|
||||
|
||||
private CompilerConfigurationKey(@NotNull @NonNls String name) {
|
||||
ideaKey = Key.create(name);
|
||||
}
|
||||
|
||||
public static <T> CompilerConfigurationKey<T> create(@NotNull @NonNls String name) {
|
||||
return new CompilerConfigurationKey<T>(name);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user