From 2e4f5d0bad762af3e0f0403d33df4b96916750f4 Mon Sep 17 00:00:00 2001 From: Eugene Zhuravlev Date: Mon, 16 Nov 2009 21:54:05 +0300 Subject: [PATCH] UI for generated sources output dir handling --- .../compiler/CompilerConfigurationImpl.java | 78 +++++---- .../intellij/compiler/impl/CompileDriver.java | 12 +- .../AnnotationProcessingCompiler.java | 2 +- .../AnnotationProcessorsConfigurable.java | 41 +++-- .../options/ProcessedModulesChooser.java | 154 ++++++++++-------- .../compiler/CompilerConfiguration.java | 10 +- .../openapi/compiler/CompilerPaths.java | 2 +- 7 files changed, 175 insertions(+), 124 deletions(-) diff --git a/java/compiler/impl/src/com/intellij/compiler/CompilerConfigurationImpl.java b/java/compiler/impl/src/com/intellij/compiler/CompilerConfigurationImpl.java index ab4a23c4cd78..bf4a1f606a73 100644 --- a/java/compiler/impl/src/com/intellij/compiler/CompilerConfigurationImpl.java +++ b/java/compiler/impl/src/com/intellij/compiler/CompilerConfigurationImpl.java @@ -54,6 +54,7 @@ public class CompilerConfigurationImpl extends CompilerConfiguration implements private static final Logger LOG = Logger.getInstance("#com.intellij.compiler.CompilerConfiguration"); @NonNls public static final String TESTS_EXTERNAL_COMPILER_HOME_PROPERTY_NAME = "tests.external.compiler.home"; public static final int DEPENDENCY_FORMAT_VERSION = 54; + private static final String DEFAULT_GENERATED_DIR_NAME = "generated"; @SuppressWarnings({"WeakerAccess"}) public String DEFAULT_COMPILER; @NotNull private BackendCompiler myDefaultJavaCompiler; @@ -80,11 +81,10 @@ public class CompilerConfigurationImpl extends CompilerConfiguration implements private boolean myEnableAnnotationProcessors = false; private final Map myProcessorsMap = new HashMap(); // map: AnnotationProcessorName -> options private boolean myObtainProcessorsFromClasspath = true; - private boolean myStoreGenerateSourcesUnderModuleContent = false; - private String myGeneratedDirName = "generated"; + private String myGeneratedDirName = DEFAULT_GENERATED_DIR_NAME; private String myProcessorPath = ""; - private final Set myExcludedModules = new HashSet(); - private final Set myExcludedModuleNames = new HashSet(); + private final Map myProcessedModules = new HashMap(); + private final Map myModuleNames = new HashMap(); public CompilerConfigurationImpl(Project project, ModuleManager moduleManager) { @@ -100,13 +100,14 @@ public class CompilerConfigurationImpl extends CompilerConfiguration implements } public void beforeModuleRemoved(Project project, Module module) { - myExcludedModules.remove(module); - myExcludedModuleNames.remove(module.getName()); + myProcessedModules.remove(module); + myModuleNames.remove(module.getName()); } public void moduleAdded(Project project, Module module) { - if (myExcludedModuleNames.remove(module.getName())) { - myExcludedModules.add(module); + final Boolean storeUnderContent = myModuleNames.remove(module.getName()); + if (storeUnderContent != null) { + myProcessedModules.put(module, storeUnderContent); } } }); @@ -312,22 +313,18 @@ public class CompilerConfigurationImpl extends CompilerConfiguration implements myObtainProcessorsFromClasspath = obtainProcessorsFromClasspath; } - public boolean isStoreGenerateSourcesUnderModuleContent(Module module) { - // todo: make this per-module setting - return myStoreGenerateSourcesUnderModuleContent; - } - - public void setStoreGenerateSourcesUnderModuleContent(boolean storeGenerateSourcesUnderModuleContent) { - myStoreGenerateSourcesUnderModuleContent = storeGenerateSourcesUnderModuleContent; - } - @NotNull public String getGeneratedDirName() { return myGeneratedDirName; } public void setGeneratedDirName(String generatedDirName) { - myGeneratedDirName = generatedDirName; + if (generatedDirName == null || generatedDirName.length() == 0) { + myGeneratedDirName = DEFAULT_GENERATED_DIR_NAME; + } + else { + myGeneratedDirName = generatedDirName; + } } public String getProcessorPath() { @@ -347,14 +344,22 @@ public class CompilerConfigurationImpl extends CompilerConfiguration implements myProcessorsMap.putAll(map); } - public Set getExcludedModules() { - return Collections.unmodifiableSet(myExcludedModules); + public void setAnotationProcessedModules(Map modules) { + myProcessedModules.clear(); + myModuleNames.clear(); + myProcessedModules.putAll(modules); } - public void setExcludedModules(Collection modules) { - myExcludedModules.clear(); - myExcludedModuleNames.clear(); - myExcludedModules.addAll(modules); + public Map getAnotationProcessedModules() { + return Collections.unmodifiableMap(myProcessedModules); + } + + public boolean isAnnotationProcessingEnabled(Module module) { + return myProcessedModules.containsKey(module); + } + + public boolean isStoreGeneratedSourcesUnderContent(Module module) { + return Boolean.TRUE.equals(myProcessedModules.get(module)); } private void addWildcardResourcePattern(@NonNls final String wildcardPattern) throws MalformedPatternException { @@ -542,8 +547,7 @@ public class CompilerConfigurationImpl extends CompilerConfiguration implements if (annotationProcessingSettings != null) { myEnableAnnotationProcessors = Boolean.valueOf(annotationProcessingSettings.getAttributeValue("enabled", "false")); myObtainProcessorsFromClasspath = Boolean.valueOf(annotationProcessingSettings.getAttributeValue("useClasspath", "true")); - myStoreGenerateSourcesUnderModuleContent = Boolean.valueOf(annotationProcessingSettings.getAttributeValue("storeGeneratedUnderContent", "false")); - myGeneratedDirName = annotationProcessingSettings.getAttributeValue("generatedDirName", "generated"); + myGeneratedDirName = annotationProcessingSettings.getAttributeValue("generatedDirName", DEFAULT_GENERATED_DIR_NAME); final StringBuilder pathBuilder = new StringBuilder(); for (Element pathElement : ((Collection)annotationProcessingSettings.getChildren("processorPath"))) { @@ -563,23 +567,25 @@ public class CompilerConfigurationImpl extends CompilerConfiguration implements final String options = processorChild.getAttributeValue("options", ""); myProcessorsMap.put(name, options); } - myExcludedModules.clear(); - myExcludedModuleNames.clear(); - final Collection excluded = (Collection)annotationProcessingSettings.getChildren("excludeModule"); - if (excluded.size() > 0) { + myProcessedModules.clear(); + myModuleNames.clear(); + + final Collection processed = (Collection)annotationProcessingSettings.getChildren("processModule"); + if (processed.size() > 0) { final Map moduleMap = new com.intellij.util.containers.HashMap(); for (Module module : myModuleManager.getModules()) { moduleMap.put(module.getName(), module); } - for (Element moduleElement : excluded) { + for (Element moduleElement : processed) { final String name = moduleElement.getAttributeValue("name"); + final Boolean isStoreUnderContent = Boolean.valueOf(moduleElement.getAttributeValue("storeGeneratedUnderContent", "false")); if (name != null) { final Module module = moduleMap.get(name); if (module != null) { - myExcludedModules.add(module); + myProcessedModules.put(module, isStoreUnderContent); } else { - myExcludedModuleNames.add(name); + myModuleNames.put(name, isStoreUnderContent); } } } @@ -618,7 +624,6 @@ public class CompilerConfigurationImpl extends CompilerConfiguration implements parentNode.addContent(annotationProcessingSettings); annotationProcessingSettings.setAttribute("enabled", String.valueOf(myEnableAnnotationProcessors)); annotationProcessingSettings.setAttribute("useClasspath", String.valueOf(myObtainProcessorsFromClasspath)); - annotationProcessingSettings.setAttribute("storeGeneratedUnderContent", String.valueOf(myStoreGenerateSourcesUnderModuleContent)); annotationProcessingSettings.setAttribute("generatedDirName", myGeneratedDirName); if (myProcessorPath.length() > 0) { final StringTokenizer tokenizer = new StringTokenizer(myProcessorPath, File.pathSeparator, false); @@ -635,16 +640,17 @@ public class CompilerConfigurationImpl extends CompilerConfiguration implements processor.setAttribute("name", entry.getKey()); processor.setAttribute("options", entry.getValue()); } - final List modules = new ArrayList(getExcludedModules()); + final List modules = new ArrayList(myProcessedModules.keySet()); Collections.sort(modules, new Comparator() { public int compare(Module o1, Module o2) { return o1.getName().compareToIgnoreCase(o2.getName()); } }); for (Module module : modules) { - final Element moduleElement = new Element("excludeModule"); + final Element moduleElement = new Element("processModule"); annotationProcessingSettings.addContent(moduleElement); moduleElement.setAttribute("name", module.getName()); + moduleElement.setAttribute("storeGeneratedUnderContent", String.valueOf(isStoreGeneratedSourcesUnderContent(module))); } } diff --git a/java/compiler/impl/src/com/intellij/compiler/impl/CompileDriver.java b/java/compiler/impl/src/com/intellij/compiler/impl/CompileDriver.java index 9e054c8bc751..e34ec539697e 100644 --- a/java/compiler/impl/src/com/intellij/compiler/impl/CompileDriver.java +++ b/java/compiler/impl/src/com/intellij/compiler/impl/CompileDriver.java @@ -155,7 +155,7 @@ public class CompileDriver { myGenerationCompilerModuleToOutputDirMap.put(pair, outputs); } if (config.isAnnotationProcessorsEnabled()) { - if (!config.getExcludedModules().contains(module)) { + if (config.isAnnotationProcessingEnabled(module)) { final String path = CompilerPaths.getAnnotationProcessorsGenerationPath(module); if (path != null) { lookupVFile(lfs, path); // ensure the file is created and added to VFS @@ -1181,7 +1181,7 @@ public class CompileDriver { final CompilerConfiguration config = CompilerConfiguration.getInstance(myProject); if (config.isAnnotationProcessorsEnabled()) { for (Module module : modules) { - if (!config.getExcludedModules().contains(module)) { + if (config.isAnnotationProcessingEnabled(module)) { final String path = CompilerPaths.getAnnotationProcessorsGenerationPath(module); if (path != null) { outputDirs.add(new File(path)); @@ -1874,10 +1874,11 @@ public class CompileDriver { modulesWithoutOutputPathSpecified.add(module.getName()); } } - if (config.isAnnotationProcessorsEnabled() && !config.getExcludedModules().contains(module)) { + if (config.isAnnotationProcessorsEnabled() && config.isAnnotationProcessingEnabled(module)) { final String path = CompilerPaths.getAnnotationProcessorsGenerationPath(module); if (path == null) { - if (CompilerProjectExtension.getInstance(module.getProject()).getCompilerOutputUrl() == null) { + final CompilerProjectExtension extension = CompilerProjectExtension.getInstance(module.getProject()); + if (extension == null || extension.getCompilerOutputUrl() == null) { isProjectCompilePathSpecified = false; } else { @@ -1958,9 +1959,8 @@ public class CompileDriver { continue; // no need to check one-module chunks } if (config.isAnnotationProcessorsEnabled()) { - final Set excluded = config.getExcludedModules(); for (Module chunkModule : chunkModules) { - if (!excluded.contains(chunkModule)) { + if (config.isAnnotationProcessingEnabled(chunkModule)) { showCyclesNotSupportedForAnnotationProcessors(chunkModules.toArray(new Module[chunkModules.size()])); return false; } diff --git a/java/compiler/impl/src/com/intellij/compiler/impl/javaCompiler/AnnotationProcessingCompiler.java b/java/compiler/impl/src/com/intellij/compiler/impl/javaCompiler/AnnotationProcessingCompiler.java index 5cb1e3e76f1a..0a381533fc76 100644 --- a/java/compiler/impl/src/com/intellij/compiler/impl/javaCompiler/AnnotationProcessingCompiler.java +++ b/java/compiler/impl/src/com/intellij/compiler/impl/javaCompiler/AnnotationProcessingCompiler.java @@ -112,7 +112,7 @@ public class AnnotationProcessingCompiler implements TranslatingCompiler{ private boolean isExcludedFromAnnotationProcessing(VirtualFile file, CompileContext context) { final Module module = context.getModuleByFile(file); if (module != null) { - if (myConfig.getExcludedModules().contains(module)) { + if (!myConfig.isAnnotationProcessingEnabled(module)) { return true; } final String path = CompilerPaths.getAnnotationProcessorsGenerationPath(module); diff --git a/java/compiler/impl/src/com/intellij/compiler/options/AnnotationProcessorsConfigurable.java b/java/compiler/impl/src/com/intellij/compiler/options/AnnotationProcessorsConfigurable.java index cfa2e7c112d4..2c55ff53099a 100644 --- a/java/compiler/impl/src/com/intellij/compiler/options/AnnotationProcessorsConfigurable.java +++ b/java/compiler/impl/src/com/intellij/compiler/options/AnnotationProcessorsConfigurable.java @@ -9,6 +9,8 @@ import com.intellij.openapi.options.Configurable; import com.intellij.openapi.options.ConfigurationException; import com.intellij.openapi.project.Project; import com.intellij.openapi.ui.TextFieldWithBrowseButton; +import com.intellij.openapi.ui.ex.MultiLineLabel; +import com.intellij.openapi.util.Pair; import com.intellij.openapi.util.io.FileUtil; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.ui.TableUtil; @@ -29,7 +31,10 @@ import java.awt.event.ActionListener; import java.awt.event.ItemEvent; import java.awt.event.ItemListener; import java.io.File; -import java.util.*; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; +import java.util.Map; /** * @author Eugene Zhuravlev @@ -43,6 +48,7 @@ public class AnnotationProcessorsConfigurable implements Configurable{ private TextFieldWithBrowseButton myProcessorPathField; private ProcessorTableModel myProcessorsModel; private JCheckBox myCbEnableProcessing; + private JTextField myGeneratedSourcesDirField; private JButton myRemoveButton; private Table myProcessorTable; private JButton myAddButton; @@ -107,12 +113,19 @@ public class AnnotationProcessorsConfigurable implements Configurable{ myModulesChooser = new ProcessedModulesChooser(); myModulesChooser.setBorder(BorderFactory.createTitledBorder("Processed Modules")); + final JLabel noteMessage = new MultiLineLabel("Source files generated by annotation processors will be stored under the project output directory.\n" + + "To override this behaviour for certain modules see the corresponding option in the table below.\n" + + "If checked, the directory will be created under corresponding module's content root."); + myGeneratedSourcesDirField = new JTextField(); mainPanel.add(myCbEnableProcessing, new GridBagConstraints(0, GridBagConstraints.RELATIVE, 2, 1, 1.0, 0.0, GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, new Insets(5, 0, 0, 0), 0, 0)); mainPanel.add(myRbClasspath, new GridBagConstraints(0, GridBagConstraints.RELATIVE, 2, 1, 1.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(10, 0, 0, 0), 0, 0)); mainPanel.add(myRbProcessorsPath, new GridBagConstraints(0, GridBagConstraints.RELATIVE, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5, 0, 0, 0), 0, 0)); mainPanel.add(myProcessorPathField, new GridBagConstraints(1, GridBagConstraints.RELATIVE, 1, 1, 1.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 0, 0), 0, 0)); mainPanel.add(processorTablePanel, new GridBagConstraints(0, GridBagConstraints.RELATIVE, 2, 1, 1.0, 1.0, GridBagConstraints.NORTHWEST, GridBagConstraints.BOTH, new Insets(10, 0, 0, 0), 0, 0)); + mainPanel.add(noteMessage, new GridBagConstraints(0, GridBagConstraints.RELATIVE, 2, 1, 1.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(10, 5, 0, 0), 0, 0)); + mainPanel.add(new JLabel("Generated sources directory name: "), new GridBagConstraints(0, GridBagConstraints.RELATIVE, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(10, 5, 0, 0), 0, 0)); + mainPanel.add(myGeneratedSourcesDirField, new GridBagConstraints(1, GridBagConstraints.RELATIVE, 1, 1, 1.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(10, 0, 0, 0), 0, 0)); mainPanel.add(myModulesChooser, new GridBagConstraints(0, GridBagConstraints.RELATIVE, 2, 1, 1.0, 1.0, GridBagConstraints.NORTHWEST, GridBagConstraints.BOTH, new Insets(10, 0, 0, 0), 0, 0)); @@ -191,7 +204,11 @@ public class AnnotationProcessorsConfigurable implements Configurable{ return true; } - if (!getExcludedModules().equals(config.getExcludedModules())) { + if (!myGeneratedSourcesDirField.getText().trim().equals(config.getGeneratedDirName().trim())) { + return true; + } + + if (!getMarkedModules().equals(config.getAnotationProcessedModules())) { return true; } @@ -207,13 +224,17 @@ public class AnnotationProcessorsConfigurable implements Configurable{ config.setAnnotationProcessorsMap(myProcessorsModel.exportToMap()); - config.setExcludedModules(getExcludedModules()); + config.setGeneratedDirName(myGeneratedSourcesDirField.getText().trim()); + + config.setAnotationProcessedModules(getMarkedModules()); } - private Set getExcludedModules() { - final Set excludedModules = new HashSet(Arrays.asList(ModuleManager.getInstance(myProject).getModules())); - excludedModules.removeAll(new HashSet(myModulesChooser.getMarkedElements())); - return excludedModules; + private Map getMarkedModules() { + final Map result = new HashMap(); + for (Pair pair : myModulesChooser.getMarkedModules()) { + result.put(pair.getFirst(), pair.getSecond()); + } + return result; } public void reset() { @@ -232,11 +253,11 @@ public class AnnotationProcessorsConfigurable implements Configurable{ myProcessorsModel.setProcessorMap(config.getAnnotationProcessorsMap()); - // excludes - final Set excludedModules = new HashSet(config.getExcludedModules()); + myGeneratedSourcesDirField.setText(config.getGeneratedDirName().trim()); + myModulesChooser.removeAllElements(); for (final Module module : ModuleManager.getInstance(myProject).getModules()) { - myModulesChooser.addElement(module, !excludedModules.contains(module)); + myModulesChooser.addModule(module, config.isAnnotationProcessingEnabled(module), config.isStoreGeneratedSourcesUnderContent(module)); } myModulesChooser.sort(new Comparator() { public int compare(Module o1, Module o2) { diff --git a/java/compiler/impl/src/com/intellij/compiler/options/ProcessedModulesChooser.java b/java/compiler/impl/src/com/intellij/compiler/options/ProcessedModulesChooser.java index 82de94917718..790cbac5421b 100644 --- a/java/compiler/impl/src/com/intellij/compiler/options/ProcessedModulesChooser.java +++ b/java/compiler/impl/src/com/intellij/compiler/options/ProcessedModulesChooser.java @@ -16,6 +16,7 @@ package com.intellij.compiler.options; import com.intellij.openapi.module.Module; +import com.intellij.openapi.util.Pair; import com.intellij.openapi.util.io.FileUtil; import com.intellij.ui.ScrollPaneFactory; import com.intellij.ui.SpeedSearchBase; @@ -37,28 +38,43 @@ public class ProcessedModulesChooser extends JPanel { private Table myTable = null; private MyTableModel myTableModel = null; private boolean myColorUnmarkedElements = true; - private final Map myDisabledMap = new HashMap(); public ProcessedModulesChooser() { super(new BorderLayout()); - myTableModel = new MyTableModel(true); + myTableModel = new MyTableModel(); myTable = new Table(myTableModel); myTable.setShowGrid(false); myTable.setIntercellSpacing(new Dimension(0, 0)); - myTable.setTableHeader(null); myTable.setAutoResizeMode(JTable.AUTO_RESIZE_LAST_COLUMN); myTable.setColumnSelectionAllowed(false); JScrollPane pane = ScrollPaneFactory.createScrollPane(myTable); pane.setPreferredSize(new Dimension(100, 155)); - int width = new JCheckBox().getPreferredSize().width; - TableColumnModel columnModel = myTable.getColumnModel(); - TableColumn checkMarkColumn = columnModel.getColumn(myTableModel.CHECK_MARK_COLUM_INDEX); - checkMarkColumn.setPreferredWidth(width); - checkMarkColumn.setMaxWidth(width); - checkMarkColumn.setCellRenderer(new CheckMarkColumnCellRenderer(myTable.getDefaultRenderer(Boolean.class))); - columnModel.getColumn(myTableModel.ELEMENT_COLUMN_INDEX).setCellRenderer(new MyElementColumnCellRenderer()); + final TableColumnModel columnModel = myTable.getColumnModel(); + + final int checkmarkWidth = new JCheckBox().getPreferredSize().width; + final CheckMarkColumnCellRenderer checkmarkRenderer = new CheckMarkColumnCellRenderer(myTable.getDefaultRenderer(Boolean.class)); + + final TableColumn checkMarkColumn = columnModel.getColumn(myTableModel.CHECK_MARK_COLUM_INDEX); + checkMarkColumn.setHeaderValue(""); + checkMarkColumn.setPreferredWidth(checkmarkWidth); + checkMarkColumn.setMaxWidth(checkmarkWidth); + checkMarkColumn.setCellRenderer(checkmarkRenderer); + + TableColumn storeUnderContent = columnModel.getColumn(myTableModel.STORE_UNDER_CONTENT_COLUM_INDEX); + final String title = "Generate Sources Under Content"; + storeUnderContent.setHeaderValue(title); + final JTableHeader tableHeader = myTable.getTableHeader(); + final FontMetrics metrics = tableHeader.getFontMetrics(tableHeader.getFont()); + final int preferredWidth = metrics.stringWidth(title) + 12; + storeUnderContent.setPreferredWidth(preferredWidth); + storeUnderContent.setMaxWidth(preferredWidth); + storeUnderContent.setCellRenderer(checkmarkRenderer); + + final TableColumn moduleColumn = columnModel.getColumn(myTableModel.ELEMENT_COLUMN_INDEX); + moduleColumn.setHeaderValue("Module"); + moduleColumn.setCellRenderer(new MyElementColumnCellRenderer()); add(pane, BorderLayout.CENTER); myTable.registerKeyboardAction( @@ -67,7 +83,7 @@ public class ProcessedModulesChooser extends JPanel { final int[] selectedRows = myTable.getSelectedRows(); boolean currentlyMarked = true; for (int selectedRow : selectedRows) { - currentlyMarked = myTableModel.isElementMarked(selectedRow); + currentlyMarked = myTableModel.isMarked(selectedRow); if (!currentlyMarked) { break; } @@ -88,7 +104,7 @@ public class ProcessedModulesChooser extends JPanel { final int count = myTableModel.getRowCount(); Object[] elements = new Object[count]; for (int idx = 0; idx < count; idx++) { - elements[idx] = myTableModel.getElementAt(idx); + elements[idx] = myTableModel.getModuleAt(idx); } return elements; } @@ -100,7 +116,7 @@ public class ProcessedModulesChooser extends JPanel { public void selectElement(Object element, String selectedText) { final int count = myTableModel.getRowCount(); for (int row = 0; row < count; row++) { - if (element.equals(myTableModel.getElementAt(row))) { + if (element.equals(myTableModel.getModuleAt(row))) { myTable.getSelectionModel().setSelectionInterval(row, row); TableUtil.scrollSelectionToVisible(myTable); break; @@ -134,22 +150,26 @@ public class ProcessedModulesChooser extends JPanel { } } - public void addElement(Module element, final boolean isMarked) { - myTableModel.addElement(element, isMarked); + public void addModule(Module element, final boolean isMarked, boolean isStoreGeneratedSourcesUnderContent) { + myTableModel.addElement(element, isMarked, isStoreGeneratedSourcesUnderContent); selectRow(myTableModel.getRowCount() - 1); myTable.requestFocus(); } public boolean isElementMarked(Module element) { final int elementRow = myTableModel.getElementRow(element); - return myTableModel.isElementMarked(elementRow); + return myTableModel.isMarked(elementRow); } public void setElementMarked(Module element, boolean marked) { final int elementRow = myTableModel.getElementRow(element); - myTableModel.setMarked(elementRow, marked); + myTableModel.updateBooleanMap(elementRow, marked, myTableModel.myMarkedMap); } + public void setStoreGeneratedSourcesUnderContent(Module element, boolean value) { + final int elementRow = myTableModel.getElementRow(element); + myTableModel.updateBooleanMap(elementRow, value, myTableModel.myStoreUnderContentMap); + } public void removeElement(Module element) { final int elementRow = myTableModel.getElementRow(element); @@ -185,7 +205,7 @@ public class ProcessedModulesChooser extends JPanel { @Nullable public Module getSelectedElement() { final int selectedRow = getSelectedElementRow(); - return selectedRow < 0? null : myTableModel.getElementAt(selectedRow); + return selectedRow < 0? null : myTableModel.getModuleAt(selectedRow); } public int getSelectedElementRow() { @@ -199,7 +219,7 @@ public class ProcessedModulesChooser extends JPanel { if (selectedRow < 0) { continue; } - elements.add(myTableModel.getElementAt(selectedRow)); + elements.add(myTableModel.getModuleAt(selectedRow)); } return elements; } @@ -224,17 +244,13 @@ public class ProcessedModulesChooser extends JPanel { return rows; } - public void markElements(Collection elements) { - myTableModel.setMarked(getElementsRows(elements), true); - } - - public List getMarkedElements() { + public List> getMarkedModules() { final int count = myTableModel.getRowCount(); - List elements = new ArrayList(); + List> elements = new ArrayList>(); for (int idx = 0; idx < count; idx++) { - final Module element = myTableModel.getElementAt(idx); - if (myTableModel.isElementMarked(idx)) { - elements.add(element); + final Module module = myTableModel.getModuleAt(idx); + if (myTableModel.isMarked(idx)) { + elements.add(new Pair(module, myTableModel.isGenerateSourcesToContent(module))); } } return elements; @@ -270,50 +286,45 @@ public class ProcessedModulesChooser extends JPanel { } public Module getElementAt(int row) { - return myTableModel.getElementAt(row); - } - - public void disableElement(Module element) { - myDisabledMap.put(element, Boolean.TRUE); + return myTableModel.getModuleAt(row); } private final class MyTableModel extends AbstractTableModel { private final List myElements = new ArrayList(); private final Map myMarkedMap = new HashMap(); - public final int CHECK_MARK_COLUM_INDEX; - public final int ELEMENT_COLUMN_INDEX; - private final boolean myElementsCanBeMarked; - - public MyTableModel(final boolean elementsCanBeMarked) { - myElementsCanBeMarked = elementsCanBeMarked; - if (elementsCanBeMarked) { - CHECK_MARK_COLUM_INDEX = 0; - ELEMENT_COLUMN_INDEX = 1; - } - else { - CHECK_MARK_COLUM_INDEX = -1; - ELEMENT_COLUMN_INDEX = 0; - } - } + private final Map myStoreUnderContentMap = new HashMap(); + public final int CHECK_MARK_COLUM_INDEX = 0; + public final int ELEMENT_COLUMN_INDEX = 1; + public final int STORE_UNDER_CONTENT_COLUM_INDEX = 2; public void sort(Comparator comparator) { Collections.sort(myElements, comparator); fireTableDataChanged(); } - public Module getElementAt(int index) { + public Module getModuleAt(int index) { return myElements.get(index); } - public boolean isElementMarked(int index) { + public boolean isMarked(int index) { final Module element = myElements.get(index); - final Boolean isMarked = myMarkedMap.get(element); - return isMarked.booleanValue(); + return myMarkedMap.get(element).booleanValue(); } - void addElement(Module element, boolean isMarked) { + public boolean isGenerateSourcesToContent(int index) { + final Module element = myElements.get(index); + return myStoreUnderContentMap.get(element).booleanValue(); + } + + public boolean isGenerateSourcesToContent(Module module) { + final Boolean value = myStoreUnderContentMap.get(module); + return value != null && value.booleanValue(); + } + + void addElement(Module element, boolean isMarked, boolean isStoreGeneratedSourcesUnderContent) { myElements.add(element); - myMarkedMap.put(element, isMarked? Boolean.TRUE : Boolean.FALSE); + myMarkedMap.put(element, Boolean.valueOf(isMarked)); + myStoreUnderContentMap.put(element, Boolean.valueOf(isStoreGeneratedSourcesUnderContent)); int row = myElements.size() - 1; fireTableRowsInserted(row, row); } @@ -325,6 +336,7 @@ public class ProcessedModulesChooser extends JPanel { for (final Module element : elements) { myElements.add(element); myMarkedMap.put(element, isMarked ? Boolean.TRUE : Boolean.FALSE); + myStoreUnderContentMap.put(element, Boolean.FALSE); } fireTableRowsInserted(myElements.size() - elements.size(), myElements.size() - 1); } @@ -333,6 +345,7 @@ public class ProcessedModulesChooser extends JPanel { final boolean reallyRemoved = myElements.remove(element); if (reallyRemoved) { myMarkedMap.remove(element); + myStoreUnderContentMap.remove(element); fireTableDataChanged(); } } @@ -360,6 +373,7 @@ public class ProcessedModulesChooser extends JPanel { final Module element = myElements.get(row); toRemove.add(element); myMarkedMap.remove(element); + myStoreUnderContentMap.remove(element); } myElements.removeAll(toRemove); fireTableDataChanged(); @@ -370,7 +384,7 @@ public class ProcessedModulesChooser extends JPanel { } public int getColumnCount() { - return myElementsCanBeMarked? 2 : 1; + return 3; } @Nullable @@ -382,19 +396,25 @@ public class ProcessedModulesChooser extends JPanel { if (columnIndex == CHECK_MARK_COLUM_INDEX) { return myMarkedMap.get(element); } + if (columnIndex == STORE_UNDER_CONTENT_COLUM_INDEX) { + return myStoreUnderContentMap.get(element); + } return null; } - public void setValueAt(Object aValue, int rowIndex, int columnIndex) { + public void setValueAt(Object value, int rowIndex, int columnIndex) { if (columnIndex == CHECK_MARK_COLUM_INDEX) { - setMarked(rowIndex, ((Boolean)aValue).booleanValue()); + updateBooleanMap(rowIndex, ((Boolean)value).booleanValue(), myMarkedMap); + } + else if (columnIndex == STORE_UNDER_CONTENT_COLUM_INDEX) { + updateBooleanMap(rowIndex, ((Boolean)value).booleanValue(), myStoreUnderContentMap); } } - private void setMarked(int rowIndex, final boolean marked) { + private void updateBooleanMap(int rowIndex, boolean marked, final Map map) { final Module element = myElements.get(rowIndex); final Boolean newValue = marked? Boolean.TRUE : Boolean.FALSE; - myMarkedMap.put(element, newValue); + map.put(element, newValue); fireTableRowsUpdated(rowIndex, rowIndex); } @@ -415,23 +435,29 @@ public class ProcessedModulesChooser extends JPanel { } public Class getColumnClass(int columnIndex) { - if (columnIndex == CHECK_MARK_COLUM_INDEX) { + if (columnIndex == CHECK_MARK_COLUM_INDEX || columnIndex == STORE_UNDER_CONTENT_COLUM_INDEX) { return Boolean.class; } return super.getColumnClass(columnIndex); } public boolean isCellEditable(int rowIndex, int columnIndex) { - if (!ProcessedModulesChooser.this.isEnabled() || columnIndex != CHECK_MARK_COLUM_INDEX) { + if (!ProcessedModulesChooser.this.isEnabled()) { return false; } - final Module o = (Module)getValueAt(rowIndex, ELEMENT_COLUMN_INDEX); - return myDisabledMap.get(o) == null; + if (columnIndex == CHECK_MARK_COLUM_INDEX) { + return true; + } + if (columnIndex == STORE_UNDER_CONTENT_COLUM_INDEX) { + return isMarked(rowIndex); + } + return false; } public void clear() { myElements.clear(); myMarkedMap.clear(); + myStoreUnderContentMap.clear(); fireTableDataChanged(); } } @@ -453,7 +479,7 @@ public class ProcessedModulesChooser extends JPanel { UIManager.put(UIUtil.TABLE_FOCUS_CELL_BACKGROUND_PROPERTY, color); } final MyTableModel model = (MyTableModel)table.getModel(); - component.setEnabled(ProcessedModulesChooser.this.isEnabled() && (myColorUnmarkedElements? model.isElementMarked(row) : true)); + component.setEnabled(ProcessedModulesChooser.this.isEnabled() && (myColorUnmarkedElements? model.isMarked(row) : true)); if (component instanceof JLabel) { final Icon icon = module != null ? module.getModuleType().getNodeIcon(false) : null; JLabel label = (JLabel)component; diff --git a/java/compiler/openapi/src/com/intellij/compiler/CompilerConfiguration.java b/java/compiler/openapi/src/com/intellij/compiler/CompilerConfiguration.java index 277aabe9e05e..d675ddd303e5 100644 --- a/java/compiler/openapi/src/com/intellij/compiler/CompilerConfiguration.java +++ b/java/compiler/openapi/src/com/intellij/compiler/CompilerConfiguration.java @@ -21,9 +21,7 @@ import com.intellij.openapi.project.Project; import com.intellij.openapi.vfs.VirtualFile; import org.jetbrains.annotations.NotNull; -import java.util.Collection; import java.util.Map; -import java.util.Set; public abstract class CompilerConfiguration { // need this flag for profiling purposes. In production code is always set to 'true' @@ -57,13 +55,13 @@ public abstract class CompilerConfiguration { public abstract void setAnnotationProcessorsMap(Map map); - public abstract Set getExcludedModules(); + public abstract void setAnotationProcessedModules(Map modules); - public abstract void setExcludedModules(Collection modules); + public abstract Map getAnotationProcessedModules(); - public abstract boolean isStoreGenerateSourcesUnderModuleContent(Module module); + public abstract boolean isAnnotationProcessingEnabled(Module module); - public abstract void setStoreGenerateSourcesUnderModuleContent(boolean storeGenerateSourcesUnderModuleContent); + public abstract boolean isStoreGeneratedSourcesUnderContent(Module module); @NotNull public abstract String getGeneratedDirName(); diff --git a/java/compiler/openapi/src/com/intellij/openapi/compiler/CompilerPaths.java b/java/compiler/openapi/src/com/intellij/openapi/compiler/CompilerPaths.java index 5516269b5365..6a0938bf94e3 100644 --- a/java/compiler/openapi/src/com/intellij/openapi/compiler/CompilerPaths.java +++ b/java/compiler/openapi/src/com/intellij/openapi/compiler/CompilerPaths.java @@ -193,7 +193,7 @@ public class CompilerPaths { public static String getAnnotationProcessorsGenerationPath(Module module) { final CompilerConfiguration config = CompilerConfiguration.getInstance(module.getProject()); - if (config.isStoreGenerateSourcesUnderModuleContent(module)) { + if (config.isStoreGeneratedSourcesUnderContent(module)) { final String[] roots = ModuleRootManager.getInstance(module).getContentRootUrls(); if (roots.length == 0) { return null;