use our groovy stub generator by default, give an UI option to switch to groovyc's one for perverts (IDEADEV-42045)

This commit is contained in:
peter
2009-12-21 15:18:53 +00:00
parent 61558d1967
commit d90dec9ace
6 changed files with 59 additions and 22 deletions
@@ -8,7 +8,7 @@
<properties/>
<border type="none"/>
<children>
<grid id="838f2" layout-manager="GridLayoutManager" row-count="1" column-count="3" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<grid id="838f2" layout-manager="GridLayoutManager" row-count="2" column-count="3" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
@@ -37,6 +37,14 @@
<grid row="0" column="2" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
</hspacer>
<component id="cb8cb" class="javax.swing.JCheckBox" binding="myUseGroovycStubs">
<constraints>
<grid row="1" column="0" row-span="1" col-span="3" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Use groovyc's native &amp;stub generator"/>
</properties>
</component>
</children>
</grid>
<grid id="4e3dc" binding="myExcludesPanel" layout-manager="BorderLayout" hgap="0" vgap="0">
@@ -43,6 +43,7 @@ public class GroovyCompilerConfigurable implements SearchableConfigurable, Compi
private JTextField myHeapSize;
private JPanel myMainPanel;
private JPanel myExcludesPanel;
private JCheckBox myUseGroovycStubs;
private ExcludedEntriesConfigurable myExcludes;
private final GroovyCompilerConfiguration myConfig;
@@ -100,16 +101,20 @@ public class GroovyCompilerConfigurable implements SearchableConfigurable, Compi
}
public boolean isModified() {
return !Comparing.equal(myConfig.getHeapSize(), myHeapSize.getText()) || myExcludes.isModified();
return !Comparing.equal(myConfig.getHeapSize(), myHeapSize.getText()) ||
myExcludes.isModified() ||
myConfig.isUseGroovycStubs() != myUseGroovycStubs.isSelected();
}
public void apply() throws ConfigurationException {
myExcludes.apply();
myConfig.setHeapSize(myHeapSize.getText());
myConfig.setUseGroovycStubs(myUseGroovycStubs.isSelected());
}
public void reset() {
myHeapSize.setText(myConfig.getHeapSize());
myUseGroovycStubs.setSelected(myConfig.isUseGroovycStubs());
myExcludes.reset();
}
@@ -36,11 +36,13 @@ import org.jdom.Element;
)
public class GroovyCompilerConfiguration implements PersistentStateComponent<GroovyCompilerConfiguration.MyStateBean>, Disposable {
private String myHeapSize = "400";
private boolean myUseGroovycStubs = false;
private final ExcludedEntriesConfiguration myExcludeFromStubGeneration = new ExcludedEntriesConfiguration();
public MyStateBean getState() {
final MyStateBean bean = new MyStateBean();
bean.heapSize = myHeapSize;
bean.useGroovycStubs = myUseGroovycStubs;
myExcludeFromStubGeneration.writeExternal(bean.excludes);
return bean;
}
@@ -55,11 +57,7 @@ public class GroovyCompilerConfiguration implements PersistentStateComponent<Gro
public void loadState(MyStateBean state) {
myHeapSize = state.heapSize;
final Element oldStyle = state.option.getChild("ExcludedEntriesConfiguration");
if (oldStyle != null) {
myExcludeFromStubGeneration.readExternal(oldStyle);
return;
}
myUseGroovycStubs = state.useGroovycStubs;
myExcludeFromStubGeneration.readExternal(state.excludes);
}
@@ -76,6 +74,14 @@ public class GroovyCompilerConfiguration implements PersistentStateComponent<Gro
myHeapSize = heapSize;
}
public boolean isUseGroovycStubs() {
return myUseGroovycStubs;
}
public void setUseGroovycStubs(boolean useGroovycStubs) {
myUseGroovycStubs = useGroovycStubs;
}
public void dispose() {
Disposer.dispose(myExcludeFromStubGeneration);
}
@@ -85,7 +91,7 @@ public class GroovyCompilerConfiguration implements PersistentStateComponent<Gro
@Tag("excludes") public Element excludes = new Element("aaa");
//todo remove after Maia beta
@Tag("option") public Element option = new Element("bbb");
public boolean useGroovycStubs = false;
}
}
@@ -41,15 +41,13 @@ public class GroovyCompilerLoader extends AbstractProjectComponent {
CompilerManager compilerManager = CompilerManager.getInstance(myProject);
compilerManager.addCompilableFileType(GroovyFileType.GROOVY_FILE_TYPE);
if (System.getProperty("use.groovyc.stub.generator", "true").equals("true")) {
compilerManager.addTranslatingCompiler(new GroovycStubGenerator(myProject),
new HashSet<FileType>(Arrays.asList(GroovyFileType.GROOVY_FILE_TYPE, StdFileTypes.JAVA)),
new HashSet<FileType>(Arrays.asList(StdFileTypes.JAVA)));
} else {
GroovyToJavaGenerator generator = new GroovyToJavaGenerator(myProject);
compilerManager.addCompiler(generator);
compilerManager.addCompilationStatusListener(generator);
}
compilerManager.addTranslatingCompiler(new GroovycStubGenerator(myProject),
new HashSet<FileType>(Arrays.asList(GroovyFileType.GROOVY_FILE_TYPE, StdFileTypes.JAVA)),
new HashSet<FileType>(Arrays.asList(StdFileTypes.JAVA)));
GroovyToJavaGenerator generator = new GroovyToJavaGenerator(myProject);
compilerManager.addCompiler(generator);
compilerManager.addCompilationStatusListener(generator);
compilerManager.addTranslatingCompiler(new GroovyCompiler(myProject),
new HashSet<FileType>(Arrays.asList(GroovyFileType.GROOVY_FILE_TYPE, StdFileTypes.CLASS)),
@@ -114,6 +114,10 @@ public class GroovyToJavaGenerator implements SourceGeneratingCompiler, Compilat
}
public GenerationItem[] getGenerationItems(CompileContext context) {
if (GroovyCompilerConfiguration.getInstance(myProject).isUseGroovycStubs()) {
return new GenerationItem[0];
}
myContext = context;
List<GenerationItem> generationItems = new ArrayList<GenerationItem>();
@@ -24,9 +24,9 @@ import com.intellij.openapi.compiler.CompileScope;
import com.intellij.openapi.compiler.CompilerPaths;
import com.intellij.openapi.compiler.ex.CompileContextEx;
import com.intellij.openapi.compiler.options.ExcludedEntriesConfiguration;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.fileTypes.StdFileTypes;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.module.ModuleUtil;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.io.FileUtil;
import com.intellij.openapi.vfs.LocalFileSystem;
@@ -47,7 +47,6 @@ import java.util.List;
* @author peter
*/
public class GroovycStubGenerator extends GroovyCompilerBase {
private static final Logger LOG = Logger.getInstance("#org.jetbrains.plugins.groovy.compiler.generator.GroovycStubGenerator");
public GroovycStubGenerator(Project project) {
super(project);
@@ -55,8 +54,26 @@ public class GroovycStubGenerator extends GroovyCompilerBase {
@Override
public void compile(CompileContext compileContext, Chunk<Module> moduleChunk, VirtualFile[] virtualFiles, OutputSink sink) {
if (!GroovyCompilerConfiguration.getInstance(myProject).isUseGroovycStubs()) {
return;
}
final CompileScope scope = compileContext.getCompileScope();
if (scope.getFiles(StdFileTypes.JAVA, true).length == 0) {
final VirtualFile[] javaFiles = scope.getFiles(StdFileTypes.JAVA, true);
if (javaFiles.length == 0) {
return;
}
boolean hasJava = false;
for (VirtualFile javaFile : javaFiles) {
final Module module = ModuleUtil.findModuleForFile(javaFile, myProject);
if (module != null && moduleChunk.containsNode(module)) {
hasJava = true;
break;
}
}
if (!hasJava) {
return;
}
@@ -103,7 +120,6 @@ public class GroovycStubGenerator extends GroovyCompilerBase {
if (!hasJava) {
//always pass groovyc stub generator at least 1 java file, or it won't generate stubs
//todo not needed anymore with groovy 1.7?
toCompile.add(createMockJavaFile(rootPath));
}