diff --git a/.idea/compiler.xml b/.idea/compiler.xml
index 3b66d4ce869..8c89653e336 100644
--- a/.idea/compiler.xml
+++ b/.idea/compiler.xml
@@ -17,6 +17,7 @@
+
diff --git a/.idea/modules.xml b/.idea/modules.xml
index 94213936f8b..a7a32bf50d1 100644
--- a/.idea/modules.xml
+++ b/.idea/modules.xml
@@ -6,6 +6,7 @@
+
diff --git a/TeamCityBuild.xml b/TeamCityBuild.xml
index f9ab064f01b..a37cd929ec5 100644
--- a/TeamCityBuild.xml
+++ b/TeamCityBuild.xml
@@ -10,7 +10,7 @@
-
+
diff --git a/bin/kotlin b/bin/kotlin
index e456ffbe73d..5cca3809cde 100755
--- a/bin/kotlin
+++ b/bin/kotlin
@@ -24,7 +24,7 @@ classpath="$classpath:$root/lib/*:$ideaRoot/lib/*:$ideaRoot/lib/rt/*"
exec java $JAVA_OPTS \
-classpath "$classpath" \
- org.jetbrains.jet.cli.KotlinCompiler \
+ org.jetbrains.jet.cli.jvm.K2JVMCompiler \
"$@"
# vim: set ts=4 sw=4 et:
diff --git a/build-tools/ant/src/org/jetbrains/jet/buildtools/ant/BytecodeCompilerTask.java b/build-tools/ant/src/org/jetbrains/jet/buildtools/ant/BytecodeCompilerTask.java
index 95c745b429c..7d0099cf964 100644
--- a/build-tools/ant/src/org/jetbrains/jet/buildtools/ant/BytecodeCompilerTask.java
+++ b/build-tools/ant/src/org/jetbrains/jet/buildtools/ant/BytecodeCompilerTask.java
@@ -21,7 +21,7 @@ import org.apache.tools.ant.Task;
import org.apache.tools.ant.types.Path;
import org.apache.tools.ant.types.Reference;
import org.jetbrains.jet.buildtools.core.BytecodeCompiler;
-import org.jetbrains.jet.compiler.CompileEnvironmentException;
+import org.jetbrains.jet.cli.jvm.compiler.CompileEnvironmentException;
import java.io.File;
diff --git a/build-tools/build-tools.iml b/build-tools/build-tools.iml
index d184270053f..d0304c4b431 100644
--- a/build-tools/build-tools.iml
+++ b/build-tools/build-tools.iml
@@ -10,6 +10,7 @@
+
diff --git a/build-tools/core/src/org/jetbrains/jet/buildtools/core/BytecodeCompiler.java b/build-tools/core/src/org/jetbrains/jet/buildtools/core/BytecodeCompiler.java
index 8617f13f719..d03683a331b 100644
--- a/build-tools/core/src/org/jetbrains/jet/buildtools/core/BytecodeCompiler.java
+++ b/build-tools/core/src/org/jetbrains/jet/buildtools/core/BytecodeCompiler.java
@@ -16,10 +16,12 @@
package org.jetbrains.jet.buildtools.core;
+import jet.modules.Module;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
-import org.jetbrains.jet.compiler.*;
-import org.jetbrains.jet.compiler.messages.MessageCollector;
+import org.jetbrains.jet.cli.common.CompilerPlugin;
+import org.jetbrains.jet.cli.jvm.compiler.*;
+import org.jetbrains.jet.cli.common.messages.MessageCollector;
import org.jetbrains.jet.lang.resolve.java.CompilerDependencies;
import org.jetbrains.jet.lang.resolve.java.CompilerSpecialMode;
@@ -40,7 +42,7 @@ public class BytecodeCompiler {
/**
- * Creates new instance of {@link org.jetbrains.jet.compiler.CompileEnvironmentConfiguration} instance using the arguments specified.
+ * Creates new instance of {@link org.jetbrains.jet.cli.jvm.compiler.CompileEnvironmentConfiguration} instance using the arguments specified.
*
* @param stdlib path to "kotlin-runtime.jar", only used if not null and not empty
* @param classpath compilation classpath, only used if not null and not empty
@@ -128,7 +130,7 @@ public class BytecodeCompiler {
/**
- * {@code CompileEnvironment#compileModuleScript} wrapper.
+ * {@code CompileEnvironment#compileModules} wrapper.
*
* @param module compilation module file
* @param jar compilation destination jar
@@ -139,7 +141,9 @@ public class BytecodeCompiler {
public void moduleToJar ( @NotNull String module, @NotNull String jar, boolean includeRuntime, @Nullable String stdlib, @Nullable String[] classpath ) {
try {
CompileEnvironmentConfiguration env = env(stdlib, classpath);
- boolean success = KotlinToJVMBytecodeCompiler.compileModuleScript(env, module, jar, null, includeRuntime);
+ List modules = CompileEnvironmentUtil.loadModuleScript(module, env.getMessageCollector());
+ File directory = new File(module).getParentFile();
+ boolean success = KotlinToJVMBytecodeCompiler.compileModules(env, modules, directory, jar, null, includeRuntime);
if ( ! success ) {
throw new CompileEnvironmentException( errorMessage( module, false ));
}
diff --git a/build.xml b/build.xml
index f5260c35565..cdee4e237a9 100644
--- a/build.xml
+++ b/build.xml
@@ -54,7 +54,7 @@
-
+
@@ -72,7 +72,7 @@
-
+
@@ -88,7 +88,7 @@
-
+
@@ -210,7 +210,7 @@
-
+
diff --git a/compiler/backend/src/org/jetbrains/jet/compiler/TipsManager.java b/compiler/backend/src/org/jetbrains/jet/cli/jvm/compiler/TipsManager.java
similarity index 99%
rename from compiler/backend/src/org/jetbrains/jet/compiler/TipsManager.java
rename to compiler/backend/src/org/jetbrains/jet/cli/jvm/compiler/TipsManager.java
index 8b6cb8c4a16..3e7972e5e28 100644
--- a/compiler/backend/src/org/jetbrains/jet/compiler/TipsManager.java
+++ b/compiler/backend/src/org/jetbrains/jet/cli/jvm/compiler/TipsManager.java
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-package org.jetbrains.jet.compiler;
+package org.jetbrains.jet.cli.jvm.compiler;
import com.google.common.base.Predicate;
import com.google.common.collect.Collections2;
diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/ClassBodyCodegen.java b/compiler/backend/src/org/jetbrains/jet/codegen/ClassBodyCodegen.java
index ea431b29b9b..82415fce97e 100644
--- a/compiler/backend/src/org/jetbrains/jet/codegen/ClassBodyCodegen.java
+++ b/compiler/backend/src/org/jetbrains/jet/codegen/ClassBodyCodegen.java
@@ -90,9 +90,10 @@ public abstract class ClassBodyCodegen {
try {
genNamedFunction((JetNamedFunction) declaration, functionCodegen);
}
- catch(CompilationException e) {
+ catch (CompilationException e) {
throw e;
- } catch (RuntimeException e) {
+ }
+ catch (RuntimeException e) {
throw new RuntimeException("Error generating method " + myClass.getName() + "." + declaration.getName() + " in " + context, e);
}
}
diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/CompilationErrorHandler.java b/compiler/backend/src/org/jetbrains/jet/codegen/CompilationErrorHandler.java
index ccd782a7c12..a3b2acf3846 100644
--- a/compiler/backend/src/org/jetbrains/jet/codegen/CompilationErrorHandler.java
+++ b/compiler/backend/src/org/jetbrains/jet/codegen/CompilationErrorHandler.java
@@ -24,6 +24,9 @@ public interface CompilationErrorHandler {
CompilationErrorHandler THROW_EXCEPTION = new CompilationErrorHandler() {
@Override
public void reportException(Throwable exception, String fileUrl) {
+ if (exception instanceof RuntimeException) {
+ throw (RuntimeException)exception;
+ }
throw new IllegalStateException(exception);
}
};
diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/CompilationException.java b/compiler/backend/src/org/jetbrains/jet/codegen/CompilationException.java
index 017b499e327..f60a56148b9 100644
--- a/compiler/backend/src/org/jetbrains/jet/codegen/CompilationException.java
+++ b/compiler/backend/src/org/jetbrains/jet/codegen/CompilationException.java
@@ -16,50 +16,29 @@
package org.jetbrains.jet.codegen;
-import com.intellij.openapi.editor.Document;
-import com.intellij.openapi.util.TextRange;
import com.intellij.psi.PsiElement;
-import com.intellij.psi.PsiFile;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+import org.jetbrains.jet.lang.diagnostics.DiagnosticUtils;
/**
* @author alex.tkachman
+* @author abreslav
*/
public class CompilationException extends RuntimeException {
- private PsiElement element;
+ private final PsiElement element;
- CompilationException(String message, Throwable cause, PsiElement element) {
+ CompilationException(@NotNull String message, @Nullable Throwable cause, @NotNull PsiElement element) {
super(message, cause);
this.element = element;
}
+ @NotNull
public PsiElement getElement() {
return element;
}
- @Override
- public String toString() {
- PsiFile psiFile = element.getContainingFile();
- TextRange textRange = element.getTextRange();
- Document document = psiFile.getViewProvider().getDocument();
- int line;
- int col;
- if (document != null) {
- line = document.getLineNumber(textRange.getStartOffset());
- col = textRange.getStartOffset() - document.getLineStartOffset(line) + 1;
- }
- else {
- line = -1;
- col = -1;
- }
- String s2 = "";
- Throwable cause = getCause();
- if (cause != null) {
- s2 = cause.getMessage() != null ? cause.getMessage() : cause.toString();
- }
- return "Internal error: (" + (line+1) + "," + col + ") " + s2 + "\n@" + where();
- }
-
private String where() {
Throwable cause = getCause();
Throwable throwable = cause != null ? cause : this;
@@ -67,13 +46,20 @@ public class CompilationException extends RuntimeException {
if (stackTrace != null && stackTrace.length > 0) {
return stackTrace[0].getFileName() + ":" + stackTrace[0].getLineNumber();
}
- else {
- return "unknown";
- }
+ return "unknown";
}
@Override
public String getMessage() {
- return this.toString();
+ StringBuilder message = new StringBuilder("Back-end (JVM) Internal error: ").append(super.getMessage()).append("\n");
+ Throwable cause = getCause();
+ if (cause != null) {
+ String causeMessage = cause.getMessage();
+ message.append("Cause: ").append(causeMessage == null ? cause.toString() : causeMessage).append("\n");
+ }
+ message.append("File being compiled and position: ").append(DiagnosticUtils.atLocation(element)).append("\n");
+ message.append("The root cause was thrown at: ").append(where());
+
+ return message.toString();
}
}
diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/GenerationState.java b/compiler/backend/src/org/jetbrains/jet/codegen/GenerationState.java
index 33bb005af93..b536dae92bf 100644
--- a/compiler/backend/src/org/jetbrains/jet/codegen/GenerationState.java
+++ b/compiler/backend/src/org/jetbrains/jet/codegen/GenerationState.java
@@ -170,4 +170,8 @@ public class GenerationState {
return answer.toString();
}
+
+ public void destroy() {
+ injector.destroy();
+ }
}
diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/NamespaceCodegen.java b/compiler/backend/src/org/jetbrains/jet/codegen/NamespaceCodegen.java
index 2a3338c7510..6478143b709 100644
--- a/compiler/backend/src/org/jetbrains/jet/codegen/NamespaceCodegen.java
+++ b/compiler/backend/src/org/jetbrains/jet/codegen/NamespaceCodegen.java
@@ -69,7 +69,8 @@ public class NamespaceCodegen {
else if (declaration instanceof JetNamedFunction) {
try {
functionCodegen.gen((JetNamedFunction) declaration);
- } catch (CompilationException e) {
+ }
+ catch (CompilationException e) {
throw e;
}
catch (Exception e) {
diff --git a/compiler/backend/src/org/jetbrains/jet/di/InjectorForJetTypeMapper.java b/compiler/backend/src/org/jetbrains/jet/di/InjectorForJetTypeMapper.java
index 30a4db600be..0d0ec20975d 100644
--- a/compiler/backend/src/org/jetbrains/jet/di/InjectorForJetTypeMapper.java
+++ b/compiler/backend/src/org/jetbrains/jet/di/InjectorForJetTypeMapper.java
@@ -30,21 +30,31 @@ import org.jetbrains.jet.lang.resolve.BindingContext;
import java.util.List;
import org.jetbrains.jet.lang.psi.JetFile;
import org.jetbrains.annotations.NotNull;
+import javax.annotation.PreDestroy;
/* This file is generated by org.jetbrains.jet.di.AllInjectorsGenerator. DO NOT EDIT! */
public class InjectorForJetTypeMapper {
+ private final JetStandardLibrary jetStandardLibrary;
+ private final BindingContext bindingContext;
+ private final List listOfJetFile;
private JetTypeMapper jetTypeMapper;
+ private CompilerSpecialMode compilerSpecialMode;
+ private ClassBuilderMode classBuilderMode;
+ private ClosureAnnotator closureAnnotator;
public InjectorForJetTypeMapper(
@NotNull JetStandardLibrary jetStandardLibrary,
@NotNull BindingContext bindingContext,
@NotNull List listOfJetFile
) {
+ this.jetStandardLibrary = jetStandardLibrary;
+ this.bindingContext = bindingContext;
+ this.listOfJetFile = listOfJetFile;
this.jetTypeMapper = new JetTypeMapper();
- CompilerSpecialMode compilerSpecialMode = CompilerSpecialMode.REGULAR;
- ClassBuilderMode classBuilderMode = ClassBuilderMode.FULL;
- ClosureAnnotator closureAnnotator = new ClosureAnnotator();
+ this.compilerSpecialMode = CompilerSpecialMode.REGULAR;
+ this.classBuilderMode = ClassBuilderMode.FULL;
+ this.closureAnnotator = new ClosureAnnotator();
this.jetTypeMapper.setBindingContext(bindingContext);
this.jetTypeMapper.setClassBuilderMode(classBuilderMode);
@@ -61,6 +71,10 @@ public class InjectorForJetTypeMapper {
}
+ @PreDestroy
+ public void destroy() {
+ }
+
public JetTypeMapper getJetTypeMapper() {
return this.jetTypeMapper;
}
diff --git a/compiler/backend/src/org/jetbrains/jet/di/InjectorForJvmCodegen.java b/compiler/backend/src/org/jetbrains/jet/di/InjectorForJvmCodegen.java
index e54bef57e52..b5987e16532 100644
--- a/compiler/backend/src/org/jetbrains/jet/di/InjectorForJvmCodegen.java
+++ b/compiler/backend/src/org/jetbrains/jet/di/InjectorForJvmCodegen.java
@@ -40,15 +40,23 @@ import org.jetbrains.jet.codegen.ClassBuilderMode;
import org.jetbrains.jet.codegen.GenerationState;
import org.jetbrains.jet.codegen.ClassBuilderFactory;
import org.jetbrains.annotations.NotNull;
+import javax.annotation.PreDestroy;
/* This file is generated by org.jetbrains.jet.di.AllInjectorsGenerator. DO NOT EDIT! */
public class InjectorForJvmCodegen {
private final JetStandardLibrary jetStandardLibrary;
+ private final BindingContext bindingContext;
+ private final List listOfJetFile;
+ private final Project project;
+ private final CompilerSpecialMode compilerSpecialMode;
+ private final ClassBuilderMode classBuilderMode;
private final GenerationState generationState;
+ private final ClassBuilderFactory classBuilderFactory;
private JetTypeMapper jetTypeMapper;
private IntrinsicMethods intrinsics;
private ClassFileFactory classFileFactory;
+ private ClosureAnnotator closureAnnotator;
public InjectorForJvmCodegen(
@NotNull JetStandardLibrary jetStandardLibrary,
@@ -61,11 +69,17 @@ public class InjectorForJvmCodegen {
@NotNull ClassBuilderFactory classBuilderFactory
) {
this.jetStandardLibrary = jetStandardLibrary;
+ this.bindingContext = bindingContext;
+ this.listOfJetFile = listOfJetFile;
+ this.project = project;
+ this.compilerSpecialMode = compilerSpecialMode;
+ this.classBuilderMode = classBuilderMode;
this.generationState = generationState;
+ this.classBuilderFactory = classBuilderFactory;
this.jetTypeMapper = new JetTypeMapper();
this.intrinsics = new IntrinsicMethods();
this.classFileFactory = new ClassFileFactory();
- ClosureAnnotator closureAnnotator = new ClosureAnnotator();
+ this.closureAnnotator = new ClosureAnnotator();
this.jetTypeMapper.setBindingContext(bindingContext);
this.jetTypeMapper.setClassBuilderMode(classBuilderMode);
@@ -90,6 +104,10 @@ public class InjectorForJvmCodegen {
}
+ @PreDestroy
+ public void destroy() {
+ }
+
public JetStandardLibrary getJetStandardLibrary() {
return this.jetStandardLibrary;
}
diff --git a/compiler/cli/bin/kotlinc b/compiler/cli/bin/kotlinc
index 78cde18cb55..22858259c8b 100644
--- a/compiler/cli/bin/kotlinc
+++ b/compiler/cli/bin/kotlinc
@@ -95,4 +95,4 @@ CPSELECT="-cp "
$JAVA_OPTS \
"${java_args[@]}" \
${CPSELECT}${TOOL_CLASSPATH} \
- org.jetbrains.jet.cli.KotlinCompiler "$@"
+ org.jetbrains.jet.cli.jvm.K2JVMCompiler "$@"
diff --git a/compiler/cli/bin/kotlinc.bat b/compiler/cli/bin/kotlinc.bat
index 4fb6990f3b9..803309766f0 100644
--- a/compiler/cli/bin/kotlinc.bat
+++ b/compiler/cli/bin/kotlinc.bat
@@ -27,7 +27,7 @@ if "%_TOOL_CLASSPATH%"=="" (
for /d %%f in ("%_KOTLIN_HOME%\lib\*") do call :add_cpath "%%f"
)
-"%_JAVACMD%" %_JAVA_OPTS% -cp "%_TOOL_CLASSPATH%" org.jetbrains.jet.cli.KotlinCompiler %*
+"%_JAVACMD%" %_JAVA_OPTS% -cp "%_TOOL_CLASSPATH%" org.jetbrains.jet.cli.jvm.K2JVMCompiler %*
goto end
rem ##########################################################################
diff --git a/compiler/cli/src/org/jetbrains/jet/cli/KotlinCompiler.java b/compiler/cli/src/org/jetbrains/jet/cli/KotlinCompiler.java
deleted file mode 100644
index 54a6eef6608..00000000000
--- a/compiler/cli/src/org/jetbrains/jet/cli/KotlinCompiler.java
+++ /dev/null
@@ -1,296 +0,0 @@
-/*
- * 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.cli;
-
-import com.google.common.base.Splitter;
-import com.google.common.collect.Iterables;
-import com.google.common.collect.LinkedHashMultimap;
-import com.google.common.collect.Multimap;
-import com.intellij.openapi.Disposable;
-import com.intellij.openapi.util.Disposer;
-import com.sampullara.cli.Args;
-import org.jetbrains.annotations.NotNull;
-import org.jetbrains.jet.compiler.*;
-import org.jetbrains.jet.compiler.messages.CompilerMessageLocation;
-import org.jetbrains.jet.compiler.messages.CompilerMessageSeverity;
-import org.jetbrains.jet.compiler.messages.MessageCollector;
-import org.jetbrains.jet.compiler.messages.MessageRenderer;
-import org.jetbrains.jet.lang.resolve.java.CompilerDependencies;
-import org.jetbrains.jet.lang.resolve.java.CompilerSpecialMode;
-import org.jetbrains.jet.utils.PathUtil;
-
-import java.io.File;
-import java.io.PrintStream;
-import java.util.Collection;
-import java.util.List;
-
-import static org.jetbrains.jet.cli.KotlinCompiler.ExitCode.*;
-
-/**
- * @author yole
- * @author alex.tkachman
- */
-@SuppressWarnings("UseOfSystemOutOrSystemErr")
-public class KotlinCompiler {
-
- public enum ExitCode {
- OK(0),
- COMPILATION_ERROR(1),
- INTERNAL_ERROR(2);
-
- private final int code;
-
- private ExitCode(int code) {
- this.code = code;
- }
-
- public int getCode() {
- return code;
- }
- }
-
- public static void main(String... args) {
- doMain(new KotlinCompiler(), args);
- }
-
- /**
- * Useful main for derived command line tools
- */
- public static void doMain(KotlinCompiler compiler, String[] args) {
- try {
- ExitCode rc = compiler.exec(System.out, args);
- if (rc != OK) {
- System.err.println("exec() finished with " + rc + " return code");
- System.exit(rc.getCode());
- }
- } catch (CompileEnvironmentException e) {
- System.err.println(e.getMessage());
- System.exit(INTERNAL_ERROR.getCode());
- }
- }
-
- public ExitCode exec(PrintStream errStream, String... args) {
- CompilerArguments arguments = createArguments();
- if (!parseArguments(errStream, arguments, args)) {
- return INTERNAL_ERROR;
- }
- return exec(errStream, arguments);
- }
-
- /**
- * Executes the compiler on the parsed arguments
- */
- public ExitCode exec(final PrintStream errStream, CompilerArguments arguments) {
- if (arguments.help) {
- usage(errStream);
- return OK;
- }
- System.setProperty("java.awt.headless", "true");
-
- final MessageRenderer messageRenderer = arguments.tags ? MessageRenderer.TAGS : MessageRenderer.PLAIN;
-
- if (arguments.version) {
- errStream.println(messageRenderer.render(CompilerMessageSeverity.INFO, "Kotlin Compiler version " + CompilerVersion.VERSION, CompilerMessageLocation.NO_LOCATION));
- }
-
- CompilerSpecialMode mode = parseCompilerSpecialMode(arguments);
-
- File jdkHeadersJar;
- if (mode.includeJdkHeaders()) {
- if (arguments.jdkHeaders != null) {
- jdkHeadersJar = new File(arguments.jdkHeaders);
- }
- else {
- jdkHeadersJar = PathUtil.getAltHeadersPath();
- }
- }
- else {
- jdkHeadersJar = null;
- }
- File runtimeJar;
-
- if (mode.includeKotlinRuntime()) {
- if (arguments.stdlib != null) {
- runtimeJar = new File(arguments.stdlib);
- }
- else {
- runtimeJar = PathUtil.getDefaultRuntimePath();
- }
- }
- else {
- runtimeJar = null;
- }
-
- CompilerDependencies dependencies = new CompilerDependencies(mode, jdkHeadersJar, runtimeJar);
- PrintingMessageCollector messageCollector = new PrintingMessageCollector(errStream, messageRenderer, arguments.verbose);
- Disposable rootDisposable = CompileEnvironmentUtil.createMockDisposable();
-
- JetCoreEnvironment environment = new JetCoreEnvironment(rootDisposable, dependencies);
- CompileEnvironmentConfiguration configuration = new CompileEnvironmentConfiguration(environment, dependencies, messageCollector);
- try {
- configureEnvironment(configuration, arguments);
-
- boolean noErrors;
- if (arguments.module != null) {
- noErrors = KotlinToJVMBytecodeCompiler.compileModuleScript(configuration,
- arguments.module, arguments.jar, arguments.outputDir,
- arguments.includeRuntime);
- }
- else {
- // TODO ideally we'd unify to just having a single field that supports multiple files/dirs
- if (arguments.getSourceDirs() != null) {
- noErrors = KotlinToJVMBytecodeCompiler.compileBunchOfSourceDirectories(configuration,
- arguments.getSourceDirs(), arguments.jar, arguments.outputDir, arguments.includeRuntime);
- }
- else {
- noErrors = KotlinToJVMBytecodeCompiler.compileBunchOfSources(configuration,
- arguments.src, arguments.jar, arguments.outputDir, arguments.includeRuntime);
- }
- }
- return noErrors ? OK : COMPILATION_ERROR;
- }
- catch (Throwable t) {
- errStream.println(messageRenderer.renderException(t));
- return INTERNAL_ERROR;
- }
- finally {
- Disposer.dispose(rootDisposable);
- messageCollector.printToErrStream();
- }
- }
-
- @NotNull
- private CompilerSpecialMode parseCompilerSpecialMode(@NotNull CompilerArguments arguments) {
- if (arguments.mode == null) {
- return CompilerSpecialMode.REGULAR;
- }
- else {
- for (CompilerSpecialMode variant : CompilerSpecialMode.values()) {
- if (arguments.mode.equalsIgnoreCase(variant.name().replaceAll("_", ""))) {
- return variant;
- }
- }
- }
- // TODO: report properly
- throw new IllegalArgumentException("unknown compiler mode: " + arguments.mode);
- }
-
- /**
- * Returns true if the arguments can be parsed correctly
- */
- protected boolean parseArguments(PrintStream errStream, CompilerArguments arguments, String[] args) {
- try {
- Args.parse(arguments, args);
- return true;
- }
- catch (IllegalArgumentException e) {
- usage(errStream);
- }
- catch (Throwable t) {
- // Always use tags
- errStream.println(MessageRenderer.TAGS.renderException(t));
- }
- return false;
- }
-
- protected void usage(PrintStream target) {
- // We should say something like
- // Args.usage(target, CompilerArguments.class);
- // but currently cli-parser we are using does not support that
- // a corresponding patch has been sent to the authors
- // For now, we are using this:
-
- PrintStream oldErr = System.err;
- System.setErr(target);
- try {
- // TODO: use proper argv0
- Args.usage(new CompilerArguments());
- } finally {
- System.setErr(oldErr);
- }
- }
-
- /**
- * Allow derived classes to add additional command line arguments
- */
- protected CompilerArguments createArguments() {
- return new CompilerArguments();
- }
-
- /**
- * Strategy method to configure the environment, allowing compiler
- * based tools to customise their own plugins
- */
- protected void configureEnvironment(CompileEnvironmentConfiguration configuration, CompilerArguments arguments) {
- // install any compiler plugins
- List plugins = arguments.getCompilerPlugins();
- if (plugins != null) {
- configuration.getCompilerPlugins().addAll(plugins);
- }
-
- if (configuration.getCompilerDependencies().getRuntimeJar() != null) {
- CompileEnvironmentUtil.addToClasspath(configuration.getEnvironment(), configuration.getCompilerDependencies().getRuntimeJar());
- }
-
- if (arguments.classpath != null) {
- final Iterable classpath = Splitter.on(File.pathSeparatorChar).split(arguments.classpath);
- CompileEnvironmentUtil.addToClasspath(configuration.getEnvironment(), Iterables.toArray(classpath, String.class));
- }
- }
-
- private static class PrintingMessageCollector implements MessageCollector {
- private final boolean verbose;
- private final PrintStream errStream;
- private final MessageRenderer messageRenderer;
-
- // File path (nullable) -> error message
- private final Multimap groupedMessages = LinkedHashMultimap.create();
-
- public PrintingMessageCollector(PrintStream errStream,
- MessageRenderer messageRenderer,
- boolean verbose) {
- this.verbose = verbose;
- this.errStream = errStream;
- this.messageRenderer = messageRenderer;
- }
-
- @Override
- public void report(@NotNull CompilerMessageSeverity severity,
- @NotNull String message,
- @NotNull CompilerMessageLocation location) {
- String text = messageRenderer.render(severity, message, location);
- if (severity == CompilerMessageSeverity.LOGGING) {
- if (!verbose) {
- return;
- }
- errStream.println(text);
- }
- groupedMessages.put(location.getPath(), text);
- }
-
- public void printToErrStream() {
- if (!groupedMessages.isEmpty()) {
- for (String path : groupedMessages.keySet()) {
- Collection messageTexts = groupedMessages.get(path);
- for (String text : messageTexts) {
- errStream.println(text);
- }
- }
- }
- }
- }
-}
diff --git a/compiler/cli/src/org/jetbrains/jet/compiler/CompilerPlugin.java b/compiler/cli/src/org/jetbrains/jet/cli/common/CompilerPlugin.java
similarity index 95%
rename from compiler/cli/src/org/jetbrains/jet/compiler/CompilerPlugin.java
rename to compiler/cli/src/org/jetbrains/jet/cli/common/CompilerPlugin.java
index bc2db80c71e..8587929d80c 100644
--- a/compiler/cli/src/org/jetbrains/jet/compiler/CompilerPlugin.java
+++ b/compiler/cli/src/org/jetbrains/jet/cli/common/CompilerPlugin.java
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-package org.jetbrains.jet.compiler;
+package org.jetbrains.jet.cli.common;
/**
* A simple interface for compiler plugins to run after the compiler has finished such as for things like
diff --git a/compiler/cli/src/org/jetbrains/jet/compiler/CompilerPluginContext.java b/compiler/cli/src/org/jetbrains/jet/cli/common/CompilerPluginContext.java
similarity index 97%
rename from compiler/cli/src/org/jetbrains/jet/compiler/CompilerPluginContext.java
rename to compiler/cli/src/org/jetbrains/jet/cli/common/CompilerPluginContext.java
index 8ce1d7ef805..7716e3130ed 100644
--- a/compiler/cli/src/org/jetbrains/jet/compiler/CompilerPluginContext.java
+++ b/compiler/cli/src/org/jetbrains/jet/cli/common/CompilerPluginContext.java
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-package org.jetbrains.jet.compiler;
+package org.jetbrains.jet.cli.common;
import com.intellij.openapi.project.Project;
import org.jetbrains.jet.lang.psi.JetFile;
diff --git a/compiler/cli/src/org/jetbrains/jet/cli/common/ExitCode.java b/compiler/cli/src/org/jetbrains/jet/cli/common/ExitCode.java
new file mode 100644
index 00000000000..db3c954d0db
--- /dev/null
+++ b/compiler/cli/src/org/jetbrains/jet/cli/common/ExitCode.java
@@ -0,0 +1,36 @@
+/*
+ * 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.cli.common;
+
+/**
+* @author Pavel Talanov
+*/
+public enum ExitCode {
+ OK(0),
+ COMPILATION_ERROR(1),
+ INTERNAL_ERROR(2);
+
+ private final int code;
+
+ ExitCode(int code) {
+ this.code = code;
+ }
+
+ public int getCode() {
+ return code;
+ }
+}
diff --git a/compiler/cli/src/org/jetbrains/jet/cli/common/messages/AnalyzerWithCompilerReport.java b/compiler/cli/src/org/jetbrains/jet/cli/common/messages/AnalyzerWithCompilerReport.java
new file mode 100644
index 00000000000..24c2f1b1175
--- /dev/null
+++ b/compiler/cli/src/org/jetbrains/jet/cli/common/messages/AnalyzerWithCompilerReport.java
@@ -0,0 +1,151 @@
+/*
+ * 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.cli.common.messages;
+
+import com.intellij.openapi.util.text.StringUtil;
+import com.intellij.openapi.vfs.VirtualFile;
+import com.intellij.psi.PsiErrorElement;
+import com.intellij.psi.PsiRecursiveElementWalkingVisitor;
+import jet.Function0;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+import org.jetbrains.jet.analyzer.AnalyzeExhaust;
+import org.jetbrains.jet.lang.descriptors.ClassDescriptor;
+import org.jetbrains.jet.lang.diagnostics.*;
+import org.jetbrains.jet.lang.diagnostics.rendering.DefaultErrorMessages;
+import org.jetbrains.jet.lang.psi.JetFile;
+import org.jetbrains.jet.lang.resolve.BindingContext;
+import org.jetbrains.jet.lang.resolve.DescriptorUtils;
+
+import java.util.Collection;
+
+/**
+ * @author Pavel Talanov
+ */
+public final class AnalyzerWithCompilerReport {
+
+ @NotNull
+ private static CompilerMessageSeverity convertSeverity(@NotNull Severity severity) {
+ switch (severity) {
+ case INFO:
+ return CompilerMessageSeverity.INFO;
+ case ERROR:
+ return CompilerMessageSeverity.ERROR;
+ case WARNING:
+ return CompilerMessageSeverity.WARNING;
+ }
+ throw new IllegalStateException("Unknown severity: " + severity);
+ }
+
+ @NotNull
+ private static final SimpleDiagnosticFactory SYNTAX_ERROR_FACTORY = SimpleDiagnosticFactory.create(Severity.ERROR);
+
+ private boolean hasErrors = false;
+ @NotNull
+ private final MessageCollector messageCollectorWrapper;
+ @Nullable
+ private AnalyzeExhaust analyzeExhaust = null;
+
+ public AnalyzerWithCompilerReport(@NotNull final MessageCollector collector) {
+ messageCollectorWrapper = new MessageCollector() {
+ @Override
+ public void report(@NotNull CompilerMessageSeverity severity,
+ @NotNull String message,
+ @NotNull CompilerMessageLocation location) {
+ if (CompilerMessageSeverity.ERRORS.contains(severity)) {
+ hasErrors = true;
+ }
+ collector.report(severity, message, location);
+ }
+ };
+ }
+
+ private void reportDiagnostic(@NotNull Diagnostic diagnostic) {
+ DiagnosticUtils.LineAndColumn lineAndColumn = DiagnosticUtils.getLineAndColumn(diagnostic);
+ VirtualFile virtualFile = diagnostic.getPsiFile().getVirtualFile();
+ String path = virtualFile == null ? null : virtualFile.getPath();
+ String render;
+ if (diagnostic.getFactory() == SYNTAX_ERROR_FACTORY) {
+ render = ((SyntaxErrorDiagnostic)diagnostic).message;
+ }
+ else {
+ render = DefaultErrorMessages.RENDERER.render(diagnostic);
+ }
+ messageCollectorWrapper.report(convertSeverity(diagnostic.getSeverity()), render,
+ CompilerMessageLocation.create(path, lineAndColumn.getLine(), lineAndColumn.getColumn()));
+ }
+
+ private void reportIncompleteHierarchies() {
+ assert analyzeExhaust != null;
+ Collection incompletes = analyzeExhaust.getBindingContext().getKeys(BindingContext.INCOMPLETE_HIERARCHY);
+ if (!incompletes.isEmpty()) {
+ StringBuilder message = new StringBuilder("The following classes have incomplete hierarchies:\n");
+ for (ClassDescriptor incomplete : incompletes) {
+ String fqName = DescriptorUtils.getFQName(incomplete).getFqName();
+ message.append(" ").append(fqName).append("\n");
+ }
+ messageCollectorWrapper.report(CompilerMessageSeverity.ERROR, message.toString(), CompilerMessageLocation.NO_LOCATION);
+ }
+ }
+
+ private void reportDiagnostics() {
+ assert analyzeExhaust != null;
+ for (Diagnostic diagnostic : analyzeExhaust.getBindingContext().getDiagnostics()) {
+ reportDiagnostic(diagnostic);
+ }
+ }
+
+ private void reportSyntaxErrors(@NotNull Collection files) {
+ for (JetFile file : files) {
+ file.accept(new PsiRecursiveElementWalkingVisitor() {
+ @Override
+ public void visitErrorElement(PsiErrorElement element) {
+ String description = element.getErrorDescription();
+ String message = StringUtil.isEmpty(description) ? "Syntax error" : description;
+ Diagnostic diagnostic = new SyntaxErrorDiagnostic(element, Severity.ERROR, message);
+ reportDiagnostic(diagnostic);
+ }
+ });
+ }
+ }
+
+ @Nullable
+ public AnalyzeExhaust getAnalyzeExhaust() {
+ return analyzeExhaust;
+ }
+
+ public boolean hasErrors() {
+ return hasErrors;
+ }
+
+ public void analyzeAndReport(@NotNull Function0 analyzer, @NotNull Collection files) {
+ reportSyntaxErrors(files);
+ analyzeExhaust = analyzer.invoke();
+ reportDiagnostics();
+ reportIncompleteHierarchies();
+ }
+
+
+ public static class SyntaxErrorDiagnostic extends SimpleDiagnostic {
+ private String message;
+
+ public SyntaxErrorDiagnostic(@NotNull PsiErrorElement psiElement, @NotNull Severity severity, String message) {
+ super(psiElement, SYNTAX_ERROR_FACTORY, severity);
+ this.message = message;
+ }
+ }
+}
diff --git a/compiler/cli/src/org/jetbrains/jet/compiler/messages/CompilerMessageLocation.java b/compiler/cli/src/org/jetbrains/jet/cli/common/messages/CompilerMessageLocation.java
similarity index 96%
rename from compiler/cli/src/org/jetbrains/jet/compiler/messages/CompilerMessageLocation.java
rename to compiler/cli/src/org/jetbrains/jet/cli/common/messages/CompilerMessageLocation.java
index f39e6c43a4e..247656bc88b 100644
--- a/compiler/cli/src/org/jetbrains/jet/compiler/messages/CompilerMessageLocation.java
+++ b/compiler/cli/src/org/jetbrains/jet/cli/common/messages/CompilerMessageLocation.java
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-package org.jetbrains.jet.compiler.messages;
+package org.jetbrains.jet.cli.common.messages;
import org.jetbrains.annotations.Nullable;
diff --git a/compiler/cli/src/org/jetbrains/jet/compiler/messages/CompilerMessageSeverity.java b/compiler/cli/src/org/jetbrains/jet/cli/common/messages/CompilerMessageSeverity.java
similarity index 94%
rename from compiler/cli/src/org/jetbrains/jet/compiler/messages/CompilerMessageSeverity.java
rename to compiler/cli/src/org/jetbrains/jet/cli/common/messages/CompilerMessageSeverity.java
index 9171be05403..2608639a9f6 100644
--- a/compiler/cli/src/org/jetbrains/jet/compiler/messages/CompilerMessageSeverity.java
+++ b/compiler/cli/src/org/jetbrains/jet/cli/common/messages/CompilerMessageSeverity.java
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-package org.jetbrains.jet.compiler.messages;
+package org.jetbrains.jet.cli.common.messages;
import java.util.EnumSet;
diff --git a/compiler/cli/src/org/jetbrains/jet/compiler/messages/MessageCollector.java b/compiler/cli/src/org/jetbrains/jet/cli/common/messages/MessageCollector.java
similarity index 96%
rename from compiler/cli/src/org/jetbrains/jet/compiler/messages/MessageCollector.java
rename to compiler/cli/src/org/jetbrains/jet/cli/common/messages/MessageCollector.java
index 5fb1b0973a0..44b2697262b 100644
--- a/compiler/cli/src/org/jetbrains/jet/compiler/messages/MessageCollector.java
+++ b/compiler/cli/src/org/jetbrains/jet/cli/common/messages/MessageCollector.java
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-package org.jetbrains.jet.compiler.messages;
+package org.jetbrains.jet.cli.common.messages;
import org.jetbrains.annotations.NotNull;
diff --git a/compiler/cli/src/org/jetbrains/jet/compiler/messages/MessageRenderer.java b/compiler/cli/src/org/jetbrains/jet/cli/common/messages/MessageRenderer.java
similarity index 77%
rename from compiler/cli/src/org/jetbrains/jet/compiler/messages/MessageRenderer.java
rename to compiler/cli/src/org/jetbrains/jet/cli/common/messages/MessageRenderer.java
index acf7ec08e21..15eb3824455 100644
--- a/compiler/cli/src/org/jetbrains/jet/compiler/messages/MessageRenderer.java
+++ b/compiler/cli/src/org/jetbrains/jet/cli/common/messages/MessageRenderer.java
@@ -14,8 +14,9 @@
* limitations under the License.
*/
-package org.jetbrains.jet.compiler.messages;
+package org.jetbrains.jet.cli.common.messages;
+import com.intellij.openapi.util.text.StringUtil;
import org.jetbrains.annotations.NotNull;
import java.io.PrintWriter;
@@ -27,30 +28,49 @@ import java.io.StringWriter;
public interface MessageRenderer {
MessageRenderer TAGS = new MessageRenderer() {
+ @Override
+ public String renderPreamble() {
+ return "";
+ }
+
@Override
public String render(@NotNull CompilerMessageSeverity severity, @NotNull String message, @NotNull CompilerMessageLocation location) {
StringBuilder out = new StringBuilder();
out.append("<").append(severity.toString());
if (location.getPath() != null) {
- out.append(" path=\"").append(location.getPath()).append("\"");
+ out.append(" path=\"").append(e(location.getPath())).append("\"");
out.append(" line=\"").append(location.getLine()).append("\"");
out.append(" column=\"").append(location.getColumn()).append("\"");
}
out.append(">\n");
- out.append(message);
+ out.append(e(message));
out.append("").append(severity.toString()).append(">\n");
return out.toString();
}
+ private String e(String str) {
+ return StringUtil.escapeXml(str);
+ }
+
@Override
public String renderException(@NotNull Throwable e) {
return render(CompilerMessageSeverity.EXCEPTION, PLAIN.renderException(e), CompilerMessageLocation.NO_LOCATION);
}
+
+ @Override
+ public String renderConclusion() {
+ return "";
+ }
};
MessageRenderer PLAIN = new MessageRenderer() {
+ @Override
+ public String renderPreamble() {
+ return "";
+ }
+
@Override
public String render(@NotNull CompilerMessageSeverity severity, @NotNull String message, @NotNull CompilerMessageLocation location) {
String path = location.getPath();
@@ -65,8 +85,15 @@ public interface MessageRenderer {
e.printStackTrace(new PrintWriter(out));
return out.toString();
}
+
+ @Override
+ public String renderConclusion() {
+ return "";
+ }
};
+ String renderPreamble();
String render(@NotNull CompilerMessageSeverity severity, @NotNull String message, @NotNull CompilerMessageLocation location);
String renderException(@NotNull Throwable e);
+ String renderConclusion();
}
diff --git a/compiler/cli/src/org/jetbrains/jet/cli/common/messages/MessageUtil.java b/compiler/cli/src/org/jetbrains/jet/cli/common/messages/MessageUtil.java
new file mode 100644
index 00000000000..9e3775e3ef4
--- /dev/null
+++ b/compiler/cli/src/org/jetbrains/jet/cli/common/messages/MessageUtil.java
@@ -0,0 +1,32 @@
+/*
+ * 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.cli.common.messages;
+
+import com.intellij.psi.PsiElement;
+import com.intellij.psi.PsiFile;
+import org.jetbrains.jet.lang.diagnostics.DiagnosticUtils;
+
+/**
+ * @author abreslav
+ */
+public class MessageUtil {
+ public static CompilerMessageLocation psiElementToMessageLocation(PsiElement element) {
+ PsiFile file = element.getContainingFile();
+ DiagnosticUtils.LineAndColumn lineAndColumn = DiagnosticUtils.getLineAndColumnInPsiFile(file, element.getTextRange());
+ return CompilerMessageLocation.create(file.getVirtualFile().getPath(), lineAndColumn.getLine(), lineAndColumn.getColumn());
+ }
+}
diff --git a/compiler/cli/src/org/jetbrains/jet/cli/common/messages/PrintingMessageCollector.java b/compiler/cli/src/org/jetbrains/jet/cli/common/messages/PrintingMessageCollector.java
new file mode 100644
index 00000000000..9f9e8b0120d
--- /dev/null
+++ b/compiler/cli/src/org/jetbrains/jet/cli/common/messages/PrintingMessageCollector.java
@@ -0,0 +1,73 @@
+/*
+ * 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.cli.common.messages;
+
+import com.google.common.collect.LinkedHashMultimap;
+import com.google.common.collect.Multimap;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.jet.cli.common.messages.CompilerMessageLocation;
+import org.jetbrains.jet.cli.common.messages.CompilerMessageSeverity;
+import org.jetbrains.jet.cli.common.messages.MessageCollector;
+import org.jetbrains.jet.cli.common.messages.MessageRenderer;
+
+import java.io.PrintStream;
+import java.util.Collection;
+
+/**
+ * @author Pavel Talanov
+ */
+public class PrintingMessageCollector implements MessageCollector {
+ private final boolean verbose;
+ private final PrintStream errStream;
+ private final MessageRenderer messageRenderer;
+
+ // File path (nullable) -> error message
+ private final Multimap groupedMessages = LinkedHashMultimap.create();
+
+ public PrintingMessageCollector(PrintStream errStream,
+ MessageRenderer messageRenderer,
+ boolean verbose) {
+ this.verbose = verbose;
+ this.errStream = errStream;
+ this.messageRenderer = messageRenderer;
+ }
+
+ @Override
+ public void report(@NotNull CompilerMessageSeverity severity,
+ @NotNull String message,
+ @NotNull CompilerMessageLocation location) {
+ String text = messageRenderer.render(severity, message, location);
+ if (severity == CompilerMessageSeverity.LOGGING) {
+ if (!verbose) {
+ return;
+ }
+ errStream.println(text);
+ }
+ groupedMessages.put(location.getPath(), text);
+ }
+
+ public void printToErrStream() {
+ if (!groupedMessages.isEmpty()) {
+ for (String path : groupedMessages.keySet()) {
+ Collection messageTexts = groupedMessages.get(path);
+ for (String text : messageTexts) {
+ errStream.println(text);
+ }
+ }
+ }
+ }
+}
diff --git a/compiler/cli/src/org/jetbrains/jet/cli/js/K2JSCompiler.java b/compiler/cli/src/org/jetbrains/jet/cli/js/K2JSCompiler.java
new file mode 100644
index 00000000000..63d8e8fb778
--- /dev/null
+++ b/compiler/cli/src/org/jetbrains/jet/cli/js/K2JSCompiler.java
@@ -0,0 +1,27 @@
+/*
+ * 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.cli.js;
+
+/**
+ * @author Pavel Talanov
+ */
+public final class K2JSCompiler {
+
+ public static void main(String... args) {
+ //TODO
+ }
+}
diff --git a/compiler/cli/src/org/jetbrains/jet/cli/js/K2JSCompilerArguments.java b/compiler/cli/src/org/jetbrains/jet/cli/js/K2JSCompilerArguments.java
new file mode 100644
index 00000000000..46522696f05
--- /dev/null
+++ b/compiler/cli/src/org/jetbrains/jet/cli/js/K2JSCompilerArguments.java
@@ -0,0 +1,24 @@
+/*
+ * 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.cli.js;
+
+/**
+ * @author Pavel Talanov
+ */
+//TODO
+public class K2JSCompilerArguments {
+}
diff --git a/compiler/cli/src/org/jetbrains/jet/cli/jvm/K2JVMCompiler.java b/compiler/cli/src/org/jetbrains/jet/cli/jvm/K2JVMCompiler.java
new file mode 100644
index 00000000000..007253e25e5
--- /dev/null
+++ b/compiler/cli/src/org/jetbrains/jet/cli/jvm/K2JVMCompiler.java
@@ -0,0 +1,255 @@
+/*
+ * 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.cli.jvm;
+
+import com.google.common.base.Splitter;
+import com.google.common.collect.Iterables;
+import com.intellij.openapi.Disposable;
+import com.intellij.openapi.util.Disposer;
+import com.sampullara.cli.Args;
+import jet.modules.Module;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.jet.cli.common.CompilerPlugin;
+import org.jetbrains.jet.cli.common.ExitCode;
+import org.jetbrains.jet.cli.common.messages.PrintingMessageCollector;
+import org.jetbrains.jet.codegen.CompilationException;
+import org.jetbrains.jet.cli.jvm.compiler.*;
+import org.jetbrains.jet.cli.common.messages.*;
+import org.jetbrains.jet.lang.resolve.java.CompilerDependencies;
+import org.jetbrains.jet.lang.resolve.java.CompilerSpecialMode;
+import org.jetbrains.jet.utils.PathUtil;
+
+import java.io.File;
+import java.io.PrintStream;
+import java.util.List;
+
+import static org.jetbrains.jet.cli.common.ExitCode.*;
+
+/**
+ * @author yole
+ * @author alex.tkachman
+ */
+@SuppressWarnings("UseOfSystemOutOrSystemErr")
+public class K2JVMCompiler {
+
+ public static void main(String... args) {
+ doMain(new K2JVMCompiler(), args);
+ }
+
+ /**
+ * Useful main for derived command line tools
+ */
+ public static void doMain(K2JVMCompiler compiler, String[] args) {
+ try {
+ ExitCode rc = compiler.exec(System.out, args);
+ if (rc != OK) {
+ System.err.println("exec() finished with " + rc + " return code");
+ System.exit(rc.getCode());
+ }
+ }
+ catch (CompileEnvironmentException e) {
+ System.err.println(e.getMessage());
+ System.exit(INTERNAL_ERROR.getCode());
+ }
+ }
+
+ public ExitCode exec(PrintStream errStream, String... args) {
+ K2JVMCompilerArguments arguments = createArguments();
+ if (!parseArguments(errStream, arguments, args)) {
+ return INTERNAL_ERROR;
+ }
+ return exec(errStream, arguments);
+ }
+
+ /**
+ * Executes the compiler on the parsed arguments
+ */
+ public ExitCode exec(final PrintStream errStream, K2JVMCompilerArguments arguments) {
+ if (arguments.help) {
+ usage(errStream);
+ return OK;
+ }
+ System.setProperty("java.awt.headless", "true");
+
+ final MessageRenderer messageRenderer = arguments.tags ? MessageRenderer.TAGS : MessageRenderer.PLAIN;
+
+ errStream.print(messageRenderer.renderPreamble());
+
+ try {
+ if (arguments.version) {
+ errStream.println(messageRenderer.render(CompilerMessageSeverity.INFO, "Kotlin Compiler version " + K2JVMCompilerVersion.VERSION, CompilerMessageLocation.NO_LOCATION));
+ }
+
+ CompilerSpecialMode mode = parseCompilerSpecialMode(arguments);
+
+ File jdkHeadersJar;
+ if (mode.includeJdkHeaders()) {
+ if (arguments.jdkHeaders != null) {
+ jdkHeadersJar = new File(arguments.jdkHeaders);
+ }
+ else {
+ jdkHeadersJar = PathUtil.getAltHeadersPath();
+ }
+ }
+ else {
+ jdkHeadersJar = null;
+ }
+ File runtimeJar;
+
+ if (mode.includeKotlinRuntime()) {
+ if (arguments.stdlib != null) {
+ runtimeJar = new File(arguments.stdlib);
+ }
+ else {
+ runtimeJar = PathUtil.getDefaultRuntimePath();
+ }
+ }
+ else {
+ runtimeJar = null;
+ }
+
+ CompilerDependencies dependencies = new CompilerDependencies(mode, CompilerDependencies.findRtJar(), jdkHeadersJar, runtimeJar);
+ PrintingMessageCollector messageCollector = new PrintingMessageCollector(errStream, messageRenderer, arguments.verbose);
+ Disposable rootDisposable = CompileEnvironmentUtil.createMockDisposable();
+
+ JetCoreEnvironment environment = new JetCoreEnvironment(rootDisposable, dependencies);
+ CompileEnvironmentConfiguration configuration = new CompileEnvironmentConfiguration(environment, dependencies, messageCollector);
+
+ messageCollector.report(CompilerMessageSeverity.LOGGING, "Configuring the compilation environment",
+ CompilerMessageLocation.NO_LOCATION);
+ try {
+ configureEnvironment(configuration, arguments);
+
+ boolean noErrors;
+ if (arguments.module != null) {
+ List modules = CompileEnvironmentUtil.loadModuleScript(arguments.module, new PrintingMessageCollector(errStream, messageRenderer, false));
+ File directory = new File(arguments.module).getParentFile();
+ noErrors = KotlinToJVMBytecodeCompiler.compileModules(configuration, modules,
+ directory, arguments.jar, arguments.outputDir,
+ arguments.includeRuntime);
+ }
+ else {
+ // TODO ideally we'd unify to just having a single field that supports multiple files/dirs
+ if (arguments.getSourceDirs() != null) {
+ noErrors = KotlinToJVMBytecodeCompiler.compileBunchOfSourceDirectories(configuration,
+ arguments.getSourceDirs(), arguments.jar, arguments.outputDir, arguments.includeRuntime);
+ }
+ else {
+ noErrors = KotlinToJVMBytecodeCompiler.compileBunchOfSources(configuration,
+ arguments.src, arguments.jar, arguments.outputDir, arguments.includeRuntime);
+ }
+ }
+ return noErrors ? OK : COMPILATION_ERROR;
+ }
+ catch (CompilationException e) {
+ messageCollector.report(CompilerMessageSeverity.EXCEPTION, MessageRenderer.PLAIN.renderException(e),
+ MessageUtil.psiElementToMessageLocation(e.getElement()));
+ return INTERNAL_ERROR;
+ }
+ catch (Throwable t) {
+ messageCollector.report(CompilerMessageSeverity.EXCEPTION, MessageRenderer.PLAIN.renderException(t), CompilerMessageLocation.NO_LOCATION);
+ return INTERNAL_ERROR;
+ }
+ finally {
+ Disposer.dispose(rootDisposable);
+ messageCollector.printToErrStream();
+ }
+ }
+ finally {
+ errStream.print(messageRenderer.renderConclusion());
+ }
+ }
+
+ @NotNull
+ private CompilerSpecialMode parseCompilerSpecialMode(@NotNull K2JVMCompilerArguments arguments) {
+ if (arguments.mode == null) {
+ return CompilerSpecialMode.REGULAR;
+ }
+ else {
+ for (CompilerSpecialMode variant : CompilerSpecialMode.values()) {
+ if (arguments.mode.equalsIgnoreCase(variant.name().replaceAll("_", ""))) {
+ return variant;
+ }
+ }
+ }
+ // TODO: report properly
+ throw new IllegalArgumentException("unknown compiler mode: " + arguments.mode);
+ }
+
+ /**
+ * Returns true if the arguments can be parsed correctly
+ */
+ protected boolean parseArguments(PrintStream errStream, K2JVMCompilerArguments arguments, String[] args) {
+ try {
+ Args.parse(arguments, args);
+ return true;
+ }
+ catch (IllegalArgumentException e) {
+ usage(errStream);
+ }
+ catch (Throwable t) {
+ // Always use tags
+ errStream.println(MessageRenderer.TAGS.renderException(t));
+ }
+ return false;
+ }
+
+ protected void usage(PrintStream target) {
+ // We should say something like
+ // Args.usage(target, K2JVMCompilerArguments.class);
+ // but currently cli-parser we are using does not support that
+ // a corresponding patch has been sent to the authors
+ // For now, we are using this:
+
+ PrintStream oldErr = System.err;
+ System.setErr(target);
+ try {
+ // TODO: use proper argv0
+ Args.usage(new K2JVMCompilerArguments());
+ } finally {
+ System.setErr(oldErr);
+ }
+ }
+
+ /**
+ * Allow derived classes to add additional command line arguments
+ */
+ protected K2JVMCompilerArguments createArguments() {
+ return new K2JVMCompilerArguments();
+ }
+
+ /**
+ * Strategy method to configure the environment, allowing compiler
+ * based tools to customise their own plugins
+ */
+ protected void configureEnvironment(CompileEnvironmentConfiguration configuration, K2JVMCompilerArguments arguments) {
+ // install any compiler plugins
+ List plugins = arguments.getCompilerPlugins();
+ if (plugins != null) {
+ configuration.getCompilerPlugins().addAll(plugins);
+ }
+
+ if (configuration.getCompilerDependencies().getRuntimeJar() != null) {
+ CompileEnvironmentUtil.addToClasspath(configuration.getEnvironment(), configuration.getCompilerDependencies().getRuntimeJar());
+ }
+
+ if (arguments.classpath != null) {
+ final Iterable classpath = Splitter.on(File.pathSeparatorChar).split(arguments.classpath);
+ CompileEnvironmentUtil.addToClasspath(configuration.getEnvironment(), Iterables.toArray(classpath, String.class));
+ }
+ }
+}
diff --git a/compiler/cli/src/org/jetbrains/jet/cli/CompilerArguments.java b/compiler/cli/src/org/jetbrains/jet/cli/jvm/K2JVMCompilerArguments.java
similarity index 95%
rename from compiler/cli/src/org/jetbrains/jet/cli/CompilerArguments.java
rename to compiler/cli/src/org/jetbrains/jet/cli/jvm/K2JVMCompilerArguments.java
index ee233809581..bed558b5f08 100644
--- a/compiler/cli/src/org/jetbrains/jet/cli/CompilerArguments.java
+++ b/compiler/cli/src/org/jetbrains/jet/cli/jvm/K2JVMCompilerArguments.java
@@ -15,18 +15,18 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.jetbrains.jet.cli;
+package org.jetbrains.jet.cli.jvm;
import com.sampullara.cli.Argument;
-import org.jetbrains.jet.compiler.CompilerPlugin;
+import org.jetbrains.jet.cli.common.CompilerPlugin;
import java.util.ArrayList;
import java.util.List;
/**
- * Command line arguments for the {@link KotlinCompiler}
+ * Command line arguments for the {@link K2JVMCompiler}
*/
-public class CompilerArguments {
+public class K2JVMCompilerArguments {
private List compilerPlugins = new ArrayList();
// TODO ideally we'd unify this with 'src' to just having a single field that supports multiple files/dirs
@@ -157,7 +157,7 @@ public class CompilerArguments {
}
/**
- * Sets the compiler plugins to be used when working with the {@link KotlinCompiler}
+ * Sets the compiler plugins to be used when working with the {@link K2JVMCompiler}
*/
public void setCompilerPlugins(List compilerPlugins) {
this.compilerPlugins = compilerPlugins;
diff --git a/compiler/cli/src/org/jetbrains/jet/cli/CompilerVersion.java b/compiler/cli/src/org/jetbrains/jet/cli/jvm/K2JVMCompilerVersion.java
similarity index 91%
rename from compiler/cli/src/org/jetbrains/jet/cli/CompilerVersion.java
rename to compiler/cli/src/org/jetbrains/jet/cli/jvm/K2JVMCompilerVersion.java
index 674ba94041d..460d5c89493 100644
--- a/compiler/cli/src/org/jetbrains/jet/cli/CompilerVersion.java
+++ b/compiler/cli/src/org/jetbrains/jet/cli/jvm/K2JVMCompilerVersion.java
@@ -14,12 +14,12 @@
* limitations under the License.
*/
-package org.jetbrains.jet.cli;
+package org.jetbrains.jet.cli.jvm;
/**
* @author abreslav
*/
-public class CompilerVersion {
+public class K2JVMCompilerVersion {
// The value of this constant is generated by the build script
// DON'T MODIFY IT
public static final String VERSION = "@snapshot@";
diff --git a/compiler/cli/src/org/jetbrains/jet/compiler/CliJetFilesProvider.java b/compiler/cli/src/org/jetbrains/jet/cli/jvm/compiler/CliJetFilesProvider.java
similarity index 97%
rename from compiler/cli/src/org/jetbrains/jet/compiler/CliJetFilesProvider.java
rename to compiler/cli/src/org/jetbrains/jet/cli/jvm/compiler/CliJetFilesProvider.java
index a5e95ae5696..fa66c13bcaa 100644
--- a/compiler/cli/src/org/jetbrains/jet/compiler/CliJetFilesProvider.java
+++ b/compiler/cli/src/org/jetbrains/jet/cli/jvm/compiler/CliJetFilesProvider.java
@@ -17,7 +17,7 @@
/*
* @author max
*/
-package org.jetbrains.jet.compiler;
+package org.jetbrains.jet.cli.jvm.compiler;
import com.intellij.psi.search.GlobalSearchScope;
import com.intellij.util.Function;
diff --git a/compiler/cli/src/org/jetbrains/jet/compiler/CompileEnvironmentConfiguration.java b/compiler/cli/src/org/jetbrains/jet/cli/jvm/compiler/CompileEnvironmentConfiguration.java
similarity index 92%
rename from compiler/cli/src/org/jetbrains/jet/compiler/CompileEnvironmentConfiguration.java
rename to compiler/cli/src/org/jetbrains/jet/cli/jvm/compiler/CompileEnvironmentConfiguration.java
index cf57bee50b2..e95f3ba7186 100644
--- a/compiler/cli/src/org/jetbrains/jet/compiler/CompileEnvironmentConfiguration.java
+++ b/compiler/cli/src/org/jetbrains/jet/cli/jvm/compiler/CompileEnvironmentConfiguration.java
@@ -14,12 +14,13 @@
* limitations under the License.
*/
-package org.jetbrains.jet.compiler;
+package org.jetbrains.jet.cli.jvm.compiler;
import com.google.common.collect.Lists;
import com.intellij.openapi.util.Disposer;
import org.jetbrains.annotations.NotNull;
-import org.jetbrains.jet.compiler.messages.MessageCollector;
+import org.jetbrains.jet.cli.common.CompilerPlugin;
+import org.jetbrains.jet.cli.common.messages.MessageCollector;
import org.jetbrains.jet.lang.resolve.java.CompilerDependencies;
import java.util.List;
diff --git a/compiler/cli/src/org/jetbrains/jet/compiler/CompileEnvironmentException.java b/compiler/cli/src/org/jetbrains/jet/cli/jvm/compiler/CompileEnvironmentException.java
similarity index 95%
rename from compiler/cli/src/org/jetbrains/jet/compiler/CompileEnvironmentException.java
rename to compiler/cli/src/org/jetbrains/jet/cli/jvm/compiler/CompileEnvironmentException.java
index bf9d8e58c05..92ef9b972d7 100644
--- a/compiler/cli/src/org/jetbrains/jet/compiler/CompileEnvironmentException.java
+++ b/compiler/cli/src/org/jetbrains/jet/cli/jvm/compiler/CompileEnvironmentException.java
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-package org.jetbrains.jet.compiler;
+package org.jetbrains.jet.cli.jvm.compiler;
/**
* @author yole
diff --git a/compiler/cli/src/org/jetbrains/jet/compiler/CompileEnvironmentUtil.java b/compiler/cli/src/org/jetbrains/jet/cli/jvm/compiler/CompileEnvironmentUtil.java
similarity index 90%
rename from compiler/cli/src/org/jetbrains/jet/compiler/CompileEnvironmentUtil.java
rename to compiler/cli/src/org/jetbrains/jet/cli/jvm/compiler/CompileEnvironmentUtil.java
index ca803c0549f..344fa99cd59 100644
--- a/compiler/cli/src/org/jetbrains/jet/compiler/CompileEnvironmentUtil.java
+++ b/compiler/cli/src/org/jetbrains/jet/cli/jvm/compiler/CompileEnvironmentUtil.java
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-package org.jetbrains.jet.compiler;
+package org.jetbrains.jet.cli.jvm.compiler;
import com.intellij.openapi.Disposable;
import com.intellij.openapi.util.Disposer;
@@ -25,10 +25,10 @@ import com.intellij.util.Processor;
import jet.modules.AllModules;
import jet.modules.Module;
import org.jetbrains.annotations.Nullable;
+import org.jetbrains.jet.cli.common.messages.MessageCollector;
import org.jetbrains.jet.codegen.ClassFileFactory;
import org.jetbrains.jet.codegen.GeneratedClassLoader;
import org.jetbrains.jet.codegen.GenerationState;
-import org.jetbrains.jet.compiler.messages.MessageCollector;
import org.jetbrains.jet.lang.resolve.FqName;
import org.jetbrains.jet.lang.resolve.java.CompilerDependencies;
import org.jetbrains.jet.lang.resolve.java.CompilerSpecialMode;
@@ -78,10 +78,6 @@ public class CompileEnvironmentUtil {
return null;
}
- //public static void ensureRuntime(@NotNull JetCoreEnvironment env) {
- // ensureJdkRuntime(env);
- //}
-
public static void ensureKotlinRuntime(JetCoreEnvironment env) {
if (JavaPsiFacade.getInstance(env.getProject()).findClass("jet.JetObject", GlobalSearchScope.allScope(env.getProject())) == null) {
// TODO: prepend
@@ -97,8 +93,10 @@ public class CompileEnvironmentUtil {
}
}
+
public static void ensureJdkRuntime(JetCoreEnvironment env) {
- if (JavaPsiFacade.getInstance(env.getProject()).findClass("java.lang.Object", GlobalSearchScope.allScope(env.getProject())) == null) {
+ if (JavaPsiFacade.getInstance(env.getProject()).findClass("java.lang.Object", GlobalSearchScope.allScope(env.getProject())) ==
+ null) {
// TODO: prepend
env.addToClasspath(findRtJar());
}
@@ -151,16 +149,7 @@ public class CompileEnvironmentUtil {
}
}
- //private CompileEnvironment copyEnvironment(boolean verbose) {
- // CompileEnvironment compileEnvironment = new CompileEnvironment(messageRenderer, verbose, compilerDependencies);
- // compileEnvironment.setIgnoreErrors(ignoreErrors);
- // compileEnvironment.setErrorStream(errorStream);
- // // copy across any compiler plugins
- // compileEnvironment.getEnvironment().getCompilerPlugins().addAll(environment.getCompilerPlugins());
- // return compileEnvironment;
- //}
- //
- public static List loadModuleScript(String moduleFile, MessageCollector messageCollector) {
+ public static List loadModuleScript(String moduleScriptFile, MessageCollector messageCollector) {
Disposable disposable = new Disposable() {
@Override
public void dispose() {
@@ -170,7 +159,7 @@ public class CompileEnvironmentUtil {
CompilerDependencies dependencies = CompilerDependencies.compilerDependenciesForProduction(CompilerSpecialMode.REGULAR);
JetCoreEnvironment scriptEnvironment = new JetCoreEnvironment(disposable, dependencies);
ensureRuntime(scriptEnvironment, dependencies);
- scriptEnvironment.addSources(moduleFile);
+ scriptEnvironment.addSources(moduleScriptFile);
GenerationState generationState = KotlinToJVMBytecodeCompiler
.analyzeAndGenerate(new CompileEnvironmentConfiguration(scriptEnvironment, dependencies, messageCollector), false);
@@ -178,9 +167,17 @@ public class CompileEnvironmentUtil {
return null;
}
- List modules = runDefineModules(dependencies, moduleFile, generationState.getFactory());
+ List modules = runDefineModules(dependencies, moduleScriptFile, generationState.getFactory());
Disposer.dispose(disposable);
+
+ if (modules == null) {
+ throw new CompileEnvironmentException("Module script " + moduleScriptFile + " compilation failed");
+ }
+
+ if (modules.isEmpty()) {
+ throw new CompileEnvironmentException("No modules where defined by " + moduleScriptFile);
+ }
return modules;
}
@@ -189,8 +186,10 @@ public class CompileEnvironmentUtil {
GeneratedClassLoader loader;
if (stdlibJar != null) {
try {
- loader = new GeneratedClassLoader(factory, new URLClassLoader(new URL[]{stdlibJar.toURI().toURL()}, AllModules.class.getClassLoader()));
- } catch (MalformedURLException e) {
+ loader = new GeneratedClassLoader(factory, new URLClassLoader(new URL[]{stdlibJar.toURI().toURL()},
+ AllModules.class.getClassLoader()));
+ }
+ catch (MalformedURLException e) {
throw new RuntimeException(e);
}
}
@@ -242,8 +241,8 @@ public class CompileEnvironmentUtil {
stream.close();
fos.close();
}
-
- } catch (IOException e) {
+ }
+ catch (IOException e) {
throw new CompileEnvironmentException("Failed to generate jar file", e);
}
}
@@ -288,7 +287,8 @@ public class CompileEnvironmentUtil {
FileUtil.copy(jis, stream);
}
}
- } finally {
+ }
+ finally {
jis.close();
}
}
@@ -304,7 +304,8 @@ public class CompileEnvironmentUtil {
File target = new File(outputDir, file);
try {
FileUtil.writeToFile(target, factory.asBytes(file));
- } catch (IOException e) {
+ }
+ catch (IOException e) {
throw new CompileEnvironmentException(e);
}
}
@@ -312,10 +313,11 @@ public class CompileEnvironmentUtil {
/**
* Add path specified to the compilation environment.
+ *
* @param environment compilation environment to add to
- * @param paths paths to add
+ * @param paths paths to add
*/
- public static void addToClasspath(JetCoreEnvironment environment, File ... paths) {
+ public static void addToClasspath(JetCoreEnvironment environment, File... paths) {
for (File path : paths) {
if (!path.exists()) {
throw new CompileEnvironmentException("'" + path + "' does not exist");
@@ -326,10 +328,11 @@ public class CompileEnvironmentUtil {
/**
* Add path specified to the compilation environment.
+ *
* @param environment compilation environment to add to
- * @param paths paths to add
+ * @param paths paths to add
*/
- public static void addToClasspath(JetCoreEnvironment environment, String ... paths) {
+ public static void addToClasspath(JetCoreEnvironment environment, String... paths) {
for (String path : paths) {
addToClasspath(environment, new File(path));
}
diff --git a/compiler/cli/src/org/jetbrains/jet/compiler/JetCoreEnvironment.java b/compiler/cli/src/org/jetbrains/jet/cli/jvm/compiler/JetCoreEnvironment.java
similarity index 98%
rename from compiler/cli/src/org/jetbrains/jet/compiler/JetCoreEnvironment.java
rename to compiler/cli/src/org/jetbrains/jet/cli/jvm/compiler/JetCoreEnvironment.java
index bd8eb357ccf..14e5111f06b 100644
--- a/compiler/cli/src/org/jetbrains/jet/compiler/JetCoreEnvironment.java
+++ b/compiler/cli/src/org/jetbrains/jet/cli/jvm/compiler/JetCoreEnvironment.java
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-package org.jetbrains.jet.compiler;
+package org.jetbrains.jet.cli.jvm.compiler;
import com.intellij.core.JavaCoreEnvironment;
import com.intellij.lang.java.JavaParserDefinition;
@@ -64,6 +64,8 @@ public class JetCoreEnvironment extends JavaCoreEnvironment {
CompilerSpecialMode compilerSpecialMode = compilerDependencies.getCompilerSpecialMode();
+ addToClasspath(compilerDependencies.getJdkJar());
+
if (compilerSpecialMode.includeJdkHeaders()) {
for (VirtualFile root : compilerDependencies.getJdkHeaderRoots()) {
addLibraryRoot(root);
diff --git a/compiler/cli/src/org/jetbrains/jet/compiler/KotlinToJVMBytecodeCompiler.java b/compiler/cli/src/org/jetbrains/jet/cli/jvm/compiler/KotlinToJVMBytecodeCompiler.java
similarity index 56%
rename from compiler/cli/src/org/jetbrains/jet/compiler/KotlinToJVMBytecodeCompiler.java
rename to compiler/cli/src/org/jetbrains/jet/cli/jvm/compiler/KotlinToJVMBytecodeCompiler.java
index 7e6af64de21..af98cf42dc6 100644
--- a/compiler/cli/src/org/jetbrains/jet/compiler/KotlinToJVMBytecodeCompiler.java
+++ b/compiler/cli/src/org/jetbrains/jet/cli/jvm/compiler/KotlinToJVMBytecodeCompiler.java
@@ -14,37 +14,28 @@
* limitations under the License.
*/
-package org.jetbrains.jet.compiler;
+package org.jetbrains.jet.cli.jvm.compiler;
import com.google.common.base.Predicate;
import com.google.common.base.Predicates;
import com.intellij.openapi.project.Project;
-import com.intellij.openapi.util.Ref;
-import com.intellij.openapi.util.text.StringUtil;
-import com.intellij.openapi.vfs.VirtualFile;
-import com.intellij.psi.PsiErrorElement;
import com.intellij.psi.PsiFile;
-import com.intellij.psi.PsiRecursiveElementWalkingVisitor;
import com.intellij.testFramework.LightVirtualFile;
import com.intellij.util.LocalTimeCounter;
+import jet.Function0;
import jet.modules.Module;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.analyzer.AnalyzeExhaust;
+import org.jetbrains.jet.cli.common.CompilerPlugin;
+import org.jetbrains.jet.cli.common.CompilerPluginContext;
import org.jetbrains.jet.codegen.*;
-import org.jetbrains.jet.compiler.messages.CompilerMessageLocation;
-import org.jetbrains.jet.compiler.messages.CompilerMessageSeverity;
-import org.jetbrains.jet.compiler.messages.MessageCollector;
+import org.jetbrains.jet.cli.common.messages.AnalyzerWithCompilerReport;
+import org.jetbrains.jet.cli.common.messages.CompilerMessageLocation;
+import org.jetbrains.jet.cli.common.messages.CompilerMessageSeverity;
import org.jetbrains.jet.lang.cfg.pseudocode.JetControlFlowDataTraceFactory;
-import org.jetbrains.jet.lang.descriptors.ClassDescriptor;
-import org.jetbrains.jet.lang.diagnostics.Diagnostic;
-import org.jetbrains.jet.lang.diagnostics.DiagnosticFactory;
-import org.jetbrains.jet.lang.diagnostics.DiagnosticUtils;
-import org.jetbrains.jet.lang.diagnostics.Severity;
import org.jetbrains.jet.lang.psi.JetFile;
import org.jetbrains.jet.lang.psi.JetPsiUtil;
-import org.jetbrains.jet.lang.resolve.BindingContext;
-import org.jetbrains.jet.lang.resolve.DescriptorUtils;
import org.jetbrains.jet.lang.resolve.FqName;
import org.jetbrains.jet.lang.resolve.java.AnalyzerFacadeForJVM;
import org.jetbrains.jet.lang.resolve.java.JvmAbi;
@@ -55,7 +46,6 @@ import org.jetbrains.jet.utils.Progress;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
-import java.util.Collection;
import java.util.List;
/**
@@ -64,11 +54,14 @@ import java.util.List;
*/
public class KotlinToJVMBytecodeCompiler {
+ private KotlinToJVMBytecodeCompiler() {
+ }
+
@Nullable
public static ClassFileFactory compileModule(
CompileEnvironmentConfiguration configuration,
Module moduleBuilder,
- String directory
+ File directory
) {
if (moduleBuilder.getSourceFiles().isEmpty()) {
throw new CompileEnvironmentException("No source files where defined");
@@ -99,30 +92,23 @@ public class KotlinToJVMBytecodeCompiler {
return generationState.getFactory();
}
- public static boolean compileModuleScript(
+ public static boolean compileModules(
CompileEnvironmentConfiguration configuration,
- @NotNull String moduleScriptFile,
+ @NotNull List modules,
+
+ @NotNull File directory,
@Nullable String jarPath,
@Nullable String outputDir,
boolean jarRuntime) {
- List modules = CompileEnvironmentUtil.loadModuleScript(moduleScriptFile, configuration.getMessageCollector());
- if (modules == null) {
- throw new CompileEnvironmentException("Module script " + moduleScriptFile + " compilation failed");
- }
-
- if (modules.isEmpty()) {
- throw new CompileEnvironmentException("No modules where defined by " + moduleScriptFile);
- }
-
- final String directory = new File(moduleScriptFile).getParent();
for (Module moduleBuilder : modules) {
// TODO: this should be done only once for the environment
if (configuration.getCompilerDependencies().getRuntimeJar() != null) {
- CompileEnvironmentUtil.addToClasspath(configuration.getEnvironment(), configuration.getCompilerDependencies().getRuntimeJar());
+ CompileEnvironmentUtil
+ .addToClasspath(configuration.getEnvironment(), configuration.getCompilerDependencies().getRuntimeJar());
}
- ClassFileFactory moduleFactory = KotlinToJVMBytecodeCompiler.compileModule(configuration, moduleBuilder, directory);
+ ClassFileFactory moduleFactory = compileModule(configuration, moduleBuilder, directory);
if (moduleFactory == null) {
return false;
}
@@ -144,7 +130,6 @@ public class KotlinToJVMBytecodeCompiler {
private static boolean compileBunchOfSources(
CompileEnvironmentConfiguration configuration,
-
String jar,
String outputDir,
boolean includeRuntime
@@ -165,21 +150,27 @@ public class KotlinToJVMBytecodeCompiler {
return false;
}
- ClassFileFactory factory = generationState.getFactory();
- if (jar != null) {
- try {
- CompileEnvironmentUtil.writeToJar(factory, new FileOutputStream(jar), mainClass, includeRuntime);
- } catch (FileNotFoundException e) {
- throw new CompileEnvironmentException("Invalid jar path " + jar, e);
+ try {
+ ClassFileFactory factory = generationState.getFactory();
+ if (jar != null) {
+ try {
+ CompileEnvironmentUtil.writeToJar(factory, new FileOutputStream(jar), mainClass, includeRuntime);
+ }
+ catch (FileNotFoundException e) {
+ throw new CompileEnvironmentException("Invalid jar path " + jar, e);
+ }
}
+ else if (outputDir != null) {
+ CompileEnvironmentUtil.writeToOutputDirectory(factory, outputDir);
+ }
+ else {
+ throw new CompileEnvironmentException("Output directory or jar file is not specified - no files will be saved to the disk");
+ }
+ return true;
}
- else if (outputDir != null) {
- CompileEnvironmentUtil.writeToOutputDirectory(factory, outputDir);
+ finally {
+ generationState.destroy();
}
- else {
- throw new CompileEnvironmentException("Output directory or jar file is not specified - no files will be saved to the disk");
- }
- return true;
}
public static boolean compileBunchOfSources(
@@ -205,9 +196,9 @@ public class KotlinToJVMBytecodeCompiler {
@Nullable
public static ClassLoader compileText(
CompileEnvironmentConfiguration configuration,
-
String code) {
- configuration.getEnvironment().addSources(new LightVirtualFile("script" + LocalTimeCounter.currentTime() + ".kt", JetLanguage.INSTANCE, code));
+ configuration.getEnvironment()
+ .addSources(new LightVirtualFile("script" + LocalTimeCounter.currentTime() + ".kt", JetLanguage.INSTANCE, code));
GenerationState generationState = analyzeAndGenerate(configuration);
if (generationState == null) {
@@ -224,7 +215,6 @@ public class KotlinToJVMBytecodeCompiler {
@Nullable
public static GenerationState analyzeAndGenerate(
CompileEnvironmentConfiguration configuration,
-
boolean stubs
) {
AnalyzeExhaust exhaust = analyze(configuration, stubs);
@@ -241,59 +231,31 @@ public class KotlinToJVMBytecodeCompiler {
@Nullable
private static AnalyzeExhaust analyze(
final CompileEnvironmentConfiguration configuration,
-
boolean stubs) {
- final Ref hasErrors = new Ref(false);
- final MessageCollector messageCollectorWrapper = new MessageCollector() {
-
- @Override
- public void report(@NotNull CompilerMessageSeverity severity,
- @NotNull String message,
- @NotNull CompilerMessageLocation location) {
- if (CompilerMessageSeverity.ERRORS.contains(severity)) {
- hasErrors.set(true);
- }
- configuration.getMessageCollector().report(severity, message, location);
- }
- };
-
- JetCoreEnvironment environment = configuration.getEnvironment();
-
- // Report syntax errors
- for (JetFile file : environment.getSourceFiles()) {
- file.accept(new PsiRecursiveElementWalkingVisitor() {
- @Override
- public void visitErrorElement(PsiErrorElement element) {
- String description = element.getErrorDescription();
- String message = StringUtil.isEmpty(description) ? "Syntax error" : description;
- Diagnostic diagnostic = DiagnosticFactory.create(Severity.ERROR, message).on(element);
- reportDiagnostic(messageCollectorWrapper, diagnostic);
- }
- });
- }
-
- // Analyze and report semantic errors
- Predicate filesToAnalyzeCompletely =
+ final JetCoreEnvironment environment = configuration.getEnvironment();
+ AnalyzerWithCompilerReport analyzerWithCompilerReport = new AnalyzerWithCompilerReport(configuration.getMessageCollector());
+ final Predicate filesToAnalyzeCompletely =
stubs ? Predicates.alwaysFalse() : Predicates.alwaysTrue();
- AnalyzeExhaust exhaust = AnalyzerFacadeForJVM.analyzeFilesWithJavaIntegration(
- environment.getProject(), environment.getSourceFiles(), filesToAnalyzeCompletely, JetControlFlowDataTraceFactory.EMPTY,
- configuration.getCompilerDependencies());
+ analyzerWithCompilerReport.analyzeAndReport(
+ new Function0() {
+ @NotNull
+ @Override
+ public AnalyzeExhaust invoke() {
+ return AnalyzerFacadeForJVM.analyzeFilesWithJavaIntegration(
+ environment.getProject(), environment.getSourceFiles(), filesToAnalyzeCompletely,
+ JetControlFlowDataTraceFactory.EMPTY,
+ configuration.getCompilerDependencies());
+ }
+ }, environment.getSourceFiles()
+ );
- for (Diagnostic diagnostic : exhaust.getBindingContext().getDiagnostics()) {
- reportDiagnostic(messageCollectorWrapper, diagnostic);
- }
-
- reportIncompleteHierarchies(messageCollectorWrapper, exhaust);
-
- return hasErrors.get() ? null : exhaust;
+ return analyzerWithCompilerReport.hasErrors() ? null : analyzerWithCompilerReport.getAnalyzeExhaust();
}
@NotNull
private static GenerationState generate(
final CompileEnvironmentConfiguration configuration,
-
AnalyzeExhaust exhaust,
-
boolean stubs) {
JetCoreEnvironment environment = configuration.getEnvironment();
Project project = environment.getProject();
@@ -304,7 +266,8 @@ public class KotlinToJVMBytecodeCompiler {
}
};
GenerationState generationState = new GenerationState(project, ClassBuilderFactories.binaries(stubs), backendProgress,
- exhaust, environment.getSourceFiles(), configuration.getCompilerDependencies().getCompilerSpecialMode());
+ exhaust, environment.getSourceFiles(),
+ configuration.getCompilerDependencies().getCompilerSpecialMode());
generationState.compileCorrectFiles(CompilationErrorHandler.THROW_EXCEPTION);
List plugins = configuration.getCompilerPlugins();
@@ -316,35 +279,4 @@ public class KotlinToJVMBytecodeCompiler {
}
return generationState;
}
-
- private static void reportDiagnostic(MessageCollector collector, Diagnostic diagnostic) {
- DiagnosticUtils.LineAndColumn lineAndColumn = DiagnosticUtils.getLineAndColumn(diagnostic);
- VirtualFile virtualFile = diagnostic.getPsiFile().getVirtualFile();
- String path = virtualFile == null ? null : virtualFile.getPath();
- collector.report(convertSeverity(diagnostic.getSeverity()), diagnostic.getMessage(), CompilerMessageLocation.create(path, lineAndColumn.getLine(), lineAndColumn.getColumn()));
- }
-
- private static CompilerMessageSeverity convertSeverity(Severity severity) {
- switch (severity) {
- case INFO:
- return CompilerMessageSeverity.INFO;
- case ERROR:
- return CompilerMessageSeverity.ERROR;
- case WARNING:
- return CompilerMessageSeverity.WARNING;
- }
- throw new IllegalStateException("Unknown severity: " + severity);
- }
-
- private static void reportIncompleteHierarchies(MessageCollector collector, AnalyzeExhaust exhaust) {
- Collection incompletes = exhaust.getBindingContext().getKeys(BindingContext.INCOMPLETE_HIERARCHY);
- if (!incompletes.isEmpty()) {
- StringBuilder message = new StringBuilder("The following classes have incomplete hierarchies:\n");
- for (ClassDescriptor incomplete : incompletes) {
- String fqName = DescriptorUtils.getFQName(incomplete).getFqName();
- message.append(" ").append(fqName).append("\n");
- }
- collector.report(CompilerMessageSeverity.ERROR, message.toString(), CompilerMessageLocation.NO_LOCATION);
- }
- }
}
diff --git a/compiler/cli/src/org/jetbrains/jet/compiler/ModuleExecutionException.java b/compiler/cli/src/org/jetbrains/jet/cli/jvm/compiler/ModuleExecutionException.java
similarity index 95%
rename from compiler/cli/src/org/jetbrains/jet/compiler/ModuleExecutionException.java
rename to compiler/cli/src/org/jetbrains/jet/cli/jvm/compiler/ModuleExecutionException.java
index 67e7a05ea34..e20d73888fd 100644
--- a/compiler/cli/src/org/jetbrains/jet/compiler/ModuleExecutionException.java
+++ b/compiler/cli/src/org/jetbrains/jet/cli/jvm/compiler/ModuleExecutionException.java
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-package org.jetbrains.jet.compiler;
+package org.jetbrains.jet.cli.jvm.compiler;
/**
* @author yole
diff --git a/compiler/frontend.java/src/org/jetbrains/jet/di/InjectorForJavaSemanticServices.java b/compiler/frontend.java/src/org/jetbrains/jet/di/InjectorForJavaSemanticServices.java
index 7ff65b75d00..a3fe4e74de8 100644
--- a/compiler/frontend.java/src/org/jetbrains/jet/di/InjectorForJavaSemanticServices.java
+++ b/compiler/frontend.java/src/org/jetbrains/jet/di/InjectorForJavaSemanticServices.java
@@ -31,6 +31,7 @@ import org.jetbrains.jet.lang.resolve.NamespaceFactoryImpl;
import org.jetbrains.jet.lang.resolve.java.CompilerDependencies;
import com.intellij.openapi.project.Project;
import org.jetbrains.annotations.NotNull;
+import javax.annotation.PreDestroy;
/* This file is generated by org.jetbrains.jet.di.AllInjectorsGenerator. DO NOT EDIT! */
public class InjectorForJavaSemanticServices {
@@ -38,8 +39,14 @@ public class InjectorForJavaSemanticServices {
private JavaSemanticServices javaSemanticServices;
private JavaDescriptorResolver javaDescriptorResolver;
private BindingTrace bindingTrace;
+ private JavaBridgeConfiguration javaBridgeConfiguration;
private PsiClassFinderForJvm psiClassFinderForJvm;
+ private ModuleDescriptor moduleDescriptor;
+ private final CompilerDependencies compilerDependencies;
+ private CompilerSpecialMode compilerSpecialMode;
private final Project project;
+ private JavaTypeTransformer javaTypeTransformer;
+ private NamespaceFactoryImpl namespaceFactoryImpl;
public InjectorForJavaSemanticServices(
@NotNull CompilerDependencies compilerDependencies,
@@ -48,13 +55,14 @@ public class InjectorForJavaSemanticServices {
this.javaSemanticServices = new JavaSemanticServices();
this.javaDescriptorResolver = new JavaDescriptorResolver();
this.bindingTrace = new org.jetbrains.jet.lang.resolve.BindingTraceContext();
- JavaBridgeConfiguration javaBridgeConfiguration = new JavaBridgeConfiguration();
+ this.javaBridgeConfiguration = new JavaBridgeConfiguration();
this.psiClassFinderForJvm = new PsiClassFinderForJvm();
- ModuleDescriptor moduleDescriptor = new org.jetbrains.jet.lang.descriptors.ModuleDescriptor("");
- CompilerSpecialMode compilerSpecialMode = compilerDependencies.getCompilerSpecialMode();
+ this.moduleDescriptor = new org.jetbrains.jet.lang.descriptors.ModuleDescriptor("");
+ this.compilerDependencies = compilerDependencies;
+ this.compilerSpecialMode = compilerDependencies.getCompilerSpecialMode();
this.project = project;
- JavaTypeTransformer javaTypeTransformer = new JavaTypeTransformer();
- NamespaceFactoryImpl namespaceFactoryImpl = new NamespaceFactoryImpl();
+ this.javaTypeTransformer = new JavaTypeTransformer();
+ this.namespaceFactoryImpl = new NamespaceFactoryImpl();
this.javaSemanticServices.setDescriptorResolver(javaDescriptorResolver);
this.javaSemanticServices.setPsiClassFinder(psiClassFinderForJvm);
@@ -87,6 +95,10 @@ public class InjectorForJavaSemanticServices {
}
+ @PreDestroy
+ public void destroy() {
+ }
+
public JavaSemanticServices getJavaSemanticServices() {
return this.javaSemanticServices;
}
diff --git a/compiler/frontend.java/src/org/jetbrains/jet/di/InjectorForTopDownAnalyzerForJvm.java b/compiler/frontend.java/src/org/jetbrains/jet/di/InjectorForTopDownAnalyzerForJvm.java
index f90be7eefc1..69366baf299 100644
--- a/compiler/frontend.java/src/org/jetbrains/jet/di/InjectorForTopDownAnalyzerForJvm.java
+++ b/compiler/frontend.java/src/org/jetbrains/jet/di/InjectorForTopDownAnalyzerForJvm.java
@@ -55,6 +55,7 @@ import org.jetbrains.jet.lang.descriptors.ModuleDescriptor;
import org.jetbrains.jet.lang.cfg.pseudocode.JetControlFlowDataTraceFactory;
import org.jetbrains.jet.lang.resolve.java.CompilerDependencies;
import org.jetbrains.annotations.NotNull;
+import javax.annotation.PreDestroy;
/* This file is generated by org.jetbrains.jet.di.AllInjectorsGenerator. DO NOT EDIT! */
public class InjectorForTopDownAnalyzerForJvm {
@@ -68,7 +69,28 @@ public class InjectorForTopDownAnalyzerForJvm {
private final Project project;
private final TopDownAnalysisParameters topDownAnalysisParameters;
private final ObservableBindingTrace observableBindingTrace;
+ private final ModuleDescriptor moduleDescriptor;
+ private final JetControlFlowDataTraceFactory jetControlFlowDataTraceFactory;
+ private final CompilerDependencies compilerDependencies;
+ private CompilerSpecialMode compilerSpecialMode;
private JavaBridgeConfiguration javaBridgeConfiguration;
+ private PsiClassFinderForJvm psiClassFinderForJvm;
+ private DeclarationResolver declarationResolver;
+ private AnnotationResolver annotationResolver;
+ private CallResolver callResolver;
+ private ExpressionTypingServices expressionTypingServices;
+ private TypeResolver typeResolver;
+ private QualifiedExpressionResolver qualifiedExpressionResolver;
+ private OverloadingConflictResolver overloadingConflictResolver;
+ private ImportsResolver importsResolver;
+ private DelegationResolver delegationResolver;
+ private NamespaceFactoryImpl namespaceFactoryImpl;
+ private OverloadResolver overloadResolver;
+ private OverrideResolver overrideResolver;
+ private TypeHierarchyResolver typeHierarchyResolver;
+ private JavaSemanticServices javaSemanticServices;
+ private JavaDescriptorResolver javaDescriptorResolver;
+ private JavaTypeTransformer javaTypeTransformer;
public InjectorForTopDownAnalyzerForJvm(
@NotNull Project project,
@@ -87,25 +109,28 @@ public class InjectorForTopDownAnalyzerForJvm {
this.project = project;
this.topDownAnalysisParameters = topDownAnalysisParameters;
this.observableBindingTrace = observableBindingTrace;
- CompilerSpecialMode compilerSpecialMode = compilerDependencies.getCompilerSpecialMode();
+ this.moduleDescriptor = moduleDescriptor;
+ this.jetControlFlowDataTraceFactory = jetControlFlowDataTraceFactory;
+ this.compilerDependencies = compilerDependencies;
+ this.compilerSpecialMode = compilerDependencies.getCompilerSpecialMode();
this.javaBridgeConfiguration = new JavaBridgeConfiguration();
- PsiClassFinderForJvm psiClassFinderForJvm = new PsiClassFinderForJvm();
- DeclarationResolver declarationResolver = new DeclarationResolver();
- AnnotationResolver annotationResolver = new AnnotationResolver();
- CallResolver callResolver = new CallResolver();
- ExpressionTypingServices expressionTypingServices = new ExpressionTypingServices();
- TypeResolver typeResolver = new TypeResolver();
- QualifiedExpressionResolver qualifiedExpressionResolver = new QualifiedExpressionResolver();
- OverloadingConflictResolver overloadingConflictResolver = new OverloadingConflictResolver();
- ImportsResolver importsResolver = new ImportsResolver();
- DelegationResolver delegationResolver = new DelegationResolver();
- NamespaceFactoryImpl namespaceFactoryImpl = new NamespaceFactoryImpl();
- OverloadResolver overloadResolver = new OverloadResolver();
- OverrideResolver overrideResolver = new OverrideResolver();
- TypeHierarchyResolver typeHierarchyResolver = new TypeHierarchyResolver();
- JavaSemanticServices javaSemanticServices = new JavaSemanticServices();
- JavaDescriptorResolver javaDescriptorResolver = new JavaDescriptorResolver();
- JavaTypeTransformer javaTypeTransformer = new JavaTypeTransformer();
+ this.psiClassFinderForJvm = new PsiClassFinderForJvm();
+ this.declarationResolver = new DeclarationResolver();
+ this.annotationResolver = new AnnotationResolver();
+ this.callResolver = new CallResolver();
+ this.expressionTypingServices = new ExpressionTypingServices();
+ this.typeResolver = new TypeResolver();
+ this.qualifiedExpressionResolver = new QualifiedExpressionResolver();
+ this.overloadingConflictResolver = new OverloadingConflictResolver();
+ this.importsResolver = new ImportsResolver();
+ this.delegationResolver = new DelegationResolver();
+ this.namespaceFactoryImpl = new NamespaceFactoryImpl();
+ this.overloadResolver = new OverloadResolver();
+ this.overrideResolver = new OverrideResolver();
+ this.typeHierarchyResolver = new TypeHierarchyResolver();
+ this.javaSemanticServices = new JavaSemanticServices();
+ this.javaDescriptorResolver = new JavaDescriptorResolver();
+ this.javaTypeTransformer = new JavaTypeTransformer();
this.topDownAnalyzer.setBodyResolver(bodyResolver);
this.topDownAnalyzer.setContext(topDownAnalysisContext);
@@ -217,6 +242,10 @@ public class InjectorForTopDownAnalyzerForJvm {
}
+ @PreDestroy
+ public void destroy() {
+ }
+
public TopDownAnalyzer getTopDownAnalyzer() {
return this.topDownAnalyzer;
}
diff --git a/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/AnalyzerFacadeForJVM.java b/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/AnalyzerFacadeForJVM.java
index 05fef231d78..97875e8ee8a 100644
--- a/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/AnalyzerFacadeForJVM.java
+++ b/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/AnalyzerFacadeForJVM.java
@@ -95,9 +95,13 @@ public enum AnalyzerFacadeForJVM implements AnalyzerFacade {
compilerDependencies);
- injector.getTopDownAnalyzer().analyzeFiles(files);
+ try {
+ injector.getTopDownAnalyzer().analyzeFiles(files);
- return AnalyzeExhaust.success(bindingTraceContext.getBindingContext(), JetStandardLibrary.getInstance());
+ return AnalyzeExhaust.success(bindingTraceContext.getBindingContext(), JetStandardLibrary.getInstance());
+ } finally {
+ injector.destroy();
+ }
}
public static AnalyzeExhaust shallowAnalyzeFiles(Collection files,
diff --git a/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/CompilerDependencies.java b/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/CompilerDependencies.java
index caea1d27035..05075e34c10 100644
--- a/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/CompilerDependencies.java
+++ b/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/CompilerDependencies.java
@@ -33,12 +33,15 @@ public class CompilerDependencies {
@NotNull
private final CompilerSpecialMode compilerSpecialMode;
@Nullable
+ private final File jdkJar;
+ @Nullable
private final File jdkHeadersJar;
@Nullable
private final File runtimeJar;
- public CompilerDependencies(@NotNull CompilerSpecialMode compilerSpecialMode, @Nullable File jdkHeadersJar, @Nullable File runtimeJar) {
+ public CompilerDependencies(@NotNull CompilerSpecialMode compilerSpecialMode, @Nullable File jdkJar, @Nullable File jdkHeadersJar, @Nullable File runtimeJar) {
this.compilerSpecialMode = compilerSpecialMode;
+ this.jdkJar = jdkJar;
this.jdkHeadersJar = jdkHeadersJar;
this.runtimeJar = runtimeJar;
@@ -59,6 +62,11 @@ public class CompilerDependencies {
return compilerSpecialMode;
}
+ @Nullable
+ public File getJdkJar() {
+ return jdkJar;
+ }
+
@Nullable
public File getJdkHeadersJar() {
return jdkHeadersJar;
@@ -93,8 +101,36 @@ public class CompilerDependencies {
public static CompilerDependencies compilerDependenciesForProduction(@NotNull CompilerSpecialMode compilerSpecialMode) {
return new CompilerDependencies(
compilerSpecialMode,
+ findRtJar(),
compilerSpecialMode.includeJdkHeaders() ? PathUtil.getAltHeadersPath() : null,
compilerSpecialMode.includeKotlinRuntime() ? PathUtil.getDefaultRuntimePath() : null);
}
+ public static File findRtJar() {
+ String javaHome = System.getProperty("java.home");
+ if ("jre".equals(new File(javaHome).getName())) {
+ javaHome = new File(javaHome).getParent();
+ }
+
+ File rtJar = findRtJar(javaHome);
+
+ if (rtJar == null || !rtJar.exists()) {
+ throw new IllegalArgumentException("No JDK rt.jar found under " + javaHome);
+ }
+
+ return rtJar;
+ }
+
+ private static File findRtJar(String javaHome) {
+ File rtJar = new File(javaHome, "jre/lib/rt.jar");
+ if (rtJar.exists()) {
+ return rtJar;
+ }
+
+ File classesJar = new File(new File(javaHome).getParentFile().getAbsolutePath(), "Classes/classes.jar");
+ if (classesJar.exists()) {
+ return classesJar;
+ }
+ return null;
+ }
}
diff --git a/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/JavaDescriptorResolver.java b/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/JavaDescriptorResolver.java
index 9f8015a8b06..556323eed38 100644
--- a/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/JavaDescriptorResolver.java
+++ b/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/JavaDescriptorResolver.java
@@ -76,7 +76,6 @@ import org.jetbrains.jet.lang.psi.JetPsiUtil;
import org.jetbrains.jet.lang.resolve.BindingContext;
import org.jetbrains.jet.lang.resolve.BindingContextUtils;
import org.jetbrains.jet.lang.resolve.BindingTrace;
-import org.jetbrains.jet.lang.resolve.BindingTraceContext;
import org.jetbrains.jet.lang.resolve.DescriptorUtils;
import org.jetbrains.jet.lang.resolve.FqName;
import org.jetbrains.jet.lang.resolve.NamespaceFactory;
@@ -93,7 +92,6 @@ import org.jetbrains.jet.lang.resolve.constants.NullValue;
import org.jetbrains.jet.lang.resolve.constants.ShortValue;
import org.jetbrains.jet.lang.resolve.constants.StringValue;
import org.jetbrains.jet.lang.resolve.java.kt.JetClassAnnotation;
-import org.jetbrains.jet.lang.types.DeferredType;
import org.jetbrains.jet.lang.types.ErrorUtils;
import org.jetbrains.jet.lang.types.JetType;
import org.jetbrains.jet.lang.types.TypeSubstitutor;
@@ -105,7 +103,6 @@ import org.jetbrains.jet.rt.signature.JetSignatureAdapter;
import org.jetbrains.jet.rt.signature.JetSignatureExceptionsAdapter;
import org.jetbrains.jet.rt.signature.JetSignatureReader;
import org.jetbrains.jet.rt.signature.JetSignatureVisitor;
-import org.jetbrains.jet.util.lazy.LazyValue;
import javax.inject.Inject;
import java.util.ArrayList;
@@ -209,11 +206,9 @@ public class JavaDescriptorResolver {
final PsiClass psiClass;
@Nullable
final PsiPackage psiPackage;
- @NotNull
final FqName fqName;
final boolean staticMembers;
final boolean kotlin;
- @NotNull
final ClassOrNamespaceDescriptor classOrNamespaceDescriptor;
protected ResolverScopeData(@Nullable PsiClass psiClass, @Nullable PsiPackage psiPackage, @NotNull FqName fqName, boolean staticMembers, @NotNull ClassOrNamespaceDescriptor descriptor) {
@@ -237,6 +232,22 @@ public class JavaDescriptorResolver {
classOrNamespaceDescriptor = descriptor;
}
+ protected ResolverScopeData(boolean negative) {
+ if (!negative) {
+ throw new IllegalStateException();
+ }
+ this.psiClass = null;
+ this.psiPackage = null;
+ this.fqName = null;
+ this.staticMembers = false;
+ this.kotlin = false;
+ this.classOrNamespaceDescriptor = null;
+ }
+
+ public boolean isPositive() {
+ return this.classOrNamespaceDescriptor != null;
+ }
+
@NotNull
public PsiElement getPsiPackageOrPsiClass() {
if (psiPackage != null) {
@@ -262,6 +273,13 @@ public class JavaDescriptorResolver {
this.classDescriptor = classDescriptor;
}
+ private ResolverBinaryClassData(boolean negative) {
+ super(negative);
+ this.classDescriptor = null;
+ }
+
+ static final ResolverBinaryClassData NEGATIVE = new ResolverBinaryClassData(true);
+
List typeParameters;
@NotNull
@@ -286,6 +304,13 @@ public class JavaDescriptorResolver {
this.namespaceDescriptor = namespaceDescriptor;
}
+ private ResolverNamespaceData(boolean negative) {
+ super(negative);
+ this.namespaceDescriptor = null;
+ }
+
+ static final ResolverNamespaceData NEGATIVE = new ResolverNamespaceData(true);
+
private JavaPackageScope memberScope;
@NotNull
@@ -374,13 +399,18 @@ public class JavaDescriptorResolver {
if (classData == null) {
PsiClass psiClass = psiClassFinder.findPsiClass(qualifiedName, PsiClassFinder.RuntimeClassesHandleMode.THROW);
if (psiClass == null) {
+ ResolverBinaryClassData oldValue = classDescriptorCache.put(qualifiedName, ResolverBinaryClassData.NEGATIVE);
+ if (oldValue != null) {
+ throw new IllegalStateException("rewrite at " + qualifiedName);
+ }
return null;
}
classData = createJavaClassDescriptor(psiClass, tasks);
}
- return classData.getClassDescriptor();
+ return classData.classDescriptor;
}
+ @NotNull
private ResolverBinaryClassData createJavaClassDescriptor(@NotNull final PsiClass psiClass, List taskList) {
FqName fqName = new FqName(psiClass.getQualifiedName());
if (classDescriptorCache.containsKey(fqName)) {
@@ -392,18 +422,21 @@ public class JavaDescriptorResolver {
String name = psiClass.getName();
ClassKind kind = psiClass.isInterface() ? (psiClass.isAnnotationType() ? ClassKind.ANNOTATION_CLASS : ClassKind.TRAIT) : ClassKind.CLASS;
ClassOrNamespaceDescriptor containingDeclaration = resolveParentDescriptor(psiClass);
- ResolverBinaryClassData classData = new ResolverBinaryClassData(psiClass, fqName, new MutableClassDescriptorLite(containingDeclaration, kind));
+
+ // class may be resolved during resolution of parent
+ ResolverBinaryClassData classData = classDescriptorCache.get(fqName);
+ if (classData != null) {
+ return classData;
+ }
+
+ classData = new ResolverBinaryClassData(psiClass, fqName, new MutableClassDescriptorLite(containingDeclaration, kind));
classDescriptorCache.put(fqName, classData);
classData.classDescriptor.setName(name);
classData.classDescriptor.setAnnotations(resolveAnnotations(psiClass, taskList));
List supertypes = new ArrayList();
- TypeVariableResolver outerTypeVariableByNameResolver = TypeVariableResolvers.classTypeVariableResolver(
- (ClassOrNamespaceDescriptor) classData.classDescriptor.getContainingDeclaration(),
- "class " + psiClass.getQualifiedName());
-
- classData.typeParameters = createUninitializedClassTypeParameters(psiClass, classData, outerTypeVariableByNameResolver);
+ classData.typeParameters = createUninitializedClassTypeParameters(psiClass, classData);
List typeParameters = new ArrayList();
for (TypeParameterDescriptorInitialization typeParameter : classData.typeParameters) {
@@ -583,7 +616,7 @@ public class JavaDescriptorResolver {
return classData.classDescriptor;
}
- private List createUninitializedClassTypeParameters(PsiClass psiClass, ResolverBinaryClassData classData, TypeVariableResolver typeVariableResolver) {
+ private List createUninitializedClassTypeParameters(PsiClass psiClass, ResolverBinaryClassData classData) {
JetClassAnnotation jetClassAnnotation = JetClassAnnotation.get(psiClass);
if (jetClassAnnotation.signature().length() > 0) {
@@ -974,6 +1007,10 @@ public class JavaDescriptorResolver {
break lookingForPsi;
}
+ ResolverNamespaceData oldValue = namespaceDescriptorCacheByFqn.put(fqName, ResolverNamespaceData.NEGATIVE);
+ if (oldValue != null) {
+ throw new IllegalStateException("rewrite at " + fqName);
+ }
return null;
}
diff --git a/compiler/frontend/src/org/jetbrains/jet/checkers/CheckerTestUtil.java b/compiler/frontend/src/org/jetbrains/jet/checkers/CheckerTestUtil.java
index 88e8988b2c5..3cf3bedd3f3 100644
--- a/compiler/frontend/src/org/jetbrains/jet/checkers/CheckerTestUtil.java
+++ b/compiler/frontend/src/org/jetbrains/jet/checkers/CheckerTestUtil.java
@@ -320,12 +320,6 @@ public class CheckerTestUtil {
return SyntaxErrorDiagnosticFactory.instance;
}
- @NotNull
- @Override
- public String getMessage() {
- throw new IllegalStateException();
- }
-
@NotNull
@Override
public Severity getSeverity() {
diff --git a/compiler/frontend/src/org/jetbrains/jet/di/InjectorForMacros.java b/compiler/frontend/src/org/jetbrains/jet/di/InjectorForMacros.java
index ca570d75b93..23020ab2793 100644
--- a/compiler/frontend/src/org/jetbrains/jet/di/InjectorForMacros.java
+++ b/compiler/frontend/src/org/jetbrains/jet/di/InjectorForMacros.java
@@ -27,24 +27,31 @@ import org.jetbrains.jet.lang.resolve.QualifiedExpressionResolver;
import org.jetbrains.jet.lang.resolve.calls.OverloadingConflictResolver;
import com.intellij.openapi.project.Project;
import org.jetbrains.annotations.NotNull;
+import javax.annotation.PreDestroy;
/* This file is generated by org.jetbrains.jet.di.AllInjectorsGenerator. DO NOT EDIT! */
public class InjectorForMacros {
private ExpressionTypingServices expressionTypingServices;
private final Project project;
+ private CallResolver callResolver;
+ private DescriptorResolver descriptorResolver;
+ private AnnotationResolver annotationResolver;
+ private TypeResolver typeResolver;
+ private QualifiedExpressionResolver qualifiedExpressionResolver;
+ private OverloadingConflictResolver overloadingConflictResolver;
public InjectorForMacros(
@NotNull Project project
) {
this.expressionTypingServices = new ExpressionTypingServices();
this.project = project;
- CallResolver callResolver = new CallResolver();
- DescriptorResolver descriptorResolver = new DescriptorResolver();
- AnnotationResolver annotationResolver = new AnnotationResolver();
- TypeResolver typeResolver = new TypeResolver();
- QualifiedExpressionResolver qualifiedExpressionResolver = new QualifiedExpressionResolver();
- OverloadingConflictResolver overloadingConflictResolver = new OverloadingConflictResolver();
+ this.callResolver = new CallResolver();
+ this.descriptorResolver = new DescriptorResolver();
+ this.annotationResolver = new AnnotationResolver();
+ this.typeResolver = new TypeResolver();
+ this.qualifiedExpressionResolver = new QualifiedExpressionResolver();
+ this.overloadingConflictResolver = new OverloadingConflictResolver();
this.expressionTypingServices.setCallResolver(callResolver);
this.expressionTypingServices.setDescriptorResolver(descriptorResolver);
@@ -69,6 +76,10 @@ public class InjectorForMacros {
}
+ @PreDestroy
+ public void destroy() {
+ }
+
public ExpressionTypingServices getExpressionTypingServices() {
return this.expressionTypingServices;
}
diff --git a/compiler/frontend/src/org/jetbrains/jet/di/InjectorForTopDownAnalyzerBasic.java b/compiler/frontend/src/org/jetbrains/jet/di/InjectorForTopDownAnalyzerBasic.java
index 7c8405cfa5a..569ef4f592c 100644
--- a/compiler/frontend/src/org/jetbrains/jet/di/InjectorForTopDownAnalyzerBasic.java
+++ b/compiler/frontend/src/org/jetbrains/jet/di/InjectorForTopDownAnalyzerBasic.java
@@ -49,6 +49,7 @@ import org.jetbrains.jet.lang.descriptors.ModuleDescriptor;
import org.jetbrains.jet.lang.cfg.pseudocode.JetControlFlowDataTraceFactory;
import org.jetbrains.jet.lang.ModuleConfiguration;
import org.jetbrains.annotations.NotNull;
+import javax.annotation.PreDestroy;
/* This file is generated by org.jetbrains.jet.di.AllInjectorsGenerator. DO NOT EDIT! */
public class InjectorForTopDownAnalyzerBasic {
@@ -62,6 +63,22 @@ public class InjectorForTopDownAnalyzerBasic {
private final Project project;
private final TopDownAnalysisParameters topDownAnalysisParameters;
private final ObservableBindingTrace observableBindingTrace;
+ private final ModuleDescriptor moduleDescriptor;
+ private final JetControlFlowDataTraceFactory jetControlFlowDataTraceFactory;
+ private final ModuleConfiguration moduleConfiguration;
+ private DeclarationResolver declarationResolver;
+ private AnnotationResolver annotationResolver;
+ private CallResolver callResolver;
+ private ExpressionTypingServices expressionTypingServices;
+ private TypeResolver typeResolver;
+ private QualifiedExpressionResolver qualifiedExpressionResolver;
+ private OverloadingConflictResolver overloadingConflictResolver;
+ private ImportsResolver importsResolver;
+ private DelegationResolver delegationResolver;
+ private NamespaceFactoryImpl namespaceFactoryImpl;
+ private OverloadResolver overloadResolver;
+ private OverrideResolver overrideResolver;
+ private TypeHierarchyResolver typeHierarchyResolver;
public InjectorForTopDownAnalyzerBasic(
@NotNull Project project,
@@ -80,19 +97,22 @@ public class InjectorForTopDownAnalyzerBasic {
this.project = project;
this.topDownAnalysisParameters = topDownAnalysisParameters;
this.observableBindingTrace = observableBindingTrace;
- DeclarationResolver declarationResolver = new DeclarationResolver();
- AnnotationResolver annotationResolver = new AnnotationResolver();
- CallResolver callResolver = new CallResolver();
- ExpressionTypingServices expressionTypingServices = new ExpressionTypingServices();
- TypeResolver typeResolver = new TypeResolver();
- QualifiedExpressionResolver qualifiedExpressionResolver = new QualifiedExpressionResolver();
- OverloadingConflictResolver overloadingConflictResolver = new OverloadingConflictResolver();
- ImportsResolver importsResolver = new ImportsResolver();
- DelegationResolver delegationResolver = new DelegationResolver();
- NamespaceFactoryImpl namespaceFactoryImpl = new NamespaceFactoryImpl();
- OverloadResolver overloadResolver = new OverloadResolver();
- OverrideResolver overrideResolver = new OverrideResolver();
- TypeHierarchyResolver typeHierarchyResolver = new TypeHierarchyResolver();
+ this.moduleDescriptor = moduleDescriptor;
+ this.jetControlFlowDataTraceFactory = jetControlFlowDataTraceFactory;
+ this.moduleConfiguration = moduleConfiguration;
+ this.declarationResolver = new DeclarationResolver();
+ this.annotationResolver = new AnnotationResolver();
+ this.callResolver = new CallResolver();
+ this.expressionTypingServices = new ExpressionTypingServices();
+ this.typeResolver = new TypeResolver();
+ this.qualifiedExpressionResolver = new QualifiedExpressionResolver();
+ this.overloadingConflictResolver = new OverloadingConflictResolver();
+ this.importsResolver = new ImportsResolver();
+ this.delegationResolver = new DelegationResolver();
+ this.namespaceFactoryImpl = new NamespaceFactoryImpl();
+ this.overloadResolver = new OverloadResolver();
+ this.overrideResolver = new OverrideResolver();
+ this.typeHierarchyResolver = new TypeHierarchyResolver();
this.topDownAnalyzer.setBodyResolver(bodyResolver);
this.topDownAnalyzer.setContext(topDownAnalysisContext);
@@ -179,6 +199,10 @@ public class InjectorForTopDownAnalyzerBasic {
}
+ @PreDestroy
+ public void destroy() {
+ }
+
public TopDownAnalyzer getTopDownAnalyzer() {
return this.topDownAnalyzer;
}
diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/AbstractDiagnostic.java b/compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/AbstractDiagnostic.java
index 3e1622aa486..33450c87fe2 100644
--- a/compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/AbstractDiagnostic.java
+++ b/compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/AbstractDiagnostic.java
@@ -25,15 +25,15 @@ import org.jetbrains.annotations.NotNull;
*/
public abstract class AbstractDiagnostic implements ParametrizedDiagnostic {
private final E psiElement;
- private final String message;
private final AbstractDiagnosticFactory factory;
private final Severity severity;
- public AbstractDiagnostic(@NotNull E psiElement, @NotNull AbstractDiagnosticFactory factory, @NotNull Severity severity, @NotNull String message) {
+ public AbstractDiagnostic(@NotNull E psiElement,
+ @NotNull AbstractDiagnosticFactory factory,
+ @NotNull Severity severity) {
this.psiElement = psiElement;
this.factory = factory;
this.severity = severity;
- this.message = message;
}
@NotNull
@@ -48,19 +48,12 @@ public abstract class AbstractDiagnostic implements Parame
return psiElement.getContainingFile();
}
- @NotNull
- @Override
- public String getMessage() {
- return message;
- }
-
@NotNull
@Override
public Severity getSeverity() {
return severity;
}
-
@Override
@NotNull
public E getPsiElement() {
diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/AbstractDiagnosticFactory.java b/compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/AbstractDiagnosticFactory.java
index 8d6198a8a58..aeebc9f633f 100644
--- a/compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/AbstractDiagnosticFactory.java
+++ b/compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/AbstractDiagnosticFactory.java
@@ -19,7 +19,7 @@ package org.jetbrains.jet.lang.diagnostics;
/**
* @author abreslav
*/
-public class AbstractDiagnosticFactory {
+public abstract class AbstractDiagnosticFactory {
private String name = null;
diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/AmbiguousDescriptorDiagnosticFactory.java b/compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/AmbiguousDescriptorDiagnosticFactory.java
index 57cf016fdb4..809012d233b 100644
--- a/compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/AmbiguousDescriptorDiagnosticFactory.java
+++ b/compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/AmbiguousDescriptorDiagnosticFactory.java
@@ -17,11 +17,8 @@
package org.jetbrains.jet.lang.diagnostics;
import com.intellij.psi.PsiElement;
-import org.jetbrains.annotations.NotNull;
-import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.lang.descriptors.CallableDescriptor;
import org.jetbrains.jet.lang.resolve.calls.ResolvedCall;
-import org.jetbrains.jet.resolve.DescriptorRenderer;
import java.util.Collection;
@@ -29,24 +26,11 @@ import java.util.Collection;
* @author abreslav
*/
public class AmbiguousDescriptorDiagnosticFactory extends DiagnosticFactory1>> {
- public static AmbiguousDescriptorDiagnosticFactory create(String messageTemplate) {
- return new AmbiguousDescriptorDiagnosticFactory(messageTemplate);
+ public static AmbiguousDescriptorDiagnosticFactory create() {
+ return new AmbiguousDescriptorDiagnosticFactory();
}
- public AmbiguousDescriptorDiagnosticFactory(String messageTemplate) {
- super(Severity.ERROR, messageTemplate, PositioningStrategies.DEFAULT, AMBIGUOUS_DESCRIPTOR_RENDERER);
+ public AmbiguousDescriptorDiagnosticFactory() {
+ super(Severity.ERROR, PositioningStrategies.DEFAULT);
}
-
- private static Renderer>> AMBIGUOUS_DESCRIPTOR_RENDERER =
- new Renderer>>() {
- @NotNull
- @Override
- public String render(@Nullable Collection extends ResolvedCall extends CallableDescriptor>> argument) {
- StringBuilder stringBuilder = new StringBuilder("\n");
- for (ResolvedCall extends CallableDescriptor> call : argument) {
- stringBuilder.append(DescriptorRenderer.TEXT.render(call.getResultingDescriptor())).append("\n");
- }
- return stringBuilder.toString();
- }
- };
}
diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/Diagnostic.java b/compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/Diagnostic.java
index d4369a0513d..8fcfbf18762 100644
--- a/compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/Diagnostic.java
+++ b/compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/Diagnostic.java
@@ -31,9 +31,6 @@ public interface Diagnostic {
@NotNull
AbstractDiagnosticFactory getFactory();
- @NotNull
- String getMessage();
-
@NotNull
Severity getSeverity();
diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/DiagnosticFactory.java b/compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/DiagnosticFactory.java
deleted file mode 100644
index 5e893eef3f1..00000000000
--- a/compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/DiagnosticFactory.java
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
- * 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.diagnostics;
-
-import com.intellij.psi.PsiElement;
-import org.jetbrains.annotations.NotNull;
-
-/**
- * @author svtk
- */
-public class DiagnosticFactory extends DiagnosticFactoryWithPsiElement {
- protected final String message;
-
- protected DiagnosticFactory(Severity severity, String message, PositioningStrategy super E> positioningStrategy) {
- super(severity, positioningStrategy);
- this.message = message;
- }
-
- public static DiagnosticFactory create(Severity severity, String message) {
- return create(severity, message, PositioningStrategies.DEFAULT);
- }
-
- public static DiagnosticFactory create(Severity severity, String message, PositioningStrategy super T> positioningStrategy) {
- return new DiagnosticFactory(severity, message, positioningStrategy);
- }
-
- @NotNull
- public ParametrizedDiagnostic on(@NotNull E element) {
- return new DiagnosticWithPsiElement(element, this, severity, message);
- }
-}
\ No newline at end of file
diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/DiagnosticFactory1.java b/compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/DiagnosticFactory1.java
index c6e1d9d3f91..ebc4ebe4b23 100644
--- a/compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/DiagnosticFactory1.java
+++ b/compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/DiagnosticFactory1.java
@@ -22,40 +22,21 @@ import org.jetbrains.annotations.NotNull;
/**
* @author svtk
*/
-public class DiagnosticFactory1 extends DiagnosticFactoryWithMessageFormat {
- private final Renderer super A> renderer;
-
- protected String makeMessage(@NotNull A argument) {
- return messageFormat.format(new Object[]{makeMessageFor(argument)});
- }
-
- protected String makeMessageFor(@NotNull A argument) {
- return renderer.render(argument);
- }
-
+public class DiagnosticFactory1 extends DiagnosticFactoryWithPsiElement {
@NotNull
public ParametrizedDiagnostic on(@NotNull E element, @NotNull A argument) {
- return new DiagnosticWithPsiElement(element, this, severity, makeMessage(argument));
+ return new DiagnosticWithParameters1(element, argument, this, severity);
}
- protected DiagnosticFactory1(Severity severity, String message, PositioningStrategy super E> positioningStrategy, Renderer super A> renderer) {
- super(severity, message, positioningStrategy);
- this.renderer = renderer;
+ protected DiagnosticFactory1(Severity severity, PositioningStrategy super E> positioningStrategy) {
+ super(severity, positioningStrategy);
}
- public static DiagnosticFactory1 create(Severity severity, String message, PositioningStrategy super T> positioningStrategy, Renderer super A> renderer) {
- return new DiagnosticFactory1(severity, message, positioningStrategy, renderer);
+ public static DiagnosticFactory1 create(Severity severity, PositioningStrategy super T> positioningStrategy) {
+ return new DiagnosticFactory1(severity, positioningStrategy);
}
- public static DiagnosticFactory1 create(Severity severity, String message, PositioningStrategy super T> positioningStrategy) {
- return create(severity, message, positioningStrategy, Renderers.TO_STRING);
- }
-
- public static DiagnosticFactory1 create(Severity severity, String message, Renderer super A> renderer) {
- return create(severity, message, PositioningStrategies.DEFAULT, renderer);
- }
-
- public static DiagnosticFactory1 create(Severity severity, String message) {
- return create(severity, message, PositioningStrategies.DEFAULT, Renderers.TO_STRING);
+ public static DiagnosticFactory1 create(Severity severity) {
+ return create(severity, PositioningStrategies.DEFAULT);
}
}
\ No newline at end of file
diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/DiagnosticFactory2.java b/compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/DiagnosticFactory2.java
index 8eb63ff8c04..5f63a87870b 100644
--- a/compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/DiagnosticFactory2.java
+++ b/compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/DiagnosticFactory2.java
@@ -22,48 +22,23 @@ import org.jetbrains.annotations.NotNull;
/**
* @author abreslav
*/
-public class DiagnosticFactory2 extends DiagnosticFactoryWithMessageFormat {
- private final Renderer super A> rendererForA;
- private final Renderer super B> rendererForB;
-
- private String makeMessage(@NotNull A a, @NotNull B b) {
- return messageFormat.format(new Object[] {makeMessageForA(a), makeMessageForB(b)});
- }
-
- private String makeMessageForA(@NotNull A a) {
- return rendererForA.render(a);
- }
-
- private String makeMessageForB(@NotNull B b) {
- return rendererForB.render(b);
- }
+public class DiagnosticFactory2 extends DiagnosticFactoryWithPsiElement {
@NotNull
public ParametrizedDiagnostic on(@NotNull E element, @NotNull A a, @NotNull B b) {
- return new DiagnosticWithPsiElement(element, this, severity, makeMessage(a, b));
+ return new DiagnosticWithParameters2(element, a, b, this, severity);
}
-
- private DiagnosticFactory2(Severity severity, String message, PositioningStrategy super E> positioningStrategy, Renderer super A> rendererForA, Renderer super B> rendererForB) {
- super(severity, message, positioningStrategy);
- this.rendererForA = rendererForA;
- this.rendererForB = rendererForB;
+ private DiagnosticFactory2(Severity severity, PositioningStrategy super E> positioningStrategy) {
+ super(severity, positioningStrategy);
}
- public static DiagnosticFactory2 create(Severity severity, String messageStub, PositioningStrategy super T> positioningStrategy, Renderer super A> rendererForA, Renderer super B> rendererForB) {
- return new DiagnosticFactory2(severity, messageStub, positioningStrategy, rendererForA, rendererForB);
+ public static DiagnosticFactory2 create(Severity severity, PositioningStrategy super T> positioningStrategy) {
+ return new DiagnosticFactory2(severity, positioningStrategy);
}
- public static DiagnosticFactory2 create(Severity severity, String messageStub, PositioningStrategy super T> positioningStrategy) {
- return new DiagnosticFactory2(severity, messageStub, positioningStrategy, Renderers.TO_STRING, Renderers.TO_STRING);
- }
-
- public static DiagnosticFactory2 create(Severity severity, String messageStub, Renderer super A> rendererForA, Renderer super B> rendererForB) {
- return new DiagnosticFactory2(severity, messageStub, PositioningStrategies.DEFAULT, rendererForA, rendererForB);
- }
-
- public static DiagnosticFactory2 create(Severity severity, String messageStub) {
- return new DiagnosticFactory2(severity, messageStub, PositioningStrategies.DEFAULT, Renderers.TO_STRING, Renderers.TO_STRING);
+ public static DiagnosticFactory2 create(Severity severity) {
+ return new DiagnosticFactory2(severity, PositioningStrategies.DEFAULT);
}
}
diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/DiagnosticFactory3.java b/compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/DiagnosticFactory3.java
index caa5b8518e1..2bb0deb23da 100644
--- a/compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/DiagnosticFactory3.java
+++ b/compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/DiagnosticFactory3.java
@@ -22,51 +22,22 @@ import org.jetbrains.annotations.NotNull;
/**
* @author svtk
*/
-public class DiagnosticFactory3 extends DiagnosticFactoryWithMessageFormat {
- private final Renderer super A> rendererForA;
- private final Renderer super B> rendererForB;
- private final Renderer super C> rendererForC;
-
- protected DiagnosticFactory3(Severity severity, String messageStub, PositioningStrategy super E> positioningStrategy, Renderer super A> rendererForA, Renderer super B> rendererForB, Renderer super C> rendererForC) {
- super(severity, messageStub, positioningStrategy);
- this.rendererForA = rendererForA;
- this.rendererForB = rendererForB;
- this.rendererForC = rendererForC;
+public class DiagnosticFactory3 extends DiagnosticFactoryWithPsiElement {
+
+ protected DiagnosticFactory3(Severity severity, PositioningStrategy super E> positioningStrategy) {
+ super(severity, positioningStrategy);
}
- public static DiagnosticFactory3 create(Severity severity, String messageStub) {
- return create(severity, messageStub, PositioningStrategies.DEFAULT);
+ public static DiagnosticFactory3 create(Severity severity) {
+ return create(severity, PositioningStrategies.DEFAULT);
}
- public static DiagnosticFactory3 create(Severity severity, String messageStub, PositioningStrategy super T> positioningStrategy) {
- return create(severity, messageStub, positioningStrategy, Renderers.TO_STRING, Renderers.TO_STRING, Renderers.TO_STRING);
+ public static DiagnosticFactory3 create(Severity severity, PositioningStrategy super T> positioningStrategy) {
+ return new DiagnosticFactory3(severity, positioningStrategy);
}
- public static DiagnosticFactory3 create(Severity severity, String messageStub, Renderer super A> rendererForA, Renderer super B> rendererForB, Renderer super C> rendererForC) {
- return create(severity, messageStub, PositioningStrategies.DEFAULT, rendererForA, rendererForB, rendererForC);
- }
-
- public static DiagnosticFactory3 create(Severity severity, String messageStub, PositioningStrategy super T> positioningStrategy, Renderer super A> rendererForA, Renderer super B> rendererForB, Renderer super C> rendererForC) {
- return new DiagnosticFactory3(severity, messageStub, positioningStrategy, rendererForA, rendererForB, rendererForC);
- }
-
- private String makeMessage(@NotNull A a, @NotNull B b, @NotNull C c) {
- return messageFormat.format(new Object[]{makeMessageForA(a), makeMessageForB(b), makeMessageForC(c)});
- }
-
- private String makeMessageForA(@NotNull A a) {
- return rendererForA.render(a);
- }
-
- private String makeMessageForB(@NotNull B b) {
- return rendererForB.render(b);
- }
-
- private String makeMessageForC(@NotNull C c) {
- return rendererForC.render(c);
- }
@NotNull
public ParametrizedDiagnostic on(@NotNull E element, @NotNull A a, @NotNull B b, @NotNull C c) {
- return new DiagnosticWithPsiElement(element, this, severity, makeMessage(a, b, c));
+ return new DiagnosticWithParameters3(element, a, b, c, this, severity);
}
}
diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/DiagnosticFactoryWithMessageFormat.java b/compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/DiagnosticFactoryWithMessageFormat.java
deleted file mode 100644
index 9478ec5191d..00000000000
--- a/compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/DiagnosticFactoryWithMessageFormat.java
+++ /dev/null
@@ -1,37 +0,0 @@
-/*
- * 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.diagnostics;
-
-import com.intellij.psi.PsiElement;
-
-import java.text.MessageFormat;
-
-/**
-* @author abreslav
-*/
-public abstract class DiagnosticFactoryWithMessageFormat extends DiagnosticFactoryWithPsiElement {
- protected final MessageFormat messageFormat;
-
- public DiagnosticFactoryWithMessageFormat(Severity severity, String message) {
- this(severity, message, PositioningStrategies.DEFAULT);
- }
-
- public DiagnosticFactoryWithMessageFormat(Severity severity, String message, PositioningStrategy super E> positioningStrategy) {
- super(severity, positioningStrategy);
- this.messageFormat = new MessageFormat(message);
- }
-}
diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/DiagnosticHolder.java b/compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/DiagnosticHolder.java
index f0c110e14bd..c1f1472d2c5 100644
--- a/compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/DiagnosticHolder.java
+++ b/compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/DiagnosticHolder.java
@@ -17,7 +17,6 @@
package org.jetbrains.jet.lang.diagnostics;
import com.intellij.openapi.util.TextRange;
-import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiFile;
import org.jetbrains.annotations.NotNull;
@@ -38,7 +37,7 @@ public interface DiagnosticHolder {
if (diagnostic.getSeverity() == Severity.ERROR) {
PsiFile psiFile = diagnostic.getPsiFile();
List textRanges = diagnostic.getTextRanges();
- throw new IllegalStateException(diagnostic.getMessage() + DiagnosticUtils.atLocation(psiFile, textRanges.get(0)));
+ throw new IllegalStateException(diagnostic.getFactory().getName() + DiagnosticUtils.atLocation(psiFile, textRanges.get(0)));
}
}
};
diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/DiagnosticUtils.java b/compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/DiagnosticUtils.java
index 67ab02f1d5f..be456c83593 100644
--- a/compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/DiagnosticUtils.java
+++ b/compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/DiagnosticUtils.java
@@ -80,11 +80,16 @@ public class DiagnosticUtils {
@NotNull
public static LineAndColumn getLineAndColumn(@NotNull Diagnostic diagnostic) {
PsiFile file = diagnostic.getPsiFile();
- Document document = file.getViewProvider().getDocument();
List textRanges = diagnostic.getTextRanges();
if (textRanges.isEmpty()) return LineAndColumn.NONE;
TextRange firstRange = textRanges.iterator().next();
- return offsetToLineAndColumn(document, firstRange.getStartOffset());
+ return getLineAndColumnInPsiFile(file, firstRange);
+ }
+
+ @NotNull
+ public static LineAndColumn getLineAndColumnInPsiFile(PsiFile file, TextRange range) {
+ Document document = file.getViewProvider().getDocument();
+ return offsetToLineAndColumn(document, range.getStartOffset());
}
@NotNull
diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/DiagnosticWithParameters1.java b/compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/DiagnosticWithParameters1.java
new file mode 100644
index 00000000000..50976c627c4
--- /dev/null
+++ b/compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/DiagnosticWithParameters1.java
@@ -0,0 +1,56 @@
+/*
+ * 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.diagnostics;
+
+import com.intellij.openapi.util.TextRange;
+import com.intellij.psi.PsiElement;
+import org.jetbrains.annotations.NotNull;
+
+import java.util.List;
+
+/**
+ * @author Evgeny Gerashchenko
+ * @since 4/11/12
+ */
+public class DiagnosticWithParameters1 extends AbstractDiagnostic {
+ private A a;
+
+ public DiagnosticWithParameters1(@NotNull E psiElement,
+ @NotNull A a,
+ @NotNull DiagnosticFactory1 factory,
+ @NotNull Severity severity) {
+ super(psiElement, factory, severity);
+ this.a = a;
+ }
+
+ @NotNull
+ @Override
+ public DiagnosticFactory1 getFactory() {
+ return (DiagnosticFactory1)super.getFactory();
+ }
+
+ @Override
+ @NotNull
+ public List getTextRanges() {
+ return getFactory().getTextRanges(this);
+ }
+
+ @NotNull
+ public A getA() {
+ return a;
+ }
+}
diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/UnresolvedReferenceDiagnostic.java b/compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/DiagnosticWithParameters2.java
similarity index 50%
rename from compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/UnresolvedReferenceDiagnostic.java
rename to compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/DiagnosticWithParameters2.java
index 8b1f2242987..272577dcfba 100644
--- a/compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/UnresolvedReferenceDiagnostic.java
+++ b/compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/DiagnosticWithParameters2.java
@@ -17,37 +17,48 @@
package org.jetbrains.jet.lang.diagnostics;
import com.intellij.openapi.util.TextRange;
+import com.intellij.psi.PsiElement;
import org.jetbrains.annotations.NotNull;
-import org.jetbrains.jet.lang.psi.JetArrayAccessExpression;
-import org.jetbrains.jet.lang.psi.JetReferenceExpression;
-import java.util.Collections;
import java.util.List;
-import static org.jetbrains.jet.lang.diagnostics.Severity.ERROR;
-
/**
- * @author abreslav
+ * @author Evgeny Gerashchenko
+ * @since 4/11/12
*/
-public class UnresolvedReferenceDiagnostic extends AbstractDiagnostic {
+public class DiagnosticWithParameters2 extends AbstractDiagnostic {
+ private A a;
+ private B b;
- public UnresolvedReferenceDiagnostic(JetReferenceExpression referenceExpression, String message) {
- super(referenceExpression, Errors.UNRESOLVED_REFERENCE, ERROR, message);
+ public DiagnosticWithParameters2(@NotNull E psiElement,
+ @NotNull A a,
+ @NotNull B b,
+ @NotNull DiagnosticFactory2 factory,
+ @NotNull Severity severity) {
+ super(psiElement, factory, severity);
+ this.a = a;
+ this.b = b;
}
@NotNull
@Override
- public String getMessage() {
- return super.getMessage() + ": " + getPsiElement().getText();
+ public DiagnosticFactory2 getFactory() {
+ return (DiagnosticFactory2)super.getFactory();
}
- @NotNull
@Override
+ @NotNull
public List getTextRanges() {
- JetReferenceExpression element = getPsiElement();
- if (element instanceof JetArrayAccessExpression) {
- return ((JetArrayAccessExpression) element).getBracketRanges();
- }
- return Collections.singletonList(element.getTextRange());
+ return getFactory().getTextRanges(this);
+ }
+
+ @NotNull
+ public A getA() {
+ return a;
+ }
+
+ @NotNull
+ public B getB() {
+ return b;
}
}
diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/DiagnosticWithParameters3.java b/compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/DiagnosticWithParameters3.java
new file mode 100644
index 00000000000..febe21d7a5b
--- /dev/null
+++ b/compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/DiagnosticWithParameters3.java
@@ -0,0 +1,72 @@
+/*
+ * 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.diagnostics;
+
+import com.intellij.openapi.util.TextRange;
+import com.intellij.psi.PsiElement;
+import org.jetbrains.annotations.NotNull;
+
+import java.util.List;
+
+/**
+ * @author Evgeny Gerashchenko
+ * @since 4/11/12
+ */
+public class DiagnosticWithParameters3 extends AbstractDiagnostic {
+ private A a;
+ private B b;
+ private C c;
+
+ public DiagnosticWithParameters3(@NotNull E psiElement,
+ @NotNull A a,
+ @NotNull B b,
+ @NotNull C c,
+ @NotNull DiagnosticFactory3 factory,
+ @NotNull Severity severity) {
+ super(psiElement, factory, severity);
+ this.a = a;
+ this.b = b;
+ this.c = c;
+ }
+
+ @NotNull
+ @Override
+ public DiagnosticFactory3 getFactory() {
+ return (DiagnosticFactory3)super.getFactory();
+ }
+
+ @Override
+ @NotNull
+ public List getTextRanges() {
+ return getFactory().getTextRanges(this);
+ }
+
+ @NotNull
+ public A getA() {
+ return a;
+ }
+
+ @NotNull
+ public B getB() {
+ return b;
+ }
+
+ @NotNull
+ public C getC() {
+ return c;
+ }
+}
diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/Errors.java b/compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/Errors.java
index d2e374196ed..929f1350017 100644
--- a/compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/Errors.java
+++ b/compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/Errors.java
@@ -21,267 +21,259 @@ import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiNameIdentifierOwner;
import com.intellij.psi.impl.source.tree.LeafPsiElement;
import org.jetbrains.annotations.NotNull;
-import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.lang.descriptors.*;
import org.jetbrains.jet.lang.psi.*;
import org.jetbrains.jet.lang.resolve.calls.inference.SolutionStatus;
import org.jetbrains.jet.lang.types.JetType;
import org.jetbrains.jet.lexer.JetKeywordToken;
import org.jetbrains.jet.lexer.JetTokens;
-import org.jetbrains.jet.resolve.DescriptorRenderer;
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.util.Collection;
import java.util.Collections;
-import java.util.Iterator;
import java.util.List;
-import static org.jetbrains.jet.lang.diagnostics.Renderers.*;
import static org.jetbrains.jet.lang.diagnostics.Severity.ERROR;
import static org.jetbrains.jet.lang.diagnostics.Severity.WARNING;
/**
+ * For error messages, see DefaultErrorMessages and IdeErrorMessages.
+ *
* @author abreslav
*/
public interface Errors {
- DiagnosticFactory1 EXCEPTION_WHILE_ANALYZING = DiagnosticFactory1.create(ERROR, "{0}", new Renderer() {
- @NotNull
- @Override
- public String render(@Nullable Throwable e) {
- return e.getClass().getSimpleName() + ": " + e.getMessage();
- }
- });
+ DiagnosticFactory1 EXCEPTION_WHILE_ANALYZING = DiagnosticFactory1.create(ERROR);
- UnresolvedReferenceDiagnosticFactory UNRESOLVED_REFERENCE = UnresolvedReferenceDiagnosticFactory.create("Unresolved reference");
+ UnresolvedReferenceDiagnosticFactory UNRESOLVED_REFERENCE = UnresolvedReferenceDiagnosticFactory.create();
//Elements with "INVISIBLE_REFERENCE" error are marked as unresolved, unlike elements with "INVISIBLE_MEMBER" error
- DiagnosticFactory2 INVISIBLE_REFERENCE = DiagnosticFactory2.create(ERROR, "Cannot access ''{0}'' in ''{1}''", NAME, NAME);
- DiagnosticFactory2 INVISIBLE_MEMBER = DiagnosticFactory2.create(ERROR, "Cannot access ''{0}'' in ''{1}''", NAME, NAME);
+ DiagnosticFactory2 INVISIBLE_REFERENCE =
+ DiagnosticFactory2.create(ERROR);
+ DiagnosticFactory2 INVISIBLE_MEMBER = DiagnosticFactory2.create(ERROR);
- RedeclarationDiagnosticFactory REDECLARATION = RedeclarationDiagnosticFactory.REDECLARATION;
- RedeclarationDiagnosticFactory NAME_SHADOWING = RedeclarationDiagnosticFactory.NAME_SHADOWING;
+ RedeclarationDiagnosticFactory REDECLARATION = new RedeclarationDiagnosticFactory(ERROR);
+ RedeclarationDiagnosticFactory NAME_SHADOWING = new RedeclarationDiagnosticFactory(WARNING);
- DiagnosticFactory2 TYPE_MISMATCH = DiagnosticFactory2.create(ERROR, "Type mismatch: inferred type is {1} but {0} was expected",
- RENDER_TYPE, RENDER_TYPE);
- DiagnosticFactory1> INCOMPATIBLE_MODIFIERS =
- DiagnosticFactory1.create(ERROR, "Incompatible modifiers: ''{0}''",
- new Renderer>() {
- @NotNull
- @Override
- public String render(@Nullable Collection element) {
- assert element != null;
- StringBuilder sb = new StringBuilder();
- for (Iterator iterator = element.iterator(); iterator.hasNext(); ) {
- JetKeywordToken modifier = iterator.next();
- sb.append(modifier.getValue());
- if (iterator.hasNext()) {
- sb.append(" ");
- }
- }
- return sb.toString();
- }
- });
- DiagnosticFactory1 ILLEGAL_MODIFIER = DiagnosticFactory1.create(ERROR, "Illegal modifier ''{0}''");
+ DiagnosticFactory2 TYPE_MISMATCH = DiagnosticFactory2.create(ERROR);
+ DiagnosticFactory1> INCOMPATIBLE_MODIFIERS = DiagnosticFactory1.create(ERROR);
+ DiagnosticFactory1 ILLEGAL_MODIFIER = DiagnosticFactory1.create(ERROR);
- DiagnosticFactory2 REDUNDANT_MODIFIER = DiagnosticFactory2.create(Severity.WARNING, "Modifier {0} is redundant because {1} is present");
- DiagnosticFactory ABSTRACT_MODIFIER_IN_TRAIT = DiagnosticFactory.create(WARNING, "Modifier ''{0}'' is redundant in trait", PositioningStrategies.POSITION_ABSTRACT_MODIFIER);
- DiagnosticFactory OPEN_MODIFIER_IN_TRAIT = DiagnosticFactory.create(WARNING, "Modifier ''{0}'' is redundant in trait", PositioningStrategies.positionModifier(JetTokens.OPEN_KEYWORD));
- DiagnosticFactory REDUNDANT_MODIFIER_IN_GETTER = DiagnosticFactory.create(WARNING, "Visibility modifiers are redundant in getter");
- DiagnosticFactory TRAIT_CAN_NOT_BE_FINAL = DiagnosticFactory.create(ERROR, "Trait can not be final");
- DiagnosticFactory TYPECHECKER_HAS_RUN_INTO_RECURSIVE_PROBLEM = DiagnosticFactory.create(ERROR, "Type checking has run into a recursive problem. Easiest workaround: specify types of your declarations explicitly"); // TODO: message
- DiagnosticFactory RETURN_NOT_ALLOWED = DiagnosticFactory.create(ERROR, "'return' is not allowed here");
- DiagnosticFactory PROJECTION_IN_IMMEDIATE_ARGUMENT_TO_SUPERTYPE = DiagnosticFactory.create(ERROR, "Projections are not allowed for immediate arguments of a supertype", new PositioningStrategy() {
- @NotNull
- @Override
- public List mark(@NotNull JetTypeProjection element) {
- return markNode(element.getProjectionNode());
- }
- });
- DiagnosticFactory LABEL_NAME_CLASH = DiagnosticFactory.create(WARNING, "There is more than one label with such a name in this scope");
- DiagnosticFactory EXPRESSION_EXPECTED_NAMESPACE_FOUND = DiagnosticFactory.create(ERROR, "Expression expected, but a namespace name found");
+ DiagnosticFactory2 REDUNDANT_MODIFIER = DiagnosticFactory2.create(Severity.WARNING);
+ SimpleDiagnosticFactory ABSTRACT_MODIFIER_IN_TRAIT = SimpleDiagnosticFactory
+ .create(WARNING, PositioningStrategies.POSITION_ABSTRACT_MODIFIER);
+ SimpleDiagnosticFactory OPEN_MODIFIER_IN_TRAIT = SimpleDiagnosticFactory
+ .create(WARNING, PositioningStrategies.positionModifier(JetTokens.OPEN_KEYWORD));
+ SimpleDiagnosticFactory
+ REDUNDANT_MODIFIER_IN_GETTER = SimpleDiagnosticFactory.create(WARNING);
+ SimpleDiagnosticFactory TRAIT_CAN_NOT_BE_FINAL = SimpleDiagnosticFactory.create(ERROR);
+ SimpleDiagnosticFactory TYPECHECKER_HAS_RUN_INTO_RECURSIVE_PROBLEM = SimpleDiagnosticFactory.create(ERROR);
+ SimpleDiagnosticFactory RETURN_NOT_ALLOWED = SimpleDiagnosticFactory.create(ERROR);
+ SimpleDiagnosticFactory PROJECTION_IN_IMMEDIATE_ARGUMENT_TO_SUPERTYPE =
+ SimpleDiagnosticFactory.create(ERROR, PositioningStrategies.PROJECTION_MODIFIER);
+ SimpleDiagnosticFactoryLABEL_NAME_CLASH = SimpleDiagnosticFactory.create(WARNING);
+ SimpleDiagnosticFactory EXPRESSION_EXPECTED_NAMESPACE_FOUND = SimpleDiagnosticFactory.create(ERROR);
- DiagnosticFactory1 CANNOT_IMPORT_FROM_ELEMENT = DiagnosticFactory1.create(ERROR, "Cannot import from ''{0}''", NAME);
- DiagnosticFactory1 CANNOT_BE_IMPORTED = DiagnosticFactory1.create(ERROR, "Cannot import ''{0}'', functions and properties can be imported only from packages", NAME);
- DiagnosticFactory USELESS_HIDDEN_IMPORT = DiagnosticFactory.create(WARNING, "Useless import, it is hidden further");
- DiagnosticFactory USELESS_SIMPLE_IMPORT = DiagnosticFactory.create(WARNING, "Useless import, does nothing");
+ DiagnosticFactory1 CANNOT_IMPORT_FROM_ELEMENT = DiagnosticFactory1.create(ERROR);
+ DiagnosticFactory1 CANNOT_BE_IMPORTED = DiagnosticFactory1.create(ERROR);
+ SimpleDiagnosticFactoryUSELESS_HIDDEN_IMPORT = SimpleDiagnosticFactory.create(WARNING);
+ SimpleDiagnosticFactory USELESS_SIMPLE_IMPORT = SimpleDiagnosticFactory.create(WARNING);
- DiagnosticFactory CANNOT_INFER_PARAMETER_TYPE = DiagnosticFactory.create(ERROR, "Cannot infer a type for this parameter. To specify it explicitly use the {(p : Type) => ...} notation");
+ SimpleDiagnosticFactory CANNOT_INFER_PARAMETER_TYPE = SimpleDiagnosticFactory.create(ERROR);
- DiagnosticFactory NO_BACKING_FIELD_ABSTRACT_PROPERTY = DiagnosticFactory.create(ERROR, "This property doesn't have a backing field, because it's abstract");
- DiagnosticFactory NO_BACKING_FIELD_CUSTOM_ACCESSORS = DiagnosticFactory.create(ERROR, "This property doesn't have a backing field, because it has custom accessors without reference to the backing field");
- DiagnosticFactory INACCESSIBLE_BACKING_FIELD = DiagnosticFactory.create(ERROR, "The backing field is not accessible here");
- DiagnosticFactory NOT_PROPERTY_BACKING_FIELD = DiagnosticFactory.create(ERROR, "The referenced variable is not a property and doesn't have backing field");
+ SimpleDiagnosticFactory NO_BACKING_FIELD_ABSTRACT_PROPERTY = SimpleDiagnosticFactory.create(ERROR);
+ SimpleDiagnosticFactory NO_BACKING_FIELD_CUSTOM_ACCESSORS = SimpleDiagnosticFactory.create(ERROR
+ );
+ SimpleDiagnosticFactory INACCESSIBLE_BACKING_FIELD = SimpleDiagnosticFactory.create(ERROR);
+ SimpleDiagnosticFactory NOT_PROPERTY_BACKING_FIELD = SimpleDiagnosticFactory.create(ERROR);
- DiagnosticFactory MIXING_NAMED_AND_POSITIONED_ARGUMENTS = DiagnosticFactory.create(ERROR, "Mixing named and positioned arguments in not allowed");
- DiagnosticFactory ARGUMENT_PASSED_TWICE = DiagnosticFactory.create(ERROR, "An argument is already passed for this parameter");
- UnresolvedReferenceDiagnosticFactory NAMED_PARAMETER_NOT_FOUND = UnresolvedReferenceDiagnosticFactory.create("Cannot find a parameter with this name");
- DiagnosticFactory VARARG_OUTSIDE_PARENTHESES = DiagnosticFactory.create(ERROR, "Passing value as a vararg is only allowed inside a parenthesized argument list");
- DiagnosticFactory NON_VARARG_SPREAD = DiagnosticFactory.create(ERROR, "The spread operator (*foo) may only be applied in a vararg position");
+ SimpleDiagnosticFactory MIXING_NAMED_AND_POSITIONED_ARGUMENTS = SimpleDiagnosticFactory.create(ERROR);
+ SimpleDiagnosticFactory ARGUMENT_PASSED_TWICE = SimpleDiagnosticFactory.create(ERROR);
+ UnresolvedReferenceDiagnosticFactory NAMED_PARAMETER_NOT_FOUND = UnresolvedReferenceDiagnosticFactory.create();
+ SimpleDiagnosticFactory VARARG_OUTSIDE_PARENTHESES = SimpleDiagnosticFactory.create(ERROR);
+ SimpleDiagnosticFactory NON_VARARG_SPREAD = SimpleDiagnosticFactory.create(ERROR);
- DiagnosticFactory MANY_FUNCTION_LITERAL_ARGUMENTS = DiagnosticFactory.create(ERROR, "Only one function literal is allowed outside a parenthesized argument list");
- DiagnosticFactory PROPERTY_WITH_NO_TYPE_NO_INITIALIZER = DiagnosticFactory.create(ERROR, "This property must either have a type annotation or be initialized");
+ SimpleDiagnosticFactory MANY_FUNCTION_LITERAL_ARGUMENTS = SimpleDiagnosticFactory.create(ERROR);
+ SimpleDiagnosticFactory PROPERTY_WITH_NO_TYPE_NO_INITIALIZER = SimpleDiagnosticFactory.create(ERROR);
- DiagnosticFactory ABSTRACT_PROPERTY_IN_PRIMARY_CONSTRUCTOR_PARAMETERS = DiagnosticFactory.create(ERROR, "This property cannot be declared abstract", PositioningStrategies.POSITION_ABSTRACT_MODIFIER);
- DiagnosticFactory ABSTRACT_PROPERTY_NOT_IN_CLASS = DiagnosticFactory.create(ERROR, "A property may be abstract only when defined in a class or trait", PositioningStrategies.POSITION_ABSTRACT_MODIFIER);
- DiagnosticFactory ABSTRACT_PROPERTY_WITH_INITIALIZER = DiagnosticFactory.create(ERROR, "Property with initializer cannot be abstract");
- DiagnosticFactory ABSTRACT_PROPERTY_WITH_GETTER = DiagnosticFactory.create(ERROR, "Property with getter implementation cannot be abstract");
- DiagnosticFactory ABSTRACT_PROPERTY_WITH_SETTER = DiagnosticFactory.create(ERROR, "Property with setter implementation cannot be abstract");
+ SimpleDiagnosticFactory ABSTRACT_PROPERTY_IN_PRIMARY_CONSTRUCTOR_PARAMETERS = SimpleDiagnosticFactory
+ .create(ERROR, PositioningStrategies.POSITION_ABSTRACT_MODIFIER);
+ SimpleDiagnosticFactory ABSTRACT_PROPERTY_NOT_IN_CLASS = SimpleDiagnosticFactory.create(ERROR,
+ PositioningStrategies.POSITION_ABSTRACT_MODIFIER);
+ SimpleDiagnosticFactory ABSTRACT_PROPERTY_WITH_INITIALIZER = SimpleDiagnosticFactory.create(ERROR);
+ SimpleDiagnosticFactory ABSTRACT_PROPERTY_WITH_GETTER = SimpleDiagnosticFactory.create(ERROR);
+ SimpleDiagnosticFactoryABSTRACT_PROPERTY_WITH_SETTER = SimpleDiagnosticFactory.create(ERROR);
- DiagnosticFactory PACKAGE_MEMBER_CANNOT_BE_PROTECTED = DiagnosticFactory.create(ERROR, "Package member cannot be protected");
+ SimpleDiagnosticFactory PACKAGE_MEMBER_CANNOT_BE_PROTECTED = SimpleDiagnosticFactory.create(ERROR);
- DiagnosticFactory GETTER_VISIBILITY_DIFFERS_FROM_PROPERTY_VISIBILITY = DiagnosticFactory.create(ERROR, "Getter visibility must be the same as property visibility");
- DiagnosticFactory BACKING_FIELD_IN_TRAIT = DiagnosticFactory.create(ERROR, "Property in a trait cannot have a backing field", PositioningStrategies.POSITION_NAME_IDENTIFIER);
- DiagnosticFactory MUST_BE_INITIALIZED = DiagnosticFactory.create(ERROR, "Property must be initialized", PositioningStrategies.POSITION_NAME_IDENTIFIER);
- DiagnosticFactory MUST_BE_INITIALIZED_OR_BE_ABSTRACT = DiagnosticFactory.create(ERROR, "Property must be initialized or be abstract", PositioningStrategies.POSITION_NAME_IDENTIFIER);
- DiagnosticFactory PROPERTY_INITIALIZER_IN_TRAIT = DiagnosticFactory.create(ERROR, "Property initializers are not allowed in traits");
- DiagnosticFactory PROPERTY_INITIALIZER_NO_BACKING_FIELD = DiagnosticFactory.create(ERROR, "Initializer is not allowed here because this property has no backing field");
- DiagnosticFactory3 ABSTRACT_PROPERTY_IN_NON_ABSTRACT_CLASS = DiagnosticFactory3.create(ERROR, "Abstract property {0} in non-abstract class {1}", PositioningStrategies.POSITION_ABSTRACT_MODIFIER);
- DiagnosticFactory3 ABSTRACT_FUNCTION_IN_NON_ABSTRACT_CLASS = DiagnosticFactory3.create(ERROR, "Abstract function {0} in non-abstract class {1}", PositioningStrategies.POSITION_ABSTRACT_MODIFIER);
- DiagnosticFactory1 ABSTRACT_FUNCTION_WITH_BODY = DiagnosticFactory1.create(ERROR, "A function {0} with body cannot be abstract", PositioningStrategies.POSITION_ABSTRACT_MODIFIER);
- DiagnosticFactory1