renaming/code moving to meet the code style

This commit is contained in:
Andrey Breslav
2012-03-29 17:52:58 +04:00
parent 752949687d
commit ed04839901
6 changed files with 75 additions and 76 deletions
@@ -58,7 +58,7 @@ public class BytecodeCompiler {
}
// lets register any compiler plugins
env.getMyEnvironment().getCompilerPlugins().addAll(getCompilerPlugins());
env.getEnvironment().getCompilerPlugins().addAll(getCompilerPlugins());
return env;
}
@@ -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<CompilerPlugin> plugins = arguments.getCompilerPlugins();
if (plugins != null) {
environment.getMyEnvironment().getCompilerPlugins().addAll(plugins);
environment.getEnvironment().getCompilerPlugins().addAll(plugins);
}
if (arguments.stdlib != null) {
@@ -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<Module> 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<Module> 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;
}
}
@@ -56,27 +56,27 @@ import java.util.List;
* @author yole
*/
public class CompileSession {
private final JetCoreEnvironment myEnvironment;
private final MessageCollector myMessageCollector;
private final List<JetFile> mySourceFiles = new ArrayList<JetFile>();
private List<String> myErrors = new ArrayList<String>();
private final JetCoreEnvironment environment;
private final MessageCollector messageCollector;
private final List<JetFile> sourceFiles = new ArrayList<JetFile>();
private List<String> errors = new ArrayList<String>();
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<JetFile> 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<PsiFile> filesToAnalyzeCompletely =
stubs ? Predicates.<PsiFile>alwaysFalse() : Predicates.<PsiFile>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<ClassDescriptor> incompletes = myBindingContext.getBindingContext().getKeys(BindingContext.INCOMPLETE_HIERARCHY);
Collection<ClassDescriptor> 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<CompilerPlugin> plugins = myEnvironment.getCompilerPlugins();
List<CompilerPlugin> 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));
}
}
}
@@ -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");
@@ -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<JetType> allSuperTypes = new THashSet<JetType>();
CodegenUtil.addSuperTypes(descriptor.getDefaultType(), allSuperTypes);