diff --git a/.idea/gant_config.xml b/.idea/gant_config.xml new file mode 100644 index 000000000000..b476f6c37404 --- /dev/null +++ b/.idea/gant_config.xml @@ -0,0 +1,7 @@ + + + + + + diff --git a/.idea/libraries/Gant.xml b/.idea/libraries/Gant.xml deleted file mode 100644 index ec46297abec3..000000000000 --- a/.idea/libraries/Gant.xml +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git a/build/build.iml b/build/build.iml index 7460b6c97711..677960ccfaf4 100644 --- a/build/build.iml +++ b/build/build.iml @@ -4,8 +4,9 @@ - + + diff --git a/build/scripts/dist.gant b/build/scripts/dist.gant index f6ee5ab69d93..9b022fba90cc 100644 --- a/build/scripts/dist.gant +++ b/build/scripts/dist.gant @@ -56,6 +56,7 @@ String appInfoFile() { } def wire_build_date(String buildNumber) { + ant.tstamp() ant.replace(token: "__BUILD_NUMBER__", value: buildNumber, file: appInfoFile()) ant.replace(token: "__BUILD_DATE__", value: DSTAMP, file: appInfoFile()) } diff --git a/java/compiler/impl/src/com/intellij/compiler/actions/AntBuildForm.form b/java/compiler/impl/src/com/intellij/compiler/actions/AntBuildForm.form index 44abfab964b8..da9463433bbe 100644 --- a/java/compiler/impl/src/com/intellij/compiler/actions/AntBuildForm.form +++ b/java/compiler/impl/src/com/intellij/compiler/actions/AntBuildForm.form @@ -3,12 +3,12 @@ - + - + @@ -18,7 +18,7 @@ - + @@ -26,7 +26,7 @@ - + @@ -34,7 +34,7 @@ - + @@ -42,12 +42,28 @@ - + + + + + + + + + + + + + + + + + diff --git a/java/compiler/impl/src/com/intellij/compiler/actions/GenerateAntBuildAction.java b/java/compiler/impl/src/com/intellij/compiler/actions/GenerateAntBuildAction.java index 291e06e25725..8af49a55007e 100644 --- a/java/compiler/impl/src/com/intellij/compiler/actions/GenerateAntBuildAction.java +++ b/java/compiler/impl/src/com/intellij/compiler/actions/GenerateAntBuildAction.java @@ -56,7 +56,7 @@ public class GenerateAntBuildAction extends CompileActionBase { public void run() { genOptions[0] = new GenerationOptionsImpl(project, dialog.isGenerateSingleFileBuild(), dialog.isFormsCompilationEnabled(), dialog.isBackupFiles(), dialog.isForceTargetJdk(), dialog.isRuntimeClasspathInlined(), - dialog.isIdeaHomeGenerated(), names); + dialog.isIdeaHomeGenerated(), names, dialog.getOutputFileName()); } }; if (!ProgressManager.getInstance().runProcessWithProgressSynchronously(runnable, "Analyzing project structure...", true, project)) { @@ -118,8 +118,8 @@ public class GenerateAntBuildAction extends CompileActionBase { try { if (genOptions.generateSingleFile) { final File projectBuildFileDestDir = VfsUtil.virtualToIoFile(project.getBaseDir()); - final File destFile = new File(projectBuildFileDestDir, BuildProperties.getProjectBuildFileName(project) + XML_EXTENSION); - final File propertiesFile = new File(projectBuildFileDestDir, BuildProperties.getPropertyFileName(project)); + final File destFile = new File(projectBuildFileDestDir, genOptions.getBuildFileName()); + final File propertiesFile = new File(projectBuildFileDestDir, genOptions.getPropertiesFileName()); ensureFilesWritable(project, new File[]{destFile, propertiesFile}); } @@ -127,8 +127,8 @@ public class GenerateAntBuildAction extends CompileActionBase { final List allFiles = new ArrayList(); final File projectBuildFileDestDir = VfsUtil.virtualToIoFile(project.getBaseDir()); - allFiles.add(new File(projectBuildFileDestDir, BuildProperties.getProjectBuildFileName(project) + XML_EXTENSION)); - allFiles.add(new File(projectBuildFileDestDir, BuildProperties.getPropertyFileName(project))); + allFiles.add(new File(projectBuildFileDestDir, genOptions.getBuildFileName())); + allFiles.add(new File(projectBuildFileDestDir, genOptions.getPropertiesFileName())); final ModuleChunk[] chunks = genOptions.getModuleChunks(); for (final ModuleChunk chunk : chunks) { @@ -218,8 +218,8 @@ public class GenerateAntBuildAction extends CompileActionBase { private File[] generateSingleFileBuild(Project project, GenerationOptions genOptions, List filesToRefresh) throws IOException { final File projectBuildFileDestDir = VfsUtil.virtualToIoFile(project.getBaseDir()); projectBuildFileDestDir.mkdirs(); - final File destFile = new File(projectBuildFileDestDir, BuildProperties.getProjectBuildFileName(project) + XML_EXTENSION); - final File propertiesFile = new File(projectBuildFileDestDir, BuildProperties.getPropertyFileName(project)); + final File destFile = new File(projectBuildFileDestDir, genOptions.getBuildFileName()); + final File propertiesFile = new File(projectBuildFileDestDir, genOptions.getPropertiesFileName()); if (!backup(destFile, project, genOptions, filesToRefresh)) { return null; @@ -289,8 +289,8 @@ public class GenerateAntBuildAction extends CompileActionBase { final File projectBuildFileDestDir = VfsUtil.virtualToIoFile(project.getBaseDir()); projectBuildFileDestDir.mkdirs(); final List generated = new ArrayList(); - final File projectBuildFile = new File(projectBuildFileDestDir, BuildProperties.getProjectBuildFileName(project) + XML_EXTENSION); - final File propertiesFile = new File(projectBuildFileDestDir, BuildProperties.getPropertyFileName(project)); + final File projectBuildFile = new File(projectBuildFileDestDir, genOptions.getBuildFileName()); + final File propertiesFile = new File(projectBuildFileDestDir, genOptions.getPropertiesFileName()); final ModuleChunk[] chunks = genOptions.getModuleChunks(); final File[] chunkFiles = new File[chunks.length]; diff --git a/java/compiler/impl/src/com/intellij/compiler/actions/GenerateAntBuildDialog.java b/java/compiler/impl/src/com/intellij/compiler/actions/GenerateAntBuildDialog.java index c121779066ba..ae81d85668be 100644 --- a/java/compiler/impl/src/com/intellij/compiler/actions/GenerateAntBuildDialog.java +++ b/java/compiler/impl/src/com/intellij/compiler/actions/GenerateAntBuildDialog.java @@ -17,6 +17,7 @@ package com.intellij.compiler.actions; import com.intellij.compiler.HelpID; import com.intellij.compiler.ModuleCompilerUtil; +import com.intellij.compiler.ant.BuildProperties; import com.intellij.ide.util.PropertiesComponent; import com.intellij.openapi.compiler.CompilerBundle; import com.intellij.openapi.help.HelpManager; @@ -51,178 +52,197 @@ import java.util.List; * Date: Mar 29, 2004 */ public class GenerateAntBuildDialog extends DialogWrapper { - private JPanel myPanel; - private JRadioButton myRbGenerateSingleFileBuild; - private JRadioButton myRbGenerateMultipleFilesBuild; - private JCheckBox myCbEnableUIFormsCompilation; - private JRadioButton myRbBackupFiles; - private JRadioButton myRbOverwriteFiles; - private JCheckBox myCbForceTargetJdk; - private JCheckBox myCbInlineRuntimeClasspath; - private JPanel myChunksPanel; - private JCheckBox myGenerateIdeaHomeProperty; - private final Project myProject; - @NonNls private static final String SINGLE_FILE_PROPERTY = "GenerateAntBuildDialog.generateSingleFile"; - @NonNls private static final String UI_FORM_PROPERTY = "GenerateAntBuildDialog.enableUiFormCompile"; - @NonNls private static final String FORCE_TARGET_JDK_PROPERTY = "GenerateAntBuildDialog.forceTargetJdk"; - @NonNls private static final String BACKUP_FILES_PROPERTY = "GenerateAntBuildDialog.backupFiles"; - @NonNls private static final String INLINE_RUNTIME_CLASSPATH_PROPERTY = "GenerateAntBuildDialog.inclineRuntiemClasspath"; - @NonNls private static final String GENERATE_IDEA_HOME_PROPERTY = "GenerateAntBuildDialog.generateIdeaHomeProperty"; - private MyTableModel myTableModel; - private Table myTable; + private JPanel myPanel; + private JRadioButton myRbGenerateSingleFileBuild; + private JRadioButton myRbGenerateMultipleFilesBuild; + private JCheckBox myCbEnableUIFormsCompilation; + private JRadioButton myRbBackupFiles; + private JRadioButton myRbOverwriteFiles; + private JCheckBox myCbForceTargetJdk; + private JCheckBox myCbInlineRuntimeClasspath; + private JPanel myChunksPanel; + private JCheckBox myGenerateIdeaHomeProperty; + private JTextField myOutputFileNameField; + private final Project myProject; + @NonNls private static final String SINGLE_FILE_PROPERTY = "GenerateAntBuildDialog.generateSingleFile"; + @NonNls private static final String UI_FORM_PROPERTY = "GenerateAntBuildDialog.enableUiFormCompile"; + @NonNls private static final String FORCE_TARGET_JDK_PROPERTY = "GenerateAntBuildDialog.forceTargetJdk"; + @NonNls private static final String BACKUP_FILES_PROPERTY = "GenerateAntBuildDialog.backupFiles"; + @NonNls private static final String INLINE_RUNTIME_CLASSPATH_PROPERTY = "GenerateAntBuildDialog.inclineRuntiemClasspath"; + @NonNls private static final String GENERATE_IDEA_HOME_PROPERTY = "GenerateAntBuildDialog.generateIdeaHomeProperty"; + @NonNls private static final String OUTPUT_FILE_NAME_PROPERTY = "GenerateAntBuildDialog.outputFileNameProperty"; + private MyTableModel myTableModel; + private Table myTable; - public GenerateAntBuildDialog(Project project) { - super(project, false); - myProject = project; - setTitle(CompilerBundle.message("generate.ant.build.title")); - init(); - loadSettings(); - } + public GenerateAntBuildDialog(Project project) { + super(project, false); + myProject = project; + setTitle(CompilerBundle.message("generate.ant.build.title")); + init(); + loadSettings(); + } - private List> getCycleChunks() { - List> chunks = - ModuleCompilerUtil.getSortedModuleChunks(myProject, Arrays.asList(ModuleManager.getInstance(myProject).getModules())); - for (Iterator> it = chunks.iterator(); it.hasNext();) { - final Chunk chunk = it.next(); - if (chunk.getNodes().size() == 1) { - it.remove(); - } + private List> getCycleChunks() { + List> chunks = + ModuleCompilerUtil.getSortedModuleChunks(myProject, Arrays.asList(ModuleManager.getInstance(myProject).getModules())); + for (Iterator> it = chunks.iterator(); it.hasNext();) { + final Chunk chunk = it.next(); + if (chunk.getNodes().size() == 1) { + it.remove(); } - return chunks; } + return chunks; + } - private void loadSettings() { - final PropertiesComponent properties = PropertiesComponent.getInstance(myProject); - if (properties.isValueSet(SINGLE_FILE_PROPERTY)) { - final boolean singleFile = properties.isTrueValue(SINGLE_FILE_PROPERTY); - myRbGenerateSingleFileBuild.setSelected(singleFile); - myRbGenerateMultipleFilesBuild.setSelected(!singleFile); - } - if (properties.isValueSet(UI_FORM_PROPERTY)) { - myCbEnableUIFormsCompilation.setSelected(properties.isTrueValue(UI_FORM_PROPERTY)); - } - if (properties.isValueSet(FORCE_TARGET_JDK_PROPERTY)) { - myCbForceTargetJdk.setSelected(properties.isTrueValue(FORCE_TARGET_JDK_PROPERTY)); - } - if (properties.isValueSet(BACKUP_FILES_PROPERTY)) { - final boolean backup = properties.isTrueValue(BACKUP_FILES_PROPERTY); - myRbBackupFiles.setSelected(backup); - myRbOverwriteFiles.setSelected(!backup); - } - if (properties.isValueSet(INLINE_RUNTIME_CLASSPATH_PROPERTY)) { - myCbInlineRuntimeClasspath.setSelected(properties.isTrueValue(INLINE_RUNTIME_CLASSPATH_PROPERTY)); - } - if (properties.isValueSet(GENERATE_IDEA_HOME_PROPERTY)) { - myGenerateIdeaHomeProperty.setSelected(properties.isTrueValue(GENERATE_IDEA_HOME_PROPERTY)); - } + private void loadSettings() { + final PropertiesComponent properties = PropertiesComponent.getInstance(myProject); + if (properties.isValueSet(SINGLE_FILE_PROPERTY)) { + final boolean singleFile = properties.isTrueValue(SINGLE_FILE_PROPERTY); + myRbGenerateSingleFileBuild.setSelected(singleFile); + myRbGenerateMultipleFilesBuild.setSelected(!singleFile); } - - private void saveSettings() { - final PropertiesComponent properties = PropertiesComponent.getInstance(myProject); - properties.setValue(SINGLE_FILE_PROPERTY, Boolean.toString(myRbGenerateSingleFileBuild.isSelected())); - properties.setValue(UI_FORM_PROPERTY, Boolean.toString(myCbEnableUIFormsCompilation.isSelected())); - properties.setValue(FORCE_TARGET_JDK_PROPERTY, Boolean.toString(myCbForceTargetJdk.isSelected())); - properties.setValue(BACKUP_FILES_PROPERTY, Boolean.toString(myRbBackupFiles.isSelected())); - properties.setValue(INLINE_RUNTIME_CLASSPATH_PROPERTY, Boolean.toString(myCbInlineRuntimeClasspath.isSelected())); - properties.setValue(GENERATE_IDEA_HOME_PROPERTY, Boolean.toString(myGenerateIdeaHomeProperty.isSelected())); + if (properties.isValueSet(UI_FORM_PROPERTY)) { + myCbEnableUIFormsCompilation.setSelected(properties.isTrueValue(UI_FORM_PROPERTY)); } - - public void dispose() { - saveSettings(); - super.dispose(); + if (properties.isValueSet(FORCE_TARGET_JDK_PROPERTY)) { + myCbForceTargetJdk.setSelected(properties.isTrueValue(FORCE_TARGET_JDK_PROPERTY)); } - - protected JComponent createCenterPanel() { - final ButtonGroup group = new ButtonGroup(); - group.add(myRbGenerateMultipleFilesBuild); - group.add(myRbGenerateSingleFileBuild); - - final ButtonGroup group1 = new ButtonGroup(); - group1.add(myRbBackupFiles); - group1.add(myRbOverwriteFiles); - - myRbGenerateMultipleFilesBuild.setSelected(true); - myRbBackupFiles.setSelected(true); - myCbEnableUIFormsCompilation.setSelected(true); - myCbForceTargetJdk.setSelected(true); - myCbInlineRuntimeClasspath.setSelected(false); - - initChunksPanel(); - - return myPanel; + if (properties.isValueSet(BACKUP_FILES_PROPERTY)) { + final boolean backup = properties.isTrueValue(BACKUP_FILES_PROPERTY); + myRbBackupFiles.setSelected(backup); + myRbOverwriteFiles.setSelected(!backup); } - - private void initChunksPanel() { - List> chunks = getCycleChunks(); - if (chunks.isEmpty()) { - return; - } - myChunksPanel.setLayout(new BorderLayout()); - myChunksPanel.setBorder( - IdeBorderFactory.createTitledBorder(CompilerBundle.message("generate.ant.build.dialog.cyclic.modules.table.title"))); - JLabel textLabel = new JLabel(CompilerBundle.message("generate.ant.build.dialog.cyclic.modules.table.description")); - textLabel.setUI(new MultiLineLabelUI()); - textLabel.setBorder(IdeBorderFactory.createEmptyBorder(4, 4, 6, 4)); - myChunksPanel.add(textLabel, BorderLayout.NORTH); - - myTableModel = new MyTableModel(chunks); - myTable = new Table(myTableModel); - final MyTableCellRenderer cellRenderer = new MyTableCellRenderer(); - final TableColumn nameColumn = myTable.getColumnModel().getColumn(MyTableModel.NAME_COLUMN); - nameColumn.setCellEditor(ComboBoxTableCellEditor.INSTANCE); - nameColumn.setCellRenderer(cellRenderer); - final TableColumn labelColumn = myTable.getColumnModel().getColumn(MyTableModel.NUMBER_COLUMN); - labelColumn.setCellRenderer(cellRenderer); - - final Dimension preferredSize = new Dimension(myTable.getPreferredSize()); - preferredSize.height = (myTableModel.getRowCount() + 2) * myTable.getRowHeight() + myTable.getTableHeader().getHeight(); - - final JScrollPane scrollPane = ScrollPaneFactory.createScrollPane(myTable); - scrollPane.setPreferredSize(preferredSize); - myChunksPanel.add(scrollPane, BorderLayout.CENTER); + if (properties.isValueSet(INLINE_RUNTIME_CLASSPATH_PROPERTY)) { + myCbInlineRuntimeClasspath.setSelected(properties.isTrueValue(INLINE_RUNTIME_CLASSPATH_PROPERTY)); } - - protected void doOKAction() { - if (myTable != null) { - TableCellEditor cellEditor = myTable.getCellEditor(); - if (cellEditor != null) { - cellEditor.stopCellEditing(); - } - } - super.doOKAction(); + if (properties.isValueSet(GENERATE_IDEA_HOME_PROPERTY)) { + myGenerateIdeaHomeProperty.setSelected(properties.isTrueValue(GENERATE_IDEA_HOME_PROPERTY)); } - - public boolean isGenerateSingleFileBuild() { - return myRbGenerateSingleFileBuild.isSelected(); + if (properties.isValueSet(OUTPUT_FILE_NAME_PROPERTY)) { + myOutputFileNameField.setText(properties.getValue(OUTPUT_FILE_NAME_PROPERTY)); } - - public boolean isFormsCompilationEnabled() { - return myCbEnableUIFormsCompilation.isSelected(); + else { + myOutputFileNameField.setText(BuildProperties.getProjectBuildFileName(myProject)); } + } - public boolean isForceTargetJdk() { - return myCbForceTargetJdk.isSelected(); + private void saveSettings() { + final PropertiesComponent properties = PropertiesComponent.getInstance(myProject); + properties.setValue(SINGLE_FILE_PROPERTY, Boolean.toString(myRbGenerateSingleFileBuild.isSelected())); + properties.setValue(UI_FORM_PROPERTY, Boolean.toString(myCbEnableUIFormsCompilation.isSelected())); + properties.setValue(FORCE_TARGET_JDK_PROPERTY, Boolean.toString(myCbForceTargetJdk.isSelected())); + properties.setValue(BACKUP_FILES_PROPERTY, Boolean.toString(myRbBackupFiles.isSelected())); + properties.setValue(INLINE_RUNTIME_CLASSPATH_PROPERTY, Boolean.toString(myCbInlineRuntimeClasspath.isSelected())); + properties.setValue(GENERATE_IDEA_HOME_PROPERTY, Boolean.toString(myGenerateIdeaHomeProperty.isSelected())); + final String outputFileName = getOutputFileName(); + if (outputFileName.length() > 0) { + properties.setValue(OUTPUT_FILE_NAME_PROPERTY, outputFileName); } - - public boolean isBackupFiles() { - return myRbBackupFiles.isSelected(); + else { + properties.unsetValue(OUTPUT_FILE_NAME_PROPERTY); } + } - public boolean isRuntimeClasspathInlined() { - return myCbInlineRuntimeClasspath.isSelected(); + public void dispose() { + saveSettings(); + super.dispose(); + } + + protected JComponent createCenterPanel() { + final ButtonGroup group = new ButtonGroup(); + group.add(myRbGenerateMultipleFilesBuild); + group.add(myRbGenerateSingleFileBuild); + + final ButtonGroup group1 = new ButtonGroup(); + group1.add(myRbBackupFiles); + group1.add(myRbOverwriteFiles); + + myRbGenerateMultipleFilesBuild.setSelected(true); + myRbBackupFiles.setSelected(true); + myCbEnableUIFormsCompilation.setSelected(true); + myCbForceTargetJdk.setSelected(true); + myCbInlineRuntimeClasspath.setSelected(false); + + initChunksPanel(); + + return myPanel; + } + + private void initChunksPanel() { + List> chunks = getCycleChunks(); + if (chunks.isEmpty()) { + return; } + myChunksPanel.setLayout(new BorderLayout()); + myChunksPanel.setBorder( + IdeBorderFactory.createTitledBorder(CompilerBundle.message("generate.ant.build.dialog.cyclic.modules.table.title"))); + JLabel textLabel = new JLabel(CompilerBundle.message("generate.ant.build.dialog.cyclic.modules.table.description")); + textLabel.setUI(new MultiLineLabelUI()); + textLabel.setBorder(IdeBorderFactory.createEmptyBorder(4, 4, 6, 4)); + myChunksPanel.add(textLabel, BorderLayout.NORTH); - public String[] getRepresentativeModuleNames() { - return myTableModel != null ? myTableModel.getModuleRepresentatives() : ArrayUtil.EMPTY_STRING_ARRAY; + myTableModel = new MyTableModel(chunks); + myTable = new Table(myTableModel); + final MyTableCellRenderer cellRenderer = new MyTableCellRenderer(); + final TableColumn nameColumn = myTable.getColumnModel().getColumn(MyTableModel.NAME_COLUMN); + nameColumn.setCellEditor(ComboBoxTableCellEditor.INSTANCE); + nameColumn.setCellRenderer(cellRenderer); + final TableColumn labelColumn = myTable.getColumnModel().getColumn(MyTableModel.NUMBER_COLUMN); + labelColumn.setCellRenderer(cellRenderer); + + final Dimension preferredSize = new Dimension(myTable.getPreferredSize()); + preferredSize.height = (myTableModel.getRowCount() + 2) * myTable.getRowHeight() + myTable.getTableHeader().getHeight(); + + final JScrollPane scrollPane = ScrollPaneFactory.createScrollPane(myTable); + scrollPane.setPreferredSize(preferredSize); + myChunksPanel.add(scrollPane, BorderLayout.CENTER); + } + + protected void doOKAction() { + if (myTable != null) { + TableCellEditor cellEditor = myTable.getCellEditor(); + if (cellEditor != null) { + cellEditor.stopCellEditing(); + } } + super.doOKAction(); + } - /** - * @return true if user has selected to generate IDEA_HOME property - */ - public boolean isIdeaHomeGenerated() { - return myGenerateIdeaHomeProperty.isSelected(); - } + public boolean isGenerateSingleFileBuild() { + return myRbGenerateSingleFileBuild.isSelected(); + } + public boolean isFormsCompilationEnabled() { + return myCbEnableUIFormsCompilation.isSelected(); + } + + public boolean isForceTargetJdk() { + return myCbForceTargetJdk.isSelected(); + } + + public boolean isBackupFiles() { + return myRbBackupFiles.isSelected(); + } + + public boolean isRuntimeClasspathInlined() { + return myCbInlineRuntimeClasspath.isSelected(); + } + + public String[] getRepresentativeModuleNames() { + return myTableModel != null ? myTableModel.getModuleRepresentatives() : ArrayUtil.EMPTY_STRING_ARRAY; + } + + /** + * @return true if user has selected to generate IDEA_HOME property + */ + public boolean isIdeaHomeGenerated() { + return myGenerateIdeaHomeProperty.isSelected(); + } + + public String getOutputFileName() { + return myOutputFileNameField.getText().trim(); + } + private static class MyTableModel extends AbstractTableModel { private static final int NUMBER_COLUMN = 0; private static final int NAME_COLUMN = 1; diff --git a/java/compiler/impl/src/com/intellij/compiler/ant/BuildPropertiesImpl.java b/java/compiler/impl/src/com/intellij/compiler/ant/BuildPropertiesImpl.java index c7e1a8d20a50..5b77864f6e1a 100644 --- a/java/compiler/impl/src/com/intellij/compiler/ant/BuildPropertiesImpl.java +++ b/java/compiler/impl/src/com/intellij/compiler/ant/BuildPropertiesImpl.java @@ -43,7 +43,7 @@ import java.io.IOException; public class BuildPropertiesImpl extends BuildProperties { public BuildPropertiesImpl(Project project, final GenerationOptions genOptions) { - add(new Property(getPropertyFileName(project))); + add(new Property(genOptions.getPropertiesFileName())); //noinspection HardCodedStringLiteral add(new Comment(CompilerBundle.message("generated.ant.build.disable.tests.property.comment"), diff --git a/java/compiler/impl/src/com/intellij/compiler/ant/GenerationOptionsImpl.java b/java/compiler/impl/src/com/intellij/compiler/ant/GenerationOptionsImpl.java index bfa9141e1ced..0bfe80e303b6 100644 --- a/java/compiler/impl/src/com/intellij/compiler/ant/GenerationOptionsImpl.java +++ b/java/compiler/impl/src/com/intellij/compiler/ant/GenerationOptionsImpl.java @@ -44,267 +44,286 @@ import java.util.*; * Date: Mar 25, 2004 */ public class GenerationOptionsImpl extends GenerationOptions { - /** - * from absolute path to macro substitutions - */ - private final ReplacePathToMacroMap myMacroReplacementMap; - /** - * from absolute path to macro substitutions - */ - private final Map myOutputUrlToPropertyRefMap; - /** - * module chunks - */ - private final ModuleChunk[] myModuleChunks; - /** - * the project to be converted - */ - private final Project myProject; - private final boolean myGenerateIdeaHomeProperty; - private Set myJdkUrls; - /** - * Custom compilers used in the ant build. - */ - private final Set myCustomCompilers = new HashSet(); - /** - * map from modules to chunks - */ - private final Map myModuleToChunkMap = new HashMap(); - /** - * A constructor - * - * @param project a project to generate - * @param forceTargetJdk a value of corresponding option - * @param generateSingleFile a value of corresponding option - * @param enableFormCompiler a value of corresponding option - * @param backupPreviouslyGeneratedFiles a value of corresponding option - * @param inlineRuntimeClasspath if true a runtiem classpaths are inlined - * @param representativeModuleNames a module name that represents module chunks. - */ - public GenerationOptionsImpl(Project project, - boolean generateSingleFile, - boolean enableFormCompiler, - boolean backupPreviouslyGeneratedFiles, - boolean forceTargetJdk, - boolean inlineRuntimeClasspath, - boolean generateIdeaHomeProperty, - String[] representativeModuleNames) { - super(forceTargetJdk, generateSingleFile, enableFormCompiler, backupPreviouslyGeneratedFiles, inlineRuntimeClasspath); - myProject = project; - myGenerateIdeaHomeProperty = generateIdeaHomeProperty; - myMacroReplacementMap = createReplacementMap(); - myModuleChunks = createModuleChunks(representativeModuleNames); - myOutputUrlToPropertyRefMap = createOutputUrlToPropertyRefMap(myModuleChunks); + /** + * from absolute path to macro substitutions + */ + private final ReplacePathToMacroMap myMacroReplacementMap; + /** + * from absolute path to macro substitutions + */ + private final Map myOutputUrlToPropertyRefMap; + /** + * module chunks + */ + private final ModuleChunk[] myModuleChunks; + /** + * the project to be converted + */ + private final Project myProject; + private final boolean myGenerateIdeaHomeProperty; + private final String myOutputFileName; + private Set myJdkUrls; + /** + * Custom compilers used in the ant build. + */ + private final Set myCustomCompilers = new HashSet(); + /** + * map from modules to chunks + */ + private final Map myModuleToChunkMap = new HashMap(); + + /** + * A constructor + * + * @param project a project to generate + * @param generateSingleFile a value of corresponding option + * @param enableFormCompiler a value of corresponding option + * @param backupPreviouslyGeneratedFiles a value of corresponding option + * @param forceTargetJdk a value of corresponding option + * @param inlineRuntimeClasspath if true a runtiem classpaths are inlined + * @param representativeModuleNames a module name that represents module chunks. + * @param outputFileName a name for the output file + */ + public GenerationOptionsImpl(Project project, + boolean generateSingleFile, + boolean enableFormCompiler, + boolean backupPreviouslyGeneratedFiles, + boolean forceTargetJdk, + boolean inlineRuntimeClasspath, + boolean generateIdeaHomeProperty, + String[] representativeModuleNames, String outputFileName) { + super(forceTargetJdk, generateSingleFile, enableFormCompiler, backupPreviouslyGeneratedFiles, inlineRuntimeClasspath); + myProject = project; + myGenerateIdeaHomeProperty = generateIdeaHomeProperty; + myOutputFileName = outputFileName; + myMacroReplacementMap = createReplacementMap(); + myModuleChunks = createModuleChunks(representativeModuleNames); + myOutputUrlToPropertyRefMap = createOutputUrlToPropertyRefMap(myModuleChunks); + } + + /** + * A constructor + * + * @param project a project to generate + * @param forceTargetJdk a value of corresponding option + * @param generateSingleFile a value of corresponding option + * @param enableFormCompiler a value of corresponding option + * @param backupPreviouslyGeneratedFiles a value of corresponding option + * @param representativeModuleNames a module name that represents module chunks. + */ + @Deprecated + public GenerationOptionsImpl(Project project, + boolean generateSingleFile, + boolean enableFormCompiler, + boolean backupPreviouslyGeneratedFiles, + boolean forceTargetJdk, + String[] representativeModuleNames) { + this(project, forceTargetJdk, generateSingleFile, enableFormCompiler, backupPreviouslyGeneratedFiles, false, false, + representativeModuleNames, null); + } + + /** + * {@inheritDoc} + */ + @Override + public boolean isIdeaHomeGenerated() { + return myGenerateIdeaHomeProperty; + } + + public String getBuildFileName() { + return getOutputFileName() + ".xml"; + } + + public String getPropertiesFileName() { + return getOutputFileName() + ".properties"; + } + + private String getOutputFileName() { + if (myOutputFileName == null || myOutputFileName.length() == 0) { + return BuildProperties.getProjectBuildFileName(myProject); } + return myOutputFileName; + } - /** - * A constructor - * - * @param project a project to generate - * @param forceTargetJdk a value of corresponding option - * @param generateSingleFile a value of corresponding option - * @param enableFormCompiler a value of corresponding option - * @param backupPreviouslyGeneratedFiles a value of corresponding option - * @param representativeModuleNames a module name that represents module chunks. - */ - @Deprecated - public GenerationOptionsImpl(Project project, - boolean generateSingleFile, - boolean enableFormCompiler, - boolean backupPreviouslyGeneratedFiles, - boolean forceTargetJdk, - String[] representativeModuleNames) { - this(project, forceTargetJdk, generateSingleFile, enableFormCompiler, backupPreviouslyGeneratedFiles, false, false, - representativeModuleNames); - } - - /** - * {@inheritDoc} - */ - @Override - public boolean isIdeaHomeGenerated() { - return myGenerateIdeaHomeProperty; - } - - /** - * {@inheritDoc} - */ - @Override - public ModuleChunk getChunkByModule(final Module module) { - if (myModuleToChunkMap.isEmpty()) { - for (ModuleChunk c : myModuleChunks) { - for (Module m : c.getModules()) { - myModuleToChunkMap.put(m, c); - } - } + /** + * {@inheritDoc} + */ + @Override + public ModuleChunk getChunkByModule(final Module module) { + if (myModuleToChunkMap.isEmpty()) { + for (ModuleChunk c : myModuleChunks) { + for (Module m : c.getModules()) { + myModuleToChunkMap.put(m, c); } - return myModuleToChunkMap.get(module); + } } + return myModuleToChunkMap.get(module); + } - @Override - public String subsitutePathWithMacros(String path) { - if (myMacroReplacementMap.size() == 0) { - return path; // optimization + @Override + public String subsitutePathWithMacros(String path) { + if (myMacroReplacementMap.size() == 0) { + return path; // optimization + } + return myMacroReplacementMap.substitute(path, SystemInfo.isFileSystemCaseSensitive); + } + + public String getPropertyRefForUrl(String url) { + return myOutputUrlToPropertyRefMap.get(url); + } + + private static ReplacePathToMacroMap createReplacementMap() { + final PathMacros pathMacros = PathMacros.getInstance(); + final Set macroNames = pathMacros.getUserMacroNames(); + final ReplacePathToMacroMap map = new ReplacePathToMacroMap(); + for (final String macroName : macroNames) { + map.put(GenerationUtils.normalizePath(pathMacros.getValue(macroName)), + BuildProperties.propertyRef(BuildProperties.getPathMacroProperty(macroName))); + } + map.put(GenerationUtils.normalizePath(PathManager.getHomePath()), BuildProperties.propertyRef(BuildProperties.PROPERTY_IDEA_HOME)); + return map; + } + + private static Map createOutputUrlToPropertyRefMap(ModuleChunk[] chunks) { + final Map map = new HashMap(); + + for (final ModuleChunk chunk : chunks) { + final String outputPathRef = BuildProperties.propertyRef(BuildProperties.getOutputPathProperty(chunk.getName())); + final String testsOutputPathRef = BuildProperties.propertyRef(BuildProperties.getOutputPathForTestsProperty(chunk.getName())); + + final Module[] modules = chunk.getModules(); + for (final Module module : modules) { + final String outputPathUrl = CompilerModuleExtension.getInstance(module).getCompilerOutputUrl(); + if (outputPathUrl != null) { + map.put(outputPathUrl, outputPathRef); } - return myMacroReplacementMap.substitute(path, SystemInfo.isFileSystemCaseSensitive); - } - - public String getPropertyRefForUrl(String url) { - return myOutputUrlToPropertyRefMap.get(url); - } - - private static ReplacePathToMacroMap createReplacementMap() { - final PathMacros pathMacros = PathMacros.getInstance(); - final Set macroNames = pathMacros.getUserMacroNames(); - final ReplacePathToMacroMap map = new ReplacePathToMacroMap(); - for (final String macroName : macroNames) { - map.put(GenerationUtils.normalizePath(pathMacros.getValue(macroName)), - BuildProperties.propertyRef(BuildProperties.getPathMacroProperty(macroName))); - } - map.put(GenerationUtils.normalizePath(PathManager.getHomePath()), BuildProperties.propertyRef(BuildProperties.PROPERTY_IDEA_HOME)); - return map; - } - - private static Map createOutputUrlToPropertyRefMap(ModuleChunk[] chunks) { - final Map map = new HashMap(); - - for (final ModuleChunk chunk : chunks) { - final String outputPathRef = BuildProperties.propertyRef(BuildProperties.getOutputPathProperty(chunk.getName())); - final String testsOutputPathRef = BuildProperties.propertyRef(BuildProperties.getOutputPathForTestsProperty(chunk.getName())); - - final Module[] modules = chunk.getModules(); - for (final Module module : modules) { - final String outputPathUrl = CompilerModuleExtension.getInstance(module).getCompilerOutputUrl(); - if (outputPathUrl != null) { - map.put(outputPathUrl, outputPathRef); - } - final String outputPathForTestsUrl = CompilerModuleExtension.getInstance(module).getCompilerOutputUrlForTests(); - if (outputPathForTestsUrl != null) { - if (outputPathUrl == null || !outputPathForTestsUrl.equals(outputPathUrl)) { - map.put(outputPathForTestsUrl, testsOutputPathRef); - } - } - } - } - return map; - } - - @Override - public ModuleChunk[] getModuleChunks() { - return myModuleChunks; - } - - private ModuleChunk[] createModuleChunks(String[] representativeModuleNames) { - final Set mainModuleNames = new HashSet(Arrays.asList(representativeModuleNames)); - final Graph> chunkGraph = ModuleCompilerUtil.toChunkGraph(ModuleManager.getInstance(myProject).moduleGraph()); - final Map, ModuleChunk> map = new HashMap, ModuleChunk>(); - final Map> reverseMap = new HashMap>(); - for (final Chunk chunk : chunkGraph.getNodes()) { - final Set modules = chunk.getNodes(); - final ModuleChunk moduleChunk = new ModuleChunk(modules.toArray(new Module[modules.size()])); - for (final Module module : modules) { - if (mainModuleNames.contains(module.getName())) { - moduleChunk.setMainModule(module); - break; - } - } - map.put(chunk, moduleChunk); - reverseMap.put(moduleChunk, chunk); - } - - final Graph moduleChunkGraph = - GraphGenerator.create(CachingSemiGraph.create(new GraphGenerator.SemiGraph() { - public Collection getNodes() { - return map.values(); - } - - public Iterator getIn(ModuleChunk n) { - final Chunk chunk = reverseMap.get(n); - final Iterator> in = chunkGraph.getIn(chunk); - return new Iterator() { - public boolean hasNext() { - return in.hasNext(); - } - - public ModuleChunk next() { - return map.get(in.next()); - } - - public void remove() { - new OperationNotSupportedException(); - } - }; - } - })); - final Collection nodes = moduleChunkGraph.getNodes(); - final ModuleChunk[] moduleChunks = nodes.toArray(new ModuleChunk[nodes.size()]); - for (ModuleChunk moduleChunk : moduleChunks) { - final Iterator depsIterator = moduleChunkGraph.getIn(moduleChunk); - List deps = new ArrayList(); - while (depsIterator.hasNext()) { - deps.add(depsIterator.next()); + final String outputPathForTestsUrl = CompilerModuleExtension.getInstance(module).getCompilerOutputUrlForTests(); + if (outputPathForTestsUrl != null) { + if (outputPathUrl == null || !outputPathForTestsUrl.equals(outputPathUrl)) { + map.put(outputPathForTestsUrl, testsOutputPathRef); } - moduleChunk.setDependentChunks(deps.toArray(new ModuleChunk[deps.size()])); - ContainerUtil.addAll(myCustomCompilers, moduleChunk.getCustomCompilers()); } - Arrays.sort(moduleChunks, new ChunksComparator()); - if (generateSingleFile) { - final File baseDir = BuildProperties.getProjectBaseDir(myProject); - for (ModuleChunk chunk : moduleChunks) { - chunk.setBaseDir(baseDir); + } + } + return map; + } + + @Override + public ModuleChunk[] getModuleChunks() { + return myModuleChunks; + } + + private ModuleChunk[] createModuleChunks(String[] representativeModuleNames) { + final Set mainModuleNames = new HashSet(Arrays.asList(representativeModuleNames)); + final Graph> chunkGraph = ModuleCompilerUtil.toChunkGraph(ModuleManager.getInstance(myProject).moduleGraph()); + final Map, ModuleChunk> map = new HashMap, ModuleChunk>(); + final Map> reverseMap = new HashMap>(); + for (final Chunk chunk : chunkGraph.getNodes()) { + final Set modules = chunk.getNodes(); + final ModuleChunk moduleChunk = new ModuleChunk(modules.toArray(new Module[modules.size()])); + for (final Module module : modules) { + if (mainModuleNames.contains(module.getName())) { + moduleChunk.setMainModule(module); + break; + } + } + map.put(chunk, moduleChunk); + reverseMap.put(moduleChunk, chunk); + } + + final Graph moduleChunkGraph = + GraphGenerator.create(CachingSemiGraph.create(new GraphGenerator.SemiGraph() { + public Collection getNodes() { + return map.values(); + } + + public Iterator getIn(ModuleChunk n) { + final Chunk chunk = reverseMap.get(n); + final Iterator> in = chunkGraph.getIn(chunk); + return new Iterator() { + public boolean hasNext() { + return in.hasNext(); } - } - return moduleChunks; - } - /** - * {@inheritDoc} - */ - public ChunkCustomCompilerExtension[] getCustomCompilers() { - ChunkCustomCompilerExtension[] sorted = myCustomCompilers.toArray(new ChunkCustomCompilerExtension[myCustomCompilers.size()]); - Arrays.sort(sorted, ChunkCustomCompilerExtension.COMPARATOR); - return sorted; - } - - Set getAllJdkUrls() { - if (myJdkUrls != null) { - return myJdkUrls; - } - final Sdk[] projectJdks = ProjectJdkTable.getInstance().getAllJdks(); - myJdkUrls = new HashSet(); - for (Sdk jdk : projectJdks) { - ContainerUtil.addAll(myJdkUrls, jdk.getRootProvider().getUrls(OrderRootType.CLASSES)); - } - return myJdkUrls; - } - - private static class ChunksComparator implements Comparator { - final Map myCachedLevels = new HashMap(); - - public int compare(final ModuleChunk o1, final ModuleChunk o2) { - final int level1 = getChunkLevel(o1); - final int level2 = getChunkLevel(o2); - return (level1 == level2) ? o1.getName().compareToIgnoreCase(o2.getName()) : (level1 - level2); - } - - private int getChunkLevel(ModuleChunk chunk) { - Integer level = myCachedLevels.get(chunk); - if (level == null) { - final ModuleChunk[] chunks = chunk.getDependentChunks(); - if (chunks.length > 0) { - int maxLevel = 0; - for (ModuleChunk dependent : chunks) { - maxLevel = Math.max(maxLevel, getChunkLevel(dependent)); - } - level = 1 + maxLevel; - } - else { - level = 0; - } - myCachedLevels.put(chunk, level); + public ModuleChunk next() { + return map.get(in.next()); } - return level.intValue(); + + public void remove() { + new OperationNotSupportedException(); + } + }; } + })); + final Collection nodes = moduleChunkGraph.getNodes(); + final ModuleChunk[] moduleChunks = nodes.toArray(new ModuleChunk[nodes.size()]); + for (ModuleChunk moduleChunk : moduleChunks) { + final Iterator depsIterator = moduleChunkGraph.getIn(moduleChunk); + List deps = new ArrayList(); + while (depsIterator.hasNext()) { + deps.add(depsIterator.next()); + } + moduleChunk.setDependentChunks(deps.toArray(new ModuleChunk[deps.size()])); + ContainerUtil.addAll(myCustomCompilers, moduleChunk.getCustomCompilers()); } + Arrays.sort(moduleChunks, new ChunksComparator()); + if (generateSingleFile) { + final File baseDir = BuildProperties.getProjectBaseDir(myProject); + for (ModuleChunk chunk : moduleChunks) { + chunk.setBaseDir(baseDir); + } + } + return moduleChunks; + } + + /** + * {@inheritDoc} + */ + public ChunkCustomCompilerExtension[] getCustomCompilers() { + ChunkCustomCompilerExtension[] sorted = myCustomCompilers.toArray(new ChunkCustomCompilerExtension[myCustomCompilers.size()]); + Arrays.sort(sorted, ChunkCustomCompilerExtension.COMPARATOR); + return sorted; + } + + Set getAllJdkUrls() { + if (myJdkUrls != null) { + return myJdkUrls; + } + final Sdk[] projectJdks = ProjectJdkTable.getInstance().getAllJdks(); + myJdkUrls = new HashSet(); + for (Sdk jdk : projectJdks) { + ContainerUtil.addAll(myJdkUrls, jdk.getRootProvider().getUrls(OrderRootType.CLASSES)); + } + return myJdkUrls; + } + + private static class ChunksComparator implements Comparator { + final Map myCachedLevels = new HashMap(); + + public int compare(final ModuleChunk o1, final ModuleChunk o2) { + final int level1 = getChunkLevel(o1); + final int level2 = getChunkLevel(o2); + return (level1 == level2) ? o1.getName().compareToIgnoreCase(o2.getName()) : (level1 - level2); + } + + private int getChunkLevel(ModuleChunk chunk) { + Integer level = myCachedLevels.get(chunk); + if (level == null) { + final ModuleChunk[] chunks = chunk.getDependentChunks(); + if (chunks.length > 0) { + int maxLevel = 0; + for (ModuleChunk dependent : chunks) { + maxLevel = Math.max(maxLevel, getChunkLevel(dependent)); + } + level = 1 + maxLevel; + } + else { + level = 0; + } + myCachedLevels.put(chunk, level); + } + return level.intValue(); + } + } } diff --git a/java/compiler/openapi/src/com/intellij/compiler/ant/BuildProperties.java b/java/compiler/openapi/src/com/intellij/compiler/ant/BuildProperties.java index 0eb86f056305..51ee7d10e320 100644 --- a/java/compiler/openapi/src/com/intellij/compiler/ant/BuildProperties.java +++ b/java/compiler/openapi/src/com/intellij/compiler/ant/BuildProperties.java @@ -72,11 +72,6 @@ public abstract class BuildProperties extends CompositeGenerator { return jdks.toArray(new Sdk[jdks.size()]); } - @NonNls - public static String getPropertyFileName(Project project) { - return getProjectBuildFileName(project) + ".properties"; - } - @NonNls public static String getJdkPathId(@NonNls final String jdkName) { return "jdk.classpath." + convertName(jdkName); diff --git a/java/compiler/openapi/src/com/intellij/compiler/ant/GenerationOptions.java b/java/compiler/openapi/src/com/intellij/compiler/ant/GenerationOptions.java index bd6a0ec9751a..fc286ee7db52 100644 --- a/java/compiler/openapi/src/com/intellij/compiler/ant/GenerationOptions.java +++ b/java/compiler/openapi/src/com/intellij/compiler/ant/GenerationOptions.java @@ -23,7 +23,7 @@ import com.intellij.openapi.module.Module; * @author anna */ public abstract class GenerationOptions { - /** + /** * This option specifies whether mulitfile or single file ant script is created. */ public final boolean generateSingleFile; @@ -146,4 +146,7 @@ public abstract class GenerationOptions { public abstract boolean isIdeaHomeGenerated(); + public abstract String getBuildFileName(); + + public abstract String getPropertiesFileName(); } \ No newline at end of file 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 fe0fcacf503e..0496e5abfeea 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 @@ -374,10 +374,12 @@ public class HighlightUtil { IElementType opSign = TypeConversionUtil.convertEQtoOperation(eqOpSign); if (opSign == null) return null; HighlightInfo errorResult = null; - if (!TypeConversionUtil.isBinaryOperatorApplicable(opSign, assignment.getLExpression(), assignment.getRExpression(), true)) { + final PsiType lType = assignment.getLExpression().getType(); + if (!TypeConversionUtil.isBinaryOperatorApplicable(opSign, assignment.getLExpression(), assignment.getRExpression(), true) || + PsiType.getJavaLangObject(assignment.getManager(), assignment.getResolveScope()).equals(lType)) { String operatorText = operationSign.getText().substring(0, operationSign.getText().length() - 1); String message = JavaErrorMessages.message("binary.operator.not.applicable", operatorText, - formatType(assignment.getLExpression().getType()), + formatType(lType), formatType(assignment.getRExpression().getType())); errorResult = HighlightInfo.createHighlightInfo(HighlightInfoType.ERROR, assignment, message); diff --git a/java/java-impl/src/com/intellij/codeInsight/intention/impl/InvertIfConditionAction.java b/java/java-impl/src/com/intellij/codeInsight/intention/impl/InvertIfConditionAction.java index 9e98454ef5e5..52b60ac4af50 100644 --- a/java/java-impl/src/com/intellij/codeInsight/intention/impl/InvertIfConditionAction.java +++ b/java/java-impl/src/com/intellij/codeInsight/intention/impl/InvertIfConditionAction.java @@ -209,7 +209,7 @@ public class InvertIfConditionAction extends PsiElementBaseIntentionAction { PsiStatement[] statements = ((PsiBlockStatement) thenBranch).getCodeBlock().getStatements(); int len = statements.length; if (len > 0) { - if (statements[len - 1] instanceof PsiReturnStatement) len--; + //if (statements[len - 1] instanceof PsiReturnStatement) len--; if (len > 0) { PsiElement firstElement = statements [0]; while (firstElement.getPrevSibling() instanceof PsiWhiteSpace || firstElement.getPrevSibling() instanceof PsiComment) { diff --git a/java/java-impl/src/com/intellij/lang/java/parser/JavaParserUtil.java b/java/java-impl/src/com/intellij/lang/java/parser/JavaParserUtil.java index 9313500b6149..5f7105e29f22 100644 --- a/java/java-impl/src/com/intellij/lang/java/parser/JavaParserUtil.java +++ b/java/java-impl/src/com/intellij/lang/java/parser/JavaParserUtil.java @@ -334,6 +334,16 @@ public class JavaParserUtil { return myDelegate.lookAhead(steps); } + @Override + public IElementType rawLookup(int steps) { + return myDelegate.rawLookup(steps); + } + + @Override + public int rawTokenTypeStart(int steps) { + return myDelegate.rawTokenTypeStart(steps); + } + @Nullable @NonNls public String getTokenText() { return myDelegate.getTokenText(); diff --git a/java/java-impl/src/com/intellij/psi/NonClasspathClassFinder.java b/java/java-impl/src/com/intellij/psi/NonClasspathClassFinder.java index feb111e02e38..dd60aefb5a3e 100644 --- a/java/java-impl/src/com/intellij/psi/NonClasspathClassFinder.java +++ b/java/java-impl/src/com/intellij/psi/NonClasspathClassFinder.java @@ -31,18 +31,44 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import java.util.*; +import java.util.concurrent.atomic.AtomicLong; /** * @author peter */ public abstract class NonClasspathClassFinder extends PsiElementFinder { private static final Logger LOG = Logger.getInstance("#com.intellij.psi.NonClasspathClassFinder"); + private final AtomicLong myLastStamp = new AtomicLong(); protected final Project myProject; + private volatile List myCache; public NonClasspathClassFinder(Project project) { myProject = project; } + protected List getClassRoots() { + List cache = myCache; + long stamp = PsiManager.getInstance(myProject).getModificationTracker().getModificationCount(); + if (myLastStamp.get() != stamp) { + cache = null; + } + + if (cache != null && !cache.isEmpty()) { + for (VirtualFile file : cache) { + if (!file.isValid()) { + cache = null; + break; + } + } + } + + if (cache == null) { + myCache = cache = calcClassRoots(); + myLastStamp.set(stamp); + } + return cache; + } + @Override public PsiClass findClass(@NotNull String qualifiedName, @NotNull GlobalSearchScope scope) { final List classRoots = getClassRoots(); @@ -71,7 +97,7 @@ public abstract class NonClasspathClassFinder extends PsiElementFinder { return null; } - protected abstract List getClassRoots(); + protected abstract List calcClassRoots(); @NotNull @Override diff --git a/java/java-impl/src/com/intellij/psi/impl/source/codeStyle/ShiftIndentInsideHelper.java b/java/java-impl/src/com/intellij/psi/impl/source/codeStyle/ShiftIndentInsideHelper.java index 6b9ff5fd85eb..ec72035793b3 100644 --- a/java/java-impl/src/com/intellij/psi/impl/source/codeStyle/ShiftIndentInsideHelper.java +++ b/java/java-impl/src/com/intellij/psi/impl/source/codeStyle/ShiftIndentInsideHelper.java @@ -114,7 +114,7 @@ public class ShiftIndentInsideHelper { } else { if (newSpace.length() > 0) { - LeafElement newLeaf = ASTFactory.leaf(TokenType.WHITE_SPACE, newSpace, charTableByTree); + LeafElement newLeaf = ASTFactory.whitespace(newSpace); next.getTreeParent().addChild(newLeaf, next); } text = text.substring(0, offset + 1) + newSpace + text.substring(offset1); diff --git a/java/java-impl/src/com/intellij/refactoring/inline/InlineMethodProcessor.java b/java/java-impl/src/com/intellij/refactoring/inline/InlineMethodProcessor.java index bcde92bdaffe..414ab6c99855 100644 --- a/java/java-impl/src/com/intellij/refactoring/inline/InlineMethodProcessor.java +++ b/java/java-impl/src/com/intellij/refactoring/inline/InlineMethodProcessor.java @@ -291,10 +291,13 @@ public class InlineMethodProcessor extends BaseRefactoringProcessor { } else { List refExprList = new ArrayList(); + final List imports2Delete = new ArrayList(); for (final UsageInfo usage : usages) { final PsiElement element = usage.getElement(); if (element instanceof PsiReferenceExpression) { refExprList.add((PsiReferenceExpression)element); + } else if (element instanceof PsiImportStaticReferenceElement) { + imports2Delete.add(PsiTreeUtil.getParentOfType(element, PsiImportStaticStatement.class)); } } PsiReferenceExpression[] refs = refExprList.toArray(new PsiReferenceExpression[refExprList.size()]); @@ -302,6 +305,11 @@ public class InlineMethodProcessor extends BaseRefactoringProcessor { for (PsiReferenceExpression ref : refs) { inlineMethodCall(ref); } + for (PsiElement psiElement : imports2Delete) { + if (psiElement != null && psiElement.isValid()) { + psiElement.delete(); + } + } myMethod.delete(); } } diff --git a/java/java-impl/src/com/intellij/refactoring/introduceField/BaseExpressionToFieldHandler.java b/java/java-impl/src/com/intellij/refactoring/introduceField/BaseExpressionToFieldHandler.java index 74c3bba54825..a443a6e461b4 100644 --- a/java/java-impl/src/com/intellij/refactoring/introduceField/BaseExpressionToFieldHandler.java +++ b/java/java-impl/src/com/intellij/refactoring/introduceField/BaseExpressionToFieldHandler.java @@ -39,6 +39,7 @@ import com.intellij.openapi.editor.colors.EditorColorsManager; import com.intellij.openapi.editor.markup.RangeHighlighter; import com.intellij.openapi.editor.markup.TextAttributes; import com.intellij.openapi.project.Project; +import com.intellij.openapi.util.Comparing; import com.intellij.openapi.util.Pass; import com.intellij.openapi.util.text.StringUtil; import com.intellij.openapi.wm.WindowManager; @@ -134,7 +135,8 @@ public abstract class BaseExpressionToFieldHandler extends IntroduceHandlerBase } PsiElement tempAnchorElement = RefactoringUtil.getParentExpressionAnchorElement(selectedExpr); - if (IntroduceVariableBase.checkAnchorBeforeThisOrSuper(project, editor, tempAnchorElement, getRefactoringName(), getHelpID())) return false; + if (!Comparing.strEqual(IntroduceConstantHandler.REFACTORING_NAME, getRefactoringName()) && + IntroduceVariableBase.checkAnchorBeforeThisOrSuper(project, editor, tempAnchorElement, getRefactoringName(), getHelpID())) return false; final Settings settings = showRefactoringDialog(project, editor, myParentClass, selectedExpr, tempType, diff --git a/java/java-impl/src/com/intellij/refactoring/introduceParameter/IntroduceParameterDialog.java b/java/java-impl/src/com/intellij/refactoring/introduceParameter/IntroduceParameterDialog.java index 0c1686fa719d..ea50ab941de6 100644 --- a/java/java-impl/src/com/intellij/refactoring/introduceParameter/IntroduceParameterDialog.java +++ b/java/java-impl/src/com/intellij/refactoring/introduceParameter/IntroduceParameterDialog.java @@ -300,11 +300,13 @@ public class IntroduceParameterDialog extends RefactoringDialog { myCbGenerateDelegate = new NonFocusableCheckBox(RefactoringBundle.message("delegation.panel.delegate.via.overloading.method")); panel.add(myCbGenerateDelegate, gbConstraints); + final JCheckBox[] removeParamsCb = new JCheckBox[myParametersToRemove.length]; for (int i = 0; i < myParametersToRemove.length; i++) { PsiParameter parameter = myParametersToRemove[i]; if (parameter == null) continue; final NonFocusableCheckBox cb = new NonFocusableCheckBox(RefactoringBundle.message("remove.parameter.0.no.longer.used", parameter.getName())); + removeParamsCb[i] = cb; cb.setSelected(true); gbConstraints.gridy++; panel.add(cb, gbConstraints); @@ -317,12 +319,13 @@ public class IntroduceParameterDialog extends RefactoringDialog { myParametersToRemoveChecked[i] = true; } - updateControls(); + updateControls(removeParamsCb); if (myCbReplaceAllOccurences != null) { myCbReplaceAllOccurences.addItemListener( new ItemListener() { public void itemStateChanged(ItemEvent e) { - updateControls(); + updateControls(removeParamsCb); + } } ); @@ -330,8 +333,13 @@ public class IntroduceParameterDialog extends RefactoringDialog { return panel; } - private void updateControls() { - if(myCbReplaceAllOccurences != null) { + private void updateControls(JCheckBox[] removeParamsCb) { + if (myCbReplaceAllOccurences != null) { + for (JCheckBox box : removeParamsCb) { + if (box != null) { + box.setEnabled(myCbReplaceAllOccurences.isSelected()); + } + } myTypeSelectorManager.setAllOccurences(myCbReplaceAllOccurences.isSelected()); if(myCbReplaceAllOccurences.isSelected()) { if (myCbDeleteLocalVariable != null) { 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 a6af24a45a59..9113660522d7 100644 --- a/java/java-impl/src/com/intellij/refactoring/introduceParameter/IntroduceParameterHandler.java +++ b/java/java-impl/src/com/intellij/refactoring/introduceParameter/IntroduceParameterHandler.java @@ -141,12 +141,6 @@ public class IntroduceParameterHandler extends IntroduceHandlerBase implements R if (methodToSearchFor == null) return false; if (!CommonRefactoringUtil.checkReadOnlyStatus(project, methodToSearchFor)) return false; - PsiExpression expressionToRemoveParamFrom = expr; - if (expr == null) { - expressionToRemoveParamFrom = localVar.getInitializer(); - } - TIntArrayList parametersToRemove = expressionToRemoveParamFrom == null ? new TIntArrayList() : Util.findParametersToRemove(method, expressionToRemoveParamFrom); - PsiExpression[] occurences; if (expr != null) { occurences = new ExpressionOccurenceManager(expr, method, null).findExpressionOccurrences(); @@ -154,6 +148,11 @@ public class IntroduceParameterHandler extends IntroduceHandlerBase implements R else { // local variable occurences = CodeInsightUtil.findReferenceExpressions(method, localVar); } + PsiExpression expressionToRemoveParamFrom = expr; + if (expr == null) { + expressionToRemoveParamFrom = localVar.getInitializer(); + } + TIntArrayList parametersToRemove = expressionToRemoveParamFrom == null ? new TIntArrayList() : Util.findParametersToRemove(method, expressionToRemoveParamFrom, occurences); if (editor != null) { RefactoringUtil.highlightAllOccurences(myProject, occurences, editor); } diff --git a/java/java-impl/src/com/intellij/refactoring/introduceParameter/Util.java b/java/java-impl/src/com/intellij/refactoring/introduceParameter/Util.java index 5d56382918f0..fb94ecbf37b5 100644 --- a/java/java-impl/src/com/intellij/refactoring/introduceParameter/Util.java +++ b/java/java-impl/src/com/intellij/refactoring/introduceParameter/Util.java @@ -37,6 +37,7 @@ import gnu.trove.TIntArrayList; import gnu.trove.TIntHashSet; import gnu.trove.TIntIterator; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import java.util.List; @@ -102,7 +103,9 @@ public class Util { // returns parameters that are used solely in specified expression @NotNull - public static TIntArrayList findParametersToRemove(@NotNull PsiMethod method, @NotNull final PsiExpression expr) { + public static TIntArrayList findParametersToRemove(@NotNull PsiMethod method, + @NotNull final PsiExpression expr, + @Nullable final PsiExpression[] occurences) { final PsiParameter[] parameters = method.getParameterList().getParameters(); if (parameters.length == 0) return new TIntArrayList(); @@ -133,7 +136,18 @@ public class Util { if (!ReferencesSearch.search(parameter, parameter.getResolveScope(), false).forEach(new Processor() { public boolean process(final PsiReference reference) { PsiElement element = reference.getElement(); - boolean stillCanBeRemoved = element != null && (PsiTreeUtil.isAncestor(expr, element, false) || PsiUtil.isInsideJavadocComment(element)); + boolean stillCanBeRemoved = false; + if (element != null) { + stillCanBeRemoved = PsiTreeUtil.isAncestor(expr, element, false) || PsiUtil.isInsideJavadocComment(element); + if (!stillCanBeRemoved && occurences != null) { + for (PsiExpression occurence : occurences) { + if (PsiTreeUtil.isAncestor(occurence, element, false)) { + stillCanBeRemoved = true; + break; + } + } + } + } if (!stillCanBeRemoved) { iterator.remove(); return false; diff --git a/java/java-impl/src/com/intellij/refactoring/rename/RenameAliasingPomTargetProcessor.java b/java/java-impl/src/com/intellij/refactoring/rename/RenameAliasingPomTargetProcessor.java index b9ec190bb82b..907d1aa78e9c 100644 --- a/java/java-impl/src/com/intellij/refactoring/rename/RenameAliasingPomTargetProcessor.java +++ b/java/java-impl/src/com/intellij/refactoring/rename/RenameAliasingPomTargetProcessor.java @@ -22,14 +22,14 @@ import com.intellij.pom.references.PomService; import com.intellij.psi.PsiElement; import com.intellij.psi.targets.AliasingPsiTarget; import com.intellij.psi.targets.AliasingPsiTargetMapper; -import org.jetbrains.annotations.Nullable; +import org.jetbrains.annotations.NotNull; import java.util.Map; public class RenameAliasingPomTargetProcessor extends RenamePsiElementProcessor { @Override - public boolean canProcessElement(@Nullable PsiElement element) { + public boolean canProcessElement(@NotNull PsiElement element) { return element instanceof PomTarget || element instanceof PomTargetPsiElement; } diff --git a/java/java-impl/src/com/intellij/refactoring/rename/RenameJavaClassProcessor.java b/java/java-impl/src/com/intellij/refactoring/rename/RenameJavaClassProcessor.java index 6a9330284ab3..55f332d43a6e 100644 --- a/java/java-impl/src/com/intellij/refactoring/rename/RenameJavaClassProcessor.java +++ b/java/java-impl/src/com/intellij/refactoring/rename/RenameJavaClassProcessor.java @@ -50,7 +50,7 @@ import java.util.regex.Pattern; public class RenameJavaClassProcessor extends RenamePsiElementProcessor { private static final Logger LOG = Logger.getInstance("#com.intellij.refactoring.rename.RenameJavaClassProcessor"); - public boolean canProcessElement(final PsiElement element) { + public boolean canProcessElement(@NotNull final PsiElement element) { return element instanceof PsiClass; } diff --git a/java/java-impl/src/com/intellij/refactoring/rename/RenameJavaMethodProcessor.java b/java/java-impl/src/com/intellij/refactoring/rename/RenameJavaMethodProcessor.java index 4446e42826c1..843f66603b31 100644 --- a/java/java-impl/src/com/intellij/refactoring/rename/RenameJavaMethodProcessor.java +++ b/java/java-impl/src/com/intellij/refactoring/rename/RenameJavaMethodProcessor.java @@ -48,7 +48,7 @@ import java.util.*; public class RenameJavaMethodProcessor extends RenameJavaMemberProcessor { private static final Logger LOG = Logger.getInstance("#com.intellij.refactoring.rename.RenameJavaMethodProcessor"); - public boolean canProcessElement(final PsiElement element) { + public boolean canProcessElement(@NotNull final PsiElement element) { return element instanceof PsiMethod; } diff --git a/java/java-impl/src/com/intellij/refactoring/rename/RenameJavaVariableProcessor.java b/java/java-impl/src/com/intellij/refactoring/rename/RenameJavaVariableProcessor.java index 36e7f0acedba..dca5382895f4 100644 --- a/java/java-impl/src/com/intellij/refactoring/rename/RenameJavaVariableProcessor.java +++ b/java/java-impl/src/com/intellij/refactoring/rename/RenameJavaVariableProcessor.java @@ -40,6 +40,7 @@ import com.intellij.util.IncorrectOperationException; import com.intellij.util.Processor; import com.intellij.util.containers.MultiMap; import org.jetbrains.annotations.NonNls; +import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import java.util.ArrayList; @@ -50,7 +51,7 @@ import java.util.Map; public class RenameJavaVariableProcessor extends RenameJavaMemberProcessor { private static final Logger LOG = Logger.getInstance("#com.intellij.refactoring.rename.RenameJavaVariableProcessor"); - public boolean canProcessElement(final PsiElement element) { + public boolean canProcessElement(@NotNull final PsiElement element) { return element instanceof PsiVariable; } diff --git a/java/java-impl/src/com/intellij/refactoring/rename/RenamePsiDirectoryProcessor.java b/java/java-impl/src/com/intellij/refactoring/rename/RenamePsiDirectoryProcessor.java index d6cd0d60b356..da8525c43470 100644 --- a/java/java-impl/src/com/intellij/refactoring/rename/RenamePsiDirectoryProcessor.java +++ b/java/java-impl/src/com/intellij/refactoring/rename/RenamePsiDirectoryProcessor.java @@ -33,7 +33,7 @@ import java.util.Collection; * @author yole */ public class RenamePsiDirectoryProcessor extends RenamePsiElementProcessor { - public boolean canProcessElement(final PsiElement element) { + public boolean canProcessElement(@NotNull final PsiElement element) { return element instanceof PsiDirectory; } diff --git a/java/java-impl/src/com/intellij/refactoring/rename/RenamePsiPackageProcessor.java b/java/java-impl/src/com/intellij/refactoring/rename/RenamePsiPackageProcessor.java index 339a1752962f..c7f430869acd 100644 --- a/java/java-impl/src/com/intellij/refactoring/rename/RenamePsiPackageProcessor.java +++ b/java/java-impl/src/com/intellij/refactoring/rename/RenamePsiPackageProcessor.java @@ -26,6 +26,7 @@ import com.intellij.usageView.UsageInfo; import com.intellij.util.IncorrectOperationException; import com.intellij.util.containers.MultiMap; import org.jetbrains.annotations.NonNls; +import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import java.util.Map; @@ -36,7 +37,7 @@ import java.util.Map; public class RenamePsiPackageProcessor extends RenamePsiElementProcessor { private final Logger LOG = Logger.getInstance("#com.intellij.refactoring.rename.RenamePsiPackageProcessor"); - public boolean canProcessElement(final PsiElement element) { + public boolean canProcessElement(@NotNull final PsiElement element) { return element instanceof PsiPackage; } diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/OperatorApplicability.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/OperatorApplicability.java index 8b577ba54a7d..bcb1caa5ca6a 100644 --- a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/OperatorApplicability.java +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/OperatorApplicability.java @@ -44,7 +44,7 @@ public class a { ia[~i | (i+=(!b?2:i))] -= i + 3.3; // Object += String - o += o + "string"; + o += o + "string"; return 0; } diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting/WildcardCastConversion.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting/WildcardCastConversion.java index 2d29970dbc02..389db6c27f05 100644 --- a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting/WildcardCastConversion.java +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting/WildcardCastConversion.java @@ -475,6 +475,27 @@ public class Test { } } } + + //IDEA-63447 + void testUnboundWildcardWithArrayTypes() { + class IUWWAT{ + private void method1(T[][] matrix) { + final Class type = (Class) matrix.getClass().getComponentType(); + } + + private void method2(T[][] matrix) { + final Class type = (Class) matrix.getClass().getComponentType(); + } + + private void method3(T[][] matrix) { + final Class type = (Class) matrix.getClass().getComponentType(); + } + + private void method4(T[][] matrix) { + final Class type = (Class) matrix.getClass().getComponentType(); + } + } + } } class W {} diff --git a/java/java-tests/testData/codeInsight/invertIfCondition/afterDoNotRemoveReturn.java b/java/java-tests/testData/codeInsight/invertIfCondition/afterDoNotRemoveReturn.java new file mode 100644 index 000000000000..ee944540c9d3 --- /dev/null +++ b/java/java-tests/testData/codeInsight/invertIfCondition/afterDoNotRemoveReturn.java @@ -0,0 +1,10 @@ +// "Invert If Condition" "true" +class Test { + public static int create() { + if (true) { + return; + } + return "s"; + + } +} \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/invertIfCondition/beforeDoNotRemoveReturn.java b/java/java-tests/testData/codeInsight/invertIfCondition/beforeDoNotRemoveReturn.java new file mode 100644 index 000000000000..b847d4825c3b --- /dev/null +++ b/java/java-tests/testData/codeInsight/invertIfCondition/beforeDoNotRemoveReturn.java @@ -0,0 +1,9 @@ +// "Invert If Condition" "true" +class Test { + public static int create() { + if (!true) { + return "s"; + } + + } +} \ No newline at end of file diff --git a/java/java-tests/testData/refactoring/inlineMethod/multifile/removeStaticImports/after/Bar.java b/java/java-tests/testData/refactoring/inlineMethod/multifile/removeStaticImports/after/Bar.java new file mode 100644 index 000000000000..2f1dfde98c09 --- /dev/null +++ b/java/java-tests/testData/refactoring/inlineMethod/multifile/removeStaticImports/after/Bar.java @@ -0,0 +1,4 @@ +public class Bar { + void bar() { + } +} \ No newline at end of file diff --git a/java/java-tests/testData/refactoring/inlineMethod/multifile/removeStaticImports/after/Foo.java b/java/java-tests/testData/refactoring/inlineMethod/multifile/removeStaticImports/after/Foo.java new file mode 100644 index 000000000000..0a2b05268bb6 --- /dev/null +++ b/java/java-tests/testData/refactoring/inlineMethod/multifile/removeStaticImports/after/Foo.java @@ -0,0 +1,2 @@ +public class Foo { +} \ No newline at end of file diff --git a/java/java-tests/testData/refactoring/inlineMethod/multifile/removeStaticImports/before/Bar.java b/java/java-tests/testData/refactoring/inlineMethod/multifile/removeStaticImports/before/Bar.java new file mode 100644 index 000000000000..0d111602e175 --- /dev/null +++ b/java/java-tests/testData/refactoring/inlineMethod/multifile/removeStaticImports/before/Bar.java @@ -0,0 +1,6 @@ +import static Foo.foo; +public class Bar { + void bar() { + foo(); + } +} \ No newline at end of file diff --git a/java/java-tests/testData/refactoring/inlineMethod/multifile/removeStaticImports/before/Foo.java b/java/java-tests/testData/refactoring/inlineMethod/multifile/removeStaticImports/before/Foo.java new file mode 100644 index 000000000000..38f408a46ec2 --- /dev/null +++ b/java/java-tests/testData/refactoring/inlineMethod/multifile/removeStaticImports/before/Foo.java @@ -0,0 +1,3 @@ +public class Foo { + public static void foo(){} +} \ No newline at end of file diff --git a/java/java-tests/testData/refactoring/introduceConstant/IntroduceConstantFromThisCall.java b/java/java-tests/testData/refactoring/introduceConstant/IntroduceConstantFromThisCall.java new file mode 100644 index 000000000000..4ffcf064fc46 --- /dev/null +++ b/java/java-tests/testData/refactoring/introduceConstant/IntroduceConstantFromThisCall.java @@ -0,0 +1,8 @@ +class Test { + public Test() { + this(10); + } + + public Test(final int i) { + } +} \ No newline at end of file diff --git a/java/java-tests/testData/refactoring/introduceConstant/IntroduceConstantFromThisCall_after.java b/java/java-tests/testData/refactoring/introduceConstant/IntroduceConstantFromThisCall_after.java new file mode 100644 index 000000000000..25ad079525ce --- /dev/null +++ b/java/java-tests/testData/refactoring/introduceConstant/IntroduceConstantFromThisCall_after.java @@ -0,0 +1,10 @@ +class Test { + public static final int xxx = 10; + + public Test() { + this(xxx); + } + + public Test(final int i) { + } +} \ No newline at end of file diff --git a/java/java-tests/testData/refactoring/introduceParameter/afterReplaceAllAndDeleteUnused.java b/java/java-tests/testData/refactoring/introduceParameter/afterReplaceAllAndDeleteUnused.java new file mode 100644 index 000000000000..8f99f871ea4c --- /dev/null +++ b/java/java-tests/testData/refactoring/introduceParameter/afterReplaceAllAndDeleteUnused.java @@ -0,0 +1,11 @@ +public class Parameters { + public void subject(final int anObject) { + System.out.println(anObject); + System.out.println(anObject); + } + + public void context() { + subject(1 +1); + subject(2 +1); + } +} \ No newline at end of file diff --git a/java/java-tests/testData/refactoring/introduceParameter/beforeReplaceAllAndDeleteUnused.java b/java/java-tests/testData/refactoring/introduceParameter/beforeReplaceAllAndDeleteUnused.java new file mode 100644 index 000000000000..820f5e59bcdc --- /dev/null +++ b/java/java-tests/testData/refactoring/introduceParameter/beforeReplaceAllAndDeleteUnused.java @@ -0,0 +1,11 @@ +public class Parameters { + public void subject(int p) { + System.out.println(p+1); + System.out.println(p+1); + } + + public void context() { + subject(1); + subject(2); + } +} \ No newline at end of file diff --git a/java/java-tests/testSrc/com/intellij/refactoring/IntroduceConstantTest.java b/java/java-tests/testSrc/com/intellij/refactoring/IntroduceConstantTest.java index 4f6776101396..bab6d71717ea 100644 --- a/java/java-tests/testSrc/com/intellij/refactoring/IntroduceConstantTest.java +++ b/java/java-tests/testSrc/com/intellij/refactoring/IntroduceConstantTest.java @@ -73,6 +73,12 @@ public class IntroduceConstantTest extends LightCodeInsightTestCase { checkResultByFile(BASE_PATH + getTestName(false) + "_after.java"); } + public void testIntroduceConstantFromThisCall() throws Exception { + configureByFile(BASE_PATH + getTestName(false) + ".java"); + new MockIntroduceConstantHandler(null).invoke(getProject(), getEditor(), getFile(), null); + checkResultByFile(BASE_PATH + getTestName(false) + "_after.java"); + } + public void testEscalateVisibility() throws Exception { configureByFile(BASE_PATH + getTestName(false) + ".java"); final PsiClass[] classes = ((PsiJavaFile)getFile()).getClasses(); diff --git a/java/java-tests/testSrc/com/intellij/refactoring/IntroduceParameterTest.java b/java/java-tests/testSrc/com/intellij/refactoring/IntroduceParameterTest.java index db8f8863a438..cba854352cc2 100644 --- a/java/java-tests/testSrc/com/intellij/refactoring/IntroduceParameterTest.java +++ b/java/java-tests/testSrc/com/intellij/refactoring/IntroduceParameterTest.java @@ -21,6 +21,7 @@ import com.intellij.psi.util.PsiTreeUtil; import com.intellij.refactoring.introduceParameter.IntroduceParameterHandler; import com.intellij.refactoring.introduceParameter.IntroduceParameterProcessor; import com.intellij.refactoring.introduceParameter.Util; +import com.intellij.refactoring.util.occurences.ExpressionOccurenceManager; import com.intellij.testFramework.LightCodeInsightTestCase; import com.intellij.testFramework.TestDataPath; import gnu.trove.TIntArrayList; @@ -253,6 +254,10 @@ public class IntroduceParameterTest extends LightCodeInsightTestCase { doTest(IntroduceParameterRefactoring.REPLACE_FIELDS_WITH_GETTERS_ALL, true, true, true, true); } + public void testReplaceAllAndDeleteUnused() throws Exception { + doTest(IntroduceParameterRefactoring.REPLACE_FIELDS_WITH_GETTERS_ALL, true, false, true, false); + } + private void doTestThroughHandler() throws Exception { configureByFile("/refactoring/introduceParameter/before" + getTestName(false) + ".java"); new IntroduceParameterHandler().invoke(getProject(), myEditor, myFile, new DataContext() { @@ -296,8 +301,17 @@ public class IntroduceParameterTest extends LightCodeInsightTestCase { else { methodToSearchFor = method; } - PsiExpression initializer = expr == null ? localVariable.getInitializer() : expr; - TIntArrayList parametersToRemove = removeUnusedParameters ? Util.findParametersToRemove(method, initializer) : new TIntArrayList(); + PsiExpression[] occurences = null; + PsiExpression initializer; + if (expr == null) { + initializer = localVariable.getInitializer(); + occurences = CodeInsightUtil.findReferenceExpressions(method, localVariable); + } + else { + initializer = expr; + occurences = new ExpressionOccurenceManager(expr, method, null).findExpressionOccurrences(); + } + TIntArrayList parametersToRemove = removeUnusedParameters ? Util.findParametersToRemove(method, initializer, occurences) : new TIntArrayList(); new IntroduceParameterProcessor( getProject(), method, methodToSearchFor, initializer, expr, localVariable, true, parameterName, replaceAllOccurences, replaceFieldsWithGetters, @@ -325,7 +339,7 @@ public class IntroduceParameterTest extends LightCodeInsightTestCase { assertNotNull(methodToSearchFor); final PsiLocalVariable localVariable = (PsiLocalVariable)element; final PsiExpression parameterInitializer = localVariable.getInitializer(); - TIntArrayList parametersToRemove = removeUnusedParameters ? Util.findParametersToRemove(method, parameterInitializer) : new TIntArrayList(); + TIntArrayList parametersToRemove = removeUnusedParameters ? Util.findParametersToRemove(method, parameterInitializer, null) : new TIntArrayList(); new IntroduceParameterProcessor( getProject(), method, methodToSearchFor, diff --git a/java/java-tests/testSrc/com/intellij/refactoring/inline/InlineMethodMultifileTest.java b/java/java-tests/testSrc/com/intellij/refactoring/inline/InlineMethodMultifileTest.java new file mode 100644 index 000000000000..e157e0756a9a --- /dev/null +++ b/java/java-tests/testSrc/com/intellij/refactoring/inline/InlineMethodMultifileTest.java @@ -0,0 +1,67 @@ +/* + * Copyright 2000-2010 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.refactoring.inline; + +import com.intellij.JavaTestUtil; +import com.intellij.codeInsight.CodeInsightTestCase; +import com.intellij.openapi.projectRoots.impl.JavaSdkImpl; +import com.intellij.openapi.vfs.LocalFileSystem; +import com.intellij.openapi.vfs.VirtualFile; +import com.intellij.psi.PsiClass; +import com.intellij.psi.PsiElement; +import com.intellij.psi.PsiMethod; +import com.intellij.psi.impl.source.PostprocessReformattingAspect; +import com.intellij.psi.search.ProjectScope; +import com.intellij.refactoring.MockInlineMethodOptions; +import com.intellij.refactoring.util.InlineUtil; +import com.intellij.testFramework.IdeaTestUtil; +import com.intellij.testFramework.PsiTestUtil; + +import java.io.File; + + +public class InlineMethodMultifileTest extends CodeInsightTestCase { + + private String getRoot() { + return JavaTestUtil.getJavaTestDataPath() + "/refactoring/inlineMethod/multifile/" + getTestName(true); + } + + public void testRemoveStaticImports() throws Exception { + doTest("Foo", "foo"); + } + + private void doTest(String className, String methodName) throws Exception { + String rootBefore = getRoot() + "/before"; + PsiTestUtil.removeAllRoots(myModule, JavaSdkImpl.getMockJdk17()); + final VirtualFile rootDir = PsiTestUtil.createTestProjectStructure(myProject, myModule, rootBefore, myFilesToDelete); + PsiClass aClass = myJavaFacade.findClass(className, ProjectScope.getAllScope(myProject)); + assertTrue(aClass != null); + PsiElement element = aClass.findMethodsByName(methodName, false)[0]; + assertTrue(element instanceof PsiMethod); + PsiMethod method = (PsiMethod)element; + final boolean condition = InlineMethodProcessor.checkBadReturns(method) && !InlineUtil.allUsagesAreTailCalls(method); + assertFalse("Bad returns found", condition); + + InlineOptions options = new MockInlineMethodOptions(); + final InlineMethodProcessor processor = new InlineMethodProcessor(getProject(), method, null, myEditor, options.isInlineThisOnly()); + processor.run(); + + String rootAfter = getRoot() + "/after"; + VirtualFile rootDir2 = LocalFileSystem.getInstance().findFileByPath(rootAfter.replace(File.separatorChar, '/')); + myProject.getComponent(PostprocessReformattingAspect.class).doPostponedFormatting(); + IdeaTestUtil.assertDirectoriesEqual(rootDir2, rootDir, IdeaTestUtil.CVS_FILE_FILTER); + } +} diff --git a/java/openapi/src/com/intellij/psi/util/TypesDistinctProver.java b/java/openapi/src/com/intellij/psi/util/TypesDistinctProver.java index 37f7ab9e2e8a..8484ef5f0c26 100644 --- a/java/openapi/src/com/intellij/psi/util/TypesDistinctProver.java +++ b/java/openapi/src/com/intellij/psi/util/TypesDistinctProver.java @@ -196,6 +196,9 @@ public class TypesDistinctProver { else if (bound instanceof PsiClassType) { return !possibleClasses.contains(((PsiClassType)bound).resolve()); } + else if (bound instanceof PsiWildcardType && !((PsiWildcardType)bound).isBounded()) { + return false; + } return true; } } diff --git a/java/openapi/src/com/intellij/ui/classFilter/ClassFilterEditorAddDialog.java b/java/openapi/src/com/intellij/ui/classFilter/ClassFilterEditorAddDialog.java index 79695e91aa1c..2ee5f610d92a 100644 --- a/java/openapi/src/com/intellij/ui/classFilter/ClassFilterEditorAddDialog.java +++ b/java/openapi/src/com/intellij/ui/classFilter/ClassFilterEditorAddDialog.java @@ -48,23 +48,14 @@ class ClassFilterEditorAddDialog extends DialogWrapper { } protected JComponent createCenterPanel() { - Box box = Box.createVerticalBox(); - - JPanel _panel = new JPanel(new BorderLayout()); - myClassName = new TextFieldWithBrowseButton(); - _panel.add(new JLabel(UIBundle.message("label.class.filter.editor.add.dialog.filter.pattern")), BorderLayout.NORTH); - _panel.add(myClassName, BorderLayout.CENTER); - box.add(_panel); - - box.add(Box.createVerticalBox()); - - - JPanel panel = new JPanel(new BorderLayout()); - panel.setPreferredSize(new Dimension(310, -1)); - - JLabel iconLabel = new JLabel(Messages.getQuestionIcon()); - panel.add(iconLabel, BorderLayout.WEST); - panel.add(box, BorderLayout.CENTER); + final JPanel panel = new JPanel(new GridBagLayout()); + final JLabel header = new JLabel(UIBundle.message("label.class.filter.editor.add.dialog.filter.pattern")); + myClassName = new TextFieldWithBrowseButton(new JTextField(35)); + final JLabel iconLabel = new JLabel(Messages.getQuestionIcon()); + + panel.add(header, new GridBagConstraints(1, 0, 1, 1, 1.0, 0.0, GridBagConstraints.NORTHWEST, GridBagConstraints.HORIZONTAL, new Insets(5, 10, 0, 0), 0, 0)); + panel.add(myClassName, new GridBagConstraints(1, 1, 1, 1, 1.0, 1.0, GridBagConstraints.NORTHWEST, GridBagConstraints.HORIZONTAL, new Insets(5, 10, 0, 0), 0, 0)); + panel.add(iconLabel, new GridBagConstraints(0, 0, 1, 2, 0.0, 1.0, GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, new Insets(15, 0, 0, 0), 0, 0)); myClassName.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { diff --git a/java/testFramework/src/com/intellij/codeInsight/daemon/DaemonAnalyzerTestCase.java b/java/testFramework/src/com/intellij/codeInsight/daemon/DaemonAnalyzerTestCase.java index e60ee0a4902a..8dc526ea335f 100644 --- a/java/testFramework/src/com/intellij/codeInsight/daemon/DaemonAnalyzerTestCase.java +++ b/java/testFramework/src/com/intellij/codeInsight/daemon/DaemonAnalyzerTestCase.java @@ -48,6 +48,7 @@ import com.intellij.openapi.editor.Document; import com.intellij.openapi.editor.Editor; import com.intellij.openapi.extensions.Extensions; import com.intellij.openapi.module.Module; +import com.intellij.openapi.project.DumbService; import com.intellij.openapi.roots.ModuleRootManager; import com.intellij.openapi.startup.StartupManager; import com.intellij.openapi.util.Disposer; @@ -288,7 +289,9 @@ public abstract class DaemonAnalyzerTestCase extends CodeInsightTestCase { //to initialize caches - myPsiManager.getCacheManager().getFilesWithWord("XXX", UsageSearchContext.IN_COMMENTS, GlobalSearchScope.allScope(myProject), true); + if (!DumbService.isDumb(getProject())) { + myPsiManager.getCacheManager().getFilesWithWord("XXX", UsageSearchContext.IN_COMMENTS, GlobalSearchScope.allScope(myProject), true); + } final JavaPsiFacadeEx facade = getJavaFacade(); if (facade != null) { facade.setAssertOnFileLoadingFilter(myFileTreeAccessFilter); // check repository work diff --git a/platform/lang-api/src/com/intellij/facet/frameworks/LibrariesDownloadAssistant.java b/platform/lang-api/src/com/intellij/facet/frameworks/LibrariesDownloadAssistant.java index 61340ad030c0..5d48f92fae26 100644 --- a/platform/lang-api/src/com/intellij/facet/frameworks/LibrariesDownloadAssistant.java +++ b/platform/lang-api/src/com/intellij/facet/frameworks/LibrariesDownloadAssistant.java @@ -28,7 +28,7 @@ public class LibrariesDownloadAssistant { private LibrariesDownloadAssistant() { } - @Nullable + @NotNull public static Artifact[] getVersions(@NotNull String groupId, @NotNull URL... localUrls) { final Artifact[] versions = getDownloadServiceVersions(groupId); return versions == null ? getVersions(localUrls) : versions; diff --git a/platform/lang-api/src/com/intellij/lang/PsiBuilder.java b/platform/lang-api/src/com/intellij/lang/PsiBuilder.java index 05d53dfe4d96..9e3b685c2444 100644 --- a/platform/lang-api/src/com/intellij/lang/PsiBuilder.java +++ b/platform/lang-api/src/com/intellij/lang/PsiBuilder.java @@ -87,6 +87,22 @@ public interface PsiBuilder extends UserDataHolder, UserDataHolderUnprotected { @Nullable IElementType lookAhead(int steps); + /** + * See what token type is in steps ahead / behind + * @param steps 0 is current token (i.e. the same {@link PsiBuilder#getTokenType()} returns) + * @return type element ahead or behind, including whitespace / comment tokens + */ + @Nullable + IElementType rawLookup(int steps); + + /** + * See what token type is in steps ahead / behind current position + * @param steps 0 is current token (i.e. the same {@link PsiBuilder#getTokenType()} returns) + * @return offset type element ahead or behind, including whitespace / comment tokens, -1 if first token, + * getOriginalText().getLength() at end + */ + int rawTokenTypeStart(int steps); + /** * Returns the text of the current token from the lexer. * diff --git a/platform/lang-api/src/com/intellij/openapi/roots/ui/configuration/libraryEditor/DocumentationOrderRootTypeUIFactory.java b/platform/lang-api/src/com/intellij/openapi/roots/ui/configuration/libraryEditor/DocumentationOrderRootTypeUIFactory.java new file mode 100644 index 000000000000..8fb371be99b9 --- /dev/null +++ b/platform/lang-api/src/com/intellij/openapi/roots/ui/configuration/libraryEditor/DocumentationOrderRootTypeUIFactory.java @@ -0,0 +1,49 @@ +/* + * Copyright 2000-2010 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.roots.ui.configuration.libraryEditor; + +import com.intellij.openapi.project.ProjectBundle; +import com.intellij.openapi.projectRoots.Sdk; +import com.intellij.openapi.projectRoots.ui.PathEditor; +import com.intellij.openapi.roots.ui.OrderRootTypeUIFactory; +import com.intellij.openapi.util.IconLoader; +import org.jetbrains.annotations.Nullable; + +import javax.swing.*; + +/** + * @author Rustam Vishnyakov + */ +public class DocumentationOrderRootTypeUIFactory implements OrderRootTypeUIFactory { + + private static final Icon ICON = IconLoader.getIcon("/nodes/javaDocFolder.png"); + + @Override + @Nullable + public PathEditor createPathEditor(Sdk sdk) { + return null; + } + + @Override + public Icon getIcon() { + return ICON; + } + + @Override + public String getNodeText() { + return ProjectBundle.message("library.docs.node"); + } +} diff --git a/platform/lang-api/src/com/intellij/psi/templateLanguages/TemplateDataHighlighterWrapper.java b/platform/lang-api/src/com/intellij/psi/templateLanguages/TemplateDataHighlighterWrapper.java new file mode 100644 index 000000000000..f14ed9447dfa --- /dev/null +++ b/platform/lang-api/src/com/intellij/psi/templateLanguages/TemplateDataHighlighterWrapper.java @@ -0,0 +1,34 @@ +package com.intellij.psi.templateLanguages; + +import com.intellij.lexer.Lexer; +import com.intellij.openapi.editor.colors.TextAttributesKey; +import com.intellij.openapi.fileTypes.SyntaxHighlighter; +import com.intellij.psi.tree.IElementType; +import org.jetbrains.annotations.NotNull; + +import static com.intellij.psi.TokenType.BAD_CHARACTER; + +/** +* @author peter +*/ +public class TemplateDataHighlighterWrapper implements SyntaxHighlighter { + private final SyntaxHighlighter myHighlighter; + + public TemplateDataHighlighterWrapper(SyntaxHighlighter highlighter) { + myHighlighter = highlighter; + } + + @NotNull + public Lexer getHighlightingLexer() { + return myHighlighter.getHighlightingLexer(); + } + + @NotNull + public TextAttributesKey[] getTokenHighlights(final IElementType tokenType) { + if (tokenType == BAD_CHARACTER) { + return new TextAttributesKey[0]; + } + + return myHighlighter.getTokenHighlights(tokenType); + } +} diff --git a/platform/lang-impl/src/com/intellij/codeInsight/editorActions/CopyPasteIndentProcessor.java b/platform/lang-impl/src/com/intellij/codeInsight/editorActions/CopyPasteIndentProcessor.java index cba12a20d4d9..ed59492c5fee 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/editorActions/CopyPasteIndentProcessor.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/editorActions/CopyPasteIndentProcessor.java @@ -97,7 +97,10 @@ public class CopyPasteIndentProcessor implements CopyPastePostProcessor { public static final LanguageASTFactory INSTANCE = new LanguageASTFactory(); private LanguageASTFactory() { super("com.intellij.lang.ast.factory", ASTFactory.DEFAULT); } -} \ No newline at end of file +} diff --git a/platform/lang-impl/src/com/intellij/lang/impl/PsiBuilderImpl.java b/platform/lang-impl/src/com/intellij/lang/impl/PsiBuilderImpl.java index 5d9f5e95ea24..cd5362dac2a8 100644 --- a/platform/lang-impl/src/com/intellij/lang/impl/PsiBuilderImpl.java +++ b/platform/lang-impl/src/com/intellij/lang/impl/PsiBuilderImpl.java @@ -623,6 +623,7 @@ public class PsiBuilderImpl extends UserDataHolderBase implements PsiBuilder { int cur = myCurrentLexeme; while (steps > 0) { + ++cur; while (cur < myLexemeCount && whitespaceOrComment(myLexTypes[cur])) { cur++; } @@ -633,6 +634,20 @@ public class PsiBuilderImpl extends UserDataHolderBase implements PsiBuilder { return cur < myLexemeCount ? myLexTypes[cur] : null; } + @Override + public IElementType rawLookup(int steps) { + int cur = myCurrentLexeme + steps; + return cur < myLexemeCount && cur >= 0 ? myLexTypes[cur] : null; + } + + @Override + public int rawTokenTypeStart(int steps) { + int cur = myCurrentLexeme + steps; + if (cur < 0) return -1; + if (cur >= myLexemeCount) return getOriginalText().length(); + return myLexStarts[cur]; + } + @Override public void setWhitespaceSkippedCallback(WhitespaceSkippedCallback callback) { myWhitespaceSkippedCallback = callback; diff --git a/platform/lang-impl/src/com/intellij/openapi/roots/libraries/scripting/ScriptingIndexableSetContributor.java b/platform/lang-impl/src/com/intellij/openapi/roots/libraries/scripting/ScriptingIndexableSetContributor.java index 7b1524ae6b78..9fb1b06b21ba 100644 --- a/platform/lang-impl/src/com/intellij/openapi/roots/libraries/scripting/ScriptingIndexableSetContributor.java +++ b/platform/lang-impl/src/com/intellij/openapi/roots/libraries/scripting/ScriptingIndexableSetContributor.java @@ -25,6 +25,7 @@ import com.intellij.openapi.util.Key; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.util.indexing.IndexableSetContributor; import gnu.trove.THashSet; +import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import java.util.Set; @@ -34,15 +35,13 @@ import java.util.Set; */ public abstract class ScriptingIndexableSetContributor extends IndexableSetContributor { + @NotNull @Override - public Set getAdditionalRootsToIndex(@Nullable Project project) { - final Set predefinedFiles = getPredefinedFilesToIndex(); - final THashSet filesToIndex = new THashSet(); - filesToIndex.addAll(predefinedFiles); - filesToIndex.addAll(getLibraryFiles(project)); - return filesToIndex; + public Set getAdditionalProjectRootsToIndex(@Nullable Project project) { + return getLibraryFiles(project); } + @NotNull public Set getLibraryFiles(Project project) { final THashSet libFiles = new THashSet(); LibraryType libType = getLibraryType(); @@ -67,8 +66,8 @@ public abstract class ScriptingIndexableSetContributor extends IndexableSetContr } @Override - public Set getAdditionalRootsToIndex() { - return getAdditionalRootsToIndex(null); + public final Set getAdditionalRootsToIndex() { + return getPredefinedFilesToIndex(); } public abstract Set getPredefinedFilesToIndex(); diff --git a/platform/lang-impl/src/com/intellij/profile/codeInspection/ui/SingleInspectionProfilePanel.java b/platform/lang-impl/src/com/intellij/profile/codeInspection/ui/SingleInspectionProfilePanel.java index ab69da6d42f2..9c26e8cbf787 100644 --- a/platform/lang-impl/src/com/intellij/profile/codeInspection/ui/SingleInspectionProfilePanel.java +++ b/platform/lang-impl/src/com/intellij/profile/codeInspection/ui/SingleInspectionProfilePanel.java @@ -849,7 +849,7 @@ public class SingleInspectionProfilePanel extends JPanel { } public Dimension getPreferredSize() { - return new Dimension(700, -1); + return new Dimension(700, 500); } public void disposeUI() { 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 7dcd48d7a11d..66beef533b34 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 @@ -18,11 +18,9 @@ package com.intellij.psi.impl.file.impl; import com.intellij.AppTopics; import com.intellij.ProjectTopics; -import com.intellij.extapi.psi.PsiFileBase; import com.intellij.injected.editor.DocumentWindow; import com.intellij.injected.editor.VirtualFileWindow; import com.intellij.lang.Language; -import com.intellij.lang.LanguageParserDefinitions; import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.editor.Document; @@ -1083,12 +1081,8 @@ public class FileManagerImpl implements FileManager { } // When file is renamed so that extension changes then language dialect might change and thus psiFile should be invalidated - // We could detect it right now with checks of parser definition equivalence - // The file name under passed psi file is "new" but parser def is from old name private static boolean languageDialectChanged(final PsiFile newPsiFile, String oldFileName) { - return newPsiFile instanceof PsiFileBase - && LanguageParserDefinitions.INSTANCE.forLanguage(newPsiFile.getLanguage()).getClass() == ((PsiFileBase)newPsiFile).getParserDefinition().getClass() - && !FileUtil.getExtension(newPsiFile.getName()).equals(FileUtil.getExtension(oldFileName)); + return newPsiFile != null && !FileUtil.getExtension(newPsiFile.getName()).equals(FileUtil.getExtension(oldFileName)); } private class MyModuleRootListener implements ModuleRootListener { diff --git a/platform/lang-impl/src/com/intellij/refactoring/rename/PsiElementRenameHandler.java b/platform/lang-impl/src/com/intellij/refactoring/rename/PsiElementRenameHandler.java index 254b1e5d6d7a..45712a26d1f3 100644 --- a/platform/lang-impl/src/com/intellij/refactoring/rename/PsiElementRenameHandler.java +++ b/platform/lang-impl/src/com/intellij/refactoring/rename/PsiElementRenameHandler.java @@ -87,6 +87,14 @@ public class PsiElementRenameHandler implements RenameHandler { static boolean canRename(Project project, Editor editor, PsiElement element) { if (element == null) return false; if (!(element instanceof PsiFile) && CollectHighlightsUtil.isOutsideSourceRootJavaFile(element.getContainingFile())) return false; + + if (!element.isWritable()) { + String message = RefactoringBundle.getCannotRefactorMessage("This element cannot be renamed."); + showErrorMessage(project, editor, message); + + return false; + } + boolean hasRenameProcessor = RenamePsiElementProcessor.forElement(element) != RenamePsiElementProcessor.DEFAULT; boolean hasWritableMetaData = element instanceof PsiMetaOwner && ((PsiMetaOwner)element).getMetaData() instanceof PsiWritableMetaData; diff --git a/platform/lang-impl/src/com/intellij/refactoring/rename/RenameProcessor.java b/platform/lang-impl/src/com/intellij/refactoring/rename/RenameProcessor.java index f15f07ceb484..c6d809fde561 100644 --- a/platform/lang-impl/src/com/intellij/refactoring/rename/RenameProcessor.java +++ b/platform/lang-impl/src/com/intellij/refactoring/rename/RenameProcessor.java @@ -114,7 +114,7 @@ public class RenameProcessor extends BaseRefactoringProcessor { super.doRun(); } - public void prepareRenaming(final PsiElement element, final String newName, final LinkedHashMap allRenames) { + public void prepareRenaming(@NotNull final PsiElement element, final String newName, final LinkedHashMap allRenames) { final List processors = RenamePsiElementProcessor.allForElement(element); myForceShowPreview = false; for (RenamePsiElementProcessor processor : processors) { diff --git a/platform/lang-impl/src/com/intellij/refactoring/rename/RenamePsiElementProcessor.java b/platform/lang-impl/src/com/intellij/refactoring/rename/RenamePsiElementProcessor.java index dde8aeda8421..ad2eaf1cd0f9 100644 --- a/platform/lang-impl/src/com/intellij/refactoring/rename/RenamePsiElementProcessor.java +++ b/platform/lang-impl/src/com/intellij/refactoring/rename/RenamePsiElementProcessor.java @@ -46,7 +46,7 @@ import java.util.Map; public abstract class RenamePsiElementProcessor { private static final ExtensionPointName EP_NAME = ExtensionPointName.create("com.intellij.renamePsiElementProcessor"); - public abstract boolean canProcessElement(@Nullable PsiElement element); + public abstract boolean canProcessElement(@NotNull PsiElement element); public RenameDialog createRenameDialog(Project project, PsiElement element, PsiElement nameSuggestionContext, Editor editor) { return new RenameDialog(project, element, nameSuggestionContext, editor); @@ -85,7 +85,7 @@ public abstract class RenamePsiElementProcessor { public void findExistingNameConflicts(final PsiElement element, final String newName, final MultiMap conflicts) { } - public static List allForElement(PsiElement element) { + public static List allForElement(@NotNull PsiElement element) { final List result = new ArrayList(); for (RenamePsiElementProcessor processor : EP_NAME.getExtensions()) { if (processor.canProcessElement(element)) { @@ -96,7 +96,7 @@ public abstract class RenamePsiElementProcessor { } @NotNull - public static RenamePsiElementProcessor forElement(PsiElement element) { + public static RenamePsiElementProcessor forElement(@NotNull PsiElement element) { for(RenamePsiElementProcessor processor: Extensions.getExtensions(EP_NAME)) { if (processor.canProcessElement(element)) { return processor; @@ -161,7 +161,7 @@ public abstract class RenamePsiElementProcessor { } public static final RenamePsiElementProcessor DEFAULT = new RenamePsiElementProcessor() { - public boolean canProcessElement(final PsiElement element) { + public boolean canProcessElement(@NotNull final PsiElement element) { return true; } }; diff --git a/platform/lang-impl/src/com/intellij/refactoring/rename/RenamePsiFileProcessor.java b/platform/lang-impl/src/com/intellij/refactoring/rename/RenamePsiFileProcessor.java index 1d5ea969d22a..1096166d6f82 100644 --- a/platform/lang-impl/src/com/intellij/refactoring/rename/RenamePsiFileProcessor.java +++ b/platform/lang-impl/src/com/intellij/refactoring/rename/RenamePsiFileProcessor.java @@ -32,7 +32,7 @@ import java.util.Collections; */ public class RenamePsiFileProcessor extends RenamePsiElementProcessor { @Override - public boolean canProcessElement(@Nullable PsiElement element) { + public boolean canProcessElement(@NotNull PsiElement element) { return element instanceof PsiFile; } diff --git a/platform/lang-impl/src/com/intellij/util/indexing/FileBasedIndex.java b/platform/lang-impl/src/com/intellij/util/indexing/FileBasedIndex.java index 6b92e08c50ef..1e5663babfa3 100644 --- a/platform/lang-impl/src/com/intellij/util/indexing/FileBasedIndex.java +++ b/platform/lang-impl/src/com/intellij/util/indexing/FileBasedIndex.java @@ -1912,7 +1912,12 @@ public class FileBasedIndex implements ApplicationComponent { if (project.isDisposed()) { return; } - for (VirtualFile root : IndexableSetContributor.getRootsToIndex(provider, project)) { + for (VirtualFile root : IndexableSetContributor.getRootsToIndex(provider)) { + if (visitedRoots.add(root)) { + iterateRecursively(root, processor, indicator); + } + } + for (VirtualFile root : IndexableSetContributor.getProjectRootsToIndex(provider, project)) { if (visitedRoots.add(root)) { iterateRecursively(root, processor, indicator); } diff --git a/platform/lang-impl/src/com/intellij/util/indexing/IndexableSetContributor.java b/platform/lang-impl/src/com/intellij/util/indexing/IndexableSetContributor.java index f61b47b52b03..ad053ee92d34 100644 --- a/platform/lang-impl/src/com/intellij/util/indexing/IndexableSetContributor.java +++ b/platform/lang-impl/src/com/intellij/util/indexing/IndexableSetContributor.java @@ -5,9 +5,11 @@ import com.intellij.openapi.vfs.VirtualFile; import com.intellij.openapi.vfs.VirtualFileManager; import com.intellij.util.NotNullFunction; import com.intellij.util.containers.ContainerUtil; +import org.apache.commons.collections.SetUtils; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import java.util.Collections; import java.util.HashSet; import java.util.Set; @@ -15,6 +17,9 @@ import java.util.Set; * @author peter */ public abstract class IndexableSetContributor implements IndexedRootsProvider { + + protected static final Set EMPTY_FILE_SET = Collections.unmodifiableSet(new HashSet()); + @Override public final Set getRootsToIndex() { return ContainerUtil.map2Set(getAdditionalRootsToIndex(), new NotNullFunction() { @@ -26,13 +31,17 @@ public abstract class IndexableSetContributor implements IndexedRootsProvider { }); } - public static Set getRootsToIndex(IndexedRootsProvider provider) { - return getRootsToIndex(provider, null); + @NotNull + public static Set getProjectRootsToIndex(IndexedRootsProvider provider, Project project) { + if (provider instanceof IndexableSetContributor) { + return ((IndexableSetContributor)provider).getAdditionalProjectRootsToIndex(project); + } + return EMPTY_FILE_SET; } - public static Set getRootsToIndex(IndexedRootsProvider provider, @Nullable Project project) { + public static Set getRootsToIndex(IndexedRootsProvider provider) { if (provider instanceof IndexableSetContributor) { - return ((IndexableSetContributor)provider).getAdditionalRootsToIndex(project); + return ((IndexableSetContributor)provider).getAdditionalRootsToIndex(); } final HashSet result = new HashSet(); @@ -43,8 +52,9 @@ public abstract class IndexableSetContributor implements IndexedRootsProvider { return result; } - public Set getAdditionalRootsToIndex(@Nullable Project project) { - return getAdditionalRootsToIndex(); + @NotNull + public Set getAdditionalProjectRootsToIndex(@Nullable Project project) { + return EMPTY_FILE_SET; } public abstract Set getAdditionalRootsToIndex(); diff --git a/platform/platform-api/src/com/intellij/codeHighlighting/HighlightDisplayLevel.java b/platform/platform-api/src/com/intellij/codeHighlighting/HighlightDisplayLevel.java index a1ea2ba6c0de..88624c496a68 100644 --- a/platform/platform-api/src/com/intellij/codeHighlighting/HighlightDisplayLevel.java +++ b/platform/platform-api/src/com/intellij/codeHighlighting/HighlightDisplayLevel.java @@ -17,6 +17,9 @@ package com.intellij.codeHighlighting; import com.intellij.lang.annotation.HighlightSeverity; import com.intellij.openapi.editor.colors.CodeInsightColors; +import com.intellij.openapi.editor.colors.EditorColorsManager; +import com.intellij.openapi.editor.colors.EditorColorsScheme; +import com.intellij.openapi.editor.colors.TextAttributesKey; import com.intellij.openapi.util.Comparing; import com.intellij.util.ImageLoader; import com.intellij.util.containers.HashMap; @@ -30,9 +33,9 @@ public class HighlightDisplayLevel { private static final Map ourMap = new HashMap(); public static final HighlightDisplayLevel GENERIC_SERVER_ERROR_OR_WARNING = new HighlightDisplayLevel(HighlightSeverity.GENERIC_SERVER_ERROR_OR_WARNING, - createIconByMask(CodeInsightColors.GENERIC_SERVER_ERROR_OR_WARNING.getDefaultAttributes().getErrorStripeColor())); - public static final HighlightDisplayLevel ERROR = new HighlightDisplayLevel(HighlightSeverity.ERROR, createIconByMask(CodeInsightColors.ERRORS_ATTRIBUTES.getDefaultAttributes().getErrorStripeColor())); - public static final HighlightDisplayLevel WARNING = new HighlightDisplayLevel(HighlightSeverity.WARNING, createIconByMask(CodeInsightColors.WARNINGS_ATTRIBUTES.getDefaultAttributes().getErrorStripeColor())); + createIconByMask(CodeInsightColors.GENERIC_SERVER_ERROR_OR_WARNING)); + public static final HighlightDisplayLevel ERROR = new HighlightDisplayLevel(HighlightSeverity.ERROR, createIconByMask(CodeInsightColors.ERRORS_ATTRIBUTES)); + public static final HighlightDisplayLevel WARNING = new HighlightDisplayLevel(HighlightSeverity.WARNING, createIconByMask(CodeInsightColors.WARNINGS_ATTRIBUTES)); public static final HighlightDisplayLevel DO_NOT_SHOW = new HighlightDisplayLevel(HighlightSeverity.INFORMATION, createIconByMask(new Color(30, 160, 0))); public static final HighlightDisplayLevel INFO = new HighlightDisplayLevel(HighlightSeverity.INFO, DO_NOT_SHOW.getIcon()); @@ -89,6 +92,17 @@ public class HighlightDisplayLevel { } private static final int EMPTY_ICON_DIM = 12; + + public static Icon createIconByMask(TextAttributesKey key) { + final EditorColorsManager manager = EditorColorsManager.getInstance(); + if (manager != null) { + final EditorColorsScheme globalScheme = manager.getGlobalScheme(); + return createIconByMask(globalScheme.getAttributes(key).getErrorStripeColor()); + } + + return createIconByMask(key.getDefaultAttributes().getErrorStripeColor()); + } + public static Icon createIconByMask(final Color renderColor) { return new Icon() { public void paintIcon(Component c, Graphics g, int x, int y) { diff --git a/platform/platform-api/src/com/intellij/ui/table/BaseTableView.java b/platform/platform-api/src/com/intellij/ui/table/BaseTableView.java index 67a63dbc61f6..000d313443d0 100644 --- a/platform/platform-api/src/com/intellij/ui/table/BaseTableView.java +++ b/platform/platform-api/src/com/intellij/ui/table/BaseTableView.java @@ -84,7 +84,10 @@ public class BaseTableView extends Table { } index = 0; for (final String columnIndex : columnIndices) { - columnModel.moveColumn(indexbyModelIndex(columnModel, Integer.parseInt(columnIndex)), index); + final int modelColumnIndex = indexbyModelIndex(columnModel, Integer.parseInt(columnIndex)); + if (modelColumnIndex > 0 && modelColumnIndex < columnModel.getColumnCount()) { + columnModel.moveColumn(modelColumnIndex, index); + } index++; } for (int i = 0; i < columnIndices.size(); i++) { diff --git a/platform/platform-impl/src/com/intellij/ide/IdeEventQueue.java b/platform/platform-impl/src/com/intellij/ide/IdeEventQueue.java index a6c06815780e..e978cc84e260 100644 --- a/platform/platform-impl/src/com/intellij/ide/IdeEventQueue.java +++ b/platform/platform-impl/src/com/intellij/ide/IdeEventQueue.java @@ -39,7 +39,6 @@ import com.intellij.util.Alarm; import com.intellij.util.ReflectionUtil; import com.intellij.util.containers.ContainerUtil; import com.intellij.util.containers.HashMap; -import com.intellij.util.ui.UIUtil; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -49,7 +48,6 @@ import java.awt.event.*; import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; import java.lang.reflect.Field; -import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.util.*; @@ -131,6 +129,7 @@ public class IdeEventQueue extends EventQueue { private final Set myReady = new HashSet(); private boolean myKeyboardBusy; + private boolean myDispatchingFocusEvent; private static class IdeEventQueueHolder { private static final IdeEventQueue INSTANCE = new IdeEventQueue(); @@ -649,6 +648,7 @@ public class IdeEventQueue extends EventQueue { private void defaultDispatchEvent(final AWTEvent e) { try { + myDispatchingFocusEvent = e instanceof FocusEvent; super.dispatchEvent(e); } catch (ProcessCanceledException pce) { @@ -658,9 +658,15 @@ public class IdeEventQueue extends EventQueue { if (!myToolkitBugsProcessor.process(exc)) { LOG.error("Error during dispatching of " + e, exc); } + } finally { + myDispatchingFocusEvent = false; } } + public boolean isDispatchingFocusEvent() { + return myDispatchingFocusEvent; + } + private static boolean typeAheadDispatchToFocusManager(AWTEvent e) { if (e instanceof KeyEvent) { final KeyEvent event = (KeyEvent)e; @@ -787,7 +793,7 @@ public class IdeEventQueue extends EventQueue { return peekEvent(FocusEvent.FOCUS_GAINED) != null || peekEvent(FocusEvent.FOCUS_LOST) != null; } - private boolean isReady() { + public boolean isReady() { return !myKeyboardBusy && myKeyEventDispatcher.isReady(); } diff --git a/platform/platform-impl/src/com/intellij/ide/actions/CreateLauncherScriptAction.java b/platform/platform-impl/src/com/intellij/ide/actions/CreateLauncherScriptAction.java index efacd1cc50de..1a3a2472ab09 100644 --- a/platform/platform-impl/src/com/intellij/ide/actions/CreateLauncherScriptAction.java +++ b/platform/platform-impl/src/com/intellij/ide/actions/CreateLauncherScriptAction.java @@ -118,7 +118,7 @@ public class CreateLauncherScriptAction extends AnAction { String launcherContents = FileUtil.loadTextAndClose(new InputStreamReader(stream)); launcherContents = launcherContents.replace("$CONFIG_PATH$", PathManager.getConfigPath()); - String homePath = PathManager.getHomePath().replace(" ", "\\ "); + String homePath = PathManager.getHomePath(); String productName = ApplicationNamesInfo.getInstance().getProductName().toLowerCase(); if (SystemInfo.isMac) { launcherContents = launcherContents.replace("$RUN_PATH$", homePath + "/Contents/MacOS/" + productName); diff --git a/platform/platform-impl/src/com/intellij/ide/plugins/PluginManagerConfigurable.java b/platform/platform-impl/src/com/intellij/ide/plugins/PluginManagerConfigurable.java index 9a9d0e8712ca..ed274b4ea6d0 100644 --- a/platform/platform-impl/src/com/intellij/ide/plugins/PluginManagerConfigurable.java +++ b/platform/platform-impl/src/com/intellij/ide/plugins/PluginManagerConfigurable.java @@ -25,6 +25,7 @@ import com.intellij.openapi.options.SearchableConfigurable; import com.intellij.openapi.ui.Messages; import com.intellij.openapi.util.Disposer; import com.intellij.openapi.util.IconLoader; +import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.Nullable; import javax.swing.*; @@ -41,6 +42,7 @@ import java.util.List; */ public class PluginManagerConfigurable extends BaseConfigurable implements SearchableConfigurable { + @NonNls private static final String POSTPONE = "&Postpone"; public boolean EXPANDED = false; public String FIND = ""; public boolean TREE_VIEW = false; @@ -172,15 +174,13 @@ public class PluginManagerConfigurable extends BaseConfigurable implements Searc private static int showShutDownIDEADialog() { String message = IdeBundle.message("message.idea.shutdown.required", ApplicationNamesInfo.getInstance().getProductName()); String title = IdeBundle.message("title.plugins.changed"); - String cancel = IdeBundle.message("button.cancel"); - return Messages.showDialog(message, title, new String[]{"Shut Down", cancel},0,0,Messages.getQuestionIcon()); + return Messages.showDialog(message, title, new String[]{"Shut Down", POSTPONE},0,0,Messages.getQuestionIcon()); } public static int showRestartIDEADialog() { String message = IdeBundle.message("message.idea.restart.required", ApplicationNamesInfo.getInstance().getProductName()); String title = IdeBundle.message("title.plugins.changed"); - String cancel = IdeBundle.message("button.cancel"); - return Messages.showDialog(message, title, new String[]{"Restart", cancel},0,0,Messages.getQuestionIcon()); + return Messages.showDialog(message, title, new String[]{"Restart", POSTPONE},0,0,Messages.getQuestionIcon()); } public boolean isModified() { diff --git a/platform/platform-impl/src/com/intellij/openapi/project/DumbServiceImpl.java b/platform/platform-impl/src/com/intellij/openapi/project/DumbServiceImpl.java index 2908d9450e1d..2a0a0ad62cb6 100644 --- a/platform/platform-impl/src/com/intellij/openapi/project/DumbServiceImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/project/DumbServiceImpl.java @@ -39,8 +39,8 @@ import com.intellij.util.io.storage.HeavyProcessLatch; import com.intellij.util.messages.MessageBus; import com.intellij.util.ui.UIUtil; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.TestOnly; -import javax.swing.*; import javax.swing.event.HyperlinkEvent; import javax.swing.event.HyperlinkListener; import java.lang.reflect.InvocationHandler; @@ -79,6 +79,17 @@ public class DumbServiceImpl extends DumbService { return myDumb; } + @TestOnly + public void setDumb(boolean dumb) { + if (dumb) { + myDumb = true; + myPublisher.enteredDumbMode(); + } + else { + updateFinished(); + } + } + @Override public void runWhenSmart(Runnable runnable) { if (!isDumb()) { @@ -159,7 +170,7 @@ public class DumbServiceImpl extends DumbService { final IndexUpdateRunnable updateRunnable = new IndexUpdateRunnable(runner); - invokeOnEDT(new DumbAwareRunnable() { + UIUtil.invokeLaterIfNeeded(new DumbAwareRunnable() { public void run() { if (myProject.isDisposed()) { return; @@ -185,15 +196,6 @@ public class DumbServiceImpl extends DumbService { }); } - private static void invokeOnEDT(DumbAwareRunnable runnable) { - if (ApplicationManager.getApplication().isDispatchThread()) { - runnable.run(); - } - else { - SwingUtilities.invokeLater(runnable); - } - } - private void updateFinished() { myDumb = false; myPublisher.exitDumbMode(); @@ -359,7 +361,7 @@ public class DumbServiceImpl extends DumbService { } finally { myProcessedItems += count; - invokeOnEDT(new DumbAwareRunnable() { + UIUtil.invokeLaterIfNeeded(new DumbAwareRunnable() { public void run() { if (myUpdatesQueue.isEmpty()) { // really terminate the task diff --git a/platform/platform-impl/src/com/intellij/openapi/updateSettings/impl/NoUpdatesPanel.form b/platform/platform-impl/src/com/intellij/openapi/updateSettings/impl/NoUpdatesPanel.form index d5da892ed764..e2e23cf5c340 100644 --- a/platform/platform-impl/src/com/intellij/openapi/updateSettings/impl/NoUpdatesPanel.form +++ b/platform/platform-impl/src/com/intellij/openapi/updateSettings/impl/NoUpdatesPanel.form @@ -11,12 +11,12 @@ - + - + diff --git a/platform/platform-impl/src/com/intellij/openapi/wm/impl/FocusManagerImpl.java b/platform/platform-impl/src/com/intellij/openapi/wm/impl/FocusManagerImpl.java index 9f18c64b142a..7cd5e9efed12 100644 --- a/platform/platform-impl/src/com/intellij/openapi/wm/impl/FocusManagerImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/wm/impl/FocusManagerImpl.java @@ -85,7 +85,7 @@ public class FocusManagerImpl extends IdeFocusManager implements Disposable { private boolean myFlushWasDelayedToFixFocus; private boolean canFlushIdleRequests() { - return isFocusTransferReady() && !isIdleQueueEmpty(); + return isFocusTransferReady() && !isIdleQueueEmpty() && !IdeEventQueue.getInstance().isDispatchingFocusEvent(); } private final Map> myLastFocused = new HashMap>(); diff --git a/platform/platform-resources-en/src/tips/SearchInSettings.html b/platform/platform-resources-en/src/tips/SearchInSettings.html index b9a158bd277a..2858bdfdc42e 100644 --- a/platform/platform-resources-en/src/tips/SearchInSettings.html +++ b/platform/platform-resources-en/src/tips/SearchInSettings.html @@ -5,7 +5,7 @@ You can quickly find a setting you need in the Settings dialog, without browsing through the numerous options. Just type some characters that to your opinion exist in the option description, and the list of settings will reduce to the matching ones. Select the desired entry, and see the setting that contains the entered characters highlighted: -

+

diff --git a/platform/testFramework/src/com/intellij/testFramework/fixtures/impl/CodeInsightTestFixtureImpl.java b/platform/testFramework/src/com/intellij/testFramework/fixtures/impl/CodeInsightTestFixtureImpl.java index 4679f4bf0eb2..d38a17eb4605 100644 --- a/platform/testFramework/src/com/intellij/testFramework/fixtures/impl/CodeInsightTestFixtureImpl.java +++ b/platform/testFramework/src/com/intellij/testFramework/fixtures/impl/CodeInsightTestFixtureImpl.java @@ -25,7 +25,10 @@ import com.intellij.codeInsight.completion.CompletionType; import com.intellij.codeInsight.daemon.DaemonCodeAnalyzer; import com.intellij.codeInsight.daemon.DaemonCodeAnalyzerSettings; import com.intellij.codeInsight.daemon.HighlightDisplayKey; -import com.intellij.codeInsight.daemon.impl.*; +import com.intellij.codeInsight.daemon.impl.DaemonCodeAnalyzerImpl; +import com.intellij.codeInsight.daemon.impl.HighlightInfo; +import com.intellij.codeInsight.daemon.impl.HighlightInfoType; +import com.intellij.codeInsight.daemon.impl.ShowIntentionsPass; import com.intellij.codeInsight.folding.impl.CodeFoldingManagerImpl; import com.intellij.codeInsight.highlighting.actions.HighlightUsagesAction; import com.intellij.codeInsight.intention.IntentionAction; @@ -70,7 +73,7 @@ import com.intellij.openapi.fileTypes.FileType; import com.intellij.openapi.fileTypes.FileTypeManager; import com.intellij.openapi.fileTypes.StdFileTypes; import com.intellij.openapi.module.Module; -import com.intellij.openapi.project.DumbServiceImpl; +import com.intellij.openapi.project.DumbService; import com.intellij.openapi.project.Project; import com.intellij.openapi.util.*; import com.intellij.openapi.util.io.FileUtil; @@ -1307,9 +1310,10 @@ public class CodeInsightTestFixtureImpl extends BaseFixture implements CodeInsig } public static void ensureIndexesUpToDate(Project project) { - FileBasedIndex.getInstance().ensureUpToDate(StubUpdatingIndex.INDEX_ID, project, null); - FileBasedIndex.getInstance().ensureUpToDate(TodoIndex.NAME, project, null); - assertTrue(!DumbServiceImpl.getInstance(project).isDumb()); + if (!DumbService.isDumb(project)) { + FileBasedIndex.getInstance().ensureUpToDate(StubUpdatingIndex.INDEX_ID, project, null); + FileBasedIndex.getInstance().ensureUpToDate(TodoIndex.NAME, project, null); + } } @Override diff --git a/platform/vcs-api/src/com/intellij/openapi/vcs/AbstractVcs.java b/platform/vcs-api/src/com/intellij/openapi/vcs/AbstractVcs.java index a23bd2747fc5..5e735f8dd554 100644 --- a/platform/vcs-api/src/com/intellij/openapi/vcs/AbstractVcs.java +++ b/platform/vcs-api/src/com/intellij/openapi/vcs/AbstractVcs.java @@ -32,6 +32,7 @@ import com.intellij.openapi.vcs.diff.RevisionSelector; import com.intellij.openapi.vcs.history.VcsFileRevision; import com.intellij.openapi.vcs.history.VcsHistoryProvider; import com.intellij.openapi.vcs.history.VcsRevisionNumber; +import com.intellij.openapi.vcs.impl.IllegalStateProxy; import com.intellij.openapi.vcs.merge.MergeProvider; import com.intellij.openapi.vcs.rollback.RollbackEnvironment; import com.intellij.openapi.vcs.update.UpdateEnvironment; @@ -61,6 +62,10 @@ public abstract class AbstractVcs extends S private VcsShowSettingOption myUpdateOption; private VcsShowSettingOption myStatusOption; + private CheckinEnvironment myCheckinEnvironment; + private UpdateEnvironment myUpdateEnvironment; + private RollbackEnvironment myRollbackEnvironment; + public AbstractVcs(final Project project, final String name) { super(project); @@ -124,23 +129,43 @@ public abstract class AbstractVcs extends S } /** + * creates the object for performing checkin / commit / submit operations. + */ + @Nullable + protected CheckinEnvironment createCheckinEnvironment() { + return IllegalStateProxy.create(CheckinEnvironment.class); + } + + /** + * !!! concrete VCS should define {@link #createCheckinEnvironment} method + * this method wraps created environment with a listener + * * Returns the interface for performing checkin / commit / submit operations. * * @return the checkin interface, or null if checkins are not supported by the VCS. */ @Nullable public CheckinEnvironment getCheckinEnvironment() { - return null; + return myCheckinEnvironment; } /** * Returns the interface for performing revert / rollback operations. + */ + @Nullable + protected RollbackEnvironment createRollbackEnvironment() { + return IllegalStateProxy.create(RollbackEnvironment.class); + } + + /** + * !!! concrete VCS should define {@link #createRollbackEnvironment()} method + * this method wraps created environment with a listener * * @return the rollback interface, or null if rollbacks are not supported by the VCS. */ @Nullable public RollbackEnvironment getRollbackEnvironment() { - return null; + return myRollbackEnvironment; } @Nullable @@ -159,12 +184,21 @@ public abstract class AbstractVcs extends S /** * Returns the interface for performing update/sync operations. + */ + @Nullable + protected UpdateEnvironment createUpdateEnvironment() { + return IllegalStateProxy.create(UpdateEnvironment.class); + } + + /** + * !!! concrete VCS should define {@link #createUpdateEnvironment()} method + * this method wraps created environment with a listener * * @return the update interface, or null if the updates are not supported by the VCS. */ @Nullable public UpdateEnvironment getUpdateEnvironment() { - return null; + return myUpdateEnvironment; } /** @@ -494,5 +528,20 @@ public abstract class AbstractVcs extends S @CalledInAwt public void generalPreConfigurationStep() { } + + public void setCheckinEnvironment(CheckinEnvironment checkinEnvironment) { + if (myCheckinEnvironment != null) throw new IllegalStateException("Attempt to redefine checkin environment"); + myCheckinEnvironment = checkinEnvironment; + } + + public void setUpdateEnvironment(UpdateEnvironment updateEnvironment) { + if (myUpdateEnvironment != null) throw new IllegalStateException("Attempt to redefine update environment"); + myUpdateEnvironment = updateEnvironment; + } + + public void setRollbackEnvironment(RollbackEnvironment rollbackEnvironment) { + if (myRollbackEnvironment != null) throw new IllegalStateException("Attempt to redefine rollback environment"); + myRollbackEnvironment = rollbackEnvironment; + } } diff --git a/plugins/InspectionGadgets/src/com/siyeh/ig/telemetry/InspectionRunListener.java b/platform/vcs-api/src/com/intellij/openapi/vcs/ForwardingListener.java similarity index 52% rename from plugins/InspectionGadgets/src/com/siyeh/ig/telemetry/InspectionRunListener.java rename to platform/vcs-api/src/com/intellij/openapi/vcs/ForwardingListener.java index 6356215b623e..120111989b12 100644 --- a/plugins/InspectionGadgets/src/com/siyeh/ig/telemetry/InspectionRunListener.java +++ b/platform/vcs-api/src/com/intellij/openapi/vcs/ForwardingListener.java @@ -1,5 +1,5 @@ /* - * Copyright 2003-2010 Dave Griffith, Bas Leijdekkers + * Copyright 2000-2010 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,9 +13,25 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.siyeh.ig.telemetry; +package com.intellij.openapi.vcs; -public interface InspectionRunListener{ - - void reportRun(String inspectionID, long runTime); +import com.intellij.openapi.util.Pair; +import com.intellij.util.Consumer; + +/** +* @author irengrig +* Date: 12/21/10 +* Time: 2:15 PM +*/ +public class ForwardingListener implements Consumer>> { + private final T myT; + + public ForwardingListener(T t) { + myT = t; + } + + @Override + public void consume(Pair> vcsKeyConsumerPair) { + vcsKeyConsumerPair.getSecond().consume(myT); + } } diff --git a/platform/vcs-api/src/com/intellij/openapi/vcs/ProjectLevelVcsManager.java b/platform/vcs-api/src/com/intellij/openapi/vcs/ProjectLevelVcsManager.java index f85e747459de..2218aa571c56 100644 --- a/platform/vcs-api/src/com/intellij/openapi/vcs/ProjectLevelVcsManager.java +++ b/platform/vcs-api/src/com/intellij/openapi/vcs/ProjectLevelVcsManager.java @@ -23,6 +23,7 @@ import com.intellij.openapi.project.Project; import com.intellij.openapi.util.Computable; import com.intellij.openapi.vcs.checkin.CheckinHandlerFactory; import com.intellij.openapi.vcs.impl.VcsDescriptor; +import com.intellij.openapi.vcs.impl.VcsEnvironmentsProxyCreator; import com.intellij.openapi.vcs.update.UpdatedFiles; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.util.Processor; @@ -275,4 +276,7 @@ public abstract class ProjectLevelVcsManager { public abstract CheckoutProvider.Listener getCompositeCheckoutListener(); public static Topic VCS_CONFIGURATION_CHANGED = Topic.create("VCS configuration changed", VcsListener.class); + + public abstract VcsEventsListenerManager getVcsEventsListenerManager(); + protected abstract VcsEnvironmentsProxyCreator getProxyCreator(); } diff --git a/platform/vcs-api/src/com/intellij/openapi/vcs/VcsActiveEnvironmentsProxy.java b/platform/vcs-api/src/com/intellij/openapi/vcs/VcsActiveEnvironmentsProxy.java new file mode 100644 index 000000000000..c031ea0bf8b1 --- /dev/null +++ b/platform/vcs-api/src/com/intellij/openapi/vcs/VcsActiveEnvironmentsProxy.java @@ -0,0 +1,57 @@ +/* + * Copyright 2000-2010 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.vcs; + +import com.intellij.openapi.vcs.checkin.CheckinEnvironment; +import com.intellij.openapi.vcs.impl.IllegalStateProxy; +import com.intellij.openapi.vcs.impl.VcsEnvironmentsProxyCreator; +import com.intellij.openapi.vcs.rollback.RollbackEnvironment; +import com.intellij.openapi.vcs.update.UpdateEnvironment; + +/** + * @author irengrig + * Date: 12/17/10 + * Time: 12:46 PM + */ +public class VcsActiveEnvironmentsProxy { + private VcsActiveEnvironmentsProxy() { + } + + public static AbstractVcs proxyVcs(final AbstractVcs vcs) { + final ProjectLevelVcsManager manager = ProjectLevelVcsManager.getInstance(vcs.getProject()); + final VcsEnvironmentsProxyCreator proxyCreator = manager.getProxyCreator(); + if (proxyCreator == null) return vcs; + + final VcsKey key = vcs.getKeyInstanceMethod(); + final CheckinEnvironment checkinEnvironment = vcs.createCheckinEnvironment(); + final UpdateEnvironment updateEnvironment = vcs.createUpdateEnvironment(); + final RollbackEnvironment rollbackEnvironment = vcs.createRollbackEnvironment(); + + if (checkinEnvironment != null && checkinEnvironment.equals(IllegalStateProxy.IDENTITY) || + updateEnvironment != null && updateEnvironment.equals(IllegalStateProxy.IDENTITY) || + rollbackEnvironment != null && rollbackEnvironment.equals(IllegalStateProxy.IDENTITY)) { + return vcs; + } else { + final CheckinEnvironment proxedCheckin = proxyCreator.proxyCheckin(key, checkinEnvironment); + final UpdateEnvironment proxedUpdate = proxyCreator.proxyUpdate(key, updateEnvironment); + final RollbackEnvironment proxedRollback = proxyCreator.proxyRollback(key, rollbackEnvironment); + vcs.setCheckinEnvironment(proxedCheckin); + vcs.setUpdateEnvironment(proxedUpdate); + vcs.setRollbackEnvironment(proxedRollback); + return vcs; + } + } +} diff --git a/platform/vcs-api/src/com/intellij/openapi/vcs/VcsEventsListenerManager.java b/platform/vcs-api/src/com/intellij/openapi/vcs/VcsEventsListenerManager.java new file mode 100644 index 000000000000..562625a814df --- /dev/null +++ b/platform/vcs-api/src/com/intellij/openapi/vcs/VcsEventsListenerManager.java @@ -0,0 +1,37 @@ +/* + * Copyright 2000-2010 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.vcs; + +import com.intellij.openapi.util.Pair; +import com.intellij.openapi.vcs.checkin.CheckinEnvironment; +import com.intellij.openapi.vcs.rollback.RollbackEnvironment; +import com.intellij.openapi.vcs.update.UpdateEnvironment; +import com.intellij.util.Consumer; + +/** + * @author irengrig + * Date: 12/15/10 + * Time: 5:42 PM + */ +public interface VcsEventsListenerManager { + void removeCheckin(final Object key); + void removeUpdate(final Object key); + void removeRollback(final Object key); + + Object addCheckin(Consumer>> consumer); + Object addUpdate(Consumer>> consumer); + Object addRollback(Consumer>> consumer); +} diff --git a/platform/vcs-api/src/com/intellij/openapi/vcs/impl/IllegalStateProxy.java b/platform/vcs-api/src/com/intellij/openapi/vcs/impl/IllegalStateProxy.java new file mode 100644 index 000000000000..e4ecd49463f8 --- /dev/null +++ b/platform/vcs-api/src/com/intellij/openapi/vcs/impl/IllegalStateProxy.java @@ -0,0 +1,46 @@ +/* + * Copyright 2000-2010 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.vcs.impl; + +import java.lang.reflect.InvocationHandler; +import java.lang.reflect.Method; +import java.lang.reflect.Proxy; + +/** + * @author irengrig + * Date: 12/17/10 + * Time: 2:21 PM + */ +public class IllegalStateProxy { + public static final Object IDENTITY = new Object(); + + private static final InvocationHandler HANDLER = new InvocationHandler() { + @Override + public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { + if ("equals".equals(method.getName())) { + return IDENTITY.equals(args[0]); + } + throw new IllegalStateException(); + } + }; + + private IllegalStateProxy() { + } + + public static T create(final Class clazz) { + return (T) Proxy.newProxyInstance(clazz.getClassLoader(), new Class[]{clazz}, HANDLER); + } +} diff --git a/platform/vcs-api/src/com/intellij/openapi/vcs/impl/VcsEnvironmentsProxyCreator.java b/platform/vcs-api/src/com/intellij/openapi/vcs/impl/VcsEnvironmentsProxyCreator.java new file mode 100644 index 000000000000..eea5ff2dde86 --- /dev/null +++ b/platform/vcs-api/src/com/intellij/openapi/vcs/impl/VcsEnvironmentsProxyCreator.java @@ -0,0 +1,38 @@ +/* + * Copyright 2000-2010 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.vcs.impl; + +import com.intellij.openapi.vcs.VcsKey; +import com.intellij.openapi.vcs.checkin.CheckinEnvironment; +import com.intellij.openapi.vcs.rollback.RollbackEnvironment; +import com.intellij.openapi.vcs.update.UpdateEnvironment; +import org.jetbrains.annotations.Nullable; + +/** + * @author irengrig + * Date: 12/17/10 + * Time: 5:34 PM + */ +public interface VcsEnvironmentsProxyCreator { + @Nullable + CheckinEnvironment proxyCheckin(VcsKey key, CheckinEnvironment environment); + + @Nullable + UpdateEnvironment proxyUpdate(VcsKey key, UpdateEnvironment environment); + + @Nullable + RollbackEnvironment proxyRollback(VcsKey key, RollbackEnvironment environment); +} diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ChangeListWorker.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ChangeListWorker.java index 1a16670fa137..1d6e08c8209e 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ChangeListWorker.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ChangeListWorker.java @@ -232,7 +232,7 @@ public class ChangeListWorker implements ChangeListsWriteOperations { } public boolean addChangeToList(@NotNull final String name, final Change change, final VcsKey vcsKey) { - LOG.debug("[addChangeToList] name: " + name + " change: " + ChangesUtil.getFilePath(change).getPath() + " vcs: " + + LOG.info("[addChangeToList] name: " + name + " change: " + ChangesUtil.getFilePath(change).getPath() + " vcs: " + (vcsKey == null ? null : vcsKey.getName())); final LocalChangeList changeList = myMap.get(name); if (changeList != null) { @@ -243,16 +243,16 @@ public class ChangeListWorker implements ChangeListsWriteOperations { } public void addChangeToCorrespondingList(final Change change, final VcsKey vcsKey) { - final String path = LOG.isDebugEnabled() ? ChangesUtil.getFilePath(change).getPath() : ""; - LOG.debug("[addChangeToCorrespondingList] for change " + path + " type: " + change.getType() + " have before revision: " + (change.getBeforeRevision() != null)); + final String path = ChangesUtil.getFilePath(change).getPath(); + LOG.info("[addChangeToCorrespondingList] for change " + path + " type: " + change.getType() + " have before revision: " + (change.getBeforeRevision() != null)); assert myDefault != null; for (LocalChangeList list : myMap.values()) { if (list.isDefault()) { - LOG.debug("[addChangeToCorrespondingList] skip default list: " + list.getName() + " type: " + change.getType() + " have before revision: " + (change.getBeforeRevision() != null)); + LOG.info("[addChangeToCorrespondingList] skip default list: " + list.getName() + " type: " + change.getType() + " have before revision: " + (change.getBeforeRevision() != null)); continue; } if (((LocalChangeListImpl) list).processChange(change)) { - LOG.debug("[addChangeToCorrespondingList] matched: " + list.getName() + " type: " + change.getType() + " have before revision: " + (change.getBeforeRevision() != null)); + LOG.info("[addChangeToCorrespondingList] matched: " + list.getName() + " type: " + change.getType() + " have before revision: " + (change.getBeforeRevision() != null)); myIdx.changeAdded(change, vcsKey); return; } diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/UpdatingChangeListBuilder.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/UpdatingChangeListBuilder.java index 1cfc7eea25e4..933e45d00b28 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/UpdatingChangeListBuilder.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/UpdatingChangeListBuilder.java @@ -66,11 +66,11 @@ class UpdatingChangeListBuilder implements ChangelistBuilder { public void processChangeInList(final Change change, @Nullable final ChangeList changeList, final VcsKey vcsKey) { checkIfDisposed(); - LOG.debug("[processChangeInList-1] entering, cl name: " + ((changeList == null) ? null: changeList.getName()) + + LOG.info("[processChangeInList-1] entering, cl name: " + ((changeList == null) ? null: changeList.getName()) + " change: " + ChangesUtil.getFilePath(change).getPath()); final String fileName = ChangesUtil.getFilePath(change).getName(); if (FileTypeManager.getInstance().isFileIgnored(fileName)) { - LOG.debug("[processChangeInList-1] file type ignored"); + LOG.info("[processChangeInList-1] file type ignored"); return; } @@ -78,14 +78,14 @@ class UpdatingChangeListBuilder implements ChangelistBuilder { public void run() { if (ChangeListManagerImpl.isUnder(change, myScope)) { if (changeList != null) { - LOG.debug("[processChangeInList-1] to add change to cl"); + LOG.info("[processChangeInList-1] to add change to cl"); myChangeListWorker.addChangeToList(changeList.getName(), change, vcsKey); } else { - LOG.debug("[processChangeInList-1] to add to corresponding list"); + LOG.info("[processChangeInList-1] to add to corresponding list"); myChangeListWorker.addChangeToCorrespondingList(change, vcsKey); } } else { - LOG.debug("[processChangeInList-1] not under scope"); + LOG.info("[processChangeInList-1] not under scope"); } } }); diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/ex/ProjectLevelVcsManagerEx.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/ex/ProjectLevelVcsManagerEx.java index 88a13a480b15..345dd7a69631 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/ex/ProjectLevelVcsManagerEx.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/ex/ProjectLevelVcsManagerEx.java @@ -50,4 +50,4 @@ public abstract class ProjectLevelVcsManagerEx extends ProjectLevelVcsManager { public abstract void fireDirectoryMappingsChanged(); public abstract String haveDefaultMapping(); -} \ No newline at end of file +} diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/impl/ProjectLevelVcsManagerImpl.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/impl/ProjectLevelVcsManagerImpl.java index ee3866ea4bd3..3ec1fd720d1b 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/impl/ProjectLevelVcsManagerImpl.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/impl/ProjectLevelVcsManagerImpl.java @@ -53,7 +53,6 @@ import com.intellij.ui.content.Content; import com.intellij.ui.content.ContentFactory; import com.intellij.ui.content.ContentManager; import com.intellij.util.ContentsUtil; -import com.intellij.util.EventDispatcher; import com.intellij.util.Icons; import com.intellij.util.Processor; import com.intellij.util.containers.Convertor; @@ -105,6 +104,7 @@ public class ProjectLevelVcsManagerImpl extends ProjectLevelVcsManagerEx impleme private final Map myBackgroundableActionHandlerMap; private final List> myPendingOutput = new ArrayList>(); + private VcsEventsListenerManagerImpl myVcsEventListenerManager; public ProjectLevelVcsManagerImpl(Project project, final FileStatusManager manager, MessageBus messageBus) { myProject = project; @@ -118,6 +118,10 @@ public class ProjectLevelVcsManagerImpl extends ProjectLevelVcsManagerEx impleme myInitialization = new VcsInitialization(myProject); myMappings = new NewMappings(myProject, myMessageBus, this, manager); myMappingsToRoots = new MappingsToRoots(myMappings, myProject); + + if (! myProject.isDefault()) { + myVcsEventListenerManager = new VcsEventsListenerManagerImpl(); + } } public void initComponent() { @@ -660,6 +664,11 @@ public void addMessageToConsoleWindow(final String message, final TextAttributes return new CompositeCheckoutListener(myProject); } + @Override + public VcsEventsListenerManager getVcsEventsListenerManager() { + return myVcsEventListenerManager; + } + public void fireDirectoryMappingsChanged() { if (myProject.isOpen() && (! myProject.isDisposed())) { myMappings.mappingsChanged(); @@ -670,6 +679,11 @@ public void addMessageToConsoleWindow(final String message, final TextAttributes return myMappings.haveDefaultMapping(); } + @Override + protected VcsEnvironmentsProxyCreator getProxyCreator() { + return myVcsEventListenerManager; + } + public BackgroundableActionEnabledHandler getBackgroundableActionHandler(final VcsBackgroundableActions action) { ApplicationManager.getApplication().assertIsDispatchThread(); diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/impl/VcsEP.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/impl/VcsEP.java index e20cd188f0e5..3e7a18770404 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/impl/VcsEP.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/impl/VcsEP.java @@ -23,6 +23,7 @@ import com.intellij.openapi.extensions.AbstractExtensionPointBean; import com.intellij.openapi.extensions.ExtensionPointName; import com.intellij.openapi.project.Project; import com.intellij.openapi.vcs.AbstractVcs; +import com.intellij.openapi.vcs.VcsActiveEnvironmentsProxy; import com.intellij.util.xmlb.annotations.Attribute; /** @@ -56,7 +57,7 @@ public class VcsEP extends AbstractExtensionPointBean { return myVcs; } } - myVcs = instantiate(vcsClass, project.getPicoContainer()); + myVcs = VcsActiveEnvironmentsProxy.proxyVcs((AbstractVcs)instantiate(vcsClass, project.getPicoContainer())); } catch(Exception e) { LOG.error(e); @@ -69,4 +70,4 @@ public class VcsEP extends AbstractExtensionPointBean { public VcsDescriptor createDescriptor() { return new VcsDescriptor(administrativeAreaName, displayName, name); } -} \ No newline at end of file +} diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/impl/VcsEventsListenerManagerImpl.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/impl/VcsEventsListenerManagerImpl.java new file mode 100644 index 000000000000..b60861caa698 --- /dev/null +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/impl/VcsEventsListenerManagerImpl.java @@ -0,0 +1,197 @@ +/* + * Copyright 2000-2010 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.vcs.impl; + +import com.intellij.openapi.diagnostic.Logger; +import com.intellij.openapi.util.Pair; +import com.intellij.openapi.vcs.VcsEventsListenerManager; +import com.intellij.openapi.vcs.VcsKey; +import com.intellij.openapi.vcs.checkin.CheckinEnvironment; +import com.intellij.openapi.vcs.rollback.RollbackEnvironment; +import com.intellij.openapi.vcs.update.UpdateEnvironment; +import com.intellij.util.Consumer; +import com.intellij.util.EventDispatcher; +import org.jetbrains.annotations.Nullable; + +import java.lang.reflect.InvocationHandler; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.lang.reflect.Proxy; +import java.util.Collections; +import java.util.EventListener; +import java.util.HashMap; +import java.util.Map; + +/** + * @author irengrig + * Date: 12/15/10 + * Time: 5:50 PM + */ +public class VcsEventsListenerManagerImpl implements VcsEventsListenerManager, VcsEnvironmentsProxyCreator { + private final Wrapper myCheckinWrapper; + private final Wrapper myUpdateWrapper; + private final Wrapper myRollbackWrapper; + + public VcsEventsListenerManagerImpl() { + myCheckinWrapper = new Wrapper(CheckinEnvironment.class); + myUpdateWrapper = new Wrapper(UpdateEnvironment.class); + myRollbackWrapper = new Wrapper(RollbackEnvironment.class); + } + + @Override + public Object addCheckin(final Consumer>> consumer) { + return myCheckinWrapper.add(consumer); + } + + @Override + public Object addUpdate(final Consumer>> consumer) { + return myUpdateWrapper.add(consumer); + } + + @Override + public Object addRollback(final Consumer>> consumer) { + return myRollbackWrapper.add(consumer); + } + + @Override + public void removeCheckin(Object key) { + myCheckinWrapper.remove(key); + } + + @Override + public void removeUpdate(Object key) { + myUpdateWrapper.remove(key); + } + + @Override + public void removeRollback(Object key) { + myRollbackWrapper.remove(key); + } + + @Nullable + @Override + public CheckinEnvironment proxyCheckin(final VcsKey key, final CheckinEnvironment environment) { + return myCheckinWrapper.createProxy(key, environment); + } + + @Nullable + @Override + public UpdateEnvironment proxyUpdate(final VcsKey key, final UpdateEnvironment environment) { + return myUpdateWrapper.createProxy(key, environment); + } + + @Nullable + @Override + public RollbackEnvironment proxyRollback(final VcsKey key, final RollbackEnvironment environment) { + return myRollbackWrapper.createProxy(key, environment); + } + + private static class Wrapper { + private final Map myListenersMap; + private final Map> myExistingMulticasters; + private final Class myClazz; + private final Object myLock; + private static final Logger LOG = Logger.getInstance("#com.intellij.openapi.vcs.impl.VcsEventsListenerManagerImpl.Wrapper"); + + private Wrapper(final Class clazz) { + myClazz = clazz; + myListenersMap = new HashMap(); + myExistingMulticasters = Collections.synchronizedMap(new HashMap>()); + myLock = new Object(); + } + + @Nullable + public T createProxy(final VcsKey key, @Nullable final T environment) { + if (environment == null) return null; + final EventDispatcher eventDispatcher; + synchronized (myLock) { + assert ! myExistingMulticasters.containsKey(key); + eventDispatcher = EventDispatcher.create(EventListenerWrapperI.class); + myExistingMulticasters.put(key, eventDispatcher); + for (EventListenerWrapperI wrapper : myListenersMap.values()) { + eventDispatcher.addListener(wrapper); + } + } + + final T proxy = (T) Proxy.newProxyInstance(myClazz.getClassLoader(), + new Class[]{myClazz}, + new InvocationHandler() { + @Override + public Object invoke(final Object proxy, final Method method, final Object[] args) throws Throwable { + method.setAccessible(true); + synchronized (myLock) { + eventDispatcher.getMulticaster().consume( + new Pair>(key, new Consumer() { + @Override + public void consume(T t) { + try { + method.invoke(t, args); + } + catch (IllegalAccessException e) { + LOG.info(e); + } + catch (InvocationTargetException e) { + LOG.info(e); + } + } + })); + } + return method.invoke(environment, args); + } + }); + + return proxy; + } + + public Object add(final Consumer>> consumer) { + final Object key = new Object(); + synchronized (myLock) { + EventListenerWrapper listenerWrapper = new EventListenerWrapper(consumer); + myListenersMap.put(key, listenerWrapper); + for (EventDispatcher eventDispatcher : myExistingMulticasters.values()) { + eventDispatcher.addListener(listenerWrapper); + } + } + return key; + } + + public void remove(Object key) { + synchronized (myLock) { + final EventListenerWrapperI listenerWrapper = myListenersMap.remove(key); + if (listenerWrapper != null) { + for (EventDispatcher dispatcher : myExistingMulticasters.values()) { + dispatcher.removeListener(listenerWrapper); + } + } + } + } + + private interface EventListenerWrapperI extends Consumer>>, EventListener {} + + private static class EventListenerWrapper implements EventListenerWrapperI { + private final Consumer>> myConsumer; + + public EventListenerWrapper(Consumer>> consumer) { + myConsumer = consumer; + } + + @Override + public void consume(Pair> vcsKeyConsumerPair) { + myConsumer.consume(vcsKeyConsumerPair); + } + } + } +} diff --git a/plugins/InspectionGadgets/src/com/siyeh/InspectionGadgetsBundle.properties b/plugins/InspectionGadgets/src/com/siyeh/InspectionGadgetsBundle.properties index 39ac3f89973e..9aea0ed08ddf 100644 --- a/plugins/InspectionGadgets/src/com/siyeh/InspectionGadgetsBundle.properties +++ b/plugins/InspectionGadgets/src/com/siyeh/InspectionGadgetsBundle.properties @@ -203,10 +203,10 @@ public.method.without.logging.display.name='public' method without logging public.method.without.logging.problem.descriptor='public' method #ref has no logging statement #loc action.reset.telemetry.description=Reset telemetry data -telemetry.table.column.inspection.name=Inspection Name -telemetry.table.column.total.time=Total Run Time (msecs) -telemetry.table.column.average.time=Average Run Time (msecs) -telemetry.table.column.run.count=Total Run Count +telemetry.table.column.inspection.name=Inspection +telemetry.table.column.total.time=Total Run Time (ms) +telemetry.table.column.average.time=Average Run Time (ms) +telemetry.table.column.run.count=Run Count telemetry.toolwindow.title=IG Telemetry action.telemetry.refresh.description=Refresh telemetry display finalize.doesnt.call.super.display.name='finalize()' does not call 'super.finalize()' diff --git a/plugins/InspectionGadgets/src/com/siyeh/ig/psiutils/ImportUtils.java b/plugins/InspectionGadgets/src/com/siyeh/ig/psiutils/ImportUtils.java index 5f6137269533..ec3563362c77 100644 --- a/plugins/InspectionGadgets/src/com/siyeh/ig/psiutils/ImportUtils.java +++ b/plugins/InspectionGadgets/src/com/siyeh/ig/psiutils/ImportUtils.java @@ -535,7 +535,7 @@ public class ImportUtils{ PsiTreeUtil.getParentOfType(context, PsiClass.class); if (InheritanceUtil.isCorrectDescendant(containingClass, memberClass, true)) { - return true; + return false; } final PsiFile psiFile = context.getContainingFile(); if (!(psiFile instanceof PsiJavaFile)) { diff --git a/plugins/InspectionGadgets/src/com/siyeh/ig/telemetry/InspectionGadgetsTelemetry.java b/plugins/InspectionGadgets/src/com/siyeh/ig/telemetry/InspectionGadgetsTelemetry.java index bad05252e5dd..a0f81b205444 100644 --- a/plugins/InspectionGadgets/src/com/siyeh/ig/telemetry/InspectionGadgetsTelemetry.java +++ b/plugins/InspectionGadgets/src/com/siyeh/ig/telemetry/InspectionGadgetsTelemetry.java @@ -15,85 +15,39 @@ */ package com.siyeh.ig.telemetry; -import java.util.Arrays; -import java.util.HashMap; -import java.util.Map; -import java.util.Set; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.concurrent.ConcurrentHashMap; -public class InspectionGadgetsTelemetry implements InspectionRunListener { +public class InspectionGadgetsTelemetry { - private final Map totalRunCount = - new HashMap(400); - private final Map totalRunTime = - new HashMap(400); - private final Object lock = new Object(); + private final ConcurrentHashMap inspectionRunTimes = + new ConcurrentHashMap(); + + public List buildList() { + if (inspectionRunTimes.isEmpty()) { + return Collections.EMPTY_LIST; + } + return new ArrayList(inspectionRunTimes.values()); + } public void reportRun(String inspectionID, long runTime) { - synchronized (lock) { - final Integer count = totalRunCount.get(inspectionID); - if (count == null) { - totalRunCount.put(inspectionID, Integer.valueOf(1)); - } else { - totalRunCount.put(inspectionID, - Integer.valueOf(count.intValue() + 1)); - } - final Long runTimeSoFar = totalRunTime.get(inspectionID); - if (runTimeSoFar == null) { - totalRunTime.put(inspectionID, Long.valueOf(runTime)); - } else { - totalRunTime.put(inspectionID, - Long.valueOf(runTimeSoFar.longValue() + runTime)); + InspectionRunTime inspectionRunTime = + inspectionRunTimes.get(inspectionID); + if (inspectionRunTime == null) { + inspectionRunTime = new InspectionRunTime(inspectionID); + final InspectionRunTime oldValue = + inspectionRunTimes.putIfAbsent(inspectionID, + inspectionRunTime); + if (oldValue != null) { + inspectionRunTime = oldValue; } } + inspectionRunTime.addRunTime(runTime); } public void reset() { - synchronized (lock) { - totalRunCount.clear(); - totalRunTime.clear(); - } - } - - public long getRunTimeForInspection(String inspectionID) { - synchronized (lock) { - final Long runTime = totalRunTime.get(inspectionID); - if (runTime == null) { - return 0L; - } - return runTime.longValue(); - } - } - - public int getRunCountForInspection(String inspectionID) { - synchronized (lock) { - final Integer runCount = totalRunCount.get(inspectionID); - if (runCount == null) { - return 0; - } - return runCount.intValue(); - } - } - - public String[] getInspections() { - synchronized (lock) { - final Set inspections = totalRunCount.keySet(); - final int numInspections = inspections.size(); - final String[] inspectionArray = - inspections.toArray(new String[numInspections]); - Arrays.sort(inspectionArray); - return inspectionArray; - } - } - - public double getAverageRunTimeForInspection(String inspectionID) { - synchronized (lock) { - final Integer runCount = totalRunCount.get(inspectionID); - if (runCount == null) { - return 0.0; - } - final Long runTime = totalRunTime.get(inspectionID); - - return (double)runTime / (double)runCount; - } + inspectionRunTimes.clear(); } } \ No newline at end of file diff --git a/plugins/InspectionGadgets/src/com/siyeh/ig/telemetry/InspectionRunTime.java b/plugins/InspectionGadgets/src/com/siyeh/ig/telemetry/InspectionRunTime.java new file mode 100644 index 000000000000..639a468baf8c --- /dev/null +++ b/plugins/InspectionGadgets/src/com/siyeh/ig/telemetry/InspectionRunTime.java @@ -0,0 +1,57 @@ +/* + * Copyright 2010 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.telemetry; + +public class InspectionRunTime { + + private final String inspectionName; + + private long totalRunTime = 0L; + private int runCount = 0; + + public InspectionRunTime(String inspectionName) { + this.inspectionName = inspectionName; + } + + public void addRunTime(long runTime) { + synchronized (this) { + totalRunTime += runTime; + runCount++; + } + } + + public double getAverageRunTime() { + synchronized (this) { + return (double) totalRunTime / (double) runCount; + } + } + + public String getInspectionName() { + return inspectionName; + } + + public int getRunCount() { + synchronized (this) { + return runCount; + } + } + + public long getTotalRunTime() { + synchronized (this) { + return totalRunTime; + } + } +} diff --git a/plugins/InspectionGadgets/src/com/siyeh/ig/telemetry/ResetTelemetryAction.java b/plugins/InspectionGadgets/src/com/siyeh/ig/telemetry/ResetTelemetryAction.java index 24f47ca5b430..163a753d40af 100644 --- a/plugins/InspectionGadgets/src/com/siyeh/ig/telemetry/ResetTelemetryAction.java +++ b/plugins/InspectionGadgets/src/com/siyeh/ig/telemetry/ResetTelemetryAction.java @@ -27,7 +27,7 @@ class ResetTelemetryAction extends AnAction{ private final TelemetryDisplay display; ResetTelemetryAction(InspectionGadgetsTelemetry telemetry, - TelemetryDisplay display){ + TelemetryDisplay display){ super(CommonBundle.message("button.reset"), InspectionGadgetsBundle.message( "action.reset.telemetry.description"), @@ -39,6 +39,6 @@ class ResetTelemetryAction extends AnAction{ @Override public void actionPerformed(AnActionEvent event){ telemetry.reset(); - display.update(); + display.update(telemetry.buildList()); } } \ No newline at end of file diff --git a/plugins/InspectionGadgets/src/com/siyeh/ig/telemetry/TableSorter.java b/plugins/InspectionGadgets/src/com/siyeh/ig/telemetry/TableSorter.java deleted file mode 100644 index 07ac3cb05baa..000000000000 --- a/plugins/InspectionGadgets/src/com/siyeh/ig/telemetry/TableSorter.java +++ /dev/null @@ -1,485 +0,0 @@ -/* - * Copyright 2000-2009 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.telemetry; - -import javax.swing.Icon; -import javax.swing.JLabel; -import javax.swing.JTable; -import javax.swing.event.TableModelEvent; -import javax.swing.event.TableModelListener; -import javax.swing.table.*; -import java.awt.Color; -import java.awt.Component; -import java.awt.Graphics; -import java.awt.Font; -import java.awt.event.MouseAdapter; -import java.awt.event.MouseEvent; -import java.awt.event.MouseListener; -import java.util.*; - -/** - * TableSorter is a decorator for TableModels; adding sorting - * functionality to a supplied TableModel. TableSorter does - * not store or copy the data in its TableModel; instead it maintains - * a map from the row indexes of the view to the row indexes of the - * model. As requests are made of the sorter (like getValueAt(row, col)) - * they are passed to the underlying model after the row numbers - * have been translated via the internal mapping array. This way, - * the TableSorter appears to hold another copy of the table - * with the rows in a different order. - *

- * TableSorter registers itself as a listener to the underlying model, - * just as the JTable itself would. Events recieved from the model - * are examined, sometimes manipulated (typically widened), and then - * passed on to the TableSorter's listeners (typically the JTable). - * If a change to the model has invalidated the order of TableSorter's - * rows, a note of this is made and the sorter will resort the - * rows the next time a value is requested. - *

- * When the tableHeader property is set, either by using the - * setTableHeader() method or the two argument constructor, the - * table header may be used as a complete UI for TableSorter. - * The default renderer of the tableHeader is decorated with a renderer - * that indicates the sorting status of each column. In addition, - * a mouse listener is installed with the following behavior: - *

    - *
  • - * Mouse-click: Clears the sorting status of all other columns - * and advances the sorting status of that column through three - * values: {NOT_SORTED, ASCENDING, DESCENDING} (then back to - * NOT_SORTED again). - *
  • - * SHIFT-mouse-click: Clears the sorting status of all other columns - * and cycles the sorting status of the column through the same - * three values, in the opposite order: {NOT_SORTED, DESCENDING, ASCENDING}. - *
  • - * CONTROL-mouse-click and CONTROL-SHIFT-mouse-click: as above except - * that the changes to the column do not cancel the statuses of columns - * that are already sorting - giving a way to initiate a compound - * sort. - *
- *

- * This is a long overdue rewrite of a class of the same name that - * first appeared in the swing table demos in 1997. - * - * @author Philip Milne - * @author Brendon McLean - * @author Dan van Enckevort - * @author Parwinder Sekhon - * @version 2.0 02/27/04 - */ - -public class TableSorter extends AbstractTableModel { - - protected TableModel tableModel = null; - - public static final int DESCENDING = -1; - public static final int NOT_SORTED = 0; - public static final int ASCENDING = 1; - - private static final Directive EMPTY_DIRECTIVE = new Directive(-1, NOT_SORTED); - - public static final Comparator COMPARABLE_COMPARATOR = new Comparator() { - public int compare(Comparable c1, Comparable c2) { - return c1.compareTo(c2); - } - }; - public static final Comparator LEXICAL_COMPARATOR = new Comparator() { - public int compare(Object o1, Object o2) { - return o1.toString().compareTo(o2.toString()); - } - }; - - private Row[] viewToModel = null; - int[] modelToView = null; - - private JTableHeader tableHeader = null; - private MouseListener mouseListener; - private TableModelListener tableModelListener; - private final Map columnComparators = new HashMap(); - List sortingColumns = new ArrayList(); - - public TableSorter() { - mouseListener = new MouseHandler(); - tableModelListener = new TableModelHandler(); - } - - public TableSorter(TableModel tableModel) { - this(); - setTableModel(tableModel); - } - - public TableSorter(TableModel tableModel, JTableHeader tableHeader) { - this(); - setTableHeader(tableHeader); - setTableModel(tableModel); - } - - void clearSortingState() { - viewToModel = null; - modelToView = null; - } - - public TableModel getTableModel() { - return tableModel; - } - - public void setTableModel(TableModel tableModel) { - if (this.tableModel != null) { - this.tableModel.removeTableModelListener(tableModelListener); - } - - this.tableModel = tableModel; - if (this.tableModel != null) { - this.tableModel.addTableModelListener(tableModelListener); - } - - clearSortingState(); - fireTableStructureChanged(); - } - - public JTableHeader getTableHeader() { - return tableHeader; - } - - public void setTableHeader(JTableHeader tableHeader) { - if (this.tableHeader != null) { - this.tableHeader.removeMouseListener(mouseListener); - final TableCellRenderer defaultRenderer = - this.tableHeader.getDefaultRenderer(); - if (defaultRenderer instanceof SortableHeaderRenderer) { - final TableCellRenderer tableCellRenderer = - ((SortableHeaderRenderer)defaultRenderer).tableCellRenderer; - this.tableHeader.setDefaultRenderer(tableCellRenderer); - } - } - this.tableHeader = tableHeader; - if (this.tableHeader != null) { - this.tableHeader.addMouseListener(mouseListener); - this.tableHeader.setDefaultRenderer( - new SortableHeaderRenderer(this.tableHeader.getDefaultRenderer())); - } - } - - public boolean isSorting() { - return sortingColumns.size() != 0; - } - - private Directive getDirective(int column) { - for (Directive directive : sortingColumns) { - if (directive.column == column) { - return directive; - } - } - return EMPTY_DIRECTIVE; - } - - public int getSortingStatus(int column) { - return getDirective(column).direction; - } - - private void sortingStatusChanged() { - clearSortingState(); - fireTableDataChanged(); - if (tableHeader != null) { - tableHeader.repaint(); - } - } - - public void setSortingStatus(int column, int status) { - final Directive directive = getDirective(column); - if (directive != EMPTY_DIRECTIVE) { - sortingColumns.remove(directive); - } - if (status != NOT_SORTED) { - sortingColumns.add(new Directive(column, status)); - } - sortingStatusChanged(); - } - - protected Icon getHeaderRendererIcon(int column, int size) { - final Directive directive = getDirective(column); - final int index = sortingColumns.indexOf(directive); - if (index >= 0 && index == sortingColumns.size() - 1) { - return new Arrow(directive.direction == DESCENDING, size); - } else { - return null; - } - } - - void cancelSorting() { - sortingColumns.clear(); - sortingStatusChanged(); - } - - public void setColumnComparator(Class type, Comparator comparator) { - if (comparator == null) { - columnComparators.remove(type); - } else { - columnComparators.put(type, comparator); - } - } - - protected Comparator getComparator(int column) { - final Class columnType = tableModel.getColumnClass(column); - final Comparator comparator = columnComparators.get(columnType); - if (comparator != null) { - return comparator; - } - if (Comparable.class.isAssignableFrom(columnType)) { - return COMPARABLE_COMPARATOR; - } - return LEXICAL_COMPARATOR; - } - - private Row[] getViewToModel() { - if (viewToModel == null || - viewToModel.length != tableModel.getRowCount()) { - final int tableModelRowCount = tableModel.getRowCount(); - viewToModel = new Row[tableModelRowCount]; - for (int row = 0; row < tableModelRowCount; row++) { - viewToModel[row] = new Row(row); - } - if (isSorting()) { - Arrays.sort(viewToModel); - } - } - return viewToModel; - } - - public int modelIndex(int viewIndex) { - return getViewToModel()[viewIndex].modelIndex; - } - - int[] getModelToView() { - if (modelToView == null) { - final int n = getViewToModel().length; - modelToView = new int[n]; - for (int i = 0; i < n; i++) { - modelToView[modelIndex(i)] = i; - } - } - return modelToView; - } - - // TableModel interface methods - - public int getRowCount() { - if (tableModel == null) { - return 0; - } else { - return tableModel.getRowCount(); - } - } - - public int getColumnCount() { - if (tableModel == null) { - return 0; - } else { - return tableModel.getColumnCount(); - } - } - - public String getColumnName(int column) { - return tableModel.getColumnName(column); - } - - public Class getColumnClass(int column) { - return tableModel.getColumnClass(column); - } - - public boolean isCellEditable(int row, int column) { - return tableModel.isCellEditable(modelIndex(row), column); - } - - public Object getValueAt(int row, int column) { - return tableModel.getValueAt(modelIndex(row), column); - } - - public void setValueAt(Object aValue, int row, int column) { - tableModel.setValueAt(aValue, modelIndex(row), column); - } - - // Helper classes - - private class Row implements Comparable { - - int modelIndex; - - Row(int index) { - modelIndex = index; - } - - public int compareTo(Object o) { - final int row1 = modelIndex; - final int row2 = ((Row) o).modelIndex; - - for (Directive directive : sortingColumns) { - final int column = directive.column; - final Object o1 = tableModel.getValueAt(row1, column); - final Object o2 = tableModel.getValueAt(row2, column); - - final int comparison; - // Define null less than everything, except null. - if (o1 == null && o2 == null) { - comparison = 0; - } else if (o1 == null) { - comparison = -1; - } else if (o2 == null) { - comparison = 1; - } else { - final Comparator comparator = getComparator(column); - comparison = comparator.compare(o1, o2); - } - if (comparison != 0) { - if (directive.direction == DESCENDING) { - return -comparison; - } else { - return comparison; - } - } - } - return 0; - } - } - - private class TableModelHandler implements TableModelListener { - public void tableChanged(TableModelEvent e) { - // If we're not sorting by anything, just pass the event along. - if (!isSorting()) { - clearSortingState(); - fireTableChanged(e); - return; - } - - // If the table structure has changed, cancel the sorting; the - // sorting columns may have been either moved or deleted from - // the model. - if (e.getFirstRow() == TableModelEvent.HEADER_ROW) { - cancelSorting(); - fireTableChanged(e); - return; - } - - // Something has happened to the data that may have invalidated the row order. - clearSortingState(); - fireTableDataChanged(); - } - } - - private class MouseHandler extends MouseAdapter { - public void mouseClicked(MouseEvent event) { - final JTableHeader header = (JTableHeader) event.getSource(); - final TableColumnModel columnModel = header.getColumnModel(); - final int viewColumn = columnModel.getColumnIndexAtX(event.getX()); - final TableColumn column = columnModel.getColumn(viewColumn); - final int columnIndex = column.getModelIndex(); - if (columnIndex != -1) { - int status = getSortingStatus(columnIndex); - - // Cycle the sorting states through {NOT_SORTED, ASCENDING, DESCENDING} or - // {NOT_SORTED, DESCENDING, ASCENDING} depending on whether shift is pressed. - if (status == ASCENDING) { - status = DESCENDING; - } else { - status = ASCENDING; - } - setSortingStatus(columnIndex, status); - } - } - } - - private static class Arrow implements Icon { - - private final boolean descending; - private final int size; - - Arrow(boolean descending, int size) { - this.descending = descending; - this.size = size; - } - - public void paintIcon(Component component, Graphics g, int x, int y) { - final Color color; - if (component == null) { - color = Color.GRAY; - } else { - color = component.getBackground(); - } - final int dx = size - 2; - final int dy; - if (descending) { - dy = dx - 2; - } else { - dy = -(dx - 3); - } - // Align icon (roughly) with font baseline. - y += 4 * size / 6; - if (descending) { - y += -dy; - } - g.translate(x, y); - g.setColor(color.darker()); - g.fillPolygon(new int[]{dx >> 1, 0, dx}, new int[]{0, dy, dy}, 3); - g.setColor(color); - g.translate(-x, -y); - } - - public int getIconWidth() { - return size; - } - - public int getIconHeight() { - return size; - } - } - - private class SortableHeaderRenderer implements TableCellRenderer { - - TableCellRenderer tableCellRenderer; - - SortableHeaderRenderer(TableCellRenderer tableCellRenderer) { - this.tableCellRenderer = tableCellRenderer; - } - - public Component getTableCellRendererComponent( - JTable table, Object value, boolean isSelected, - boolean hasFocus, int row, int column) { - final Component component = - tableCellRenderer.getTableCellRendererComponent(table, - value, isSelected, hasFocus, row, column); - if (component instanceof JLabel) { - final JLabel label = (JLabel) component; - label.setHorizontalTextPosition(JLabel.LEADING); - final int modelColumn = table.convertColumnIndexToModel(column); - final Font font = label.getFont(); - label.setIcon(getHeaderRendererIcon(modelColumn, font.getSize())); - } - return component; - } - } - - private static class Directive { - - int column; - int direction; - - Directive(int column, int direction) { - this.column = column; - this.direction = direction; - } - } -} diff --git a/plugins/InspectionGadgets/src/com/siyeh/ig/telemetry/TelemetryDisplay.java b/plugins/InspectionGadgets/src/com/siyeh/ig/telemetry/TelemetryDisplay.java index 7e7eb28c8147..6ea1ab576da4 100644 --- a/plugins/InspectionGadgets/src/com/siyeh/ig/telemetry/TelemetryDisplay.java +++ b/plugins/InspectionGadgets/src/com/siyeh/ig/telemetry/TelemetryDisplay.java @@ -16,31 +16,153 @@ package com.siyeh.ig.telemetry; import com.intellij.ui.ScrollPaneFactory; +import com.intellij.ui.TableSpeedSearch; import com.intellij.ui.table.JBTable; +import com.intellij.util.ui.ColumnInfo; +import com.intellij.util.ui.ListTableModel; +import com.siyeh.InspectionGadgetsBundle; import javax.swing.*; -import javax.swing.table.JTableHeader; +import java.text.NumberFormat; +import java.util.Comparator; +import java.util.List; public class TelemetryDisplay { - private final JTable table; private final JScrollPane scrollPane; - private final TableSorter model; + private final ListTableModel tableModel; public TelemetryDisplay(InspectionGadgetsTelemetry telemetry){ - model = new TableSorter(new TelemetryTableModel(telemetry)); - table = new JBTable(model); - final JTableHeader tableHeader = table.getTableHeader(); - model.setTableHeader(tableHeader); + tableModel = new ListTableModel(createColumns(), + telemetry.buildList(), 0); + final JTable table = new JBTable(tableModel); + new TableSpeedSearch(table); scrollPane = ScrollPaneFactory.createScrollPane(table); } + private static ColumnInfo[] createColumns() { + final Comparator nameComparator = + new Comparator() { + + public int compare(InspectionRunTime runTime1, + InspectionRunTime runTime2) { + return runTime1.getInspectionName().compareToIgnoreCase( + runTime2.getInspectionName()); + } + }; + final Comparator runCountComparator = + new Comparator() { + + public int compare(InspectionRunTime runTime1, + InspectionRunTime runTime2) { + return runTime1.getRunCount() - runTime2.getRunCount(); + } + }; + final Comparator totalRunTimeComparator = + new Comparator() { + + public int compare(InspectionRunTime runTime1, + InspectionRunTime runTime2) { + final long totalRunTime1 = runTime1.getTotalRunTime(); + final long totalRunTime2 = runTime2.getTotalRunTime(); + if (totalRunTime1 < totalRunTime2) { + return -1; + } else if (totalRunTime1 > totalRunTime2) { + return 1; + } else { + return 0; + } + } + }; + final Comparator averageRunTimeComparator = + new Comparator() { + + public int compare(InspectionRunTime runTime1, + InspectionRunTime runTime2) { + final double averageRunTime1 = + runTime1.getAverageRunTime(); + final double averageRunTime2 = + runTime2.getAverageRunTime(); + if (averageRunTime1 < averageRunTime2) { + return -1; + } else if (averageRunTime1 > averageRunTime2) { + return 1; + } else { + return 0; + } + } + }; + return new ColumnInfo[] { + new ColumnInfo( + InspectionGadgetsBundle.message( + "telemetry.table.column.inspection.name")) { + @Override + public String valueOf(InspectionRunTime inspectionRunTime) { + return inspectionRunTime.getInspectionName(); + } + + @Override + public Comparator getComparator() { + return nameComparator; + } + }, + new ColumnInfo( + InspectionGadgetsBundle.message( + "telemetry.table.column.run.count")) { + @Override + public Integer valueOf( + InspectionRunTime inspectionRunTime) { + return Integer.valueOf(inspectionRunTime.getRunCount()); + } + + @Override + public Comparator getComparator() { + return runCountComparator; + } + }, + new ColumnInfo( + InspectionGadgetsBundle.message( + "telemetry.table.column.total.time")) { + @Override + public Long valueOf(InspectionRunTime inspectionRunTime) { + return Long.valueOf( + inspectionRunTime.getTotalRunTime()); + } + + @Override + public Comparator getComparator() { + return totalRunTimeComparator; + } + }, + new ColumnInfo( + InspectionGadgetsBundle.message( + "telemetry.table.column.average.time")) { + + private final NumberFormat format = + NumberFormat.getNumberInstance(); + { + format.setMaximumFractionDigits(2); + format.setMinimumFractionDigits(2); + } + + @Override + public String valueOf(InspectionRunTime inspectionRunTime) { + return format.format(inspectionRunTime.getAverageRunTime()); + } + + @Override + public Comparator getComparator() { + return averageRunTimeComparator; + } + } + }; + } + public JComponent getContentPane(){ return scrollPane; } - public void update(){ - table.setModel(model); - table.repaint(); + public void update(List inspectionRunTimes){ + tableModel.setItems(inspectionRunTimes); } } diff --git a/plugins/InspectionGadgets/src/com/siyeh/ig/telemetry/TelemetryTableModel.java b/plugins/InspectionGadgets/src/com/siyeh/ig/telemetry/TelemetryTableModel.java deleted file mode 100644 index d18a30f20758..000000000000 --- a/plugins/InspectionGadgets/src/com/siyeh/ig/telemetry/TelemetryTableModel.java +++ /dev/null @@ -1,120 +0,0 @@ -/* - * Copyright 2003-2010 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.telemetry; - -import org.jetbrains.annotations.Nullable; - -import javax.swing.table.DefaultTableModel; -import java.text.NumberFormat; - -import com.siyeh.InspectionGadgetsBundle; - -class TelemetryTableModel extends DefaultTableModel { - - private final InspectionGadgetsTelemetry telemetry; - private final NumberFormat format = NumberFormat.getNumberInstance(); - - TelemetryTableModel(InspectionGadgetsTelemetry telemetry) { - this.telemetry = telemetry; - format.setMaximumFractionDigits(2); - format.setMinimumFractionDigits(2); - } - - @Override - public int getColumnCount() { - return 4; - } - - @Override - @Nullable - public Class getColumnClass(int column) { - switch (column) { - case 0: - return String.class; - case 1: - return Long.class; - case 2: - return String.class; - case 3: - return Integer.class; - default: - return null; - } - } - - @Override - public int getRowCount() { - if (telemetry == null) { - return 0; - } - return telemetry.getInspections().length; - } - - @Override - @Nullable - public Object getValueAt(int row, int column) { - if (telemetry == null) { - return null; - } - final String[] inspections = telemetry.getInspections(); - final String inspection = inspections[row]; - switch (column) { - case 0: - return inspection; - case 1: - final long totalRunTime = - telemetry.getRunTimeForInspection(inspection); - return Long.valueOf(totalRunTime); - case 2: - final double averageRunTime = - telemetry.getAverageRunTimeForInspection(inspection); - return format.format(averageRunTime); - case 3: - final int runCount = - telemetry.getRunCountForInspection(inspection); - return Integer.valueOf(runCount); - default: - return null; - } - } - - @Override - public void setValueAt(Object object, int i, - int i1) { - //don't do anything - } - - @Override - @Nullable - public String getColumnName(int column) { - switch (column) { - case 0: - return InspectionGadgetsBundle.message( - "telemetry.table.column.inspection.name"); - case 1: - return InspectionGadgetsBundle.message( - "telemetry.table.column.total.time"); - case 2: - return InspectionGadgetsBundle.message( - "telemetry.table.column.average.time"); - case 3: - return InspectionGadgetsBundle.message( - "telemetry.table.column.run.count"); - default: - return null; - } - } -} \ No newline at end of file diff --git a/plugins/InspectionGadgets/src/com/siyeh/ig/telemetry/TelemetryToolWindow.java b/plugins/InspectionGadgets/src/com/siyeh/ig/telemetry/TelemetryToolWindow.java index 9f5d26279002..686cb36ea175 100644 --- a/plugins/InspectionGadgets/src/com/siyeh/ig/telemetry/TelemetryToolWindow.java +++ b/plugins/InspectionGadgets/src/com/siyeh/ig/telemetry/TelemetryToolWindow.java @@ -42,7 +42,8 @@ public class TelemetryToolWindow { final TelemetryDisplay telemetryDisplay = new TelemetryDisplay(telemetry); final DefaultActionGroup toolbarGroup = new DefaultActionGroup(); - toolbarGroup.add(new UpdateTelemetryViewAction(telemetryDisplay)); + toolbarGroup.add( + new UpdateTelemetryViewAction(telemetry, telemetryDisplay)); toolbarGroup.add(new ResetTelemetryAction(telemetry, telemetryDisplay)); final ActionManager actionManager = ActionManager.getInstance(); final ActionToolbar toolbar = diff --git a/plugins/InspectionGadgets/src/com/siyeh/ig/telemetry/UpdateTelemetryViewAction.java b/plugins/InspectionGadgets/src/com/siyeh/ig/telemetry/UpdateTelemetryViewAction.java index 6d920a290691..8524854cea70 100644 --- a/plugins/InspectionGadgets/src/com/siyeh/ig/telemetry/UpdateTelemetryViewAction.java +++ b/plugins/InspectionGadgets/src/com/siyeh/ig/telemetry/UpdateTelemetryViewAction.java @@ -23,18 +23,21 @@ import com.siyeh.InspectionGadgetsBundle; class UpdateTelemetryViewAction extends AnAction{ + private final InspectionGadgetsTelemetry telemetry; private final TelemetryDisplay telemetryDisplay; - UpdateTelemetryViewAction(TelemetryDisplay telemetryDisplay){ + UpdateTelemetryViewAction(InspectionGadgetsTelemetry telemetry, + TelemetryDisplay telemetryDisplay){ super(CommonBundle.message("action.refresh"), InspectionGadgetsBundle.message( "action.telemetry.refresh.description"), IconLoader.getIcon("/actions/sync.png")); + this.telemetry = telemetry; this.telemetryDisplay = telemetryDisplay; } @Override public void actionPerformed(AnActionEvent event){ - telemetryDisplay.update(); + telemetryDisplay.update(telemetry.buildList()); } } \ No newline at end of file diff --git a/plugins/android/src/org/jetbrains/android/AndroidRenameResourceProcessor.java b/plugins/android/src/org/jetbrains/android/AndroidRenameResourceProcessor.java index 084e1803fb18..2355fcc3366a 100644 --- a/plugins/android/src/org/jetbrains/android/AndroidRenameResourceProcessor.java +++ b/plugins/android/src/org/jetbrains/android/AndroidRenameResourceProcessor.java @@ -47,6 +47,7 @@ import org.jetbrains.android.resourceManagers.LocalResourceManager; import org.jetbrains.android.resourceManagers.ResourceManager; import org.jetbrains.android.util.AndroidBundle; import org.jetbrains.android.util.AndroidResourceUtil; +import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import java.util.ArrayList; @@ -62,7 +63,7 @@ public class AndroidRenameResourceProcessor extends RenamePsiElementProcessor { // for tests public static volatile boolean ASK = true; - public boolean canProcessElement(final PsiElement element) { + public boolean canProcessElement(@NotNull final PsiElement element) { return ApplicationManager.getApplication().runReadAction(new Computable() { public Boolean compute() { if (element instanceof PsiFile) { diff --git a/plugins/ant/src/com/intellij/lang/ant/dom/AntRenameProcessor.java b/plugins/ant/src/com/intellij/lang/ant/dom/AntRenameProcessor.java index 95df74e528cc..f32238692923 100644 --- a/plugins/ant/src/com/intellij/lang/ant/dom/AntRenameProcessor.java +++ b/plugins/ant/src/com/intellij/lang/ant/dom/AntRenameProcessor.java @@ -22,6 +22,7 @@ import com.intellij.psi.PsiElement; import com.intellij.refactoring.rename.RenamePsiElementProcessor; import com.intellij.util.xml.DomElement; import com.intellij.util.xml.DomTarget; +import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import java.util.Collection; @@ -58,7 +59,7 @@ public class AntRenameProcessor extends RenamePsiElementProcessor{ } } - public boolean canProcessElement(PsiElement element) { + public boolean canProcessElement(@NotNull PsiElement element) { final AntDomElement antElement = convertToAntDomElement(element); if (antElement instanceof AntDomProperty || antElement instanceof AntDomAntCallParam) { return true; diff --git a/plugins/copyright/src/com/maddyhome/idea/copyright/util/FileTypeUtil.java b/plugins/copyright/src/com/maddyhome/idea/copyright/util/FileTypeUtil.java index f9559579f0fa..05af2c44951d 100644 --- a/plugins/copyright/src/com/maddyhome/idea/copyright/util/FileTypeUtil.java +++ b/plugins/copyright/src/com/maddyhome/idea/copyright/util/FileTypeUtil.java @@ -16,6 +16,7 @@ package com.maddyhome.idea.copyright.util; +import com.intellij.ide.impl.ProjectUtil; import com.intellij.lang.Commenter; import com.intellij.lang.LanguageCommenters; import com.intellij.openapi.diagnostic.Logger; @@ -28,7 +29,6 @@ import com.maddyhome.idea.copyright.CopyrightUpdaters; import com.maddyhome.idea.copyright.options.LanguageOptions; import java.util.*; -import java.util.regex.Matcher; public class FileTypeUtil { @@ -226,6 +226,7 @@ public class FileTypeUtil return false; } + if (ProjectUtil.isProjectOrWorkspaceFile(file)) return false; FileType type = FileTypeManager.getInstance().getFileTypeByFile(file); return types.get(type.getName()) != null; @@ -237,7 +238,9 @@ public class FileTypeUtil { return false; } - + final VirtualFile virtualFile = file.getVirtualFile(); + if (virtualFile == null) return false; + if (ProjectUtil.isProjectOrWorkspaceFile(virtualFile)) return false; return isSupportedType(file.getFileType()); } diff --git a/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/CvsVcs2.java b/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/CvsVcs2.java index f7f9319a5bb3..89de8f83eb02 100644 --- a/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/CvsVcs2.java +++ b/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/CvsVcs2.java @@ -265,11 +265,11 @@ public class CvsVcs2 extends AbstractVcs implements TransactionProvider, EditFil } @NotNull - public CheckinEnvironment getCheckinEnvironment() { + public CheckinEnvironment createCheckinEnvironment() { return myCvsCheckinEnvironment; } - public RollbackEnvironment getRollbackEnvironment() { + public RollbackEnvironment createRollbackEnvironment() { if (myCvsRollbackEnvironment == null) { myCvsRollbackEnvironment = new CvsRollbackEnvironment(myProject); } @@ -289,7 +289,7 @@ public class CvsVcs2 extends AbstractVcs implements TransactionProvider, EditFil return CvsBundle.message("menu.text.cvsGroup"); } - public UpdateEnvironment getUpdateEnvironment() { + public UpdateEnvironment createUpdateEnvironment() { return myCvsUpdateEnvironment; } diff --git a/plugins/git4idea/src/git4idea/GitVcs.java b/plugins/git4idea/src/git4idea/GitVcs.java index 6ddbeb88dc0b..95de9e110c94 100644 --- a/plugins/git4idea/src/git4idea/GitVcs.java +++ b/plugins/git4idea/src/git4idea/GitVcs.java @@ -230,7 +230,7 @@ public class GitVcs extends AbstractVcs { @Override @NotNull - public CheckinEnvironment getCheckinEnvironment() { + public CheckinEnvironment createCheckinEnvironment() { return myCheckinEnvironment; } @@ -242,7 +242,7 @@ public class GitVcs extends AbstractVcs { @Override @NotNull - public RollbackEnvironment getRollbackEnvironment() { + public RollbackEnvironment createRollbackEnvironment() { return myRollbackEnvironment; } @@ -265,7 +265,7 @@ public class GitVcs extends AbstractVcs { @Override @Nullable - public UpdateEnvironment getUpdateEnvironment() { + public UpdateEnvironment createUpdateEnvironment() { return myUpdateEnvironment; } diff --git a/plugins/git4idea/src/git4idea/checkin/GitCheckinEnvironment.java b/plugins/git4idea/src/git4idea/checkin/GitCheckinEnvironment.java index 564360e240dd..69abc82031d8 100644 --- a/plugins/git4idea/src/git4idea/checkin/GitCheckinEnvironment.java +++ b/plugins/git4idea/src/git4idea/checkin/GitCheckinEnvironment.java @@ -30,6 +30,7 @@ import com.intellij.openapi.vcs.changes.VcsDirtyScopeManager; import com.intellij.openapi.vcs.checkin.CheckinEnvironment; import com.intellij.openapi.vcs.ui.RefreshableOnComponent; import com.intellij.openapi.vfs.VirtualFile; +import com.intellij.ui.GuiUtils; import com.intellij.util.NullableFunction; import com.intellij.util.PairConsumer; import com.intellij.util.containers.ContainerUtil; @@ -48,31 +49,11 @@ import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import javax.swing.JCheckBox; -import javax.swing.JComboBox; -import javax.swing.JComponent; -import javax.swing.JLabel; -import javax.swing.JPanel; -import java.awt.EventQueue; -import java.awt.GridBagConstraints; -import java.awt.GridBagLayout; -import java.awt.Insets; -import java.io.File; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.OutputStreamWriter; -import java.io.Writer; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.Collections; -import java.util.HashMap; -import java.util.HashSet; +import javax.swing.*; +import java.awt.*; +import java.io.*; +import java.util.*; import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.StringTokenizer; -import java.util.TreeSet; /** * Git environment for commit operations. @@ -266,14 +247,14 @@ public class GitCheckinEnvironment implements CheckinEnvironment { if (line.length() == 0) { continue; } - String[] tk = line.split("[ \t]+"); + String[] tk = line.split("\t"); switch (tk[0].charAt(0)) { case 'M': case 'A': - realAdded.add(VcsUtil.getFilePath(rootPath + "/" + tk[tk.length - 1])); + realAdded.add(VcsUtil.getFilePath(rootPath + "/" + tk[1])); break; case 'D': - realRemoved.add(VcsUtil.getFilePathForDeletedFile(rootPath + "/" + tk[tk.length - 1], false)); + realRemoved.add(VcsUtil.getFilePathForDeletedFile(rootPath + "/" + tk[1], false)); break; default: throw new IllegalStateException("Unexpected status: " + line); @@ -298,11 +279,10 @@ public class GitCheckinEnvironment implements CheckinEnvironment { } final int[] rc = new int[1]; try { - EventQueue.invokeAndWait(new Runnable() { + GuiUtils.runOrInvokeAndWait(new Runnable() { public void run() { rc[0] = Messages.showOkCancelDialog(project, GitBundle.message("commit.partial.merge.message", fileList.toString()), GitBundle.getString("commit.partial.merge.title"), null); - } }); } diff --git a/plugins/git4idea/src/git4idea/vfs/GitVFSListener.java b/plugins/git4idea/src/git4idea/vfs/GitVFSListener.java index 452a307ddd6e..61d175b758e0 100644 --- a/plugins/git4idea/src/git4idea/vfs/GitVFSListener.java +++ b/plugins/git4idea/src/git4idea/vfs/GitVFSListener.java @@ -148,14 +148,14 @@ public class GitVFSListener extends VcsVFSListener { }); } } - addedFiles.retainAll(retainedFiles); - UIUtil.invokeLaterIfNeeded(new Runnable() { - @Override - public void run() { - originalExecuteAdd(addedFiles, copiedFiles); - } - }); } + addedFiles.retainAll(retainedFiles); + UIUtil.invokeLaterIfNeeded(new Runnable() { + @Override + public void run() { + originalExecuteAdd(addedFiles, copiedFiles); + } + }); } }); } diff --git a/plugins/git4idea/tests/git4idea/tests/ChangeListManagerUpdateOnFileChangeTest.java b/plugins/git4idea/tests/git4idea/tests/ChangeListManagerUpdateOnFileChangeTest.java index c64512dc9033..c7aeccb90fbb 100644 --- a/plugins/git4idea/tests/git4idea/tests/ChangeListManagerUpdateOnFileChangeTest.java +++ b/plugins/git4idea/tests/git4idea/tests/ChangeListManagerUpdateOnFileChangeTest.java @@ -37,7 +37,7 @@ import static org.testng.Assert.assertTrue; * TODO: This shouldn't rely on Git. Either test all version controls, either test a mock version control. Or even use both approaches. * @author Kirill Likhodedov */ -public class ChangeListManagerUpdateOnFileChangeTest extends GitSingleUserTestCase { +public class ChangeListManagerUpdateOnFileChangeTest extends GitSingleUserTest { private ChangeListManagerImpl myChangeListManager; private VirtualFile afile; diff --git a/plugins/git4idea/tests/git4idea/tests/GitBranchTest.java b/plugins/git4idea/tests/git4idea/tests/GitBranchTest.java index ccc72d192662..d11f58419973 100644 --- a/plugins/git4idea/tests/git4idea/tests/GitBranchTest.java +++ b/plugins/git4idea/tests/git4idea/tests/GitBranchTest.java @@ -29,7 +29,7 @@ import static org.testng.Assert.*; /** * @author Kirill Likhodedov */ -public class GitBranchTest extends GitCollaborativeTestCase { +public class GitBranchTest extends GitCollaborativeTest { private List myBranches; private VirtualFile myDir; diff --git a/plugins/git4idea/tests/git4idea/tests/GitChangeProviderTest.java b/plugins/git4idea/tests/git4idea/tests/GitChangeProviderTest.java index 985a7c2ef010..e89f1b3ba746 100644 --- a/plugins/git4idea/tests/git4idea/tests/GitChangeProviderTest.java +++ b/plugins/git4idea/tests/git4idea/tests/GitChangeProviderTest.java @@ -45,7 +45,7 @@ import static org.testng.Assert.*; * 3. Calls ChangeProvider.getChanges() and checks that the changes are there. * @author Kirill Likhodedov */ -public class GitChangeProviderTest extends GitSingleUserTestCase { +public class GitChangeProviderTest extends GitSingleUserTest { private GitChangeProvider myChangeProvider; private VcsModifiableDirtyScope myDirtyScope; diff --git a/plugins/git4idea/tests/git4idea/tests/GitCollaborativeTestCase.java b/plugins/git4idea/tests/git4idea/tests/GitCollaborativeTest.java similarity index 96% rename from plugins/git4idea/tests/git4idea/tests/GitCollaborativeTestCase.java rename to plugins/git4idea/tests/git4idea/tests/GitCollaborativeTest.java index 382106f862a9..c572a20f2c74 100644 --- a/plugins/git4idea/tests/git4idea/tests/GitCollaborativeTestCase.java +++ b/plugins/git4idea/tests/git4idea/tests/GitCollaborativeTest.java @@ -19,7 +19,7 @@ package git4idea.tests; * * @author Kirill Likhodedov */ -public class GitCollaborativeTestCase extends GitTestCase { +public class GitCollaborativeTest extends GitTest { public static final String MAIN_USER_NAME = "John Smith"; public static final String MAIN_USER_EMAIL = "john.smith@email.com"; public static final String BROTHER_USER_NAME = "Bob Doe"; diff --git a/plugins/git4idea/tests/git4idea/tests/GitHistoryUtilsTestCase.java b/plugins/git4idea/tests/git4idea/tests/GitHistoryUtilsTest.java similarity index 99% rename from plugins/git4idea/tests/git4idea/tests/GitHistoryUtilsTestCase.java rename to plugins/git4idea/tests/git4idea/tests/GitHistoryUtilsTest.java index 9bf872e10951..ee9912245565 100644 --- a/plugins/git4idea/tests/git4idea/tests/GitHistoryUtilsTestCase.java +++ b/plugins/git4idea/tests/git4idea/tests/GitHistoryUtilsTest.java @@ -48,7 +48,7 @@ import static org.testng.Assert.*; * * @author Kirill Likhodedov */ -public class GitHistoryUtilsTestCase extends GitSingleUserTestCase { +public class GitHistoryUtilsTest extends GitSingleUserTest { private VirtualFile afile; private FilePath bfilePath; diff --git a/plugins/git4idea/tests/git4idea/tests/GitMergeTest.java b/plugins/git4idea/tests/git4idea/tests/GitMergeTest.java new file mode 100644 index 000000000000..4658dd54b56b --- /dev/null +++ b/plugins/git4idea/tests/git4idea/tests/GitMergeTest.java @@ -0,0 +1,76 @@ +/* + * Copyright 2000-2010 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 git4idea.tests; + +import com.intellij.openapi.application.ApplicationManager; +import com.intellij.openapi.application.ModalityState; +import com.intellij.openapi.vcs.changes.Change; +import com.intellij.openapi.vcs.changes.ChangeListManager; +import com.intellij.openapi.vcs.changes.LocalChangeList; +import org.testng.annotations.Test; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.concurrent.atomic.AtomicBoolean; + +import static org.testng.Assert.assertTrue; + +/** + * @author Kirill Likhodedov + */ +public class GitMergeTest extends GitCollaborativeTest { + + /** + * Tests that merge commit after resolving a conflict works fine if there is a file with spaces in its path. + * IDEA-50318 + */ + @Test + public void testMergeCommitWithSpacesInPath() throws IOException { + final String PATH = "dir with spaces/file with spaces.txt"; + GitTestUtil.createFileStructure(myProject, myRepo, PATH); + myRepo.commit(); + myRepo.push("origin", "master"); + editFileInCommand(myRepo.getDir().findFileByRelativePath(PATH), "my content"); + myRepo.addCommit(); + + myBrotherRepo.pull(); + editFileInCommand(myBrotherRepo.getDir().findFileByRelativePath(PATH), "brother content"); + myBrotherRepo.addCommit(); + myBrotherRepo.push(); + + myRepo.pull(); + editFileInCommand(myRepo.getDir().findFileByRelativePath(PATH), "my and brother content"); // manually resolving conflict + myRepo.add(); + + final ChangeListManager changeListManager = ChangeListManager.getInstance(myProject); + changeListManager.ensureUpToDate(false); + final LocalChangeList changeList = changeListManager.getDefaultChangeList(); + changeList.setName("Name"); + changeList.setComment("Commit message"); + final AtomicBoolean res = new AtomicBoolean(); + ApplicationManager.getApplication().invokeAndWait(new Runnable() { + @Override + public void run() { + res.set(changeListManager.commitChangesSynchronouslyWithResult(changeList, new ArrayList( + changeListManager.getChangesIn(myRepo.getDir())))); + } + }, ModalityState.defaultModalityState()); + assertTrue(res.get()); + changeListManager.ensureUpToDate(false); + assertTrue(changeListManager.getChangesIn(myRepo.getDir()).isEmpty()); + } + +} diff --git a/plugins/git4idea/tests/git4idea/tests/GitSingleUserTestCase.java b/plugins/git4idea/tests/git4idea/tests/GitSingleUserTest.java similarity index 95% rename from plugins/git4idea/tests/git4idea/tests/GitSingleUserTestCase.java rename to plugins/git4idea/tests/git4idea/tests/GitSingleUserTest.java index 89e65d1aba36..dc5610400664 100644 --- a/plugins/git4idea/tests/git4idea/tests/GitSingleUserTestCase.java +++ b/plugins/git4idea/tests/git4idea/tests/GitSingleUserTest.java @@ -18,7 +18,7 @@ package git4idea.tests; /** * @author Kirill Likhodedov */ -public class GitSingleUserTestCase extends GitTestCase { +public class GitSingleUserTest extends GitTest { public static final String CONFIG_USER_NAME = "John Smith"; public static final String CONFIG_USER_EMAIL = "john.smith@email.com"; diff --git a/plugins/git4idea/tests/git4idea/tests/GitTestCase.java b/plugins/git4idea/tests/git4idea/tests/GitTest.java similarity index 94% rename from plugins/git4idea/tests/git4idea/tests/GitTestCase.java rename to plugins/git4idea/tests/git4idea/tests/GitTest.java index f7998aaa99ce..dad816cc5734 100644 --- a/plugins/git4idea/tests/git4idea/tests/GitTestCase.java +++ b/plugins/git4idea/tests/git4idea/tests/GitTest.java @@ -27,8 +27,8 @@ import org.jetbrains.annotations.Nullable; import org.testng.annotations.AfterMethod; import org.testng.annotations.BeforeMethod; -import javax.swing.SwingUtilities; -import java.awt.EventQueue; +import javax.swing.*; +import java.awt.*; import java.io.File; import java.io.IOException; @@ -38,7 +38,7 @@ import java.io.IOException; * contains git executable. * @author Kirill Likhodedov */ -public abstract class GitTestCase extends AbstractVcsTestCase { +public abstract class GitTest extends AbstractVcsTestCase { public static final String GIT_EXECUTABLE_PATH = "IDEA_TEST_GIT_EXECUTABLE_PATH"; @@ -84,7 +84,7 @@ public abstract class GitTestCase extends AbstractVcsTestCase { } /** - * Different implementations for {@link git4idea.tests.GitSingleUserTestCase} and {@link git4idea.tests.GitCollaborativeTestCase}: + * Different implementations for {@link GitSingleUserTest} and {@link GitCollaborativeTest}: * create a single or several repositories, which will be used in tests. * @return main repository which IDEA project will be bound to. */ diff --git a/plugins/git4idea/tests/git4idea/tests/GitTestRepository.java b/plugins/git4idea/tests/git4idea/tests/GitTestRepository.java index 3cdaa2b2f3b0..54e069b312da 100644 --- a/plugins/git4idea/tests/git4idea/tests/GitTestRepository.java +++ b/plugins/git4idea/tests/git4idea/tests/GitTestRepository.java @@ -37,27 +37,27 @@ import static org.testng.Assert.fail; * @author Kirill Likhodedov */ public class GitTestRepository { - @NotNull private final GitTestCase myTest; + @NotNull private final GitTest myTest; @NotNull private final TempDirTestFixture myDirFixture; private VirtualFile myDir; - public GitTestRepository(@NotNull GitTestCase test, @NotNull TempDirTestFixture fixture) { + public GitTestRepository(@NotNull GitTest test, @NotNull TempDirTestFixture fixture) { myTest = test; myDirFixture = fixture; } /** * Creates a new Mercurial repository in a new temporary test directory. - * @param testCase reference to the test case instance. + * @param test reference to the test case instance. * @param parameters optional array of parameters passed to 'git init' * @return created repository. */ - public static GitTestRepository create(GitTestCase testCase, String... parameters) throws Exception { + public static GitTestRepository create(GitTest test, String... parameters) throws Exception { final TempDirTestFixture dirFixture = createFixtureDir(); final File repo = new File(dirFixture.getTempDirPath()); - final ProcessOutput processOutput = testCase.executeCommand(repo, join("init", parameters)); + final ProcessOutput processOutput = test.executeCommand(repo, join("init", parameters)); AbstractVcsTestCase.verify(processOutput); - return new GitTestRepository(testCase, dirFixture); + return new GitTestRepository(test, dirFixture); } public static GitTestRepository cloneFrom(GitTestRepository parent) throws Exception { @@ -307,7 +307,7 @@ public class GitTestRepository { } @NotNull - public GitTestCase getTest() { + public GitTest getTest() { return myTest; } } diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/codeInspection/assignment/GroovyAssignabilityCheckInspection.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/codeInspection/assignment/GroovyAssignabilityCheckInspection.java index bcc9d6603d2e..ff504996c2b6 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/codeInspection/assignment/GroovyAssignabilityCheckInspection.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/codeInspection/assignment/GroovyAssignabilityCheckInspection.java @@ -43,6 +43,7 @@ import org.jetbrains.plugins.groovy.lang.psi.api.statements.blocks.GrOpenBlock; import org.jetbrains.plugins.groovy.lang.psi.api.statements.branch.GrReturnStatement; import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.*; import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrAccessorMethod; +import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrBuilderMethod; import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrMethod; import org.jetbrains.plugins.groovy.lang.psi.api.types.GrCodeReferenceElement; import org.jetbrains.plugins.groovy.lang.psi.controlFlow.Instruction; @@ -336,6 +337,7 @@ public class GroovyAssignabilityCheckInspection extends BaseInspection { private boolean checkMethodApplicability(GroovyResolveResult methodResolveResult, GroovyPsiElement place) { final PsiElement element = methodResolveResult.getElement(); if (!(element instanceof PsiMethod)) return true; + if (element instanceof GrBuilderMethod) return true; final PsiMethod method = (PsiMethod)element; PsiType[] argumentTypes = PsiUtil.getArgumentTypes(place, true); diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/codeInspection/unusedDef/UnusedDefInspection.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/codeInspection/unusedDef/UnusedDefInspection.java index 2f450f234a6d..c6cec4247bfe 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/codeInspection/unusedDef/UnusedDefInspection.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/codeInspection/unusedDef/UnusedDefInspection.java @@ -19,6 +19,7 @@ import com.intellij.codeInspection.ProblemHighlightType; import com.intellij.codeInspection.ProblemsHolder; import com.intellij.openapi.diagnostic.Logger; import com.intellij.psi.PsiElement; +import com.intellij.psi.PsiFile; import com.intellij.psi.PsiReference; import com.intellij.psi.impl.DebugUtil; import com.intellij.psi.search.LocalSearchScope; @@ -156,7 +157,10 @@ public class UnusedDefInspection extends GroovyLocalInspectionBase { if (var != null) { final GroovyPsiElement scope = getScope(var); - LOG.assertTrue(scope != null, DebugUtil.psiToString(var.getContainingFile(), true, false)); + if (scope == null) { + PsiFile file = var.getContainingFile(); + LOG.error(file == null ? "no file???" : DebugUtil.psiToString(file, true, false)); + } return ReferencesSearch.search(var, new LocalSearchScope(scope)).forEach(new Processor() { public boolean process(PsiReference ref) { diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/dsl/GroovyDslAnnotator.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/dsl/GroovyDslAnnotator.java index bad1e095378a..7e8257080ba5 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/dsl/GroovyDslAnnotator.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/dsl/GroovyDslAnnotator.java @@ -20,7 +20,9 @@ import com.intellij.codeInsight.intention.IntentionAction; import com.intellij.lang.annotation.Annotation; import com.intellij.lang.annotation.AnnotationHolder; import com.intellij.lang.annotation.Annotator; +import com.intellij.openapi.editor.Document; import com.intellij.openapi.editor.Editor; +import com.intellij.openapi.fileEditor.FileDocumentManager; import com.intellij.openapi.project.Project; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.psi.PsiElement; @@ -37,7 +39,9 @@ public class GroovyDslAnnotator implements Annotator { public void annotate(@NotNull PsiElement psiElement, @NotNull AnnotationHolder holder) { if (psiElement instanceof GroovyFile) { final VirtualFile vfile = ((GroovyFile)psiElement).getVirtualFile(); - if (vfile != null && "gdsl".equals(vfile.getExtension()) && !GroovyDslFileIndex.isActivated(vfile)) { + Document document = ((GroovyFile)psiElement).getViewProvider().getDocument(); + if (vfile != null && "gdsl".equals(vfile.getExtension()) && + (!GroovyDslFileIndex.isActivated(vfile) || document != null && FileDocumentManager.getInstance().isDocumentUnsaved(document))) { final Annotation annotation = holder.createWarningAnnotation(psiElement, "DSL descriptor file has been changed and isn't currently executed. Click to activate it back."); annotation.setFileLevelAnnotation(true); annotation.registerFix(new IntentionAction() { @@ -56,6 +60,7 @@ public class GroovyDslAnnotator implements Annotator { } public void invoke(@NotNull Project project, Editor editor, PsiFile file) throws IncorrectOperationException { + FileDocumentManager.getInstance().saveAllDocuments(); GroovyDslFileIndex.activateUntilModification(vfile); DaemonCodeAnalyzer.getInstance(project).restart(); } diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/dsl/GroovyDslFileIndex.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/dsl/GroovyDslFileIndex.java index 5503749886c1..1808a78ff35a 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/dsl/GroovyDslFileIndex.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/dsl/GroovyDslFileIndex.java @@ -22,10 +22,7 @@ import com.intellij.notification.Notifications; import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.application.ex.ApplicationManagerEx; import com.intellij.openapi.diagnostic.Logger; -import com.intellij.openapi.editor.Document; -import com.intellij.openapi.editor.event.DocumentAdapter; -import com.intellij.openapi.editor.event.DocumentEvent; -import com.intellij.openapi.fileEditor.FileDocumentManager; +import com.intellij.openapi.fileEditor.impl.LoadTextUtil; import com.intellij.openapi.progress.ProgressManager; import com.intellij.openapi.project.Project; import com.intellij.openapi.project.ProjectManager; @@ -34,6 +31,9 @@ import com.intellij.openapi.roots.ProjectRootManager; import com.intellij.openapi.util.Key; import com.intellij.openapi.util.Pair; import com.intellij.openapi.vfs.VirtualFile; +import com.intellij.openapi.vfs.VirtualFileAdapter; +import com.intellij.openapi.vfs.VirtualFileEvent; +import com.intellij.openapi.vfs.VirtualFileManager; import com.intellij.openapi.vfs.newvfs.FileAttribute; import com.intellij.psi.*; import com.intellij.psi.impl.PsiModificationTrackerImpl; @@ -93,6 +93,19 @@ public class GroovyDslFileIndex extends ScalarIndexExtension { private final EnumeratorStringDescriptor myKeyDescriptor = new EnumeratorStringDescriptor(); private static final byte[] ENABLED_FLAG = new byte[]{(byte)239}; + public GroovyDslFileIndex() { + VirtualFileManager.getInstance().addVirtualFileListener(new VirtualFileAdapter() { + + @Override + public void contentsChanged(VirtualFileEvent event) { + if (event.getFileName().endsWith(".gdsl")) { + disableFile(event.getFile()); + } + } + + }); + } + public ID getName() { return NAME; } @@ -132,17 +145,6 @@ public class GroovyDslFileIndex extends ScalarIndexExtension { } public static void activateUntilModification(final VirtualFile vfile) { - final Document document = FileDocumentManager.getInstance().getDocument(vfile); - if (document != null) { - document.addDocumentListener(new DocumentAdapter() { - @Override - public void beforeDocumentChange(DocumentEvent e) { - disableFile(vfile); - document.removeDocumentListener(this); - } - }); - } - try { ENABLED.writeAttributeBytes(vfile, ENABLED_FLAG); } @@ -237,15 +239,10 @@ public class GroovyDslFileIndex extends ScalarIndexExtension { } } - final PsiFile psiFile = PsiManager.getInstance(project).findFile(vfile); - if (psiFile == null) { - continue; - } - final long stamp = vfile.getModificationStamp(); final GroovyDslExecutor cached = getCachedExecutor(vfile, stamp); if (cached == null) { - scheduleParsing(queue, project, vfile, stamp, psiFile.getText()); + scheduleParsing(queue, project, vfile, stamp, LoadTextUtil.loadText(vfile).toString()); count++; } else { diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/dsl/GroovyDslScript.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/dsl/GroovyDslScript.java index b93db88b18c4..66172a113465 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/dsl/GroovyDslScript.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/dsl/GroovyDslScript.java @@ -115,4 +115,8 @@ public class GroovyDslScript { return false; } + @Override + public String toString() { + return "GroovyDslScript: " + file.getPath(); + } } diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/gant/GantClassFinder.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/gant/GantClassFinder.java index 4496fb1afa95..6d2e0105aac3 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/gant/GantClassFinder.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/gant/GantClassFinder.java @@ -33,7 +33,7 @@ public class GantClassFinder extends NonClasspathClassFinder { } @Override - protected List getClassRoots() { + protected List calcClassRoots() { return mySettings.getClassRoots(); } diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/gant/GantSettings.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/gant/GantSettings.java index e2f46ad52ccb..2af617fd06d5 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/gant/GantSettings.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/gant/GantSettings.java @@ -33,6 +33,9 @@ import org.jetbrains.plugins.groovy.util.SdkHomeSettings; } ) public class GantSettings extends SdkHomeSettings { + public GantSettings(Project project) { + super(project); + } public static GantSettings getInstance(Project project) { return ServiceManager.getService(project, GantSettings.class); diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/gradle/GradleClassFinder.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/gradle/GradleClassFinder.java index d30ec8b12fc6..39b3168b0322 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/gradle/GradleClassFinder.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/gradle/GradleClassFinder.java @@ -34,7 +34,7 @@ public class GradleClassFinder extends NonClasspathClassFinder { } @Override - protected List getClassRoots() { + protected List calcClassRoots() { return mySettings.getClassRoots(); } diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/gradle/GradleSettings.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/gradle/GradleSettings.java index 15f8b7e5f29f..d897bf33dca4 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/gradle/GradleSettings.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/gradle/GradleSettings.java @@ -33,6 +33,9 @@ import org.jetbrains.plugins.groovy.util.SdkHomeSettings; } ) public class GradleSettings extends SdkHomeSettings { + public GradleSettings(Project project) { + super(project); + } public static GradleSettings getInstance(Project project) { return ServiceManager.getService(project, GradleSettings.class); diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/folding/GroovyFoldingBuilder.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/folding/GroovyFoldingBuilder.java index cb379094cf92..740e5e067557 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/folding/GroovyFoldingBuilder.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/folding/GroovyFoldingBuilder.java @@ -237,7 +237,7 @@ public class GroovyFoldingBuilder implements FoldingBuilder, GroovyElementTypes, } if (node.getElementType() == CLOSABLE_BLOCK) { - return settings.isCollapseLambdas(); + return settings.isCollapseAnonymousClasses(); } if (node.getElementType() == CLASS_BODY) { diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/rename/GrLightElementRenamer.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/rename/GrLightElementRenamer.java index 61f9ef039a05..f8642041bda3 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/rename/GrLightElementRenamer.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/rename/GrLightElementRenamer.java @@ -22,6 +22,7 @@ import com.intellij.psi.impl.light.LightElement; import com.intellij.refactoring.RefactoringBundle; import com.intellij.refactoring.rename.RenamePsiElementProcessor; import com.intellij.refactoring.util.CommonRefactoringUtil; +import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.jetbrains.plugins.groovy.GroovyFileType; import org.jetbrains.plugins.groovy.refactoring.GroovyRefactoringBundle; @@ -40,7 +41,7 @@ public class GrLightElementRenamer extends RenamePsiElementProcessor { } @Override - public boolean canProcessElement(@Nullable PsiElement element) { + public boolean canProcessElement(@NotNull PsiElement element) { if (!(element instanceof LightElement)) return false; final Language language = element.getLanguage(); return GroovyFileType.GROOVY_LANGUAGE.equals(language); diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/rename/RenameAliasImportedClassProcessor.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/rename/RenameAliasImportedClassProcessor.java index d3a9e4319ef9..372baa83ea43 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/rename/RenameAliasImportedClassProcessor.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/rename/RenameAliasImportedClassProcessor.java @@ -28,8 +28,8 @@ import java.util.Collection; */ public class RenameAliasImportedClassProcessor extends RenameJavaClassProcessor { @Override - public boolean canProcessElement(PsiElement element) { - return super.canProcessElement(element) && element instanceof GroovyPsiElement; + public boolean canProcessElement(@NotNull PsiElement element) { + return element instanceof GroovyPsiElement && super.canProcessElement(element); } @NotNull diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/rename/RenameAliasImportedFieldProcessor.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/rename/RenameAliasImportedFieldProcessor.java index 3ddc4836d9df..3cd416459bd3 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/rename/RenameAliasImportedFieldProcessor.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/rename/RenameAliasImportedFieldProcessor.java @@ -28,7 +28,7 @@ import java.util.Collection; */ public class RenameAliasImportedFieldProcessor extends RenameJavaVariableProcessor{ @Override - public boolean canProcessElement(PsiElement element) { + public boolean canProcessElement(@NotNull PsiElement element) { return element instanceof GrField && !((GrField)element).isProperty(); } diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/rename/RenameAliasImportedMethodProcessor.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/rename/RenameAliasImportedMethodProcessor.java index 5e2df617fa1b..5eb9492e4514 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/rename/RenameAliasImportedMethodProcessor.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/rename/RenameAliasImportedMethodProcessor.java @@ -28,8 +28,8 @@ import java.util.Collection; */ public class RenameAliasImportedMethodProcessor extends RenameJavaMethodProcessor { @Override - public boolean canProcessElement(PsiElement element) { - return super.canProcessElement(element) && element instanceof GroovyPsiElement; + public boolean canProcessElement(@NotNull PsiElement element) { + return element instanceof GroovyPsiElement && super.canProcessElement(element); } @NotNull diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/rename/RenameGroovyPropertyProcessor.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/rename/RenameGroovyPropertyProcessor.java index 252b18195cdd..6ee5ee9a3bf9 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/rename/RenameGroovyPropertyProcessor.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/rename/RenameGroovyPropertyProcessor.java @@ -190,7 +190,7 @@ public class RenameGroovyPropertyProcessor extends RenameJavaVariableProcessor { } @Override - public boolean canProcessElement(final PsiElement element) { + public boolean canProcessElement(@NotNull final PsiElement element) { return element instanceof GrField && ((GrField)element).isProperty(); } diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/util/SdkHomeSettings.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/util/SdkHomeSettings.java index 2ec1dd20b9af..22302709e669 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/util/SdkHomeSettings.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/util/SdkHomeSettings.java @@ -16,11 +16,14 @@ package org.jetbrains.plugins.groovy.util; +import com.intellij.openapi.components.PersistentStateComponent; +import com.intellij.openapi.project.Project; import com.intellij.openapi.util.text.StringUtil; import com.intellij.openapi.vfs.JarFileSystem; import com.intellij.openapi.vfs.LocalFileSystem; import com.intellij.openapi.vfs.VirtualFile; -import com.intellij.openapi.components.PersistentStateComponent; +import com.intellij.psi.PsiManager; +import com.intellij.psi.impl.PsiModificationTrackerImpl; import com.intellij.util.containers.ContainerUtil; import org.jetbrains.annotations.Nullable; @@ -32,9 +35,12 @@ import java.util.List; * @author peter */ public abstract class SdkHomeSettings implements PersistentStateComponent { + private final PsiModificationTrackerImpl myTracker; private SdkHomeConfigurable.SdkHomeBean mySdkPath; - private volatile VirtualFile mySdkHome; - private volatile List myClassRoots; + + protected SdkHomeSettings(Project project) { + myTracker = (PsiModificationTrackerImpl)PsiManager.getInstance(project).getModificationTracker(); + } public SdkHomeConfigurable.SdkHomeBean getState() { return mySdkPath; @@ -42,16 +48,7 @@ public abstract class SdkHomeSettings implements PersistentStateComponent getClassRoots() { - if (myClassRoots == null) { - calculateRoots(); - } - return myClassRoots; + return calcRoots(getSdkHome()); } private static List calcRoots(@Nullable VirtualFile home) { diff --git a/plugins/groovy/test/org/jetbrains/plugins/groovy/gant/GantReferenceCompletionTest.groovy b/plugins/groovy/test/org/jetbrains/plugins/groovy/gant/GantReferenceCompletionTest.groovy index ebb97fead944..82c4f481a280 100644 --- a/plugins/groovy/test/org/jetbrains/plugins/groovy/gant/GantReferenceCompletionTest.groovy +++ b/plugins/groovy/test/org/jetbrains/plugins/groovy/gant/GantReferenceCompletionTest.groovy @@ -164,10 +164,10 @@ target (default : '') { myFixture.configureByText "a.gant", """ target (default : '') { - echo(new FileInputStream()) echo("hello2") echo(message: 'Echo task.') ant.fail('Failure reason') + ant.junit(fork:'yes') {} }""" myFixture.checkHighlighting(true, false, false) } diff --git a/plugins/groovy/test/org/jetbrains/plugins/groovy/refactoring/introduceParameter/IntroduceParameterTest.java b/plugins/groovy/test/org/jetbrains/plugins/groovy/refactoring/introduceParameter/IntroduceParameterTest.java index 82ead2c02a9f..2a5f58f23970 100644 --- a/plugins/groovy/test/org/jetbrains/plugins/groovy/refactoring/introduceParameter/IntroduceParameterTest.java +++ b/plugins/groovy/test/org/jetbrains/plugins/groovy/refactoring/introduceParameter/IntroduceParameterTest.java @@ -97,7 +97,7 @@ public class IntroduceParameterTest extends LightCodeInsightFixtureTestCase { } PsiExpression initializer = (expr == null) ? localVariable.getInitializer() : expr; - TIntArrayList parametersToRemove = removeUnusedParameters ? Util.findParametersToRemove(method, initializer) : new TIntArrayList(); + TIntArrayList parametersToRemove = removeUnusedParameters ? Util.findParametersToRemove(method, initializer, null) : new TIntArrayList(); final Project project = myFixture.getProject(); final IntroduceParameterProcessor processor = new IntroduceParameterProcessor(project, method, methodToSearchFor, initializer, expr, localVariable, true, parameterName, diff --git a/plugins/hg4idea/src/org/zmlx/hg4idea/HgVcs.java b/plugins/hg4idea/src/org/zmlx/hg4idea/HgVcs.java index 8bcd946412d3..0c455674b76a 100644 --- a/plugins/hg4idea/src/org/zmlx/hg4idea/HgVcs.java +++ b/plugins/hg4idea/src/org/zmlx/hg4idea/HgVcs.java @@ -25,11 +25,7 @@ import com.intellij.openapi.project.Project; import com.intellij.openapi.util.Disposer; import com.intellij.openapi.util.IconLoader; import com.intellij.openapi.util.SystemInfo; -import com.intellij.openapi.vcs.AbstractVcs; -import com.intellij.openapi.vcs.CommittedChangesProvider; -import com.intellij.openapi.vcs.ProjectLevelVcsManager; -import com.intellij.openapi.vcs.RepositoryChangeListener; -import com.intellij.openapi.vcs.VcsException; +import com.intellij.openapi.vcs.*; import com.intellij.openapi.vcs.annotate.AnnotationProvider; import com.intellij.openapi.vcs.changes.ChangeProvider; import com.intellij.openapi.vcs.checkin.CheckinEnvironment; @@ -48,12 +44,7 @@ import com.intellij.util.containers.Convertor; import com.intellij.util.messages.MessageBusConnection; import com.intellij.util.messages.Topic; import org.jetbrains.annotations.Nullable; -import org.zmlx.hg4idea.provider.HgCachingCommitedChangesProvider; -import org.zmlx.hg4idea.provider.HgChangeProvider; -import org.zmlx.hg4idea.provider.HgDiffProvider; -import org.zmlx.hg4idea.provider.HgHistoryProvider; -import org.zmlx.hg4idea.provider.HgMergeProvider; -import org.zmlx.hg4idea.provider.HgRollbackEnvironment; +import org.zmlx.hg4idea.provider.*; import org.zmlx.hg4idea.provider.annotate.HgAnnotationProvider; import org.zmlx.hg4idea.provider.commit.HgCheckinEnvironment; import org.zmlx.hg4idea.provider.update.HgIntegrateEnvironment; @@ -61,7 +52,7 @@ import org.zmlx.hg4idea.provider.update.HgUpdateEnvironment; import org.zmlx.hg4idea.ui.HgChangesetStatus; import org.zmlx.hg4idea.ui.HgCurrentBranchStatus; -import javax.swing.Icon; +import javax.swing.*; import java.io.File; import java.util.Collections; import java.util.List; @@ -152,8 +143,9 @@ public class HgVcs extends AbstractVcs { return changeProvider; } + @Nullable @Override - public RollbackEnvironment getRollbackEnvironment() { + public RollbackEnvironment createRollbackEnvironment() { if (!started) { return null; } @@ -184,8 +176,9 @@ public class HgVcs extends AbstractVcs { return getVcsHistoryProvider(); } + @Nullable @Override - public CheckinEnvironment getCheckinEnvironment() { + public CheckinEnvironment createCheckinEnvironment() { if (!started) { return null; } @@ -207,8 +200,9 @@ public class HgVcs extends AbstractVcs { return myMergeProvider; } + @Nullable @Override - public UpdateEnvironment getUpdateEnvironment() { + public UpdateEnvironment createUpdateEnvironment() { if (!started) { return null; } diff --git a/plugins/junit/src/com/intellij/execution/junit2/ui/StatisticsPanel.java b/plugins/junit/src/com/intellij/execution/junit2/ui/StatisticsPanel.java index 774cea6a883b..990105589d1e 100644 --- a/plugins/junit/src/com/intellij/execution/junit2/ui/StatisticsPanel.java +++ b/plugins/junit/src/com/intellij/execution/junit2/ui/StatisticsPanel.java @@ -79,9 +79,9 @@ class StatisticsPanel extends JPanel implements DataProvider{ private void updateStatistics() { myTable.setVisible(true); // myTestCaseInfo.setVisible(false); - TestProxy proxy = myCurrentTest; - if (myCurrentTest.isLeaf() && myCurrentTest.getParent() != null) { - proxy = myCurrentTest.getParent(); + TestProxy proxy = myCurrentTest != null ? myCurrentTest : myModel.getRoot(); + if (proxy.isLeaf() && proxy.getParent() != null) { + proxy = proxy.getParent(); } myChildInfo.updateStatistics(proxy); myTotalLabel.clear(); @@ -113,7 +113,10 @@ class StatisticsPanel extends JPanel implements DataProvider{ private class MyJUnitListener extends JUnitAdapter { public void onTestChanged(final TestEvent event) { if (!StatisticsPanel.this.isShowing()) return; - if (myCurrentTest == event.getSource()) updateStatistics(); + final TestProxy source = event.getSource(); + if (myCurrentTest == source || myCurrentTest == null && source == myModel.getRoot()) { + updateStatistics(); + } } public void onTestSelected(final TestProxy test) { diff --git a/plugins/properties/src/com/intellij/refactoring/rename/RenamePropertyProcessor.java b/plugins/properties/src/com/intellij/refactoring/rename/RenamePropertyProcessor.java index be365ce93429..7cc026a1e31e 100644 --- a/plugins/properties/src/com/intellij/refactoring/rename/RenamePropertyProcessor.java +++ b/plugins/properties/src/com/intellij/refactoring/rename/RenamePropertyProcessor.java @@ -19,12 +19,13 @@ import com.intellij.lang.properties.PropertiesUtil; import com.intellij.lang.properties.ResourceBundle; import com.intellij.lang.properties.psi.Property; import com.intellij.psi.PsiElement; +import org.jetbrains.annotations.NotNull; import java.util.List; import java.util.Map; public class RenamePropertyProcessor extends RenamePsiElementProcessor { - public boolean canProcessElement(final PsiElement element) { + public boolean canProcessElement(@NotNull final PsiElement element) { return element instanceof Property; } diff --git a/plugins/svn4idea/src/org/jetbrains/idea/svn/SvnVcs.java b/plugins/svn4idea/src/org/jetbrains/idea/svn/SvnVcs.java index eb6e79d17d56..975724077a6f 100644 --- a/plugins/svn4idea/src/org/jetbrains/idea/svn/SvnVcs.java +++ b/plugins/svn4idea/src/org/jetbrains/idea/svn/SvnVcs.java @@ -591,7 +591,7 @@ public class SvnVcs extends AbstractVcs { return mySvnIntegrateEnvironment; } - public UpdateEnvironment getUpdateEnvironment() { + public UpdateEnvironment createUpdateEnvironment() { if (mySvnUpdateEnvironment == null) { mySvnUpdateEnvironment = new SvnUpdateEnvironment(this); } @@ -618,7 +618,7 @@ public class SvnVcs extends AbstractVcs { } @NotNull - public CheckinEnvironment getCheckinEnvironment() { + public CheckinEnvironment createCheckinEnvironment() { if (myCheckinEnvironment == null) { myCheckinEnvironment = new SvnCheckinEnvironment(this); } @@ -626,7 +626,7 @@ public class SvnVcs extends AbstractVcs { } @NotNull - public RollbackEnvironment getRollbackEnvironment() { + public RollbackEnvironment createRollbackEnvironment() { if (myRollbackEnvironment == null) { myRollbackEnvironment = new SvnRollbackEnvironment(this); } diff --git a/plugins/testng/lib/src/testng.zip b/plugins/testng/lib/src/testng.zip index 35edabb826bb..f66e33e3e52d 100644 Binary files a/plugins/testng/lib/src/testng.zip and b/plugins/testng/lib/src/testng.zip differ diff --git a/plugins/testng/lib/testng-jdk15.jar b/plugins/testng/lib/testng-jdk15.jar index 61cdc2fb79da..2a9d24e63226 100644 Binary files a/plugins/testng/lib/testng-jdk15.jar and b/plugins/testng/lib/testng-jdk15.jar differ diff --git a/plugins/testng/src/com/theoryinpractice/testng/configuration/SearchingForTestsTask.java b/plugins/testng/src/com/theoryinpractice/testng/configuration/SearchingForTestsTask.java index f61de0da36e9..ec877f611a57 100644 --- a/plugins/testng/src/com/theoryinpractice/testng/configuration/SearchingForTestsTask.java +++ b/plugins/testng/src/com/theoryinpractice/testng/configuration/SearchingForTestsTask.java @@ -39,13 +39,14 @@ import com.intellij.psi.search.PackageScope; import com.intellij.psi.search.searches.AllClassesSearch; import com.intellij.psi.search.searches.AnnotatedMembersSearch; import com.intellij.util.containers.ContainerUtil; +import com.theoryinpractice.testng.model.IDEARemoteTestRunnerClient; import com.theoryinpractice.testng.model.TestClassFilter; import com.theoryinpractice.testng.model.TestData; import com.theoryinpractice.testng.model.TestType; import com.theoryinpractice.testng.util.TestNGUtil; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import org.testng.TestNG; +import org.testng.internal.AnnotationTypeEnum; import org.testng.xml.LaunchSuite; import org.testng.xml.Parser; import org.testng.xml.SuiteGenerator; @@ -66,12 +67,15 @@ public class SearchingForTestsTask extends Task.Backgroundable { private final boolean myIs15; private final TestNGConfiguration myConfig; private final File myTempFile; + private final IDEARemoteTestRunnerClient myClient; public SearchingForTestsTask(ServerSocket serverSocket, boolean is15, TestNGConfiguration config, - File tempFile) { + File tempFile, + IDEARemoteTestRunnerClient client) { super(config.getProject(), "Searching For Tests ...", true); + myClient = client; myData = config.getPersistantData(); myProject = config.getProject(); myServerSocket = serverSocket; @@ -100,6 +104,8 @@ public class SearchingForTestsTask extends Task.Backgroundable { public void onSuccess() { writeTempFile(); connect(); + + myClient.startListening(); } @Override @@ -198,13 +204,6 @@ public class SearchingForTestsTask extends Task.Backgroundable { Map testParams = buildTestParameters(); - String annotationType = myData.ANNOTATION_TYPE; - if (annotationType == null || "".equals(annotationType)) { - annotationType = myIs15 ? TestNG.JDK_ANNOTATION_TYPE : TestNG.JAVADOC_ANNOTATION_TYPE; - } - - LOG.info("Using annotationType of " + annotationType); - int logLevel = 1; try { final Properties properties = new Properties(); @@ -219,7 +218,7 @@ public class SearchingForTestsTask extends Task.Backgroundable { } LaunchSuite suite = - SuiteGenerator.createSuite(myProject.getName(), null, map, groupNames, testParams, annotationType, logLevel); + SuiteGenerator.createSuite(myProject.getName(), null, map, groupNames, testParams, AnnotationTypeEnum.JDK.getName(), logLevel); File xmlFile = suite.save(new File(PathManager.getSystemPath())); String path = xmlFile.getAbsolutePath() + "\n"; @@ -232,7 +231,13 @@ public class SearchingForTestsTask extends Task.Backgroundable { } private void composeTestSuiteFromXml() throws CantRunException { + final Map buildTestParams = buildTestParameters(); try { + if (buildTestParams.isEmpty()) { + String path = new File(myData.getSuiteName()).getAbsolutePath() + "\n"; + FileUtil.writeToFile(myTempFile, path.getBytes(), true); + return; + } Collection suites; FileInputStream in = new FileInputStream(myData.getSuiteName()); try { @@ -241,16 +246,11 @@ public class SearchingForTestsTask extends Task.Backgroundable { finally { in.close(); } + for (XmlSuite suite : suites) { Map params = suite.getParameters(); - params.putAll(buildTestParameters()); - - String annotationType = myData.ANNOTATION_TYPE; - if (annotationType != null && !"".equals(annotationType)) { - suite.setAnnotations(annotationType); - } - LOG.info("Using annotationType of " + annotationType); + params.putAll(buildTestParams); final String fileId = (myProject.getName() + '_' + suite.getName() + '_' + Integer.toHexString(suite.getName().hashCode()) + ".xml") @@ -293,7 +293,7 @@ public class SearchingForTestsTask extends Task.Backgroundable { TestSearchScope scope = myConfig.getPersistantData().getScope(); //TODO we should narrow this down by module really, if that's what's specified TestClassFilter projectFilter = - new TestClassFilter(scope.getSourceScope(myConfig).getGlobalSearchScope(), myProject, true); + new TestClassFilter(scope.getSourceScope(myConfig).getGlobalSearchScope(), myProject, true, true); TestClassFilter filter = projectFilter.intersectionWith(PackageScope.packageScope(psiPackage, true)); classes.putAll(calculateDependencies(null, TestNGUtil.getAllTestClasses(filter, false))); if (classes.size() == 0) { @@ -365,7 +365,7 @@ public class SearchingForTestsTask extends Task.Backgroundable { else if (data.TEST_OBJECT.equals(TestType.GROUP.getType())) { //for a group, we include all classes PsiClass[] testClasses = TestNGUtil - .getAllTestClasses(new TestClassFilter(data.getScope().getSourceScope(myConfig).getGlobalSearchScope(), myProject, true), false); + .getAllTestClasses(new TestClassFilter(data.getScope().getSourceScope(myConfig).getGlobalSearchScope(), myProject, true, true), false); for (PsiClass c : testClasses) { classes.put(c, new HashSet()); } diff --git a/plugins/testng/src/com/theoryinpractice/testng/configuration/TestNGConfiguration.java b/plugins/testng/src/com/theoryinpractice/testng/configuration/TestNGConfiguration.java index 3a0652e355fc..4c4464fcc6a8 100644 --- a/plugins/testng/src/com/theoryinpractice/testng/configuration/TestNGConfiguration.java +++ b/plugins/testng/src/com/theoryinpractice/testng/configuration/TestNGConfiguration.java @@ -295,7 +295,9 @@ public class TestNGConfiguration extends ModuleBasedConfiguration - + @@ -119,7 +119,7 @@ - + @@ -133,14 +133,6 @@ - - - - - - - - @@ -172,6 +164,7 @@ + @@ -248,7 +241,7 @@ - + @@ -322,7 +315,7 @@ - + diff --git a/plugins/testng/src/com/theoryinpractice/testng/configuration/TestNGConfigurationEditor.java b/plugins/testng/src/com/theoryinpractice/testng/configuration/TestNGConfigurationEditor.java index 4988ca383dec..92eda7ff8379 100644 --- a/plugins/testng/src/com/theoryinpractice/testng/configuration/TestNGConfigurationEditor.java +++ b/plugins/testng/src/com/theoryinpractice/testng/configuration/TestNGConfigurationEditor.java @@ -47,7 +47,6 @@ import com.theoryinpractice.testng.configuration.browser.*; import com.theoryinpractice.testng.model.*; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import org.testng.TestNG; import javax.swing.*; import javax.swing.event.ChangeEvent; @@ -94,7 +93,6 @@ public class TestNGConfigurationEditor extends SettingsEditor annotationType; private JCheckBox myUseDefaultReportersCheckBox; private final CommonJavaParametersPanel commonJavaParameters = new CommonJavaParametersPanel(); private ArrayList propertiesList; @@ -232,9 +230,7 @@ public class TestNGConfigurationEditor extends SettingsEditor entry : propertiesList) { data.TEST_PROPERTIES.put(entry.getKey(), entry.getValue()); @@ -305,8 +300,6 @@ public class TestNGConfigurationEditor extends SettingsEditor 0) { + boolean withoutParam = false; + for (PsiMethod constructor : constructors) { + if (constructor.getParameterList().getParametersCount() == 0) { + withoutParam = true; + break; + } + } + if (!withoutParam) return includeConfig && TestNGUtil.hasConfig(psiClass); + } + } + return true; + } + return includeConfig && TestNGUtil.hasConfig(psiClass); } diff --git a/plugins/testng/src/com/theoryinpractice/testng/model/TestData.java b/plugins/testng/src/com/theoryinpractice/testng/model/TestData.java index d45ffe87e196..113e32c2e253 100644 --- a/plugins/testng/src/com/theoryinpractice/testng/model/TestData.java +++ b/plugins/testng/src/com/theoryinpractice/testng/model/TestData.java @@ -93,10 +93,6 @@ public class TestData implements Cloneable return OUTPUT_DIRECTORY == null ? "" : OUTPUT_DIRECTORY; } - public String getAnnotationType() { - return ANNOTATION_TYPE == null ? "" : ANNOTATION_TYPE; - } - public void setVMParameters(String value) { VM_PARAMETERS = value; } diff --git a/plugins/testng/src/com/theoryinpractice/testng/model/TestNGResultsTableModel.java b/plugins/testng/src/com/theoryinpractice/testng/model/TestNGResultsTableModel.java index 0815afab7efa..269b8cc04aca 100644 --- a/plugins/testng/src/com/theoryinpractice/testng/model/TestNGResultsTableModel.java +++ b/plugins/testng/src/com/theoryinpractice/testng/model/TestNGResultsTableModel.java @@ -22,6 +22,7 @@ */ package com.theoryinpractice.testng.model; +import com.intellij.openapi.project.Project; import com.intellij.util.ui.ColumnInfo; import com.intellij.util.ui.ListTableModel; import org.testng.remote.strprotocol.MessageHelper; @@ -36,8 +37,8 @@ public class TestNGResultsTableModel extends ListTableModel { private final List testResults; - public TestNGResultsTableModel() { - super(new StatusColumnInfo(), new TestNameColumnInfo(), new TestClassNameColumnInfo(), new DurationColumnInfo()); + public TestNGResultsTableModel(Project project) { + super(new StatusColumnInfo(), new TestNameColumnInfo(project), new TestClassNameColumnInfo(project), new DurationColumnInfo()); testResults = new ArrayList(); } @@ -80,12 +81,15 @@ public class TestNGResultsTableModel extends ListTableModel { } private static class TestNameColumnInfo extends ColumnInfo { - public TestNameColumnInfo() { + private final Project project; + + public TestNameColumnInfo(Project project) { super("Test"); + this.project = project; } public String valueOf(final TestResultMessage result) { - final String displayString = result.toDisplayString(); + final String displayString = TestProxy.toDisplayText(result, project); final String description = result.getTestDescription(); if (description != null && description.startsWith(displayString)) return description; return displayString; @@ -101,14 +105,17 @@ public class TestNGResultsTableModel extends ListTableModel { } private static class TestClassNameColumnInfo extends ColumnInfo { - public TestClassNameColumnInfo() { + private final Project project; + + public TestClassNameColumnInfo(Project project) { super("Test Class"); + this.project = project; } public String valueOf(final TestResultMessage result) { final String description = result.getTestClass(); if (description != null) return description; - return result.toDisplayString(); + return TestProxy.toDisplayText(result, project); } public Comparator getComparator() { diff --git a/plugins/testng/src/com/theoryinpractice/testng/model/TestProxy.java b/plugins/testng/src/com/theoryinpractice/testng/model/TestProxy.java index cc4f83d992e7..cc70adfe8e0a 100644 --- a/plugins/testng/src/com/theoryinpractice/testng/model/TestProxy.java +++ b/plugins/testng/src/com/theoryinpractice/testng/model/TestProxy.java @@ -26,6 +26,7 @@ import com.intellij.execution.ui.ConsoleViewContentType; import com.intellij.ide.util.EditSourceUtil; import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.project.Project; +import com.intellij.openapi.util.Comparing; import com.intellij.pom.Navigatable; import com.intellij.psi.*; import org.jetbrains.annotations.NonNls; @@ -122,7 +123,8 @@ public class TestProxy extends AbstractTestProxy { } if (this.resultMessage == null || this.resultMessage.getResult() == MessageHelper.TEST_STARTED) { this.resultMessage = resultMessage; - this.name = resultMessage.toDisplayString(); + final PsiElement psiElement = getPsiElement(); + this.name = toDisplayText(resultMessage, psiElement != null ? psiElement.getProject() : null); } } @@ -333,6 +335,36 @@ public class TestProxy extends AbstractTestProxy { return printables; } + public static String toDisplayText(TestResultMessage message, Project project) { + String name = message.getName(); + if (project != null && Comparing.strEqual(name, project.getName())) { + name = message.getMethod(); + } + final String mainNamePart = name; + final String[] parameters = message.getParameters(); + if (parameters != null && parameters.length > 0) { + final String[] parameterTypes = message.getParameterTypes(); + name += " ("; + for(int i= 0; i < parameters.length; i++) { + if(i > 0) { + name += ", "; + } + if(CommonClassNames.JAVA_LANG_STRING.equals(parameterTypes[i]) && !("null".equals(parameters[i]) || "\"\"".equals(parameters[i]))) { + name += "\"" + parameters[i] + "\""; + } + else { + name += parameters[i]; + } + + } + name += ")"; + } + final String testDescription = message.getTestDescription(); + if (testDescription != null && !Comparing.strEqual(testDescription, mainNamePart)) { + name += " [" + testDescription + "]"; + } + return name; + } public static class Chunk implements Printable { public String text; diff --git a/plugins/testng/src/com/theoryinpractice/testng/ui/ResultTreeRenderer.java b/plugins/testng/src/com/theoryinpractice/testng/ui/ResultTreeRenderer.java index b5aef935b66b..0e2123b872eb 100644 --- a/plugins/testng/src/com/theoryinpractice/testng/ui/ResultTreeRenderer.java +++ b/plugins/testng/src/com/theoryinpractice/testng/ui/ResultTreeRenderer.java @@ -69,7 +69,13 @@ public class ResultTreeRenderer extends ColoredTreeCellRenderer } else { if (proxy.getResultMessage() != null) { TestResultMessage result = proxy.getResultMessage(); - final String name = node.getChildCount() == 0 ? result.toDisplayString() : result.getTestClass(); + String name; + if (node.getChildCount() == 0) { + name = TestProxy.toDisplayText(result, consoleProperties.getProject()); + } + else { + name = result.getTestClass(); + } append(name, SimpleTextAttributes.REGULAR_ATTRIBUTES); final String description = result.getTestDescription(); if (description != null && description.startsWith(name) && description.length() > name.length()) { diff --git a/plugins/testng/src/com/theoryinpractice/testng/ui/TestNGConsoleView.java b/plugins/testng/src/com/theoryinpractice/testng/ui/TestNGConsoleView.java index d626de3c5c63..9d5fe3290367 100644 --- a/plugins/testng/src/com/theoryinpractice/testng/ui/TestNGConsoleView.java +++ b/plugins/testng/src/com/theoryinpractice/testng/ui/TestNGConsoleView.java @@ -125,6 +125,14 @@ public class TestNGConsoleView extends BaseTestsOutputConsoleView { } public void finish() { + if (currentTest != null) { + final TestProxy failedToStart = testNGResults.getFailedToStart(); + if (failedToStart != null) { + currentTest.addChild(failedToStart); + currentTest.setTearDownFailure(true); + testNGResults.setFailedToStart(null); + } + } currentTest = null; } diff --git a/plugins/testng/src/com/theoryinpractice/testng/ui/TestNGResults.java b/plugins/testng/src/com/theoryinpractice/testng/ui/TestNGResults.java index e939ca59234f..7c233fd179da 100644 --- a/plugins/testng/src/com/theoryinpractice/testng/ui/TestNGResults.java +++ b/plugins/testng/src/com/theoryinpractice/testng/ui/TestNGResults.java @@ -92,7 +92,7 @@ public class TestNGResults extends TestResultsPanel implements TestFrameworkRunn runnerSettings, configurationSettings, TESTNG_SPLITTER_PROPERTY, 0.5f); this.project = configuration.getProject(); - model = new TestNGResultsTableModel(); + model = new TestNGResultsTableModel(project); resultsTable = new TableView(model); resultsTable.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent e) { @@ -228,9 +228,21 @@ public class TestNGResults extends TestResultsPanel implements TestFrameworkRunn } } ); - if (methods.length > 0 && !AnnotationUtil.isAnnotated(methods[0], Arrays.asList(TestNGUtil.CONFIG_ANNOTATIONS_FQN))) { - testCase = testStarted(result); - testCase.appendStacktrace(result); + if (methods.length > 0 && methods[0] != null && !AnnotationUtil.isAnnotated(methods[0], Arrays.asList(TestNGUtil.CONFIG_ANNOTATIONS_FQN))) { + for (List proxies : started.values()) { + if (proxies != null) { + for (TestProxy proxy : proxies) { + if (methods[0].equals(proxy.getPsiElement())) { + testCase = proxy; + break; + } + } + } + } + if (testCase == null) { + testCase = testStarted(result); + testCase.appendStacktrace(result); + } } } } @@ -247,7 +259,7 @@ public class TestNGResults extends TestResultsPanel implements TestFrameworkRunn } else { //do not remember testresultmessage: test hierarchy is not set - testCase = new TestProxy(result.toDisplayString()); + testCase = new TestProxy(TestProxy.toDisplayText(result, project)); testCase.appendStacktrace(result); failedToStart = testCase; } @@ -384,6 +396,10 @@ public class TestNGResults extends TestResultsPanel implements TestFrameworkRunn return failedToStart; } + public void setFailedToStart(TestProxy failedToStart) { + this.failedToStart = failedToStart; + } + private class OpenSourceSelectionListener implements TreeSelectionListener { public void valueChanged(TreeSelectionEvent e) { diff --git a/plugins/testng/src/com/theoryinpractice/testng/ui/actions/RerunFailedTestsAction.java b/plugins/testng/src/com/theoryinpractice/testng/ui/actions/RerunFailedTestsAction.java index 0a37ce3231f5..8cc6c90fd38c 100644 --- a/plugins/testng/src/com/theoryinpractice/testng/ui/actions/RerunFailedTestsAction.java +++ b/plugins/testng/src/com/theoryinpractice/testng/ui/actions/RerunFailedTestsAction.java @@ -52,7 +52,7 @@ public class RerunFailedTestsAction extends AbstractRerunFailedTestsAction { @Override protected SearchingForTestsTask createSearchingForTestsTask(ServerSocket serverSocket, boolean is15, final TestNGConfiguration config, final File tempFile) { - return new SearchingForTestsTask(serverSocket, is15, config, tempFile) { + return new SearchingForTestsTask(serverSocket, is15, config, tempFile, client) { @Override protected void fillTestObjects(final Map> classes) throws CantRunException { for (AbstractTestProxy proxy : failedTests) { diff --git a/plugins/testng/src/com/theoryinpractice/testng/util/TestNGUtil.java b/plugins/testng/src/com/theoryinpractice/testng/util/TestNGUtil.java index 83ea2d8c6957..ae73916fd90e 100644 --- a/plugins/testng/src/com/theoryinpractice/testng/util/TestNGUtil.java +++ b/plugins/testng/src/com/theoryinpractice/testng/util/TestNGUtil.java @@ -134,6 +134,7 @@ public class TestNGUtil if (element instanceof PsiClass) { methods = ((PsiClass) element).getMethods(); } else { + if (!(element instanceof PsiMethod)) return false; methods = new PsiMethod[] {(PsiMethod) element}; } diff --git a/plugins/testng/testSources/com/theoryinpractice/testng/inspection/ConvertJUnitInspectionTest.java b/plugins/testng/testSources/com/theoryinpractice/testng/inspection/ConvertJUnitInspectionTest.java index ed21043a906f..840f21307507 100644 --- a/plugins/testng/testSources/com/theoryinpractice/testng/inspection/ConvertJUnitInspectionTest.java +++ b/plugins/testng/testSources/com/theoryinpractice/testng/inspection/ConvertJUnitInspectionTest.java @@ -21,7 +21,6 @@ package com.theoryinpractice.testng.inspection; import com.intellij.codeInspection.LocalInspectionTool; -import com.theoryinpractice.testng.inspection.JUnitConvertTool; import org.testng.annotations.Test; public class ConvertJUnitInspectionTest extends BaseTestNGInspectionsTest{ @@ -46,4 +45,4 @@ public class ConvertJUnitInspectionTest extends BaseTestNGInspectionsTest{ public void test2() throws Throwable { doTest("Fail"); } -} \ No newline at end of file +} diff --git a/plugins/testng/testSources/com/theoryinpractice/testng/inspection/ConvertOldAnnotationInspectionTest.java b/plugins/testng/testSources/com/theoryinpractice/testng/inspection/ConvertOldAnnotationInspectionTest.java index 31311eaf754f..f6eea3a0f718 100644 --- a/plugins/testng/testSources/com/theoryinpractice/testng/inspection/ConvertOldAnnotationInspectionTest.java +++ b/plugins/testng/testSources/com/theoryinpractice/testng/inspection/ConvertOldAnnotationInspectionTest.java @@ -21,7 +21,6 @@ package com.theoryinpractice.testng.inspection; import com.intellij.codeInspection.LocalInspectionTool; -import com.theoryinpractice.testng.inspection.ConvertOldAnnotationInspection; import org.testng.annotations.Test; public class ConvertOldAnnotationInspectionTest extends BaseTestNGInspectionsTest{ @@ -37,4 +36,4 @@ public class ConvertOldAnnotationInspectionTest extends BaseTestNGInspectionsTes public void test1() throws Throwable { doTest("1"); } -} \ No newline at end of file +} diff --git a/resources-en/src/messages/CompilerBundle.properties b/resources-en/src/messages/CompilerBundle.properties index 4e747c04f0fb..b7ab2a5bfca9 100644 --- a/resources-en/src/messages/CompilerBundle.properties +++ b/resources-en/src/messages/CompilerBundle.properties @@ -212,3 +212,4 @@ label.resource.patterns.legend=\ Accepted wildcards: ? - exactly one symbol; * - zero or more symbols; / - path separator; /**/ - any number of directories
\ label.option.autoshow.first.error=Automatically show first &error in editor +label.generate.ant.script.filename=Output file name: diff --git a/resources/src/META-INF/IdeaPlugin.xml b/resources/src/META-INF/IdeaPlugin.xml index ee28c62169ff..063df1355216 100644 --- a/resources/src/META-INF/IdeaPlugin.xml +++ b/resources/src/META-INF/IdeaPlugin.xml @@ -854,7 +854,7 @@ + implementationClass="com.intellij.openapi.roots.ui.configuration.libraryEditor.DocumentationOrderRootTypeUIFactory"/> diff --git a/xml/dom-openapi/src/com/intellij/util/xml/ElementPresentationManager.java b/xml/dom-openapi/src/com/intellij/util/xml/ElementPresentationManager.java index 5ae1f18081f9..0f5624ee5810 100644 --- a/xml/dom-openapi/src/com/intellij/util/xml/ElementPresentationManager.java +++ b/xml/dom-openapi/src/com/intellij/util/xml/ElementPresentationManager.java @@ -78,6 +78,10 @@ public abstract class ElementPresentationManager { return createVariants(elements, namer, 0); } + /** + * Use {@link com.intellij.codeInsight.lookup.LookupElementBuilder} + */ + @Deprecated public abstract Object createVariant(final Object variant, final String name, final PsiElement psiElement); @NotNull @@ -103,8 +107,6 @@ public abstract class ElementPresentationManager { public static void registerDocumentationProvider(Function function) { ourDocumentationProviders.add(function); } public static void registerIconProvider(Function function) { ourIconProviders.add(function); } - public static void unregisterNameProvider(Function function) { ourNameProviders.remove(function); } - /** Use extension point {@code com.intellij.typeIcon} instead. */ public static void registerIcon(Class aClass, Icon icon) { registerIcons(aClass, icon); } public static void registerIcons(Class aClass, Icon... icon) { ourIcons.put(aClass, icon); } diff --git a/xml/impl/src/com/intellij/codeInspection/htmlInspections/RenameTagBeginOrEndIntentionAction.java b/xml/impl/src/com/intellij/codeInspection/htmlInspections/RenameTagBeginOrEndIntentionAction.java index 897a6a2edfdc..8356b78ca6be 100644 --- a/xml/impl/src/com/intellij/codeInspection/htmlInspections/RenameTagBeginOrEndIntentionAction.java +++ b/xml/impl/src/com/intellij/codeInspection/htmlInspections/RenameTagBeginOrEndIntentionAction.java @@ -71,6 +71,7 @@ public class RenameTagBeginOrEndIntentionAction implements IntentionAction { if (psiElement == null || !psiElement.isValid()) return; if (!CodeInsightUtilBase.prepareFileForWrite(psiElement.getContainingFile())) return; + if (psiElement instanceof PsiWhiteSpace) psiElement = PsiTreeUtil.prevLeaf(psiElement); if (psiElement instanceof XmlToken) { final IElementType tokenType = ((XmlToken)psiElement).getTokenType(); if (tokenType != XmlTokenType.XML_NAME) { diff --git a/xml/impl/src/com/intellij/psi/impl/source/parsing/xml/XmlParsing.java b/xml/impl/src/com/intellij/psi/impl/source/parsing/xml/XmlParsing.java index 1c779b1ee412..5b449f1fa4d3 100644 --- a/xml/impl/src/com/intellij/psi/impl/source/parsing/xml/XmlParsing.java +++ b/xml/impl/src/com/intellij/psi/impl/source/parsing/xml/XmlParsing.java @@ -13,10 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - -/* - * @author max - */ package com.intellij.psi.impl.source.parsing.xml; import com.intellij.codeInsight.daemon.XmlErrorMessages; @@ -25,17 +21,21 @@ import com.intellij.psi.tree.CustomParsingType; import com.intellij.psi.tree.IElementType; import com.intellij.psi.tree.ILazyParseableElementType; import com.intellij.psi.xml.XmlElementType; -import static com.intellij.psi.xml.XmlElementType.*; import com.intellij.psi.xml.XmlTokenType; import com.intellij.util.containers.Stack; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import static com.intellij.psi.xml.XmlElementType.*; +/* + * @author max + */ public class XmlParsing { + private static final int BALANCING_DEPTH_THRESHOLD = 1000; + private final PsiBuilder myBuilder; private final Stack myTagNamesStack = new Stack(); - private static final int BALANCING_DEPTH_THRESHOULD = 1000; public XmlParsing(final PsiBuilder builder) { myBuilder = builder; @@ -79,7 +79,6 @@ public class XmlParsing { if (error != null) { error.error(XmlErrorMessages.message("top.level.element.is.not.completed")); - error = null; } if (rootTagCount == 0) { @@ -220,7 +219,7 @@ public class XmlParsing { return null; } - if (myTagNamesStack.size() > BALANCING_DEPTH_THRESHOULD) { + if (myTagNamesStack.size() > BALANCING_DEPTH_THRESHOLD) { error(XmlErrorMessages.message("way.too.unbalanced")); tag.done(XmlElementType.XML_TAG); return null; @@ -469,6 +468,7 @@ public class XmlParsing { pi.done(XML_PROCESSING_INSTRUCTION); } + @Nullable protected final IElementType token() { return myBuilder.getTokenType(); } diff --git a/xml/impl/src/com/intellij/refactoring/rename/RenameXmlAttributeProcessor.java b/xml/impl/src/com/intellij/refactoring/rename/RenameXmlAttributeProcessor.java index 26f89264c0f9..1b8c15d59d58 100644 --- a/xml/impl/src/com/intellij/refactoring/rename/RenameXmlAttributeProcessor.java +++ b/xml/impl/src/com/intellij/refactoring/rename/RenameXmlAttributeProcessor.java @@ -34,7 +34,7 @@ import org.jetbrains.annotations.NotNull; public class RenameXmlAttributeProcessor extends RenamePsiElementProcessor { private static final Logger LOG = Logger.getInstance("#com.intellij.refactoring.rename.RenameXmlAttributeProcessor"); - public boolean canProcessElement(final PsiElement element) { + public boolean canProcessElement(@NotNull final PsiElement element) { return element instanceof XmlAttribute || element instanceof XmlAttributeValue; }