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 9edf8d1f19a..6a65f9ff739 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 @@ -58,7 +58,7 @@ public class BytecodeCompiler { } // lets register any compiler plugins - env.getMyEnvironment().getCompilerPlugins().addAll(getCompilerPlugins()); + env.getEnvironment().getCompilerPlugins().addAll(getCompilerPlugins()); return env; } diff --git a/compiler/cli/src/org/jetbrains/jet/cli/KotlinCompiler.java b/compiler/cli/src/org/jetbrains/jet/cli/KotlinCompiler.java index c7ea21b4323..33c9df6b514 100644 --- a/compiler/cli/src/org/jetbrains/jet/cli/KotlinCompiler.java +++ b/compiler/cli/src/org/jetbrains/jet/cli/KotlinCompiler.java @@ -166,13 +166,13 @@ public class KotlinCompiler { environment.setStubs(arguments.stubs); if (arguments.docOutputDir != null) { - KDocLoader.install(arguments.docOutputDir, environment.getMyEnvironment()); + KDocLoader.install(arguments.docOutputDir, environment.getEnvironment()); } // install any compiler plugins List plugins = arguments.getCompilerPlugins(); if (plugins != null) { - environment.getMyEnvironment().getCompilerPlugins().addAll(plugins); + environment.getEnvironment().getCompilerPlugins().addAll(plugins); } if (arguments.stdlib != null) { diff --git a/compiler/cli/src/org/jetbrains/jet/compiler/CompileEnvironment.java b/compiler/cli/src/org/jetbrains/jet/compiler/CompileEnvironment.java index 500400e158c..91f97fc4009 100644 --- a/compiler/cli/src/org/jetbrains/jet/compiler/CompileEnvironment.java +++ b/compiler/cli/src/org/jetbrains/jet/compiler/CompileEnvironment.java @@ -54,12 +54,12 @@ import java.util.jar.*; * @author yole */ public class CompileEnvironment { - private JetCoreEnvironment myEnvironment; - private final Disposable myRootDisposable; - private final MessageRenderer myMessageRenderer; - private PrintStream myErrorStream = System.err; + private JetCoreEnvironment environment; + private final Disposable rootDisposable; + private final MessageRenderer messageRenderer; + private PrintStream errorStream = System.err; - private URL myStdlib; + private URL stdlibUrl; private boolean ignoreErrors = false; private boolean stubs = false; @@ -78,17 +78,17 @@ public class CompileEnvironment { */ public CompileEnvironment(MessageRenderer messageRenderer, boolean verbose) { this.verbose = verbose; - myRootDisposable = new Disposable() { + rootDisposable = new Disposable() { @Override public void dispose() { } }; - myEnvironment = new JetCoreEnvironment(myRootDisposable); - myMessageRenderer = messageRenderer; + environment = new JetCoreEnvironment(rootDisposable); + this.messageRenderer = messageRenderer; } public void setErrorStream(PrintStream errorStream) { - myErrorStream = errorStream; + this.errorStream = errorStream; } public void setIgnoreErrors(boolean ignoreErrors) { @@ -100,7 +100,7 @@ public class CompileEnvironment { } public void dispose() { - Disposer.dispose(myRootDisposable); + Disposer.dispose(rootDisposable); } @Nullable @@ -123,7 +123,7 @@ public class CompileEnvironment { } public void ensureRuntime() { - ensureRuntime(myEnvironment); + ensureRuntime(environment); } public static void ensureRuntime(@NotNull JetCoreEnvironment env) { @@ -178,7 +178,7 @@ public class CompileEnvironment { public boolean compileModuleScript(String moduleScriptFile, @Nullable String jarPath, @Nullable String outputDir, boolean jarRuntime) { CompileEnvironment moduleCompilationEnvironment = copyEnvironment(false); try { - moduleCompilationEnvironment.myStdlib = myStdlib; + moduleCompilationEnvironment.stdlibUrl = stdlibUrl; List modules = moduleCompilationEnvironment.loadModuleScript(moduleScriptFile); @@ -220,11 +220,11 @@ public class CompileEnvironment { } private CompileEnvironment copyEnvironment(boolean verbose) { - CompileEnvironment compileEnvironment = new CompileEnvironment(myMessageRenderer, verbose); + CompileEnvironment compileEnvironment = new CompileEnvironment(messageRenderer, verbose); compileEnvironment.setIgnoreErrors(ignoreErrors); - compileEnvironment.setErrorStream(myErrorStream); + compileEnvironment.setErrorStream(errorStream); // copy across any compiler plugins - compileEnvironment.getMyEnvironment().getCompilerPlugins().addAll(myEnvironment.getCompilerPlugins()); + compileEnvironment.getEnvironment().getCompilerPlugins().addAll(environment.getCompilerPlugins()); return compileEnvironment; } @@ -236,13 +236,13 @@ public class CompileEnvironment { if (!scriptCompileSession.analyze()) { return null; } - final ClassFileFactory factory = scriptCompileSession.generate(true); + ClassFileFactory factory = scriptCompileSession.generate(true); return runDefineModules(moduleFile, factory); } private List runDefineModules(String moduleFile, ClassFileFactory factory) { - GeneratedClassLoader loader = myStdlib != null ? new GeneratedClassLoader(factory, new URLClassLoader(new URL[] {myStdlib}, AllModules.class.getClassLoader())) + GeneratedClassLoader loader = stdlibUrl != null ? new GeneratedClassLoader(factory, new URLClassLoader(new URL[] {stdlibUrl}, AllModules.class.getClassLoader())) : new GeneratedClassLoader(factory, CompileEnvironment.class.getClassLoader()); try { Class namespaceClass = loader.loadClass(JvmAbi.PACKAGE_CLASS); @@ -287,7 +287,7 @@ public class CompileEnvironment { moduleCompileSession.addSources(source.getPath()); } for (String classpathRoot : moduleBuilder.getClasspathRoots()) { - myEnvironment.addToClasspath(new File(classpathRoot)); + environment.addToClasspath(new File(classpathRoot)); } ensureRuntime(); @@ -426,7 +426,7 @@ public class CompileEnvironment { } private CompileSession newCompileSession() { - return new CompileSession(myEnvironment, myMessageRenderer, myErrorStream, verbose); + return new CompileSession(environment, messageRenderer, errorStream, verbose); } public static void writeToOutputDirectory(ClassFileFactory factory, final String outputDir) { @@ -451,7 +451,7 @@ public class CompileEnvironment { if ( ! path.exists()) { throw new CompileEnvironmentException("'" + path + "' does not exist"); } - myEnvironment.addToClasspath(path); + environment.addToClasspath(path); } } @@ -470,14 +470,14 @@ public class CompileEnvironment { addToClasspath(file); try { - myStdlib = file.toURL(); + stdlibUrl = file.toURL(); } catch (MalformedURLException e) { throw new RuntimeException(e); } } - public JetCoreEnvironment getMyEnvironment() { - return myEnvironment; + public JetCoreEnvironment getEnvironment() { + return environment; } } diff --git a/compiler/cli/src/org/jetbrains/jet/compiler/CompileSession.java b/compiler/cli/src/org/jetbrains/jet/compiler/CompileSession.java index cd617917e31..02768269932 100644 --- a/compiler/cli/src/org/jetbrains/jet/compiler/CompileSession.java +++ b/compiler/cli/src/org/jetbrains/jet/compiler/CompileSession.java @@ -56,27 +56,27 @@ import java.util.List; * @author yole */ public class CompileSession { - private final JetCoreEnvironment myEnvironment; - private final MessageCollector myMessageCollector; - private final List mySourceFiles = new ArrayList(); - private List myErrors = new ArrayList(); + private final JetCoreEnvironment environment; + private final MessageCollector messageCollector; + private final List sourceFiles = new ArrayList(); + private List errors = new ArrayList(); private boolean stubs = false; - private final MessageRenderer myMessageRenderer; - private final PrintStream myErrorStream; - private final boolean myIsVerbose; - - public AnalyzeExhaust getMyBindingContext() { - return myBindingContext; - } - - private AnalyzeExhaust myBindingContext; + private final MessageRenderer messageRenderer; + private final PrintStream errorStream; + private final boolean isVerbose; + private AnalyzeExhaust bindingContext; public CompileSession(JetCoreEnvironment environment, MessageRenderer messageRenderer, PrintStream errorStream, boolean verbose) { - myEnvironment = environment; - myMessageRenderer = messageRenderer; - myErrorStream = errorStream; - myIsVerbose = verbose; - myMessageCollector = new MessageCollector(myMessageRenderer); + this.environment = environment; + this.messageRenderer = messageRenderer; + this.errorStream = errorStream; + isVerbose = verbose; + messageCollector = new MessageCollector(this.messageRenderer); + } + + @NotNull + public AnalyzeExhaust getBindingContext() { + return bindingContext; } public void setStubs(boolean stubs) { @@ -87,13 +87,13 @@ public class CompileSession { if(path == null) return; - VirtualFile vFile = myEnvironment.getLocalFileSystem().findFileByPath(path); + VirtualFile vFile = environment.getLocalFileSystem().findFileByPath(path); if (vFile == null) { - myErrors.add("File/directory not found: " + path); + errors.add("File/directory not found: " + path); return; } if (!vFile.isDirectory() && vFile.getFileType() != JetFileType.INSTANCE) { - myErrors.add("Not a Kotlin file: " + path); + errors.add("Not a Kotlin file: " + path); return; } @@ -110,11 +110,11 @@ public class CompileSession { } } else { - VirtualFile fileByPath = myEnvironment.getLocalFileSystem().findFileByPath(file.getAbsolutePath()); + VirtualFile fileByPath = environment.getLocalFileSystem().findFileByPath(file.getAbsolutePath()); if (fileByPath != null) { - PsiFile psiFile = PsiManager.getInstance(myEnvironment.getProject()).findFile(fileByPath); + PsiFile psiFile = PsiManager.getInstance(environment.getProject()).findFile(fileByPath); if(psiFile instanceof JetFile) { - mySourceFiles.add((JetFile) psiFile); + sourceFiles.add((JetFile)psiFile); } } } @@ -128,29 +128,29 @@ public class CompileSession { } else { if (vFile.getFileType() == JetFileType.INSTANCE) { - PsiFile psiFile = PsiManager.getInstance(myEnvironment.getProject()).findFile(vFile); + PsiFile psiFile = PsiManager.getInstance(environment.getProject()).findFile(vFile); if (psiFile instanceof JetFile) { - mySourceFiles.add((JetFile) psiFile); + sourceFiles.add((JetFile)psiFile); } } } } public List getSourceFileNamespaces() { - return mySourceFiles; + return sourceFiles; } public boolean analyze() { - for (String error : myErrors) { - myMessageCollector.report(Severity.ERROR, error, null, -1, -1); + for (String error : errors) { + messageCollector.report(Severity.ERROR, error, null, -1, -1); } reportSyntaxErrors(); analyzeAndReportSemanticErrors(); - myMessageCollector.printTo(myErrorStream); + messageCollector.printTo(errorStream); - return !myMessageCollector.hasErrors(); + return !messageCollector.hasErrors(); } /** @@ -169,18 +169,18 @@ public class CompileSession { private void analyzeAndReportSemanticErrors() { Predicate filesToAnalyzeCompletely = stubs ? Predicates.alwaysFalse() : Predicates.alwaysTrue(); - myBindingContext = AnalyzerFacadeForJVM.analyzeFilesWithJavaIntegration( - myEnvironment.getProject(), mySourceFiles, filesToAnalyzeCompletely, JetControlFlowDataTraceFactory.EMPTY); + bindingContext = AnalyzerFacadeForJVM.analyzeFilesWithJavaIntegration( + environment.getProject(), sourceFiles, filesToAnalyzeCompletely, JetControlFlowDataTraceFactory.EMPTY); - for (Diagnostic diagnostic : myBindingContext.getBindingContext().getDiagnostics()) { - reportDiagnostic(myMessageCollector, diagnostic); + for (Diagnostic diagnostic : bindingContext.getBindingContext().getDiagnostics()) { + reportDiagnostic(messageCollector, diagnostic); } - reportIncompleteHierarchies(myMessageCollector); + reportIncompleteHierarchies(messageCollector); } private void reportIncompleteHierarchies(MessageCollector collector) { - Collection incompletes = myBindingContext.getBindingContext().getKeys(BindingContext.INCOMPLETE_HIERARCHY); + Collection incompletes = bindingContext.getBindingContext().getKeys(BindingContext.INCOMPLETE_HIERARCHY); if (!incompletes.isEmpty()) { StringBuilder message = new StringBuilder("The following classes have incomplete hierarchies:\n"); for (ClassDescriptor incomplete : incompletes) { @@ -191,14 +191,14 @@ public class CompileSession { } private void reportSyntaxErrors() { - for (JetFile file : mySourceFiles) { + for (JetFile file : sourceFiles) { 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(myMessageCollector, diagnostic); + reportDiagnostic(messageCollector, diagnostic); } }); } @@ -213,16 +213,16 @@ public class CompileSession { @NotNull public ClassFileFactory generate(boolean module) { - Project project = myEnvironment.getProject(); - GenerationState generationState = new GenerationState(project, ClassBuilderFactories.binaries(stubs), myIsVerbose ? new BackendProgress() : Progress.DEAF); - generationState.compileCorrectFiles(myBindingContext, mySourceFiles, CompilationErrorHandler.THROW_EXCEPTION, true); + Project project = environment.getProject(); + GenerationState generationState = new GenerationState(project, ClassBuilderFactories.binaries(stubs), isVerbose ? new BackendProgress() : Progress.DEAF); + generationState.compileCorrectFiles(bindingContext, sourceFiles, CompilationErrorHandler.THROW_EXCEPTION, true); ClassFileFactory answer = generationState.getFactory(); - List plugins = myEnvironment.getCompilerPlugins(); + List plugins = environment.getCompilerPlugins(); if (!module) { if (plugins != null) { for (CompilerPlugin plugin : plugins) { - plugin.processFiles(myBindingContext.getBindingContext(), getSourceFileNamespaces()); + plugin.processFiles(bindingContext.getBindingContext(), getSourceFileNamespaces()); } } } @@ -232,7 +232,7 @@ public class CompileSession { private class BackendProgress implements Progress { @Override public void log(String message) { - myErrorStream.println(myMessageRenderer.render(Severity.LOGGING, message, null, -1, -1)); + errorStream.println(messageRenderer.render(Severity.LOGGING, message, null, -1, -1)); } } } diff --git a/compiler/tests/org/jetbrains/jet/codegen/CompileTextTest.java b/compiler/tests/org/jetbrains/jet/codegen/CompileTextTest.java index c0a562ba37c..3c9e142fccf 100644 --- a/compiler/tests/org/jetbrains/jet/codegen/CompileTextTest.java +++ b/compiler/tests/org/jetbrains/jet/codegen/CompileTextTest.java @@ -16,7 +16,6 @@ package org.jetbrains.jet.codegen; -import junit.framework.TestCase; import org.jetbrains.jet.compiler.CompileEnvironment; import java.lang.reflect.InvocationTargetException; @@ -26,7 +25,7 @@ public class CompileTextTest extends CodegenTestCase { public void testMe() throws ClassNotFoundException, NoSuchMethodException, InvocationTargetException, IllegalAccessException { String text = "import org.jetbrains.jet.codegen.CompileTextTest; fun x() = CompileTextTest()"; CompileEnvironment compileEnvironment = new CompileEnvironment(); - compileEnvironment.getMyEnvironment().addToClasspathFromClassLoader(getClass().getClassLoader()); + compileEnvironment.getEnvironment().addToClasspathFromClassLoader(getClass().getClassLoader()); ClassLoader classLoader = compileEnvironment.compileText(text); Class namespace = classLoader.loadClass("namespace"); Method x = namespace.getDeclaredMethod("x"); diff --git a/compiler/tests/org/jetbrains/jet/codegen/TestlibTest.java b/compiler/tests/org/jetbrains/jet/codegen/TestlibTest.java index a01bdf1baea..ae18c04eeaf 100644 --- a/compiler/tests/org/jetbrains/jet/codegen/TestlibTest.java +++ b/compiler/tests/org/jetbrains/jet/codegen/TestlibTest.java @@ -98,8 +98,8 @@ public class TestlibTest extends CodegenTestCase { TestCase.class.getClassLoader())); InjectorForJvmCodegen injector = new InjectorForJvmCodegen( - session.getMyBindingContext().getStandardLibrary(), - session.getMyBindingContext().getBindingContext(), + session.getBindingContext().getStandardLibrary(), + session.getBindingContext().getBindingContext(), session.getSourceFileNamespaces(), getProject()); JetTypeMapper typeMapper = injector.getJetTypeMapper(); @@ -110,7 +110,7 @@ public class TestlibTest extends CodegenTestCase { if(decl instanceof JetClass) { JetClass jetClass = (JetClass) decl; - ClassDescriptor descriptor = (ClassDescriptor) session.getMyBindingContext().getBindingContext().get(BindingContext.DECLARATION_TO_DESCRIPTOR, jetClass); + ClassDescriptor descriptor = (ClassDescriptor) session.getBindingContext().getBindingContext().get(BindingContext.DECLARATION_TO_DESCRIPTOR, jetClass); Set allSuperTypes = new THashSet(); CodegenUtil.addSuperTypes(descriptor.getDefaultType(), allSuperTypes);