Refactor dependencies, so jet-as-java might be used in cli.

This commit is contained in:
Maxim Shafirov
2012-03-29 21:18:35 +04:00
parent b29c31ad2d
commit 060be0a8f8
37 changed files with 263 additions and 140 deletions
@@ -0,0 +1,60 @@
/*
* 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.
*/
/*
* @author max
*/
package org.jetbrains.jet.compiler;
import com.intellij.psi.search.GlobalSearchScope;
import com.intellij.util.Function;
import org.jetbrains.jet.lang.psi.JetFile;
import org.jetbrains.jet.lang.resolve.java.JetFilesProvider;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
public class CliJetFilesProvider extends JetFilesProvider {
private final JetCoreEnvironment environment;
private Function<JetFile,Collection<JetFile>> all_files = new Function<JetFile, Collection<JetFile>>() {
@Override
public Collection<JetFile> fun(JetFile file) {
return environment.getSession().getSourceFiles();
}
};
public CliJetFilesProvider(JetCoreEnvironment environment) {
this.environment = environment;
}
@Override
public Function<JetFile, Collection<JetFile>> sampleToAllFilesInModule() {
return all_files;
}
@Override
public List<JetFile> allInScope(GlobalSearchScope scope) {
List<JetFile> answer = new ArrayList<JetFile>();
for (JetFile file : environment.getSession().getSourceFiles()) {
if (scope.contains(file.getVirtualFile())) {
answer.add(file);
}
}
return answer;
}
}
@@ -394,7 +394,7 @@ public class CompileEnvironment {
session.addSources(sourceFileOrDir);
FqName mainClass = null;
for (JetFile file : session.getSourceFileNamespaces()) {
for (JetFile file : session.getSourceFiles()) {
if (JetMainDetector.hasMain(file.getDeclarations())) {
FqName fqName = JetPsiUtil.getFQName(file);
mainClass = fqName.child(JvmAbi.PACKAGE_CLASS);
@@ -426,7 +426,9 @@ public class CompileEnvironment {
}
private CompileSession newCompileSession() {
return new CompileSession(environment, messageRenderer, errorStream, verbose);
CompileSession answer = new CompileSession(environment, messageRenderer, errorStream, verbose);
environment.setSession(answer);
return answer;
}
public static void writeToOutputDirectory(ClassFileFactory factory, final String outputDir) {
@@ -26,7 +26,10 @@ import com.intellij.psi.PsiFile;
import com.intellij.psi.PsiManager;
import com.intellij.psi.PsiRecursiveElementWalkingVisitor;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.codegen.*;
import org.jetbrains.jet.codegen.ClassBuilderFactories;
import org.jetbrains.jet.codegen.CompilationErrorHandler;
import org.jetbrains.jet.codegen.GenerationState;
import org.jetbrains.jet.codegen.JetTypeMapper;
import org.jetbrains.jet.lang.cfg.pseudocode.JetControlFlowDataTraceFactory;
import org.jetbrains.jet.lang.descriptors.ClassDescriptor;
import org.jetbrains.jet.lang.descriptors.ClassOrNamespaceDescriptor;
@@ -136,7 +139,7 @@ public class CompileSession {
}
}
public List<JetFile> getSourceFileNamespaces() {
public List<JetFile> getSourceFiles() {
return sourceFiles;
}
@@ -221,7 +224,7 @@ public class CompileSession {
List<CompilerPlugin> plugins = environment.getCompilerPlugins();
if (!module) {
if (plugins != null) {
CompilerPluginContext context = new CompilerPluginContext(project, bindingContext.getBindingContext(), getSourceFileNamespaces());
CompilerPluginContext context = new CompilerPluginContext(project, bindingContext.getBindingContext(), getSourceFiles());
for (CompilerPlugin plugin : plugins) {
plugin.processFiles(context);
}
@@ -20,8 +20,12 @@ import com.intellij.core.JavaCoreEnvironment;
import com.intellij.lang.java.JavaParserDefinition;
import com.intellij.mock.MockApplication;
import com.intellij.openapi.Disposable;
import com.intellij.openapi.extensions.Extensions;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.psi.PsiElementFinder;
import org.jetbrains.jet.asJava.JavaElementFinder;
import org.jetbrains.jet.lang.parsing.JetParserDefinition;
import org.jetbrains.jet.lang.resolve.java.JetFilesProvider;
import org.jetbrains.jet.lang.types.lang.JetStandardLibrary;
import org.jetbrains.jet.plugin.JetFileType;
import org.jetbrains.jet.utils.PathUtil;
@@ -37,6 +41,7 @@ import java.util.List;
*/
public class JetCoreEnvironment extends JavaCoreEnvironment {
private List<CompilerPlugin> compilerPlugins = new ArrayList<CompilerPlugin>();
private CompileSession session;
public JetCoreEnvironment(Disposable parentDisposable) {
super(parentDisposable);
@@ -47,11 +52,11 @@ public class JetCoreEnvironment extends JavaCoreEnvironment {
registerParserDefinition(new JavaParserDefinition());
registerParserDefinition(new JetParserDefinition());
/*
myProject.registerService(JetFilesProvider.class, new CliJetFilesProvider(this));
Extensions.getArea(myProject)
.getExtensionPoint(PsiElementFinder.EP_NAME)
.registerExtension(new JavaElementFinder(myProject));
*/
for (VirtualFile root : PathUtil.getAltHeadersRoots()) {
addLibraryRoot(root);
@@ -85,4 +90,12 @@ public class JetCoreEnvironment extends JavaCoreEnvironment {
}
}
}
public void setSession(CompileSession session) {
this.session = session;
}
public CompileSession getSession() {
return session;
}
}