provide a hook so we can add post processors into the compiler; such as for generating javadoc etc

This commit is contained in:
James Strachan
2012-02-21 11:29:36 +00:00
parent a68b00dfd4
commit 44169529f3
7 changed files with 106 additions and 2 deletions
+1
View File
@@ -13,6 +13,7 @@
<orderEntry type="module" module-name="stdlib" />
<orderEntry type="module" module-name="jet.as.java.psi" />
<orderEntry type="library" name="intellij-core" level="project" />
<orderEntry type="library" name="asm" level="project" />
</component>
</module>
@@ -0,0 +1,41 @@
/**
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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.
*/
package org.jetbrains.jet.cli;
import org.jetbrains.jet.compiler.JetFileProcessor;
import org.jetbrains.jet.lang.psi.JetDeclaration;
import org.jetbrains.jet.lang.psi.JetFile;
import org.jetbrains.jet.lang.resolve.java.AnalyzerFacade;
import java.util.List;
/**
*/
public class KDocProcessor implements JetFileProcessor {
private final String outputDir;
public KDocProcessor(String outputDir) {
this.outputDir = outputDir;
}
@Override
public void processFiles(List<JetFile> sources) {
// TODO fire up the KDoc processor here...
}
}
@@ -47,6 +47,9 @@ public class KotlinCompiler {
@Argument(value = "output", description = "output directory")
public String outputDir;
@Argument(value = "docOutput", description = "KDoc output directory")
public String docOutputDir;
@Argument(value = "jar", description = "jar file name")
public String jar;
@@ -124,6 +127,10 @@ public class KotlinCompiler {
environment.setErrorStream(errStream);
}
if (arguments.docOutputDir != null) {
environment.getMyEnvironment().getFileProcessors().add(new KDocProcessor(arguments.docOutputDir));
}
if (arguments.stdlib != null) {
environment.setStdlib(arguments.stdlib);
}
@@ -415,4 +415,8 @@ public class CompileEnvironment {
throw new RuntimeException(e);
}
}
public JetCoreEnvironment getMyEnvironment() {
return myEnvironment;
}
}
@@ -17,6 +17,7 @@
package org.jetbrains.jet.compiler;
import com.google.common.base.Predicates;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.psi.PsiErrorElement;
@@ -198,8 +199,17 @@ public class CompileSession {
@NotNull
public ClassFileFactory generate() {
GenerationState generationState = new GenerationState(myEnvironment.getProject(), ClassBuilderFactory.BINARIES, myFileNameTransformer);
Project project = myEnvironment.getProject();
GenerationState generationState = new GenerationState(project, ClassBuilderFactory.BINARIES, myFileNameTransformer);
generationState.compileCorrectFiles(myBindingContext, mySourceFiles);
return generationState.getFactory();
ClassFileFactory answer = generationState.getFactory();
List<JetFileProcessor> fileProcessors = myEnvironment.getFileProcessors();
if (fileProcessors != null) {
for (JetFileProcessor processor : fileProcessors) {
processor.processFiles(getSourceFileNamespaces());
}
}
return answer;
}
}
@@ -26,10 +26,15 @@ import org.jetbrains.jet.lang.types.JetStandardLibrary;
import org.jetbrains.jet.plugin.JetFileType;
import org.jetbrains.jet.plugin.compiler.PathUtil;
import java.util.ArrayList;
import java.util.List;
/**
* @author yole
*/
public class JetCoreEnvironment extends JavaCoreEnvironment {
private List<JetFileProcessor> fileProcessors = new ArrayList<JetFileProcessor>();
public JetCoreEnvironment(Disposable parentDisposable) {
super(parentDisposable);
registerFileType(JetFileType.INSTANCE, "kt");
@@ -55,4 +60,12 @@ public class JetCoreEnvironment extends JavaCoreEnvironment {
public MockApplication getApplication() {
return myApplication;
}
public List<JetFileProcessor> getFileProcessors() {
return fileProcessors;
}
public void setFileProcessors(List<JetFileProcessor> fileProcessors) {
this.fileProcessors = fileProcessors;
}
}
@@ -0,0 +1,28 @@
/**
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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.
*/
package org.jetbrains.jet.compiler;
import org.jetbrains.jet.lang.psi.JetFile;
import java.util.List;
/**
*/
public interface JetFileProcessor {
void processFiles(List<JetFile> sources);
}