Convert CompilerEnvironment to Kotlin: actual conversion

Original commit: e3550c5ea2
This commit is contained in:
Alexey Tsvetkov
2016-11-03 17:23:34 +03:00
parent 9879cb49d9
commit 1537f6cb3c
@@ -14,65 +14,41 @@
* limitations under the License. * limitations under the License.
*/ */
package org.jetbrains.kotlin.compilerRunner; package org.jetbrains.kotlin.compilerRunner
import org.jetbrains.annotations.NotNull; import org.jetbrains.kotlin.cli.common.messages.MessageCollector
import org.jetbrains.kotlin.cli.common.messages.MessageCollector; import org.jetbrains.kotlin.config.Services
import org.jetbrains.kotlin.config.Services; import org.jetbrains.kotlin.preloading.ClassCondition
import org.jetbrains.kotlin.preloading.ClassCondition; import org.jetbrains.kotlin.utils.KotlinPaths
import org.jetbrains.kotlin.utils.KotlinPaths; import org.jetbrains.kotlin.utils.PathUtil
import org.jetbrains.kotlin.utils.PathUtil;
import static org.jetbrains.kotlin.cli.common.messages.CompilerMessageLocation.NO_LOCATION; import org.jetbrains.kotlin.cli.common.messages.CompilerMessageLocation.Companion.NO_LOCATION
import static org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity.ERROR; import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity.ERROR
public class CompilerEnvironment { class CompilerEnvironment private constructor(
@NotNull val kotlinPaths: KotlinPaths,
public static CompilerEnvironment getEnvironmentFor( val classesToLoadByParent: ClassCondition,
@NotNull KotlinPaths kotlinPaths, val services: Services
@NotNull ClassCondition classesToLoadByParent, ) {
@NotNull Services compilerServices
) { fun success(): Boolean {
return new CompilerEnvironment(kotlinPaths, classesToLoadByParent, compilerServices); return kotlinPaths.homePath.exists()
} }
private final KotlinPaths kotlinPaths; fun reportErrorsTo(messageCollector: MessageCollector) {
private final ClassCondition classesToLoadByParent; if (!kotlinPaths.homePath.exists()) {
private final Services services; messageCollector.report(ERROR, "Cannot find kotlinc home: " + kotlinPaths.homePath + ". Make sure plugin is properly installed, " +
"or specify " + PathUtil.JPS_KOTLIN_HOME_PROPERTY + " system property", NO_LOCATION)
private CompilerEnvironment(
@NotNull KotlinPaths kotlinPaths,
@NotNull ClassCondition classesToLoadByParent,
@NotNull Services services
) {
this.kotlinPaths = kotlinPaths;
this.classesToLoadByParent = classesToLoadByParent;
this.services = services;
}
public boolean success() {
return kotlinPaths.getHomePath().exists();
}
@NotNull
public KotlinPaths getKotlinPaths() {
return kotlinPaths;
}
@NotNull
public ClassCondition getClassesToLoadByParent() {
return classesToLoadByParent;
}
public void reportErrorsTo(@NotNull MessageCollector messageCollector) {
if (!kotlinPaths.getHomePath().exists()) {
messageCollector.report(ERROR, "Cannot find kotlinc home: " + kotlinPaths.getHomePath() + ". Make sure plugin is properly installed, " +
"or specify " + PathUtil.JPS_KOTLIN_HOME_PROPERTY + " system property", NO_LOCATION);
} }
} }
@NotNull companion object {
public Services getServices() { fun getEnvironmentFor(
return services; kotlinPaths: KotlinPaths,
classesToLoadByParent: ClassCondition,
compilerServices: Services
): CompilerEnvironment {
return CompilerEnvironment(kotlinPaths, classesToLoadByParent, compilerServices)
}
} }
} }