Reverting problematic commits:
fa500f453dAlex Tkachman Today 19:47725bebc23fAlex Tkachman Today 19:36
This commit is contained in:
@@ -13,12 +13,6 @@
|
||||
</component>
|
||||
</project-components>
|
||||
|
||||
<module-components>
|
||||
<component>
|
||||
<implementation-class>org.jetbrains.jet.plugin.compiler.JetLibraryManager</implementation-class>
|
||||
</component>
|
||||
</module-components>
|
||||
|
||||
<actions>
|
||||
<action id="ShowJetExpressionType" class="org.jetbrains.jet.plugin.actions.ShowExpressionTypeAction"
|
||||
text="Show Expression Type">
|
||||
|
||||
@@ -17,7 +17,6 @@ import com.intellij.psi.PsiManager;
|
||||
import com.intellij.util.Chunk;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.codegen.*;
|
||||
import org.jetbrains.jet.compiler.CompileSession;
|
||||
import org.jetbrains.jet.lang.cfg.pseudocode.JetControlFlowDataTraceFactory;
|
||||
import org.jetbrains.jet.lang.diagnostics.Diagnostic;
|
||||
import org.jetbrains.jet.lang.psi.JetFile;
|
||||
@@ -28,7 +27,6 @@ import org.jetbrains.jet.plugin.JetFileType;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static com.intellij.openapi.compiler.CompilerMessageCategory.ERROR;
|
||||
@@ -67,12 +65,19 @@ public class JetCompiler implements TranslatingCompiler {
|
||||
ApplicationManager.getApplication().runReadAction(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
PluginCompilerEnvironment compilerEnvironment = new PluginCompilerEnvironment(compileContext.getProject());
|
||||
CompileSession compileSession = new CompileSession(compilerEnvironment);
|
||||
compileSession.addSources(compileContext.getCompileScope().getFiles(null, true));
|
||||
compileSession.addStdLibSources();
|
||||
VirtualFile[] allFiles = compileContext.getCompileScope().getFiles(null, true);
|
||||
|
||||
BindingContext bindingContext = compileSession.analyze();
|
||||
GenerationState generationState = new GenerationState(compileContext.getProject(), ClassBuilderFactory.BINARIES);
|
||||
List<JetNamespace> namespaces = Lists.newArrayList();
|
||||
for (VirtualFile virtualFile : allFiles) {
|
||||
PsiFile psiFile = PsiManager.getInstance(compileContext.getProject()).findFile(virtualFile);
|
||||
if (psiFile instanceof JetFile) {
|
||||
namespaces.add(((JetFile) psiFile).getRootNamespace());
|
||||
}
|
||||
}
|
||||
|
||||
BindingContext bindingContext =
|
||||
AnalyzerFacade.analyzeNamespacesWithJavaIntegration(compileContext.getProject(), namespaces, Predicates.<PsiFile>alwaysTrue(), JetControlFlowDataTraceFactory.EMPTY);
|
||||
|
||||
boolean errors = false;
|
||||
for (Diagnostic diagnostic : bindingContext.getDiagnostics()) {
|
||||
@@ -91,7 +96,7 @@ public class JetCompiler implements TranslatingCompiler {
|
||||
}
|
||||
|
||||
if (!errors) {
|
||||
final ClassFileFactory factory = compileSession.generate(new CompilationErrorHandler() {
|
||||
generationState.compileCorrectNamespaces(bindingContext, namespaces, new CompilationErrorHandler() {
|
||||
@Override
|
||||
public void reportException(Throwable exception, String fileUrl) {
|
||||
if(exception instanceof CompilationException) {
|
||||
@@ -102,7 +107,22 @@ public class JetCompiler implements TranslatingCompiler {
|
||||
}
|
||||
}
|
||||
});
|
||||
///////////
|
||||
// GenerationState generationState2 = new GenerationState(compileContext.getProject(), ClassBuilderFactory.TEXT);
|
||||
// generationState2.compileCorrectNamespaces(bindingContext, namespaces);
|
||||
// StringBuilder answer = new StringBuilder();
|
||||
//
|
||||
// final ClassFileFactory factory2 = generationState2.getFactory();
|
||||
// List<String> files2 = factory2.files();
|
||||
// for (String file : files2) {
|
||||
// answer.append("@").append(file).append('\n');
|
||||
// answer.append(factory2.asText(file));
|
||||
// }
|
||||
// System.out.println(answer.toString());
|
||||
///////////
|
||||
|
||||
|
||||
final ClassFileFactory factory = generationState.getFactory();
|
||||
List<String> files = factory.files();
|
||||
for (String file : files) {
|
||||
File target = new File(outputDir.getPath(), file);
|
||||
@@ -115,6 +135,23 @@ public class JetCompiler implements TranslatingCompiler {
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// Map<Module, ModuleCompileState> moduleMap = new HashMap<Module, ModuleCompileState>();
|
||||
//
|
||||
// for (VirtualFile virtualFile : virtualFiles) {
|
||||
// Module module = compileContext.getModuleByFile(virtualFile);
|
||||
// ModuleCompileState state = moduleMap.get(module);
|
||||
// if (state == null) {
|
||||
// state = new ModuleCompileState(compileContext, module, outputSink);
|
||||
// moduleMap.put(module, state);
|
||||
// }
|
||||
// state.compile(virtualFile);
|
||||
// }
|
||||
//
|
||||
// for (ModuleCompileState state : moduleMap.values()) {
|
||||
// state.done();
|
||||
// }
|
||||
|
||||
}
|
||||
|
||||
private void report(Diagnostic diagnostic, CompilerMessageCategory severity, CompileContext compileContext) {
|
||||
|
||||
@@ -1,105 +0,0 @@
|
||||
package org.jetbrains.jet.plugin.compiler;
|
||||
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.module.Module;
|
||||
import com.intellij.openapi.module.ModuleComponent;
|
||||
import com.intellij.openapi.roots.LibraryOrderEntry;
|
||||
import com.intellij.openapi.roots.ModifiableRootModel;
|
||||
import com.intellij.openapi.roots.ModuleRootManager;
|
||||
import com.intellij.openapi.roots.OrderRootType;
|
||||
import com.intellij.openapi.roots.impl.ModuleLibraryTable;
|
||||
import com.intellij.openapi.roots.impl.libraries.ProjectLibraryTable;
|
||||
import com.intellij.openapi.roots.libraries.Library;
|
||||
import com.intellij.openapi.roots.libraries.LibraryTable;
|
||||
import com.intellij.openapi.util.Computable;
|
||||
import com.intellij.openapi.vfs.LocalFileSystem;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.compiler.AbstractCompileEnvironment;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
/**
|
||||
* @author alex.tkachman
|
||||
*/
|
||||
public class JetLibraryManager implements ModuleComponent {
|
||||
public static final String KOTLIN_STD_LIB = "KotlinStdLib";
|
||||
private Module module;
|
||||
private Library kotlin;
|
||||
|
||||
public JetLibraryManager(Module module) {
|
||||
this.module = module;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void projectOpened() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void projectClosed() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void moduleAdded() {
|
||||
if(ApplicationManager.getApplication().isUnitTestMode())
|
||||
return;
|
||||
|
||||
final LibraryTable libraryTable = ProjectLibraryTable.getInstance(module.getProject());
|
||||
kotlin = ApplicationManager.getApplication().runReadAction(new Computable<Library>() {
|
||||
@Override
|
||||
public Library compute() {
|
||||
return libraryTable.getLibraryByName(KOTLIN_STD_LIB);
|
||||
}
|
||||
});
|
||||
if(kotlin == null) {
|
||||
kotlin = ApplicationManager.getApplication().runWriteAction(new Computable<Library>() {
|
||||
@Override
|
||||
public Library compute() {
|
||||
Library library = libraryTable.createLibrary(KOTLIN_STD_LIB);
|
||||
Library.ModifiableModel modifiableModel = library.getModifiableModel();
|
||||
final File unpackedRuntimePath = AbstractCompileEnvironment.getUnpackedRuntimePath();
|
||||
if (unpackedRuntimePath != null) {
|
||||
modifiableModel.addRoot(LocalFileSystem.getInstance().findFileByIoFile(unpackedRuntimePath), OrderRootType.CLASSES);
|
||||
}
|
||||
else {
|
||||
final File runtimeJarPath = AbstractCompileEnvironment.getRuntimeJarPath();
|
||||
if (runtimeJarPath != null && runtimeJarPath.exists()) {
|
||||
modifiableModel.addRoot(LocalFileSystem.getInstance().findFileByIoFile(unpackedRuntimePath), OrderRootType.CLASSES);
|
||||
}
|
||||
else {
|
||||
// todo
|
||||
}
|
||||
}
|
||||
modifiableModel.commit();
|
||||
return library;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
ModuleRootManager rootManager = ModuleRootManager.getInstance(module);
|
||||
final ModifiableRootModel modifiableModel = rootManager.getModifiableModel();
|
||||
LibraryOrderEntry libraryOrderEntry = modifiableModel.findLibraryOrderEntry(kotlin);
|
||||
if(libraryOrderEntry == null) {
|
||||
modifiableModel.addLibraryEntry(kotlin);
|
||||
ApplicationManager.getApplication().runWriteAction(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
modifiableModel.commit();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initComponent() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void disposeComponent() {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String getComponentName() {
|
||||
return JetLibraryManager.class.getCanonicalName();
|
||||
}
|
||||
}
|
||||
@@ -1,34 +0,0 @@
|
||||
package org.jetbrains.jet.plugin.compiler;
|
||||
|
||||
import com.intellij.openapi.compiler.CompileContext;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.vfs.JarFileSystem;
|
||||
import com.intellij.openapi.vfs.LocalFileSystem;
|
||||
import com.intellij.openapi.vfs.VirtualFileSystem;
|
||||
import org.jetbrains.jet.compiler.AbstractCompileEnvironment;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
/**
|
||||
* @author alex.tkachman
|
||||
*/
|
||||
public class PluginCompilerEnvironment extends AbstractCompileEnvironment {
|
||||
public PluginCompilerEnvironment(Project project) {
|
||||
this.project = project;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void addToClasspath(File file) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public VirtualFileSystem getLocalFileSystem() {
|
||||
return LocalFileSystem.getInstance();
|
||||
}
|
||||
|
||||
@Override
|
||||
public VirtualFileSystem getJarFileSystem() {
|
||||
return JarFileSystem.getInstance();
|
||||
}
|
||||
}
|
||||
@@ -11,7 +11,6 @@ import com.intellij.psi.PsiFile;
|
||||
import com.intellij.psi.PsiManager;
|
||||
import com.intellij.util.Function;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.compiler.CompileSession;
|
||||
import org.jetbrains.jet.lang.psi.JetDeclaration;
|
||||
import org.jetbrains.jet.lang.psi.JetFile;
|
||||
import org.jetbrains.jet.lang.resolve.BindingContext;
|
||||
@@ -41,11 +40,6 @@ public final class WholeProjectAnalyzerFacade {
|
||||
final Set<JetDeclaration> namespaces = Sets.newLinkedHashSet();
|
||||
final ProjectRootManager rootManager = ProjectRootManager.getInstance(project);
|
||||
|
||||
PluginCompilerEnvironment environment = new PluginCompilerEnvironment(project);
|
||||
CompileSession session = new CompileSession(environment);
|
||||
session.addStdLibSources(true);
|
||||
namespaces.addAll(session.getLibrarySourceFileNamespaces());
|
||||
|
||||
if (rootManager != null /* && !ApplicationManager.getApplication().isUnitTestMode() */) {
|
||||
VirtualFile[] contentRoots = rootManager.getContentRoots();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user