diff --git a/java/compiler/impl/compiler-impl.iml b/java/compiler/impl/compiler-impl.iml index 8dfaa1996ef4..4f7473c9ff2a 100644 --- a/java/compiler/impl/compiler-impl.iml +++ b/java/compiler/impl/compiler-impl.iml @@ -30,6 +30,7 @@ + diff --git a/java/compiler/impl/src/com/intellij/compiler/CompilerConfigurationImpl.java b/java/compiler/impl/src/com/intellij/compiler/CompilerConfigurationImpl.java index bf4a1f606a73..033835abbf96 100644 --- a/java/compiler/impl/src/com/intellij/compiler/CompilerConfigurationImpl.java +++ b/java/compiler/impl/src/com/intellij/compiler/CompilerConfigurationImpl.java @@ -54,7 +54,6 @@ 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; @@ -81,10 +80,9 @@ public class CompilerConfigurationImpl extends CompilerConfiguration implements private boolean myEnableAnnotationProcessors = false; private final Map myProcessorsMap = new HashMap(); // map: AnnotationProcessorName -> options private boolean myObtainProcessorsFromClasspath = true; - private String myGeneratedDirName = DEFAULT_GENERATED_DIR_NAME; private String myProcessorPath = ""; - private final Map myProcessedModules = new HashMap(); - private final Map myModuleNames = new HashMap(); + private final Map myProcessedModules = new HashMap(); + private final Map myModuleNames = new HashMap(); public CompilerConfigurationImpl(Project project, ModuleManager moduleManager) { @@ -105,9 +103,10 @@ public class CompilerConfigurationImpl extends CompilerConfiguration implements } public void moduleAdded(Project project, Module module) { - final Boolean storeUnderContent = myModuleNames.remove(module.getName()); - if (storeUnderContent != null) { - myProcessedModules.put(module, storeUnderContent); + final String moduleName = module.getName(); + if (myModuleNames.containsKey(moduleName)) { + final String dirName = myModuleNames.remove(moduleName); + myProcessedModules.put(module, dirName); } } }); @@ -313,20 +312,6 @@ public class CompilerConfigurationImpl extends CompilerConfiguration implements myObtainProcessorsFromClasspath = obtainProcessorsFromClasspath; } - @NotNull - public String getGeneratedDirName() { - return myGeneratedDirName; - } - - public void setGeneratedDirName(String generatedDirName) { - if (generatedDirName == null || generatedDirName.length() == 0) { - myGeneratedDirName = DEFAULT_GENERATED_DIR_NAME; - } - else { - myGeneratedDirName = generatedDirName; - } - } - public String getProcessorPath() { return myProcessorPath; } @@ -344,13 +329,13 @@ public class CompilerConfigurationImpl extends CompilerConfiguration implements myProcessorsMap.putAll(map); } - public void setAnotationProcessedModules(Map modules) { + public void setAnotationProcessedModules(Map modules) { myProcessedModules.clear(); myModuleNames.clear(); myProcessedModules.putAll(modules); } - public Map getAnotationProcessedModules() { + public Map getAnotationProcessedModules() { return Collections.unmodifiableMap(myProcessedModules); } @@ -358,8 +343,8 @@ public class CompilerConfigurationImpl extends CompilerConfiguration implements return myProcessedModules.containsKey(module); } - public boolean isStoreGeneratedSourcesUnderContent(Module module) { - return Boolean.TRUE.equals(myProcessedModules.get(module)); + public String getGeneratedSourceDirName(Module module) { + return myProcessedModules.get(module); } private void addWildcardResourcePattern(@NonNls final String wildcardPattern) throws MalformedPatternException { @@ -547,7 +532,6 @@ public class CompilerConfigurationImpl extends CompilerConfiguration implements if (annotationProcessingSettings != null) { myEnableAnnotationProcessors = Boolean.valueOf(annotationProcessingSettings.getAttributeValue("enabled", "false")); myObtainProcessorsFromClasspath = Boolean.valueOf(annotationProcessingSettings.getAttributeValue("useClasspath", "true")); - myGeneratedDirName = annotationProcessingSettings.getAttributeValue("generatedDirName", DEFAULT_GENERATED_DIR_NAME); final StringBuilder pathBuilder = new StringBuilder(); for (Element pathElement : ((Collection)annotationProcessingSettings.getChildren("processorPath"))) { @@ -578,14 +562,14 @@ public class CompilerConfigurationImpl extends CompilerConfiguration implements } for (Element moduleElement : processed) { final String name = moduleElement.getAttributeValue("name"); - final Boolean isStoreUnderContent = Boolean.valueOf(moduleElement.getAttributeValue("storeGeneratedUnderContent", "false")); + final String dirname = moduleElement.getAttributeValue("generatedDirName"); if (name != null) { final Module module = moduleMap.get(name); if (module != null) { - myProcessedModules.put(module, isStoreUnderContent); + myProcessedModules.put(module, dirname); } else { - myModuleNames.put(name, isStoreUnderContent); + myModuleNames.put(name, dirname); } } } @@ -624,7 +608,6 @@ public class CompilerConfigurationImpl extends CompilerConfiguration implements parentNode.addContent(annotationProcessingSettings); annotationProcessingSettings.setAttribute("enabled", String.valueOf(myEnableAnnotationProcessors)); annotationProcessingSettings.setAttribute("useClasspath", String.valueOf(myObtainProcessorsFromClasspath)); - annotationProcessingSettings.setAttribute("generatedDirName", myGeneratedDirName); if (myProcessorPath.length() > 0) { final StringTokenizer tokenizer = new StringTokenizer(myProcessorPath, File.pathSeparator, false); while (tokenizer.hasMoreTokens()) { @@ -650,7 +633,10 @@ public class CompilerConfigurationImpl extends CompilerConfiguration implements final Element moduleElement = new Element("processModule"); annotationProcessingSettings.addContent(moduleElement); moduleElement.setAttribute("name", module.getName()); - moduleElement.setAttribute("storeGeneratedUnderContent", String.valueOf(isStoreGeneratedSourcesUnderContent(module))); + final String dirName = myProcessedModules.get(module); + if (dirName != null && dirName.length() > 0) { + moduleElement.setAttribute("generatedDirName", dirName); + } } } 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 e34ec539697e..9cfbf27ec0c5 100644 --- a/java/compiler/impl/src/com/intellij/compiler/impl/CompileDriver.java +++ b/java/compiler/impl/src/com/intellij/compiler/impl/CompileDriver.java @@ -341,8 +341,12 @@ public class CompileDriver { private void attachAnnotationProcessorsOutputDirectories(CompileContextEx context) { final LocalFileSystem lfs = LocalFileSystem.getInstance(); + final CompilerConfiguration config = CompilerConfiguration.getInstance(myProject); final Set affected = new HashSet(Arrays.asList(context.getCompileScope().getAffectedModules())); for (Module module : affected) { + if (!config.isAnnotationProcessingEnabled(module)) { + continue; + } final String path = CompilerPaths.getAnnotationProcessorsGenerationPath(module); if (path == null) { continue; 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 2c55ff53099a..e20bb8d7ddca 100644 --- a/java/compiler/impl/src/com/intellij/compiler/options/AnnotationProcessorsConfigurable.java +++ b/java/compiler/impl/src/com/intellij/compiler/options/AnnotationProcessorsConfigurable.java @@ -41,14 +41,13 @@ import java.util.Map; * Date: Oct 5, 2009 */ public class AnnotationProcessorsConfigurable implements Configurable{ - private ProcessedModulesChooser myModulesChooser; + private ProcessedModulesTable myModulesTable; private final Project myProject; private JRadioButton myRbClasspath; private JRadioButton myRbProcessorsPath; private TextFieldWithBrowseButton myProcessorPathField; private ProcessorTableModel myProcessorsModel; private JCheckBox myCbEnableProcessing; - private JTextField myGeneratedSourcesDirField; private JButton myRemoveButton; private Table myProcessorTable; private JButton myAddButton; @@ -97,7 +96,6 @@ public class AnnotationProcessorsConfigurable implements Configurable{ } }); - final JPanel processorTablePanel = new JPanel(new BorderLayout()); myProcessorsModel = new ProcessorTableModel(); processorTablePanel.setBorder(new TitledBorder("Annotation Processors")); @@ -111,22 +109,18 @@ public class AnnotationProcessorsConfigurable implements Configurable{ processorTablePanel.add(buttons, BorderLayout.EAST); processorTablePanel.setPreferredSize(new Dimension(processorTablePanel.getPreferredSize().width, 50)); - myModulesChooser = new ProcessedModulesChooser(); - myModulesChooser.setBorder(BorderFactory.createTitledBorder("Processed Modules")); + myModulesTable = new ProcessedModulesTable(myProject); + myModulesTable.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(); - + "To override this behaviour for certain modules you may specify the directory name in the table below.\n" + + "If specified, the directory will be created under corresponding module's content root."); 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)); + mainPanel.add(myModulesTable, new GridBagConstraints(0, GridBagConstraints.RELATIVE, 2, 1, 1.0, 1.0, GridBagConstraints.NORTHWEST, GridBagConstraints.BOTH, new Insets(10, 0, 0, 0), 0, 0)); myRbClasspath.addItemListener(new ItemListener() { @@ -184,7 +178,7 @@ public class AnnotationProcessorsConfigurable implements Configurable{ if (header != null) { header.repaint(); } - myModulesChooser.setEnabled(enabled); + myModulesTable.setEnabled(enabled); } public boolean isModified() { @@ -204,10 +198,6 @@ public class AnnotationProcessorsConfigurable implements Configurable{ return true; } - if (!myGeneratedSourcesDirField.getText().trim().equals(config.getGeneratedDirName().trim())) { - return true; - } - if (!getMarkedModules().equals(config.getAnotationProcessedModules())) { return true; } @@ -224,14 +214,12 @@ public class AnnotationProcessorsConfigurable implements Configurable{ config.setAnnotationProcessorsMap(myProcessorsModel.exportToMap()); - config.setGeneratedDirName(myGeneratedSourcesDirField.getText().trim()); - config.setAnotationProcessedModules(getMarkedModules()); } - private Map getMarkedModules() { - final Map result = new HashMap(); - for (Pair pair : myModulesChooser.getMarkedModules()) { + private Map getMarkedModules() { + final Map result = new HashMap(); + for (Pair pair : myModulesTable.getAllModules()) { result.put(pair.getFirst(), pair.getSecond()); } return result; @@ -253,13 +241,13 @@ public class AnnotationProcessorsConfigurable implements Configurable{ myProcessorsModel.setProcessorMap(config.getAnnotationProcessorsMap()); - myGeneratedSourcesDirField.setText(config.getGeneratedDirName().trim()); - - myModulesChooser.removeAllElements(); + myModulesTable.removeAllElements(); for (final Module module : ModuleManager.getInstance(myProject).getModules()) { - myModulesChooser.addModule(module, config.isAnnotationProcessingEnabled(module), config.isStoreGeneratedSourcesUnderContent(module)); + if (config.isAnnotationProcessingEnabled(module)) { + myModulesTable.addModule(module, config.getGeneratedSourceDirName(module)); + } } - myModulesChooser.sort(new Comparator() { + myModulesTable.sort(new Comparator() { public int compare(Module o1, Module o2) { return o1.getName().compareToIgnoreCase(o2.getName()); } diff --git a/java/compiler/impl/src/com/intellij/compiler/options/ProcessedModulesChooser.java b/java/compiler/impl/src/com/intellij/compiler/options/ProcessedModulesTable.java similarity index 54% rename from java/compiler/impl/src/com/intellij/compiler/options/ProcessedModulesChooser.java rename to java/compiler/impl/src/com/intellij/compiler/options/ProcessedModulesTable.java index 790cbac5421b..f6dceaba6c7e 100644 --- a/java/compiler/impl/src/com/intellij/compiler/options/ProcessedModulesChooser.java +++ b/java/compiler/impl/src/com/intellij/compiler/options/ProcessedModulesTable.java @@ -16,35 +16,39 @@ package com.intellij.compiler.options; import com.intellij.openapi.module.Module; +import com.intellij.openapi.module.ModuleManager; +import com.intellij.openapi.project.Project; +import com.intellij.openapi.roots.ui.configuration.libraryEditor.ChooseModulesDialog; import com.intellij.openapi.util.Pair; import com.intellij.openapi.util.io.FileUtil; import com.intellij.ui.ScrollPaneFactory; import com.intellij.ui.SpeedSearchBase; import com.intellij.ui.TableUtil; +import com.intellij.util.ui.ItemRemovable; import com.intellij.util.ui.Table; import com.intellij.util.ui.UIUtil; import org.jetbrains.annotations.Nullable; import javax.swing.*; +import javax.swing.event.ListSelectionEvent; +import javax.swing.event.ListSelectionListener; import javax.swing.table.*; import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; -import java.awt.event.KeyEvent; import java.util.*; import java.util.List; -public class ProcessedModulesChooser extends JPanel { +public class ProcessedModulesTable extends JPanel { private Table myTable = null; private MyTableModel myTableModel = null; - private boolean myColorUnmarkedElements = true; - public ProcessedModulesChooser() { + public ProcessedModulesTable(final Project project) { super(new BorderLayout()); myTableModel = new MyTableModel(); myTable = new Table(myTableModel); - myTable.setShowGrid(false); + //myTable.setShowGrid(false); myTable.setIntercellSpacing(new Dimension(0, 0)); myTable.setAutoResizeMode(JTable.AUTO_RESIZE_LAST_COLUMN); myTable.setColumnSelectionAllowed(false); @@ -53,47 +57,54 @@ public class ProcessedModulesChooser extends JPanel { 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 TableColumn dirNameColumn = columnModel.getColumn(myTableModel.DIRNAME_COLUMN_INDEX); + final String title = "Generated Sources Directory Name"; + dirNameColumn.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); + dirNameColumn.setPreferredWidth(preferredWidth); + dirNameColumn.setMaxWidth(preferredWidth + 20); + dirNameColumn.setCellRenderer(new MyElementColumnCellRenderer()); final TableColumn moduleColumn = columnModel.getColumn(myTableModel.ELEMENT_COLUMN_INDEX); moduleColumn.setHeaderValue("Module"); moduleColumn.setCellRenderer(new MyElementColumnCellRenderer()); add(pane, BorderLayout.CENTER); - myTable.registerKeyboardAction( - new ActionListener() { - public void actionPerformed(ActionEvent e) { - final int[] selectedRows = myTable.getSelectedRows(); - boolean currentlyMarked = true; - for (int selectedRow : selectedRows) { - currentlyMarked = myTableModel.isMarked(selectedRow); - if (!currentlyMarked) { - break; - } + + final JButton addButton = new JButton("Add"); + addButton.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + final Set projectModules = new HashSet(Arrays.asList(ModuleManager.getInstance(project).getModules())); + projectModules.removeAll(myTableModel.getAllModules()); + final ChooseModulesDialog chooser = new ChooseModulesDialog(ProcessedModulesTable.this, new ArrayList(projectModules), "ChooseModule"); + chooser.show(); + if (chooser.isOK()) { + final List chosen = chooser.getChosenElements(); + for (Module module : chosen) { + myTableModel.addElement(module, null); } - myTableModel.setMarked(selectedRows, !currentlyMarked); } - }, - KeyStroke.getKeyStroke(KeyEvent.VK_SPACE, 0), - JComponent.WHEN_FOCUSED - ); + } + }); + + final JButton removeButton = new JButton("Remove"); + myTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() { + public void valueChanged(ListSelectionEvent e) { + removeButton.setEnabled(myTable.getSelectedRowCount() > 0); + } + }); + removeButton.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + TableUtil.removeSelectedItems(myTable); + } + }); + + final JPanel buttonPanel = new JPanel(new GridBagLayout()); + buttonPanel.add(addButton, new GridBagConstraints(0, GridBagConstraints.RELATIVE, 1, 1, 1.0, 0.0, GridBagConstraints.NORTH, GridBagConstraints.HORIZONTAL, new Insets(0, 6, 0, 0), 0, 0)); + buttonPanel.add(removeButton, new GridBagConstraints(0, GridBagConstraints.RELATIVE, 1, 1, 1.0, 1.0, GridBagConstraints.NORTH, GridBagConstraints.HORIZONTAL, new Insets(5, 6, 0, 0), 0, 0)); + add(buttonPanel, BorderLayout.EAST); final SpeedSearchBase speedSearch = new SpeedSearchBase
(myTable) { public int getSelectedIndex() { @@ -150,28 +161,13 @@ public class ProcessedModulesChooser extends JPanel { } } - public void addModule(Module element, final boolean isMarked, boolean isStoreGeneratedSourcesUnderContent) { - myTableModel.addElement(element, isMarked, isStoreGeneratedSourcesUnderContent); + public void addModule(Module element, String dirName) { + myTableModel.addElement(element, dirName); selectRow(myTableModel.getRowCount() - 1); myTable.requestFocus(); } - public boolean isElementMarked(Module element) { - final int elementRow = myTableModel.getElementRow(element); - return myTableModel.isMarked(elementRow); - } - - public void setElementMarked(Module element, boolean marked) { - final int elementRow = myTableModel.getElementRow(element); - 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) { + public void removeModule(Module element) { final int elementRow = myTableModel.getElementRow(element); if (elementRow < 0) { return; // no such element @@ -244,14 +240,12 @@ public class ProcessedModulesChooser extends JPanel { return rows; } - public List> getMarkedModules() { + public List> getAllModules() { final int count = myTableModel.getRowCount(); - List> elements = new ArrayList>(); + List> elements = new ArrayList>(); for (int idx = 0; idx < count; idx++) { final Module module = myTableModel.getModuleAt(idx); - if (myTableModel.isMarked(idx)) { - elements.add(new Pair(module, myTableModel.isGenerateSourcesToContent(module))); - } + elements.add(new Pair(module, myTableModel.getGenDirName(module))); } return elements; } @@ -289,71 +283,48 @@ public class ProcessedModulesChooser extends JPanel { return myTableModel.getModuleAt(row); } - private final class MyTableModel extends AbstractTableModel { + private final class MyTableModel extends AbstractTableModel implements ItemRemovable { private final List myElements = new ArrayList(); - private final Map myMarkedMap = new HashMap(); - 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; + private final Map myDirNameMap = new HashMap(); + public final int ELEMENT_COLUMN_INDEX = 0; + public final int DIRNAME_COLUMN_INDEX = 1; public void sort(Comparator comparator) { Collections.sort(myElements, comparator); fireTableDataChanged(); } + public List getAllModules() { + return Collections.unmodifiableList(myElements); + } + public Module getModuleAt(int index) { return myElements.get(index); } - public boolean isMarked(int index) { - final Module element = myElements.get(index); - return myMarkedMap.get(element).booleanValue(); + public String getGenDirName(Module module) { + return myDirNameMap.get(module); } - 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, Boolean.valueOf(isMarked)); - myStoreUnderContentMap.put(element, Boolean.valueOf(isStoreGeneratedSourcesUnderContent)); + void addElement(Module module, final String dirName) { + myElements.add(module); + if (dirName != null && dirName.length() > 0) { + myDirNameMap.put(module, dirName); + } int row = myElements.size() - 1; fireTableRowsInserted(row, row); } - void addElements(List elements, boolean isMarked) { - if (elements == null || elements.size() == 0) { - return; - } - 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); + public void removeRow(int idx) { + final Module element = myElements.remove(idx); + myDirNameMap.remove(element); + fireTableRowsDeleted(idx, idx); } public void removeElement(Module element) { final boolean reallyRemoved = myElements.remove(element); if (reallyRemoved) { - myMarkedMap.remove(element); - myStoreUnderContentMap.remove(element); - fireTableDataChanged(); - } - } - - public void changeElementRow(Module element, int row) { - final boolean reallyRemoved = myElements.remove(element); - if (reallyRemoved) { - myElements.add(row, element); + myDirNameMap.remove(element); fireTableDataChanged(); } } @@ -367,24 +338,12 @@ public class ProcessedModulesChooser extends JPanel { fireTableDataChanged(); } - public void removeRows(int[] rows) { - final List toRemove = new ArrayList(); - for (int row : rows) { - final Module element = myElements.get(row); - toRemove.add(element); - myMarkedMap.remove(element); - myStoreUnderContentMap.remove(element); - } - myElements.removeAll(toRemove); - fireTableDataChanged(); - } - public int getRowCount() { return myElements.size(); } public int getColumnCount() { - return 3; + return 2; } @Nullable @@ -393,71 +352,54 @@ public class ProcessedModulesChooser extends JPanel { if (columnIndex == ELEMENT_COLUMN_INDEX) { return element; } - if (columnIndex == CHECK_MARK_COLUM_INDEX) { - return myMarkedMap.get(element); - } - if (columnIndex == STORE_UNDER_CONTENT_COLUM_INDEX) { - return myStoreUnderContentMap.get(element); + if (columnIndex == DIRNAME_COLUMN_INDEX) { + return myDirNameMap.get(element); } return null; } public void setValueAt(Object value, int rowIndex, int columnIndex) { - if (columnIndex == CHECK_MARK_COLUM_INDEX) { - updateBooleanMap(rowIndex, ((Boolean)value).booleanValue(), myMarkedMap); + if (columnIndex == DIRNAME_COLUMN_INDEX) { + final Module module = myElements.get(rowIndex); + if (value != null) { + String dir = FileUtil.toSystemIndependentName((String)value); + while (dir.startsWith("/")) { + dir = dir.substring(1); + } + if (dir.length() > 0) { + myDirNameMap.put(module, dir); + } + else { + myDirNameMap.remove(module); + } + } + else { + myDirNameMap.remove(module); + } + fireTableRowsUpdated(rowIndex, rowIndex); } - else if (columnIndex == STORE_UNDER_CONTENT_COLUM_INDEX) { - updateBooleanMap(rowIndex, ((Boolean)value).booleanValue(), myStoreUnderContentMap); - } - } - - private void updateBooleanMap(int rowIndex, boolean marked, final Map map) { - final Module element = myElements.get(rowIndex); - final Boolean newValue = marked? Boolean.TRUE : Boolean.FALSE; - map.put(element, newValue); - fireTableRowsUpdated(rowIndex, rowIndex); - } - - private void setMarked(int[] rows, final boolean marked) { - if (rows == null || rows.length == 0) { - return; - } - int firstRow = Integer.MAX_VALUE; - int lastRow = Integer.MIN_VALUE; - final Boolean newValue = marked? Boolean.TRUE : Boolean.FALSE; - for (final int row : rows) { - final Module element = myElements.get(row); - myMarkedMap.put(element, newValue); - firstRow = Math.min(firstRow, row); - lastRow = Math.max(lastRow, row); - } - fireTableRowsUpdated(firstRow, lastRow); } public Class getColumnClass(int columnIndex) { - if (columnIndex == CHECK_MARK_COLUM_INDEX || columnIndex == STORE_UNDER_CONTENT_COLUM_INDEX) { - return Boolean.class; + if (columnIndex == DIRNAME_COLUMN_INDEX) { + return String.class; } return super.getColumnClass(columnIndex); } public boolean isCellEditable(int rowIndex, int columnIndex) { - if (!ProcessedModulesChooser.this.isEnabled()) { + if (!ProcessedModulesTable.this.isEnabled()) { return false; } - if (columnIndex == CHECK_MARK_COLUM_INDEX) { + if (columnIndex == DIRNAME_COLUMN_INDEX) { return true; } - if (columnIndex == STORE_UNDER_CONTENT_COLUM_INDEX) { - return isMarked(rowIndex); - } return false; } public void clear() { myElements.clear(); - myMarkedMap.clear(); - myStoreUnderContentMap.clear(); + myDirNameMap.clear(); fireTableDataChanged(); } } @@ -466,11 +408,13 @@ public class ProcessedModulesChooser extends JPanel { public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { final Color color = UIUtil.getTableFocusCellBackground(); Component component; - Module module = (Module)value; + final Module module = value instanceof Module? (Module)value : null; try { UIManager.put(UIUtil.TABLE_FOCUS_CELL_BACKGROUND_PROPERTY, table.getSelectionBackground()); component = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column); - setText(module != null ? module.getName() + " (" + FileUtil.toSystemDependentName(module.getModuleFilePath()) + ")" : ""); + if (module != null) { + setText(module.getName() + " (" + FileUtil.toSystemDependentName(module.getModuleFilePath()) + ")"); + } if (component instanceof JLabel) { ((JLabel)component).setBorder(noFocusBorder); } @@ -478,8 +422,7 @@ public class ProcessedModulesChooser extends JPanel { finally { UIManager.put(UIUtil.TABLE_FOCUS_CELL_BACKGROUND_PROPERTY, color); } - final MyTableModel model = (MyTableModel)table.getModel(); - component.setEnabled(ProcessedModulesChooser.this.isEnabled() && (myColorUnmarkedElements? model.isMarked(row) : true)); + component.setEnabled(ProcessedModulesTable.this.isEnabled()); if (component instanceof JLabel) { final Icon icon = module != null ? module.getModuleType().getNodeIcon(false) : null; JLabel label = (JLabel)component; @@ -490,21 +433,4 @@ public class ProcessedModulesChooser extends JPanel { return component; } } - - private class CheckMarkColumnCellRenderer implements TableCellRenderer { - private final TableCellRenderer myDelegate; - - public CheckMarkColumnCellRenderer(TableCellRenderer delegate) { - myDelegate = delegate; - } - - public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { - Component component = myDelegate.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column); - component.setEnabled(ProcessedModulesChooser.this.isEnabled()); - if (component instanceof JComponent) { - ((JComponent)component).setBorder(null); - } - return component; - } - } } \ No newline at end of file diff --git a/java/compiler/openapi/src/com/intellij/compiler/CompilerConfiguration.java b/java/compiler/openapi/src/com/intellij/compiler/CompilerConfiguration.java index d675ddd303e5..b86970f2c5ae 100644 --- a/java/compiler/openapi/src/com/intellij/compiler/CompilerConfiguration.java +++ b/java/compiler/openapi/src/com/intellij/compiler/CompilerConfiguration.java @@ -19,7 +19,6 @@ package com.intellij.compiler; import com.intellij.openapi.module.Module; import com.intellij.openapi.project.Project; import com.intellij.openapi.vfs.VirtualFile; -import org.jetbrains.annotations.NotNull; import java.util.Map; @@ -55,16 +54,12 @@ public abstract class CompilerConfiguration { public abstract void setAnnotationProcessorsMap(Map map); - public abstract void setAnotationProcessedModules(Map modules); + public abstract void setAnotationProcessedModules(Map modules); - public abstract Map getAnotationProcessedModules(); + public abstract Map getAnotationProcessedModules(); public abstract boolean isAnnotationProcessingEnabled(Module module); - public abstract boolean isStoreGeneratedSourcesUnderContent(Module module); + public abstract String getGeneratedSourceDirName(Module module); - @NotNull - public abstract String getGeneratedDirName(); - - public abstract void setGeneratedDirName(String generatedDirName); } \ No newline at end of file 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 6a0938bf94e3..7816779a921a 100644 --- a/java/compiler/openapi/src/com/intellij/openapi/compiler/CompilerPaths.java +++ b/java/compiler/openapi/src/com/intellij/openapi/compiler/CompilerPaths.java @@ -51,6 +51,7 @@ public class CompilerPaths { return o1.compareTo(o2); } }; + private static final String DEFAULT_GENERATED_DIR_NAME = "generated"; /** * Returns a directory @@ -190,10 +191,12 @@ public class CompilerPaths { return outPathUrl != null? VirtualFileManager.extractPath(outPathUrl) : null; } + @Nullable public static String getAnnotationProcessorsGenerationPath(Module module) { final CompilerConfiguration config = CompilerConfiguration.getInstance(module.getProject()); - if (config.isStoreGeneratedSourcesUnderContent(module)) { + final String sourceDirName = config.getGeneratedSourceDirName(module); + if (sourceDirName != null && sourceDirName.length() > 0) { final String[] roots = ModuleRootManager.getInstance(module).getContentRootUrls(); if (roots.length == 0) { return null; @@ -201,14 +204,18 @@ public class CompilerPaths { if (roots.length > 1) { Arrays.sort(roots, URLS_COMPARATOR); } - return VirtualFileManager.extractPath(roots[0]) + "/" + config.getGeneratedDirName(); + return VirtualFileManager.extractPath(roots[0]) + "/" + sourceDirName; } - final String url = CompilerProjectExtension.getInstance(module.getProject()).getCompilerOutputUrl(); + final CompilerProjectExtension extension = CompilerProjectExtension.getInstance(module.getProject()); + if (extension == null) { + return null; + } + final String url = extension.getCompilerOutputUrl(); if (url == null) { return null; } - return VirtualFileManager.extractPath(url) + "/generated/" + module.getName().toLowerCase(); + return VirtualFileManager.extractPath(url) + "/" + DEFAULT_GENERATED_DIR_NAME + "/" + module.getName().toLowerCase(); } @NonNls