proper environment when compiling special things
* do not include anything when compiling builtins * do not include kotlin-runtime and jdk-headers when compiling jdk-headers
This commit is contained in:
@@ -77,7 +77,8 @@
|
||||
<arg value="${basedir}/jdk-headers/src"/>
|
||||
<arg value="-output"/>
|
||||
<arg value="${output}/classes/jdk-headers"/>
|
||||
<arg value="-stubs"/>
|
||||
<arg value="-mode"/>
|
||||
<arg value="jdkHeaders"/>
|
||||
</java>
|
||||
</target>
|
||||
|
||||
@@ -92,7 +93,8 @@
|
||||
<arg value="${basedir}/compiler/frontend/src"/>
|
||||
<arg value="-output"/>
|
||||
<arg value="${output}/classes/lang"/>
|
||||
<arg value="-stubs"/>
|
||||
<arg value="-mode"/>
|
||||
<arg value="builtins"/>
|
||||
</java>
|
||||
</target>
|
||||
|
||||
|
||||
@@ -53,8 +53,8 @@ public class CompilerArguments {
|
||||
@Argument(value = "help", alias = "h", description = "show help")
|
||||
public boolean help;
|
||||
|
||||
@Argument(value = "stubs", description = "Compile stubs: ignore function bodies")
|
||||
public boolean stubs;
|
||||
@Argument(value = "mode", description = "Special compiler modes: stubs or jdkHeaders")
|
||||
public String mode;
|
||||
|
||||
@Argument(value = "tags", description = "Demarcate each compilation message (error, warning, etc) with an open and close tag")
|
||||
public boolean tags;
|
||||
@@ -130,14 +130,6 @@ public class CompilerArguments {
|
||||
this.stdlib = stdlib;
|
||||
}
|
||||
|
||||
public boolean isStubs() {
|
||||
return stubs;
|
||||
}
|
||||
|
||||
public void setStubs(boolean stubs) {
|
||||
this.stubs = stubs;
|
||||
}
|
||||
|
||||
public boolean isTags() {
|
||||
return tags;
|
||||
}
|
||||
|
||||
@@ -17,11 +17,9 @@
|
||||
package org.jetbrains.jet.cli;
|
||||
|
||||
import com.sampullara.cli.Args;
|
||||
import org.jetbrains.jet.compiler.CompileEnvironment;
|
||||
import org.jetbrains.jet.compiler.CompileEnvironmentException;
|
||||
import org.jetbrains.jet.compiler.CompilerPlugin;
|
||||
import org.jetbrains.jet.compiler.MessageRenderer;
|
||||
import org.jetbrains.jet.compiler.*;
|
||||
import org.jetbrains.jet.lang.diagnostics.Severity;
|
||||
import org.jetbrains.jet.lang.resolve.java.CompilerSpecialMode;
|
||||
|
||||
import java.io.PrintStream;
|
||||
import java.util.List;
|
||||
@@ -99,7 +97,18 @@ public class KotlinCompiler {
|
||||
errStream.println(messageRenderer.render(Severity.INFO, "Kotlin Compiler version " + CompilerVersion.VERSION, null, -1, -1));
|
||||
}
|
||||
|
||||
CompileEnvironment environment = new CompileEnvironment(messageRenderer, arguments.verbose);
|
||||
CompilerSpecialMode mode;
|
||||
if (arguments.mode == null) {
|
||||
mode = CompilerSpecialMode.REGULAR;
|
||||
} else if (arguments.mode.equals("jdkHeaders")) {
|
||||
mode = CompilerSpecialMode.JDK_HEADERS;
|
||||
} else if (arguments.mode.equals("builtins")) {
|
||||
mode = CompilerSpecialMode.BUILTINS;
|
||||
} else {
|
||||
throw new IllegalArgumentException("unknown compiler mode: " + arguments.mode);
|
||||
}
|
||||
|
||||
CompileEnvironment environment = new CompileEnvironment(messageRenderer, arguments.verbose, mode);
|
||||
try {
|
||||
configureEnvironment(environment, arguments, errStream);
|
||||
|
||||
@@ -163,8 +172,6 @@ public class KotlinCompiler {
|
||||
environment.setIgnoreErrors(false);
|
||||
environment.setErrorStream(errStream);
|
||||
|
||||
environment.setStubs(arguments.stubs);
|
||||
|
||||
// install any compiler plugins
|
||||
List<CompilerPlugin> plugins = arguments.getCompilerPlugins();
|
||||
if (plugins != null) {
|
||||
|
||||
@@ -37,6 +37,7 @@ import org.jetbrains.jet.lang.resolve.FqName;
|
||||
import org.jetbrains.jet.lang.resolve.java.JvmAbi;
|
||||
import org.jetbrains.jet.plugin.JetLanguage;
|
||||
import org.jetbrains.jet.plugin.JetMainDetector;
|
||||
import org.jetbrains.jet.lang.resolve.java.CompilerSpecialMode;
|
||||
import org.jetbrains.jet.utils.PathUtil;
|
||||
|
||||
import java.io.*;
|
||||
@@ -62,11 +63,11 @@ public class CompileEnvironment {
|
||||
private URL stdlibUrl;
|
||||
|
||||
private boolean ignoreErrors = false;
|
||||
private boolean stubs = false;
|
||||
private final CompilerSpecialMode mode;
|
||||
private final boolean verbose;
|
||||
|
||||
public CompileEnvironment() {
|
||||
this(MessageRenderer.PLAIN, false);
|
||||
this(MessageRenderer.PLAIN, false, CompilerSpecialMode.REGULAR);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -76,14 +77,15 @@ public class CompileEnvironment {
|
||||
* @param messageRenderer
|
||||
* @param verbose
|
||||
*/
|
||||
public CompileEnvironment(MessageRenderer messageRenderer, boolean verbose) {
|
||||
public CompileEnvironment(MessageRenderer messageRenderer, boolean verbose, CompilerSpecialMode mode) {
|
||||
this.mode = mode;
|
||||
this.verbose = verbose;
|
||||
rootDisposable = new Disposable() {
|
||||
@Override
|
||||
public void dispose() {
|
||||
}
|
||||
};
|
||||
environment = new JetCoreEnvironment(rootDisposable);
|
||||
environment = new JetCoreEnvironment(rootDisposable, mode == CompilerSpecialMode.REGULAR);
|
||||
this.messageRenderer = messageRenderer;
|
||||
}
|
||||
|
||||
@@ -95,10 +97,6 @@ public class CompileEnvironment {
|
||||
this.ignoreErrors = ignoreErrors;
|
||||
}
|
||||
|
||||
public void setStubs(boolean stubs) {
|
||||
this.stubs = stubs;
|
||||
}
|
||||
|
||||
public void dispose() {
|
||||
Disposer.dispose(rootDisposable);
|
||||
}
|
||||
@@ -123,17 +121,24 @@ public class CompileEnvironment {
|
||||
}
|
||||
|
||||
public void ensureRuntime() {
|
||||
ensureRuntime(environment);
|
||||
if (mode == CompilerSpecialMode.REGULAR) {
|
||||
ensureRuntime(environment);
|
||||
} else if (mode == CompilerSpecialMode.JDK_HEADERS) {
|
||||
ensureJdkRuntime(environment);
|
||||
} else if (mode == CompilerSpecialMode.BUILTINS) {
|
||||
// nop
|
||||
} else {
|
||||
throw new IllegalStateException("unknown mode: " + mode);
|
||||
}
|
||||
}
|
||||
|
||||
public static void ensureRuntime(@NotNull JetCoreEnvironment env) {
|
||||
Project project = env.getProject();
|
||||
if (JavaPsiFacade.getInstance(project).findClass("java.lang.Object", GlobalSearchScope.allScope(project)) == null) {
|
||||
// TODO: prepend
|
||||
env.addToClasspath(findRtJar());
|
||||
}
|
||||
ensureJdkRuntime(env);
|
||||
ensureKotlinRuntime(env);
|
||||
}
|
||||
|
||||
if (JavaPsiFacade.getInstance(project).findClass("jet.JetObject", GlobalSearchScope.allScope(project)) == null) {
|
||||
private static void ensureKotlinRuntime(JetCoreEnvironment env) {
|
||||
if (JavaPsiFacade.getInstance(env.getProject()).findClass("jet.JetObject", GlobalSearchScope.allScope(env.getProject())) == null) {
|
||||
// TODO: prepend
|
||||
File kotlin = PathUtil.getDefaultRuntimePath();
|
||||
if (kotlin == null || !kotlin.exists()) {
|
||||
@@ -147,6 +152,13 @@ public class CompileEnvironment {
|
||||
}
|
||||
}
|
||||
|
||||
public static void ensureJdkRuntime(JetCoreEnvironment env) {
|
||||
if (JavaPsiFacade.getInstance(env.getProject()).findClass("java.lang.Object", GlobalSearchScope.allScope(env.getProject())) == null) {
|
||||
// TODO: prepend
|
||||
env.addToClasspath(findRtJar());
|
||||
}
|
||||
}
|
||||
|
||||
public static File findRtJar() {
|
||||
String javaHome = System.getProperty("java.home");
|
||||
if ("jre".equals(new File(javaHome).getName())) {
|
||||
@@ -220,7 +232,7 @@ public class CompileEnvironment {
|
||||
}
|
||||
|
||||
private CompileEnvironment copyEnvironment(boolean verbose) {
|
||||
CompileEnvironment compileEnvironment = new CompileEnvironment(messageRenderer, verbose);
|
||||
CompileEnvironment compileEnvironment = new CompileEnvironment(messageRenderer, verbose, mode);
|
||||
compileEnvironment.setIgnoreErrors(ignoreErrors);
|
||||
compileEnvironment.setErrorStream(errorStream);
|
||||
// copy across any compiler plugins
|
||||
@@ -268,7 +280,7 @@ public class CompileEnvironment {
|
||||
|
||||
public ClassFileFactory compileModule(Module moduleBuilder, String directory) {
|
||||
CompileSession moduleCompileSession = newCompileSession();
|
||||
moduleCompileSession.setStubs(stubs);
|
||||
moduleCompileSession.setStubs(mode != CompilerSpecialMode.REGULAR);
|
||||
|
||||
if (moduleBuilder.getSourceFiles().isEmpty()) {
|
||||
throw new CompileEnvironmentException("No source files where defined");
|
||||
@@ -389,7 +401,7 @@ public class CompileEnvironment {
|
||||
|
||||
public boolean compileBunchOfSources(String sourceFileOrDir, String jar, String outputDir, boolean includeRuntime) {
|
||||
CompileSession session = newCompileSession();
|
||||
session.setStubs(stubs);
|
||||
session.setStubs(mode != CompilerSpecialMode.REGULAR);
|
||||
|
||||
session.addSources(sourceFileOrDir);
|
||||
|
||||
@@ -426,7 +438,7 @@ public class CompileEnvironment {
|
||||
}
|
||||
|
||||
private CompileSession newCompileSession() {
|
||||
CompileSession answer = new CompileSession(environment, messageRenderer, errorStream, verbose);
|
||||
CompileSession answer = new CompileSession(environment, messageRenderer, errorStream, verbose, mode);
|
||||
environment.setSession(answer);
|
||||
return answer;
|
||||
}
|
||||
|
||||
@@ -43,6 +43,7 @@ import org.jetbrains.jet.lang.psi.JetFile;
|
||||
import org.jetbrains.jet.lang.resolve.BindingContext;
|
||||
import org.jetbrains.jet.lang.resolve.java.AnalyzeExhaust;
|
||||
import org.jetbrains.jet.lang.resolve.java.AnalyzerFacadeForJVM;
|
||||
import org.jetbrains.jet.lang.resolve.java.CompilerSpecialMode;
|
||||
import org.jetbrains.jet.lang.resolve.java.JavaDescriptorResolver;
|
||||
import org.jetbrains.jet.plugin.JetFileType;
|
||||
import org.jetbrains.jet.utils.Progress;
|
||||
@@ -67,13 +68,15 @@ public class CompileSession {
|
||||
private final MessageRenderer messageRenderer;
|
||||
private final PrintStream errorStream;
|
||||
private final boolean isVerbose;
|
||||
private final CompilerSpecialMode compilerSpecialMode;
|
||||
private AnalyzeExhaust bindingContext;
|
||||
|
||||
public CompileSession(JetCoreEnvironment environment, MessageRenderer messageRenderer, PrintStream errorStream, boolean verbose) {
|
||||
public CompileSession(JetCoreEnvironment environment, MessageRenderer messageRenderer, PrintStream errorStream, boolean verbose, CompilerSpecialMode mode) {
|
||||
this.environment = environment;
|
||||
this.messageRenderer = messageRenderer;
|
||||
this.errorStream = errorStream;
|
||||
isVerbose = verbose;
|
||||
this.compilerSpecialMode = mode;
|
||||
messageCollector = new MessageCollector(this.messageRenderer);
|
||||
}
|
||||
|
||||
@@ -173,7 +176,7 @@ public class CompileSession {
|
||||
Predicate<PsiFile> filesToAnalyzeCompletely =
|
||||
stubs ? Predicates.<PsiFile>alwaysFalse() : Predicates.<PsiFile>alwaysTrue();
|
||||
bindingContext = AnalyzerFacadeForJVM.analyzeFilesWithJavaIntegration(
|
||||
environment.getProject(), sourceFiles, filesToAnalyzeCompletely, JetControlFlowDataTraceFactory.EMPTY);
|
||||
environment.getProject(), sourceFiles, filesToAnalyzeCompletely, JetControlFlowDataTraceFactory.EMPTY, compilerSpecialMode);
|
||||
|
||||
for (Diagnostic diagnostic : bindingContext.getBindingContext().getDiagnostics()) {
|
||||
reportDiagnostic(messageCollector, diagnostic);
|
||||
|
||||
@@ -43,7 +43,7 @@ public class JetCoreEnvironment extends JavaCoreEnvironment {
|
||||
private List<CompilerPlugin> compilerPlugins = new ArrayList<CompilerPlugin>();
|
||||
private CompileSession session;
|
||||
|
||||
public JetCoreEnvironment(Disposable parentDisposable) {
|
||||
public JetCoreEnvironment(Disposable parentDisposable, boolean includeJdkHeaders) {
|
||||
super(parentDisposable);
|
||||
registerFileType(JetFileType.INSTANCE, "kt");
|
||||
registerFileType(JetFileType.INSTANCE, "kts");
|
||||
@@ -58,8 +58,10 @@ public class JetCoreEnvironment extends JavaCoreEnvironment {
|
||||
.getExtensionPoint(PsiElementFinder.EP_NAME)
|
||||
.registerExtension(new JavaElementFinder(myProject));
|
||||
|
||||
for (VirtualFile root : PathUtil.getAltHeadersRoots()) {
|
||||
addLibraryRoot(root);
|
||||
if (includeJdkHeaders) {
|
||||
for (VirtualFile root : PathUtil.getAltHeadersRoots()) {
|
||||
addLibraryRoot(root);
|
||||
}
|
||||
}
|
||||
|
||||
JetStandardLibrary.initialize(getProject());
|
||||
|
||||
@@ -23,6 +23,7 @@ import org.jetbrains.jet.lang.resolve.BindingTrace;
|
||||
import org.jetbrains.jet.lang.resolve.java.JavaBridgeConfiguration;
|
||||
import org.jetbrains.jet.lang.resolve.java.PsiClassFinderForJvm;
|
||||
import org.jetbrains.jet.lang.descriptors.ModuleDescriptor;
|
||||
import org.jetbrains.jet.lang.resolve.java.CompilerSpecialMode;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import org.jetbrains.jet.lang.resolve.java.JavaTypeTransformer;
|
||||
import org.jetbrains.jet.lang.resolve.NamespaceFactoryImpl;
|
||||
@@ -47,6 +48,7 @@ public class InjectorForJavaSemanticServices {
|
||||
JavaBridgeConfiguration javaBridgeConfiguration = new JavaBridgeConfiguration();
|
||||
this.psiClassFinderForJvm = new PsiClassFinderForJvm();
|
||||
ModuleDescriptor moduleDescriptor = new org.jetbrains.jet.lang.descriptors.ModuleDescriptor("<dummy>");
|
||||
CompilerSpecialMode compilerSpecialMode = CompilerSpecialMode.REGULAR;
|
||||
this.project = project;
|
||||
JavaTypeTransformer javaTypeTransformer = new JavaTypeTransformer();
|
||||
NamespaceFactoryImpl namespaceFactoryImpl = new NamespaceFactoryImpl();
|
||||
@@ -63,6 +65,7 @@ public class InjectorForJavaSemanticServices {
|
||||
this.javaDescriptorResolver.setTrace(bindingTrace);
|
||||
|
||||
javaBridgeConfiguration.setJavaSemanticServices(javaSemanticServices);
|
||||
javaBridgeConfiguration.setMode(compilerSpecialMode);
|
||||
javaBridgeConfiguration.setProject(project);
|
||||
|
||||
this.psiClassFinderForJvm.setProject(project);
|
||||
@@ -74,6 +77,8 @@ public class InjectorForJavaSemanticServices {
|
||||
namespaceFactoryImpl.setModuleDescriptor(moduleDescriptor);
|
||||
namespaceFactoryImpl.setTrace(bindingTrace);
|
||||
|
||||
javaBridgeConfiguration.init();
|
||||
|
||||
psiClassFinderForJvm.initialize();
|
||||
|
||||
}
|
||||
|
||||
+7
-1
@@ -28,6 +28,7 @@ import org.jetbrains.jet.lang.resolve.TopDownAnalysisParameters;
|
||||
import org.jetbrains.jet.lang.resolve.ObservableBindingTrace;
|
||||
import org.jetbrains.jet.lang.descriptors.ModuleDescriptor;
|
||||
import org.jetbrains.jet.lang.cfg.pseudocode.JetControlFlowDataTraceFactory;
|
||||
import org.jetbrains.jet.lang.resolve.java.CompilerSpecialMode;
|
||||
import org.jetbrains.jet.lang.resolve.java.JavaBridgeConfiguration;
|
||||
import org.jetbrains.jet.lang.resolve.java.PsiClassFinderForJvm;
|
||||
import org.jetbrains.jet.lang.resolve.DeclarationResolver;
|
||||
@@ -51,6 +52,7 @@ import org.jetbrains.jet.lang.resolve.TopDownAnalysisParameters;
|
||||
import org.jetbrains.jet.lang.resolve.ObservableBindingTrace;
|
||||
import org.jetbrains.jet.lang.descriptors.ModuleDescriptor;
|
||||
import org.jetbrains.jet.lang.cfg.pseudocode.JetControlFlowDataTraceFactory;
|
||||
import org.jetbrains.jet.lang.resolve.java.CompilerSpecialMode;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/* This file is generated by org.jetbrains.jet.di.AllInjectorsGenerator. DO NOT EDIT! */
|
||||
@@ -72,7 +74,8 @@ public class InjectorForTopDownAnalyzerForJvm {
|
||||
@NotNull TopDownAnalysisParameters topDownAnalysisParameters,
|
||||
@NotNull ObservableBindingTrace observableBindingTrace,
|
||||
@NotNull ModuleDescriptor moduleDescriptor,
|
||||
JetControlFlowDataTraceFactory jetControlFlowDataTraceFactory
|
||||
JetControlFlowDataTraceFactory jetControlFlowDataTraceFactory,
|
||||
@NotNull CompilerSpecialMode compilerSpecialMode
|
||||
) {
|
||||
this.topDownAnalyzer = new TopDownAnalyzer();
|
||||
this.topDownAnalysisContext = new TopDownAnalysisContext();
|
||||
@@ -138,6 +141,7 @@ public class InjectorForTopDownAnalyzerForJvm {
|
||||
this.descriptorResolver.setTypeResolver(typeResolver);
|
||||
|
||||
this.javaBridgeConfiguration.setJavaSemanticServices(javaSemanticServices);
|
||||
this.javaBridgeConfiguration.setMode(compilerSpecialMode);
|
||||
this.javaBridgeConfiguration.setProject(project);
|
||||
|
||||
psiClassFinderForJvm.setProject(project);
|
||||
@@ -204,6 +208,8 @@ public class InjectorForTopDownAnalyzerForJvm {
|
||||
javaTypeTransformer.setJavaSemanticServices(javaSemanticServices);
|
||||
javaTypeTransformer.setResolver(javaDescriptorResolver);
|
||||
|
||||
javaBridgeConfiguration.init();
|
||||
|
||||
psiClassFinderForJvm.initialize();
|
||||
|
||||
}
|
||||
|
||||
+12
-6
@@ -84,7 +84,8 @@ public class AnalyzerFacadeForJVM {
|
||||
file.getProject(),
|
||||
declarationProvider.fun(file),
|
||||
Predicates.<PsiFile>equalTo(file),
|
||||
JetControlFlowDataTraceFactory.EMPTY);
|
||||
JetControlFlowDataTraceFactory.EMPTY,
|
||||
CompilerSpecialMode.REGULAR);
|
||||
return new Result<AnalyzeExhaust>(bindingContext, PsiModificationTracker.MODIFICATION_COUNT);
|
||||
}
|
||||
catch (ProcessCanceledException e) {
|
||||
@@ -123,7 +124,8 @@ public class AnalyzerFacadeForJVM {
|
||||
project,
|
||||
files,
|
||||
Predicates.<PsiFile>alwaysFalse(),
|
||||
JetControlFlowDataTraceFactory.EMPTY);
|
||||
JetControlFlowDataTraceFactory.EMPTY,
|
||||
CompilerSpecialMode.REGULAR);
|
||||
return new Result<AnalyzeExhaust>(analyzeExhaust, PsiModificationTracker.MODIFICATION_COUNT);
|
||||
}
|
||||
catch (ProcessCanceledException e) {
|
||||
@@ -156,12 +158,14 @@ public class AnalyzerFacadeForJVM {
|
||||
}
|
||||
|
||||
public static AnalyzeExhaust analyzeOneFileWithJavaIntegration(JetFile file, JetControlFlowDataTraceFactory flowDataTraceFactory) {
|
||||
return analyzeFilesWithJavaIntegration(file.getProject(), Collections.singleton(file), Predicates.<PsiFile>alwaysTrue(), flowDataTraceFactory);
|
||||
return analyzeFilesWithJavaIntegration(file.getProject(), Collections.singleton(file),
|
||||
Predicates.<PsiFile>alwaysTrue(), flowDataTraceFactory, CompilerSpecialMode.REGULAR);
|
||||
}
|
||||
|
||||
public static AnalyzeExhaust analyzeFilesWithJavaIntegration(
|
||||
Project project, Collection<JetFile> files, Predicate<PsiFile> filesToAnalyzeCompletely,
|
||||
JetControlFlowDataTraceFactory flowDataTraceFactory) {
|
||||
JetControlFlowDataTraceFactory flowDataTraceFactory,
|
||||
CompilerSpecialMode compilerSpecialMode) {
|
||||
BindingTraceContext bindingTraceContext = new BindingTraceContext();
|
||||
|
||||
final ModuleDescriptor owner = new ModuleDescriptor("<module>");
|
||||
@@ -172,7 +176,8 @@ public class AnalyzerFacadeForJVM {
|
||||
|
||||
InjectorForTopDownAnalyzerForJvm injector = new InjectorForTopDownAnalyzerForJvm(
|
||||
project, topDownAnalysisParameters,
|
||||
new ObservableBindingTrace(bindingTraceContext), owner, flowDataTraceFactory);
|
||||
new ObservableBindingTrace(bindingTraceContext), owner, flowDataTraceFactory,
|
||||
compilerSpecialMode);
|
||||
|
||||
|
||||
injector.getTopDownAnalyzer().analyzeFiles(files);
|
||||
@@ -184,6 +189,7 @@ public class AnalyzerFacadeForJVM {
|
||||
|
||||
Project project = files.iterator().next().getProject();
|
||||
|
||||
return analyzeFilesWithJavaIntegration(project, files, Predicates.<PsiFile>alwaysFalse(), JetControlFlowDataTraceFactory.EMPTY);
|
||||
return analyzeFilesWithJavaIntegration(project, files, Predicates.<PsiFile>alwaysFalse(),
|
||||
JetControlFlowDataTraceFactory.EMPTY, CompilerSpecialMode.REGULAR);
|
||||
}
|
||||
}
|
||||
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
/*
|
||||
* 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.lang.resolve.java;
|
||||
|
||||
/**
|
||||
* @author Stepan Koltsov
|
||||
*/
|
||||
public enum CompilerSpecialMode {
|
||||
REGULAR,
|
||||
BUILTINS,
|
||||
JDK_HEADERS,
|
||||
}
|
||||
+13
-1
@@ -30,6 +30,7 @@ import org.jetbrains.jet.lang.resolve.FqName;
|
||||
import org.jetbrains.jet.lang.resolve.ImportPath;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.WritableScope;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import javax.inject.Inject;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
@@ -48,11 +49,12 @@ public class JavaBridgeConfiguration implements ModuleConfiguration {
|
||||
private JavaSemanticServices javaSemanticServices;
|
||||
@NotNull
|
||||
private ModuleConfiguration delegateConfiguration;
|
||||
@NotNull
|
||||
private CompilerSpecialMode mode;
|
||||
|
||||
@Inject
|
||||
public void setProject(@NotNull Project project) {
|
||||
this.project = project;
|
||||
this.delegateConfiguration = DefaultModuleConfiguration.createStandardConfiguration(project);
|
||||
}
|
||||
|
||||
@Inject
|
||||
@@ -60,6 +62,16 @@ public class JavaBridgeConfiguration implements ModuleConfiguration {
|
||||
this.javaSemanticServices = javaSemanticServices;
|
||||
}
|
||||
|
||||
@Inject
|
||||
public void setMode(@NotNull CompilerSpecialMode mode) {
|
||||
this.mode = mode;
|
||||
}
|
||||
|
||||
@PostConstruct
|
||||
public void init() {
|
||||
this.delegateConfiguration = DefaultModuleConfiguration.createStandardConfiguration(project, mode == CompilerSpecialMode.BUILTINS);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
|
||||
@@ -38,14 +38,16 @@ public class DefaultModuleConfiguration implements ModuleConfiguration {
|
||||
public static final ImportPath[] DEFAULT_JET_IMPORTS = new ImportPath[] {
|
||||
new ImportPath("kotlin.*"), new ImportPath("kotlin.io.*"), new ImportPath("jet.*"), };
|
||||
|
||||
private Project project;
|
||||
private final Project project;
|
||||
private final boolean extendBuiltins;
|
||||
|
||||
public static DefaultModuleConfiguration createStandardConfiguration(Project project) {
|
||||
return new DefaultModuleConfiguration(project);
|
||||
public static DefaultModuleConfiguration createStandardConfiguration(Project project, boolean extendBuiltins) {
|
||||
return new DefaultModuleConfiguration(project, extendBuiltins);
|
||||
}
|
||||
|
||||
private DefaultModuleConfiguration(Project project) {
|
||||
private DefaultModuleConfiguration(@NotNull Project project, boolean extendBuiltins) {
|
||||
this.project = project;
|
||||
this.extendBuiltins = extendBuiltins;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -58,7 +60,12 @@ public class DefaultModuleConfiguration implements ModuleConfiguration {
|
||||
@Override
|
||||
public void extendNamespaceScope(@NotNull BindingTrace trace, @NotNull NamespaceDescriptor namespaceDescriptor, @NotNull WritableScope namespaceMemberScope) {
|
||||
if (DescriptorUtils.getFQName(namespaceDescriptor).equals(JetStandardClasses.STANDARD_CLASSES_FQNAME.toUnsafe())) {
|
||||
namespaceMemberScope.importScope(JetStandardLibrary.getInstance().getLibraryScope());
|
||||
if (!extendBuiltins) {
|
||||
namespaceMemberScope.importScope(JetStandardClasses.STANDARD_CLASSES);
|
||||
} else {
|
||||
namespaceMemberScope.importScope(JetStandardLibrary.getInstance().getLibraryScope());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -235,7 +235,7 @@ public class JetStandardClasses {
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
@NotNull
|
||||
/*package*/ static final JetScope STANDARD_CLASSES;
|
||||
public static final JetScope STANDARD_CLASSES;
|
||||
|
||||
static {
|
||||
WritableScope writableScope = new WritableScopeImpl(JetScope.EMPTY, STANDARD_CLASSES_NAMESPACE, RedeclarationHandler.DO_NOTHING).setDebugName("JetStandardClasses.STANDARD_CLASSES");
|
||||
|
||||
@@ -27,7 +27,7 @@ public class CompileBuiltinsTest extends TestCaseWithTmpdirIndependentFromIdea {
|
||||
@Test
|
||||
public void compile() {
|
||||
KotlinCompiler.ExitCode exitCode = new KotlinCompiler().exec(
|
||||
System.err, "-output", tmpdir.getPath(), "-src", "./compiler/frontend/src", "-stubs");
|
||||
System.err, "-output", tmpdir.getPath(), "-src", "./compiler/frontend/src", "-mode", "builtins");
|
||||
if (exitCode != KotlinCompiler.ExitCode.OK) {
|
||||
throw new IllegalStateException("jdk headers compilation failed: " + exitCode);
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@ public class CompileJdkHeadersTest extends TestCaseWithTmpdirIndependentFromIdea
|
||||
@Test
|
||||
public void compile() {
|
||||
KotlinCompiler.ExitCode exitCode = new KotlinCompiler().exec(
|
||||
System.err, "-output", tmpdir.getPath(), "-src", "./jdk-headers/src", "-stubs");
|
||||
System.err, "-output", tmpdir.getPath(), "-src", "./jdk-headers/src", "-mode", "jdkHeaders");
|
||||
if (exitCode != KotlinCompiler.ExitCode.OK) {
|
||||
throw new IllegalStateException("jdk headers compilation failed: " + exitCode);
|
||||
}
|
||||
|
||||
@@ -74,7 +74,7 @@ public abstract class JetLiteFixture extends UsefulTestCase {
|
||||
}
|
||||
|
||||
protected void createEnvironmentWithFullJdk() {
|
||||
myEnvironment = new JetCoreEnvironment(getTestRootDisposable());
|
||||
myEnvironment = new JetCoreEnvironment(getTestRootDisposable(), true);
|
||||
final File rtJar = CompileEnvironment.findRtJar();
|
||||
myEnvironment.addToClasspath(rtJar);
|
||||
}
|
||||
|
||||
@@ -162,7 +162,7 @@ public class JetTestUtils {
|
||||
|
||||
|
||||
public static JetCoreEnvironment createEnvironmentWithMockJdk(Disposable disposable) {
|
||||
JetCoreEnvironment environment = new JetCoreEnvironment(disposable);
|
||||
JetCoreEnvironment environment = new JetCoreEnvironment(disposable, true);
|
||||
final File rtJar = new File(JetTestCaseBuilder.getHomeDirectory(), "compiler/testData/mockJDK-1.7/jre/lib/rt.jar");
|
||||
environment.addToClasspath(rtJar);
|
||||
environment.addToClasspath(getAnnotationsJar());
|
||||
|
||||
@@ -37,6 +37,7 @@ import org.jetbrains.jet.lang.psi.JetFile;
|
||||
import org.jetbrains.jet.lang.resolve.AnalyzingUtils;
|
||||
import org.jetbrains.jet.lang.resolve.BindingContext;
|
||||
import org.jetbrains.jet.lang.resolve.java.AnalyzerFacadeForJVM;
|
||||
import org.jetbrains.jet.lang.resolve.java.CompilerSpecialMode;
|
||||
|
||||
import java.io.File;
|
||||
import java.nio.charset.Charset;
|
||||
@@ -166,7 +167,7 @@ public class JetDiagnosticsTest extends JetLiteFixture {
|
||||
}
|
||||
|
||||
BindingContext bindingContext = AnalyzerFacadeForJVM.analyzeFilesWithJavaIntegration(
|
||||
getProject(), jetFiles, Predicates.<PsiFile>alwaysTrue(), JetControlFlowDataTraceFactory.EMPTY)
|
||||
getProject(), jetFiles, Predicates.<PsiFile>alwaysTrue(), JetControlFlowDataTraceFactory.EMPTY, CompilerSpecialMode.REGULAR)
|
||||
.getBindingContext();
|
||||
|
||||
boolean ok = true;
|
||||
|
||||
@@ -28,6 +28,7 @@ import org.jetbrains.jet.lang.psi.JetClass;
|
||||
import org.jetbrains.jet.lang.psi.JetDeclaration;
|
||||
import org.jetbrains.jet.lang.psi.JetFile;
|
||||
import org.jetbrains.jet.lang.resolve.BindingContext;
|
||||
import org.jetbrains.jet.lang.resolve.java.CompilerSpecialMode;
|
||||
import org.jetbrains.jet.lang.types.JetType;
|
||||
import org.jetbrains.jet.parsing.JetParsingTest;
|
||||
|
||||
@@ -69,7 +70,7 @@ public class TestlibTest extends CodegenTestCase {
|
||||
|
||||
private TestSuite doBuildSuite() {
|
||||
try {
|
||||
CompileSession session = new CompileSession(myEnvironment, MessageRenderer.PLAIN, System.err, false);
|
||||
CompileSession session = new CompileSession(myEnvironment, MessageRenderer.PLAIN, System.err, false, CompilerSpecialMode.REGULAR);
|
||||
|
||||
myEnvironment.addToClasspath(ForTestCompileStdlib.stdlibJarForTests());
|
||||
|
||||
|
||||
@@ -33,6 +33,7 @@ import org.jetbrains.jet.lang.resolve.BindingContext;
|
||||
import org.jetbrains.jet.lang.resolve.BindingContextUtils;
|
||||
import org.jetbrains.jet.lang.resolve.java.AnalyzeExhaust;
|
||||
import org.jetbrains.jet.lang.resolve.java.AnalyzerFacadeForJVM;
|
||||
import org.jetbrains.jet.lang.resolve.java.CompilerSpecialMode;
|
||||
import org.jetbrains.jet.lang.types.ErrorUtils;
|
||||
import org.jetbrains.jet.lang.types.lang.JetStandardLibrary;
|
||||
import org.jetbrains.jet.lang.types.JetType;
|
||||
@@ -137,7 +138,8 @@ public abstract class ExpectedResolveData {
|
||||
Project project = files.iterator().next().getProject();
|
||||
JetStandardLibrary lib = JetStandardLibrary.getInstance();
|
||||
|
||||
AnalyzeExhaust analyzeExhaust = AnalyzerFacadeForJVM.analyzeFilesWithJavaIntegration(project, files, Predicates.<PsiFile>alwaysTrue(), JetControlFlowDataTraceFactory.EMPTY);
|
||||
AnalyzeExhaust analyzeExhaust = AnalyzerFacadeForJVM.analyzeFilesWithJavaIntegration(project, files,
|
||||
Predicates.<PsiFile>alwaysTrue(), JetControlFlowDataTraceFactory.EMPTY, CompilerSpecialMode.REGULAR);
|
||||
BindingContext bindingContext = analyzeExhaust.getBindingContext();
|
||||
for (Diagnostic diagnostic : bindingContext.getDiagnostics()) {
|
||||
if (diagnostic instanceof UnresolvedReferenceDiagnostic) {
|
||||
|
||||
@@ -28,10 +28,7 @@ import org.jetbrains.jet.lang.descriptors.ModuleDescriptor;
|
||||
import org.jetbrains.jet.lang.psi.JetFile;
|
||||
import org.jetbrains.jet.lang.resolve.*;
|
||||
import org.jetbrains.jet.lang.resolve.calls.CallResolver;
|
||||
import org.jetbrains.jet.lang.resolve.java.JavaBridgeConfiguration;
|
||||
import org.jetbrains.jet.lang.resolve.java.JavaDescriptorResolver;
|
||||
import org.jetbrains.jet.lang.resolve.java.JavaSemanticServices;
|
||||
import org.jetbrains.jet.lang.resolve.java.PsiClassFinderForJvm;
|
||||
import org.jetbrains.jet.lang.resolve.java.*;
|
||||
import org.jetbrains.jet.lang.types.expressions.ExpressionTypingServices;
|
||||
import org.jetbrains.jet.lang.types.lang.JetStandardLibrary;
|
||||
|
||||
@@ -72,6 +69,7 @@ public class AllInjectorsGenerator {
|
||||
private static void generateInjectorForTopDownAnalyzerForJvm() throws IOException {
|
||||
DependencyInjectorGenerator generator = new DependencyInjectorGenerator(false);
|
||||
generateInjectorForTopDownAnalyzerCommon(generator);
|
||||
generator.addParameter(CompilerSpecialMode.class);
|
||||
generator.addPublicField(JavaBridgeConfiguration.class);
|
||||
generator.addField(PsiClassFinderForJvm.class);
|
||||
generator.generate("compiler/frontend.java/src", "org.jetbrains.jet.di", "InjectorForTopDownAnalyzerForJvm");
|
||||
@@ -134,7 +132,9 @@ public class AllInjectorsGenerator {
|
||||
generator.addPublicField(PsiClassFinderForJvm.class);
|
||||
generator.addField(false, ModuleDescriptor.class, null,
|
||||
new GivenExpression("new org.jetbrains.jet.lang.descriptors.ModuleDescriptor(\"<dummy>\")"));
|
||||
|
||||
generator.addField(false, CompilerSpecialMode.class, null,
|
||||
new GivenExpression("CompilerSpecialMode.REGULAR"));
|
||||
|
||||
// Parameters
|
||||
generator.addPublicParameter(Project.class);
|
||||
|
||||
|
||||
@@ -142,7 +142,7 @@ public final class AnalyzerFacadeForJS {
|
||||
@Override
|
||||
public void extendNamespaceScope(@NotNull BindingTrace trace, @NotNull NamespaceDescriptor namespaceDescriptor,
|
||||
@NotNull WritableScope namespaceMemberScope) {
|
||||
DefaultModuleConfiguration.createStandardConfiguration(project).extendNamespaceScope(trace, namespaceDescriptor, namespaceMemberScope);
|
||||
DefaultModuleConfiguration.createStandardConfiguration(project, true).extendNamespaceScope(trace, namespaceDescriptor, namespaceMemberScope);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user