diff --git a/images/src/org/intellij/images/index/ImageInfoIndex.java b/images/src/org/intellij/images/index/ImageInfoIndex.java index 5413e4adfe54..94026bc8de64 100644 --- a/images/src/org/intellij/images/index/ImageInfoIndex.java +++ b/images/src/org/intellij/images/index/ImageInfoIndex.java @@ -19,7 +19,7 @@ import com.intellij.openapi.project.Project; import com.intellij.openapi.vfs.LocalFileSystem; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.openapi.vfs.ex.temp.TempFileSystem; -import com.intellij.psi.search.GlobalSearchScope; +import com.intellij.psi.search.GlobalSearchScopes; import com.intellij.util.indexing.*; import com.intellij.util.io.DataExternalizer; import org.intellij.images.fileTypes.ImageFileTypeManager; @@ -71,7 +71,8 @@ public class ImageInfoIndex extends SingleEntryFileBasedIndexExtension processor, Project project) { - FileBasedIndex.getInstance().processValues(INDEX_ID, Math.abs(FileBasedIndex.getFileId(virtualFile)), virtualFile, processor, GlobalSearchScope.fileScope(project, virtualFile)); + FileBasedIndex.getInstance().processValues(INDEX_ID, Math.abs(FileBasedIndex.getFileId(virtualFile)), virtualFile, processor, GlobalSearchScopes + .fileScope(project, virtualFile)); } public DataExternalizer getValueExternalizer() { diff --git a/java/compiler/impl/src/com/intellij/compiler/impl/javaCompiler/BackendCompilerWrapper.java b/java/compiler/impl/src/com/intellij/compiler/impl/javaCompiler/BackendCompilerWrapper.java index 08305785073f..c0a04a997893 100644 --- a/java/compiler/impl/src/com/intellij/compiler/impl/javaCompiler/BackendCompilerWrapper.java +++ b/java/compiler/impl/src/com/intellij/compiler/impl/javaCompiler/BackendCompilerWrapper.java @@ -60,6 +60,7 @@ import com.intellij.openapi.vfs.VirtualFile; import com.intellij.psi.JavaPsiFacade; import com.intellij.psi.PsiClass; import com.intellij.psi.search.GlobalSearchScope; +import com.intellij.psi.search.GlobalSearchScopes; import com.intellij.util.Chunk; import com.intellij.util.cls.ClsFormatException; import gnu.trove.THashMap; @@ -345,7 +346,7 @@ public class BackendCompilerWrapper { return; // should not invoke javac with empty sources list } - ModuleType moduleType = chunk.getModules()[0].getModuleType(); + ModuleType moduleType = ModuleType.get(chunk.getModules()[0]); if (!(chunk.getJdk().getSdkType() instanceof JavaSdkType) && !(moduleType instanceof JavaModuleType || moduleType.createModuleBuilder() instanceof JavaModuleBuilder)) { // TODO @@ -584,7 +585,8 @@ public class BackendCompilerWrapper { final String packagePrefix, final List filesToRefresh, final Map> results) throws CacheCorruptedException { final Ref exRef = new Ref(null); final ModuleFileIndex fileIndex = ModuleRootManager.getInstance(module).getFileIndex(); - final GlobalSearchScope srcRootScope = GlobalSearchScope.moduleScope(module).intersectWith(GlobalSearchScope.directoryScope(myProject, sourceRoot, true)); + final GlobalSearchScope srcRootScope = GlobalSearchScope.moduleScope(module).intersectWith( + GlobalSearchScopes.directoryScope(myProject, sourceRoot, true)); final ContentIterator contentIterator = new ContentIterator() { public boolean processFile(final VirtualFile child) { diff --git a/java/compiler/impl/src/com/intellij/compiler/make/ChangedConstantsDependencyProcessor.java b/java/compiler/impl/src/com/intellij/compiler/make/ChangedConstantsDependencyProcessor.java index e4102a9899f5..40208f5479c3 100644 --- a/java/compiler/impl/src/com/intellij/compiler/make/ChangedConstantsDependencyProcessor.java +++ b/java/compiler/impl/src/com/intellij/compiler/make/ChangedConstantsDependencyProcessor.java @@ -117,7 +117,7 @@ class ChangedConstantsDependencyProcessor { } } } - final PsiSearchHelper psiSearchHelper = PsiManager.getInstance(myProject).getSearchHelper(); + final PsiSearchHelper psiSearchHelper = PsiSearchHelper.SERVICE.getInstance(myProject); final Ref exRef = new Ref(null); final long analysisStart = System.currentTimeMillis(); 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 f403a627cd81..7cac391ba10c 100644 --- a/java/compiler/impl/src/com/intellij/compiler/options/AnnotationProcessorsConfigurable.java +++ b/java/compiler/impl/src/com/intellij/compiler/options/AnnotationProcessorsConfigurable.java @@ -13,12 +13,10 @@ 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.IdeBorderFactory; -import com.intellij.ui.ScrollPaneFactory; -import com.intellij.ui.TableUtil; +import com.intellij.ui.*; +import com.intellij.ui.table.JBTable; import com.intellij.util.containers.HashMap; -import com.intellij.util.ui.ItemRemovable; -import com.intellij.util.ui.Table; +import com.intellij.util.ui.EditableModel; import org.jetbrains.annotations.NotNull; import javax.swing.*; @@ -50,9 +48,8 @@ public class AnnotationProcessorsConfigurable implements SearchableConfigurable private TextFieldWithBrowseButton myProcessorPathField; private ProcessorTableModel myProcessorsModel; private JCheckBox myCbEnableProcessing; - private JButton myRemoveButton; - private Table myProcessorTable; - private JButton myAddButton; + private JBTable myProcessorTable; + private JPanel myProcessorPanel; public AnnotationProcessorsConfigurable(final Project project) { myProject = project; @@ -110,16 +107,28 @@ public class AnnotationProcessorsConfigurable implements SearchableConfigurable final JPanel processorTablePanel = new JPanel(new BorderLayout()); myProcessorsModel = new ProcessorTableModel(); processorTablePanel.setBorder(IdeBorderFactory.createTitledBorder("Annotation Processors", false, false, true)); - myProcessorTable = new Table(myProcessorsModel); + myProcessorTable = new JBTable(myProcessorsModel); myProcessorTable.getEmptyText().setText("No processors configured"); + myProcessorPanel = ToolbarDecorator.createDecorator(myProcessorTable) + .disableUpAction() + .disableDownAction() + .setAddAction(new AnActionButtonRunnable() { + @Override + public void run(AnActionButton anActionButton) { + final TableCellEditor cellEditor = myProcessorTable.getCellEditor(); + if (cellEditor != null) { + cellEditor.stopCellEditing(); + } + final ProcessorTableModel model = (ProcessorTableModel)myProcessorTable.getModel(); + model.addRow(); + TableUtil.editCellAt(myProcessorTable, model.getRowCount() - 1, ProcessorTableRow.NAME_COLUMN); + } + }) + .createPanel(); - processorTablePanel.add(ScrollPaneFactory.createScrollPane(myProcessorTable), BorderLayout.CENTER); - final JPanel buttons = new JPanel(new GridBagLayout()); - myAddButton = new JButton("Add"); - buttons.add(myAddButton, new GridBagConstraints(0, GridBagConstraints.RELATIVE, 1, 1, 1.0, 0.0, GridBagConstraints.NORTH, GridBagConstraints.HORIZONTAL, new Insets(0, 5, 0, 0), 0, 0)); - myRemoveButton = new JButton("Remove"); - buttons.add(myRemoveButton, new GridBagConstraints(0, GridBagConstraints.RELATIVE, 1, 1, 1.0, 1.0, GridBagConstraints.NORTH, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 0, 0), 0, 0)); - processorTablePanel.add(buttons, BorderLayout.EAST); + + + processorTablePanel.add(myProcessorPanel, BorderLayout.CENTER); processorTablePanel.setPreferredSize(new Dimension(processorTablePanel.getPreferredSize().width, 50)); myModulesTable = new ProcessedModulesTable(myProject); @@ -157,23 +166,6 @@ public class AnnotationProcessorsConfigurable implements SearchableConfigurable } } }); - myAddButton.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent e) { - final TableCellEditor cellEditor = myProcessorTable.getCellEditor(); - if (cellEditor != null) { - cellEditor.stopCellEditing(); - } - final ProcessorTableModel model = (ProcessorTableModel)myProcessorTable.getModel(); - final int inserdedIndex = model.addRow(); - TableUtil.editCellAt(myProcessorTable, inserdedIndex, ProcessorTableRow.NAME_COLUMN); - } - }); - - myRemoveButton.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent e) { - TableUtil.removeSelectedItems(myProcessorTable); - } - }); myCbEnableProcessing.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent e) { @@ -192,8 +184,14 @@ public class AnnotationProcessorsConfigurable implements SearchableConfigurable myRbClasspath.setEnabled(enabled); myRbProcessorsPath.setEnabled(enabled); myProcessorPathField.setEnabled(enabled && useProcessorpath); - myRemoveButton.setEnabled(enabled && myProcessorTable.getSelectedRow() >= 0); - myAddButton.setEnabled(enabled); + final AnActionButton addButton = ToolbarDecorator.findAddButton(myProcessorPanel); + if (addButton != null) { + addButton.setEnabled(enabled); + } + final AnActionButton removeButton = ToolbarDecorator.findRemoveButton(myProcessorPanel); + if (removeButton != null) { + removeButton.setEnabled(enabled && myProcessorTable.getSelectedRow() >= 0); + } myProcessorTable.setEnabled(enabled); final JTableHeader header = myProcessorTable.getTableHeader(); if (header != null) { @@ -278,7 +276,7 @@ public class AnnotationProcessorsConfigurable implements SearchableConfigurable public void disposeUIResources() { } - private static class ProcessorTableModel extends AbstractTableModel implements ItemRemovable{ + private static class ProcessorTableModel extends AbstractTableModel implements EditableModel { private final java.util.List myRows = new ArrayList(); public String getColumnName(int column) { @@ -333,11 +331,14 @@ public class AnnotationProcessorsConfigurable implements SearchableConfigurable fireTableRowsDeleted(idx, idx); } - public int addRow() { + @Override + public void exchangeRows(int oldIndex, int newIndex) { + } + + public void addRow() { myRows.add(new ProcessorTableRow()); - final int inserted = myRows.size() - 1; - fireTableRowsInserted(inserted, inserted); - return inserted; + final int index = myRows.size() - 1; + fireTableRowsInserted(index, index); } public void setProcessorMap(Map processorMap) { diff --git a/java/compiler/impl/src/com/intellij/compiler/options/ProcessedModulesTable.java b/java/compiler/impl/src/com/intellij/compiler/options/ProcessedModulesTable.java index d5b5210b2c69..2f9b75f8fa41 100644 --- a/java/compiler/impl/src/com/intellij/compiler/options/ProcessedModulesTable.java +++ b/java/compiler/impl/src/com/intellij/compiler/options/ProcessedModulesTable.java @@ -17,45 +17,40 @@ package com.intellij.compiler.options; import com.intellij.openapi.module.Module; import com.intellij.openapi.module.ModuleManager; +import com.intellij.openapi.module.ModuleType; import com.intellij.openapi.project.Project; import com.intellij.openapi.roots.ui.configuration.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.ui.ToolbarDecorator; +import com.intellij.ui.table.JBTable; +import com.intellij.util.ui.EditableModel; 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.util.*; import java.util.List; public class ProcessedModulesTable extends JPanel { - private Table myTable = null; + private JBTable myTable = null; private MyTableModel myTableModel = null; public ProcessedModulesTable(final Project project) { super(new BorderLayout()); - myTableModel = new MyTableModel(); - myTable = new Table(myTableModel); + myTableModel = new MyTableModel(project); + myTable = new JBTable(myTableModel); myTable.getEmptyText().setText("No modules configured"); //myTable.setShowGrid(false); myTable.setIntercellSpacing(new Dimension(0, 0)); myTable.setAutoResizeMode(JTable.AUTO_RESIZE_LAST_COLUMN); myTable.setColumnSelectionAllowed(false); - JScrollPane pane = ScrollPaneFactory.createScrollPane(myTable); - pane.setPreferredSize(new Dimension(100, 155)); final TableColumnModel columnModel = myTable.getColumnModel(); @@ -73,42 +68,13 @@ public class ProcessedModulesTable extends JPanel { moduleColumn.setHeaderValue("Module"); moduleColumn.setCellRenderer(new MyElementColumnCellRenderer()); - add(pane, BorderLayout.CENTER); + final JPanel panel = ToolbarDecorator.createDecorator(myTable) + .disableUpDownActions() + .setPreferredSize(new Dimension(100, 155)) + .createPanel(); + add(panel, BorderLayout.CENTER); - 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); - } - } - } - }); - - 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) { + final SpeedSearchBase speedSearch = new SpeedSearchBase(myTable) { public int getSelectedIndex() { return myTable.getSelectedRow(); } @@ -291,11 +257,16 @@ public class ProcessedModulesTable extends JPanel { return myTableModel.getModuleAt(row); } - private final class MyTableModel extends AbstractTableModel implements ItemRemovable { + private final class MyTableModel extends AbstractTableModel implements EditableModel { private final List myElements = new ArrayList(); private final Map myDirNameMap = new HashMap(); public final int ELEMENT_COLUMN_INDEX = 0; public final int DIRNAME_COLUMN_INDEX = 1; + private final Project myProject; + + private MyTableModel(Project project) { + myProject = project; + } public void sort(Comparator comparator) { Collections.sort(myElements, comparator); @@ -323,12 +294,30 @@ public class ProcessedModulesTable extends JPanel { fireTableRowsInserted(row, row); } + @Override + public void addRow() { + final Set projectModules = new HashSet(Arrays.asList(ModuleManager.getInstance(myProject).getModules())); + projectModules.removeAll(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) { + addElement(module, null); + } + } + } + public void removeRow(int idx) { final Module element = myElements.remove(idx); myDirNameMap.remove(element); fireTableRowsDeleted(idx, idx); } + @Override + public void exchangeRows(int oldIndex, int newIndex) { + } + public void removeElement(Module element) { final boolean reallyRemoved = myElements.remove(element); if (reallyRemoved) { @@ -432,7 +421,7 @@ public class ProcessedModulesTable extends JPanel { } component.setEnabled(ProcessedModulesTable.this.isEnabled()); if (component instanceof JLabel) { - final Icon icon = module != null ? module.getModuleType().getNodeIcon(false) : null; + final Icon icon = module != null ? ModuleType.get(module).getNodeIcon(false) : null; JLabel label = (JLabel)component; label.setIcon(icon); label.setDisabledIcon(icon); diff --git a/java/compiler/impl/src/com/intellij/openapi/deployment/DeploymentUtilImpl.java b/java/compiler/impl/src/com/intellij/openapi/deployment/DeploymentUtilImpl.java index 6804b5ccc8eb..9968fdbe3fb6 100644 --- a/java/compiler/impl/src/com/intellij/openapi/deployment/DeploymentUtilImpl.java +++ b/java/compiler/impl/src/com/intellij/openapi/deployment/DeploymentUtilImpl.java @@ -22,6 +22,7 @@ import com.intellij.openapi.compiler.CompilerMessageCategory; import com.intellij.openapi.compiler.make.BuildRecipe; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.module.Module; +import com.intellij.openapi.module.ModuleType; import com.intellij.openapi.util.SystemInfo; import com.intellij.openapi.util.io.FileUtil; import com.intellij.openapi.vfs.VfsUtil; @@ -119,7 +120,7 @@ public class DeploymentUtilImpl extends DeploymentUtil { } public void reportDeploymentDescriptorDoesNotExists(ConfigFile descriptor, CompileContext context, Module module) { - final String description = module.getModuleType().getName() + " '" + module.getName() + '\''; + final String description = ModuleType.get(module).getName() + " '" + module.getName() + '\''; String descriptorPath = VfsUtil.urlToPath(descriptor.getUrl()); final String message = CompilerBundle.message("message.text.compiling.item.deployment.descriptor.could.not.be.found", description, descriptorPath); @@ -130,7 +131,7 @@ public class DeploymentUtilImpl extends DeploymentUtil { if (new File(VfsUtil.urlToPath(descriptor.getUrl())).exists()) { String message = getConfigFileErrorMessage(descriptor); if (message != null) { - final String moduleDescription = module.getModuleType().getName() + " '" + module.getName() + '\''; + final String moduleDescription = ModuleType.get(module).getName() + " '" + module.getName() + '\''; compileContext.addMessage(CompilerMessageCategory.ERROR, CompilerBundle.message("message.text.compiling.module.message", moduleDescription, message), descriptor.getUrl(), -1, -1); diff --git a/java/compiler/impl/src/com/intellij/packaging/impl/artifacts/JarArtifactFromModulesDialog.java b/java/compiler/impl/src/com/intellij/packaging/impl/artifacts/JarArtifactFromModulesDialog.java index b2c377b0d160..a5e401eaabaa 100644 --- a/java/compiler/impl/src/com/intellij/packaging/impl/artifacts/JarArtifactFromModulesDialog.java +++ b/java/compiler/impl/src/com/intellij/packaging/impl/artifacts/JarArtifactFromModulesDialog.java @@ -17,6 +17,7 @@ package com.intellij.packaging.impl.artifacts; import com.intellij.ide.ui.ListCellRendererWrapper; import com.intellij.openapi.module.Module; +import com.intellij.openapi.module.ModuleType; import com.intellij.openapi.project.Project; import com.intellij.openapi.roots.ui.configuration.ModulesAlphaComparator; import com.intellij.openapi.ui.DialogWrapper; @@ -165,7 +166,7 @@ public class JarArtifactFromModulesDialog extends DialogWrapper { @Override public void customize(JList list, Module value, int index, boolean selected, boolean hasFocus) { if (value != null) { - setIcon(value.getModuleType().getNodeIcon(false)); + setIcon(ModuleType.get(value).getNodeIcon(false)); setText(value.getName()); } else { diff --git a/java/compiler/impl/src/com/intellij/packaging/impl/ui/ModuleElementPresentation.java b/java/compiler/impl/src/com/intellij/packaging/impl/ui/ModuleElementPresentation.java index 9b05f101f6fb..042329d9f2ac 100644 --- a/java/compiler/impl/src/com/intellij/packaging/impl/ui/ModuleElementPresentation.java +++ b/java/compiler/impl/src/com/intellij/packaging/impl/ui/ModuleElementPresentation.java @@ -20,6 +20,7 @@ import com.intellij.openapi.compiler.CompilerBundle; import com.intellij.openapi.module.ModifiableModuleModel; import com.intellij.openapi.module.Module; import com.intellij.openapi.module.ModulePointer; +import com.intellij.openapi.module.ModuleType; import com.intellij.packaging.ui.ArtifactEditorContext; import com.intellij.packaging.ui.PackagingElementWeights; import com.intellij.packaging.ui.TreeNodePresentation; @@ -70,8 +71,8 @@ public class ModuleElementPresentation extends TreeNodePresentation { presentationData.setIcons(PlatformIcons.TEST_SOURCE_FOLDER); } else if (module != null) { - presentationData.setOpenIcon(module.getModuleType().getNodeIcon(true)); - presentationData.setClosedIcon(module.getModuleType().getNodeIcon(false)); + presentationData.setOpenIcon(ModuleType.get(module).getNodeIcon(true)); + presentationData.setClosedIcon(ModuleType.get(module).getNodeIcon(false)); } String moduleName; if (module != null) { diff --git a/java/execution/impl/src/com/intellij/execution/ui/ConfigurationModuleSelector.java b/java/execution/impl/src/com/intellij/execution/ui/ConfigurationModuleSelector.java index f488a89cc32b..2d7dd2f7ca16 100644 --- a/java/execution/impl/src/com/intellij/execution/ui/ConfigurationModuleSelector.java +++ b/java/execution/impl/src/com/intellij/execution/ui/ConfigurationModuleSelector.java @@ -20,6 +20,7 @@ import com.intellij.execution.configurations.ModuleBasedConfiguration; import com.intellij.ide.ui.ListCellRendererWrapper; import com.intellij.openapi.module.Module; import com.intellij.openapi.module.ModuleManager; +import com.intellij.openapi.module.ModuleType; import com.intellij.openapi.module.ModuleTypeManager; import com.intellij.openapi.project.Project; import com.intellij.psi.PsiClass; @@ -66,7 +67,7 @@ public class ConfigurationModuleSelector { public void customize(final JList list, final Object value, final int index, final boolean selected, final boolean hasFocus) { if (value instanceof Module) { final Module module = (Module)value; - setIcon(module.getModuleType().getNodeIcon(true)); + setIcon(ModuleType.get(module).getNodeIcon(true)); setText(module.getName()); } else if (value == null) { @@ -91,7 +92,7 @@ public class ConfigurationModuleSelector { } public static boolean isModuleAccepted(final Module module) { - return ModuleTypeManager.getInstance().isClasspathProvider(module.getModuleType()); + return ModuleTypeManager.getInstance().isClasspathProvider(ModuleType.get(module)); } public Project getProject() { diff --git a/java/idea-ui/src/com/intellij/ide/util/frameworkSupport/FrameworkSupportUtil.java b/java/idea-ui/src/com/intellij/ide/util/frameworkSupport/FrameworkSupportUtil.java index 3993992f007a..0e6fb261fe63 100644 --- a/java/idea-ui/src/com/intellij/ide/util/frameworkSupport/FrameworkSupportUtil.java +++ b/java/idea-ui/src/com/intellij/ide/util/frameworkSupport/FrameworkSupportUtil.java @@ -29,7 +29,7 @@ public class FrameworkSupportUtil { } public static List getProviders(@NotNull Module module) { - return getProviders(module.getModuleType(), module); + return getProviders(ModuleType.get(module), module); } private static List getProviders(@NotNull ModuleType moduleType, @Nullable Module module) { diff --git a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/DefaultModuleEditorsProvider.java b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/DefaultModuleEditorsProvider.java index f365793da0d7..fe98d3db07a6 100644 --- a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/DefaultModuleEditorsProvider.java +++ b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/DefaultModuleEditorsProvider.java @@ -18,6 +18,7 @@ package com.intellij.openapi.roots.ui.configuration; import com.intellij.openapi.module.JavaModuleType; import com.intellij.openapi.module.Module; import com.intellij.openapi.module.ModuleConfigurationEditor; +import com.intellij.openapi.module.ModuleType; import com.intellij.openapi.roots.ModifiableRootModel; import java.util.ArrayList; @@ -27,7 +28,7 @@ public class DefaultModuleEditorsProvider implements ModuleConfigurationEditorPr public ModuleConfigurationEditor[] createEditors(ModuleConfigurationState state) { ModifiableRootModel rootModel = state.getRootModel(); Module module = rootModel.getModule(); - if (!(module.getModuleType() instanceof JavaModuleType)) { + if (!(ModuleType.get(module) instanceof JavaModuleType)) { return ModuleConfigurationEditor.EMPTY; } diff --git a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/ProjectStructureConfigurable.java b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/ProjectStructureConfigurable.java index 1db3b05fecf3..cfaf748cf0ea 100644 --- a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/ProjectStructureConfigurable.java +++ b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/ProjectStructureConfigurable.java @@ -68,7 +68,7 @@ public class ProjectStructureConfigurable extends BaseConfigurable implements Se private final UIState myUiState = new UIState(); private Splitter mySplitter; private JComponent myToolbarComponent; - @NonNls private static final String CATEGORY = "category"; + @NonNls public static final String CATEGORY = "category"; private JComponent myToFocus; private boolean myWasUiDisposed; private ConfigurationErrorsComponent myErrorsComponent; @@ -324,6 +324,10 @@ public class ProjectStructureConfigurable extends BaseConfigurable implements Se } } + public void hideSidePanel() { + mySplitter.getFirstComponent().setVisible(false); + } + public void disposeUIResources() { if (!myWasIntialized) return; final PropertiesComponent propertiesComponent = PropertiesComponent.getInstance(myProject); diff --git a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/artifacts/sourceItems/ModuleSourceItemGroup.java b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/artifacts/sourceItems/ModuleSourceItemGroup.java index aecfe28092cf..5b0d5a16fc82 100644 --- a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/artifacts/sourceItems/ModuleSourceItemGroup.java +++ b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/artifacts/sourceItems/ModuleSourceItemGroup.java @@ -17,6 +17,7 @@ package com.intellij.openapi.roots.ui.configuration.artifacts.sourceItems; import com.intellij.ide.projectView.PresentationData; import com.intellij.openapi.module.Module; +import com.intellij.openapi.module.ModuleType; import com.intellij.openapi.roots.DependencyScope; import com.intellij.openapi.roots.ModuleOrderEntry; import com.intellij.openapi.roots.OrderEntry; @@ -122,8 +123,8 @@ public class ModuleSourceItemGroup extends PackagingSourceItem { @Override public void render(@NotNull PresentationData presentationData, SimpleTextAttributes mainAttributes, SimpleTextAttributes commentAttributes) { - presentationData.setClosedIcon(myModule.getModuleType().getNodeIcon(false)); - presentationData.setOpenIcon(myModule.getModuleType().getNodeIcon(true)); + presentationData.setClosedIcon(ModuleType.get(myModule).getNodeIcon(false)); + presentationData.setOpenIcon(ModuleType.get(myModule).getNodeIcon(true)); presentationData.addText(myModule.getName(), mainAttributes); } diff --git a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/dependencyAnalysis/AnalyzeDependenciesComponent.java b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/dependencyAnalysis/AnalyzeDependenciesComponent.java index bde56cba8bc7..f6e1386ff52a 100644 --- a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/dependencyAnalysis/AnalyzeDependenciesComponent.java +++ b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/dependencyAnalysis/AnalyzeDependenciesComponent.java @@ -20,6 +20,7 @@ import com.intellij.ide.DataManager; import com.intellij.openapi.actionSystem.*; import com.intellij.openapi.actionSystem.ex.ComboBoxAction; import com.intellij.openapi.module.Module; +import com.intellij.openapi.module.ModuleType; import com.intellij.openapi.options.ConfigurationException; import com.intellij.openapi.project.DumbAwareAction; import com.intellij.openapi.roots.ModuleRootEvent; @@ -617,7 +618,7 @@ public class AnalyzeDependenciesComponent extends MasterDetailsComponent { return new CellAppearance() { @Override public void customize(SimpleColoredComponent component) { - component.setIcon(myModule.getModuleType().getNodeIcon(false)); + component.setIcon(ModuleType.get(myModule).getNodeIcon(false)); component.append("", SimpleTextAttributes.SYNTHETIC_ATTRIBUTES); } diff --git a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/projectRoot/AddFacetOfTypeAction.java b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/projectRoot/AddFacetOfTypeAction.java index 82a580cfdf52..dbc467adceed 100644 --- a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/projectRoot/AddFacetOfTypeAction.java +++ b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/projectRoot/AddFacetOfTypeAction.java @@ -24,6 +24,7 @@ import com.intellij.ide.util.ChooseElementsDialog; import com.intellij.openapi.actionSystem.AnAction; import com.intellij.openapi.actionSystem.AnActionEvent; import com.intellij.openapi.module.Module; +import com.intellij.openapi.module.ModuleType; import com.intellij.openapi.project.DumbAwareAction; import com.intellij.openapi.project.Project; import com.intellij.openapi.roots.ui.configuration.ChooseModulesDialog; @@ -68,7 +69,7 @@ class AddFacetOfTypeAction extends DumbAwareAction { final ProjectFacetsConfigurator facetsConfigurator = myContext.getModulesConfigurator().getFacetsConfigurator(); List suitableParents = new ArrayList(); for (Module module : myContext.getModules()) { - if (type.isSuitableModuleType(module.getModuleType())) { + if (type.isSuitableModuleType(ModuleType.get(module))) { suitableParents.addAll(facetsConfigurator.getFacetsByType(module, underlyingType)); } } @@ -104,7 +105,7 @@ class AddFacetOfTypeAction extends DumbAwareAction { final Iterator iterator = suitableModules.iterator(); while (iterator.hasNext()) { Module module = iterator.next(); - if (!type.isSuitableModuleType(module.getModuleType()) || (type.isOnlyOneFacetAllowed() && facetsConfigurator.hasFacetOfType(module, null, type.getId()))) { + if (!type.isSuitableModuleType(ModuleType.get(module)) || (type.isOnlyOneFacetAllowed() && facetsConfigurator.hasFacetOfType(module, null, type.getId()))) { iterator.remove(); } } @@ -139,7 +140,7 @@ class AddFacetOfTypeAction extends DumbAwareAction { private static boolean hasSuitableModules(StructureConfigurableContext context, FacetType type) { for (Module module : context.getModules()) { - if (type.isSuitableModuleType(module.getModuleType())) { + if (type.isSuitableModuleType(ModuleType.get(module))) { return true; } } diff --git a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/projectRoot/BaseStructureConfigurable.java b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/projectRoot/BaseStructureConfigurable.java index 604ef4b11b02..ec95a460d317 100644 --- a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/projectRoot/BaseStructureConfigurable.java +++ b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/projectRoot/BaseStructureConfigurable.java @@ -368,12 +368,7 @@ public abstract class BaseStructureConfigurable extends MasterDetailsComponent i if (object instanceof MyNode) { final NamedConfigurable namedConfigurable = ((MyNode)object).getConfigurable(); if (namedConfigurable != null) { - final Object editableObject = namedConfigurable.getEditableObject(); - if (editableObject instanceof Sdk || editableObject instanceof Module || editableObject instanceof Facet || editableObject instanceof Artifact) return true; - if (editableObject instanceof Library) { - final LibraryTable table = ((Library)editableObject).getTable(); - return table == null || table.isEditable(); - } + return canBeRemoved(namedConfigurable.getEditableObject()); } } return false; @@ -402,23 +397,43 @@ public abstract class BaseStructureConfigurable extends MasterDetailsComponent i final MyNode node = (MyNode)last; final NamedConfigurable configurable = node.getConfigurable(); final Object editableObject = configurable.getEditableObject(); - if (editableObject instanceof Sdk) { - removeJdk((Sdk)editableObject); - } - else if (editableObject instanceof Module) { - if (!removeModule((Module)editableObject)) return false; - } - else if (editableObject instanceof Facet) { - if (removeFacet((Facet)editableObject).isEmpty()) return false; - } - else if (editableObject instanceof Library) { - if (!removeLibrary((Library)editableObject)) return false; - } - else if (editableObject instanceof Artifact) { - removeArtifact((Artifact)editableObject); - } + + return removeObject(editableObject); + } + } + + protected boolean canBeRemoved(final Object editableObject) { + if (editableObject instanceof Sdk || + editableObject instanceof Module || + editableObject instanceof Facet || + editableObject instanceof Artifact) { return true; } + if (editableObject instanceof Library) { + final LibraryTable table = ((Library)editableObject).getTable(); + return table == null || table.isEditable(); + } + return false; + } + + protected boolean removeObject(final Object editableObject) { + // todo keep only removeModule() and removeFacet() here because other removeXXX() are empty here and overridden in subclasses? Override removeObject() instead? + if (editableObject instanceof Sdk) { + removeJdk((Sdk)editableObject); + } + else if (editableObject instanceof Module) { + if (!removeModule((Module)editableObject)) return false; + } + else if (editableObject instanceof Facet) { + if (removeFacet((Facet)editableObject).isEmpty()) return false; + } + else if (editableObject instanceof Library) { + if (!removeLibrary((Library)editableObject)) return false; + } + else if (editableObject instanceof Artifact) { + removeArtifact((Artifact)editableObject); + } + return true; } protected void removeArtifact(Artifact artifact) { diff --git a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/projectRoot/FacetEditorFacadeImpl.java b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/projectRoot/FacetEditorFacadeImpl.java index 6b6e3928d8d7..c160d90fcd14 100644 --- a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/projectRoot/FacetEditorFacadeImpl.java +++ b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/projectRoot/FacetEditorFacadeImpl.java @@ -181,7 +181,7 @@ public class FacetEditorFacadeImpl implements FacetEditorFacade { @Nullable public ModuleType getSelectedModuleType() { final Module module = getSelectedModule(); - return module != null ? module.getModuleType() : null; + return module != null ? ModuleType.get(module) : null; } @Nullable diff --git a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/projectRoot/ModuleConfigurable.java b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/projectRoot/ModuleConfigurable.java index 3584e55b996a..26cbc73fb1e2 100644 --- a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/projectRoot/ModuleConfigurable.java +++ b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/projectRoot/ModuleConfigurable.java @@ -18,6 +18,7 @@ package com.intellij.openapi.roots.ui.configuration.projectRoot; import com.intellij.openapi.module.ModifiableModuleModel; import com.intellij.openapi.module.Module; +import com.intellij.openapi.module.ModuleType; import com.intellij.openapi.module.ModuleWithNameAlreadyExists; import com.intellij.openapi.options.ConfigurationException; import com.intellij.openapi.project.ProjectBundle; @@ -91,11 +92,11 @@ public class ModuleConfigurable extends ProjectStructureElementConfigurable selectedObjectRetriever = new Computable() { + public Object compute() { + return getSelectedObject(); + } + }; + for (final ModuleStructureExtension extension : ModuleStructureExtension.EP_NAME.getExtensions()) { + result.addAll(extension.createAddActions(selectedObjectRetriever, TREE_UPDATER)); + } + return result.toArray(new AnAction[result.size()]); } }; @@ -679,6 +758,10 @@ public class ModuleStructureConfigurable extends BaseStructureConfigurable imple List removed = modulesConfigurator.getFacetsConfigurator().removeAllFacets(module); FacetStructureConfigurable.getInstance(myProject).removeFacetNodes(removed); myContext.getDaemonAnalyzer().removeElement(new ModuleProjectStructureElement(myContext, module)); + + for (final ModuleStructureExtension extension : ModuleStructureExtension.EP_NAME.getExtensions()) { + extension.moduleRemoved(module); + } return true; } @@ -771,7 +854,7 @@ public class ModuleStructureConfigurable extends BaseStructureConfigurable imple } public ModuleType getModuleType() { - return rootModel.getModule().getModuleType(); + return ModuleType.get(rootModel.getModule()); } }; builder.setName(component.getNameValue()); @@ -785,6 +868,9 @@ public class ModuleStructureConfigurable extends BaseStructureConfigurable imple LOG.error(e1); } } + else { + copyByExtension(namedConfigurable); + } } public void update(final AnActionEvent e) { @@ -792,12 +878,12 @@ public class ModuleStructureConfigurable extends BaseStructureConfigurable imple if (selectionPaths == null || selectionPaths.length != 1) { e.getPresentation().setEnabled(false); } else { - e.getPresentation().setEnabled(getSelectedConfugurable() instanceof ModuleConfigurable); + final NamedConfigurable selectedConfigurable = getSelectedConfugurable(); + e.getPresentation().setEnabled(selectedConfigurable instanceof ModuleConfigurable || canBeCopiedByExtension(selectedConfigurable)); } } } - private class AddModuleAction extends AnAction implements DumbAware { public AddModuleAction() { super(ProjectBundle.message("add.new.module.text.full"), null, IconLoader.getIcon("/actions/modul.png")); diff --git a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/projectRoot/ModuleStructureExtension.java b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/projectRoot/ModuleStructureExtension.java new file mode 100644 index 000000000000..c4dc15da4b9b --- /dev/null +++ b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/projectRoot/ModuleStructureExtension.java @@ -0,0 +1,60 @@ +package com.intellij.openapi.roots.ui.configuration.projectRoot; + +import com.intellij.openapi.actionSystem.AnAction; +import com.intellij.openapi.extensions.ExtensionPointName; +import com.intellij.openapi.module.Module; +import com.intellij.openapi.options.ConfigurationException; +import com.intellij.openapi.ui.MasterDetailsComponent; +import com.intellij.openapi.ui.NamedConfigurable; +import com.intellij.openapi.util.Computable; + +import java.util.Collection; +import java.util.Collections; + +public abstract class ModuleStructureExtension { + + public static final ExtensionPointName EP_NAME = + ExtensionPointName.create("com.intellij.configuration.ModuleStructureExtension"); + + public void reset() { + } + + public boolean addModuleNodeChildren(Module module, MasterDetailsComponent.MyNode moduleNode, Runnable treeNodeNameUpdater) { + return false; + } + + //public void moduleAdded(final Module module, final Runnable treeNodeNameUpdater) { + //} + + public void moduleRemoved(final Module module) { + } + + public boolean isModified() { + return false; + } + + public void apply() throws ConfigurationException { + } + + public void disposeUIResources() { + } + + public boolean canBeRemoved(final Object editableObject) { + return false; + } + + public boolean removeObject(final Object editableObject) { + return false; + } + + public Collection createAddActions(final Computable selectedObjectRetriever, final Runnable treeNodeNameUpdater) { + return Collections.emptyList(); + } + + public boolean canBeCopied(final NamedConfigurable confugurable) { + return false; + } + + public void copy(final NamedConfigurable confugurable, final Runnable treeNodeNameUpdater) { + } +} diff --git a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/projectRoot/daemon/UsageInModuleClasspath.java b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/projectRoot/daemon/UsageInModuleClasspath.java index ce8f23ebf821..54922119a573 100644 --- a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/projectRoot/daemon/UsageInModuleClasspath.java +++ b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/projectRoot/daemon/UsageInModuleClasspath.java @@ -1,6 +1,7 @@ package com.intellij.openapi.roots.ui.configuration.projectRoot.daemon; import com.intellij.openapi.module.Module; +import com.intellij.openapi.module.ModuleType; import com.intellij.openapi.roots.ModuleRootModel; import com.intellij.openapi.roots.OrderEntry; import com.intellij.openapi.roots.impl.OrderEntryUtil; @@ -81,6 +82,6 @@ public class UsageInModuleClasspath extends ProjectStructureElementUsage { @Override public Icon getIcon() { - return myModule.getModuleType().getNodeIcon(false); + return ModuleType.get(myModule).getNodeIcon(false); } } diff --git a/java/java-impl/src/com/intellij/codeInsight/ExpectedTypesProvider.java b/java/java-impl/src/com/intellij/codeInsight/ExpectedTypesProvider.java index b15c2381b54f..b4111d23d682 100644 --- a/java/java-impl/src/com/intellij/codeInsight/ExpectedTypesProvider.java +++ b/java/java-impl/src/com/intellij/codeInsight/ExpectedTypesProvider.java @@ -118,7 +118,9 @@ public class ExpectedTypesProvider { parent = parent.getParent(); } MyParentVisitor visitor = new MyParentVisitor(expr, forCompletion, classProvider, voidable, usedAfter); - parent.accept(visitor); + if (parent != null) { + parent.accept(visitor); + } return visitor.getResult(); } diff --git a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/PostHighlightingPass.java b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/PostHighlightingPass.java index daae8d4790d3..cba0bea1b967 100644 --- a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/PostHighlightingPass.java +++ b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/PostHighlightingPass.java @@ -537,8 +537,8 @@ public class PostHighlightingPass extends TextEditorHighlightingPass { // some classes may have references from within XML outside dependent modules, e.g. our actions if (member instanceof PsiClass) scope = scope.uniteWith(GlobalSearchScope.projectScope(myProject)); - PsiSearchHelper.SearchCostResult cheapEnough = myFile.getManager().getSearchHelper().isCheapEnoughToSearch(name, scope, myFile, - progress); + PsiSearchHelper.SearchCostResult cheapEnough = PsiSearchHelper.SERVICE.getInstance(myFile.getProject()) + .isCheapEnoughToSearch(name, scope, myFile, progress); if (cheapEnough == PsiSearchHelper.SearchCostResult.TOO_MANY_OCCURRENCES) return false; //search usages if it cheap diff --git a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/analysis/HighlightUtil.java b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/analysis/HighlightUtil.java index 5c276d0cd9cd..4c8d53375291 100644 --- a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/analysis/HighlightUtil.java +++ b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/analysis/HighlightUtil.java @@ -1168,6 +1168,9 @@ public class HighlightUtil { if (staticParent != null && isInstanceReference(place)) { QuickFixAction.registerQuickFixAction(errorResult, QUICK_FIX_FACTORY.createModifierListFix(staticParent, PsiModifier.STATIC, false, false)); } + if (place instanceof PsiReferenceExpression && refElement instanceof PsiField) { + QuickFixAction.registerQuickFixAction(errorResult, new CreateFieldFromUsageFix((PsiReferenceExpression)place)); + } } private static boolean isInstanceReference(PsiJavaCodeReferenceElement place) { diff --git a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/AddNewArrayExpressionFix.java b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/AddNewArrayExpressionFix.java index 29e3e36628f6..f770415837a1 100644 --- a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/AddNewArrayExpressionFix.java +++ b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/AddNewArrayExpressionFix.java @@ -21,6 +21,7 @@ import com.intellij.codeInsight.intention.IntentionAction; import com.intellij.openapi.editor.Editor; import com.intellij.openapi.project.Project; import com.intellij.psi.*; +import com.intellij.psi.codeStyle.CodeStyleManager; import com.intellij.util.IncorrectOperationException; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; @@ -59,7 +60,7 @@ public class AddNewArrayExpressionFix implements IntentionAction { @NonNls String text = "new " + type.getPresentableText() + "[]{}"; PsiNewExpression newExpr = (PsiNewExpression) factory.createExpressionFromText(text, null); newExpr.getArrayInitializer().replace(myInitializer); - newExpr = (PsiNewExpression) manager.getCodeStyleManager().reformat(newExpr); + newExpr = (PsiNewExpression) CodeStyleManager.getInstance(manager.getProject()).reformat(newExpr); myInitializer.replace(newExpr); } diff --git a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/BringVariableIntoScopeFix.java b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/BringVariableIntoScopeFix.java index 54bdb91e3781..985ef619415c 100644 --- a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/BringVariableIntoScopeFix.java +++ b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/BringVariableIntoScopeFix.java @@ -23,6 +23,7 @@ import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.editor.Editor; import com.intellij.openapi.project.Project; import com.intellij.psi.*; +import com.intellij.psi.codeStyle.CodeStyleManager; import com.intellij.psi.util.PsiFormatUtil; import com.intellij.psi.util.PsiTreeUtil; import com.intellij.psi.util.PsiTypesUtil; @@ -118,7 +119,7 @@ public class BringVariableIntoScopeFix implements IntentionAction { LOG.assertTrue(commonParent != null); PsiDeclarationStatement added = (PsiDeclarationStatement)commonParent.addBefore(newDeclaration, child); PsiLocalVariable addedVar = (PsiLocalVariable)added.getDeclaredElements()[0]; - manager.getCodeStyleManager().reformat(commonParent); + CodeStyleManager.getInstance(manager.getProject()).reformat(commonParent); //Leave initializer assignment PsiExpression initializer = myOutOfScopeVariable.getInitializer(); @@ -126,7 +127,7 @@ public class BringVariableIntoScopeFix implements IntentionAction { PsiExpressionStatement assignment = (PsiExpressionStatement)JavaPsiFacade.getInstance(manager.getProject()).getElementFactory().createStatementFromText(myOutOfScopeVariable .getName() + "= e;", null); ((PsiAssignmentExpression)assignment.getExpression()).getRExpression().replace(initializer); - assignment = (PsiExpressionStatement)manager.getCodeStyleManager().reformat(assignment); + assignment = (PsiExpressionStatement)CodeStyleManager.getInstance(manager.getProject()).reformat(assignment); PsiDeclarationStatement declStatement = PsiTreeUtil.getParentOfType(myOutOfScopeVariable, PsiDeclarationStatement.class); LOG.assertTrue(declStatement != null); PsiElement parent = declStatement.getParent(); diff --git a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/ChangeMethodSignatureFromUsageFix.java b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/ChangeMethodSignatureFromUsageFix.java index e6485a72f24d..365ffac25a33 100644 --- a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/ChangeMethodSignatureFromUsageFix.java +++ b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/ChangeMethodSignatureFromUsageFix.java @@ -109,15 +109,15 @@ public class ChangeMethodSignatureFromUsageFix implements IntentionAction, HighP if (myTargetMethod.getContainingClass().findMethodsByName(targetMethodName, true).length == 1) { if (newParams.size() == 1) { final ParameterInfoImpl p = newParams.iterator().next(); - return "Add " + p.getTypeText() + " as " + (ArrayUtil.find(myNewParametersInfo, p) + 1) + " parameter to method " + targetMethodName; + return QuickFixBundle.message("add.parameter.from.usage.text", p.getTypeText(), (ArrayUtil.find(myNewParametersInfo, p) + 1), targetMethodName); } if (removedParams.size() == 1) { final ParameterInfoImpl p = removedParams.iterator().next(); - return "Remove " + (p.getOldIndex() + 1) + " parameter from method " + targetMethodName; + return QuickFixBundle.message("remove.parameter.from.usage.text", (p.getOldIndex() + 1), targetMethodName); } if (changedParams.size() == 1) { final ParameterInfoImpl p = changedParams.iterator().next(); - return "Change " + (p.getOldIndex() + 1)+ " parameter of method " +targetMethodName + " from " + myTargetMethod.getParameterList().getParameters()[p.getOldIndex()].getType().getPresentableText() + " to " + p.getTypeText(); + return QuickFixBundle.message("change.parameter.from.usage.text", (p.getOldIndex() + 1), targetMethodName, myTargetMethod.getParameterList().getParameters()[p.getOldIndex()].getType().getPresentableText(), p.getTypeText()); } } return " Change signature of " + targetMethodName + "(" + buf.toString() + ")"; diff --git a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/CreateFieldFromUsageFix.java b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/CreateFieldFromUsageFix.java index 20ec50c5225a..85ea2a611336 100644 --- a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/CreateFieldFromUsageFix.java +++ b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/CreateFieldFromUsageFix.java @@ -22,7 +22,6 @@ import com.intellij.codeInsight.template.Template; import com.intellij.codeInsight.template.TemplateBuilderImpl; import com.intellij.codeInsight.template.TemplateEditingAdapter; import com.intellij.openapi.application.ApplicationManager; -import com.intellij.openapi.command.undo.UndoUtil; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.editor.Editor; import com.intellij.openapi.project.Project; @@ -32,7 +31,6 @@ import com.intellij.psi.codeStyle.CodeStyleManager; import com.intellij.psi.impl.source.codeStyle.CodeEditUtil; import com.intellij.psi.util.PsiTreeUtil; import com.intellij.psi.util.PsiUtil; -import com.intellij.util.IncorrectOperationException; import org.jetbrains.annotations.NotNull; /** @@ -54,10 +52,6 @@ public class CreateFieldFromUsageFix extends CreateVarFromUsageFix { } protected void invokeImpl(final PsiClass targetClass) { - if (CreateFromUsageUtils.isValidReference(myReferenceExpression, true)) { - return; - } - final Project project = myReferenceExpression.getProject(); PsiElementFactory factory = JavaPsiFacade.getInstance(project).getElementFactory(); diff --git a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/CreateFromUsageUtils.java b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/CreateFromUsageUtils.java index 0f43391f5df3..6a3a738c654a 100644 --- a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/CreateFromUsageUtils.java +++ b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/CreateFromUsageUtils.java @@ -342,7 +342,7 @@ public class CreateFromUsageUtils { classKind == CLASS ? elementFactory.createClass(name) : elementFactory.createEnum(name); CreateFromUsageBaseFix.setupGenericParameters(result, referenceElement); - result = (PsiClass)manager.getCodeStyleManager().reformat(result); + result = (PsiClass)CodeStyleManager.getInstance(manager.getProject()).reformat(result); return (PsiClass) psiClass.add(result); } catch (IncorrectOperationException e) { diff --git a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/CreateVarFromUsageFix.java b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/CreateVarFromUsageFix.java index bf5bb7c82284..7833c300205b 100644 --- a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/CreateVarFromUsageFix.java +++ b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/CreateVarFromUsageFix.java @@ -37,7 +37,7 @@ public abstract class CreateVarFromUsageFix extends CreateFromUsageBaseFix { protected boolean isValidElement(PsiElement element) { PsiReferenceExpression expression = (PsiReferenceExpression) element; - return CreateFromUsageUtils.isValidReference(expression, true); + return CreateFromUsageUtils.isValidReference(expression, false); } protected PsiElement getElement() { @@ -48,7 +48,7 @@ public abstract class CreateVarFromUsageFix extends CreateFromUsageBaseFix { if (parent instanceof PsiMethodCallExpression) return null; if (myReferenceExpression.getReferenceNameElement() != null) { - if (!CreateFromUsageUtils.isValidReference(myReferenceExpression, true)) { + if (!CreateFromUsageUtils.isValidReference(myReferenceExpression, false)) { return myReferenceExpression; } } diff --git a/java/java-impl/src/com/intellij/codeInsight/generation/surroundWith/JavaWithRunnableSurrounder.java b/java/java-impl/src/com/intellij/codeInsight/generation/surroundWith/JavaWithRunnableSurrounder.java index 5c0bddf016ef..a40e612f80e8 100644 --- a/java/java-impl/src/com/intellij/codeInsight/generation/surroundWith/JavaWithRunnableSurrounder.java +++ b/java/java-impl/src/com/intellij/codeInsight/generation/surroundWith/JavaWithRunnableSurrounder.java @@ -17,14 +17,21 @@ package com.intellij.codeInsight.generation.surroundWith; import com.intellij.codeInsight.CodeInsightBundle; +import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.editor.Editor; +import com.intellij.openapi.editor.RangeMarker; import com.intellij.openapi.project.Project; +import com.intellij.openapi.util.Comparing; import com.intellij.openapi.util.TextRange; import com.intellij.psi.*; import com.intellij.psi.codeStyle.CodeStyleManager; +import com.intellij.psi.codeStyle.JavaCodeStyleManager; import com.intellij.psi.search.LocalSearchScope; import com.intellij.psi.search.searches.ReferencesSearch; +import com.intellij.psi.util.PsiTreeUtil; import com.intellij.psi.util.PsiUtil; +import com.intellij.refactoring.rename.inplace.VariableInplaceRenameHandler; +import com.intellij.refactoring.rename.inplace.VariableInplaceRenamer; import com.intellij.util.IncorrectOperationException; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; @@ -37,10 +44,12 @@ public class JavaWithRunnableSurrounder extends JavaStatementsSurrounder{ return CodeInsightBundle.message("surround.with.runnable.template"); } - public TextRange surroundStatements(Project project, Editor editor, PsiElement container, PsiElement[] statements) throws IncorrectOperationException{ + public TextRange surroundStatements(Project project, final Editor editor, PsiElement container, PsiElement[] statements) throws IncorrectOperationException{ PsiManager manager = container.getManager(); PsiElementFactory factory = JavaPsiFacade.getInstance(manager.getProject()).getElementFactory(); CodeStyleManager codeStyleManager = CodeStyleManager.getInstance(project); + final String baseName = "runnable"; + final String uniqueName = JavaCodeStyleManager.getInstance(project).suggestUniqueVariableName(baseName, container, false); @NonNls String text = "Runnable runnable = new Runnable(){\npublic void run(){\n}};"; PsiDeclarationStatement declarationStatement = (PsiDeclarationStatement)factory.createStatementFromText(text, null); @@ -48,7 +57,12 @@ public class JavaWithRunnableSurrounder extends JavaStatementsSurrounder{ declarationStatement = (PsiDeclarationStatement)container.addAfter(declarationStatement, statements[statements.length - 1]); - PsiVariable variable = (PsiVariable)declarationStatement.getDeclaredElements()[0]; + final PsiVariable variable = (PsiVariable)declarationStatement.getDeclaredElements()[0]; + + if (!Comparing.strEqual(uniqueName, baseName)) { + variable.setName(uniqueName); + } + PsiNewExpression newExpression = (PsiNewExpression)variable.getInitializer(); PsiElement[] children = newExpression.getChildren(); PsiAnonymousClass anonymousClass = (PsiAnonymousClass)children[children.length - 1]; @@ -59,8 +73,22 @@ public class JavaWithRunnableSurrounder extends JavaStatementsSurrounder{ makeVariablesFinal(body, body); - TextRange range = variable.getNameIdentifier().getTextRange(); - return range; + final int textOffset = variable.getNameIdentifier().getTextOffset(); + PsiDocumentManager.getInstance(project).doPostponedOperationsAndUnblockDocument(editor.getDocument()); + editor.getCaretModel().moveToOffset(textOffset); + new VariableInplaceRenamer(variable, editor){ + @Override + protected void moveOffsetAfter(boolean success) { + super.moveOffsetAfter(success); + if (success) { + final PsiNamedElement renamedVariable = getVariable(); + if (renamedVariable != null) { + editor.getCaretModel().moveToOffset(renamedVariable.getTextRange().getEndOffset()); + } + } + } + }.performInplaceRename(); + return null; } private static void makeVariablesFinal(PsiElement scope, PsiCodeBlock body) throws IncorrectOperationException{ diff --git a/java/java-impl/src/com/intellij/codeInsight/intention/impl/ColorChooserIntentionAction.java b/java/java-impl/src/com/intellij/codeInsight/intention/impl/ColorChooserIntentionAction.java index cc750f41507d..cf54cac9fe4f 100644 --- a/java/java-impl/src/com/intellij/codeInsight/intention/impl/ColorChooserIntentionAction.java +++ b/java/java-impl/src/com/intellij/codeInsight/intention/impl/ColorChooserIntentionAction.java @@ -225,7 +225,7 @@ public class ColorChooserIntentionAction extends PsiElementBaseIntentionAction { + (color.getAlpha() < 255 ? ", " + color.getAlpha() : "") +")", expression); final PsiElement insertedElement = expression.replace(newCall); - final CodeStyleManager codeStyleManager = manager.getCodeStyleManager(); + final CodeStyleManager codeStyleManager = CodeStyleManager.getInstance(manager.getProject()); codeStyleManager.reformat(insertedElement); } } diff --git a/java/java-impl/src/com/intellij/codeInsight/intention/impl/ConcatenationToMessageFormatAction.java b/java/java-impl/src/com/intellij/codeInsight/intention/impl/ConcatenationToMessageFormatAction.java index 4a435898a227..1bb830647e82 100644 --- a/java/java-impl/src/com/intellij/codeInsight/intention/impl/ConcatenationToMessageFormatAction.java +++ b/java/java-impl/src/com/intellij/codeInsight/intention/impl/ConcatenationToMessageFormatAction.java @@ -22,6 +22,7 @@ import com.intellij.openapi.editor.Editor; import com.intellij.openapi.project.Project; import com.intellij.pom.java.LanguageLevel; import com.intellij.psi.*; +import com.intellij.psi.codeStyle.CodeStyleManager; import com.intellij.psi.codeStyle.JavaCodeStyleManager; import com.intellij.psi.search.GlobalSearchScope; import com.intellij.psi.util.PsiConcatenationUtil; @@ -78,7 +79,7 @@ public class ConcatenationToMessageFormatAction implements IntentionAction { argumentList.add(arrayArg); } call = (PsiMethodCallExpression) JavaCodeStyleManager.getInstance(project).shortenClassReferences(call); - call = (PsiMethodCallExpression) element.getManager().getCodeStyleManager().reformat(call); + call = (PsiMethodCallExpression) CodeStyleManager.getInstance(element.getManager().getProject()).reformat(call); concatenation.replace(call); } diff --git a/java/java-impl/src/com/intellij/codeInsight/intention/impl/ExpandStaticImportAction.java b/java/java-impl/src/com/intellij/codeInsight/intention/impl/ExpandStaticImportAction.java new file mode 100644 index 000000000000..a90c1d0b360f --- /dev/null +++ b/java/java-impl/src/com/intellij/codeInsight/intention/impl/ExpandStaticImportAction.java @@ -0,0 +1,163 @@ +/* + * Copyright 2000-2011 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. + */ +package com.intellij.codeInsight.intention.impl; + +import com.intellij.codeInsight.CodeInsightBundle; +import com.intellij.codeInsight.CodeInsightUtilBase; +import com.intellij.codeInsight.highlighting.HighlightManager; +import com.intellij.codeInsight.intention.PsiElementBaseIntentionAction; +import com.intellij.openapi.application.ApplicationManager; +import com.intellij.openapi.application.Result; +import com.intellij.openapi.command.WriteCommandAction; +import com.intellij.openapi.diagnostic.Logger; +import com.intellij.openapi.editor.Editor; +import com.intellij.openapi.editor.colors.EditorColors; +import com.intellij.openapi.editor.colors.EditorColorsManager; +import com.intellij.openapi.project.Project; +import com.intellij.openapi.ui.popup.JBPopupFactory; +import com.intellij.openapi.ui.popup.PopupChooserBuilder; +import com.intellij.openapi.ui.popup.PopupStep; +import com.intellij.openapi.ui.popup.util.BaseListPopupStep; +import com.intellij.psi.*; +import com.intellij.psi.util.PsiTreeUtil; +import com.intellij.psi.util.PsiUtil; +import com.intellij.util.IncorrectOperationException; +import com.sun.org.apache.xalan.internal.xsltc.compiler.util.StringStack; +import gnu.trove.TIntArrayList; +import gnu.trove.TIntProcedure; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; +import java.util.List; + +public class ExpandStaticImportAction extends PsiElementBaseIntentionAction { + private static final Logger LOG = Logger.getInstance("#" + ExpandStaticImportAction.class.getName()); + private static final String REPLACE_THIS_OCCURRENCE = "Replace this occurrence and keep the method"; + private static final String REPLACE_ALL_AND_DELETE_IMPORT = "Replace all and delete the import"; + + @NotNull + public String getFamilyName() { + return "Expand Static Import"; + } + + public boolean isAvailable(@NotNull Project project, Editor editor, @NotNull PsiElement element) { + if (!PsiUtil.isLanguageLevel5OrHigher(element)) return false; + final PsiElement parent = element.getParent(); + if (!(element instanceof PsiIdentifier) || !(parent instanceof PsiJavaCodeReferenceElement)) { + return false; + } + final PsiJavaCodeReferenceElement referenceElement = (PsiJavaCodeReferenceElement)parent; + final PsiElement resolveScope = referenceElement.advancedResolve(true).getCurrentFileResolveScope(); + if (resolveScope instanceof PsiImportStaticStatement) { + final PsiClass targetClass = ((PsiImportStaticStatement)resolveScope).resolveTargetClass(); + if (targetClass == null) return false; + setText("Expand static import to " + targetClass.getName() + "." + referenceElement.getReferenceName()); + return true; + } + return false; + } + + public void invoke(final Project project, final PsiFile file, final Editor editor, PsiElement element) { + if (!CodeInsightUtilBase.prepareFileForWrite(file)) return; + + final PsiJavaCodeReferenceElement refExpr = (PsiJavaCodeReferenceElement)element.getParent(); + + final PsiImportStaticStatement staticImport = (PsiImportStaticStatement)refExpr.advancedResolve(true).getCurrentFileResolveScope(); + + + final List expressionToExpand = new ArrayList(); + file.accept(new JavaRecursiveElementWalkingVisitor() { + @Override + public void visitReferenceElement(PsiJavaCodeReferenceElement expression) { + if (refExpr != expression) { + final PsiElement resolveScope = expression.advancedResolve(true).getCurrentFileResolveScope(); + if (resolveScope == staticImport) { + expressionToExpand.add(expression); + } + } + super.visitElement(expression); + } + }); + + + if (expressionToExpand.isEmpty()) { + expand(refExpr, staticImport); + staticImport.delete(); + } + else { + if (ApplicationManager.getApplication().isUnitTestMode()) { + replaceAllAndDeleteImport(expressionToExpand, refExpr, staticImport); + } + else { + final BaseListPopupStep step = + new BaseListPopupStep("Multiple Similar Calls Found", + new String[]{REPLACE_THIS_OCCURRENCE, REPLACE_ALL_AND_DELETE_IMPORT}) { + @Override + public PopupStep onChosen(final String selectedValue, boolean finalChoice) { + new WriteCommandAction(project, ExpandStaticImportAction.this.getText()) { + @Override + protected void run(Result result) throws Throwable { + if (selectedValue == REPLACE_THIS_OCCURRENCE) { + expand(refExpr, staticImport); + } + else { + replaceAllAndDeleteImport(expressionToExpand, refExpr, staticImport); + } + } + }.execute(); + return FINAL_CHOICE; + } + }; + JBPopupFactory.getInstance().createListPopup(step).showInBestPositionFor(editor); + } + } + } + + private static void replaceAllAndDeleteImport(List expressionToExpand, + PsiJavaCodeReferenceElement refExpr, + PsiImportStaticStatement staticImport) { + expressionToExpand.add(refExpr); + Collections.sort(expressionToExpand, new Comparator() { + @Override + public int compare(PsiJavaCodeReferenceElement o1, PsiJavaCodeReferenceElement o2) { + return o2.getTextOffset() - o1.getTextOffset(); + } + }); + for (PsiJavaCodeReferenceElement expression : expressionToExpand) { + expand(expression, staticImport); + } + staticImport.delete(); + } + + private static void expand(PsiJavaCodeReferenceElement refExpr, PsiImportStaticStatement staticImport) { + final PsiElementFactory elementFactory = JavaPsiFacade.getElementFactory(refExpr.getProject()); + final PsiReferenceExpression referenceExpression = elementFactory.createReferenceExpression(staticImport.resolveTargetClass()); + if (refExpr instanceof PsiReferenceExpression) { + ((PsiReferenceExpression)refExpr).setQualifierExpression(referenceExpression); + } + else { + refExpr.replace(elementFactory.createReferenceFromText(referenceExpression.getText() + "." + refExpr.getText(), refExpr)); + } + } + + public void invoke(@NotNull final Project project, final Editor editor, PsiFile file) throws IncorrectOperationException { + PsiElement element = file.findElementAt(editor.getCaretModel().getOffset()); + invoke(project, file, editor, element); + } +} diff --git a/java/java-impl/src/com/intellij/codeInsight/intention/impl/ImplementAbstractMethodHandler.java b/java/java-impl/src/com/intellij/codeInsight/intention/impl/ImplementAbstractMethodHandler.java index 05df29af2350..8586deff095f 100644 --- a/java/java-impl/src/com/intellij/codeInsight/intention/impl/ImplementAbstractMethodHandler.java +++ b/java/java-impl/src/com/intellij/codeInsight/intention/impl/ImplementAbstractMethodHandler.java @@ -47,10 +47,7 @@ import com.intellij.ui.components.JBList; import com.intellij.util.IncorrectOperationException; import javax.swing.*; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Comparator; -import java.util.List; +import java.util.*; public class ImplementAbstractMethodHandler { private static final Logger LOG = Logger.getInstance("#com.intellij.codeInsight.intention.impl.ImplementAbstractMethodHandler"); @@ -107,18 +104,17 @@ public class ImplementAbstractMethodHandler { } if (result[0].length == 1) { - implementInClass(result[0][0]); + implementInClass(new Object[] {result[0][0]}); return; } myList = new JBList(result[0]); - myList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); + myList.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); final Runnable runnable = new Runnable(){ public void run() { int index = myList.getSelectedIndex(); if (index < 0) return; - PsiElement element = (PsiElement)myList.getSelectedValue(); - implementInClass(element); + implementInClass(myList.getSelectedValues()); } }; final PsiElementListCellRenderer elementListCellRenderer = new MyPsiElementListCellRenderer(result[0]); @@ -133,31 +129,31 @@ public class ImplementAbstractMethodHandler { showInBestPositionFor(myEditor); } - private void implementInClass(final PsiElement psiClassOrEnumConstant) { - if (!psiClassOrEnumConstant.isValid()) return; - - final Document document = PsiDocumentManager.getInstance(myProject).getDocument(psiClassOrEnumConstant.getContainingFile()); - if (!FileDocumentManager.getInstance().requestWriting(document, myProject)) { - MessagesEx.fileIsReadOnly(myProject, psiClassOrEnumConstant.getContainingFile().getVirtualFile()).showNow(); - return; + private void implementInClass(final Object[] selection) { + for (Object o : selection) { + if (!((PsiElement)o).isValid()) return; } - CommandProcessor.getInstance().executeCommand(myProject, new Runnable() { public void run() { + final LinkedHashSet classes = new LinkedHashSet(); + for (Object o : selection) { + if (o instanceof PsiEnumConstant) { + classes.add(((PsiEnumConstant)o).getOrCreateInitializingClass()); + } + else { + classes.add((PsiClass)o); + } + } + if (!CodeInsightUtilBase.preparePsiElementsForWrite(classes)) return; ApplicationManager.getApplication().runWriteAction(new Runnable() { public void run() { - try { - PsiClass psiClass; - if (psiClassOrEnumConstant instanceof PsiEnumConstant) { - psiClass = ((PsiEnumConstant)psiClassOrEnumConstant).getOrCreateInitializingClass(); - } else { - psiClass = (PsiClass)psiClassOrEnumConstant; + for (PsiClass psiClass : classes) { + try { + OverrideImplementUtil.overrideOrImplement(psiClass, myMethod); + } + catch (IncorrectOperationException e) { + LOG.error(e); } - CodeInsightUtilBase.prepareFileForWrite(psiClass.getContainingFile()); - OverrideImplementUtil.overrideOrImplement(psiClass, myMethod); - } - catch (IncorrectOperationException e) { - LOG.error(e); } } }); diff --git a/java/java-impl/src/com/intellij/codeInsight/template/JavaCodeContextType.java b/java/java-impl/src/com/intellij/codeInsight/template/JavaCodeContextType.java index 20cec001fc04..8f9126648094 100644 --- a/java/java-impl/src/com/intellij/codeInsight/template/JavaCodeContextType.java +++ b/java/java-impl/src/com/intellij/codeInsight/template/JavaCodeContextType.java @@ -16,11 +16,15 @@ package com.intellij.codeInsight.template; import com.intellij.codeInsight.CodeInsightBundle; +import com.intellij.ide.DataManager; import com.intellij.ide.highlighter.JavaFileHighlighter; import com.intellij.lang.StdLanguages; +import com.intellij.openapi.actionSystem.PlatformDataKeys; +import com.intellij.openapi.editor.Document; import com.intellij.openapi.fileTypes.FileType; import com.intellij.openapi.fileTypes.StdFileTypes; import com.intellij.openapi.fileTypes.SyntaxHighlighter; +import com.intellij.openapi.project.Project; import com.intellij.psi.*; import com.intellij.psi.util.PsiTreeUtil; import com.intellij.psi.util.PsiUtilBase; @@ -62,4 +66,14 @@ public class JavaCodeContextType extends TemplateContextType { return new JavaFileHighlighter(); } + @Override + public Document createDocument(CharSequence text, Project project) { + if (project == null) { + return super.createDocument(text, project); + } + final JavaPsiFacade psiFacade = JavaPsiFacade.getInstance(project); + final PsiElementFactory factory = psiFacade.getElementFactory(); + final JavaCodeFragment fragment = factory.createCodeBlockCodeFragment((String)text, psiFacade.findPackage(""), true); + return PsiDocumentManager.getInstance(project).getDocument(fragment); + } } diff --git a/java/java-impl/src/com/intellij/codeInspection/deadCode/UnusedDeclarationInspection.java b/java/java-impl/src/com/intellij/codeInspection/deadCode/UnusedDeclarationInspection.java index 99d57299d621..ae14ce322e96 100644 --- a/java/java-impl/src/com/intellij/codeInspection/deadCode/UnusedDeclarationInspection.java +++ b/java/java-impl/src/com/intellij/codeInspection/deadCode/UnusedDeclarationInspection.java @@ -388,7 +388,7 @@ public class UnusedDeclarationInspection extends FilteringInspectionTool { ProgressManager.getInstance().runProcess(new Runnable() { public void run() { final RefFilter filter = new StrictUnreferencedFilter(UnusedDeclarationInspection.this); - final PsiSearchHelper helper = PsiManager.getInstance(getRefManager().getProject()).getSearchHelper(); + final PsiSearchHelper helper = PsiSearchHelper.SERVICE.getInstance(getRefManager().getProject()); getRefManager().iterate(new RefJavaVisitor() { @Override public void visitElement(final RefEntity refEntity) { if (refEntity instanceof RefClass && filter.accepts((RefClass)refEntity)) { diff --git a/java/java-impl/src/com/intellij/codeInspection/ex/GlobalJavaInspectionContextImpl.java b/java/java-impl/src/com/intellij/codeInspection/ex/GlobalJavaInspectionContextImpl.java index 03d8243e5f57..95c08724069f 100644 --- a/java/java-impl/src/com/intellij/codeInspection/ex/GlobalJavaInspectionContextImpl.java +++ b/java/java-impl/src/com/intellij/codeInspection/ex/GlobalJavaInspectionContextImpl.java @@ -31,6 +31,7 @@ import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.fileTypes.StdFileTypes; import com.intellij.openapi.module.Module; import com.intellij.openapi.module.ModuleManager; +import com.intellij.openapi.module.ModuleType; import com.intellij.openapi.project.Project; import com.intellij.openapi.projectRoots.Sdk; import com.intellij.openapi.roots.*; @@ -153,7 +154,7 @@ public class GlobalJavaInspectionContextImpl extends GlobalJavaInspectionContext for (Module module : modules) { if (ModuleRootManager.getInstance(module).isSdkInherited()) { anyModuleUsesProjectSdk = true; - if (module.getModuleType().isValidSdk(module, projectSdk)) { + if (ModuleType.get(module).isValidSdk(module, projectSdk)) { anyModuleAcceptsSdk = true; } } diff --git a/java/java-impl/src/com/intellij/codeInspection/unusedLibraries/UnusedLibrariesInspection.java b/java/java-impl/src/com/intellij/codeInspection/unusedLibraries/UnusedLibrariesInspection.java index 177b52540e65..27f8765d911d 100644 --- a/java/java-impl/src/com/intellij/codeInspection/unusedLibraries/UnusedLibrariesInspection.java +++ b/java/java-impl/src/com/intellij/codeInspection/unusedLibraries/UnusedLibrariesInspection.java @@ -48,6 +48,7 @@ import com.intellij.psi.PsiCompiledElement; import com.intellij.psi.PsiFile; import com.intellij.psi.PsiRecursiveElementVisitor; import com.intellij.psi.search.GlobalSearchScope; +import com.intellij.psi.search.GlobalSearchScopes; import com.intellij.psi.search.scope.packageSet.NamedScope; import com.intellij.psi.search.scope.packageSet.PackageSetFactory; import com.intellij.psi.search.scope.packageSet.ParsingException; @@ -94,7 +95,7 @@ public class UnusedLibrariesInspection extends DescriptorProviderInspection { GlobalSearchScope searchScope; try { @NonNls final String libsName = "libs"; - searchScope = GlobalSearchScope.filterScope(project, new NamedScope(libsName, PackageSetFactory.getInstance().compile("lib:*..*"))); + searchScope = GlobalSearchScopes.filterScope(project, new NamedScope(libsName, PackageSetFactory.getInstance().compile("lib:*..*"))); } catch (ParsingException e) { //can't be diff --git a/java/java-impl/src/com/intellij/codeInspection/unusedParameters/UnusedParametersInspection.java b/java/java-impl/src/com/intellij/codeInspection/unusedParameters/UnusedParametersInspection.java index 4ece89ad7fd4..2a3b771ff4e5 100644 --- a/java/java-impl/src/com/intellij/codeInspection/unusedParameters/UnusedParametersInspection.java +++ b/java/java-impl/src/com/intellij/codeInspection/unusedParameters/UnusedParametersInspection.java @@ -102,7 +102,7 @@ public class UnusedParametersInspection extends GlobalJavaInspectionTool { processor.ignoreElement(entryPoint); } - final PsiSearchHelper helper = PsiManager.getInstance(project).getSearchHelper(); + final PsiSearchHelper helper = PsiSearchHelper.SERVICE.getInstance(project); final AnalysisScope scope = manager.getScope(); manager.iterate(new RefJavaVisitor() { @Override public void visitElement(RefEntity refEntity) { diff --git a/java/java-impl/src/com/intellij/codeInspection/varScopeCanBeNarrowed/FieldCanBeLocalInspection.java b/java/java-impl/src/com/intellij/codeInspection/varScopeCanBeNarrowed/FieldCanBeLocalInspection.java index 07cce89f5c9e..bdd975abc162 100644 --- a/java/java-impl/src/com/intellij/codeInspection/varScopeCanBeNarrowed/FieldCanBeLocalInspection.java +++ b/java/java-impl/src/com/intellij/codeInspection/varScopeCanBeNarrowed/FieldCanBeLocalInspection.java @@ -25,6 +25,7 @@ import com.intellij.codeInspection.ProblemDescriptor; import com.intellij.codeInspection.ProblemsHolder; import com.intellij.codeInspection.ex.BaseLocalInspectionTool; import com.intellij.codeInspection.util.SpecialAnnotationsUtil; +import com.intellij.lang.java.JavaCommenter; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.editor.Editor; import com.intellij.openapi.editor.ScrollType; @@ -39,6 +40,7 @@ import com.intellij.psi.*; import com.intellij.psi.codeStyle.JavaCodeStyleManager; import com.intellij.psi.codeStyle.VariableKind; import com.intellij.psi.controlFlow.*; +import com.intellij.psi.javadoc.PsiDocComment; import com.intellij.psi.search.searches.ReferencesSearch; import com.intellij.psi.util.PsiTreeUtil; import com.intellij.psi.util.PsiUtil; @@ -229,14 +231,11 @@ public class FieldCanBeLocalInspection extends BaseLocalInspectionTool { } @Override public void visitReferenceExpression(PsiReferenceExpression expression) { - final PsiExpression qualifier = expression.getQualifierExpression(); - if (qualifier == null || qualifier instanceof PsiThisExpression) { - final PsiElement resolved = expression.resolve(); - if (resolved instanceof PsiField) { - final PsiField field = (PsiField)resolved; - if (aClass.equals(field.getContainingClass())) { - candidates.remove(field); - } + final PsiElement resolved = expression.resolve(); + if (resolved instanceof PsiField) { + final PsiField field = (PsiField)resolved; + if (aClass.equals(field.getContainingClass())) { + candidates.remove(field); } } @@ -265,6 +264,7 @@ public class FieldCanBeLocalInspection extends BaseLocalInspectionTool { PsiField myField = PsiTreeUtil.getParentOfType(element, PsiField.class); if (myField == null || !myField.isValid()) return; //weird. should not get here when field becomes invalid + final PsiDocComment docComment = myField.getDocComment(); final Collection refs = ReferencesSearch.search(myField).findAll(); if (refs.isEmpty()) return; Set refsSet = new HashSet(refs); @@ -311,6 +311,20 @@ public class FieldCanBeLocalInspection extends BaseLocalInspectionTool { } if (newDeclaration != null) { + if (docComment != null) { + final StringBuilder buf = new StringBuilder(); + for (PsiElement psiElement : docComment.getDescriptionElements()) { + buf.append(psiElement.getText()); + } + if (buf.length() > 0) { + final JavaCommenter commenter = new JavaCommenter(); + final PsiComment comment = JavaPsiFacade.getElementFactory(project) + .createCommentFromText(commenter.getBlockCommentPrefix() + + buf.toString() + + commenter.getBlockCommentSuffix(), newDeclaration); + newDeclaration.getParent().addBefore(comment, newDeclaration); + } + } final PsiFile psiFile = myField.getContainingFile(); final Editor editor = FileEditorManager.getInstance(project).getSelectedTextEditor(); if (editor != null && IJSwingUtilities.hasFocus(editor.getComponent())) { diff --git a/java/java-impl/src/com/intellij/codeInspection/visibility/VisibilityInspection.java b/java/java-impl/src/com/intellij/codeInspection/visibility/VisibilityInspection.java index 197f1405d280..4916e6c548b8 100644 --- a/java/java-impl/src/com/intellij/codeInspection/visibility/VisibilityInspection.java +++ b/java/java-impl/src/com/intellij/codeInspection/visibility/VisibilityInspection.java @@ -39,6 +39,7 @@ import com.intellij.openapi.project.Project; import com.intellij.psi.*; import com.intellij.psi.search.GlobalSearchScope; import com.intellij.psi.search.PsiNonJavaFileReferenceProcessor; +import com.intellij.psi.search.PsiSearchHelper; import com.intellij.psi.util.PsiTreeUtil; import com.intellij.psi.util.PsiUtil; import com.intellij.util.IncorrectOperationException; @@ -418,7 +419,7 @@ public class VisibilityInspection extends GlobalJavaInspectionTool { String qualifiedName = ownerClass.getElement().getQualifiedName(); if (qualifiedName != null) { final Project project = manager.getProject(); - PsiManager.getInstance(project).getSearchHelper() + PsiSearchHelper.SERVICE.getInstance(project) .processUsagesInNonJavaFiles(qualifiedName, new PsiNonJavaFileReferenceProcessor() { public boolean process(PsiFile file, int startOffset, int endOffset) { entryPointsManager.addEntryPoint(refMethod, false); diff --git a/java/java-impl/src/com/intellij/find/findUsages/JavaFindUsagesDialog.java b/java/java-impl/src/com/intellij/find/findUsages/JavaFindUsagesDialog.java index 87c6e4269acf..ba7821fad54f 100644 --- a/java/java-impl/src/com/intellij/find/findUsages/JavaFindUsagesDialog.java +++ b/java/java-impl/src/com/intellij/find/findUsages/JavaFindUsagesDialog.java @@ -21,12 +21,11 @@ import com.intellij.openapi.help.HelpManager; import com.intellij.openapi.project.Project; import com.intellij.openapi.util.text.StringUtil; import com.intellij.psi.PsiElement; -import com.intellij.psi.PsiManager; import com.intellij.psi.PsiMethod; import com.intellij.psi.search.LocalSearchScope; +import com.intellij.psi.search.PsiSearchHelper; import com.intellij.psi.util.MethodSignatureUtil; import com.intellij.ui.SimpleColoredComponent; -import com.intellij.ui.SimpleTextAttributes; import com.intellij.ui.StateRestoringCheckBox; import com.intellij.usageView.UsageViewUtil; @@ -83,13 +82,9 @@ public abstract class JavaFindUsagesDialog exte } } - private PsiManager getPsiManager() { - return myPsiElement.getManager(); - } - protected boolean isInFileOnly() { return super.isInFileOnly() || - myPsiElement != null && getPsiManager().getSearchHelper().getUseScope(myPsiElement)instanceof LocalSearchScope; + myPsiElement != null && PsiSearchHelper.SERVICE.getInstance(myPsiElement.getProject()).getUseScope(myPsiElement)instanceof LocalSearchScope; } public void configureLabelComponent(final SimpleColoredComponent coloredComponent) { diff --git a/java/java-impl/src/com/intellij/lang/java/JavaRefactoringSupportProvider.java b/java/java-impl/src/com/intellij/lang/java/JavaRefactoringSupportProvider.java index 2d09340a48f2..e4a665901380 100644 --- a/java/java-impl/src/com/intellij/lang/java/JavaRefactoringSupportProvider.java +++ b/java/java-impl/src/com/intellij/lang/java/JavaRefactoringSupportProvider.java @@ -19,6 +19,7 @@ import com.intellij.lang.refactoring.RefactoringSupportProvider; import com.intellij.psi.*; import com.intellij.psi.javadoc.PsiDocComment; import com.intellij.psi.search.LocalSearchScope; +import com.intellij.psi.search.PsiSearchHelper; import com.intellij.psi.search.SearchScope; import com.intellij.psi.util.PsiTreeUtil; import com.intellij.refactoring.RefactoringActionHandler; @@ -107,7 +108,7 @@ public class JavaRefactoringSupportProvider extends RefactoringSupportProvider { public static boolean mayRenameInplace(PsiElement elementToRename, final PsiElement nameSuggestionContext) { if (nameSuggestionContext != null && nameSuggestionContext.getContainingFile() != elementToRename.getContainingFile()) return false; if (!(elementToRename instanceof PsiLocalVariable) && !(elementToRename instanceof PsiParameter) && !(elementToRename instanceof PsiTypeParameter)) return false; - SearchScope useScope = elementToRename.getManager().getSearchHelper().getUseScope(elementToRename); + SearchScope useScope = PsiSearchHelper.SERVICE.getInstance(elementToRename.getProject()).getUseScope(elementToRename); if (!(useScope instanceof LocalSearchScope)) return false; PsiElement[] scopeElements = ((LocalSearchScope) useScope).getScope(); if (scopeElements.length > 1 && // assume there are no elements with use scopes with holes in them diff --git a/java/java-impl/src/com/intellij/psi/ClassFileViewProvider.java b/java/java-impl/src/com/intellij/psi/ClassFileViewProvider.java index 9628111f74e5..cba11dd3caa3 100644 --- a/java/java-impl/src/com/intellij/psi/ClassFileViewProvider.java +++ b/java/java-impl/src/com/intellij/psi/ClassFileViewProvider.java @@ -56,7 +56,8 @@ public class ClassFileViewProvider extends SingleRootFileViewProvider { } @NotNull - public SingleRootFileViewProvider createCopy(final LightVirtualFile copy) { + @Override + public SingleRootFileViewProvider createCopy(final VirtualFile copy) { return new ClassFileViewProvider(getManager(), copy, false); } } \ No newline at end of file diff --git a/java/java-impl/src/com/intellij/psi/impl/JavaDirectoryIconProvider.java b/java/java-impl/src/com/intellij/psi/impl/JavaDirectoryIconProvider.java index 533e75937e60..805053a99aa4 100644 --- a/java/java-impl/src/com/intellij/psi/impl/JavaDirectoryIconProvider.java +++ b/java/java-impl/src/com/intellij/psi/impl/JavaDirectoryIconProvider.java @@ -18,6 +18,7 @@ package com.intellij.psi.impl; import com.intellij.ide.IconProvider; import com.intellij.ide.projectView.impl.ProjectRootsUtil; import com.intellij.openapi.module.Module; +import com.intellij.openapi.module.ModuleType; import com.intellij.openapi.project.DumbAware; import com.intellij.openapi.project.Project; import com.intellij.openapi.roots.ProjectRootManager; @@ -56,7 +57,7 @@ public class JavaDirectoryIconProvider extends IconProvider implements DumbAware else if (isContentRoot) { Module module = ProjectRootManager.getInstance(project).getFileIndex().getModuleForFile(vFile); if (module != null) { - symbolIcon = module.getModuleType().getNodeIcon(isOpen); + symbolIcon = ModuleType.get(module).getNodeIcon(isOpen); } else { symbolIcon = isOpen ? PlatformIcons.CONTENT_ROOT_ICON_OPEN : PlatformIcons.CONTENT_ROOT_ICON_CLOSED; diff --git a/java/java-impl/src/com/intellij/psi/impl/PsiElementFactoryImpl.java b/java/java-impl/src/com/intellij/psi/impl/PsiElementFactoryImpl.java index e2e904e6e592..c8d8faa795d0 100644 --- a/java/java-impl/src/com/intellij/psi/impl/PsiElementFactoryImpl.java +++ b/java/java-impl/src/com/intellij/psi/impl/PsiElementFactoryImpl.java @@ -186,8 +186,8 @@ public class PsiElementFactoryImpl extends PsiJavaParserFacadeImpl implements Ps if (fields.length < 1) { throw new IncorrectOperationException("Field was not created " + text); } - final PsiField field = fields[0]; - JavaCodeStyleManager.getInstance(myManager.getProject()).shortenClassReferences(field); + PsiField field = fields[0]; + field = (PsiField)JavaCodeStyleManager.getInstance(myManager.getProject()).shortenClassReferences(field); return (PsiField)CodeStyleManager.getInstance(myManager.getProject()).reformat(field); } @@ -199,9 +199,18 @@ public class PsiElementFactoryImpl extends PsiJavaParserFacadeImpl implements Ps throw new IncorrectOperationException("Cannot create method with type \"null\"."); } - final PsiJavaFile aFile = createDummyJavaFile(join("class _Dummy_ { public " + returnType.getCanonicalText(), " ", name, "() {} }")); - final PsiMethod method = aFile.getClasses()[0].getMethods()[0]; - JavaCodeStyleManager.getInstance(myManager.getProject()).shortenClassReferences(method); + final String canonicalText = returnType.getCanonicalText(); + final PsiJavaFile aFile = createDummyJavaFile(join("class _Dummy_ { public " + canonicalText, " ", name, "() {} }")); + final PsiClass[] classes = aFile.getClasses(); + if (classes.length < 1) { + throw new IncorrectOperationException("Class was not created. Method name: " + name + "; return type: " + canonicalText); + } + final PsiMethod[] methods = classes[0].getMethods(); + if (methods.length < 1) { + throw new IncorrectOperationException("Method was not created. Method name: " + name + "; return type: " + canonicalText); + } + PsiMethod method = methods[0]; + method = (PsiMethod)JavaCodeStyleManager.getInstance(myManager.getProject()).shortenClassReferences(method); return (PsiMethod)CodeStyleManager.getInstance(myManager.getProject()).reformat(method); } @@ -230,12 +239,12 @@ public class PsiElementFactoryImpl extends PsiJavaParserFacadeImpl implements Ps } final String text = join(type.getCanonicalText() + " " + name); - final PsiParameter parameter = createParameterFromText(text, null); + PsiParameter parameter = createParameterFromText(text, null); final CodeStyleManager codeStyleManager = CodeStyleManager.getInstance(myManager.getProject()); PsiUtil.setModifierProperty(parameter, PsiModifier.FINAL, CodeStyleSettingsManager.getSettings(myManager.getProject()).GENERATE_FINAL_PARAMETERS); markGenerated(parameter); - JavaCodeStyleManager.getInstance(myManager.getProject()).shortenClassReferences(parameter); + parameter = (PsiParameter)JavaCodeStyleManager.getInstance(myManager.getProject()).shortenClassReferences(parameter); return (PsiParameter)codeStyleManager.reformat(parameter); } @@ -264,21 +273,13 @@ public class PsiElementFactoryImpl extends PsiJavaParserFacadeImpl implements Ps final PsiTypeParameter[] typeParameters = aClass.getTypeParameters(); assert typeParameters.length == 1 : aClass; - final Map map = Collections.singletonMap(typeParameters[0], parameter); - return createType(aClass, createSubstitutor(map)); + return createType(aClass, PsiSubstitutor.EMPTY.put(typeParameters[0], parameter)); } @NotNull @Override public PsiClassType createType(@NotNull final PsiClass aClass, final PsiType... parameters) { - final PsiTypeParameter[] typeParameters = aClass.getTypeParameters(); - assert parameters.length == typeParameters.length; - - final Map map = new java.util.HashMap(); - for (int i = 0; i < parameters.length; i++) { - map.put(typeParameters[i], parameters[i]); - } - return createType(aClass, createSubstitutor(map)); + return createType(aClass, PsiSubstitutor.EMPTY.putAll(aClass, parameters)); } @NotNull diff --git a/java/java-impl/src/com/intellij/psi/impl/PsiJavaParserFacadeImpl.java b/java/java-impl/src/com/intellij/psi/impl/PsiJavaParserFacadeImpl.java index 776d6fbfde63..1ff3da344cc6 100644 --- a/java/java-impl/src/com/intellij/psi/impl/PsiJavaParserFacadeImpl.java +++ b/java/java-impl/src/com/intellij/psi/impl/PsiJavaParserFacadeImpl.java @@ -28,6 +28,7 @@ import com.intellij.openapi.roots.LanguageLevelProjectExtension; import com.intellij.openapi.util.text.StringUtil; import com.intellij.pom.java.LanguageLevel; import com.intellij.psi.*; +import com.intellij.psi.codeStyle.CodeStyleManager; import com.intellij.psi.impl.source.DummyHolder; import com.intellij.psi.impl.source.DummyHolderFactory; import com.intellij.psi.impl.source.JavaDummyElement; @@ -407,7 +408,7 @@ public class PsiJavaParserFacadeImpl extends PsiParserFacadeImpl implements PsiJ throw new IncorrectOperationException("Incorrect catch section '" + text + "'. Parsed element: " + element); } setupCatchBlock(exceptionName, context, (PsiCatchSection)element); - return (PsiCatchSection)myManager.getCodeStyleManager().reformat(element); + return (PsiCatchSection)CodeStyleManager.getInstance(myManager.getProject()).reformat(element); } private void setupCatchBlock(final String exceptionName, @Nullable final PsiElement context, final PsiCatchSection psiCatchSection) diff --git a/java/java-impl/src/com/intellij/psi/impl/light/LightVariableBuilder.java b/java/java-impl/src/com/intellij/psi/impl/light/LightVariableBuilder.java index 402528376673..580325714502 100644 --- a/java/java-impl/src/com/intellij/psi/impl/light/LightVariableBuilder.java +++ b/java/java-impl/src/com/intellij/psi/impl/light/LightVariableBuilder.java @@ -9,6 +9,7 @@ import com.intellij.util.IncorrectOperationException; import com.intellij.util.PlatformIcons; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import javax.swing.*; @@ -30,7 +31,7 @@ public class LightVariableBuilder extends LightE setNavigationElement(navigationElement); } - public LightVariableBuilder(PsiManager manager, @NotNull String name, @NotNull PsiType type, Language language) { + public LightVariableBuilder(PsiManager manager, @Nullable String name, @NotNull PsiType type, Language language) { super(manager, language); myName = name; myType = type; diff --git a/java/java-impl/src/com/intellij/psi/impl/search/AnnotatedElementsSearcher.java b/java/java-impl/src/com/intellij/psi/impl/search/AnnotatedElementsSearcher.java index 8d489df3c774..ae56ee660763 100644 --- a/java/java-impl/src/com/intellij/psi/impl/search/AnnotatedElementsSearcher.java +++ b/java/java-impl/src/com/intellij/psi/impl/search/AnnotatedElementsSearcher.java @@ -1,6 +1,8 @@ package com.intellij.psi.impl.search; +import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.diagnostic.Logger; +import com.intellij.openapi.util.Computable; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.psi.*; import com.intellij.psi.impl.PsiManagerImpl; @@ -35,12 +37,23 @@ public class AnnotatedElementsSearcher implements QueryExecutor[] types = p.getTypes(); final GlobalSearchScope scope = useScope instanceof GlobalSearchScope ? (GlobalSearchScope)useScope : null; - final Collection annotations = JavaAnnotationIndex.getInstance().get(annClass.getName(), annClass.getProject(), scope); + final Collection annotations = ApplicationManager.getApplication().runReadAction( + new Computable>() { + @Override + public Collection compute() { + return JavaAnnotationIndex.getInstance().get(annClass.getName(), annClass.getProject(), scope); + } + }); for (PsiElement elt : annotations) { if (notAnnotation(elt)) continue; - PsiAnnotation ann = (PsiAnnotation)elt; - final PsiJavaCodeReferenceElement ref = ann.getNameReferenceElement(); + final PsiAnnotation ann = (PsiAnnotation)elt; + final PsiJavaCodeReferenceElement ref = ApplicationManager.getApplication().runReadAction(new Computable() { + @Override + public PsiJavaCodeReferenceElement compute() { + return ann.getNameReferenceElement(); + } + }); if (ref == null) continue; PsiElement parent = ann.getParent(); @@ -56,7 +69,12 @@ public class AnnotatedElementsSearcher implements QueryExecutor() { + @Override + public PsiElement compute() { + return ref.resolve(); + } + }), annClass)) continue; if (useScope instanceof GlobalSearchScope && !((GlobalSearchScope)useScope).contains(candidate.getContainingFile().getVirtualFile())) { continue; diff --git a/java/java-impl/src/com/intellij/psi/impl/search/AnnotatedPackagesSearcher.java b/java/java-impl/src/com/intellij/psi/impl/search/AnnotatedPackagesSearcher.java index cd900f6ab940..0ae95821760a 100644 --- a/java/java-impl/src/com/intellij/psi/impl/search/AnnotatedPackagesSearcher.java +++ b/java/java-impl/src/com/intellij/psi/impl/search/AnnotatedPackagesSearcher.java @@ -79,7 +79,7 @@ public class AnnotatedPackagesSearcher implements QueryExecutor 0) fieldBuffer.append(delegateVisibility).append(' '); @@ -691,7 +691,7 @@ public class ExtractClassProcessor extends FixableUsagesRefactoringProcessor { if (directory != null) { final PsiFile newFile = PsiFileFactory.getInstance(project).createFileFromText(newClassName + ".java", classString); final PsiElement addedFile = directory.add(newFile); - final CodeStyleManager codeStyleManager = manager.getCodeStyleManager(); + final CodeStyleManager codeStyleManager = CodeStyleManager.getInstance(manager.getProject()); final PsiElement shortenedFile = JavaCodeStyleManager.getInstance(project).shortenClassReferences(addedFile); return ((PsiJavaFile)codeStyleManager.reformat(shortenedFile)).getClasses()[0]; } else { diff --git a/java/java-impl/src/com/intellij/refactoring/inline/InlineMethodDialog.java b/java/java-impl/src/com/intellij/refactoring/inline/InlineMethodDialog.java index e5a3c794b843..27659f109f87 100644 --- a/java/java-impl/src/com/intellij/refactoring/inline/InlineMethodDialog.java +++ b/java/java-impl/src/com/intellij/refactoring/inline/InlineMethodDialog.java @@ -20,7 +20,6 @@ import com.intellij.openapi.help.HelpManager; import com.intellij.openapi.progress.ProgressManager; import com.intellij.openapi.project.Project; import com.intellij.psi.PsiJavaCodeReferenceElement; -import com.intellij.psi.PsiManager; import com.intellij.psi.PsiMethod; import com.intellij.psi.PsiSubstitutor; import com.intellij.psi.search.GlobalSearchScope; @@ -57,7 +56,7 @@ public class InlineMethodDialog extends InlineOptionsDialog { private void initOccurrencesNumber(PsiMethod method) { final ProgressManager progressManager = ProgressManager.getInstance(); - final PsiSearchHelper searchHelper = method.getManager().getSearchHelper(); + final PsiSearchHelper searchHelper = PsiSearchHelper.SERVICE.getInstance(method.getProject()); final GlobalSearchScope scope = GlobalSearchScope.projectScope(method.getProject()); final boolean isCheapToSearch = searchHelper.isCheapEnoughToSearch(method.getName(), scope, null, progressManager.getProgressIndicator()) != PsiSearchHelper.SearchCostResult.TOO_MANY_OCCURRENCES; diff --git a/java/java-impl/src/com/intellij/refactoring/introduceParameter/InplaceIntroduceParameterPopup.java b/java/java-impl/src/com/intellij/refactoring/introduceParameter/InplaceIntroduceParameterPopup.java index 165cfa8eab5c..9ad45a24d8fa 100644 --- a/java/java-impl/src/com/intellij/refactoring/introduceParameter/InplaceIntroduceParameterPopup.java +++ b/java/java-impl/src/com/intellij/refactoring/introduceParameter/InplaceIntroduceParameterPopup.java @@ -291,4 +291,12 @@ public class InplaceIntroduceParameterPopup extends AbstractJavaInplaceIntroduce public void setReplaceAllOccurrences(boolean replaceAll) { myPanel.setReplaceAllOccurrences(replaceAll); } + + public PsiMethod getMethodToIntroduceParameter() { + return myMethod; + } + + public PsiMethod getMethodToSearchFor() { + return myMethodToSearchFor; + } } diff --git a/java/java-impl/src/com/intellij/refactoring/introduceParameter/IntroduceParameterHandler.java b/java/java-impl/src/com/intellij/refactoring/introduceParameter/IntroduceParameterHandler.java index a96489adbbdb..692295ab092d 100644 --- a/java/java-impl/src/com/intellij/refactoring/introduceParameter/IntroduceParameterHandler.java +++ b/java/java-impl/src/com/intellij/refactoring/introduceParameter/IntroduceParameterHandler.java @@ -182,8 +182,15 @@ public class IntroduceParameterHandler extends IntroduceHandlerBase implements R private void chooseMethodToIntroduceParameter(final Editor editor, final List validEnclosingMethods, final Introducer introducer) { + final AbstractInplaceIntroducer inplaceIntroducer = AbstractInplaceIntroducer.getActiveIntroducer(editor); + if (inplaceIntroducer instanceof InplaceIntroduceParameterPopup) { + final InplaceIntroduceParameterPopup introduceParameterPopup = (InplaceIntroduceParameterPopup)inplaceIntroducer; + introducer.introduceParameter(introduceParameterPopup.getMethodToIntroduceParameter(), + introduceParameterPopup.getMethodToSearchFor()); + return; + } final JPanel panel = new JPanel(new BorderLayout()); - final JCheckBox superMethod = new JCheckBox("Use super method of", true); + final JCheckBox superMethod = new JCheckBox("Use super method", true); superMethod.setMnemonic('U'); panel.add(superMethod, BorderLayout.SOUTH); final JBList list = new JBList(validEnclosingMethods.toArray()); diff --git a/java/java-impl/src/com/intellij/refactoring/introduceParameter/OldReferenceResolver.java b/java/java-impl/src/com/intellij/refactoring/introduceParameter/OldReferenceResolver.java index c86e04e8eef8..70820656c8a0 100644 --- a/java/java-impl/src/com/intellij/refactoring/introduceParameter/OldReferenceResolver.java +++ b/java/java-impl/src/com/intellij/refactoring/introduceParameter/OldReferenceResolver.java @@ -150,13 +150,13 @@ public class OldReferenceResolver { } } - if (subj instanceof PsiField && PsiTreeUtil.isAncestor(clss, scope, false)) { + if (subj instanceof PsiField && PsiTreeUtil.isAncestor(scope, clss, false)) { // probably replacing field with a getter if (myReplaceFieldsWithGetters != IntroduceParameterRefactoring.REPLACE_FIELDS_WITH_GETTERS_NONE) { if (myReplaceFieldsWithGetters == IntroduceParameterRefactoring.REPLACE_FIELDS_WITH_GETTERS_ALL || myReplaceFieldsWithGetters == IntroduceParameterRefactoring.REPLACE_FIELDS_WITH_GETTERS_INACCESSIBLE && !JavaPsiFacade.getInstance(myProject).getResolveHelper().isAccessible((PsiMember)subj, newExpr, null)) { - newExpr = replaceFieldWithGetter(newExpr, (PsiField)subj); + newExpr = replaceFieldWithGetter(newExpr, (PsiField)subj, oldRef.getQualifierExpression() == null && !((PsiField)subj).hasModifierProperty(PsiModifier.STATIC)); } } } @@ -210,7 +210,7 @@ public class OldReferenceResolver { } } - private PsiElement replaceFieldWithGetter(PsiElement expr, PsiField psiField) throws IncorrectOperationException { + private PsiElement replaceFieldWithGetter(PsiElement expr, PsiField psiField, boolean qualify) throws IncorrectOperationException { if (RefactoringUtil.isAssignmentLHS(expr)) { // todo: warning return expr; @@ -228,9 +228,13 @@ public class OldReferenceResolver { String id = getter.getName(); String qualifier = null; if (newExpr instanceof PsiReferenceExpression) { - final PsiExpression qualifierExpression = ((PsiReferenceExpression)newExpr).getQualifierExpression(); - if (qualifierExpression != null) { - qualifier = qualifierExpression.getText(); + if (qualify) { + qualifier = getInstanceRef(factory).getText(); + } else { + final PsiExpression qualifierExpression = ((PsiReferenceExpression)newExpr).getQualifierExpression(); + if (qualifierExpression != null) { + qualifier = qualifierExpression.getText(); + } } } PsiMethodCallExpression getterCall = diff --git a/java/java-impl/src/com/intellij/refactoring/introduceparameterobject/IntroduceParameterObjectProcessor.java b/java/java-impl/src/com/intellij/refactoring/introduceparameterobject/IntroduceParameterObjectProcessor.java index ca4042a25a18..babbae72a9a7 100644 --- a/java/java-impl/src/com/intellij/refactoring/introduceparameterobject/IntroduceParameterObjectProcessor.java +++ b/java/java-impl/src/com/intellij/refactoring/introduceparameterobject/IntroduceParameterObjectProcessor.java @@ -164,7 +164,7 @@ public class IntroduceParameterObjectProcessor extends FixableUsagesRefactoringP if (myUseExistingClass && existingClass != null) { myExistingClassCompatibleConstructor = existingClassIsCompatible(existingClass, parameters); } - findUsagesForMethod(method, usages); + findUsagesForMethod(method, usages, true); if (myUseExistingClass && existingClass != null && !(paramsNeedingGetters.isEmpty() && paramsNeedingSetters.isEmpty())) { usages.add(new AppendAccessorsUsageInfo(existingClass, myGenerateAccessors, paramsNeedingGetters, paramsNeedingSetters, parameters)); @@ -172,7 +172,7 @@ public class IntroduceParameterObjectProcessor extends FixableUsagesRefactoringP final PsiMethod[] overridingMethods = OverridingMethodsSearch.search(method, method.getUseScope(), true).toArray(PsiMethod.EMPTY_ARRAY); for (PsiMethod siblingMethod : overridingMethods) { - findUsagesForMethod(siblingMethod, usages); + findUsagesForMethod(siblingMethod, usages, false); } if (myNewVisibility != null) { @@ -180,7 +180,7 @@ public class IntroduceParameterObjectProcessor extends FixableUsagesRefactoringP } } - private void findUsagesForMethod(PsiMethod overridingMethod, List usages) { + private void findUsagesForMethod(PsiMethod overridingMethod, List usages, boolean changeSignature) { final PsiCodeBlock body = overridingMethod.getBody(); final String baseParameterName = StringUtil.decapitalize(className); final String fixedParamName = @@ -188,7 +188,7 @@ public class IntroduceParameterObjectProcessor extends FixableUsagesRefactoringP ? JavaCodeStyleManager.getInstance(myProject).suggestUniqueVariableName(baseParameterName, body.getLBrace(), true) : JavaCodeStyleManager.getInstance(myProject).propertyNameToVariableName(baseParameterName, VariableKind.PARAMETER); - usages.add(new MergeMethodArguments(overridingMethod, className, packageName, fixedParamName, paramsToMerge, typeParams, keepMethodAsDelegate, myCreateInnerClass ? method.getContainingClass() : null)); + usages.add(new MergeMethodArguments(overridingMethod, className, packageName, fixedParamName, paramsToMerge, typeParams, keepMethodAsDelegate, myCreateInnerClass ? method.getContainingClass() : null, changeSignature)); final ParamUsageVisitor visitor = new ParamUsageVisitor(overridingMethod, paramsToMerge); overridingMethod.accept(visitor); @@ -279,7 +279,7 @@ public class IntroduceParameterObjectProcessor extends FixableUsagesRefactoringP if (directory != null) { - final CodeStyleManager codeStyleManager = method.getManager().getCodeStyleManager(); + final CodeStyleManager codeStyleManager = CodeStyleManager.getInstance(method.getManager().getProject()); final PsiElement shortenedFile = JavaCodeStyleManager.getInstance(newFile.getProject()).shortenClassReferences(newFile); final PsiElement reformattedFile = codeStyleManager.reformat(shortenedFile); return ((PsiJavaFile)directory.add(reformattedFile)).getClasses()[0]; diff --git a/java/java-impl/src/com/intellij/refactoring/introduceparameterobject/usageInfo/MergeMethodArguments.java b/java/java-impl/src/com/intellij/refactoring/introduceparameterobject/usageInfo/MergeMethodArguments.java index 87fcf8bb7207..992bff67c21e 100644 --- a/java/java-impl/src/com/intellij/refactoring/introduceparameterobject/usageInfo/MergeMethodArguments.java +++ b/java/java-impl/src/com/intellij/refactoring/introduceparameterobject/usageInfo/MergeMethodArguments.java @@ -22,6 +22,8 @@ import com.intellij.psi.*; import com.intellij.psi.codeStyle.JavaCodeStyleManager; import com.intellij.psi.impl.source.PsiImmediateClassType; import com.intellij.psi.search.GlobalSearchScope; +import com.intellij.psi.search.searches.ReferencesSearch; +import com.intellij.psi.util.PsiTreeUtil; import com.intellij.psi.util.TypeConversionUtil; import com.intellij.refactoring.changeSignature.ChangeSignatureProcessor; import com.intellij.refactoring.changeSignature.ParameterInfoImpl; @@ -36,6 +38,7 @@ import java.util.*; public class MergeMethodArguments extends FixableUsageInfo { private final PsiMethod method; private final PsiClass myContainingClass; + private final boolean myChangeSignature; private final boolean myKeepMethodAsDelegate; private final List typeParams; private final String className; @@ -50,7 +53,7 @@ public class MergeMethodArguments extends FixableUsageInfo { String parameterName, int[] paramsToMerge, List typeParams, - final boolean keepMethodAsDelegate, final PsiClass containingClass) { + final boolean keepMethodAsDelegate, final PsiClass containingClass, boolean changeSignature) { super(method); this.paramsToMerge = paramsToMerge; this.packageName = packageName; @@ -58,7 +61,8 @@ public class MergeMethodArguments extends FixableUsageInfo { this.parameterName = parameterName; this.method = method; myContainingClass = containingClass; - lastParamIsVararg = method.isVarArgs(); + myChangeSignature = changeSignature; + lastParamIsVararg = method.isVarArgs() && isParameterToMerge(method.getParameterList().getParametersCount() - 1); myKeepMethodAsDelegate = keepMethodAsDelegate; this.typeParams = new ArrayList(typeParams); } @@ -111,12 +115,14 @@ public class MergeMethodArguments extends FixableUsageInfo { public void run() { final PsiMethod psiMethod = meth.getElement(); if (psiMethod == null) return; - final ChangeSignatureProcessor changeSignatureProcessor = - new ChangeSignatureProcessor(psiMethod.getProject(), psiMethod, - myKeepMethodAsDelegate, null, psiMethod.getName(), - psiMethod.getReturnType(), - parametersInfo.toArray(new ParameterInfoImpl[parametersInfo.size()])); - changeSignatureProcessor.run(); + if (myChangeSignature) { + final ChangeSignatureProcessor changeSignatureProcessor = + new ChangeSignatureProcessor(psiMethod.getProject(), psiMethod, + myKeepMethodAsDelegate, null, psiMethod.getName(), + psiMethod.getReturnType(), + parametersInfo.toArray(new ParameterInfoImpl[parametersInfo.size()])); + changeSignatureProcessor.run(); + } } }; if (ApplicationManager.getApplication().isUnitTestMode()) { diff --git a/java/java-impl/src/com/intellij/refactoring/makeStatic/MakeClassStaticProcessor.java b/java/java-impl/src/com/intellij/refactoring/makeStatic/MakeClassStaticProcessor.java index 80c7417cf289..e3f325f68811 100644 --- a/java/java-impl/src/com/intellij/refactoring/makeStatic/MakeClassStaticProcessor.java +++ b/java/java-impl/src/com/intellij/refactoring/makeStatic/MakeClassStaticProcessor.java @@ -144,7 +144,7 @@ public class MakeClassStaticProcessor extends MakeMethodOrClassStaticProcessor

victims) { - final PsiSearchHelper helper = myManager.getSearchHelper(); + final PsiSearchHelper helper = PsiSearchHelper.SERVICE.getInstance(myManager.getProject()); ReductionSystem system = new ReductionSystem(myProject, victims, myTypes, myTypeVariableFactory, mySettings); diff --git a/java/java-impl/src/com/intellij/refactoring/typeMigration/ui/TypeMigrationDialog.java b/java/java-impl/src/com/intellij/refactoring/typeMigration/ui/TypeMigrationDialog.java index 8ffdffd2c6a8..edbb70b0756c 100644 --- a/java/java-impl/src/com/intellij/refactoring/typeMigration/ui/TypeMigrationDialog.java +++ b/java/java-impl/src/com/intellij/refactoring/typeMigration/ui/TypeMigrationDialog.java @@ -31,7 +31,7 @@ import com.intellij.openapi.util.Comparing; import com.intellij.openapi.util.Disposer; import com.intellij.pom.java.LanguageLevel; import com.intellij.psi.*; -import com.intellij.psi.search.GlobalSearchScope; +import com.intellij.psi.search.GlobalSearchScopes; import com.intellij.psi.search.searches.ReferencesSearch; import com.intellij.psi.util.PsiTreeUtil; import com.intellij.psi.util.PsiUtil; @@ -145,7 +145,7 @@ public class TypeMigrationDialog extends RefactoringDialog { if (VisibilityUtil.compare(VisibilityUtil.getVisibilityModifier(modifierList), PsiModifier.PRIVATE) < 0) return null; } - for (PsiReference reference : ReferencesSearch.search(root, GlobalSearchScope.fileScope(root.getContainingFile()))) { + for (PsiReference reference : ReferencesSearch.search(root, GlobalSearchScopes.fileScope(root.getContainingFile()))) { final PsiElement element = reference.getElement(); final PsiExpression expr = PsiTreeUtil.getParentOfType(element, PsiExpression.class, false); if (expr != null) { diff --git a/java/java-impl/src/com/intellij/refactoring/util/FieldConflictsResolver.java b/java/java-impl/src/com/intellij/refactoring/util/FieldConflictsResolver.java index a59d8c509f29..488cac425ff2 100644 --- a/java/java-impl/src/com/intellij/refactoring/util/FieldConflictsResolver.java +++ b/java/java-impl/src/com/intellij/refactoring/util/FieldConflictsResolver.java @@ -142,7 +142,7 @@ public class FieldConflictsResolver { expressionFromText = (PsiReferenceExpression)factory.createExpressionFromText("A." + member.getName(), null); expressionFromText.setQualifierExpression(factory.createReferenceExpression(qualifyingClass)); } - CodeStyleManager codeStyleManager = manager.getCodeStyleManager(); + CodeStyleManager codeStyleManager = CodeStyleManager.getInstance(manager.getProject()); expressionFromText = (PsiReferenceExpression)codeStyleManager.reformat(expressionFromText); return (PsiReferenceExpression)referenceExpression.replace(expressionFromText); } diff --git a/java/java-impl/src/com/intellij/refactoring/util/duplicates/ConditionalReturnStatementValue.java b/java/java-impl/src/com/intellij/refactoring/util/duplicates/ConditionalReturnStatementValue.java index d52dffdd2bff..3878619c6db9 100644 --- a/java/java-impl/src/com/intellij/refactoring/util/duplicates/ConditionalReturnStatementValue.java +++ b/java/java-impl/src/com/intellij/refactoring/util/duplicates/ConditionalReturnStatementValue.java @@ -17,6 +17,7 @@ package com.intellij.refactoring.util.duplicates; import com.intellij.codeInsight.PsiEquivalenceUtil; import com.intellij.psi.*; +import com.intellij.psi.codeStyle.CodeStyleManager; import com.intellij.util.IncorrectOperationException; /** @@ -54,6 +55,6 @@ public class ConditionalReturnStatementValue implements ReturnValue { final PsiExpression condition = statement.getCondition(); assert condition != null; condition.replace(methodCallExpression); - return (PsiStatement)statement.getManager().getCodeStyleManager().reformat(statement); + return (PsiStatement)CodeStyleManager.getInstance(statement.getManager().getProject()).reformat(statement); } } diff --git a/java/java-impl/src/com/intellij/refactoring/util/duplicates/GotoReturnValue.java b/java/java-impl/src/com/intellij/refactoring/util/duplicates/GotoReturnValue.java index f028c73863ac..7727411e3f1d 100644 --- a/java/java-impl/src/com/intellij/refactoring/util/duplicates/GotoReturnValue.java +++ b/java/java-impl/src/com/intellij/refactoring/util/duplicates/GotoReturnValue.java @@ -21,6 +21,7 @@ package com.intellij.refactoring.util.duplicates; import com.intellij.psi.*; +import com.intellij.psi.codeStyle.CodeStyleManager; import com.intellij.psi.util.TypeConversionUtil; import com.intellij.util.IncorrectOperationException; import org.jetbrains.annotations.NonNls; @@ -36,7 +37,7 @@ public abstract class GotoReturnValue implements ReturnValue { final PsiExpression condition = statement.getCondition(); assert condition != null; condition.replace(methodCallExpression); - return (PsiStatement)statement.getManager().getCodeStyleManager().reformat(statement); + return (PsiStatement)CodeStyleManager.getInstance(statement.getManager().getProject()).reformat(statement); } @NonNls diff --git a/java/java-impl/src/com/intellij/refactoring/wrapreturnvalue/WrapReturnValueProcessor.java b/java/java-impl/src/com/intellij/refactoring/wrapreturnvalue/WrapReturnValueProcessor.java index 98c39e504645..8df928b61013 100644 --- a/java/java-impl/src/com/intellij/refactoring/wrapreturnvalue/WrapReturnValueProcessor.java +++ b/java/java-impl/src/com/intellij/refactoring/wrapreturnvalue/WrapReturnValueProcessor.java @@ -259,7 +259,7 @@ public class WrapReturnValueProcessor extends FixableUsagesRefactoringProcessor try { final PsiJavaFile psiFile = (PsiJavaFile)PsiFileFactory.getInstance(project).createFileFromText(className + ".java", classString); - final CodeStyleManager codeStyleManager = manager.getCodeStyleManager(); + final CodeStyleManager codeStyleManager = CodeStyleManager.getInstance(manager.getProject()); if (myCreateInnerClass) { final PsiClass containingClass = method.getContainingClass(); final PsiElement innerClass = containingClass.add(psiFile.getClasses()[0]); diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/changeMethodSignatureFromUsage/after1.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/changeMethodSignatureFromUsage/after1.java index e0f952b64ec0..7360e006df98 100644 --- a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/changeMethodSignatureFromUsage/after1.java +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/changeMethodSignatureFromUsage/after1.java @@ -1,4 +1,4 @@ -// "Remove 1 parameter from method f" "true" +// "Remove 1st parameter from method 'f'" "true" class A { void f() {} public void foo() { diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/changeMethodSignatureFromUsage/after10.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/changeMethodSignatureFromUsage/after10.java index 63a621850328..108be299a769 100644 --- a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/changeMethodSignatureFromUsage/after10.java +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/changeMethodSignatureFromUsage/after10.java @@ -1,4 +1,4 @@ -// "Add String as 2 parameter to method set" "true" +// "Add 'String' as 2nd parameter to method 'set'" "true" import java.util.List; public class X { diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/changeMethodSignatureFromUsage/after3.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/changeMethodSignatureFromUsage/after3.java index b9b2da617f5c..bd42e46883e3 100644 --- a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/changeMethodSignatureFromUsage/after3.java +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/changeMethodSignatureFromUsage/after3.java @@ -1,4 +1,4 @@ -// "Add char as 2 parameter to method f" "true" +// "Add 'char' as 2nd parameter to method 'f'" "true" class A { void f(int i, char c, String s) {} public void foo() { diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/changeMethodSignatureFromUsage/after5.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/changeMethodSignatureFromUsage/after5.java index 41e0fdb48fd9..5acfab54d0b8 100644 --- a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/changeMethodSignatureFromUsage/after5.java +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/changeMethodSignatureFromUsage/after5.java @@ -1,4 +1,4 @@ -// "Remove 2 parameter from method f" "true" +// "Remove 2nd parameter from method 'f'" "true" class A { void f(int i, int i2) {} public void foo() { diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/changeMethodSignatureFromUsage/after6.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/changeMethodSignatureFromUsage/after6.java index 6d80ad364866..2fb3e8123f88 100644 --- a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/changeMethodSignatureFromUsage/after6.java +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/changeMethodSignatureFromUsage/after6.java @@ -1,4 +1,4 @@ -// "Change 2 parameter of method f from String to int" "true" +// "Change 2nd parameter of method 'f' from 'String' to 'int'" "true" class A { void f(int i, int s, int i2) {} public void foo() { diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/changeMethodSignatureFromUsage/after9.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/changeMethodSignatureFromUsage/after9.java index ac46bd572573..67b0c44e7856 100644 --- a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/changeMethodSignatureFromUsage/after9.java +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/changeMethodSignatureFromUsage/after9.java @@ -1,4 +1,4 @@ -// "Add int as 2 parameter to method f" "true" +// "Add 'int' as 2nd parameter to method 'f'" "true" public class S { void f(int k, int i, int... args) { f(1,1,null);// -> f(1,1,null) diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/changeMethodSignatureFromUsage/afterEraseTypeIfSubstitutionNotFound.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/changeMethodSignatureFromUsage/afterEraseTypeIfSubstitutionNotFound.java index 81fec921cc21..20f02d1ef2b1 100644 --- a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/changeMethodSignatureFromUsage/afterEraseTypeIfSubstitutionNotFound.java +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/changeMethodSignatureFromUsage/afterEraseTypeIfSubstitutionNotFound.java @@ -1,4 +1,4 @@ -// "Add Foo as 1 parameter to method Bar" "true" +// "Add 'Foo' as 1st parameter to method 'Bar'" "true" public class Bar { Bar(Foo typeParamNameFoo, String args) { diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/changeMethodSignatureFromUsage/afterEraseTypeIfSubstitutionNotFoundNotAConstructor.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/changeMethodSignatureFromUsage/afterEraseTypeIfSubstitutionNotFoundNotAConstructor.java index 59448b0ef9d9..98fd75fe9927 100644 --- a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/changeMethodSignatureFromUsage/afterEraseTypeIfSubstitutionNotFoundNotAConstructor.java +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/changeMethodSignatureFromUsage/afterEraseTypeIfSubstitutionNotFoundNotAConstructor.java @@ -1,4 +1,4 @@ -// "Add Foo as 1 parameter to method bar" "true" +// "Add 'Foo' as 1st parameter to method 'bar'" "true" public class Bar { static void bar(Foo typeParamNameFoo, String args) { diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/changeMethodSignatureFromUsage/afterNewParamName.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/changeMethodSignatureFromUsage/afterNewParamName.java index 227aaf2512b5..c3397418e3e3 100644 --- a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/changeMethodSignatureFromUsage/afterNewParamName.java +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/changeMethodSignatureFromUsage/afterNewParamName.java @@ -1,4 +1,4 @@ -// "Add int as 1 parameter to method f" "true" +// "Add 'int' as 1st parameter to method 'f'" "true" public class S { void f(int i, String args) { diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/changeMethodSignatureFromUsage/afterQualifiedTypes.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/changeMethodSignatureFromUsage/afterQualifiedTypes.java index 292baec43a73..80a544095fb5 100644 --- a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/changeMethodSignatureFromUsage/afterQualifiedTypes.java +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/changeMethodSignatureFromUsage/afterQualifiedTypes.java @@ -1,4 +1,4 @@ -// "Add Inner1 as 1 parameter to method Inner2" "true" +// "Add 'Inner1' as 1st parameter to method 'Inner2'" "true" class CoolTest { class Inner1 {} diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/changeMethodSignatureFromUsage/afterVarargs1.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/changeMethodSignatureFromUsage/afterVarargs1.java index f735bdd63db8..dcd3ce636a3a 100644 --- a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/changeMethodSignatureFromUsage/afterVarargs1.java +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/changeMethodSignatureFromUsage/afterVarargs1.java @@ -1,4 +1,4 @@ -// "Add String as 1 parameter to method f" "true" +// "Add 'String' as 1st parameter to method 'f'" "true" public class S { void f(String s, int... args) { f("",1,1); diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/changeMethodSignatureFromUsage/afterVarargs2.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/changeMethodSignatureFromUsage/afterVarargs2.java index d76e42fbb52b..55ab07ef2008 100644 --- a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/changeMethodSignatureFromUsage/afterVarargs2.java +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/changeMethodSignatureFromUsage/afterVarargs2.java @@ -1,4 +1,4 @@ -// "Add String as 1 parameter to method f" "true" +// "Add 'String' as 1st parameter to method 'f'" "true" public class S { void f(String s, int... args) { f("",null); diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/changeMethodSignatureFromUsage/before1.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/changeMethodSignatureFromUsage/before1.java index 184d20bfcfe5..3df2f76bf1e7 100644 --- a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/changeMethodSignatureFromUsage/before1.java +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/changeMethodSignatureFromUsage/before1.java @@ -1,4 +1,4 @@ -// "Remove 1 parameter from method f" "true" +// "Remove 1st parameter from method 'f'" "true" class A { void f(int i) {} public void foo() { diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/changeMethodSignatureFromUsage/before10.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/changeMethodSignatureFromUsage/before10.java index 2026129a4e98..5d966d846a0a 100644 --- a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/changeMethodSignatureFromUsage/before10.java +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/changeMethodSignatureFromUsage/before10.java @@ -1,4 +1,4 @@ -// "Add String as 2 parameter to method set" "true" +// "Add 'String' as 2nd parameter to method 'set'" "true" import java.util.List; public class X { diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/changeMethodSignatureFromUsage/before3.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/changeMethodSignatureFromUsage/before3.java index b75ee1a0e287..4e10744529a1 100644 --- a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/changeMethodSignatureFromUsage/before3.java +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/changeMethodSignatureFromUsage/before3.java @@ -1,4 +1,4 @@ -// "Add char as 2 parameter to method f" "true" +// "Add 'char' as 2nd parameter to method 'f'" "true" class A { void f(int i,String s) {} public void foo() { diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/changeMethodSignatureFromUsage/before5.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/changeMethodSignatureFromUsage/before5.java index 89e8dadd5c16..17e6682fcad9 100644 --- a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/changeMethodSignatureFromUsage/before5.java +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/changeMethodSignatureFromUsage/before5.java @@ -1,4 +1,4 @@ -// "Remove 2 parameter from method f" "true" +// "Remove 2nd parameter from method 'f'" "true" class A { void f(int i, String s, int i2) {} public void foo() { diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/changeMethodSignatureFromUsage/before6.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/changeMethodSignatureFromUsage/before6.java index da0e6178e093..628a6eccb800 100644 --- a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/changeMethodSignatureFromUsage/before6.java +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/changeMethodSignatureFromUsage/before6.java @@ -1,4 +1,4 @@ -// "Change 2 parameter of method f from String to int" "true" +// "Change 2nd parameter of method 'f' from 'String' to 'int'" "true" class A { void f(int i, String s, int i2) {} public void foo() { diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/changeMethodSignatureFromUsage/before9.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/changeMethodSignatureFromUsage/before9.java index 7dea4a36c6c8..d212efbcc9ef 100644 --- a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/changeMethodSignatureFromUsage/before9.java +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/changeMethodSignatureFromUsage/before9.java @@ -1,4 +1,4 @@ -// "Add int as 2 parameter to method f" "true" +// "Add 'int' as 2nd parameter to method 'f'" "true" public class S { void f(int k, int... args) { f(1,1,null);// -> f(1,1,null) diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/changeMethodSignatureFromUsage/beforeEraseTypeIfSubstitutionNotFound.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/changeMethodSignatureFromUsage/beforeEraseTypeIfSubstitutionNotFound.java index 54cfb7c19e12..6194d001d6ca 100644 --- a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/changeMethodSignatureFromUsage/beforeEraseTypeIfSubstitutionNotFound.java +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/changeMethodSignatureFromUsage/beforeEraseTypeIfSubstitutionNotFound.java @@ -1,4 +1,4 @@ -// "Add Foo as 1 parameter to method Bar" "true" +// "Add 'Foo' as 1st parameter to method 'Bar'" "true" public class Bar { Bar(String args) { diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/changeMethodSignatureFromUsage/beforeEraseTypeIfSubstitutionNotFoundNotAConstructor.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/changeMethodSignatureFromUsage/beforeEraseTypeIfSubstitutionNotFoundNotAConstructor.java index 3142f0b403a7..99623c4fdf08 100644 --- a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/changeMethodSignatureFromUsage/beforeEraseTypeIfSubstitutionNotFoundNotAConstructor.java +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/changeMethodSignatureFromUsage/beforeEraseTypeIfSubstitutionNotFoundNotAConstructor.java @@ -1,4 +1,4 @@ -// "Add Foo as 1 parameter to method bar" "true" +// "Add 'Foo' as 1st parameter to method 'bar'" "true" public class Bar { static void bar(String args) { diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/changeMethodSignatureFromUsage/beforeExistSignature.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/changeMethodSignatureFromUsage/beforeExistSignature.java index 7c26677ccf83..fe9dc930ee36 100644 --- a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/changeMethodSignatureFromUsage/beforeExistSignature.java +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/changeMethodSignatureFromUsage/beforeExistSignature.java @@ -1,4 +1,4 @@ -// "Add int as 1 parameter to method f" "false" +// "Add 'int' as 1st parameter to method 'f'" "false" public class Foo { void foo(Bar f) { f.f(2); diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/changeMethodSignatureFromUsage/beforeNewParamName.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/changeMethodSignatureFromUsage/beforeNewParamName.java index 37513c8d8e4a..5419bc85ef24 100644 --- a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/changeMethodSignatureFromUsage/beforeNewParamName.java +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/changeMethodSignatureFromUsage/beforeNewParamName.java @@ -1,4 +1,4 @@ -// "Add int as 1 parameter to method f" "true" +// "Add 'int' as 1st parameter to method 'f'" "true" public class S { void f(String args) { diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/changeMethodSignatureFromUsage/beforeNotAvailable.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/changeMethodSignatureFromUsage/beforeNotAvailable.java index 95bb03e7dbce..231855754787 100644 --- a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/changeMethodSignatureFromUsage/beforeNotAvailable.java +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/changeMethodSignatureFromUsage/beforeNotAvailable.java @@ -1,4 +1,4 @@ -// "Change 1 parameter of method parseInt from String to int" "false" +// "Change 1st parameter of method 'parseInt' from 'String' to 'int'" "false" class A { public void foo() { Integer.parseInt(1); diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/changeMethodSignatureFromUsage/beforeQualifiedTypes.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/changeMethodSignatureFromUsage/beforeQualifiedTypes.java index 124acc2a73d2..e64cd9737f1b 100644 --- a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/changeMethodSignatureFromUsage/beforeQualifiedTypes.java +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/changeMethodSignatureFromUsage/beforeQualifiedTypes.java @@ -1,4 +1,4 @@ -// "Add Inner1 as 1 parameter to method Inner2" "true" +// "Add 'Inner1' as 1st parameter to method 'Inner2'" "true" class CoolTest { class Inner1 {} diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/changeMethodSignatureFromUsage/beforeVarargs1.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/changeMethodSignatureFromUsage/beforeVarargs1.java index 4fce1077da3d..4ea15adc5d87 100644 --- a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/changeMethodSignatureFromUsage/beforeVarargs1.java +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/changeMethodSignatureFromUsage/beforeVarargs1.java @@ -1,4 +1,4 @@ -// "Add String as 1 parameter to method f" "true" +// "Add 'String' as 1st parameter to method 'f'" "true" public class S { void f(int... args) { f("",1,1); diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/changeMethodSignatureFromUsage/beforeVarargs2.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/changeMethodSignatureFromUsage/beforeVarargs2.java index e8f8013ac809..23362d91fdec 100644 --- a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/changeMethodSignatureFromUsage/beforeVarargs2.java +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/changeMethodSignatureFromUsage/beforeVarargs2.java @@ -1,4 +1,4 @@ -// "Add String as 1 parameter to method f" "true" +// "Add 'String' as 1st parameter to method 'f'" "true" public class S { void f(int... args) { f("",null); diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/changeMethodSignatureFromUsage/beforeVarargs2Array.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/changeMethodSignatureFromUsage/beforeVarargs2Array.java index ec86800c409f..af463ee4e1b5 100644 --- a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/changeMethodSignatureFromUsage/beforeVarargs2Array.java +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/changeMethodSignatureFromUsage/beforeVarargs2Array.java @@ -1,4 +1,4 @@ -// "Add String as 2nd parameter to method f" "false" +// "Add 'String' as 2nd parameter to method 'f'" "false" public class S { void f(int... args) { f(1,1, ""); diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/createFieldFromUsage/afterInsideStaticInnerClass.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/createFieldFromUsage/afterInsideStaticInnerClass.java new file mode 100644 index 000000000000..1477ec14a8d6 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/createFieldFromUsage/afterInsideStaticInnerClass.java @@ -0,0 +1,14 @@ +// "Create Field 'field'" "true" +class A { + String field; + + static class Foo { + private Object field; + + Foo() { + field; + } + } + +} + diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/createFieldFromUsage/beforeInsideStaticInnerClass.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/createFieldFromUsage/beforeInsideStaticInnerClass.java new file mode 100644 index 000000000000..607a2a3e36af --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/createFieldFromUsage/beforeInsideStaticInnerClass.java @@ -0,0 +1,12 @@ +// "Create Field 'field'" "true" +class A { + String field; + + static class Foo { + Foo() { + field; + } + } + +} + diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/expandStaticImport/afterMultipleViaOnDemand.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/expandStaticImport/afterMultipleViaOnDemand.java new file mode 100644 index 000000000000..12a62b4d3c14 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/expandStaticImport/afterMultipleViaOnDemand.java @@ -0,0 +1,9 @@ +// "Expand static import to Arrays.sort" "true" +import java.util.Arrays; + +class Test { + public void sendMessage(String... destinationAddressNames) { + Arrays.sort(destinationAddressNames); + Arrays.asList(destinationAddressNames) + } +} \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/expandStaticImport/afterSingle.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/expandStaticImport/afterSingle.java new file mode 100644 index 000000000000..729b346e3f03 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/expandStaticImport/afterSingle.java @@ -0,0 +1,8 @@ +// "Expand static import to Arrays.sort" "true" +import java.util.Arrays; + +class Test { + public void sendMessage(String... destinationAddressNames) { + Arrays.sort(destinationAddressNames); + } +} \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/expandStaticImport/afterSingleViaOnDemand.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/expandStaticImport/afterSingleViaOnDemand.java new file mode 100644 index 000000000000..729b346e3f03 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/expandStaticImport/afterSingleViaOnDemand.java @@ -0,0 +1,8 @@ +// "Expand static import to Arrays.sort" "true" +import java.util.Arrays; + +class Test { + public void sendMessage(String... destinationAddressNames) { + Arrays.sort(destinationAddressNames); + } +} \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/expandStaticImport/beforeMultipleViaOnDemand.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/expandStaticImport/beforeMultipleViaOnDemand.java new file mode 100644 index 000000000000..6d186681e72e --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/expandStaticImport/beforeMultipleViaOnDemand.java @@ -0,0 +1,9 @@ +// "Expand static import to Arrays.sort" "true" +import static java.util.Arrays.*; + +class Test { + public void sendMessage(String... destinationAddressNames) { + sort(destinationAddressNames); + asList(destinationAddressNames) + } +} \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/expandStaticImport/beforeSingle.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/expandStaticImport/beforeSingle.java new file mode 100644 index 000000000000..22e342362b4c --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/expandStaticImport/beforeSingle.java @@ -0,0 +1,8 @@ +// "Expand static import to Arrays.sort" "true" +import static java.util.Arrays.sort; + +class Test { + public void sendMessage(String... destinationAddressNames) { + sort(destinationAddressNames); + } +} \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/expandStaticImport/beforeSingleViaOnDemand.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/expandStaticImport/beforeSingleViaOnDemand.java new file mode 100644 index 000000000000..fc52442d2f92 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/expandStaticImport/beforeSingleViaOnDemand.java @@ -0,0 +1,8 @@ +// "Expand static import to Arrays.sort" "true" +import static java.util.Arrays.*; + +class Test { + public void sendMessage(String... destinationAddressNames) { + sort(destinationAddressNames); + } +} \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/generation/surroundWith/java/CommentAsFirstRunnableSurroundStatement.java b/java/java-tests/testData/codeInsight/generation/surroundWith/java/CommentAsFirstRunnableSurroundStatement.java index cddd0140e554..820d27d6923e 100644 --- a/java/java-tests/testData/codeInsight/generation/surroundWith/java/CommentAsFirstRunnableSurroundStatement.java +++ b/java/java-tests/testData/codeInsight/generation/surroundWith/java/CommentAsFirstRunnableSurroundStatement.java @@ -1,6 +1,6 @@ class Test { void foo() { - // This is comment" + // This is comment" int i = 1; } } \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/generation/surroundWith/java/CommentAsFirstRunnableSurroundStatement_after.java b/java/java-tests/testData/codeInsight/generation/surroundWith/java/CommentAsFirstRunnableSurroundStatement_after.java index 1762cd0c715f..30ae98a335fc 100644 --- a/java/java-tests/testData/codeInsight/generation/surroundWith/java/CommentAsFirstRunnableSurroundStatement_after.java +++ b/java/java-tests/testData/codeInsight/generation/surroundWith/java/CommentAsFirstRunnableSurroundStatement_after.java @@ -1,6 +1,6 @@ class Test { void foo() { - Runnable runnable = new Runnable() { + Runnable runnable = new Runnable() { public void run() { // This is comment" int i = 1; diff --git a/java/java-tests/testData/inspection/fieldCanBeLocal/fieldUsedInConstantInitialization/expected.xml b/java/java-tests/testData/inspection/fieldCanBeLocal/fieldUsedInConstantInitialization/expected.xml new file mode 100644 index 000000000000..580a889dbfd6 --- /dev/null +++ b/java/java-tests/testData/inspection/fieldCanBeLocal/fieldUsedInConstantInitialization/expected.xml @@ -0,0 +1,3 @@ + + + diff --git a/java/java-tests/testData/inspection/fieldCanBeLocal/fieldUsedInConstantInitialization/src/Test.java b/java/java-tests/testData/inspection/fieldCanBeLocal/fieldUsedInConstantInitialization/src/Test.java new file mode 100644 index 000000000000..6adc318926ac --- /dev/null +++ b/java/java-tests/testData/inspection/fieldCanBeLocal/fieldUsedInConstantInitialization/src/Test.java @@ -0,0 +1,9 @@ +class Test { + public static final Object FOO = new Test().foo; + + private final String foo; + + private Test() { + foo = "some text"; + } +} diff --git a/java/java-tests/testData/refactoring/introduceParameter/afterGetterQualifier.java b/java/java-tests/testData/refactoring/introduceParameter/afterGetterQualifier.java new file mode 100644 index 000000000000..a0ce8c1f4a0b --- /dev/null +++ b/java/java-tests/testData/refactoring/introduceParameter/afterGetterQualifier.java @@ -0,0 +1,23 @@ +public class Test { + private String myStr; + + public String getMyStr() { + return myStr; + } + + void foo(String anObject) { + new Runnable(){ + @Override + public void run() { + System.out.println(anObject); + } + }; + } +} + +class X { + public void n() { + final Test test = new Test(); + test.foo(test.getMyStr()); + } +} \ No newline at end of file diff --git a/java/java-tests/testData/refactoring/introduceParameter/beforeGetterQualifier.java b/java/java-tests/testData/refactoring/introduceParameter/beforeGetterQualifier.java new file mode 100644 index 000000000000..ac937dc29041 --- /dev/null +++ b/java/java-tests/testData/refactoring/introduceParameter/beforeGetterQualifier.java @@ -0,0 +1,22 @@ +public class Test { + private String myStr; + + public String getMyStr() { + return myStr; + } + + void foo() { + new Runnable(){ + @Override + public void run() { + System.out.println(myStr); + } + }; + } +} + +class X { + public void n() { + new Test().foo(); + } +} \ No newline at end of file diff --git a/java/java-tests/testData/refactoring/introduceParameterObject/sameTypeAndVarargs/after/Param.java b/java/java-tests/testData/refactoring/introduceParameterObject/sameTypeAndVarargs/after/Param.java new file mode 100644 index 000000000000..894b76127061 --- /dev/null +++ b/java/java-tests/testData/refactoring/introduceParameterObject/sameTypeAndVarargs/after/Param.java @@ -0,0 +1,17 @@ +public class Param { + private final String a; + private final String b; + + public Param(String a, String b) { + this.a = a; + this.b = b; + } + + public String getA() { + return a; + } + + public String getB() { + return b; + } +} diff --git a/java/java-tests/testData/refactoring/introduceParameterObject/sameTypeAndVarargs/after/Test.java b/java/java-tests/testData/refactoring/introduceParameterObject/sameTypeAndVarargs/after/Test.java new file mode 100644 index 000000000000..db7dbdac5a3a --- /dev/null +++ b/java/java-tests/testData/refactoring/introduceParameterObject/sameTypeAndVarargs/after/Test.java @@ -0,0 +1,30 @@ +/* +* Copyright 2000-2011 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. +*/ +interface Test { + void foo(Param param, String... v); +} + +class TestImpl implements Test { + @Override + public void foo(Param param, String... v) { + } + + void bar(){ + foo(new Param("a", "b"), "c"); + foo(new Param("a", "b")); + foo(new Param("a", "b"), "c", "d"); + } +} \ No newline at end of file diff --git a/java/java-tests/testData/refactoring/introduceParameterObject/sameTypeAndVarargs/before/Test.java b/java/java-tests/testData/refactoring/introduceParameterObject/sameTypeAndVarargs/before/Test.java new file mode 100644 index 000000000000..24bebbf315bf --- /dev/null +++ b/java/java-tests/testData/refactoring/introduceParameterObject/sameTypeAndVarargs/before/Test.java @@ -0,0 +1,30 @@ +/* +* Copyright 2000-2011 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. +*/ +interface Test { + void foo(String a, String b, String... v); +} + +class TestImpl implements Test { + @Override + public void foo(String a, String b, String... v) { + } + + void bar(){ + foo("a", "b", "c"); + foo("a", "b"); + foo("a", "b", "c", "d"); + } +} \ No newline at end of file diff --git a/java/java-tests/testData/refactoring/moveInstanceMethod/ThisInAnonymous.java b/java/java-tests/testData/refactoring/moveInstanceMethod/ThisInAnonymous.java new file mode 100644 index 000000000000..875475dc3657 --- /dev/null +++ b/java/java-tests/testData/refactoring/moveInstanceMethod/ThisInAnonymous.java @@ -0,0 +1,16 @@ +public class Test { + private void prepareAnonymousClasses(JetElement aClass) { + aClass.acceptChildren(new JetVisitor() { + public void visitJetElement(JetElement element) { + element.acceptChildren(this); + } + }); + } +} + + +class JetElement { + void acceptChildren(JetVisitor v) {} +} + +class JetVisitor {} \ No newline at end of file diff --git a/java/java-tests/testData/refactoring/moveInstanceMethod/ThisInAnonymous.java.after b/java/java-tests/testData/refactoring/moveInstanceMethod/ThisInAnonymous.java.after new file mode 100644 index 000000000000..918098f6df17 --- /dev/null +++ b/java/java-tests/testData/refactoring/moveInstanceMethod/ThisInAnonymous.java.after @@ -0,0 +1,17 @@ +public class Test { +} + + +class JetElement { + void acceptChildren(JetVisitor v) {} + + private void prepareAnonymousClasses() { + acceptChildren(new JetVisitor() { + public void visitJetElement(JetElement element) { + element.acceptChildren(this); + } + }); + } +} + +class JetVisitor {} \ No newline at end of file diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/quickFix/CreateFieldFromUsageTest.java b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/quickFix/CreateFieldFromUsageTest.java index 723a940f256e..a6531805e1df 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/quickFix/CreateFieldFromUsageTest.java +++ b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/quickFix/CreateFieldFromUsageTest.java @@ -18,6 +18,7 @@ public class CreateFieldFromUsageTest extends LightQuickFixTestCase{ public void testParametericMethod() throws Exception { doSingleTest(); } public void testQualifyInner() throws Exception { doSingleTest(); } public void testTypeArgsFormatted() throws Exception { doSingleTest(); } + public void testInsideStaticInnerClass() throws Exception { doSingleTest(); } public void testSortByRelevance() throws Exception { new WriteCommandAction(getProject()) { diff --git a/platform/core-api/src/com/intellij/openapi/vfs/ModificationAttemptEvent.java b/java/java-tests/testSrc/com/intellij/codeInsight/intention/ExpandStaticImportActionTest.java similarity index 51% rename from platform/core-api/src/com/intellij/openapi/vfs/ModificationAttemptEvent.java rename to java/java-tests/testSrc/com/intellij/codeInsight/intention/ExpandStaticImportActionTest.java index 87469a402fb5..1b0f0074bcac 100644 --- a/platform/core-api/src/com/intellij/openapi/vfs/ModificationAttemptEvent.java +++ b/java/java-tests/testSrc/com/intellij/codeInsight/intention/ExpandStaticImportActionTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2011 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. @@ -13,28 +13,16 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.intellij.openapi.vfs; +package com.intellij.codeInsight.intention; -import java.util.EventObject; +import com.intellij.codeInsight.daemon.LightIntentionActionTestCase; -public class ModificationAttemptEvent extends EventObject{ - private final VirtualFile[] myFiles; - private boolean myConsumed = false; +public class ExpandStaticImportActionTest extends LightIntentionActionTestCase { - public ModificationAttemptEvent(VirtualFileManager manager, VirtualFile[] files) { - super(manager); - myFiles = files; - } + public void test() throws Exception { doAllTests(); } - public VirtualFile[] getFiles() { - return myFiles; - } - - public void consume(){ - myConsumed = true; - } - - public boolean isConsumed() { - return myConsumed; + @Override + protected String getBasePath() { + return "/codeInsight/daemonCodeAnalyzer/quickFix/expandStaticImport"; } } diff --git a/java/java-tests/testSrc/com/intellij/codeInspection/FieldCanBeLocalTest.java b/java/java-tests/testSrc/com/intellij/codeInspection/FieldCanBeLocalTest.java index 07076a6d6321..0a3039b5a4c1 100644 --- a/java/java-tests/testSrc/com/intellij/codeInspection/FieldCanBeLocalTest.java +++ b/java/java-tests/testSrc/com/intellij/codeInspection/FieldCanBeLocalTest.java @@ -30,6 +30,7 @@ public class FieldCanBeLocalTest extends InspectionTestCase { public void testLocalStateVar2InnerClass() throws Exception { doTest(); } public void testNotConstantInitializer() throws Exception {doTest();} public void testInnerClassFieldInitializer() throws Exception {doTest();} + public void testFieldUsedInConstantInitialization() throws Exception {doTest();} public void testFieldWithImmutableType() throws Exception {doTest();} public void testIgnoreAnnotated() throws Exception { final FieldCanBeLocalInspection inspection = new FieldCanBeLocalInspection(); diff --git a/java/java-tests/testSrc/com/intellij/refactoring/IntroduceParameterObjectTest.java b/java/java-tests/testSrc/com/intellij/refactoring/IntroduceParameterObjectTest.java index 8c18910bf254..95ba680e5892 100644 --- a/java/java-tests/testSrc/com/intellij/refactoring/IntroduceParameterObjectTest.java +++ b/java/java-tests/testSrc/com/intellij/refactoring/IntroduceParameterObjectTest.java @@ -115,6 +115,24 @@ public class IntroduceParameterObjectTest extends MultiFileTestCase{ doTest(); } + public void testSameTypeAndVarargs() throws Exception { + doTest(false, false, new Function() { + @Override + public ParameterTablePanel.VariableData[] fun(PsiMethod method) { + final PsiParameter[] parameters = method.getParameterList().getParameters(); + + final ParameterTablePanel.VariableData[] datas = new ParameterTablePanel.VariableData[parameters.length - 1]; + for (int i = 0; i < parameters.length - 1; i++) { + PsiParameter parameter = parameters[i]; + datas[i] = new ParameterTablePanel.VariableData(parameter); + datas[i].name = parameter.getName(); + datas[i].passAsParameter = true; + } + return datas; + } + }); + } + public void testTypeParametersWithChosenSubtype() throws Exception { doTest(false, true, new Function() { @Override diff --git a/java/java-tests/testSrc/com/intellij/refactoring/IntroduceParameterTest.java b/java/java-tests/testSrc/com/intellij/refactoring/IntroduceParameterTest.java index 653e997218ea..8033fb3795d6 100644 --- a/java/java-tests/testSrc/com/intellij/refactoring/IntroduceParameterTest.java +++ b/java/java-tests/testSrc/com/intellij/refactoring/IntroduceParameterTest.java @@ -244,6 +244,10 @@ public class IntroduceParameterTest extends LightCodeInsightTestCase { doTest(IntroduceParameterRefactoring.REPLACE_FIELDS_WITH_GETTERS_NONE, false, false, false, false); } + public void testGetterQualifier() throws Exception { + doTest(IntroduceParameterRefactoring.REPLACE_FIELDS_WITH_GETTERS_INACCESSIBLE, false, false, false, false); + } + public void testIncompleteEnumDefinition() throws Exception { doTest(IntroduceParameterRefactoring.REPLACE_FIELDS_WITH_GETTERS_NONE, true, false, false, false, "Incomplete call(Root()): 2 parameters expected but only 0 found\n" + "Incomplete call(Root()): expected to delete the 1 parameter but only 0 parameters found"); diff --git a/java/java-tests/testSrc/com/intellij/refactoring/moveMethod/MoveInstanceMethodTest.java b/java/java-tests/testSrc/com/intellij/refactoring/moveMethod/MoveInstanceMethodTest.java index b03fb6f22442..6ee17f90bba2 100644 --- a/java/java-tests/testSrc/com/intellij/refactoring/moveMethod/MoveInstanceMethodTest.java +++ b/java/java-tests/testSrc/com/intellij/refactoring/moveMethod/MoveInstanceMethodTest.java @@ -47,6 +47,8 @@ public class MoveInstanceMethodTest extends LightCodeInsightTestCase { public void testIDEADEV11257() throws Exception { doTest(true, 0); } + public void testThisInAnonymous() throws Exception { doTest(true, 0); } + public void testEscalateVisibility() throws Exception { doTest(true, 0, VisibilityUtil.ESCALATE_VISIBILITY); } diff --git a/java/openapi/src/com/intellij/ide/IconUtilEx.java b/java/openapi/src/com/intellij/ide/IconUtilEx.java index ee012e6dfc4b..517f943c50a7 100644 --- a/java/openapi/src/com/intellij/ide/IconUtilEx.java +++ b/java/openapi/src/com/intellij/ide/IconUtilEx.java @@ -16,6 +16,7 @@ package com.intellij.ide; import com.intellij.openapi.module.Module; +import com.intellij.openapi.module.ModuleType; import com.intellij.openapi.project.Project; import com.intellij.openapi.util.Iconable; import com.intellij.openapi.vfs.VirtualFile; @@ -32,7 +33,7 @@ public class IconUtilEx { return ((PsiElement)object).getIcon(flags); } if (object instanceof Module) { - return ((Module)object).getModuleType().getNodeIcon((flags & Iconable.ICON_FLAG_OPEN) != 0); + return ModuleType.get(((Module)object)).getNodeIcon((flags & Iconable.ICON_FLAG_OPEN) != 0); } if (object instanceof VirtualFile) { VirtualFile file = (VirtualFile)object; diff --git a/platform/core-api/src/com/intellij/lang/Language.java b/platform/core-api/src/com/intellij/lang/Language.java index 58c0241d2569..985004a5e1b8 100644 --- a/platform/core-api/src/com/intellij/lang/Language.java +++ b/platform/core-api/src/com/intellij/lang/Language.java @@ -17,7 +17,7 @@ package com.intellij.lang; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.fileTypes.FileType; -import com.intellij.openapi.fileTypes.FileTypeManager; +import com.intellij.openapi.fileTypes.FileTypeRegistry; import com.intellij.openapi.fileTypes.LanguageFileType; import com.intellij.openapi.util.UserDataHolderBase; import com.intellij.util.ArrayUtil; @@ -126,7 +126,7 @@ public abstract class Language extends UserDataHolderBase { @Nullable public LanguageFileType getAssociatedFileType() { - final FileType[] types = FileTypeManager.getInstance().getRegisteredFileTypes(); + final FileType[] types = FileTypeRegistry.getInstance().getRegisteredFileTypes(); for (final FileType fileType : types) { if (fileType instanceof LanguageFileType && ((LanguageFileType)fileType).getLanguage() == this) { return (LanguageFileType)fileType; diff --git a/platform/core-api/src/com/intellij/openapi/application/ApplicationComponentLocator.java b/platform/core-api/src/com/intellij/openapi/application/ApplicationComponentLocator.java new file mode 100644 index 000000000000..58741c32e16b --- /dev/null +++ b/platform/core-api/src/com/intellij/openapi/application/ApplicationComponentLocator.java @@ -0,0 +1,42 @@ +/* + * Copyright 2000-2011 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. + */ +package com.intellij.openapi.application; + +import com.intellij.openapi.components.ComponentManager; + +/** + * @author yole + */ +public class ApplicationComponentLocator { + private static ComponentManager ourInstance; + + public static T getComponent(Class interfaceClass) { + return ourInstance.getComponent(interfaceClass); + } + + public static Object getComponentInstance(Object componentKey) { + return ourInstance.getPicoContainer().getComponentInstance(componentKey); + } + + public static void setInstance(ComponentManager instance) { + ourInstance = instance; + } + + public static boolean initialized() { + return ourInstance != null; + } +} + diff --git a/platform/core-api/src/com/intellij/openapi/components/ServiceManager.java b/platform/core-api/src/com/intellij/openapi/components/ServiceManager.java index 2e7b6e448670..78a55abe0160 100644 --- a/platform/core-api/src/com/intellij/openapi/components/ServiceManager.java +++ b/platform/core-api/src/com/intellij/openapi/components/ServiceManager.java @@ -16,7 +16,7 @@ package com.intellij.openapi.components; -import com.intellij.openapi.application.ApplicationManager; +import com.intellij.openapi.application.ApplicationComponentLocator; import com.intellij.openapi.project.Project; import com.intellij.openapi.util.NotNullLazyKey; import com.intellij.util.NotNullFunction; @@ -33,7 +33,7 @@ public class ServiceManager { } public static T getService(@NotNull Class serviceClass) { - return (T)ApplicationManager.getApplication().getPicoContainer().getComponentInstance(serviceClass.getName()); + return (T)ApplicationComponentLocator.getComponentInstance(serviceClass.getName()); } public static T getService(@NotNull Project project, @NotNull Class serviceClass) { diff --git a/platform/core-api/src/com/intellij/openapi/fileTypes/FileTypeRegistry.java b/platform/core-api/src/com/intellij/openapi/fileTypes/FileTypeRegistry.java new file mode 100644 index 000000000000..ef80b947f1c3 --- /dev/null +++ b/platform/core-api/src/com/intellij/openapi/fileTypes/FileTypeRegistry.java @@ -0,0 +1,47 @@ +/* + * Copyright 2000-2011 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. + */ +package com.intellij.openapi.fileTypes; + +import com.intellij.openapi.util.Getter; +import com.intellij.openapi.vfs.VirtualFile; +import org.jetbrains.annotations.NotNull; + +/** + * @author yole + */ +public abstract class FileTypeRegistry { + public static Getter ourInstanceGetter; + + public static FileTypeRegistry getInstance() { + return ourInstanceGetter.get(); + } + + /** + * Returns the list of all registered file types. + * + * @return The list of file types. + */ + public abstract FileType[] getRegisteredFileTypes(); + + /** + * Returns the file type for the specified file. + * + * @param file The file for which the type is requested. + * @return The file type instance. + */ + @NotNull + public abstract FileType getFileTypeByFile(@NotNull VirtualFile file); +} diff --git a/platform/core-api/src/com/intellij/openapi/progress/ProgressIndicatorProvider.java b/platform/core-api/src/com/intellij/openapi/progress/ProgressIndicatorProvider.java new file mode 100644 index 000000000000..cf9541e3d044 --- /dev/null +++ b/platform/core-api/src/com/intellij/openapi/progress/ProgressIndicatorProvider.java @@ -0,0 +1,44 @@ +/* + * Copyright 2000-2011 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. + */ +package com.intellij.openapi.progress; + +import org.jetbrains.annotations.Nullable; + +/** + * @author yole + */ +public abstract class ProgressIndicatorProvider { + @Nullable + public static ProgressIndicatorProvider ourInstance; + + @Nullable + public static ProgressIndicatorProvider getInstance() { + return ourInstance; + } + + public abstract ProgressIndicator getProgressIndicator(); + + protected abstract void doCheckCanceled() throws ProcessCanceledException; + + public static boolean ourNeedToCheckCancel = false; + public static void checkCanceled() throws ProcessCanceledException { + // smart optimization! There's a thread started in ProgressManagerImpl, that set's this flag up once in 10 milliseconds + if (ourNeedToCheckCancel && ourInstance != null) { + ourInstance.doCheckCanceled(); + ourNeedToCheckCancel = false; + } + } +} diff --git a/platform/platform-api/src/com/intellij/openapi/util/KeyedExtensionCollector.java b/platform/core-api/src/com/intellij/openapi/util/KeyedExtensionCollector.java similarity index 100% rename from platform/platform-api/src/com/intellij/openapi/util/KeyedExtensionCollector.java rename to platform/core-api/src/com/intellij/openapi/util/KeyedExtensionCollector.java diff --git a/platform/core-api/src/com/intellij/openapi/vfs/VirtualFile.java b/platform/core-api/src/com/intellij/openapi/vfs/VirtualFile.java index 467765ee78a5..7388140e6dc2 100644 --- a/platform/core-api/src/com/intellij/openapi/vfs/VirtualFile.java +++ b/platform/core-api/src/com/intellij/openapi/vfs/VirtualFile.java @@ -15,11 +15,9 @@ */ package com.intellij.openapi.vfs; -import com.intellij.openapi.application.Application; -import com.intellij.openapi.application.ModalityState; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.fileTypes.FileType; -import com.intellij.openapi.fileTypes.FileTypeManager; +import com.intellij.openapi.fileTypes.FileTypeRegistry; import com.intellij.openapi.util.*; import com.intellij.openapi.util.text.StringUtil; import com.intellij.openapi.vfs.encoding.EncodingManager; @@ -180,7 +178,7 @@ public abstract class VirtualFile extends UserDataHolderBase implements Modifica */ public void rename(Object requestor, @NotNull @NonNls String newName) throws IOException { if (getName().equals(newName)) return; - if (!VfsUtil.isValidName(newName)) { + if (!isValidName(newName)) { throw new IOException(VfsBundle.message("file.invalid.name.error", newName)); } @@ -263,7 +261,7 @@ public abstract class VirtualFile extends UserDataHolderBase implements Modifica */ @NotNull public FileType getFileType() { - return FileTypeManager.getInstance().getFileTypeByFile(this); + return FileTypeRegistry.getInstance().getFileTypeByFile(this); } /** @@ -322,7 +320,7 @@ public abstract class VirtualFile extends UserDataHolderBase implements Modifica throw new IOException(VfsBundle.message("invalid.directory.create.files")); } - if (!VfsUtil.isValidName(name)) { + if (!isValidName(name)) { throw new IOException(VfsBundle.message("directory.invalid.name.error", name)); } @@ -352,7 +350,7 @@ public abstract class VirtualFile extends UserDataHolderBase implements Modifica throw new IOException(VfsBundle.message("invalid.directory.create.files")); } - if (!VfsUtil.isValidName(name)) { + if (!isValidName(name)) { throw new IOException(VfsBundle.message("file.invalid.name.error", name)); } @@ -392,7 +390,7 @@ public abstract class VirtualFile extends UserDataHolderBase implements Modifica throw new IOException(VfsBundle.message("file.move.error", newParent.getPresentableUrl())); } - VfsUtil.doActionAndRestoreEncoding(this, new ThrowableComputable() { + EncodingManager.doActionAndRestoreEncoding(this, new ThrowableComputable() { public VirtualFile compute() throws IOException { getFileSystem().moveFile(requestor, VirtualFile.this, newParent); return VirtualFile.this; @@ -409,7 +407,7 @@ public abstract class VirtualFile extends UserDataHolderBase implements Modifica throw new IOException(VfsBundle.message("file.copy.target.must.be.directory")); } - return VfsUtil.doActionAndRestoreEncoding(this, new ThrowableComputable() { + return EncodingManager.doActionAndRestoreEncoding(this, new ThrowableComputable() { public VirtualFile compute() throws IOException { return getFileSystem().copyFile(requestor, VirtualFile.this, newParent, copyName); } @@ -575,13 +573,6 @@ public abstract class VirtualFile extends UserDataHolderBase implements Modifica */ public abstract void refresh(boolean asynchronous, boolean recursive, Runnable postRunnable); - public void refresh(boolean asynchronous, boolean recursive, Runnable postRunnable, ModalityState modalityState) { - if (modalityState != ModalityState.NON_MODAL) { - LOG.error("Refresh with non-modal modality state is not implemented for file: " + this); - } - refresh(asynchronous, recursive, postRunnable); - } - public String getPresentableName() { return getName(); } @@ -629,4 +620,8 @@ public abstract class VirtualFile extends UserDataHolderBase implements Modifica public boolean isInLocalFileSystem() { return false; } + + public static boolean isValidName(@NotNull String name) { + return name.indexOf('\\') < 0 && name.indexOf('/') < 0; + } } diff --git a/platform/core-api/src/com/intellij/openapi/vfs/VirtualFileManager.java b/platform/core-api/src/com/intellij/openapi/vfs/VirtualFileManager.java index de9f883cf93a..8c0016d7a42a 100644 --- a/platform/core-api/src/com/intellij/openapi/vfs/VirtualFileManager.java +++ b/platform/core-api/src/com/intellij/openapi/vfs/VirtualFileManager.java @@ -16,8 +16,7 @@ package com.intellij.openapi.vfs; import com.intellij.openapi.Disposable; -import com.intellij.openapi.application.ApplicationManager; -import com.intellij.openapi.application.ModalityState; +import com.intellij.openapi.application.ApplicationComponentLocator; import com.intellij.openapi.util.ModificationTracker; import com.intellij.openapi.vfs.newvfs.BulkFileListener; import com.intellij.util.messages.Topic; @@ -42,7 +41,7 @@ public abstract class VirtualFileManager implements ModificationTracker{ */ @NotNull public static VirtualFileManager getInstance(){ - return ApplicationManager.getApplication().getComponent(VirtualFileManager.class); + return ApplicationComponentLocator.getComponent(VirtualFileManager.class); } /** @@ -73,8 +72,6 @@ public abstract class VirtualFileManager implements ModificationTracker{ */ public abstract void refresh(boolean asynchronous, @Nullable Runnable postAction); - public abstract void refresh(boolean asynchronous, @Nullable Runnable postAction, ModalityState modalityState); - /** * Searches for the file specified by given URL. URL is a string which uniquely identifies file in all * file systems. @@ -123,11 +120,6 @@ public abstract class VirtualFileManager implements ModificationTracker{ */ public abstract void removeVirtualFileListener(@NotNull VirtualFileListener listener); - public abstract void addModificationAttemptListener(@NotNull ModificationAttemptListener listener); - public abstract void removeModificationAttemptListener(@NotNull ModificationAttemptListener listener); - - public abstract void fireReadOnlyModificationAttempt(@NotNull VirtualFile... files); - /** * Constructs URL by specified protocol and path. URL is a string which uniquely identifies file in all * file systems. diff --git a/platform/core-api/src/com/intellij/openapi/vfs/encoding/EncodingManager.java b/platform/core-api/src/com/intellij/openapi/vfs/encoding/EncodingManager.java index 7fdade2e7c40..d9a6372faa33 100644 --- a/platform/core-api/src/com/intellij/openapi/vfs/encoding/EncodingManager.java +++ b/platform/core-api/src/com/intellij/openapi/vfs/encoding/EncodingManager.java @@ -18,6 +18,8 @@ package com.intellij.openapi.vfs.encoding; import com.intellij.openapi.Disposable; import com.intellij.openapi.components.ServiceManager; import com.intellij.openapi.editor.Document; +import com.intellij.openapi.util.Comparing; +import com.intellij.openapi.util.ThrowableComputable; import com.intellij.openapi.vfs.VirtualFile; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; @@ -88,4 +90,21 @@ public abstract class EncodingManager { public abstract void removePropertyChangeListener(@NotNull PropertyChangeListener listener); public abstract Charset getCachedCharsetFromContent(@NotNull Document document); + + public static VirtualFile doActionAndRestoreEncoding(@NotNull VirtualFile fileBefore, @NotNull ThrowableComputable action) throws E { + Charset charsetBefore = getInstance().getEncoding(fileBefore, true); + VirtualFile fileAfter = null; + try { + fileAfter = action.compute(); + return fileAfter; + } + finally { + if (fileAfter != null) { + Charset actual = getInstance().getEncoding(fileAfter, true); + if (!Comparing.equal(actual, charsetBefore)) { + getInstance().setEncoding(fileAfter, charsetBefore); + } + } + } + } } diff --git a/platform/core-api/src/com/intellij/openapi/vfs/ModificationAttemptListener.java b/platform/core-api/src/com/intellij/openapi/vfs/newvfs/CachingVirtualFileSystem.java similarity index 69% rename from platform/core-api/src/com/intellij/openapi/vfs/ModificationAttemptListener.java rename to platform/core-api/src/com/intellij/openapi/vfs/newvfs/CachingVirtualFileSystem.java index 7675eca959ea..6e9173e07e88 100644 --- a/platform/core-api/src/com/intellij/openapi/vfs/ModificationAttemptListener.java +++ b/platform/core-api/src/com/intellij/openapi/vfs/newvfs/CachingVirtualFileSystem.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2011 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. @@ -13,10 +13,11 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.intellij.openapi.vfs; +package com.intellij.openapi.vfs.newvfs; -import java.util.EventListener; - -public interface ModificationAttemptListener extends EventListener{ - void readOnlyModificationAttempt(ModificationAttemptEvent event); +/** + * @author yole + */ +public interface CachingVirtualFileSystem { + void refreshWithoutFileWatcher(boolean asynchronous); } diff --git a/platform/core-api/src/com/intellij/openapi/vfs/newvfs/FileSystemPersistence.java b/platform/core-api/src/com/intellij/openapi/vfs/newvfs/FileSystemPersistence.java new file mode 100644 index 000000000000..2819ebb27112 --- /dev/null +++ b/platform/core-api/src/com/intellij/openapi/vfs/newvfs/FileSystemPersistence.java @@ -0,0 +1,26 @@ +/* + * Copyright 2000-2011 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. + */ +package com.intellij.openapi.vfs.newvfs; + +import com.intellij.openapi.application.ModalityState; + +/** + * @author yole + */ +public interface FileSystemPersistence { + void refresh(boolean asynchronous, Runnable postAction, ModalityState modalityState); + int getCheapFileSystemModificationCount(); +} diff --git a/platform/platform-api/src/com/intellij/openapi/vfs/newvfs/events/VFileContentChangeEvent.java b/platform/core-api/src/com/intellij/openapi/vfs/newvfs/events/VFileContentChangeEvent.java similarity index 100% rename from platform/platform-api/src/com/intellij/openapi/vfs/newvfs/events/VFileContentChangeEvent.java rename to platform/core-api/src/com/intellij/openapi/vfs/newvfs/events/VFileContentChangeEvent.java diff --git a/platform/platform-api/src/com/intellij/openapi/vfs/newvfs/events/VFileCopyEvent.java b/platform/core-api/src/com/intellij/openapi/vfs/newvfs/events/VFileCopyEvent.java similarity index 100% rename from platform/platform-api/src/com/intellij/openapi/vfs/newvfs/events/VFileCopyEvent.java rename to platform/core-api/src/com/intellij/openapi/vfs/newvfs/events/VFileCopyEvent.java diff --git a/platform/platform-api/src/com/intellij/openapi/vfs/newvfs/events/VFileCreateEvent.java b/platform/core-api/src/com/intellij/openapi/vfs/newvfs/events/VFileCreateEvent.java similarity index 100% rename from platform/platform-api/src/com/intellij/openapi/vfs/newvfs/events/VFileCreateEvent.java rename to platform/core-api/src/com/intellij/openapi/vfs/newvfs/events/VFileCreateEvent.java diff --git a/platform/platform-api/src/com/intellij/openapi/vfs/newvfs/events/VFileDeleteEvent.java b/platform/core-api/src/com/intellij/openapi/vfs/newvfs/events/VFileDeleteEvent.java similarity index 100% rename from platform/platform-api/src/com/intellij/openapi/vfs/newvfs/events/VFileDeleteEvent.java rename to platform/core-api/src/com/intellij/openapi/vfs/newvfs/events/VFileDeleteEvent.java diff --git a/platform/platform-api/src/com/intellij/openapi/vfs/newvfs/events/VFileMoveEvent.java b/platform/core-api/src/com/intellij/openapi/vfs/newvfs/events/VFileMoveEvent.java similarity index 100% rename from platform/platform-api/src/com/intellij/openapi/vfs/newvfs/events/VFileMoveEvent.java rename to platform/core-api/src/com/intellij/openapi/vfs/newvfs/events/VFileMoveEvent.java diff --git a/platform/core-api/src/com/intellij/ui/InvokeUtil.java b/platform/core-api/src/com/intellij/ui/InvokeUtil.java deleted file mode 100644 index 59877ae99e34..000000000000 --- a/platform/core-api/src/com/intellij/ui/InvokeUtil.java +++ /dev/null @@ -1,34 +0,0 @@ -package com.intellij.ui; - -import com.intellij.openapi.application.Application; -import com.intellij.openapi.application.ApplicationManager; -import org.jetbrains.annotations.NotNull; - -import javax.swing.*; -import java.lang.reflect.InvocationTargetException; - -public class InvokeUtil { - private InvokeUtil() { - } - - public static void invokeAndWait(@NotNull Runnable runnable) throws InvocationTargetException, InterruptedException { - Application application = ApplicationManager.getApplication(); - assert !application.isDispatchThread() : "Must not be invoked from AWT dispatch thread"; - if (application.isReadAccessAllowed()) { - // make ApplicationImpl catch deadlock situation with readLock held - application.invokeAndWait(runnable, application.getDefaultModalityState()); - return; - } - SwingUtilities.invokeAndWait(runnable); - } - - public static void runOrInvokeAndWait(@NotNull Runnable runnable) throws InvocationTargetException, InterruptedException { - Application application = ApplicationManager.getApplication(); - if (application.isDispatchThread()) { - runnable.run(); - } - else { - invokeAndWait(runnable); - } - } -} diff --git a/platform/platform-api/src/com/intellij/util/KeyedLazyInstance.java b/platform/core-api/src/com/intellij/util/KeyedLazyInstance.java similarity index 100% rename from platform/platform-api/src/com/intellij/util/KeyedLazyInstance.java rename to platform/core-api/src/com/intellij/util/KeyedLazyInstance.java diff --git a/platform/platform-impl/src/com/intellij/openapi/components/impl/ComponentManagerConfigurator.java b/platform/core-impl/src/com/intellij/openapi/components/impl/ComponentManagerConfigurator.java similarity index 100% rename from platform/platform-impl/src/com/intellij/openapi/components/impl/ComponentManagerConfigurator.java rename to platform/core-impl/src/com/intellij/openapi/components/impl/ComponentManagerConfigurator.java diff --git a/platform/platform-impl/src/com/intellij/openapi/components/impl/ComponentManagerImpl.java b/platform/core-impl/src/com/intellij/openapi/components/impl/ComponentManagerImpl.java similarity index 96% rename from platform/platform-impl/src/com/intellij/openapi/components/impl/ComponentManagerImpl.java rename to platform/core-impl/src/com/intellij/openapi/components/impl/ComponentManagerImpl.java index 50334de4c46f..15a14fa8c878 100644 --- a/platform/platform-impl/src/com/intellij/openapi/components/impl/ComponentManagerImpl.java +++ b/platform/core-impl/src/com/intellij/openapi/components/impl/ComponentManagerImpl.java @@ -23,7 +23,7 @@ import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.extensions.PluginDescriptor; import com.intellij.openapi.progress.ProcessCanceledException; import com.intellij.openapi.progress.ProgressIndicator; -import com.intellij.openapi.progress.ProgressManager; +import com.intellij.openapi.progress.ProgressIndicatorProvider; import com.intellij.openapi.util.Condition; import com.intellij.openapi.util.Disposer; import com.intellij.openapi.util.UserDataHolderBase; @@ -68,7 +68,6 @@ public abstract class ComponentManagerImpl extends UserDataHolderBase implements private final ComponentManager myParentComponentManager; private Boolean myHeadless; private ComponentsRegistry myComponentsRegistry = new ComponentsRegistry(); - private boolean myHaveProgressManager = false; private final Condition myDisposedCondition = new Condition() { public boolean value(final Object o) { return isDisposed(); @@ -101,9 +100,7 @@ public abstract class ComponentManagerImpl extends UserDataHolderBase implements final Class[] componentInterfaces = myComponentsRegistry.getComponentInterfaces(); for (Class componentInterface : componentInterfaces) { - if (myHaveProgressManager) { - ProgressManager.checkCanceled(); - } + ProgressIndicatorProvider.checkCanceled(); try { createComponent(componentInterface); } @@ -204,20 +201,15 @@ public abstract class ComponentManagerImpl extends UserDataHolderBase implements } private void initComponent(Object component) { - if (myHaveProgressManager) { - final ProgressManager progressManager = ProgressManager.getInstance(); + final ProgressIndicatorProvider progressManager = ProgressIndicatorProvider.getInstance(); - final ProgressIndicator indicator = progressManager != null ? progressManager.getProgressIndicator() : null; - if (indicator != null) { - String name = getComponentName(component); - indicator.checkCanceled(); - indicator.setText2(name); - indicator.setIndeterminate(false); - indicator.setFraction(myComponentsRegistry.getPercentageOfComponentsLoaded()); - } - } - if (component instanceof ProgressManager) { - myHaveProgressManager = true; + final ProgressIndicator indicator = progressManager != null ? progressManager.getProgressIndicator() : null; + if (indicator != null) { + String name = getComponentName(component); + indicator.checkCanceled(); + indicator.setText2(name); + indicator.setIndeterminate(false); + indicator.setFraction(myComponentsRegistry.getPercentageOfComponentsLoaded()); } try { @@ -290,9 +282,7 @@ public abstract class ComponentManagerImpl extends UserDataHolderBase implements Class[] componentClasses = myComponentsRegistry.getComponentInterfaces(); ArrayList components = new ArrayList(componentClasses.length); for (Class interfaceClass : componentClasses) { - if (myHaveProgressManager) { - ProgressManager.checkCanceled(); - } + ProgressIndicatorProvider.checkCanceled(); Object component = getComponent(interfaceClass); if (component != null) components.add(component); } diff --git a/platform/platform-impl/src/com/intellij/openapi/vfs/ex/VirtualFileManagerEx.java b/platform/core-impl/src/com/intellij/openapi/vfs/ex/VirtualFileManagerEx.java similarity index 81% rename from platform/platform-impl/src/com/intellij/openapi/vfs/ex/VirtualFileManagerEx.java rename to platform/core-impl/src/com/intellij/openapi/vfs/ex/VirtualFileManagerEx.java index ebda7c47ed0b..174f859f487f 100644 --- a/platform/platform-impl/src/com/intellij/openapi/vfs/ex/VirtualFileManagerEx.java +++ b/platform/core-impl/src/com/intellij/openapi/vfs/ex/VirtualFileManagerEx.java @@ -17,12 +17,8 @@ package com.intellij.openapi.vfs.ex; import com.intellij.openapi.vfs.VirtualFileManager; -import com.intellij.openapi.vfs.VirtualFileSystem; public abstract class VirtualFileManagerEx extends VirtualFileManager { - public abstract void registerFileSystem(VirtualFileSystem fileSystem); - public abstract void unregisterFileSystem(VirtualFileSystem fileSystem); - public abstract void fireBeforeRefreshStart(boolean asynchronous); public abstract void fireAfterRefreshFinish(boolean asynchronous); } diff --git a/platform/platform-impl/src/com/intellij/openapi/vfs/impl/BulkVirtualFileListenerAdapter.java b/platform/core-impl/src/com/intellij/openapi/vfs/impl/BulkVirtualFileListenerAdapter.java similarity index 100% rename from platform/platform-impl/src/com/intellij/openapi/vfs/impl/BulkVirtualFileListenerAdapter.java rename to platform/core-impl/src/com/intellij/openapi/vfs/impl/BulkVirtualFileListenerAdapter.java diff --git a/platform/platform-impl/src/com/intellij/openapi/vfs/impl/VirtualFileManagerImpl.java b/platform/core-impl/src/com/intellij/openapi/vfs/impl/VirtualFileManagerImpl.java similarity index 85% rename from platform/platform-impl/src/com/intellij/openapi/vfs/impl/VirtualFileManagerImpl.java rename to platform/core-impl/src/com/intellij/openapi/vfs/impl/VirtualFileManagerImpl.java index 66e79d719bc8..4b35483ed32e 100644 --- a/platform/platform-impl/src/com/intellij/openapi/vfs/impl/VirtualFileManagerImpl.java +++ b/platform/core-impl/src/com/intellij/openapi/vfs/impl/VirtualFileManagerImpl.java @@ -19,16 +19,12 @@ import com.intellij.openapi.Disposable; import com.intellij.openapi.application.Application; import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.application.ModalityState; -import com.intellij.openapi.components.ApplicationComponent; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.util.Disposer; import com.intellij.openapi.util.KeyedExtensionCollector; import com.intellij.openapi.vfs.*; import com.intellij.openapi.vfs.ex.VirtualFileManagerEx; -import com.intellij.openapi.vfs.newvfs.BulkFileListener; -import com.intellij.openapi.vfs.newvfs.ManagingFS; -import com.intellij.openapi.vfs.newvfs.NewVirtualFileSystem; -import com.intellij.openapi.vfs.newvfs.RefreshQueue; +import com.intellij.openapi.vfs.newvfs.*; import com.intellij.openapi.vfs.newvfs.events.VFilePropertyChangeEvent; import com.intellij.util.EventDispatcher; import com.intellij.util.containers.ContainerUtil; @@ -40,7 +36,7 @@ import java.util.ArrayList; import java.util.Collections; import java.util.List; -public class VirtualFileManagerImpl extends VirtualFileManagerEx implements ApplicationComponent { +public class VirtualFileManagerImpl extends VirtualFileManagerEx { private static final Logger LOG = Logger.getInstance("#com.intellij.openapi.vfs.impl.VirtualFileManagerImpl"); @@ -56,12 +52,11 @@ public class VirtualFileManagerImpl extends VirtualFileManagerEx implements Appl private final EventDispatcher myVirtualFileListenerMulticaster = EventDispatcher.create(VirtualFileListener.class); private final List myVirtualFileManagerListeners = ContainerUtil.createEmptyCOWList(); - private final EventDispatcher myModificationAttemptListenerMulticaster = EventDispatcher.create(ModificationAttemptListener.class); private int myRefreshCount = 0; - private final ManagingFS myPersistence; + private final FileSystemPersistence myPersistence; - public VirtualFileManagerImpl(VirtualFileSystem[] fileSystems, MessageBus bus, ManagingFS persistence) { + public VirtualFileManagerImpl(VirtualFileSystem[] fileSystems, MessageBus bus, FileSystemPersistence persistence) { myPersistence = persistence; for (VirtualFileSystem fileSystem : fileSystems) { registerFileSystem(fileSystem); @@ -74,20 +69,9 @@ public class VirtualFileManagerImpl extends VirtualFileManagerEx implements Appl bus.connect().subscribe(VFS_CHANGES, new BulkVirtualFileListenerAdapter(myVirtualFileListenerMulticaster.getMulticaster())); } - @NotNull - public String getComponentName() { - return "VirtualFileManager"; - } - - public void initComponent() { - } - - public void disposeComponent() { - } - public void registerFileSystem(VirtualFileSystem fileSystem) { myCollector.addExplicitExtension(fileSystem.getProtocol(), fileSystem); - if (!(fileSystem instanceof NewVirtualFileSystem)) { + if (!(fileSystem instanceof CachingVirtualFileSystem)) { fileSystem.addVirtualFileListener(myVirtualFileListenerMulticaster.getMulticaster()); } myPhysicalFileSystems.add(fileSystem); @@ -118,8 +102,8 @@ public class VirtualFileManagerImpl extends VirtualFileManagerEx implements Appl } for (VirtualFileSystem fileSystem : getPhysicalFileSystems()) { - if (fileSystem instanceof NewVirtualFileSystem) { - ((NewVirtualFileSystem)fileSystem).refreshWithoutFileWatcher(asynchronous); + if (fileSystem instanceof CachingVirtualFileSystem) { + ((CachingVirtualFileSystem)fileSystem).refreshWithoutFileWatcher(asynchronous); } else { fileSystem.refresh(asynchronous); @@ -131,13 +115,12 @@ public class VirtualFileManagerImpl extends VirtualFileManagerEx implements Appl refresh(asynchronous, postAction, ModalityState.NON_MODAL); } - @Override public void refresh(boolean asynchronous, @Nullable Runnable postAction, ModalityState modalityState) { if (!asynchronous) { ApplicationManager.getApplication().assertIsDispatchThread(); } - RefreshQueue.getInstance().refresh(asynchronous, true, postAction, modalityState, myPersistence.getLocalRoots()); // TODO: Get an idea how to deliver chnages from local FS to jar fs before they go refresh + myPersistence.refresh(asynchronous, postAction, modalityState); //final VirtualFile[] managedRoots = ManagingFS.getInstance().getRoots(); //for (int i = 0; i < managedRoots.length; i++) { @@ -147,7 +130,7 @@ public class VirtualFileManagerImpl extends VirtualFileManagerEx implements Appl //} for (VirtualFileSystem fileSystem : getPhysicalFileSystems()) { - if (!(fileSystem instanceof NewVirtualFileSystem)) { + if (!(fileSystem instanceof CachingVirtualFileSystem)) { fileSystem.refresh(asynchronous); } } @@ -188,21 +171,6 @@ public class VirtualFileManagerImpl extends VirtualFileManagerEx implements Appl myVirtualFileListenerMulticaster.removeListener(listener); } - public void addModificationAttemptListener(@NotNull ModificationAttemptListener listener) { - myModificationAttemptListenerMulticaster.addListener(listener); - } - - public void removeModificationAttemptListener(@NotNull ModificationAttemptListener listener) { - myModificationAttemptListenerMulticaster.removeListener(listener); - } - - public void fireReadOnlyModificationAttempt(@NotNull VirtualFile... files) { - ApplicationManager.getApplication().assertIsDispatchThread(); - - final ModificationAttemptEvent event = new ModificationAttemptEvent(this, files); - myModificationAttemptListenerMulticaster.getMulticaster().readOnlyModificationAttempt(event); - } - public void addVirtualFileManagerListener(@NotNull VirtualFileManagerListener listener) { myVirtualFileManagerListeners.add(listener); } diff --git a/platform/lang-api/src/com/intellij/analysis/AnalysisScope.java b/platform/lang-api/src/com/intellij/analysis/AnalysisScope.java index 0613ad7247d3..d26c90300257 100644 --- a/platform/lang-api/src/com/intellij/analysis/AnalysisScope.java +++ b/platform/lang-api/src/com/intellij/analysis/AnalysisScope.java @@ -38,6 +38,7 @@ import com.intellij.openapi.vfs.VirtualFileFilter; import com.intellij.profile.ProjectProfileManager; import com.intellij.psi.*; import com.intellij.psi.search.GlobalSearchScope; +import com.intellij.psi.search.GlobalSearchScopes; import com.intellij.psi.search.LocalSearchScope; import com.intellij.psi.search.SearchScope; import com.intellij.util.ArrayUtil; @@ -637,14 +638,14 @@ public class AnalysisScope { case CUSTOM: return myScope; case DIRECTORY: - return GlobalSearchScope.directoryScope((PsiDirectory)myElement, true); + return GlobalSearchScopes.directoryScope((PsiDirectory)myElement, true); case FILE: return new LocalSearchScope(myElement); case INVALID: return LocalSearchScope.EMPTY; case MODULE: GlobalSearchScope moduleScope = GlobalSearchScope.moduleScope(myModule); - return myIncludeTestSource ? moduleScope : GlobalSearchScope.notScope(GlobalSearchScope.projectTestScope(myModule.getProject())).intersectWith(moduleScope); + return myIncludeTestSource ? moduleScope : GlobalSearchScope.notScope(GlobalSearchScopes.projectTestScope(myModule.getProject())).intersectWith(moduleScope); case MODULES: SearchScope scope = GlobalSearchScope.EMPTY_SCOPE; for (Module module : myModules) { @@ -652,7 +653,7 @@ public class AnalysisScope { } return scope; case PROJECT: - return myIncludeTestSource ? GlobalSearchScope.projectScope(myProject) : GlobalSearchScope.projectProductionScope(myProject); + return myIncludeTestSource ? GlobalSearchScope.projectScope(myProject) : GlobalSearchScopes.projectProductionScope(myProject); case VIRTUAL_FILES: return new GlobalSearchScope() { @Override diff --git a/platform/lang-api/src/com/intellij/openapi/module/Module.java b/platform/lang-api/src/com/intellij/openapi/module/Module.java index 67729e540921..b233262dd8a3 100644 --- a/platform/lang-api/src/com/intellij/openapi/module/Module.java +++ b/platform/lang-api/src/com/intellij/openapi/module/Module.java @@ -21,6 +21,7 @@ import com.intellij.openapi.extensions.AreaInstance; import com.intellij.openapi.project.Project; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.psi.search.GlobalSearchScope; +import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -36,6 +37,8 @@ public interface Module extends ComponentManager, AreaInstance, Disposable { */ Module[] EMPTY_ARRAY = new Module[0]; + @NonNls String ELEMENT_TYPE = "type"; + /** * Returns the VirtualFile for the module .iml file. * @@ -51,13 +54,6 @@ public interface Module extends ComponentManager, AreaInstance, Disposable { */ @NotNull String getModuleFilePath(); - /** - * Returns the type of this module. - * - * @return the module type. - */ - @NotNull ModuleType getModuleType(); - /** * Returns the project to which this module belongs. * diff --git a/platform/lang-api/src/com/intellij/openapi/module/ModuleType.java b/platform/lang-api/src/com/intellij/openapi/module/ModuleType.java index 93ce3b0c5364..a35b82298679 100644 --- a/platform/lang-api/src/com/intellij/openapi/module/ModuleType.java +++ b/platform/lang-api/src/com/intellij/openapi/module/ModuleType.java @@ -83,4 +83,8 @@ public abstract class ModuleType { public boolean isValidSdk(final Module module, final Sdk projectSdk) { return true; } + + public static ModuleType get(Module module) { + return ModuleTypeManager.getInstance().findByID(module.getOptionValue(Module.ELEMENT_TYPE)); + } } diff --git a/platform/lang-api/src/com/intellij/openapi/module/ModuleUtil.java b/platform/lang-api/src/com/intellij/openapi/module/ModuleUtil.java index 67b3386aabe4..6f78c4cbb31e 100644 --- a/platform/lang-api/src/com/intellij/openapi/module/ModuleUtil.java +++ b/platform/lang-api/src/com/intellij/openapi/module/ModuleUtil.java @@ -80,7 +80,7 @@ public class ModuleUtil { @Nullable public static Module getParentModuleOfType(ModuleType expectedModuleType, Module module) { if (module == null) return null; - if (expectedModuleType.equals(module.getModuleType())) return module; + if (expectedModuleType.equals(ModuleType.get(module))) return module; final List parents = getParentModulesOfType(expectedModuleType, module); return parents.isEmpty() ? null : parents.get(0); } @@ -90,7 +90,7 @@ public class ModuleUtil { final List parents = ModuleManager.getInstance(module.getProject()).getModuleDependentModules(module); ArrayList modules = new ArrayList(); for (Module parent : parents) { - if (expectedModuleType.equals(parent.getModuleType())) { + if (expectedModuleType.equals(ModuleType.get(parent))) { modules.add(parent); } } diff --git a/platform/lang-api/src/com/intellij/openapi/roots/ui/util/OrderEntryCellAppearanceUtils.java b/platform/lang-api/src/com/intellij/openapi/roots/ui/util/OrderEntryCellAppearanceUtils.java index 2dfb0a1e34c0..ebafb3a04e29 100644 --- a/platform/lang-api/src/com/intellij/openapi/roots/ui/util/OrderEntryCellAppearanceUtils.java +++ b/platform/lang-api/src/com/intellij/openapi/roots/ui/util/OrderEntryCellAppearanceUtils.java @@ -17,6 +17,7 @@ package com.intellij.openapi.roots.ui.util; import com.intellij.openapi.module.Module; +import com.intellij.openapi.module.ModuleType; import com.intellij.openapi.project.Project; import com.intellij.openapi.project.ProjectBundle; import com.intellij.openapi.projectRoots.Sdk; @@ -74,7 +75,7 @@ public class OrderEntryCellAppearanceUtils { return new SimpleTextCellAppearance(presentableName, icon, SimpleTextAttributes.SYNTHETIC_ATTRIBUTES); } else if (orderEntry instanceof ModuleOrderEntry) { - final Icon icon = ((ModuleOrderEntry)orderEntry).getModule().getModuleType().getNodeIcon(false); + final Icon icon = ModuleType.get(((ModuleOrderEntry)orderEntry).getModule()).getNodeIcon(false); return SimpleTextCellAppearance.normal(orderEntry.getPresentableName(), icon); } else return CompositeAppearance.single(orderEntry.getPresentableName()); @@ -158,7 +159,7 @@ public class OrderEntryCellAppearanceUtils { } public static CellAppearance forModule(Module module) { - return SimpleTextCellAppearance.normal(module.getName(), module.getModuleType().getNodeIcon(false)); + return SimpleTextCellAppearance.normal(module.getName(), ModuleType.get(module).getNodeIcon(false)); } public static CellAppearance forContentEntry(ContentEntry contentEntry) { diff --git a/platform/lang-api/src/com/intellij/psi/FileViewProvider.java b/platform/lang-api/src/com/intellij/psi/FileViewProvider.java index ae9d4dafb3c7..ac646747f19e 100644 --- a/platform/lang-api/src/com/intellij/psi/FileViewProvider.java +++ b/platform/lang-api/src/com/intellij/psi/FileViewProvider.java @@ -19,7 +19,6 @@ import com.intellij.lang.Language; import com.intellij.openapi.editor.Document; import com.intellij.openapi.util.UserDataHolder; import com.intellij.openapi.vfs.VirtualFile; -import com.intellij.testFramework.LightVirtualFile; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -81,5 +80,5 @@ public interface FileViewProvider extends Cloneable, UserDataHolder { boolean isLockedByPsiOperations(); @NotNull - FileViewProvider createCopy(LightVirtualFile copy); + FileViewProvider createCopy(VirtualFile copy); } diff --git a/platform/lang-api/src/com/intellij/psi/PsiElementVisitor.java b/platform/lang-api/src/com/intellij/psi/PsiElementVisitor.java index d5d662916159..da0d1127efb1 100644 --- a/platform/lang-api/src/com/intellij/psi/PsiElementVisitor.java +++ b/platform/lang-api/src/com/intellij/psi/PsiElementVisitor.java @@ -15,7 +15,7 @@ */ package com.intellij.psi; -import com.intellij.openapi.progress.ProgressManager; +import com.intellij.openapi.progress.ProgressIndicatorProvider; import com.intellij.psi.templateLanguages.OuterLanguageElement; /** @@ -25,7 +25,7 @@ import com.intellij.psi.templateLanguages.OuterLanguageElement; */ public abstract class PsiElementVisitor { public void visitElement(PsiElement element) { - ProgressManager.checkCanceled(); + ProgressIndicatorProvider.checkCanceled(); } public void visitFile(PsiFile file) { diff --git a/platform/lang-api/src/com/intellij/psi/PsiManager.java b/platform/lang-api/src/com/intellij/psi/PsiManager.java index 2b15ca422656..ca2d5e3b521e 100644 --- a/platform/lang-api/src/com/intellij/psi/PsiManager.java +++ b/platform/lang-api/src/com/intellij/psi/PsiManager.java @@ -33,6 +33,7 @@ import org.jetbrains.annotations.Nullable; * The main entry point for accessing the PSI services for a project. */ public abstract class PsiManager extends UserDataHolderBase { + /** * Returns the PSI manager instance for the specified project. * @@ -114,26 +115,6 @@ public abstract class PsiManager extends UserDataHolderBase { */ public abstract void removePsiTreeChangeListener(@NotNull PsiTreeChangeListener listener); - /** - * Returns the code style manager for the project. The code style manager can be used - * to reformat code fragments, get names for elements according to the user's code style - * and work with import statements and full-qualified names. - * - * @return the code style manager instance. - */ - @NotNull - public abstract CodeStyleManager getCodeStyleManager(); - - /** - * Returns the search helper for the project, which provides low-level search and - * find usages functionality. It can be used to perform operations like finding references - * to an element, finding overriding / inheriting elements, finding to do items and so on. - * - * @return the search helper instance. - */ - @NotNull - public abstract PsiSearchHelper getSearchHelper(); - /** * Returns the modification tracker for the project, which can be used to get the PSI * modification count value. @@ -230,8 +211,6 @@ public abstract class PsiManager extends UserDataHolderBase { T; public abstract T performActionWithFormatterDisabled(Computable r); - public abstract void postponeAutoFormattingInside(Runnable runnable); - public abstract void registerLanguageInjector(@NotNull LanguageInjector injector); public abstract void registerLanguageInjector(@NotNull LanguageInjector injector, Disposable parentDisposable); diff --git a/platform/lang-api/src/com/intellij/psi/PsiRecursiveElementVisitor.java b/platform/lang-api/src/com/intellij/psi/PsiRecursiveElementVisitor.java index 6ec50dd49f4f..000d3ee4037e 100644 --- a/platform/lang-api/src/com/intellij/psi/PsiRecursiveElementVisitor.java +++ b/platform/lang-api/src/com/intellij/psi/PsiRecursiveElementVisitor.java @@ -15,7 +15,7 @@ */ package com.intellij.psi; -import com.intellij.openapi.progress.ProgressManager; +import com.intellij.openapi.progress.ProgressIndicatorProvider; import java.util.List; @@ -35,7 +35,7 @@ public abstract class PsiRecursiveElementVisitor extends PsiElementVisitor { } public void visitElement(final PsiElement element) { - ProgressManager.checkCanceled(); + ProgressIndicatorProvider.checkCanceled(); element.acceptChildren(this); } @@ -47,7 +47,7 @@ public abstract class PsiRecursiveElementVisitor extends PsiElementVisitor { if (allFiles.size() > 1) { if (file == viewProvider.getPsi(viewProvider.getBaseLanguage())) { for (PsiFile lFile : allFiles) { - ProgressManager.checkCanceled(); + ProgressIndicatorProvider.checkCanceled(); lFile.acceptChildren(this); } return; diff --git a/platform/lang-api/src/com/intellij/psi/PsiRecursiveElementWalkingVisitor.java b/platform/lang-api/src/com/intellij/psi/PsiRecursiveElementWalkingVisitor.java index 344a6a739287..8309829cf393 100644 --- a/platform/lang-api/src/com/intellij/psi/PsiRecursiveElementWalkingVisitor.java +++ b/platform/lang-api/src/com/intellij/psi/PsiRecursiveElementWalkingVisitor.java @@ -15,7 +15,7 @@ */ package com.intellij.psi; -import com.intellij.openapi.progress.ProgressManager; +import com.intellij.openapi.progress.ProgressIndicatorProvider; import org.jetbrains.annotations.NotNull; import java.util.List; @@ -41,7 +41,7 @@ public abstract class PsiRecursiveElementWalkingVisitor extends PsiElementVisito } public void visitElement(final PsiElement element) { - ProgressManager.checkCanceled(); + ProgressIndicatorProvider.checkCanceled(); myWalkingState.elementStarted(element); } diff --git a/platform/lang-api/src/com/intellij/psi/PsiReference.java b/platform/lang-api/src/com/intellij/psi/PsiReference.java index b73db89ac638..b1012da42688 100644 --- a/platform/lang-api/src/com/intellij/psi/PsiReference.java +++ b/platform/lang-api/src/com/intellij/psi/PsiReference.java @@ -17,7 +17,6 @@ package com.intellij.psi; import com.intellij.openapi.util.TextRange; import com.intellij.util.IncorrectOperationException; -import com.intellij.codeInsight.lookup.LookupElement; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; diff --git a/platform/lang-api/src/com/intellij/psi/search/GlobalSearchScope.java b/platform/lang-api/src/com/intellij/psi/search/GlobalSearchScope.java index 7bde88aaab5a..053f16ffafa7 100644 --- a/platform/lang-api/src/com/intellij/psi/search/GlobalSearchScope.java +++ b/platform/lang-api/src/com/intellij/psi/search/GlobalSearchScope.java @@ -17,25 +17,22 @@ package com.intellij.psi.search; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.fileTypes.FileType; -import com.intellij.openapi.fileTypes.FileTypeManager; +import com.intellij.openapi.fileTypes.FileTypeRegistry; import com.intellij.openapi.module.Module; import com.intellij.openapi.project.Project; -import com.intellij.openapi.roots.ProjectFileIndex; -import com.intellij.openapi.roots.ProjectRootManager; -import com.intellij.openapi.util.Comparing; -import com.intellij.openapi.vfs.VfsUtil; import com.intellij.openapi.vfs.VirtualFile; -import com.intellij.psi.*; -import com.intellij.psi.search.scope.packageSet.*; -import com.intellij.psi.util.PsiUtilBase; +import com.intellij.psi.PsiBundle; +import com.intellij.psi.PsiElement; +import com.intellij.psi.PsiFile; +import com.intellij.psi.search.scope.packageSet.NamedScope; import com.intellij.util.ArrayUtil; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import java.util.ArrayList; import java.util.Arrays; -import java.util.Collection; import java.util.List; +import java.util.Set; public abstract class GlobalSearchScope extends SearchScope implements ProjectAwareFileFilter { private static final Logger LOG = Logger.getInstance("#com.intellij.psi.search.GlobalSearchScope"); @@ -109,7 +106,7 @@ public abstract class GlobalSearchScope extends SearchScope implements ProjectAw result.add(element2); } } - return new LocalSearchScope(PsiUtilBase.toPsiElementArray(result), null, localScope2.isIgnoreInjectedPsi()); + return new LocalSearchScope(result.toArray(new PsiElement[result.size()]), null, localScope2.isIgnoreInjectedPsi()); } @NotNull @@ -161,22 +158,6 @@ public abstract class GlobalSearchScope extends SearchScope implements ProjectAw return ProjectScope.getProjectScope(project); } - public static GlobalSearchScope projectProductionScope(@NotNull Project project) { - return new IntersectionScope(projectScope(project), - new ProductionScopeFilter(project), - PsiBundle.message("psi.search.scope.production.files")); - } - - public static GlobalSearchScope projectTestScope(@NotNull Project project) { - return new IntersectionScope(projectScope(project), - new TestScopeFilter(project), - PsiBundle.message("psi.search.scope.test.files")); - } - - public static GlobalSearchScope filterScope(@NotNull Project project, @NotNull NamedScope set) { - return new FilterScopeAdapter(project, set); - } - public static GlobalSearchScope notScope(@NotNull final GlobalSearchScope scope) { return new DelegatingGlobalSearchScope(scope) { public boolean contains(final VirtualFile file) { @@ -240,33 +221,12 @@ public abstract class GlobalSearchScope extends SearchScope implements ProjectAw return module.getModuleWithDependentsScope(); } - public static GlobalSearchScope directoryScope(@NotNull PsiDirectory directory, final boolean withSubdirectories) { - return new DirectoryScope(directory, withSubdirectories); - } - - public static GlobalSearchScope directoryScope(@NotNull Project project, @NotNull VirtualFile directory, final boolean withSubdirectories) { - return new DirectoryScope(project, directory, withSubdirectories); - } - - public static GlobalSearchScope fileScope(@NotNull PsiFile psiFile) { - return new FileScope(psiFile.getProject(), psiFile.getVirtualFile()); - } - - public static GlobalSearchScope fileScope(final Project project, final VirtualFile virtualFile) { - return new FileScope(project, virtualFile); - } - - public static GlobalSearchScope filesScope(final Project project, final Collection files) { - if (files.isEmpty()) return EMPTY_SCOPE; - return files.size() == 1? fileScope(project, files.iterator().next()) : new FilesScope(project, files); - } - - private static class IntersectionScope extends GlobalSearchScope { + static class IntersectionScope extends GlobalSearchScope { private final GlobalSearchScope myScope1; private final GlobalSearchScope myScope2; private final String myDisplayName; - private IntersectionScope(@NotNull GlobalSearchScope scope1, @NotNull GlobalSearchScope scope2, String displayName) { + IntersectionScope(@NotNull GlobalSearchScope scope1, @NotNull GlobalSearchScope scope2, String displayName) { super(scope1.getProject() == null ? scope2.getProject() : scope1.getProject()); myScope1 = scope1; myScope2 = scope2; @@ -414,217 +374,6 @@ public abstract class GlobalSearchScope extends SearchScope implements ProjectAw } } - private static class ProductionScopeFilter extends GlobalSearchScope { - private final ProjectFileIndex myFileIndex; - - private ProductionScopeFilter(@NotNull Project project) { - super(project); - myFileIndex = ProjectRootManager.getInstance(project).getFileIndex(); - } - - public boolean contains(VirtualFile file) { - return myFileIndex.isInSourceContent(file) && !myFileIndex.isInTestSourceContent(file); - } - - public int compare(VirtualFile file1, VirtualFile file2) { - return 0; - } - - public boolean isSearchInModuleContent(@NotNull Module aModule) { - return true; - } - - public boolean isSearchInModuleContent(@NotNull final Module aModule, final boolean testSources) { - return !testSources; - } - - public boolean isSearchInLibraries() { - return false; - } - } - - private static class TestScopeFilter extends GlobalSearchScope { - private final ProjectFileIndex myFileIndex; - - private TestScopeFilter(@NotNull Project project) { - super(project); - myFileIndex = ProjectRootManager.getInstance(project).getFileIndex(); - } - - public boolean contains(VirtualFile file) { - return myFileIndex.isInTestSourceContent(file); - } - - public int compare(VirtualFile file1, VirtualFile file2) { - return 0; - } - - public boolean isSearchInModuleContent(@NotNull Module aModule) { - return true; - } - - public boolean isSearchInModuleContent(@NotNull final Module aModule, final boolean testSources) { - return testSources; - } - - public boolean isSearchInLibraries() { - return false; - } - } - - private static class DirectoryScope extends GlobalSearchScope { - private final VirtualFile myDirectory; - private final boolean myWithSubdirectories; - - private DirectoryScope(@NotNull PsiDirectory directory, final boolean withSubdirectories) { - super(directory.getProject()); - myWithSubdirectories = withSubdirectories; - myDirectory = directory.getVirtualFile(); - } - - private DirectoryScope(@NotNull Project project, @NotNull VirtualFile directory, final boolean withSubdirectories) { - super(project); - myWithSubdirectories = withSubdirectories; - myDirectory = directory; - } - - public boolean contains(VirtualFile file) { - if (myWithSubdirectories) { - return VfsUtil.isAncestor(myDirectory, file, false); - } - else { - return myDirectory.equals(file.getParent()); - } - } - - public int compare(VirtualFile file1, VirtualFile file2) { - return 0; - } - - public boolean isSearchInModuleContent(@NotNull Module aModule) { - return true; - } - - public boolean isSearchInLibraries() { - return false; - } - - public String toString() { - //noinspection HardCodedStringLiteral - return "directory scope: " + myDirectory + "; withSubdirs:"+myWithSubdirectories; - } - } - - private static class FileScope extends GlobalSearchScope { - private final VirtualFile myVirtualFile; - private final Module myModule; - - private FileScope(final Project project, final VirtualFile virtualFile) { - super(project); - myVirtualFile = virtualFile; - ProjectFileIndex fileIndex = ProjectRootManager.getInstance(project).getFileIndex(); - myModule = myVirtualFile != null ? fileIndex.getModuleForFile(myVirtualFile) : null; - } - - public boolean contains(VirtualFile file) { - return Comparing.equal(myVirtualFile, file); - } - - public int compare(VirtualFile file1, VirtualFile file2) { - return 0; - } - - public boolean isSearchInModuleContent(@NotNull Module aModule) { - return aModule == myModule; - } - - public boolean isSearchInLibraries() { - return myModule == null; - } - } - - private static class FilesScope extends GlobalSearchScope { - private final Collection myFiles; - - public FilesScope(final Project project, final Collection files) { - super(project); - myFiles = files; - } - - @Override - public boolean contains(final VirtualFile file) { - return myFiles.contains(file); - } - - @Override - public int compare(final VirtualFile file1, final VirtualFile file2) { - return 0; - } - - @Override - public boolean isSearchInModuleContent(@NotNull Module aModule) { - return true; - } - - @Override - public boolean isSearchInLibraries() { - return false; - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof FilesScope)) return false; - - return myFiles.equals(((FilesScope)o).myFiles); - } - - @Override - public int hashCode() { - return myFiles.hashCode(); - } - } - - private static class FilterScopeAdapter extends GlobalSearchScope { - private final NamedScope mySet; - private final PsiManager myManager; - - private FilterScopeAdapter(@NotNull Project project, @NotNull NamedScope set) { - super(project); - mySet = set; - myManager = PsiManager.getInstance(project); - } - - public boolean contains(VirtualFile file) { - NamedScopesHolder holder = NamedScopeManager.getInstance(getProject()); - final PackageSet packageSet = mySet.getValue(); - if (packageSet != null) { - if (packageSet instanceof PackageSetBase) return ((PackageSetBase)packageSet).contains(file, holder); - PsiFile psiFile = myManager.findFile(file); - if (psiFile == null) return false; - return packageSet.contains(psiFile, holder); - } - return false; - } - - public String getDisplayName() { - return mySet.getName(); - } - - public int compare(VirtualFile file1, VirtualFile file2) { - return 0; - - } - - public boolean isSearchInModuleContent(@NotNull Module aModule) { - return true; //TODO (optimization?) - } - - public boolean isSearchInLibraries() { - return true; //TODO (optimization?) - } - } - @NotNull public static GlobalSearchScope getScopeRestrictedByFileTypes (@NotNull GlobalSearchScope scope, final FileType... fileTypes) { LOG.assertTrue(fileTypes.length > 0); @@ -642,7 +391,7 @@ public abstract class GlobalSearchScope extends SearchScope implements ProjectAw public boolean contains(VirtualFile file) { if (!super.contains(file)) return false; - final FileType fileType = FileTypeManager.getInstance().getFileTypeByFile(file); + final FileType fileType = FileTypeRegistry.getInstance().getFileTypeByFile(file); for (FileType otherFileType : myFileTypes) { if (fileType.equals(otherFileType)) return true; } diff --git a/platform/lang-api/src/com/intellij/psi/search/GlobalSearchScopes.java b/platform/lang-api/src/com/intellij/psi/search/GlobalSearchScopes.java new file mode 100644 index 000000000000..e1e550aced24 --- /dev/null +++ b/platform/lang-api/src/com/intellij/psi/search/GlobalSearchScopes.java @@ -0,0 +1,288 @@ +/* + * Copyright 2000-2011 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. + */ +package com.intellij.psi.search; + +import com.intellij.openapi.module.Module; +import com.intellij.openapi.project.Project; +import com.intellij.openapi.roots.ProjectFileIndex; +import com.intellij.openapi.roots.ProjectRootManager; +import com.intellij.openapi.util.Comparing; +import com.intellij.openapi.vfs.VfsUtil; +import com.intellij.openapi.vfs.VirtualFile; +import com.intellij.psi.PsiBundle; +import com.intellij.psi.PsiDirectory; +import com.intellij.psi.PsiFile; +import com.intellij.psi.PsiManager; +import com.intellij.psi.search.scope.packageSet.*; +import org.jetbrains.annotations.NotNull; + +import java.util.Collection; + +/** + * @author yole + */ +public class GlobalSearchScopes { + private GlobalSearchScopes() { + } + + public static GlobalSearchScope projectProductionScope(@NotNull Project project) { + return new GlobalSearchScope.IntersectionScope(GlobalSearchScope.projectScope(project), + new ProductionScopeFilter(project), + PsiBundle.message("psi.search.scope.production.files")); + } + + public static GlobalSearchScope projectTestScope(@NotNull Project project) { + return new GlobalSearchScope.IntersectionScope(GlobalSearchScope.projectScope(project), + new TestScopeFilter(project), + PsiBundle.message("psi.search.scope.test.files")); + } + + public static GlobalSearchScope directoryScope(@NotNull PsiDirectory directory, final boolean withSubdirectories) { + return new DirectoryScope(directory, withSubdirectories); + } + + public static GlobalSearchScope directoryScope(@NotNull Project project, @NotNull VirtualFile directory, final boolean withSubdirectories) { + return new DirectoryScope(project, directory, withSubdirectories); + } + + public static GlobalSearchScope fileScope(@NotNull PsiFile psiFile) { + return new FileScope(psiFile.getProject(), psiFile.getVirtualFile()); + } + + public static GlobalSearchScope fileScope(final Project project, final VirtualFile virtualFile) { + return new FileScope(project, virtualFile); + } + + public static GlobalSearchScope filesScope(final Project project, final Collection files) { + if (files.isEmpty()) return GlobalSearchScope.EMPTY_SCOPE; + return files.size() == 1? fileScope(project, files.iterator().next()) : new FilesScope(project, files); + } + + private static class FilterScopeAdapter extends GlobalSearchScope { + private final NamedScope mySet; + private final PsiManager myManager; + + private FilterScopeAdapter(@NotNull Project project, @NotNull NamedScope set) { + super(project); + mySet = set; + myManager = PsiManager.getInstance(project); + } + + public boolean contains(VirtualFile file) { + NamedScopesHolder holder = NamedScopeManager.getInstance(getProject()); + final PackageSet packageSet = mySet.getValue(); + if (packageSet != null) { + if (packageSet instanceof PackageSetBase) return ((PackageSetBase)packageSet).contains(file, holder); + PsiFile psiFile = myManager.findFile(file); + if (psiFile == null) return false; + return packageSet.contains(psiFile, holder); + } + return false; + } + + public String getDisplayName() { + return mySet.getName(); + } + + public int compare(VirtualFile file1, VirtualFile file2) { + return 0; + + } + + public boolean isSearchInModuleContent(@NotNull Module aModule) { + return true; //TODO (optimization?) + } + + public boolean isSearchInLibraries() { + return true; //TODO (optimization?) + } + } + + public static GlobalSearchScope filterScope(@NotNull Project project, @NotNull NamedScope set) { + return new FilterScopeAdapter(project, set); + } + + private static class ProductionScopeFilter extends GlobalSearchScope { + private final ProjectFileIndex myFileIndex; + + private ProductionScopeFilter(@NotNull Project project) { + super(project); + myFileIndex = ProjectRootManager.getInstance(project).getFileIndex(); + } + + public boolean contains(VirtualFile file) { + return myFileIndex.isInSourceContent(file) && !myFileIndex.isInTestSourceContent(file); + } + + public int compare(VirtualFile file1, VirtualFile file2) { + return 0; + } + + public boolean isSearchInModuleContent(@NotNull Module aModule) { + return true; + } + + public boolean isSearchInModuleContent(@NotNull final Module aModule, final boolean testSources) { + return !testSources; + } + + public boolean isSearchInLibraries() { + return false; + } + } + + private static class TestScopeFilter extends GlobalSearchScope { + private final ProjectFileIndex myFileIndex; + + private TestScopeFilter(@NotNull Project project) { + super(project); + myFileIndex = ProjectRootManager.getInstance(project).getFileIndex(); + } + + public boolean contains(VirtualFile file) { + return myFileIndex.isInTestSourceContent(file); + } + + public int compare(VirtualFile file1, VirtualFile file2) { + return 0; + } + + public boolean isSearchInModuleContent(@NotNull Module aModule) { + return true; + } + + public boolean isSearchInModuleContent(@NotNull final Module aModule, final boolean testSources) { + return testSources; + } + + public boolean isSearchInLibraries() { + return false; + } + } + + private static class DirectoryScope extends GlobalSearchScope { + private final VirtualFile myDirectory; + private final boolean myWithSubdirectories; + + private DirectoryScope(@NotNull PsiDirectory directory, final boolean withSubdirectories) { + super(directory.getProject()); + myWithSubdirectories = withSubdirectories; + myDirectory = directory.getVirtualFile(); + } + + private DirectoryScope(@NotNull Project project, @NotNull VirtualFile directory, final boolean withSubdirectories) { + super(project); + myWithSubdirectories = withSubdirectories; + myDirectory = directory; + } + + public boolean contains(VirtualFile file) { + if (myWithSubdirectories) { + return VfsUtil.isAncestor(myDirectory, file, false); + } + else { + return myDirectory.equals(file.getParent()); + } + } + + public int compare(VirtualFile file1, VirtualFile file2) { + return 0; + } + + public boolean isSearchInModuleContent(@NotNull Module aModule) { + return true; + } + + public boolean isSearchInLibraries() { + return false; + } + + public String toString() { + //noinspection HardCodedStringLiteral + return "directory scope: " + myDirectory + "; withSubdirs:"+myWithSubdirectories; + } + } + + private static class FileScope extends GlobalSearchScope { + private final VirtualFile myVirtualFile; + private final Module myModule; + + private FileScope(final Project project, final VirtualFile virtualFile) { + super(project); + myVirtualFile = virtualFile; + ProjectFileIndex fileIndex = ProjectRootManager.getInstance(project).getFileIndex(); + myModule = myVirtualFile != null ? fileIndex.getModuleForFile(myVirtualFile) : null; + } + + public boolean contains(VirtualFile file) { + return Comparing.equal(myVirtualFile, file); + } + + public int compare(VirtualFile file1, VirtualFile file2) { + return 0; + } + + public boolean isSearchInModuleContent(@NotNull Module aModule) { + return aModule == myModule; + } + + public boolean isSearchInLibraries() { + return myModule == null; + } + } + + private static class FilesScope extends GlobalSearchScope { + private final Collection myFiles; + + public FilesScope(final Project project, final Collection files) { + super(project); + myFiles = files; + } + + @Override + public boolean contains(final VirtualFile file) { + return myFiles.contains(file); + } + + @Override + public int compare(final VirtualFile file1, final VirtualFile file2) { + return 0; + } + + @Override + public boolean isSearchInModuleContent(@NotNull Module aModule) { + return true; + } + + @Override + public boolean isSearchInLibraries() { + return false; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (!(o instanceof FilesScope)) return false; + + return myFiles.equals(((FilesScope)o).myFiles); + } + + @Override + public int hashCode() { + return myFiles.hashCode(); + } + } +} diff --git a/platform/lang-api/src/com/intellij/psi/search/PsiSearchHelper.java b/platform/lang-api/src/com/intellij/psi/search/PsiSearchHelper.java index 6f1f76fbf5fb..99081da94114 100644 --- a/platform/lang-api/src/com/intellij/psi/search/PsiSearchHelper.java +++ b/platform/lang-api/src/com/intellij/psi/search/PsiSearchHelper.java @@ -15,7 +15,9 @@ */ package com.intellij.psi.search; +import com.intellij.openapi.components.ServiceManager; import com.intellij.openapi.progress.ProgressIndicator; +import com.intellij.openapi.project.Project; import com.intellij.psi.PsiElement; import com.intellij.psi.PsiFile; import com.intellij.psi.PsiReference; @@ -30,6 +32,15 @@ import org.jetbrains.annotations.Nullable; * @see com.intellij.psi.PsiManager#getSearchHelper() */ public interface PsiSearchHelper extends PsiTodoSearchHelper { + class SERVICE { + private SERVICE() { + } + + public static PsiSearchHelper getInstance(Project project) { + return ServiceManager.getService(project, PsiSearchHelper.class); + } + } + /** * Searches the specified scope for comments containing the specified identifier. * diff --git a/platform/lang-api/src/com/intellij/psi/search/SearchRequestQuery.java b/platform/lang-api/src/com/intellij/psi/search/SearchRequestQuery.java index d9f6a09dda00..b9f31565a372 100644 --- a/platform/lang-api/src/com/intellij/psi/search/SearchRequestQuery.java +++ b/platform/lang-api/src/com/intellij/psi/search/SearchRequestQuery.java @@ -1,7 +1,6 @@ package com.intellij.psi.search; import com.intellij.openapi.project.Project; -import com.intellij.psi.PsiManager; import com.intellij.psi.PsiReference; import com.intellij.util.AbstractQuery; import com.intellij.util.Processor; @@ -21,6 +20,6 @@ public class SearchRequestQuery extends AbstractQuery { @Override protected boolean processResults(@NotNull Processor consumer) { - return PsiManager.getInstance(myProject).getSearchHelper().processRequests(myRequests, consumer); + return PsiSearchHelper.SERVICE.getInstance(myProject).processRequests(myRequests, consumer); } } diff --git a/platform/lang-api/src/com/intellij/psi/search/searches/ReferencesSearch.java b/platform/lang-api/src/com/intellij/psi/search/searches/ReferencesSearch.java index ec8a0f52d676..01a6f1f7f3b0 100644 --- a/platform/lang-api/src/com/intellij/psi/search/searches/ReferencesSearch.java +++ b/platform/lang-api/src/com/intellij/psi/search/searches/ReferencesSearch.java @@ -69,7 +69,7 @@ public class ReferencesSearch extends ExtensibleQueryFactory result, @NotNull Collection outsideResult) { - PsiManager psiManager = file.getManager(); - PsiSearchHelper helper = psiManager.getSearchHelper(); + PsiSearchHelper helper = PsiSearchHelper.SERVICE.getInstance(file.getProject()); TodoItem[] todoItems = helper.findTodoItems(file, startOffset, endOffset); if (todoItems.length == 0) return; diff --git a/platform/lang-impl/src/com/intellij/codeInsight/documentation/AbstractExternalFilter.java b/platform/lang-impl/src/com/intellij/codeInsight/documentation/AbstractExternalFilter.java index 6c9db5b43234..e3f88e9d5f24 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/documentation/AbstractExternalFilter.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/documentation/AbstractExternalFilter.java @@ -293,7 +293,9 @@ public abstract class AbstractExternalFilter { data.append(P); } - while (((read = buf.readLine()) != null) && read.indexOf(endSection) == -1 && read.indexOf(greatestEndSection) == -1) { + while (((read = buf.readLine()) != null) && + StringUtil.indexOfIgnoreCase(read, endSection, 0) == -1 && + StringUtil.indexOfIgnoreCase(read, greatestEndSection, 0) == -1) { if (read.toUpperCase().indexOf(HR) == -1) { appendLine(data, read); } diff --git a/platform/lang-impl/src/com/intellij/codeInsight/hint/ElementLocationUtil.java b/platform/lang-impl/src/com/intellij/codeInsight/hint/ElementLocationUtil.java index bd89680967ca..6349077970d8 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/hint/ElementLocationUtil.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/hint/ElementLocationUtil.java @@ -16,6 +16,7 @@ package com.intellij.codeInsight.hint; +import com.intellij.openapi.module.ModuleType; import com.intellij.openapi.util.IconLoader; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.openapi.roots.*; @@ -49,7 +50,7 @@ public class ElementLocationUtil { if (module != null) { label.setText(module.getName()); - label.setIcon(module.getModuleType().getNodeIcon(false)); + label.setIcon(ModuleType.get(module).getNodeIcon(false)); } else { final List entries = fileIndex.getOrderEntriesForFile(vfile); diff --git a/platform/lang-impl/src/com/intellij/codeInsight/template/TemplateContextType.java b/platform/lang-impl/src/com/intellij/codeInsight/template/TemplateContextType.java index 126f263248ac..bd17c61d48f0 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/template/TemplateContextType.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/template/TemplateContextType.java @@ -16,9 +16,12 @@ package com.intellij.codeInsight.template; +import com.intellij.openapi.editor.Document; +import com.intellij.openapi.editor.EditorFactory; import com.intellij.openapi.extensions.ExtensionPointName; import com.intellij.openapi.fileTypes.FileType; import com.intellij.openapi.fileTypes.SyntaxHighlighter; +import com.intellij.openapi.project.Project; import com.intellij.psi.PsiFile; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; @@ -77,4 +80,8 @@ public abstract class TemplateContextType { public TemplateContextType getBaseContextType() { return myBaseContextType != null ? EP_NAME.findExtension(myBaseContextType) : null; } + + public Document createDocument(CharSequence text, Project project) { + return EditorFactory.getInstance().createDocument(text); + } } diff --git a/platform/lang-impl/src/com/intellij/codeInsight/template/impl/EditTemplateDialog.java b/platform/lang-impl/src/com/intellij/codeInsight/template/impl/EditTemplateDialog.java index b8c14eda4145..2d2a464ab025 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/template/impl/EditTemplateDialog.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/template/impl/EditTemplateDialog.java @@ -88,7 +88,7 @@ public class EditTemplateDialog extends DialogWrapper { myKeyField=new JTextField(); myDescription=new JTextField(); myGroupCombo=new ComboBox(-1); - myTemplateEditor = TemplateEditorUtil.createEditor(false, myTemplate.getString()); + myTemplateEditor = TemplateEditorUtil.createEditor(false, myTemplate.getString(), context); init(); reset(); diff --git a/platform/lang-impl/src/com/intellij/codeInsight/template/impl/TemplateEditorUtil.java b/platform/lang-impl/src/com/intellij/codeInsight/template/impl/TemplateEditorUtil.java index 17f88f199c63..4d219df8e294 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/template/impl/TemplateEditorUtil.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/template/impl/TemplateEditorUtil.java @@ -17,9 +17,11 @@ package com.intellij.codeInsight.template.impl; import com.intellij.codeInsight.template.TemplateContextType; +import com.intellij.ide.DataManager; import com.intellij.lexer.CompositeLexer; import com.intellij.lexer.Lexer; import com.intellij.lexer.MergingLexerAdapter; +import com.intellij.openapi.actionSystem.PlatformDataKeys; import com.intellij.openapi.editor.Document; import com.intellij.openapi.editor.Editor; import com.intellij.openapi.editor.EditorFactory; @@ -33,15 +35,39 @@ import com.intellij.openapi.editor.ex.util.LexerEditorHighlighter; import com.intellij.openapi.fileTypes.PlainSyntaxHighlighter; import com.intellij.openapi.fileTypes.SyntaxHighlighter; import com.intellij.openapi.fileTypes.SyntaxHighlighterBase; +import com.intellij.openapi.project.Project; import com.intellij.psi.tree.IElementType; import com.intellij.psi.tree.TokenSet; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.util.Map; public class TemplateEditorUtil { - public static Editor createEditor(boolean isReadOnly, final CharSequence text) { + private TemplateEditorUtil() {} + + public static Editor createEditor(boolean isReadOnly, CharSequence text) { + return createEditor(isReadOnly, text, null); + } + + public static Editor createEditor(boolean isReadOnly, CharSequence text, @Nullable Map context) { + Document doc = EditorFactory.getInstance().createDocument(text); + final Project project = PlatformDataKeys.PROJECT.getData(DataManager.getInstance().getDataContext()); + if (context != null) { + for (Map.Entry entry : context.entrySet()) { + if (entry.getValue()) { + doc = entry.getKey().createDocument(text, project); + break; + } + } + } + + return createEditor(isReadOnly, doc, project); + } + + private static Editor createEditor(boolean isReadOnly, final Document document, final Project project) { EditorFactory editorFactory = EditorFactory.getInstance(); - Document doc = editorFactory.createDocument(text); - Editor editor = (isReadOnly ? editorFactory.createViewer(doc) : editorFactory.createEditor(doc)); + Editor editor = (isReadOnly ? editorFactory.createViewer(document, project) : editorFactory.createEditor(document, project)); EditorSettings editorSettings = editor.getSettings(); editorSettings.setVirtualSpace(false); diff --git a/platform/lang-impl/src/com/intellij/codeInspection/reference/RefModuleImpl.java b/platform/lang-impl/src/com/intellij/codeInspection/reference/RefModuleImpl.java index 455c4490e6da..89ab7b9e7ab4 100644 --- a/platform/lang-impl/src/com/intellij/codeInspection/reference/RefModuleImpl.java +++ b/platform/lang-impl/src/com/intellij/codeInspection/reference/RefModuleImpl.java @@ -3,6 +3,7 @@ package com.intellij.codeInspection.reference; import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.module.Module; import com.intellij.openapi.module.ModuleManager; +import com.intellij.openapi.module.ModuleType; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -57,7 +58,7 @@ public class RefModuleImpl extends RefEntityImpl implements RefModule { } public Icon getIcon(final boolean expanded) { - return getModule().getModuleType().getNodeIcon(expanded); + return ModuleType.get(getModule()).getNodeIcon(expanded); } @Nullable diff --git a/platform/lang-impl/src/com/intellij/codeInspection/ui/InspectionModuleNode.java b/platform/lang-impl/src/com/intellij/codeInspection/ui/InspectionModuleNode.java index eb355303165c..ff16feef19b2 100644 --- a/platform/lang-impl/src/com/intellij/codeInspection/ui/InspectionModuleNode.java +++ b/platform/lang-impl/src/com/intellij/codeInspection/ui/InspectionModuleNode.java @@ -1,6 +1,7 @@ package com.intellij.codeInspection.ui; import com.intellij.openapi.module.Module; +import com.intellij.openapi.module.ModuleType; import javax.swing.*; @@ -16,7 +17,7 @@ public class InspectionModuleNode extends InspectionTreeNode{ } public Icon getIcon(boolean expanded) { - return myModule.getModuleType().getNodeIcon(expanded); + return ModuleType.get(myModule).getNodeIcon(expanded); } public String getName(){ diff --git a/platform/lang-impl/src/com/intellij/facet/FacetManagerImpl.java b/platform/lang-impl/src/com/intellij/facet/FacetManagerImpl.java index 451c3a505bed..4cb3f4e56fb9 100644 --- a/platform/lang-impl/src/com/intellij/facet/FacetManagerImpl.java +++ b/platform/lang-impl/src/com/intellij/facet/FacetManagerImpl.java @@ -169,7 +169,7 @@ public class FacetManagerImpl extends FacetManager implements ModuleComponent, P continue; } - ModuleType moduleType = myModule.getModuleType(); + ModuleType moduleType = ModuleType.get(myModule); if (!type.isSuitableModuleType(moduleType)) { addInvalidFacet(child, model, underlyingFacet, ProjectBundle.message("error.message.0.facets.are.not.allowed.in.1", type.getPresentableName(), moduleType.getName())); diff --git a/platform/lang-impl/src/com/intellij/facet/impl/statistics/ModuleTypeUsagesCollector.java b/platform/lang-impl/src/com/intellij/facet/impl/statistics/ModuleTypeUsagesCollector.java index 397fd724c1ec..1f14356d9968 100644 --- a/platform/lang-impl/src/com/intellij/facet/impl/statistics/ModuleTypeUsagesCollector.java +++ b/platform/lang-impl/src/com/intellij/facet/impl/statistics/ModuleTypeUsagesCollector.java @@ -20,6 +20,7 @@ import com.intellij.internal.statistic.beans.GroupDescriptor; import com.intellij.internal.statistic.beans.UsageDescriptor; import com.intellij.openapi.module.Module; import com.intellij.openapi.module.ModuleManager; +import com.intellij.openapi.module.ModuleType; import com.intellij.openapi.project.Project; import com.intellij.util.Function; import com.intellij.util.containers.ContainerUtil; @@ -42,7 +43,7 @@ public class ModuleTypeUsagesCollector extends AbstractApplicationUsagesCollecto public Set getProjectUsages(@NotNull Project project) { Set modulesTypes = new HashSet(); for (Module module : ModuleManager.getInstance(project).getModules()) { - modulesTypes.add(module.getModuleType().getId()); + modulesTypes.add(ModuleType.get(module).getId()); } return ContainerUtil.map2Set(modulesTypes, new Function() { @Override diff --git a/platform/lang-impl/src/com/intellij/find/findUsages/CommonFindUsagesDialog.java b/platform/lang-impl/src/com/intellij/find/findUsages/CommonFindUsagesDialog.java index b803e272370d..b46be8cf1102 100644 --- a/platform/lang-impl/src/com/intellij/find/findUsages/CommonFindUsagesDialog.java +++ b/platform/lang-impl/src/com/intellij/find/findUsages/CommonFindUsagesDialog.java @@ -21,6 +21,7 @@ import com.intellij.openapi.project.Project; import com.intellij.openapi.util.text.StringUtil; import com.intellij.psi.PsiElement; import com.intellij.psi.search.LocalSearchScope; +import com.intellij.psi.search.PsiSearchHelper; import com.intellij.ui.SimpleColoredComponent; import com.intellij.ui.SimpleTextAttributes; import com.intellij.usageView.UsageViewUtil; @@ -51,7 +52,7 @@ public class CommonFindUsagesDialog extends AbstractFindUsagesDialog { @Override protected boolean isInFileOnly() { return super.isInFileOnly() || - myPsiElement != null && myPsiElement.getManager().getSearchHelper().getUseScope(myPsiElement)instanceof LocalSearchScope; + myPsiElement != null && PsiSearchHelper.SERVICE.getInstance(myPsiElement.getProject()).getUseScope(myPsiElement)instanceof LocalSearchScope; } protected JPanel createFindWhatPanel() { diff --git a/platform/lang-impl/src/com/intellij/find/findUsages/FindUsagesManager.java b/platform/lang-impl/src/com/intellij/find/findUsages/FindUsagesManager.java index 08c62c3f18e7..33b1dbfc804a 100644 --- a/platform/lang-impl/src/com/intellij/find/findUsages/FindUsagesManager.java +++ b/platform/lang-impl/src/com/intellij/find/findUsages/FindUsagesManager.java @@ -46,10 +46,7 @@ import com.intellij.openapi.util.*; import com.intellij.openapi.util.text.StringUtil; import com.intellij.openapi.wm.StatusBar; import com.intellij.psi.*; -import com.intellij.psi.search.LocalSearchScope; -import com.intellij.psi.search.SearchRequestCollector; -import com.intellij.psi.search.SearchScope; -import com.intellij.psi.search.SearchSession; +import com.intellij.psi.search.*; import com.intellij.psi.util.PsiUtilBase; import com.intellij.ui.LightweightHint; import com.intellij.ui.content.Content; @@ -431,11 +428,12 @@ public class FindUsagesManager implements JDOMExternalizable { return scopeFile != null ? scopeFile.getProject() : !elements.isEmpty() ? elements.get(0).getProject() : handler.getProject(); } }); - PsiManager.getInstance(project).getSearchHelper().processRequests(options.fastTrack, new ReadActionProcessor() { - public boolean processInReadAction(final PsiReference ref) { - return usageInfoProcessor.process(new UsageInfo(ref)); - } - }); + PsiSearchHelper.SERVICE.getInstance(project) + .processRequests(options.fastTrack, new ReadActionProcessor() { + public boolean processInReadAction(final PsiReference ref) { + return usageInfoProcessor.process(new UsageInfo(ref)); + } + }); } finally { options.fastTrack = null; diff --git a/platform/lang-impl/src/com/intellij/find/impl/FindInProjectUtil.java b/platform/lang-impl/src/com/intellij/find/impl/FindInProjectUtil.java index 71a459a6c037..0383f854bc5d 100644 --- a/platform/lang-impl/src/com/intellij/find/impl/FindInProjectUtil.java +++ b/platform/lang-impl/src/com/intellij/find/impl/FindInProjectUtil.java @@ -447,7 +447,7 @@ public class FindInProjectUtil { CacheManager cacheManager = ((PsiManagerEx)pm).getCacheManager(); SearchScope customScope = findModel.getCustomScope(); @NotNull GlobalSearchScope scope = psiDirectory != null - ? GlobalSearchScope.directoryScope(psiDirectory, true) + ? GlobalSearchScopes.directoryScope(psiDirectory, true) : module != null ? moduleContentScope(module) : customScope instanceof GlobalSearchScope @@ -534,7 +534,7 @@ public class FindInProjectUtil { for (VirtualFile root : contentRoots) { PsiDirectory directory = psiManager.findDirectory(root); if (directory != null) { - GlobalSearchScope moduleContent = GlobalSearchScope.directoryScope(directory, true); + GlobalSearchScope moduleContent = GlobalSearchScopes.directoryScope(directory, true); result = result == null ? moduleContent : result.uniteWith(moduleContent); } } diff --git a/platform/lang-impl/src/com/intellij/ide/hierarchy/HierarchyTreeStructure.java b/platform/lang-impl/src/com/intellij/ide/hierarchy/HierarchyTreeStructure.java index 12ca4c836848..dc8d8709ce97 100644 --- a/platform/lang-impl/src/com/intellij/ide/hierarchy/HierarchyTreeStructure.java +++ b/platform/lang-impl/src/com/intellij/ide/hierarchy/HierarchyTreeStructure.java @@ -25,6 +25,7 @@ import com.intellij.psi.PsiDocumentManager; import com.intellij.psi.PsiElement; import com.intellij.psi.PsiFile; import com.intellij.psi.search.GlobalSearchScope; +import com.intellij.psi.search.GlobalSearchScopes; import com.intellij.psi.search.LocalSearchScope; import com.intellij.psi.search.SearchScope; import com.intellij.psi.search.scope.packageSet.NamedScope; @@ -142,14 +143,14 @@ public abstract class HierarchyTreeStructure extends AbstractTreeStructure { searchScope = new LocalSearchScope(thisClass); } else if (HierarchyBrowserBaseEx.SCOPE_PROJECT.equals(scopeType)) { - searchScope = GlobalSearchScope.projectProductionScope(myProject); + searchScope = GlobalSearchScopes.projectProductionScope(myProject); } else if (HierarchyBrowserBaseEx.SCOPE_TEST.equals(scopeType)) { - searchScope = GlobalSearchScope.projectTestScope(myProject); + searchScope = GlobalSearchScopes.projectTestScope(myProject); } else { final NamedScope namedScope = NamedScopesHolder.getScope(myProject, scopeType); if (namedScope != null) { - searchScope = GlobalSearchScope.filterScope(myProject, namedScope); + searchScope = GlobalSearchScopes.filterScope(myProject, namedScope); } } return searchScope; diff --git a/platform/lang-impl/src/com/intellij/ide/navigationToolbar/NavBarPresentation.java b/platform/lang-impl/src/com/intellij/ide/navigationToolbar/NavBarPresentation.java index 22978bfc0569..cac639843895 100644 --- a/platform/lang-impl/src/com/intellij/ide/navigationToolbar/NavBarPresentation.java +++ b/platform/lang-impl/src/com/intellij/ide/navigationToolbar/NavBarPresentation.java @@ -21,6 +21,7 @@ import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.extensions.Extensions; import com.intellij.openapi.module.Module; import com.intellij.openapi.module.ModuleManager; +import com.intellij.openapi.module.ModuleType; import com.intellij.openapi.module.ModuleUtil; import com.intellij.openapi.project.IndexNotReadyException; import com.intellij.openapi.project.Project; @@ -64,7 +65,7 @@ public class NavBarPresentation { public static Icon getIcon(final Object object, final boolean open) { if (!NavBarModel.isValid(object)) return null; if (object instanceof Project) return PROJECT_ICON; - if (object instanceof Module) return ((Module)object).getModuleType().getNodeIcon(false); + if (object instanceof Module) return ModuleType.get(((Module)object)).getNodeIcon(false); try { if (object instanceof PsiElement) { return ApplicationManager.getApplication().runReadAction(new Computable() { @@ -80,7 +81,7 @@ public class NavBarPresentation { } if (object instanceof JdkOrderEntry) return ((JdkOrderEntry)object).getJdk().getSdkType().getIcon(); if (object instanceof LibraryOrderEntry) return IconLoader.getIcon("/nodes/ppLibClosed.png"); - if (object instanceof ModuleOrderEntry) return ((ModuleOrderEntry)object).getModule().getModuleType().getNodeIcon(false); + if (object instanceof ModuleOrderEntry) return ModuleType.get(((ModuleOrderEntry)object).getModule()).getNodeIcon(false); return null; } diff --git a/platform/lang-impl/src/com/intellij/ide/projectView/impl/nodes/AbstractModuleNode.java b/platform/lang-impl/src/com/intellij/ide/projectView/impl/nodes/AbstractModuleNode.java index 7dbc52abe646..db02417b443c 100644 --- a/platform/lang-impl/src/com/intellij/ide/projectView/impl/nodes/AbstractModuleNode.java +++ b/platform/lang-impl/src/com/intellij/ide/projectView/impl/nodes/AbstractModuleNode.java @@ -19,6 +19,7 @@ import com.intellij.ide.projectView.PresentationData; import com.intellij.ide.projectView.ProjectViewNode; import com.intellij.ide.projectView.ViewSettings; import com.intellij.openapi.module.Module; +import com.intellij.openapi.module.ModuleType; import com.intellij.openapi.project.Project; import com.intellij.openapi.roots.ModuleRootManager; import com.intellij.openapi.roots.ui.configuration.ProjectSettingsService; @@ -47,8 +48,8 @@ public abstract class AbstractModuleNode extends ProjectViewNode impleme presentation.addText(getValue().getName(), SimpleTextAttributes.REGULAR_BOLD_ATTRIBUTES); } - presentation.setOpenIcon(getValue().getModuleType().getNodeIcon(true)); - presentation.setClosedIcon(getValue().getModuleType().getNodeIcon(false)); + presentation.setOpenIcon(ModuleType.get(getValue()).getNodeIcon(true)); + presentation.setClosedIcon(ModuleType.get(getValue()).getNodeIcon(false)); } protected boolean showModuleNameInBold() { @@ -86,7 +87,7 @@ public abstract class AbstractModuleNode extends ProjectViewNode impleme public String getToolTip() { final Module module = getValue(); - return module.getModuleType().getName(); + return ModuleType.get(module).getName(); } public void navigate(final boolean requestFocus) { diff --git a/platform/lang-impl/src/com/intellij/ide/scopeView/ScopeTreeViewPanel.java b/platform/lang-impl/src/com/intellij/ide/scopeView/ScopeTreeViewPanel.java index ebf32de8a978..2c5c679941b9 100644 --- a/platform/lang-impl/src/com/intellij/ide/scopeView/ScopeTreeViewPanel.java +++ b/platform/lang-impl/src/com/intellij/ide/scopeView/ScopeTreeViewPanel.java @@ -402,6 +402,7 @@ public class ScopeTreeViewPanel extends JPanel implements Disposable { final DefaultTreeModel treeModel = (DefaultTreeModel)myTree.getModel(); if (rootToReload != null && rootToReload != treeModel.getRoot()) { final List treePaths = TreeUtil.collectExpandedPaths(myTree, new TreePath(rootToReload.getPath())); + final List selectionPaths = TreeUtil.collectSelectedPaths(myTree, new TreePath(rootToReload.getPath())); treeModel.reload(rootToReload); final TreePath path = new TreePath(rootToReload.getPath()); final boolean wasCollapsed = myTree.isCollapsed(path); @@ -412,6 +413,9 @@ public class ScopeTreeViewPanel extends JPanel implements Disposable { for (TreePath treePath : treePaths) { myTree.expandPath(treePath); } + for (TreePath selectionPath : selectionPaths) { + TreeUtil.selectPath(myTree, selectionPath); + } } TreeUtil.sort(rootToReload, getNodeComparator()); } @@ -511,7 +515,10 @@ public class ScopeTreeViewPanel extends JPanel implements Disposable { processNodeCreation(child); } } else { - reload((DefaultMutableTreeNode)myBuilder.addDirNode((PsiDirectory)psiElement).getParent()); + final PackageDependenciesNode node = myBuilder.addDirNode((PsiDirectory)psiElement); + if (node != null) { + reload((DefaultMutableTreeNode)node.getParent()); + } } } } diff --git a/platform/lang-impl/src/com/intellij/ide/todo/TodoTreeBuilder.java b/platform/lang-impl/src/com/intellij/ide/todo/TodoTreeBuilder.java index da4b9b3d9294..a0c783cfaf65 100644 --- a/platform/lang-impl/src/com/intellij/ide/todo/TodoTreeBuilder.java +++ b/platform/lang-impl/src/com/intellij/ide/todo/TodoTreeBuilder.java @@ -99,7 +99,7 @@ public abstract class TodoTreeBuilder extends AbstractTreeBuilder { myFile2Highlighter = new HashMap(); PsiManager psiManager = PsiManager.getInstance(myProject); - mySearchHelper = psiManager.getSearchHelper(); + mySearchHelper = PsiSearchHelper.SERVICE.getInstance(myProject); psiManager.addPsiTreeChangeListener(new MyPsiTreeChangeListener()); myFileStatusListener = new MyFileStatusListener(); diff --git a/platform/lang-impl/src/com/intellij/ide/todo/TodoTreeStructure.java b/platform/lang-impl/src/com/intellij/ide/todo/TodoTreeStructure.java index e0c8a4a94236..03a550b848a3 100644 --- a/platform/lang-impl/src/com/intellij/ide/todo/TodoTreeStructure.java +++ b/platform/lang-impl/src/com/intellij/ide/todo/TodoTreeStructure.java @@ -23,7 +23,6 @@ import com.intellij.ide.util.treeView.NodeDescriptor; import com.intellij.openapi.project.Project; import com.intellij.psi.PsiDocumentManager; import com.intellij.psi.PsiFile; -import com.intellij.psi.PsiManager; import com.intellij.psi.search.PsiSearchHelper; import com.intellij.psi.search.PsiTodoSearchHelper; import com.intellij.psi.search.TodoPattern; @@ -55,8 +54,7 @@ public abstract class TodoTreeStructure extends AbstractTreeStructureBase implem super(project); myArePackagesShown=true; mySummaryElement=new ToDoSummary(); - PsiManager psiManager = PsiManager.getInstance(project); - mySearchHelper= psiManager.getSearchHelper(); + mySearchHelper= PsiSearchHelper.SERVICE.getInstance(project); } final void setTreeBuilder(TodoTreeBuilder builder){ diff --git a/platform/lang-impl/src/com/intellij/ide/todo/nodes/ModuleToDoNode.java b/platform/lang-impl/src/com/intellij/ide/todo/nodes/ModuleToDoNode.java index b732a6950f4c..75f60b3b5e05 100644 --- a/platform/lang-impl/src/com/intellij/ide/todo/nodes/ModuleToDoNode.java +++ b/platform/lang-impl/src/com/intellij/ide/todo/nodes/ModuleToDoNode.java @@ -27,6 +27,7 @@ import com.intellij.openapi.editor.colors.EditorColorsScheme; import com.intellij.openapi.editor.markup.TextAttributes; import com.intellij.openapi.ide.CopyPasteManager; import com.intellij.openapi.module.Module; +import com.intellij.openapi.module.ModuleType; import com.intellij.openapi.project.Project; import com.intellij.openapi.roots.ModuleRootManager; import com.intellij.openapi.util.Computable; @@ -96,8 +97,8 @@ public class ModuleToDoNode extends BaseToDoNode implements HighlightedR EditorColorsScheme colorsScheme = UsageTreeColorsScheme.getInstance().getScheme(); myHighlightedRegions.add( new HighlightedRegion(nameEndOffset, newName.length(), colorsScheme.getAttributes(UsageTreeColors.NUMBER_OF_USAGES))); - presentation.setOpenIcon(getValue().getModuleType().getNodeIcon(true)); - presentation.setClosedIcon(getValue().getModuleType().getNodeIcon(false)); + presentation.setOpenIcon(ModuleType.get(getValue()).getNodeIcon(true)); + presentation.setClosedIcon(ModuleType.get(getValue()).getNodeIcon(false)); presentation.setPresentableText(newName); } diff --git a/platform/lang-impl/src/com/intellij/ide/util/DirectoryChooserModuleTreeView.java b/platform/lang-impl/src/com/intellij/ide/util/DirectoryChooserModuleTreeView.java index 83409382bfbc..d7b6944174a9 100644 --- a/platform/lang-impl/src/com/intellij/ide/util/DirectoryChooserModuleTreeView.java +++ b/platform/lang-impl/src/com/intellij/ide/util/DirectoryChooserModuleTreeView.java @@ -21,6 +21,7 @@ import com.intellij.ide.projectView.impl.ModuleGroupUtil; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.module.Module; import com.intellij.openapi.module.ModuleManager; +import com.intellij.openapi.module.ModuleType; import com.intellij.openapi.project.Project; import com.intellij.openapi.roots.ProjectFileIndex; import com.intellij.openapi.roots.ProjectRootManager; @@ -240,7 +241,7 @@ public class DirectoryChooserModuleTreeView implements DirectoryChooserView { final Module module = (Module)value; append(module.getName(), SimpleTextAttributes.REGULAR_ATTRIBUTES); int flags1 = expanded ? Iconable.ICON_FLAG_OPEN : Iconable.ICON_FLAG_CLOSED; - setIcon(module.getModuleType().getNodeIcon((flags1 & Iconable.ICON_FLAG_OPEN) != 0)); + setIcon(ModuleType.get(module).getNodeIcon((flags1 & Iconable.ICON_FLAG_OPEN) != 0)); } else if (value instanceof ModuleGroup) { append(value.toString(), SimpleTextAttributes.REGULAR_ATTRIBUTES); setIcon(expanded ? PlatformIcons.OPENED_MODULE_GROUP_ICON : PlatformIcons.CLOSED_MODULE_GROUP_ICON); diff --git a/platform/lang-impl/src/com/intellij/ide/util/PlatformPackageUtil.java b/platform/lang-impl/src/com/intellij/ide/util/PlatformPackageUtil.java index 62c13ef62938..4d152236e64a 100644 --- a/platform/lang-impl/src/com/intellij/ide/util/PlatformPackageUtil.java +++ b/platform/lang-impl/src/com/intellij/ide/util/PlatformPackageUtil.java @@ -35,6 +35,7 @@ import com.intellij.psi.PsiElement; import com.intellij.psi.PsiFile; import com.intellij.psi.PsiManager; import com.intellij.psi.search.GlobalSearchScope; +import com.intellij.psi.search.GlobalSearchScopes; import com.intellij.util.*; import com.intellij.util.containers.ContainerUtil; import org.jetbrains.annotations.NotNull; @@ -183,12 +184,12 @@ public class PlatformPackageUtil { final ProjectFileIndex fileIndex = ProjectRootManager.getInstance(baseDir.getProject()).getFileIndex(); if (fileIndex.isInTestSourceContent(baseDir.getVirtualFile())) { if (skipSourceDirsForBaseTestDirectory) { - return scope.intersectWith(GlobalSearchScope.projectTestScope(baseDir.getProject())); + return scope.intersectWith(GlobalSearchScopes.projectTestScope(baseDir.getProject())); } } else { if (skipTestDirsForBaseSourceDirectory) { - return scope.intersectWith(GlobalSearchScope.projectProductionScope(baseDir.getProject())); + return scope.intersectWith(GlobalSearchScopes.projectProductionScope(baseDir.getProject())); } } } diff --git a/platform/lang-impl/src/com/intellij/ide/util/PsiElementModuleRenderer.java b/platform/lang-impl/src/com/intellij/ide/util/PsiElementModuleRenderer.java index 4a5c108b5744..3271e723cbc6 100644 --- a/platform/lang-impl/src/com/intellij/ide/util/PsiElementModuleRenderer.java +++ b/platform/lang-impl/src/com/intellij/ide/util/PsiElementModuleRenderer.java @@ -17,6 +17,7 @@ package com.intellij.ide.util; import com.intellij.openapi.module.Module; +import com.intellij.openapi.module.ModuleType; import com.intellij.openapi.module.ModuleUtil; import com.intellij.openapi.roots.*; import com.intellij.openapi.util.IconLoader; @@ -77,7 +78,7 @@ public class PsiElementModuleRenderer extends DefaultListCellRenderer{ setIcon(TEST_ICON); } else { - setIcon(module.getModuleType().getNodeIcon(false)); + setIcon(ModuleType.get(module).getNodeIcon(false)); } } else { if (psiFile != null) { diff --git a/platform/lang-impl/src/com/intellij/ide/util/scopeChooser/ScopeChooserCombo.java b/platform/lang-impl/src/com/intellij/ide/util/scopeChooser/ScopeChooserCombo.java index 7bc8fd2d72b3..de1fa0f00566 100644 --- a/platform/lang-impl/src/com/intellij/ide/util/scopeChooser/ScopeChooserCombo.java +++ b/platform/lang-impl/src/com/intellij/ide/util/scopeChooser/ScopeChooserCombo.java @@ -36,10 +36,7 @@ import com.intellij.psi.PsiDocumentManager; import com.intellij.psi.PsiElement; import com.intellij.psi.PsiFile; import com.intellij.psi.PsiWhiteSpace; -import com.intellij.psi.search.DelegatingGlobalSearchScope; -import com.intellij.psi.search.GlobalSearchScope; -import com.intellij.psi.search.LocalSearchScope; -import com.intellij.psi.search.SearchScope; +import com.intellij.psi.search.*; import com.intellij.psi.search.scope.packageSet.NamedScope; import com.intellij.psi.search.scope.packageSet.NamedScopeManager; import com.intellij.psi.search.scope.packageSet.NamedScopesHolder; @@ -165,13 +162,13 @@ public class ScopeChooserCombo extends ComboboxWithBrowseButton implements Dispo List changeLists = ChangeListsScopesProvider.getInstance(myProject).getCustomScopes(); for (NamedScope changeListScope : changeLists) { - model.addElement(new ScopeDescriptor(GlobalSearchScope.filterScope(myProject, changeListScope))); + model.addElement(new ScopeDescriptor(GlobalSearchScopes.filterScope(myProject, changeListScope))); } final NamedScopesHolder[] holders = NamedScopesHolder.getAllNamedScopeHolders(myProject); for (NamedScopesHolder holder : holders) { NamedScope[] scopes = holder.getEditableScopes(); //predefined scopes already included for (NamedScope scope : scopes) { - model.addElement(new ScopeDescriptor(GlobalSearchScope.filterScope(myProject, scope))); + model.addElement(new ScopeDescriptor(GlobalSearchScopes.filterScope(myProject, scope))); } } @@ -201,8 +198,8 @@ public class ScopeChooserCombo extends ComboboxWithBrowseButton implements Dispo if (suggestSearchInLibs) { result.add(GlobalSearchScope.allScope(project)); } - result.add(GlobalSearchScope.projectProductionScope(project)); - result.add(GlobalSearchScope.projectTestScope(project)); + result.add(GlobalSearchScopes.projectProductionScope(project)); + result.add(GlobalSearchScopes.projectTestScope(project)); if (dataContext != null) { PsiElement dataContextElement = getDataContextElement(dataContext); @@ -350,7 +347,7 @@ public class ScopeChooserCombo extends ComboboxWithBrowseButton implements Dispo final VirtualFile[] files = PlatformDataKeys.VIRTUAL_FILE_ARRAY.getData(dataContext); if (files != null) { final List openFiles = Arrays.asList(files); - result.add(new DelegatingGlobalSearchScope(GlobalSearchScope.filesScope(project, openFiles)){ + result.add(new DelegatingGlobalSearchScope(GlobalSearchScopes.filesScope(project, openFiles)){ @Override public String getDisplayName() { return "Selected files"; diff --git a/platform/lang-impl/src/com/intellij/mock/MockPsiManager.java b/platform/lang-impl/src/com/intellij/mock/MockPsiManager.java index 9202a14aa589..7176f6764b7b 100644 --- a/platform/lang-impl/src/com/intellij/mock/MockPsiManager.java +++ b/platform/lang-impl/src/com/intellij/mock/MockPsiManager.java @@ -32,7 +32,6 @@ import com.intellij.psi.impl.cache.CacheManager; import com.intellij.psi.impl.cache.impl.CompositeCacheManager; import com.intellij.psi.impl.file.impl.FileManager; import com.intellij.psi.impl.search.PsiSearchHelperImpl; -import com.intellij.psi.impl.source.PostprocessReformattingAspect; import com.intellij.psi.impl.source.resolve.ResolveCache; import com.intellij.psi.search.PsiSearchHelper; import com.intellij.psi.util.CachedValuesManager; @@ -190,10 +189,6 @@ public class MockPsiManager extends PsiManagerEx { public void dropFileCaches(@NotNull PsiFile file) { } - public void postponeAutoFormattingInside(Runnable runnable) { - PostprocessReformattingAspect.getInstance(getProject()).postponeFormattingInside(runnable); - } - @NotNull public List getLanguageInjectors() { return Collections.emptyList(); diff --git a/platform/lang-impl/src/com/intellij/moduleDependencies/ModulesDependenciesPanel.java b/platform/lang-impl/src/com/intellij/moduleDependencies/ModulesDependenciesPanel.java index 53564cc8c009..0f074ee65eae 100644 --- a/platform/lang-impl/src/com/intellij/moduleDependencies/ModulesDependenciesPanel.java +++ b/platform/lang-impl/src/com/intellij/moduleDependencies/ModulesDependenciesPanel.java @@ -27,6 +27,7 @@ import com.intellij.openapi.Disposable; import com.intellij.openapi.actionSystem.*; import com.intellij.openapi.module.Module; import com.intellij.openapi.module.ModuleManager; +import com.intellij.openapi.module.ModuleType; import com.intellij.openapi.progress.ProgressIndicator; import com.intellij.openapi.progress.ProgressManager; import com.intellij.openapi.project.Project; @@ -530,7 +531,7 @@ public class ModulesDependenciesPanel extends JPanel implements ModuleRootListen } MyUserObject node = (MyUserObject)userObject; Module module = node.getModule(); - setIcon(module.getModuleType().getNodeIcon(expanded)); + setIcon(ModuleType.get(module).getNodeIcon(expanded)); if (node.isInCycle()){ append(module.getName(), SimpleTextAttributes.ERROR_ATTRIBUTES); } else { diff --git a/platform/lang-impl/src/com/intellij/openapi/components/impl/stores/ModuleStoreImpl.java b/platform/lang-impl/src/com/intellij/openapi/components/impl/stores/ModuleStoreImpl.java index 74bf0470155a..5d0e994a317c 100644 --- a/platform/lang-impl/src/com/intellij/openapi/components/impl/stores/ModuleStoreImpl.java +++ b/platform/lang-impl/src/com/intellij/openapi/components/impl/stores/ModuleStoreImpl.java @@ -70,7 +70,7 @@ public class ModuleStoreImpl extends BaseFileConfigurableStoreImpl implements IM final ModuleFileData storageData = getMainStorageData(); final String moduleTypeId = storageData.myOptions.get(ModuleImpl.ELEMENT_TYPE); - myModule.setModuleType(ModuleTypeManager.getInstance().findByID(moduleTypeId)); + myModule.setOption(Module.ELEMENT_TYPE, ModuleTypeManager.getInstance().findByID(moduleTypeId).getId()); if (ApplicationManager.getApplication().isHeadlessEnvironment() || ApplicationManager.getApplication().isUnitTestMode()) return; diff --git a/platform/lang-impl/src/com/intellij/openapi/module/impl/ModuleImpl.java b/platform/lang-impl/src/com/intellij/openapi/module/impl/ModuleImpl.java index 58adea10b78f..1c2078e06d2e 100644 --- a/platform/lang-impl/src/com/intellij/openapi/module/impl/ModuleImpl.java +++ b/platform/lang-impl/src/com/intellij/openapi/module/impl/ModuleImpl.java @@ -24,7 +24,6 @@ import com.intellij.openapi.components.impl.ComponentManagerImpl; import com.intellij.openapi.components.impl.ModulePathMacroManager; import com.intellij.openapi.components.impl.stores.IComponentStore; import com.intellij.openapi.components.impl.stores.IModuleStore; -import com.intellij.openapi.components.impl.stores.IProjectStore; import com.intellij.openapi.components.impl.stores.ModuleStoreImpl; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.extensions.AreaInstance; @@ -32,7 +31,6 @@ import com.intellij.openapi.extensions.ExtensionPointName; import com.intellij.openapi.extensions.Extensions; import com.intellij.openapi.module.Module; import com.intellij.openapi.module.ModuleComponent; -import com.intellij.openapi.module.ModuleType; import com.intellij.openapi.module.impl.scopes.ModuleWithDependenciesScope; import com.intellij.openapi.module.impl.scopes.ModuleWithDependentsScope; import com.intellij.openapi.project.Project; @@ -61,11 +59,9 @@ public class ModuleImpl extends ComponentManagerImpl implements Module { private static final Logger LOG = Logger.getInstance("#com.intellij.openapi.module.impl.ModuleImpl"); @NotNull private final Project myProject; - private ModuleType myModuleType = null; private boolean isModuleAdded; @NonNls private static final String OPTION_WORKSPACE = "workspace"; - @NonNls public static final String ELEMENT_TYPE = "type"; private final Map myScopeCache = new StripedLockConcurrentHashMap(); @@ -209,12 +205,6 @@ public class ModuleImpl extends ComponentManagerImpl implements Module { } } - @NotNull - public ModuleType getModuleType() { - LOG.assertTrue(myModuleType != null, "Module type not initialized yet"); - return myModuleType; - } - @NotNull public Project getProject() { return myProject; @@ -236,11 +226,6 @@ public class ModuleImpl extends ComponentManagerImpl implements Module { } } - public void setModuleType(ModuleType type) { - myModuleType = type; - setOption(ELEMENT_TYPE, type.getId()); - } - public void setOption(@NotNull String optionName, @NotNull String optionValue) { getStateStore().setOption(optionName, optionValue); } diff --git a/platform/lang-impl/src/com/intellij/openapi/module/impl/ModuleManagerImpl.java b/platform/lang-impl/src/com/intellij/openapi/module/impl/ModuleManagerImpl.java index 4bc2d0496d0e..250d6862a41e 100644 --- a/platform/lang-impl/src/com/intellij/openapi/module/impl/ModuleManagerImpl.java +++ b/platform/lang-impl/src/com/intellij/openapi/module/impl/ModuleManagerImpl.java @@ -244,7 +244,7 @@ public class ModuleManagerImpl extends ModuleManager implements ProjectComponent for (final ModulePath modulePath : myModulePaths) { try { final Module module = moduleModel.loadModuleInternal(modulePath.getPath()); - if (module.getModuleType() instanceof UnknownModuleType) { + if (ModuleType.get(module) instanceof UnknownModuleType) { modulesWithUnknownTypes.add(module); } final String groupPathString = modulePath.getModuleGroup(); @@ -273,13 +273,13 @@ public class ModuleManagerImpl extends ModuleManager implements ProjectComponent String message; if (modulesWithUnknownTypes.size() == 1) { message = ProjectBundle.message("module.unknown.type.single.error", modulesWithUnknownTypes.get(0).getName(), - modulesWithUnknownTypes.get(0).getModuleType().getId()); + ModuleType.get(modulesWithUnknownTypes.get(0)).getId()); } else { StringBuilder modulesBuilder = new StringBuilder(); for (final Module module : modulesWithUnknownTypes) { modulesBuilder.append("
\""); - modulesBuilder.append(module.getName()).append("\" (type '").append(module.getModuleType().getId()).append("')"); + modulesBuilder.append(module.getName()).append("\" (type '").append(ModuleType.get(module).getId()).append("')"); } modulesBuilder.append("
"); message = ProjectBundle.message("module.unknown.type.multiple.error", modulesBuilder.toString()); @@ -684,7 +684,7 @@ public class ModuleManagerImpl extends ModuleManager implements ProjectComponent ModuleImpl module = getModuleByFilePath(filePath); if (module == null) { module = new ModuleImpl(filePath, myProject); - module.setModuleType(moduleType); + module.setOption(Module.ELEMENT_TYPE, moduleType.getId()); if (options != null) { for ( Map.Entry option : options.entrySet()) { module.setOption(option.getKey(),option.getValue()); diff --git a/platform/lang-impl/src/com/intellij/openapi/roots/ui/configuration/ChooseModulesDialog.java b/platform/lang-impl/src/com/intellij/openapi/roots/ui/configuration/ChooseModulesDialog.java index e26799d7fc67..279fa8c76a0c 100644 --- a/platform/lang-impl/src/com/intellij/openapi/roots/ui/configuration/ChooseModulesDialog.java +++ b/platform/lang-impl/src/com/intellij/openapi/roots/ui/configuration/ChooseModulesDialog.java @@ -23,6 +23,7 @@ package com.intellij.openapi.roots.ui.configuration; import com.intellij.openapi.module.Module; +import com.intellij.openapi.module.ModuleType; import com.intellij.openapi.project.Project; import com.intellij.ide.util.ChooseElementsDialog; import org.jetbrains.annotations.Nullable; @@ -50,7 +51,7 @@ public class ChooseModulesDialog extends ChooseElementsDialog { } protected Icon getItemIcon(final Module item) { - return item.getModuleType().getNodeIcon(false); + return ModuleType.get(item).getNodeIcon(false); } protected String getItemText(final Module item) { diff --git a/platform/lang-impl/src/com/intellij/openapi/roots/ui/configuration/ModulesCombobox.java b/platform/lang-impl/src/com/intellij/openapi/roots/ui/configuration/ModulesCombobox.java index 64a0aa6e69ea..36d6b70a1840 100644 --- a/platform/lang-impl/src/com/intellij/openapi/roots/ui/configuration/ModulesCombobox.java +++ b/platform/lang-impl/src/com/intellij/openapi/roots/ui/configuration/ModulesCombobox.java @@ -18,6 +18,7 @@ package com.intellij.openapi.roots.ui.configuration; import com.intellij.ide.ui.ListCellRendererWrapper; import com.intellij.openapi.module.Module; import com.intellij.openapi.module.ModuleManager; +import com.intellij.openapi.module.ModuleType; import com.intellij.openapi.project.Project; import com.intellij.openapi.ui.ComboBox; import com.intellij.ui.SortedComboBoxModel; @@ -45,7 +46,7 @@ public class ModulesCombobox extends ComboBox { public void customize(JList list, Module value, int index, boolean selected, boolean hasFocus) { if (value != null) { setText(value.getName()); - setIcon(value.getModuleType().getNodeIcon(false)); + setIcon(ModuleType.get(value).getNodeIcon(false)); } else { setText("[none]"); diff --git a/platform/lang-impl/src/com/intellij/openapi/vcs/changes/ui/ChangesBrowserModuleNode.java b/platform/lang-impl/src/com/intellij/openapi/vcs/changes/ui/ChangesBrowserModuleNode.java index 8965746c2ecd..00fb025f7cd2 100644 --- a/platform/lang-impl/src/com/intellij/openapi/vcs/changes/ui/ChangesBrowserModuleNode.java +++ b/platform/lang-impl/src/com/intellij/openapi/vcs/changes/ui/ChangesBrowserModuleNode.java @@ -17,6 +17,7 @@ package com.intellij.openapi.vcs.changes.ui; import com.intellij.openapi.module.Module; +import com.intellij.openapi.module.ModuleType; import com.intellij.openapi.vcs.FilePath; import com.intellij.openapi.vcs.FilePathImpl; import com.intellij.openapi.vfs.VirtualFile; @@ -37,7 +38,7 @@ public class ChangesBrowserModuleNode extends ChangesBrowserNode { renderer.append(module.isDisposed() ? "" : module.getName(), SimpleTextAttributes.REGULAR_ATTRIBUTES); appendCount(renderer); - renderer.setIcon(module.getModuleType().getNodeIcon(expanded)); + renderer.setIcon(ModuleType.get(module).getNodeIcon(expanded)); } @Override diff --git a/platform/lang-impl/src/com/intellij/openapi/vcs/checkin/TodoCheckinHandlerWorker.java b/platform/lang-impl/src/com/intellij/openapi/vcs/checkin/TodoCheckinHandlerWorker.java index cc261cc2de8b..142dc882e729 100644 --- a/platform/lang-impl/src/com/intellij/openapi/vcs/checkin/TodoCheckinHandlerWorker.java +++ b/platform/lang-impl/src/com/intellij/openapi/vcs/checkin/TodoCheckinHandlerWorker.java @@ -81,7 +81,7 @@ public class TodoCheckinHandlerWorker { myTodoFilter = todoFilter; myIncludePattern = includePattern; myPsiManager = PsiManager.getInstance(project); - mySearchHelper = myPsiManager.getSearchHelper(); + mySearchHelper = PsiSearchHelper.SERVICE.getInstance(project); myAddedOrEditedTodos = new ArrayList(); myInChangedTodos = new ArrayList(); mySkipped = new SmartList>(); diff --git a/platform/lang-impl/src/com/intellij/packageDependencies/actions/AnalyzeDependenciesOnSpecifiedTargetHandler.java b/platform/lang-impl/src/com/intellij/packageDependencies/actions/AnalyzeDependenciesOnSpecifiedTargetHandler.java index 623a2ebc1b69..60a10f3b8b53 100644 --- a/platform/lang-impl/src/com/intellij/packageDependencies/actions/AnalyzeDependenciesOnSpecifiedTargetHandler.java +++ b/platform/lang-impl/src/com/intellij/packageDependencies/actions/AnalyzeDependenciesOnSpecifiedTargetHandler.java @@ -64,7 +64,7 @@ public class AnalyzeDependenciesOnSpecifiedTargetHandler extends DependenciesHan final String source = StringUtil.decapitalize(builders.get(0).getScope().getDisplayName()); final String target = StringUtil.decapitalize(myTargetScope.getDisplayName()); final String message = AnalysisScopeBundle.message("no.dependencies.found.message", source, target); - NotificationGroup.toolWindowGroup("Dependencies", ToolWindowId.DEPENDENCIES, true).createNotification("message", MessageType.INFO).notify(myProject); + NotificationGroup.toolWindowGroup("Dependencies", ToolWindowId.DEPENDENCIES, true).createNotification(message, MessageType.INFO).notify(myProject); return false; } diff --git a/platform/lang-impl/src/com/intellij/packageDependencies/ui/FileNode.java b/platform/lang-impl/src/com/intellij/packageDependencies/ui/FileNode.java index bb8a48730cb6..faa4a7324296 100644 --- a/platform/lang-impl/src/com/intellij/packageDependencies/ui/FileNode.java +++ b/platform/lang-impl/src/com/intellij/packageDependencies/ui/FileNode.java @@ -122,6 +122,6 @@ public class FileNode extends PackageDependenciesNode { @Nullable private PsiFile getFile() { - return PsiManager.getInstance(myProject).findFile(myVFile); + return myVFile.isValid() ? PsiManager.getInstance(myProject).findFile(myVFile) : null; } } diff --git a/platform/lang-impl/src/com/intellij/packageDependencies/ui/FileTreeModelBuilder.java b/platform/lang-impl/src/com/intellij/packageDependencies/ui/FileTreeModelBuilder.java index 5e091640d84b..031ddba4f9b9 100644 --- a/platform/lang-impl/src/com/intellij/packageDependencies/ui/FileTreeModelBuilder.java +++ b/platform/lang-impl/src/com/intellij/packageDependencies/ui/FileTreeModelBuilder.java @@ -497,7 +497,7 @@ public class FileTreeModelBuilder { DirectoryNode parentDirectoryNode = myModuleDirNodes.get(directory); if (parentDirectoryNode != null || !myCompactEmptyMiddlePackages - || (sourceRoot != null && VfsUtil.isAncestor(directory, sourceRoot, false)) + || sourceRoot == directory || directory == contentRoot) { getModuleDirNode(directory, module, (DirectoryNode)directoryNode).add(directoryNode); } diff --git a/platform/lang-impl/src/com/intellij/packageDependencies/ui/ModuleNode.java b/platform/lang-impl/src/com/intellij/packageDependencies/ui/ModuleNode.java index cef04e9d092a..1db1b4d5d04e 100644 --- a/platform/lang-impl/src/com/intellij/packageDependencies/ui/ModuleNode.java +++ b/platform/lang-impl/src/com/intellij/packageDependencies/ui/ModuleNode.java @@ -18,6 +18,7 @@ package com.intellij.packageDependencies.ui; import com.intellij.analysis.AnalysisScopeBundle; import com.intellij.openapi.module.Module; +import com.intellij.openapi.module.ModuleType; import com.intellij.openapi.roots.ui.configuration.ProjectSettingsService; import com.intellij.openapi.util.Comparing; import com.intellij.pom.NavigatableWithText; @@ -59,11 +60,11 @@ public class ModuleNode extends PackageDependenciesNode implements NavigatableWi } public Icon getOpenIcon() { - return myModule == null ? null : myModule.getModuleType().getNodeIcon(true); + return myModule == null ? null : ModuleType.get(myModule).getNodeIcon(true); } public Icon getClosedIcon() { - return myModule == null ? null : myModule.getModuleType().getNodeIcon(false); + return myModule == null ? null : ModuleType.get(myModule).getNodeIcon(false); } public String toString() { diff --git a/platform/lang-impl/src/com/intellij/psi/DummyHolderViewProvider.java b/platform/lang-impl/src/com/intellij/psi/DummyHolderViewProvider.java index cb0c4342970c..1a7a7e1d7517 100644 --- a/platform/lang-impl/src/com/intellij/psi/DummyHolderViewProvider.java +++ b/platform/lang-impl/src/com/intellij/psi/DummyHolderViewProvider.java @@ -141,7 +141,8 @@ public class DummyHolderViewProvider extends UserDataHolderBase implements FileV } @NotNull - public FileViewProvider createCopy(final LightVirtualFile copy) { + @Override + public FileViewProvider createCopy(final VirtualFile copy) { throw new RuntimeException("Clone is not supported for DummyHolderProviders. Use DummyHolder clone directly."); } diff --git a/platform/lang-impl/src/com/intellij/psi/MultiplePsiFilesPerDocumentFileViewProvider.java b/platform/lang-impl/src/com/intellij/psi/MultiplePsiFilesPerDocumentFileViewProvider.java index 68e9a0e19b28..b47360c3f1eb 100644 --- a/platform/lang-impl/src/com/intellij/psi/MultiplePsiFilesPerDocumentFileViewProvider.java +++ b/platform/lang-impl/src/com/intellij/psi/MultiplePsiFilesPerDocumentFileViewProvider.java @@ -123,7 +123,8 @@ public abstract class MultiplePsiFilesPerDocumentFileViewProvider extends Single } @NotNull - public final MultiplePsiFilesPerDocumentFileViewProvider createCopy(final LightVirtualFile fileCopy) { + @Override + public final MultiplePsiFilesPerDocumentFileViewProvider createCopy(final VirtualFile fileCopy) { final MultiplePsiFilesPerDocumentFileViewProvider copy = cloneInner(fileCopy); copy.myOriginal = myOriginal == null ? this : myOriginal; return copy; diff --git a/platform/lang-impl/src/com/intellij/psi/SingleRootFileViewProvider.java b/platform/lang-impl/src/com/intellij/psi/SingleRootFileViewProvider.java index 3ff629e7e250..094062b4c51c 100644 --- a/platform/lang-impl/src/com/intellij/psi/SingleRootFileViewProvider.java +++ b/platform/lang-impl/src/com/intellij/psi/SingleRootFileViewProvider.java @@ -337,7 +337,8 @@ public class SingleRootFileViewProvider extends UserDataHolderBase implements Fi } @NotNull - public SingleRootFileViewProvider createCopy(final LightVirtualFile copy) { + @Override + public SingleRootFileViewProvider createCopy(final VirtualFile copy) { return new SingleRootFileViewProvider(getManager(), copy, false, myBaseLanguage); } diff --git a/platform/lang-impl/src/com/intellij/psi/impl/PsiManagerImpl.java b/platform/lang-impl/src/com/intellij/psi/impl/PsiManagerImpl.java index 70a0900e4277..1d0dbeac7c87 100644 --- a/platform/lang-impl/src/com/intellij/psi/impl/PsiManagerImpl.java +++ b/platform/lang-impl/src/com/intellij/psi/impl/PsiManagerImpl.java @@ -41,20 +41,17 @@ import com.intellij.openapi.util.NotNullLazyValue; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.openapi.vfs.VirtualFileFilter; import com.intellij.psi.*; -import com.intellij.psi.codeStyle.CodeStyleManager; import com.intellij.psi.impl.cache.CacheManager; import com.intellij.psi.impl.cache.impl.CacheUtil; import com.intellij.psi.impl.cache.impl.CompositeCacheManager; import com.intellij.psi.impl.cache.impl.IndexCacheManagerImpl; import com.intellij.psi.impl.file.impl.FileManager; import com.intellij.psi.impl.file.impl.FileManagerImpl; -import com.intellij.psi.impl.search.PsiSearchHelperImpl; import com.intellij.psi.impl.source.PostprocessReformattingAspect; import com.intellij.psi.impl.source.PsiFileImpl; import com.intellij.psi.impl.source.resolve.ResolveCache; import com.intellij.psi.impl.source.tree.injected.InjectedLanguageManagerImpl; import com.intellij.psi.impl.source.tree.injected.InjectedLanguageUtil; -import com.intellij.psi.search.PsiSearchHelper; import com.intellij.psi.util.CachedValuesManager; import com.intellij.psi.util.PsiModificationTracker; import com.intellij.refactoring.move.moveFilesOrDirectories.MoveFilesOrDirectoriesUtil; @@ -79,7 +76,6 @@ public class PsiManagerImpl extends PsiManagerEx implements ProjectComponent { private final MessageBus myMessageBus; private final FileManager myFileManager; - private final PsiSearchHelperImpl mySearchHelper; private final CacheManager myCacheManager; private final PsiModificationTrackerImpl myModificationTracker; private final ResolveCache myResolveCache; @@ -123,7 +119,6 @@ public class PsiManagerImpl extends PsiManagerEx implements ProjectComponent { myFileManager = isProjectDefault ? new EmptyFileManager(this) : new FileManagerImpl(this, fileTypeManager, fileDocumentManager, projectRootManagerEx); - mySearchHelper = new PsiSearchHelperImpl(this); final CompositeCacheManager cacheManager = new CompositeCacheManager(); if (isProjectDefault) { cacheManager.addCacheManager(new EmptyCacheManager()); @@ -271,10 +266,6 @@ public class PsiManagerImpl extends PsiManagerEx implements ProjectComponent { InjectedLanguageManagerImpl.getInstanceImpl(myProject).psiManagerInjectorsChanged(); } - public void postponeAutoFormattingInside(Runnable runnable) { - PostprocessReformattingAspect.getInstance(getProject()).postponeFormattingInside(runnable); - } - public void projectClosed() { } @@ -326,11 +317,6 @@ public class PsiManagerImpl extends PsiManagerEx implements ProjectComponent { return myCacheManager; } - @NotNull - public CodeStyleManager getCodeStyleManager() { - return CodeStyleManager.getInstance(myProject); - } - @NotNull public ResolveCache getResolveCache() { ProgressManager.checkCanceled(); // We hope this method is being called often enough to cancel daemon processes smoothly @@ -701,11 +687,6 @@ public class PsiManagerImpl extends PsiManagerEx implements ProjectComponent { myMessageBus.syncPublisher(ANY_PSI_CHANGE_TOPIC).afterPsiChanged(isPhysical); } - @NotNull - public PsiSearchHelper getSearchHelper() { - return mySearchHelper; - } - @NotNull public PsiModificationTracker getModificationTracker() { return myModificationTracker; diff --git a/platform/lang-impl/src/com/intellij/psi/impl/cache/impl/IndexCacheManagerImpl.java b/platform/lang-impl/src/com/intellij/psi/impl/cache/impl/IndexCacheManagerImpl.java index 07a62799ea0e..2d63018bfa56 100644 --- a/platform/lang-impl/src/com/intellij/psi/impl/cache/impl/IndexCacheManagerImpl.java +++ b/platform/lang-impl/src/com/intellij/psi/impl/cache/impl/IndexCacheManagerImpl.java @@ -36,6 +36,7 @@ import com.intellij.psi.impl.cache.impl.id.IdIndexEntry; import com.intellij.psi.impl.cache.impl.todo.TodoIndex; import com.intellij.psi.impl.cache.impl.todo.TodoIndexEntry; import com.intellij.psi.search.GlobalSearchScope; +import com.intellij.psi.search.GlobalSearchScopes; import com.intellij.psi.search.IndexPattern; import com.intellij.psi.search.IndexPatternProvider; import com.intellij.psi.util.PsiUtilBase; @@ -188,7 +189,7 @@ public class IndexCacheManagerImpl implements CacheManager{ count[0] += value.intValue(); return true; } - }, GlobalSearchScope.fileScope(myProject, file)); + }, GlobalSearchScopes.fileScope(myProject, file)); return count[0]; } diff --git a/platform/lang-impl/src/com/intellij/psi/impl/file/impl/FileManagerImpl.java b/platform/lang-impl/src/com/intellij/psi/impl/file/impl/FileManagerImpl.java index a1fb032c7a78..638553369d2d 100644 --- a/platform/lang-impl/src/com/intellij/psi/impl/file/impl/FileManagerImpl.java +++ b/platform/lang-impl/src/com/intellij/psi/impl/file/impl/FileManagerImpl.java @@ -47,6 +47,7 @@ import com.intellij.psi.impl.smartPointers.SmartPointerManagerImpl; import com.intellij.psi.impl.source.PsiFileImpl; import com.intellij.psi.impl.source.resolve.FileContextUtil; import com.intellij.psi.search.GlobalSearchScope; +import com.intellij.psi.search.GlobalSearchScopes; import com.intellij.psi.search.SearchScope; import com.intellij.util.ConcurrencyUtil; import com.intellij.util.FileContentUtil; @@ -480,7 +481,7 @@ public class FileManagerImpl implements FileManager { final VirtualFile vf = f == null ? null : f.getVirtualFile(); return f == null || vf == null || vf.isDirectory() || allScope.contains(vf) - ? allScope : GlobalSearchScope.fileScope(f).uniteWith(allScope); + ? allScope : GlobalSearchScopes.fileScope(f).uniteWith(allScope); } } diff --git a/platform/lang-impl/src/com/intellij/psi/stubs/StubTree.java b/platform/lang-impl/src/com/intellij/psi/stubs/StubTree.java index 14a04b93b02d..b45f7df53397 100644 --- a/platform/lang-impl/src/com/intellij/psi/stubs/StubTree.java +++ b/platform/lang-impl/src/com/intellij/psi/stubs/StubTree.java @@ -27,7 +27,7 @@ import com.intellij.openapi.fileEditor.FileDocumentManager; import com.intellij.openapi.project.DumbService; import com.intellij.openapi.project.Project; import com.intellij.openapi.vfs.VirtualFile; -import com.intellij.psi.search.GlobalSearchScope; +import com.intellij.psi.search.GlobalSearchScopes; import com.intellij.util.indexing.FileBasedIndex; import com.intellij.util.indexing.FileContent; import com.intellij.util.indexing.FileContentImpl; @@ -133,7 +133,8 @@ public class StubTree { final int id = Math.abs(FileBasedIndex.getFileId(vFile)); if (id > 0) { - final List datas = FileBasedIndex.getInstance().getValues(StubUpdatingIndex.INDEX_ID, id, GlobalSearchScope.fileScope(project, vFile)); + final List datas = FileBasedIndex.getInstance().getValues(StubUpdatingIndex.INDEX_ID, id, GlobalSearchScopes + .fileScope(project, vFile)); final int size = datas.size(); if (size == 1) { diff --git a/platform/lang-impl/src/com/intellij/refactoring/copy/CopyFilesOrDirectoriesHandler.java b/platform/lang-impl/src/com/intellij/refactoring/copy/CopyFilesOrDirectoriesHandler.java index 7e7e7768fde5..2eea7d045ee5 100644 --- a/platform/lang-impl/src/com/intellij/refactoring/copy/CopyFilesOrDirectoriesHandler.java +++ b/platform/lang-impl/src/com/intellij/refactoring/copy/CopyFilesOrDirectoriesHandler.java @@ -23,8 +23,8 @@ import com.intellij.openapi.command.CommandProcessor; import com.intellij.openapi.project.Project; import com.intellij.openapi.ui.Messages; import com.intellij.openapi.util.ThrowableComputable; -import com.intellij.openapi.vfs.VfsUtil; import com.intellij.openapi.vfs.VirtualFile; +import com.intellij.openapi.vfs.encoding.EncodingManager; import com.intellij.openapi.wm.ToolWindowManager; import com.intellij.psi.*; import com.intellij.psi.util.PsiTreeUtil; @@ -254,7 +254,7 @@ public class CopyFilesOrDirectoriesHandler implements CopyHandlerDelegate { if (newName == null) newName = directory.getName(); final PsiDirectory existing = targetDirectory.findSubdirectory(newName); final PsiDirectory subdirectory = existing == null ? targetDirectory.createSubdirectory(newName) : existing; - VfsUtil.doActionAndRestoreEncoding(directory.getVirtualFile(), new ThrowableComputable() { + EncodingManager.doActionAndRestoreEncoding(directory.getVirtualFile(), new ThrowableComputable() { public VirtualFile compute() { return subdirectory.getVirtualFile(); } diff --git a/platform/lang-impl/src/com/intellij/refactoring/introduce/inplace/AbstractInplaceIntroducer.java b/platform/lang-impl/src/com/intellij/refactoring/introduce/inplace/AbstractInplaceIntroducer.java index 5821890d256f..f6b94827be0f 100644 --- a/platform/lang-impl/src/com/intellij/refactoring/introduce/inplace/AbstractInplaceIntroducer.java +++ b/platform/lang-impl/src/com/intellij/refactoring/introduce/inplace/AbstractInplaceIntroducer.java @@ -450,8 +450,11 @@ public abstract class AbstractInplaceIntroducer implements Ti final Document document = documentManager.getDocument(file); document.replaceString(0, document.getTextLength(), first.getText().trim()); documentManager.commitDocument(document); - PsiManager.getInstance(project).getCodeStyleManager().reformat(file); //TODO: adjustLineIndent + CodeStyleManager.getInstance(PsiManager.getInstance(project).getProject()).reformat(file); //TODO: adjustLineIndent final String relativePath = PsiFileSystemItemUtil.getRelativePath(first.getContainingFile(), file); if (relativePath == null) throw new IncorrectOperationException("Cannot extract!"); diff --git a/platform/lang-impl/src/com/intellij/refactoring/rename/inplace/VariableInplaceRenamer.java b/platform/lang-impl/src/com/intellij/refactoring/rename/inplace/VariableInplaceRenamer.java index c98a911b2878..766e38d82cb2 100644 --- a/platform/lang-impl/src/com/intellij/refactoring/rename/inplace/VariableInplaceRenamer.java +++ b/platform/lang-impl/src/com/intellij/refactoring/rename/inplace/VariableInplaceRenamer.java @@ -52,6 +52,7 @@ import com.intellij.psi.*; import com.intellij.psi.impl.source.tree.injected.InjectedLanguageUtil; import com.intellij.psi.search.LocalSearchScope; import com.intellij.psi.search.ProjectScope; +import com.intellij.psi.search.PsiSearchHelper; import com.intellij.psi.search.SearchScope; import com.intellij.psi.search.searches.ReferencesSearch; import com.intellij.psi.util.PsiTreeUtil; @@ -181,7 +182,7 @@ public class VariableInplaceRenamer { @Nullable protected PsiElement checkLocalScope() { - final SearchScope searchScope = myElementToRename.getManager().getSearchHelper().getUseScope(myElementToRename); + final SearchScope searchScope = PsiSearchHelper.SERVICE.getInstance(myElementToRename.getProject()).getUseScope(myElementToRename); if (searchScope instanceof LocalSearchScope) { final PsiElement[] elements = ((LocalSearchScope)searchScope).getScope(); return PsiTreeUtil.findCommonParent(elements); diff --git a/platform/lang-impl/src/com/intellij/refactoring/util/TextOccurrencesUtil.java b/platform/lang-impl/src/com/intellij/refactoring/util/TextOccurrencesUtil.java index 1cd199ca8c10..960271825423 100644 --- a/platform/lang-impl/src/com/intellij/refactoring/util/TextOccurrencesUtil.java +++ b/platform/lang-impl/src/com/intellij/refactoring/util/TextOccurrencesUtil.java @@ -27,7 +27,6 @@ import com.intellij.lang.ParserDefinition; import com.intellij.openapi.util.TextRange; import com.intellij.psi.PsiElement; import com.intellij.psi.PsiFile; -import com.intellij.psi.PsiManager; import com.intellij.psi.PsiReference; import com.intellij.psi.search.*; import com.intellij.usageView.UsageInfo; @@ -60,7 +59,7 @@ public class TextOccurrencesUtil { @NotNull GlobalSearchScope searchScope, @NotNull final Processor processor, @NotNull final UsageInfoFactory factory) { - PsiSearchHelper helper = element.getManager().getSearchHelper(); + PsiSearchHelper helper = PsiSearchHelper.SERVICE.getInstance(element.getProject()); helper.processUsagesInNonJavaFiles(element, stringToSearch, new PsiNonJavaFileReferenceProcessor() { public boolean process(PsiFile psiFile, int startOffset, int endOffset) { @@ -93,10 +92,9 @@ public class TextOccurrencesUtil { @NotNull final String stringToSearch, final boolean ignoreReferences, @NotNull final PairProcessor processor) { - PsiManager manager = element.getManager(); - PsiSearchHelper helper = manager.getSearchHelper(); - SearchScope scope = element.getManager().getSearchHelper().getUseScope(element); - scope = scope.intersectWith(GlobalSearchScope.projectScope(manager.getProject())); + PsiSearchHelper helper = PsiSearchHelper.SERVICE.getInstance(element.getProject()); + SearchScope scope = PsiSearchHelper.SERVICE.getInstance(element.getProject()).getUseScope(element); + scope = scope.intersectWith(GlobalSearchScope.projectScope(element.getProject())); Processor commentOrLiteralProcessor = new Processor() { public boolean process(PsiElement literal) { return processTextIn(literal, stringToSearch, ignoreReferences, processor); diff --git a/platform/lang-impl/src/com/intellij/util/ui/classpath/ChooseLibrariesDialogBase.java b/platform/lang-impl/src/com/intellij/util/ui/classpath/ChooseLibrariesDialogBase.java index fbea5193613e..02bcb475c29c 100644 --- a/platform/lang-impl/src/com/intellij/util/ui/classpath/ChooseLibrariesDialogBase.java +++ b/platform/lang-impl/src/com/intellij/util/ui/classpath/ChooseLibrariesDialogBase.java @@ -14,6 +14,7 @@ import com.intellij.openapi.application.Application; import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.module.Module; import com.intellij.openapi.module.ModuleManager; +import com.intellij.openapi.module.ModuleType; import com.intellij.openapi.project.Project; import com.intellij.openapi.project.ProjectManager; import com.intellij.openapi.roots.LibraryOrderEntry; @@ -271,8 +272,8 @@ public abstract class ChooseLibrariesDialogBase extends DialogWrapper { protected ModuleDescriptor(final Project project, final NodeDescriptor parentDescriptor, final Module element) { super(project, parentDescriptor, element); final PresentationData templatePresentation = getTemplatePresentation(); - templatePresentation.setClosedIcon(element.getModuleType().getNodeIcon(false)); - templatePresentation.setOpenIcon(element.getModuleType().getNodeIcon(true)); + templatePresentation.setClosedIcon(ModuleType.get(element).getNodeIcon(false)); + templatePresentation.setOpenIcon(ModuleType.get(element).getNodeIcon(true)); templatePresentation.addText(notEmpty(element.getName()), SimpleTextAttributes.REGULAR_ATTRIBUTES); } diff --git a/platform/platform-api/src/com/intellij/ide/util/treeView/AlphaComparator.java b/platform/platform-api/src/com/intellij/ide/util/treeView/AlphaComparator.java index 202687678420..41c940d716fc 100644 --- a/platform/platform-api/src/com/intellij/ide/util/treeView/AlphaComparator.java +++ b/platform/platform-api/src/com/intellij/ide/util/treeView/AlphaComparator.java @@ -15,6 +15,8 @@ */ package com.intellij.ide.util.treeView; +import com.intellij.openapi.util.text.StringUtil; + import java.util.Comparator; public class AlphaComparator implements Comparator{ @@ -34,28 +36,6 @@ public class AlphaComparator implements Comparator{ if (s1 == null) return s2 == null ? 0 : -1; if (s2 == null) return +1; - if (startsWithDigit(s1) && startsWithDigit(s2)) { - int p1 = calculatePrefix(s1); - int p2 = calculatePrefix(s2); - if (p1 != p2) return p1 - p2; - } - - return s1.compareToIgnoreCase(s2); - } - - private static int calculatePrefix(String s) { - int acc = 0; - for (int i = 0; i < s.length(); i++) { - char c = s.charAt(i); - if (c < '0' || c > '9') break; - acc = acc * 10 + c - '0'; - } - return acc; - } - - private static boolean startsWithDigit(String s) { - if (s.isEmpty()) return false; - char c = s.charAt(0); - return c >= '0' && c <= '9'; + return StringUtil.naturalCompare(s1, s2); } } diff --git a/platform/core-api/src/com/intellij/openapi/application/BaseActionRunnable.java b/platform/platform-api/src/com/intellij/openapi/application/BaseActionRunnable.java similarity index 100% rename from platform/core-api/src/com/intellij/openapi/application/BaseActionRunnable.java rename to platform/platform-api/src/com/intellij/openapi/application/BaseActionRunnable.java diff --git a/platform/core-api/src/com/intellij/openapi/application/Result.java b/platform/platform-api/src/com/intellij/openapi/application/Result.java similarity index 100% rename from platform/core-api/src/com/intellij/openapi/application/Result.java rename to platform/platform-api/src/com/intellij/openapi/application/Result.java diff --git a/platform/core-api/src/com/intellij/openapi/application/RunResult.java b/platform/platform-api/src/com/intellij/openapi/application/RunResult.java similarity index 100% rename from platform/core-api/src/com/intellij/openapi/application/RunResult.java rename to platform/platform-api/src/com/intellij/openapi/application/RunResult.java diff --git a/platform/core-api/src/com/intellij/openapi/application/WriteAction.java b/platform/platform-api/src/com/intellij/openapi/application/WriteAction.java similarity index 94% rename from platform/core-api/src/com/intellij/openapi/application/WriteAction.java rename to platform/platform-api/src/com/intellij/openapi/application/WriteAction.java index da14f099485a..2c993a319a5e 100644 --- a/platform/core-api/src/com/intellij/openapi/application/WriteAction.java +++ b/platform/platform-api/src/com/intellij/openapi/application/WriteAction.java @@ -15,7 +15,7 @@ */ package com.intellij.openapi.application; -import com.intellij.ui.InvokeUtil; +import com.intellij.ui.GuiUtils; import org.jetbrains.annotations.Nullable; public abstract class WriteAction extends BaseActionRunnable { @@ -28,7 +28,7 @@ public abstract class WriteAction extends BaseActionRunnable { } try { - InvokeUtil.runOrInvokeAndWait(new Runnable() { + GuiUtils.runOrInvokeAndWait(new Runnable() { public void run() { final AccessToken accessToken = start(); try { diff --git a/platform/core-api/src/com/intellij/openapi/fileTypes/ExactFileNameMatcher.java b/platform/platform-api/src/com/intellij/openapi/fileTypes/ExactFileNameMatcher.java similarity index 100% rename from platform/core-api/src/com/intellij/openapi/fileTypes/ExactFileNameMatcher.java rename to platform/platform-api/src/com/intellij/openapi/fileTypes/ExactFileNameMatcher.java diff --git a/platform/core-api/src/com/intellij/openapi/fileTypes/ExtensionFileNameMatcher.java b/platform/platform-api/src/com/intellij/openapi/fileTypes/ExtensionFileNameMatcher.java similarity index 100% rename from platform/core-api/src/com/intellij/openapi/fileTypes/ExtensionFileNameMatcher.java rename to platform/platform-api/src/com/intellij/openapi/fileTypes/ExtensionFileNameMatcher.java diff --git a/platform/core-api/src/com/intellij/openapi/fileTypes/FileNameMatcher.java b/platform/platform-api/src/com/intellij/openapi/fileTypes/FileNameMatcher.java similarity index 100% rename from platform/core-api/src/com/intellij/openapi/fileTypes/FileNameMatcher.java rename to platform/platform-api/src/com/intellij/openapi/fileTypes/FileNameMatcher.java diff --git a/platform/core-api/src/com/intellij/openapi/fileTypes/FileTypeEvent.java b/platform/platform-api/src/com/intellij/openapi/fileTypes/FileTypeEvent.java similarity index 100% rename from platform/core-api/src/com/intellij/openapi/fileTypes/FileTypeEvent.java rename to platform/platform-api/src/com/intellij/openapi/fileTypes/FileTypeEvent.java diff --git a/platform/core-api/src/com/intellij/openapi/fileTypes/FileTypeListener.java b/platform/platform-api/src/com/intellij/openapi/fileTypes/FileTypeListener.java similarity index 100% rename from platform/core-api/src/com/intellij/openapi/fileTypes/FileTypeListener.java rename to platform/platform-api/src/com/intellij/openapi/fileTypes/FileTypeListener.java diff --git a/platform/core-api/src/com/intellij/openapi/fileTypes/FileTypeManager.java b/platform/platform-api/src/com/intellij/openapi/fileTypes/FileTypeManager.java similarity index 91% rename from platform/core-api/src/com/intellij/openapi/fileTypes/FileTypeManager.java rename to platform/platform-api/src/com/intellij/openapi/fileTypes/FileTypeManager.java index a8a7818fd6f8..e5ffd641e1cf 100644 --- a/platform/core-api/src/com/intellij/openapi/fileTypes/FileTypeManager.java +++ b/platform/platform-api/src/com/intellij/openapi/fileTypes/FileTypeManager.java @@ -15,9 +15,9 @@ */ package com.intellij.openapi.fileTypes; -import com.intellij.openapi.application.Application; -import com.intellij.openapi.application.ApplicationManager; +import com.intellij.openapi.application.ApplicationComponentLocator; import com.intellij.openapi.application.CachedSingletonsRegistry; +import com.intellij.openapi.util.Getter; import com.intellij.openapi.vfs.VirtualFile; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; @@ -30,7 +30,16 @@ import java.util.List; * Manages the relationship between filenames and {@link FileType} instances. */ -public abstract class FileTypeManager{ +public abstract class FileTypeManager extends FileTypeRegistry { + static { + FileTypeRegistry.ourInstanceGetter = new Getter() { + @Override + public FileTypeRegistry get() { + return FileTypeManager.getInstance(); + } + }; + } + private static FileTypeManager ourInstance = CachedSingletonsRegistry.markCachedField(FileTypeManager.class); /** * Returns the singleton instance of the FileTypeManager component. @@ -39,8 +48,7 @@ public abstract class FileTypeManager{ */ public static FileTypeManager getInstance() { if (ourInstance == null) { - Application app = ApplicationManager.getApplication(); - ourInstance = app != null ? app.getComponent(FileTypeManager.class) : new MockFileTypeManager(); + ourInstance = ApplicationComponentLocator.initialized() ? ApplicationComponentLocator.getComponent(FileTypeManager.class) : new MockFileTypeManager(); } return ourInstance; } @@ -77,15 +85,6 @@ public abstract class FileTypeManager{ @NotNull public abstract FileType getFileTypeByFileName(@NotNull @NonNls String fileName); - /** - * Returns the file type for the specified file. - * - * @param file The file for which the type is requested. - * @return The file type instance. - */ - @NotNull - public abstract FileType getFileTypeByFile(@NotNull VirtualFile file); - /** * Returns the file type for the specified extension. * Note that a more general way of obtaining file type is with {@link #getFileTypeByFile(VirtualFile)} @@ -96,14 +95,6 @@ public abstract class FileTypeManager{ @NotNull public abstract FileType getFileTypeByExtension(@NonNls @NotNull String extension); - /** - * Returns the list of all registered file types. - * - * @return The list of file types. - */ - @NotNull - public abstract FileType[] getRegisteredFileTypes(); - /** * Checks if the specified file is ignored by IDEA. Ignored files are not visible in * different project views and cannot be opened in the editor. They will neither be parsed nor compiled. diff --git a/platform/core-api/src/com/intellij/openapi/fileTypes/FileTypes.java b/platform/platform-api/src/com/intellij/openapi/fileTypes/FileTypes.java similarity index 100% rename from platform/core-api/src/com/intellij/openapi/fileTypes/FileTypes.java rename to platform/platform-api/src/com/intellij/openapi/fileTypes/FileTypes.java diff --git a/platform/core-api/src/com/intellij/openapi/fileTypes/MockFileTypeManager.java b/platform/platform-api/src/com/intellij/openapi/fileTypes/MockFileTypeManager.java similarity index 100% rename from platform/core-api/src/com/intellij/openapi/fileTypes/MockFileTypeManager.java rename to platform/platform-api/src/com/intellij/openapi/fileTypes/MockFileTypeManager.java diff --git a/platform/core-api/src/com/intellij/openapi/fileTypes/MockLanguageFileType.java b/platform/platform-api/src/com/intellij/openapi/fileTypes/MockLanguageFileType.java similarity index 100% rename from platform/core-api/src/com/intellij/openapi/fileTypes/MockLanguageFileType.java rename to platform/platform-api/src/com/intellij/openapi/fileTypes/MockLanguageFileType.java diff --git a/platform/core-api/src/com/intellij/openapi/fileTypes/UnknownFileType.java b/platform/platform-api/src/com/intellij/openapi/fileTypes/UnknownFileType.java similarity index 100% rename from platform/core-api/src/com/intellij/openapi/fileTypes/UnknownFileType.java rename to platform/platform-api/src/com/intellij/openapi/fileTypes/UnknownFileType.java diff --git a/platform/core-api/src/com/intellij/openapi/fileTypes/WildcardFileNameMatcher.java b/platform/platform-api/src/com/intellij/openapi/fileTypes/WildcardFileNameMatcher.java similarity index 100% rename from platform/core-api/src/com/intellij/openapi/fileTypes/WildcardFileNameMatcher.java rename to platform/platform-api/src/com/intellij/openapi/fileTypes/WildcardFileNameMatcher.java diff --git a/platform/platform-api/src/com/intellij/openapi/progress/ProgressManager.java b/platform/platform-api/src/com/intellij/openapi/progress/ProgressManager.java index 6f06a809ed7d..37b0296b212b 100644 --- a/platform/platform-api/src/com/intellij/openapi/progress/ProgressManager.java +++ b/platform/platform-api/src/com/intellij/openapi/progress/ProgressManager.java @@ -26,6 +26,20 @@ import javax.swing.*; public abstract class ProgressManager { private static final ProgressManager ourInstance = ServiceManager.getService(ProgressManager.class); + static { + ProgressIndicatorProvider.ourInstance = new ProgressIndicatorProvider() { + @Override + public ProgressIndicator getProgressIndicator() { + return ProgressManager.ourInstance.getProgressIndicator(); + } + + @Override + protected void doCheckCanceled() throws ProcessCanceledException { + ProgressManager.ourInstance.doCheckCanceled(); + } + }; + } + public static ProgressManager getInstance() { return ourInstance; } diff --git a/platform/core-api/src/com/intellij/openapi/vfs/JarFileSystem.java b/platform/platform-api/src/com/intellij/openapi/vfs/JarFileSystem.java similarity index 100% rename from platform/core-api/src/com/intellij/openapi/vfs/JarFileSystem.java rename to platform/platform-api/src/com/intellij/openapi/vfs/JarFileSystem.java diff --git a/platform/core-api/src/com/intellij/openapi/vfs/LocalFileOperationsHandler.java b/platform/platform-api/src/com/intellij/openapi/vfs/LocalFileOperationsHandler.java similarity index 100% rename from platform/core-api/src/com/intellij/openapi/vfs/LocalFileOperationsHandler.java rename to platform/platform-api/src/com/intellij/openapi/vfs/LocalFileOperationsHandler.java diff --git a/platform/core-api/src/com/intellij/openapi/vfs/LocalFileSystem.java b/platform/platform-api/src/com/intellij/openapi/vfs/LocalFileSystem.java similarity index 100% rename from platform/core-api/src/com/intellij/openapi/vfs/LocalFileSystem.java rename to platform/platform-api/src/com/intellij/openapi/vfs/LocalFileSystem.java diff --git a/platform/core-api/src/com/intellij/openapi/vfs/VfsUtil.java b/platform/platform-api/src/com/intellij/openapi/vfs/VfsUtil.java similarity index 96% rename from platform/core-api/src/com/intellij/openapi/vfs/VfsUtil.java rename to platform/platform-api/src/com/intellij/openapi/vfs/VfsUtil.java index 06870db9bb9e..1c8364c7db04 100644 --- a/platform/core-api/src/com/intellij/openapi/vfs/VfsUtil.java +++ b/platform/platform-api/src/com/intellij/openapi/vfs/VfsUtil.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2011 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. @@ -15,17 +15,17 @@ */ package com.intellij.openapi.vfs; +import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.application.Result; import com.intellij.openapi.application.WriteAction; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.fileTypes.FileTypeManager; import com.intellij.openapi.fileTypes.FileTypes; -import com.intellij.openapi.util.Comparing; +import com.intellij.openapi.util.Computable; +import com.intellij.openapi.util.Ref; import com.intellij.openapi.util.SystemInfo; -import com.intellij.openapi.util.ThrowableComputable; import com.intellij.openapi.util.io.FileUtil; import com.intellij.openapi.util.text.StringUtil; -import com.intellij.openapi.vfs.encoding.EncodingManager; import com.intellij.util.ArrayUtil; import com.intellij.util.Function; import com.intellij.util.PathUtil; @@ -598,10 +598,6 @@ public class VfsUtil { return null; } - public static boolean isValidName(@NotNull String name) { - return name.indexOf('\\') < 0 && name.indexOf('/') < 0; - } - public static String getUrlForLibraryRoot(@NotNull File libraryRoot) { String path = FileUtil.toSystemIndependentName(libraryRoot.getAbsolutePath()); if (FileTypeManager.getInstance().getFileTypeByFileName(libraryRoot.getName()) == FileTypes.ARCHIVE) { @@ -683,23 +679,6 @@ public class VfsUtil { return file; } - public static VirtualFile doActionAndRestoreEncoding(@NotNull VirtualFile fileBefore, @NotNull ThrowableComputable action) throws E { - Charset charsetBefore = EncodingManager.getInstance().getEncoding(fileBefore, true); - VirtualFile fileAfter = null; - try { - fileAfter = action.compute(); - return fileAfter; - } - finally { - if (fileAfter != null) { - Charset actual = EncodingManager.getInstance().getEncoding(fileAfter, true); - if (!Comparing.equal(actual, charsetBefore)) { - EncodingManager.getInstance().setEncoding(fileAfter, charsetBefore); - } - } - } - } - public static void processFileRecursivelyWithoutIgnored(@NotNull final VirtualFile root, @NotNull final Processor processor) { final FileTypeManager ftm = FileTypeManager.getInstance(); processFilesRecursively(root, processor, new Convertor() { diff --git a/platform/core-api/src/com/intellij/openapi/vfs/newvfs/FileSystemInterface.java b/platform/platform-api/src/com/intellij/openapi/vfs/newvfs/FileSystemInterface.java similarity index 100% rename from platform/core-api/src/com/intellij/openapi/vfs/newvfs/FileSystemInterface.java rename to platform/platform-api/src/com/intellij/openapi/vfs/newvfs/FileSystemInterface.java diff --git a/platform/platform-api/src/com/intellij/openapi/vfs/newvfs/ManagingFS.java b/platform/platform-api/src/com/intellij/openapi/vfs/newvfs/ManagingFS.java index c84cb7e9e955..639d9309b607 100644 --- a/platform/platform-api/src/com/intellij/openapi/vfs/newvfs/ManagingFS.java +++ b/platform/platform-api/src/com/intellij/openapi/vfs/newvfs/ManagingFS.java @@ -29,7 +29,7 @@ import java.io.DataInputStream; import java.io.DataOutputStream; import java.util.List; -public abstract class ManagingFS implements FileSystemInterface { +public abstract class ManagingFS implements FileSystemInterface, FileSystemPersistence { private static class ManagingFSHolder { private static final ManagingFS ourInstance = ApplicationManager.getApplication().getComponent(ManagingFS.class); } diff --git a/platform/platform-api/src/com/intellij/openapi/vfs/newvfs/NewVirtualFile.java b/platform/platform-api/src/com/intellij/openapi/vfs/newvfs/NewVirtualFile.java index 7917550d3db9..e9a7650accdd 100644 --- a/platform/platform-api/src/com/intellij/openapi/vfs/newvfs/NewVirtualFile.java +++ b/platform/platform-api/src/com/intellij/openapi/vfs/newvfs/NewVirtualFile.java @@ -20,14 +20,13 @@ package com.intellij.openapi.vfs.newvfs; import com.intellij.openapi.application.ApplicationManager; -import com.intellij.openapi.application.ModalityState; import com.intellij.openapi.fileTypes.FileType; import com.intellij.openapi.util.Key; import com.intellij.openapi.util.ThrowableComputable; import com.intellij.openapi.util.io.FileUtil; -import com.intellij.openapi.vfs.VfsUtil; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.openapi.vfs.VirtualFileWithId; +import com.intellij.openapi.vfs.encoding.EncodingManager; import com.intellij.util.LocalTimeCounter; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; @@ -104,11 +103,6 @@ public abstract class NewVirtualFile extends VirtualFile implements VirtualFileW RefreshQueue.getInstance().refresh(asynchronous, recursive, postRunnable, this); } - @Override - public void refresh(boolean asynchronous, boolean recursive, Runnable postRunnable, ModalityState modalityState) { - RefreshQueue.getInstance().refresh(asynchronous, recursive, postRunnable, modalityState, this); - } - public long getModificationStamp() { return myModificationStamp; } @@ -145,7 +139,7 @@ public abstract class NewVirtualFile extends VirtualFile implements VirtualFileW throw new IOException("Destination already exists: " + newParent.getPath() + "/" + getName()); } - VfsUtil.doActionAndRestoreEncoding(this, new ThrowableComputable() { + EncodingManager.doActionAndRestoreEncoding(this, new ThrowableComputable() { public VirtualFile compute() throws IOException { getFileSystem().moveFile(requestor, NewVirtualFile.this, newParent); return NewVirtualFile.this; diff --git a/platform/core-api/src/com/intellij/openapi/vfs/newvfs/NewVirtualFileSystem.java b/platform/platform-api/src/com/intellij/openapi/vfs/newvfs/NewVirtualFileSystem.java similarity index 98% rename from platform/core-api/src/com/intellij/openapi/vfs/newvfs/NewVirtualFileSystem.java rename to platform/platform-api/src/com/intellij/openapi/vfs/newvfs/NewVirtualFileSystem.java index 958001c71769..cfaa0664bab3 100644 --- a/platform/core-api/src/com/intellij/openapi/vfs/newvfs/NewVirtualFileSystem.java +++ b/platform/platform-api/src/com/intellij/openapi/vfs/newvfs/NewVirtualFileSystem.java @@ -31,7 +31,7 @@ import java.io.IOException; import java.util.HashMap; import java.util.Map; -public abstract class NewVirtualFileSystem extends VirtualFileSystem implements FileSystemInterface { +public abstract class NewVirtualFileSystem extends VirtualFileSystem implements FileSystemInterface, CachingVirtualFileSystem { private final Map myListenerWrappers = new HashMap(); public abstract boolean isCaseSensitive(); diff --git a/platform/platform-api/src/com/intellij/openapi/vfs/newvfs/RefreshQueue.java b/platform/platform-api/src/com/intellij/openapi/vfs/newvfs/RefreshQueue.java index 8c7cfbe15178..9400ee24d539 100644 --- a/platform/platform-api/src/com/intellij/openapi/vfs/newvfs/RefreshQueue.java +++ b/platform/platform-api/src/com/intellij/openapi/vfs/newvfs/RefreshQueue.java @@ -42,6 +42,8 @@ public abstract class RefreshQueue { session.launch(); } + public abstract void refreshLocalRoots(boolean async, @Nullable Runnable postAction, ModalityState modalityState); + public final void refresh(boolean async, boolean recursive, @Nullable Runnable finishRunnable, VirtualFile... files) { refresh(async, recursive, finishRunnable, getDefaultModalityState(), files); } diff --git a/platform/core-api/src/com/intellij/openapi/vfs/newvfs/VirtualFileFilteringListener.java b/platform/platform-api/src/com/intellij/openapi/vfs/newvfs/VirtualFileFilteringListener.java similarity index 100% rename from platform/core-api/src/com/intellij/openapi/vfs/newvfs/VirtualFileFilteringListener.java rename to platform/platform-api/src/com/intellij/openapi/vfs/newvfs/VirtualFileFilteringListener.java diff --git a/platform/platform-api/src/com/intellij/ui/GuiUtils.java b/platform/platform-api/src/com/intellij/ui/GuiUtils.java index 3060de465edb..ab241fb4ee60 100644 --- a/platform/platform-api/src/com/intellij/ui/GuiUtils.java +++ b/platform/platform-api/src/com/intellij/ui/GuiUtils.java @@ -15,6 +15,8 @@ */ package com.intellij.ui; +import com.intellij.openapi.application.Application; +import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.fileChooser.FileChooser; import com.intellij.openapi.fileChooser.FileChooserDescriptor; import com.intellij.openapi.fileChooser.FileChooserDescriptorFactory; @@ -359,13 +361,24 @@ public class GuiUtils { return s; } - /** @deprecated please use InvokeUtil instead */ public static void invokeAndWait(@NotNull Runnable runnable) throws InvocationTargetException, InterruptedException { - InvokeUtil.invokeAndWait(runnable); + Application application = ApplicationManager.getApplication(); + assert !application.isDispatchThread() : "Must not be invoked from AWT dispatch thread"; + if (application.isReadAccessAllowed()) { + // make ApplicationImpl catch deadlock situation with readLock held + application.invokeAndWait(runnable, application.getDefaultModalityState()); + return; + } + SwingUtilities.invokeAndWait(runnable); } - /** @deprecated please use InvokeUtil instead */ public static void runOrInvokeAndWait(@NotNull Runnable runnable) throws InvocationTargetException, InterruptedException { - InvokeUtil.runOrInvokeAndWait(runnable); + Application application = ApplicationManager.getApplication(); + if (application.isDispatchThread()) { + runnable.run(); + } + else { + invokeAndWait(runnable); + } } } diff --git a/platform/platform-api/src/com/intellij/ui/ToolbarDecorator.java b/platform/platform-api/src/com/intellij/ui/ToolbarDecorator.java index 69f6e07fc712..b770de236525 100644 --- a/platform/platform-api/src/com/intellij/ui/ToolbarDecorator.java +++ b/platform/platform-api/src/com/intellij/ui/ToolbarDecorator.java @@ -65,6 +65,7 @@ public class ToolbarDecorator implements DataProvider, AddRemoveUpDownPanel.List private String myRemoveName; private String myMoveUpName; private String myMoveDownName; + private Dimension myPreferredSize; private AddRemoveUpDownPanel myPanel; private JList myList; @@ -303,6 +304,12 @@ public class ToolbarDecorator implements DataProvider, AddRemoveUpDownPanel.List return this; } + public ToolbarDecorator disableUpDownActions() { + myUpActionEnabled = false; + myDownActionEnabled = false; + return this; + } + public ToolbarDecorator disableDownAction() { myDownActionEnabled = false; return this; @@ -371,6 +378,11 @@ public class ToolbarDecorator implements DataProvider, AddRemoveUpDownPanel.List return this; } + public ToolbarDecorator setPreferredSize(Dimension size) { + myPreferredSize = size; + return this; + } + public JPanel createPanel() { final AddRemoveUpDownPanel.Buttons[] buttons = getButtons(); myPanel = new AddRemoveUpDownPanel(this, @@ -381,6 +393,9 @@ public class ToolbarDecorator implements DataProvider, AddRemoveUpDownPanel.List buttons); myPanel.setBorder(myBorder); final JScrollPane scrollPane = ScrollPaneFactory.createScrollPane(myTable == null ? myList == null ? myTree : myList : myTable); + if (myPreferredSize != null) { + scrollPane.setPreferredSize(myPreferredSize); + } scrollPane.setBorder(IdeBorderFactory.createEmptyBorder(0)); final JPanel panel = new JPanel(new BorderLayout()) { @Override diff --git a/platform/core-api/src/com/intellij/util/PathUtil.java b/platform/platform-api/src/com/intellij/util/PathUtil.java similarity index 100% rename from platform/core-api/src/com/intellij/util/PathUtil.java rename to platform/platform-api/src/com/intellij/util/PathUtil.java diff --git a/platform/platform-impl/src/com/intellij/diagnostic/errordialog/AttachmentsTabForm.java b/platform/platform-impl/src/com/intellij/diagnostic/errordialog/AttachmentsTabForm.java index acfbe588c5a5..218cad59484f 100644 --- a/platform/platform-impl/src/com/intellij/diagnostic/errordialog/AttachmentsTabForm.java +++ b/platform/platform-impl/src/com/intellij/diagnostic/errordialog/AttachmentsTabForm.java @@ -25,7 +25,7 @@ public class AttachmentsTabForm { private LabeledTextComponent myFileTextArea; private final ColumnInfo ENABLED_COLUMN = - new ColumnInfo(DiagnosticBundle.message("error.dialog.attachment.path.column.title")) { + new ColumnInfo(DiagnosticBundle.message("error.dialog.attachment.include.column.title")) { @Override public Boolean valueOf(Attachment attachment) { return attachment.isIncluded(); @@ -53,7 +53,7 @@ public class AttachmentsTabForm { }; private static final ColumnInfo PATH_COLUMN = - new ColumnInfo(DiagnosticBundle.message("error.dialog.attachment.include.column.title")) { + new ColumnInfo(DiagnosticBundle.message("error.dialog.attachment.path.column.title")) { @Override public String valueOf(Attachment attachment) { return attachment.getPath(); diff --git a/platform/platform-impl/src/com/intellij/ide/SaveAndSyncHandler.java b/platform/platform-impl/src/com/intellij/ide/SaveAndSyncHandler.java index 273c6e8e95ee..3f9534e82b61 100644 --- a/platform/platform-impl/src/com/intellij/ide/SaveAndSyncHandler.java +++ b/platform/platform-impl/src/com/intellij/ide/SaveAndSyncHandler.java @@ -27,7 +27,6 @@ import com.intellij.openapi.progress.ProgressManager; import com.intellij.openapi.project.Project; import com.intellij.openapi.project.ex.ProjectManagerEx; import com.intellij.openapi.vfs.VirtualFile; -import com.intellij.openapi.vfs.VirtualFileManager; import com.intellij.openapi.vfs.newvfs.NewVirtualFile; import com.intellij.openapi.vfs.newvfs.RefreshQueue; import com.intellij.openapi.vfs.newvfs.RefreshSession; @@ -164,7 +163,7 @@ public class SaveAndSyncHandler implements ApplicationComponent { if (LOG.isDebugEnabled()) { LOG.debug("refresh VFS"); } - VirtualFileManager.getInstance().refresh(true, null, modalityState); + RefreshQueue.getInstance().refreshLocalRoots(true, null, modalityState); } } diff --git a/platform/platform-impl/src/com/intellij/openapi/application/ex/ApplicationManagerEx.java b/platform/platform-impl/src/com/intellij/openapi/application/ex/ApplicationManagerEx.java index e081a0dbe9b8..e85094efa7f0 100644 --- a/platform/platform-impl/src/com/intellij/openapi/application/ex/ApplicationManagerEx.java +++ b/platform/platform-impl/src/com/intellij/openapi/application/ex/ApplicationManagerEx.java @@ -17,6 +17,7 @@ package com.intellij.openapi.application.ex; import com.intellij.openapi.Disposable; import com.intellij.openapi.application.Application; +import com.intellij.openapi.application.ApplicationComponentLocator; import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.application.CachedSingletonsRegistry; import com.intellij.openapi.application.impl.ApplicationImpl; @@ -45,6 +46,7 @@ public class ApplicationManagerEx extends ApplicationManager { public static void setApplication(Application instance) { ourApplication = instance; + ApplicationComponentLocator.setInstance(instance); CachedSingletonsRegistry.cleanupCachedFields(); } diff --git a/platform/platform-impl/src/com/intellij/openapi/application/impl/ApplicationImpl.java b/platform/platform-impl/src/com/intellij/openapi/application/impl/ApplicationImpl.java index dd5de4c51805..8dd73bb617c6 100644 --- a/platform/platform-impl/src/com/intellij/openapi/application/impl/ApplicationImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/application/impl/ApplicationImpl.java @@ -848,7 +848,7 @@ public class ApplicationImpl extends ComponentManagerImpl implements Application } public void runReadAction(@NotNull final Runnable action) { - final AccessToken token = acquireReadActionLock(); + final AccessToken token = acquireReadActionLockImpl(false); try { action.run(); @@ -876,7 +876,7 @@ public class ApplicationImpl extends ComponentManagerImpl implements Application } public T runReadAction(@NotNull final Computable computation) { - final AccessToken token = acquireReadActionLock(); + final AccessToken token = acquireReadActionLockImpl(false); try { return computation.compute(); @@ -1085,11 +1085,15 @@ public class ApplicationImpl extends ComponentManagerImpl implements Application @Override public AccessToken acquireReadActionLock() { + return acquireReadActionLockImpl(true); + } + + private AccessToken acquireReadActionLockImpl(boolean explicit) { /** if we are inside read action, do not try to acquire read lock again since it will deadlock if there is a pending writeAction * see {@link com.intellij.util.concurrency.ReentrantWriterPreferenceReadWriteLock#allowReader()} */ if (isReadAccessAllowed()) return AccessToken.EMPTY_ACCESS_TOKEN; - return new ReadAccessToken(); + return new ReadAccessToken(explicit); } @Override @@ -1157,11 +1161,14 @@ public class ApplicationImpl extends ComponentManagerImpl implements Application } private class ReadAccessToken extends AccessToken { - ReadAccessToken() { + private final boolean myExplicit; + + ReadAccessToken(boolean explicit) { + myExplicit = explicit; LOG.assertTrue(!Thread.holdsLock(PsiLock.LOCK), "Thread must not hold PsiLock while performing readAction"); try { myActionsLock.readLock().acquire(); - acquired(); + if (myExplicit) acquired(); } catch (InterruptedException e) { throw new RuntimeInterruptedException(e); @@ -1171,7 +1178,7 @@ public class ApplicationImpl extends ComponentManagerImpl implements Application @Override public void finish() { myActionsLock.readLock().release(); - released(); + if (myExplicit) released(); } } diff --git a/platform/platform-impl/src/com/intellij/openapi/command/impl/UndoRedo.java b/platform/platform-impl/src/com/intellij/openapi/command/impl/UndoRedo.java index c52f89586ecc..013879e11efe 100644 --- a/platform/platform-impl/src/com/intellij/openapi/command/impl/UndoRedo.java +++ b/platform/platform-impl/src/com/intellij/openapi/command/impl/UndoRedo.java @@ -29,7 +29,6 @@ import com.intellij.openapi.util.text.StringUtil; import com.intellij.openapi.vfs.ReadonlyStatusHandler; import com.intellij.openapi.vfs.VfsUtil; import com.intellij.openapi.vfs.VirtualFile; -import com.intellij.openapi.vfs.VirtualFileManager; import java.util.ArrayList; import java.util.Collection; @@ -119,7 +118,6 @@ abstract class UndoRedo { final VirtualFile[] files = VfsUtil.toVirtualFileArray(readOnlyFiles); if (project == null) { - VirtualFileManager.getInstance().fireReadOnlyModificationAttempt(files); return false; } diff --git a/platform/platform-impl/src/com/intellij/openapi/fileChooser/actions/RefreshFileChooserAction.java b/platform/platform-impl/src/com/intellij/openapi/fileChooser/actions/RefreshFileChooserAction.java index ee2de9368ebe..ffac802ff771 100644 --- a/platform/platform-impl/src/com/intellij/openapi/fileChooser/actions/RefreshFileChooserAction.java +++ b/platform/platform-impl/src/com/intellij/openapi/fileChooser/actions/RefreshFileChooserAction.java @@ -18,14 +18,14 @@ package com.intellij.openapi.fileChooser.actions; import com.intellij.openapi.actionSystem.AnAction; import com.intellij.openapi.actionSystem.AnActionEvent; import com.intellij.openapi.application.ModalityState; -import com.intellij.openapi.vfs.VirtualFileManager; import com.intellij.openapi.project.DumbAware; +import com.intellij.openapi.vfs.newvfs.RefreshQueue; /** * @author yole */ public class RefreshFileChooserAction extends AnAction implements DumbAware { public void actionPerformed(final AnActionEvent e) { - VirtualFileManager.getInstance().refresh(true, null, ModalityState.current()); + RefreshQueue.getInstance().refreshLocalRoots(true, null, ModalityState.current()); } } \ No newline at end of file diff --git a/platform/platform-impl/src/com/intellij/openapi/fileChooser/ex/FileSystemTreeImpl.java b/platform/platform-impl/src/com/intellij/openapi/fileChooser/ex/FileSystemTreeImpl.java index e38139bdc83b..6a00226b34a4 100644 --- a/platform/platform-impl/src/com/intellij/openapi/fileChooser/ex/FileSystemTreeImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/fileChooser/ex/FileSystemTreeImpl.java @@ -39,6 +39,7 @@ import com.intellij.openapi.vfs.JarFileSystem; import com.intellij.openapi.vfs.VfsUtil; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.openapi.vfs.newvfs.NewVirtualFile; +import com.intellij.openapi.vfs.newvfs.RefreshQueue; import com.intellij.ui.PopupHandler; import com.intellij.ui.SimpleTextAttributes; import com.intellij.ui.TreeSpeedSearch; @@ -483,10 +484,12 @@ public class FileSystemTreeImpl implements FileSystemTree { } - if (myTreeBuilder.getTreeStructure().isToBuildChildrenInBackground(virtualFile)) { - virtualFile.refresh(true, false, null, ModalityState.stateForComponent(myTree)); - } else { - virtualFile.refresh(false, false, null, ModalityState.stateForComponent(myTree)); + boolean async = myTreeBuilder.getTreeStructure().isToBuildChildrenInBackground(virtualFile); + if (virtualFile instanceof NewVirtualFile) { + RefreshQueue.getInstance().refresh(async, false, null, ModalityState.stateForComponent(myTree), virtualFile); + } + else { + virtualFile.refresh(async, false); } } } diff --git a/platform/platform-impl/src/com/intellij/openapi/fileEditor/impl/FileDocumentManagerImpl.java b/platform/platform-impl/src/com/intellij/openapi/fileEditor/impl/FileDocumentManagerImpl.java index 5bd278624af7..4dceb618cdf0 100644 --- a/platform/platform-impl/src/com/intellij/openapi/fileEditor/impl/FileDocumentManagerImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/fileEditor/impl/FileDocumentManagerImpl.java @@ -33,7 +33,6 @@ import com.intellij.openapi.editor.EditorFactory; import com.intellij.openapi.editor.event.DocumentAdapter; import com.intellij.openapi.editor.event.DocumentEvent; import com.intellij.openapi.editor.ex.DocumentEx; -import com.intellij.openapi.editor.ex.EditReadOnlyListener; import com.intellij.openapi.fileEditor.*; import com.intellij.openapi.fileTypes.BinaryFileTypeDecompilers; import com.intellij.openapi.fileTypes.FileType; @@ -78,7 +77,6 @@ public class FileDocumentManagerImpl extends FileDocumentManager implements Appl private static final Key FILE_KEY = Key.create("FILE_KEY"); private final Set myUnsavedDocuments = new ConcurrentHashSet(); - private final EditReadOnlyListener myReadOnlyListener = new MyEditReadOnlyListener(); private final EventDispatcher myVetoDispatcher = EventDispatcher.create(FileDocumentSynchronizationVetoListener.class); @@ -142,7 +140,6 @@ public class FileDocumentManagerImpl extends FileDocumentManager implements Appl } } ); - document.addEditReadOnlyListener(myReadOnlyListener); } } @@ -616,14 +613,6 @@ public class FileDocumentManagerImpl extends FileDocumentManager implements Appl public void beforeFileMovement(VirtualFileMoveEvent event) { } - private final class MyEditReadOnlyListener implements EditReadOnlyListener { - public void readOnlyModificationAttempt(Document document) { - VirtualFile file = getFile(document); - if (file == null) return; - myVirtualFileManager.fireReadOnlyModificationAttempt(file); - } - } - private void fireFileContentReloaded(final VirtualFile file, final Document document) { myBus.syncPublisher(AppTopics.FILE_DOCUMENT_SYNC).fileContentReloaded(file, document); for (FileDocumentManagerListener listener : getListeners()) { diff --git a/platform/platform-impl/src/com/intellij/openapi/progress/impl/ProgressManagerImpl.java b/platform/platform-impl/src/com/intellij/openapi/progress/impl/ProgressManagerImpl.java index 12befda938a1..296674fc61a0 100644 --- a/platform/platform-impl/src/com/intellij/openapi/progress/impl/ProgressManagerImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/progress/impl/ProgressManagerImpl.java @@ -62,6 +62,7 @@ public class ProgressManagerImpl extends ProgressManager implements Disposable{ catch (InterruptedException ignored) { } ourNeedToCheckCancel = true; + ProgressIndicatorProvider.ourNeedToCheckCancel = true; } } }; @@ -86,6 +87,7 @@ public class ProgressManagerImpl extends ProgressManager implements Disposable{ if (ourLockedCheckCounter > 10) { ourLockedCheckCounter = 0; ourNeedToCheckCancel = true; + ProgressIndicatorProvider.ourNeedToCheckCancel = true; } } else { @@ -98,6 +100,7 @@ public class ProgressManagerImpl extends ProgressManager implements Disposable{ public static void canceled() { ourNeedToCheckCancel = true; + ProgressIndicatorProvider.ourNeedToCheckCancel = true; } private static class NonCancelableIndicator extends EmptyProgressIndicator implements NonCancelableSection { @@ -458,6 +461,7 @@ public class ProgressManagerImpl extends ProgressManager implements Disposable{ @TestOnly public static void setNeedToCheckCancel(boolean needToCheckCancel) { ourNeedToCheckCancel = needToCheckCancel; + ProgressIndicatorProvider.ourNeedToCheckCancel = true; } @TestOnly diff --git a/platform/platform-impl/src/com/intellij/openapi/vfs/impl/local/LocalFileSystemImpl.java b/platform/platform-impl/src/com/intellij/openapi/vfs/impl/local/LocalFileSystemImpl.java index 9ea6b7cecd96..6d45f014f470 100644 --- a/platform/platform-impl/src/com/intellij/openapi/vfs/impl/local/LocalFileSystemImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/vfs/impl/local/LocalFileSystemImpl.java @@ -329,10 +329,10 @@ public final class LocalFileSystemImpl extends LocalFileSystemBase implements Ap if (existingFile != null) { if (!isAlreadyWatched(result)) { final ModalityState modalityState = ModalityState.current(); - existingFile.refresh(true, toWatchRecursively, null, modalityState); + RefreshQueue.getInstance().refresh(true, toWatchRecursively, null, modalityState, existingFile); if (existingFile.isDirectory() && !toWatchRecursively && existingFile instanceof NewVirtualFile) { for (VirtualFile child : ((NewVirtualFile)existingFile).getCachedChildren()) { - child.refresh(true, false, null, modalityState); + RefreshQueue.getInstance().refresh(true, false, null, modalityState, child); } } } diff --git a/platform/platform-impl/src/com/intellij/openapi/vfs/newvfs/RefreshQueueImpl.java b/platform/platform-impl/src/com/intellij/openapi/vfs/newvfs/RefreshQueueImpl.java index 928607c79af8..1540475a9813 100644 --- a/platform/platform-impl/src/com/intellij/openapi/vfs/newvfs/RefreshQueueImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/vfs/newvfs/RefreshQueueImpl.java @@ -97,6 +97,11 @@ public class RefreshQueueImpl extends RefreshQueue { return new RefreshSessionImpl(async, recursively, finishRunnable, state); } + @Override + public void refreshLocalRoots(boolean async, Runnable postAction, ModalityState modalityState) { + RefreshQueue.getInstance().refresh(async, true, postAction, modalityState, ManagingFS.getInstance().getLocalRoots()); + } + public void processSingleEvent(VFileEvent event) { new RefreshSessionImpl(Collections.singletonList(event)).launch(); } diff --git a/platform/platform-impl/src/com/intellij/openapi/vfs/newvfs/impl/VirtualFileSystemEntry.java b/platform/platform-impl/src/com/intellij/openapi/vfs/newvfs/impl/VirtualFileSystemEntry.java index 9ec8ad120f4e..f728f6f344da 100644 --- a/platform/platform-impl/src/com/intellij/openapi/vfs/newvfs/impl/VirtualFileSystemEntry.java +++ b/platform/platform-impl/src/com/intellij/openapi/vfs/newvfs/impl/VirtualFileSystemEntry.java @@ -22,7 +22,6 @@ import com.intellij.openapi.util.io.FileTooBigException; import com.intellij.openapi.util.text.StringUtil; import com.intellij.openapi.vfs.LocalFileSystem; import com.intellij.openapi.vfs.VfsBundle; -import com.intellij.openapi.vfs.VfsUtil; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.openapi.vfs.encoding.EncodingManager; import com.intellij.openapi.vfs.newvfs.ManagingFS; @@ -256,7 +255,7 @@ public abstract class VirtualFileSystemEntry extends NewVirtualFile { public void rename(final Object requestor, @NotNull @NonNls final String newName) throws IOException { if (getName().equals(newName)) return; - if (!VfsUtil.isValidName(newName)) { + if (!isValidName(newName)) { throw new IOException(VfsBundle.message("file.invalid.name.error", newName)); } @@ -298,7 +297,7 @@ public abstract class VirtualFileSystemEntry extends NewVirtualFile { throw new IOException(VfsBundle.message("file.copy.target.must.be.directory")); } - return VfsUtil.doActionAndRestoreEncoding(this, new ThrowableComputable() { + return EncodingManager.doActionAndRestoreEncoding(this, new ThrowableComputable() { public VirtualFile compute() throws IOException { return ourPersistence.copyFile(requestor, VirtualFileSystemEntry.this, newParent, copyName); } @@ -310,7 +309,7 @@ public abstract class VirtualFileSystemEntry extends NewVirtualFile { throw new IOException(VfsBundle.message("file.move.error", newParent.getPresentableUrl())); } - VfsUtil.doActionAndRestoreEncoding(this, new ThrowableComputable() { + EncodingManager.doActionAndRestoreEncoding(this, new ThrowableComputable() { public VirtualFile compute() throws IOException { ourPersistence.moveFile(requestor, VirtualFileSystemEntry.this, newParent); return VirtualFileSystemEntry.this; diff --git a/platform/platform-impl/src/com/intellij/openapi/vfs/newvfs/persistent/PersistentFS.java b/platform/platform-impl/src/com/intellij/openapi/vfs/newvfs/persistent/PersistentFS.java index 1ba65d511e62..23301ecff9fd 100644 --- a/platform/platform-impl/src/com/intellij/openapi/vfs/newvfs/persistent/PersistentFS.java +++ b/platform/platform-impl/src/com/intellij/openapi/vfs/newvfs/persistent/PersistentFS.java @@ -20,6 +20,7 @@ package com.intellij.openapi.vfs.newvfs.persistent; import com.intellij.openapi.application.ApplicationManager; +import com.intellij.openapi.application.ModalityState; import com.intellij.openapi.application.ex.ApplicationEx; import com.intellij.openapi.components.ApplicationComponent; import com.intellij.openapi.diagnostic.Logger; @@ -726,6 +727,17 @@ public class PersistentFS extends ManagingFS implements ApplicationComponent { RefreshQueue.getInstance().refresh(asynchronous, true, null, roots); } + @Override + public void refresh(boolean asynchronous, Runnable postAction, ModalityState modalityState) { + final NewVirtualFile[] roots; + synchronized (LOCK) { + Collection values = myRoots.values(); + roots = values.toArray(new NewVirtualFile[values.size()]); + } + + RefreshQueue.getInstance().refresh(asynchronous, true, postAction, modalityState, roots); + } + @NotNull public VirtualFile[] getLocalRoots() { List roots; diff --git a/platform/platform-impl/src/com/intellij/openapi/wm/impl/ToolWindowManagerImpl.java b/platform/platform-impl/src/com/intellij/openapi/wm/impl/ToolWindowManagerImpl.java index 07837dd34aaf..e2ef7e01043f 100644 --- a/platform/platform-impl/src/com/intellij/openapi/wm/impl/ToolWindowManagerImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/wm/impl/ToolWindowManagerImpl.java @@ -551,7 +551,7 @@ public final class ToolWindowManagerImpl extends ToolWindowManagerEx implements } private void activateEditorComponent(final boolean forced) { - activateEditorComponent(forced, false); + activateEditorComponent(forced, true); //TODO[kirillk]: runnable in activateEditorComponent(boolean, boolean) never runs } private void activateEditorComponent(final boolean forced, boolean now) { if (LOG.isDebugEnabled()) { @@ -567,7 +567,6 @@ public final class ToolWindowManagerImpl extends ToolWindowManagerEx implements execute(commandList); } }; - if (now) { runnable.run(); } else { diff --git a/platform/platform-resources/src/META-INF/LangExtensions.xml b/platform/platform-resources/src/META-INF/LangExtensions.xml index 1e6a9135d6d1..1546150ec0ec 100644 --- a/platform/platform-resources/src/META-INF/LangExtensions.xml +++ b/platform/platform-resources/src/META-INF/LangExtensions.xml @@ -73,6 +73,9 @@ + + diff --git a/platform/testFramework/src/com/intellij/mock/MockModule.java b/platform/testFramework/src/com/intellij/mock/MockModule.java index c900ec975d69..c0cee8e54384 100644 --- a/platform/testFramework/src/com/intellij/mock/MockModule.java +++ b/platform/testFramework/src/com/intellij/mock/MockModule.java @@ -4,7 +4,6 @@ package com.intellij.mock; import com.intellij.openapi.module.Module; -import com.intellij.openapi.module.ModuleType; import com.intellij.openapi.project.Project; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.psi.search.GlobalSearchScope; @@ -57,12 +56,6 @@ public class MockModule extends MockComponentManager implements Module { return new MockGlobalSearchScope(); } - @Override - @NotNull - public ModuleType getModuleType() { - throw new UnsupportedOperationException("Method getModuleType is not yet implemented in " + getClass().getName()); - } - @Override public GlobalSearchScope getModuleWithDependenciesAndLibrariesScope(final boolean includeTests) { return new MockGlobalSearchScope(); diff --git a/platform/testFramework/src/com/intellij/mock/MockVirtualFileManager.java b/platform/testFramework/src/com/intellij/mock/MockVirtualFileManager.java index e6e98affadfd..88429017e166 100644 --- a/platform/testFramework/src/com/intellij/mock/MockVirtualFileManager.java +++ b/platform/testFramework/src/com/intellij/mock/MockVirtualFileManager.java @@ -15,14 +15,14 @@ */ package com.intellij.mock; -import com.intellij.ide.caches.CacheUpdater; import com.intellij.openapi.Disposable; -import com.intellij.openapi.application.ModalityState; import com.intellij.openapi.util.ModificationTracker; -import com.intellij.openapi.vfs.*; +import com.intellij.openapi.vfs.VirtualFile; +import com.intellij.openapi.vfs.VirtualFileListener; +import com.intellij.openapi.vfs.VirtualFileManagerListener; +import com.intellij.openapi.vfs.VirtualFileSystem; import com.intellij.openapi.vfs.ex.VirtualFileManagerEx; import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; public class MockVirtualFileManager extends VirtualFileManagerEx { public MockVirtualFileManager() { @@ -47,10 +47,6 @@ public class MockVirtualFileManager extends VirtualFileManagerEx { public void refresh(boolean asynchronous, Runnable postAction) { } - @Override - public void refresh(boolean asynchronous, @Nullable Runnable postAction, ModalityState modalityState) { - } - @Override public VirtualFile findFileByUrl(@NotNull String url) { return null; @@ -73,18 +69,6 @@ public class MockVirtualFileManager extends VirtualFileManagerEx { public void removeVirtualFileListener(@NotNull VirtualFileListener listener) { } - @Override - public void addModificationAttemptListener(@NotNull ModificationAttemptListener listener) { - } - - @Override - public void removeModificationAttemptListener(@NotNull ModificationAttemptListener listener) { - } - - @Override - public void fireReadOnlyModificationAttempt(@NotNull VirtualFile... files) { - } - @Override public void addVirtualFileManagerListener(@NotNull VirtualFileManagerListener listener) { } @@ -97,25 +81,6 @@ public class MockVirtualFileManager extends VirtualFileManagerEx { public void removeVirtualFileManagerListener(@NotNull VirtualFileManagerListener listener) { } - public void beforeRefreshStart(boolean asynchronous, ModalityState modalityState, Runnable postAction) { - } - - public void afterRefreshFinish(boolean asynchronous, ModalityState modalityState) { - } - - public void registerRefreshUpdater(CacheUpdater updater) { - } - - public void unregisterRefreshUpdater(CacheUpdater updater) { - } - - @Override - public void registerFileSystem(VirtualFileSystem fileSystem) { - } - - @Override - public void unregisterFileSystem(VirtualFileSystem fileSystem) { - } @Override public void fireAfterRefreshFinish(final boolean asynchronous) { diff --git a/platform/usageView/src/com/intellij/usages/impl/rules/ModuleGroupingRule.java b/platform/usageView/src/com/intellij/usages/impl/rules/ModuleGroupingRule.java index 0978ab0e03bb..d57d36db645e 100644 --- a/platform/usageView/src/com/intellij/usages/impl/rules/ModuleGroupingRule.java +++ b/platform/usageView/src/com/intellij/usages/impl/rules/ModuleGroupingRule.java @@ -20,6 +20,7 @@ import com.intellij.openapi.actionSystem.DataSink; import com.intellij.openapi.actionSystem.LangDataKeys; import com.intellij.openapi.actionSystem.TypeSafeDataProvider; import com.intellij.openapi.module.Module; +import com.intellij.openapi.module.ModuleType; import com.intellij.openapi.roots.OrderEntry; import com.intellij.openapi.util.IconLoader; import com.intellij.openapi.vcs.FileStatus; @@ -137,7 +138,7 @@ public class ModuleGroupingRule implements UsageGroupingRule { } public Icon getIcon(boolean isOpen) { - return myModule.getModuleType().getNodeIcon(isOpen); + return ModuleType.get(myModule).getNodeIcon(isOpen); } @NotNull diff --git a/platform/util/src/com/intellij/openapi/util/text/StringUtil.java b/platform/util/src/com/intellij/openapi/util/text/StringUtil.java index 3c89c2b801b8..a75857118f0b 100644 --- a/platform/util/src/com/intellij/openapi/util/text/StringUtil.java +++ b/platform/util/src/com/intellij/openapi/util/text/StringUtil.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2010 JetBrains s.r.o. + * Copyright 2000-2011 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. @@ -1959,6 +1959,75 @@ public class StringUtil { return res; } + /** + * Implementation of "Sorting for Humans: Natural Sort Order": + * http://www.codinghorror.com/blog/2007/12/sorting-for-humans-natural-sort-order.html + */ + public static int naturalCompare(String string1, String string2) { + return naturalCompare(string1, string2, false); + } + + private static int naturalCompare(String string1, String string2, boolean caseSensitive) { + final int string1Length = string1.length(); + final int string2Length = string2.length(); + for(int i = 0, j = 0; i < string1Length && j < string2Length; i++, j++) { + char ch1 = string1.charAt(i); + char ch2 = string2.charAt(j); + if ((isDigit(ch1) || ch1 == ' ') && (isDigit(ch2) || ch2 == ' ')) { + int startNum1 = i; + while (ch1 == ' ' || ch1 == '0') { // skip leading spaces and zeros + startNum1++; + if (startNum1 >= string1Length) break; + ch1 = string1.charAt(startNum1); + } + int startNum2 = j; + while (ch2 == ' ' || ch2 == '0') { + startNum2++; + if (startNum2 >= string2Length) break; + ch2 = string2.charAt(startNum2); + } + i = startNum1; + j = startNum2; + while (i < string1Length && isDigit(string1.charAt(i))) i++; + while (j < string2Length && isDigit(string2.charAt(j))) j++; + final int lengthDiff = (i - startNum1) - (j - startNum2); + if (lengthDiff != 0) { + return lengthDiff; + } + for (; startNum1 < i; startNum1++, startNum2++) { + final int diff = string1.charAt(startNum1) - string2.charAt(startNum2); + if (diff != 0) { + return diff; + } + } + } else { + if (caseSensitive) { + return ch1 - ch2; + } else { + // similar logic to charsMatch() below + if (ch1 != ch2) { + final int diff1 = Character.toUpperCase(ch1) - Character.toUpperCase(ch2); + if (diff1 != 0) { + final int diff2 = Character.toLowerCase(ch1) - Character.toLowerCase(ch2); + if (diff2 != 0) { + return diff2; + } + } + } + } + } + } + if (!caseSensitive && string1Length == string2Length) { + // do case sensitive compare if case insensitive strings are equal + return naturalCompare(string1, string2, true); + } + return string1Length - string2Length; + } + + private static boolean isDigit(char c) { + return (c >= '0' && c <= '9'); + } + public static int compare(@Nullable String s1, @Nullable String s2, boolean ignoreCase) { if (s1 == s2) return 0; if (s1 == null) return -1; diff --git a/platform/util/testSrc/com/intellij/util/text/StringUtilTest.java b/platform/util/testSrc/com/intellij/util/text/StringUtilTest.java index 0a529a75da2f..fef119fc77fb 100644 --- a/platform/util/testSrc/com/intellij/util/text/StringUtilTest.java +++ b/platform/util/testSrc/com/intellij/util/text/StringUtilTest.java @@ -18,7 +18,7 @@ package com.intellij.util.text; import com.intellij.openapi.util.text.StringUtil; import junit.framework.TestCase; -import java.util.List; +import java.util.*; /** * @author Eugene Zhuravlev @@ -70,4 +70,23 @@ public class StringUtilTest extends TestCase { assertFalse(StringUtil.startsWithConcatenationOf("something", "something", ".")); assertFalse(StringUtil.startsWithConcatenationOf("some", "something", "")); } + + public void testNaturalCompare() { + final List strings = new ArrayList(Arrays.asList("Test99", "tes0", "test0", "testing", "test", "test99", "test011", "test1", + "test 3", "test2", "test10a", "test10", "1.2.10.5", "1.2.9.1")); + final Comparator c = new Comparator() { + @Override + public int compare(String o1, String o2) { + return StringUtil.naturalCompare(o1, o2); + } + }; + Collections.sort(strings, c); + assertEquals(Arrays.asList("1.2.9.1", "1.2.10.5", "tes0", "test", "test0", "test1", "test2", "test 3", "test10", "test10a", + "test011", "Test99", "test99", "testing"), strings); + final List strings2 = new ArrayList(Arrays.asList("t1", "t001", "T2", "T002", "T1", "t2")); + Collections.sort(strings2, c); + assertEquals(Arrays.asList("T1", "t1", "t001", "T2", "t2", "T002"), strings2); + assertEquals(1 ,StringUtil.naturalCompare("7403515080361171695", "07403515080361171694")); + assertEquals(-14, StringUtil.naturalCompare("_firstField", "myField1")); + } } diff --git a/plugins/InspectionGadgets/src/com/siyeh/InspectionGadgetsBundle.properties b/plugins/InspectionGadgets/src/com/siyeh/InspectionGadgetsBundle.properties index 4338ebede38b..e6a2401bbfb9 100644 --- a/plugins/InspectionGadgets/src/com/siyeh/InspectionGadgetsBundle.properties +++ b/plugins/InspectionGadgets/src/com/siyeh/InspectionGadgetsBundle.properties @@ -1930,3 +1930,6 @@ static.variable.of.concrete.class.option=Ignore static fields whose type is an a class.only.used.in.one.package.display.name=Class only used from one other package class.only.used.in.one.package.problem.descriptor=Class #ref has only dependencies on and/or dependents in package ''{0}'' #loc unnecessary.return.option=Ignore in then branch branch of if statement with else branch +usage.of.obsolete.assert.display.name=Usage of obsolete 'junit.framework.Assert' +use.of.obsolete.assert.problem.descriptor=Call to #ref() from 'org.junit.framework.Assert' should be replaced with call to method from 'org.junit.Assert' +use.of.obsolete.assert.quickfix=Replace with 'org.junit.Assert' method call diff --git a/plugins/InspectionGadgets/src/com/siyeh/ig/InspectionGadgetsPlugin.java b/plugins/InspectionGadgets/src/com/siyeh/ig/InspectionGadgetsPlugin.java index 78330d1cbdad..da077133c654 100644 --- a/plugins/InspectionGadgets/src/com/siyeh/ig/InspectionGadgetsPlugin.java +++ b/plugins/InspectionGadgets/src/com/siyeh/ig/InspectionGadgetsPlugin.java @@ -769,6 +769,7 @@ public class InspectionGadgetsPlugin implements ApplicationComponent, m_inspectionClasses.add(TestMethodIsPublicVoidNoArgInspection.class); m_inspectionClasses.add(TestMethodWithoutAssertionInspection.class); m_inspectionClasses.add(UnconstructableTestCaseInspection.class); + m_inspectionClasses.add(UseOfObsoleteAssertInspection.class); } private void registerJavaBeansInspections() { diff --git a/plugins/InspectionGadgets/src/com/siyeh/ig/abstraction/DeclareCollectionAsInterfaceInspection.java b/plugins/InspectionGadgets/src/com/siyeh/ig/abstraction/DeclareCollectionAsInterfaceInspection.java index e4f5ce18ca3b..d061b65aa7c4 100644 --- a/plugins/InspectionGadgets/src/com/siyeh/ig/abstraction/DeclareCollectionAsInterfaceInspection.java +++ b/plugins/InspectionGadgets/src/com/siyeh/ig/abstraction/DeclareCollectionAsInterfaceInspection.java @@ -288,8 +288,7 @@ public class DeclareCollectionAsInterfaceInspection extends BaseInspection { } final ProgressManager progressManager = ProgressManager.getInstance(); - final PsiManager manager = element.getManager(); - final PsiSearchHelper searchHelper = manager.getSearchHelper(); + final PsiSearchHelper searchHelper = PsiSearchHelper.SERVICE.getInstance(element.getProject()); final GlobalSearchScope scope = GlobalSearchScope.projectScope(element.getProject()); return searchHelper.isCheapEnoughToSearch(name, scope, null, diff --git a/plugins/InspectionGadgets/src/com/siyeh/ig/abstraction/StaticMethodOnlyUsedInOneClassInspection.java b/plugins/InspectionGadgets/src/com/siyeh/ig/abstraction/StaticMethodOnlyUsedInOneClassInspection.java index 3003396b69bb..4441028a0411 100644 --- a/plugins/InspectionGadgets/src/com/siyeh/ig/abstraction/StaticMethodOnlyUsedInOneClassInspection.java +++ b/plugins/InspectionGadgets/src/com/siyeh/ig/abstraction/StaticMethodOnlyUsedInOneClassInspection.java @@ -209,8 +209,7 @@ public class StaticMethodOnlyUsedInOneClassInspection public PsiClass getUsageClass(final PsiMethod method) { final ProgressManager progressManager = ProgressManager.getInstance(); - final PsiManager manager = method.getManager(); - final PsiSearchHelper searchHelper = manager.getSearchHelper(); + final PsiSearchHelper searchHelper = PsiSearchHelper.SERVICE.getInstance(method.getProject()); final String name = method.getName(); final GlobalSearchScope scope = GlobalSearchScope.allScope(method.getProject()); diff --git a/plugins/InspectionGadgets/src/com/siyeh/ig/junit/UseOfObsoleteAssertInspection.java b/plugins/InspectionGadgets/src/com/siyeh/ig/junit/UseOfObsoleteAssertInspection.java new file mode 100644 index 000000000000..c58fd7ed83cf --- /dev/null +++ b/plugins/InspectionGadgets/src/com/siyeh/ig/junit/UseOfObsoleteAssertInspection.java @@ -0,0 +1,228 @@ +/* + * Copyright 2003-2011 Dave Griffith, Bas Leijdekkers + * + * 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. + */ +package com.siyeh.ig.junit; + +import com.intellij.codeInspection.ProblemDescriptor; +import com.intellij.openapi.module.Module; +import com.intellij.openapi.module.ModuleUtil; +import com.intellij.openapi.project.Project; +import com.intellij.openapi.util.Comparing; +import com.intellij.psi.*; +import com.intellij.psi.codeStyle.JavaCodeStyleManager; +import com.intellij.psi.search.GlobalSearchScope; +import com.intellij.psi.util.PsiTreeUtil; +import com.intellij.util.IncorrectOperationException; +import com.siyeh.InspectionGadgetsBundle;import com.siyeh.ig.BaseInspection; +import com.siyeh.ig.BaseInspectionVisitor; +import com.siyeh.ig.InspectionGadgetsFix; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +public class UseOfObsoleteAssertInspection extends BaseInspection { + + @Override + @NotNull + public String getDisplayName() { + return InspectionGadgetsBundle.message("usage.of.obsolete.assert.display.name"); + } + + @Override + @NotNull + protected String buildErrorString(Object... infos) { + return InspectionGadgetsBundle.message("use.of.obsolete.assert.problem.descriptor"); + } + + @Override + protected InspectionGadgetsFix buildFix(Object... infos) { + return new ReplaceObsoleteAssertsFix(); + } + + @Override + public BaseInspectionVisitor buildVisitor() { + return new UseOfObsoleteAssertVisitor(); + } + + private static class UseOfObsoleteAssertVisitor extends BaseInspectionVisitor { + + @Override + public void visitMethodCallExpression(PsiMethodCallExpression expression) { + final Project project = expression.getProject(); + final Module module = ModuleUtil.findModuleForPsiElement(expression); + if (module == null) { + return; + } + final PsiClass newAssertClass = JavaPsiFacade.getInstance(project) + .findClass("org.junit.Assert", GlobalSearchScope.moduleWithDependenciesAndLibrariesScope(module)); + if (newAssertClass == null) { + return; + } + final PsiMethod psiMethod = expression.resolveMethod(); + if (psiMethod == null || !psiMethod.hasModifierProperty(PsiModifier.STATIC)) { + return; + } + final PsiClass containingClass = psiMethod.getContainingClass(); + if (containingClass != null && Comparing.strEqual(containingClass.getQualifiedName(), "junit.framework.Assert")) { + registerMethodCallError(expression); + } + } + } + + private static class ReplaceObsoleteAssertsFix extends InspectionGadgetsFix { + @Override + protected void doFix(Project project, ProblemDescriptor descriptor) throws IncorrectOperationException { + final PsiElement psiElement = PsiTreeUtil.getParentOfType(descriptor.getPsiElement(), PsiMethodCallExpression.class); + if (!(psiElement instanceof PsiMethodCallExpression)) { + return; + } + final PsiClass newAssertClass = + JavaPsiFacade.getInstance(project).findClass("org.junit.Assert", GlobalSearchScope.allScope(project)); + final PsiClass oldAssertClass = + JavaPsiFacade.getInstance(project).findClass("junit.framework.Assert", GlobalSearchScope.allScope(project)); + + if (newAssertClass == null) { + return; + } + final PsiMethodCallExpression methodCallExpression = (PsiMethodCallExpression)psiElement; + final PsiReferenceExpression methodExpression = methodCallExpression.getMethodExpression(); + final PsiExpression qualifierExpression = methodExpression.getQualifierExpression(); + final PsiElement usedImport = qualifierExpression instanceof PsiReferenceExpression ? + ((PsiReferenceExpression)qualifierExpression).advancedResolve(true).getCurrentFileResolveScope() : + methodExpression.advancedResolve(true).getCurrentFileResolveScope(); + final PsiMethod psiMethod = methodCallExpression.resolveMethod(); + + final boolean isImportUnused = isImportBecomeUnused(methodCallExpression, usedImport, psiMethod); + + PsiImportStaticStatement staticStatement = null; + if (qualifierExpression == null) { + staticStatement = staticallyImported(oldAssertClass, methodExpression); + } + + final JavaCodeStyleManager styleManager = JavaCodeStyleManager.getInstance(project); + if (staticStatement == null) { + methodExpression.setQualifierExpression(JavaPsiFacade.getElementFactory(project).createReferenceExpression(newAssertClass)); + + if (isImportUnused && usedImport instanceof PsiImportStatementBase) { + usedImport.delete(); + } + + styleManager.shortenClassReferences(methodExpression); + } + else { + if (isImportUnused) { + final PsiJavaCodeReferenceElement importReference = staticStatement.getImportReference(); + if (importReference != null) { + if (staticStatement.isOnDemand()) { + importReference.bindToElement(newAssertClass); + } + else { + final PsiExpression importQExpression = ((PsiReferenceExpression)importReference).getQualifierExpression(); + if (importQExpression instanceof PsiReferenceExpression) { + ((PsiReferenceExpression)importQExpression).bindToElement(newAssertClass); + } + } + } + } + else { + methodExpression + .setQualifierExpression(JavaPsiFacade.getElementFactory(project).createReferenceExpression(newAssertClass)); + styleManager.shortenClassReferences(methodExpression); + } + } + /* + //refs can be optimized now but should we really? + if (isImportUnused) { + for (PsiReference reference : ReferencesSearch.search(newAssertClass, new LocalSearchScope(methodCallExpression.getContainingFile()))) { + final PsiElement element = reference.getElement(); + styleManager.shortenClassReferences(element); + } + }*/ + } + + private static boolean isImportBecomeUnused(final PsiMethodCallExpression methodCallExpression, + final PsiElement usedImport, + final PsiMethod psiMethod) { + final boolean[] proceed = new boolean[]{true}; + methodCallExpression.getContainingFile().accept(new JavaRecursiveElementWalkingVisitor() { + @Override + public void visitElement(PsiElement element) { + if (proceed[0]) { + super.visitElement(element); + } + } + + @Override + public void visitMethodCallExpression(PsiMethodCallExpression expression) { + super.visitMethodCallExpression(expression); + if (expression == methodCallExpression) { + return; + } + final PsiMethod resolved = expression.resolveMethod(); + if (resolved == psiMethod) { + proceed[0] = false; + } + else { + final PsiElement resolveScope = + expression.getMethodExpression().advancedResolve(false).getCurrentFileResolveScope(); + if (resolveScope == usedImport) { + proceed[0] = false; + } + } + } + }); + return proceed[0]; + } + + @Nullable + private static PsiImportStaticStatement staticallyImported(PsiClass oldAssertClass, PsiReferenceExpression methodExpression) { + final String referenceName = methodExpression.getReferenceName(); + final PsiFile containingFile = methodExpression.getContainingFile(); + if (!(containingFile instanceof PsiJavaFile)) { + return null; + } + final PsiImportList importList = ((PsiJavaFile)containingFile).getImportList(); + if (importList == null) { + return null; + } + final PsiImportStaticStatement[] statements = importList.getImportStaticStatements(); + for (PsiImportStaticStatement statement : statements) { + if (oldAssertClass != statement.resolveTargetClass()) { + continue; + } + final String importRefName = statement.getReferenceName(); + final PsiJavaCodeReferenceElement importReference = statement.getImportReference(); + if (importReference == null) { + continue; + } + if (Comparing.strEqual(importRefName, referenceName)) { + final PsiElement qualifier = importReference.getQualifier(); + if (qualifier instanceof PsiJavaCodeReferenceElement) { + return statement; + } + } + else if (importRefName == null) { + return statement; + } + } + return null; + } + + @NotNull + @Override + public String getName() { + return InspectionGadgetsBundle.message("use.of.obsolete.assert.quickfix"); + } + } +} \ No newline at end of file diff --git a/plugins/InspectionGadgets/src/com/siyeh/ig/maturity/ObsoleteCollectionInspection.java b/plugins/InspectionGadgets/src/com/siyeh/ig/maturity/ObsoleteCollectionInspection.java index c99600adb7d4..4d6de46f0887 100644 --- a/plugins/InspectionGadgets/src/com/siyeh/ig/maturity/ObsoleteCollectionInspection.java +++ b/plugins/InspectionGadgets/src/com/siyeh/ig/maturity/ObsoleteCollectionInspection.java @@ -16,7 +16,7 @@ package com.siyeh.ig.maturity; import com.intellij.psi.*; -import com.intellij.psi.search.GlobalSearchScope; +import com.intellij.psi.search.GlobalSearchScopes; import com.intellij.psi.search.searches.ReferencesSearch; import com.intellij.psi.util.PsiTreeUtil; import com.intellij.util.Query; @@ -150,7 +150,7 @@ public class ObsoleteCollectionInspection extends BaseInspection { final PsiFile containingFile = namedElement.getContainingFile(); final Query query = ReferencesSearch.search(namedElement, - GlobalSearchScope.fileScope(containingFile)); + GlobalSearchScopes.fileScope(containingFile)); for (PsiReference reference : query) { final PsiElement element = reference.getElement(); if (isRequiredObsoleteCollectionElement(element)) { diff --git a/plugins/InspectionGadgets/src/com/siyeh/ig/maturity/TodoUtil.java b/plugins/InspectionGadgets/src/com/siyeh/ig/maturity/TodoUtil.java index dc96c04cd5d1..35264662194d 100644 --- a/plugins/InspectionGadgets/src/com/siyeh/ig/maturity/TodoUtil.java +++ b/plugins/InspectionGadgets/src/com/siyeh/ig/maturity/TodoUtil.java @@ -18,7 +18,6 @@ package com.siyeh.ig.maturity; import com.intellij.openapi.util.TextRange; import com.intellij.psi.PsiComment; import com.intellij.psi.PsiFile; -import com.intellij.psi.PsiManager; import com.intellij.psi.search.PsiSearchHelper; import com.intellij.psi.search.TodoItem; @@ -29,8 +28,7 @@ public class TodoUtil{ public static boolean isTodoComment(PsiComment comment){ final PsiFile file = comment.getContainingFile(); - final PsiManager psiManager = comment.getManager(); - final PsiSearchHelper searchHelper = psiManager.getSearchHelper(); + final PsiSearchHelper searchHelper = PsiSearchHelper.SERVICE.getInstance(comment.getProject()); final TodoItem[] todoItems = searchHelper.findTodoItems(file); for(final TodoItem todoItem : todoItems){ final TextRange commentTextRange = comment.getTextRange(); diff --git a/plugins/InspectionGadgets/src/inspectionDescriptions/UseOfObsoleteAssert.html b/plugins/InspectionGadgets/src/inspectionDescriptions/UseOfObsoleteAssert.html new file mode 100644 index 000000000000..8f75339f6c37 --- /dev/null +++ b/plugins/InspectionGadgets/src/inspectionDescriptions/UseOfObsoleteAssert.html @@ -0,0 +1,8 @@ + + +This inspection reports any calls to methods from the junit.framework.Assert class. This class is +obsolete and the calls can be replaced by calls to methods from the org.junit.Assert class. +

+New in 11, Powered by InspectionGadgets + + \ No newline at end of file diff --git a/plugins/InspectionGadgets/test/com/siyeh/igfixes/junit/useOfObsoleteAssert/extendsTestCase.after.java b/plugins/InspectionGadgets/test/com/siyeh/igfixes/junit/useOfObsoleteAssert/extendsTestCase.after.java new file mode 100644 index 000000000000..f0c176200bde --- /dev/null +++ b/plugins/InspectionGadgets/test/com/siyeh/igfixes/junit/useOfObsoleteAssert/extendsTestCase.after.java @@ -0,0 +1,9 @@ +import junit.framework.TestCase; +import org.junit.Assert; + +class MyTest extends TestCase { + public void test() { + Assert.fail(); + fail(); + } +} \ No newline at end of file diff --git a/plugins/InspectionGadgets/test/com/siyeh/igfixes/junit/useOfObsoleteAssert/extendsTestCase.java b/plugins/InspectionGadgets/test/com/siyeh/igfixes/junit/useOfObsoleteAssert/extendsTestCase.java new file mode 100644 index 000000000000..64124a4320e1 --- /dev/null +++ b/plugins/InspectionGadgets/test/com/siyeh/igfixes/junit/useOfObsoleteAssert/extendsTestCase.java @@ -0,0 +1,8 @@ +import junit.framework.TestCase; + +class MyTest extends TestCase { + public void test() { + fail(); + fail(); + } +} \ No newline at end of file diff --git a/plugins/InspectionGadgets/test/com/siyeh/igfixes/junit/useOfObsoleteAssert/onDemandStaticImport.after.java b/plugins/InspectionGadgets/test/com/siyeh/igfixes/junit/useOfObsoleteAssert/onDemandStaticImport.after.java new file mode 100644 index 000000000000..7f9c618b11cf --- /dev/null +++ b/plugins/InspectionGadgets/test/com/siyeh/igfixes/junit/useOfObsoleteAssert/onDemandStaticImport.after.java @@ -0,0 +1,10 @@ +import org.junit.Assert; + +import static junit.framework.Assert.*; + +class MyTest { + public void test() { + Assert.fail(); + fail(); + } +} \ No newline at end of file diff --git a/plugins/InspectionGadgets/test/com/siyeh/igfixes/junit/useOfObsoleteAssert/onDemandStaticImport.java b/plugins/InspectionGadgets/test/com/siyeh/igfixes/junit/useOfObsoleteAssert/onDemandStaticImport.java new file mode 100644 index 000000000000..e36dec6cf832 --- /dev/null +++ b/plugins/InspectionGadgets/test/com/siyeh/igfixes/junit/useOfObsoleteAssert/onDemandStaticImport.java @@ -0,0 +1,8 @@ +import static junit.framework.Assert.*; + +class MyTest { + public void test() { + fail(); + fail(); + } +} \ No newline at end of file diff --git a/plugins/InspectionGadgets/test/com/siyeh/igfixes/junit/useOfObsoleteAssert/singleStaticAccess.after.java b/plugins/InspectionGadgets/test/com/siyeh/igfixes/junit/useOfObsoleteAssert/singleStaticAccess.after.java new file mode 100644 index 000000000000..997fc560f8c2 --- /dev/null +++ b/plugins/InspectionGadgets/test/com/siyeh/igfixes/junit/useOfObsoleteAssert/singleStaticAccess.after.java @@ -0,0 +1,7 @@ +import org.junit.Assert; + +class MyTest { + public void test() { + Assert.fail(); + } +} \ No newline at end of file diff --git a/plugins/InspectionGadgets/test/com/siyeh/igfixes/junit/useOfObsoleteAssert/singleStaticAccess.java b/plugins/InspectionGadgets/test/com/siyeh/igfixes/junit/useOfObsoleteAssert/singleStaticAccess.java new file mode 100644 index 000000000000..c7aa55e4b43b --- /dev/null +++ b/plugins/InspectionGadgets/test/com/siyeh/igfixes/junit/useOfObsoleteAssert/singleStaticAccess.java @@ -0,0 +1,7 @@ +import junit.framework.Assert; + +class MyTest { + public void test() { + Assert.fail(); + } +} \ No newline at end of file diff --git a/plugins/InspectionGadgets/test/com/siyeh/igfixes/junit/useOfObsoleteAssert/staticAccess.after.java b/plugins/InspectionGadgets/test/com/siyeh/igfixes/junit/useOfObsoleteAssert/staticAccess.after.java new file mode 100644 index 000000000000..4341a60ac53e --- /dev/null +++ b/plugins/InspectionGadgets/test/com/siyeh/igfixes/junit/useOfObsoleteAssert/staticAccess.after.java @@ -0,0 +1,8 @@ +import junit.framework.Assert; + +class MyTest { + public void test() { + Assert.fail(); + org.junit.Assert.fail(); + } +} \ No newline at end of file diff --git a/plugins/InspectionGadgets/test/com/siyeh/igfixes/junit/useOfObsoleteAssert/staticAccess.java b/plugins/InspectionGadgets/test/com/siyeh/igfixes/junit/useOfObsoleteAssert/staticAccess.java new file mode 100644 index 000000000000..80bace0bcba5 --- /dev/null +++ b/plugins/InspectionGadgets/test/com/siyeh/igfixes/junit/useOfObsoleteAssert/staticAccess.java @@ -0,0 +1,8 @@ +import junit.framework.Assert; + +class MyTest { + public void test() { + Assert.fail(); + Assert.fail(); + } +} \ No newline at end of file diff --git a/plugins/InspectionGadgets/test/com/siyeh/igfixes/junit/useOfObsoleteAssert/staticImport.after.java b/plugins/InspectionGadgets/test/com/siyeh/igfixes/junit/useOfObsoleteAssert/staticImport.after.java new file mode 100644 index 000000000000..ff06c148ae81 --- /dev/null +++ b/plugins/InspectionGadgets/test/com/siyeh/igfixes/junit/useOfObsoleteAssert/staticImport.after.java @@ -0,0 +1,10 @@ +import org.junit.Assert; + +import static junit.framework.Assert.fail; + +class MyTest { + public void test() { + fail(); + Assert.fail(); + } +} \ No newline at end of file diff --git a/plugins/InspectionGadgets/test/com/siyeh/igfixes/junit/useOfObsoleteAssert/staticImport.java b/plugins/InspectionGadgets/test/com/siyeh/igfixes/junit/useOfObsoleteAssert/staticImport.java new file mode 100644 index 000000000000..f7d2cf672cb8 --- /dev/null +++ b/plugins/InspectionGadgets/test/com/siyeh/igfixes/junit/useOfObsoleteAssert/staticImport.java @@ -0,0 +1,8 @@ +import static junit.framework.Assert.fail; + +class MyTest { + public void test() { + fail(); + fail(); + } +} \ No newline at end of file diff --git a/plugins/InspectionGadgets/testsrc/com/siyeh/ig/fixes/junit/UseOfObsoleteAssertInspectionTest.java b/plugins/InspectionGadgets/testsrc/com/siyeh/ig/fixes/junit/UseOfObsoleteAssertInspectionTest.java new file mode 100644 index 000000000000..544f71b6e5cf --- /dev/null +++ b/plugins/InspectionGadgets/testsrc/com/siyeh/ig/fixes/junit/UseOfObsoleteAssertInspectionTest.java @@ -0,0 +1,67 @@ +/* + * Copyright 2000-2011 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. + */ +package com.siyeh.ig.fixes.junit; + +import com.siyeh.InspectionGadgetsBundle; +import com.siyeh.ig.IGQuickFixesTestCase; +import com.siyeh.ig.junit.UseOfObsoleteAssertInspection; + +/** + * User: anna + * Date: 8/18/11 + */ +public class UseOfObsoleteAssertInspectionTest extends IGQuickFixesTestCase { + @Override + public void setUp() throws Exception { + super.setUp(); + + myFixture.addClass("package junit.framework; public class Assert { public static void fail(){}}"); + + myFixture.addClass("package junit.framework; public class TestCase extends Assert {}"); + myFixture.addClass("package org.junit; public class Assert { public static void fail(){}}"); + + myFixture.enableInspections(new UseOfObsoleteAssertInspection()); + } + + public void testExtendsTestCase() { + doFixTest(); + } + + public void testStaticAccess() { + doFixTest(); + } + + public void testSingleStaticAccess() { + doFixTest(); + } + + public void testOnDemandStaticImport() { + doFixTest(); + } + + public void testStaticImport() { + doFixTest(); + } + + private void doFixTest() { + doTest(getTestName(true), InspectionGadgetsBundle.message("use.of.obsolete.assert.quickfix")); + } + + @Override + protected String getRelativePath() { + return "junit/useOfObsoleteAssert"; + } +} diff --git a/plugins/IntelliLang/java-support/org/intellij/plugins/intelliLang/pattern/compiler/AnnotationBasedInstrumentingCompiler.java b/plugins/IntelliLang/java-support/org/intellij/plugins/intelliLang/pattern/compiler/AnnotationBasedInstrumentingCompiler.java index 3479f56803fc..6b6190780f80 100644 --- a/plugins/IntelliLang/java-support/org/intellij/plugins/intelliLang/pattern/compiler/AnnotationBasedInstrumentingCompiler.java +++ b/plugins/IntelliLang/java-support/org/intellij/plugins/intelliLang/pattern/compiler/AnnotationBasedInstrumentingCompiler.java @@ -67,7 +67,7 @@ public abstract class AnnotationBasedInstrumentingCompiler implements ClassInstr final Project project = context.getProject(); final Set result = new HashSet(); - final PsiSearchHelper searchHelper = PsiManager.getInstance(context.getProject()).getSearchHelper(); + final PsiSearchHelper searchHelper = PsiSearchHelper.SERVICE.getInstance(context.getProject()); DumbService.getInstance(project).waitForSmartMode(); diff --git a/plugins/IntentionPowerPak/src/com/siyeh/ipp/comment/ChangeToEndOfLineCommentIntention.java b/plugins/IntentionPowerPak/src/com/siyeh/ipp/comment/ChangeToEndOfLineCommentIntention.java index 7ed686a7cf33..c389ef571aa6 100644 --- a/plugins/IntentionPowerPak/src/com/siyeh/ipp/comment/ChangeToEndOfLineCommentIntention.java +++ b/plugins/IntentionPowerPak/src/com/siyeh/ipp/comment/ChangeToEndOfLineCommentIntention.java @@ -33,7 +33,7 @@ public class ChangeToEndOfLineCommentIntention extends Intention { throws IncorrectOperationException { final PsiComment comment = (PsiComment)element; final PsiManager manager = comment.getManager(); - final CodeStyleManager codeStyleManager = manager.getCodeStyleManager(); + final CodeStyleManager codeStyleManager = CodeStyleManager.getInstance(manager.getProject()); final PsiElement parent = comment.getParent(); assert parent != null; final PsiElementFactory factory = JavaPsiFacade.getInstance(manager.getProject()).getElementFactory(); diff --git a/plugins/IntentionPowerPak/src/com/siyeh/ipp/comment/MoveCommentToSeparateLineIntention.java b/plugins/IntentionPowerPak/src/com/siyeh/ipp/comment/MoveCommentToSeparateLineIntention.java index cf042e877f4c..de84c53a93f7 100644 --- a/plugins/IntentionPowerPak/src/com/siyeh/ipp/comment/MoveCommentToSeparateLineIntention.java +++ b/plugins/IntentionPowerPak/src/com/siyeh/ipp/comment/MoveCommentToSeparateLineIntention.java @@ -58,7 +58,7 @@ public class MoveCommentToSeparateLineIntention extends Intention { parent.addBefore(copyWhiteSpace, insertedComment); selectedComment.delete(); - final CodeStyleManager codeStyleManager = manager.getCodeStyleManager(); + final CodeStyleManager codeStyleManager = CodeStyleManager.getInstance(manager.getProject()); codeStyleManager.reformat(insertedComment); } diff --git a/plugins/IntentionPowerPak/src/com/siyeh/ipp/concatenation/MakeAppendChainIntoAppendSequenceIntention.java b/plugins/IntentionPowerPak/src/com/siyeh/ipp/concatenation/MakeAppendChainIntoAppendSequenceIntention.java index 77ab17336d25..5fe2899be10e 100644 --- a/plugins/IntentionPowerPak/src/com/siyeh/ipp/concatenation/MakeAppendChainIntoAppendSequenceIntention.java +++ b/plugins/IntentionPowerPak/src/com/siyeh/ipp/concatenation/MakeAppendChainIntoAppendSequenceIntention.java @@ -112,7 +112,7 @@ public class MakeAppendChainIntoAppendSequenceIntention extends Intention { final PsiElementFactory factory = JavaPsiFacade.getElementFactory(project); final PsiElement appendStatementParent = appendStatement.getParent(); - final CodeStyleManager codeStyleManager = manager.getCodeStyleManager(); + final CodeStyleManager codeStyleManager = CodeStyleManager.getInstance(manager.getProject()); final PsiCodeBlock codeBlock = factory.createCodeBlockFromText(builder.toString(), appendStatement); diff --git a/plugins/IntentionPowerPak/src/com/siyeh/ipp/conditional/ReplaceConditionalWithIfIntention.java b/plugins/IntentionPowerPak/src/com/siyeh/ipp/conditional/ReplaceConditionalWithIfIntention.java index 858781b48918..db3e9e2e69c5 100644 --- a/plugins/IntentionPowerPak/src/com/siyeh/ipp/conditional/ReplaceConditionalWithIfIntention.java +++ b/plugins/IntentionPowerPak/src/com/siyeh/ipp/conditional/ReplaceConditionalWithIfIntention.java @@ -95,7 +95,7 @@ public class ReplaceConditionalWithIfIntention extends Intention { final PsiElement parent = statement.getParent(); final PsiElement addedElement = parent.addAfter(ifStatement, statement); - final CodeStyleManager styleManager = manager.getCodeStyleManager(); + final CodeStyleManager styleManager = CodeStyleManager.getInstance(manager.getProject()); styleManager.reformat(addedElement); } else { final PsiElement expressionParent = expression.getParent(); diff --git a/plugins/IntentionPowerPak/src/com/siyeh/ipp/initialization/SplitDeclarationAndInitializationIntention.java b/plugins/IntentionPowerPak/src/com/siyeh/ipp/initialization/SplitDeclarationAndInitializationIntention.java index 714209b55a5d..9bce9a7b725b 100644 --- a/plugins/IntentionPowerPak/src/com/siyeh/ipp/initialization/SplitDeclarationAndInitializationIntention.java +++ b/plugins/IntentionPowerPak/src/com/siyeh/ipp/initialization/SplitDeclarationAndInitializationIntention.java @@ -108,7 +108,7 @@ public class SplitDeclarationAndInitializationIntention extends Intention { } } initializer.delete(); - final CodeStyleManager codeStyleManager = manager.getCodeStyleManager(); + final CodeStyleManager codeStyleManager = CodeStyleManager.getInstance(manager.getProject()); codeStyleManager.reformat(field); codeStyleManager.reformat(classInitializer); HighlightUtil.highlightElement(addedElement, diff --git a/plugins/IntentionPowerPak/src/com/siyeh/ipp/whileloop/ExtractWhileLoopConditionToIfStatementIntention.java b/plugins/IntentionPowerPak/src/com/siyeh/ipp/whileloop/ExtractWhileLoopConditionToIfStatementIntention.java index bb685f804329..18e3b77abe9f 100644 --- a/plugins/IntentionPowerPak/src/com/siyeh/ipp/whileloop/ExtractWhileLoopConditionToIfStatementIntention.java +++ b/plugins/IntentionPowerPak/src/com/siyeh/ipp/whileloop/ExtractWhileLoopConditionToIfStatementIntention.java @@ -70,7 +70,7 @@ public class ExtractWhileLoopConditionToIfStatementIntention extends Intention { } else { return; } - final CodeStyleManager codeStyleManager = manager.getCodeStyleManager(); + final CodeStyleManager codeStyleManager = CodeStyleManager.getInstance(manager.getProject()); codeStyleManager.reformat(newElement); } } \ No newline at end of file diff --git a/plugins/android/src/org/jetbrains/android/exportSignedPackage/ChooseModuleStep.java b/plugins/android/src/org/jetbrains/android/exportSignedPackage/ChooseModuleStep.java index ccb5f9cf58a7..2244913de37e 100644 --- a/plugins/android/src/org/jetbrains/android/exportSignedPackage/ChooseModuleStep.java +++ b/plugins/android/src/org/jetbrains/android/exportSignedPackage/ChooseModuleStep.java @@ -20,6 +20,7 @@ import com.intellij.ide.ui.ListCellRendererWrapper; import com.intellij.ide.util.PropertiesComponent; import com.intellij.ide.wizard.CommitStepException; import com.intellij.openapi.module.Module; +import com.intellij.openapi.module.ModuleType; import com.intellij.ui.CollectionComboBoxModel; import org.jetbrains.android.facet.AndroidFacet; import org.jetbrains.android.util.AndroidBundle; @@ -62,7 +63,7 @@ class ChooseModuleStep extends ExportSignedPackageWizardStep { public void customize(JList list, AndroidFacet value, int index, boolean selected, boolean hasFocus) { final Module module = value.getModule(); setText(module.getName()); - setIcon(module.getModuleType().getNodeIcon(false)); + setIcon(ModuleType.get(module).getNodeIcon(false)); } }); myModuleCombo.addActionListener(new ActionListener() { diff --git a/plugins/android/src/org/jetbrains/android/newProject/AndroidModuleConfigurationEditorProvider.java b/plugins/android/src/org/jetbrains/android/newProject/AndroidModuleConfigurationEditorProvider.java index 0025a08aa9a2..98b77903d7be 100644 --- a/plugins/android/src/org/jetbrains/android/newProject/AndroidModuleConfigurationEditorProvider.java +++ b/plugins/android/src/org/jetbrains/android/newProject/AndroidModuleConfigurationEditorProvider.java @@ -16,6 +16,7 @@ package org.jetbrains.android.newProject; +import com.intellij.openapi.module.ModuleType; import com.intellij.openapi.roots.ui.configuration.ModuleConfigurationEditorProvider; import com.intellij.openapi.roots.ui.configuration.ModuleConfigurationState; import com.intellij.openapi.roots.ui.configuration.DefaultModuleConfigurationEditorFactory; @@ -35,7 +36,7 @@ import java.util.ArrayList; public class AndroidModuleConfigurationEditorProvider implements ModuleConfigurationEditorProvider { public ModuleConfigurationEditor[] createEditors(ModuleConfigurationState state) { final Module module = state.getRootModel().getModule(); - if (module.getModuleType() != AndroidModuleType.getInstance()) { + if (ModuleType.get(module) != AndroidModuleType.getInstance()) { return ModuleConfigurationEditor.EMPTY; } diff --git a/plugins/android/src/org/jetbrains/android/newProject/AndroidModulesComboBox.java b/plugins/android/src/org/jetbrains/android/newProject/AndroidModulesComboBox.java index 44b8c5f15bde..3c7dc4cb8f6e 100644 --- a/plugins/android/src/org/jetbrains/android/newProject/AndroidModulesComboBox.java +++ b/plugins/android/src/org/jetbrains/android/newProject/AndroidModulesComboBox.java @@ -18,6 +18,7 @@ package org.jetbrains.android.newProject; import com.intellij.ide.ui.ListCellRendererWrapper; import com.intellij.openapi.module.Module; import com.intellij.openapi.module.ModuleManager; +import com.intellij.openapi.module.ModuleType; import com.intellij.openapi.project.Project; import org.jetbrains.android.facet.AndroidFacet; import org.jetbrains.annotations.NotNull; @@ -37,7 +38,7 @@ public class AndroidModulesComboBox extends JComboBox { if (value instanceof Module) { final Module module = (Module)value; setText(module.getName()); - setIcon(module.getModuleType().getNodeIcon(false)); + setIcon(ModuleType.get(module).getNodeIcon(false)); } else { setText("[none]"); diff --git a/plugins/android/src/org/jetbrains/android/uipreview/LayoutDeviceConfigurationsDialog.java b/plugins/android/src/org/jetbrains/android/uipreview/LayoutDeviceConfigurationsDialog.java index 74f17aaa88d8..a002f1a86ca5 100644 --- a/plugins/android/src/org/jetbrains/android/uipreview/LayoutDeviceConfigurationsDialog.java +++ b/plugins/android/src/org/jetbrains/android/uipreview/LayoutDeviceConfigurationsDialog.java @@ -58,9 +58,11 @@ public class LayoutDeviceConfigurationsDialog extends DialogWrapper { myProject = project; myLayoutDeviceManager = layoutDeviceManager; - - mySelectedDeviceConfigName = selectedConfig.getName(); - mySelectedDeviceName = selectedConfig.getDevice().getName(); + + if (selectedConfig != null) { + mySelectedDeviceConfigName = selectedConfig.getName(); + mySelectedDeviceName = selectedConfig.getDevice().getName(); + } setTitle(AndroidBundle.message("android.layout.preview.device.configurations.dialog.title")); diff --git a/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/actions/actionVisibility/CvsActionVisibility.java b/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/actions/actionVisibility/CvsActionVisibility.java index ec73e45210b8..ea4fbdfcae22 100644 --- a/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/actions/actionVisibility/CvsActionVisibility.java +++ b/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/actions/actionVisibility/CvsActionVisibility.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2011 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. @@ -21,12 +21,10 @@ import com.intellij.cvsSupport2.actions.cvsContext.CvsLightweightFile; import com.intellij.cvsSupport2.application.CvsEntriesManager; import com.intellij.openapi.actionSystem.AnActionEvent; import com.intellij.openapi.actionSystem.Presentation; -import com.intellij.openapi.vfs.LocalFileSystem; import com.intellij.openapi.vfs.VirtualFile; import java.io.File; import java.util.ArrayList; -import java.util.Iterator; import java.util.List; /** @@ -37,13 +35,12 @@ public class CvsActionVisibility { private boolean myCanBePerformedOnFile = true; private boolean myCanBePerformedOnDirectory = true; private boolean myCanBePerformedOnSeveralFiles = false; - private final boolean myExpectedCvsAsActiveVcs = true; - private final List myConditions = new ArrayList(); + private final List myConditions = new ArrayList(); private boolean myCanBePerformedOnLocallyDeletedFile = false; private boolean myCanBePerformedOnCvsLightweightFile = false; - public static interface Condition{ + public interface Condition{ boolean isPerformedOn(CvsContext context); } @@ -51,18 +48,11 @@ public class CvsActionVisibility { myConditions.add(condition); } - public boolean isVisible(CvsContext context){ - if (!myExpectedCvsAsActiveVcs) return true; - return context.cvsIsActive(); - } - - public boolean isEnabled(CvsContext context){ - boolean result = (context.cvsIsActive() || !myExpectedCvsAsActiveVcs) - && hasSuitableType(context); + private boolean isEnabled(CvsContext context){ + boolean result = context.cvsIsActive() && hasSuitableType(context); if (!result) return false; - for (Iterator each = myConditions.iterator(); each.hasNext();) { - Condition condition = (Condition) each.next(); + for (Condition condition : myConditions) { if (!condition.isPerformedOn(context)) return false; } return true; @@ -107,40 +97,35 @@ public class CvsActionVisibility { } private boolean containsFileFromUnsupportedFileSystem(VirtualFile[] selectedFiles) { - for (int i = 0; i < selectedFiles.length; i++) { - VirtualFile selectedFile = selectedFiles[i]; + for (VirtualFile selectedFile : selectedFiles) { if (!selectedFile.isInLocalFileSystem()) return true; } return false; } private boolean containsFile(VirtualFile[] selectedFiles) { - for (int i = 0; i < selectedFiles.length; i++) { - VirtualFile selectedFile = selectedFiles[i]; + for (VirtualFile selectedFile : selectedFiles) { if (!selectedFile.isDirectory()) return true; } return false; } private boolean containsDirectory(VirtualFile[] selectedFiles) { - for (int i = 0; i < selectedFiles.length; i++) { - VirtualFile selectedFile = selectedFiles[i]; + for (VirtualFile selectedFile : selectedFiles) { if (selectedFile.isDirectory()) return true; } return false; } private boolean containsDirectory(File[] selectedFiles) { - for (int i = 0; i < selectedFiles.length; i++) { - File selectedFile = selectedFiles[i]; + for (File selectedFile : selectedFiles) { if (selectedFile.isDirectory()) return true; } return false; } private boolean containsFile(File[] selectedFiles) { - for (int i = 0; i < selectedFiles.length; i++) { - File selectedFile = selectedFiles[i]; + for (File selectedFile : selectedFiles) { if (selectedFile.isFile()) return true; } return false; @@ -160,12 +145,10 @@ public class CvsActionVisibility { CvsContext cvsContext = CvsContextWrapper.createInstance(e); Presentation presentation = e.getPresentation(); presentation.setEnabled(isEnabled(cvsContext)); - presentation.setVisible(isVisible(cvsContext)); + presentation.setVisible(cvsContext.cvsIsActive()); } public void canBePerformedOnCvsLightweightFile() { myCanBePerformedOnCvsLightweightFile = true; } - - } diff --git a/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/application/CvsEntriesManager.java b/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/application/CvsEntriesManager.java index 5239937f1b9d..7b5600a9a75f 100644 --- a/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/application/CvsEntriesManager.java +++ b/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/application/CvsEntriesManager.java @@ -384,7 +384,7 @@ public class CvsEntriesManager extends VirtualFileAdapter { return myStringToSettingsMap.get(cvsRoot); } - public UserDirIgnores getUserdIgnores() { + public UserDirIgnores getUserDirIgnores() { return myUserDirIgnores; } @@ -396,8 +396,8 @@ public class CvsEntriesManager extends VirtualFileAdapter { } } - private boolean isUserHomeCvsIgnoreFile(VirtualFile file) { - return myUserDirIgnores.userHomeCvsIgnoreFile().equals(CvsVfsUtil.getFileFor(file)); + private static boolean isUserHomeCvsIgnoreFile(VirtualFile file) { + return UserDirIgnores.userHomeCvsIgnoreFile().equals(CvsVfsUtil.getFileFor(file)); } public boolean isActive() { diff --git a/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/config/ImportConfiguration.java b/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/config/ImportConfiguration.java index 6e63dda7a808..51dcc03d33a1 100644 --- a/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/config/ImportConfiguration.java +++ b/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/config/ImportConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2011 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. @@ -20,7 +20,6 @@ import com.intellij.openapi.components.ServiceManager; import java.util.ArrayList; import java.util.Collection; -import java.util.Iterator; import java.util.List; /** * author: lesya @@ -48,8 +47,7 @@ public class ImportConfiguration extends AbstractConfiguration { return result; String[] wrappers = KEYWORD_SUBSTITUTION_WRAPPERS.split(";"); - for (int i = 0; i < wrappers.length; i++) { - String wrapper = wrappers[i]; + for (String wrapper : wrappers) { String[] extAndSubstitution = wrapper.split(" "); if (extAndSubstitution.length != 2) continue; result.add(new FileExtension(extAndSubstitution[0], extAndSubstitution[1])); @@ -57,10 +55,9 @@ public class ImportConfiguration extends AbstractConfiguration { return result; } - public void setExtensions(List items) { - StringBuffer buffer = new StringBuffer(); - for (Iterator iterator = items.iterator(); iterator.hasNext();) { - FileExtension extension = (FileExtension)iterator.next(); + public void setExtensions(List items) { + StringBuilder buffer = new StringBuilder(); + for (FileExtension extension : items) { buffer.append(extension.getExtension()); buffer.append(" "); buffer.append(extension.getKeywordSubstitution().getSubstitution().toString()); diff --git a/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/config/ui/SelectCvsConfigurationDialog.java b/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/config/ui/SelectCvsConfigurationDialog.java index d99cd350085c..53b0a9829700 100644 --- a/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/config/ui/SelectCvsConfigurationDialog.java +++ b/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/config/ui/SelectCvsConfigurationDialog.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2011 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. @@ -15,8 +15,8 @@ */ package com.intellij.cvsSupport2.config.ui; +import com.intellij.CvsBundle; import com.intellij.cvsSupport2.config.CvsRootConfiguration; -import com.intellij.cvsSupport2.config.ui.SelectCvsConfgurationPanel; import com.intellij.openapi.project.Project; import com.intellij.openapi.ui.DialogWrapper; @@ -28,11 +28,11 @@ import java.util.Observer; * author: lesya */ public class SelectCvsConfigurationDialog extends DialogWrapper { - private final SelectCvsConfgurationPanel myPanel; + private final SelectCvsConfigurationPanel myPanel; public SelectCvsConfigurationDialog(Project project) { super(true); - myPanel = new SelectCvsConfgurationPanel(project); + myPanel = new SelectCvsConfigurationPanel(project); setOKActionEnabled(myPanel.getSelectedConfiguration() != null); myPanel.getObservable().addObserver(new Observer() { @@ -40,7 +40,7 @@ public class SelectCvsConfigurationDialog extends DialogWrapper { setOKActionEnabled(myPanel.getSelectedConfiguration() != null); } }); - setTitle(com.intellij.CvsBundle.message("dialog.title.select.cvs.root.configuration")); + setTitle(CvsBundle.message("dialog.title.select.cvs.root.configuration")); init(); } @@ -56,6 +56,4 @@ public class SelectCvsConfigurationDialog extends DialogWrapper { public CvsRootConfiguration getSelectedConfiguration() { return myPanel.getSelectedConfiguration(); } - - } diff --git a/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/config/ui/SelectCvsConfgurationPanel.java b/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/config/ui/SelectCvsConfigurationPanel.java similarity index 77% rename from plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/config/ui/SelectCvsConfgurationPanel.java rename to plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/config/ui/SelectCvsConfigurationPanel.java index 189a264c20e8..f7923aedba83 100644 --- a/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/config/ui/SelectCvsConfgurationPanel.java +++ b/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/config/ui/SelectCvsConfigurationPanel.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2011 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. @@ -15,6 +15,7 @@ */ package com.intellij.cvsSupport2.config.ui; +import com.intellij.CvsBundle; import com.intellij.cvsSupport2.config.CvsApplicationLevelConfiguration; import com.intellij.cvsSupport2.config.CvsRootConfiguration; import com.intellij.openapi.project.Project; @@ -28,20 +29,20 @@ import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.util.ArrayList; -import java.util.Iterator; +import java.util.List; import java.util.Observable; /** * author: lesya */ -public class SelectCvsConfgurationPanel extends JPanel { +public class SelectCvsConfigurationPanel extends JPanel { private final DefaultListModel myModel = new DefaultListModel(); private final JList myList = new JBList(myModel); private CvsRootConfiguration mySelection; private final Project myProject; private final MyObservable myObservable; - public SelectCvsConfgurationPanel(Project project) { + public SelectCvsConfigurationPanel(Project project) { super(new BorderLayout(2, 4)); myProject = project; add(createListPanel(), BorderLayout.CENTER); @@ -58,13 +59,11 @@ public class SelectCvsConfgurationPanel extends JPanel { myList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); fillModel(null); - - } private Component createButtonPanel() { JPanel result = new JPanel(new BorderLayout()); - JButton jButton = new JButton(com.intellij.CvsBundle.message("button.text.configure.cvs.roots")); + JButton jButton = new JButton(CvsBundle.message("button.text.configure.cvs.roots")); jButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { editConfigurations(); @@ -83,44 +82,35 @@ public class SelectCvsConfgurationPanel extends JPanel { } public void editConfigurations() { + final CvsApplicationLevelConfiguration configuration = CvsApplicationLevelConfiguration.getInstance(); CvsConfigurationsListEditor cvsConfigurationsListEditor = - new CvsConfigurationsListEditor(new ArrayList(getConfigurationList()), myProject); + new CvsConfigurationsListEditor(new ArrayList(configuration.CONFIGURATIONS), myProject); CvsRootConfiguration selectedConfiguration = getSelectedConfiguration(); if (selectedConfiguration != null) { cvsConfigurationsListEditor.selectConfiguration(selectedConfiguration); } cvsConfigurationsListEditor.show(); if (cvsConfigurationsListEditor.isOK()) { - getConfiguration().CONFIGURATIONS = - new ArrayList(cvsConfigurationsListEditor.getConfigurations()); + configuration.CONFIGURATIONS = + new ArrayList(cvsConfigurationsListEditor.getConfigurations()); fillModel(cvsConfigurationsListEditor.getSelectedConfiguration()); } } private void fillModel(Object selectedConfiguration) { - Object oldSelection = selectedConfiguration == null ? myList.getSelectedValue() : selectedConfiguration; + Object selection = selectedConfiguration == null ? myList.getSelectedValue() : selectedConfiguration; myModel.removeAllElements(); - java.util.List configurations = getConfigurationList(); - for (Iterator each = configurations.iterator(); each.hasNext();) { - CvsRootConfiguration configuration = (CvsRootConfiguration)each.next(); + List configurations = CvsApplicationLevelConfiguration.getInstance().CONFIGURATIONS; + for (CvsRootConfiguration configuration : configurations) { myModel.addElement(configuration); } - myList.setSelectedValue(oldSelection, true); + myList.setSelectedValue(selection, true); if (myList.getSelectedIndex() < 0 && myList.getModel().getSize() > 0) { myList.setSelectedIndex(0); } } - private java.util.List getConfigurationList() { - return getConfiguration().CONFIGURATIONS; - } - - private CvsApplicationLevelConfiguration getConfiguration() { - return CvsApplicationLevelConfiguration.getInstance(); - } - - public CvsRootConfiguration getSelectedConfiguration() { return mySelection; } diff --git a/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/cvsBrowser/TreeNodeComparator.java b/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/cvsBrowser/TreeNodeComparator.java index 83279cc84cbc..c86fc6bb34f2 100644 --- a/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/cvsBrowser/TreeNodeComparator.java +++ b/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/cvsBrowser/TreeNodeComparator.java @@ -16,6 +16,7 @@ package com.intellij.cvsSupport2.cvsBrowser; import com.intellij.openapi.util.SystemInfo; +import com.intellij.openapi.util.text.StringUtil; import javax.swing.tree.DefaultMutableTreeNode; import java.util.Comparator; @@ -55,10 +56,6 @@ public class TreeNodeComparator implements Comparator { } final String name1 = ((CvsElement)node1).getName(); final String name2 = ((CvsElement)node2).getName(); - final int result = name1.compareToIgnoreCase(name2); - if (result != 0) { - return result; - } - return name1.compareTo(name2); + return StringUtil.naturalCompare(name1, name2); } } diff --git a/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/cvsIgnore/IgnoredFilesInfoImpl.java b/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/cvsIgnore/IgnoredFilesInfoImpl.java index d11c2ed41658..7575644b1edc 100644 --- a/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/cvsIgnore/IgnoredFilesInfoImpl.java +++ b/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/cvsIgnore/IgnoredFilesInfoImpl.java @@ -68,7 +68,7 @@ public class IgnoredFilesInfoImpl implements IgnoredFilesInfo { public static IgnoredFilesInfo EMPTY_FILTER = new IgnoredFilesInfoImpl(){ public boolean shouldBeIgnored(String fileName) { - if (checkPatterns(CvsEntriesManager.getInstance().getUserdIgnores().getPatterns(), fileName)) return true; + if (checkPatterns(CvsEntriesManager.getInstance().getUserDirIgnores().getPatterns(), fileName)) return true; if (checkPatterns(PREDEFINED_PATTERNS, fileName)) return true; return false; } diff --git a/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/cvsIgnore/UserDirIgnores.java b/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/cvsIgnore/UserDirIgnores.java index 319015d22bf8..95e849f69819 100644 --- a/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/cvsIgnore/UserDirIgnores.java +++ b/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/cvsIgnore/UserDirIgnores.java @@ -31,7 +31,21 @@ import java.util.List; public class UserDirIgnores{ private List myPatterns; - @NonNls private static final File ourUserHomeCVSIgnoreFile = new File(System.getProperty("user.home") + "/" + CvsUtil.CVS_IGNORE_FILE); + @NonNls private static final File ourUserHomeCVSIgnoreFile; + + static { + final String home = System.getenv().get("HOME"); + if (home != null) { + final File homeDir = new File(home); + if (homeDir.exists() && homeDir.isDirectory()) { + ourUserHomeCVSIgnoreFile = new File(homeDir, CvsUtil.CVS_IGNORE_FILE); + } else { + ourUserHomeCVSIgnoreFile = new File(System.getProperty("user.home") + "/" + CvsUtil.CVS_IGNORE_FILE); + } + } else { + ourUserHomeCVSIgnoreFile = new File(System.getProperty("user.home") + "/" + CvsUtil.CVS_IGNORE_FILE); + } + } public List getPatterns(){ if (myPatterns == null){ @@ -40,7 +54,7 @@ public class UserDirIgnores{ return myPatterns; } - private List createUserDirIgnoredFilesInfo() { + private static List createUserDirIgnoredFilesInfo() { final File file = userHomeCvsIgnoreFile(); ApplicationManager.getApplication().invokeLater(new Runnable() { public void run() { @@ -50,7 +64,7 @@ public class UserDirIgnores{ return IgnoredFilesInfoImpl.getPattensFor(file); } - public File userHomeCvsIgnoreFile() { + public static File userHomeCvsIgnoreFile() { return ourUserHomeCVSIgnoreFile; } diff --git a/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/cvsoperations/cvsErrors/ErrorMessagesProcessor.java b/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/cvsoperations/cvsErrors/ErrorMessagesProcessor.java index 7e1475c78da0..e687c965f71f 100644 --- a/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/cvsoperations/cvsErrors/ErrorMessagesProcessor.java +++ b/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/cvsoperations/cvsErrors/ErrorMessagesProcessor.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2011 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. @@ -15,11 +15,8 @@ */ package com.intellij.cvsSupport2.cvsoperations.cvsErrors; +import com.intellij.cvsSupport2.cvsoperations.cvsMessages.CvsMessagesAdapter; import com.intellij.cvsSupport2.errorHandling.CvsException; -import com.intellij.cvsSupport2.cvsoperations.cvsMessages.CvsMessagesAdapter; -import com.intellij.cvsSupport2.cvsoperations.cvsErrors.ErrorProcessor; -import com.intellij.cvsSupport2.cvsoperations.cvsErrors.ErrorProcessor; -import com.intellij.cvsSupport2.cvsoperations.cvsMessages.CvsMessagesAdapter; import com.intellij.cvsSupport2.util.CvsVfsUtil; import com.intellij.openapi.vcs.VcsException; import com.intellij.openapi.vfs.VirtualFile; @@ -32,7 +29,6 @@ public class ErrorMessagesProcessor extends CvsMessagesAdapter implements ErrorP private final List myErrors; private final List myWarnings; - public ErrorMessagesProcessor(List errors) { myErrors = errors; myWarnings = new ArrayList(); @@ -43,7 +39,6 @@ public class ErrorMessagesProcessor extends CvsMessagesAdapter implements ErrorP } public void addError(String message, String relativeFilePath, ICvsFileSystem cvsFileSystem, String cvsRoot) { - addErrorOnCurrentMessage(relativeFilePath, message, cvsFileSystem, myErrors, cvsRoot); } @@ -51,17 +46,18 @@ public class ErrorMessagesProcessor extends CvsMessagesAdapter implements ErrorP addErrorOnCurrentMessage(relativeFilePath, message, cvsFileSystem, myWarnings, cvsRoot); } - private void addErrorOnCurrentMessage(String relativeFileName, - String message, - ICvsFileSystem cvsFileSystem, - List collection, String cvsRoot) { + private static void addErrorOnCurrentMessage(String relativeFileName, + String message, + ICvsFileSystem cvsFileSystem, + List collection, + String cvsRoot) { VirtualFile vFile = getVirtualFile(cvsFileSystem, relativeFileName); VcsException vcsException = new CvsException(message, cvsRoot); if (vFile != null) vcsException.setVirtualFile(vFile); collection.add(vcsException); } - private VirtualFile getVirtualFile(ICvsFileSystem cvsFileSystem, String relativeFileName) { + private static VirtualFile getVirtualFile(ICvsFileSystem cvsFileSystem, String relativeFileName) { if (cvsFileSystem == null) return null; if (relativeFileName == null) return null; return CvsVfsUtil.findFileByIoFile(cvsFileSystem.getLocalFileSystem().getFile(relativeFileName)); diff --git a/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/cvsoperations/cvsErrors/ErrorProcessor.java b/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/cvsoperations/cvsErrors/ErrorProcessor.java index 7fd3d8412747..5c9e5ad05e6f 100644 --- a/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/cvsoperations/cvsErrors/ErrorProcessor.java +++ b/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/cvsoperations/cvsErrors/ErrorProcessor.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2011 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. @@ -26,5 +26,5 @@ public interface ErrorProcessor { void addError(VcsException ex); void addWarning(VcsException ex); - List getErrors(); + List getErrors(); } diff --git a/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/ui/experts/SelectCVSConfigurationStep.java b/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/ui/experts/SelectCVSConfigurationStep.java index b9623c737cb7..71d2d3888fcc 100644 --- a/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/ui/experts/SelectCVSConfigurationStep.java +++ b/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/ui/experts/SelectCVSConfigurationStep.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2011 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. @@ -15,8 +15,9 @@ */ package com.intellij.cvsSupport2.ui.experts; +import com.intellij.CvsBundle; import com.intellij.cvsSupport2.config.CvsRootConfiguration; -import com.intellij.cvsSupport2.config.ui.SelectCvsConfgurationPanel; +import com.intellij.cvsSupport2.config.ui.SelectCvsConfigurationPanel; import com.intellij.openapi.project.Project; import javax.swing.*; @@ -28,28 +29,28 @@ import java.util.Observer; * author: lesya */ public class SelectCVSConfigurationStep extends WizardStep{ - private final SelectCvsConfgurationPanel mySelectCvsConfgurationPanel; + private final SelectCvsConfigurationPanel mySelectCvsConfigurationPanel; private final Observer myObserver; public SelectCVSConfigurationStep(Project project, CvsWizard wizard) { - super(com.intellij.CvsBundle.message("dialog.title.select.cvs.configuration"), wizard); - mySelectCvsConfgurationPanel = new SelectCvsConfgurationPanel(project); + super(CvsBundle.message("dialog.title.select.cvs.configuration"), wizard); + mySelectCvsConfigurationPanel = new SelectCvsConfigurationPanel(project); myObserver = new Observer() { public void update(Observable o, Object arg) { getWizard().updateStep(); } }; - mySelectCvsConfgurationPanel.getObservable().addObserver(myObserver); + mySelectCvsConfigurationPanel.getObservable().addObserver(myObserver); init(); } protected void dispose() { - mySelectCvsConfgurationPanel.getObservable().deleteObserver(myObserver); + mySelectCvsConfigurationPanel.getObservable().deleteObserver(myObserver); } public boolean nextIsEnabled() { - return mySelectCvsConfgurationPanel.getSelectedConfiguration() != null; + return mySelectCvsConfigurationPanel.getSelectedConfiguration() != null; } public boolean setActive() { @@ -58,17 +59,17 @@ public class SelectCVSConfigurationStep extends WizardStep{ protected JComponent createComponent() { JPanel result = new JPanel(new BorderLayout()); - result.add(mySelectCvsConfgurationPanel, BorderLayout.CENTER); + result.add(mySelectCvsConfigurationPanel, BorderLayout.CENTER); JPanel buttonPanel = new JPanel(new BorderLayout()); result.add(buttonPanel, BorderLayout.SOUTH); return result; } public CvsRootConfiguration getSelectedConfiguration() { - return mySelectCvsConfgurationPanel.getSelectedConfiguration(); + return mySelectCvsConfigurationPanel.getSelectedConfiguration(); } public Component getPreferredFocusedComponent() { - return mySelectCvsConfgurationPanel.getJList(); + return mySelectCvsConfigurationPanel.getJList(); } } diff --git a/plugins/devkit/src/actions/GenerateComponentExternalizationAction.java b/plugins/devkit/src/actions/GenerateComponentExternalizationAction.java index 170c567d7404..62eda1f665c9 100644 --- a/plugins/devkit/src/actions/GenerateComponentExternalizationAction.java +++ b/plugins/devkit/src/actions/GenerateComponentExternalizationAction.java @@ -46,7 +46,7 @@ public class GenerateComponentExternalizationAction extends AnAction { assert target != null; final PsiElementFactory factory = JavaPsiFacade.getInstance(target.getProject()).getElementFactory(); - final CodeStyleManager formatter = target.getManager().getCodeStyleManager(); + final CodeStyleManager formatter = CodeStyleManager.getInstance(target.getManager().getProject()); final JavaCodeStyleManager styler = JavaCodeStyleManager.getInstance(target.getProject()); final String qualifiedName = target.getQualifiedName(); Runnable runnable = new Runnable() { diff --git a/plugins/devkit/src/actions/GeneratePluginClassAction.java b/plugins/devkit/src/actions/GeneratePluginClassAction.java index 24e066ee5014..db5e55e00c38 100644 --- a/plugins/devkit/src/actions/GeneratePluginClassAction.java +++ b/plugins/devkit/src/actions/GeneratePluginClassAction.java @@ -20,6 +20,7 @@ import com.intellij.ide.actions.CreateElementActionBase; import com.intellij.openapi.actionSystem.*; import com.intellij.openapi.module.Module; import com.intellij.openapi.module.ModuleManager; +import com.intellij.openapi.module.ModuleType; import com.intellij.openapi.project.Project; import com.intellij.openapi.roots.OrderEntry; import com.intellij.openapi.roots.ProjectFileIndex; @@ -77,7 +78,7 @@ public abstract class GeneratePluginClassAction extends CreateElementActionBase final Module module = getModule(directory); if (module != null) { - if (module.getModuleType() == PluginModuleType.getInstance()) { + if (ModuleType.get(module) == PluginModuleType.getInstance()) { addPluginModule(module); } else { final List candidateModules = PluginModuleType.getCandidateModules(module); diff --git a/plugins/devkit/src/build/PluginBuildParticipantProvider.java b/plugins/devkit/src/build/PluginBuildParticipantProvider.java index 7064ce720196..b8a35d377a96 100644 --- a/plugins/devkit/src/build/PluginBuildParticipantProvider.java +++ b/plugins/devkit/src/build/PluginBuildParticipantProvider.java @@ -18,6 +18,7 @@ package org.jetbrains.idea.devkit.build; import com.intellij.openapi.compiler.make.BuildParticipantProvider; import com.intellij.openapi.module.Module; +import com.intellij.openapi.module.ModuleType; import org.jetbrains.idea.devkit.module.PluginModuleType; import java.util.Collection; @@ -28,7 +29,7 @@ import java.util.Collections; */ public class PluginBuildParticipantProvider extends BuildParticipantProvider { public Collection getParticipants(final Module module) { - if (module.getModuleType() != PluginModuleType.getInstance()) { + if (ModuleType.get(module) != PluginModuleType.getInstance()) { return Collections.emptyList(); } diff --git a/plugins/devkit/src/build/PluginBuildUtil.java b/plugins/devkit/src/build/PluginBuildUtil.java index c173fdc50fcc..157d31cd0cfa 100644 --- a/plugins/devkit/src/build/PluginBuildUtil.java +++ b/plugins/devkit/src/build/PluginBuildUtil.java @@ -18,6 +18,7 @@ package org.jetbrains.idea.devkit.build; import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.module.Module; import com.intellij.openapi.module.ModuleManager; +import com.intellij.openapi.module.ModuleType; import com.intellij.openapi.module.StdModuleTypes; import com.intellij.openapi.projectRoots.Sdk; import com.intellij.openapi.roots.*; @@ -63,7 +64,7 @@ public class PluginBuildUtil { productionRuntimeDependencies(module).forEachModule(new Processor() { @Override public boolean process(Module dep) { - if (dep.getModuleType() == StdModuleTypes.JAVA && !modules.contains(dep)) { + if (ModuleType.get(dep) == StdModuleTypes.JAVA && !modules.contains(dep)) { modules.add(dep); getDependencies(dep, modules); } diff --git a/plugins/devkit/src/build/PrepareAllToDeployAction.java b/plugins/devkit/src/build/PrepareAllToDeployAction.java index b9cf49fa938d..da57a7d1fbd3 100644 --- a/plugins/devkit/src/build/PrepareAllToDeployAction.java +++ b/plugins/devkit/src/build/PrepareAllToDeployAction.java @@ -20,6 +20,7 @@ import com.intellij.openapi.actionSystem.LangDataKeys; import com.intellij.openapi.actionSystem.PlatformDataKeys; import com.intellij.openapi.module.Module; import com.intellij.openapi.module.ModuleManager; +import com.intellij.openapi.module.ModuleType; import com.intellij.openapi.project.Project; import org.jetbrains.idea.devkit.DevKitBundle; import org.jetbrains.idea.devkit.module.PluginModuleType; @@ -36,7 +37,7 @@ public class PrepareAllToDeployAction extends PrepareToDeployAction { List pluginModules = new ArrayList(); for (Module aModule : ModuleManager.getInstance(project).getModules()) { - if (aModule.getModuleType() instanceof PluginModuleType) { + if (ModuleType.get(aModule) instanceof PluginModuleType) { pluginModules.add(aModule); } } @@ -55,7 +56,7 @@ public class PrepareAllToDeployAction extends PrepareToDeployAction { final Project project = e.getData(PlatformDataKeys.PROJECT); if (project != null) { for (Module aModule : (ModuleManager.getInstance(project).getModules())) { - if (aModule.getModuleType() instanceof PluginModuleType) { + if (ModuleType.get(aModule) instanceof PluginModuleType) { moduleCount++; } } @@ -66,7 +67,7 @@ public class PrepareAllToDeployAction extends PrepareToDeployAction { } else if (moduleCount > 0) { final Module module = e.getData(LangDataKeys.MODULE); - if (module == null || !(module.getModuleType() instanceof PluginModuleType)) { + if (module == null || !(ModuleType.get(module) instanceof PluginModuleType)) { enabled = true; } } diff --git a/plugins/devkit/src/build/PrepareToDeployAction.java b/plugins/devkit/src/build/PrepareToDeployAction.java index c141f3723d4d..9739ef0dbc74 100644 --- a/plugins/devkit/src/build/PrepareToDeployAction.java +++ b/plugins/devkit/src/build/PrepareToDeployAction.java @@ -25,6 +25,7 @@ import com.intellij.openapi.compiler.CompilerManager; import com.intellij.openapi.compiler.make.ManifestBuilder; import com.intellij.openapi.fileTypes.FileTypeManager; import com.intellij.openapi.module.Module; +import com.intellij.openapi.module.ModuleType; import com.intellij.openapi.progress.ProgressIndicator; import com.intellij.openapi.progress.ProgressManager; import com.intellij.openapi.project.Project; @@ -67,7 +68,7 @@ public class PrepareToDeployAction extends AnAction { public void actionPerformed(final AnActionEvent e) { final Module module = LangDataKeys.MODULE.getData(e.getDataContext()); - if (module != null && module.getModuleType() instanceof PluginModuleType) { + if (module != null && ModuleType.get(module) instanceof PluginModuleType) { doPrepare(Arrays.asList(module), LangDataKeys.PROJECT.getData(e.getDataContext())); } } @@ -343,7 +344,7 @@ public class PrepareToDeployAction extends AnAction { public void update(AnActionEvent e) { final Module module = LangDataKeys.MODULE.getData(e.getDataContext()); - boolean enabled = module != null && module.getModuleType() instanceof PluginModuleType; + boolean enabled = module != null && ModuleType.get(module) instanceof PluginModuleType; e.getPresentation().setVisible(enabled); e.getPresentation().setEnabled(enabled); if (enabled) { diff --git a/plugins/devkit/src/module/PluginModuleEditorsProvider.java b/plugins/devkit/src/module/PluginModuleEditorsProvider.java index c2b5d0a5cf6f..2e91b570e8bb 100644 --- a/plugins/devkit/src/module/PluginModuleEditorsProvider.java +++ b/plugins/devkit/src/module/PluginModuleEditorsProvider.java @@ -17,6 +17,7 @@ package org.jetbrains.idea.devkit.module; import com.intellij.openapi.module.Module; import com.intellij.openapi.module.ModuleConfigurationEditor; +import com.intellij.openapi.module.ModuleType; import com.intellij.openapi.roots.ui.configuration.DefaultModuleConfigurationEditorFactory; import com.intellij.openapi.roots.ui.configuration.ModuleConfigurationEditorProvider; import com.intellij.openapi.roots.ui.configuration.ModuleConfigurationState; @@ -29,7 +30,7 @@ public class PluginModuleEditorsProvider implements ModuleConfigurationEditorPro public ModuleConfigurationEditor[] createEditors(ModuleConfigurationState state) { final Module module = state.getRootModel().getModule(); - if (module.getModuleType() != PluginModuleType.getInstance()) return ModuleConfigurationEditor.EMPTY; + if (ModuleType.get(module) != PluginModuleType.getInstance()) return ModuleConfigurationEditor.EMPTY; final DefaultModuleConfigurationEditorFactory editorFactory = DefaultModuleConfigurationEditorFactory.getInstance(); List editors = new ArrayList(); diff --git a/plugins/devkit/src/module/PluginModuleType.java b/plugins/devkit/src/module/PluginModuleType.java index 315295f71bfa..b1637ec0e643 100644 --- a/plugins/devkit/src/module/PluginModuleType.java +++ b/plugins/devkit/src/module/PluginModuleType.java @@ -60,7 +60,7 @@ public class PluginModuleType extends ModuleType { } public static boolean isOfType(Module module) { - return module.getModuleType() instanceof PluginModuleType; + return get(module) instanceof PluginModuleType; } public ModuleWizardStep[] createWizardSteps(final WizardContext wizardContext, @@ -107,7 +107,7 @@ public class PluginModuleType extends ModuleType { @Nullable public static XmlFile getPluginXml(Module module, boolean initialize) { if (module == null) return null; - if (!(module.getModuleType() instanceof PluginModuleType)) return null; + if (!(get(module) instanceof PluginModuleType)) return null; final PluginBuildConfiguration buildConfiguration = PluginBuildConfiguration.getInstance(module); if (buildConfiguration == null) return null; @@ -137,7 +137,7 @@ public class PluginModuleType extends ModuleType { final List candidates = new ArrayList(modules.length); final Set deps = new HashSet(modules.length); for (Module m : modules) { - if (m.getModuleType() == getInstance()) { + if (get(m) == getInstance()) { deps.clear(); PluginBuildUtil.getDependencies(m, deps); diff --git a/plugins/devkit/src/run/PluginRunConfiguration.java b/plugins/devkit/src/run/PluginRunConfiguration.java index 301459f68afc..dc0da164deb5 100644 --- a/plugins/devkit/src/run/PluginRunConfiguration.java +++ b/plugins/devkit/src/run/PluginRunConfiguration.java @@ -25,6 +25,7 @@ import com.intellij.execution.runners.ProgramRunner; import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.module.Module; import com.intellij.openapi.module.ModuleManager; +import com.intellij.openapi.module.ModuleType; import com.intellij.openapi.options.SettingsEditor; import com.intellij.openapi.project.Project; import com.intellij.openapi.projectRoots.JavaSdkType; @@ -207,7 +208,7 @@ public class PluginRunConfiguration extends RunConfigurationBase implements Modu List modules = new ArrayList(); Module[] allModules = ModuleManager.getInstance(getProject()).getModules(); for (Module module : allModules) { - if (module.getModuleType() == PluginModuleType.getInstance()) { + if (ModuleType.get(module) == PluginModuleType.getInstance()) { modules.add(module); } } diff --git a/plugins/devkit/src/run/PluginRunConfigurationEditor.java b/plugins/devkit/src/run/PluginRunConfigurationEditor.java index ae1da5511c7d..e583397b813d 100644 --- a/plugins/devkit/src/run/PluginRunConfigurationEditor.java +++ b/plugins/devkit/src/run/PluginRunConfigurationEditor.java @@ -19,6 +19,7 @@ import com.intellij.execution.configurations.LogFileOptions; import com.intellij.ide.ui.ListCellRendererWrapper; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.module.Module; +import com.intellij.openapi.module.ModuleType; import com.intellij.openapi.options.ConfigurationException; import com.intellij.openapi.options.SettingsEditor; import com.intellij.openapi.projectRoots.Sdk; @@ -126,7 +127,7 @@ public class PluginRunConfigurationEditor extends SettingsEditor nojdkModules = new HashSet(); for (Module module : modules) { - if(!GroovyUtils.isAcceptableModuleType(module.getModuleType())) continue; + if(!GroovyUtils.isAcceptableModuleType(ModuleType.get(module))) continue; final Sdk sdk = ModuleRootManager.getInstance(module).getSdk(); if (sdk == null || !(sdk.getSdkType() instanceof JavaSdkType)) { nojdkModules.add(module); diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/compiler/GroovyCompilerBase.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/compiler/GroovyCompilerBase.java index 6e8982a2003c..924d785d4a6f 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/compiler/GroovyCompilerBase.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/compiler/GroovyCompilerBase.java @@ -36,6 +36,7 @@ import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.fileTypes.FileType; import com.intellij.openapi.fileTypes.StdFileTypes; import com.intellij.openapi.module.Module; +import com.intellij.openapi.module.ModuleType; import com.intellij.openapi.progress.ProgressIndicator; import com.intellij.openapi.progress.ProgressManager; import com.intellij.openapi.project.Project; @@ -383,7 +384,7 @@ public abstract class GroovyCompilerBase implements TranslatingCompiler { final CompilerConfiguration configuration = CompilerConfiguration.getInstance(myProject); final PsiManager psiManager = PsiManager.getInstance(myProject); - if (GroovyUtils.isAcceptableModuleType(module.getModuleType())) { + if (GroovyUtils.isAcceptableModuleType(ModuleType.get(module))) { for (final VirtualFile file : moduleFiles) { if (shouldCompile(file, configuration, psiManager)) { (index.isInTestSourceContent(file) ? toCompileTests : toCompile).add(file); diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/findUsages/GrAliasedImportedElementSearcher.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/findUsages/GrAliasedImportedElementSearcher.java index 1cfa50c98c8c..3b89fe4310ca 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/findUsages/GrAliasedImportedElementSearcher.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/findUsages/GrAliasedImportedElementSearcher.java @@ -100,7 +100,7 @@ public class GrAliasedImportedElementSearcher extends QueryExecutorBase T addMemberDeclaration(@NotNull T decl, PsiElement anchorBefore) throws IncorrectOperationException { T result = (T)addBefore(decl, anchorBefore); - CodeStyleManager styleManager = getManager().getCodeStyleManager(); + CodeStyleManager styleManager = CodeStyleManager.getInstance(getManager().getProject()); PsiElement parent = result.getContainingFile(); TextRange range = result.getTextRange(); styleManager.reformatRange(parent, range.getEndOffset() - 1, range.getEndOffset() + 1); diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/statements/GrVariableBaseImpl.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/statements/GrVariableBaseImpl.java index a31a7714ebac..334b19bceb9d 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/statements/GrVariableBaseImpl.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/statements/GrVariableBaseImpl.java @@ -60,7 +60,7 @@ import javax.swing.*; public abstract class GrVariableBaseImpl extends GrStubElementBase implements GrVariable { public static final Logger LOG = Logger.getInstance("org.jetbrains.plugins.groovy.lang.psi.impl.statements.GrVariableImpl"); - private final RecursionGuard myGuard = RecursionManager.createGuard("grVariableInitializer"); + private static final RecursionGuard ourGuard = RecursionManager.createGuard("grVariableInitializer"); public GrVariableBaseImpl(ASTNode node) { super(node); @@ -165,7 +165,7 @@ public abstract class GrVariableBaseImpl extends GrStubEl } if (initializer != null) { - PsiType initializerType = myGuard.doPreventingRecursion(this, true, new NullableComputable() { + PsiType initializerType = ourGuard.doPreventingRecursion(this, true, new NullableComputable() { @Override public PsiType compute() { return initializer.getType(); diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/statements/expressions/path/GrDescriptorReturnTypeCalculator.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/statements/expressions/path/GrDescriptorReturnTypeCalculator.java index 73bfac77f632..0f825eeaf434 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/statements/expressions/path/GrDescriptorReturnTypeCalculator.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/statements/expressions/path/GrDescriptorReturnTypeCalculator.java @@ -1,12 +1,17 @@ package org.jetbrains.plugins.groovy.lang.psi.impl.statements.expressions.path; +import com.intellij.openapi.util.Computable; import com.intellij.openapi.util.Pair; +import com.intellij.openapi.util.RecursionGuard; +import com.intellij.openapi.util.RecursionManager; import com.intellij.openapi.util.text.StringUtil; import com.intellij.psi.*; import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; +import org.jetbrains.plugins.groovy.lang.psi.api.statements.blocks.GrClosableBlock; +import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression; import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrMethodCall; import org.jetbrains.plugins.groovy.lang.psi.impl.statements.expressions.TypesUtil; +import org.jetbrains.plugins.groovy.lang.psi.util.PsiUtil; import java.util.ArrayList; import java.util.HashMap; @@ -18,6 +23,8 @@ import java.util.Map; */ public class GrDescriptorReturnTypeCalculator extends GrCallExpressionTypeCalculator { + private static final RecursionGuard ourGuard = RecursionManager.createGuard("GrDescriptorReturnTypeCalculator getClosureReturnType"); + private Map>>> map; private Map>>> getMap() { @@ -42,21 +49,21 @@ public class GrDescriptorReturnTypeCalculator extends GrCallExpressionTypeCalcul GrMethodReturnTypeDescriptor.Param[] params; - if (descriptor.anyParams != null) { - assert descriptor.anyParams.length == 1; - assert descriptor.params == null; - assert pairs.isEmpty(); - - params = null; - } - else { + if (descriptor.params != null) { params = descriptor.params; - if (params == null) params = GrMethodReturnTypeDescriptor.Param.EMPTY_ARRAY; + assert params != null; + assert (descriptor.checkParamsType == null || descriptor.checkParamsType); for (GrMethodReturnTypeDescriptor.Param param : params) { assert StringUtil.isNotEmpty(param.type); } } + else if (descriptor.checkParamsType != null && descriptor.checkParamsType) { + params = GrMethodReturnTypeDescriptor.Param.EMPTY_ARRAY; + } + else { + params = null; + } assert StringUtil.isNotEmpty(descriptor.returnType); pairs.add(new Pair(params, descriptor.returnType)); @@ -107,11 +114,31 @@ public class GrDescriptorReturnTypeCalculator extends GrCallExpressionTypeCalcul if (typeName == null) return null; - if (typeName.endsWith("[]")) { - PsiClassType type = TypesUtil.createType(typeName.substring(0, typeName.length() - 2), callExpression); - return type.createArrayType(); + if (typeName.equals("!closure")) { + GrExpression[] allArguments = PsiUtil.getAllArguments(callExpression); + GrClosableBlock closure = null; + + for (GrExpression argument : allArguments) { + if (argument instanceof GrClosableBlock) { + closure = (GrClosableBlock)argument; + break; + } + } + + if (closure == null) return null; + + final GrClosableBlock finalClosure = closure; + + return ourGuard.doPreventingRecursion(callExpression, true, new Computable() { + @Override + public PsiType compute() { + PsiType returnType = finalClosure.getReturnType(); + if (returnType == PsiType.VOID) return null; + return returnType; + } + }); } - return TypesUtil.createType(typeName, callExpression); + return JavaPsiFacade.getElementFactory(containingClass.getProject()).createTypeFromText(typeName, callExpression); } } diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/statements/expressions/path/GrMethodReturnTypeDescriptor.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/statements/expressions/path/GrMethodReturnTypeDescriptor.java index 791670457750..1b0c49c5d2fc 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/statements/expressions/path/GrMethodReturnTypeDescriptor.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/statements/expressions/path/GrMethodReturnTypeDescriptor.java @@ -23,9 +23,8 @@ public class GrMethodReturnTypeDescriptor { @Attribute("returnType") public String returnType; - @Property(surroundWithTag = false) - @AbstractCollection(surroundWithTag = false) - public AnyParams[] anyParams; + @Attribute("checkParamsType") + public Boolean checkParamsType; @Property(surroundWithTag = false) @AbstractCollection(surroundWithTag = false) @@ -40,8 +39,4 @@ public class GrMethodReturnTypeDescriptor { public String type; } - @Tag("anyParams") - public static class AnyParams { - - } } diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/synthetic/GrLightMethodBuilder.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/synthetic/GrLightMethodBuilder.java index a00362b15f6d..d63da9877f30 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/synthetic/GrLightMethodBuilder.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/synthetic/GrLightMethodBuilder.java @@ -65,6 +65,8 @@ public class GrLightMethodBuilder extends LightElement implements GrMethod { private String[] myNamedParametersArray = ArrayUtil.EMPTY_STRING_ARRAY; private Runnable myOnRename; + private Object myData; + public GrLightMethodBuilder(PsiManager manager, String name) { this(manager, name, new GrLightParameterListBuilder(manager, GroovyFileType.GROOVY_LANGUAGE), null); } @@ -98,17 +100,14 @@ public class GrLightMethodBuilder extends LightElement implements GrMethod { } public PsiTypeParameterList getTypeParameterList() { - //todo return null; } public GrDocComment getDocComment() { - //todo return null; } public boolean isDeprecated() { - //todo return false; } @@ -202,6 +201,7 @@ public class GrLightMethodBuilder extends LightElement implements GrMethod { return myReturnType; } + @Nullable public GrTypeElement setReturnType(String returnType) { setReturnType(JavaPsiFacade.getInstance(myManager.getProject()).getElementFactory().createTypeByFQClassName(returnType, getResolveScope())); return null; @@ -242,7 +242,6 @@ public class GrLightMethodBuilder extends LightElement implements GrMethod { @NotNull public PsiReferenceList getThrowsList() { - //todo return new LightEmptyImplementsList(getManager()); } @@ -256,8 +255,9 @@ public class GrLightMethodBuilder extends LightElement implements GrMethod { } public boolean isVarArgs() { - //todo - return false; + GrParameter[] parameters = myParameterList.getParameters(); + if (parameters.length == 0) return false; + return parameters[parameters.length - 1].isVarArgs(); } @NotNull @@ -318,6 +318,10 @@ public class GrLightMethodBuilder extends LightElement implements GrMethod { return this; } + public Object getMethodKind() { + return myMethodKind; + } + public GrLightMethodBuilder setMethodKind(@Nullable Object methodKind) { myMethodKind = methodKind; return this; @@ -425,4 +429,15 @@ public class GrLightMethodBuilder extends LightElement implements GrMethod { return copy; } + + @Nullable + public T getData() { + return (T)myData; + } + + public GrLightMethodBuilder setData(@Nullable Object data) { + myData = data; + return this; + } + } diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/synthetic/GrLightParameter.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/synthetic/GrLightParameter.java index 425bdd8bd220..d9236b12434d 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/synthetic/GrLightParameter.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/synthetic/GrLightParameter.java @@ -15,10 +15,7 @@ */ package org.jetbrains.plugins.groovy.lang.psi.impl.synthetic; -import com.intellij.psi.PsiAnnotation; -import com.intellij.psi.PsiElement; -import com.intellij.psi.PsiFile; -import com.intellij.psi.PsiType; +import com.intellij.psi.*; import com.intellij.psi.impl.light.LightVariableBuilder; import com.intellij.util.ArrayUtil; import com.intellij.util.IncorrectOperationException; @@ -39,8 +36,9 @@ public class GrLightParameter extends LightVariableBuilder imp private volatile boolean myOptional; private volatile GrModifierList myModifierList; private PsiElement myScope; + private boolean myVarArg; - public GrLightParameter(@NotNull String name, @NotNull PsiType type, @NotNull PsiElement scope) { + public GrLightParameter(@Nullable String name, @NotNull PsiType type, @NotNull PsiElement scope) { super(scope.getManager(), name, type, GroovyFileType.GROOVY_LANGUAGE); myScope = scope; myModifierList = new GrLightModifierList(this, ArrayUtil.EMPTY_STRING_ARRAY); @@ -54,7 +52,7 @@ public class GrLightParameter extends LightVariableBuilder imp @Override public boolean isVarArgs() { - return false; + return getType() instanceof PsiEllipsisType; } @NotNull diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/synthetic/GrLightParameterListBuilder.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/synthetic/GrLightParameterListBuilder.java index b883720ecf0a..c79e23ae02b0 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/synthetic/GrLightParameterListBuilder.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/synthetic/GrLightParameterListBuilder.java @@ -38,7 +38,7 @@ public class GrLightParameterListBuilder extends LightElement implements GrParam super(manager, language); } - public void addParameter(GrParameter parameter) { + public void addParameter(@NotNull GrParameter parameter) { myParameters.add(parameter); myCachedParameters = null; } @@ -65,12 +65,13 @@ public class GrLightParameterListBuilder extends LightElement implements GrParam @Override public void addParameterToEnd(GrParameter parameter) { - + addParameter(parameter); } @Override public void addParameterToHead(GrParameter parameter) { - throw new IncorrectOperationException("GrLightParameterListBuilder is unmodifiable"); + myParameters.add(0, parameter); + myCachedParameters = null; } @Override @@ -105,4 +106,11 @@ public class GrLightParameterListBuilder extends LightElement implements GrParam public void acceptChildren(GroovyElementVisitor visitor) { } + + @NotNull + public GrParameter removeParameter(int index) { + GrParameter removed = myParameters.remove(index); + myCachedParameters = null; + return removed; + } } diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/mvc/util/ModuleCellRenderer.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/mvc/util/ModuleCellRenderer.java index a483b060ccfd..8cea320dc95e 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/mvc/util/ModuleCellRenderer.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/mvc/util/ModuleCellRenderer.java @@ -17,6 +17,7 @@ package org.jetbrains.plugins.groovy.mvc.util; import com.intellij.ide.ui.ListCellRendererWrapper; import com.intellij.openapi.module.Module; +import com.intellij.openapi.module.ModuleType; import javax.swing.*; @@ -31,7 +32,7 @@ public class ModuleCellRenderer extends ListCellRendererWrapper { @Override public void customize(JList list, Module module, int index, boolean selected, boolean hasFocus) { if (module != null) { - setIcon(module.getModuleType().getNodeIcon(false)); + setIcon(ModuleType.get(module).getNodeIcon(false)); setText(module.getName()); } } diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/introduce/parameter/FieldConflictsResolver.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/introduce/parameter/FieldConflictsResolver.java index 710c1b01e597..138405dd2ea7 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/introduce/parameter/FieldConflictsResolver.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/introduce/parameter/FieldConflictsResolver.java @@ -141,7 +141,7 @@ public class FieldConflictsResolver { expressionFromText = (GrReferenceExpression)factory.createExpressionFromText("A." + member.getName()); expressionFromText.setQualifier(factory.createReferenceElementForClass(qualifyingClass)); } - CodeStyleManager codeStyleManager = manager.getCodeStyleManager(); + CodeStyleManager codeStyleManager = CodeStyleManager.getInstance(manager.getProject()); expressionFromText = (GrReferenceExpression)codeStyleManager.reformat(expressionFromText); return (GrReferenceExpression)referenceExpression.replace(expressionFromText); } diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/introduce/parameter/java2groovy/FieldConflictsResolver.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/introduce/parameter/java2groovy/FieldConflictsResolver.java index 32a7fab003ed..ec310ebba33f 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/introduce/parameter/java2groovy/FieldConflictsResolver.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/introduce/parameter/java2groovy/FieldConflictsResolver.java @@ -105,7 +105,7 @@ public class FieldConflictsResolver { else { expressionFromText = (GrReferenceExpression)factory.createExpressionFromText(qualifyingClass.getQualifiedName()+ '.' + member.getName()); } - CodeStyleManager codeStyleManager = manager.getCodeStyleManager(); + CodeStyleManager codeStyleManager = CodeStyleManager.getInstance(manager.getProject()); expressionFromText = (GrReferenceExpression)codeStyleManager.reformat(expressionFromText); return (GrReferenceExpression)referenceExpression.replace(expressionFromText); } diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/runner/GroovyRunConfigurationEditor.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/runner/GroovyRunConfigurationEditor.java index a46e50b107cf..7eb93093acc3 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/runner/GroovyRunConfigurationEditor.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/runner/GroovyRunConfigurationEditor.java @@ -21,6 +21,7 @@ import com.intellij.ide.ui.ListCellRendererWrapper; import com.intellij.ide.util.BrowseFilesListener; import com.intellij.openapi.fileChooser.FileChooserDescriptor; import com.intellij.openapi.module.Module; +import com.intellij.openapi.module.ModuleType; import com.intellij.openapi.options.ConfigurationException; import com.intellij.openapi.options.SettingsEditor; import com.intellij.openapi.roots.ui.configuration.ModulesAlphaComparator; @@ -119,7 +120,7 @@ public class GroovyRunConfigurationEditor extends SettingsEditor execute(@NotNull HgFile hgFile, VcsFileRevision revision) { @@ -54,14 +55,19 @@ public class HgAnnotateCommand { arguments.add(revisionNumber.getChangeset()); } arguments.add(hgFile.getRelativePath()); - final HgCommandResult result = new HgCommandExecutor(project).executeInCurrentThread(hgFile.getRepo(), "annotate", arguments); + final HgCommandResult result = new HgCommandExecutor(myProject).executeInCurrentThread(hgFile.getRepo(), "annotate", arguments); - final List annotations = new ArrayList(); if (result == null) { - return annotations; + return Collections.emptyList(); } - for (String line : result.getOutputLines()) { + List outputLines = result.getOutputLines(); + return parse(outputLines); + } + + private static List parse(List outputLines) { + List annotations = new ArrayList(outputLines.size()); + for (String line : outputLines) { Matcher matcher = LINE_PATTERN.matcher(line); if (matcher.matches()) { String user = matcher.group(USER_GROUP); diff --git a/plugins/hg4idea/src/org/zmlx/hg4idea/command/HgCommitCommand.java b/plugins/hg4idea/src/org/zmlx/hg4idea/command/HgCommitCommand.java index 7c4f40ceb527..05a4c71c543c 100644 --- a/plugins/hg4idea/src/org/zmlx/hg4idea/command/HgCommitCommand.java +++ b/plugins/hg4idea/src/org/zmlx/hg4idea/command/HgCommitCommand.java @@ -13,9 +13,10 @@ package org.zmlx.hg4idea.command; import com.intellij.openapi.application.PathManager; -import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.project.Project; +import com.intellij.openapi.util.io.FileUtil; import com.intellij.openapi.vcs.VcsException; +import com.intellij.openapi.vfs.CharsetToolkit; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.util.messages.MessageBus; import org.apache.commons.lang.StringUtils; @@ -26,11 +27,8 @@ import org.zmlx.hg4idea.HgVcsMessages; import org.zmlx.hg4idea.execution.HgCommandException; import org.zmlx.hg4idea.execution.HgCommandExecutor; -import java.io.BufferedWriter; import java.io.File; -import java.io.FileWriter; import java.io.IOException; -import java.io.Writer; import java.util.Collections; import java.util.LinkedList; import java.util.List; @@ -40,54 +38,51 @@ import static org.zmlx.hg4idea.HgErrorHandler.ensureSuccess; public class HgCommitCommand { - private static final Logger LOG = Logger.getInstance(HgCommitCommand.class.getName()); - private static final String TEMP_FILE_NAME = ".hg4idea-commit.tmp"; - private final Project project; - private final VirtualFile repo; - private final String message; + private final Project myProject; + private final VirtualFile myRoot; + private final String myMessage; - private Set files = Collections.emptySet(); + private Set myFiles = Collections.emptySet(); - public HgCommitCommand(Project project, @NotNull VirtualFile repo, String message) { - this.project = project; - this.repo = repo; - this.message = message; + public HgCommitCommand(Project project, @NotNull VirtualFile root, String message) { + myProject = project; + myRoot = root; + myMessage = message; } public void setFiles(@NotNull Set files) { - this.files = files; + myFiles = files; } public void execute() throws HgCommandException, VcsException { - if (StringUtils.isBlank(message)) { + if (StringUtils.isBlank(myMessage)) { throw new HgCommandException(HgVcsMessages.message("hg4idea.commit.error.messageEmpty")); } - try { - List parameters = new LinkedList(); - parameters.add("--logfile"); - parameters.add(saveCommitMessage().getAbsolutePath()); - for (HgFile hgFile : files) { - parameters.add(hgFile.getRelativePath()); - } - ensureSuccess(new HgCommandExecutor(project).executeInCurrentThread(repo, "commit", parameters)); - final MessageBus messageBus = project.getMessageBus(); - messageBus.syncPublisher(HgVcs.REMOTE_TOPIC).update(project); - messageBus.syncPublisher(HgVcs.BRANCH_TOPIC).update(project); - } catch (IOException e) { - LOG.info(e); + List parameters = new LinkedList(); + parameters.add("--logfile"); + parameters.add(saveCommitMessage().getAbsolutePath()); + for (HgFile hgFile : myFiles) { + parameters.add(hgFile.getRelativePath()); } + parameters.add("--encoding"); + parameters.add(CharsetToolkit.UTF8); + + ensureSuccess(new HgCommandExecutor(myProject).executeInCurrentThread(myRoot, "commit", parameters)); + final MessageBus messageBus = myProject.getMessageBus(); + messageBus.syncPublisher(HgVcs.REMOTE_TOPIC).update(myProject); + messageBus.syncPublisher(HgVcs.BRANCH_TOPIC).update(myProject); } - private File saveCommitMessage() throws IOException { + private File saveCommitMessage() throws VcsException { File systemDir = new File(PathManager.getSystemPath()); File tempFile = new File(systemDir, TEMP_FILE_NAME); - Writer output = new BufferedWriter(new FileWriter(tempFile, false)); + try { - output.write(message); - } finally { - output.close(); + FileUtil.writeToFile(tempFile, myMessage); + } catch (IOException e) { + throw new VcsException("Couldn't prepare commit message", e); } return tempFile; } diff --git a/plugins/hg4idea/src/org/zmlx/hg4idea/provider/annotate/HgAnnotationLine.java b/plugins/hg4idea/src/org/zmlx/hg4idea/provider/annotate/HgAnnotationLine.java index 939f0fa359b2..1eb3064dbc8c 100644 --- a/plugins/hg4idea/src/org/zmlx/hg4idea/provider/annotate/HgAnnotationLine.java +++ b/plugins/hg4idea/src/org/zmlx/hg4idea/provider/annotate/HgAnnotationLine.java @@ -38,4 +38,20 @@ public class HgAnnotationLine { return fields.get(field); } + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (!(obj instanceof HgAnnotationLine)) { + return false; + } + HgAnnotationLine other = (HgAnnotationLine) obj; + return fields.equals(other.fields); + } + + @Override + public int hashCode() { + return fields.hashCode(); + } } diff --git a/plugins/hg4idea/testData/annotate/etalon b/plugins/hg4idea/testData/annotate/etalon new file mode 100644 index 000000000000..352a6064087d --- /dev/null +++ b/plugins/hg4idea/testData/annotate/etalon @@ -0,0 +1,4621 @@ + + + + + USER + adrian + + + REVISION + + 2287 + 3f0790d500a9 + + + + false + + + + DATE + 2006-02-24 + + + LINE + 1 + + + CONTENT + "Database cache backend." + + + + + + + + jezdez + + + + + 16338 + bf038debb499 + + + + false + + + + + 2011-07-13 + + + + 2 + + + + import base64 + + + + + + + + jezdez + + + + + 16338 + bf038debb499 + + + + false + + + + + 2011-07-13 + + + + 3 + + + + import time + + + + + + + + jezdez + + + + + 16338 + bf038debb499 + + + + false + + + + + 2011-07-13 + + + + 4 + + + + from datetime import datetime + + + + + + + + adrian + + + + + 2287 + 3f0790d500a9 + + + + false + + + + + 2006-02-24 + + + + 2 + + + + + + + + + + + + adrian + + + + + 2287 + 3f0790d500a9 + + + + false + + + + + 2006-02-24 + + + + 7 + + + + try: + + + + + + + + adrian + + + + + 2287 + 3f0790d500a9 + + + + false + + + + + 2006-02-24 + + + + 8 + + + + import cPickle as pickle + + + + + + + + adrian + + + + + 2287 + 3f0790d500a9 + + + + false + + + + + 2006-02-24 + + + + 9 + + + + except ImportError: + + + + + + + + adrian + + + + + 2287 + 3f0790d500a9 + + + + false + + + + + 2006-02-24 + + + + 10 + + + + import pickle + + + + + + + + adrian + + + + + 2287 + 3f0790d500a9 + + + + false + + + + + 2006-02-24 + + + + 11 + + + + + + + + + + + + jezdez + + + + + 16338 + bf038debb499 + + + + false + + + + + 2011-07-13 + + + + 11 + + + + from django.core.cache.backends.base import BaseCache + + + + + + + + jezdez + + + + + 16338 + bf038debb499 + + + + false + + + + + 2011-07-13 + + + + 12 + + + + from django.db import connections, router, transaction, DatabaseError + + + + + + + + jezdez + + + + + 16338 + bf038debb499 + + + + false + + + + + 2011-07-13 + + + + 13 + + + + + + + + + + + + jezdez + + + + + 16338 + bf038debb499 + + + + false + + + + + 2011-07-13 + + + + 14 + + + + + + + + + + + + russellm + + + + + 13275 + 4dd52d4f3f50 + + + + false + + + + + 2010-08-05 + + + + 12 + + + + class Options(object): + + + + + + + + russellm + + + + + 13275 + 4dd52d4f3f50 + + + + false + + + + + 2010-08-05 + + + + 13 + + + + """A class that will quack like a Django model _meta class. + + + + + + + + russellm + + + + + 13275 + 4dd52d4f3f50 + + + + false + + + + + 2010-08-05 + + + + 14 + + + + + + + + + + + + russellm + + + + + 13275 + 4dd52d4f3f50 + + + + false + + + + + 2010-08-05 + + + + 15 + + + + This allows cache operations to be controlled by the router + + + + + + + + russellm + + + + + 13275 + 4dd52d4f3f50 + + + + false + + + + + 2010-08-05 + + + + 16 + + + + """ + + + + + + + + russellm + + + + + 13275 + 4dd52d4f3f50 + + + + false + + + + + 2010-08-05 + + + + 17 + + + + def __init__(self, table): + + + + + + + + russellm + + + + + 13275 + 4dd52d4f3f50 + + + + false + + + + + 2010-08-05 + + + + 18 + + + + self.db_table = table + + + + + + + + russellm + + + + + 13275 + 4dd52d4f3f50 + + + + false + + + + + 2010-08-05 + + + + 19 + + + + self.app_label = 'django_cache' + + + + + + + + russellm + + + + + 13275 + 4dd52d4f3f50 + + + + false + + + + + 2010-08-05 + + + + 20 + + + + self.module_name = 'cacheentry' + + + + + + + + russellm + + + + + 13275 + 4dd52d4f3f50 + + + + false + + + + + 2010-08-05 + + + + 21 + + + + self.verbose_name = 'cache entry' + + + + + + + + russellm + + + + + 13275 + 4dd52d4f3f50 + + + + false + + + + + 2010-08-05 + + + + 22 + + + + self.verbose_name_plural = 'cache entries' + + + + + + + + russellm + + + + + 13275 + 4dd52d4f3f50 + + + + false + + + + + 2010-08-05 + + + + 23 + + + + self.object_name = 'CacheEntry' + + + + + + + + russellm + + + + + 13275 + 4dd52d4f3f50 + + + + false + + + + + 2010-08-05 + + + + 24 + + + + self.abstract = False + + + + + + + + russellm + + + + + 13275 + 4dd52d4f3f50 + + + + false + + + + + 2010-08-05 + + + + 25 + + + + self.managed = True + + + + + + + + russellm + + + + + 13275 + 4dd52d4f3f50 + + + + false + + + + + 2010-08-05 + + + + 26 + + + + self.proxy = False + + + + + + + + russellm + + + + + 13275 + 4dd52d4f3f50 + + + + false + + + + + 2010-08-05 + + + + 27 + + + + + + + + + + + + russellm + + + + + 14807 + 905c4a7e1f19 + + + + false + + + + + 2010-12-21 + + + + 28 + + + + class BaseDatabaseCache(BaseCache): + + + + + + + + russellm + + + + + 14807 + 905c4a7e1f19 + + + + false + + + + + 2010-12-21 + + + + 29 + + + + def __init__(self, table, params): + + + + + + + + russellm + + + + + 14807 + 905c4a7e1f19 + + + + false + + + + + 2010-12-21 + + + + 30 + + + + BaseCache.__init__(self, params) + + + + + + + + russellm + + + + + 13275 + 4dd52d4f3f50 + + + + false + + + + + 2010-08-05 + + + + 31 + + + + self._table = table + + + + + + + + russellm + + + + + 13275 + 4dd52d4f3f50 + + + + false + + + + + 2010-08-05 + + + + 32 + + + + + + + + + + + + russellm + + + + + 13275 + 4dd52d4f3f50 + + + + false + + + + + 2010-08-05 + + + + 33 + + + + class CacheEntry(object): + + + + + + + + russellm + + + + + 13275 + 4dd52d4f3f50 + + + + false + + + + + 2010-08-05 + + + + 34 + + + + _meta = Options(table) + + + + + + + + russellm + + + + + 13275 + 4dd52d4f3f50 + + + + false + + + + + 2010-08-05 + + + + 35 + + + + self.cache_model_class = CacheEntry + + + + + + + + russellm + + + + + 13275 + 4dd52d4f3f50 + + + + false + + + + + 2010-08-05 + + + + 36 + + + + + + + + + + + + russellm + + + + + 14807 + 905c4a7e1f19 + + + + false + + + + + 2010-12-21 + + + + 37 + + + + class DatabaseCache(BaseDatabaseCache): + + + + + + + + russellm + + + + + 14425 + 793e94ba2037 + + + + false + + + + + 2010-11-19 + + + + 38 + + + + def get(self, key, default=None, version=None): + + + + + + + + russellm + + + + + 14425 + 793e94ba2037 + + + + false + + + + + 2010-11-19 + + + + 39 + + + + key = self.make_key(key, version=version) + + + + + + + + mtredinnick + + + + + 13568 + 7e0b7bf098d2 + + + + false + + + + + 2010-09-12 + + + + 49 + + + + self.validate_key(key) + + + + + + + + russellm + + + + + 13275 + 4dd52d4f3f50 + + + + false + + + + + 2010-08-05 + + + + 49 + + + + db = router.db_for_read(self.cache_model_class) + + + + + + + + russellm + + + + + 13275 + 4dd52d4f3f50 + + + + false + + + + + 2010-08-05 + + + + 50 + + + + table = connections[db].ops.quote_name(self._table) + + + + + + + + russellm + + + + + 13275 + 4dd52d4f3f50 + + + + false + + + + + 2010-08-05 + + + + 51 + + + + cursor = connections[db].cursor() + + + + + + + + russellm + + + + + 13275 + 4dd52d4f3f50 + + + + false + + + + + 2010-08-05 + + + + 52 + + + + + + + + + + + + russellm + + + + + 13275 + 4dd52d4f3f50 + + + + false + + + + + 2010-08-05 + + + + 53 + + + + cursor.execute("SELECT cache_key, value, expires FROM %s WHERE cache_key = %%s" % table, [key]) + + + + + + + + adrian + + + + + 2287 + 3f0790d500a9 + + + + false + + + + + 2006-02-24 + + + + 30 + + + + row = cursor.fetchone() + + + + + + + + adrian + + + + + 2287 + 3f0790d500a9 + + + + false + + + + + 2006-02-24 + + + + 31 + + + + if row is None: + + + + + + + + adrian + + + + + 2287 + 3f0790d500a9 + + + + false + + + + + 2006-02-24 + + + + 32 + + + + return default + + + + + + + + adrian + + + + + 2287 + 3f0790d500a9 + + + + false + + + + + 2006-02-24 + + + + 33 + + + + now = datetime.now() + + + + + + + + adrian + + + + + 2287 + 3f0790d500a9 + + + + false + + + + + 2006-02-24 + + + + 34 + + + + if row[2] < now: + + + + + + + + russellm + + + + + 13275 + 4dd52d4f3f50 + + + + false + + + + + 2010-08-05 + + + + 59 + + + + db = router.db_for_write(self.cache_model_class) + + + + + + + + russellm + + + + + 13275 + 4dd52d4f3f50 + + + + false + + + + + 2010-08-05 + + + + 60 + + + + cursor = connections[db].cursor() + + + + + + + + russellm + + + + + 13275 + 4dd52d4f3f50 + + + + false + + + + + 2010-08-05 + + + + 61 + + + + cursor.execute("DELETE FROM %s WHERE cache_key = %%s" % table, [key]) + + + + + + + + russellm + + + + + 13275 + 4dd52d4f3f50 + + + + false + + + + + 2010-08-05 + + + + 62 + + + + transaction.commit_unless_managed(using=db) + + + + + + + + adrian + + + + + 2287 + 3f0790d500a9 + + + + false + + + + + 2006-02-24 + + + + 37 + + + + return default + + + + + + + + russellm + + + + + 13275 + 4dd52d4f3f50 + + + + false + + + + + 2010-08-05 + + + + 64 + + + + value = connections[db].ops.process_clob(row[1]) + + + + + + + + ikelly + + + + + 9862 + 8739c35149dd + + + + false + + + + + 2009-03-13 + + + + 39 + + + + return pickle.loads(base64.decodestring(value)) + + + + + + + + adrian + + + + + 2287 + 3f0790d500a9 + + + + false + + + + + 2006-02-24 + + + + 39 + + + + + + + + + + + + russellm + + + + + 14425 + 793e94ba2037 + + + + false + + + + + 2010-11-19 + + + + 59 + + + + def set(self, key, value, timeout=None, version=None): + + + + + + + + russellm + + + + + 14425 + 793e94ba2037 + + + + false + + + + + 2010-11-19 + + + + 60 + + + + key = self.make_key(key, version=version) + + + + + + + + mtredinnick + + + + + 13568 + 7e0b7bf098d2 + + + + false + + + + + 2010-09-12 + + + + 69 + + + + self.validate_key(key) + + + + + + + + mtredinnick + + + + + 8110 + c787c7f62142 + + + + false + + + + + 2008-08-10 + + + + 41 + + + + self._base_set('set', key, value, timeout) + + + + + + + + mtredinnick + + + + + 6421 + b4175804cc7b + + + + false + + + + + 2007-10-20 + + + + 45 + + + + + + + + + + + + russellm + + + + + 14425 + 793e94ba2037 + + + + false + + + + + 2010-11-19 + + + + 64 + + + + def add(self, key, value, timeout=None, version=None): + + + + + + + + russellm + + + + + 14425 + 793e94ba2037 + + + + false + + + + + 2010-11-19 + + + + 65 + + + + key = self.make_key(key, version=version) + + + + + + + + mtredinnick + + + + + 13568 + 7e0b7bf098d2 + + + + false + + + + + 2010-09-12 + + + + 73 + + + + self.validate_key(key) + + + + + + + + mtredinnick + + + + + 6438 + 5096a56a9ac6 + + + + false + + + + + 2007-10-21 + + + + 44 + + + + return self._base_set('add', key, value, timeout) + + + + + + + + mtredinnick + + + + + 6438 + 5096a56a9ac6 + + + + false + + + + + 2007-10-21 + + + + 45 + + + + + + + + + + + + mtredinnick + + + + + 6421 + b4175804cc7b + + + + false + + + + + 2007-10-20 + + + + 46 + + + + def _base_set(self, mode, key, value, timeout=None): + + + + + + + + adrian + + + + + 2287 + 3f0790d500a9 + + + + false + + + + + 2006-02-24 + + + + 41 + + + + if timeout is None: + + + + + + + + adrian + + + + + 2287 + 3f0790d500a9 + + + + false + + + + + 2006-02-24 + + + + 42 + + + + timeout = self.default_timeout + + + + + + + + russellm + + + + + 13275 + 4dd52d4f3f50 + + + + false + + + + + 2010-08-05 + + + + 76 + + + + db = router.db_for_write(self.cache_model_class) + + + + + + + + russellm + + + + + 13275 + 4dd52d4f3f50 + + + + false + + + + + 2010-08-05 + + + + 77 + + + + table = connections[db].ops.quote_name(self._table) + + + + + + + + russellm + + + + + 13275 + 4dd52d4f3f50 + + + + false + + + + + 2010-08-05 + + + + 78 + + + + cursor = connections[db].cursor() + + + + + + + + russellm + + + + + 13275 + 4dd52d4f3f50 + + + + false + + + + + 2010-08-05 + + + + 79 + + + + + + + + + + + + russellm + + + + + 13275 + 4dd52d4f3f50 + + + + false + + + + + 2010-08-05 + + + + 80 + + + + cursor.execute("SELECT COUNT(*) FROM %s" % table) + + + + + + + + adrian + + + + + 2287 + 3f0790d500a9 + + + + false + + + + + 2006-02-24 + + + + 45 + + + + num = cursor.fetchone()[0] + + + + + + + + adrian + + + + + 2287 + 3f0790d500a9 + + + + false + + + + + 2006-02-24 + + + + 46 + + + + now = datetime.now().replace(microsecond=0) + + + + + + + + adrian + + + + + 2287 + 3f0790d500a9 + + + + false + + + + + 2006-02-24 + + + + 47 + + + + exp = datetime.fromtimestamp(time.time() + timeout).replace(microsecond=0) + + + + + + + + adrian + + + + + 2287 + 3f0790d500a9 + + + + false + + + + + 2006-02-24 + + + + 48 + + + + if num > self._max_entries: + + + + + + + + russellm + + + + + 13275 + 4dd52d4f3f50 + + + + false + + + + + 2010-08-05 + + + + 85 + + + + self._cull(db, cursor, now) + + + + + + + + adrian + + + + + 2287 + 3f0790d500a9 + + + + false + + + + + 2006-02-24 + + + + 50 + + + + encoded = base64.encodestring(pickle.dumps(value, 2)).strip() + + + + + + + + russellm + + + + + 13275 + 4dd52d4f3f50 + + + + false + + + + + 2010-08-05 + + + + 87 + + + + cursor.execute("SELECT cache_key, expires FROM %s WHERE cache_key = %%s" % table, [key]) + + + + + + + + adrian + + + + + 2287 + 3f0790d500a9 + + + + false + + + + + 2006-02-24 + + + + 52 + + + + try: + + + + + + + + mtredinnick + + + + + 9753 + 0ab5ef23e1bc + + + + false + + + + + 2009-03-02 + + + + 59 + + + + result = cursor.fetchone() + + + + + + + + mtredinnick + + + + + 9753 + 0ab5ef23e1bc + + + + false + + + + + 2009-03-02 + + + + 60 + + + + if result and (mode == 'set' or + + + + + + + + mtredinnick + + + + + 9753 + 0ab5ef23e1bc + + + + false + + + + + 2009-03-02 + + + + 61 + + + + (mode == 'add' and result[1] < now)): + + + + + + + + russellm + + + + + 13275 + 4dd52d4f3f50 + + + + false + + + + + 2010-08-05 + + + + 92 + + + + cursor.execute("UPDATE %s SET value = %%s, expires = %%s WHERE cache_key = %%s" % table, + + + + + + + + russellm + + + + + 13275 + 4dd52d4f3f50 + + + + false + + + + + 2010-08-05 + + + + 93 + + + + [encoded, connections[db].ops.value_to_db_datetime(exp), key]) + + + + + + + + adrian + + + + + 2287 + 3f0790d500a9 + + + + false + + + + + 2006-02-24 + + + + 55 + + + + else: + + + + + + + + russellm + + + + + 13275 + 4dd52d4f3f50 + + + + false + + + + + 2010-08-05 + + + + 95 + + + + cursor.execute("INSERT INTO %s (cache_key, value, expires) VALUES (%%s, %%s, %%s)" % table, + + + + + + + + russellm + + + + + 13275 + 4dd52d4f3f50 + + + + false + + + + + 2010-08-05 + + + + 96 + + + + [key, encoded, connections[db].ops.value_to_db_datetime(exp)]) + + + + + + + + adrian + + + + + 2287 + 3f0790d500a9 + + + + false + + + + + 2006-02-24 + + + + 57 + + + + except DatabaseError: + + + + + + + + adrian + + + + + 2287 + 3f0790d500a9 + + + + false + + + + + 2006-02-24 + + + + 58 + + + + # To be threadsafe, updates/inserts are allowed to fail silently + + + + + + + + russellm + + + + + 13275 + 4dd52d4f3f50 + + + + false + + + + + 2010-08-05 + + + + 99 + + + + transaction.rollback_unless_managed(using=db) + + + + + + + + mtredinnick + + + + + 8110 + c787c7f62142 + + + + false + + + + + 2008-08-10 + + + + 65 + + + + return False + + + + + + + + adrian + + + + + 2287 + 3f0790d500a9 + + + + false + + + + + 2006-02-24 + + + + 60 + + + + else: + + + + + + + + russellm + + + + + 13275 + 4dd52d4f3f50 + + + + false + + + + + 2010-08-05 + + + + 102 + + + + transaction.commit_unless_managed(using=db) + + + + + + + + mtredinnick + + + + + 8110 + c787c7f62142 + + + + false + + + + + 2008-08-10 + + + + 68 + + + + return True + + + + + + + + adrian + + + + + 2287 + 3f0790d500a9 + + + + false + + + + + 2006-02-24 + + + + 62 + + + + + + + + + + + + russellm + + + + + 14425 + 793e94ba2037 + + + + false + + + + + 2010-11-19 + + + + 101 + + + + def delete(self, key, version=None): + + + + + + + + russellm + + + + + 14425 + 793e94ba2037 + + + + false + + + + + 2010-11-19 + + + + 102 + + + + key = self.make_key(key, version=version) + + + + + + + + mtredinnick + + + + + 13568 + 7e0b7bf098d2 + + + + false + + + + + 2010-09-12 + + + + 109 + + + + self.validate_key(key) + + + + + + + + russellm + + + + + 14425 + 793e94ba2037 + + + + false + + + + + 2010-11-19 + + + + 104 + + + + + + + + + + + + russellm + + + + + 13275 + 4dd52d4f3f50 + + + + false + + + + + 2010-08-05 + + + + 106 + + + + db = router.db_for_write(self.cache_model_class) + + + + + + + + russellm + + + + + 13275 + 4dd52d4f3f50 + + + + false + + + + + 2010-08-05 + + + + 107 + + + + table = connections[db].ops.quote_name(self._table) + + + + + + + + russellm + + + + + 13275 + 4dd52d4f3f50 + + + + false + + + + + 2010-08-05 + + + + 108 + + + + cursor = connections[db].cursor() + + + + + + + + russellm + + + + + 13275 + 4dd52d4f3f50 + + + + false + + + + + 2010-08-05 + + + + 109 + + + + + + + + + + + + russellm + + + + + 13275 + 4dd52d4f3f50 + + + + false + + + + + 2010-08-05 + + + + 110 + + + + cursor.execute("DELETE FROM %s WHERE cache_key = %%s" % table, [key]) + + + + + + + + russellm + + + + + 13275 + 4dd52d4f3f50 + + + + false + + + + + 2010-08-05 + + + + 111 + + + + transaction.commit_unless_managed(using=db) + + + + + + + + adrian + + + + + 2287 + 3f0790d500a9 + + + + false + + + + + 2006-02-24 + + + + 67 + + + + + + + + + + + + russellm + + + + + 14425 + 793e94ba2037 + + + + false + + + + + 2010-11-19 + + + + 112 + + + + def has_key(self, key, version=None): + + + + + + + + russellm + + + + + 14425 + 793e94ba2037 + + + + false + + + + + 2010-11-19 + + + + 113 + + + + key = self.make_key(key, version=version) + + + + + + + + mtredinnick + + + + + 13568 + 7e0b7bf098d2 + + + + false + + + + + 2010-09-12 + + + + 118 + + + + self.validate_key(key) + + + + + + + + russellm + + + + + 14425 + 793e94ba2037 + + + + false + + + + + 2010-11-19 + + + + 115 + + + + + + + + + + + + russellm + + + + + 13275 + 4dd52d4f3f50 + + + + false + + + + + 2010-08-05 + + + + 114 + + + + db = router.db_for_read(self.cache_model_class) + + + + + + + + russellm + + + + + 13275 + 4dd52d4f3f50 + + + + false + + + + + 2010-08-05 + + + + 115 + + + + table = connections[db].ops.quote_name(self._table) + + + + + + + + russellm + + + + + 13275 + 4dd52d4f3f50 + + + + false + + + + + 2010-08-05 + + + + 116 + + + + cursor = connections[db].cursor() + + + + + + + + russellm + + + + + 13275 + 4dd52d4f3f50 + + + + false + + + + + 2010-08-05 + + + + 117 + + + + + + + + + + + + mtredinnick + + + + + 9753 + 0ab5ef23e1bc + + + + false + + + + + 2009-03-02 + + + + 78 + + + + now = datetime.now().replace(microsecond=0) + + + + + + + + russellm + + + + + 13275 + 4dd52d4f3f50 + + + + false + + + + + 2010-08-05 + + + + 119 + + + + cursor.execute("SELECT cache_key FROM %s WHERE cache_key = %%s and expires > %%s" % table, + + + + + + + + russellm + + + + + 13275 + 4dd52d4f3f50 + + + + false + + + + + 2010-08-05 + + + + 120 + + + + [key, connections[db].ops.value_to_db_datetime(now)]) + + + + + + + + adrian + + + + + 2287 + 3f0790d500a9 + + + + false + + + + + 2006-02-24 + + + + 71 + + + + return cursor.fetchone() is not None + + + + + + + + adrian + + + + + 2287 + 3f0790d500a9 + + + + false + + + + + 2006-02-24 + + + + 72 + + + + + + + + + + + + russellm + + + + + 13275 + 4dd52d4f3f50 + + + + false + + + + + 2010-08-05 + + + + 123 + + + + def _cull(self, db, cursor, now): + + + + + + + + adrian + + + + + 2287 + 3f0790d500a9 + + + + false + + + + + 2006-02-24 + + + + 74 + + + + if self._cull_frequency == 0: + + + + + + + + russellm + + + + + 12116 + c1ad14c551a9 + + + + false + + + + + 2010-01-27 + + + + 87 + + + + self.clear() + + + + + + + + adrian + + + + + 2287 + 3f0790d500a9 + + + + false + + + + + 2006-02-24 + + + + 76 + + + + else: + + + + + + + + russellm + + + + + 13480 + 7351411944a9 + + + + false + + + + + 2010-08-31 + + + + 127 + + + + table = connections[db].ops.quote_name(self._table) + + + + + + + + russellm + + + + + 13275 + 4dd52d4f3f50 + + + + false + + + + + 2010-08-05 + + + + 127 + + + + cursor.execute("DELETE FROM %s WHERE expires < %%s" % table, + + + + + + + + russellm + + + + + 13275 + 4dd52d4f3f50 + + + + false + + + + + 2010-08-05 + + + + 128 + + + + [connections[db].ops.value_to_db_datetime(now)]) + + + + + + + + russellm + + + + + 13275 + 4dd52d4f3f50 + + + + false + + + + + 2010-08-05 + + + + 129 + + + + cursor.execute("SELECT COUNT(*) FROM %s" % table) + + + + + + + + adrian + + + + + 2287 + 3f0790d500a9 + + + + false + + + + + 2006-02-24 + + + + 79 + + + + num = cursor.fetchone()[0] + + + + + + + + adrian + + + + + 2287 + 3f0790d500a9 + + + + false + + + + + 2006-02-24 + + + + 80 + + + + if num > self._max_entries: + + + + + + + + russellm + + + + + 13275 + 4dd52d4f3f50 + + + + false + + + + + 2010-08-05 + + + + 132 + + + + cursor.execute("SELECT cache_key FROM %s ORDER BY cache_key LIMIT 1 OFFSET %%s" % table, [num / self._cull_frequency]) + + + + + + + + russellm + + + + + 13275 + 4dd52d4f3f50 + + + + false + + + + + 2010-08-05 + + + + 133 + + + + cursor.execute("DELETE FROM %s WHERE cache_key < %%s" % table, [cursor.fetchone()[0]]) + + + + + + + + russellm + + + + + 12116 + c1ad14c551a9 + + + + false + + + + + 2010-01-27 + + + + 95 + + + + + + + + + + + + russellm + + + + + 12116 + c1ad14c551a9 + + + + false + + + + + 2010-01-27 + + + + 96 + + + + def clear(self): + + + + + + + + russellm + + + + + 13275 + 4dd52d4f3f50 + + + + false + + + + + 2010-08-05 + + + + 136 + + + + db = router.db_for_write(self.cache_model_class) + + + + + + + + russellm + + + + + 13275 + 4dd52d4f3f50 + + + + false + + + + + 2010-08-05 + + + + 137 + + + + table = connections[db].ops.quote_name(self._table) + + + + + + + + russellm + + + + + 13275 + 4dd52d4f3f50 + + + + false + + + + + 2010-08-05 + + + + 138 + + + + cursor = connections[db].cursor() + + + + + + + + russellm + + + + + 13275 + 4dd52d4f3f50 + + + + false + + + + + 2010-08-05 + + + + 139 + + + + cursor.execute('DELETE FROM %s' % table) + + + + + + + + russellm + + + + + 14807 + 905c4a7e1f19 + + + + false + + + + + 2010-12-21 + + + + 143 + + + + + + + + + + + + russellm + + + + + 14807 + 905c4a7e1f19 + + + + false + + + + + 2010-12-21 + + + + 144 + + + + # For backwards compatibility + + + + + + + + russellm + + + + + 14807 + 905c4a7e1f19 + + + + false + + + + + 2010-12-21 + + + + 145 + + + + class CacheClass(DatabaseCache): + + + + + + + + russellm + + + + + 14807 + 905c4a7e1f19 + + + + false + + + + + 2010-12-21 + + + + 146 + + + + pass + + + + \ No newline at end of file diff --git a/plugins/hg4idea/testData/annotate/info.txt b/plugins/hg4idea/testData/annotate/info.txt new file mode 100644 index 000000000000..b459a2df2395 --- /dev/null +++ b/plugins/hg4idea/testData/annotate/info.txt @@ -0,0 +1,3 @@ +The source - a file with huge history from the hg repository of the Django project: https://bitbucket.org/django/django/ +File: /Users/loki/temp/django/django/core/cache/backends/db.py +Last revision at the time of parsing: bf038debb499 (13.07.11 13:35) \ No newline at end of file diff --git a/plugins/hg4idea/testData/annotate/outputs/hg_1.7.1 b/plugins/hg4idea/testData/annotate/outputs/hg_1.7.1 new file mode 100644 index 000000000000..3acc13feeb81 --- /dev/null +++ b/plugins/hg4idea/testData/annotate/outputs/hg_1.7.1 @@ -0,0 +1,149 @@ + adrian 2287 3f0790d500a9 2006-02-24:1: "Database cache backend." + jezdez 16338 bf038debb499 2011-07-13:2: import base64 + jezdez 16338 bf038debb499 2011-07-13:3: import time + jezdez 16338 bf038debb499 2011-07-13:4: from datetime import datetime + adrian 2287 3f0790d500a9 2006-02-24:2: + adrian 2287 3f0790d500a9 2006-02-24:7: try: + adrian 2287 3f0790d500a9 2006-02-24:8: import cPickle as pickle + adrian 2287 3f0790d500a9 2006-02-24:9: except ImportError: + adrian 2287 3f0790d500a9 2006-02-24:10: import pickle + adrian 2287 3f0790d500a9 2006-02-24:11: + jezdez 16338 bf038debb499 2011-07-13:11: from django.core.cache.backends.base import BaseCache + jezdez 16338 bf038debb499 2011-07-13:12: from django.db import connections, router, transaction, DatabaseError + jezdez 16338 bf038debb499 2011-07-13:13: + jezdez 16338 bf038debb499 2011-07-13:14: + russellm 13275 4dd52d4f3f50 2010-08-05:12: class Options(object): + russellm 13275 4dd52d4f3f50 2010-08-05:13: """A class that will quack like a Django model _meta class. + russellm 13275 4dd52d4f3f50 2010-08-05:14: + russellm 13275 4dd52d4f3f50 2010-08-05:15: This allows cache operations to be controlled by the router + russellm 13275 4dd52d4f3f50 2010-08-05:16: """ + russellm 13275 4dd52d4f3f50 2010-08-05:17: def __init__(self, table): + russellm 13275 4dd52d4f3f50 2010-08-05:18: self.db_table = table + russellm 13275 4dd52d4f3f50 2010-08-05:19: self.app_label = 'django_cache' + russellm 13275 4dd52d4f3f50 2010-08-05:20: self.module_name = 'cacheentry' + russellm 13275 4dd52d4f3f50 2010-08-05:21: self.verbose_name = 'cache entry' + russellm 13275 4dd52d4f3f50 2010-08-05:22: self.verbose_name_plural = 'cache entries' + russellm 13275 4dd52d4f3f50 2010-08-05:23: self.object_name = 'CacheEntry' + russellm 13275 4dd52d4f3f50 2010-08-05:24: self.abstract = False + russellm 13275 4dd52d4f3f50 2010-08-05:25: self.managed = True + russellm 13275 4dd52d4f3f50 2010-08-05:26: self.proxy = False + russellm 13275 4dd52d4f3f50 2010-08-05:27: + russellm 14807 905c4a7e1f19 2010-12-21:28: class BaseDatabaseCache(BaseCache): + russellm 14807 905c4a7e1f19 2010-12-21:29: def __init__(self, table, params): + russellm 14807 905c4a7e1f19 2010-12-21:30: BaseCache.__init__(self, params) + russellm 13275 4dd52d4f3f50 2010-08-05:31: self._table = table + russellm 13275 4dd52d4f3f50 2010-08-05:32: + russellm 13275 4dd52d4f3f50 2010-08-05:33: class CacheEntry(object): + russellm 13275 4dd52d4f3f50 2010-08-05:34: _meta = Options(table) + russellm 13275 4dd52d4f3f50 2010-08-05:35: self.cache_model_class = CacheEntry + russellm 13275 4dd52d4f3f50 2010-08-05:36: + russellm 14807 905c4a7e1f19 2010-12-21:37: class DatabaseCache(BaseDatabaseCache): + russellm 14425 793e94ba2037 2010-11-19:38: def get(self, key, default=None, version=None): + russellm 14425 793e94ba2037 2010-11-19:39: key = self.make_key(key, version=version) +mtredinnick 13568 7e0b7bf098d2 2010-09-12:49: self.validate_key(key) + russellm 13275 4dd52d4f3f50 2010-08-05:49: db = router.db_for_read(self.cache_model_class) + russellm 13275 4dd52d4f3f50 2010-08-05:50: table = connections[db].ops.quote_name(self._table) + russellm 13275 4dd52d4f3f50 2010-08-05:51: cursor = connections[db].cursor() + russellm 13275 4dd52d4f3f50 2010-08-05:52: + russellm 13275 4dd52d4f3f50 2010-08-05:53: cursor.execute("SELECT cache_key, value, expires FROM %s WHERE cache_key = %%s" % table, [key]) + adrian 2287 3f0790d500a9 2006-02-24:30: row = cursor.fetchone() + adrian 2287 3f0790d500a9 2006-02-24:31: if row is None: + adrian 2287 3f0790d500a9 2006-02-24:32: return default + adrian 2287 3f0790d500a9 2006-02-24:33: now = datetime.now() + adrian 2287 3f0790d500a9 2006-02-24:34: if row[2] < now: + russellm 13275 4dd52d4f3f50 2010-08-05:59: db = router.db_for_write(self.cache_model_class) + russellm 13275 4dd52d4f3f50 2010-08-05:60: cursor = connections[db].cursor() + russellm 13275 4dd52d4f3f50 2010-08-05:61: cursor.execute("DELETE FROM %s WHERE cache_key = %%s" % table, [key]) + russellm 13275 4dd52d4f3f50 2010-08-05:62: transaction.commit_unless_managed(using=db) + adrian 2287 3f0790d500a9 2006-02-24:37: return default + russellm 13275 4dd52d4f3f50 2010-08-05:64: value = connections[db].ops.process_clob(row[1]) + ikelly 9862 8739c35149dd 2009-03-13:39: return pickle.loads(base64.decodestring(value)) + adrian 2287 3f0790d500a9 2006-02-24:39: + russellm 14425 793e94ba2037 2010-11-19:59: def set(self, key, value, timeout=None, version=None): + russellm 14425 793e94ba2037 2010-11-19:60: key = self.make_key(key, version=version) +mtredinnick 13568 7e0b7bf098d2 2010-09-12:69: self.validate_key(key) +mtredinnick 8110 c787c7f62142 2008-08-10:41: self._base_set('set', key, value, timeout) +mtredinnick 6421 b4175804cc7b 2007-10-20:45: + russellm 14425 793e94ba2037 2010-11-19:64: def add(self, key, value, timeout=None, version=None): + russellm 14425 793e94ba2037 2010-11-19:65: key = self.make_key(key, version=version) +mtredinnick 13568 7e0b7bf098d2 2010-09-12:73: self.validate_key(key) +mtredinnick 6438 5096a56a9ac6 2007-10-21:44: return self._base_set('add', key, value, timeout) +mtredinnick 6438 5096a56a9ac6 2007-10-21:45: +mtredinnick 6421 b4175804cc7b 2007-10-20:46: def _base_set(self, mode, key, value, timeout=None): + adrian 2287 3f0790d500a9 2006-02-24:41: if timeout is None: + adrian 2287 3f0790d500a9 2006-02-24:42: timeout = self.default_timeout + russellm 13275 4dd52d4f3f50 2010-08-05:76: db = router.db_for_write(self.cache_model_class) + russellm 13275 4dd52d4f3f50 2010-08-05:77: table = connections[db].ops.quote_name(self._table) + russellm 13275 4dd52d4f3f50 2010-08-05:78: cursor = connections[db].cursor() + russellm 13275 4dd52d4f3f50 2010-08-05:79: + russellm 13275 4dd52d4f3f50 2010-08-05:80: cursor.execute("SELECT COUNT(*) FROM %s" % table) + adrian 2287 3f0790d500a9 2006-02-24:45: num = cursor.fetchone()[0] + adrian 2287 3f0790d500a9 2006-02-24:46: now = datetime.now().replace(microsecond=0) + adrian 2287 3f0790d500a9 2006-02-24:47: exp = datetime.fromtimestamp(time.time() + timeout).replace(microsecond=0) + adrian 2287 3f0790d500a9 2006-02-24:48: if num > self._max_entries: + russellm 13275 4dd52d4f3f50 2010-08-05:85: self._cull(db, cursor, now) + adrian 2287 3f0790d500a9 2006-02-24:50: encoded = base64.encodestring(pickle.dumps(value, 2)).strip() + russellm 13275 4dd52d4f3f50 2010-08-05:87: cursor.execute("SELECT cache_key, expires FROM %s WHERE cache_key = %%s" % table, [key]) + adrian 2287 3f0790d500a9 2006-02-24:52: try: +mtredinnick 9753 0ab5ef23e1bc 2009-03-02:59: result = cursor.fetchone() +mtredinnick 9753 0ab5ef23e1bc 2009-03-02:60: if result and (mode == 'set' or +mtredinnick 9753 0ab5ef23e1bc 2009-03-02:61: (mode == 'add' and result[1] < now)): + russellm 13275 4dd52d4f3f50 2010-08-05:92: cursor.execute("UPDATE %s SET value = %%s, expires = %%s WHERE cache_key = %%s" % table, + russellm 13275 4dd52d4f3f50 2010-08-05:93: [encoded, connections[db].ops.value_to_db_datetime(exp), key]) + adrian 2287 3f0790d500a9 2006-02-24:55: else: + russellm 13275 4dd52d4f3f50 2010-08-05:95: cursor.execute("INSERT INTO %s (cache_key, value, expires) VALUES (%%s, %%s, %%s)" % table, + russellm 13275 4dd52d4f3f50 2010-08-05:96: [key, encoded, connections[db].ops.value_to_db_datetime(exp)]) + adrian 2287 3f0790d500a9 2006-02-24:57: except DatabaseError: + adrian 2287 3f0790d500a9 2006-02-24:58: # To be threadsafe, updates/inserts are allowed to fail silently + russellm 13275 4dd52d4f3f50 2010-08-05:99: transaction.rollback_unless_managed(using=db) +mtredinnick 8110 c787c7f62142 2008-08-10:65: return False + adrian 2287 3f0790d500a9 2006-02-24:60: else: + russellm 13275 4dd52d4f3f50 2010-08-05:102: transaction.commit_unless_managed(using=db) +mtredinnick 8110 c787c7f62142 2008-08-10:68: return True + adrian 2287 3f0790d500a9 2006-02-24:62: + russellm 14425 793e94ba2037 2010-11-19:101: def delete(self, key, version=None): + russellm 14425 793e94ba2037 2010-11-19:102: key = self.make_key(key, version=version) +mtredinnick 13568 7e0b7bf098d2 2010-09-12:109: self.validate_key(key) + russellm 14425 793e94ba2037 2010-11-19:104: + russellm 13275 4dd52d4f3f50 2010-08-05:106: db = router.db_for_write(self.cache_model_class) + russellm 13275 4dd52d4f3f50 2010-08-05:107: table = connections[db].ops.quote_name(self._table) + russellm 13275 4dd52d4f3f50 2010-08-05:108: cursor = connections[db].cursor() + russellm 13275 4dd52d4f3f50 2010-08-05:109: + russellm 13275 4dd52d4f3f50 2010-08-05:110: cursor.execute("DELETE FROM %s WHERE cache_key = %%s" % table, [key]) + russellm 13275 4dd52d4f3f50 2010-08-05:111: transaction.commit_unless_managed(using=db) + adrian 2287 3f0790d500a9 2006-02-24:67: + russellm 14425 793e94ba2037 2010-11-19:112: def has_key(self, key, version=None): + russellm 14425 793e94ba2037 2010-11-19:113: key = self.make_key(key, version=version) +mtredinnick 13568 7e0b7bf098d2 2010-09-12:118: self.validate_key(key) + russellm 14425 793e94ba2037 2010-11-19:115: + russellm 13275 4dd52d4f3f50 2010-08-05:114: db = router.db_for_read(self.cache_model_class) + russellm 13275 4dd52d4f3f50 2010-08-05:115: table = connections[db].ops.quote_name(self._table) + russellm 13275 4dd52d4f3f50 2010-08-05:116: cursor = connections[db].cursor() + russellm 13275 4dd52d4f3f50 2010-08-05:117: +mtredinnick 9753 0ab5ef23e1bc 2009-03-02:78: now = datetime.now().replace(microsecond=0) + russellm 13275 4dd52d4f3f50 2010-08-05:119: cursor.execute("SELECT cache_key FROM %s WHERE cache_key = %%s and expires > %%s" % table, + russellm 13275 4dd52d4f3f50 2010-08-05:120: [key, connections[db].ops.value_to_db_datetime(now)]) + adrian 2287 3f0790d500a9 2006-02-24:71: return cursor.fetchone() is not None + adrian 2287 3f0790d500a9 2006-02-24:72: + russellm 13275 4dd52d4f3f50 2010-08-05:123: def _cull(self, db, cursor, now): + adrian 2287 3f0790d500a9 2006-02-24:74: if self._cull_frequency == 0: + russellm 12116 c1ad14c551a9 2010-01-27:87: self.clear() + adrian 2287 3f0790d500a9 2006-02-24:76: else: + russellm 13480 7351411944a9 2010-08-31:127: table = connections[db].ops.quote_name(self._table) + russellm 13275 4dd52d4f3f50 2010-08-05:127: cursor.execute("DELETE FROM %s WHERE expires < %%s" % table, + russellm 13275 4dd52d4f3f50 2010-08-05:128: [connections[db].ops.value_to_db_datetime(now)]) + russellm 13275 4dd52d4f3f50 2010-08-05:129: cursor.execute("SELECT COUNT(*) FROM %s" % table) + adrian 2287 3f0790d500a9 2006-02-24:79: num = cursor.fetchone()[0] + adrian 2287 3f0790d500a9 2006-02-24:80: if num > self._max_entries: + russellm 13275 4dd52d4f3f50 2010-08-05:132: cursor.execute("SELECT cache_key FROM %s ORDER BY cache_key LIMIT 1 OFFSET %%s" % table, [num / self._cull_frequency]) + russellm 13275 4dd52d4f3f50 2010-08-05:133: cursor.execute("DELETE FROM %s WHERE cache_key < %%s" % table, [cursor.fetchone()[0]]) + russellm 12116 c1ad14c551a9 2010-01-27:95: + russellm 12116 c1ad14c551a9 2010-01-27:96: def clear(self): + russellm 13275 4dd52d4f3f50 2010-08-05:136: db = router.db_for_write(self.cache_model_class) + russellm 13275 4dd52d4f3f50 2010-08-05:137: table = connections[db].ops.quote_name(self._table) + russellm 13275 4dd52d4f3f50 2010-08-05:138: cursor = connections[db].cursor() + russellm 13275 4dd52d4f3f50 2010-08-05:139: cursor.execute('DELETE FROM %s' % table) + russellm 14807 905c4a7e1f19 2010-12-21:143: + russellm 14807 905c4a7e1f19 2010-12-21:144: # For backwards compatibility + russellm 14807 905c4a7e1f19 2010-12-21:145: class CacheClass(DatabaseCache): + russellm 14807 905c4a7e1f19 2010-12-21:146: pass diff --git a/plugins/hg4idea/testData/annotate/outputs/hg_1.8.2 b/plugins/hg4idea/testData/annotate/outputs/hg_1.8.2 new file mode 100644 index 000000000000..3acc13feeb81 --- /dev/null +++ b/plugins/hg4idea/testData/annotate/outputs/hg_1.8.2 @@ -0,0 +1,149 @@ + adrian 2287 3f0790d500a9 2006-02-24:1: "Database cache backend." + jezdez 16338 bf038debb499 2011-07-13:2: import base64 + jezdez 16338 bf038debb499 2011-07-13:3: import time + jezdez 16338 bf038debb499 2011-07-13:4: from datetime import datetime + adrian 2287 3f0790d500a9 2006-02-24:2: + adrian 2287 3f0790d500a9 2006-02-24:7: try: + adrian 2287 3f0790d500a9 2006-02-24:8: import cPickle as pickle + adrian 2287 3f0790d500a9 2006-02-24:9: except ImportError: + adrian 2287 3f0790d500a9 2006-02-24:10: import pickle + adrian 2287 3f0790d500a9 2006-02-24:11: + jezdez 16338 bf038debb499 2011-07-13:11: from django.core.cache.backends.base import BaseCache + jezdez 16338 bf038debb499 2011-07-13:12: from django.db import connections, router, transaction, DatabaseError + jezdez 16338 bf038debb499 2011-07-13:13: + jezdez 16338 bf038debb499 2011-07-13:14: + russellm 13275 4dd52d4f3f50 2010-08-05:12: class Options(object): + russellm 13275 4dd52d4f3f50 2010-08-05:13: """A class that will quack like a Django model _meta class. + russellm 13275 4dd52d4f3f50 2010-08-05:14: + russellm 13275 4dd52d4f3f50 2010-08-05:15: This allows cache operations to be controlled by the router + russellm 13275 4dd52d4f3f50 2010-08-05:16: """ + russellm 13275 4dd52d4f3f50 2010-08-05:17: def __init__(self, table): + russellm 13275 4dd52d4f3f50 2010-08-05:18: self.db_table = table + russellm 13275 4dd52d4f3f50 2010-08-05:19: self.app_label = 'django_cache' + russellm 13275 4dd52d4f3f50 2010-08-05:20: self.module_name = 'cacheentry' + russellm 13275 4dd52d4f3f50 2010-08-05:21: self.verbose_name = 'cache entry' + russellm 13275 4dd52d4f3f50 2010-08-05:22: self.verbose_name_plural = 'cache entries' + russellm 13275 4dd52d4f3f50 2010-08-05:23: self.object_name = 'CacheEntry' + russellm 13275 4dd52d4f3f50 2010-08-05:24: self.abstract = False + russellm 13275 4dd52d4f3f50 2010-08-05:25: self.managed = True + russellm 13275 4dd52d4f3f50 2010-08-05:26: self.proxy = False + russellm 13275 4dd52d4f3f50 2010-08-05:27: + russellm 14807 905c4a7e1f19 2010-12-21:28: class BaseDatabaseCache(BaseCache): + russellm 14807 905c4a7e1f19 2010-12-21:29: def __init__(self, table, params): + russellm 14807 905c4a7e1f19 2010-12-21:30: BaseCache.__init__(self, params) + russellm 13275 4dd52d4f3f50 2010-08-05:31: self._table = table + russellm 13275 4dd52d4f3f50 2010-08-05:32: + russellm 13275 4dd52d4f3f50 2010-08-05:33: class CacheEntry(object): + russellm 13275 4dd52d4f3f50 2010-08-05:34: _meta = Options(table) + russellm 13275 4dd52d4f3f50 2010-08-05:35: self.cache_model_class = CacheEntry + russellm 13275 4dd52d4f3f50 2010-08-05:36: + russellm 14807 905c4a7e1f19 2010-12-21:37: class DatabaseCache(BaseDatabaseCache): + russellm 14425 793e94ba2037 2010-11-19:38: def get(self, key, default=None, version=None): + russellm 14425 793e94ba2037 2010-11-19:39: key = self.make_key(key, version=version) +mtredinnick 13568 7e0b7bf098d2 2010-09-12:49: self.validate_key(key) + russellm 13275 4dd52d4f3f50 2010-08-05:49: db = router.db_for_read(self.cache_model_class) + russellm 13275 4dd52d4f3f50 2010-08-05:50: table = connections[db].ops.quote_name(self._table) + russellm 13275 4dd52d4f3f50 2010-08-05:51: cursor = connections[db].cursor() + russellm 13275 4dd52d4f3f50 2010-08-05:52: + russellm 13275 4dd52d4f3f50 2010-08-05:53: cursor.execute("SELECT cache_key, value, expires FROM %s WHERE cache_key = %%s" % table, [key]) + adrian 2287 3f0790d500a9 2006-02-24:30: row = cursor.fetchone() + adrian 2287 3f0790d500a9 2006-02-24:31: if row is None: + adrian 2287 3f0790d500a9 2006-02-24:32: return default + adrian 2287 3f0790d500a9 2006-02-24:33: now = datetime.now() + adrian 2287 3f0790d500a9 2006-02-24:34: if row[2] < now: + russellm 13275 4dd52d4f3f50 2010-08-05:59: db = router.db_for_write(self.cache_model_class) + russellm 13275 4dd52d4f3f50 2010-08-05:60: cursor = connections[db].cursor() + russellm 13275 4dd52d4f3f50 2010-08-05:61: cursor.execute("DELETE FROM %s WHERE cache_key = %%s" % table, [key]) + russellm 13275 4dd52d4f3f50 2010-08-05:62: transaction.commit_unless_managed(using=db) + adrian 2287 3f0790d500a9 2006-02-24:37: return default + russellm 13275 4dd52d4f3f50 2010-08-05:64: value = connections[db].ops.process_clob(row[1]) + ikelly 9862 8739c35149dd 2009-03-13:39: return pickle.loads(base64.decodestring(value)) + adrian 2287 3f0790d500a9 2006-02-24:39: + russellm 14425 793e94ba2037 2010-11-19:59: def set(self, key, value, timeout=None, version=None): + russellm 14425 793e94ba2037 2010-11-19:60: key = self.make_key(key, version=version) +mtredinnick 13568 7e0b7bf098d2 2010-09-12:69: self.validate_key(key) +mtredinnick 8110 c787c7f62142 2008-08-10:41: self._base_set('set', key, value, timeout) +mtredinnick 6421 b4175804cc7b 2007-10-20:45: + russellm 14425 793e94ba2037 2010-11-19:64: def add(self, key, value, timeout=None, version=None): + russellm 14425 793e94ba2037 2010-11-19:65: key = self.make_key(key, version=version) +mtredinnick 13568 7e0b7bf098d2 2010-09-12:73: self.validate_key(key) +mtredinnick 6438 5096a56a9ac6 2007-10-21:44: return self._base_set('add', key, value, timeout) +mtredinnick 6438 5096a56a9ac6 2007-10-21:45: +mtredinnick 6421 b4175804cc7b 2007-10-20:46: def _base_set(self, mode, key, value, timeout=None): + adrian 2287 3f0790d500a9 2006-02-24:41: if timeout is None: + adrian 2287 3f0790d500a9 2006-02-24:42: timeout = self.default_timeout + russellm 13275 4dd52d4f3f50 2010-08-05:76: db = router.db_for_write(self.cache_model_class) + russellm 13275 4dd52d4f3f50 2010-08-05:77: table = connections[db].ops.quote_name(self._table) + russellm 13275 4dd52d4f3f50 2010-08-05:78: cursor = connections[db].cursor() + russellm 13275 4dd52d4f3f50 2010-08-05:79: + russellm 13275 4dd52d4f3f50 2010-08-05:80: cursor.execute("SELECT COUNT(*) FROM %s" % table) + adrian 2287 3f0790d500a9 2006-02-24:45: num = cursor.fetchone()[0] + adrian 2287 3f0790d500a9 2006-02-24:46: now = datetime.now().replace(microsecond=0) + adrian 2287 3f0790d500a9 2006-02-24:47: exp = datetime.fromtimestamp(time.time() + timeout).replace(microsecond=0) + adrian 2287 3f0790d500a9 2006-02-24:48: if num > self._max_entries: + russellm 13275 4dd52d4f3f50 2010-08-05:85: self._cull(db, cursor, now) + adrian 2287 3f0790d500a9 2006-02-24:50: encoded = base64.encodestring(pickle.dumps(value, 2)).strip() + russellm 13275 4dd52d4f3f50 2010-08-05:87: cursor.execute("SELECT cache_key, expires FROM %s WHERE cache_key = %%s" % table, [key]) + adrian 2287 3f0790d500a9 2006-02-24:52: try: +mtredinnick 9753 0ab5ef23e1bc 2009-03-02:59: result = cursor.fetchone() +mtredinnick 9753 0ab5ef23e1bc 2009-03-02:60: if result and (mode == 'set' or +mtredinnick 9753 0ab5ef23e1bc 2009-03-02:61: (mode == 'add' and result[1] < now)): + russellm 13275 4dd52d4f3f50 2010-08-05:92: cursor.execute("UPDATE %s SET value = %%s, expires = %%s WHERE cache_key = %%s" % table, + russellm 13275 4dd52d4f3f50 2010-08-05:93: [encoded, connections[db].ops.value_to_db_datetime(exp), key]) + adrian 2287 3f0790d500a9 2006-02-24:55: else: + russellm 13275 4dd52d4f3f50 2010-08-05:95: cursor.execute("INSERT INTO %s (cache_key, value, expires) VALUES (%%s, %%s, %%s)" % table, + russellm 13275 4dd52d4f3f50 2010-08-05:96: [key, encoded, connections[db].ops.value_to_db_datetime(exp)]) + adrian 2287 3f0790d500a9 2006-02-24:57: except DatabaseError: + adrian 2287 3f0790d500a9 2006-02-24:58: # To be threadsafe, updates/inserts are allowed to fail silently + russellm 13275 4dd52d4f3f50 2010-08-05:99: transaction.rollback_unless_managed(using=db) +mtredinnick 8110 c787c7f62142 2008-08-10:65: return False + adrian 2287 3f0790d500a9 2006-02-24:60: else: + russellm 13275 4dd52d4f3f50 2010-08-05:102: transaction.commit_unless_managed(using=db) +mtredinnick 8110 c787c7f62142 2008-08-10:68: return True + adrian 2287 3f0790d500a9 2006-02-24:62: + russellm 14425 793e94ba2037 2010-11-19:101: def delete(self, key, version=None): + russellm 14425 793e94ba2037 2010-11-19:102: key = self.make_key(key, version=version) +mtredinnick 13568 7e0b7bf098d2 2010-09-12:109: self.validate_key(key) + russellm 14425 793e94ba2037 2010-11-19:104: + russellm 13275 4dd52d4f3f50 2010-08-05:106: db = router.db_for_write(self.cache_model_class) + russellm 13275 4dd52d4f3f50 2010-08-05:107: table = connections[db].ops.quote_name(self._table) + russellm 13275 4dd52d4f3f50 2010-08-05:108: cursor = connections[db].cursor() + russellm 13275 4dd52d4f3f50 2010-08-05:109: + russellm 13275 4dd52d4f3f50 2010-08-05:110: cursor.execute("DELETE FROM %s WHERE cache_key = %%s" % table, [key]) + russellm 13275 4dd52d4f3f50 2010-08-05:111: transaction.commit_unless_managed(using=db) + adrian 2287 3f0790d500a9 2006-02-24:67: + russellm 14425 793e94ba2037 2010-11-19:112: def has_key(self, key, version=None): + russellm 14425 793e94ba2037 2010-11-19:113: key = self.make_key(key, version=version) +mtredinnick 13568 7e0b7bf098d2 2010-09-12:118: self.validate_key(key) + russellm 14425 793e94ba2037 2010-11-19:115: + russellm 13275 4dd52d4f3f50 2010-08-05:114: db = router.db_for_read(self.cache_model_class) + russellm 13275 4dd52d4f3f50 2010-08-05:115: table = connections[db].ops.quote_name(self._table) + russellm 13275 4dd52d4f3f50 2010-08-05:116: cursor = connections[db].cursor() + russellm 13275 4dd52d4f3f50 2010-08-05:117: +mtredinnick 9753 0ab5ef23e1bc 2009-03-02:78: now = datetime.now().replace(microsecond=0) + russellm 13275 4dd52d4f3f50 2010-08-05:119: cursor.execute("SELECT cache_key FROM %s WHERE cache_key = %%s and expires > %%s" % table, + russellm 13275 4dd52d4f3f50 2010-08-05:120: [key, connections[db].ops.value_to_db_datetime(now)]) + adrian 2287 3f0790d500a9 2006-02-24:71: return cursor.fetchone() is not None + adrian 2287 3f0790d500a9 2006-02-24:72: + russellm 13275 4dd52d4f3f50 2010-08-05:123: def _cull(self, db, cursor, now): + adrian 2287 3f0790d500a9 2006-02-24:74: if self._cull_frequency == 0: + russellm 12116 c1ad14c551a9 2010-01-27:87: self.clear() + adrian 2287 3f0790d500a9 2006-02-24:76: else: + russellm 13480 7351411944a9 2010-08-31:127: table = connections[db].ops.quote_name(self._table) + russellm 13275 4dd52d4f3f50 2010-08-05:127: cursor.execute("DELETE FROM %s WHERE expires < %%s" % table, + russellm 13275 4dd52d4f3f50 2010-08-05:128: [connections[db].ops.value_to_db_datetime(now)]) + russellm 13275 4dd52d4f3f50 2010-08-05:129: cursor.execute("SELECT COUNT(*) FROM %s" % table) + adrian 2287 3f0790d500a9 2006-02-24:79: num = cursor.fetchone()[0] + adrian 2287 3f0790d500a9 2006-02-24:80: if num > self._max_entries: + russellm 13275 4dd52d4f3f50 2010-08-05:132: cursor.execute("SELECT cache_key FROM %s ORDER BY cache_key LIMIT 1 OFFSET %%s" % table, [num / self._cull_frequency]) + russellm 13275 4dd52d4f3f50 2010-08-05:133: cursor.execute("DELETE FROM %s WHERE cache_key < %%s" % table, [cursor.fetchone()[0]]) + russellm 12116 c1ad14c551a9 2010-01-27:95: + russellm 12116 c1ad14c551a9 2010-01-27:96: def clear(self): + russellm 13275 4dd52d4f3f50 2010-08-05:136: db = router.db_for_write(self.cache_model_class) + russellm 13275 4dd52d4f3f50 2010-08-05:137: table = connections[db].ops.quote_name(self._table) + russellm 13275 4dd52d4f3f50 2010-08-05:138: cursor = connections[db].cursor() + russellm 13275 4dd52d4f3f50 2010-08-05:139: cursor.execute('DELETE FROM %s' % table) + russellm 14807 905c4a7e1f19 2010-12-21:143: + russellm 14807 905c4a7e1f19 2010-12-21:144: # For backwards compatibility + russellm 14807 905c4a7e1f19 2010-12-21:145: class CacheClass(DatabaseCache): + russellm 14807 905c4a7e1f19 2010-12-21:146: pass diff --git a/plugins/hg4idea/testData/annotate/outputs/hg_1.9.0 b/plugins/hg4idea/testData/annotate/outputs/hg_1.9.0 new file mode 100644 index 000000000000..886d778c2800 --- /dev/null +++ b/plugins/hg4idea/testData/annotate/outputs/hg_1.9.0 @@ -0,0 +1,149 @@ + adrian 2287 3f0790d500a9 2006-02-24: 1: "Database cache backend." + jezdez 16338 bf038debb499 2011-07-13: 2: import base64 + jezdez 16338 bf038debb499 2011-07-13: 3: import time + jezdez 16338 bf038debb499 2011-07-13: 4: from datetime import datetime + adrian 2287 3f0790d500a9 2006-02-24: 2: + adrian 2287 3f0790d500a9 2006-02-24: 7: try: + adrian 2287 3f0790d500a9 2006-02-24: 8: import cPickle as pickle + adrian 2287 3f0790d500a9 2006-02-24: 9: except ImportError: + adrian 2287 3f0790d500a9 2006-02-24: 10: import pickle + adrian 2287 3f0790d500a9 2006-02-24: 11: + jezdez 16338 bf038debb499 2011-07-13: 11: from django.core.cache.backends.base import BaseCache + jezdez 16338 bf038debb499 2011-07-13: 12: from django.db import connections, router, transaction, DatabaseError + jezdez 16338 bf038debb499 2011-07-13: 13: + jezdez 16338 bf038debb499 2011-07-13: 14: + russellm 13275 4dd52d4f3f50 2010-08-05: 12: class Options(object): + russellm 13275 4dd52d4f3f50 2010-08-05: 13: """A class that will quack like a Django model _meta class. + russellm 13275 4dd52d4f3f50 2010-08-05: 14: + russellm 13275 4dd52d4f3f50 2010-08-05: 15: This allows cache operations to be controlled by the router + russellm 13275 4dd52d4f3f50 2010-08-05: 16: """ + russellm 13275 4dd52d4f3f50 2010-08-05: 17: def __init__(self, table): + russellm 13275 4dd52d4f3f50 2010-08-05: 18: self.db_table = table + russellm 13275 4dd52d4f3f50 2010-08-05: 19: self.app_label = 'django_cache' + russellm 13275 4dd52d4f3f50 2010-08-05: 20: self.module_name = 'cacheentry' + russellm 13275 4dd52d4f3f50 2010-08-05: 21: self.verbose_name = 'cache entry' + russellm 13275 4dd52d4f3f50 2010-08-05: 22: self.verbose_name_plural = 'cache entries' + russellm 13275 4dd52d4f3f50 2010-08-05: 23: self.object_name = 'CacheEntry' + russellm 13275 4dd52d4f3f50 2010-08-05: 24: self.abstract = False + russellm 13275 4dd52d4f3f50 2010-08-05: 25: self.managed = True + russellm 13275 4dd52d4f3f50 2010-08-05: 26: self.proxy = False + russellm 13275 4dd52d4f3f50 2010-08-05: 27: + russellm 14807 905c4a7e1f19 2010-12-21: 28: class BaseDatabaseCache(BaseCache): + russellm 14807 905c4a7e1f19 2010-12-21: 29: def __init__(self, table, params): + russellm 14807 905c4a7e1f19 2010-12-21: 30: BaseCache.__init__(self, params) + russellm 13275 4dd52d4f3f50 2010-08-05: 31: self._table = table + russellm 13275 4dd52d4f3f50 2010-08-05: 32: + russellm 13275 4dd52d4f3f50 2010-08-05: 33: class CacheEntry(object): + russellm 13275 4dd52d4f3f50 2010-08-05: 34: _meta = Options(table) + russellm 13275 4dd52d4f3f50 2010-08-05: 35: self.cache_model_class = CacheEntry + russellm 13275 4dd52d4f3f50 2010-08-05: 36: + russellm 14807 905c4a7e1f19 2010-12-21: 37: class DatabaseCache(BaseDatabaseCache): + russellm 14425 793e94ba2037 2010-11-19: 38: def get(self, key, default=None, version=None): + russellm 14425 793e94ba2037 2010-11-19: 39: key = self.make_key(key, version=version) +mtredinnick 13568 7e0b7bf098d2 2010-09-12: 49: self.validate_key(key) + russellm 13275 4dd52d4f3f50 2010-08-05: 49: db = router.db_for_read(self.cache_model_class) + russellm 13275 4dd52d4f3f50 2010-08-05: 50: table = connections[db].ops.quote_name(self._table) + russellm 13275 4dd52d4f3f50 2010-08-05: 51: cursor = connections[db].cursor() + russellm 13275 4dd52d4f3f50 2010-08-05: 52: + russellm 13275 4dd52d4f3f50 2010-08-05: 53: cursor.execute("SELECT cache_key, value, expires FROM %s WHERE cache_key = %%s" % table, [key]) + adrian 2287 3f0790d500a9 2006-02-24: 30: row = cursor.fetchone() + adrian 2287 3f0790d500a9 2006-02-24: 31: if row is None: + adrian 2287 3f0790d500a9 2006-02-24: 32: return default + adrian 2287 3f0790d500a9 2006-02-24: 33: now = datetime.now() + adrian 2287 3f0790d500a9 2006-02-24: 34: if row[2] < now: + russellm 13275 4dd52d4f3f50 2010-08-05: 59: db = router.db_for_write(self.cache_model_class) + russellm 13275 4dd52d4f3f50 2010-08-05: 60: cursor = connections[db].cursor() + russellm 13275 4dd52d4f3f50 2010-08-05: 61: cursor.execute("DELETE FROM %s WHERE cache_key = %%s" % table, [key]) + russellm 13275 4dd52d4f3f50 2010-08-05: 62: transaction.commit_unless_managed(using=db) + adrian 2287 3f0790d500a9 2006-02-24: 37: return default + russellm 13275 4dd52d4f3f50 2010-08-05: 64: value = connections[db].ops.process_clob(row[1]) + ikelly 9862 8739c35149dd 2009-03-13: 39: return pickle.loads(base64.decodestring(value)) + adrian 2287 3f0790d500a9 2006-02-24: 39: + russellm 14425 793e94ba2037 2010-11-19: 59: def set(self, key, value, timeout=None, version=None): + russellm 14425 793e94ba2037 2010-11-19: 60: key = self.make_key(key, version=version) +mtredinnick 13568 7e0b7bf098d2 2010-09-12: 69: self.validate_key(key) +mtredinnick 8110 c787c7f62142 2008-08-10: 41: self._base_set('set', key, value, timeout) +mtredinnick 6421 b4175804cc7b 2007-10-20: 45: + russellm 14425 793e94ba2037 2010-11-19: 64: def add(self, key, value, timeout=None, version=None): + russellm 14425 793e94ba2037 2010-11-19: 65: key = self.make_key(key, version=version) +mtredinnick 13568 7e0b7bf098d2 2010-09-12: 73: self.validate_key(key) +mtredinnick 6438 5096a56a9ac6 2007-10-21: 44: return self._base_set('add', key, value, timeout) +mtredinnick 6438 5096a56a9ac6 2007-10-21: 45: +mtredinnick 6421 b4175804cc7b 2007-10-20: 46: def _base_set(self, mode, key, value, timeout=None): + adrian 2287 3f0790d500a9 2006-02-24: 41: if timeout is None: + adrian 2287 3f0790d500a9 2006-02-24: 42: timeout = self.default_timeout + russellm 13275 4dd52d4f3f50 2010-08-05: 76: db = router.db_for_write(self.cache_model_class) + russellm 13275 4dd52d4f3f50 2010-08-05: 77: table = connections[db].ops.quote_name(self._table) + russellm 13275 4dd52d4f3f50 2010-08-05: 78: cursor = connections[db].cursor() + russellm 13275 4dd52d4f3f50 2010-08-05: 79: + russellm 13275 4dd52d4f3f50 2010-08-05: 80: cursor.execute("SELECT COUNT(*) FROM %s" % table) + adrian 2287 3f0790d500a9 2006-02-24: 45: num = cursor.fetchone()[0] + adrian 2287 3f0790d500a9 2006-02-24: 46: now = datetime.now().replace(microsecond=0) + adrian 2287 3f0790d500a9 2006-02-24: 47: exp = datetime.fromtimestamp(time.time() + timeout).replace(microsecond=0) + adrian 2287 3f0790d500a9 2006-02-24: 48: if num > self._max_entries: + russellm 13275 4dd52d4f3f50 2010-08-05: 85: self._cull(db, cursor, now) + adrian 2287 3f0790d500a9 2006-02-24: 50: encoded = base64.encodestring(pickle.dumps(value, 2)).strip() + russellm 13275 4dd52d4f3f50 2010-08-05: 87: cursor.execute("SELECT cache_key, expires FROM %s WHERE cache_key = %%s" % table, [key]) + adrian 2287 3f0790d500a9 2006-02-24: 52: try: +mtredinnick 9753 0ab5ef23e1bc 2009-03-02: 59: result = cursor.fetchone() +mtredinnick 9753 0ab5ef23e1bc 2009-03-02: 60: if result and (mode == 'set' or +mtredinnick 9753 0ab5ef23e1bc 2009-03-02: 61: (mode == 'add' and result[1] < now)): + russellm 13275 4dd52d4f3f50 2010-08-05: 92: cursor.execute("UPDATE %s SET value = %%s, expires = %%s WHERE cache_key = %%s" % table, + russellm 13275 4dd52d4f3f50 2010-08-05: 93: [encoded, connections[db].ops.value_to_db_datetime(exp), key]) + adrian 2287 3f0790d500a9 2006-02-24: 55: else: + russellm 13275 4dd52d4f3f50 2010-08-05: 95: cursor.execute("INSERT INTO %s (cache_key, value, expires) VALUES (%%s, %%s, %%s)" % table, + russellm 13275 4dd52d4f3f50 2010-08-05: 96: [key, encoded, connections[db].ops.value_to_db_datetime(exp)]) + adrian 2287 3f0790d500a9 2006-02-24: 57: except DatabaseError: + adrian 2287 3f0790d500a9 2006-02-24: 58: # To be threadsafe, updates/inserts are allowed to fail silently + russellm 13275 4dd52d4f3f50 2010-08-05: 99: transaction.rollback_unless_managed(using=db) +mtredinnick 8110 c787c7f62142 2008-08-10: 65: return False + adrian 2287 3f0790d500a9 2006-02-24: 60: else: + russellm 13275 4dd52d4f3f50 2010-08-05:102: transaction.commit_unless_managed(using=db) +mtredinnick 8110 c787c7f62142 2008-08-10: 68: return True + adrian 2287 3f0790d500a9 2006-02-24: 62: + russellm 14425 793e94ba2037 2010-11-19:101: def delete(self, key, version=None): + russellm 14425 793e94ba2037 2010-11-19:102: key = self.make_key(key, version=version) +mtredinnick 13568 7e0b7bf098d2 2010-09-12:109: self.validate_key(key) + russellm 14425 793e94ba2037 2010-11-19:104: + russellm 13275 4dd52d4f3f50 2010-08-05:106: db = router.db_for_write(self.cache_model_class) + russellm 13275 4dd52d4f3f50 2010-08-05:107: table = connections[db].ops.quote_name(self._table) + russellm 13275 4dd52d4f3f50 2010-08-05:108: cursor = connections[db].cursor() + russellm 13275 4dd52d4f3f50 2010-08-05:109: + russellm 13275 4dd52d4f3f50 2010-08-05:110: cursor.execute("DELETE FROM %s WHERE cache_key = %%s" % table, [key]) + russellm 13275 4dd52d4f3f50 2010-08-05:111: transaction.commit_unless_managed(using=db) + adrian 2287 3f0790d500a9 2006-02-24: 67: + russellm 14425 793e94ba2037 2010-11-19:112: def has_key(self, key, version=None): + russellm 14425 793e94ba2037 2010-11-19:113: key = self.make_key(key, version=version) +mtredinnick 13568 7e0b7bf098d2 2010-09-12:118: self.validate_key(key) + russellm 14425 793e94ba2037 2010-11-19:115: + russellm 13275 4dd52d4f3f50 2010-08-05:114: db = router.db_for_read(self.cache_model_class) + russellm 13275 4dd52d4f3f50 2010-08-05:115: table = connections[db].ops.quote_name(self._table) + russellm 13275 4dd52d4f3f50 2010-08-05:116: cursor = connections[db].cursor() + russellm 13275 4dd52d4f3f50 2010-08-05:117: +mtredinnick 9753 0ab5ef23e1bc 2009-03-02: 78: now = datetime.now().replace(microsecond=0) + russellm 13275 4dd52d4f3f50 2010-08-05:119: cursor.execute("SELECT cache_key FROM %s WHERE cache_key = %%s and expires > %%s" % table, + russellm 13275 4dd52d4f3f50 2010-08-05:120: [key, connections[db].ops.value_to_db_datetime(now)]) + adrian 2287 3f0790d500a9 2006-02-24: 71: return cursor.fetchone() is not None + adrian 2287 3f0790d500a9 2006-02-24: 72: + russellm 13275 4dd52d4f3f50 2010-08-05:123: def _cull(self, db, cursor, now): + adrian 2287 3f0790d500a9 2006-02-24: 74: if self._cull_frequency == 0: + russellm 12116 c1ad14c551a9 2010-01-27: 87: self.clear() + adrian 2287 3f0790d500a9 2006-02-24: 76: else: + russellm 13480 7351411944a9 2010-08-31:127: table = connections[db].ops.quote_name(self._table) + russellm 13275 4dd52d4f3f50 2010-08-05:127: cursor.execute("DELETE FROM %s WHERE expires < %%s" % table, + russellm 13275 4dd52d4f3f50 2010-08-05:128: [connections[db].ops.value_to_db_datetime(now)]) + russellm 13275 4dd52d4f3f50 2010-08-05:129: cursor.execute("SELECT COUNT(*) FROM %s" % table) + adrian 2287 3f0790d500a9 2006-02-24: 79: num = cursor.fetchone()[0] + adrian 2287 3f0790d500a9 2006-02-24: 80: if num > self._max_entries: + russellm 13275 4dd52d4f3f50 2010-08-05:132: cursor.execute("SELECT cache_key FROM %s ORDER BY cache_key LIMIT 1 OFFSET %%s" % table, [num / self._cull_frequency]) + russellm 13275 4dd52d4f3f50 2010-08-05:133: cursor.execute("DELETE FROM %s WHERE cache_key < %%s" % table, [cursor.fetchone()[0]]) + russellm 12116 c1ad14c551a9 2010-01-27: 95: + russellm 12116 c1ad14c551a9 2010-01-27: 96: def clear(self): + russellm 13275 4dd52d4f3f50 2010-08-05:136: db = router.db_for_write(self.cache_model_class) + russellm 13275 4dd52d4f3f50 2010-08-05:137: table = connections[db].ops.quote_name(self._table) + russellm 13275 4dd52d4f3f50 2010-08-05:138: cursor = connections[db].cursor() + russellm 13275 4dd52d4f3f50 2010-08-05:139: cursor.execute('DELETE FROM %s' % table) + russellm 14807 905c4a7e1f19 2010-12-21:143: + russellm 14807 905c4a7e1f19 2010-12-21:144: # For backwards compatibility + russellm 14807 905c4a7e1f19 2010-12-21:145: class CacheClass(DatabaseCache): + russellm 14807 905c4a7e1f19 2010-12-21:146: pass diff --git a/plugins/hg4idea/testSrc/org/zmlx/hg4idea/test/HgAnnotateCommandTest.java b/plugins/hg4idea/testSrc/org/zmlx/hg4idea/test/HgAnnotateCommandTest.java new file mode 100644 index 000000000000..aee72fd237a6 --- /dev/null +++ b/plugins/hg4idea/testSrc/org/zmlx/hg4idea/test/HgAnnotateCommandTest.java @@ -0,0 +1,139 @@ +/* + * Copyright 2000-2011 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. + */ +package org.zmlx.hg4idea.test; + +import com.intellij.openapi.application.PluginPathManager; +import com.intellij.openapi.util.io.FileUtil; +import com.thoughtworks.xstream.XStream; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.DataProvider; +import org.testng.annotations.Test; +import org.zmlx.hg4idea.HgRevisionNumber; +import org.zmlx.hg4idea.HgVcs; +import org.zmlx.hg4idea.command.HgAnnotateCommand; +import org.zmlx.hg4idea.provider.annotate.HgAnnotationLine; + +import java.io.File; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.fail; + +/** + * @author Kirill Likhodedov + */ +public class HgAnnotateCommandTest extends HgSingleUserTest { + + private File myPluginRoot; + private File myAnnotateDataDir; + private File myOutputsDir; + private List myAnnotations; + + @BeforeMethod + @Override + protected void setUp() throws Exception { + super.setUp(); + } + + @BeforeClass + private void loadEthalonAnnotations() throws IOException { + myPluginRoot = new File(PluginPathManager.getPluginHomePath(HgVcs.VCS_NAME)); + myAnnotateDataDir = new File(myPluginRoot, "testData/annotate"); + myOutputsDir = new File(myAnnotateDataDir, "outputs"); + + final File etalonFile = new File(myAnnotateDataDir, "etalon"); + + XStream xStream = new XStream(); + FileReader reader = new FileReader(etalonFile); + try { + myAnnotations = (List) xStream.fromXML(reader); + } + finally { + reader.close(); + } + } + + @DataProvider(name = "annotate_output") + public Object[][] createValidData() throws IOException { + Object[][] data = new Object[myOutputsDir.listFiles().length][]; + for (int i = 0; i < myOutputsDir.listFiles().length; i++) { + File annotateData = myOutputsDir.listFiles()[i]; + String fileText = FileUtil.loadFile(annotateData); + data[i] = new String[] {annotateData.getName(), fileText}; + } + return data; + } + + @Test(dataProvider = "annotate_output") + public void testParse(String fileName, String annotationNativeOutput) + throws NoSuchMethodException, InvocationTargetException, IllegalAccessException + { + HgAnnotateCommand command = new HgAnnotateCommand(myProject); + Method parseMethod = HgAnnotateCommand.class.getDeclaredMethod("parse", List.class); + parseMethod.setAccessible(true); + + List annotations = Arrays.asList(annotationNativeOutput.split("(\n|\r|\r\n)")); + List result = (List)parseMethod.invoke(command, annotations); + assertEquals(result, myAnnotations); + } + + //@Test + public void generateCorrectAnnotation() throws IOException { + final File etalonFile = new File(myAnnotateDataDir, "etalon"); + + File outputFile = new File(myOutputsDir, "hg_1.9.0"); + String output = FileUtil.loadFile(outputFile); + String[] split = output.split("(\n|\r|\r\n)"); + List annotationLines = new ArrayList(split.length); + + Pattern pattern = Pattern.compile("\\s*(.+)\\s+(\\d+)\\s+([a-fA-F0-9]+)\\s+(\\d{4}-\\d{2}-\\d{2}):\\s*(\\d+): ?(.*)"); + for (String line : split) { + Matcher matcher = pattern.matcher(line); + if (!matcher.matches()) { + fail("Couldn't parse line [ " + line + " ]"); + } + String user = matcher.group(1); + String shortRev = matcher.group(2); + String fullRev = matcher.group(3); + String date = matcher.group(4); + String lineNum = matcher.group(5); + String content = matcher.group(6); + annotationLines + .add(new HgAnnotationLine(user, HgRevisionNumber.getInstance(shortRev, fullRev), date, Integer.parseInt(lineNum), content)); + } + + XStream xStream = new XStream(); + FileWriter writer = new FileWriter(etalonFile); + try { + xStream.toXML(annotationLines, writer); + } + finally { + writer.close(); + } + } + + +} diff --git a/plugins/java-i18n/src/com/intellij/codeInspection/duplicateStringLiteral/DuplicateStringLiteralInspection.java b/plugins/java-i18n/src/com/intellij/codeInspection/duplicateStringLiteral/DuplicateStringLiteralInspection.java index 33a404c44183..88a5ae3675b7 100644 --- a/plugins/java-i18n/src/com/intellij/codeInspection/duplicateStringLiteral/DuplicateStringLiteralInspection.java +++ b/plugins/java-i18n/src/com/intellij/codeInspection/duplicateStringLiteral/DuplicateStringLiteralInspection.java @@ -100,7 +100,7 @@ public class DuplicateStringLiteralInspection extends BaseLocalInspectionTool { final String stringToFind = (String)value; if (stringToFind.length() == 0) return; final GlobalSearchScope scope = GlobalSearchScope.projectScope(originalExpression.getProject()); - final PsiSearchHelper searchHelper = holder.getFile().getManager().getSearchHelper(); + final PsiSearchHelper searchHelper = PsiSearchHelper.SERVICE.getInstance(holder.getFile().getProject()); final List words = StringUtil.getWordsIn(stringToFind); if (words.isEmpty()) return; // put longer strings first diff --git a/plugins/junit/src/com/intellij/execution/ConfigurationUtil.java b/plugins/junit/src/com/intellij/execution/ConfigurationUtil.java index b2da9f1c85fb..47a46f16712f 100644 --- a/plugins/junit/src/com/intellij/execution/ConfigurationUtil.java +++ b/plugins/junit/src/com/intellij/execution/ConfigurationUtil.java @@ -94,32 +94,34 @@ public class ConfigurationUtil { } ); if (testAnnotation != null) { - ApplicationManager.getApplication().runReadAction(new Runnable() { - public void run(){ - AnnotatedMembersSearch.search(testAnnotation, GlobalSearchScope.allScope(manager.getProject())).forEach(new Processor() { - public boolean process(final PsiMember annotated) { - PsiClass containingClass = annotated instanceof PsiClass ? (PsiClass)annotated : annotated.getContainingClass(); - if (containingClass != null && annotated instanceof PsiMethod == isMethod) { - if (scope.contains(PsiUtilBase.getVirtualFile(containingClass)) && testClassFilter.isAccepted(containingClass)) { - found.add(containingClass); - isJUnit4.set(Boolean.TRUE); - } - ClassInheritorsSearch.search(containingClass, scope, true).forEach(new PsiElementProcessorAdapter(new PsiElementProcessor() { - public boolean execute(final PsiClass aClass) { - if (testClassFilter.isAccepted(aClass)) { - found.add(aClass); - isJUnit4.set(Boolean.TRUE); - } - return true; - } - })); - } - return true; - } - }); - } - }); - + AnnotatedMembersSearch.search(testAnnotation, GlobalSearchScope.allScope(manager.getProject())).forEach(new Processor() { + public boolean process(final PsiMember annotated) { + final PsiClass containingClass = annotated instanceof PsiClass ? (PsiClass)annotated : annotated.getContainingClass(); + if (containingClass != null && annotated instanceof PsiMethod == isMethod) { + if (scope.contains(PsiUtilBase.getVirtualFile(containingClass)) && ApplicationManager.getApplication().runReadAction( + new Computable() { + @Override + public Boolean compute() { + return testClassFilter.isAccepted(containingClass); + } + })) { + found.add(containingClass); + isJUnit4.set(Boolean.TRUE); + } + ClassInheritorsSearch.search(containingClass, scope, true) + .forEach(new PsiElementProcessorAdapter(new PsiElementProcessor() { + public boolean execute(final PsiClass aClass) { + if (testClassFilter.isAccepted(aClass)) { + found.add(aClass); + isJUnit4.set(Boolean.TRUE); + } + return true; + } + })); + } + return true; + } + }); } return isJUnit4.get().booleanValue(); diff --git a/plugins/junit/src/com/intellij/execution/junit/TestDirectory.java b/plugins/junit/src/com/intellij/execution/junit/TestDirectory.java index 9f616cf59249..a6d4607f9cc1 100644 --- a/plugins/junit/src/com/intellij/execution/junit/TestDirectory.java +++ b/plugins/junit/src/com/intellij/execution/junit/TestDirectory.java @@ -20,7 +20,6 @@ import com.intellij.execution.ExecutionBundle; import com.intellij.execution.configurations.*; import com.intellij.execution.testframework.SourceScope; import com.intellij.openapi.module.Module; -import com.intellij.openapi.module.ModuleUtil; import com.intellij.openapi.project.Project; import com.intellij.openapi.projectRoots.JavaSdk; import com.intellij.openapi.util.io.FileUtil; @@ -28,9 +27,9 @@ import com.intellij.openapi.vfs.LocalFileSystem; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.psi.*; import com.intellij.psi.search.GlobalSearchScope; +import com.intellij.psi.search.GlobalSearchScopes; import java.util.Collection; -import java.util.List; /** * User: anna @@ -51,7 +50,8 @@ class TestDirectory extends TestPackage { public SourceScope getSourceScope() { final String dirName = myConfiguration.getPersistentData().getDirName(); final VirtualFile file = LocalFileSystem.getInstance().findFileByPath(FileUtil.toSystemIndependentName(dirName)); - final GlobalSearchScope globalSearchScope = file == null ? GlobalSearchScope.EMPTY_SCOPE : GlobalSearchScope.directoryScope(myProject, file, true); + final GlobalSearchScope globalSearchScope = file == null ? GlobalSearchScope.EMPTY_SCOPE : GlobalSearchScopes + .directoryScope(myProject, file, true); return new SourceScope() { @Override public GlobalSearchScope getGlobalSearchScope() { diff --git a/plugins/maven/src/main/java/org/jetbrains/idea/maven/importing/MavenProjectImporter.java b/plugins/maven/src/main/java/org/jetbrains/idea/maven/importing/MavenProjectImporter.java index cc2e0f6c68da..32c3051362cf 100644 --- a/plugins/maven/src/main/java/org/jetbrains/idea/maven/importing/MavenProjectImporter.java +++ b/plugins/maven/src/main/java/org/jetbrains/idea/maven/importing/MavenProjectImporter.java @@ -17,10 +17,7 @@ package org.jetbrains.idea.maven.importing; import com.intellij.compiler.impl.javaCompiler.javac.JavacSettings; import com.intellij.openapi.application.ApplicationManager; -import com.intellij.openapi.module.JavaModuleType; -import com.intellij.openapi.module.ModifiableModuleModel; -import com.intellij.openapi.module.Module; -import com.intellij.openapi.module.StdModuleTypes; +import com.intellij.openapi.module.*; import com.intellij.openapi.project.Project; import com.intellij.openapi.roots.LibraryOrderEntry; import com.intellij.openapi.roots.ModifiableRootModel; @@ -218,7 +215,7 @@ public class MavenProjectImporter { Module module = myFileToModuleMapping.get(each.getFile()); if (module == null) continue; - if (shouldCreateModuleFor(each) && !(module.getModuleType() instanceof JavaModuleType)) { + if (shouldCreateModuleFor(each) && !(ModuleType.get(module) instanceof JavaModuleType)) { incompatible.add(Pair.create(each, module)); } } @@ -230,7 +227,7 @@ public class MavenProjectImporter { public String fun(Pair each) { MavenProject project = each.first; Module module = each.second; - return module.getModuleType().getName() + + return ModuleType.get(module).getName() + " '" + module.getName() + "' for Maven project '" + diff --git a/plugins/properties/src/com/intellij/codeInspection/duplicatePropertyInspection/DuplicatePropertyInspection.java b/plugins/properties/src/com/intellij/codeInspection/duplicatePropertyInspection/DuplicatePropertyInspection.java index c0bf1fe80224..dd68cb49cc96 100644 --- a/plugins/properties/src/com/intellij/codeInspection/duplicatePropertyInspection/DuplicatePropertyInspection.java +++ b/plugins/properties/src/com/intellij/codeInspection/duplicatePropertyInspection/DuplicatePropertyInspection.java @@ -39,6 +39,7 @@ import com.intellij.psi.PsiElement; import com.intellij.psi.PsiFile; import com.intellij.psi.impl.search.LowLevelSearchUtil; import com.intellij.psi.search.GlobalSearchScope; +import com.intellij.psi.search.GlobalSearchScopes; import com.intellij.psi.search.PsiSearchHelper; import com.intellij.util.CommonProcessors; import com.intellij.util.Processor; @@ -146,13 +147,13 @@ public class DuplicatePropertyInspection extends GlobalSimpleInspectionTool { private void checkFile(final PsiFile file, final InspectionManager manager, GlobalInspectionContextImpl context, final RefManager refManager, final ProblemDescriptionsProcessor processor) { if (!(file instanceof PropertiesFile)) return; if (!context.isToCheckMember(file, this)) return; - final PsiSearchHelper searchHelper = file.getManager().getSearchHelper(); + final PsiSearchHelper searchHelper = PsiSearchHelper.SERVICE.getInstance(file.getProject()); final PropertiesFile propertiesFile = (PropertiesFile)file; final List properties = propertiesFile.getProperties(); Module module = ModuleUtil.findModuleForPsiElement(file); if (module == null) return; final GlobalSearchScope scope = CURRENT_FILE - ? GlobalSearchScope.fileScope(file) + ? GlobalSearchScopes.fileScope(file) : MODULE_WITH_DEPENDENCIES ? GlobalSearchScope.moduleWithDependenciesScope(module) : GlobalSearchScope.projectScope(file.getProject()); diff --git a/plugins/properties/src/com/intellij/lang/properties/UnusedPropertyInspection.java b/plugins/properties/src/com/intellij/lang/properties/UnusedPropertyInspection.java index 2afbbe43644c..dca886a3727a 100644 --- a/plugins/properties/src/com/intellij/lang/properties/UnusedPropertyInspection.java +++ b/plugins/properties/src/com/intellij/lang/properties/UnusedPropertyInspection.java @@ -24,10 +24,7 @@ import com.intellij.openapi.module.Module; import com.intellij.openapi.module.ModuleUtil; import com.intellij.openapi.progress.ProgressIndicator; import com.intellij.openapi.progress.ProgressManager; -import com.intellij.psi.PsiElement; -import com.intellij.psi.PsiElementVisitor; -import com.intellij.psi.PsiFile; -import com.intellij.psi.PsiReference; +import com.intellij.psi.*; import com.intellij.psi.search.GlobalSearchScope; import com.intellij.psi.search.PsiSearchHelper; import com.intellij.psi.search.searches.ReferencesSearch; @@ -57,7 +54,7 @@ public class UnusedPropertyInspection extends PropertySuppressableInspectionBase Module module = ModuleUtil.findModuleForPsiElement(file); if (module == null) return super.buildVisitor(holder, isOnTheFly, session); final GlobalSearchScope searchScope = GlobalSearchScope.moduleWithDependentsScope(module); - final PsiSearchHelper searchHelper = file.getManager().getSearchHelper(); + final PsiSearchHelper searchHelper = PsiSearchHelper.SERVICE.getInstance(file.getProject()); return new PsiElementVisitor() { @Override public void visitElement(PsiElement element) { diff --git a/plugins/testng/src/com/theoryinpractice/testng/inspection/UndeclaredTestInspection.java b/plugins/testng/src/com/theoryinpractice/testng/inspection/UndeclaredTestInspection.java index 85b8620156cf..c96fe49e056e 100644 --- a/plugins/testng/src/com/theoryinpractice/testng/inspection/UndeclaredTestInspection.java +++ b/plugins/testng/src/com/theoryinpractice/testng/inspection/UndeclaredTestInspection.java @@ -34,6 +34,7 @@ import com.intellij.openapi.vfs.VirtualFile; import com.intellij.psi.*; import com.intellij.psi.search.GlobalSearchScope; import com.intellij.psi.search.PsiNonJavaFileReferenceProcessor; +import com.intellij.psi.search.PsiSearchHelper; import com.intellij.psi.util.PsiClassUtil; import com.intellij.psi.util.PsiTreeUtil; import com.intellij.psi.xml.XmlAttribute; @@ -90,13 +91,13 @@ public class UndeclaredTestInspection extends BaseJavaLocalInspectionTool { } for (final String name : names) { final boolean[] found = new boolean[]{false}; - PsiManager.getInstance(project).getSearchHelper() + PsiSearchHelper.SERVICE.getInstance(project) .processUsagesInNonJavaFiles(name, new PsiNonJavaFileReferenceProcessor() { public boolean process(final PsiFile file, final int startOffset, final int endOffset) { if (file.findReferenceAt(startOffset) != null) { if (packageQName.endsWith(name)) { //special package tag required final XmlTag tag = PsiTreeUtil.getParentOfType(file.findElementAt(startOffset), XmlTag.class); - if (tag == null || !tag.getName().equals("package")){ + if (tag == null || !tag.getName().equals("package")) { return true; } final XmlAttribute attribute = tag.getAttribute("name"); diff --git a/plugins/xpath/xpath-lang/src/org/intellij/lang/xpath/xslt/intentions/ConvertIfToChooseIntention.java b/plugins/xpath/xpath-lang/src/org/intellij/lang/xpath/xslt/intentions/ConvertIfToChooseIntention.java index 7e294be6486a..8fb77d73801f 100644 --- a/plugins/xpath/xpath-lang/src/org/intellij/lang/xpath/xslt/intentions/ConvertIfToChooseIntention.java +++ b/plugins/xpath/xpath-lang/src/org/intellij/lang/xpath/xslt/intentions/ConvertIfToChooseIntention.java @@ -21,6 +21,7 @@ import com.intellij.openapi.editor.Editor; import com.intellij.openapi.project.Project; import com.intellij.psi.PsiElement; import com.intellij.psi.PsiFile; +import com.intellij.psi.codeStyle.CodeStyleManager; import com.intellij.psi.util.PsiTreeUtil; import com.intellij.psi.xml.XmlChildRole; import com.intellij.psi.xml.XmlTag; @@ -60,7 +61,7 @@ public class ConvertIfToChooseIntention implements IntentionAction { chooseTag.add(whenTag); chooseTag.add(otherwiseTag); - tag.getManager().getCodeStyleManager().reformat(tag.replace(chooseTag)); + CodeStyleManager.getInstance(tag.getManager().getProject()).reformat(tag.replace(chooseTag)); } public boolean isAvailable(@NotNull Project project, Editor editor, PsiFile file) { diff --git a/plugins/xpath/xpath-lang/src/org/intellij/lang/xpath/xslt/quickfix/CreateTemplateFix.java b/plugins/xpath/xpath-lang/src/org/intellij/lang/xpath/xslt/quickfix/CreateTemplateFix.java index 03de27beae4f..6e28e5aebd97 100644 --- a/plugins/xpath/xpath-lang/src/org/intellij/lang/xpath/xslt/quickfix/CreateTemplateFix.java +++ b/plugins/xpath/xpath-lang/src/org/intellij/lang/xpath/xslt/quickfix/CreateTemplateFix.java @@ -22,6 +22,7 @@ import com.intellij.openapi.project.Project; import com.intellij.psi.PsiDocumentManager; import com.intellij.psi.PsiFile; import com.intellij.psi.XmlElementFactory; +import com.intellij.psi.codeStyle.CodeStyleManager; import com.intellij.psi.xml.XmlTag; import com.intellij.util.IncorrectOperationException; import org.intellij.lang.xpath.xslt.XsltSupport; @@ -72,7 +73,7 @@ public class CreateTemplateFix extends AbstractFix { // the start tag of the newly created tag final XmlTag dummy1 = (XmlTag)parentTag.addAfter(XmlElementFactory.getInstance(project).createTagFromText(DUMMY_TAG, XMLLanguage.INSTANCE), tag); templateTag = (XmlTag)parentTag.addAfter(templateTag, dummy1); - templateTag = (XmlTag)tag.getManager().getCodeStyleManager().reformat(templateTag); + templateTag = (XmlTag)CodeStyleManager.getInstance(tag.getManager().getProject()).reformat(templateTag); final XmlTag dummy2 = templateTag.findFirstSubTag("dummy"); diff --git a/plugins/xpath/xpath-lang/src/org/intellij/lang/xpath/xslt/refactoring/RefactoringUtil.java b/plugins/xpath/xpath-lang/src/org/intellij/lang/xpath/xslt/refactoring/RefactoringUtil.java index 7f813d3cf229..305486c34839 100644 --- a/plugins/xpath/xpath-lang/src/org/intellij/lang/xpath/xslt/refactoring/RefactoringUtil.java +++ b/plugins/xpath/xpath-lang/src/org/intellij/lang/xpath/xslt/refactoring/RefactoringUtil.java @@ -18,6 +18,7 @@ package org.intellij.lang.xpath.xslt.refactoring; import com.intellij.psi.PsiElement; import com.intellij.psi.PsiFile; import com.intellij.psi.XmlRecursiveElementVisitor; +import com.intellij.psi.codeStyle.CodeStyleManager; import com.intellij.psi.util.PsiTreeUtil; import com.intellij.psi.xml.XmlAttribute; import com.intellij.psi.xml.XmlTag; @@ -66,7 +67,7 @@ public class RefactoringUtil { } else { paramTag = (XmlTag)templateTag.add(paramTag); } - paramTag = (XmlTag)paramTag.getManager().getCodeStyleManager().reformat(paramTag); + paramTag = (XmlTag)CodeStyleManager.getInstance(paramTag.getManager().getProject()).reformat(paramTag); return paramTag; } @@ -82,7 +83,7 @@ public class RefactoringUtil { } else { withParamTag = (XmlTag)templateTag.add(withParamTag); } - withParamTag = (XmlTag)withParamTag.getManager().getCodeStyleManager().reformat(withParamTag); + withParamTag = (XmlTag)CodeStyleManager.getInstance(withParamTag.getManager().getProject()).reformat(withParamTag); return withParamTag; } diff --git a/plugins/xpath/xpath-lang/src/org/intellij/lang/xpath/xslt/refactoring/XsltExtractFunctionAction.java b/plugins/xpath/xpath-lang/src/org/intellij/lang/xpath/xslt/refactoring/XsltExtractFunctionAction.java index 8f8dc9271f8e..6f2d03ce2438 100644 --- a/plugins/xpath/xpath-lang/src/org/intellij/lang/xpath/xslt/refactoring/XsltExtractFunctionAction.java +++ b/plugins/xpath/xpath-lang/src/org/intellij/lang/xpath/xslt/refactoring/XsltExtractFunctionAction.java @@ -21,6 +21,7 @@ import com.intellij.openapi.editor.Editor; import com.intellij.openapi.ui.Messages; import com.intellij.psi.PsiElement; import com.intellij.psi.PsiFile; +import com.intellij.psi.codeStyle.CodeStyleManager; import com.intellij.psi.util.PsiTreeUtil; import com.intellij.psi.xml.XmlAttribute; import com.intellij.psi.xml.XmlElement; @@ -109,7 +110,7 @@ public class XsltExtractFunctionAction extends BaseIntroduceAction { return module.getName(); } })); - setIcon(module.getModuleType().getNodeIcon(true)); + setIcon(ModuleType.get(module).getNodeIcon(true)); } else if (value instanceof String) { setText((String)value); } diff --git a/plugins/xpath/xpath-lang/src/org/intellij/lang/xpath/xslt/validation/inspections/SuppressInspectionAction.java b/plugins/xpath/xpath-lang/src/org/intellij/lang/xpath/xslt/validation/inspections/SuppressInspectionAction.java index ddc17c80f218..d3d5928b2f7f 100644 --- a/plugins/xpath/xpath-lang/src/org/intellij/lang/xpath/xslt/validation/inspections/SuppressInspectionAction.java +++ b/plugins/xpath/xpath-lang/src/org/intellij/lang/xpath/xslt/validation/inspections/SuppressInspectionAction.java @@ -23,6 +23,7 @@ import com.intellij.psi.PsiElement; import com.intellij.psi.PsiManager; import com.intellij.psi.PsiWhiteSpace; import com.intellij.psi.XmlElementFactory; +import com.intellij.psi.codeStyle.CodeStyleManager; import com.intellij.psi.util.PsiTreeUtil; import com.intellij.psi.xml.XmlComment; import com.intellij.psi.xml.XmlProlog; @@ -81,7 +82,7 @@ abstract class SuppressInspectionAction extends SuppressIntentionAction { if (text != null && InspectionUtil.SUPPRESSION_PATTERN.matcher(text).matches()) { final String s = text.trim() + ", " + myToolId; final XmlComment newComment = createComment(project, s); - PsiManager.getInstance(project).getCodeStyleManager().reformat(comment.replace(newComment)); + CodeStyleManager.getInstance(PsiManager.getInstance(project).getProject()).reformat(comment.replace(newComment)); } else { addNoinspectionComment(project, anchor); } @@ -96,10 +97,10 @@ abstract class SuppressInspectionAction extends SuppressIntentionAction { if (parent == null) { parent = PsiTreeUtil.getPrevSiblingOfType(anchor, XmlProlog.class); if (parent != null) { - PsiManager.getInstance(project).getCodeStyleManager().reformat(parent.add(newComment)); + CodeStyleManager.getInstance(PsiManager.getInstance(project).getProject()).reformat(parent.add(newComment)); } } else { - PsiManager.getInstance(project).getCodeStyleManager().reformat(parent.addBefore(newComment, anchor)); + CodeStyleManager.getInstance(PsiManager.getInstance(project).getProject()).reformat(parent.addBefore(newComment, anchor)); } } diff --git a/plugins/xpath/xpath-view/src/org/intellij/plugins/xpathView/search/ScopePanel.java b/plugins/xpath/xpath-view/src/org/intellij/plugins/xpathView/search/ScopePanel.java index ab813d6e8d35..2d79e7571fad 100644 --- a/plugins/xpath/xpath-view/src/org/intellij/plugins/xpathView/search/ScopePanel.java +++ b/plugins/xpath/xpath-view/src/org/intellij/plugins/xpathView/search/ScopePanel.java @@ -21,6 +21,7 @@ import com.intellij.openapi.Disposable; import com.intellij.openapi.fileChooser.FileChooserDescriptorFactory; import com.intellij.openapi.module.Module; import com.intellij.openapi.module.ModuleManager; +import com.intellij.openapi.module.ModuleType; import com.intellij.openapi.project.Project; import com.intellij.openapi.ui.ComboBox; import com.intellij.openapi.ui.TextFieldWithBrowseButton; @@ -95,7 +96,7 @@ public class ScopePanel extends JPanel implements Disposable{ @Override public void customize(JList list, Module m, int index, boolean selected, boolean hasFocus) { if (m != null) { - setIcon(m.getModuleType().getNodeIcon(true)); + setIcon(ModuleType.get(m).getNodeIcon(true)); setText(m.getName()); } } diff --git a/resources-en/src/intentionDescriptions/ExpandStaticImportAction/after.java.template b/resources-en/src/intentionDescriptions/ExpandStaticImportAction/after.java.template new file mode 100644 index 000000000000..1af96f6a8ed0 --- /dev/null +++ b/resources-en/src/intentionDescriptions/ExpandStaticImportAction/after.java.template @@ -0,0 +1,7 @@ +import java.util.Arrays; + +class Foo { + public void foo(String... args) { + Arrays.sort(args); + } +} \ No newline at end of file diff --git a/resources-en/src/intentionDescriptions/ExpandStaticImportAction/before.java.template b/resources-en/src/intentionDescriptions/ExpandStaticImportAction/before.java.template new file mode 100644 index 000000000000..5db1418cdfb3 --- /dev/null +++ b/resources-en/src/intentionDescriptions/ExpandStaticImportAction/before.java.template @@ -0,0 +1,7 @@ +import static java.util.Arrays.sort; + +class Foo { + public void foo(String... args) { + sort(args); + } +} \ No newline at end of file diff --git a/resources-en/src/intentionDescriptions/ExpandStaticImportAction/description.html b/resources-en/src/intentionDescriptions/ExpandStaticImportAction/description.html new file mode 100644 index 000000000000..16b31cc736e9 --- /dev/null +++ b/resources-en/src/intentionDescriptions/ExpandStaticImportAction/description.html @@ -0,0 +1,6 @@ + + +This intention expands statically imported method call to explicit class qualification. + When multiple calls use corresponding static import, it is possible to replace them all or to change current one only. + + \ No newline at end of file diff --git a/resources-en/src/messages/QuickFixBundle.properties b/resources-en/src/messages/QuickFixBundle.properties index 3b9f912d78e2..697dc582a731 100644 --- a/resources-en/src/messages/QuickFixBundle.properties +++ b/resources-en/src/messages/QuickFixBundle.properties @@ -45,6 +45,9 @@ change.method.signature.from.usage.family=Change method signature from usage # {0} - original method signature including name, {1} - method name, {2} - proposed new parameters list change.method.signature.from.usage.text=Change signature of ''{0}'' to ''{1}({2})'' +add.parameter.from.usage.text=Add ''{0}'' as {1, choice, 1#1st|2#2nd|3#3rd|4#{0,number}th} parameter to method ''{2}'' +remove.parameter.from.usage.text=Remove {0, choice, 1#1st|2#2nd|3#3rd|4#{0,number}th} parameter from method ''{1}'' +change.parameter.from.usage.text=Change {0, choice, 1#1st|2#2nd|3#3rd|4#{0,number}th} parameter of method ''{1}'' from ''{2}'' to ''{3}'' searching.for.usages.progress.title=Searching For Usages... create.class.from.new.family=Create Class from New create.class.from.new.text=Create Class ''{0}'' diff --git a/resources/src/META-INF/IdeaPlugin.xml b/resources/src/META-INF/IdeaPlugin.xml index f42d2f5e592c..b21ef356a174 100644 --- a/resources/src/META-INF/IdeaPlugin.xml +++ b/resources/src/META-INF/IdeaPlugin.xml @@ -438,7 +438,10 @@ com.intellij.codeInsight.intention.impl.AddSingleMemberStaticImportAction Imports - + + com.intellij.codeInsight.intention.impl.ExpandStaticImportAction + Imports + com.intellij.codeInspection.actions.UnimplementInterfaceAction diff --git a/resources/src/idea/RichPlatformPlugin.xml b/resources/src/idea/RichPlatformPlugin.xml index 111ede4a6194..1ae56a9e8d54 100644 --- a/resources/src/idea/RichPlatformPlugin.xml +++ b/resources/src/idea/RichPlatformPlugin.xml @@ -88,6 +88,7 @@ + diff --git a/xml/relaxng/src/org/intellij/plugins/relaxNG/compact/psi/impl/PatternReference.java b/xml/relaxng/src/org/intellij/plugins/relaxNG/compact/psi/impl/PatternReference.java index 14dde89d3faf..13304f73254c 100644 --- a/xml/relaxng/src/org/intellij/plugins/relaxNG/compact/psi/impl/PatternReference.java +++ b/xml/relaxng/src/org/intellij/plugins/relaxNG/compact/psi/impl/PatternReference.java @@ -27,6 +27,7 @@ import com.intellij.openapi.editor.ScrollType; import com.intellij.openapi.project.Project; import com.intellij.openapi.util.TextRange; import com.intellij.psi.*; +import com.intellij.psi.codeStyle.CodeStyleManager; import com.intellij.psi.util.PsiTreeUtil; import com.intellij.util.ArrayUtil; import com.intellij.util.Function; @@ -202,7 +203,7 @@ class PatternReference extends PsiReferenceBase.Poly implements Function final ASTNode newNode = e.getNode(); assert newNode != null; - e.getManager().getCodeStyleManager().reformatNewlyAddedElement(blockNode, newNode); + CodeStyleManager.getInstance(e.getManager().getProject()).reformatNewlyAddedElement(blockNode, newNode); PsiDocumentManager.getInstance(project).doPostponedOperationsAndUnblockDocument(editor.getDocument()); diff --git a/xml/relaxng/src/org/intellij/plugins/relaxNG/compact/psi/impl/RncNameImpl.java b/xml/relaxng/src/org/intellij/plugins/relaxNG/compact/psi/impl/RncNameImpl.java index 1b66e0c8e9e5..522cfd0f31c6 100644 --- a/xml/relaxng/src/org/intellij/plugins/relaxNG/compact/psi/impl/RncNameImpl.java +++ b/xml/relaxng/src/org/intellij/plugins/relaxNG/compact/psi/impl/RncNameImpl.java @@ -29,6 +29,7 @@ import com.intellij.openapi.project.Project; import com.intellij.openapi.util.Comparing; import com.intellij.openapi.util.TextRange; import com.intellij.psi.*; +import com.intellij.psi.codeStyle.CodeStyleManager; import com.intellij.psi.scope.BaseScopeProcessor; import com.intellij.psi.tree.IElementType; import com.intellij.util.ArrayUtil; @@ -226,7 +227,7 @@ public class RncNameImpl extends RncElementImpl implements RncName, PsiReference final ASTNode newNode = e.getNode(); assert newNode != null; - e.getManager().getCodeStyleManager().reformatNewlyAddedElement(blockNode, newNode); + CodeStyleManager.getInstance(e.getManager().getProject()).reformatNewlyAddedElement(blockNode, newNode); final SmartPsiElementPointer p = SmartPointerManager.getInstance(project).createLazyPointer(e); PsiDocumentManager.getInstance(project).doPostponedOperationsAndUnblockDocument(editor.getDocument()); diff --git a/xml/relaxng/src/org/intellij/plugins/relaxNG/model/resolve/DefinitionResolver.java b/xml/relaxng/src/org/intellij/plugins/relaxNG/model/resolve/DefinitionResolver.java index 13c0a8a5b8f6..93295ac39ff8 100644 --- a/xml/relaxng/src/org/intellij/plugins/relaxNG/model/resolve/DefinitionResolver.java +++ b/xml/relaxng/src/org/intellij/plugins/relaxNG/model/resolve/DefinitionResolver.java @@ -27,6 +27,7 @@ import com.intellij.psi.util.CachedValueProvider; import com.intellij.psi.util.CachedValuesManager; import com.intellij.psi.xml.XmlFile; import com.intellij.util.containers.ContainerUtil; +import com.intellij.util.containers.HashSet; import com.intellij.util.xml.DomFileElement; import com.intellij.util.xml.DomManager; import gnu.trove.THashSet; @@ -70,17 +71,21 @@ public class DefinitionResolver extends CommonElement.Visitor implements myVisitedFiles.set(new THashSet(TObjectHashingStrategy.IDENTITY)); } if (value != null && myVisitedFiles.get().add(value)) { - if (value instanceof RncFile) { - final Grammar grammar = ((RncFile)value).getGrammar(); - if (grammar != null) { - grammar.acceptChildren(this); - } - } else if (value instanceof XmlFile) { - final DomManager mgr = DomManager.getDomManager(value.getProject()); - final DomFileElement element = mgr.getFileElement((XmlFile)value, RngGrammar.class); - if (element != null) { - element.getRootElement().acceptChildren(this); - } + doVisitRncOrRngFile(value, this); + } + } + + private static void doVisitRncOrRngFile(PsiFile file, CommonElement.Visitor visitor) { + if (file instanceof RncFile) { + final Grammar grammar = ((RncFile)file).getGrammar(); + if (grammar != null) { + grammar.acceptChildren(visitor); + } + } else if (file instanceof XmlFile) { + final DomManager mgr = DomManager.getDomManager(file.getProject()); + final DomFileElement element = mgr.getFileElement((XmlFile)file, RngGrammar.class); + if (element != null) { + element.getRootElement().acceptChildren(visitor); } } } @@ -181,6 +186,7 @@ public class DefinitionResolver extends CommonElement.Visitor implements private static class BackwardDefinitionResolver implements PsiElementProcessor { private final String myValue; private Define myResult; + private final Set myVisitedPsiFiles = new HashSet(); public BackwardDefinitionResolver(String value) { myValue = value; @@ -203,6 +209,14 @@ public class DefinitionResolver extends CommonElement.Visitor implements myResult = define; } } + + @Override + public void visitInclude(Include include) { + final PsiFile file = include.getInclude(); + if (file != null && myVisitedPsiFiles.add(file)) { + doVisitRncOrRngFile(file, this); + } + } }); } return myResult == null; diff --git a/xml/relaxng/test/org/intellij/plugins/relaxNG/HighlightingTestBase.java b/xml/relaxng/test/org/intellij/plugins/relaxNG/HighlightingTestBase.java index bf0a5c6f2b65..57c54065d6f4 100644 --- a/xml/relaxng/test/org/intellij/plugins/relaxNG/HighlightingTestBase.java +++ b/xml/relaxng/test/org/intellij/plugins/relaxNG/HighlightingTestBase.java @@ -181,6 +181,10 @@ public abstract class HighlightingTestBase extends UsefulTestCase implements Ide protected void doCustomHighlighting(String name, final boolean checkWeakWarnings, final Boolean includeExternalToolPass) throws Throwable { myTestFixture.configureByFile(name); + doCustomHighlighting(checkWeakWarnings, includeExternalToolPass); + } + + protected void doCustomHighlighting(boolean checkWeakWarnings, Boolean includeExternalToolPass) { final PsiFile file = myTestFixture.getFile(); final Document doc = myTestFixture.getEditor().getDocument(); ExpectedHighlightingData data = new ExpectedHighlightingData(doc, true, checkWeakWarnings, false, file); @@ -192,7 +196,7 @@ public abstract class HighlightingTestBase extends UsefulTestCase implements Ide } @NotNull - private Collection doHighlighting(final Boolean externalToolPass) { + protected Collection doHighlighting(final Boolean externalToolPass) { final Project project = myTestFixture.getProject(); PsiDocumentManager.getInstance(project).commitAllDocuments(); final Editor editor = myTestFixture.getEditor(); diff --git a/xml/relaxng/test/org/intellij/plugins/relaxNG/RncIndexHighlightingTest.java b/xml/relaxng/test/org/intellij/plugins/relaxNG/RncIndexHighlightingTest.java index e936352b5b8f..97b6219105e3 100644 --- a/xml/relaxng/test/org/intellij/plugins/relaxNG/RncIndexHighlightingTest.java +++ b/xml/relaxng/test/org/intellij/plugins/relaxNG/RncIndexHighlightingTest.java @@ -45,4 +45,9 @@ public class RncIndexHighlightingTest extends AbstractIndexTest { public void testInspectionUsedDefine() throws Throwable { doHighlightingTest("used-define.rnc"); } + + public void testInclude1() throws Throwable { + myTestFixture.configureByFiles("include1.rnc", "include1_1.rnc", "include1_2.rnc"); + doCustomHighlighting(true, false); + } } \ No newline at end of file diff --git a/xml/relaxng/testData/highlighting/rnc/include1.rnc b/xml/relaxng/testData/highlighting/rnc/include1.rnc new file mode 100644 index 000000000000..6be67d5f826f --- /dev/null +++ b/xml/relaxng/testData/highlighting/rnc/include1.rnc @@ -0,0 +1,2 @@ + +myelement = element myelement {myattrs} \ No newline at end of file diff --git a/xml/relaxng/testData/highlighting/rnc/include1_1.rnc b/xml/relaxng/testData/highlighting/rnc/include1_1.rnc new file mode 100644 index 000000000000..38c49645472b --- /dev/null +++ b/xml/relaxng/testData/highlighting/rnc/include1_1.rnc @@ -0,0 +1,2 @@ + +myattrs = ( empty ) \ No newline at end of file diff --git a/xml/relaxng/testData/highlighting/rnc/include1_2.rnc b/xml/relaxng/testData/highlighting/rnc/include1_2.rnc new file mode 100644 index 000000000000..d12253b5cbe9 --- /dev/null +++ b/xml/relaxng/testData/highlighting/rnc/include1_2.rnc @@ -0,0 +1,3 @@ + +include "include1_1.rnc" +include "include1.rnc" \ No newline at end of file