Built-ins can now be initialized on demand
This commit is contained in:
committed by
Alexander Udalov
parent
30daf0aded
commit
25a5025c58
@@ -124,8 +124,6 @@ public class JetCoreEnvironment {
|
|||||||
}
|
}
|
||||||
|
|
||||||
JetScriptDefinitionProvider.getInstance(project).addScriptDefinitions(configuration.getList(CommonConfigurationKeys.SCRIPT_DEFINITIONS_KEY));
|
JetScriptDefinitionProvider.getInstance(project).addScriptDefinitions(configuration.getList(CommonConfigurationKeys.SCRIPT_DEFINITIONS_KEY));
|
||||||
|
|
||||||
KotlinBuiltIns.initialize();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public CompilerConfiguration getConfiguration() {
|
public CompilerConfiguration getConfiguration() {
|
||||||
|
|||||||
@@ -72,9 +72,7 @@ public class KotlinBuiltIns {
|
|||||||
private static volatile boolean initializing;
|
private static volatile boolean initializing;
|
||||||
private static Throwable initializationFailed;
|
private static Throwable initializationFailed;
|
||||||
|
|
||||||
// This method must be called at least once per application run, on any project
|
private static synchronized void initialize() {
|
||||||
// before any type checking is run
|
|
||||||
public static synchronized void initialize() {
|
|
||||||
if (instance == null) {
|
if (instance == null) {
|
||||||
if (initializationFailed != null) {
|
if (initializationFailed != null) {
|
||||||
throw new RuntimeException(
|
throw new RuntimeException(
|
||||||
@@ -98,7 +96,7 @@ public class KotlinBuiltIns {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull // This asserts that initialize() is called before any resolution happens
|
@NotNull
|
||||||
public static KotlinBuiltIns getInstance() {
|
public static KotlinBuiltIns getInstance() {
|
||||||
if (initializing) {
|
if (initializing) {
|
||||||
synchronized (KotlinBuiltIns.class) {
|
synchronized (KotlinBuiltIns.class) {
|
||||||
@@ -107,7 +105,7 @@ public class KotlinBuiltIns {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (instance == null) {
|
if (instance == null) {
|
||||||
throw new IllegalStateException("Initialize standard library first");
|
initialize();
|
||||||
}
|
}
|
||||||
return instance;
|
return instance;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,9 +13,6 @@
|
|||||||
<depends optional="true" config-file="kotlin-copyright.xml">com.intellij.copyright</depends>
|
<depends optional="true" config-file="kotlin-copyright.xml">com.intellij.copyright</depends>
|
||||||
|
|
||||||
<project-components>
|
<project-components>
|
||||||
<component>
|
|
||||||
<implementation-class>org.jetbrains.jet.plugin.BuiltInsInitializer</implementation-class>
|
|
||||||
</component>
|
|
||||||
<component>
|
<component>
|
||||||
<implementation-class>org.jetbrains.jet.plugin.compiler.JetCompilerManager</implementation-class>
|
<implementation-class>org.jetbrains.jet.plugin.compiler.JetCompilerManager</implementation-class>
|
||||||
</component>
|
</component>
|
||||||
|
|||||||
@@ -1,40 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2010-2013 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.plugin;
|
|
||||||
|
|
||||||
import com.intellij.openapi.progress.ProgressManager;
|
|
||||||
import com.intellij.openapi.project.Project;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This project component initializes KotlinBuiltIns so that throwing a ProcessCanceledException while
|
|
||||||
* loading PSI from declaration files is prevented.
|
|
||||||
*/
|
|
||||||
public class BuiltInsInitializer {
|
|
||||||
public BuiltInsInitializer(@NotNull final Project project) {
|
|
||||||
ProgressManager.getInstance().executeNonCancelableSection(new Runnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
// MULTI_THREADED is important not only because of threading as such: since built-ins rely on a project,
|
|
||||||
// if they are not fully initialized when a project is closed,
|
|
||||||
// they will be referencing invalid PSI upon a next request
|
|
||||||
KotlinBuiltIns.initialize();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -46,7 +46,6 @@ import org.jetbrains.jet.lang.resolve.scopes.RedeclarationHandler;
|
|||||||
import org.jetbrains.jet.lang.resolve.scopes.WritableScope;
|
import org.jetbrains.jet.lang.resolve.scopes.WritableScope;
|
||||||
import org.jetbrains.jet.lang.resolve.scopes.WritableScopeImpl;
|
import org.jetbrains.jet.lang.resolve.scopes.WritableScopeImpl;
|
||||||
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns;
|
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns;
|
||||||
import org.jetbrains.jet.plugin.BuiltInsInitializer;
|
|
||||||
import org.jetbrains.jet.renderer.DescriptorRenderer;
|
import org.jetbrains.jet.renderer.DescriptorRenderer;
|
||||||
|
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
@@ -59,11 +58,7 @@ public class BuiltInsReferenceResolver extends AbstractProjectComponent {
|
|||||||
private BindingContext bindingContext = null;
|
private BindingContext bindingContext = null;
|
||||||
private Set<? extends PsiFile> builtInsSources = Sets.newHashSet();
|
private Set<? extends PsiFile> builtInsSources = Sets.newHashSet();
|
||||||
|
|
||||||
public BuiltInsReferenceResolver(
|
public BuiltInsReferenceResolver(Project project) {
|
||||||
Project project,
|
|
||||||
// This parameter is needed to initialize built-ins before this component
|
|
||||||
BuiltInsInitializer ignored
|
|
||||||
) {
|
|
||||||
super(project);
|
super(project);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -29,7 +29,6 @@ import org.jetbrains.jet.j2k.util.AstUtil;
|
|||||||
import org.jetbrains.jet.j2k.visitors.*;
|
import org.jetbrains.jet.j2k.visitors.*;
|
||||||
import org.jetbrains.jet.lang.resolve.name.Name;
|
import org.jetbrains.jet.lang.resolve.name.Name;
|
||||||
import org.jetbrains.jet.lang.types.expressions.OperatorConventions;
|
import org.jetbrains.jet.lang.types.expressions.OperatorConventions;
|
||||||
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns;
|
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
@@ -63,7 +62,6 @@ public class Converter {
|
|||||||
|
|
||||||
public Converter(@NotNull Project project) {
|
public Converter(@NotNull Project project) {
|
||||||
this.project = project;
|
this.project = project;
|
||||||
KotlinBuiltIns.initialize();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
|
|||||||
Reference in New Issue
Block a user