diff --git a/compiler/preloader/src/org/jetbrains/jet/preloading/ClassPreloadingUtils.java b/compiler/preloader/src/org/jetbrains/jet/preloading/ClassPreloadingUtils.java index a9cf32480a8..3f129f6d813 100644 --- a/compiler/preloader/src/org/jetbrains/jet/preloading/ClassPreloadingUtils.java +++ b/compiler/preloader/src/org/jetbrains/jet/preloading/ClassPreloadingUtils.java @@ -191,7 +191,7 @@ public class ClassPreloadingUtils { public URL getURL() { try { - String path = "file:" + jarFile + "!" + resourceName; + String path = "file:" + jarFile + "!/" + resourceName; return new URL("jar", null, 0, path, new URLStreamHandler() { @Override protected URLConnection openConnection(URL u) throws IOException { diff --git a/idea/src/META-INF/plugin.xml b/idea/src/META-INF/plugin.xml index 0d994df117e..24160265f63 100644 --- a/idea/src/META-INF/plugin.xml +++ b/idea/src/META-INF/plugin.xml @@ -6,7 +6,7 @@ @snapshot@ JetBrains Inc. - + JUnit TestNG-J diff --git a/idea/src/org/jetbrains/jet/plugin/project/K2JSModuleComponent.java b/idea/src/org/jetbrains/jet/plugin/project/K2JSModuleComponent.java index c25cbe3fac1..90d4caf28c1 100644 --- a/idea/src/org/jetbrains/jet/plugin/project/K2JSModuleComponent.java +++ b/idea/src/org/jetbrains/jet/plugin/project/K2JSModuleComponent.java @@ -21,17 +21,14 @@ import com.intellij.openapi.components.State; import com.intellij.openapi.components.Storage; import com.intellij.openapi.module.Module; import com.intellij.openapi.module.ModuleComponent; -import com.intellij.openapi.roots.impl.storage.ClasspathStorage; -import com.intellij.util.xmlb.XmlSerializerUtil; +import com.intellij.openapi.roots.impl.storage.ClassPathStorageUtil; import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; -import org.jetbrains.k2js.config.EcmaVersion; @Deprecated @State( name = "K2JSModule", storages = @Storage( - id = ClasspathStorage.DEFAULT_STORAGE, + id = ClassPathStorageUtil.DEFAULT_STORAGE, file = "$MODULE_FILE$" ) ) diff --git a/idea/src/org/jetbrains/jet/plugin/quickfix/ExclExclCallFix.java b/idea/src/org/jetbrains/jet/plugin/quickfix/ExclExclCallFix.java index efb955cff18..8db90f07d04 100644 --- a/idea/src/org/jetbrains/jet/plugin/quickfix/ExclExclCallFix.java +++ b/idea/src/org/jetbrains/jet/plugin/quickfix/ExclExclCallFix.java @@ -16,7 +16,7 @@ package org.jetbrains.jet.plugin.quickfix; -import com.intellij.codeInsight.CodeInsightUtilBase; +import com.intellij.codeInsight.FileModificationService; import com.intellij.codeInsight.intention.IntentionAction; import com.intellij.openapi.editor.Editor; import com.intellij.openapi.project.Project; @@ -79,7 +79,7 @@ public class ExclExclCallFix implements IntentionAction { @Override public void invoke(@NotNull Project project, Editor editor, PsiFile file) throws IncorrectOperationException { - if (!CodeInsightUtilBase.prepareFileForWrite(file)) { + if (!FileModificationService.getInstance().prepareFileForWrite(file)) { return; } diff --git a/idea/src/org/jetbrains/jet/plugin/quickfix/JetIntentionAction.java b/idea/src/org/jetbrains/jet/plugin/quickfix/JetIntentionAction.java index 5fbbd1b99f0..729091fa5f3 100644 --- a/idea/src/org/jetbrains/jet/plugin/quickfix/JetIntentionAction.java +++ b/idea/src/org/jetbrains/jet/plugin/quickfix/JetIntentionAction.java @@ -16,7 +16,7 @@ package org.jetbrains.jet.plugin.quickfix; -import com.intellij.codeInsight.CodeInsightUtilBase; +import com.intellij.codeInsight.FileModificationService; import com.intellij.codeInsight.intention.IntentionAction; import com.intellij.openapi.editor.Editor; import com.intellij.openapi.project.Project; @@ -43,7 +43,7 @@ public abstract class JetIntentionAction implements Intent @Override public void invoke(@NotNull Project project, Editor editor, PsiFile file) throws IncorrectOperationException { if (file instanceof JetFile) { - if (CodeInsightUtilBase.prepareFileForWrite(element.getContainingFile())) { + if (FileModificationService.getInstance().prepareFileForWrite(element.getContainingFile())) { invoke(project, editor, (JetFile) file); } } diff --git a/idea/src/org/jetbrains/jet/plugin/quickfix/MapPlatformClassToKotlinFix.java b/idea/src/org/jetbrains/jet/plugin/quickfix/MapPlatformClassToKotlinFix.java index 064e28bff51..efbf3cf8749 100644 --- a/idea/src/org/jetbrains/jet/plugin/quickfix/MapPlatformClassToKotlinFix.java +++ b/idea/src/org/jetbrains/jet/plugin/quickfix/MapPlatformClassToKotlinFix.java @@ -150,7 +150,7 @@ public class MapPlatformClassToKotlinFix extends JetIntentionAction classIdentifiers = Sets.newHashSet(); @@ -59,9 +62,15 @@ public class Converter { private final Set flags = Sets.newHashSet(); public Converter(@NotNull Project project) { + this.project = project; KotlinBuiltIns.initialize(project, KotlinBuiltIns.InitializationMode.MULTI_THREADED); } + @NotNull + public Project getProject() { + return project; + } + public boolean addFlag(@NotNull J2KConverterFlags flag) { return flags.add(flag); } diff --git a/j2k/tests/j2k-tests.iml b/j2k/tests/j2k-tests.iml index 0d3d4fd6bce..bd44f2f04ce 100644 --- a/j2k/tests/j2k-tests.iml +++ b/j2k/tests/j2k-tests.iml @@ -13,6 +13,7 @@ + diff --git a/j2k/tests/test/org/jetbrains/jet/j2k/StandaloneJavaToKotlinConverterTest.java b/j2k/tests/test/org/jetbrains/jet/j2k/StandaloneJavaToKotlinConverterTest.java index b5a97417e62..de1f996a202 100644 --- a/j2k/tests/test/org/jetbrains/jet/j2k/StandaloneJavaToKotlinConverterTest.java +++ b/j2k/tests/test/org/jetbrains/jet/j2k/StandaloneJavaToKotlinConverterTest.java @@ -16,44 +16,24 @@ package org.jetbrains.jet.j2k; -import com.intellij.openapi.Disposable; import com.intellij.openapi.util.io.FileUtil; import com.intellij.psi.PsiFile; import com.intellij.psi.PsiJavaFile; +import com.intellij.testFramework.UsefulTestCase; import junit.framework.Assert; import junit.framework.Test; -import junit.framework.TestCase; import junit.framework.TestSuite; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import org.jetbrains.jet.cli.jvm.JVMConfigurationKeys; +import org.jetbrains.jet.ConfigurationKind; import org.jetbrains.jet.cli.jvm.compiler.JetCoreEnvironment; -import org.jetbrains.jet.config.CompilerConfiguration; -import org.jetbrains.jet.utils.PathUtil; import java.io.File; import java.io.IOException; -public class StandaloneJavaToKotlinConverterTest extends TestCase { - private static final JetCoreEnvironment jetCoreEnvironment; - - static { - CompilerConfiguration config = new CompilerConfiguration(); - - config.add(JVMConfigurationKeys.CLASSPATH_KEY, PathUtil.findRtJar()); - File annotations = JavaToKotlinTranslator.findAnnotations(); - if (annotations != null && annotations.exists()) { - config.add(JVMConfigurationKeys.CLASSPATH_KEY, annotations); - } - - Disposable disposable = new Disposable() { - @Override - public void dispose() { - } - }; - jetCoreEnvironment = new JetCoreEnvironment(disposable, config); - } +import static org.jetbrains.jet.JetTestUtils.createEnvironmentWithMockJdkAndIdeaAnnotations; +public class StandaloneJavaToKotlinConverterTest extends UsefulTestCase { private final String myDataPath; private final String myName; @@ -64,7 +44,9 @@ public class StandaloneJavaToKotlinConverterTest extends TestCase { @Override protected void runTest() throws Throwable { + JetCoreEnvironment jetCoreEnvironment = createEnvironmentWithMockJdkAndIdeaAnnotations(getTestRootDisposable(), ConfigurationKind.JDK_ONLY); Converter converter = new Converter(jetCoreEnvironment.getProject()); + String javaPath = "j2k/tests/testData/" + getTestFilePath(); String kotlinPath = javaPath.replace(".jav", ".kt"); @@ -140,7 +122,7 @@ public class StandaloneJavaToKotlinConverterTest extends TestCase { @NotNull private String fileToKotlin(Converter converter, @NotNull String text) { - return generateKotlinCode(converter, JavaToKotlinTranslator.createFile(jetCoreEnvironment.getProject(), text)); + return generateKotlinCode(converter, JavaToKotlinTranslator.createFile(converter.getProject(), text)); } @NotNull diff --git a/jdk-annotations/java/io/annotations.xml b/jdk-annotations/java/io/annotations.xml index 665f4d87c05..4c510479b92 100644 --- a/jdk-annotations/java/io/annotations.xml +++ b/jdk-annotations/java/io/annotations.xml @@ -906,6 +906,9 @@ + + + diff --git a/jdk-annotations/java/lang/annotations.xml b/jdk-annotations/java/lang/annotations.xml index dc404c0ddaf..d8f6eb8a2d0 100644 --- a/jdk-annotations/java/lang/annotations.xml +++ b/jdk-annotations/java/lang/annotations.xml @@ -1187,6 +1187,9 @@ + + + diff --git a/jdk-annotations/java/net/annotations.xml b/jdk-annotations/java/net/annotations.xml index e50303fd43a..290782ce0d0 100644 --- a/jdk-annotations/java/net/annotations.xml +++ b/jdk-annotations/java/net/annotations.xml @@ -318,6 +318,9 @@ + + + @@ -333,6 +336,9 @@ + + + diff --git a/jdk-annotations/java/nio/annotations.xml b/jdk-annotations/java/nio/annotations.xml index b5297ebbfa5..a299a37bb9f 100644 --- a/jdk-annotations/java/nio/annotations.xml +++ b/jdk-annotations/java/nio/annotations.xml @@ -21,6 +21,9 @@ + + + @@ -60,6 +63,9 @@ + + + diff --git a/jdk-annotations/java/util/annotations.xml b/jdk-annotations/java/util/annotations.xml index b80ae57f71d..296c3570ba0 100644 --- a/jdk-annotations/java/util/annotations.xml +++ b/jdk-annotations/java/util/annotations.xml @@ -2104,6 +2104,9 @@ + + + diff --git a/libraries/stdlib/src/kotlin/properties/delegation/Delegation.kt b/libraries/stdlib/src/kotlin/properties/delegation/Delegation.kt new file mode 100644 index 00000000000..fe4dbb05a6d --- /dev/null +++ b/libraries/stdlib/src/kotlin/properties/delegation/Delegation.kt @@ -0,0 +1,118 @@ +package kotlin.properties.delegation + +import kotlin.properties.ChangeSupport + +public class NotNullVar { + private var value: T? = null + + public fun get(thisRef: Any?, desc: PropertyMetadata): T { + return value ?: throw IllegalStateException("Property ${desc.name} should be initialized before get") + } + + public fun set(thisRef: Any?, desc: PropertyMetadata, value: T) { + this.value = value + } +} + +public class SynchronizedVar(private val initValue: T, private val lock: Any) { + private var value: T = initValue + + public fun get(thisRef: Any?, desc: PropertyMetadata): T { + return synchronized(lock) { value } + } + + public fun set(thisRef: Any?, desc: PropertyMetadata, newValue: T) { + synchronized(lock) { + value = newValue + } + } +} + +class ObservableProperty(initialValue: T, val changeSupport: (name: String, oldValue: T, newValue: T) -> Unit) { + private var value = initialValue + + public fun get(thisRef: Any?, desc: PropertyMetadata): T { + return value + } + + public fun set(thisRef: Any?, desc: PropertyMetadata, newValue: T) { + changeSupport(desc.name, value, newValue) + value = newValue + } +} + +public class KeyMissingException(message: String): RuntimeException(message) + +public abstract class MapVal { + public abstract fun getMap(thisRef: T): Map<*, *> + public abstract fun getKey(desc: PropertyMetadata): Any? + + public open fun getDefaultValue(desc: PropertyMetadata, key: Any?): V { + throw KeyMissingException("Key $key is missing") + } + + public fun get(thisRef: T, desc: PropertyMetadata): V { + val key = getKey(desc) + val map = getMap(thisRef) + if (!map.containsKey(key)) { + return getDefaultValue(desc, key) + } + return map[key] as V + } +} + +public abstract class MapVar: MapVal() { + + public fun set(thisRef: T, desc: PropertyMetadata, newValue: V) { + val map = getMap(thisRef) as MutableMap + map[getKey(desc)] = newValue + } +} + +public fun Map.readOnlyProperty(default: (() -> V)? = null): MapVal { + return object: MapVal() { + override fun getMap(thisRef: Any?) = this@readOnlyProperty + override fun getKey(desc: PropertyMetadata) = desc.name + override fun getDefaultValue(desc: PropertyMetadata, key: Any?) = if (default == null) super.getDefaultValue(desc, key) else default() + } +} + +public fun Map<*, *>.readOnlyProperty(default: (() -> V)? = null, key: Any?): MapVal { + return object: MapVal() { + override fun getMap(thisRef: Any?) = this@readOnlyProperty + override fun getKey(desc: PropertyMetadata) = key + override fun getDefaultValue(desc: PropertyMetadata, key: Any?) = if (default == null) super.getDefaultValue(desc, key) else default() + } +} + +public fun Map<*, *>.readOnlyProperty(default: (() -> V)? = null, key: (desc: PropertyMetadata) -> Any?): MapVal { + return object: MapVal() { + override fun getMap(thisRef: Any?) = this@readOnlyProperty + override fun getKey(desc: PropertyMetadata) = key(desc) + override fun getDefaultValue(desc: PropertyMetadata, key: Any?) = if (default == null) super.getDefaultValue(desc, key) else default() + } +} + +public fun MutableMap.property(default: (() -> V)? = null): MapVar { + return object: MapVar() { + override fun getMap(thisRef: Any?) = this@property + override fun getKey(desc: PropertyMetadata) = desc.name + override fun getDefaultValue(desc: PropertyMetadata, key: Any?) = if (default == null) super.getDefaultValue(desc, key) else default() + } +} + +public fun MutableMap<*, *>.property(default: (() -> V)? = null, key: Any?): MapVar { + return object: MapVar() { + override fun getMap(thisRef: Any?) = this@property + override fun getKey(desc: PropertyMetadata) = key + override fun getDefaultValue(desc: PropertyMetadata, key: Any?) = if (default == null) super.getDefaultValue(desc, key) else default() + } +} + +public fun MutableMap<*, *>.property(default: (() -> V)? = null, key: (desc: PropertyMetadata) -> Any?): MapVar { + return object: MapVar() { + override fun getMap(thisRef: Any?) = this@property + override fun getKey(desc: PropertyMetadata) = key(desc) + override fun getDefaultValue(desc: PropertyMetadata, key: Any?) = if (default == null) super.getDefaultValue(desc, key) else default() + } +} \ No newline at end of file diff --git a/libraries/stdlib/src/kotlin/properties/delegation/lazy/LazyValues.kt b/libraries/stdlib/src/kotlin/properties/delegation/lazy/LazyValues.kt new file mode 100644 index 00000000000..2d0767446d3 --- /dev/null +++ b/libraries/stdlib/src/kotlin/properties/delegation/lazy/LazyValues.kt @@ -0,0 +1,75 @@ +package kotlin.properties.delegation.lazy + +private val NULL_VALUE: Any = Any() + +private fun escape(value: T): Any { + return if (value == null) NULL_VALUE else value +} + +private fun unescape(value: Any): T? { + return if (value == NULL_VALUE) null else value as T +} + +public open class LazyVal(initializer: () -> T): NullableLazyVal(initializer) { + override fun get(thisRef: Any?, desc: PropertyMetadata): T { + return super.get(thisRef, desc)!! + } +} + +public open class NullableLazyVal(private val initializer: () -> T?) { + private var value: Any? = null + + public open fun get(thisRef: Any?, desc: PropertyMetadata): T? { + if (value == null) { + value = escape(initializer()) + } + return unescape(value!!) + } +} + +public open class VolatileLazyVal(initializer: () -> T): VolatileNullableLazyVal(initializer) { + override fun get(thisRef: Any?, desc: PropertyMetadata): T { + return super.get(thisRef, desc)!! + } +} + +public open class VolatileNullableLazyVal(private val initializer: () -> T?) { + private volatile var value: Any? = null + + public open fun get(thisRef: Any?, desc: PropertyMetadata): T? { + if (value == null) { + value = escape(initializer()) + } + return unescape(value!!) + } +} + +public open class AtomicLazyVal(lock: Any? = null, initializer: () -> T): AtomicNullableLazyVal(lock, initializer) { + override fun get(thisRef: Any?, desc: PropertyMetadata): T { + return super.get(thisRef, desc)!! + } +} + +public open class AtomicNullableLazyVal(lock: Any? = null, private val initializer: () -> T?) { + private val lock = lock ?: this + private volatile var value: Any? = null + + public open fun get(thisRef: Any?, desc: PropertyMetadata): T? { + val _v1 = value + if (_v1 != null) { + return unescape(_v1) + } + + return synchronized(lock) { + val _v2 = value + if (_v2 != null) { + unescape(_v2) + } + else { + val typedValue = initializer() + value = escape(typedValue) + typedValue + } + } + } +} \ No newline at end of file diff --git a/update_dependencies.xml b/update_dependencies.xml index 9991fd7bc0e..5fdf093cf5c 100644 --- a/update_dependencies.xml +++ b/update_dependencies.xml @@ -1,7 +1,7 @@ - - - + + + @@ -118,7 +118,7 @@ --> - + @@ -178,7 +178,7 @@ - + @@ -192,7 +192,7 @@ - +