From 981f8c85afd40dfd255cb7b1ab618293033e30a9 Mon Sep 17 00:00:00 2001 From: Bas Leijdekkers Date: Fri, 19 Aug 2011 10:41:55 +0200 Subject: [PATCH 01/78] fix notification message --- .../actions/AnalyzeDependenciesOnSpecifiedTargetHandler.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/platform/lang-impl/src/com/intellij/packageDependencies/actions/AnalyzeDependenciesOnSpecifiedTargetHandler.java b/platform/lang-impl/src/com/intellij/packageDependencies/actions/AnalyzeDependenciesOnSpecifiedTargetHandler.java index 623a2ebc1b69..60a10f3b8b53 100644 --- a/platform/lang-impl/src/com/intellij/packageDependencies/actions/AnalyzeDependenciesOnSpecifiedTargetHandler.java +++ b/platform/lang-impl/src/com/intellij/packageDependencies/actions/AnalyzeDependenciesOnSpecifiedTargetHandler.java @@ -64,7 +64,7 @@ public class AnalyzeDependenciesOnSpecifiedTargetHandler extends DependenciesHan final String source = StringUtil.decapitalize(builders.get(0).getScope().getDisplayName()); final String target = StringUtil.decapitalize(myTargetScope.getDisplayName()); final String message = AnalysisScopeBundle.message("no.dependencies.found.message", source, target); - NotificationGroup.toolWindowGroup("Dependencies", ToolWindowId.DEPENDENCIES, true).createNotification("message", MessageType.INFO).notify(myProject); + NotificationGroup.toolWindowGroup("Dependencies", ToolWindowId.DEPENDENCIES, true).createNotification(message, MessageType.INFO).notify(myProject); return false; } From 653c18cf45ced5dee91ba5080eb8d930e8bf0d6a Mon Sep 17 00:00:00 2001 From: Bas Leijdekkers Date: Fri, 19 Aug 2011 10:48:54 +0200 Subject: [PATCH 02/78] Generify, fix spelling --- .../actionVisibility/CvsActionVisibility.java | 41 ++++++------------- .../config/ImportConfiguration.java | 13 +++--- .../ui/SelectCvsConfigurationDialog.java | 12 +++--- ....java => SelectCvsConfigurationPanel.java} | 38 +++++++---------- .../cvsErrors/ErrorMessagesProcessor.java | 20 ++++----- .../cvsErrors/ErrorProcessor.java | 4 +- .../experts/SelectCVSConfigurationStep.java | 23 ++++++----- 7 files changed, 58 insertions(+), 93 deletions(-) rename plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/config/ui/{SelectCvsConfgurationPanel.java => SelectCvsConfigurationPanel.java} (77%) diff --git a/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/actions/actionVisibility/CvsActionVisibility.java b/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/actions/actionVisibility/CvsActionVisibility.java index ec73e45210b8..ea4fbdfcae22 100644 --- a/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/actions/actionVisibility/CvsActionVisibility.java +++ b/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/actions/actionVisibility/CvsActionVisibility.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2011 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,12 +21,10 @@ import com.intellij.cvsSupport2.actions.cvsContext.CvsLightweightFile; import com.intellij.cvsSupport2.application.CvsEntriesManager; import com.intellij.openapi.actionSystem.AnActionEvent; import com.intellij.openapi.actionSystem.Presentation; -import com.intellij.openapi.vfs.LocalFileSystem; import com.intellij.openapi.vfs.VirtualFile; import java.io.File; import java.util.ArrayList; -import java.util.Iterator; import java.util.List; /** @@ -37,13 +35,12 @@ public class CvsActionVisibility { private boolean myCanBePerformedOnFile = true; private boolean myCanBePerformedOnDirectory = true; private boolean myCanBePerformedOnSeveralFiles = false; - private final boolean myExpectedCvsAsActiveVcs = true; - private final List myConditions = new ArrayList(); + private final List myConditions = new ArrayList(); private boolean myCanBePerformedOnLocallyDeletedFile = false; private boolean myCanBePerformedOnCvsLightweightFile = false; - public static interface Condition{ + public interface Condition{ boolean isPerformedOn(CvsContext context); } @@ -51,18 +48,11 @@ public class CvsActionVisibility { myConditions.add(condition); } - public boolean isVisible(CvsContext context){ - if (!myExpectedCvsAsActiveVcs) return true; - return context.cvsIsActive(); - } - - public boolean isEnabled(CvsContext context){ - boolean result = (context.cvsIsActive() || !myExpectedCvsAsActiveVcs) - && hasSuitableType(context); + private boolean isEnabled(CvsContext context){ + boolean result = context.cvsIsActive() && hasSuitableType(context); if (!result) return false; - for (Iterator each = myConditions.iterator(); each.hasNext();) { - Condition condition = (Condition) each.next(); + for (Condition condition : myConditions) { if (!condition.isPerformedOn(context)) return false; } return true; @@ -107,40 +97,35 @@ public class CvsActionVisibility { } private boolean containsFileFromUnsupportedFileSystem(VirtualFile[] selectedFiles) { - for (int i = 0; i < selectedFiles.length; i++) { - VirtualFile selectedFile = selectedFiles[i]; + for (VirtualFile selectedFile : selectedFiles) { if (!selectedFile.isInLocalFileSystem()) return true; } return false; } private boolean containsFile(VirtualFile[] selectedFiles) { - for (int i = 0; i < selectedFiles.length; i++) { - VirtualFile selectedFile = selectedFiles[i]; + for (VirtualFile selectedFile : selectedFiles) { if (!selectedFile.isDirectory()) return true; } return false; } private boolean containsDirectory(VirtualFile[] selectedFiles) { - for (int i = 0; i < selectedFiles.length; i++) { - VirtualFile selectedFile = selectedFiles[i]; + for (VirtualFile selectedFile : selectedFiles) { if (selectedFile.isDirectory()) return true; } return false; } private boolean containsDirectory(File[] selectedFiles) { - for (int i = 0; i < selectedFiles.length; i++) { - File selectedFile = selectedFiles[i]; + for (File selectedFile : selectedFiles) { if (selectedFile.isDirectory()) return true; } return false; } private boolean containsFile(File[] selectedFiles) { - for (int i = 0; i < selectedFiles.length; i++) { - File selectedFile = selectedFiles[i]; + for (File selectedFile : selectedFiles) { if (selectedFile.isFile()) return true; } return false; @@ -160,12 +145,10 @@ public class CvsActionVisibility { CvsContext cvsContext = CvsContextWrapper.createInstance(e); Presentation presentation = e.getPresentation(); presentation.setEnabled(isEnabled(cvsContext)); - presentation.setVisible(isVisible(cvsContext)); + presentation.setVisible(cvsContext.cvsIsActive()); } public void canBePerformedOnCvsLightweightFile() { myCanBePerformedOnCvsLightweightFile = true; } - - } diff --git a/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/config/ImportConfiguration.java b/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/config/ImportConfiguration.java index 6e63dda7a808..51dcc03d33a1 100644 --- a/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/config/ImportConfiguration.java +++ b/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/config/ImportConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2011 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,7 +20,6 @@ import com.intellij.openapi.components.ServiceManager; import java.util.ArrayList; import java.util.Collection; -import java.util.Iterator; import java.util.List; /** * author: lesya @@ -48,8 +47,7 @@ public class ImportConfiguration extends AbstractConfiguration { return result; String[] wrappers = KEYWORD_SUBSTITUTION_WRAPPERS.split(";"); - for (int i = 0; i < wrappers.length; i++) { - String wrapper = wrappers[i]; + for (String wrapper : wrappers) { String[] extAndSubstitution = wrapper.split(" "); if (extAndSubstitution.length != 2) continue; result.add(new FileExtension(extAndSubstitution[0], extAndSubstitution[1])); @@ -57,10 +55,9 @@ public class ImportConfiguration extends AbstractConfiguration { return result; } - public void setExtensions(List items) { - StringBuffer buffer = new StringBuffer(); - for (Iterator iterator = items.iterator(); iterator.hasNext();) { - FileExtension extension = (FileExtension)iterator.next(); + public void setExtensions(List items) { + StringBuilder buffer = new StringBuilder(); + for (FileExtension extension : items) { buffer.append(extension.getExtension()); buffer.append(" "); buffer.append(extension.getKeywordSubstitution().getSubstitution().toString()); diff --git a/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/config/ui/SelectCvsConfigurationDialog.java b/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/config/ui/SelectCvsConfigurationDialog.java index d99cd350085c..53b0a9829700 100644 --- a/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/config/ui/SelectCvsConfigurationDialog.java +++ b/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/config/ui/SelectCvsConfigurationDialog.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2011 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,8 +15,8 @@ */ package com.intellij.cvsSupport2.config.ui; +import com.intellij.CvsBundle; import com.intellij.cvsSupport2.config.CvsRootConfiguration; -import com.intellij.cvsSupport2.config.ui.SelectCvsConfgurationPanel; import com.intellij.openapi.project.Project; import com.intellij.openapi.ui.DialogWrapper; @@ -28,11 +28,11 @@ import java.util.Observer; * author: lesya */ public class SelectCvsConfigurationDialog extends DialogWrapper { - private final SelectCvsConfgurationPanel myPanel; + private final SelectCvsConfigurationPanel myPanel; public SelectCvsConfigurationDialog(Project project) { super(true); - myPanel = new SelectCvsConfgurationPanel(project); + myPanel = new SelectCvsConfigurationPanel(project); setOKActionEnabled(myPanel.getSelectedConfiguration() != null); myPanel.getObservable().addObserver(new Observer() { @@ -40,7 +40,7 @@ public class SelectCvsConfigurationDialog extends DialogWrapper { setOKActionEnabled(myPanel.getSelectedConfiguration() != null); } }); - setTitle(com.intellij.CvsBundle.message("dialog.title.select.cvs.root.configuration")); + setTitle(CvsBundle.message("dialog.title.select.cvs.root.configuration")); init(); } @@ -56,6 +56,4 @@ public class SelectCvsConfigurationDialog extends DialogWrapper { public CvsRootConfiguration getSelectedConfiguration() { return myPanel.getSelectedConfiguration(); } - - } diff --git a/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/config/ui/SelectCvsConfgurationPanel.java b/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/config/ui/SelectCvsConfigurationPanel.java similarity index 77% rename from plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/config/ui/SelectCvsConfgurationPanel.java rename to plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/config/ui/SelectCvsConfigurationPanel.java index 189a264c20e8..f7923aedba83 100644 --- a/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/config/ui/SelectCvsConfgurationPanel.java +++ b/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/config/ui/SelectCvsConfigurationPanel.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2011 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,6 +15,7 @@ */ package com.intellij.cvsSupport2.config.ui; +import com.intellij.CvsBundle; import com.intellij.cvsSupport2.config.CvsApplicationLevelConfiguration; import com.intellij.cvsSupport2.config.CvsRootConfiguration; import com.intellij.openapi.project.Project; @@ -28,20 +29,20 @@ import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.util.ArrayList; -import java.util.Iterator; +import java.util.List; import java.util.Observable; /** * author: lesya */ -public class SelectCvsConfgurationPanel extends JPanel { +public class SelectCvsConfigurationPanel extends JPanel { private final DefaultListModel myModel = new DefaultListModel(); private final JList myList = new JBList(myModel); private CvsRootConfiguration mySelection; private final Project myProject; private final MyObservable myObservable; - public SelectCvsConfgurationPanel(Project project) { + public SelectCvsConfigurationPanel(Project project) { super(new BorderLayout(2, 4)); myProject = project; add(createListPanel(), BorderLayout.CENTER); @@ -58,13 +59,11 @@ public class SelectCvsConfgurationPanel extends JPanel { myList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); fillModel(null); - - } private Component createButtonPanel() { JPanel result = new JPanel(new BorderLayout()); - JButton jButton = new JButton(com.intellij.CvsBundle.message("button.text.configure.cvs.roots")); + JButton jButton = new JButton(CvsBundle.message("button.text.configure.cvs.roots")); jButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { editConfigurations(); @@ -83,44 +82,35 @@ public class SelectCvsConfgurationPanel extends JPanel { } public void editConfigurations() { + final CvsApplicationLevelConfiguration configuration = CvsApplicationLevelConfiguration.getInstance(); CvsConfigurationsListEditor cvsConfigurationsListEditor = - new CvsConfigurationsListEditor(new ArrayList(getConfigurationList()), myProject); + new CvsConfigurationsListEditor(new ArrayList(configuration.CONFIGURATIONS), myProject); CvsRootConfiguration selectedConfiguration = getSelectedConfiguration(); if (selectedConfiguration != null) { cvsConfigurationsListEditor.selectConfiguration(selectedConfiguration); } cvsConfigurationsListEditor.show(); if (cvsConfigurationsListEditor.isOK()) { - getConfiguration().CONFIGURATIONS = - new ArrayList(cvsConfigurationsListEditor.getConfigurations()); + configuration.CONFIGURATIONS = + new ArrayList(cvsConfigurationsListEditor.getConfigurations()); fillModel(cvsConfigurationsListEditor.getSelectedConfiguration()); } } private void fillModel(Object selectedConfiguration) { - Object oldSelection = selectedConfiguration == null ? myList.getSelectedValue() : selectedConfiguration; + Object selection = selectedConfiguration == null ? myList.getSelectedValue() : selectedConfiguration; myModel.removeAllElements(); - java.util.List configurations = getConfigurationList(); - for (Iterator each = configurations.iterator(); each.hasNext();) { - CvsRootConfiguration configuration = (CvsRootConfiguration)each.next(); + List configurations = CvsApplicationLevelConfiguration.getInstance().CONFIGURATIONS; + for (CvsRootConfiguration configuration : configurations) { myModel.addElement(configuration); } - myList.setSelectedValue(oldSelection, true); + myList.setSelectedValue(selection, true); if (myList.getSelectedIndex() < 0 && myList.getModel().getSize() > 0) { myList.setSelectedIndex(0); } } - private java.util.List getConfigurationList() { - return getConfiguration().CONFIGURATIONS; - } - - private CvsApplicationLevelConfiguration getConfiguration() { - return CvsApplicationLevelConfiguration.getInstance(); - } - - public CvsRootConfiguration getSelectedConfiguration() { return mySelection; } diff --git a/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/cvsoperations/cvsErrors/ErrorMessagesProcessor.java b/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/cvsoperations/cvsErrors/ErrorMessagesProcessor.java index 7e1475c78da0..e687c965f71f 100644 --- a/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/cvsoperations/cvsErrors/ErrorMessagesProcessor.java +++ b/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/cvsoperations/cvsErrors/ErrorMessagesProcessor.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2011 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,11 +15,8 @@ */ package com.intellij.cvsSupport2.cvsoperations.cvsErrors; +import com.intellij.cvsSupport2.cvsoperations.cvsMessages.CvsMessagesAdapter; import com.intellij.cvsSupport2.errorHandling.CvsException; -import com.intellij.cvsSupport2.cvsoperations.cvsMessages.CvsMessagesAdapter; -import com.intellij.cvsSupport2.cvsoperations.cvsErrors.ErrorProcessor; -import com.intellij.cvsSupport2.cvsoperations.cvsErrors.ErrorProcessor; -import com.intellij.cvsSupport2.cvsoperations.cvsMessages.CvsMessagesAdapter; import com.intellij.cvsSupport2.util.CvsVfsUtil; import com.intellij.openapi.vcs.VcsException; import com.intellij.openapi.vfs.VirtualFile; @@ -32,7 +29,6 @@ public class ErrorMessagesProcessor extends CvsMessagesAdapter implements ErrorP private final List myErrors; private final List myWarnings; - public ErrorMessagesProcessor(List errors) { myErrors = errors; myWarnings = new ArrayList(); @@ -43,7 +39,6 @@ public class ErrorMessagesProcessor extends CvsMessagesAdapter implements ErrorP } public void addError(String message, String relativeFilePath, ICvsFileSystem cvsFileSystem, String cvsRoot) { - addErrorOnCurrentMessage(relativeFilePath, message, cvsFileSystem, myErrors, cvsRoot); } @@ -51,17 +46,18 @@ public class ErrorMessagesProcessor extends CvsMessagesAdapter implements ErrorP addErrorOnCurrentMessage(relativeFilePath, message, cvsFileSystem, myWarnings, cvsRoot); } - private void addErrorOnCurrentMessage(String relativeFileName, - String message, - ICvsFileSystem cvsFileSystem, - List collection, String cvsRoot) { + private static void addErrorOnCurrentMessage(String relativeFileName, + String message, + ICvsFileSystem cvsFileSystem, + List collection, + String cvsRoot) { VirtualFile vFile = getVirtualFile(cvsFileSystem, relativeFileName); VcsException vcsException = new CvsException(message, cvsRoot); if (vFile != null) vcsException.setVirtualFile(vFile); collection.add(vcsException); } - private VirtualFile getVirtualFile(ICvsFileSystem cvsFileSystem, String relativeFileName) { + private static VirtualFile getVirtualFile(ICvsFileSystem cvsFileSystem, String relativeFileName) { if (cvsFileSystem == null) return null; if (relativeFileName == null) return null; return CvsVfsUtil.findFileByIoFile(cvsFileSystem.getLocalFileSystem().getFile(relativeFileName)); diff --git a/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/cvsoperations/cvsErrors/ErrorProcessor.java b/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/cvsoperations/cvsErrors/ErrorProcessor.java index 7fd3d8412747..5c9e5ad05e6f 100644 --- a/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/cvsoperations/cvsErrors/ErrorProcessor.java +++ b/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/cvsoperations/cvsErrors/ErrorProcessor.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2011 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -26,5 +26,5 @@ public interface ErrorProcessor { void addError(VcsException ex); void addWarning(VcsException ex); - List getErrors(); + List getErrors(); } diff --git a/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/ui/experts/SelectCVSConfigurationStep.java b/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/ui/experts/SelectCVSConfigurationStep.java index b9623c737cb7..71d2d3888fcc 100644 --- a/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/ui/experts/SelectCVSConfigurationStep.java +++ b/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/ui/experts/SelectCVSConfigurationStep.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2011 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,8 +15,9 @@ */ package com.intellij.cvsSupport2.ui.experts; +import com.intellij.CvsBundle; import com.intellij.cvsSupport2.config.CvsRootConfiguration; -import com.intellij.cvsSupport2.config.ui.SelectCvsConfgurationPanel; +import com.intellij.cvsSupport2.config.ui.SelectCvsConfigurationPanel; import com.intellij.openapi.project.Project; import javax.swing.*; @@ -28,28 +29,28 @@ import java.util.Observer; * author: lesya */ public class SelectCVSConfigurationStep extends WizardStep{ - private final SelectCvsConfgurationPanel mySelectCvsConfgurationPanel; + private final SelectCvsConfigurationPanel mySelectCvsConfigurationPanel; private final Observer myObserver; public SelectCVSConfigurationStep(Project project, CvsWizard wizard) { - super(com.intellij.CvsBundle.message("dialog.title.select.cvs.configuration"), wizard); - mySelectCvsConfgurationPanel = new SelectCvsConfgurationPanel(project); + super(CvsBundle.message("dialog.title.select.cvs.configuration"), wizard); + mySelectCvsConfigurationPanel = new SelectCvsConfigurationPanel(project); myObserver = new Observer() { public void update(Observable o, Object arg) { getWizard().updateStep(); } }; - mySelectCvsConfgurationPanel.getObservable().addObserver(myObserver); + mySelectCvsConfigurationPanel.getObservable().addObserver(myObserver); init(); } protected void dispose() { - mySelectCvsConfgurationPanel.getObservable().deleteObserver(myObserver); + mySelectCvsConfigurationPanel.getObservable().deleteObserver(myObserver); } public boolean nextIsEnabled() { - return mySelectCvsConfgurationPanel.getSelectedConfiguration() != null; + return mySelectCvsConfigurationPanel.getSelectedConfiguration() != null; } public boolean setActive() { @@ -58,17 +59,17 @@ public class SelectCVSConfigurationStep extends WizardStep{ protected JComponent createComponent() { JPanel result = new JPanel(new BorderLayout()); - result.add(mySelectCvsConfgurationPanel, BorderLayout.CENTER); + result.add(mySelectCvsConfigurationPanel, BorderLayout.CENTER); JPanel buttonPanel = new JPanel(new BorderLayout()); result.add(buttonPanel, BorderLayout.SOUTH); return result; } public CvsRootConfiguration getSelectedConfiguration() { - return mySelectCvsConfgurationPanel.getSelectedConfiguration(); + return mySelectCvsConfigurationPanel.getSelectedConfiguration(); } public Component getPreferredFocusedComponent() { - return mySelectCvsConfgurationPanel.getJList(); + return mySelectCvsConfigurationPanel.getJList(); } } From 8c0bf64c96e3cf19e236089ecd8cef170ae5865b Mon Sep 17 00:00:00 2001 From: Kirill Likhodedov Date: Fri, 19 Aug 2011 15:56:54 +0400 Subject: [PATCH 03/78] IDEA-72909 Fix annotate pattern for Mercurial 1. Spacing alignment between date and line number was changed in hg 1.9. Make the pattern more flexible. 2. Fix leading spaces being added to the author name. 3. Test parsing of the annotate output (HgAnnotateCommand.parse) for 3 versions of Mercurial. Move parse functionality of HgAnnotateCommand to a separate method. 4. Implement equals, hashCode for HgAnnotationLine. [Reviewed by irengrig] --- .../hg4idea/command/HgAnnotateCommand.java | 20 +- .../provider/annotate/HgAnnotationLine.java | 16 + plugins/hg4idea/testData/annotate/etalon | 4621 +++++++++++++++++ plugins/hg4idea/testData/annotate/info.txt | 3 + .../testData/annotate/outputs/hg_1.7.1 | 149 + .../testData/annotate/outputs/hg_1.8.2 | 149 + .../testData/annotate/outputs/hg_1.9.0 | 149 + .../hg4idea/test/HgAnnotateCommandTest.java | 139 + 8 files changed, 5239 insertions(+), 7 deletions(-) create mode 100644 plugins/hg4idea/testData/annotate/etalon create mode 100644 plugins/hg4idea/testData/annotate/info.txt create mode 100644 plugins/hg4idea/testData/annotate/outputs/hg_1.7.1 create mode 100644 plugins/hg4idea/testData/annotate/outputs/hg_1.8.2 create mode 100644 plugins/hg4idea/testData/annotate/outputs/hg_1.9.0 create mode 100644 plugins/hg4idea/testSrc/org/zmlx/hg4idea/test/HgAnnotateCommandTest.java diff --git a/plugins/hg4idea/src/org/zmlx/hg4idea/command/HgAnnotateCommand.java b/plugins/hg4idea/src/org/zmlx/hg4idea/command/HgAnnotateCommand.java index 6fc4bbd22f01..879c6f0428b0 100644 --- a/plugins/hg4idea/src/org/zmlx/hg4idea/command/HgAnnotateCommand.java +++ b/plugins/hg4idea/src/org/zmlx/hg4idea/command/HgAnnotateCommand.java @@ -22,6 +22,7 @@ import org.zmlx.hg4idea.execution.HgCommandResult; import org.zmlx.hg4idea.provider.annotate.HgAnnotationLine; import java.util.ArrayList; +import java.util.Collections; import java.util.List; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -29,7 +30,7 @@ import java.util.regex.Pattern; public class HgAnnotateCommand { private static final Pattern LINE_PATTERN = Pattern.compile( - "(.+)\\s+([0-9]+)\\s+([0-9a-f]+)\\s+([0-9]{4}-[0-9]{2}-[0-9]{2}):([0-9]+):\\s(.*)" + "\\s*(.+)\\s+([0-9]+)\\s+([0-9a-fA-F]+)\\s+([0-9]{4}-[0-9]{2}-[0-9]{2}):\\s*([0-9]+):\\s(.*)" ); private static final int USER_GROUP = 1; @@ -39,10 +40,10 @@ public class HgAnnotateCommand { private static final int LINE_NUMBER_GROUP = 5; private static final int CONTENT_GROUP = 6; - private final Project project; + private final Project myProject; public HgAnnotateCommand(Project project) { - this.project = project; + myProject = project; } public List execute(@NotNull HgFile hgFile, VcsFileRevision revision) { @@ -54,14 +55,19 @@ public class HgAnnotateCommand { arguments.add(revisionNumber.getChangeset()); } arguments.add(hgFile.getRelativePath()); - final HgCommandResult result = new HgCommandExecutor(project).executeInCurrentThread(hgFile.getRepo(), "annotate", arguments); + final HgCommandResult result = new HgCommandExecutor(myProject).executeInCurrentThread(hgFile.getRepo(), "annotate", arguments); - final List annotations = new ArrayList(); if (result == null) { - return annotations; + return Collections.emptyList(); } - for (String line : result.getOutputLines()) { + List outputLines = result.getOutputLines(); + return parse(outputLines); + } + + private static List parse(List outputLines) { + List annotations = new ArrayList(outputLines.size()); + for (String line : outputLines) { Matcher matcher = LINE_PATTERN.matcher(line); if (matcher.matches()) { String user = matcher.group(USER_GROUP); diff --git a/plugins/hg4idea/src/org/zmlx/hg4idea/provider/annotate/HgAnnotationLine.java b/plugins/hg4idea/src/org/zmlx/hg4idea/provider/annotate/HgAnnotationLine.java index 939f0fa359b2..1eb3064dbc8c 100644 --- a/plugins/hg4idea/src/org/zmlx/hg4idea/provider/annotate/HgAnnotationLine.java +++ b/plugins/hg4idea/src/org/zmlx/hg4idea/provider/annotate/HgAnnotationLine.java @@ -38,4 +38,20 @@ public class HgAnnotationLine { return fields.get(field); } + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (!(obj instanceof HgAnnotationLine)) { + return false; + } + HgAnnotationLine other = (HgAnnotationLine) obj; + return fields.equals(other.fields); + } + + @Override + public int hashCode() { + return fields.hashCode(); + } } diff --git a/plugins/hg4idea/testData/annotate/etalon b/plugins/hg4idea/testData/annotate/etalon new file mode 100644 index 000000000000..352a6064087d --- /dev/null +++ b/plugins/hg4idea/testData/annotate/etalon @@ -0,0 +1,4621 @@ + + + + + USER + adrian + + + REVISION + + 2287 + 3f0790d500a9 + + + + false + + + + DATE + 2006-02-24 + + + LINE + 1 + + + CONTENT + "Database cache backend." + + + + + + + + jezdez + + + + + 16338 + bf038debb499 + + + + false + + + + + 2011-07-13 + + + + 2 + + + + import base64 + + + + + + + + jezdez + + + + + 16338 + bf038debb499 + + + + false + + + + + 2011-07-13 + + + + 3 + + + + import time + + + + + + + + jezdez + + + + + 16338 + bf038debb499 + + + + false + + + + + 2011-07-13 + + + + 4 + + + + from datetime import datetime + + + + + + + + adrian + + + + + 2287 + 3f0790d500a9 + + + + false + + + + + 2006-02-24 + + + + 2 + + + + + + + + + + + + adrian + + + + + 2287 + 3f0790d500a9 + + + + false + + + + + 2006-02-24 + + + + 7 + + + + try: + + + + + + + + adrian + + + + + 2287 + 3f0790d500a9 + + + + false + + + + + 2006-02-24 + + + + 8 + + + + import cPickle as pickle + + + + + + + + adrian + + + + + 2287 + 3f0790d500a9 + + + + false + + + + + 2006-02-24 + + + + 9 + + + + except ImportError: + + + + + + + + adrian + + + + + 2287 + 3f0790d500a9 + + + + false + + + + + 2006-02-24 + + + + 10 + + + + import pickle + + + + + + + + adrian + + + + + 2287 + 3f0790d500a9 + + + + false + + + + + 2006-02-24 + + + + 11 + + + + + + + + + + + + jezdez + + + + + 16338 + bf038debb499 + + + + false + + + + + 2011-07-13 + + + + 11 + + + + from django.core.cache.backends.base import BaseCache + + + + + + + + jezdez + + + + + 16338 + bf038debb499 + + + + false + + + + + 2011-07-13 + + + + 12 + + + + from django.db import connections, router, transaction, DatabaseError + + + + + + + + jezdez + + + + + 16338 + bf038debb499 + + + + false + + + + + 2011-07-13 + + + + 13 + + + + + + + + + + + + jezdez + + + + + 16338 + bf038debb499 + + + + false + + + + + 2011-07-13 + + + + 14 + + + + + + + + + + + + russellm + + + + + 13275 + 4dd52d4f3f50 + + + + false + + + + + 2010-08-05 + + + + 12 + + + + class Options(object): + + + + + + + + russellm + + + + + 13275 + 4dd52d4f3f50 + + + + false + + + + + 2010-08-05 + + + + 13 + + + + """A class that will quack like a Django model _meta class. + + + + + + + + russellm + + + + + 13275 + 4dd52d4f3f50 + + + + false + + + + + 2010-08-05 + + + + 14 + + + + + + + + + + + + russellm + + + + + 13275 + 4dd52d4f3f50 + + + + false + + + + + 2010-08-05 + + + + 15 + + + + This allows cache operations to be controlled by the router + + + + + + + + russellm + + + + + 13275 + 4dd52d4f3f50 + + + + false + + + + + 2010-08-05 + + + + 16 + + + + """ + + + + + + + + russellm + + + + + 13275 + 4dd52d4f3f50 + + + + false + + + + + 2010-08-05 + + + + 17 + + + + def __init__(self, table): + + + + + + + + russellm + + + + + 13275 + 4dd52d4f3f50 + + + + false + + + + + 2010-08-05 + + + + 18 + + + + self.db_table = table + + + + + + + + russellm + + + + + 13275 + 4dd52d4f3f50 + + + + false + + + + + 2010-08-05 + + + + 19 + + + + self.app_label = 'django_cache' + + + + + + + + russellm + + + + + 13275 + 4dd52d4f3f50 + + + + false + + + + + 2010-08-05 + + + + 20 + + + + self.module_name = 'cacheentry' + + + + + + + + russellm + + + + + 13275 + 4dd52d4f3f50 + + + + false + + + + + 2010-08-05 + + + + 21 + + + + self.verbose_name = 'cache entry' + + + + + + + + russellm + + + + + 13275 + 4dd52d4f3f50 + + + + false + + + + + 2010-08-05 + + + + 22 + + + + self.verbose_name_plural = 'cache entries' + + + + + + + + russellm + + + + + 13275 + 4dd52d4f3f50 + + + + false + + + + + 2010-08-05 + + + + 23 + + + + self.object_name = 'CacheEntry' + + + + + + + + russellm + + + + + 13275 + 4dd52d4f3f50 + + + + false + + + + + 2010-08-05 + + + + 24 + + + + self.abstract = False + + + + + + + + russellm + + + + + 13275 + 4dd52d4f3f50 + + + + false + + + + + 2010-08-05 + + + + 25 + + + + self.managed = True + + + + + + + + russellm + + + + + 13275 + 4dd52d4f3f50 + + + + false + + + + + 2010-08-05 + + + + 26 + + + + self.proxy = False + + + + + + + + russellm + + + + + 13275 + 4dd52d4f3f50 + + + + false + + + + + 2010-08-05 + + + + 27 + + + + + + + + + + + + russellm + + + + + 14807 + 905c4a7e1f19 + + + + false + + + + + 2010-12-21 + + + + 28 + + + + class BaseDatabaseCache(BaseCache): + + + + + + + + russellm + + + + + 14807 + 905c4a7e1f19 + + + + false + + + + + 2010-12-21 + + + + 29 + + + + def __init__(self, table, params): + + + + + + + + russellm + + + + + 14807 + 905c4a7e1f19 + + + + false + + + + + 2010-12-21 + + + + 30 + + + + BaseCache.__init__(self, params) + + + + + + + + russellm + + + + + 13275 + 4dd52d4f3f50 + + + + false + + + + + 2010-08-05 + + + + 31 + + + + self._table = table + + + + + + + + russellm + + + + + 13275 + 4dd52d4f3f50 + + + + false + + + + + 2010-08-05 + + + + 32 + + + + + + + + + + + + russellm + + + + + 13275 + 4dd52d4f3f50 + + + + false + + + + + 2010-08-05 + + + + 33 + + + + class CacheEntry(object): + + + + + + + + russellm + + + + + 13275 + 4dd52d4f3f50 + + + + false + + + + + 2010-08-05 + + + + 34 + + + + _meta = Options(table) + + + + + + + + russellm + + + + + 13275 + 4dd52d4f3f50 + + + + false + + + + + 2010-08-05 + + + + 35 + + + + self.cache_model_class = CacheEntry + + + + + + + + russellm + + + + + 13275 + 4dd52d4f3f50 + + + + false + + + + + 2010-08-05 + + + + 36 + + + + + + + + + + + + russellm + + + + + 14807 + 905c4a7e1f19 + + + + false + + + + + 2010-12-21 + + + + 37 + + + + class DatabaseCache(BaseDatabaseCache): + + + + + + + + russellm + + + + + 14425 + 793e94ba2037 + + + + false + + + + + 2010-11-19 + + + + 38 + + + + def get(self, key, default=None, version=None): + + + + + + + + russellm + + + + + 14425 + 793e94ba2037 + + + + false + + + + + 2010-11-19 + + + + 39 + + + + key = self.make_key(key, version=version) + + + + + + + + mtredinnick + + + + + 13568 + 7e0b7bf098d2 + + + + false + + + + + 2010-09-12 + + + + 49 + + + + self.validate_key(key) + + + + + + + + russellm + + + + + 13275 + 4dd52d4f3f50 + + + + false + + + + + 2010-08-05 + + + + 49 + + + + db = router.db_for_read(self.cache_model_class) + + + + + + + + russellm + + + + + 13275 + 4dd52d4f3f50 + + + + false + + + + + 2010-08-05 + + + + 50 + + + + table = connections[db].ops.quote_name(self._table) + + + + + + + + russellm + + + + + 13275 + 4dd52d4f3f50 + + + + false + + + + + 2010-08-05 + + + + 51 + + + + cursor = connections[db].cursor() + + + + + + + + russellm + + + + + 13275 + 4dd52d4f3f50 + + + + false + + + + + 2010-08-05 + + + + 52 + + + + + + + + + + + + russellm + + + + + 13275 + 4dd52d4f3f50 + + + + false + + + + + 2010-08-05 + + + + 53 + + + + cursor.execute("SELECT cache_key, value, expires FROM %s WHERE cache_key = %%s" % table, [key]) + + + + + + + + adrian + + + + + 2287 + 3f0790d500a9 + + + + false + + + + + 2006-02-24 + + + + 30 + + + + row = cursor.fetchone() + + + + + + + + adrian + + + + + 2287 + 3f0790d500a9 + + + + false + + + + + 2006-02-24 + + + + 31 + + + + if row is None: + + + + + + + + adrian + + + + + 2287 + 3f0790d500a9 + + + + false + + + + + 2006-02-24 + + + + 32 + + + + return default + + + + + + + + adrian + + + + + 2287 + 3f0790d500a9 + + + + false + + + + + 2006-02-24 + + + + 33 + + + + now = datetime.now() + + + + + + + + adrian + + + + + 2287 + 3f0790d500a9 + + + + false + + + + + 2006-02-24 + + + + 34 + + + + if row[2] < now: + + + + + + + + russellm + + + + + 13275 + 4dd52d4f3f50 + + + + false + + + + + 2010-08-05 + + + + 59 + + + + db = router.db_for_write(self.cache_model_class) + + + + + + + + russellm + + + + + 13275 + 4dd52d4f3f50 + + + + false + + + + + 2010-08-05 + + + + 60 + + + + cursor = connections[db].cursor() + + + + + + + + russellm + + + + + 13275 + 4dd52d4f3f50 + + + + false + + + + + 2010-08-05 + + + + 61 + + + + cursor.execute("DELETE FROM %s WHERE cache_key = %%s" % table, [key]) + + + + + + + + russellm + + + + + 13275 + 4dd52d4f3f50 + + + + false + + + + + 2010-08-05 + + + + 62 + + + + transaction.commit_unless_managed(using=db) + + + + + + + + adrian + + + + + 2287 + 3f0790d500a9 + + + + false + + + + + 2006-02-24 + + + + 37 + + + + return default + + + + + + + + russellm + + + + + 13275 + 4dd52d4f3f50 + + + + false + + + + + 2010-08-05 + + + + 64 + + + + value = connections[db].ops.process_clob(row[1]) + + + + + + + + ikelly + + + + + 9862 + 8739c35149dd + + + + false + + + + + 2009-03-13 + + + + 39 + + + + return pickle.loads(base64.decodestring(value)) + + + + + + + + adrian + + + + + 2287 + 3f0790d500a9 + + + + false + + + + + 2006-02-24 + + + + 39 + + + + + + + + + + + + russellm + + + + + 14425 + 793e94ba2037 + + + + false + + + + + 2010-11-19 + + + + 59 + + + + def set(self, key, value, timeout=None, version=None): + + + + + + + + russellm + + + + + 14425 + 793e94ba2037 + + + + false + + + + + 2010-11-19 + + + + 60 + + + + key = self.make_key(key, version=version) + + + + + + + + mtredinnick + + + + + 13568 + 7e0b7bf098d2 + + + + false + + + + + 2010-09-12 + + + + 69 + + + + self.validate_key(key) + + + + + + + + mtredinnick + + + + + 8110 + c787c7f62142 + + + + false + + + + + 2008-08-10 + + + + 41 + + + + self._base_set('set', key, value, timeout) + + + + + + + + mtredinnick + + + + + 6421 + b4175804cc7b + + + + false + + + + + 2007-10-20 + + + + 45 + + + + + + + + + + + + russellm + + + + + 14425 + 793e94ba2037 + + + + false + + + + + 2010-11-19 + + + + 64 + + + + def add(self, key, value, timeout=None, version=None): + + + + + + + + russellm + + + + + 14425 + 793e94ba2037 + + + + false + + + + + 2010-11-19 + + + + 65 + + + + key = self.make_key(key, version=version) + + + + + + + + mtredinnick + + + + + 13568 + 7e0b7bf098d2 + + + + false + + + + + 2010-09-12 + + + + 73 + + + + self.validate_key(key) + + + + + + + + mtredinnick + + + + + 6438 + 5096a56a9ac6 + + + + false + + + + + 2007-10-21 + + + + 44 + + + + return self._base_set('add', key, value, timeout) + + + + + + + + mtredinnick + + + + + 6438 + 5096a56a9ac6 + + + + false + + + + + 2007-10-21 + + + + 45 + + + + + + + + + + + + mtredinnick + + + + + 6421 + b4175804cc7b + + + + false + + + + + 2007-10-20 + + + + 46 + + + + def _base_set(self, mode, key, value, timeout=None): + + + + + + + + adrian + + + + + 2287 + 3f0790d500a9 + + + + false + + + + + 2006-02-24 + + + + 41 + + + + if timeout is None: + + + + + + + + adrian + + + + + 2287 + 3f0790d500a9 + + + + false + + + + + 2006-02-24 + + + + 42 + + + + timeout = self.default_timeout + + + + + + + + russellm + + + + + 13275 + 4dd52d4f3f50 + + + + false + + + + + 2010-08-05 + + + + 76 + + + + db = router.db_for_write(self.cache_model_class) + + + + + + + + russellm + + + + + 13275 + 4dd52d4f3f50 + + + + false + + + + + 2010-08-05 + + + + 77 + + + + table = connections[db].ops.quote_name(self._table) + + + + + + + + russellm + + + + + 13275 + 4dd52d4f3f50 + + + + false + + + + + 2010-08-05 + + + + 78 + + + + cursor = connections[db].cursor() + + + + + + + + russellm + + + + + 13275 + 4dd52d4f3f50 + + + + false + + + + + 2010-08-05 + + + + 79 + + + + + + + + + + + + russellm + + + + + 13275 + 4dd52d4f3f50 + + + + false + + + + + 2010-08-05 + + + + 80 + + + + cursor.execute("SELECT COUNT(*) FROM %s" % table) + + + + + + + + adrian + + + + + 2287 + 3f0790d500a9 + + + + false + + + + + 2006-02-24 + + + + 45 + + + + num = cursor.fetchone()[0] + + + + + + + + adrian + + + + + 2287 + 3f0790d500a9 + + + + false + + + + + 2006-02-24 + + + + 46 + + + + now = datetime.now().replace(microsecond=0) + + + + + + + + adrian + + + + + 2287 + 3f0790d500a9 + + + + false + + + + + 2006-02-24 + + + + 47 + + + + exp = datetime.fromtimestamp(time.time() + timeout).replace(microsecond=0) + + + + + + + + adrian + + + + + 2287 + 3f0790d500a9 + + + + false + + + + + 2006-02-24 + + + + 48 + + + + if num > self._max_entries: + + + + + + + + russellm + + + + + 13275 + 4dd52d4f3f50 + + + + false + + + + + 2010-08-05 + + + + 85 + + + + self._cull(db, cursor, now) + + + + + + + + adrian + + + + + 2287 + 3f0790d500a9 + + + + false + + + + + 2006-02-24 + + + + 50 + + + + encoded = base64.encodestring(pickle.dumps(value, 2)).strip() + + + + + + + + russellm + + + + + 13275 + 4dd52d4f3f50 + + + + false + + + + + 2010-08-05 + + + + 87 + + + + cursor.execute("SELECT cache_key, expires FROM %s WHERE cache_key = %%s" % table, [key]) + + + + + + + + adrian + + + + + 2287 + 3f0790d500a9 + + + + false + + + + + 2006-02-24 + + + + 52 + + + + try: + + + + + + + + mtredinnick + + + + + 9753 + 0ab5ef23e1bc + + + + false + + + + + 2009-03-02 + + + + 59 + + + + result = cursor.fetchone() + + + + + + + + mtredinnick + + + + + 9753 + 0ab5ef23e1bc + + + + false + + + + + 2009-03-02 + + + + 60 + + + + if result and (mode == 'set' or + + + + + + + + mtredinnick + + + + + 9753 + 0ab5ef23e1bc + + + + false + + + + + 2009-03-02 + + + + 61 + + + + (mode == 'add' and result[1] < now)): + + + + + + + + russellm + + + + + 13275 + 4dd52d4f3f50 + + + + false + + + + + 2010-08-05 + + + + 92 + + + + cursor.execute("UPDATE %s SET value = %%s, expires = %%s WHERE cache_key = %%s" % table, + + + + + + + + russellm + + + + + 13275 + 4dd52d4f3f50 + + + + false + + + + + 2010-08-05 + + + + 93 + + + + [encoded, connections[db].ops.value_to_db_datetime(exp), key]) + + + + + + + + adrian + + + + + 2287 + 3f0790d500a9 + + + + false + + + + + 2006-02-24 + + + + 55 + + + + else: + + + + + + + + russellm + + + + + 13275 + 4dd52d4f3f50 + + + + false + + + + + 2010-08-05 + + + + 95 + + + + cursor.execute("INSERT INTO %s (cache_key, value, expires) VALUES (%%s, %%s, %%s)" % table, + + + + + + + + russellm + + + + + 13275 + 4dd52d4f3f50 + + + + false + + + + + 2010-08-05 + + + + 96 + + + + [key, encoded, connections[db].ops.value_to_db_datetime(exp)]) + + + + + + + + adrian + + + + + 2287 + 3f0790d500a9 + + + + false + + + + + 2006-02-24 + + + + 57 + + + + except DatabaseError: + + + + + + + + adrian + + + + + 2287 + 3f0790d500a9 + + + + false + + + + + 2006-02-24 + + + + 58 + + + + # To be threadsafe, updates/inserts are allowed to fail silently + + + + + + + + russellm + + + + + 13275 + 4dd52d4f3f50 + + + + false + + + + + 2010-08-05 + + + + 99 + + + + transaction.rollback_unless_managed(using=db) + + + + + + + + mtredinnick + + + + + 8110 + c787c7f62142 + + + + false + + + + + 2008-08-10 + + + + 65 + + + + return False + + + + + + + + adrian + + + + + 2287 + 3f0790d500a9 + + + + false + + + + + 2006-02-24 + + + + 60 + + + + else: + + + + + + + + russellm + + + + + 13275 + 4dd52d4f3f50 + + + + false + + + + + 2010-08-05 + + + + 102 + + + + transaction.commit_unless_managed(using=db) + + + + + + + + mtredinnick + + + + + 8110 + c787c7f62142 + + + + false + + + + + 2008-08-10 + + + + 68 + + + + return True + + + + + + + + adrian + + + + + 2287 + 3f0790d500a9 + + + + false + + + + + 2006-02-24 + + + + 62 + + + + + + + + + + + + russellm + + + + + 14425 + 793e94ba2037 + + + + false + + + + + 2010-11-19 + + + + 101 + + + + def delete(self, key, version=None): + + + + + + + + russellm + + + + + 14425 + 793e94ba2037 + + + + false + + + + + 2010-11-19 + + + + 102 + + + + key = self.make_key(key, version=version) + + + + + + + + mtredinnick + + + + + 13568 + 7e0b7bf098d2 + + + + false + + + + + 2010-09-12 + + + + 109 + + + + self.validate_key(key) + + + + + + + + russellm + + + + + 14425 + 793e94ba2037 + + + + false + + + + + 2010-11-19 + + + + 104 + + + + + + + + + + + + russellm + + + + + 13275 + 4dd52d4f3f50 + + + + false + + + + + 2010-08-05 + + + + 106 + + + + db = router.db_for_write(self.cache_model_class) + + + + + + + + russellm + + + + + 13275 + 4dd52d4f3f50 + + + + false + + + + + 2010-08-05 + + + + 107 + + + + table = connections[db].ops.quote_name(self._table) + + + + + + + + russellm + + + + + 13275 + 4dd52d4f3f50 + + + + false + + + + + 2010-08-05 + + + + 108 + + + + cursor = connections[db].cursor() + + + + + + + + russellm + + + + + 13275 + 4dd52d4f3f50 + + + + false + + + + + 2010-08-05 + + + + 109 + + + + + + + + + + + + russellm + + + + + 13275 + 4dd52d4f3f50 + + + + false + + + + + 2010-08-05 + + + + 110 + + + + cursor.execute("DELETE FROM %s WHERE cache_key = %%s" % table, [key]) + + + + + + + + russellm + + + + + 13275 + 4dd52d4f3f50 + + + + false + + + + + 2010-08-05 + + + + 111 + + + + transaction.commit_unless_managed(using=db) + + + + + + + + adrian + + + + + 2287 + 3f0790d500a9 + + + + false + + + + + 2006-02-24 + + + + 67 + + + + + + + + + + + + russellm + + + + + 14425 + 793e94ba2037 + + + + false + + + + + 2010-11-19 + + + + 112 + + + + def has_key(self, key, version=None): + + + + + + + + russellm + + + + + 14425 + 793e94ba2037 + + + + false + + + + + 2010-11-19 + + + + 113 + + + + key = self.make_key(key, version=version) + + + + + + + + mtredinnick + + + + + 13568 + 7e0b7bf098d2 + + + + false + + + + + 2010-09-12 + + + + 118 + + + + self.validate_key(key) + + + + + + + + russellm + + + + + 14425 + 793e94ba2037 + + + + false + + + + + 2010-11-19 + + + + 115 + + + + + + + + + + + + russellm + + + + + 13275 + 4dd52d4f3f50 + + + + false + + + + + 2010-08-05 + + + + 114 + + + + db = router.db_for_read(self.cache_model_class) + + + + + + + + russellm + + + + + 13275 + 4dd52d4f3f50 + + + + false + + + + + 2010-08-05 + + + + 115 + + + + table = connections[db].ops.quote_name(self._table) + + + + + + + + russellm + + + + + 13275 + 4dd52d4f3f50 + + + + false + + + + + 2010-08-05 + + + + 116 + + + + cursor = connections[db].cursor() + + + + + + + + russellm + + + + + 13275 + 4dd52d4f3f50 + + + + false + + + + + 2010-08-05 + + + + 117 + + + + + + + + + + + + mtredinnick + + + + + 9753 + 0ab5ef23e1bc + + + + false + + + + + 2009-03-02 + + + + 78 + + + + now = datetime.now().replace(microsecond=0) + + + + + + + + russellm + + + + + 13275 + 4dd52d4f3f50 + + + + false + + + + + 2010-08-05 + + + + 119 + + + + cursor.execute("SELECT cache_key FROM %s WHERE cache_key = %%s and expires > %%s" % table, + + + + + + + + russellm + + + + + 13275 + 4dd52d4f3f50 + + + + false + + + + + 2010-08-05 + + + + 120 + + + + [key, connections[db].ops.value_to_db_datetime(now)]) + + + + + + + + adrian + + + + + 2287 + 3f0790d500a9 + + + + false + + + + + 2006-02-24 + + + + 71 + + + + return cursor.fetchone() is not None + + + + + + + + adrian + + + + + 2287 + 3f0790d500a9 + + + + false + + + + + 2006-02-24 + + + + 72 + + + + + + + + + + + + russellm + + + + + 13275 + 4dd52d4f3f50 + + + + false + + + + + 2010-08-05 + + + + 123 + + + + def _cull(self, db, cursor, now): + + + + + + + + adrian + + + + + 2287 + 3f0790d500a9 + + + + false + + + + + 2006-02-24 + + + + 74 + + + + if self._cull_frequency == 0: + + + + + + + + russellm + + + + + 12116 + c1ad14c551a9 + + + + false + + + + + 2010-01-27 + + + + 87 + + + + self.clear() + + + + + + + + adrian + + + + + 2287 + 3f0790d500a9 + + + + false + + + + + 2006-02-24 + + + + 76 + + + + else: + + + + + + + + russellm + + + + + 13480 + 7351411944a9 + + + + false + + + + + 2010-08-31 + + + + 127 + + + + table = connections[db].ops.quote_name(self._table) + + + + + + + + russellm + + + + + 13275 + 4dd52d4f3f50 + + + + false + + + + + 2010-08-05 + + + + 127 + + + + cursor.execute("DELETE FROM %s WHERE expires < %%s" % table, + + + + + + + + russellm + + + + + 13275 + 4dd52d4f3f50 + + + + false + + + + + 2010-08-05 + + + + 128 + + + + [connections[db].ops.value_to_db_datetime(now)]) + + + + + + + + russellm + + + + + 13275 + 4dd52d4f3f50 + + + + false + + + + + 2010-08-05 + + + + 129 + + + + cursor.execute("SELECT COUNT(*) FROM %s" % table) + + + + + + + + adrian + + + + + 2287 + 3f0790d500a9 + + + + false + + + + + 2006-02-24 + + + + 79 + + + + num = cursor.fetchone()[0] + + + + + + + + adrian + + + + + 2287 + 3f0790d500a9 + + + + false + + + + + 2006-02-24 + + + + 80 + + + + if num > self._max_entries: + + + + + + + + russellm + + + + + 13275 + 4dd52d4f3f50 + + + + false + + + + + 2010-08-05 + + + + 132 + + + + cursor.execute("SELECT cache_key FROM %s ORDER BY cache_key LIMIT 1 OFFSET %%s" % table, [num / self._cull_frequency]) + + + + + + + + russellm + + + + + 13275 + 4dd52d4f3f50 + + + + false + + + + + 2010-08-05 + + + + 133 + + + + cursor.execute("DELETE FROM %s WHERE cache_key < %%s" % table, [cursor.fetchone()[0]]) + + + + + + + + russellm + + + + + 12116 + c1ad14c551a9 + + + + false + + + + + 2010-01-27 + + + + 95 + + + + + + + + + + + + russellm + + + + + 12116 + c1ad14c551a9 + + + + false + + + + + 2010-01-27 + + + + 96 + + + + def clear(self): + + + + + + + + russellm + + + + + 13275 + 4dd52d4f3f50 + + + + false + + + + + 2010-08-05 + + + + 136 + + + + db = router.db_for_write(self.cache_model_class) + + + + + + + + russellm + + + + + 13275 + 4dd52d4f3f50 + + + + false + + + + + 2010-08-05 + + + + 137 + + + + table = connections[db].ops.quote_name(self._table) + + + + + + + + russellm + + + + + 13275 + 4dd52d4f3f50 + + + + false + + + + + 2010-08-05 + + + + 138 + + + + cursor = connections[db].cursor() + + + + + + + + russellm + + + + + 13275 + 4dd52d4f3f50 + + + + false + + + + + 2010-08-05 + + + + 139 + + + + cursor.execute('DELETE FROM %s' % table) + + + + + + + + russellm + + + + + 14807 + 905c4a7e1f19 + + + + false + + + + + 2010-12-21 + + + + 143 + + + + + + + + + + + + russellm + + + + + 14807 + 905c4a7e1f19 + + + + false + + + + + 2010-12-21 + + + + 144 + + + + # For backwards compatibility + + + + + + + + russellm + + + + + 14807 + 905c4a7e1f19 + + + + false + + + + + 2010-12-21 + + + + 145 + + + + class CacheClass(DatabaseCache): + + + + + + + + russellm + + + + + 14807 + 905c4a7e1f19 + + + + false + + + + + 2010-12-21 + + + + 146 + + + + pass + + + + \ No newline at end of file diff --git a/plugins/hg4idea/testData/annotate/info.txt b/plugins/hg4idea/testData/annotate/info.txt new file mode 100644 index 000000000000..b459a2df2395 --- /dev/null +++ b/plugins/hg4idea/testData/annotate/info.txt @@ -0,0 +1,3 @@ +The source - a file with huge history from the hg repository of the Django project: https://bitbucket.org/django/django/ +File: /Users/loki/temp/django/django/core/cache/backends/db.py +Last revision at the time of parsing: bf038debb499 (13.07.11 13:35) \ No newline at end of file diff --git a/plugins/hg4idea/testData/annotate/outputs/hg_1.7.1 b/plugins/hg4idea/testData/annotate/outputs/hg_1.7.1 new file mode 100644 index 000000000000..3acc13feeb81 --- /dev/null +++ b/plugins/hg4idea/testData/annotate/outputs/hg_1.7.1 @@ -0,0 +1,149 @@ + adrian 2287 3f0790d500a9 2006-02-24:1: "Database cache backend." + jezdez 16338 bf038debb499 2011-07-13:2: import base64 + jezdez 16338 bf038debb499 2011-07-13:3: import time + jezdez 16338 bf038debb499 2011-07-13:4: from datetime import datetime + adrian 2287 3f0790d500a9 2006-02-24:2: + adrian 2287 3f0790d500a9 2006-02-24:7: try: + adrian 2287 3f0790d500a9 2006-02-24:8: import cPickle as pickle + adrian 2287 3f0790d500a9 2006-02-24:9: except ImportError: + adrian 2287 3f0790d500a9 2006-02-24:10: import pickle + adrian 2287 3f0790d500a9 2006-02-24:11: + jezdez 16338 bf038debb499 2011-07-13:11: from django.core.cache.backends.base import BaseCache + jezdez 16338 bf038debb499 2011-07-13:12: from django.db import connections, router, transaction, DatabaseError + jezdez 16338 bf038debb499 2011-07-13:13: + jezdez 16338 bf038debb499 2011-07-13:14: + russellm 13275 4dd52d4f3f50 2010-08-05:12: class Options(object): + russellm 13275 4dd52d4f3f50 2010-08-05:13: """A class that will quack like a Django model _meta class. + russellm 13275 4dd52d4f3f50 2010-08-05:14: + russellm 13275 4dd52d4f3f50 2010-08-05:15: This allows cache operations to be controlled by the router + russellm 13275 4dd52d4f3f50 2010-08-05:16: """ + russellm 13275 4dd52d4f3f50 2010-08-05:17: def __init__(self, table): + russellm 13275 4dd52d4f3f50 2010-08-05:18: self.db_table = table + russellm 13275 4dd52d4f3f50 2010-08-05:19: self.app_label = 'django_cache' + russellm 13275 4dd52d4f3f50 2010-08-05:20: self.module_name = 'cacheentry' + russellm 13275 4dd52d4f3f50 2010-08-05:21: self.verbose_name = 'cache entry' + russellm 13275 4dd52d4f3f50 2010-08-05:22: self.verbose_name_plural = 'cache entries' + russellm 13275 4dd52d4f3f50 2010-08-05:23: self.object_name = 'CacheEntry' + russellm 13275 4dd52d4f3f50 2010-08-05:24: self.abstract = False + russellm 13275 4dd52d4f3f50 2010-08-05:25: self.managed = True + russellm 13275 4dd52d4f3f50 2010-08-05:26: self.proxy = False + russellm 13275 4dd52d4f3f50 2010-08-05:27: + russellm 14807 905c4a7e1f19 2010-12-21:28: class BaseDatabaseCache(BaseCache): + russellm 14807 905c4a7e1f19 2010-12-21:29: def __init__(self, table, params): + russellm 14807 905c4a7e1f19 2010-12-21:30: BaseCache.__init__(self, params) + russellm 13275 4dd52d4f3f50 2010-08-05:31: self._table = table + russellm 13275 4dd52d4f3f50 2010-08-05:32: + russellm 13275 4dd52d4f3f50 2010-08-05:33: class CacheEntry(object): + russellm 13275 4dd52d4f3f50 2010-08-05:34: _meta = Options(table) + russellm 13275 4dd52d4f3f50 2010-08-05:35: self.cache_model_class = CacheEntry + russellm 13275 4dd52d4f3f50 2010-08-05:36: + russellm 14807 905c4a7e1f19 2010-12-21:37: class DatabaseCache(BaseDatabaseCache): + russellm 14425 793e94ba2037 2010-11-19:38: def get(self, key, default=None, version=None): + russellm 14425 793e94ba2037 2010-11-19:39: key = self.make_key(key, version=version) +mtredinnick 13568 7e0b7bf098d2 2010-09-12:49: self.validate_key(key) + russellm 13275 4dd52d4f3f50 2010-08-05:49: db = router.db_for_read(self.cache_model_class) + russellm 13275 4dd52d4f3f50 2010-08-05:50: table = connections[db].ops.quote_name(self._table) + russellm 13275 4dd52d4f3f50 2010-08-05:51: cursor = connections[db].cursor() + russellm 13275 4dd52d4f3f50 2010-08-05:52: + russellm 13275 4dd52d4f3f50 2010-08-05:53: cursor.execute("SELECT cache_key, value, expires FROM %s WHERE cache_key = %%s" % table, [key]) + adrian 2287 3f0790d500a9 2006-02-24:30: row = cursor.fetchone() + adrian 2287 3f0790d500a9 2006-02-24:31: if row is None: + adrian 2287 3f0790d500a9 2006-02-24:32: return default + adrian 2287 3f0790d500a9 2006-02-24:33: now = datetime.now() + adrian 2287 3f0790d500a9 2006-02-24:34: if row[2] < now: + russellm 13275 4dd52d4f3f50 2010-08-05:59: db = router.db_for_write(self.cache_model_class) + russellm 13275 4dd52d4f3f50 2010-08-05:60: cursor = connections[db].cursor() + russellm 13275 4dd52d4f3f50 2010-08-05:61: cursor.execute("DELETE FROM %s WHERE cache_key = %%s" % table, [key]) + russellm 13275 4dd52d4f3f50 2010-08-05:62: transaction.commit_unless_managed(using=db) + adrian 2287 3f0790d500a9 2006-02-24:37: return default + russellm 13275 4dd52d4f3f50 2010-08-05:64: value = connections[db].ops.process_clob(row[1]) + ikelly 9862 8739c35149dd 2009-03-13:39: return pickle.loads(base64.decodestring(value)) + adrian 2287 3f0790d500a9 2006-02-24:39: + russellm 14425 793e94ba2037 2010-11-19:59: def set(self, key, value, timeout=None, version=None): + russellm 14425 793e94ba2037 2010-11-19:60: key = self.make_key(key, version=version) +mtredinnick 13568 7e0b7bf098d2 2010-09-12:69: self.validate_key(key) +mtredinnick 8110 c787c7f62142 2008-08-10:41: self._base_set('set', key, value, timeout) +mtredinnick 6421 b4175804cc7b 2007-10-20:45: + russellm 14425 793e94ba2037 2010-11-19:64: def add(self, key, value, timeout=None, version=None): + russellm 14425 793e94ba2037 2010-11-19:65: key = self.make_key(key, version=version) +mtredinnick 13568 7e0b7bf098d2 2010-09-12:73: self.validate_key(key) +mtredinnick 6438 5096a56a9ac6 2007-10-21:44: return self._base_set('add', key, value, timeout) +mtredinnick 6438 5096a56a9ac6 2007-10-21:45: +mtredinnick 6421 b4175804cc7b 2007-10-20:46: def _base_set(self, mode, key, value, timeout=None): + adrian 2287 3f0790d500a9 2006-02-24:41: if timeout is None: + adrian 2287 3f0790d500a9 2006-02-24:42: timeout = self.default_timeout + russellm 13275 4dd52d4f3f50 2010-08-05:76: db = router.db_for_write(self.cache_model_class) + russellm 13275 4dd52d4f3f50 2010-08-05:77: table = connections[db].ops.quote_name(self._table) + russellm 13275 4dd52d4f3f50 2010-08-05:78: cursor = connections[db].cursor() + russellm 13275 4dd52d4f3f50 2010-08-05:79: + russellm 13275 4dd52d4f3f50 2010-08-05:80: cursor.execute("SELECT COUNT(*) FROM %s" % table) + adrian 2287 3f0790d500a9 2006-02-24:45: num = cursor.fetchone()[0] + adrian 2287 3f0790d500a9 2006-02-24:46: now = datetime.now().replace(microsecond=0) + adrian 2287 3f0790d500a9 2006-02-24:47: exp = datetime.fromtimestamp(time.time() + timeout).replace(microsecond=0) + adrian 2287 3f0790d500a9 2006-02-24:48: if num > self._max_entries: + russellm 13275 4dd52d4f3f50 2010-08-05:85: self._cull(db, cursor, now) + adrian 2287 3f0790d500a9 2006-02-24:50: encoded = base64.encodestring(pickle.dumps(value, 2)).strip() + russellm 13275 4dd52d4f3f50 2010-08-05:87: cursor.execute("SELECT cache_key, expires FROM %s WHERE cache_key = %%s" % table, [key]) + adrian 2287 3f0790d500a9 2006-02-24:52: try: +mtredinnick 9753 0ab5ef23e1bc 2009-03-02:59: result = cursor.fetchone() +mtredinnick 9753 0ab5ef23e1bc 2009-03-02:60: if result and (mode == 'set' or +mtredinnick 9753 0ab5ef23e1bc 2009-03-02:61: (mode == 'add' and result[1] < now)): + russellm 13275 4dd52d4f3f50 2010-08-05:92: cursor.execute("UPDATE %s SET value = %%s, expires = %%s WHERE cache_key = %%s" % table, + russellm 13275 4dd52d4f3f50 2010-08-05:93: [encoded, connections[db].ops.value_to_db_datetime(exp), key]) + adrian 2287 3f0790d500a9 2006-02-24:55: else: + russellm 13275 4dd52d4f3f50 2010-08-05:95: cursor.execute("INSERT INTO %s (cache_key, value, expires) VALUES (%%s, %%s, %%s)" % table, + russellm 13275 4dd52d4f3f50 2010-08-05:96: [key, encoded, connections[db].ops.value_to_db_datetime(exp)]) + adrian 2287 3f0790d500a9 2006-02-24:57: except DatabaseError: + adrian 2287 3f0790d500a9 2006-02-24:58: # To be threadsafe, updates/inserts are allowed to fail silently + russellm 13275 4dd52d4f3f50 2010-08-05:99: transaction.rollback_unless_managed(using=db) +mtredinnick 8110 c787c7f62142 2008-08-10:65: return False + adrian 2287 3f0790d500a9 2006-02-24:60: else: + russellm 13275 4dd52d4f3f50 2010-08-05:102: transaction.commit_unless_managed(using=db) +mtredinnick 8110 c787c7f62142 2008-08-10:68: return True + adrian 2287 3f0790d500a9 2006-02-24:62: + russellm 14425 793e94ba2037 2010-11-19:101: def delete(self, key, version=None): + russellm 14425 793e94ba2037 2010-11-19:102: key = self.make_key(key, version=version) +mtredinnick 13568 7e0b7bf098d2 2010-09-12:109: self.validate_key(key) + russellm 14425 793e94ba2037 2010-11-19:104: + russellm 13275 4dd52d4f3f50 2010-08-05:106: db = router.db_for_write(self.cache_model_class) + russellm 13275 4dd52d4f3f50 2010-08-05:107: table = connections[db].ops.quote_name(self._table) + russellm 13275 4dd52d4f3f50 2010-08-05:108: cursor = connections[db].cursor() + russellm 13275 4dd52d4f3f50 2010-08-05:109: + russellm 13275 4dd52d4f3f50 2010-08-05:110: cursor.execute("DELETE FROM %s WHERE cache_key = %%s" % table, [key]) + russellm 13275 4dd52d4f3f50 2010-08-05:111: transaction.commit_unless_managed(using=db) + adrian 2287 3f0790d500a9 2006-02-24:67: + russellm 14425 793e94ba2037 2010-11-19:112: def has_key(self, key, version=None): + russellm 14425 793e94ba2037 2010-11-19:113: key = self.make_key(key, version=version) +mtredinnick 13568 7e0b7bf098d2 2010-09-12:118: self.validate_key(key) + russellm 14425 793e94ba2037 2010-11-19:115: + russellm 13275 4dd52d4f3f50 2010-08-05:114: db = router.db_for_read(self.cache_model_class) + russellm 13275 4dd52d4f3f50 2010-08-05:115: table = connections[db].ops.quote_name(self._table) + russellm 13275 4dd52d4f3f50 2010-08-05:116: cursor = connections[db].cursor() + russellm 13275 4dd52d4f3f50 2010-08-05:117: +mtredinnick 9753 0ab5ef23e1bc 2009-03-02:78: now = datetime.now().replace(microsecond=0) + russellm 13275 4dd52d4f3f50 2010-08-05:119: cursor.execute("SELECT cache_key FROM %s WHERE cache_key = %%s and expires > %%s" % table, + russellm 13275 4dd52d4f3f50 2010-08-05:120: [key, connections[db].ops.value_to_db_datetime(now)]) + adrian 2287 3f0790d500a9 2006-02-24:71: return cursor.fetchone() is not None + adrian 2287 3f0790d500a9 2006-02-24:72: + russellm 13275 4dd52d4f3f50 2010-08-05:123: def _cull(self, db, cursor, now): + adrian 2287 3f0790d500a9 2006-02-24:74: if self._cull_frequency == 0: + russellm 12116 c1ad14c551a9 2010-01-27:87: self.clear() + adrian 2287 3f0790d500a9 2006-02-24:76: else: + russellm 13480 7351411944a9 2010-08-31:127: table = connections[db].ops.quote_name(self._table) + russellm 13275 4dd52d4f3f50 2010-08-05:127: cursor.execute("DELETE FROM %s WHERE expires < %%s" % table, + russellm 13275 4dd52d4f3f50 2010-08-05:128: [connections[db].ops.value_to_db_datetime(now)]) + russellm 13275 4dd52d4f3f50 2010-08-05:129: cursor.execute("SELECT COUNT(*) FROM %s" % table) + adrian 2287 3f0790d500a9 2006-02-24:79: num = cursor.fetchone()[0] + adrian 2287 3f0790d500a9 2006-02-24:80: if num > self._max_entries: + russellm 13275 4dd52d4f3f50 2010-08-05:132: cursor.execute("SELECT cache_key FROM %s ORDER BY cache_key LIMIT 1 OFFSET %%s" % table, [num / self._cull_frequency]) + russellm 13275 4dd52d4f3f50 2010-08-05:133: cursor.execute("DELETE FROM %s WHERE cache_key < %%s" % table, [cursor.fetchone()[0]]) + russellm 12116 c1ad14c551a9 2010-01-27:95: + russellm 12116 c1ad14c551a9 2010-01-27:96: def clear(self): + russellm 13275 4dd52d4f3f50 2010-08-05:136: db = router.db_for_write(self.cache_model_class) + russellm 13275 4dd52d4f3f50 2010-08-05:137: table = connections[db].ops.quote_name(self._table) + russellm 13275 4dd52d4f3f50 2010-08-05:138: cursor = connections[db].cursor() + russellm 13275 4dd52d4f3f50 2010-08-05:139: cursor.execute('DELETE FROM %s' % table) + russellm 14807 905c4a7e1f19 2010-12-21:143: + russellm 14807 905c4a7e1f19 2010-12-21:144: # For backwards compatibility + russellm 14807 905c4a7e1f19 2010-12-21:145: class CacheClass(DatabaseCache): + russellm 14807 905c4a7e1f19 2010-12-21:146: pass diff --git a/plugins/hg4idea/testData/annotate/outputs/hg_1.8.2 b/plugins/hg4idea/testData/annotate/outputs/hg_1.8.2 new file mode 100644 index 000000000000..3acc13feeb81 --- /dev/null +++ b/plugins/hg4idea/testData/annotate/outputs/hg_1.8.2 @@ -0,0 +1,149 @@ + adrian 2287 3f0790d500a9 2006-02-24:1: "Database cache backend." + jezdez 16338 bf038debb499 2011-07-13:2: import base64 + jezdez 16338 bf038debb499 2011-07-13:3: import time + jezdez 16338 bf038debb499 2011-07-13:4: from datetime import datetime + adrian 2287 3f0790d500a9 2006-02-24:2: + adrian 2287 3f0790d500a9 2006-02-24:7: try: + adrian 2287 3f0790d500a9 2006-02-24:8: import cPickle as pickle + adrian 2287 3f0790d500a9 2006-02-24:9: except ImportError: + adrian 2287 3f0790d500a9 2006-02-24:10: import pickle + adrian 2287 3f0790d500a9 2006-02-24:11: + jezdez 16338 bf038debb499 2011-07-13:11: from django.core.cache.backends.base import BaseCache + jezdez 16338 bf038debb499 2011-07-13:12: from django.db import connections, router, transaction, DatabaseError + jezdez 16338 bf038debb499 2011-07-13:13: + jezdez 16338 bf038debb499 2011-07-13:14: + russellm 13275 4dd52d4f3f50 2010-08-05:12: class Options(object): + russellm 13275 4dd52d4f3f50 2010-08-05:13: """A class that will quack like a Django model _meta class. + russellm 13275 4dd52d4f3f50 2010-08-05:14: + russellm 13275 4dd52d4f3f50 2010-08-05:15: This allows cache operations to be controlled by the router + russellm 13275 4dd52d4f3f50 2010-08-05:16: """ + russellm 13275 4dd52d4f3f50 2010-08-05:17: def __init__(self, table): + russellm 13275 4dd52d4f3f50 2010-08-05:18: self.db_table = table + russellm 13275 4dd52d4f3f50 2010-08-05:19: self.app_label = 'django_cache' + russellm 13275 4dd52d4f3f50 2010-08-05:20: self.module_name = 'cacheentry' + russellm 13275 4dd52d4f3f50 2010-08-05:21: self.verbose_name = 'cache entry' + russellm 13275 4dd52d4f3f50 2010-08-05:22: self.verbose_name_plural = 'cache entries' + russellm 13275 4dd52d4f3f50 2010-08-05:23: self.object_name = 'CacheEntry' + russellm 13275 4dd52d4f3f50 2010-08-05:24: self.abstract = False + russellm 13275 4dd52d4f3f50 2010-08-05:25: self.managed = True + russellm 13275 4dd52d4f3f50 2010-08-05:26: self.proxy = False + russellm 13275 4dd52d4f3f50 2010-08-05:27: + russellm 14807 905c4a7e1f19 2010-12-21:28: class BaseDatabaseCache(BaseCache): + russellm 14807 905c4a7e1f19 2010-12-21:29: def __init__(self, table, params): + russellm 14807 905c4a7e1f19 2010-12-21:30: BaseCache.__init__(self, params) + russellm 13275 4dd52d4f3f50 2010-08-05:31: self._table = table + russellm 13275 4dd52d4f3f50 2010-08-05:32: + russellm 13275 4dd52d4f3f50 2010-08-05:33: class CacheEntry(object): + russellm 13275 4dd52d4f3f50 2010-08-05:34: _meta = Options(table) + russellm 13275 4dd52d4f3f50 2010-08-05:35: self.cache_model_class = CacheEntry + russellm 13275 4dd52d4f3f50 2010-08-05:36: + russellm 14807 905c4a7e1f19 2010-12-21:37: class DatabaseCache(BaseDatabaseCache): + russellm 14425 793e94ba2037 2010-11-19:38: def get(self, key, default=None, version=None): + russellm 14425 793e94ba2037 2010-11-19:39: key = self.make_key(key, version=version) +mtredinnick 13568 7e0b7bf098d2 2010-09-12:49: self.validate_key(key) + russellm 13275 4dd52d4f3f50 2010-08-05:49: db = router.db_for_read(self.cache_model_class) + russellm 13275 4dd52d4f3f50 2010-08-05:50: table = connections[db].ops.quote_name(self._table) + russellm 13275 4dd52d4f3f50 2010-08-05:51: cursor = connections[db].cursor() + russellm 13275 4dd52d4f3f50 2010-08-05:52: + russellm 13275 4dd52d4f3f50 2010-08-05:53: cursor.execute("SELECT cache_key, value, expires FROM %s WHERE cache_key = %%s" % table, [key]) + adrian 2287 3f0790d500a9 2006-02-24:30: row = cursor.fetchone() + adrian 2287 3f0790d500a9 2006-02-24:31: if row is None: + adrian 2287 3f0790d500a9 2006-02-24:32: return default + adrian 2287 3f0790d500a9 2006-02-24:33: now = datetime.now() + adrian 2287 3f0790d500a9 2006-02-24:34: if row[2] < now: + russellm 13275 4dd52d4f3f50 2010-08-05:59: db = router.db_for_write(self.cache_model_class) + russellm 13275 4dd52d4f3f50 2010-08-05:60: cursor = connections[db].cursor() + russellm 13275 4dd52d4f3f50 2010-08-05:61: cursor.execute("DELETE FROM %s WHERE cache_key = %%s" % table, [key]) + russellm 13275 4dd52d4f3f50 2010-08-05:62: transaction.commit_unless_managed(using=db) + adrian 2287 3f0790d500a9 2006-02-24:37: return default + russellm 13275 4dd52d4f3f50 2010-08-05:64: value = connections[db].ops.process_clob(row[1]) + ikelly 9862 8739c35149dd 2009-03-13:39: return pickle.loads(base64.decodestring(value)) + adrian 2287 3f0790d500a9 2006-02-24:39: + russellm 14425 793e94ba2037 2010-11-19:59: def set(self, key, value, timeout=None, version=None): + russellm 14425 793e94ba2037 2010-11-19:60: key = self.make_key(key, version=version) +mtredinnick 13568 7e0b7bf098d2 2010-09-12:69: self.validate_key(key) +mtredinnick 8110 c787c7f62142 2008-08-10:41: self._base_set('set', key, value, timeout) +mtredinnick 6421 b4175804cc7b 2007-10-20:45: + russellm 14425 793e94ba2037 2010-11-19:64: def add(self, key, value, timeout=None, version=None): + russellm 14425 793e94ba2037 2010-11-19:65: key = self.make_key(key, version=version) +mtredinnick 13568 7e0b7bf098d2 2010-09-12:73: self.validate_key(key) +mtredinnick 6438 5096a56a9ac6 2007-10-21:44: return self._base_set('add', key, value, timeout) +mtredinnick 6438 5096a56a9ac6 2007-10-21:45: +mtredinnick 6421 b4175804cc7b 2007-10-20:46: def _base_set(self, mode, key, value, timeout=None): + adrian 2287 3f0790d500a9 2006-02-24:41: if timeout is None: + adrian 2287 3f0790d500a9 2006-02-24:42: timeout = self.default_timeout + russellm 13275 4dd52d4f3f50 2010-08-05:76: db = router.db_for_write(self.cache_model_class) + russellm 13275 4dd52d4f3f50 2010-08-05:77: table = connections[db].ops.quote_name(self._table) + russellm 13275 4dd52d4f3f50 2010-08-05:78: cursor = connections[db].cursor() + russellm 13275 4dd52d4f3f50 2010-08-05:79: + russellm 13275 4dd52d4f3f50 2010-08-05:80: cursor.execute("SELECT COUNT(*) FROM %s" % table) + adrian 2287 3f0790d500a9 2006-02-24:45: num = cursor.fetchone()[0] + adrian 2287 3f0790d500a9 2006-02-24:46: now = datetime.now().replace(microsecond=0) + adrian 2287 3f0790d500a9 2006-02-24:47: exp = datetime.fromtimestamp(time.time() + timeout).replace(microsecond=0) + adrian 2287 3f0790d500a9 2006-02-24:48: if num > self._max_entries: + russellm 13275 4dd52d4f3f50 2010-08-05:85: self._cull(db, cursor, now) + adrian 2287 3f0790d500a9 2006-02-24:50: encoded = base64.encodestring(pickle.dumps(value, 2)).strip() + russellm 13275 4dd52d4f3f50 2010-08-05:87: cursor.execute("SELECT cache_key, expires FROM %s WHERE cache_key = %%s" % table, [key]) + adrian 2287 3f0790d500a9 2006-02-24:52: try: +mtredinnick 9753 0ab5ef23e1bc 2009-03-02:59: result = cursor.fetchone() +mtredinnick 9753 0ab5ef23e1bc 2009-03-02:60: if result and (mode == 'set' or +mtredinnick 9753 0ab5ef23e1bc 2009-03-02:61: (mode == 'add' and result[1] < now)): + russellm 13275 4dd52d4f3f50 2010-08-05:92: cursor.execute("UPDATE %s SET value = %%s, expires = %%s WHERE cache_key = %%s" % table, + russellm 13275 4dd52d4f3f50 2010-08-05:93: [encoded, connections[db].ops.value_to_db_datetime(exp), key]) + adrian 2287 3f0790d500a9 2006-02-24:55: else: + russellm 13275 4dd52d4f3f50 2010-08-05:95: cursor.execute("INSERT INTO %s (cache_key, value, expires) VALUES (%%s, %%s, %%s)" % table, + russellm 13275 4dd52d4f3f50 2010-08-05:96: [key, encoded, connections[db].ops.value_to_db_datetime(exp)]) + adrian 2287 3f0790d500a9 2006-02-24:57: except DatabaseError: + adrian 2287 3f0790d500a9 2006-02-24:58: # To be threadsafe, updates/inserts are allowed to fail silently + russellm 13275 4dd52d4f3f50 2010-08-05:99: transaction.rollback_unless_managed(using=db) +mtredinnick 8110 c787c7f62142 2008-08-10:65: return False + adrian 2287 3f0790d500a9 2006-02-24:60: else: + russellm 13275 4dd52d4f3f50 2010-08-05:102: transaction.commit_unless_managed(using=db) +mtredinnick 8110 c787c7f62142 2008-08-10:68: return True + adrian 2287 3f0790d500a9 2006-02-24:62: + russellm 14425 793e94ba2037 2010-11-19:101: def delete(self, key, version=None): + russellm 14425 793e94ba2037 2010-11-19:102: key = self.make_key(key, version=version) +mtredinnick 13568 7e0b7bf098d2 2010-09-12:109: self.validate_key(key) + russellm 14425 793e94ba2037 2010-11-19:104: + russellm 13275 4dd52d4f3f50 2010-08-05:106: db = router.db_for_write(self.cache_model_class) + russellm 13275 4dd52d4f3f50 2010-08-05:107: table = connections[db].ops.quote_name(self._table) + russellm 13275 4dd52d4f3f50 2010-08-05:108: cursor = connections[db].cursor() + russellm 13275 4dd52d4f3f50 2010-08-05:109: + russellm 13275 4dd52d4f3f50 2010-08-05:110: cursor.execute("DELETE FROM %s WHERE cache_key = %%s" % table, [key]) + russellm 13275 4dd52d4f3f50 2010-08-05:111: transaction.commit_unless_managed(using=db) + adrian 2287 3f0790d500a9 2006-02-24:67: + russellm 14425 793e94ba2037 2010-11-19:112: def has_key(self, key, version=None): + russellm 14425 793e94ba2037 2010-11-19:113: key = self.make_key(key, version=version) +mtredinnick 13568 7e0b7bf098d2 2010-09-12:118: self.validate_key(key) + russellm 14425 793e94ba2037 2010-11-19:115: + russellm 13275 4dd52d4f3f50 2010-08-05:114: db = router.db_for_read(self.cache_model_class) + russellm 13275 4dd52d4f3f50 2010-08-05:115: table = connections[db].ops.quote_name(self._table) + russellm 13275 4dd52d4f3f50 2010-08-05:116: cursor = connections[db].cursor() + russellm 13275 4dd52d4f3f50 2010-08-05:117: +mtredinnick 9753 0ab5ef23e1bc 2009-03-02:78: now = datetime.now().replace(microsecond=0) + russellm 13275 4dd52d4f3f50 2010-08-05:119: cursor.execute("SELECT cache_key FROM %s WHERE cache_key = %%s and expires > %%s" % table, + russellm 13275 4dd52d4f3f50 2010-08-05:120: [key, connections[db].ops.value_to_db_datetime(now)]) + adrian 2287 3f0790d500a9 2006-02-24:71: return cursor.fetchone() is not None + adrian 2287 3f0790d500a9 2006-02-24:72: + russellm 13275 4dd52d4f3f50 2010-08-05:123: def _cull(self, db, cursor, now): + adrian 2287 3f0790d500a9 2006-02-24:74: if self._cull_frequency == 0: + russellm 12116 c1ad14c551a9 2010-01-27:87: self.clear() + adrian 2287 3f0790d500a9 2006-02-24:76: else: + russellm 13480 7351411944a9 2010-08-31:127: table = connections[db].ops.quote_name(self._table) + russellm 13275 4dd52d4f3f50 2010-08-05:127: cursor.execute("DELETE FROM %s WHERE expires < %%s" % table, + russellm 13275 4dd52d4f3f50 2010-08-05:128: [connections[db].ops.value_to_db_datetime(now)]) + russellm 13275 4dd52d4f3f50 2010-08-05:129: cursor.execute("SELECT COUNT(*) FROM %s" % table) + adrian 2287 3f0790d500a9 2006-02-24:79: num = cursor.fetchone()[0] + adrian 2287 3f0790d500a9 2006-02-24:80: if num > self._max_entries: + russellm 13275 4dd52d4f3f50 2010-08-05:132: cursor.execute("SELECT cache_key FROM %s ORDER BY cache_key LIMIT 1 OFFSET %%s" % table, [num / self._cull_frequency]) + russellm 13275 4dd52d4f3f50 2010-08-05:133: cursor.execute("DELETE FROM %s WHERE cache_key < %%s" % table, [cursor.fetchone()[0]]) + russellm 12116 c1ad14c551a9 2010-01-27:95: + russellm 12116 c1ad14c551a9 2010-01-27:96: def clear(self): + russellm 13275 4dd52d4f3f50 2010-08-05:136: db = router.db_for_write(self.cache_model_class) + russellm 13275 4dd52d4f3f50 2010-08-05:137: table = connections[db].ops.quote_name(self._table) + russellm 13275 4dd52d4f3f50 2010-08-05:138: cursor = connections[db].cursor() + russellm 13275 4dd52d4f3f50 2010-08-05:139: cursor.execute('DELETE FROM %s' % table) + russellm 14807 905c4a7e1f19 2010-12-21:143: + russellm 14807 905c4a7e1f19 2010-12-21:144: # For backwards compatibility + russellm 14807 905c4a7e1f19 2010-12-21:145: class CacheClass(DatabaseCache): + russellm 14807 905c4a7e1f19 2010-12-21:146: pass diff --git a/plugins/hg4idea/testData/annotate/outputs/hg_1.9.0 b/plugins/hg4idea/testData/annotate/outputs/hg_1.9.0 new file mode 100644 index 000000000000..886d778c2800 --- /dev/null +++ b/plugins/hg4idea/testData/annotate/outputs/hg_1.9.0 @@ -0,0 +1,149 @@ + adrian 2287 3f0790d500a9 2006-02-24: 1: "Database cache backend." + jezdez 16338 bf038debb499 2011-07-13: 2: import base64 + jezdez 16338 bf038debb499 2011-07-13: 3: import time + jezdez 16338 bf038debb499 2011-07-13: 4: from datetime import datetime + adrian 2287 3f0790d500a9 2006-02-24: 2: + adrian 2287 3f0790d500a9 2006-02-24: 7: try: + adrian 2287 3f0790d500a9 2006-02-24: 8: import cPickle as pickle + adrian 2287 3f0790d500a9 2006-02-24: 9: except ImportError: + adrian 2287 3f0790d500a9 2006-02-24: 10: import pickle + adrian 2287 3f0790d500a9 2006-02-24: 11: + jezdez 16338 bf038debb499 2011-07-13: 11: from django.core.cache.backends.base import BaseCache + jezdez 16338 bf038debb499 2011-07-13: 12: from django.db import connections, router, transaction, DatabaseError + jezdez 16338 bf038debb499 2011-07-13: 13: + jezdez 16338 bf038debb499 2011-07-13: 14: + russellm 13275 4dd52d4f3f50 2010-08-05: 12: class Options(object): + russellm 13275 4dd52d4f3f50 2010-08-05: 13: """A class that will quack like a Django model _meta class. + russellm 13275 4dd52d4f3f50 2010-08-05: 14: + russellm 13275 4dd52d4f3f50 2010-08-05: 15: This allows cache operations to be controlled by the router + russellm 13275 4dd52d4f3f50 2010-08-05: 16: """ + russellm 13275 4dd52d4f3f50 2010-08-05: 17: def __init__(self, table): + russellm 13275 4dd52d4f3f50 2010-08-05: 18: self.db_table = table + russellm 13275 4dd52d4f3f50 2010-08-05: 19: self.app_label = 'django_cache' + russellm 13275 4dd52d4f3f50 2010-08-05: 20: self.module_name = 'cacheentry' + russellm 13275 4dd52d4f3f50 2010-08-05: 21: self.verbose_name = 'cache entry' + russellm 13275 4dd52d4f3f50 2010-08-05: 22: self.verbose_name_plural = 'cache entries' + russellm 13275 4dd52d4f3f50 2010-08-05: 23: self.object_name = 'CacheEntry' + russellm 13275 4dd52d4f3f50 2010-08-05: 24: self.abstract = False + russellm 13275 4dd52d4f3f50 2010-08-05: 25: self.managed = True + russellm 13275 4dd52d4f3f50 2010-08-05: 26: self.proxy = False + russellm 13275 4dd52d4f3f50 2010-08-05: 27: + russellm 14807 905c4a7e1f19 2010-12-21: 28: class BaseDatabaseCache(BaseCache): + russellm 14807 905c4a7e1f19 2010-12-21: 29: def __init__(self, table, params): + russellm 14807 905c4a7e1f19 2010-12-21: 30: BaseCache.__init__(self, params) + russellm 13275 4dd52d4f3f50 2010-08-05: 31: self._table = table + russellm 13275 4dd52d4f3f50 2010-08-05: 32: + russellm 13275 4dd52d4f3f50 2010-08-05: 33: class CacheEntry(object): + russellm 13275 4dd52d4f3f50 2010-08-05: 34: _meta = Options(table) + russellm 13275 4dd52d4f3f50 2010-08-05: 35: self.cache_model_class = CacheEntry + russellm 13275 4dd52d4f3f50 2010-08-05: 36: + russellm 14807 905c4a7e1f19 2010-12-21: 37: class DatabaseCache(BaseDatabaseCache): + russellm 14425 793e94ba2037 2010-11-19: 38: def get(self, key, default=None, version=None): + russellm 14425 793e94ba2037 2010-11-19: 39: key = self.make_key(key, version=version) +mtredinnick 13568 7e0b7bf098d2 2010-09-12: 49: self.validate_key(key) + russellm 13275 4dd52d4f3f50 2010-08-05: 49: db = router.db_for_read(self.cache_model_class) + russellm 13275 4dd52d4f3f50 2010-08-05: 50: table = connections[db].ops.quote_name(self._table) + russellm 13275 4dd52d4f3f50 2010-08-05: 51: cursor = connections[db].cursor() + russellm 13275 4dd52d4f3f50 2010-08-05: 52: + russellm 13275 4dd52d4f3f50 2010-08-05: 53: cursor.execute("SELECT cache_key, value, expires FROM %s WHERE cache_key = %%s" % table, [key]) + adrian 2287 3f0790d500a9 2006-02-24: 30: row = cursor.fetchone() + adrian 2287 3f0790d500a9 2006-02-24: 31: if row is None: + adrian 2287 3f0790d500a9 2006-02-24: 32: return default + adrian 2287 3f0790d500a9 2006-02-24: 33: now = datetime.now() + adrian 2287 3f0790d500a9 2006-02-24: 34: if row[2] < now: + russellm 13275 4dd52d4f3f50 2010-08-05: 59: db = router.db_for_write(self.cache_model_class) + russellm 13275 4dd52d4f3f50 2010-08-05: 60: cursor = connections[db].cursor() + russellm 13275 4dd52d4f3f50 2010-08-05: 61: cursor.execute("DELETE FROM %s WHERE cache_key = %%s" % table, [key]) + russellm 13275 4dd52d4f3f50 2010-08-05: 62: transaction.commit_unless_managed(using=db) + adrian 2287 3f0790d500a9 2006-02-24: 37: return default + russellm 13275 4dd52d4f3f50 2010-08-05: 64: value = connections[db].ops.process_clob(row[1]) + ikelly 9862 8739c35149dd 2009-03-13: 39: return pickle.loads(base64.decodestring(value)) + adrian 2287 3f0790d500a9 2006-02-24: 39: + russellm 14425 793e94ba2037 2010-11-19: 59: def set(self, key, value, timeout=None, version=None): + russellm 14425 793e94ba2037 2010-11-19: 60: key = self.make_key(key, version=version) +mtredinnick 13568 7e0b7bf098d2 2010-09-12: 69: self.validate_key(key) +mtredinnick 8110 c787c7f62142 2008-08-10: 41: self._base_set('set', key, value, timeout) +mtredinnick 6421 b4175804cc7b 2007-10-20: 45: + russellm 14425 793e94ba2037 2010-11-19: 64: def add(self, key, value, timeout=None, version=None): + russellm 14425 793e94ba2037 2010-11-19: 65: key = self.make_key(key, version=version) +mtredinnick 13568 7e0b7bf098d2 2010-09-12: 73: self.validate_key(key) +mtredinnick 6438 5096a56a9ac6 2007-10-21: 44: return self._base_set('add', key, value, timeout) +mtredinnick 6438 5096a56a9ac6 2007-10-21: 45: +mtredinnick 6421 b4175804cc7b 2007-10-20: 46: def _base_set(self, mode, key, value, timeout=None): + adrian 2287 3f0790d500a9 2006-02-24: 41: if timeout is None: + adrian 2287 3f0790d500a9 2006-02-24: 42: timeout = self.default_timeout + russellm 13275 4dd52d4f3f50 2010-08-05: 76: db = router.db_for_write(self.cache_model_class) + russellm 13275 4dd52d4f3f50 2010-08-05: 77: table = connections[db].ops.quote_name(self._table) + russellm 13275 4dd52d4f3f50 2010-08-05: 78: cursor = connections[db].cursor() + russellm 13275 4dd52d4f3f50 2010-08-05: 79: + russellm 13275 4dd52d4f3f50 2010-08-05: 80: cursor.execute("SELECT COUNT(*) FROM %s" % table) + adrian 2287 3f0790d500a9 2006-02-24: 45: num = cursor.fetchone()[0] + adrian 2287 3f0790d500a9 2006-02-24: 46: now = datetime.now().replace(microsecond=0) + adrian 2287 3f0790d500a9 2006-02-24: 47: exp = datetime.fromtimestamp(time.time() + timeout).replace(microsecond=0) + adrian 2287 3f0790d500a9 2006-02-24: 48: if num > self._max_entries: + russellm 13275 4dd52d4f3f50 2010-08-05: 85: self._cull(db, cursor, now) + adrian 2287 3f0790d500a9 2006-02-24: 50: encoded = base64.encodestring(pickle.dumps(value, 2)).strip() + russellm 13275 4dd52d4f3f50 2010-08-05: 87: cursor.execute("SELECT cache_key, expires FROM %s WHERE cache_key = %%s" % table, [key]) + adrian 2287 3f0790d500a9 2006-02-24: 52: try: +mtredinnick 9753 0ab5ef23e1bc 2009-03-02: 59: result = cursor.fetchone() +mtredinnick 9753 0ab5ef23e1bc 2009-03-02: 60: if result and (mode == 'set' or +mtredinnick 9753 0ab5ef23e1bc 2009-03-02: 61: (mode == 'add' and result[1] < now)): + russellm 13275 4dd52d4f3f50 2010-08-05: 92: cursor.execute("UPDATE %s SET value = %%s, expires = %%s WHERE cache_key = %%s" % table, + russellm 13275 4dd52d4f3f50 2010-08-05: 93: [encoded, connections[db].ops.value_to_db_datetime(exp), key]) + adrian 2287 3f0790d500a9 2006-02-24: 55: else: + russellm 13275 4dd52d4f3f50 2010-08-05: 95: cursor.execute("INSERT INTO %s (cache_key, value, expires) VALUES (%%s, %%s, %%s)" % table, + russellm 13275 4dd52d4f3f50 2010-08-05: 96: [key, encoded, connections[db].ops.value_to_db_datetime(exp)]) + adrian 2287 3f0790d500a9 2006-02-24: 57: except DatabaseError: + adrian 2287 3f0790d500a9 2006-02-24: 58: # To be threadsafe, updates/inserts are allowed to fail silently + russellm 13275 4dd52d4f3f50 2010-08-05: 99: transaction.rollback_unless_managed(using=db) +mtredinnick 8110 c787c7f62142 2008-08-10: 65: return False + adrian 2287 3f0790d500a9 2006-02-24: 60: else: + russellm 13275 4dd52d4f3f50 2010-08-05:102: transaction.commit_unless_managed(using=db) +mtredinnick 8110 c787c7f62142 2008-08-10: 68: return True + adrian 2287 3f0790d500a9 2006-02-24: 62: + russellm 14425 793e94ba2037 2010-11-19:101: def delete(self, key, version=None): + russellm 14425 793e94ba2037 2010-11-19:102: key = self.make_key(key, version=version) +mtredinnick 13568 7e0b7bf098d2 2010-09-12:109: self.validate_key(key) + russellm 14425 793e94ba2037 2010-11-19:104: + russellm 13275 4dd52d4f3f50 2010-08-05:106: db = router.db_for_write(self.cache_model_class) + russellm 13275 4dd52d4f3f50 2010-08-05:107: table = connections[db].ops.quote_name(self._table) + russellm 13275 4dd52d4f3f50 2010-08-05:108: cursor = connections[db].cursor() + russellm 13275 4dd52d4f3f50 2010-08-05:109: + russellm 13275 4dd52d4f3f50 2010-08-05:110: cursor.execute("DELETE FROM %s WHERE cache_key = %%s" % table, [key]) + russellm 13275 4dd52d4f3f50 2010-08-05:111: transaction.commit_unless_managed(using=db) + adrian 2287 3f0790d500a9 2006-02-24: 67: + russellm 14425 793e94ba2037 2010-11-19:112: def has_key(self, key, version=None): + russellm 14425 793e94ba2037 2010-11-19:113: key = self.make_key(key, version=version) +mtredinnick 13568 7e0b7bf098d2 2010-09-12:118: self.validate_key(key) + russellm 14425 793e94ba2037 2010-11-19:115: + russellm 13275 4dd52d4f3f50 2010-08-05:114: db = router.db_for_read(self.cache_model_class) + russellm 13275 4dd52d4f3f50 2010-08-05:115: table = connections[db].ops.quote_name(self._table) + russellm 13275 4dd52d4f3f50 2010-08-05:116: cursor = connections[db].cursor() + russellm 13275 4dd52d4f3f50 2010-08-05:117: +mtredinnick 9753 0ab5ef23e1bc 2009-03-02: 78: now = datetime.now().replace(microsecond=0) + russellm 13275 4dd52d4f3f50 2010-08-05:119: cursor.execute("SELECT cache_key FROM %s WHERE cache_key = %%s and expires > %%s" % table, + russellm 13275 4dd52d4f3f50 2010-08-05:120: [key, connections[db].ops.value_to_db_datetime(now)]) + adrian 2287 3f0790d500a9 2006-02-24: 71: return cursor.fetchone() is not None + adrian 2287 3f0790d500a9 2006-02-24: 72: + russellm 13275 4dd52d4f3f50 2010-08-05:123: def _cull(self, db, cursor, now): + adrian 2287 3f0790d500a9 2006-02-24: 74: if self._cull_frequency == 0: + russellm 12116 c1ad14c551a9 2010-01-27: 87: self.clear() + adrian 2287 3f0790d500a9 2006-02-24: 76: else: + russellm 13480 7351411944a9 2010-08-31:127: table = connections[db].ops.quote_name(self._table) + russellm 13275 4dd52d4f3f50 2010-08-05:127: cursor.execute("DELETE FROM %s WHERE expires < %%s" % table, + russellm 13275 4dd52d4f3f50 2010-08-05:128: [connections[db].ops.value_to_db_datetime(now)]) + russellm 13275 4dd52d4f3f50 2010-08-05:129: cursor.execute("SELECT COUNT(*) FROM %s" % table) + adrian 2287 3f0790d500a9 2006-02-24: 79: num = cursor.fetchone()[0] + adrian 2287 3f0790d500a9 2006-02-24: 80: if num > self._max_entries: + russellm 13275 4dd52d4f3f50 2010-08-05:132: cursor.execute("SELECT cache_key FROM %s ORDER BY cache_key LIMIT 1 OFFSET %%s" % table, [num / self._cull_frequency]) + russellm 13275 4dd52d4f3f50 2010-08-05:133: cursor.execute("DELETE FROM %s WHERE cache_key < %%s" % table, [cursor.fetchone()[0]]) + russellm 12116 c1ad14c551a9 2010-01-27: 95: + russellm 12116 c1ad14c551a9 2010-01-27: 96: def clear(self): + russellm 13275 4dd52d4f3f50 2010-08-05:136: db = router.db_for_write(self.cache_model_class) + russellm 13275 4dd52d4f3f50 2010-08-05:137: table = connections[db].ops.quote_name(self._table) + russellm 13275 4dd52d4f3f50 2010-08-05:138: cursor = connections[db].cursor() + russellm 13275 4dd52d4f3f50 2010-08-05:139: cursor.execute('DELETE FROM %s' % table) + russellm 14807 905c4a7e1f19 2010-12-21:143: + russellm 14807 905c4a7e1f19 2010-12-21:144: # For backwards compatibility + russellm 14807 905c4a7e1f19 2010-12-21:145: class CacheClass(DatabaseCache): + russellm 14807 905c4a7e1f19 2010-12-21:146: pass diff --git a/plugins/hg4idea/testSrc/org/zmlx/hg4idea/test/HgAnnotateCommandTest.java b/plugins/hg4idea/testSrc/org/zmlx/hg4idea/test/HgAnnotateCommandTest.java new file mode 100644 index 000000000000..aee72fd237a6 --- /dev/null +++ b/plugins/hg4idea/testSrc/org/zmlx/hg4idea/test/HgAnnotateCommandTest.java @@ -0,0 +1,139 @@ +/* + * Copyright 2000-2011 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.zmlx.hg4idea.test; + +import com.intellij.openapi.application.PluginPathManager; +import com.intellij.openapi.util.io.FileUtil; +import com.thoughtworks.xstream.XStream; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.DataProvider; +import org.testng.annotations.Test; +import org.zmlx.hg4idea.HgRevisionNumber; +import org.zmlx.hg4idea.HgVcs; +import org.zmlx.hg4idea.command.HgAnnotateCommand; +import org.zmlx.hg4idea.provider.annotate.HgAnnotationLine; + +import java.io.File; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.fail; + +/** + * @author Kirill Likhodedov + */ +public class HgAnnotateCommandTest extends HgSingleUserTest { + + private File myPluginRoot; + private File myAnnotateDataDir; + private File myOutputsDir; + private List myAnnotations; + + @BeforeMethod + @Override + protected void setUp() throws Exception { + super.setUp(); + } + + @BeforeClass + private void loadEthalonAnnotations() throws IOException { + myPluginRoot = new File(PluginPathManager.getPluginHomePath(HgVcs.VCS_NAME)); + myAnnotateDataDir = new File(myPluginRoot, "testData/annotate"); + myOutputsDir = new File(myAnnotateDataDir, "outputs"); + + final File etalonFile = new File(myAnnotateDataDir, "etalon"); + + XStream xStream = new XStream(); + FileReader reader = new FileReader(etalonFile); + try { + myAnnotations = (List) xStream.fromXML(reader); + } + finally { + reader.close(); + } + } + + @DataProvider(name = "annotate_output") + public Object[][] createValidData() throws IOException { + Object[][] data = new Object[myOutputsDir.listFiles().length][]; + for (int i = 0; i < myOutputsDir.listFiles().length; i++) { + File annotateData = myOutputsDir.listFiles()[i]; + String fileText = FileUtil.loadFile(annotateData); + data[i] = new String[] {annotateData.getName(), fileText}; + } + return data; + } + + @Test(dataProvider = "annotate_output") + public void testParse(String fileName, String annotationNativeOutput) + throws NoSuchMethodException, InvocationTargetException, IllegalAccessException + { + HgAnnotateCommand command = new HgAnnotateCommand(myProject); + Method parseMethod = HgAnnotateCommand.class.getDeclaredMethod("parse", List.class); + parseMethod.setAccessible(true); + + List annotations = Arrays.asList(annotationNativeOutput.split("(\n|\r|\r\n)")); + List result = (List)parseMethod.invoke(command, annotations); + assertEquals(result, myAnnotations); + } + + //@Test + public void generateCorrectAnnotation() throws IOException { + final File etalonFile = new File(myAnnotateDataDir, "etalon"); + + File outputFile = new File(myOutputsDir, "hg_1.9.0"); + String output = FileUtil.loadFile(outputFile); + String[] split = output.split("(\n|\r|\r\n)"); + List annotationLines = new ArrayList(split.length); + + Pattern pattern = Pattern.compile("\\s*(.+)\\s+(\\d+)\\s+([a-fA-F0-9]+)\\s+(\\d{4}-\\d{2}-\\d{2}):\\s*(\\d+): ?(.*)"); + for (String line : split) { + Matcher matcher = pattern.matcher(line); + if (!matcher.matches()) { + fail("Couldn't parse line [ " + line + " ]"); + } + String user = matcher.group(1); + String shortRev = matcher.group(2); + String fullRev = matcher.group(3); + String date = matcher.group(4); + String lineNum = matcher.group(5); + String content = matcher.group(6); + annotationLines + .add(new HgAnnotationLine(user, HgRevisionNumber.getInstance(shortRev, fullRev), date, Integer.parseInt(lineNum), content)); + } + + XStream xStream = new XStream(); + FileWriter writer = new FileWriter(etalonFile); + try { + xStream.toXML(annotationLines, writer); + } + finally { + writer.close(); + } + } + + +} From 354b3c6cd2dd8c31eba3f4c800f6af473f5460b0 Mon Sep 17 00:00:00 2001 From: "Maxim.Mossienko" Date: Fri, 19 Aug 2011 16:23:50 +0400 Subject: [PATCH 04/78] do not use Thread.setName for explicit runReadActions to fix performance on Mac --- .../application/impl/ApplicationImpl.java | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/platform/platform-impl/src/com/intellij/openapi/application/impl/ApplicationImpl.java b/platform/platform-impl/src/com/intellij/openapi/application/impl/ApplicationImpl.java index dd5de4c51805..8dd73bb617c6 100644 --- a/platform/platform-impl/src/com/intellij/openapi/application/impl/ApplicationImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/application/impl/ApplicationImpl.java @@ -848,7 +848,7 @@ public class ApplicationImpl extends ComponentManagerImpl implements Application } public void runReadAction(@NotNull final Runnable action) { - final AccessToken token = acquireReadActionLock(); + final AccessToken token = acquireReadActionLockImpl(false); try { action.run(); @@ -876,7 +876,7 @@ public class ApplicationImpl extends ComponentManagerImpl implements Application } public T runReadAction(@NotNull final Computable computation) { - final AccessToken token = acquireReadActionLock(); + final AccessToken token = acquireReadActionLockImpl(false); try { return computation.compute(); @@ -1085,11 +1085,15 @@ public class ApplicationImpl extends ComponentManagerImpl implements Application @Override public AccessToken acquireReadActionLock() { + return acquireReadActionLockImpl(true); + } + + private AccessToken acquireReadActionLockImpl(boolean explicit) { /** if we are inside read action, do not try to acquire read lock again since it will deadlock if there is a pending writeAction * see {@link com.intellij.util.concurrency.ReentrantWriterPreferenceReadWriteLock#allowReader()} */ if (isReadAccessAllowed()) return AccessToken.EMPTY_ACCESS_TOKEN; - return new ReadAccessToken(); + return new ReadAccessToken(explicit); } @Override @@ -1157,11 +1161,14 @@ public class ApplicationImpl extends ComponentManagerImpl implements Application } private class ReadAccessToken extends AccessToken { - ReadAccessToken() { + private final boolean myExplicit; + + ReadAccessToken(boolean explicit) { + myExplicit = explicit; LOG.assertTrue(!Thread.holdsLock(PsiLock.LOCK), "Thread must not hold PsiLock while performing readAction"); try { myActionsLock.readLock().acquire(); - acquired(); + if (myExplicit) acquired(); } catch (InterruptedException e) { throw new RuntimeInterruptedException(e); @@ -1171,7 +1178,7 @@ public class ApplicationImpl extends ComponentManagerImpl implements Application @Override public void finish() { myActionsLock.readLock().release(); - released(); + if (myExplicit) released(); } } From 3557e4b43c3617a6121b7a8dd4b7c7e9f2155b87 Mon Sep 17 00:00:00 2001 From: Bas Leijdekkers Date: Fri, 19 Aug 2011 15:25:54 +0200 Subject: [PATCH 05/78] naturalCompare for sorting in "natural/human" sort order --- .../openapi/util/text/StringUtil.java | 54 ++++++++++++++++++- .../intellij/util/text/StringUtilTest.java | 19 ++++++- 2 files changed, 71 insertions(+), 2 deletions(-) diff --git a/platform/util/src/com/intellij/openapi/util/text/StringUtil.java b/platform/util/src/com/intellij/openapi/util/text/StringUtil.java index 3c89c2b801b8..776f513229a6 100644 --- a/platform/util/src/com/intellij/openapi/util/text/StringUtil.java +++ b/platform/util/src/com/intellij/openapi/util/text/StringUtil.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2010 JetBrains s.r.o. + * Copyright 2000-2011 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -1959,6 +1959,58 @@ public class StringUtil { return res; } + /** + * Implementation of "Sorting for Humans: Natural Sort Order": + * http://www.codinghorror.com/blog/2007/12/sorting-for-humans-natural-sort-order.html + */ + public static int naturalCompare(String string1, String string2) { + return naturalCompare(string1, string2, false); + } + + private static int naturalCompare(String string1, String string2, boolean caseSensitive) { + final int string1Length = string1.length(); + final int string2Length = string2.length(); + for(int i = 0, j = 0; i < string1Length && j < string2Length; i++, j++) { + final char ch1 = string1.charAt(i); + final char ch2 = string2.charAt(j); + if (isDigit(ch1) && isDigit(ch2)) { + int startNum1 = i; + int startNum2 = j; + i++; + j++; + while (i < string1Length && isDigit(string1.charAt(i))) i++; + while (j < string2Length && isDigit(string2.charAt(j))) j++; + final int difference = Integer.parseInt(string1.substring(startNum1, i)) - + Integer.parseInt(string2.substring(startNum2, j)); + if (difference != 0) { + return difference; + } + } else { + if (caseSensitive) { + return ch1 - ch2; + } else { + // similar logic to charsMatch() below + final int diff1 = Character.toUpperCase(ch1) - Character.toUpperCase(ch2); + if (diff1 != 0) { + final int diff2 = Character.toLowerCase(ch1) - Character.toLowerCase(ch2); + if (diff2 != 0) { + return diff1; + } + } + } + } + } + if (!caseSensitive && string1Length == string2Length) { + // do case sensitive compare if case insensitive strings are equal + return naturalCompare(string1, string2, true); + } + return string1Length - string2Length; + } + + public static boolean isDigit(char c) { + return c >= '0' && c <= '9'; + } + public static int compare(@Nullable String s1, @Nullable String s2, boolean ignoreCase) { if (s1 == s2) return 0; if (s1 == null) return -1; diff --git a/platform/util/testSrc/com/intellij/util/text/StringUtilTest.java b/platform/util/testSrc/com/intellij/util/text/StringUtilTest.java index 0a529a75da2f..f6cef2aa0101 100644 --- a/platform/util/testSrc/com/intellij/util/text/StringUtilTest.java +++ b/platform/util/testSrc/com/intellij/util/text/StringUtilTest.java @@ -18,7 +18,7 @@ package com.intellij.util.text; import com.intellij.openapi.util.text.StringUtil; import junit.framework.TestCase; -import java.util.List; +import java.util.*; /** * @author Eugene Zhuravlev @@ -70,4 +70,21 @@ public class StringUtilTest extends TestCase { assertFalse(StringUtil.startsWithConcatenationOf("something", "something", ".")); assertFalse(StringUtil.startsWithConcatenationOf("some", "something", "")); } + + public void testNaturalCompare() { + final List strings = new ArrayList(Arrays.asList("Test99", "tes0", "test0", "testing", "test", "test99", "test011", "test1", + "test 3", "test2", "test10a", "test10", "1.2.10.5", "1.2.9.1")); + final Comparator c = new Comparator() { + @Override + public int compare(String o1, String o2) { + return StringUtil.naturalCompare(o1, o2); + } + }; + Collections.sort(strings, c); + assertEquals(Arrays.asList("1.2.9.1", "1.2.10.5", "tes0", "test", "test 3", "test0", "test1", "test2", "test10", "test10a", + "test011", "Test99", "test99", "testing"), strings); + final List strings2 = new ArrayList(Arrays.asList("t1", "T2", "T1", "t2")); + Collections.sort(strings2, c); + assertEquals(Arrays.asList("T1", "t1", "T2", "t2"), strings2); + } } From b2daf005c734a2c3027b654682a279134d3bfcf7 Mon Sep 17 00:00:00 2001 From: Bas Leijdekkers Date: Fri, 19 Aug 2011 15:28:46 +0200 Subject: [PATCH 06/78] Even smarter sorting for file names, i.e [test1.txt, test03.txt, test2.txt, test11.txt, test20.txt] --- .../ide/util/treeView/AlphaComparator.java | 26 +++---------------- 1 file changed, 3 insertions(+), 23 deletions(-) diff --git a/platform/platform-api/src/com/intellij/ide/util/treeView/AlphaComparator.java b/platform/platform-api/src/com/intellij/ide/util/treeView/AlphaComparator.java index 202687678420..41c940d716fc 100644 --- a/platform/platform-api/src/com/intellij/ide/util/treeView/AlphaComparator.java +++ b/platform/platform-api/src/com/intellij/ide/util/treeView/AlphaComparator.java @@ -15,6 +15,8 @@ */ package com.intellij.ide.util.treeView; +import com.intellij.openapi.util.text.StringUtil; + import java.util.Comparator; public class AlphaComparator implements Comparator{ @@ -34,28 +36,6 @@ public class AlphaComparator implements Comparator{ if (s1 == null) return s2 == null ? 0 : -1; if (s2 == null) return +1; - if (startsWithDigit(s1) && startsWithDigit(s2)) { - int p1 = calculatePrefix(s1); - int p2 = calculatePrefix(s2); - if (p1 != p2) return p1 - p2; - } - - return s1.compareToIgnoreCase(s2); - } - - private static int calculatePrefix(String s) { - int acc = 0; - for (int i = 0; i < s.length(); i++) { - char c = s.charAt(i); - if (c < '0' || c > '9') break; - acc = acc * 10 + c - '0'; - } - return acc; - } - - private static boolean startsWithDigit(String s) { - if (s.isEmpty()) return false; - char c = s.charAt(0); - return c >= '0' && c <= '9'; + return StringUtil.naturalCompare(s1, s2); } } From cef7da219e9f39b2e8ed7e439f5065141b30b595 Mon Sep 17 00:00:00 2001 From: Bas Leijdekkers Date: Fri, 19 Aug 2011 15:43:13 +0200 Subject: [PATCH 07/78] test that longer strings sort behind shorter strings --- .../util/testSrc/com/intellij/util/text/StringUtilTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/platform/util/testSrc/com/intellij/util/text/StringUtilTest.java b/platform/util/testSrc/com/intellij/util/text/StringUtilTest.java index f6cef2aa0101..721b81254c63 100644 --- a/platform/util/testSrc/com/intellij/util/text/StringUtilTest.java +++ b/platform/util/testSrc/com/intellij/util/text/StringUtilTest.java @@ -83,8 +83,8 @@ public class StringUtilTest extends TestCase { Collections.sort(strings, c); assertEquals(Arrays.asList("1.2.9.1", "1.2.10.5", "tes0", "test", "test 3", "test0", "test1", "test2", "test10", "test10a", "test011", "Test99", "test99", "testing"), strings); - final List strings2 = new ArrayList(Arrays.asList("t1", "T2", "T1", "t2")); + final List strings2 = new ArrayList(Arrays.asList("t1", "t001", "T2", "T002", "T1", "t2")); Collections.sort(strings2, c); - assertEquals(Arrays.asList("T1", "t1", "T2", "t2"), strings2); + assertEquals(Arrays.asList("T1", "t1", "t001", "T2", "t2", "T002"), strings2); } } From 0407c1fc8a0debf8d1ec2e50435df34902fe6abe Mon Sep 17 00:00:00 2001 From: Bas Leijdekkers Date: Fri, 19 Aug 2011 15:44:02 +0200 Subject: [PATCH 08/78] sort cvs tree nodes in natural order --- .../cvsSupport2/cvsBrowser/TreeNodeComparator.java | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/cvsBrowser/TreeNodeComparator.java b/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/cvsBrowser/TreeNodeComparator.java index 83279cc84cbc..c86fc6bb34f2 100644 --- a/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/cvsBrowser/TreeNodeComparator.java +++ b/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/cvsBrowser/TreeNodeComparator.java @@ -16,6 +16,7 @@ package com.intellij.cvsSupport2.cvsBrowser; import com.intellij.openapi.util.SystemInfo; +import com.intellij.openapi.util.text.StringUtil; import javax.swing.tree.DefaultMutableTreeNode; import java.util.Comparator; @@ -55,10 +56,6 @@ public class TreeNodeComparator implements Comparator { } final String name1 = ((CvsElement)node1).getName(); final String name2 = ((CvsElement)node2).getName(); - final int result = name1.compareToIgnoreCase(name2); - if (result != 0) { - return result; - } - return name1.compareTo(name2); + return StringUtil.naturalCompare(name1, name2); } } From 9afb6a0a8b25d290910d4c7f15414548c23d2dfe Mon Sep 17 00:00:00 2001 From: Bas Leijdekkers Date: Fri, 19 Aug 2011 16:11:20 +0200 Subject: [PATCH 09/78] IDEA-34881 (CVS: if the HOME environment variable is set, use the $HOME/.cvsignore file) --- .../application/CvsEntriesManager.java | 6 +++--- .../cvsIgnore/IgnoredFilesInfoImpl.java | 2 +- .../cvsSupport2/cvsIgnore/UserDirIgnores.java | 15 ++++++++++++--- 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/application/CvsEntriesManager.java b/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/application/CvsEntriesManager.java index 5239937f1b9d..7b5600a9a75f 100644 --- a/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/application/CvsEntriesManager.java +++ b/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/application/CvsEntriesManager.java @@ -384,7 +384,7 @@ public class CvsEntriesManager extends VirtualFileAdapter { return myStringToSettingsMap.get(cvsRoot); } - public UserDirIgnores getUserdIgnores() { + public UserDirIgnores getUserDirIgnores() { return myUserDirIgnores; } @@ -396,8 +396,8 @@ public class CvsEntriesManager extends VirtualFileAdapter { } } - private boolean isUserHomeCvsIgnoreFile(VirtualFile file) { - return myUserDirIgnores.userHomeCvsIgnoreFile().equals(CvsVfsUtil.getFileFor(file)); + private static boolean isUserHomeCvsIgnoreFile(VirtualFile file) { + return UserDirIgnores.userHomeCvsIgnoreFile().equals(CvsVfsUtil.getFileFor(file)); } public boolean isActive() { diff --git a/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/cvsIgnore/IgnoredFilesInfoImpl.java b/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/cvsIgnore/IgnoredFilesInfoImpl.java index d11c2ed41658..7575644b1edc 100644 --- a/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/cvsIgnore/IgnoredFilesInfoImpl.java +++ b/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/cvsIgnore/IgnoredFilesInfoImpl.java @@ -68,7 +68,7 @@ public class IgnoredFilesInfoImpl implements IgnoredFilesInfo { public static IgnoredFilesInfo EMPTY_FILTER = new IgnoredFilesInfoImpl(){ public boolean shouldBeIgnored(String fileName) { - if (checkPatterns(CvsEntriesManager.getInstance().getUserdIgnores().getPatterns(), fileName)) return true; + if (checkPatterns(CvsEntriesManager.getInstance().getUserDirIgnores().getPatterns(), fileName)) return true; if (checkPatterns(PREDEFINED_PATTERNS, fileName)) return true; return false; } diff --git a/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/cvsIgnore/UserDirIgnores.java b/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/cvsIgnore/UserDirIgnores.java index 319015d22bf8..8d416d4ab261 100644 --- a/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/cvsIgnore/UserDirIgnores.java +++ b/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/cvsIgnore/UserDirIgnores.java @@ -31,7 +31,16 @@ import java.util.List; public class UserDirIgnores{ private List myPatterns; - @NonNls private static final File ourUserHomeCVSIgnoreFile = new File(System.getProperty("user.home") + "/" + CvsUtil.CVS_IGNORE_FILE); + @NonNls private static final File ourUserHomeCVSIgnoreFile; + + static { + final String home = System.getenv().get("HOME"); + if (home != null) { + ourUserHomeCVSIgnoreFile = new File(home + "/" + CvsUtil.CVS_IGNORE_FILE); + } else { + ourUserHomeCVSIgnoreFile = new File(System.getProperty("user.home") + "/" + CvsUtil.CVS_IGNORE_FILE); + } + } public List getPatterns(){ if (myPatterns == null){ @@ -40,7 +49,7 @@ public class UserDirIgnores{ return myPatterns; } - private List createUserDirIgnoredFilesInfo() { + private static List createUserDirIgnoredFilesInfo() { final File file = userHomeCvsIgnoreFile(); ApplicationManager.getApplication().invokeLater(new Runnable() { public void run() { @@ -50,7 +59,7 @@ public class UserDirIgnores{ return IgnoredFilesInfoImpl.getPattensFor(file); } - public File userHomeCvsIgnoreFile() { + public static File userHomeCvsIgnoreFile() { return ourUserHomeCVSIgnoreFile; } From 7fe51270e02ed537b3c99a3755a33e49bb552636 Mon Sep 17 00:00:00 2001 From: Bas Leijdekkers Date: Fri, 19 Aug 2011 16:17:15 +0200 Subject: [PATCH 10/78] More fault resistant logic to locate .cvsignore --- .../com/intellij/cvsSupport2/cvsIgnore/UserDirIgnores.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/cvsIgnore/UserDirIgnores.java b/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/cvsIgnore/UserDirIgnores.java index 8d416d4ab261..95e849f69819 100644 --- a/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/cvsIgnore/UserDirIgnores.java +++ b/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/cvsIgnore/UserDirIgnores.java @@ -36,7 +36,12 @@ public class UserDirIgnores{ static { final String home = System.getenv().get("HOME"); if (home != null) { - ourUserHomeCVSIgnoreFile = new File(home + "/" + CvsUtil.CVS_IGNORE_FILE); + final File homeDir = new File(home); + if (homeDir.exists() && homeDir.isDirectory()) { + ourUserHomeCVSIgnoreFile = new File(homeDir, CvsUtil.CVS_IGNORE_FILE); + } else { + ourUserHomeCVSIgnoreFile = new File(System.getProperty("user.home") + "/" + CvsUtil.CVS_IGNORE_FILE); + } } else { ourUserHomeCVSIgnoreFile = new File(System.getProperty("user.home") + "/" + CvsUtil.CVS_IGNORE_FILE); } From 784c89e53f294c055700fca066930ebd4cfd03b5 Mon Sep 17 00:00:00 2001 From: Eugene Kudelevsky Date: Fri, 19 Aug 2011 14:41:27 +0400 Subject: [PATCH 11/78] resolve references from included file to other file included to the same file --- .../model/resolve/DefinitionResolver.java | 36 +++++++++++++------ .../plugins/relaxNG/HighlightingTestBase.java | 6 +++- .../relaxNG/RncIndexHighlightingTest.java | 5 +++ .../testData/highlighting/rnc/include1.rnc | 2 ++ .../testData/highlighting/rnc/include1_1.rnc | 2 ++ .../testData/highlighting/rnc/include1_2.rnc | 3 ++ 6 files changed, 42 insertions(+), 12 deletions(-) create mode 100644 xml/relaxng/testData/highlighting/rnc/include1.rnc create mode 100644 xml/relaxng/testData/highlighting/rnc/include1_1.rnc create mode 100644 xml/relaxng/testData/highlighting/rnc/include1_2.rnc diff --git a/xml/relaxng/src/org/intellij/plugins/relaxNG/model/resolve/DefinitionResolver.java b/xml/relaxng/src/org/intellij/plugins/relaxNG/model/resolve/DefinitionResolver.java index 13c0a8a5b8f6..93295ac39ff8 100644 --- a/xml/relaxng/src/org/intellij/plugins/relaxNG/model/resolve/DefinitionResolver.java +++ b/xml/relaxng/src/org/intellij/plugins/relaxNG/model/resolve/DefinitionResolver.java @@ -27,6 +27,7 @@ import com.intellij.psi.util.CachedValueProvider; import com.intellij.psi.util.CachedValuesManager; import com.intellij.psi.xml.XmlFile; import com.intellij.util.containers.ContainerUtil; +import com.intellij.util.containers.HashSet; import com.intellij.util.xml.DomFileElement; import com.intellij.util.xml.DomManager; import gnu.trove.THashSet; @@ -70,17 +71,21 @@ public class DefinitionResolver extends CommonElement.Visitor implements myVisitedFiles.set(new THashSet(TObjectHashingStrategy.IDENTITY)); } if (value != null && myVisitedFiles.get().add(value)) { - if (value instanceof RncFile) { - final Grammar grammar = ((RncFile)value).getGrammar(); - if (grammar != null) { - grammar.acceptChildren(this); - } - } else if (value instanceof XmlFile) { - final DomManager mgr = DomManager.getDomManager(value.getProject()); - final DomFileElement element = mgr.getFileElement((XmlFile)value, RngGrammar.class); - if (element != null) { - element.getRootElement().acceptChildren(this); - } + doVisitRncOrRngFile(value, this); + } + } + + private static void doVisitRncOrRngFile(PsiFile file, CommonElement.Visitor visitor) { + if (file instanceof RncFile) { + final Grammar grammar = ((RncFile)file).getGrammar(); + if (grammar != null) { + grammar.acceptChildren(visitor); + } + } else if (file instanceof XmlFile) { + final DomManager mgr = DomManager.getDomManager(file.getProject()); + final DomFileElement element = mgr.getFileElement((XmlFile)file, RngGrammar.class); + if (element != null) { + element.getRootElement().acceptChildren(visitor); } } } @@ -181,6 +186,7 @@ public class DefinitionResolver extends CommonElement.Visitor implements private static class BackwardDefinitionResolver implements PsiElementProcessor { private final String myValue; private Define myResult; + private final Set myVisitedPsiFiles = new HashSet(); public BackwardDefinitionResolver(String value) { myValue = value; @@ -203,6 +209,14 @@ public class DefinitionResolver extends CommonElement.Visitor implements myResult = define; } } + + @Override + public void visitInclude(Include include) { + final PsiFile file = include.getInclude(); + if (file != null && myVisitedPsiFiles.add(file)) { + doVisitRncOrRngFile(file, this); + } + } }); } return myResult == null; diff --git a/xml/relaxng/test/org/intellij/plugins/relaxNG/HighlightingTestBase.java b/xml/relaxng/test/org/intellij/plugins/relaxNG/HighlightingTestBase.java index bf0a5c6f2b65..57c54065d6f4 100644 --- a/xml/relaxng/test/org/intellij/plugins/relaxNG/HighlightingTestBase.java +++ b/xml/relaxng/test/org/intellij/plugins/relaxNG/HighlightingTestBase.java @@ -181,6 +181,10 @@ public abstract class HighlightingTestBase extends UsefulTestCase implements Ide protected void doCustomHighlighting(String name, final boolean checkWeakWarnings, final Boolean includeExternalToolPass) throws Throwable { myTestFixture.configureByFile(name); + doCustomHighlighting(checkWeakWarnings, includeExternalToolPass); + } + + protected void doCustomHighlighting(boolean checkWeakWarnings, Boolean includeExternalToolPass) { final PsiFile file = myTestFixture.getFile(); final Document doc = myTestFixture.getEditor().getDocument(); ExpectedHighlightingData data = new ExpectedHighlightingData(doc, true, checkWeakWarnings, false, file); @@ -192,7 +196,7 @@ public abstract class HighlightingTestBase extends UsefulTestCase implements Ide } @NotNull - private Collection doHighlighting(final Boolean externalToolPass) { + protected Collection doHighlighting(final Boolean externalToolPass) { final Project project = myTestFixture.getProject(); PsiDocumentManager.getInstance(project).commitAllDocuments(); final Editor editor = myTestFixture.getEditor(); diff --git a/xml/relaxng/test/org/intellij/plugins/relaxNG/RncIndexHighlightingTest.java b/xml/relaxng/test/org/intellij/plugins/relaxNG/RncIndexHighlightingTest.java index e936352b5b8f..97b6219105e3 100644 --- a/xml/relaxng/test/org/intellij/plugins/relaxNG/RncIndexHighlightingTest.java +++ b/xml/relaxng/test/org/intellij/plugins/relaxNG/RncIndexHighlightingTest.java @@ -45,4 +45,9 @@ public class RncIndexHighlightingTest extends AbstractIndexTest { public void testInspectionUsedDefine() throws Throwable { doHighlightingTest("used-define.rnc"); } + + public void testInclude1() throws Throwable { + myTestFixture.configureByFiles("include1.rnc", "include1_1.rnc", "include1_2.rnc"); + doCustomHighlighting(true, false); + } } \ No newline at end of file diff --git a/xml/relaxng/testData/highlighting/rnc/include1.rnc b/xml/relaxng/testData/highlighting/rnc/include1.rnc new file mode 100644 index 000000000000..6be67d5f826f --- /dev/null +++ b/xml/relaxng/testData/highlighting/rnc/include1.rnc @@ -0,0 +1,2 @@ + +myelement = element myelement {myattrs} \ No newline at end of file diff --git a/xml/relaxng/testData/highlighting/rnc/include1_1.rnc b/xml/relaxng/testData/highlighting/rnc/include1_1.rnc new file mode 100644 index 000000000000..38c49645472b --- /dev/null +++ b/xml/relaxng/testData/highlighting/rnc/include1_1.rnc @@ -0,0 +1,2 @@ + +myattrs = ( empty ) \ No newline at end of file diff --git a/xml/relaxng/testData/highlighting/rnc/include1_2.rnc b/xml/relaxng/testData/highlighting/rnc/include1_2.rnc new file mode 100644 index 000000000000..d12253b5cbe9 --- /dev/null +++ b/xml/relaxng/testData/highlighting/rnc/include1_2.rnc @@ -0,0 +1,3 @@ + +include "include1_1.rnc" +include "include1.rnc" \ No newline at end of file From 857c7d832c1af71ea8298596edd6a2f2b9b9e4dc Mon Sep 17 00:00:00 2001 From: Eugene Kudelevsky Date: Fri, 19 Aug 2011 15:29:51 +0400 Subject: [PATCH 12/78] fix NPE --- .../uipreview/LayoutDeviceConfigurationsDialog.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/plugins/android/src/org/jetbrains/android/uipreview/LayoutDeviceConfigurationsDialog.java b/plugins/android/src/org/jetbrains/android/uipreview/LayoutDeviceConfigurationsDialog.java index 74f17aaa88d8..a002f1a86ca5 100644 --- a/plugins/android/src/org/jetbrains/android/uipreview/LayoutDeviceConfigurationsDialog.java +++ b/plugins/android/src/org/jetbrains/android/uipreview/LayoutDeviceConfigurationsDialog.java @@ -58,9 +58,11 @@ public class LayoutDeviceConfigurationsDialog extends DialogWrapper { myProject = project; myLayoutDeviceManager = layoutDeviceManager; - - mySelectedDeviceConfigName = selectedConfig.getName(); - mySelectedDeviceName = selectedConfig.getDevice().getName(); + + if (selectedConfig != null) { + mySelectedDeviceConfigName = selectedConfig.getName(); + mySelectedDeviceName = selectedConfig.getDevice().getName(); + } setTitle(AndroidBundle.message("android.layout.preview.device.configurations.dialog.title")); From a9459e363fa4e78ad832d4f4d2a16b621ac916c4 Mon Sep 17 00:00:00 2001 From: Kirill Likhodedov Date: Fri, 19 Aug 2011 18:10:55 +0400 Subject: [PATCH 13/78] IDEA-72302 Mercurial: commit in UTF-8 1. Prepare the commit message file in UTF-8. 2. Add "--encoding UTF-8" options to hg command - for safety (utf-8 is by default). 3. Don't LOG.info an IOException, transform it to the VcsException. [Reviewed by irengrig] --- .../zmlx/hg4idea/command/HgCommitCommand.java | 63 +++++++++---------- 1 file changed, 29 insertions(+), 34 deletions(-) diff --git a/plugins/hg4idea/src/org/zmlx/hg4idea/command/HgCommitCommand.java b/plugins/hg4idea/src/org/zmlx/hg4idea/command/HgCommitCommand.java index 7c4f40ceb527..05a4c71c543c 100644 --- a/plugins/hg4idea/src/org/zmlx/hg4idea/command/HgCommitCommand.java +++ b/plugins/hg4idea/src/org/zmlx/hg4idea/command/HgCommitCommand.java @@ -13,9 +13,10 @@ package org.zmlx.hg4idea.command; import com.intellij.openapi.application.PathManager; -import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.project.Project; +import com.intellij.openapi.util.io.FileUtil; import com.intellij.openapi.vcs.VcsException; +import com.intellij.openapi.vfs.CharsetToolkit; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.util.messages.MessageBus; import org.apache.commons.lang.StringUtils; @@ -26,11 +27,8 @@ import org.zmlx.hg4idea.HgVcsMessages; import org.zmlx.hg4idea.execution.HgCommandException; import org.zmlx.hg4idea.execution.HgCommandExecutor; -import java.io.BufferedWriter; import java.io.File; -import java.io.FileWriter; import java.io.IOException; -import java.io.Writer; import java.util.Collections; import java.util.LinkedList; import java.util.List; @@ -40,54 +38,51 @@ import static org.zmlx.hg4idea.HgErrorHandler.ensureSuccess; public class HgCommitCommand { - private static final Logger LOG = Logger.getInstance(HgCommitCommand.class.getName()); - private static final String TEMP_FILE_NAME = ".hg4idea-commit.tmp"; - private final Project project; - private final VirtualFile repo; - private final String message; + private final Project myProject; + private final VirtualFile myRoot; + private final String myMessage; - private Set files = Collections.emptySet(); + private Set myFiles = Collections.emptySet(); - public HgCommitCommand(Project project, @NotNull VirtualFile repo, String message) { - this.project = project; - this.repo = repo; - this.message = message; + public HgCommitCommand(Project project, @NotNull VirtualFile root, String message) { + myProject = project; + myRoot = root; + myMessage = message; } public void setFiles(@NotNull Set files) { - this.files = files; + myFiles = files; } public void execute() throws HgCommandException, VcsException { - if (StringUtils.isBlank(message)) { + if (StringUtils.isBlank(myMessage)) { throw new HgCommandException(HgVcsMessages.message("hg4idea.commit.error.messageEmpty")); } - try { - List parameters = new LinkedList(); - parameters.add("--logfile"); - parameters.add(saveCommitMessage().getAbsolutePath()); - for (HgFile hgFile : files) { - parameters.add(hgFile.getRelativePath()); - } - ensureSuccess(new HgCommandExecutor(project).executeInCurrentThread(repo, "commit", parameters)); - final MessageBus messageBus = project.getMessageBus(); - messageBus.syncPublisher(HgVcs.REMOTE_TOPIC).update(project); - messageBus.syncPublisher(HgVcs.BRANCH_TOPIC).update(project); - } catch (IOException e) { - LOG.info(e); + List parameters = new LinkedList(); + parameters.add("--logfile"); + parameters.add(saveCommitMessage().getAbsolutePath()); + for (HgFile hgFile : myFiles) { + parameters.add(hgFile.getRelativePath()); } + parameters.add("--encoding"); + parameters.add(CharsetToolkit.UTF8); + + ensureSuccess(new HgCommandExecutor(myProject).executeInCurrentThread(myRoot, "commit", parameters)); + final MessageBus messageBus = myProject.getMessageBus(); + messageBus.syncPublisher(HgVcs.REMOTE_TOPIC).update(myProject); + messageBus.syncPublisher(HgVcs.BRANCH_TOPIC).update(myProject); } - private File saveCommitMessage() throws IOException { + private File saveCommitMessage() throws VcsException { File systemDir = new File(PathManager.getSystemPath()); File tempFile = new File(systemDir, TEMP_FILE_NAME); - Writer output = new BufferedWriter(new FileWriter(tempFile, false)); + try { - output.write(message); - } finally { - output.close(); + FileUtil.writeToFile(tempFile, myMessage); + } catch (IOException e) { + throw new VcsException("Couldn't prepare commit message", e); } return tempFile; } From d3f1823f8ac01258a88010f8eec522f8e6299588 Mon Sep 17 00:00:00 2001 From: Kirill Likhodedov Date: Fri, 19 Aug 2011 18:12:41 +0400 Subject: [PATCH 14/78] Fix NPE in HgErrorHandler --- plugins/hg4idea/src/org/zmlx/hg4idea/HgErrorHandler.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/plugins/hg4idea/src/org/zmlx/hg4idea/HgErrorHandler.java b/plugins/hg4idea/src/org/zmlx/hg4idea/HgErrorHandler.java index e80373f66032..e58b488ec638 100644 --- a/plugins/hg4idea/src/org/zmlx/hg4idea/HgErrorHandler.java +++ b/plugins/hg4idea/src/org/zmlx/hg4idea/HgErrorHandler.java @@ -13,11 +13,15 @@ package org.zmlx.hg4idea; import com.intellij.openapi.vcs.VcsException; +import org.jetbrains.annotations.Nullable; import org.zmlx.hg4idea.execution.HgCommandResult; public abstract class HgErrorHandler { - public static HgCommandResult ensureSuccess(HgCommandResult result) throws VcsException { + public static HgCommandResult ensureSuccess(@Nullable HgCommandResult result) throws VcsException { + if (result == null) { + throw new VcsException("Couldn't execute Mercurial command"); + } if (fatalErrorOccurred(result)) { throw new VcsException(result.getRawError()); } From bcfe8e0fb8281fdf1d2444ed2e655b4eaa7b68c8 Mon Sep 17 00:00:00 2001 From: Sergey Evdokimov Date: Fri, 19 Aug 2011 18:38:19 +0400 Subject: [PATCH 15/78] Provide Domain class dynamic methods via AST transformation. Methods should be getted from GormInstanceApi, GormStaticApi, GormValidationApi. --- .../psi/impl/PsiElementFactoryImpl.java | 12 ++-------- .../psi/impl/light/LightVariableBuilder.java | 3 ++- .../impl/synthetic/GrLightMethodBuilder.java | 23 ++++++++++++++----- .../psi/impl/synthetic/GrLightParameter.java | 10 ++++---- 4 files changed, 25 insertions(+), 23 deletions(-) diff --git a/java/java-impl/src/com/intellij/psi/impl/PsiElementFactoryImpl.java b/java/java-impl/src/com/intellij/psi/impl/PsiElementFactoryImpl.java index e2e904e6e592..34e0ab24b863 100644 --- a/java/java-impl/src/com/intellij/psi/impl/PsiElementFactoryImpl.java +++ b/java/java-impl/src/com/intellij/psi/impl/PsiElementFactoryImpl.java @@ -264,21 +264,13 @@ public class PsiElementFactoryImpl extends PsiJavaParserFacadeImpl implements Ps final PsiTypeParameter[] typeParameters = aClass.getTypeParameters(); assert typeParameters.length == 1 : aClass; - final Map map = Collections.singletonMap(typeParameters[0], parameter); - return createType(aClass, createSubstitutor(map)); + return createType(aClass, PsiSubstitutor.EMPTY.put(typeParameters[0], parameter)); } @NotNull @Override public PsiClassType createType(@NotNull final PsiClass aClass, final PsiType... parameters) { - final PsiTypeParameter[] typeParameters = aClass.getTypeParameters(); - assert parameters.length == typeParameters.length; - - final Map map = new java.util.HashMap(); - for (int i = 0; i < parameters.length; i++) { - map.put(typeParameters[i], parameters[i]); - } - return createType(aClass, createSubstitutor(map)); + return createType(aClass, PsiSubstitutor.EMPTY.putAll(aClass, parameters)); } @NotNull diff --git a/java/java-impl/src/com/intellij/psi/impl/light/LightVariableBuilder.java b/java/java-impl/src/com/intellij/psi/impl/light/LightVariableBuilder.java index 402528376673..580325714502 100644 --- a/java/java-impl/src/com/intellij/psi/impl/light/LightVariableBuilder.java +++ b/java/java-impl/src/com/intellij/psi/impl/light/LightVariableBuilder.java @@ -9,6 +9,7 @@ import com.intellij.util.IncorrectOperationException; import com.intellij.util.PlatformIcons; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import javax.swing.*; @@ -30,7 +31,7 @@ public class LightVariableBuilder extends LightE setNavigationElement(navigationElement); } - public LightVariableBuilder(PsiManager manager, @NotNull String name, @NotNull PsiType type, Language language) { + public LightVariableBuilder(PsiManager manager, @Nullable String name, @NotNull PsiType type, Language language) { super(manager, language); myName = name; myType = type; diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/synthetic/GrLightMethodBuilder.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/synthetic/GrLightMethodBuilder.java index a00362b15f6d..9c791fb1e88e 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/synthetic/GrLightMethodBuilder.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/synthetic/GrLightMethodBuilder.java @@ -65,6 +65,8 @@ public class GrLightMethodBuilder extends LightElement implements GrMethod { private String[] myNamedParametersArray = ArrayUtil.EMPTY_STRING_ARRAY; private Runnable myOnRename; + private Object myData; + public GrLightMethodBuilder(PsiManager manager, String name) { this(manager, name, new GrLightParameterListBuilder(manager, GroovyFileType.GROOVY_LANGUAGE), null); } @@ -98,17 +100,14 @@ public class GrLightMethodBuilder extends LightElement implements GrMethod { } public PsiTypeParameterList getTypeParameterList() { - //todo return null; } public GrDocComment getDocComment() { - //todo return null; } public boolean isDeprecated() { - //todo return false; } @@ -202,6 +201,7 @@ public class GrLightMethodBuilder extends LightElement implements GrMethod { return myReturnType; } + @Nullable public GrTypeElement setReturnType(String returnType) { setReturnType(JavaPsiFacade.getInstance(myManager.getProject()).getElementFactory().createTypeByFQClassName(returnType, getResolveScope())); return null; @@ -242,7 +242,6 @@ public class GrLightMethodBuilder extends LightElement implements GrMethod { @NotNull public PsiReferenceList getThrowsList() { - //todo return new LightEmptyImplementsList(getManager()); } @@ -256,8 +255,9 @@ public class GrLightMethodBuilder extends LightElement implements GrMethod { } public boolean isVarArgs() { - //todo - return false; + GrParameter[] parameters = myParameterList.getParameters(); + if (parameters.length == 0) return false; + return parameters[parameters.length - 1].isVarArgs(); } @NotNull @@ -425,4 +425,15 @@ public class GrLightMethodBuilder extends LightElement implements GrMethod { return copy; } + + @Nullable + public T getData() { + return (T)myData; + } + + public GrLightMethodBuilder setData(@Nullable Object data) { + myData = data; + return this; + } + } diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/synthetic/GrLightParameter.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/synthetic/GrLightParameter.java index 425bdd8bd220..d9236b12434d 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/synthetic/GrLightParameter.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/synthetic/GrLightParameter.java @@ -15,10 +15,7 @@ */ package org.jetbrains.plugins.groovy.lang.psi.impl.synthetic; -import com.intellij.psi.PsiAnnotation; -import com.intellij.psi.PsiElement; -import com.intellij.psi.PsiFile; -import com.intellij.psi.PsiType; +import com.intellij.psi.*; import com.intellij.psi.impl.light.LightVariableBuilder; import com.intellij.util.ArrayUtil; import com.intellij.util.IncorrectOperationException; @@ -39,8 +36,9 @@ public class GrLightParameter extends LightVariableBuilder imp private volatile boolean myOptional; private volatile GrModifierList myModifierList; private PsiElement myScope; + private boolean myVarArg; - public GrLightParameter(@NotNull String name, @NotNull PsiType type, @NotNull PsiElement scope) { + public GrLightParameter(@Nullable String name, @NotNull PsiType type, @NotNull PsiElement scope) { super(scope.getManager(), name, type, GroovyFileType.GROOVY_LANGUAGE); myScope = scope; myModifierList = new GrLightModifierList(this, ArrayUtil.EMPTY_STRING_ARRAY); @@ -54,7 +52,7 @@ public class GrLightParameter extends LightVariableBuilder imp @Override public boolean isVarArgs() { - return false; + return getType() instanceof PsiEllipsisType; } @NotNull From af1840ad54e7cf7f06c255a52b0ba3c528fc2e07 Mon Sep 17 00:00:00 2001 From: Sergey Evdokimov Date: Fri, 19 Aug 2011 20:07:18 +0400 Subject: [PATCH 16/78] Remove class GrailsLightMethodBuilder, use GrLightMethodBuilder instead. --- .../impl/synthetic/GrLightMethodBuilder.java | 4 ++++ .../GrLightParameterListBuilder.java | 14 ++++++++++--- .../dynamicMembers/DynamicMemberUtils.java | 21 +++++++++++++++---- 3 files changed, 32 insertions(+), 7 deletions(-) diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/synthetic/GrLightMethodBuilder.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/synthetic/GrLightMethodBuilder.java index 9c791fb1e88e..d63da9877f30 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/synthetic/GrLightMethodBuilder.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/synthetic/GrLightMethodBuilder.java @@ -318,6 +318,10 @@ public class GrLightMethodBuilder extends LightElement implements GrMethod { return this; } + public Object getMethodKind() { + return myMethodKind; + } + public GrLightMethodBuilder setMethodKind(@Nullable Object methodKind) { myMethodKind = methodKind; return this; diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/synthetic/GrLightParameterListBuilder.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/synthetic/GrLightParameterListBuilder.java index b883720ecf0a..c79e23ae02b0 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/synthetic/GrLightParameterListBuilder.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/synthetic/GrLightParameterListBuilder.java @@ -38,7 +38,7 @@ public class GrLightParameterListBuilder extends LightElement implements GrParam super(manager, language); } - public void addParameter(GrParameter parameter) { + public void addParameter(@NotNull GrParameter parameter) { myParameters.add(parameter); myCachedParameters = null; } @@ -65,12 +65,13 @@ public class GrLightParameterListBuilder extends LightElement implements GrParam @Override public void addParameterToEnd(GrParameter parameter) { - + addParameter(parameter); } @Override public void addParameterToHead(GrParameter parameter) { - throw new IncorrectOperationException("GrLightParameterListBuilder is unmodifiable"); + myParameters.add(0, parameter); + myCachedParameters = null; } @Override @@ -105,4 +106,11 @@ public class GrLightParameterListBuilder extends LightElement implements GrParam public void acceptChildren(GroovyElementVisitor visitor) { } + + @NotNull + public GrParameter removeParameter(int index) { + GrParameter removed = myParameters.remove(index); + myCachedParameters = null; + return removed; + } } diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/util/dynamicMembers/DynamicMemberUtils.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/util/dynamicMembers/DynamicMemberUtils.java index 5c26fd72b5f3..cc51497a12a0 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/util/dynamicMembers/DynamicMemberUtils.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/util/dynamicMembers/DynamicMemberUtils.java @@ -112,7 +112,7 @@ public class DynamicMemberUtils { int i = 0; for (PsiField field : fields) { - PsiField dynamicField = new MyGrDynamicPropertyImpl(null, (GrField)field, null, classSource); + PsiField dynamicField = new MyGrDynamicPropertyImpl(psiClass, (GrField)field, null, classSource); PsiField[] dynamicFieldArray = new PsiField[]{dynamicField}; if (field.hasModifierProperty(PsiModifier.STATIC)) { @@ -241,8 +241,9 @@ public class DynamicMemberUtils { return element instanceof DynamicElement && classSource.equals(((DynamicElement)element).getSource()); } - private interface DynamicElement { + public interface DynamicElement { String getSource(); + PsiClass getSourceClass(); } private static class GrDynamicMethodWithCache extends GrDynamicMethodImpl implements DynamicElement { @@ -293,13 +294,20 @@ public class DynamicMemberUtils { public String getSource() { return mySource; } + + @Override + public PsiClass getSourceClass() { + return myMethod.getContainingClass(); + } } private static class MyGrDynamicPropertyImpl extends GrDynamicPropertyImpl implements DynamicElement { private final String mySource; - + private final PsiClass myClass; + private MyGrDynamicPropertyImpl(PsiClass containingClass, GrField field, PsiElement navigationalElement, String source) { - super(containingClass, field, navigationalElement); + super(null, field, navigationalElement); + myClass = containingClass; mySource = source; } @@ -307,5 +315,10 @@ public class DynamicMemberUtils { public String getSource() { return mySource; } + + @Override + public PsiClass getSourceClass() { + return myClass; + } } } From 999bdad34ce490da13838ef7c600eae815d9a335 Mon Sep 17 00:00:00 2001 From: Konstantin Bulenkov Date: Fri, 19 Aug 2011 18:10:36 +0200 Subject: [PATCH 17/78] add preferred size and few utility methods --- .../src/com/intellij/ui/ToolbarDecorator.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/platform/platform-api/src/com/intellij/ui/ToolbarDecorator.java b/platform/platform-api/src/com/intellij/ui/ToolbarDecorator.java index 69f6e07fc712..b770de236525 100644 --- a/platform/platform-api/src/com/intellij/ui/ToolbarDecorator.java +++ b/platform/platform-api/src/com/intellij/ui/ToolbarDecorator.java @@ -65,6 +65,7 @@ public class ToolbarDecorator implements DataProvider, AddRemoveUpDownPanel.List private String myRemoveName; private String myMoveUpName; private String myMoveDownName; + private Dimension myPreferredSize; private AddRemoveUpDownPanel myPanel; private JList myList; @@ -303,6 +304,12 @@ public class ToolbarDecorator implements DataProvider, AddRemoveUpDownPanel.List return this; } + public ToolbarDecorator disableUpDownActions() { + myUpActionEnabled = false; + myDownActionEnabled = false; + return this; + } + public ToolbarDecorator disableDownAction() { myDownActionEnabled = false; return this; @@ -371,6 +378,11 @@ public class ToolbarDecorator implements DataProvider, AddRemoveUpDownPanel.List return this; } + public ToolbarDecorator setPreferredSize(Dimension size) { + myPreferredSize = size; + return this; + } + public JPanel createPanel() { final AddRemoveUpDownPanel.Buttons[] buttons = getButtons(); myPanel = new AddRemoveUpDownPanel(this, @@ -381,6 +393,9 @@ public class ToolbarDecorator implements DataProvider, AddRemoveUpDownPanel.List buttons); myPanel.setBorder(myBorder); final JScrollPane scrollPane = ScrollPaneFactory.createScrollPane(myTable == null ? myList == null ? myTree : myList : myTable); + if (myPreferredSize != null) { + scrollPane.setPreferredSize(myPreferredSize); + } scrollPane.setBorder(IdeBorderFactory.createEmptyBorder(0)); final JPanel panel = new JPanel(new BorderLayout()) { @Override From 16f62d8896668ce9f94dac1026c07818799fab87 Mon Sep 17 00:00:00 2001 From: Konstantin Bulenkov Date: Fri, 19 Aug 2011 18:11:05 +0200 Subject: [PATCH 18/78] toolbar decorator --- .../AnnotationProcessorsConfigurable.java | 81 +++++++++--------- .../options/ProcessedModulesTable.java | 84 ++++++++----------- 2 files changed, 77 insertions(+), 88 deletions(-) diff --git a/java/compiler/impl/src/com/intellij/compiler/options/AnnotationProcessorsConfigurable.java b/java/compiler/impl/src/com/intellij/compiler/options/AnnotationProcessorsConfigurable.java index f403a627cd81..7cac391ba10c 100644 --- a/java/compiler/impl/src/com/intellij/compiler/options/AnnotationProcessorsConfigurable.java +++ b/java/compiler/impl/src/com/intellij/compiler/options/AnnotationProcessorsConfigurable.java @@ -13,12 +13,10 @@ import com.intellij.openapi.ui.ex.MultiLineLabel; import com.intellij.openapi.util.Pair; import com.intellij.openapi.util.io.FileUtil; import com.intellij.openapi.vfs.VirtualFile; -import com.intellij.ui.IdeBorderFactory; -import com.intellij.ui.ScrollPaneFactory; -import com.intellij.ui.TableUtil; +import com.intellij.ui.*; +import com.intellij.ui.table.JBTable; import com.intellij.util.containers.HashMap; -import com.intellij.util.ui.ItemRemovable; -import com.intellij.util.ui.Table; +import com.intellij.util.ui.EditableModel; import org.jetbrains.annotations.NotNull; import javax.swing.*; @@ -50,9 +48,8 @@ public class AnnotationProcessorsConfigurable implements SearchableConfigurable private TextFieldWithBrowseButton myProcessorPathField; private ProcessorTableModel myProcessorsModel; private JCheckBox myCbEnableProcessing; - private JButton myRemoveButton; - private Table myProcessorTable; - private JButton myAddButton; + private JBTable myProcessorTable; + private JPanel myProcessorPanel; public AnnotationProcessorsConfigurable(final Project project) { myProject = project; @@ -110,16 +107,28 @@ public class AnnotationProcessorsConfigurable implements SearchableConfigurable final JPanel processorTablePanel = new JPanel(new BorderLayout()); myProcessorsModel = new ProcessorTableModel(); processorTablePanel.setBorder(IdeBorderFactory.createTitledBorder("Annotation Processors", false, false, true)); - myProcessorTable = new Table(myProcessorsModel); + myProcessorTable = new JBTable(myProcessorsModel); myProcessorTable.getEmptyText().setText("No processors configured"); + myProcessorPanel = ToolbarDecorator.createDecorator(myProcessorTable) + .disableUpAction() + .disableDownAction() + .setAddAction(new AnActionButtonRunnable() { + @Override + public void run(AnActionButton anActionButton) { + final TableCellEditor cellEditor = myProcessorTable.getCellEditor(); + if (cellEditor != null) { + cellEditor.stopCellEditing(); + } + final ProcessorTableModel model = (ProcessorTableModel)myProcessorTable.getModel(); + model.addRow(); + TableUtil.editCellAt(myProcessorTable, model.getRowCount() - 1, ProcessorTableRow.NAME_COLUMN); + } + }) + .createPanel(); - processorTablePanel.add(ScrollPaneFactory.createScrollPane(myProcessorTable), BorderLayout.CENTER); - final JPanel buttons = new JPanel(new GridBagLayout()); - myAddButton = new JButton("Add"); - buttons.add(myAddButton, new GridBagConstraints(0, GridBagConstraints.RELATIVE, 1, 1, 1.0, 0.0, GridBagConstraints.NORTH, GridBagConstraints.HORIZONTAL, new Insets(0, 5, 0, 0), 0, 0)); - myRemoveButton = new JButton("Remove"); - buttons.add(myRemoveButton, new GridBagConstraints(0, GridBagConstraints.RELATIVE, 1, 1, 1.0, 1.0, GridBagConstraints.NORTH, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 0, 0), 0, 0)); - processorTablePanel.add(buttons, BorderLayout.EAST); + + + processorTablePanel.add(myProcessorPanel, BorderLayout.CENTER); processorTablePanel.setPreferredSize(new Dimension(processorTablePanel.getPreferredSize().width, 50)); myModulesTable = new ProcessedModulesTable(myProject); @@ -157,23 +166,6 @@ public class AnnotationProcessorsConfigurable implements SearchableConfigurable } } }); - myAddButton.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent e) { - final TableCellEditor cellEditor = myProcessorTable.getCellEditor(); - if (cellEditor != null) { - cellEditor.stopCellEditing(); - } - final ProcessorTableModel model = (ProcessorTableModel)myProcessorTable.getModel(); - final int inserdedIndex = model.addRow(); - TableUtil.editCellAt(myProcessorTable, inserdedIndex, ProcessorTableRow.NAME_COLUMN); - } - }); - - myRemoveButton.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent e) { - TableUtil.removeSelectedItems(myProcessorTable); - } - }); myCbEnableProcessing.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent e) { @@ -192,8 +184,14 @@ public class AnnotationProcessorsConfigurable implements SearchableConfigurable myRbClasspath.setEnabled(enabled); myRbProcessorsPath.setEnabled(enabled); myProcessorPathField.setEnabled(enabled && useProcessorpath); - myRemoveButton.setEnabled(enabled && myProcessorTable.getSelectedRow() >= 0); - myAddButton.setEnabled(enabled); + final AnActionButton addButton = ToolbarDecorator.findAddButton(myProcessorPanel); + if (addButton != null) { + addButton.setEnabled(enabled); + } + final AnActionButton removeButton = ToolbarDecorator.findRemoveButton(myProcessorPanel); + if (removeButton != null) { + removeButton.setEnabled(enabled && myProcessorTable.getSelectedRow() >= 0); + } myProcessorTable.setEnabled(enabled); final JTableHeader header = myProcessorTable.getTableHeader(); if (header != null) { @@ -278,7 +276,7 @@ public class AnnotationProcessorsConfigurable implements SearchableConfigurable public void disposeUIResources() { } - private static class ProcessorTableModel extends AbstractTableModel implements ItemRemovable{ + private static class ProcessorTableModel extends AbstractTableModel implements EditableModel { private final java.util.List myRows = new ArrayList(); public String getColumnName(int column) { @@ -333,11 +331,14 @@ public class AnnotationProcessorsConfigurable implements SearchableConfigurable fireTableRowsDeleted(idx, idx); } - public int addRow() { + @Override + public void exchangeRows(int oldIndex, int newIndex) { + } + + public void addRow() { myRows.add(new ProcessorTableRow()); - final int inserted = myRows.size() - 1; - fireTableRowsInserted(inserted, inserted); - return inserted; + final int index = myRows.size() - 1; + fireTableRowsInserted(index, index); } public void setProcessorMap(Map processorMap) { diff --git a/java/compiler/impl/src/com/intellij/compiler/options/ProcessedModulesTable.java b/java/compiler/impl/src/com/intellij/compiler/options/ProcessedModulesTable.java index d5b5210b2c69..05e28ae826fb 100644 --- a/java/compiler/impl/src/com/intellij/compiler/options/ProcessedModulesTable.java +++ b/java/compiler/impl/src/com/intellij/compiler/options/ProcessedModulesTable.java @@ -21,41 +21,35 @@ import com.intellij.openapi.project.Project; import com.intellij.openapi.roots.ui.configuration.ChooseModulesDialog; import com.intellij.openapi.util.Pair; import com.intellij.openapi.util.io.FileUtil; -import com.intellij.ui.ScrollPaneFactory; import com.intellij.ui.SpeedSearchBase; import com.intellij.ui.TableUtil; -import com.intellij.util.ui.ItemRemovable; -import com.intellij.util.ui.Table; +import com.intellij.ui.ToolbarDecorator; +import com.intellij.ui.table.JBTable; +import com.intellij.util.ui.EditableModel; import com.intellij.util.ui.UIUtil; import org.jetbrains.annotations.Nullable; import javax.swing.*; -import javax.swing.event.ListSelectionEvent; -import javax.swing.event.ListSelectionListener; import javax.swing.table.*; import java.awt.*; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; import java.util.*; import java.util.List; public class ProcessedModulesTable extends JPanel { - private Table myTable = null; + private JBTable myTable = null; private MyTableModel myTableModel = null; public ProcessedModulesTable(final Project project) { super(new BorderLayout()); - myTableModel = new MyTableModel(); - myTable = new Table(myTableModel); + myTableModel = new MyTableModel(project); + myTable = new JBTable(myTableModel); myTable.getEmptyText().setText("No modules configured"); //myTable.setShowGrid(false); myTable.setIntercellSpacing(new Dimension(0, 0)); myTable.setAutoResizeMode(JTable.AUTO_RESIZE_LAST_COLUMN); myTable.setColumnSelectionAllowed(false); - JScrollPane pane = ScrollPaneFactory.createScrollPane(myTable); - pane.setPreferredSize(new Dimension(100, 155)); final TableColumnModel columnModel = myTable.getColumnModel(); @@ -73,42 +67,13 @@ public class ProcessedModulesTable extends JPanel { moduleColumn.setHeaderValue("Module"); moduleColumn.setCellRenderer(new MyElementColumnCellRenderer()); - add(pane, BorderLayout.CENTER); + final JPanel panel = ToolbarDecorator.createDecorator(myTable) + .disableUpDownActions() + .setPreferredSize(new Dimension(100, 155)) + .createPanel(); + add(panel, BorderLayout.CENTER); - final JButton addButton = new JButton("Add"); - addButton.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent e) { - final Set projectModules = new HashSet(Arrays.asList(ModuleManager.getInstance(project).getModules())); - projectModules.removeAll(myTableModel.getAllModules()); - final ChooseModulesDialog chooser = new ChooseModulesDialog(ProcessedModulesTable.this, new ArrayList(projectModules), "ChooseModule"); - chooser.show(); - if (chooser.isOK()) { - final List chosen = chooser.getChosenElements(); - for (Module module : chosen) { - myTableModel.addElement(module, null); - } - } - } - }); - - final JButton removeButton = new JButton("Remove"); - myTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() { - public void valueChanged(ListSelectionEvent e) { - removeButton.setEnabled(myTable.getSelectedRowCount() > 0); - } - }); - removeButton.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent e) { - TableUtil.removeSelectedItems(myTable); - } - }); - - final JPanel buttonPanel = new JPanel(new GridBagLayout()); - buttonPanel.add(addButton, new GridBagConstraints(0, GridBagConstraints.RELATIVE, 1, 1, 1.0, 0.0, GridBagConstraints.NORTH, GridBagConstraints.HORIZONTAL, new Insets(0, 6, 0, 0), 0, 0)); - buttonPanel.add(removeButton, new GridBagConstraints(0, GridBagConstraints.RELATIVE, 1, 1, 1.0, 1.0, GridBagConstraints.NORTH, GridBagConstraints.HORIZONTAL, new Insets(5, 6, 0, 0), 0, 0)); - add(buttonPanel, BorderLayout.EAST); - - final SpeedSearchBase speedSearch = new SpeedSearchBase
(myTable) { + final SpeedSearchBase speedSearch = new SpeedSearchBase(myTable) { public int getSelectedIndex() { return myTable.getSelectedRow(); } @@ -291,11 +256,16 @@ public class ProcessedModulesTable extends JPanel { return myTableModel.getModuleAt(row); } - private final class MyTableModel extends AbstractTableModel implements ItemRemovable { + private final class MyTableModel extends AbstractTableModel implements EditableModel { private final List myElements = new ArrayList(); private final Map myDirNameMap = new HashMap(); public final int ELEMENT_COLUMN_INDEX = 0; public final int DIRNAME_COLUMN_INDEX = 1; + private final Project myProject; + + private MyTableModel(Project project) { + myProject = project; + } public void sort(Comparator comparator) { Collections.sort(myElements, comparator); @@ -323,12 +293,30 @@ public class ProcessedModulesTable extends JPanel { fireTableRowsInserted(row, row); } + @Override + public void addRow() { + final Set projectModules = new HashSet(Arrays.asList(ModuleManager.getInstance(myProject).getModules())); + projectModules.removeAll(getAllModules()); + final ChooseModulesDialog chooser = new ChooseModulesDialog(ProcessedModulesTable.this, new ArrayList(projectModules), "ChooseModule"); + chooser.show(); + if (chooser.isOK()) { + final List chosen = chooser.getChosenElements(); + for (Module module : chosen) { + addElement(module, null); + } + } + } + public void removeRow(int idx) { final Module element = myElements.remove(idx); myDirNameMap.remove(element); fireTableRowsDeleted(idx, idx); } + @Override + public void exchangeRows(int oldIndex, int newIndex) { + } + public void removeElement(Module element) { final boolean reallyRemoved = myElements.remove(element); if (reallyRemoved) { From d91c0b877046a65ef21d75d84c79170285ef9a02 Mon Sep 17 00:00:00 2001 From: Konstantin Bulenkov Date: Fri, 19 Aug 2011 18:25:24 +0200 Subject: [PATCH 19/78] focus stays in NavBar after choosing an element from popup --- .../com/intellij/openapi/wm/impl/ToolWindowManagerImpl.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/platform/platform-impl/src/com/intellij/openapi/wm/impl/ToolWindowManagerImpl.java b/platform/platform-impl/src/com/intellij/openapi/wm/impl/ToolWindowManagerImpl.java index 07837dd34aaf..e2ef7e01043f 100644 --- a/platform/platform-impl/src/com/intellij/openapi/wm/impl/ToolWindowManagerImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/wm/impl/ToolWindowManagerImpl.java @@ -551,7 +551,7 @@ public final class ToolWindowManagerImpl extends ToolWindowManagerEx implements } private void activateEditorComponent(final boolean forced) { - activateEditorComponent(forced, false); + activateEditorComponent(forced, true); //TODO[kirillk]: runnable in activateEditorComponent(boolean, boolean) never runs } private void activateEditorComponent(final boolean forced, boolean now) { if (LOG.isDebugEnabled()) { @@ -567,7 +567,6 @@ public final class ToolWindowManagerImpl extends ToolWindowManagerEx implements execute(commandList); } }; - if (now) { runnable.run(); } else { From fbd8efa67df23c73de548556c883cd885d8f2039 Mon Sep 17 00:00:00 2001 From: Dmitry Jemerov Date: Fri, 19 Aug 2011 13:06:42 +0400 Subject: [PATCH 20/78] dead code --- .../openapi/vfs/ModificationAttemptEvent.java | 40 ------------------- .../vfs/ModificationAttemptListener.java | 22 ---------- .../openapi/vfs/VirtualFileManager.java | 5 --- .../openapi/command/impl/UndoRedo.java | 2 - .../impl/FileDocumentManagerImpl.java | 11 ----- .../openapi/vfs/ex/VirtualFileManagerEx.java | 4 -- .../vfs/impl/VirtualFileManagerImpl.java | 16 -------- .../intellij/mock/MockVirtualFileManager.java | 32 --------------- 8 files changed, 132 deletions(-) delete mode 100644 platform/core-api/src/com/intellij/openapi/vfs/ModificationAttemptEvent.java delete mode 100644 platform/core-api/src/com/intellij/openapi/vfs/ModificationAttemptListener.java diff --git a/platform/core-api/src/com/intellij/openapi/vfs/ModificationAttemptEvent.java b/platform/core-api/src/com/intellij/openapi/vfs/ModificationAttemptEvent.java deleted file mode 100644 index 87469a402fb5..000000000000 --- a/platform/core-api/src/com/intellij/openapi/vfs/ModificationAttemptEvent.java +++ /dev/null @@ -1,40 +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.intellij.openapi.vfs; - -import java.util.EventObject; - -public class ModificationAttemptEvent extends EventObject{ - private final VirtualFile[] myFiles; - private boolean myConsumed = false; - - public ModificationAttemptEvent(VirtualFileManager manager, VirtualFile[] files) { - super(manager); - myFiles = files; - } - - public VirtualFile[] getFiles() { - return myFiles; - } - - public void consume(){ - myConsumed = true; - } - - public boolean isConsumed() { - return myConsumed; - } -} diff --git a/platform/core-api/src/com/intellij/openapi/vfs/ModificationAttemptListener.java b/platform/core-api/src/com/intellij/openapi/vfs/ModificationAttemptListener.java deleted file mode 100644 index 7675eca959ea..000000000000 --- a/platform/core-api/src/com/intellij/openapi/vfs/ModificationAttemptListener.java +++ /dev/null @@ -1,22 +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.intellij.openapi.vfs; - -import java.util.EventListener; - -public interface ModificationAttemptListener extends EventListener{ - void readOnlyModificationAttempt(ModificationAttemptEvent event); -} diff --git a/platform/core-api/src/com/intellij/openapi/vfs/VirtualFileManager.java b/platform/core-api/src/com/intellij/openapi/vfs/VirtualFileManager.java index de9f883cf93a..5bef2cda67b0 100644 --- a/platform/core-api/src/com/intellij/openapi/vfs/VirtualFileManager.java +++ b/platform/core-api/src/com/intellij/openapi/vfs/VirtualFileManager.java @@ -123,11 +123,6 @@ public abstract class VirtualFileManager implements ModificationTracker{ */ public abstract void removeVirtualFileListener(@NotNull VirtualFileListener listener); - public abstract void addModificationAttemptListener(@NotNull ModificationAttemptListener listener); - public abstract void removeModificationAttemptListener(@NotNull ModificationAttemptListener listener); - - public abstract void fireReadOnlyModificationAttempt(@NotNull VirtualFile... files); - /** * Constructs URL by specified protocol and path. URL is a string which uniquely identifies file in all * file systems. diff --git a/platform/platform-impl/src/com/intellij/openapi/command/impl/UndoRedo.java b/platform/platform-impl/src/com/intellij/openapi/command/impl/UndoRedo.java index c52f89586ecc..013879e11efe 100644 --- a/platform/platform-impl/src/com/intellij/openapi/command/impl/UndoRedo.java +++ b/platform/platform-impl/src/com/intellij/openapi/command/impl/UndoRedo.java @@ -29,7 +29,6 @@ import com.intellij.openapi.util.text.StringUtil; import com.intellij.openapi.vfs.ReadonlyStatusHandler; import com.intellij.openapi.vfs.VfsUtil; import com.intellij.openapi.vfs.VirtualFile; -import com.intellij.openapi.vfs.VirtualFileManager; import java.util.ArrayList; import java.util.Collection; @@ -119,7 +118,6 @@ abstract class UndoRedo { final VirtualFile[] files = VfsUtil.toVirtualFileArray(readOnlyFiles); if (project == null) { - VirtualFileManager.getInstance().fireReadOnlyModificationAttempt(files); return false; } diff --git a/platform/platform-impl/src/com/intellij/openapi/fileEditor/impl/FileDocumentManagerImpl.java b/platform/platform-impl/src/com/intellij/openapi/fileEditor/impl/FileDocumentManagerImpl.java index 5bd278624af7..4dceb618cdf0 100644 --- a/platform/platform-impl/src/com/intellij/openapi/fileEditor/impl/FileDocumentManagerImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/fileEditor/impl/FileDocumentManagerImpl.java @@ -33,7 +33,6 @@ import com.intellij.openapi.editor.EditorFactory; import com.intellij.openapi.editor.event.DocumentAdapter; import com.intellij.openapi.editor.event.DocumentEvent; import com.intellij.openapi.editor.ex.DocumentEx; -import com.intellij.openapi.editor.ex.EditReadOnlyListener; import com.intellij.openapi.fileEditor.*; import com.intellij.openapi.fileTypes.BinaryFileTypeDecompilers; import com.intellij.openapi.fileTypes.FileType; @@ -78,7 +77,6 @@ public class FileDocumentManagerImpl extends FileDocumentManager implements Appl private static final Key FILE_KEY = Key.create("FILE_KEY"); private final Set myUnsavedDocuments = new ConcurrentHashSet(); - private final EditReadOnlyListener myReadOnlyListener = new MyEditReadOnlyListener(); private final EventDispatcher myVetoDispatcher = EventDispatcher.create(FileDocumentSynchronizationVetoListener.class); @@ -142,7 +140,6 @@ public class FileDocumentManagerImpl extends FileDocumentManager implements Appl } } ); - document.addEditReadOnlyListener(myReadOnlyListener); } } @@ -616,14 +613,6 @@ public class FileDocumentManagerImpl extends FileDocumentManager implements Appl public void beforeFileMovement(VirtualFileMoveEvent event) { } - private final class MyEditReadOnlyListener implements EditReadOnlyListener { - public void readOnlyModificationAttempt(Document document) { - VirtualFile file = getFile(document); - if (file == null) return; - myVirtualFileManager.fireReadOnlyModificationAttempt(file); - } - } - private void fireFileContentReloaded(final VirtualFile file, final Document document) { myBus.syncPublisher(AppTopics.FILE_DOCUMENT_SYNC).fileContentReloaded(file, document); for (FileDocumentManagerListener listener : getListeners()) { diff --git a/platform/platform-impl/src/com/intellij/openapi/vfs/ex/VirtualFileManagerEx.java b/platform/platform-impl/src/com/intellij/openapi/vfs/ex/VirtualFileManagerEx.java index ebda7c47ed0b..174f859f487f 100644 --- a/platform/platform-impl/src/com/intellij/openapi/vfs/ex/VirtualFileManagerEx.java +++ b/platform/platform-impl/src/com/intellij/openapi/vfs/ex/VirtualFileManagerEx.java @@ -17,12 +17,8 @@ package com.intellij.openapi.vfs.ex; import com.intellij.openapi.vfs.VirtualFileManager; -import com.intellij.openapi.vfs.VirtualFileSystem; public abstract class VirtualFileManagerEx extends VirtualFileManager { - public abstract void registerFileSystem(VirtualFileSystem fileSystem); - public abstract void unregisterFileSystem(VirtualFileSystem fileSystem); - public abstract void fireBeforeRefreshStart(boolean asynchronous); public abstract void fireAfterRefreshFinish(boolean asynchronous); } diff --git a/platform/platform-impl/src/com/intellij/openapi/vfs/impl/VirtualFileManagerImpl.java b/platform/platform-impl/src/com/intellij/openapi/vfs/impl/VirtualFileManagerImpl.java index 66e79d719bc8..81ac98e52091 100644 --- a/platform/platform-impl/src/com/intellij/openapi/vfs/impl/VirtualFileManagerImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/vfs/impl/VirtualFileManagerImpl.java @@ -56,7 +56,6 @@ public class VirtualFileManagerImpl extends VirtualFileManagerEx implements Appl private final EventDispatcher myVirtualFileListenerMulticaster = EventDispatcher.create(VirtualFileListener.class); private final List myVirtualFileManagerListeners = ContainerUtil.createEmptyCOWList(); - private final EventDispatcher myModificationAttemptListenerMulticaster = EventDispatcher.create(ModificationAttemptListener.class); private int myRefreshCount = 0; private final ManagingFS myPersistence; @@ -188,21 +187,6 @@ public class VirtualFileManagerImpl extends VirtualFileManagerEx implements Appl myVirtualFileListenerMulticaster.removeListener(listener); } - public void addModificationAttemptListener(@NotNull ModificationAttemptListener listener) { - myModificationAttemptListenerMulticaster.addListener(listener); - } - - public void removeModificationAttemptListener(@NotNull ModificationAttemptListener listener) { - myModificationAttemptListenerMulticaster.removeListener(listener); - } - - public void fireReadOnlyModificationAttempt(@NotNull VirtualFile... files) { - ApplicationManager.getApplication().assertIsDispatchThread(); - - final ModificationAttemptEvent event = new ModificationAttemptEvent(this, files); - myModificationAttemptListenerMulticaster.getMulticaster().readOnlyModificationAttempt(event); - } - public void addVirtualFileManagerListener(@NotNull VirtualFileManagerListener listener) { myVirtualFileManagerListeners.add(listener); } diff --git a/platform/testFramework/src/com/intellij/mock/MockVirtualFileManager.java b/platform/testFramework/src/com/intellij/mock/MockVirtualFileManager.java index e6e98affadfd..006d56698142 100644 --- a/platform/testFramework/src/com/intellij/mock/MockVirtualFileManager.java +++ b/platform/testFramework/src/com/intellij/mock/MockVirtualFileManager.java @@ -15,7 +15,6 @@ */ package com.intellij.mock; -import com.intellij.ide.caches.CacheUpdater; import com.intellij.openapi.Disposable; import com.intellij.openapi.application.ModalityState; import com.intellij.openapi.util.ModificationTracker; @@ -73,18 +72,6 @@ public class MockVirtualFileManager extends VirtualFileManagerEx { public void removeVirtualFileListener(@NotNull VirtualFileListener listener) { } - @Override - public void addModificationAttemptListener(@NotNull ModificationAttemptListener listener) { - } - - @Override - public void removeModificationAttemptListener(@NotNull ModificationAttemptListener listener) { - } - - @Override - public void fireReadOnlyModificationAttempt(@NotNull VirtualFile... files) { - } - @Override public void addVirtualFileManagerListener(@NotNull VirtualFileManagerListener listener) { } @@ -97,25 +84,6 @@ public class MockVirtualFileManager extends VirtualFileManagerEx { public void removeVirtualFileManagerListener(@NotNull VirtualFileManagerListener listener) { } - public void beforeRefreshStart(boolean asynchronous, ModalityState modalityState, Runnable postAction) { - } - - public void afterRefreshFinish(boolean asynchronous, ModalityState modalityState) { - } - - public void registerRefreshUpdater(CacheUpdater updater) { - } - - public void unregisterRefreshUpdater(CacheUpdater updater) { - } - - @Override - public void registerFileSystem(VirtualFileSystem fileSystem) { - } - - @Override - public void unregisterFileSystem(VirtualFileSystem fileSystem) { - } @Override public void fireAfterRefreshFinish(final boolean asynchronous) { From 3add19272d159cc73b99dbf564cf6bad8c854128 Mon Sep 17 00:00:00 2001 From: Dmitry Jemerov Date: Fri, 19 Aug 2011 13:49:08 +0400 Subject: [PATCH 21/78] remove getCodeStyleManager() from PsiManager --- .../impl/quickfix/AddNewArrayExpressionFix.java | 3 ++- .../impl/quickfix/BringVariableIntoScopeFix.java | 5 +++-- .../daemon/impl/quickfix/CreateFromUsageUtils.java | 2 +- .../intention/impl/ColorChooserIntentionAction.java | 2 +- .../impl/ConcatenationToMessageFormatAction.java | 3 ++- .../intellij/psi/impl/PsiJavaParserFacadeImpl.java | 3 ++- .../com/intellij/psi/impl/source/tree/SourceUtil.java | 2 +- .../JavaChangeSignatureUsageProcessor.java | 5 +++-- .../extractclass/ExtractClassProcessor.java | 4 ++-- .../IntroduceParameterObjectProcessor.java | 2 +- .../makeStatic/MakeClassStaticProcessor.java | 2 +- .../refactoring/move/MoveInstanceMembersUtil.java | 3 ++- .../com/intellij/refactoring/psi/MutationUtils.java | 10 +++++----- .../ReplaceConstructorWithBuilderProcessor.java | 2 +- .../refactoring/util/FieldConflictsResolver.java | 2 +- .../duplicates/ConditionalReturnStatementValue.java | 3 ++- .../refactoring/util/duplicates/GotoReturnValue.java | 3 ++- .../wrapreturnvalue/WrapReturnValueProcessor.java | 2 +- .../lang-api/src/com/intellij/psi/PsiManager.java | 11 ----------- .../src/com/intellij/psi/impl/PsiManagerImpl.java | 6 ------ .../refactoring/lang/ExtractIncludeFileBase.java | 3 ++- .../comment/ChangeToEndOfLineCommentIntention.java | 2 +- .../comment/MoveCommentToSeparateLineIntention.java | 2 +- .../MakeAppendChainIntoAppendSequenceIntention.java | 2 +- .../ReplaceConditionalWithIfIntention.java | 2 +- .../SplitDeclarationAndInitializationIntention.java | 2 +- ...tractWhileLoopConditionToIfStatementIntention.java | 2 +- .../GenerateComponentExternalizationAction.java | 2 +- .../plugins/groovy/lang/psi/impl/GroovyFileImpl.java | 2 +- .../introduce/parameter/FieldConflictsResolver.java | 2 +- .../parameter/java2groovy/FieldConflictsResolver.java | 2 +- .../xslt/intentions/ConvertIfToChooseIntention.java | 3 ++- .../lang/xpath/xslt/quickfix/CreateTemplateFix.java | 3 ++- .../lang/xpath/xslt/refactoring/RefactoringUtil.java | 5 +++-- .../xslt/refactoring/XsltExtractFunctionAction.java | 3 ++- .../extractTemplate/XsltExtractTemplateAction.java | 3 ++- .../XsltIntroduceVariableAction.java | 3 ++- .../inspections/SuppressInspectionAction.java | 7 ++++--- .../relaxNG/compact/psi/impl/PatternReference.java | 3 ++- .../plugins/relaxNG/compact/psi/impl/RncNameImpl.java | 3 ++- 40 files changed, 66 insertions(+), 65 deletions(-) diff --git a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/AddNewArrayExpressionFix.java b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/AddNewArrayExpressionFix.java index 29e3e36628f6..f770415837a1 100644 --- a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/AddNewArrayExpressionFix.java +++ b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/AddNewArrayExpressionFix.java @@ -21,6 +21,7 @@ import com.intellij.codeInsight.intention.IntentionAction; import com.intellij.openapi.editor.Editor; import com.intellij.openapi.project.Project; import com.intellij.psi.*; +import com.intellij.psi.codeStyle.CodeStyleManager; import com.intellij.util.IncorrectOperationException; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; @@ -59,7 +60,7 @@ public class AddNewArrayExpressionFix implements IntentionAction { @NonNls String text = "new " + type.getPresentableText() + "[]{}"; PsiNewExpression newExpr = (PsiNewExpression) factory.createExpressionFromText(text, null); newExpr.getArrayInitializer().replace(myInitializer); - newExpr = (PsiNewExpression) manager.getCodeStyleManager().reformat(newExpr); + newExpr = (PsiNewExpression) CodeStyleManager.getInstance(manager.getProject()).reformat(newExpr); myInitializer.replace(newExpr); } diff --git a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/BringVariableIntoScopeFix.java b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/BringVariableIntoScopeFix.java index 54bdb91e3781..985ef619415c 100644 --- a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/BringVariableIntoScopeFix.java +++ b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/BringVariableIntoScopeFix.java @@ -23,6 +23,7 @@ import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.editor.Editor; import com.intellij.openapi.project.Project; import com.intellij.psi.*; +import com.intellij.psi.codeStyle.CodeStyleManager; import com.intellij.psi.util.PsiFormatUtil; import com.intellij.psi.util.PsiTreeUtil; import com.intellij.psi.util.PsiTypesUtil; @@ -118,7 +119,7 @@ public class BringVariableIntoScopeFix implements IntentionAction { LOG.assertTrue(commonParent != null); PsiDeclarationStatement added = (PsiDeclarationStatement)commonParent.addBefore(newDeclaration, child); PsiLocalVariable addedVar = (PsiLocalVariable)added.getDeclaredElements()[0]; - manager.getCodeStyleManager().reformat(commonParent); + CodeStyleManager.getInstance(manager.getProject()).reformat(commonParent); //Leave initializer assignment PsiExpression initializer = myOutOfScopeVariable.getInitializer(); @@ -126,7 +127,7 @@ public class BringVariableIntoScopeFix implements IntentionAction { PsiExpressionStatement assignment = (PsiExpressionStatement)JavaPsiFacade.getInstance(manager.getProject()).getElementFactory().createStatementFromText(myOutOfScopeVariable .getName() + "= e;", null); ((PsiAssignmentExpression)assignment.getExpression()).getRExpression().replace(initializer); - assignment = (PsiExpressionStatement)manager.getCodeStyleManager().reformat(assignment); + assignment = (PsiExpressionStatement)CodeStyleManager.getInstance(manager.getProject()).reformat(assignment); PsiDeclarationStatement declStatement = PsiTreeUtil.getParentOfType(myOutOfScopeVariable, PsiDeclarationStatement.class); LOG.assertTrue(declStatement != null); PsiElement parent = declStatement.getParent(); diff --git a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/CreateFromUsageUtils.java b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/CreateFromUsageUtils.java index 0f43391f5df3..6a3a738c654a 100644 --- a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/CreateFromUsageUtils.java +++ b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/CreateFromUsageUtils.java @@ -342,7 +342,7 @@ public class CreateFromUsageUtils { classKind == CLASS ? elementFactory.createClass(name) : elementFactory.createEnum(name); CreateFromUsageBaseFix.setupGenericParameters(result, referenceElement); - result = (PsiClass)manager.getCodeStyleManager().reformat(result); + result = (PsiClass)CodeStyleManager.getInstance(manager.getProject()).reformat(result); return (PsiClass) psiClass.add(result); } catch (IncorrectOperationException e) { diff --git a/java/java-impl/src/com/intellij/codeInsight/intention/impl/ColorChooserIntentionAction.java b/java/java-impl/src/com/intellij/codeInsight/intention/impl/ColorChooserIntentionAction.java index cc750f41507d..cf54cac9fe4f 100644 --- a/java/java-impl/src/com/intellij/codeInsight/intention/impl/ColorChooserIntentionAction.java +++ b/java/java-impl/src/com/intellij/codeInsight/intention/impl/ColorChooserIntentionAction.java @@ -225,7 +225,7 @@ public class ColorChooserIntentionAction extends PsiElementBaseIntentionAction { + (color.getAlpha() < 255 ? ", " + color.getAlpha() : "") +")", expression); final PsiElement insertedElement = expression.replace(newCall); - final CodeStyleManager codeStyleManager = manager.getCodeStyleManager(); + final CodeStyleManager codeStyleManager = CodeStyleManager.getInstance(manager.getProject()); codeStyleManager.reformat(insertedElement); } } diff --git a/java/java-impl/src/com/intellij/codeInsight/intention/impl/ConcatenationToMessageFormatAction.java b/java/java-impl/src/com/intellij/codeInsight/intention/impl/ConcatenationToMessageFormatAction.java index 4a435898a227..1bb830647e82 100644 --- a/java/java-impl/src/com/intellij/codeInsight/intention/impl/ConcatenationToMessageFormatAction.java +++ b/java/java-impl/src/com/intellij/codeInsight/intention/impl/ConcatenationToMessageFormatAction.java @@ -22,6 +22,7 @@ import com.intellij.openapi.editor.Editor; import com.intellij.openapi.project.Project; import com.intellij.pom.java.LanguageLevel; import com.intellij.psi.*; +import com.intellij.psi.codeStyle.CodeStyleManager; import com.intellij.psi.codeStyle.JavaCodeStyleManager; import com.intellij.psi.search.GlobalSearchScope; import com.intellij.psi.util.PsiConcatenationUtil; @@ -78,7 +79,7 @@ public class ConcatenationToMessageFormatAction implements IntentionAction { argumentList.add(arrayArg); } call = (PsiMethodCallExpression) JavaCodeStyleManager.getInstance(project).shortenClassReferences(call); - call = (PsiMethodCallExpression) element.getManager().getCodeStyleManager().reformat(call); + call = (PsiMethodCallExpression) CodeStyleManager.getInstance(element.getManager().getProject()).reformat(call); concatenation.replace(call); } diff --git a/java/java-impl/src/com/intellij/psi/impl/PsiJavaParserFacadeImpl.java b/java/java-impl/src/com/intellij/psi/impl/PsiJavaParserFacadeImpl.java index 776d6fbfde63..1ff3da344cc6 100644 --- a/java/java-impl/src/com/intellij/psi/impl/PsiJavaParserFacadeImpl.java +++ b/java/java-impl/src/com/intellij/psi/impl/PsiJavaParserFacadeImpl.java @@ -28,6 +28,7 @@ import com.intellij.openapi.roots.LanguageLevelProjectExtension; import com.intellij.openapi.util.text.StringUtil; import com.intellij.pom.java.LanguageLevel; import com.intellij.psi.*; +import com.intellij.psi.codeStyle.CodeStyleManager; import com.intellij.psi.impl.source.DummyHolder; import com.intellij.psi.impl.source.DummyHolderFactory; import com.intellij.psi.impl.source.JavaDummyElement; @@ -407,7 +408,7 @@ public class PsiJavaParserFacadeImpl extends PsiParserFacadeImpl implements PsiJ throw new IncorrectOperationException("Incorrect catch section '" + text + "'. Parsed element: " + element); } setupCatchBlock(exceptionName, context, (PsiCatchSection)element); - return (PsiCatchSection)myManager.getCodeStyleManager().reformat(element); + return (PsiCatchSection)CodeStyleManager.getInstance(myManager.getProject()).reformat(element); } private void setupCatchBlock(final String exceptionName, @Nullable final PsiElement context, final PsiCatchSection psiCatchSection) diff --git a/java/java-impl/src/com/intellij/psi/impl/source/tree/SourceUtil.java b/java/java-impl/src/com/intellij/psi/impl/source/tree/SourceUtil.java index e0f27777e718..a8d8fcab2847 100644 --- a/java/java-impl/src/com/intellij/psi/impl/source/tree/SourceUtil.java +++ b/java/java-impl/src/com/intellij/psi/impl/source/tree/SourceUtil.java @@ -52,7 +52,7 @@ public class SourceUtil { parenthExpr.rawAddChildren(ASTFactory.leaf(JavaTokenType.RPARENTH, ")")); try { - CodeStyleManager codeStyleManager = manager.getCodeStyleManager(); + CodeStyleManager codeStyleManager = CodeStyleManager.getInstance(manager.getProject()); parenthExpr = (CompositeElement)SourceTreeToPsiMap.psiElementToTree( codeStyleManager.reformat(SourceTreeToPsiMap.treeElementToPsi(parenthExpr))); diff --git a/java/java-impl/src/com/intellij/refactoring/changeSignature/JavaChangeSignatureUsageProcessor.java b/java/java-impl/src/com/intellij/refactoring/changeSignature/JavaChangeSignatureUsageProcessor.java index 5da444654889..d710ee9948d7 100644 --- a/java/java-impl/src/com/intellij/refactoring/changeSignature/JavaChangeSignatureUsageProcessor.java +++ b/java/java-impl/src/com/intellij/refactoring/changeSignature/JavaChangeSignatureUsageProcessor.java @@ -779,8 +779,9 @@ public class JavaChangeSignatureUsageProcessor implements ChangeSignatureUsagePr PsiReferenceList methodThrowsList = (PsiReferenceList)method.getThrowsList().replace(throwsList); methodThrowsList = (PsiReferenceList)JavaCodeStyleManager.getInstance(method.getProject()).shortenClassReferences(methodThrowsList); - method.getManager().getCodeStyleManager().reformatRange(method, method.getParameterList().getTextRange().getEndOffset(), - methodThrowsList.getTextRange().getEndOffset()); + CodeStyleManager.getInstance(method.getManager().getProject()) + .reformatRange(method, method.getParameterList().getTextRange().getEndOffset(), + methodThrowsList.getTextRange().getEndOffset()); } private static void fixJavadocsForChangedMethod(PsiMethod method, JavaChangeInfo changeInfo, int newParamsLength) throws IncorrectOperationException { diff --git a/java/java-impl/src/com/intellij/refactoring/extractclass/ExtractClassProcessor.java b/java/java-impl/src/com/intellij/refactoring/extractclass/ExtractClassProcessor.java index 0977e8672894..9c7f742ba292 100644 --- a/java/java-impl/src/com/intellij/refactoring/extractclass/ExtractClassProcessor.java +++ b/java/java-impl/src/com/intellij/refactoring/extractclass/ExtractClassProcessor.java @@ -392,7 +392,7 @@ public class ExtractClassProcessor extends FixableUsagesRefactoringProcessor { private void buildDelegate() { final PsiManager manager = sourceClass.getManager(); final PsiElementFactory factory = JavaPsiFacade.getInstance(manager.getProject()).getElementFactory(); - final CodeStyleManager codeStyleManager = manager.getCodeStyleManager(); + final CodeStyleManager codeStyleManager = CodeStyleManager.getInstance(manager.getProject()); @NonNls final StringBuilder fieldBuffer = new StringBuilder(); final String delegateVisibility = calculateDelegateVisibility(); if (delegateVisibility.length() > 0) fieldBuffer.append(delegateVisibility).append(' '); @@ -691,7 +691,7 @@ public class ExtractClassProcessor extends FixableUsagesRefactoringProcessor { if (directory != null) { final PsiFile newFile = PsiFileFactory.getInstance(project).createFileFromText(newClassName + ".java", classString); final PsiElement addedFile = directory.add(newFile); - final CodeStyleManager codeStyleManager = manager.getCodeStyleManager(); + final CodeStyleManager codeStyleManager = CodeStyleManager.getInstance(manager.getProject()); final PsiElement shortenedFile = JavaCodeStyleManager.getInstance(project).shortenClassReferences(addedFile); return ((PsiJavaFile)codeStyleManager.reformat(shortenedFile)).getClasses()[0]; } else { diff --git a/java/java-impl/src/com/intellij/refactoring/introduceparameterobject/IntroduceParameterObjectProcessor.java b/java/java-impl/src/com/intellij/refactoring/introduceparameterobject/IntroduceParameterObjectProcessor.java index ca4042a25a18..75d5a63971d6 100644 --- a/java/java-impl/src/com/intellij/refactoring/introduceparameterobject/IntroduceParameterObjectProcessor.java +++ b/java/java-impl/src/com/intellij/refactoring/introduceparameterobject/IntroduceParameterObjectProcessor.java @@ -279,7 +279,7 @@ public class IntroduceParameterObjectProcessor extends FixableUsagesRefactoringP if (directory != null) { - final CodeStyleManager codeStyleManager = method.getManager().getCodeStyleManager(); + final CodeStyleManager codeStyleManager = CodeStyleManager.getInstance(method.getManager().getProject()); final PsiElement shortenedFile = JavaCodeStyleManager.getInstance(newFile.getProject()).shortenClassReferences(newFile); final PsiElement reformattedFile = codeStyleManager.reformat(shortenedFile); return ((PsiJavaFile)directory.add(reformattedFile)).getClasses()[0]; diff --git a/java/java-impl/src/com/intellij/refactoring/makeStatic/MakeClassStaticProcessor.java b/java/java-impl/src/com/intellij/refactoring/makeStatic/MakeClassStaticProcessor.java index 80c7417cf289..e3f325f68811 100644 --- a/java/java-impl/src/com/intellij/refactoring/makeStatic/MakeClassStaticProcessor.java +++ b/java/java-impl/src/com/intellij/refactoring/makeStatic/MakeClassStaticProcessor.java @@ -144,7 +144,7 @@ public class MakeClassStaticProcessor extends MakeMethodOrClassStaticProcessor

implements Ti final Document document = documentManager.getDocument(file); document.replaceString(0, document.getTextLength(), first.getText().trim()); documentManager.commitDocument(document); - PsiManager.getInstance(project).getCodeStyleManager().reformat(file); //TODO: adjustLineIndent + CodeStyleManager.getInstance(PsiManager.getInstance(project).getProject()).reformat(file); //TODO: adjustLineIndent final String relativePath = PsiFileSystemItemUtil.getRelativePath(first.getContainingFile(), file); if (relativePath == null) throw new IncorrectOperationException("Cannot extract!"); diff --git a/plugins/IntentionPowerPak/src/com/siyeh/ipp/comment/ChangeToEndOfLineCommentIntention.java b/plugins/IntentionPowerPak/src/com/siyeh/ipp/comment/ChangeToEndOfLineCommentIntention.java index 7ed686a7cf33..c389ef571aa6 100644 --- a/plugins/IntentionPowerPak/src/com/siyeh/ipp/comment/ChangeToEndOfLineCommentIntention.java +++ b/plugins/IntentionPowerPak/src/com/siyeh/ipp/comment/ChangeToEndOfLineCommentIntention.java @@ -33,7 +33,7 @@ public class ChangeToEndOfLineCommentIntention extends Intention { throws IncorrectOperationException { final PsiComment comment = (PsiComment)element; final PsiManager manager = comment.getManager(); - final CodeStyleManager codeStyleManager = manager.getCodeStyleManager(); + final CodeStyleManager codeStyleManager = CodeStyleManager.getInstance(manager.getProject()); final PsiElement parent = comment.getParent(); assert parent != null; final PsiElementFactory factory = JavaPsiFacade.getInstance(manager.getProject()).getElementFactory(); diff --git a/plugins/IntentionPowerPak/src/com/siyeh/ipp/comment/MoveCommentToSeparateLineIntention.java b/plugins/IntentionPowerPak/src/com/siyeh/ipp/comment/MoveCommentToSeparateLineIntention.java index cf042e877f4c..de84c53a93f7 100644 --- a/plugins/IntentionPowerPak/src/com/siyeh/ipp/comment/MoveCommentToSeparateLineIntention.java +++ b/plugins/IntentionPowerPak/src/com/siyeh/ipp/comment/MoveCommentToSeparateLineIntention.java @@ -58,7 +58,7 @@ public class MoveCommentToSeparateLineIntention extends Intention { parent.addBefore(copyWhiteSpace, insertedComment); selectedComment.delete(); - final CodeStyleManager codeStyleManager = manager.getCodeStyleManager(); + final CodeStyleManager codeStyleManager = CodeStyleManager.getInstance(manager.getProject()); codeStyleManager.reformat(insertedComment); } diff --git a/plugins/IntentionPowerPak/src/com/siyeh/ipp/concatenation/MakeAppendChainIntoAppendSequenceIntention.java b/plugins/IntentionPowerPak/src/com/siyeh/ipp/concatenation/MakeAppendChainIntoAppendSequenceIntention.java index 77ab17336d25..5fe2899be10e 100644 --- a/plugins/IntentionPowerPak/src/com/siyeh/ipp/concatenation/MakeAppendChainIntoAppendSequenceIntention.java +++ b/plugins/IntentionPowerPak/src/com/siyeh/ipp/concatenation/MakeAppendChainIntoAppendSequenceIntention.java @@ -112,7 +112,7 @@ public class MakeAppendChainIntoAppendSequenceIntention extends Intention { final PsiElementFactory factory = JavaPsiFacade.getElementFactory(project); final PsiElement appendStatementParent = appendStatement.getParent(); - final CodeStyleManager codeStyleManager = manager.getCodeStyleManager(); + final CodeStyleManager codeStyleManager = CodeStyleManager.getInstance(manager.getProject()); final PsiCodeBlock codeBlock = factory.createCodeBlockFromText(builder.toString(), appendStatement); diff --git a/plugins/IntentionPowerPak/src/com/siyeh/ipp/conditional/ReplaceConditionalWithIfIntention.java b/plugins/IntentionPowerPak/src/com/siyeh/ipp/conditional/ReplaceConditionalWithIfIntention.java index 858781b48918..db3e9e2e69c5 100644 --- a/plugins/IntentionPowerPak/src/com/siyeh/ipp/conditional/ReplaceConditionalWithIfIntention.java +++ b/plugins/IntentionPowerPak/src/com/siyeh/ipp/conditional/ReplaceConditionalWithIfIntention.java @@ -95,7 +95,7 @@ public class ReplaceConditionalWithIfIntention extends Intention { final PsiElement parent = statement.getParent(); final PsiElement addedElement = parent.addAfter(ifStatement, statement); - final CodeStyleManager styleManager = manager.getCodeStyleManager(); + final CodeStyleManager styleManager = CodeStyleManager.getInstance(manager.getProject()); styleManager.reformat(addedElement); } else { final PsiElement expressionParent = expression.getParent(); diff --git a/plugins/IntentionPowerPak/src/com/siyeh/ipp/initialization/SplitDeclarationAndInitializationIntention.java b/plugins/IntentionPowerPak/src/com/siyeh/ipp/initialization/SplitDeclarationAndInitializationIntention.java index 714209b55a5d..9bce9a7b725b 100644 --- a/plugins/IntentionPowerPak/src/com/siyeh/ipp/initialization/SplitDeclarationAndInitializationIntention.java +++ b/plugins/IntentionPowerPak/src/com/siyeh/ipp/initialization/SplitDeclarationAndInitializationIntention.java @@ -108,7 +108,7 @@ public class SplitDeclarationAndInitializationIntention extends Intention { } } initializer.delete(); - final CodeStyleManager codeStyleManager = manager.getCodeStyleManager(); + final CodeStyleManager codeStyleManager = CodeStyleManager.getInstance(manager.getProject()); codeStyleManager.reformat(field); codeStyleManager.reformat(classInitializer); HighlightUtil.highlightElement(addedElement, diff --git a/plugins/IntentionPowerPak/src/com/siyeh/ipp/whileloop/ExtractWhileLoopConditionToIfStatementIntention.java b/plugins/IntentionPowerPak/src/com/siyeh/ipp/whileloop/ExtractWhileLoopConditionToIfStatementIntention.java index bb685f804329..18e3b77abe9f 100644 --- a/plugins/IntentionPowerPak/src/com/siyeh/ipp/whileloop/ExtractWhileLoopConditionToIfStatementIntention.java +++ b/plugins/IntentionPowerPak/src/com/siyeh/ipp/whileloop/ExtractWhileLoopConditionToIfStatementIntention.java @@ -70,7 +70,7 @@ public class ExtractWhileLoopConditionToIfStatementIntention extends Intention { } else { return; } - final CodeStyleManager codeStyleManager = manager.getCodeStyleManager(); + final CodeStyleManager codeStyleManager = CodeStyleManager.getInstance(manager.getProject()); codeStyleManager.reformat(newElement); } } \ No newline at end of file diff --git a/plugins/devkit/src/actions/GenerateComponentExternalizationAction.java b/plugins/devkit/src/actions/GenerateComponentExternalizationAction.java index 170c567d7404..62eda1f665c9 100644 --- a/plugins/devkit/src/actions/GenerateComponentExternalizationAction.java +++ b/plugins/devkit/src/actions/GenerateComponentExternalizationAction.java @@ -46,7 +46,7 @@ public class GenerateComponentExternalizationAction extends AnAction { assert target != null; final PsiElementFactory factory = JavaPsiFacade.getInstance(target.getProject()).getElementFactory(); - final CodeStyleManager formatter = target.getManager().getCodeStyleManager(); + final CodeStyleManager formatter = CodeStyleManager.getInstance(target.getManager().getProject()); final JavaCodeStyleManager styler = JavaCodeStyleManager.getInstance(target.getProject()); final String qualifiedName = target.getQualifiedName(); Runnable runnable = new Runnable() { diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/GroovyFileImpl.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/GroovyFileImpl.java index aaef612050d2..cd86a6e4f513 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/GroovyFileImpl.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/GroovyFileImpl.java @@ -479,7 +479,7 @@ public class GroovyFileImpl extends GroovyFileBaseImpl implements GroovyFile { public T addMemberDeclaration(@NotNull T decl, PsiElement anchorBefore) throws IncorrectOperationException { T result = (T)addBefore(decl, anchorBefore); - CodeStyleManager styleManager = getManager().getCodeStyleManager(); + CodeStyleManager styleManager = CodeStyleManager.getInstance(getManager().getProject()); PsiElement parent = result.getContainingFile(); TextRange range = result.getTextRange(); styleManager.reformatRange(parent, range.getEndOffset() - 1, range.getEndOffset() + 1); diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/introduce/parameter/FieldConflictsResolver.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/introduce/parameter/FieldConflictsResolver.java index 710c1b01e597..138405dd2ea7 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/introduce/parameter/FieldConflictsResolver.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/introduce/parameter/FieldConflictsResolver.java @@ -141,7 +141,7 @@ public class FieldConflictsResolver { expressionFromText = (GrReferenceExpression)factory.createExpressionFromText("A." + member.getName()); expressionFromText.setQualifier(factory.createReferenceElementForClass(qualifyingClass)); } - CodeStyleManager codeStyleManager = manager.getCodeStyleManager(); + CodeStyleManager codeStyleManager = CodeStyleManager.getInstance(manager.getProject()); expressionFromText = (GrReferenceExpression)codeStyleManager.reformat(expressionFromText); return (GrReferenceExpression)referenceExpression.replace(expressionFromText); } diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/introduce/parameter/java2groovy/FieldConflictsResolver.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/introduce/parameter/java2groovy/FieldConflictsResolver.java index 32a7fab003ed..ec310ebba33f 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/introduce/parameter/java2groovy/FieldConflictsResolver.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/introduce/parameter/java2groovy/FieldConflictsResolver.java @@ -105,7 +105,7 @@ public class FieldConflictsResolver { else { expressionFromText = (GrReferenceExpression)factory.createExpressionFromText(qualifyingClass.getQualifiedName()+ '.' + member.getName()); } - CodeStyleManager codeStyleManager = manager.getCodeStyleManager(); + CodeStyleManager codeStyleManager = CodeStyleManager.getInstance(manager.getProject()); expressionFromText = (GrReferenceExpression)codeStyleManager.reformat(expressionFromText); return (GrReferenceExpression)referenceExpression.replace(expressionFromText); } diff --git a/plugins/xpath/xpath-lang/src/org/intellij/lang/xpath/xslt/intentions/ConvertIfToChooseIntention.java b/plugins/xpath/xpath-lang/src/org/intellij/lang/xpath/xslt/intentions/ConvertIfToChooseIntention.java index 7e294be6486a..8fb77d73801f 100644 --- a/plugins/xpath/xpath-lang/src/org/intellij/lang/xpath/xslt/intentions/ConvertIfToChooseIntention.java +++ b/plugins/xpath/xpath-lang/src/org/intellij/lang/xpath/xslt/intentions/ConvertIfToChooseIntention.java @@ -21,6 +21,7 @@ import com.intellij.openapi.editor.Editor; import com.intellij.openapi.project.Project; import com.intellij.psi.PsiElement; import com.intellij.psi.PsiFile; +import com.intellij.psi.codeStyle.CodeStyleManager; import com.intellij.psi.util.PsiTreeUtil; import com.intellij.psi.xml.XmlChildRole; import com.intellij.psi.xml.XmlTag; @@ -60,7 +61,7 @@ public class ConvertIfToChooseIntention implements IntentionAction { chooseTag.add(whenTag); chooseTag.add(otherwiseTag); - tag.getManager().getCodeStyleManager().reformat(tag.replace(chooseTag)); + CodeStyleManager.getInstance(tag.getManager().getProject()).reformat(tag.replace(chooseTag)); } public boolean isAvailable(@NotNull Project project, Editor editor, PsiFile file) { diff --git a/plugins/xpath/xpath-lang/src/org/intellij/lang/xpath/xslt/quickfix/CreateTemplateFix.java b/plugins/xpath/xpath-lang/src/org/intellij/lang/xpath/xslt/quickfix/CreateTemplateFix.java index 03de27beae4f..6e28e5aebd97 100644 --- a/plugins/xpath/xpath-lang/src/org/intellij/lang/xpath/xslt/quickfix/CreateTemplateFix.java +++ b/plugins/xpath/xpath-lang/src/org/intellij/lang/xpath/xslt/quickfix/CreateTemplateFix.java @@ -22,6 +22,7 @@ import com.intellij.openapi.project.Project; import com.intellij.psi.PsiDocumentManager; import com.intellij.psi.PsiFile; import com.intellij.psi.XmlElementFactory; +import com.intellij.psi.codeStyle.CodeStyleManager; import com.intellij.psi.xml.XmlTag; import com.intellij.util.IncorrectOperationException; import org.intellij.lang.xpath.xslt.XsltSupport; @@ -72,7 +73,7 @@ public class CreateTemplateFix extends AbstractFix { // the start tag of the newly created tag final XmlTag dummy1 = (XmlTag)parentTag.addAfter(XmlElementFactory.getInstance(project).createTagFromText(DUMMY_TAG, XMLLanguage.INSTANCE), tag); templateTag = (XmlTag)parentTag.addAfter(templateTag, dummy1); - templateTag = (XmlTag)tag.getManager().getCodeStyleManager().reformat(templateTag); + templateTag = (XmlTag)CodeStyleManager.getInstance(tag.getManager().getProject()).reformat(templateTag); final XmlTag dummy2 = templateTag.findFirstSubTag("dummy"); diff --git a/plugins/xpath/xpath-lang/src/org/intellij/lang/xpath/xslt/refactoring/RefactoringUtil.java b/plugins/xpath/xpath-lang/src/org/intellij/lang/xpath/xslt/refactoring/RefactoringUtil.java index 7f813d3cf229..305486c34839 100644 --- a/plugins/xpath/xpath-lang/src/org/intellij/lang/xpath/xslt/refactoring/RefactoringUtil.java +++ b/plugins/xpath/xpath-lang/src/org/intellij/lang/xpath/xslt/refactoring/RefactoringUtil.java @@ -18,6 +18,7 @@ package org.intellij.lang.xpath.xslt.refactoring; import com.intellij.psi.PsiElement; import com.intellij.psi.PsiFile; import com.intellij.psi.XmlRecursiveElementVisitor; +import com.intellij.psi.codeStyle.CodeStyleManager; import com.intellij.psi.util.PsiTreeUtil; import com.intellij.psi.xml.XmlAttribute; import com.intellij.psi.xml.XmlTag; @@ -66,7 +67,7 @@ public class RefactoringUtil { } else { paramTag = (XmlTag)templateTag.add(paramTag); } - paramTag = (XmlTag)paramTag.getManager().getCodeStyleManager().reformat(paramTag); + paramTag = (XmlTag)CodeStyleManager.getInstance(paramTag.getManager().getProject()).reformat(paramTag); return paramTag; } @@ -82,7 +83,7 @@ public class RefactoringUtil { } else { withParamTag = (XmlTag)templateTag.add(withParamTag); } - withParamTag = (XmlTag)withParamTag.getManager().getCodeStyleManager().reformat(withParamTag); + withParamTag = (XmlTag)CodeStyleManager.getInstance(withParamTag.getManager().getProject()).reformat(withParamTag); return withParamTag; } diff --git a/plugins/xpath/xpath-lang/src/org/intellij/lang/xpath/xslt/refactoring/XsltExtractFunctionAction.java b/plugins/xpath/xpath-lang/src/org/intellij/lang/xpath/xslt/refactoring/XsltExtractFunctionAction.java index 8f8dc9271f8e..6f2d03ce2438 100644 --- a/plugins/xpath/xpath-lang/src/org/intellij/lang/xpath/xslt/refactoring/XsltExtractFunctionAction.java +++ b/plugins/xpath/xpath-lang/src/org/intellij/lang/xpath/xslt/refactoring/XsltExtractFunctionAction.java @@ -21,6 +21,7 @@ import com.intellij.openapi.editor.Editor; import com.intellij.openapi.ui.Messages; import com.intellij.psi.PsiElement; import com.intellij.psi.PsiFile; +import com.intellij.psi.codeStyle.CodeStyleManager; import com.intellij.psi.util.PsiTreeUtil; import com.intellij.psi.xml.XmlAttribute; import com.intellij.psi.xml.XmlElement; @@ -109,7 +110,7 @@ public class XsltExtractFunctionAction extends BaseIntroduceAction implements Function final ASTNode newNode = e.getNode(); assert newNode != null; - e.getManager().getCodeStyleManager().reformatNewlyAddedElement(blockNode, newNode); + CodeStyleManager.getInstance(e.getManager().getProject()).reformatNewlyAddedElement(blockNode, newNode); PsiDocumentManager.getInstance(project).doPostponedOperationsAndUnblockDocument(editor.getDocument()); diff --git a/xml/relaxng/src/org/intellij/plugins/relaxNG/compact/psi/impl/RncNameImpl.java b/xml/relaxng/src/org/intellij/plugins/relaxNG/compact/psi/impl/RncNameImpl.java index 1b66e0c8e9e5..522cfd0f31c6 100644 --- a/xml/relaxng/src/org/intellij/plugins/relaxNG/compact/psi/impl/RncNameImpl.java +++ b/xml/relaxng/src/org/intellij/plugins/relaxNG/compact/psi/impl/RncNameImpl.java @@ -29,6 +29,7 @@ import com.intellij.openapi.project.Project; import com.intellij.openapi.util.Comparing; import com.intellij.openapi.util.TextRange; import com.intellij.psi.*; +import com.intellij.psi.codeStyle.CodeStyleManager; import com.intellij.psi.scope.BaseScopeProcessor; import com.intellij.psi.tree.IElementType; import com.intellij.util.ArrayUtil; @@ -226,7 +227,7 @@ public class RncNameImpl extends RncElementImpl implements RncName, PsiReference final ASTNode newNode = e.getNode(); assert newNode != null; - e.getManager().getCodeStyleManager().reformatNewlyAddedElement(blockNode, newNode); + CodeStyleManager.getInstance(e.getManager().getProject()).reformatNewlyAddedElement(blockNode, newNode); final SmartPsiElementPointer p = SmartPointerManager.getInstance(project).createLazyPointer(e); PsiDocumentManager.getInstance(project).doPostponedOperationsAndUnblockDocument(editor.getDocument()); From 99d3fbc9745ba92e4c341bca712a5b6ff3c2ae32 Mon Sep 17 00:00:00 2001 From: Dmitry Jemerov Date: Fri, 19 Aug 2011 13:59:13 +0400 Subject: [PATCH 22/78] decouple ComponentManagerImpl from ProgressManager; move to core-impl --- .../progress/ProgressIndicatorProvider.java | 44 +++++++++++++++++++ .../impl/ComponentManagerConfigurator.java | 0 .../components/impl/ComponentManagerImpl.java | 32 +++++--------- .../openapi/progress/ProgressManager.java | 14 ++++++ .../progress/impl/ProgressManagerImpl.java | 4 ++ 5 files changed, 73 insertions(+), 21 deletions(-) create mode 100644 platform/core-api/src/com/intellij/openapi/progress/ProgressIndicatorProvider.java rename platform/{platform-impl => core-impl}/src/com/intellij/openapi/components/impl/ComponentManagerConfigurator.java (100%) rename platform/{platform-impl => core-impl}/src/com/intellij/openapi/components/impl/ComponentManagerImpl.java (96%) diff --git a/platform/core-api/src/com/intellij/openapi/progress/ProgressIndicatorProvider.java b/platform/core-api/src/com/intellij/openapi/progress/ProgressIndicatorProvider.java new file mode 100644 index 000000000000..cf9541e3d044 --- /dev/null +++ b/platform/core-api/src/com/intellij/openapi/progress/ProgressIndicatorProvider.java @@ -0,0 +1,44 @@ +/* + * Copyright 2000-2011 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.intellij.openapi.progress; + +import org.jetbrains.annotations.Nullable; + +/** + * @author yole + */ +public abstract class ProgressIndicatorProvider { + @Nullable + public static ProgressIndicatorProvider ourInstance; + + @Nullable + public static ProgressIndicatorProvider getInstance() { + return ourInstance; + } + + public abstract ProgressIndicator getProgressIndicator(); + + protected abstract void doCheckCanceled() throws ProcessCanceledException; + + public static boolean ourNeedToCheckCancel = false; + public static void checkCanceled() throws ProcessCanceledException { + // smart optimization! There's a thread started in ProgressManagerImpl, that set's this flag up once in 10 milliseconds + if (ourNeedToCheckCancel && ourInstance != null) { + ourInstance.doCheckCanceled(); + ourNeedToCheckCancel = false; + } + } +} diff --git a/platform/platform-impl/src/com/intellij/openapi/components/impl/ComponentManagerConfigurator.java b/platform/core-impl/src/com/intellij/openapi/components/impl/ComponentManagerConfigurator.java similarity index 100% rename from platform/platform-impl/src/com/intellij/openapi/components/impl/ComponentManagerConfigurator.java rename to platform/core-impl/src/com/intellij/openapi/components/impl/ComponentManagerConfigurator.java diff --git a/platform/platform-impl/src/com/intellij/openapi/components/impl/ComponentManagerImpl.java b/platform/core-impl/src/com/intellij/openapi/components/impl/ComponentManagerImpl.java similarity index 96% rename from platform/platform-impl/src/com/intellij/openapi/components/impl/ComponentManagerImpl.java rename to platform/core-impl/src/com/intellij/openapi/components/impl/ComponentManagerImpl.java index 50334de4c46f..15a14fa8c878 100644 --- a/platform/platform-impl/src/com/intellij/openapi/components/impl/ComponentManagerImpl.java +++ b/platform/core-impl/src/com/intellij/openapi/components/impl/ComponentManagerImpl.java @@ -23,7 +23,7 @@ import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.extensions.PluginDescriptor; import com.intellij.openapi.progress.ProcessCanceledException; import com.intellij.openapi.progress.ProgressIndicator; -import com.intellij.openapi.progress.ProgressManager; +import com.intellij.openapi.progress.ProgressIndicatorProvider; import com.intellij.openapi.util.Condition; import com.intellij.openapi.util.Disposer; import com.intellij.openapi.util.UserDataHolderBase; @@ -68,7 +68,6 @@ public abstract class ComponentManagerImpl extends UserDataHolderBase implements private final ComponentManager myParentComponentManager; private Boolean myHeadless; private ComponentsRegistry myComponentsRegistry = new ComponentsRegistry(); - private boolean myHaveProgressManager = false; private final Condition myDisposedCondition = new Condition() { public boolean value(final Object o) { return isDisposed(); @@ -101,9 +100,7 @@ public abstract class ComponentManagerImpl extends UserDataHolderBase implements final Class[] componentInterfaces = myComponentsRegistry.getComponentInterfaces(); for (Class componentInterface : componentInterfaces) { - if (myHaveProgressManager) { - ProgressManager.checkCanceled(); - } + ProgressIndicatorProvider.checkCanceled(); try { createComponent(componentInterface); } @@ -204,20 +201,15 @@ public abstract class ComponentManagerImpl extends UserDataHolderBase implements } private void initComponent(Object component) { - if (myHaveProgressManager) { - final ProgressManager progressManager = ProgressManager.getInstance(); + final ProgressIndicatorProvider progressManager = ProgressIndicatorProvider.getInstance(); - final ProgressIndicator indicator = progressManager != null ? progressManager.getProgressIndicator() : null; - if (indicator != null) { - String name = getComponentName(component); - indicator.checkCanceled(); - indicator.setText2(name); - indicator.setIndeterminate(false); - indicator.setFraction(myComponentsRegistry.getPercentageOfComponentsLoaded()); - } - } - if (component instanceof ProgressManager) { - myHaveProgressManager = true; + final ProgressIndicator indicator = progressManager != null ? progressManager.getProgressIndicator() : null; + if (indicator != null) { + String name = getComponentName(component); + indicator.checkCanceled(); + indicator.setText2(name); + indicator.setIndeterminate(false); + indicator.setFraction(myComponentsRegistry.getPercentageOfComponentsLoaded()); } try { @@ -290,9 +282,7 @@ public abstract class ComponentManagerImpl extends UserDataHolderBase implements Class[] componentClasses = myComponentsRegistry.getComponentInterfaces(); ArrayList components = new ArrayList(componentClasses.length); for (Class interfaceClass : componentClasses) { - if (myHaveProgressManager) { - ProgressManager.checkCanceled(); - } + ProgressIndicatorProvider.checkCanceled(); Object component = getComponent(interfaceClass); if (component != null) components.add(component); } diff --git a/platform/platform-api/src/com/intellij/openapi/progress/ProgressManager.java b/platform/platform-api/src/com/intellij/openapi/progress/ProgressManager.java index 6f06a809ed7d..37b0296b212b 100644 --- a/platform/platform-api/src/com/intellij/openapi/progress/ProgressManager.java +++ b/platform/platform-api/src/com/intellij/openapi/progress/ProgressManager.java @@ -26,6 +26,20 @@ import javax.swing.*; public abstract class ProgressManager { private static final ProgressManager ourInstance = ServiceManager.getService(ProgressManager.class); + static { + ProgressIndicatorProvider.ourInstance = new ProgressIndicatorProvider() { + @Override + public ProgressIndicator getProgressIndicator() { + return ProgressManager.ourInstance.getProgressIndicator(); + } + + @Override + protected void doCheckCanceled() throws ProcessCanceledException { + ProgressManager.ourInstance.doCheckCanceled(); + } + }; + } + public static ProgressManager getInstance() { return ourInstance; } diff --git a/platform/platform-impl/src/com/intellij/openapi/progress/impl/ProgressManagerImpl.java b/platform/platform-impl/src/com/intellij/openapi/progress/impl/ProgressManagerImpl.java index 12befda938a1..296674fc61a0 100644 --- a/platform/platform-impl/src/com/intellij/openapi/progress/impl/ProgressManagerImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/progress/impl/ProgressManagerImpl.java @@ -62,6 +62,7 @@ public class ProgressManagerImpl extends ProgressManager implements Disposable{ catch (InterruptedException ignored) { } ourNeedToCheckCancel = true; + ProgressIndicatorProvider.ourNeedToCheckCancel = true; } } }; @@ -86,6 +87,7 @@ public class ProgressManagerImpl extends ProgressManager implements Disposable{ if (ourLockedCheckCounter > 10) { ourLockedCheckCounter = 0; ourNeedToCheckCancel = true; + ProgressIndicatorProvider.ourNeedToCheckCancel = true; } } else { @@ -98,6 +100,7 @@ public class ProgressManagerImpl extends ProgressManager implements Disposable{ public static void canceled() { ourNeedToCheckCancel = true; + ProgressIndicatorProvider.ourNeedToCheckCancel = true; } private static class NonCancelableIndicator extends EmptyProgressIndicator implements NonCancelableSection { @@ -458,6 +461,7 @@ public class ProgressManagerImpl extends ProgressManager implements Disposable{ @TestOnly public static void setNeedToCheckCancel(boolean needToCheckCancel) { ourNeedToCheckCancel = needToCheckCancel; + ProgressIndicatorProvider.ourNeedToCheckCancel = true; } @TestOnly From 1eaa28394a4de114631c85a7e8475a6c4886b113 Mon Sep 17 00:00:00 2001 From: Dmitry Jemerov Date: Fri, 19 Aug 2011 14:37:39 +0400 Subject: [PATCH 23/78] don't use WriteAction in VfsUtil; rollback InvokeUtil extraction --- .../src/com/intellij/openapi/vfs/VfsUtil.java | 26 ++++++++------ .../src/com/intellij/ui/InvokeUtil.java | 34 ------------------- .../openapi/application/WriteAction.java | 4 +-- .../src/com/intellij/ui/GuiUtils.java | 21 +++++++++--- 4 files changed, 34 insertions(+), 51 deletions(-) delete mode 100644 platform/core-api/src/com/intellij/ui/InvokeUtil.java rename platform/{core-api => platform-api}/src/com/intellij/openapi/application/WriteAction.java (94%) diff --git a/platform/core-api/src/com/intellij/openapi/vfs/VfsUtil.java b/platform/core-api/src/com/intellij/openapi/vfs/VfsUtil.java index 06870db9bb9e..b538fd5992ec 100644 --- a/platform/core-api/src/com/intellij/openapi/vfs/VfsUtil.java +++ b/platform/core-api/src/com/intellij/openapi/vfs/VfsUtil.java @@ -15,14 +15,11 @@ */ package com.intellij.openapi.vfs; -import com.intellij.openapi.application.Result; -import com.intellij.openapi.application.WriteAction; +import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.fileTypes.FileTypeManager; import com.intellij.openapi.fileTypes.FileTypes; -import com.intellij.openapi.util.Comparing; -import com.intellij.openapi.util.SystemInfo; -import com.intellij.openapi.util.ThrowableComputable; +import com.intellij.openapi.util.*; import com.intellij.openapi.util.io.FileUtil; import com.intellij.openapi.util.text.StringUtil; import com.intellij.openapi.vfs.encoding.EncodingManager; @@ -645,13 +642,20 @@ public class VfsUtil { } public static VirtualFile createDirectories(@NotNull final String dir) throws IOException { - return new WriteAction() { - @Override - protected void run(Result result) throws Throwable { - VirtualFile res = createDirectoryIfMissing(dir); - result.setResult(res); + final Ref err = new Ref(); + VirtualFile result = ApplicationManager.getApplication().runWriteAction(new Computable() { + public VirtualFile compute() { + try { + return createDirectoryIfMissing(dir); + } + catch (IOException e) { + err.set(e); + return null; + } } - }.execute().throwException().getResultObject(); + }); + if (!err.isNull()) throw err.get(); + return result; } public static VirtualFile createDirectoryIfMissing(VirtualFile parent, String relativePath) throws IOException { diff --git a/platform/core-api/src/com/intellij/ui/InvokeUtil.java b/platform/core-api/src/com/intellij/ui/InvokeUtil.java deleted file mode 100644 index 59877ae99e34..000000000000 --- a/platform/core-api/src/com/intellij/ui/InvokeUtil.java +++ /dev/null @@ -1,34 +0,0 @@ -package com.intellij.ui; - -import com.intellij.openapi.application.Application; -import com.intellij.openapi.application.ApplicationManager; -import org.jetbrains.annotations.NotNull; - -import javax.swing.*; -import java.lang.reflect.InvocationTargetException; - -public class InvokeUtil { - private InvokeUtil() { - } - - public static void invokeAndWait(@NotNull Runnable runnable) throws InvocationTargetException, InterruptedException { - Application application = ApplicationManager.getApplication(); - assert !application.isDispatchThread() : "Must not be invoked from AWT dispatch thread"; - if (application.isReadAccessAllowed()) { - // make ApplicationImpl catch deadlock situation with readLock held - application.invokeAndWait(runnable, application.getDefaultModalityState()); - return; - } - SwingUtilities.invokeAndWait(runnable); - } - - public static void runOrInvokeAndWait(@NotNull Runnable runnable) throws InvocationTargetException, InterruptedException { - Application application = ApplicationManager.getApplication(); - if (application.isDispatchThread()) { - runnable.run(); - } - else { - invokeAndWait(runnable); - } - } -} diff --git a/platform/core-api/src/com/intellij/openapi/application/WriteAction.java b/platform/platform-api/src/com/intellij/openapi/application/WriteAction.java similarity index 94% rename from platform/core-api/src/com/intellij/openapi/application/WriteAction.java rename to platform/platform-api/src/com/intellij/openapi/application/WriteAction.java index da14f099485a..2c993a319a5e 100644 --- a/platform/core-api/src/com/intellij/openapi/application/WriteAction.java +++ b/platform/platform-api/src/com/intellij/openapi/application/WriteAction.java @@ -15,7 +15,7 @@ */ package com.intellij.openapi.application; -import com.intellij.ui.InvokeUtil; +import com.intellij.ui.GuiUtils; import org.jetbrains.annotations.Nullable; public abstract class WriteAction extends BaseActionRunnable { @@ -28,7 +28,7 @@ public abstract class WriteAction extends BaseActionRunnable { } try { - InvokeUtil.runOrInvokeAndWait(new Runnable() { + GuiUtils.runOrInvokeAndWait(new Runnable() { public void run() { final AccessToken accessToken = start(); try { diff --git a/platform/platform-api/src/com/intellij/ui/GuiUtils.java b/platform/platform-api/src/com/intellij/ui/GuiUtils.java index 3060de465edb..ab241fb4ee60 100644 --- a/platform/platform-api/src/com/intellij/ui/GuiUtils.java +++ b/platform/platform-api/src/com/intellij/ui/GuiUtils.java @@ -15,6 +15,8 @@ */ package com.intellij.ui; +import com.intellij.openapi.application.Application; +import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.fileChooser.FileChooser; import com.intellij.openapi.fileChooser.FileChooserDescriptor; import com.intellij.openapi.fileChooser.FileChooserDescriptorFactory; @@ -359,13 +361,24 @@ public class GuiUtils { return s; } - /** @deprecated please use InvokeUtil instead */ public static void invokeAndWait(@NotNull Runnable runnable) throws InvocationTargetException, InterruptedException { - InvokeUtil.invokeAndWait(runnable); + Application application = ApplicationManager.getApplication(); + assert !application.isDispatchThread() : "Must not be invoked from AWT dispatch thread"; + if (application.isReadAccessAllowed()) { + // make ApplicationImpl catch deadlock situation with readLock held + application.invokeAndWait(runnable, application.getDefaultModalityState()); + return; + } + SwingUtilities.invokeAndWait(runnable); } - /** @deprecated please use InvokeUtil instead */ public static void runOrInvokeAndWait(@NotNull Runnable runnable) throws InvocationTargetException, InterruptedException { - InvokeUtil.runOrInvokeAndWait(runnable); + Application application = ApplicationManager.getApplication(); + if (application.isDispatchThread()) { + runnable.run(); + } + else { + invokeAndWait(runnable); + } } } From 72a7c46665c3c96bdf3e80c4b1a55b2017123ddb Mon Sep 17 00:00:00 2001 From: Dmitry Jemerov Date: Fri, 19 Aug 2011 14:47:12 +0400 Subject: [PATCH 24/78] introduce ApplicationComponentLocator; use it for implementing getInstance() --- .../ApplicationComponentLocator.java | 42 +++++++++++++++++++ .../openapi/components/ServiceManager.java | 4 +- .../openapi/fileTypes/FileTypeManager.java | 6 +-- .../com/intellij/openapi/vfs/VirtualFile.java | 1 - .../openapi/vfs/VirtualFileManager.java | 4 +- .../application/ex/ApplicationManagerEx.java | 2 + 6 files changed, 50 insertions(+), 9 deletions(-) create mode 100644 platform/core-api/src/com/intellij/openapi/application/ApplicationComponentLocator.java diff --git a/platform/core-api/src/com/intellij/openapi/application/ApplicationComponentLocator.java b/platform/core-api/src/com/intellij/openapi/application/ApplicationComponentLocator.java new file mode 100644 index 000000000000..58741c32e16b --- /dev/null +++ b/platform/core-api/src/com/intellij/openapi/application/ApplicationComponentLocator.java @@ -0,0 +1,42 @@ +/* + * Copyright 2000-2011 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.intellij.openapi.application; + +import com.intellij.openapi.components.ComponentManager; + +/** + * @author yole + */ +public class ApplicationComponentLocator { + private static ComponentManager ourInstance; + + public static T getComponent(Class interfaceClass) { + return ourInstance.getComponent(interfaceClass); + } + + public static Object getComponentInstance(Object componentKey) { + return ourInstance.getPicoContainer().getComponentInstance(componentKey); + } + + public static void setInstance(ComponentManager instance) { + ourInstance = instance; + } + + public static boolean initialized() { + return ourInstance != null; + } +} + diff --git a/platform/core-api/src/com/intellij/openapi/components/ServiceManager.java b/platform/core-api/src/com/intellij/openapi/components/ServiceManager.java index 2e7b6e448670..78a55abe0160 100644 --- a/platform/core-api/src/com/intellij/openapi/components/ServiceManager.java +++ b/platform/core-api/src/com/intellij/openapi/components/ServiceManager.java @@ -16,7 +16,7 @@ package com.intellij.openapi.components; -import com.intellij.openapi.application.ApplicationManager; +import com.intellij.openapi.application.ApplicationComponentLocator; import com.intellij.openapi.project.Project; import com.intellij.openapi.util.NotNullLazyKey; import com.intellij.util.NotNullFunction; @@ -33,7 +33,7 @@ public class ServiceManager { } public static T getService(@NotNull Class serviceClass) { - return (T)ApplicationManager.getApplication().getPicoContainer().getComponentInstance(serviceClass.getName()); + return (T)ApplicationComponentLocator.getComponentInstance(serviceClass.getName()); } public static T getService(@NotNull Project project, @NotNull Class serviceClass) { diff --git a/platform/core-api/src/com/intellij/openapi/fileTypes/FileTypeManager.java b/platform/core-api/src/com/intellij/openapi/fileTypes/FileTypeManager.java index a8a7818fd6f8..e8b98ff595a7 100644 --- a/platform/core-api/src/com/intellij/openapi/fileTypes/FileTypeManager.java +++ b/platform/core-api/src/com/intellij/openapi/fileTypes/FileTypeManager.java @@ -15,8 +15,7 @@ */ package com.intellij.openapi.fileTypes; -import com.intellij.openapi.application.Application; -import com.intellij.openapi.application.ApplicationManager; +import com.intellij.openapi.application.ApplicationComponentLocator; import com.intellij.openapi.application.CachedSingletonsRegistry; import com.intellij.openapi.vfs.VirtualFile; import org.jetbrains.annotations.NonNls; @@ -39,8 +38,7 @@ public abstract class FileTypeManager{ */ public static FileTypeManager getInstance() { if (ourInstance == null) { - Application app = ApplicationManager.getApplication(); - ourInstance = app != null ? app.getComponent(FileTypeManager.class) : new MockFileTypeManager(); + ourInstance = ApplicationComponentLocator.initialized() ? ApplicationComponentLocator.getComponent(FileTypeManager.class) : new MockFileTypeManager(); } return ourInstance; } diff --git a/platform/core-api/src/com/intellij/openapi/vfs/VirtualFile.java b/platform/core-api/src/com/intellij/openapi/vfs/VirtualFile.java index 467765ee78a5..3c9cfa19a11f 100644 --- a/platform/core-api/src/com/intellij/openapi/vfs/VirtualFile.java +++ b/platform/core-api/src/com/intellij/openapi/vfs/VirtualFile.java @@ -15,7 +15,6 @@ */ package com.intellij.openapi.vfs; -import com.intellij.openapi.application.Application; import com.intellij.openapi.application.ModalityState; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.fileTypes.FileType; diff --git a/platform/core-api/src/com/intellij/openapi/vfs/VirtualFileManager.java b/platform/core-api/src/com/intellij/openapi/vfs/VirtualFileManager.java index 5bef2cda67b0..f78ebe5c8d30 100644 --- a/platform/core-api/src/com/intellij/openapi/vfs/VirtualFileManager.java +++ b/platform/core-api/src/com/intellij/openapi/vfs/VirtualFileManager.java @@ -16,7 +16,7 @@ package com.intellij.openapi.vfs; import com.intellij.openapi.Disposable; -import com.intellij.openapi.application.ApplicationManager; +import com.intellij.openapi.application.ApplicationComponentLocator; import com.intellij.openapi.application.ModalityState; import com.intellij.openapi.util.ModificationTracker; import com.intellij.openapi.vfs.newvfs.BulkFileListener; @@ -42,7 +42,7 @@ public abstract class VirtualFileManager implements ModificationTracker{ */ @NotNull public static VirtualFileManager getInstance(){ - return ApplicationManager.getApplication().getComponent(VirtualFileManager.class); + return ApplicationComponentLocator.getComponent(VirtualFileManager.class); } /** diff --git a/platform/platform-impl/src/com/intellij/openapi/application/ex/ApplicationManagerEx.java b/platform/platform-impl/src/com/intellij/openapi/application/ex/ApplicationManagerEx.java index e081a0dbe9b8..e85094efa7f0 100644 --- a/platform/platform-impl/src/com/intellij/openapi/application/ex/ApplicationManagerEx.java +++ b/platform/platform-impl/src/com/intellij/openapi/application/ex/ApplicationManagerEx.java @@ -17,6 +17,7 @@ package com.intellij.openapi.application.ex; import com.intellij.openapi.Disposable; import com.intellij.openapi.application.Application; +import com.intellij.openapi.application.ApplicationComponentLocator; import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.application.CachedSingletonsRegistry; import com.intellij.openapi.application.impl.ApplicationImpl; @@ -45,6 +46,7 @@ public class ApplicationManagerEx extends ApplicationManager { public static void setApplication(Application instance) { ourApplication = instance; + ApplicationComponentLocator.setInstance(instance); CachedSingletonsRegistry.cleanupCachedFields(); } From 532435deccd739fbe48d115d934b72d9f58e1f7e Mon Sep 17 00:00:00 2001 From: Dmitry Jemerov Date: Fri, 19 Aug 2011 15:25:02 +0400 Subject: [PATCH 25/78] VfsUtil moves back to platform-api; VirtualFile dependencies on VfsUtil moved elsewhere --- .../com/intellij/openapi/vfs/VirtualFile.java | 14 ++++++---- .../openapi/vfs/encoding/EncodingManager.java | 19 ++++++++++++++ .../copy/CopyFilesOrDirectoriesHandler.java | 4 +-- .../src/com/intellij/openapi/vfs/VfsUtil.java | 26 +++---------------- .../openapi/vfs/newvfs/NewVirtualFile.java | 4 +-- .../newvfs/impl/VirtualFileSystemEntry.java | 7 +++-- 6 files changed, 38 insertions(+), 36 deletions(-) rename platform/{core-api => platform-api}/src/com/intellij/openapi/vfs/VfsUtil.java (96%) diff --git a/platform/core-api/src/com/intellij/openapi/vfs/VirtualFile.java b/platform/core-api/src/com/intellij/openapi/vfs/VirtualFile.java index 3c9cfa19a11f..e8869e898dad 100644 --- a/platform/core-api/src/com/intellij/openapi/vfs/VirtualFile.java +++ b/platform/core-api/src/com/intellij/openapi/vfs/VirtualFile.java @@ -179,7 +179,7 @@ public abstract class VirtualFile extends UserDataHolderBase implements Modifica */ public void rename(Object requestor, @NotNull @NonNls String newName) throws IOException { if (getName().equals(newName)) return; - if (!VfsUtil.isValidName(newName)) { + if (!isValidName(newName)) { throw new IOException(VfsBundle.message("file.invalid.name.error", newName)); } @@ -321,7 +321,7 @@ public abstract class VirtualFile extends UserDataHolderBase implements Modifica throw new IOException(VfsBundle.message("invalid.directory.create.files")); } - if (!VfsUtil.isValidName(name)) { + if (!isValidName(name)) { throw new IOException(VfsBundle.message("directory.invalid.name.error", name)); } @@ -351,7 +351,7 @@ public abstract class VirtualFile extends UserDataHolderBase implements Modifica throw new IOException(VfsBundle.message("invalid.directory.create.files")); } - if (!VfsUtil.isValidName(name)) { + if (!isValidName(name)) { throw new IOException(VfsBundle.message("file.invalid.name.error", name)); } @@ -391,7 +391,7 @@ public abstract class VirtualFile extends UserDataHolderBase implements Modifica throw new IOException(VfsBundle.message("file.move.error", newParent.getPresentableUrl())); } - VfsUtil.doActionAndRestoreEncoding(this, new ThrowableComputable() { + EncodingManager.doActionAndRestoreEncoding(this, new ThrowableComputable() { public VirtualFile compute() throws IOException { getFileSystem().moveFile(requestor, VirtualFile.this, newParent); return VirtualFile.this; @@ -408,7 +408,7 @@ public abstract class VirtualFile extends UserDataHolderBase implements Modifica throw new IOException(VfsBundle.message("file.copy.target.must.be.directory")); } - return VfsUtil.doActionAndRestoreEncoding(this, new ThrowableComputable() { + return EncodingManager.doActionAndRestoreEncoding(this, new ThrowableComputable() { public VirtualFile compute() throws IOException { return getFileSystem().copyFile(requestor, VirtualFile.this, newParent, copyName); } @@ -628,4 +628,8 @@ public abstract class VirtualFile extends UserDataHolderBase implements Modifica public boolean isInLocalFileSystem() { return false; } + + public static boolean isValidName(@NotNull String name) { + return name.indexOf('\\') < 0 && name.indexOf('/') < 0; + } } diff --git a/platform/core-api/src/com/intellij/openapi/vfs/encoding/EncodingManager.java b/platform/core-api/src/com/intellij/openapi/vfs/encoding/EncodingManager.java index 7fdade2e7c40..d9a6372faa33 100644 --- a/platform/core-api/src/com/intellij/openapi/vfs/encoding/EncodingManager.java +++ b/platform/core-api/src/com/intellij/openapi/vfs/encoding/EncodingManager.java @@ -18,6 +18,8 @@ package com.intellij.openapi.vfs.encoding; import com.intellij.openapi.Disposable; import com.intellij.openapi.components.ServiceManager; import com.intellij.openapi.editor.Document; +import com.intellij.openapi.util.Comparing; +import com.intellij.openapi.util.ThrowableComputable; import com.intellij.openapi.vfs.VirtualFile; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; @@ -88,4 +90,21 @@ public abstract class EncodingManager { public abstract void removePropertyChangeListener(@NotNull PropertyChangeListener listener); public abstract Charset getCachedCharsetFromContent(@NotNull Document document); + + public static VirtualFile doActionAndRestoreEncoding(@NotNull VirtualFile fileBefore, @NotNull ThrowableComputable action) throws E { + Charset charsetBefore = getInstance().getEncoding(fileBefore, true); + VirtualFile fileAfter = null; + try { + fileAfter = action.compute(); + return fileAfter; + } + finally { + if (fileAfter != null) { + Charset actual = getInstance().getEncoding(fileAfter, true); + if (!Comparing.equal(actual, charsetBefore)) { + getInstance().setEncoding(fileAfter, charsetBefore); + } + } + } + } } diff --git a/platform/lang-impl/src/com/intellij/refactoring/copy/CopyFilesOrDirectoriesHandler.java b/platform/lang-impl/src/com/intellij/refactoring/copy/CopyFilesOrDirectoriesHandler.java index 7e7e7768fde5..2eea7d045ee5 100644 --- a/platform/lang-impl/src/com/intellij/refactoring/copy/CopyFilesOrDirectoriesHandler.java +++ b/platform/lang-impl/src/com/intellij/refactoring/copy/CopyFilesOrDirectoriesHandler.java @@ -23,8 +23,8 @@ import com.intellij.openapi.command.CommandProcessor; import com.intellij.openapi.project.Project; import com.intellij.openapi.ui.Messages; import com.intellij.openapi.util.ThrowableComputable; -import com.intellij.openapi.vfs.VfsUtil; import com.intellij.openapi.vfs.VirtualFile; +import com.intellij.openapi.vfs.encoding.EncodingManager; import com.intellij.openapi.wm.ToolWindowManager; import com.intellij.psi.*; import com.intellij.psi.util.PsiTreeUtil; @@ -254,7 +254,7 @@ public class CopyFilesOrDirectoriesHandler implements CopyHandlerDelegate { if (newName == null) newName = directory.getName(); final PsiDirectory existing = targetDirectory.findSubdirectory(newName); final PsiDirectory subdirectory = existing == null ? targetDirectory.createSubdirectory(newName) : existing; - VfsUtil.doActionAndRestoreEncoding(directory.getVirtualFile(), new ThrowableComputable() { + EncodingManager.doActionAndRestoreEncoding(directory.getVirtualFile(), new ThrowableComputable() { public VirtualFile compute() { return subdirectory.getVirtualFile(); } diff --git a/platform/core-api/src/com/intellij/openapi/vfs/VfsUtil.java b/platform/platform-api/src/com/intellij/openapi/vfs/VfsUtil.java similarity index 96% rename from platform/core-api/src/com/intellij/openapi/vfs/VfsUtil.java rename to platform/platform-api/src/com/intellij/openapi/vfs/VfsUtil.java index b538fd5992ec..e612fe0a7d06 100644 --- a/platform/core-api/src/com/intellij/openapi/vfs/VfsUtil.java +++ b/platform/platform-api/src/com/intellij/openapi/vfs/VfsUtil.java @@ -19,10 +19,11 @@ import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.fileTypes.FileTypeManager; import com.intellij.openapi.fileTypes.FileTypes; -import com.intellij.openapi.util.*; +import com.intellij.openapi.util.Computable; +import com.intellij.openapi.util.Ref; +import com.intellij.openapi.util.SystemInfo; import com.intellij.openapi.util.io.FileUtil; import com.intellij.openapi.util.text.StringUtil; -import com.intellij.openapi.vfs.encoding.EncodingManager; import com.intellij.util.ArrayUtil; import com.intellij.util.Function; import com.intellij.util.PathUtil; @@ -595,10 +596,6 @@ public class VfsUtil { return null; } - public static boolean isValidName(@NotNull String name) { - return name.indexOf('\\') < 0 && name.indexOf('/') < 0; - } - public static String getUrlForLibraryRoot(@NotNull File libraryRoot) { String path = FileUtil.toSystemIndependentName(libraryRoot.getAbsolutePath()); if (FileTypeManager.getInstance().getFileTypeByFileName(libraryRoot.getName()) == FileTypes.ARCHIVE) { @@ -687,23 +684,6 @@ public class VfsUtil { return file; } - public static VirtualFile doActionAndRestoreEncoding(@NotNull VirtualFile fileBefore, @NotNull ThrowableComputable action) throws E { - Charset charsetBefore = EncodingManager.getInstance().getEncoding(fileBefore, true); - VirtualFile fileAfter = null; - try { - fileAfter = action.compute(); - return fileAfter; - } - finally { - if (fileAfter != null) { - Charset actual = EncodingManager.getInstance().getEncoding(fileAfter, true); - if (!Comparing.equal(actual, charsetBefore)) { - EncodingManager.getInstance().setEncoding(fileAfter, charsetBefore); - } - } - } - } - public static void processFileRecursivelyWithoutIgnored(@NotNull final VirtualFile root, @NotNull final Processor processor) { final FileTypeManager ftm = FileTypeManager.getInstance(); processFilesRecursively(root, processor, new Convertor() { diff --git a/platform/platform-api/src/com/intellij/openapi/vfs/newvfs/NewVirtualFile.java b/platform/platform-api/src/com/intellij/openapi/vfs/newvfs/NewVirtualFile.java index 7917550d3db9..c372fa34c9a4 100644 --- a/platform/platform-api/src/com/intellij/openapi/vfs/newvfs/NewVirtualFile.java +++ b/platform/platform-api/src/com/intellij/openapi/vfs/newvfs/NewVirtualFile.java @@ -25,9 +25,9 @@ import com.intellij.openapi.fileTypes.FileType; import com.intellij.openapi.util.Key; import com.intellij.openapi.util.ThrowableComputable; import com.intellij.openapi.util.io.FileUtil; -import com.intellij.openapi.vfs.VfsUtil; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.openapi.vfs.VirtualFileWithId; +import com.intellij.openapi.vfs.encoding.EncodingManager; import com.intellij.util.LocalTimeCounter; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; @@ -145,7 +145,7 @@ public abstract class NewVirtualFile extends VirtualFile implements VirtualFileW throw new IOException("Destination already exists: " + newParent.getPath() + "/" + getName()); } - VfsUtil.doActionAndRestoreEncoding(this, new ThrowableComputable() { + EncodingManager.doActionAndRestoreEncoding(this, new ThrowableComputable() { public VirtualFile compute() throws IOException { getFileSystem().moveFile(requestor, NewVirtualFile.this, newParent); return NewVirtualFile.this; diff --git a/platform/platform-impl/src/com/intellij/openapi/vfs/newvfs/impl/VirtualFileSystemEntry.java b/platform/platform-impl/src/com/intellij/openapi/vfs/newvfs/impl/VirtualFileSystemEntry.java index 9ec8ad120f4e..f728f6f344da 100644 --- a/platform/platform-impl/src/com/intellij/openapi/vfs/newvfs/impl/VirtualFileSystemEntry.java +++ b/platform/platform-impl/src/com/intellij/openapi/vfs/newvfs/impl/VirtualFileSystemEntry.java @@ -22,7 +22,6 @@ import com.intellij.openapi.util.io.FileTooBigException; import com.intellij.openapi.util.text.StringUtil; import com.intellij.openapi.vfs.LocalFileSystem; import com.intellij.openapi.vfs.VfsBundle; -import com.intellij.openapi.vfs.VfsUtil; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.openapi.vfs.encoding.EncodingManager; import com.intellij.openapi.vfs.newvfs.ManagingFS; @@ -256,7 +255,7 @@ public abstract class VirtualFileSystemEntry extends NewVirtualFile { public void rename(final Object requestor, @NotNull @NonNls final String newName) throws IOException { if (getName().equals(newName)) return; - if (!VfsUtil.isValidName(newName)) { + if (!isValidName(newName)) { throw new IOException(VfsBundle.message("file.invalid.name.error", newName)); } @@ -298,7 +297,7 @@ public abstract class VirtualFileSystemEntry extends NewVirtualFile { throw new IOException(VfsBundle.message("file.copy.target.must.be.directory")); } - return VfsUtil.doActionAndRestoreEncoding(this, new ThrowableComputable() { + return EncodingManager.doActionAndRestoreEncoding(this, new ThrowableComputable() { public VirtualFile compute() throws IOException { return ourPersistence.copyFile(requestor, VirtualFileSystemEntry.this, newParent, copyName); } @@ -310,7 +309,7 @@ public abstract class VirtualFileSystemEntry extends NewVirtualFile { throw new IOException(VfsBundle.message("file.move.error", newParent.getPresentableUrl())); } - VfsUtil.doActionAndRestoreEncoding(this, new ThrowableComputable() { + EncodingManager.doActionAndRestoreEncoding(this, new ThrowableComputable() { public VirtualFile compute() throws IOException { ourPersistence.moveFile(requestor, VirtualFileSystemEntry.this, newParent); return VirtualFileSystemEntry.this; From f942dfe973e46154b44263268fb45e739390c293 Mon Sep 17 00:00:00 2001 From: Dmitry Jemerov Date: Fri, 19 Aug 2011 16:07:46 +0400 Subject: [PATCH 26/78] remove refresh() with modality state from VirtualFile API --- .../src/com/intellij/openapi/vfs/VirtualFile.java | 8 -------- .../intellij/openapi/vfs/newvfs/NewVirtualFile.java | 6 ------ .../openapi/fileChooser/ex/FileSystemTreeImpl.java | 11 +++++++---- .../openapi/vfs/impl/local/LocalFileSystemImpl.java | 4 ++-- 4 files changed, 9 insertions(+), 20 deletions(-) diff --git a/platform/core-api/src/com/intellij/openapi/vfs/VirtualFile.java b/platform/core-api/src/com/intellij/openapi/vfs/VirtualFile.java index e8869e898dad..3f00356c99b6 100644 --- a/platform/core-api/src/com/intellij/openapi/vfs/VirtualFile.java +++ b/platform/core-api/src/com/intellij/openapi/vfs/VirtualFile.java @@ -15,7 +15,6 @@ */ package com.intellij.openapi.vfs; -import com.intellij.openapi.application.ModalityState; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.fileTypes.FileType; import com.intellij.openapi.fileTypes.FileTypeManager; @@ -574,13 +573,6 @@ public abstract class VirtualFile extends UserDataHolderBase implements Modifica */ public abstract void refresh(boolean asynchronous, boolean recursive, Runnable postRunnable); - public void refresh(boolean asynchronous, boolean recursive, Runnable postRunnable, ModalityState modalityState) { - if (modalityState != ModalityState.NON_MODAL) { - LOG.error("Refresh with non-modal modality state is not implemented for file: " + this); - } - refresh(asynchronous, recursive, postRunnable); - } - public String getPresentableName() { return getName(); } diff --git a/platform/platform-api/src/com/intellij/openapi/vfs/newvfs/NewVirtualFile.java b/platform/platform-api/src/com/intellij/openapi/vfs/newvfs/NewVirtualFile.java index c372fa34c9a4..e9a7650accdd 100644 --- a/platform/platform-api/src/com/intellij/openapi/vfs/newvfs/NewVirtualFile.java +++ b/platform/platform-api/src/com/intellij/openapi/vfs/newvfs/NewVirtualFile.java @@ -20,7 +20,6 @@ package com.intellij.openapi.vfs.newvfs; import com.intellij.openapi.application.ApplicationManager; -import com.intellij.openapi.application.ModalityState; import com.intellij.openapi.fileTypes.FileType; import com.intellij.openapi.util.Key; import com.intellij.openapi.util.ThrowableComputable; @@ -104,11 +103,6 @@ public abstract class NewVirtualFile extends VirtualFile implements VirtualFileW RefreshQueue.getInstance().refresh(asynchronous, recursive, postRunnable, this); } - @Override - public void refresh(boolean asynchronous, boolean recursive, Runnable postRunnable, ModalityState modalityState) { - RefreshQueue.getInstance().refresh(asynchronous, recursive, postRunnable, modalityState, this); - } - public long getModificationStamp() { return myModificationStamp; } diff --git a/platform/platform-impl/src/com/intellij/openapi/fileChooser/ex/FileSystemTreeImpl.java b/platform/platform-impl/src/com/intellij/openapi/fileChooser/ex/FileSystemTreeImpl.java index e38139bdc83b..6a00226b34a4 100644 --- a/platform/platform-impl/src/com/intellij/openapi/fileChooser/ex/FileSystemTreeImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/fileChooser/ex/FileSystemTreeImpl.java @@ -39,6 +39,7 @@ import com.intellij.openapi.vfs.JarFileSystem; import com.intellij.openapi.vfs.VfsUtil; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.openapi.vfs.newvfs.NewVirtualFile; +import com.intellij.openapi.vfs.newvfs.RefreshQueue; import com.intellij.ui.PopupHandler; import com.intellij.ui.SimpleTextAttributes; import com.intellij.ui.TreeSpeedSearch; @@ -483,10 +484,12 @@ public class FileSystemTreeImpl implements FileSystemTree { } - if (myTreeBuilder.getTreeStructure().isToBuildChildrenInBackground(virtualFile)) { - virtualFile.refresh(true, false, null, ModalityState.stateForComponent(myTree)); - } else { - virtualFile.refresh(false, false, null, ModalityState.stateForComponent(myTree)); + boolean async = myTreeBuilder.getTreeStructure().isToBuildChildrenInBackground(virtualFile); + if (virtualFile instanceof NewVirtualFile) { + RefreshQueue.getInstance().refresh(async, false, null, ModalityState.stateForComponent(myTree), virtualFile); + } + else { + virtualFile.refresh(async, false); } } } diff --git a/platform/platform-impl/src/com/intellij/openapi/vfs/impl/local/LocalFileSystemImpl.java b/platform/platform-impl/src/com/intellij/openapi/vfs/impl/local/LocalFileSystemImpl.java index 9ea6b7cecd96..6d45f014f470 100644 --- a/platform/platform-impl/src/com/intellij/openapi/vfs/impl/local/LocalFileSystemImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/vfs/impl/local/LocalFileSystemImpl.java @@ -329,10 +329,10 @@ public final class LocalFileSystemImpl extends LocalFileSystemBase implements Ap if (existingFile != null) { if (!isAlreadyWatched(result)) { final ModalityState modalityState = ModalityState.current(); - existingFile.refresh(true, toWatchRecursively, null, modalityState); + RefreshQueue.getInstance().refresh(true, toWatchRecursively, null, modalityState, existingFile); if (existingFile.isDirectory() && !toWatchRecursively && existingFile instanceof NewVirtualFile) { for (VirtualFile child : ((NewVirtualFile)existingFile).getCachedChildren()) { - child.refresh(true, false, null, modalityState); + RefreshQueue.getInstance().refresh(true, false, null, modalityState, child); } } } From db272521bbb56dea7d0806dbf5c403248d4d28e1 Mon Sep 17 00:00:00 2001 From: Dmitry Jemerov Date: Fri, 19 Aug 2011 16:46:31 +0400 Subject: [PATCH 27/78] moving stuff back to platform-api --- .../src/com/intellij/openapi/application/BaseActionRunnable.java | 0 .../src/com/intellij/openapi/application/Result.java | 0 .../src/com/intellij/openapi/application/RunResult.java | 0 .../src/com/intellij/openapi/vfs/JarFileSystem.java | 0 .../src/com/intellij/openapi/vfs/LocalFileOperationsHandler.java | 0 .../src/com/intellij/openapi/vfs/LocalFileSystem.java | 0 .../src/com/intellij/openapi/vfs/newvfs/FileSystemInterface.java | 0 .../src/com/intellij/openapi/vfs/newvfs/NewVirtualFileSystem.java | 0 .../intellij/openapi/vfs/newvfs/VirtualFileFilteringListener.java | 0 .../src/com/intellij/util/PathUtil.java | 0 10 files changed, 0 insertions(+), 0 deletions(-) rename platform/{core-api => platform-api}/src/com/intellij/openapi/application/BaseActionRunnable.java (100%) rename platform/{core-api => platform-api}/src/com/intellij/openapi/application/Result.java (100%) rename platform/{core-api => platform-api}/src/com/intellij/openapi/application/RunResult.java (100%) rename platform/{core-api => platform-api}/src/com/intellij/openapi/vfs/JarFileSystem.java (100%) rename platform/{core-api => platform-api}/src/com/intellij/openapi/vfs/LocalFileOperationsHandler.java (100%) rename platform/{core-api => platform-api}/src/com/intellij/openapi/vfs/LocalFileSystem.java (100%) rename platform/{core-api => platform-api}/src/com/intellij/openapi/vfs/newvfs/FileSystemInterface.java (100%) rename platform/{core-api => platform-api}/src/com/intellij/openapi/vfs/newvfs/NewVirtualFileSystem.java (100%) rename platform/{core-api => platform-api}/src/com/intellij/openapi/vfs/newvfs/VirtualFileFilteringListener.java (100%) rename platform/{core-api => platform-api}/src/com/intellij/util/PathUtil.java (100%) diff --git a/platform/core-api/src/com/intellij/openapi/application/BaseActionRunnable.java b/platform/platform-api/src/com/intellij/openapi/application/BaseActionRunnable.java similarity index 100% rename from platform/core-api/src/com/intellij/openapi/application/BaseActionRunnable.java rename to platform/platform-api/src/com/intellij/openapi/application/BaseActionRunnable.java diff --git a/platform/core-api/src/com/intellij/openapi/application/Result.java b/platform/platform-api/src/com/intellij/openapi/application/Result.java similarity index 100% rename from platform/core-api/src/com/intellij/openapi/application/Result.java rename to platform/platform-api/src/com/intellij/openapi/application/Result.java diff --git a/platform/core-api/src/com/intellij/openapi/application/RunResult.java b/platform/platform-api/src/com/intellij/openapi/application/RunResult.java similarity index 100% rename from platform/core-api/src/com/intellij/openapi/application/RunResult.java rename to platform/platform-api/src/com/intellij/openapi/application/RunResult.java diff --git a/platform/core-api/src/com/intellij/openapi/vfs/JarFileSystem.java b/platform/platform-api/src/com/intellij/openapi/vfs/JarFileSystem.java similarity index 100% rename from platform/core-api/src/com/intellij/openapi/vfs/JarFileSystem.java rename to platform/platform-api/src/com/intellij/openapi/vfs/JarFileSystem.java diff --git a/platform/core-api/src/com/intellij/openapi/vfs/LocalFileOperationsHandler.java b/platform/platform-api/src/com/intellij/openapi/vfs/LocalFileOperationsHandler.java similarity index 100% rename from platform/core-api/src/com/intellij/openapi/vfs/LocalFileOperationsHandler.java rename to platform/platform-api/src/com/intellij/openapi/vfs/LocalFileOperationsHandler.java diff --git a/platform/core-api/src/com/intellij/openapi/vfs/LocalFileSystem.java b/platform/platform-api/src/com/intellij/openapi/vfs/LocalFileSystem.java similarity index 100% rename from platform/core-api/src/com/intellij/openapi/vfs/LocalFileSystem.java rename to platform/platform-api/src/com/intellij/openapi/vfs/LocalFileSystem.java diff --git a/platform/core-api/src/com/intellij/openapi/vfs/newvfs/FileSystemInterface.java b/platform/platform-api/src/com/intellij/openapi/vfs/newvfs/FileSystemInterface.java similarity index 100% rename from platform/core-api/src/com/intellij/openapi/vfs/newvfs/FileSystemInterface.java rename to platform/platform-api/src/com/intellij/openapi/vfs/newvfs/FileSystemInterface.java diff --git a/platform/core-api/src/com/intellij/openapi/vfs/newvfs/NewVirtualFileSystem.java b/platform/platform-api/src/com/intellij/openapi/vfs/newvfs/NewVirtualFileSystem.java similarity index 100% rename from platform/core-api/src/com/intellij/openapi/vfs/newvfs/NewVirtualFileSystem.java rename to platform/platform-api/src/com/intellij/openapi/vfs/newvfs/NewVirtualFileSystem.java diff --git a/platform/core-api/src/com/intellij/openapi/vfs/newvfs/VirtualFileFilteringListener.java b/platform/platform-api/src/com/intellij/openapi/vfs/newvfs/VirtualFileFilteringListener.java similarity index 100% rename from platform/core-api/src/com/intellij/openapi/vfs/newvfs/VirtualFileFilteringListener.java rename to platform/platform-api/src/com/intellij/openapi/vfs/newvfs/VirtualFileFilteringListener.java diff --git a/platform/core-api/src/com/intellij/util/PathUtil.java b/platform/platform-api/src/com/intellij/util/PathUtil.java similarity index 100% rename from platform/core-api/src/com/intellij/util/PathUtil.java rename to platform/platform-api/src/com/intellij/util/PathUtil.java From 5fa7a9fa2b501835b22cc6a1afcec2114a3eee8a Mon Sep 17 00:00:00 2001 From: Dmitry Jemerov Date: Fri, 19 Aug 2011 16:49:30 +0400 Subject: [PATCH 28/78] unimplement unneeded interface --- .../openapi/vfs/impl/VirtualFileManagerImpl.java | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) diff --git a/platform/platform-impl/src/com/intellij/openapi/vfs/impl/VirtualFileManagerImpl.java b/platform/platform-impl/src/com/intellij/openapi/vfs/impl/VirtualFileManagerImpl.java index 81ac98e52091..8fbf65ffb83d 100644 --- a/platform/platform-impl/src/com/intellij/openapi/vfs/impl/VirtualFileManagerImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/vfs/impl/VirtualFileManagerImpl.java @@ -19,7 +19,6 @@ import com.intellij.openapi.Disposable; import com.intellij.openapi.application.Application; import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.application.ModalityState; -import com.intellij.openapi.components.ApplicationComponent; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.util.Disposer; import com.intellij.openapi.util.KeyedExtensionCollector; @@ -40,7 +39,7 @@ import java.util.ArrayList; import java.util.Collections; import java.util.List; -public class VirtualFileManagerImpl extends VirtualFileManagerEx implements ApplicationComponent { +public class VirtualFileManagerImpl extends VirtualFileManagerEx { private static final Logger LOG = Logger.getInstance("#com.intellij.openapi.vfs.impl.VirtualFileManagerImpl"); @@ -73,17 +72,6 @@ public class VirtualFileManagerImpl extends VirtualFileManagerEx implements Appl bus.connect().subscribe(VFS_CHANGES, new BulkVirtualFileListenerAdapter(myVirtualFileListenerMulticaster.getMulticaster())); } - @NotNull - public String getComponentName() { - return "VirtualFileManager"; - } - - public void initComponent() { - } - - public void disposeComponent() { - } - public void registerFileSystem(VirtualFileSystem fileSystem) { myCollector.addExplicitExtension(fileSystem.getProtocol(), fileSystem); if (!(fileSystem instanceof NewVirtualFileSystem)) { From 24a1e71a72d9219fb012364ff4abd69f52ca6e9b Mon Sep 17 00:00:00 2001 From: Dmitry Jemerov Date: Fri, 19 Aug 2011 16:52:20 +0400 Subject: [PATCH 29/78] to core-api --- .../src/com/intellij/openapi/util/KeyedExtensionCollector.java | 0 .../src/com/intellij/util/KeyedLazyInstance.java | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename platform/{platform-api => core-api}/src/com/intellij/openapi/util/KeyedExtensionCollector.java (100%) rename platform/{platform-api => core-api}/src/com/intellij/util/KeyedLazyInstance.java (100%) diff --git a/platform/platform-api/src/com/intellij/openapi/util/KeyedExtensionCollector.java b/platform/core-api/src/com/intellij/openapi/util/KeyedExtensionCollector.java similarity index 100% rename from platform/platform-api/src/com/intellij/openapi/util/KeyedExtensionCollector.java rename to platform/core-api/src/com/intellij/openapi/util/KeyedExtensionCollector.java diff --git a/platform/platform-api/src/com/intellij/util/KeyedLazyInstance.java b/platform/core-api/src/com/intellij/util/KeyedLazyInstance.java similarity index 100% rename from platform/platform-api/src/com/intellij/util/KeyedLazyInstance.java rename to platform/core-api/src/com/intellij/util/KeyedLazyInstance.java From df988b50f80f84351dbe141bfad9b35d88d0a854 Mon Sep 17 00:00:00 2001 From: Dmitry Jemerov Date: Fri, 19 Aug 2011 17:11:51 +0400 Subject: [PATCH 30/78] remove refresh with modality state from VirtualFileManager API --- .../com/intellij/openapi/vfs/VirtualFileManager.java | 3 --- .../com/intellij/openapi/vfs/newvfs/RefreshQueue.java | 2 ++ .../src/com/intellij/ide/SaveAndSyncHandler.java | 3 +-- .../fileChooser/actions/RefreshFileChooserAction.java | 4 ++-- .../openapi/vfs/impl/VirtualFileManagerImpl.java | 1 - .../intellij/openapi/vfs/newvfs/RefreshQueueImpl.java | 5 +++++ .../src/com/intellij/mock/MockVirtualFileManager.java | 11 ++++------- 7 files changed, 14 insertions(+), 15 deletions(-) diff --git a/platform/core-api/src/com/intellij/openapi/vfs/VirtualFileManager.java b/platform/core-api/src/com/intellij/openapi/vfs/VirtualFileManager.java index f78ebe5c8d30..8c0016d7a42a 100644 --- a/platform/core-api/src/com/intellij/openapi/vfs/VirtualFileManager.java +++ b/platform/core-api/src/com/intellij/openapi/vfs/VirtualFileManager.java @@ -17,7 +17,6 @@ package com.intellij.openapi.vfs; import com.intellij.openapi.Disposable; import com.intellij.openapi.application.ApplicationComponentLocator; -import com.intellij.openapi.application.ModalityState; import com.intellij.openapi.util.ModificationTracker; import com.intellij.openapi.vfs.newvfs.BulkFileListener; import com.intellij.util.messages.Topic; @@ -73,8 +72,6 @@ public abstract class VirtualFileManager implements ModificationTracker{ */ public abstract void refresh(boolean asynchronous, @Nullable Runnable postAction); - public abstract void refresh(boolean asynchronous, @Nullable Runnable postAction, ModalityState modalityState); - /** * Searches for the file specified by given URL. URL is a string which uniquely identifies file in all * file systems. diff --git a/platform/platform-api/src/com/intellij/openapi/vfs/newvfs/RefreshQueue.java b/platform/platform-api/src/com/intellij/openapi/vfs/newvfs/RefreshQueue.java index 8c7cfbe15178..9400ee24d539 100644 --- a/platform/platform-api/src/com/intellij/openapi/vfs/newvfs/RefreshQueue.java +++ b/platform/platform-api/src/com/intellij/openapi/vfs/newvfs/RefreshQueue.java @@ -42,6 +42,8 @@ public abstract class RefreshQueue { session.launch(); } + public abstract void refreshLocalRoots(boolean async, @Nullable Runnable postAction, ModalityState modalityState); + public final void refresh(boolean async, boolean recursive, @Nullable Runnable finishRunnable, VirtualFile... files) { refresh(async, recursive, finishRunnable, getDefaultModalityState(), files); } diff --git a/platform/platform-impl/src/com/intellij/ide/SaveAndSyncHandler.java b/platform/platform-impl/src/com/intellij/ide/SaveAndSyncHandler.java index 273c6e8e95ee..3f9534e82b61 100644 --- a/platform/platform-impl/src/com/intellij/ide/SaveAndSyncHandler.java +++ b/platform/platform-impl/src/com/intellij/ide/SaveAndSyncHandler.java @@ -27,7 +27,6 @@ import com.intellij.openapi.progress.ProgressManager; import com.intellij.openapi.project.Project; import com.intellij.openapi.project.ex.ProjectManagerEx; import com.intellij.openapi.vfs.VirtualFile; -import com.intellij.openapi.vfs.VirtualFileManager; import com.intellij.openapi.vfs.newvfs.NewVirtualFile; import com.intellij.openapi.vfs.newvfs.RefreshQueue; import com.intellij.openapi.vfs.newvfs.RefreshSession; @@ -164,7 +163,7 @@ public class SaveAndSyncHandler implements ApplicationComponent { if (LOG.isDebugEnabled()) { LOG.debug("refresh VFS"); } - VirtualFileManager.getInstance().refresh(true, null, modalityState); + RefreshQueue.getInstance().refreshLocalRoots(true, null, modalityState); } } diff --git a/platform/platform-impl/src/com/intellij/openapi/fileChooser/actions/RefreshFileChooserAction.java b/platform/platform-impl/src/com/intellij/openapi/fileChooser/actions/RefreshFileChooserAction.java index ee2de9368ebe..ffac802ff771 100644 --- a/platform/platform-impl/src/com/intellij/openapi/fileChooser/actions/RefreshFileChooserAction.java +++ b/platform/platform-impl/src/com/intellij/openapi/fileChooser/actions/RefreshFileChooserAction.java @@ -18,14 +18,14 @@ package com.intellij.openapi.fileChooser.actions; import com.intellij.openapi.actionSystem.AnAction; import com.intellij.openapi.actionSystem.AnActionEvent; import com.intellij.openapi.application.ModalityState; -import com.intellij.openapi.vfs.VirtualFileManager; import com.intellij.openapi.project.DumbAware; +import com.intellij.openapi.vfs.newvfs.RefreshQueue; /** * @author yole */ public class RefreshFileChooserAction extends AnAction implements DumbAware { public void actionPerformed(final AnActionEvent e) { - VirtualFileManager.getInstance().refresh(true, null, ModalityState.current()); + RefreshQueue.getInstance().refreshLocalRoots(true, null, ModalityState.current()); } } \ No newline at end of file diff --git a/platform/platform-impl/src/com/intellij/openapi/vfs/impl/VirtualFileManagerImpl.java b/platform/platform-impl/src/com/intellij/openapi/vfs/impl/VirtualFileManagerImpl.java index 8fbf65ffb83d..3e80699c2d73 100644 --- a/platform/platform-impl/src/com/intellij/openapi/vfs/impl/VirtualFileManagerImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/vfs/impl/VirtualFileManagerImpl.java @@ -118,7 +118,6 @@ public class VirtualFileManagerImpl extends VirtualFileManagerEx { refresh(asynchronous, postAction, ModalityState.NON_MODAL); } - @Override public void refresh(boolean asynchronous, @Nullable Runnable postAction, ModalityState modalityState) { if (!asynchronous) { ApplicationManager.getApplication().assertIsDispatchThread(); diff --git a/platform/platform-impl/src/com/intellij/openapi/vfs/newvfs/RefreshQueueImpl.java b/platform/platform-impl/src/com/intellij/openapi/vfs/newvfs/RefreshQueueImpl.java index 928607c79af8..1540475a9813 100644 --- a/platform/platform-impl/src/com/intellij/openapi/vfs/newvfs/RefreshQueueImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/vfs/newvfs/RefreshQueueImpl.java @@ -97,6 +97,11 @@ public class RefreshQueueImpl extends RefreshQueue { return new RefreshSessionImpl(async, recursively, finishRunnable, state); } + @Override + public void refreshLocalRoots(boolean async, Runnable postAction, ModalityState modalityState) { + RefreshQueue.getInstance().refresh(async, true, postAction, modalityState, ManagingFS.getInstance().getLocalRoots()); + } + public void processSingleEvent(VFileEvent event) { new RefreshSessionImpl(Collections.singletonList(event)).launch(); } diff --git a/platform/testFramework/src/com/intellij/mock/MockVirtualFileManager.java b/platform/testFramework/src/com/intellij/mock/MockVirtualFileManager.java index 006d56698142..88429017e166 100644 --- a/platform/testFramework/src/com/intellij/mock/MockVirtualFileManager.java +++ b/platform/testFramework/src/com/intellij/mock/MockVirtualFileManager.java @@ -16,12 +16,13 @@ package com.intellij.mock; import com.intellij.openapi.Disposable; -import com.intellij.openapi.application.ModalityState; import com.intellij.openapi.util.ModificationTracker; -import com.intellij.openapi.vfs.*; +import com.intellij.openapi.vfs.VirtualFile; +import com.intellij.openapi.vfs.VirtualFileListener; +import com.intellij.openapi.vfs.VirtualFileManagerListener; +import com.intellij.openapi.vfs.VirtualFileSystem; import com.intellij.openapi.vfs.ex.VirtualFileManagerEx; import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; public class MockVirtualFileManager extends VirtualFileManagerEx { public MockVirtualFileManager() { @@ -46,10 +47,6 @@ public class MockVirtualFileManager extends VirtualFileManagerEx { public void refresh(boolean asynchronous, Runnable postAction) { } - @Override - public void refresh(boolean asynchronous, @Nullable Runnable postAction, ModalityState modalityState) { - } - @Override public VirtualFile findFileByUrl(@NotNull String url) { return null; From 900ee038361bdd6945de17d9370de4285833189e Mon Sep 17 00:00:00 2001 From: Dmitry Jemerov Date: Fri, 19 Aug 2011 17:31:06 +0400 Subject: [PATCH 31/78] VirtualFileManagerImpl -> core-impl --- .../vfs/newvfs/CachingVirtualFileSystem.java | 23 ++++++++++++++++ .../vfs/newvfs/FileSystemPersistence.java | 26 +++++++++++++++++++ .../events/VFileContentChangeEvent.java | 0 .../vfs/newvfs/events/VFileCopyEvent.java | 0 .../vfs/newvfs/events/VFileCreateEvent.java | 0 .../vfs/newvfs/events/VFileDeleteEvent.java | 0 .../vfs/newvfs/events/VFileMoveEvent.java | 0 .../openapi/vfs/ex/VirtualFileManagerEx.java | 0 .../impl/BulkVirtualFileListenerAdapter.java | 0 .../vfs/impl/VirtualFileManagerImpl.java | 19 ++++++-------- .../openapi/vfs/newvfs/ManagingFS.java | 2 +- .../vfs/newvfs/NewVirtualFileSystem.java | 2 +- .../vfs/newvfs/persistent/PersistentFS.java | 12 +++++++++ 13 files changed, 71 insertions(+), 13 deletions(-) create mode 100644 platform/core-api/src/com/intellij/openapi/vfs/newvfs/CachingVirtualFileSystem.java create mode 100644 platform/core-api/src/com/intellij/openapi/vfs/newvfs/FileSystemPersistence.java rename platform/{platform-api => core-api}/src/com/intellij/openapi/vfs/newvfs/events/VFileContentChangeEvent.java (100%) rename platform/{platform-api => core-api}/src/com/intellij/openapi/vfs/newvfs/events/VFileCopyEvent.java (100%) rename platform/{platform-api => core-api}/src/com/intellij/openapi/vfs/newvfs/events/VFileCreateEvent.java (100%) rename platform/{platform-api => core-api}/src/com/intellij/openapi/vfs/newvfs/events/VFileDeleteEvent.java (100%) rename platform/{platform-api => core-api}/src/com/intellij/openapi/vfs/newvfs/events/VFileMoveEvent.java (100%) rename platform/{platform-impl => core-impl}/src/com/intellij/openapi/vfs/ex/VirtualFileManagerEx.java (100%) rename platform/{platform-impl => core-impl}/src/com/intellij/openapi/vfs/impl/BulkVirtualFileListenerAdapter.java (100%) rename platform/{platform-impl => core-impl}/src/com/intellij/openapi/vfs/impl/VirtualFileManagerImpl.java (93%) diff --git a/platform/core-api/src/com/intellij/openapi/vfs/newvfs/CachingVirtualFileSystem.java b/platform/core-api/src/com/intellij/openapi/vfs/newvfs/CachingVirtualFileSystem.java new file mode 100644 index 000000000000..6e9173e07e88 --- /dev/null +++ b/platform/core-api/src/com/intellij/openapi/vfs/newvfs/CachingVirtualFileSystem.java @@ -0,0 +1,23 @@ +/* + * Copyright 2000-2011 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.intellij.openapi.vfs.newvfs; + +/** + * @author yole + */ +public interface CachingVirtualFileSystem { + void refreshWithoutFileWatcher(boolean asynchronous); +} diff --git a/platform/core-api/src/com/intellij/openapi/vfs/newvfs/FileSystemPersistence.java b/platform/core-api/src/com/intellij/openapi/vfs/newvfs/FileSystemPersistence.java new file mode 100644 index 000000000000..2819ebb27112 --- /dev/null +++ b/platform/core-api/src/com/intellij/openapi/vfs/newvfs/FileSystemPersistence.java @@ -0,0 +1,26 @@ +/* + * Copyright 2000-2011 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.intellij.openapi.vfs.newvfs; + +import com.intellij.openapi.application.ModalityState; + +/** + * @author yole + */ +public interface FileSystemPersistence { + void refresh(boolean asynchronous, Runnable postAction, ModalityState modalityState); + int getCheapFileSystemModificationCount(); +} diff --git a/platform/platform-api/src/com/intellij/openapi/vfs/newvfs/events/VFileContentChangeEvent.java b/platform/core-api/src/com/intellij/openapi/vfs/newvfs/events/VFileContentChangeEvent.java similarity index 100% rename from platform/platform-api/src/com/intellij/openapi/vfs/newvfs/events/VFileContentChangeEvent.java rename to platform/core-api/src/com/intellij/openapi/vfs/newvfs/events/VFileContentChangeEvent.java diff --git a/platform/platform-api/src/com/intellij/openapi/vfs/newvfs/events/VFileCopyEvent.java b/platform/core-api/src/com/intellij/openapi/vfs/newvfs/events/VFileCopyEvent.java similarity index 100% rename from platform/platform-api/src/com/intellij/openapi/vfs/newvfs/events/VFileCopyEvent.java rename to platform/core-api/src/com/intellij/openapi/vfs/newvfs/events/VFileCopyEvent.java diff --git a/platform/platform-api/src/com/intellij/openapi/vfs/newvfs/events/VFileCreateEvent.java b/platform/core-api/src/com/intellij/openapi/vfs/newvfs/events/VFileCreateEvent.java similarity index 100% rename from platform/platform-api/src/com/intellij/openapi/vfs/newvfs/events/VFileCreateEvent.java rename to platform/core-api/src/com/intellij/openapi/vfs/newvfs/events/VFileCreateEvent.java diff --git a/platform/platform-api/src/com/intellij/openapi/vfs/newvfs/events/VFileDeleteEvent.java b/platform/core-api/src/com/intellij/openapi/vfs/newvfs/events/VFileDeleteEvent.java similarity index 100% rename from platform/platform-api/src/com/intellij/openapi/vfs/newvfs/events/VFileDeleteEvent.java rename to platform/core-api/src/com/intellij/openapi/vfs/newvfs/events/VFileDeleteEvent.java diff --git a/platform/platform-api/src/com/intellij/openapi/vfs/newvfs/events/VFileMoveEvent.java b/platform/core-api/src/com/intellij/openapi/vfs/newvfs/events/VFileMoveEvent.java similarity index 100% rename from platform/platform-api/src/com/intellij/openapi/vfs/newvfs/events/VFileMoveEvent.java rename to platform/core-api/src/com/intellij/openapi/vfs/newvfs/events/VFileMoveEvent.java diff --git a/platform/platform-impl/src/com/intellij/openapi/vfs/ex/VirtualFileManagerEx.java b/platform/core-impl/src/com/intellij/openapi/vfs/ex/VirtualFileManagerEx.java similarity index 100% rename from platform/platform-impl/src/com/intellij/openapi/vfs/ex/VirtualFileManagerEx.java rename to platform/core-impl/src/com/intellij/openapi/vfs/ex/VirtualFileManagerEx.java diff --git a/platform/platform-impl/src/com/intellij/openapi/vfs/impl/BulkVirtualFileListenerAdapter.java b/platform/core-impl/src/com/intellij/openapi/vfs/impl/BulkVirtualFileListenerAdapter.java similarity index 100% rename from platform/platform-impl/src/com/intellij/openapi/vfs/impl/BulkVirtualFileListenerAdapter.java rename to platform/core-impl/src/com/intellij/openapi/vfs/impl/BulkVirtualFileListenerAdapter.java diff --git a/platform/platform-impl/src/com/intellij/openapi/vfs/impl/VirtualFileManagerImpl.java b/platform/core-impl/src/com/intellij/openapi/vfs/impl/VirtualFileManagerImpl.java similarity index 93% rename from platform/platform-impl/src/com/intellij/openapi/vfs/impl/VirtualFileManagerImpl.java rename to platform/core-impl/src/com/intellij/openapi/vfs/impl/VirtualFileManagerImpl.java index 3e80699c2d73..4b35483ed32e 100644 --- a/platform/platform-impl/src/com/intellij/openapi/vfs/impl/VirtualFileManagerImpl.java +++ b/platform/core-impl/src/com/intellij/openapi/vfs/impl/VirtualFileManagerImpl.java @@ -24,10 +24,7 @@ import com.intellij.openapi.util.Disposer; import com.intellij.openapi.util.KeyedExtensionCollector; import com.intellij.openapi.vfs.*; import com.intellij.openapi.vfs.ex.VirtualFileManagerEx; -import com.intellij.openapi.vfs.newvfs.BulkFileListener; -import com.intellij.openapi.vfs.newvfs.ManagingFS; -import com.intellij.openapi.vfs.newvfs.NewVirtualFileSystem; -import com.intellij.openapi.vfs.newvfs.RefreshQueue; +import com.intellij.openapi.vfs.newvfs.*; import com.intellij.openapi.vfs.newvfs.events.VFilePropertyChangeEvent; import com.intellij.util.EventDispatcher; import com.intellij.util.containers.ContainerUtil; @@ -57,9 +54,9 @@ public class VirtualFileManagerImpl extends VirtualFileManagerEx { private final List myVirtualFileManagerListeners = ContainerUtil.createEmptyCOWList(); private int myRefreshCount = 0; - private final ManagingFS myPersistence; + private final FileSystemPersistence myPersistence; - public VirtualFileManagerImpl(VirtualFileSystem[] fileSystems, MessageBus bus, ManagingFS persistence) { + public VirtualFileManagerImpl(VirtualFileSystem[] fileSystems, MessageBus bus, FileSystemPersistence persistence) { myPersistence = persistence; for (VirtualFileSystem fileSystem : fileSystems) { registerFileSystem(fileSystem); @@ -74,7 +71,7 @@ public class VirtualFileManagerImpl extends VirtualFileManagerEx { public void registerFileSystem(VirtualFileSystem fileSystem) { myCollector.addExplicitExtension(fileSystem.getProtocol(), fileSystem); - if (!(fileSystem instanceof NewVirtualFileSystem)) { + if (!(fileSystem instanceof CachingVirtualFileSystem)) { fileSystem.addVirtualFileListener(myVirtualFileListenerMulticaster.getMulticaster()); } myPhysicalFileSystems.add(fileSystem); @@ -105,8 +102,8 @@ public class VirtualFileManagerImpl extends VirtualFileManagerEx { } for (VirtualFileSystem fileSystem : getPhysicalFileSystems()) { - if (fileSystem instanceof NewVirtualFileSystem) { - ((NewVirtualFileSystem)fileSystem).refreshWithoutFileWatcher(asynchronous); + if (fileSystem instanceof CachingVirtualFileSystem) { + ((CachingVirtualFileSystem)fileSystem).refreshWithoutFileWatcher(asynchronous); } else { fileSystem.refresh(asynchronous); @@ -123,7 +120,7 @@ public class VirtualFileManagerImpl extends VirtualFileManagerEx { ApplicationManager.getApplication().assertIsDispatchThread(); } - RefreshQueue.getInstance().refresh(asynchronous, true, postAction, modalityState, myPersistence.getLocalRoots()); // TODO: Get an idea how to deliver chnages from local FS to jar fs before they go refresh + myPersistence.refresh(asynchronous, postAction, modalityState); //final VirtualFile[] managedRoots = ManagingFS.getInstance().getRoots(); //for (int i = 0; i < managedRoots.length; i++) { @@ -133,7 +130,7 @@ public class VirtualFileManagerImpl extends VirtualFileManagerEx { //} for (VirtualFileSystem fileSystem : getPhysicalFileSystems()) { - if (!(fileSystem instanceof NewVirtualFileSystem)) { + if (!(fileSystem instanceof CachingVirtualFileSystem)) { fileSystem.refresh(asynchronous); } } diff --git a/platform/platform-api/src/com/intellij/openapi/vfs/newvfs/ManagingFS.java b/platform/platform-api/src/com/intellij/openapi/vfs/newvfs/ManagingFS.java index c84cb7e9e955..639d9309b607 100644 --- a/platform/platform-api/src/com/intellij/openapi/vfs/newvfs/ManagingFS.java +++ b/platform/platform-api/src/com/intellij/openapi/vfs/newvfs/ManagingFS.java @@ -29,7 +29,7 @@ import java.io.DataInputStream; import java.io.DataOutputStream; import java.util.List; -public abstract class ManagingFS implements FileSystemInterface { +public abstract class ManagingFS implements FileSystemInterface, FileSystemPersistence { private static class ManagingFSHolder { private static final ManagingFS ourInstance = ApplicationManager.getApplication().getComponent(ManagingFS.class); } diff --git a/platform/platform-api/src/com/intellij/openapi/vfs/newvfs/NewVirtualFileSystem.java b/platform/platform-api/src/com/intellij/openapi/vfs/newvfs/NewVirtualFileSystem.java index 958001c71769..cfaa0664bab3 100644 --- a/platform/platform-api/src/com/intellij/openapi/vfs/newvfs/NewVirtualFileSystem.java +++ b/platform/platform-api/src/com/intellij/openapi/vfs/newvfs/NewVirtualFileSystem.java @@ -31,7 +31,7 @@ import java.io.IOException; import java.util.HashMap; import java.util.Map; -public abstract class NewVirtualFileSystem extends VirtualFileSystem implements FileSystemInterface { +public abstract class NewVirtualFileSystem extends VirtualFileSystem implements FileSystemInterface, CachingVirtualFileSystem { private final Map myListenerWrappers = new HashMap(); public abstract boolean isCaseSensitive(); diff --git a/platform/platform-impl/src/com/intellij/openapi/vfs/newvfs/persistent/PersistentFS.java b/platform/platform-impl/src/com/intellij/openapi/vfs/newvfs/persistent/PersistentFS.java index 1ba65d511e62..23301ecff9fd 100644 --- a/platform/platform-impl/src/com/intellij/openapi/vfs/newvfs/persistent/PersistentFS.java +++ b/platform/platform-impl/src/com/intellij/openapi/vfs/newvfs/persistent/PersistentFS.java @@ -20,6 +20,7 @@ package com.intellij.openapi.vfs.newvfs.persistent; import com.intellij.openapi.application.ApplicationManager; +import com.intellij.openapi.application.ModalityState; import com.intellij.openapi.application.ex.ApplicationEx; import com.intellij.openapi.components.ApplicationComponent; import com.intellij.openapi.diagnostic.Logger; @@ -726,6 +727,17 @@ public class PersistentFS extends ManagingFS implements ApplicationComponent { RefreshQueue.getInstance().refresh(asynchronous, true, null, roots); } + @Override + public void refresh(boolean asynchronous, Runnable postAction, ModalityState modalityState) { + final NewVirtualFile[] roots; + synchronized (LOCK) { + Collection values = myRoots.values(); + roots = values.toArray(new NewVirtualFile[values.size()]); + } + + RefreshQueue.getInstance().refresh(asynchronous, true, postAction, modalityState, roots); + } + @NotNull public VirtualFile[] getLocalRoots() { List roots; From aa19acec636f1131900701be793bdeb6c64ea866 Mon Sep 17 00:00:00 2001 From: Dmitry Jemerov Date: Fri, 19 Aug 2011 18:44:44 +0400 Subject: [PATCH 32/78] extract FileTypeRegistry interface; move the big FileTypeManager back to platform-api --- .../src/com/intellij/lang/Language.java | 4 +- .../openapi/fileTypes/FileTypeRegistry.java | 47 +++++++++++++++++++ .../com/intellij/openapi/vfs/VirtualFile.java | 4 +- .../fileTypes/ExactFileNameMatcher.java | 0 .../fileTypes/ExtensionFileNameMatcher.java | 0 .../openapi/fileTypes/FileNameMatcher.java | 0 .../openapi/fileTypes/FileTypeEvent.java | 0 .../openapi/fileTypes/FileTypeListener.java | 0 .../openapi/fileTypes/FileTypeManager.java | 29 +++++------- .../intellij/openapi/fileTypes/FileTypes.java | 0 .../fileTypes/MockFileTypeManager.java | 0 .../fileTypes/MockLanguageFileType.java | 0 .../openapi/fileTypes/UnknownFileType.java | 0 .../fileTypes/WildcardFileNameMatcher.java | 0 14 files changed, 62 insertions(+), 22 deletions(-) create mode 100644 platform/core-api/src/com/intellij/openapi/fileTypes/FileTypeRegistry.java rename platform/{core-api => platform-api}/src/com/intellij/openapi/fileTypes/ExactFileNameMatcher.java (100%) rename platform/{core-api => platform-api}/src/com/intellij/openapi/fileTypes/ExtensionFileNameMatcher.java (100%) rename platform/{core-api => platform-api}/src/com/intellij/openapi/fileTypes/FileNameMatcher.java (100%) rename platform/{core-api => platform-api}/src/com/intellij/openapi/fileTypes/FileTypeEvent.java (100%) rename platform/{core-api => platform-api}/src/com/intellij/openapi/fileTypes/FileTypeListener.java (100%) rename platform/{core-api => platform-api}/src/com/intellij/openapi/fileTypes/FileTypeManager.java (94%) rename platform/{core-api => platform-api}/src/com/intellij/openapi/fileTypes/FileTypes.java (100%) rename platform/{core-api => platform-api}/src/com/intellij/openapi/fileTypes/MockFileTypeManager.java (100%) rename platform/{core-api => platform-api}/src/com/intellij/openapi/fileTypes/MockLanguageFileType.java (100%) rename platform/{core-api => platform-api}/src/com/intellij/openapi/fileTypes/UnknownFileType.java (100%) rename platform/{core-api => platform-api}/src/com/intellij/openapi/fileTypes/WildcardFileNameMatcher.java (100%) diff --git a/platform/core-api/src/com/intellij/lang/Language.java b/platform/core-api/src/com/intellij/lang/Language.java index 58c0241d2569..985004a5e1b8 100644 --- a/platform/core-api/src/com/intellij/lang/Language.java +++ b/platform/core-api/src/com/intellij/lang/Language.java @@ -17,7 +17,7 @@ package com.intellij.lang; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.fileTypes.FileType; -import com.intellij.openapi.fileTypes.FileTypeManager; +import com.intellij.openapi.fileTypes.FileTypeRegistry; import com.intellij.openapi.fileTypes.LanguageFileType; import com.intellij.openapi.util.UserDataHolderBase; import com.intellij.util.ArrayUtil; @@ -126,7 +126,7 @@ public abstract class Language extends UserDataHolderBase { @Nullable public LanguageFileType getAssociatedFileType() { - final FileType[] types = FileTypeManager.getInstance().getRegisteredFileTypes(); + final FileType[] types = FileTypeRegistry.getInstance().getRegisteredFileTypes(); for (final FileType fileType : types) { if (fileType instanceof LanguageFileType && ((LanguageFileType)fileType).getLanguage() == this) { return (LanguageFileType)fileType; diff --git a/platform/core-api/src/com/intellij/openapi/fileTypes/FileTypeRegistry.java b/platform/core-api/src/com/intellij/openapi/fileTypes/FileTypeRegistry.java new file mode 100644 index 000000000000..ef80b947f1c3 --- /dev/null +++ b/platform/core-api/src/com/intellij/openapi/fileTypes/FileTypeRegistry.java @@ -0,0 +1,47 @@ +/* + * Copyright 2000-2011 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.intellij.openapi.fileTypes; + +import com.intellij.openapi.util.Getter; +import com.intellij.openapi.vfs.VirtualFile; +import org.jetbrains.annotations.NotNull; + +/** + * @author yole + */ +public abstract class FileTypeRegistry { + public static Getter ourInstanceGetter; + + public static FileTypeRegistry getInstance() { + return ourInstanceGetter.get(); + } + + /** + * Returns the list of all registered file types. + * + * @return The list of file types. + */ + public abstract FileType[] getRegisteredFileTypes(); + + /** + * Returns the file type for the specified file. + * + * @param file The file for which the type is requested. + * @return The file type instance. + */ + @NotNull + public abstract FileType getFileTypeByFile(@NotNull VirtualFile file); +} diff --git a/platform/core-api/src/com/intellij/openapi/vfs/VirtualFile.java b/platform/core-api/src/com/intellij/openapi/vfs/VirtualFile.java index 3f00356c99b6..7388140e6dc2 100644 --- a/platform/core-api/src/com/intellij/openapi/vfs/VirtualFile.java +++ b/platform/core-api/src/com/intellij/openapi/vfs/VirtualFile.java @@ -17,7 +17,7 @@ package com.intellij.openapi.vfs; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.fileTypes.FileType; -import com.intellij.openapi.fileTypes.FileTypeManager; +import com.intellij.openapi.fileTypes.FileTypeRegistry; import com.intellij.openapi.util.*; import com.intellij.openapi.util.text.StringUtil; import com.intellij.openapi.vfs.encoding.EncodingManager; @@ -261,7 +261,7 @@ public abstract class VirtualFile extends UserDataHolderBase implements Modifica */ @NotNull public FileType getFileType() { - return FileTypeManager.getInstance().getFileTypeByFile(this); + return FileTypeRegistry.getInstance().getFileTypeByFile(this); } /** diff --git a/platform/core-api/src/com/intellij/openapi/fileTypes/ExactFileNameMatcher.java b/platform/platform-api/src/com/intellij/openapi/fileTypes/ExactFileNameMatcher.java similarity index 100% rename from platform/core-api/src/com/intellij/openapi/fileTypes/ExactFileNameMatcher.java rename to platform/platform-api/src/com/intellij/openapi/fileTypes/ExactFileNameMatcher.java diff --git a/platform/core-api/src/com/intellij/openapi/fileTypes/ExtensionFileNameMatcher.java b/platform/platform-api/src/com/intellij/openapi/fileTypes/ExtensionFileNameMatcher.java similarity index 100% rename from platform/core-api/src/com/intellij/openapi/fileTypes/ExtensionFileNameMatcher.java rename to platform/platform-api/src/com/intellij/openapi/fileTypes/ExtensionFileNameMatcher.java diff --git a/platform/core-api/src/com/intellij/openapi/fileTypes/FileNameMatcher.java b/platform/platform-api/src/com/intellij/openapi/fileTypes/FileNameMatcher.java similarity index 100% rename from platform/core-api/src/com/intellij/openapi/fileTypes/FileNameMatcher.java rename to platform/platform-api/src/com/intellij/openapi/fileTypes/FileNameMatcher.java diff --git a/platform/core-api/src/com/intellij/openapi/fileTypes/FileTypeEvent.java b/platform/platform-api/src/com/intellij/openapi/fileTypes/FileTypeEvent.java similarity index 100% rename from platform/core-api/src/com/intellij/openapi/fileTypes/FileTypeEvent.java rename to platform/platform-api/src/com/intellij/openapi/fileTypes/FileTypeEvent.java diff --git a/platform/core-api/src/com/intellij/openapi/fileTypes/FileTypeListener.java b/platform/platform-api/src/com/intellij/openapi/fileTypes/FileTypeListener.java similarity index 100% rename from platform/core-api/src/com/intellij/openapi/fileTypes/FileTypeListener.java rename to platform/platform-api/src/com/intellij/openapi/fileTypes/FileTypeListener.java diff --git a/platform/core-api/src/com/intellij/openapi/fileTypes/FileTypeManager.java b/platform/platform-api/src/com/intellij/openapi/fileTypes/FileTypeManager.java similarity index 94% rename from platform/core-api/src/com/intellij/openapi/fileTypes/FileTypeManager.java rename to platform/platform-api/src/com/intellij/openapi/fileTypes/FileTypeManager.java index e8b98ff595a7..e5ffd641e1cf 100644 --- a/platform/core-api/src/com/intellij/openapi/fileTypes/FileTypeManager.java +++ b/platform/platform-api/src/com/intellij/openapi/fileTypes/FileTypeManager.java @@ -17,6 +17,7 @@ package com.intellij.openapi.fileTypes; import com.intellij.openapi.application.ApplicationComponentLocator; import com.intellij.openapi.application.CachedSingletonsRegistry; +import com.intellij.openapi.util.Getter; import com.intellij.openapi.vfs.VirtualFile; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; @@ -29,7 +30,16 @@ import java.util.List; * Manages the relationship between filenames and {@link FileType} instances. */ -public abstract class FileTypeManager{ +public abstract class FileTypeManager extends FileTypeRegistry { + static { + FileTypeRegistry.ourInstanceGetter = new Getter() { + @Override + public FileTypeRegistry get() { + return FileTypeManager.getInstance(); + } + }; + } + private static FileTypeManager ourInstance = CachedSingletonsRegistry.markCachedField(FileTypeManager.class); /** * Returns the singleton instance of the FileTypeManager component. @@ -75,15 +85,6 @@ public abstract class FileTypeManager{ @NotNull public abstract FileType getFileTypeByFileName(@NotNull @NonNls String fileName); - /** - * Returns the file type for the specified file. - * - * @param file The file for which the type is requested. - * @return The file type instance. - */ - @NotNull - public abstract FileType getFileTypeByFile(@NotNull VirtualFile file); - /** * Returns the file type for the specified extension. * Note that a more general way of obtaining file type is with {@link #getFileTypeByFile(VirtualFile)} @@ -94,14 +95,6 @@ public abstract class FileTypeManager{ @NotNull public abstract FileType getFileTypeByExtension(@NonNls @NotNull String extension); - /** - * Returns the list of all registered file types. - * - * @return The list of file types. - */ - @NotNull - public abstract FileType[] getRegisteredFileTypes(); - /** * Checks if the specified file is ignored by IDEA. Ignored files are not visible in * different project views and cannot be opened in the editor. They will neither be parsed nor compiled. diff --git a/platform/core-api/src/com/intellij/openapi/fileTypes/FileTypes.java b/platform/platform-api/src/com/intellij/openapi/fileTypes/FileTypes.java similarity index 100% rename from platform/core-api/src/com/intellij/openapi/fileTypes/FileTypes.java rename to platform/platform-api/src/com/intellij/openapi/fileTypes/FileTypes.java diff --git a/platform/core-api/src/com/intellij/openapi/fileTypes/MockFileTypeManager.java b/platform/platform-api/src/com/intellij/openapi/fileTypes/MockFileTypeManager.java similarity index 100% rename from platform/core-api/src/com/intellij/openapi/fileTypes/MockFileTypeManager.java rename to platform/platform-api/src/com/intellij/openapi/fileTypes/MockFileTypeManager.java diff --git a/platform/core-api/src/com/intellij/openapi/fileTypes/MockLanguageFileType.java b/platform/platform-api/src/com/intellij/openapi/fileTypes/MockLanguageFileType.java similarity index 100% rename from platform/core-api/src/com/intellij/openapi/fileTypes/MockLanguageFileType.java rename to platform/platform-api/src/com/intellij/openapi/fileTypes/MockLanguageFileType.java diff --git a/platform/core-api/src/com/intellij/openapi/fileTypes/UnknownFileType.java b/platform/platform-api/src/com/intellij/openapi/fileTypes/UnknownFileType.java similarity index 100% rename from platform/core-api/src/com/intellij/openapi/fileTypes/UnknownFileType.java rename to platform/platform-api/src/com/intellij/openapi/fileTypes/UnknownFileType.java diff --git a/platform/core-api/src/com/intellij/openapi/fileTypes/WildcardFileNameMatcher.java b/platform/platform-api/src/com/intellij/openapi/fileTypes/WildcardFileNameMatcher.java similarity index 100% rename from platform/core-api/src/com/intellij/openapi/fileTypes/WildcardFileNameMatcher.java rename to platform/platform-api/src/com/intellij/openapi/fileTypes/WildcardFileNameMatcher.java From 3a1e8b347804636abdd021f5d3ebc751c6c44919 Mon Sep 17 00:00:00 2001 From: Dmitry Jemerov Date: Fri, 19 Aug 2011 19:21:17 +0400 Subject: [PATCH 33/78] decouple PsiSearchHelper from PsiManager --- .../ChangedConstantsDependencyProcessor.java | 2 +- .../daemon/impl/PostHighlightingPass.java | 4 ++-- .../deadCode/UnusedDeclarationInspection.java | 2 +- .../UnusedParametersInspection.java | 2 +- .../visibility/VisibilityInspection.java | 3 ++- .../find/findUsages/JavaFindUsagesDialog.java | 9 ++------- .../java/JavaRefactoringSupportProvider.java | 3 ++- .../impl/search/AnnotatedPackagesSearcher.java | 2 +- .../refactoring/inline/InlineMethodDialog.java | 3 +-- .../TurnRefsToSuperProcessorBase.java | 2 +- .../deductive/builder/SystemBuilder.java | 4 ++-- .../src/com/intellij/psi/PsiManager.java | 11 ----------- .../com/intellij/psi/search/PsiSearchHelper.java | 11 +++++++++++ .../intellij/psi/search/SearchRequestQuery.java | 3 +-- .../psi/search/searches/ReferencesSearch.java | 2 +- .../daemon/impl/GeneralHighlightingPass.java | 3 +-- .../find/findUsages/CommonFindUsagesDialog.java | 3 ++- .../find/findUsages/FindUsagesManager.java | 16 +++++++--------- .../com/intellij/ide/todo/TodoTreeBuilder.java | 2 +- .../com/intellij/ide/todo/TodoTreeStructure.java | 4 +--- .../vcs/checkin/TodoCheckinHandlerWorker.java | 2 +- .../com/intellij/psi/impl/PsiManagerImpl.java | 9 --------- .../rename/inplace/VariableInplaceRenamer.java | 3 ++- .../refactoring/util/TextOccurrencesUtil.java | 10 ++++------ .../src/META-INF/LangExtensions.xml | 3 +++ .../DeclareCollectionAsInterfaceInspection.java | 3 +-- ...StaticMethodOnlyUsedInOneClassInspection.java | 3 +-- .../src/com/siyeh/ig/maturity/TodoUtil.java | 4 +--- .../AnnotationBasedInstrumentingCompiler.java | 2 +- .../GrAliasedImportedElementSearcher.java | 2 +- .../GroovyConstructorUsagesSearcher.java | 2 +- .../DuplicateStringLiteralInspection.java | 2 +- .../DuplicatePropertyInspection.java | 2 +- .../properties/UnusedPropertyInspection.java | 7 ++----- .../inspection/UndeclaredTestInspection.java | 5 +++-- 35 files changed, 64 insertions(+), 86 deletions(-) diff --git a/java/compiler/impl/src/com/intellij/compiler/make/ChangedConstantsDependencyProcessor.java b/java/compiler/impl/src/com/intellij/compiler/make/ChangedConstantsDependencyProcessor.java index e4102a9899f5..40208f5479c3 100644 --- a/java/compiler/impl/src/com/intellij/compiler/make/ChangedConstantsDependencyProcessor.java +++ b/java/compiler/impl/src/com/intellij/compiler/make/ChangedConstantsDependencyProcessor.java @@ -117,7 +117,7 @@ class ChangedConstantsDependencyProcessor { } } } - final PsiSearchHelper psiSearchHelper = PsiManager.getInstance(myProject).getSearchHelper(); + final PsiSearchHelper psiSearchHelper = PsiSearchHelper.SERVICE.getInstance(myProject); final Ref exRef = new Ref(null); final long analysisStart = System.currentTimeMillis(); diff --git a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/PostHighlightingPass.java b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/PostHighlightingPass.java index daae8d4790d3..cba0bea1b967 100644 --- a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/PostHighlightingPass.java +++ b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/PostHighlightingPass.java @@ -537,8 +537,8 @@ public class PostHighlightingPass extends TextEditorHighlightingPass { // some classes may have references from within XML outside dependent modules, e.g. our actions if (member instanceof PsiClass) scope = scope.uniteWith(GlobalSearchScope.projectScope(myProject)); - PsiSearchHelper.SearchCostResult cheapEnough = myFile.getManager().getSearchHelper().isCheapEnoughToSearch(name, scope, myFile, - progress); + PsiSearchHelper.SearchCostResult cheapEnough = PsiSearchHelper.SERVICE.getInstance(myFile.getProject()) + .isCheapEnoughToSearch(name, scope, myFile, progress); if (cheapEnough == PsiSearchHelper.SearchCostResult.TOO_MANY_OCCURRENCES) return false; //search usages if it cheap diff --git a/java/java-impl/src/com/intellij/codeInspection/deadCode/UnusedDeclarationInspection.java b/java/java-impl/src/com/intellij/codeInspection/deadCode/UnusedDeclarationInspection.java index 99d57299d621..ae14ce322e96 100644 --- a/java/java-impl/src/com/intellij/codeInspection/deadCode/UnusedDeclarationInspection.java +++ b/java/java-impl/src/com/intellij/codeInspection/deadCode/UnusedDeclarationInspection.java @@ -388,7 +388,7 @@ public class UnusedDeclarationInspection extends FilteringInspectionTool { ProgressManager.getInstance().runProcess(new Runnable() { public void run() { final RefFilter filter = new StrictUnreferencedFilter(UnusedDeclarationInspection.this); - final PsiSearchHelper helper = PsiManager.getInstance(getRefManager().getProject()).getSearchHelper(); + final PsiSearchHelper helper = PsiSearchHelper.SERVICE.getInstance(getRefManager().getProject()); getRefManager().iterate(new RefJavaVisitor() { @Override public void visitElement(final RefEntity refEntity) { if (refEntity instanceof RefClass && filter.accepts((RefClass)refEntity)) { diff --git a/java/java-impl/src/com/intellij/codeInspection/unusedParameters/UnusedParametersInspection.java b/java/java-impl/src/com/intellij/codeInspection/unusedParameters/UnusedParametersInspection.java index 4ece89ad7fd4..2a3b771ff4e5 100644 --- a/java/java-impl/src/com/intellij/codeInspection/unusedParameters/UnusedParametersInspection.java +++ b/java/java-impl/src/com/intellij/codeInspection/unusedParameters/UnusedParametersInspection.java @@ -102,7 +102,7 @@ public class UnusedParametersInspection extends GlobalJavaInspectionTool { processor.ignoreElement(entryPoint); } - final PsiSearchHelper helper = PsiManager.getInstance(project).getSearchHelper(); + final PsiSearchHelper helper = PsiSearchHelper.SERVICE.getInstance(project); final AnalysisScope scope = manager.getScope(); manager.iterate(new RefJavaVisitor() { @Override public void visitElement(RefEntity refEntity) { diff --git a/java/java-impl/src/com/intellij/codeInspection/visibility/VisibilityInspection.java b/java/java-impl/src/com/intellij/codeInspection/visibility/VisibilityInspection.java index 197f1405d280..4916e6c548b8 100644 --- a/java/java-impl/src/com/intellij/codeInspection/visibility/VisibilityInspection.java +++ b/java/java-impl/src/com/intellij/codeInspection/visibility/VisibilityInspection.java @@ -39,6 +39,7 @@ import com.intellij.openapi.project.Project; import com.intellij.psi.*; import com.intellij.psi.search.GlobalSearchScope; import com.intellij.psi.search.PsiNonJavaFileReferenceProcessor; +import com.intellij.psi.search.PsiSearchHelper; import com.intellij.psi.util.PsiTreeUtil; import com.intellij.psi.util.PsiUtil; import com.intellij.util.IncorrectOperationException; @@ -418,7 +419,7 @@ public class VisibilityInspection extends GlobalJavaInspectionTool { String qualifiedName = ownerClass.getElement().getQualifiedName(); if (qualifiedName != null) { final Project project = manager.getProject(); - PsiManager.getInstance(project).getSearchHelper() + PsiSearchHelper.SERVICE.getInstance(project) .processUsagesInNonJavaFiles(qualifiedName, new PsiNonJavaFileReferenceProcessor() { public boolean process(PsiFile file, int startOffset, int endOffset) { entryPointsManager.addEntryPoint(refMethod, false); diff --git a/java/java-impl/src/com/intellij/find/findUsages/JavaFindUsagesDialog.java b/java/java-impl/src/com/intellij/find/findUsages/JavaFindUsagesDialog.java index 87c6e4269acf..ba7821fad54f 100644 --- a/java/java-impl/src/com/intellij/find/findUsages/JavaFindUsagesDialog.java +++ b/java/java-impl/src/com/intellij/find/findUsages/JavaFindUsagesDialog.java @@ -21,12 +21,11 @@ import com.intellij.openapi.help.HelpManager; import com.intellij.openapi.project.Project; import com.intellij.openapi.util.text.StringUtil; import com.intellij.psi.PsiElement; -import com.intellij.psi.PsiManager; import com.intellij.psi.PsiMethod; import com.intellij.psi.search.LocalSearchScope; +import com.intellij.psi.search.PsiSearchHelper; import com.intellij.psi.util.MethodSignatureUtil; import com.intellij.ui.SimpleColoredComponent; -import com.intellij.ui.SimpleTextAttributes; import com.intellij.ui.StateRestoringCheckBox; import com.intellij.usageView.UsageViewUtil; @@ -83,13 +82,9 @@ public abstract class JavaFindUsagesDialog exte } } - private PsiManager getPsiManager() { - return myPsiElement.getManager(); - } - protected boolean isInFileOnly() { return super.isInFileOnly() || - myPsiElement != null && getPsiManager().getSearchHelper().getUseScope(myPsiElement)instanceof LocalSearchScope; + myPsiElement != null && PsiSearchHelper.SERVICE.getInstance(myPsiElement.getProject()).getUseScope(myPsiElement)instanceof LocalSearchScope; } public void configureLabelComponent(final SimpleColoredComponent coloredComponent) { diff --git a/java/java-impl/src/com/intellij/lang/java/JavaRefactoringSupportProvider.java b/java/java-impl/src/com/intellij/lang/java/JavaRefactoringSupportProvider.java index 2d09340a48f2..e4a665901380 100644 --- a/java/java-impl/src/com/intellij/lang/java/JavaRefactoringSupportProvider.java +++ b/java/java-impl/src/com/intellij/lang/java/JavaRefactoringSupportProvider.java @@ -19,6 +19,7 @@ import com.intellij.lang.refactoring.RefactoringSupportProvider; import com.intellij.psi.*; import com.intellij.psi.javadoc.PsiDocComment; import com.intellij.psi.search.LocalSearchScope; +import com.intellij.psi.search.PsiSearchHelper; import com.intellij.psi.search.SearchScope; import com.intellij.psi.util.PsiTreeUtil; import com.intellij.refactoring.RefactoringActionHandler; @@ -107,7 +108,7 @@ public class JavaRefactoringSupportProvider extends RefactoringSupportProvider { public static boolean mayRenameInplace(PsiElement elementToRename, final PsiElement nameSuggestionContext) { if (nameSuggestionContext != null && nameSuggestionContext.getContainingFile() != elementToRename.getContainingFile()) return false; if (!(elementToRename instanceof PsiLocalVariable) && !(elementToRename instanceof PsiParameter) && !(elementToRename instanceof PsiTypeParameter)) return false; - SearchScope useScope = elementToRename.getManager().getSearchHelper().getUseScope(elementToRename); + SearchScope useScope = PsiSearchHelper.SERVICE.getInstance(elementToRename.getProject()).getUseScope(elementToRename); if (!(useScope instanceof LocalSearchScope)) return false; PsiElement[] scopeElements = ((LocalSearchScope) useScope).getScope(); if (scopeElements.length > 1 && // assume there are no elements with use scopes with holes in them diff --git a/java/java-impl/src/com/intellij/psi/impl/search/AnnotatedPackagesSearcher.java b/java/java-impl/src/com/intellij/psi/impl/search/AnnotatedPackagesSearcher.java index cd900f6ab940..0ae95821760a 100644 --- a/java/java-impl/src/com/intellij/psi/impl/search/AnnotatedPackagesSearcher.java +++ b/java/java-impl/src/com/intellij/psi/impl/search/AnnotatedPackagesSearcher.java @@ -79,7 +79,7 @@ public class AnnotatedPackagesSearcher implements QueryExecutor victims) { - final PsiSearchHelper helper = myManager.getSearchHelper(); + final PsiSearchHelper helper = PsiSearchHelper.SERVICE.getInstance(myManager.getProject()); ReductionSystem system = new ReductionSystem(myProject, victims, myTypes, myTypeVariableFactory, mySettings); diff --git a/platform/lang-api/src/com/intellij/psi/PsiManager.java b/platform/lang-api/src/com/intellij/psi/PsiManager.java index b1e6562a0539..f63dbae7ed83 100644 --- a/platform/lang-api/src/com/intellij/psi/PsiManager.java +++ b/platform/lang-api/src/com/intellij/psi/PsiManager.java @@ -20,7 +20,6 @@ import com.intellij.openapi.project.Project; import com.intellij.openapi.util.Computable; import com.intellij.openapi.util.UserDataHolderBase; import com.intellij.openapi.vfs.VirtualFile; -import com.intellij.psi.search.PsiSearchHelper; import com.intellij.psi.util.CachedValuesManager; import com.intellij.psi.util.PsiModificationTracker; import com.intellij.util.IncorrectOperationException; @@ -113,16 +112,6 @@ public abstract class PsiManager extends UserDataHolderBase { */ public abstract void removePsiTreeChangeListener(@NotNull PsiTreeChangeListener listener); - /** - * Returns the search helper for the project, which provides low-level search and - * find usages functionality. It can be used to perform operations like finding references - * to an element, finding overriding / inheriting elements, finding to do items and so on. - * - * @return the search helper instance. - */ - @NotNull - public abstract PsiSearchHelper getSearchHelper(); - /** * Returns the modification tracker for the project, which can be used to get the PSI * modification count value. diff --git a/platform/lang-api/src/com/intellij/psi/search/PsiSearchHelper.java b/platform/lang-api/src/com/intellij/psi/search/PsiSearchHelper.java index 6f1f76fbf5fb..99081da94114 100644 --- a/platform/lang-api/src/com/intellij/psi/search/PsiSearchHelper.java +++ b/platform/lang-api/src/com/intellij/psi/search/PsiSearchHelper.java @@ -15,7 +15,9 @@ */ package com.intellij.psi.search; +import com.intellij.openapi.components.ServiceManager; import com.intellij.openapi.progress.ProgressIndicator; +import com.intellij.openapi.project.Project; import com.intellij.psi.PsiElement; import com.intellij.psi.PsiFile; import com.intellij.psi.PsiReference; @@ -30,6 +32,15 @@ import org.jetbrains.annotations.Nullable; * @see com.intellij.psi.PsiManager#getSearchHelper() */ public interface PsiSearchHelper extends PsiTodoSearchHelper { + class SERVICE { + private SERVICE() { + } + + public static PsiSearchHelper getInstance(Project project) { + return ServiceManager.getService(project, PsiSearchHelper.class); + } + } + /** * Searches the specified scope for comments containing the specified identifier. * diff --git a/platform/lang-api/src/com/intellij/psi/search/SearchRequestQuery.java b/platform/lang-api/src/com/intellij/psi/search/SearchRequestQuery.java index d9f6a09dda00..b9f31565a372 100644 --- a/platform/lang-api/src/com/intellij/psi/search/SearchRequestQuery.java +++ b/platform/lang-api/src/com/intellij/psi/search/SearchRequestQuery.java @@ -1,7 +1,6 @@ package com.intellij.psi.search; import com.intellij.openapi.project.Project; -import com.intellij.psi.PsiManager; import com.intellij.psi.PsiReference; import com.intellij.util.AbstractQuery; import com.intellij.util.Processor; @@ -21,6 +20,6 @@ public class SearchRequestQuery extends AbstractQuery { @Override protected boolean processResults(@NotNull Processor consumer) { - return PsiManager.getInstance(myProject).getSearchHelper().processRequests(myRequests, consumer); + return PsiSearchHelper.SERVICE.getInstance(myProject).processRequests(myRequests, consumer); } } diff --git a/platform/lang-api/src/com/intellij/psi/search/searches/ReferencesSearch.java b/platform/lang-api/src/com/intellij/psi/search/searches/ReferencesSearch.java index ec8a0f52d676..01a6f1f7f3b0 100644 --- a/platform/lang-api/src/com/intellij/psi/search/searches/ReferencesSearch.java +++ b/platform/lang-api/src/com/intellij/psi/search/searches/ReferencesSearch.java @@ -69,7 +69,7 @@ public class ReferencesSearch extends ExtensibleQueryFactory result, @NotNull Collection outsideResult) { - PsiManager psiManager = file.getManager(); - PsiSearchHelper helper = psiManager.getSearchHelper(); + PsiSearchHelper helper = PsiSearchHelper.SERVICE.getInstance(file.getProject()); TodoItem[] todoItems = helper.findTodoItems(file, startOffset, endOffset); if (todoItems.length == 0) return; diff --git a/platform/lang-impl/src/com/intellij/find/findUsages/CommonFindUsagesDialog.java b/platform/lang-impl/src/com/intellij/find/findUsages/CommonFindUsagesDialog.java index b803e272370d..b46be8cf1102 100644 --- a/platform/lang-impl/src/com/intellij/find/findUsages/CommonFindUsagesDialog.java +++ b/platform/lang-impl/src/com/intellij/find/findUsages/CommonFindUsagesDialog.java @@ -21,6 +21,7 @@ import com.intellij.openapi.project.Project; import com.intellij.openapi.util.text.StringUtil; import com.intellij.psi.PsiElement; import com.intellij.psi.search.LocalSearchScope; +import com.intellij.psi.search.PsiSearchHelper; import com.intellij.ui.SimpleColoredComponent; import com.intellij.ui.SimpleTextAttributes; import com.intellij.usageView.UsageViewUtil; @@ -51,7 +52,7 @@ public class CommonFindUsagesDialog extends AbstractFindUsagesDialog { @Override protected boolean isInFileOnly() { return super.isInFileOnly() || - myPsiElement != null && myPsiElement.getManager().getSearchHelper().getUseScope(myPsiElement)instanceof LocalSearchScope; + myPsiElement != null && PsiSearchHelper.SERVICE.getInstance(myPsiElement.getProject()).getUseScope(myPsiElement)instanceof LocalSearchScope; } protected JPanel createFindWhatPanel() { diff --git a/platform/lang-impl/src/com/intellij/find/findUsages/FindUsagesManager.java b/platform/lang-impl/src/com/intellij/find/findUsages/FindUsagesManager.java index 08c62c3f18e7..33b1dbfc804a 100644 --- a/platform/lang-impl/src/com/intellij/find/findUsages/FindUsagesManager.java +++ b/platform/lang-impl/src/com/intellij/find/findUsages/FindUsagesManager.java @@ -46,10 +46,7 @@ import com.intellij.openapi.util.*; import com.intellij.openapi.util.text.StringUtil; import com.intellij.openapi.wm.StatusBar; import com.intellij.psi.*; -import com.intellij.psi.search.LocalSearchScope; -import com.intellij.psi.search.SearchRequestCollector; -import com.intellij.psi.search.SearchScope; -import com.intellij.psi.search.SearchSession; +import com.intellij.psi.search.*; import com.intellij.psi.util.PsiUtilBase; import com.intellij.ui.LightweightHint; import com.intellij.ui.content.Content; @@ -431,11 +428,12 @@ public class FindUsagesManager implements JDOMExternalizable { return scopeFile != null ? scopeFile.getProject() : !elements.isEmpty() ? elements.get(0).getProject() : handler.getProject(); } }); - PsiManager.getInstance(project).getSearchHelper().processRequests(options.fastTrack, new ReadActionProcessor() { - public boolean processInReadAction(final PsiReference ref) { - return usageInfoProcessor.process(new UsageInfo(ref)); - } - }); + PsiSearchHelper.SERVICE.getInstance(project) + .processRequests(options.fastTrack, new ReadActionProcessor() { + public boolean processInReadAction(final PsiReference ref) { + return usageInfoProcessor.process(new UsageInfo(ref)); + } + }); } finally { options.fastTrack = null; diff --git a/platform/lang-impl/src/com/intellij/ide/todo/TodoTreeBuilder.java b/platform/lang-impl/src/com/intellij/ide/todo/TodoTreeBuilder.java index da4b9b3d9294..a0c783cfaf65 100644 --- a/platform/lang-impl/src/com/intellij/ide/todo/TodoTreeBuilder.java +++ b/platform/lang-impl/src/com/intellij/ide/todo/TodoTreeBuilder.java @@ -99,7 +99,7 @@ public abstract class TodoTreeBuilder extends AbstractTreeBuilder { myFile2Highlighter = new HashMap(); PsiManager psiManager = PsiManager.getInstance(myProject); - mySearchHelper = psiManager.getSearchHelper(); + mySearchHelper = PsiSearchHelper.SERVICE.getInstance(myProject); psiManager.addPsiTreeChangeListener(new MyPsiTreeChangeListener()); myFileStatusListener = new MyFileStatusListener(); diff --git a/platform/lang-impl/src/com/intellij/ide/todo/TodoTreeStructure.java b/platform/lang-impl/src/com/intellij/ide/todo/TodoTreeStructure.java index e0c8a4a94236..03a550b848a3 100644 --- a/platform/lang-impl/src/com/intellij/ide/todo/TodoTreeStructure.java +++ b/platform/lang-impl/src/com/intellij/ide/todo/TodoTreeStructure.java @@ -23,7 +23,6 @@ import com.intellij.ide.util.treeView.NodeDescriptor; import com.intellij.openapi.project.Project; import com.intellij.psi.PsiDocumentManager; import com.intellij.psi.PsiFile; -import com.intellij.psi.PsiManager; import com.intellij.psi.search.PsiSearchHelper; import com.intellij.psi.search.PsiTodoSearchHelper; import com.intellij.psi.search.TodoPattern; @@ -55,8 +54,7 @@ public abstract class TodoTreeStructure extends AbstractTreeStructureBase implem super(project); myArePackagesShown=true; mySummaryElement=new ToDoSummary(); - PsiManager psiManager = PsiManager.getInstance(project); - mySearchHelper= psiManager.getSearchHelper(); + mySearchHelper= PsiSearchHelper.SERVICE.getInstance(project); } final void setTreeBuilder(TodoTreeBuilder builder){ diff --git a/platform/lang-impl/src/com/intellij/openapi/vcs/checkin/TodoCheckinHandlerWorker.java b/platform/lang-impl/src/com/intellij/openapi/vcs/checkin/TodoCheckinHandlerWorker.java index cc261cc2de8b..142dc882e729 100644 --- a/platform/lang-impl/src/com/intellij/openapi/vcs/checkin/TodoCheckinHandlerWorker.java +++ b/platform/lang-impl/src/com/intellij/openapi/vcs/checkin/TodoCheckinHandlerWorker.java @@ -81,7 +81,7 @@ public class TodoCheckinHandlerWorker { myTodoFilter = todoFilter; myIncludePattern = includePattern; myPsiManager = PsiManager.getInstance(project); - mySearchHelper = myPsiManager.getSearchHelper(); + mySearchHelper = PsiSearchHelper.SERVICE.getInstance(project); myAddedOrEditedTodos = new ArrayList(); myInChangedTodos = new ArrayList(); mySkipped = new SmartList>(); diff --git a/platform/lang-impl/src/com/intellij/psi/impl/PsiManagerImpl.java b/platform/lang-impl/src/com/intellij/psi/impl/PsiManagerImpl.java index 68df7ba9fdae..71a37cd995d0 100644 --- a/platform/lang-impl/src/com/intellij/psi/impl/PsiManagerImpl.java +++ b/platform/lang-impl/src/com/intellij/psi/impl/PsiManagerImpl.java @@ -47,13 +47,11 @@ import com.intellij.psi.impl.cache.impl.CompositeCacheManager; import com.intellij.psi.impl.cache.impl.IndexCacheManagerImpl; import com.intellij.psi.impl.file.impl.FileManager; import com.intellij.psi.impl.file.impl.FileManagerImpl; -import com.intellij.psi.impl.search.PsiSearchHelperImpl; import com.intellij.psi.impl.source.PostprocessReformattingAspect; import com.intellij.psi.impl.source.PsiFileImpl; import com.intellij.psi.impl.source.resolve.ResolveCache; import com.intellij.psi.impl.source.tree.injected.InjectedLanguageManagerImpl; import com.intellij.psi.impl.source.tree.injected.InjectedLanguageUtil; -import com.intellij.psi.search.PsiSearchHelper; import com.intellij.psi.util.CachedValuesManager; import com.intellij.psi.util.PsiModificationTracker; import com.intellij.refactoring.move.moveFilesOrDirectories.MoveFilesOrDirectoriesUtil; @@ -78,7 +76,6 @@ public class PsiManagerImpl extends PsiManagerEx implements ProjectComponent { private final MessageBus myMessageBus; private final FileManager myFileManager; - private final PsiSearchHelperImpl mySearchHelper; private final CacheManager myCacheManager; private final PsiModificationTrackerImpl myModificationTracker; private final ResolveCache myResolveCache; @@ -122,7 +119,6 @@ public class PsiManagerImpl extends PsiManagerEx implements ProjectComponent { myFileManager = isProjectDefault ? new EmptyFileManager(this) : new FileManagerImpl(this, fileTypeManager, fileDocumentManager, projectRootManagerEx); - mySearchHelper = new PsiSearchHelperImpl(this); final CompositeCacheManager cacheManager = new CompositeCacheManager(); if (isProjectDefault) { cacheManager.addCacheManager(new EmptyCacheManager()); @@ -695,11 +691,6 @@ public class PsiManagerImpl extends PsiManagerEx implements ProjectComponent { myMessageBus.syncPublisher(ANY_PSI_CHANGE_TOPIC).afterPsiChanged(isPhysical); } - @NotNull - public PsiSearchHelper getSearchHelper() { - return mySearchHelper; - } - @NotNull public PsiModificationTracker getModificationTracker() { return myModificationTracker; diff --git a/platform/lang-impl/src/com/intellij/refactoring/rename/inplace/VariableInplaceRenamer.java b/platform/lang-impl/src/com/intellij/refactoring/rename/inplace/VariableInplaceRenamer.java index c98a911b2878..766e38d82cb2 100644 --- a/platform/lang-impl/src/com/intellij/refactoring/rename/inplace/VariableInplaceRenamer.java +++ b/platform/lang-impl/src/com/intellij/refactoring/rename/inplace/VariableInplaceRenamer.java @@ -52,6 +52,7 @@ import com.intellij.psi.*; import com.intellij.psi.impl.source.tree.injected.InjectedLanguageUtil; import com.intellij.psi.search.LocalSearchScope; import com.intellij.psi.search.ProjectScope; +import com.intellij.psi.search.PsiSearchHelper; import com.intellij.psi.search.SearchScope; import com.intellij.psi.search.searches.ReferencesSearch; import com.intellij.psi.util.PsiTreeUtil; @@ -181,7 +182,7 @@ public class VariableInplaceRenamer { @Nullable protected PsiElement checkLocalScope() { - final SearchScope searchScope = myElementToRename.getManager().getSearchHelper().getUseScope(myElementToRename); + final SearchScope searchScope = PsiSearchHelper.SERVICE.getInstance(myElementToRename.getProject()).getUseScope(myElementToRename); if (searchScope instanceof LocalSearchScope) { final PsiElement[] elements = ((LocalSearchScope)searchScope).getScope(); return PsiTreeUtil.findCommonParent(elements); diff --git a/platform/lang-impl/src/com/intellij/refactoring/util/TextOccurrencesUtil.java b/platform/lang-impl/src/com/intellij/refactoring/util/TextOccurrencesUtil.java index 1cd199ca8c10..960271825423 100644 --- a/platform/lang-impl/src/com/intellij/refactoring/util/TextOccurrencesUtil.java +++ b/platform/lang-impl/src/com/intellij/refactoring/util/TextOccurrencesUtil.java @@ -27,7 +27,6 @@ import com.intellij.lang.ParserDefinition; import com.intellij.openapi.util.TextRange; import com.intellij.psi.PsiElement; import com.intellij.psi.PsiFile; -import com.intellij.psi.PsiManager; import com.intellij.psi.PsiReference; import com.intellij.psi.search.*; import com.intellij.usageView.UsageInfo; @@ -60,7 +59,7 @@ public class TextOccurrencesUtil { @NotNull GlobalSearchScope searchScope, @NotNull final Processor processor, @NotNull final UsageInfoFactory factory) { - PsiSearchHelper helper = element.getManager().getSearchHelper(); + PsiSearchHelper helper = PsiSearchHelper.SERVICE.getInstance(element.getProject()); helper.processUsagesInNonJavaFiles(element, stringToSearch, new PsiNonJavaFileReferenceProcessor() { public boolean process(PsiFile psiFile, int startOffset, int endOffset) { @@ -93,10 +92,9 @@ public class TextOccurrencesUtil { @NotNull final String stringToSearch, final boolean ignoreReferences, @NotNull final PairProcessor processor) { - PsiManager manager = element.getManager(); - PsiSearchHelper helper = manager.getSearchHelper(); - SearchScope scope = element.getManager().getSearchHelper().getUseScope(element); - scope = scope.intersectWith(GlobalSearchScope.projectScope(manager.getProject())); + PsiSearchHelper helper = PsiSearchHelper.SERVICE.getInstance(element.getProject()); + SearchScope scope = PsiSearchHelper.SERVICE.getInstance(element.getProject()).getUseScope(element); + scope = scope.intersectWith(GlobalSearchScope.projectScope(element.getProject())); Processor commentOrLiteralProcessor = new Processor() { public boolean process(PsiElement literal) { return processTextIn(literal, stringToSearch, ignoreReferences, processor); diff --git a/platform/platform-resources/src/META-INF/LangExtensions.xml b/platform/platform-resources/src/META-INF/LangExtensions.xml index 1e6a9135d6d1..1546150ec0ec 100644 --- a/platform/platform-resources/src/META-INF/LangExtensions.xml +++ b/platform/platform-resources/src/META-INF/LangExtensions.xml @@ -73,6 +73,9 @@ + + diff --git a/plugins/InspectionGadgets/src/com/siyeh/ig/abstraction/DeclareCollectionAsInterfaceInspection.java b/plugins/InspectionGadgets/src/com/siyeh/ig/abstraction/DeclareCollectionAsInterfaceInspection.java index e4f5ce18ca3b..d061b65aa7c4 100644 --- a/plugins/InspectionGadgets/src/com/siyeh/ig/abstraction/DeclareCollectionAsInterfaceInspection.java +++ b/plugins/InspectionGadgets/src/com/siyeh/ig/abstraction/DeclareCollectionAsInterfaceInspection.java @@ -288,8 +288,7 @@ public class DeclareCollectionAsInterfaceInspection extends BaseInspection { } final ProgressManager progressManager = ProgressManager.getInstance(); - final PsiManager manager = element.getManager(); - final PsiSearchHelper searchHelper = manager.getSearchHelper(); + final PsiSearchHelper searchHelper = PsiSearchHelper.SERVICE.getInstance(element.getProject()); final GlobalSearchScope scope = GlobalSearchScope.projectScope(element.getProject()); return searchHelper.isCheapEnoughToSearch(name, scope, null, diff --git a/plugins/InspectionGadgets/src/com/siyeh/ig/abstraction/StaticMethodOnlyUsedInOneClassInspection.java b/plugins/InspectionGadgets/src/com/siyeh/ig/abstraction/StaticMethodOnlyUsedInOneClassInspection.java index 3003396b69bb..4441028a0411 100644 --- a/plugins/InspectionGadgets/src/com/siyeh/ig/abstraction/StaticMethodOnlyUsedInOneClassInspection.java +++ b/plugins/InspectionGadgets/src/com/siyeh/ig/abstraction/StaticMethodOnlyUsedInOneClassInspection.java @@ -209,8 +209,7 @@ public class StaticMethodOnlyUsedInOneClassInspection public PsiClass getUsageClass(final PsiMethod method) { final ProgressManager progressManager = ProgressManager.getInstance(); - final PsiManager manager = method.getManager(); - final PsiSearchHelper searchHelper = manager.getSearchHelper(); + final PsiSearchHelper searchHelper = PsiSearchHelper.SERVICE.getInstance(method.getProject()); final String name = method.getName(); final GlobalSearchScope scope = GlobalSearchScope.allScope(method.getProject()); diff --git a/plugins/InspectionGadgets/src/com/siyeh/ig/maturity/TodoUtil.java b/plugins/InspectionGadgets/src/com/siyeh/ig/maturity/TodoUtil.java index dc96c04cd5d1..35264662194d 100644 --- a/plugins/InspectionGadgets/src/com/siyeh/ig/maturity/TodoUtil.java +++ b/plugins/InspectionGadgets/src/com/siyeh/ig/maturity/TodoUtil.java @@ -18,7 +18,6 @@ package com.siyeh.ig.maturity; import com.intellij.openapi.util.TextRange; import com.intellij.psi.PsiComment; import com.intellij.psi.PsiFile; -import com.intellij.psi.PsiManager; import com.intellij.psi.search.PsiSearchHelper; import com.intellij.psi.search.TodoItem; @@ -29,8 +28,7 @@ public class TodoUtil{ public static boolean isTodoComment(PsiComment comment){ final PsiFile file = comment.getContainingFile(); - final PsiManager psiManager = comment.getManager(); - final PsiSearchHelper searchHelper = psiManager.getSearchHelper(); + final PsiSearchHelper searchHelper = PsiSearchHelper.SERVICE.getInstance(comment.getProject()); final TodoItem[] todoItems = searchHelper.findTodoItems(file); for(final TodoItem todoItem : todoItems){ final TextRange commentTextRange = comment.getTextRange(); diff --git a/plugins/IntelliLang/java-support/org/intellij/plugins/intelliLang/pattern/compiler/AnnotationBasedInstrumentingCompiler.java b/plugins/IntelliLang/java-support/org/intellij/plugins/intelliLang/pattern/compiler/AnnotationBasedInstrumentingCompiler.java index 3479f56803fc..6b6190780f80 100644 --- a/plugins/IntelliLang/java-support/org/intellij/plugins/intelliLang/pattern/compiler/AnnotationBasedInstrumentingCompiler.java +++ b/plugins/IntelliLang/java-support/org/intellij/plugins/intelliLang/pattern/compiler/AnnotationBasedInstrumentingCompiler.java @@ -67,7 +67,7 @@ public abstract class AnnotationBasedInstrumentingCompiler implements ClassInstr final Project project = context.getProject(); final Set result = new HashSet(); - final PsiSearchHelper searchHelper = PsiManager.getInstance(context.getProject()).getSearchHelper(); + final PsiSearchHelper searchHelper = PsiSearchHelper.SERVICE.getInstance(context.getProject()); DumbService.getInstance(project).waitForSmartMode(); diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/findUsages/GrAliasedImportedElementSearcher.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/findUsages/GrAliasedImportedElementSearcher.java index 1cfa50c98c8c..3b89fe4310ca 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/findUsages/GrAliasedImportedElementSearcher.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/findUsages/GrAliasedImportedElementSearcher.java @@ -100,7 +100,7 @@ public class GrAliasedImportedElementSearcher extends QueryExecutorBase words = StringUtil.getWordsIn(stringToFind); if (words.isEmpty()) return; // put longer strings first diff --git a/plugins/properties/src/com/intellij/codeInspection/duplicatePropertyInspection/DuplicatePropertyInspection.java b/plugins/properties/src/com/intellij/codeInspection/duplicatePropertyInspection/DuplicatePropertyInspection.java index c0bf1fe80224..3a474bf0e537 100644 --- a/plugins/properties/src/com/intellij/codeInspection/duplicatePropertyInspection/DuplicatePropertyInspection.java +++ b/plugins/properties/src/com/intellij/codeInspection/duplicatePropertyInspection/DuplicatePropertyInspection.java @@ -146,7 +146,7 @@ public class DuplicatePropertyInspection extends GlobalSimpleInspectionTool { private void checkFile(final PsiFile file, final InspectionManager manager, GlobalInspectionContextImpl context, final RefManager refManager, final ProblemDescriptionsProcessor processor) { if (!(file instanceof PropertiesFile)) return; if (!context.isToCheckMember(file, this)) return; - final PsiSearchHelper searchHelper = file.getManager().getSearchHelper(); + final PsiSearchHelper searchHelper = PsiSearchHelper.SERVICE.getInstance(file.getProject()); final PropertiesFile propertiesFile = (PropertiesFile)file; final List properties = propertiesFile.getProperties(); Module module = ModuleUtil.findModuleForPsiElement(file); diff --git a/plugins/properties/src/com/intellij/lang/properties/UnusedPropertyInspection.java b/plugins/properties/src/com/intellij/lang/properties/UnusedPropertyInspection.java index 2afbbe43644c..dca886a3727a 100644 --- a/plugins/properties/src/com/intellij/lang/properties/UnusedPropertyInspection.java +++ b/plugins/properties/src/com/intellij/lang/properties/UnusedPropertyInspection.java @@ -24,10 +24,7 @@ import com.intellij.openapi.module.Module; import com.intellij.openapi.module.ModuleUtil; import com.intellij.openapi.progress.ProgressIndicator; import com.intellij.openapi.progress.ProgressManager; -import com.intellij.psi.PsiElement; -import com.intellij.psi.PsiElementVisitor; -import com.intellij.psi.PsiFile; -import com.intellij.psi.PsiReference; +import com.intellij.psi.*; import com.intellij.psi.search.GlobalSearchScope; import com.intellij.psi.search.PsiSearchHelper; import com.intellij.psi.search.searches.ReferencesSearch; @@ -57,7 +54,7 @@ public class UnusedPropertyInspection extends PropertySuppressableInspectionBase Module module = ModuleUtil.findModuleForPsiElement(file); if (module == null) return super.buildVisitor(holder, isOnTheFly, session); final GlobalSearchScope searchScope = GlobalSearchScope.moduleWithDependentsScope(module); - final PsiSearchHelper searchHelper = file.getManager().getSearchHelper(); + final PsiSearchHelper searchHelper = PsiSearchHelper.SERVICE.getInstance(file.getProject()); return new PsiElementVisitor() { @Override public void visitElement(PsiElement element) { diff --git a/plugins/testng/src/com/theoryinpractice/testng/inspection/UndeclaredTestInspection.java b/plugins/testng/src/com/theoryinpractice/testng/inspection/UndeclaredTestInspection.java index 85b8620156cf..c96fe49e056e 100644 --- a/plugins/testng/src/com/theoryinpractice/testng/inspection/UndeclaredTestInspection.java +++ b/plugins/testng/src/com/theoryinpractice/testng/inspection/UndeclaredTestInspection.java @@ -34,6 +34,7 @@ import com.intellij.openapi.vfs.VirtualFile; import com.intellij.psi.*; import com.intellij.psi.search.GlobalSearchScope; import com.intellij.psi.search.PsiNonJavaFileReferenceProcessor; +import com.intellij.psi.search.PsiSearchHelper; import com.intellij.psi.util.PsiClassUtil; import com.intellij.psi.util.PsiTreeUtil; import com.intellij.psi.xml.XmlAttribute; @@ -90,13 +91,13 @@ public class UndeclaredTestInspection extends BaseJavaLocalInspectionTool { } for (final String name : names) { final boolean[] found = new boolean[]{false}; - PsiManager.getInstance(project).getSearchHelper() + PsiSearchHelper.SERVICE.getInstance(project) .processUsagesInNonJavaFiles(name, new PsiNonJavaFileReferenceProcessor() { public boolean process(final PsiFile file, final int startOffset, final int endOffset) { if (file.findReferenceAt(startOffset) != null) { if (packageQName.endsWith(name)) { //special package tag required final XmlTag tag = PsiTreeUtil.getParentOfType(file.findElementAt(startOffset), XmlTag.class); - if (tag == null || !tag.getName().equals("package")){ + if (tag == null || !tag.getName().equals("package")) { return true; } final XmlAttribute attribute = tag.getAttribute("name"); From 4f6538b7c69f8fba06d40bd5be4f5bcdeb684097 Mon Sep 17 00:00:00 2001 From: Dmitry Jemerov Date: Fri, 19 Aug 2011 19:22:23 +0400 Subject: [PATCH 34/78] unused delegating method removed --- platform/lang-api/src/com/intellij/psi/PsiManager.java | 2 -- platform/lang-impl/src/com/intellij/mock/MockPsiManager.java | 5 ----- .../lang-impl/src/com/intellij/psi/impl/PsiManagerImpl.java | 4 ---- 3 files changed, 11 deletions(-) diff --git a/platform/lang-api/src/com/intellij/psi/PsiManager.java b/platform/lang-api/src/com/intellij/psi/PsiManager.java index f63dbae7ed83..706979e4d128 100644 --- a/platform/lang-api/src/com/intellij/psi/PsiManager.java +++ b/platform/lang-api/src/com/intellij/psi/PsiManager.java @@ -208,8 +208,6 @@ public abstract class PsiManager extends UserDataHolderBase { T; public abstract T performActionWithFormatterDisabled(Computable r); - public abstract void postponeAutoFormattingInside(Runnable runnable); - public abstract void registerLanguageInjector(@NotNull LanguageInjector injector); public abstract void registerLanguageInjector(@NotNull LanguageInjector injector, Disposable parentDisposable); diff --git a/platform/lang-impl/src/com/intellij/mock/MockPsiManager.java b/platform/lang-impl/src/com/intellij/mock/MockPsiManager.java index 9202a14aa589..7176f6764b7b 100644 --- a/platform/lang-impl/src/com/intellij/mock/MockPsiManager.java +++ b/platform/lang-impl/src/com/intellij/mock/MockPsiManager.java @@ -32,7 +32,6 @@ import com.intellij.psi.impl.cache.CacheManager; import com.intellij.psi.impl.cache.impl.CompositeCacheManager; import com.intellij.psi.impl.file.impl.FileManager; import com.intellij.psi.impl.search.PsiSearchHelperImpl; -import com.intellij.psi.impl.source.PostprocessReformattingAspect; import com.intellij.psi.impl.source.resolve.ResolveCache; import com.intellij.psi.search.PsiSearchHelper; import com.intellij.psi.util.CachedValuesManager; @@ -190,10 +189,6 @@ public class MockPsiManager extends PsiManagerEx { public void dropFileCaches(@NotNull PsiFile file) { } - public void postponeAutoFormattingInside(Runnable runnable) { - PostprocessReformattingAspect.getInstance(getProject()).postponeFormattingInside(runnable); - } - @NotNull public List getLanguageInjectors() { return Collections.emptyList(); diff --git a/platform/lang-impl/src/com/intellij/psi/impl/PsiManagerImpl.java b/platform/lang-impl/src/com/intellij/psi/impl/PsiManagerImpl.java index 71a37cd995d0..1d0dbeac7c87 100644 --- a/platform/lang-impl/src/com/intellij/psi/impl/PsiManagerImpl.java +++ b/platform/lang-impl/src/com/intellij/psi/impl/PsiManagerImpl.java @@ -266,10 +266,6 @@ public class PsiManagerImpl extends PsiManagerEx implements ProjectComponent { InjectedLanguageManagerImpl.getInstanceImpl(myProject).psiManagerInjectorsChanged(); } - public void postponeAutoFormattingInside(Runnable runnable) { - PostprocessReformattingAspect.getInstance(getProject()).postponeFormattingInside(runnable); - } - public void projectClosed() { } From d4e83980699e7130552d6c5a02bbba821e749441 Mon Sep 17 00:00:00 2001 From: Dmitry Jemerov Date: Fri, 19 Aug 2011 19:44:26 +0400 Subject: [PATCH 35/78] Module.getModuleType() -> ModuleType.get(Module) --- .../impl/javaCompiler/BackendCompilerWrapper.java | 2 +- .../compiler/options/ProcessedModulesTable.java | 3 ++- .../openapi/deployment/DeploymentUtilImpl.java | 5 +++-- .../artifacts/JarArtifactFromModulesDialog.java | 3 ++- .../impl/ui/ModuleElementPresentation.java | 5 +++-- .../execution/ui/ConfigurationModuleSelector.java | 5 +++-- .../frameworkSupport/FrameworkSupportUtil.java | 2 +- .../DefaultModuleEditorsProvider.java | 3 ++- .../sourceItems/ModuleSourceItemGroup.java | 5 +++-- .../AnalyzeDependenciesComponent.java | 3 ++- .../projectRoot/AddFacetOfTypeAction.java | 7 ++++--- .../projectRoot/FacetEditorFacadeImpl.java | 2 +- .../projectRoot/ModuleConfigurable.java | 5 +++-- .../projectRoot/ModuleStructureConfigurable.java | 2 +- .../daemon/UsageInModuleClasspath.java | 3 ++- .../ex/GlobalJavaInspectionContextImpl.java | 3 ++- .../psi/impl/JavaDirectoryIconProvider.java | 3 ++- java/openapi/src/com/intellij/ide/IconUtilEx.java | 3 ++- .../src/com/intellij/openapi/module/Module.java | 10 +++------- .../com/intellij/openapi/module/ModuleType.java | 4 ++++ .../com/intellij/openapi/module/ModuleUtil.java | 4 ++-- .../ui/util/OrderEntryCellAppearanceUtils.java | 5 +++-- .../codeInsight/hint/ElementLocationUtil.java | 3 ++- .../codeInspection/reference/RefModuleImpl.java | 3 ++- .../codeInspection/ui/InspectionModuleNode.java | 3 ++- .../src/com/intellij/facet/FacetManagerImpl.java | 2 +- .../statistics/ModuleTypeUsagesCollector.java | 3 ++- .../ide/navigationToolbar/NavBarPresentation.java | 5 +++-- .../impl/nodes/AbstractModuleNode.java | 7 ++++--- .../intellij/ide/todo/nodes/ModuleToDoNode.java | 5 +++-- .../ide/util/DirectoryChooserModuleTreeView.java | 3 ++- .../ide/util/PsiElementModuleRenderer.java | 3 ++- .../ModulesDependenciesPanel.java | 3 ++- .../components/impl/stores/ModuleStoreImpl.java | 2 +- .../intellij/openapi/module/impl/ModuleImpl.java | 15 --------------- .../openapi/module/impl/ModuleManagerImpl.java | 8 ++++---- .../ui/configuration/ChooseModulesDialog.java | 3 ++- .../roots/ui/configuration/ModulesCombobox.java | 3 ++- .../vcs/changes/ui/ChangesBrowserModuleNode.java | 3 ++- .../packageDependencies/ui/ModuleNode.java | 5 +++-- .../ui/classpath/ChooseLibrariesDialogBase.java | 5 +++-- .../src/com/intellij/mock/MockModule.java | 7 ------- .../usages/impl/rules/ModuleGroupingRule.java | 3 ++- .../exportSignedPackage/ChooseModuleStep.java | 3 ++- .../AndroidModuleConfigurationEditorProvider.java | 3 ++- .../newProject/AndroidModulesComboBox.java | 3 ++- .../src/actions/GeneratePluginClassAction.java | 3 ++- .../src/build/PluginBuildParticipantProvider.java | 3 ++- plugins/devkit/src/build/PluginBuildUtil.java | 3 ++- .../src/build/PrepareAllToDeployAction.java | 7 ++++--- .../devkit/src/build/PrepareToDeployAction.java | 5 +++-- .../src/module/PluginModuleEditorsProvider.java | 3 ++- plugins/devkit/src/module/PluginModuleType.java | 6 +++--- .../devkit/src/run/PluginRunConfiguration.java | 3 ++- .../src/run/PluginRunConfigurationEditor.java | 3 ++- plugins/devkit/src/util/ChooseModulesDialog.java | 3 ++- .../eclipse/conversion/DotProjectFileHelper.java | 3 ++- .../plugins/groovy/compiler/GroovyCompiler.java | 3 ++- .../groovy/compiler/GroovyCompilerBase.java | 3 ++- .../groovy/mvc/util/ModuleCellRenderer.java | 3 ++- .../runner/GroovyRunConfigurationEditor.java | 3 ++- .../plugins/groovy/util/GroovyUtils.java | 2 +- .../maven/importing/MavenProjectImporter.java | 9 +++------ .../xpath/xslt/run/XsltRunSettingsEditor.java | 3 ++- .../plugins/xpathView/search/ScopePanel.java | 3 ++- 65 files changed, 143 insertions(+), 118 deletions(-) diff --git a/java/compiler/impl/src/com/intellij/compiler/impl/javaCompiler/BackendCompilerWrapper.java b/java/compiler/impl/src/com/intellij/compiler/impl/javaCompiler/BackendCompilerWrapper.java index 08305785073f..033bec365cd4 100644 --- a/java/compiler/impl/src/com/intellij/compiler/impl/javaCompiler/BackendCompilerWrapper.java +++ b/java/compiler/impl/src/com/intellij/compiler/impl/javaCompiler/BackendCompilerWrapper.java @@ -345,7 +345,7 @@ public class BackendCompilerWrapper { return; // should not invoke javac with empty sources list } - ModuleType moduleType = chunk.getModules()[0].getModuleType(); + ModuleType moduleType = ModuleType.get(chunk.getModules()[0]); if (!(chunk.getJdk().getSdkType() instanceof JavaSdkType) && !(moduleType instanceof JavaModuleType || moduleType.createModuleBuilder() instanceof JavaModuleBuilder)) { // TODO diff --git a/java/compiler/impl/src/com/intellij/compiler/options/ProcessedModulesTable.java b/java/compiler/impl/src/com/intellij/compiler/options/ProcessedModulesTable.java index 05e28ae826fb..2f9b75f8fa41 100644 --- a/java/compiler/impl/src/com/intellij/compiler/options/ProcessedModulesTable.java +++ b/java/compiler/impl/src/com/intellij/compiler/options/ProcessedModulesTable.java @@ -17,6 +17,7 @@ package com.intellij.compiler.options; import com.intellij.openapi.module.Module; import com.intellij.openapi.module.ModuleManager; +import com.intellij.openapi.module.ModuleType; import com.intellij.openapi.project.Project; import com.intellij.openapi.roots.ui.configuration.ChooseModulesDialog; import com.intellij.openapi.util.Pair; @@ -420,7 +421,7 @@ public class ProcessedModulesTable extends JPanel { } component.setEnabled(ProcessedModulesTable.this.isEnabled()); if (component instanceof JLabel) { - final Icon icon = module != null ? module.getModuleType().getNodeIcon(false) : null; + final Icon icon = module != null ? ModuleType.get(module).getNodeIcon(false) : null; JLabel label = (JLabel)component; label.setIcon(icon); label.setDisabledIcon(icon); diff --git a/java/compiler/impl/src/com/intellij/openapi/deployment/DeploymentUtilImpl.java b/java/compiler/impl/src/com/intellij/openapi/deployment/DeploymentUtilImpl.java index 6804b5ccc8eb..9968fdbe3fb6 100644 --- a/java/compiler/impl/src/com/intellij/openapi/deployment/DeploymentUtilImpl.java +++ b/java/compiler/impl/src/com/intellij/openapi/deployment/DeploymentUtilImpl.java @@ -22,6 +22,7 @@ import com.intellij.openapi.compiler.CompilerMessageCategory; import com.intellij.openapi.compiler.make.BuildRecipe; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.module.Module; +import com.intellij.openapi.module.ModuleType; import com.intellij.openapi.util.SystemInfo; import com.intellij.openapi.util.io.FileUtil; import com.intellij.openapi.vfs.VfsUtil; @@ -119,7 +120,7 @@ public class DeploymentUtilImpl extends DeploymentUtil { } public void reportDeploymentDescriptorDoesNotExists(ConfigFile descriptor, CompileContext context, Module module) { - final String description = module.getModuleType().getName() + " '" + module.getName() + '\''; + final String description = ModuleType.get(module).getName() + " '" + module.getName() + '\''; String descriptorPath = VfsUtil.urlToPath(descriptor.getUrl()); final String message = CompilerBundle.message("message.text.compiling.item.deployment.descriptor.could.not.be.found", description, descriptorPath); @@ -130,7 +131,7 @@ public class DeploymentUtilImpl extends DeploymentUtil { if (new File(VfsUtil.urlToPath(descriptor.getUrl())).exists()) { String message = getConfigFileErrorMessage(descriptor); if (message != null) { - final String moduleDescription = module.getModuleType().getName() + " '" + module.getName() + '\''; + final String moduleDescription = ModuleType.get(module).getName() + " '" + module.getName() + '\''; compileContext.addMessage(CompilerMessageCategory.ERROR, CompilerBundle.message("message.text.compiling.module.message", moduleDescription, message), descriptor.getUrl(), -1, -1); diff --git a/java/compiler/impl/src/com/intellij/packaging/impl/artifacts/JarArtifactFromModulesDialog.java b/java/compiler/impl/src/com/intellij/packaging/impl/artifacts/JarArtifactFromModulesDialog.java index b2c377b0d160..a5e401eaabaa 100644 --- a/java/compiler/impl/src/com/intellij/packaging/impl/artifacts/JarArtifactFromModulesDialog.java +++ b/java/compiler/impl/src/com/intellij/packaging/impl/artifacts/JarArtifactFromModulesDialog.java @@ -17,6 +17,7 @@ package com.intellij.packaging.impl.artifacts; import com.intellij.ide.ui.ListCellRendererWrapper; import com.intellij.openapi.module.Module; +import com.intellij.openapi.module.ModuleType; import com.intellij.openapi.project.Project; import com.intellij.openapi.roots.ui.configuration.ModulesAlphaComparator; import com.intellij.openapi.ui.DialogWrapper; @@ -165,7 +166,7 @@ public class JarArtifactFromModulesDialog extends DialogWrapper { @Override public void customize(JList list, Module value, int index, boolean selected, boolean hasFocus) { if (value != null) { - setIcon(value.getModuleType().getNodeIcon(false)); + setIcon(ModuleType.get(value).getNodeIcon(false)); setText(value.getName()); } else { diff --git a/java/compiler/impl/src/com/intellij/packaging/impl/ui/ModuleElementPresentation.java b/java/compiler/impl/src/com/intellij/packaging/impl/ui/ModuleElementPresentation.java index 9b05f101f6fb..042329d9f2ac 100644 --- a/java/compiler/impl/src/com/intellij/packaging/impl/ui/ModuleElementPresentation.java +++ b/java/compiler/impl/src/com/intellij/packaging/impl/ui/ModuleElementPresentation.java @@ -20,6 +20,7 @@ import com.intellij.openapi.compiler.CompilerBundle; import com.intellij.openapi.module.ModifiableModuleModel; import com.intellij.openapi.module.Module; import com.intellij.openapi.module.ModulePointer; +import com.intellij.openapi.module.ModuleType; import com.intellij.packaging.ui.ArtifactEditorContext; import com.intellij.packaging.ui.PackagingElementWeights; import com.intellij.packaging.ui.TreeNodePresentation; @@ -70,8 +71,8 @@ public class ModuleElementPresentation extends TreeNodePresentation { presentationData.setIcons(PlatformIcons.TEST_SOURCE_FOLDER); } else if (module != null) { - presentationData.setOpenIcon(module.getModuleType().getNodeIcon(true)); - presentationData.setClosedIcon(module.getModuleType().getNodeIcon(false)); + presentationData.setOpenIcon(ModuleType.get(module).getNodeIcon(true)); + presentationData.setClosedIcon(ModuleType.get(module).getNodeIcon(false)); } String moduleName; if (module != null) { diff --git a/java/execution/impl/src/com/intellij/execution/ui/ConfigurationModuleSelector.java b/java/execution/impl/src/com/intellij/execution/ui/ConfigurationModuleSelector.java index f488a89cc32b..2d7dd2f7ca16 100644 --- a/java/execution/impl/src/com/intellij/execution/ui/ConfigurationModuleSelector.java +++ b/java/execution/impl/src/com/intellij/execution/ui/ConfigurationModuleSelector.java @@ -20,6 +20,7 @@ import com.intellij.execution.configurations.ModuleBasedConfiguration; import com.intellij.ide.ui.ListCellRendererWrapper; import com.intellij.openapi.module.Module; import com.intellij.openapi.module.ModuleManager; +import com.intellij.openapi.module.ModuleType; import com.intellij.openapi.module.ModuleTypeManager; import com.intellij.openapi.project.Project; import com.intellij.psi.PsiClass; @@ -66,7 +67,7 @@ public class ConfigurationModuleSelector { public void customize(final JList list, final Object value, final int index, final boolean selected, final boolean hasFocus) { if (value instanceof Module) { final Module module = (Module)value; - setIcon(module.getModuleType().getNodeIcon(true)); + setIcon(ModuleType.get(module).getNodeIcon(true)); setText(module.getName()); } else if (value == null) { @@ -91,7 +92,7 @@ public class ConfigurationModuleSelector { } public static boolean isModuleAccepted(final Module module) { - return ModuleTypeManager.getInstance().isClasspathProvider(module.getModuleType()); + return ModuleTypeManager.getInstance().isClasspathProvider(ModuleType.get(module)); } public Project getProject() { diff --git a/java/idea-ui/src/com/intellij/ide/util/frameworkSupport/FrameworkSupportUtil.java b/java/idea-ui/src/com/intellij/ide/util/frameworkSupport/FrameworkSupportUtil.java index 3993992f007a..0e6fb261fe63 100644 --- a/java/idea-ui/src/com/intellij/ide/util/frameworkSupport/FrameworkSupportUtil.java +++ b/java/idea-ui/src/com/intellij/ide/util/frameworkSupport/FrameworkSupportUtil.java @@ -29,7 +29,7 @@ public class FrameworkSupportUtil { } public static List getProviders(@NotNull Module module) { - return getProviders(module.getModuleType(), module); + return getProviders(ModuleType.get(module), module); } private static List getProviders(@NotNull ModuleType moduleType, @Nullable Module module) { diff --git a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/DefaultModuleEditorsProvider.java b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/DefaultModuleEditorsProvider.java index f365793da0d7..fe98d3db07a6 100644 --- a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/DefaultModuleEditorsProvider.java +++ b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/DefaultModuleEditorsProvider.java @@ -18,6 +18,7 @@ package com.intellij.openapi.roots.ui.configuration; import com.intellij.openapi.module.JavaModuleType; import com.intellij.openapi.module.Module; import com.intellij.openapi.module.ModuleConfigurationEditor; +import com.intellij.openapi.module.ModuleType; import com.intellij.openapi.roots.ModifiableRootModel; import java.util.ArrayList; @@ -27,7 +28,7 @@ public class DefaultModuleEditorsProvider implements ModuleConfigurationEditorPr public ModuleConfigurationEditor[] createEditors(ModuleConfigurationState state) { ModifiableRootModel rootModel = state.getRootModel(); Module module = rootModel.getModule(); - if (!(module.getModuleType() instanceof JavaModuleType)) { + if (!(ModuleType.get(module) instanceof JavaModuleType)) { return ModuleConfigurationEditor.EMPTY; } diff --git a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/artifacts/sourceItems/ModuleSourceItemGroup.java b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/artifacts/sourceItems/ModuleSourceItemGroup.java index aecfe28092cf..5b0d5a16fc82 100644 --- a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/artifacts/sourceItems/ModuleSourceItemGroup.java +++ b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/artifacts/sourceItems/ModuleSourceItemGroup.java @@ -17,6 +17,7 @@ package com.intellij.openapi.roots.ui.configuration.artifacts.sourceItems; import com.intellij.ide.projectView.PresentationData; import com.intellij.openapi.module.Module; +import com.intellij.openapi.module.ModuleType; import com.intellij.openapi.roots.DependencyScope; import com.intellij.openapi.roots.ModuleOrderEntry; import com.intellij.openapi.roots.OrderEntry; @@ -122,8 +123,8 @@ public class ModuleSourceItemGroup extends PackagingSourceItem { @Override public void render(@NotNull PresentationData presentationData, SimpleTextAttributes mainAttributes, SimpleTextAttributes commentAttributes) { - presentationData.setClosedIcon(myModule.getModuleType().getNodeIcon(false)); - presentationData.setOpenIcon(myModule.getModuleType().getNodeIcon(true)); + presentationData.setClosedIcon(ModuleType.get(myModule).getNodeIcon(false)); + presentationData.setOpenIcon(ModuleType.get(myModule).getNodeIcon(true)); presentationData.addText(myModule.getName(), mainAttributes); } diff --git a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/dependencyAnalysis/AnalyzeDependenciesComponent.java b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/dependencyAnalysis/AnalyzeDependenciesComponent.java index bde56cba8bc7..f6e1386ff52a 100644 --- a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/dependencyAnalysis/AnalyzeDependenciesComponent.java +++ b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/dependencyAnalysis/AnalyzeDependenciesComponent.java @@ -20,6 +20,7 @@ import com.intellij.ide.DataManager; import com.intellij.openapi.actionSystem.*; import com.intellij.openapi.actionSystem.ex.ComboBoxAction; import com.intellij.openapi.module.Module; +import com.intellij.openapi.module.ModuleType; import com.intellij.openapi.options.ConfigurationException; import com.intellij.openapi.project.DumbAwareAction; import com.intellij.openapi.roots.ModuleRootEvent; @@ -617,7 +618,7 @@ public class AnalyzeDependenciesComponent extends MasterDetailsComponent { return new CellAppearance() { @Override public void customize(SimpleColoredComponent component) { - component.setIcon(myModule.getModuleType().getNodeIcon(false)); + component.setIcon(ModuleType.get(myModule).getNodeIcon(false)); component.append("", SimpleTextAttributes.SYNTHETIC_ATTRIBUTES); } diff --git a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/projectRoot/AddFacetOfTypeAction.java b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/projectRoot/AddFacetOfTypeAction.java index 82a580cfdf52..dbc467adceed 100644 --- a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/projectRoot/AddFacetOfTypeAction.java +++ b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/projectRoot/AddFacetOfTypeAction.java @@ -24,6 +24,7 @@ import com.intellij.ide.util.ChooseElementsDialog; import com.intellij.openapi.actionSystem.AnAction; import com.intellij.openapi.actionSystem.AnActionEvent; import com.intellij.openapi.module.Module; +import com.intellij.openapi.module.ModuleType; import com.intellij.openapi.project.DumbAwareAction; import com.intellij.openapi.project.Project; import com.intellij.openapi.roots.ui.configuration.ChooseModulesDialog; @@ -68,7 +69,7 @@ class AddFacetOfTypeAction extends DumbAwareAction { final ProjectFacetsConfigurator facetsConfigurator = myContext.getModulesConfigurator().getFacetsConfigurator(); List suitableParents = new ArrayList(); for (Module module : myContext.getModules()) { - if (type.isSuitableModuleType(module.getModuleType())) { + if (type.isSuitableModuleType(ModuleType.get(module))) { suitableParents.addAll(facetsConfigurator.getFacetsByType(module, underlyingType)); } } @@ -104,7 +105,7 @@ class AddFacetOfTypeAction extends DumbAwareAction { final Iterator iterator = suitableModules.iterator(); while (iterator.hasNext()) { Module module = iterator.next(); - if (!type.isSuitableModuleType(module.getModuleType()) || (type.isOnlyOneFacetAllowed() && facetsConfigurator.hasFacetOfType(module, null, type.getId()))) { + if (!type.isSuitableModuleType(ModuleType.get(module)) || (type.isOnlyOneFacetAllowed() && facetsConfigurator.hasFacetOfType(module, null, type.getId()))) { iterator.remove(); } } @@ -139,7 +140,7 @@ class AddFacetOfTypeAction extends DumbAwareAction { private static boolean hasSuitableModules(StructureConfigurableContext context, FacetType type) { for (Module module : context.getModules()) { - if (type.isSuitableModuleType(module.getModuleType())) { + if (type.isSuitableModuleType(ModuleType.get(module))) { return true; } } diff --git a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/projectRoot/FacetEditorFacadeImpl.java b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/projectRoot/FacetEditorFacadeImpl.java index 6b6e3928d8d7..c160d90fcd14 100644 --- a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/projectRoot/FacetEditorFacadeImpl.java +++ b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/projectRoot/FacetEditorFacadeImpl.java @@ -181,7 +181,7 @@ public class FacetEditorFacadeImpl implements FacetEditorFacade { @Nullable public ModuleType getSelectedModuleType() { final Module module = getSelectedModule(); - return module != null ? module.getModuleType() : null; + return module != null ? ModuleType.get(module) : null; } @Nullable diff --git a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/projectRoot/ModuleConfigurable.java b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/projectRoot/ModuleConfigurable.java index 3584e55b996a..26cbc73fb1e2 100644 --- a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/projectRoot/ModuleConfigurable.java +++ b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/projectRoot/ModuleConfigurable.java @@ -18,6 +18,7 @@ package com.intellij.openapi.roots.ui.configuration.projectRoot; import com.intellij.openapi.module.ModifiableModuleModel; import com.intellij.openapi.module.Module; +import com.intellij.openapi.module.ModuleType; import com.intellij.openapi.module.ModuleWithNameAlreadyExists; import com.intellij.openapi.options.ConfigurationException; import com.intellij.openapi.project.ProjectBundle; @@ -91,11 +92,11 @@ public class ModuleConfigurable extends ProjectStructureElementConfigurableVirtualFile for the module .iml file. * @@ -51,13 +54,6 @@ public interface Module extends ComponentManager, AreaInstance, Disposable { */ @NotNull String getModuleFilePath(); - /** - * Returns the type of this module. - * - * @return the module type. - */ - @NotNull ModuleType getModuleType(); - /** * Returns the project to which this module belongs. * diff --git a/platform/lang-api/src/com/intellij/openapi/module/ModuleType.java b/platform/lang-api/src/com/intellij/openapi/module/ModuleType.java index 93ce3b0c5364..a35b82298679 100644 --- a/platform/lang-api/src/com/intellij/openapi/module/ModuleType.java +++ b/platform/lang-api/src/com/intellij/openapi/module/ModuleType.java @@ -83,4 +83,8 @@ public abstract class ModuleType { public boolean isValidSdk(final Module module, final Sdk projectSdk) { return true; } + + public static ModuleType get(Module module) { + return ModuleTypeManager.getInstance().findByID(module.getOptionValue(Module.ELEMENT_TYPE)); + } } diff --git a/platform/lang-api/src/com/intellij/openapi/module/ModuleUtil.java b/platform/lang-api/src/com/intellij/openapi/module/ModuleUtil.java index 67b3386aabe4..6f78c4cbb31e 100644 --- a/platform/lang-api/src/com/intellij/openapi/module/ModuleUtil.java +++ b/platform/lang-api/src/com/intellij/openapi/module/ModuleUtil.java @@ -80,7 +80,7 @@ public class ModuleUtil { @Nullable public static Module getParentModuleOfType(ModuleType expectedModuleType, Module module) { if (module == null) return null; - if (expectedModuleType.equals(module.getModuleType())) return module; + if (expectedModuleType.equals(ModuleType.get(module))) return module; final List parents = getParentModulesOfType(expectedModuleType, module); return parents.isEmpty() ? null : parents.get(0); } @@ -90,7 +90,7 @@ public class ModuleUtil { final List parents = ModuleManager.getInstance(module.getProject()).getModuleDependentModules(module); ArrayList modules = new ArrayList(); for (Module parent : parents) { - if (expectedModuleType.equals(parent.getModuleType())) { + if (expectedModuleType.equals(ModuleType.get(parent))) { modules.add(parent); } } diff --git a/platform/lang-api/src/com/intellij/openapi/roots/ui/util/OrderEntryCellAppearanceUtils.java b/platform/lang-api/src/com/intellij/openapi/roots/ui/util/OrderEntryCellAppearanceUtils.java index 2dfb0a1e34c0..ebafb3a04e29 100644 --- a/platform/lang-api/src/com/intellij/openapi/roots/ui/util/OrderEntryCellAppearanceUtils.java +++ b/platform/lang-api/src/com/intellij/openapi/roots/ui/util/OrderEntryCellAppearanceUtils.java @@ -17,6 +17,7 @@ package com.intellij.openapi.roots.ui.util; import com.intellij.openapi.module.Module; +import com.intellij.openapi.module.ModuleType; import com.intellij.openapi.project.Project; import com.intellij.openapi.project.ProjectBundle; import com.intellij.openapi.projectRoots.Sdk; @@ -74,7 +75,7 @@ public class OrderEntryCellAppearanceUtils { return new SimpleTextCellAppearance(presentableName, icon, SimpleTextAttributes.SYNTHETIC_ATTRIBUTES); } else if (orderEntry instanceof ModuleOrderEntry) { - final Icon icon = ((ModuleOrderEntry)orderEntry).getModule().getModuleType().getNodeIcon(false); + final Icon icon = ModuleType.get(((ModuleOrderEntry)orderEntry).getModule()).getNodeIcon(false); return SimpleTextCellAppearance.normal(orderEntry.getPresentableName(), icon); } else return CompositeAppearance.single(orderEntry.getPresentableName()); @@ -158,7 +159,7 @@ public class OrderEntryCellAppearanceUtils { } public static CellAppearance forModule(Module module) { - return SimpleTextCellAppearance.normal(module.getName(), module.getModuleType().getNodeIcon(false)); + return SimpleTextCellAppearance.normal(module.getName(), ModuleType.get(module).getNodeIcon(false)); } public static CellAppearance forContentEntry(ContentEntry contentEntry) { diff --git a/platform/lang-impl/src/com/intellij/codeInsight/hint/ElementLocationUtil.java b/platform/lang-impl/src/com/intellij/codeInsight/hint/ElementLocationUtil.java index bd89680967ca..6349077970d8 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/hint/ElementLocationUtil.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/hint/ElementLocationUtil.java @@ -16,6 +16,7 @@ package com.intellij.codeInsight.hint; +import com.intellij.openapi.module.ModuleType; import com.intellij.openapi.util.IconLoader; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.openapi.roots.*; @@ -49,7 +50,7 @@ public class ElementLocationUtil { if (module != null) { label.setText(module.getName()); - label.setIcon(module.getModuleType().getNodeIcon(false)); + label.setIcon(ModuleType.get(module).getNodeIcon(false)); } else { final List entries = fileIndex.getOrderEntriesForFile(vfile); diff --git a/platform/lang-impl/src/com/intellij/codeInspection/reference/RefModuleImpl.java b/platform/lang-impl/src/com/intellij/codeInspection/reference/RefModuleImpl.java index 455c4490e6da..89ab7b9e7ab4 100644 --- a/platform/lang-impl/src/com/intellij/codeInspection/reference/RefModuleImpl.java +++ b/platform/lang-impl/src/com/intellij/codeInspection/reference/RefModuleImpl.java @@ -3,6 +3,7 @@ package com.intellij.codeInspection.reference; import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.module.Module; import com.intellij.openapi.module.ModuleManager; +import com.intellij.openapi.module.ModuleType; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -57,7 +58,7 @@ public class RefModuleImpl extends RefEntityImpl implements RefModule { } public Icon getIcon(final boolean expanded) { - return getModule().getModuleType().getNodeIcon(expanded); + return ModuleType.get(getModule()).getNodeIcon(expanded); } @Nullable diff --git a/platform/lang-impl/src/com/intellij/codeInspection/ui/InspectionModuleNode.java b/platform/lang-impl/src/com/intellij/codeInspection/ui/InspectionModuleNode.java index eb355303165c..ff16feef19b2 100644 --- a/platform/lang-impl/src/com/intellij/codeInspection/ui/InspectionModuleNode.java +++ b/platform/lang-impl/src/com/intellij/codeInspection/ui/InspectionModuleNode.java @@ -1,6 +1,7 @@ package com.intellij.codeInspection.ui; import com.intellij.openapi.module.Module; +import com.intellij.openapi.module.ModuleType; import javax.swing.*; @@ -16,7 +17,7 @@ public class InspectionModuleNode extends InspectionTreeNode{ } public Icon getIcon(boolean expanded) { - return myModule.getModuleType().getNodeIcon(expanded); + return ModuleType.get(myModule).getNodeIcon(expanded); } public String getName(){ diff --git a/platform/lang-impl/src/com/intellij/facet/FacetManagerImpl.java b/platform/lang-impl/src/com/intellij/facet/FacetManagerImpl.java index 451c3a505bed..4cb3f4e56fb9 100644 --- a/platform/lang-impl/src/com/intellij/facet/FacetManagerImpl.java +++ b/platform/lang-impl/src/com/intellij/facet/FacetManagerImpl.java @@ -169,7 +169,7 @@ public class FacetManagerImpl extends FacetManager implements ModuleComponent, P continue; } - ModuleType moduleType = myModule.getModuleType(); + ModuleType moduleType = ModuleType.get(myModule); if (!type.isSuitableModuleType(moduleType)) { addInvalidFacet(child, model, underlyingFacet, ProjectBundle.message("error.message.0.facets.are.not.allowed.in.1", type.getPresentableName(), moduleType.getName())); diff --git a/platform/lang-impl/src/com/intellij/facet/impl/statistics/ModuleTypeUsagesCollector.java b/platform/lang-impl/src/com/intellij/facet/impl/statistics/ModuleTypeUsagesCollector.java index 397fd724c1ec..1f14356d9968 100644 --- a/platform/lang-impl/src/com/intellij/facet/impl/statistics/ModuleTypeUsagesCollector.java +++ b/platform/lang-impl/src/com/intellij/facet/impl/statistics/ModuleTypeUsagesCollector.java @@ -20,6 +20,7 @@ import com.intellij.internal.statistic.beans.GroupDescriptor; import com.intellij.internal.statistic.beans.UsageDescriptor; import com.intellij.openapi.module.Module; import com.intellij.openapi.module.ModuleManager; +import com.intellij.openapi.module.ModuleType; import com.intellij.openapi.project.Project; import com.intellij.util.Function; import com.intellij.util.containers.ContainerUtil; @@ -42,7 +43,7 @@ public class ModuleTypeUsagesCollector extends AbstractApplicationUsagesCollecto public Set getProjectUsages(@NotNull Project project) { Set modulesTypes = new HashSet(); for (Module module : ModuleManager.getInstance(project).getModules()) { - modulesTypes.add(module.getModuleType().getId()); + modulesTypes.add(ModuleType.get(module).getId()); } return ContainerUtil.map2Set(modulesTypes, new Function() { @Override diff --git a/platform/lang-impl/src/com/intellij/ide/navigationToolbar/NavBarPresentation.java b/platform/lang-impl/src/com/intellij/ide/navigationToolbar/NavBarPresentation.java index 22978bfc0569..cac639843895 100644 --- a/platform/lang-impl/src/com/intellij/ide/navigationToolbar/NavBarPresentation.java +++ b/platform/lang-impl/src/com/intellij/ide/navigationToolbar/NavBarPresentation.java @@ -21,6 +21,7 @@ import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.extensions.Extensions; import com.intellij.openapi.module.Module; import com.intellij.openapi.module.ModuleManager; +import com.intellij.openapi.module.ModuleType; import com.intellij.openapi.module.ModuleUtil; import com.intellij.openapi.project.IndexNotReadyException; import com.intellij.openapi.project.Project; @@ -64,7 +65,7 @@ public class NavBarPresentation { public static Icon getIcon(final Object object, final boolean open) { if (!NavBarModel.isValid(object)) return null; if (object instanceof Project) return PROJECT_ICON; - if (object instanceof Module) return ((Module)object).getModuleType().getNodeIcon(false); + if (object instanceof Module) return ModuleType.get(((Module)object)).getNodeIcon(false); try { if (object instanceof PsiElement) { return ApplicationManager.getApplication().runReadAction(new Computable() { @@ -80,7 +81,7 @@ public class NavBarPresentation { } if (object instanceof JdkOrderEntry) return ((JdkOrderEntry)object).getJdk().getSdkType().getIcon(); if (object instanceof LibraryOrderEntry) return IconLoader.getIcon("/nodes/ppLibClosed.png"); - if (object instanceof ModuleOrderEntry) return ((ModuleOrderEntry)object).getModule().getModuleType().getNodeIcon(false); + if (object instanceof ModuleOrderEntry) return ModuleType.get(((ModuleOrderEntry)object).getModule()).getNodeIcon(false); return null; } diff --git a/platform/lang-impl/src/com/intellij/ide/projectView/impl/nodes/AbstractModuleNode.java b/platform/lang-impl/src/com/intellij/ide/projectView/impl/nodes/AbstractModuleNode.java index 7dbc52abe646..db02417b443c 100644 --- a/platform/lang-impl/src/com/intellij/ide/projectView/impl/nodes/AbstractModuleNode.java +++ b/platform/lang-impl/src/com/intellij/ide/projectView/impl/nodes/AbstractModuleNode.java @@ -19,6 +19,7 @@ import com.intellij.ide.projectView.PresentationData; import com.intellij.ide.projectView.ProjectViewNode; import com.intellij.ide.projectView.ViewSettings; import com.intellij.openapi.module.Module; +import com.intellij.openapi.module.ModuleType; import com.intellij.openapi.project.Project; import com.intellij.openapi.roots.ModuleRootManager; import com.intellij.openapi.roots.ui.configuration.ProjectSettingsService; @@ -47,8 +48,8 @@ public abstract class AbstractModuleNode extends ProjectViewNode impleme presentation.addText(getValue().getName(), SimpleTextAttributes.REGULAR_BOLD_ATTRIBUTES); } - presentation.setOpenIcon(getValue().getModuleType().getNodeIcon(true)); - presentation.setClosedIcon(getValue().getModuleType().getNodeIcon(false)); + presentation.setOpenIcon(ModuleType.get(getValue()).getNodeIcon(true)); + presentation.setClosedIcon(ModuleType.get(getValue()).getNodeIcon(false)); } protected boolean showModuleNameInBold() { @@ -86,7 +87,7 @@ public abstract class AbstractModuleNode extends ProjectViewNode impleme public String getToolTip() { final Module module = getValue(); - return module.getModuleType().getName(); + return ModuleType.get(module).getName(); } public void navigate(final boolean requestFocus) { diff --git a/platform/lang-impl/src/com/intellij/ide/todo/nodes/ModuleToDoNode.java b/platform/lang-impl/src/com/intellij/ide/todo/nodes/ModuleToDoNode.java index b732a6950f4c..75f60b3b5e05 100644 --- a/platform/lang-impl/src/com/intellij/ide/todo/nodes/ModuleToDoNode.java +++ b/platform/lang-impl/src/com/intellij/ide/todo/nodes/ModuleToDoNode.java @@ -27,6 +27,7 @@ import com.intellij.openapi.editor.colors.EditorColorsScheme; import com.intellij.openapi.editor.markup.TextAttributes; import com.intellij.openapi.ide.CopyPasteManager; import com.intellij.openapi.module.Module; +import com.intellij.openapi.module.ModuleType; import com.intellij.openapi.project.Project; import com.intellij.openapi.roots.ModuleRootManager; import com.intellij.openapi.util.Computable; @@ -96,8 +97,8 @@ public class ModuleToDoNode extends BaseToDoNode implements HighlightedR EditorColorsScheme colorsScheme = UsageTreeColorsScheme.getInstance().getScheme(); myHighlightedRegions.add( new HighlightedRegion(nameEndOffset, newName.length(), colorsScheme.getAttributes(UsageTreeColors.NUMBER_OF_USAGES))); - presentation.setOpenIcon(getValue().getModuleType().getNodeIcon(true)); - presentation.setClosedIcon(getValue().getModuleType().getNodeIcon(false)); + presentation.setOpenIcon(ModuleType.get(getValue()).getNodeIcon(true)); + presentation.setClosedIcon(ModuleType.get(getValue()).getNodeIcon(false)); presentation.setPresentableText(newName); } diff --git a/platform/lang-impl/src/com/intellij/ide/util/DirectoryChooserModuleTreeView.java b/platform/lang-impl/src/com/intellij/ide/util/DirectoryChooserModuleTreeView.java index 83409382bfbc..d7b6944174a9 100644 --- a/platform/lang-impl/src/com/intellij/ide/util/DirectoryChooserModuleTreeView.java +++ b/platform/lang-impl/src/com/intellij/ide/util/DirectoryChooserModuleTreeView.java @@ -21,6 +21,7 @@ import com.intellij.ide.projectView.impl.ModuleGroupUtil; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.module.Module; import com.intellij.openapi.module.ModuleManager; +import com.intellij.openapi.module.ModuleType; import com.intellij.openapi.project.Project; import com.intellij.openapi.roots.ProjectFileIndex; import com.intellij.openapi.roots.ProjectRootManager; @@ -240,7 +241,7 @@ public class DirectoryChooserModuleTreeView implements DirectoryChooserView { final Module module = (Module)value; append(module.getName(), SimpleTextAttributes.REGULAR_ATTRIBUTES); int flags1 = expanded ? Iconable.ICON_FLAG_OPEN : Iconable.ICON_FLAG_CLOSED; - setIcon(module.getModuleType().getNodeIcon((flags1 & Iconable.ICON_FLAG_OPEN) != 0)); + setIcon(ModuleType.get(module).getNodeIcon((flags1 & Iconable.ICON_FLAG_OPEN) != 0)); } else if (value instanceof ModuleGroup) { append(value.toString(), SimpleTextAttributes.REGULAR_ATTRIBUTES); setIcon(expanded ? PlatformIcons.OPENED_MODULE_GROUP_ICON : PlatformIcons.CLOSED_MODULE_GROUP_ICON); diff --git a/platform/lang-impl/src/com/intellij/ide/util/PsiElementModuleRenderer.java b/platform/lang-impl/src/com/intellij/ide/util/PsiElementModuleRenderer.java index 4a5c108b5744..3271e723cbc6 100644 --- a/platform/lang-impl/src/com/intellij/ide/util/PsiElementModuleRenderer.java +++ b/platform/lang-impl/src/com/intellij/ide/util/PsiElementModuleRenderer.java @@ -17,6 +17,7 @@ package com.intellij.ide.util; import com.intellij.openapi.module.Module; +import com.intellij.openapi.module.ModuleType; import com.intellij.openapi.module.ModuleUtil; import com.intellij.openapi.roots.*; import com.intellij.openapi.util.IconLoader; @@ -77,7 +78,7 @@ public class PsiElementModuleRenderer extends DefaultListCellRenderer{ setIcon(TEST_ICON); } else { - setIcon(module.getModuleType().getNodeIcon(false)); + setIcon(ModuleType.get(module).getNodeIcon(false)); } } else { if (psiFile != null) { diff --git a/platform/lang-impl/src/com/intellij/moduleDependencies/ModulesDependenciesPanel.java b/platform/lang-impl/src/com/intellij/moduleDependencies/ModulesDependenciesPanel.java index 53564cc8c009..0f074ee65eae 100644 --- a/platform/lang-impl/src/com/intellij/moduleDependencies/ModulesDependenciesPanel.java +++ b/platform/lang-impl/src/com/intellij/moduleDependencies/ModulesDependenciesPanel.java @@ -27,6 +27,7 @@ import com.intellij.openapi.Disposable; import com.intellij.openapi.actionSystem.*; import com.intellij.openapi.module.Module; import com.intellij.openapi.module.ModuleManager; +import com.intellij.openapi.module.ModuleType; import com.intellij.openapi.progress.ProgressIndicator; import com.intellij.openapi.progress.ProgressManager; import com.intellij.openapi.project.Project; @@ -530,7 +531,7 @@ public class ModulesDependenciesPanel extends JPanel implements ModuleRootListen } MyUserObject node = (MyUserObject)userObject; Module module = node.getModule(); - setIcon(module.getModuleType().getNodeIcon(expanded)); + setIcon(ModuleType.get(module).getNodeIcon(expanded)); if (node.isInCycle()){ append(module.getName(), SimpleTextAttributes.ERROR_ATTRIBUTES); } else { diff --git a/platform/lang-impl/src/com/intellij/openapi/components/impl/stores/ModuleStoreImpl.java b/platform/lang-impl/src/com/intellij/openapi/components/impl/stores/ModuleStoreImpl.java index 74bf0470155a..5d0e994a317c 100644 --- a/platform/lang-impl/src/com/intellij/openapi/components/impl/stores/ModuleStoreImpl.java +++ b/platform/lang-impl/src/com/intellij/openapi/components/impl/stores/ModuleStoreImpl.java @@ -70,7 +70,7 @@ public class ModuleStoreImpl extends BaseFileConfigurableStoreImpl implements IM final ModuleFileData storageData = getMainStorageData(); final String moduleTypeId = storageData.myOptions.get(ModuleImpl.ELEMENT_TYPE); - myModule.setModuleType(ModuleTypeManager.getInstance().findByID(moduleTypeId)); + myModule.setOption(Module.ELEMENT_TYPE, ModuleTypeManager.getInstance().findByID(moduleTypeId).getId()); if (ApplicationManager.getApplication().isHeadlessEnvironment() || ApplicationManager.getApplication().isUnitTestMode()) return; diff --git a/platform/lang-impl/src/com/intellij/openapi/module/impl/ModuleImpl.java b/platform/lang-impl/src/com/intellij/openapi/module/impl/ModuleImpl.java index 58adea10b78f..1c2078e06d2e 100644 --- a/platform/lang-impl/src/com/intellij/openapi/module/impl/ModuleImpl.java +++ b/platform/lang-impl/src/com/intellij/openapi/module/impl/ModuleImpl.java @@ -24,7 +24,6 @@ import com.intellij.openapi.components.impl.ComponentManagerImpl; import com.intellij.openapi.components.impl.ModulePathMacroManager; import com.intellij.openapi.components.impl.stores.IComponentStore; import com.intellij.openapi.components.impl.stores.IModuleStore; -import com.intellij.openapi.components.impl.stores.IProjectStore; import com.intellij.openapi.components.impl.stores.ModuleStoreImpl; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.extensions.AreaInstance; @@ -32,7 +31,6 @@ import com.intellij.openapi.extensions.ExtensionPointName; import com.intellij.openapi.extensions.Extensions; import com.intellij.openapi.module.Module; import com.intellij.openapi.module.ModuleComponent; -import com.intellij.openapi.module.ModuleType; import com.intellij.openapi.module.impl.scopes.ModuleWithDependenciesScope; import com.intellij.openapi.module.impl.scopes.ModuleWithDependentsScope; import com.intellij.openapi.project.Project; @@ -61,11 +59,9 @@ public class ModuleImpl extends ComponentManagerImpl implements Module { private static final Logger LOG = Logger.getInstance("#com.intellij.openapi.module.impl.ModuleImpl"); @NotNull private final Project myProject; - private ModuleType myModuleType = null; private boolean isModuleAdded; @NonNls private static final String OPTION_WORKSPACE = "workspace"; - @NonNls public static final String ELEMENT_TYPE = "type"; private final Map myScopeCache = new StripedLockConcurrentHashMap(); @@ -209,12 +205,6 @@ public class ModuleImpl extends ComponentManagerImpl implements Module { } } - @NotNull - public ModuleType getModuleType() { - LOG.assertTrue(myModuleType != null, "Module type not initialized yet"); - return myModuleType; - } - @NotNull public Project getProject() { return myProject; @@ -236,11 +226,6 @@ public class ModuleImpl extends ComponentManagerImpl implements Module { } } - public void setModuleType(ModuleType type) { - myModuleType = type; - setOption(ELEMENT_TYPE, type.getId()); - } - public void setOption(@NotNull String optionName, @NotNull String optionValue) { getStateStore().setOption(optionName, optionValue); } diff --git a/platform/lang-impl/src/com/intellij/openapi/module/impl/ModuleManagerImpl.java b/platform/lang-impl/src/com/intellij/openapi/module/impl/ModuleManagerImpl.java index 4bc2d0496d0e..250d6862a41e 100644 --- a/platform/lang-impl/src/com/intellij/openapi/module/impl/ModuleManagerImpl.java +++ b/platform/lang-impl/src/com/intellij/openapi/module/impl/ModuleManagerImpl.java @@ -244,7 +244,7 @@ public class ModuleManagerImpl extends ModuleManager implements ProjectComponent for (final ModulePath modulePath : myModulePaths) { try { final Module module = moduleModel.loadModuleInternal(modulePath.getPath()); - if (module.getModuleType() instanceof UnknownModuleType) { + if (ModuleType.get(module) instanceof UnknownModuleType) { modulesWithUnknownTypes.add(module); } final String groupPathString = modulePath.getModuleGroup(); @@ -273,13 +273,13 @@ public class ModuleManagerImpl extends ModuleManager implements ProjectComponent String message; if (modulesWithUnknownTypes.size() == 1) { message = ProjectBundle.message("module.unknown.type.single.error", modulesWithUnknownTypes.get(0).getName(), - modulesWithUnknownTypes.get(0).getModuleType().getId()); + ModuleType.get(modulesWithUnknownTypes.get(0)).getId()); } else { StringBuilder modulesBuilder = new StringBuilder(); for (final Module module : modulesWithUnknownTypes) { modulesBuilder.append("
\""); - modulesBuilder.append(module.getName()).append("\" (type '").append(module.getModuleType().getId()).append("')"); + modulesBuilder.append(module.getName()).append("\" (type '").append(ModuleType.get(module).getId()).append("')"); } modulesBuilder.append("
"); message = ProjectBundle.message("module.unknown.type.multiple.error", modulesBuilder.toString()); @@ -684,7 +684,7 @@ public class ModuleManagerImpl extends ModuleManager implements ProjectComponent ModuleImpl module = getModuleByFilePath(filePath); if (module == null) { module = new ModuleImpl(filePath, myProject); - module.setModuleType(moduleType); + module.setOption(Module.ELEMENT_TYPE, moduleType.getId()); if (options != null) { for ( Map.Entry option : options.entrySet()) { module.setOption(option.getKey(),option.getValue()); diff --git a/platform/lang-impl/src/com/intellij/openapi/roots/ui/configuration/ChooseModulesDialog.java b/platform/lang-impl/src/com/intellij/openapi/roots/ui/configuration/ChooseModulesDialog.java index e26799d7fc67..279fa8c76a0c 100644 --- a/platform/lang-impl/src/com/intellij/openapi/roots/ui/configuration/ChooseModulesDialog.java +++ b/platform/lang-impl/src/com/intellij/openapi/roots/ui/configuration/ChooseModulesDialog.java @@ -23,6 +23,7 @@ package com.intellij.openapi.roots.ui.configuration; import com.intellij.openapi.module.Module; +import com.intellij.openapi.module.ModuleType; import com.intellij.openapi.project.Project; import com.intellij.ide.util.ChooseElementsDialog; import org.jetbrains.annotations.Nullable; @@ -50,7 +51,7 @@ public class ChooseModulesDialog extends ChooseElementsDialog { } protected Icon getItemIcon(final Module item) { - return item.getModuleType().getNodeIcon(false); + return ModuleType.get(item).getNodeIcon(false); } protected String getItemText(final Module item) { diff --git a/platform/lang-impl/src/com/intellij/openapi/roots/ui/configuration/ModulesCombobox.java b/platform/lang-impl/src/com/intellij/openapi/roots/ui/configuration/ModulesCombobox.java index 64a0aa6e69ea..36d6b70a1840 100644 --- a/platform/lang-impl/src/com/intellij/openapi/roots/ui/configuration/ModulesCombobox.java +++ b/platform/lang-impl/src/com/intellij/openapi/roots/ui/configuration/ModulesCombobox.java @@ -18,6 +18,7 @@ package com.intellij.openapi.roots.ui.configuration; import com.intellij.ide.ui.ListCellRendererWrapper; import com.intellij.openapi.module.Module; import com.intellij.openapi.module.ModuleManager; +import com.intellij.openapi.module.ModuleType; import com.intellij.openapi.project.Project; import com.intellij.openapi.ui.ComboBox; import com.intellij.ui.SortedComboBoxModel; @@ -45,7 +46,7 @@ public class ModulesCombobox extends ComboBox { public void customize(JList list, Module value, int index, boolean selected, boolean hasFocus) { if (value != null) { setText(value.getName()); - setIcon(value.getModuleType().getNodeIcon(false)); + setIcon(ModuleType.get(value).getNodeIcon(false)); } else { setText("[none]"); diff --git a/platform/lang-impl/src/com/intellij/openapi/vcs/changes/ui/ChangesBrowserModuleNode.java b/platform/lang-impl/src/com/intellij/openapi/vcs/changes/ui/ChangesBrowserModuleNode.java index 8965746c2ecd..00fb025f7cd2 100644 --- a/platform/lang-impl/src/com/intellij/openapi/vcs/changes/ui/ChangesBrowserModuleNode.java +++ b/platform/lang-impl/src/com/intellij/openapi/vcs/changes/ui/ChangesBrowserModuleNode.java @@ -17,6 +17,7 @@ package com.intellij.openapi.vcs.changes.ui; import com.intellij.openapi.module.Module; +import com.intellij.openapi.module.ModuleType; import com.intellij.openapi.vcs.FilePath; import com.intellij.openapi.vcs.FilePathImpl; import com.intellij.openapi.vfs.VirtualFile; @@ -37,7 +38,7 @@ public class ChangesBrowserModuleNode extends ChangesBrowserNode { renderer.append(module.isDisposed() ? "" : module.getName(), SimpleTextAttributes.REGULAR_ATTRIBUTES); appendCount(renderer); - renderer.setIcon(module.getModuleType().getNodeIcon(expanded)); + renderer.setIcon(ModuleType.get(module).getNodeIcon(expanded)); } @Override diff --git a/platform/lang-impl/src/com/intellij/packageDependencies/ui/ModuleNode.java b/platform/lang-impl/src/com/intellij/packageDependencies/ui/ModuleNode.java index cef04e9d092a..1db1b4d5d04e 100644 --- a/platform/lang-impl/src/com/intellij/packageDependencies/ui/ModuleNode.java +++ b/platform/lang-impl/src/com/intellij/packageDependencies/ui/ModuleNode.java @@ -18,6 +18,7 @@ package com.intellij.packageDependencies.ui; import com.intellij.analysis.AnalysisScopeBundle; import com.intellij.openapi.module.Module; +import com.intellij.openapi.module.ModuleType; import com.intellij.openapi.roots.ui.configuration.ProjectSettingsService; import com.intellij.openapi.util.Comparing; import com.intellij.pom.NavigatableWithText; @@ -59,11 +60,11 @@ public class ModuleNode extends PackageDependenciesNode implements NavigatableWi } public Icon getOpenIcon() { - return myModule == null ? null : myModule.getModuleType().getNodeIcon(true); + return myModule == null ? null : ModuleType.get(myModule).getNodeIcon(true); } public Icon getClosedIcon() { - return myModule == null ? null : myModule.getModuleType().getNodeIcon(false); + return myModule == null ? null : ModuleType.get(myModule).getNodeIcon(false); } public String toString() { diff --git a/platform/lang-impl/src/com/intellij/util/ui/classpath/ChooseLibrariesDialogBase.java b/platform/lang-impl/src/com/intellij/util/ui/classpath/ChooseLibrariesDialogBase.java index fbea5193613e..02bcb475c29c 100644 --- a/platform/lang-impl/src/com/intellij/util/ui/classpath/ChooseLibrariesDialogBase.java +++ b/platform/lang-impl/src/com/intellij/util/ui/classpath/ChooseLibrariesDialogBase.java @@ -14,6 +14,7 @@ import com.intellij.openapi.application.Application; import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.module.Module; import com.intellij.openapi.module.ModuleManager; +import com.intellij.openapi.module.ModuleType; import com.intellij.openapi.project.Project; import com.intellij.openapi.project.ProjectManager; import com.intellij.openapi.roots.LibraryOrderEntry; @@ -271,8 +272,8 @@ public abstract class ChooseLibrariesDialogBase extends DialogWrapper { protected ModuleDescriptor(final Project project, final NodeDescriptor parentDescriptor, final Module element) { super(project, parentDescriptor, element); final PresentationData templatePresentation = getTemplatePresentation(); - templatePresentation.setClosedIcon(element.getModuleType().getNodeIcon(false)); - templatePresentation.setOpenIcon(element.getModuleType().getNodeIcon(true)); + templatePresentation.setClosedIcon(ModuleType.get(element).getNodeIcon(false)); + templatePresentation.setOpenIcon(ModuleType.get(element).getNodeIcon(true)); templatePresentation.addText(notEmpty(element.getName()), SimpleTextAttributes.REGULAR_ATTRIBUTES); } diff --git a/platform/testFramework/src/com/intellij/mock/MockModule.java b/platform/testFramework/src/com/intellij/mock/MockModule.java index c900ec975d69..c0cee8e54384 100644 --- a/platform/testFramework/src/com/intellij/mock/MockModule.java +++ b/platform/testFramework/src/com/intellij/mock/MockModule.java @@ -4,7 +4,6 @@ package com.intellij.mock; import com.intellij.openapi.module.Module; -import com.intellij.openapi.module.ModuleType; import com.intellij.openapi.project.Project; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.psi.search.GlobalSearchScope; @@ -57,12 +56,6 @@ public class MockModule extends MockComponentManager implements Module { return new MockGlobalSearchScope(); } - @Override - @NotNull - public ModuleType getModuleType() { - throw new UnsupportedOperationException("Method getModuleType is not yet implemented in " + getClass().getName()); - } - @Override public GlobalSearchScope getModuleWithDependenciesAndLibrariesScope(final boolean includeTests) { return new MockGlobalSearchScope(); diff --git a/platform/usageView/src/com/intellij/usages/impl/rules/ModuleGroupingRule.java b/platform/usageView/src/com/intellij/usages/impl/rules/ModuleGroupingRule.java index 0978ab0e03bb..d57d36db645e 100644 --- a/platform/usageView/src/com/intellij/usages/impl/rules/ModuleGroupingRule.java +++ b/platform/usageView/src/com/intellij/usages/impl/rules/ModuleGroupingRule.java @@ -20,6 +20,7 @@ import com.intellij.openapi.actionSystem.DataSink; import com.intellij.openapi.actionSystem.LangDataKeys; import com.intellij.openapi.actionSystem.TypeSafeDataProvider; import com.intellij.openapi.module.Module; +import com.intellij.openapi.module.ModuleType; import com.intellij.openapi.roots.OrderEntry; import com.intellij.openapi.util.IconLoader; import com.intellij.openapi.vcs.FileStatus; @@ -137,7 +138,7 @@ public class ModuleGroupingRule implements UsageGroupingRule { } public Icon getIcon(boolean isOpen) { - return myModule.getModuleType().getNodeIcon(isOpen); + return ModuleType.get(myModule).getNodeIcon(isOpen); } @NotNull diff --git a/plugins/android/src/org/jetbrains/android/exportSignedPackage/ChooseModuleStep.java b/plugins/android/src/org/jetbrains/android/exportSignedPackage/ChooseModuleStep.java index ccb5f9cf58a7..2244913de37e 100644 --- a/plugins/android/src/org/jetbrains/android/exportSignedPackage/ChooseModuleStep.java +++ b/plugins/android/src/org/jetbrains/android/exportSignedPackage/ChooseModuleStep.java @@ -20,6 +20,7 @@ import com.intellij.ide.ui.ListCellRendererWrapper; import com.intellij.ide.util.PropertiesComponent; import com.intellij.ide.wizard.CommitStepException; import com.intellij.openapi.module.Module; +import com.intellij.openapi.module.ModuleType; import com.intellij.ui.CollectionComboBoxModel; import org.jetbrains.android.facet.AndroidFacet; import org.jetbrains.android.util.AndroidBundle; @@ -62,7 +63,7 @@ class ChooseModuleStep extends ExportSignedPackageWizardStep { public void customize(JList list, AndroidFacet value, int index, boolean selected, boolean hasFocus) { final Module module = value.getModule(); setText(module.getName()); - setIcon(module.getModuleType().getNodeIcon(false)); + setIcon(ModuleType.get(module).getNodeIcon(false)); } }); myModuleCombo.addActionListener(new ActionListener() { diff --git a/plugins/android/src/org/jetbrains/android/newProject/AndroidModuleConfigurationEditorProvider.java b/plugins/android/src/org/jetbrains/android/newProject/AndroidModuleConfigurationEditorProvider.java index 0025a08aa9a2..98b77903d7be 100644 --- a/plugins/android/src/org/jetbrains/android/newProject/AndroidModuleConfigurationEditorProvider.java +++ b/plugins/android/src/org/jetbrains/android/newProject/AndroidModuleConfigurationEditorProvider.java @@ -16,6 +16,7 @@ package org.jetbrains.android.newProject; +import com.intellij.openapi.module.ModuleType; import com.intellij.openapi.roots.ui.configuration.ModuleConfigurationEditorProvider; import com.intellij.openapi.roots.ui.configuration.ModuleConfigurationState; import com.intellij.openapi.roots.ui.configuration.DefaultModuleConfigurationEditorFactory; @@ -35,7 +36,7 @@ import java.util.ArrayList; public class AndroidModuleConfigurationEditorProvider implements ModuleConfigurationEditorProvider { public ModuleConfigurationEditor[] createEditors(ModuleConfigurationState state) { final Module module = state.getRootModel().getModule(); - if (module.getModuleType() != AndroidModuleType.getInstance()) { + if (ModuleType.get(module) != AndroidModuleType.getInstance()) { return ModuleConfigurationEditor.EMPTY; } diff --git a/plugins/android/src/org/jetbrains/android/newProject/AndroidModulesComboBox.java b/plugins/android/src/org/jetbrains/android/newProject/AndroidModulesComboBox.java index 44b8c5f15bde..3c7dc4cb8f6e 100644 --- a/plugins/android/src/org/jetbrains/android/newProject/AndroidModulesComboBox.java +++ b/plugins/android/src/org/jetbrains/android/newProject/AndroidModulesComboBox.java @@ -18,6 +18,7 @@ package org.jetbrains.android.newProject; import com.intellij.ide.ui.ListCellRendererWrapper; import com.intellij.openapi.module.Module; import com.intellij.openapi.module.ModuleManager; +import com.intellij.openapi.module.ModuleType; import com.intellij.openapi.project.Project; import org.jetbrains.android.facet.AndroidFacet; import org.jetbrains.annotations.NotNull; @@ -37,7 +38,7 @@ public class AndroidModulesComboBox extends JComboBox { if (value instanceof Module) { final Module module = (Module)value; setText(module.getName()); - setIcon(module.getModuleType().getNodeIcon(false)); + setIcon(ModuleType.get(module).getNodeIcon(false)); } else { setText("[none]"); diff --git a/plugins/devkit/src/actions/GeneratePluginClassAction.java b/plugins/devkit/src/actions/GeneratePluginClassAction.java index 24e066ee5014..db5e55e00c38 100644 --- a/plugins/devkit/src/actions/GeneratePluginClassAction.java +++ b/plugins/devkit/src/actions/GeneratePluginClassAction.java @@ -20,6 +20,7 @@ import com.intellij.ide.actions.CreateElementActionBase; import com.intellij.openapi.actionSystem.*; import com.intellij.openapi.module.Module; import com.intellij.openapi.module.ModuleManager; +import com.intellij.openapi.module.ModuleType; import com.intellij.openapi.project.Project; import com.intellij.openapi.roots.OrderEntry; import com.intellij.openapi.roots.ProjectFileIndex; @@ -77,7 +78,7 @@ public abstract class GeneratePluginClassAction extends CreateElementActionBase final Module module = getModule(directory); if (module != null) { - if (module.getModuleType() == PluginModuleType.getInstance()) { + if (ModuleType.get(module) == PluginModuleType.getInstance()) { addPluginModule(module); } else { final List candidateModules = PluginModuleType.getCandidateModules(module); diff --git a/plugins/devkit/src/build/PluginBuildParticipantProvider.java b/plugins/devkit/src/build/PluginBuildParticipantProvider.java index 7064ce720196..b8a35d377a96 100644 --- a/plugins/devkit/src/build/PluginBuildParticipantProvider.java +++ b/plugins/devkit/src/build/PluginBuildParticipantProvider.java @@ -18,6 +18,7 @@ package org.jetbrains.idea.devkit.build; import com.intellij.openapi.compiler.make.BuildParticipantProvider; import com.intellij.openapi.module.Module; +import com.intellij.openapi.module.ModuleType; import org.jetbrains.idea.devkit.module.PluginModuleType; import java.util.Collection; @@ -28,7 +29,7 @@ import java.util.Collections; */ public class PluginBuildParticipantProvider extends BuildParticipantProvider { public Collection getParticipants(final Module module) { - if (module.getModuleType() != PluginModuleType.getInstance()) { + if (ModuleType.get(module) != PluginModuleType.getInstance()) { return Collections.emptyList(); } diff --git a/plugins/devkit/src/build/PluginBuildUtil.java b/plugins/devkit/src/build/PluginBuildUtil.java index c173fdc50fcc..157d31cd0cfa 100644 --- a/plugins/devkit/src/build/PluginBuildUtil.java +++ b/plugins/devkit/src/build/PluginBuildUtil.java @@ -18,6 +18,7 @@ package org.jetbrains.idea.devkit.build; import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.module.Module; import com.intellij.openapi.module.ModuleManager; +import com.intellij.openapi.module.ModuleType; import com.intellij.openapi.module.StdModuleTypes; import com.intellij.openapi.projectRoots.Sdk; import com.intellij.openapi.roots.*; @@ -63,7 +64,7 @@ public class PluginBuildUtil { productionRuntimeDependencies(module).forEachModule(new Processor() { @Override public boolean process(Module dep) { - if (dep.getModuleType() == StdModuleTypes.JAVA && !modules.contains(dep)) { + if (ModuleType.get(dep) == StdModuleTypes.JAVA && !modules.contains(dep)) { modules.add(dep); getDependencies(dep, modules); } diff --git a/plugins/devkit/src/build/PrepareAllToDeployAction.java b/plugins/devkit/src/build/PrepareAllToDeployAction.java index b9cf49fa938d..da57a7d1fbd3 100644 --- a/plugins/devkit/src/build/PrepareAllToDeployAction.java +++ b/plugins/devkit/src/build/PrepareAllToDeployAction.java @@ -20,6 +20,7 @@ import com.intellij.openapi.actionSystem.LangDataKeys; import com.intellij.openapi.actionSystem.PlatformDataKeys; import com.intellij.openapi.module.Module; import com.intellij.openapi.module.ModuleManager; +import com.intellij.openapi.module.ModuleType; import com.intellij.openapi.project.Project; import org.jetbrains.idea.devkit.DevKitBundle; import org.jetbrains.idea.devkit.module.PluginModuleType; @@ -36,7 +37,7 @@ public class PrepareAllToDeployAction extends PrepareToDeployAction { List pluginModules = new ArrayList(); for (Module aModule : ModuleManager.getInstance(project).getModules()) { - if (aModule.getModuleType() instanceof PluginModuleType) { + if (ModuleType.get(aModule) instanceof PluginModuleType) { pluginModules.add(aModule); } } @@ -55,7 +56,7 @@ public class PrepareAllToDeployAction extends PrepareToDeployAction { final Project project = e.getData(PlatformDataKeys.PROJECT); if (project != null) { for (Module aModule : (ModuleManager.getInstance(project).getModules())) { - if (aModule.getModuleType() instanceof PluginModuleType) { + if (ModuleType.get(aModule) instanceof PluginModuleType) { moduleCount++; } } @@ -66,7 +67,7 @@ public class PrepareAllToDeployAction extends PrepareToDeployAction { } else if (moduleCount > 0) { final Module module = e.getData(LangDataKeys.MODULE); - if (module == null || !(module.getModuleType() instanceof PluginModuleType)) { + if (module == null || !(ModuleType.get(module) instanceof PluginModuleType)) { enabled = true; } } diff --git a/plugins/devkit/src/build/PrepareToDeployAction.java b/plugins/devkit/src/build/PrepareToDeployAction.java index c141f3723d4d..9739ef0dbc74 100644 --- a/plugins/devkit/src/build/PrepareToDeployAction.java +++ b/plugins/devkit/src/build/PrepareToDeployAction.java @@ -25,6 +25,7 @@ import com.intellij.openapi.compiler.CompilerManager; import com.intellij.openapi.compiler.make.ManifestBuilder; import com.intellij.openapi.fileTypes.FileTypeManager; import com.intellij.openapi.module.Module; +import com.intellij.openapi.module.ModuleType; import com.intellij.openapi.progress.ProgressIndicator; import com.intellij.openapi.progress.ProgressManager; import com.intellij.openapi.project.Project; @@ -67,7 +68,7 @@ public class PrepareToDeployAction extends AnAction { public void actionPerformed(final AnActionEvent e) { final Module module = LangDataKeys.MODULE.getData(e.getDataContext()); - if (module != null && module.getModuleType() instanceof PluginModuleType) { + if (module != null && ModuleType.get(module) instanceof PluginModuleType) { doPrepare(Arrays.asList(module), LangDataKeys.PROJECT.getData(e.getDataContext())); } } @@ -343,7 +344,7 @@ public class PrepareToDeployAction extends AnAction { public void update(AnActionEvent e) { final Module module = LangDataKeys.MODULE.getData(e.getDataContext()); - boolean enabled = module != null && module.getModuleType() instanceof PluginModuleType; + boolean enabled = module != null && ModuleType.get(module) instanceof PluginModuleType; e.getPresentation().setVisible(enabled); e.getPresentation().setEnabled(enabled); if (enabled) { diff --git a/plugins/devkit/src/module/PluginModuleEditorsProvider.java b/plugins/devkit/src/module/PluginModuleEditorsProvider.java index c2b5d0a5cf6f..2e91b570e8bb 100644 --- a/plugins/devkit/src/module/PluginModuleEditorsProvider.java +++ b/plugins/devkit/src/module/PluginModuleEditorsProvider.java @@ -17,6 +17,7 @@ package org.jetbrains.idea.devkit.module; import com.intellij.openapi.module.Module; import com.intellij.openapi.module.ModuleConfigurationEditor; +import com.intellij.openapi.module.ModuleType; import com.intellij.openapi.roots.ui.configuration.DefaultModuleConfigurationEditorFactory; import com.intellij.openapi.roots.ui.configuration.ModuleConfigurationEditorProvider; import com.intellij.openapi.roots.ui.configuration.ModuleConfigurationState; @@ -29,7 +30,7 @@ public class PluginModuleEditorsProvider implements ModuleConfigurationEditorPro public ModuleConfigurationEditor[] createEditors(ModuleConfigurationState state) { final Module module = state.getRootModel().getModule(); - if (module.getModuleType() != PluginModuleType.getInstance()) return ModuleConfigurationEditor.EMPTY; + if (ModuleType.get(module) != PluginModuleType.getInstance()) return ModuleConfigurationEditor.EMPTY; final DefaultModuleConfigurationEditorFactory editorFactory = DefaultModuleConfigurationEditorFactory.getInstance(); List editors = new ArrayList(); diff --git a/plugins/devkit/src/module/PluginModuleType.java b/plugins/devkit/src/module/PluginModuleType.java index 315295f71bfa..b1637ec0e643 100644 --- a/plugins/devkit/src/module/PluginModuleType.java +++ b/plugins/devkit/src/module/PluginModuleType.java @@ -60,7 +60,7 @@ public class PluginModuleType extends ModuleType { } public static boolean isOfType(Module module) { - return module.getModuleType() instanceof PluginModuleType; + return get(module) instanceof PluginModuleType; } public ModuleWizardStep[] createWizardSteps(final WizardContext wizardContext, @@ -107,7 +107,7 @@ public class PluginModuleType extends ModuleType { @Nullable public static XmlFile getPluginXml(Module module, boolean initialize) { if (module == null) return null; - if (!(module.getModuleType() instanceof PluginModuleType)) return null; + if (!(get(module) instanceof PluginModuleType)) return null; final PluginBuildConfiguration buildConfiguration = PluginBuildConfiguration.getInstance(module); if (buildConfiguration == null) return null; @@ -137,7 +137,7 @@ public class PluginModuleType extends ModuleType { final List candidates = new ArrayList(modules.length); final Set deps = new HashSet(modules.length); for (Module m : modules) { - if (m.getModuleType() == getInstance()) { + if (get(m) == getInstance()) { deps.clear(); PluginBuildUtil.getDependencies(m, deps); diff --git a/plugins/devkit/src/run/PluginRunConfiguration.java b/plugins/devkit/src/run/PluginRunConfiguration.java index 301459f68afc..dc0da164deb5 100644 --- a/plugins/devkit/src/run/PluginRunConfiguration.java +++ b/plugins/devkit/src/run/PluginRunConfiguration.java @@ -25,6 +25,7 @@ import com.intellij.execution.runners.ProgramRunner; import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.module.Module; import com.intellij.openapi.module.ModuleManager; +import com.intellij.openapi.module.ModuleType; import com.intellij.openapi.options.SettingsEditor; import com.intellij.openapi.project.Project; import com.intellij.openapi.projectRoots.JavaSdkType; @@ -207,7 +208,7 @@ public class PluginRunConfiguration extends RunConfigurationBase implements Modu List modules = new ArrayList(); Module[] allModules = ModuleManager.getInstance(getProject()).getModules(); for (Module module : allModules) { - if (module.getModuleType() == PluginModuleType.getInstance()) { + if (ModuleType.get(module) == PluginModuleType.getInstance()) { modules.add(module); } } diff --git a/plugins/devkit/src/run/PluginRunConfigurationEditor.java b/plugins/devkit/src/run/PluginRunConfigurationEditor.java index ae1da5511c7d..e583397b813d 100644 --- a/plugins/devkit/src/run/PluginRunConfigurationEditor.java +++ b/plugins/devkit/src/run/PluginRunConfigurationEditor.java @@ -19,6 +19,7 @@ import com.intellij.execution.configurations.LogFileOptions; import com.intellij.ide.ui.ListCellRendererWrapper; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.module.Module; +import com.intellij.openapi.module.ModuleType; import com.intellij.openapi.options.ConfigurationException; import com.intellij.openapi.options.SettingsEditor; import com.intellij.openapi.projectRoots.Sdk; @@ -126,7 +127,7 @@ public class PluginRunConfigurationEditor extends SettingsEditor nojdkModules = new HashSet(); for (Module module : modules) { - if(!GroovyUtils.isAcceptableModuleType(module.getModuleType())) continue; + if(!GroovyUtils.isAcceptableModuleType(ModuleType.get(module))) continue; final Sdk sdk = ModuleRootManager.getInstance(module).getSdk(); if (sdk == null || !(sdk.getSdkType() instanceof JavaSdkType)) { nojdkModules.add(module); diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/compiler/GroovyCompilerBase.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/compiler/GroovyCompilerBase.java index 6e8982a2003c..924d785d4a6f 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/compiler/GroovyCompilerBase.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/compiler/GroovyCompilerBase.java @@ -36,6 +36,7 @@ import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.fileTypes.FileType; import com.intellij.openapi.fileTypes.StdFileTypes; import com.intellij.openapi.module.Module; +import com.intellij.openapi.module.ModuleType; import com.intellij.openapi.progress.ProgressIndicator; import com.intellij.openapi.progress.ProgressManager; import com.intellij.openapi.project.Project; @@ -383,7 +384,7 @@ public abstract class GroovyCompilerBase implements TranslatingCompiler { final CompilerConfiguration configuration = CompilerConfiguration.getInstance(myProject); final PsiManager psiManager = PsiManager.getInstance(myProject); - if (GroovyUtils.isAcceptableModuleType(module.getModuleType())) { + if (GroovyUtils.isAcceptableModuleType(ModuleType.get(module))) { for (final VirtualFile file : moduleFiles) { if (shouldCompile(file, configuration, psiManager)) { (index.isInTestSourceContent(file) ? toCompileTests : toCompile).add(file); diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/mvc/util/ModuleCellRenderer.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/mvc/util/ModuleCellRenderer.java index a483b060ccfd..8cea320dc95e 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/mvc/util/ModuleCellRenderer.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/mvc/util/ModuleCellRenderer.java @@ -17,6 +17,7 @@ package org.jetbrains.plugins.groovy.mvc.util; import com.intellij.ide.ui.ListCellRendererWrapper; import com.intellij.openapi.module.Module; +import com.intellij.openapi.module.ModuleType; import javax.swing.*; @@ -31,7 +32,7 @@ public class ModuleCellRenderer extends ListCellRendererWrapper { @Override public void customize(JList list, Module module, int index, boolean selected, boolean hasFocus) { if (module != null) { - setIcon(module.getModuleType().getNodeIcon(false)); + setIcon(ModuleType.get(module).getNodeIcon(false)); setText(module.getName()); } } diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/runner/GroovyRunConfigurationEditor.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/runner/GroovyRunConfigurationEditor.java index a46e50b107cf..7eb93093acc3 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/runner/GroovyRunConfigurationEditor.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/runner/GroovyRunConfigurationEditor.java @@ -21,6 +21,7 @@ import com.intellij.ide.ui.ListCellRendererWrapper; import com.intellij.ide.util.BrowseFilesListener; import com.intellij.openapi.fileChooser.FileChooserDescriptor; import com.intellij.openapi.module.Module; +import com.intellij.openapi.module.ModuleType; import com.intellij.openapi.options.ConfigurationException; import com.intellij.openapi.options.SettingsEditor; import com.intellij.openapi.roots.ui.configuration.ModulesAlphaComparator; @@ -119,7 +120,7 @@ public class GroovyRunConfigurationEditor extends SettingsEditor each) { MavenProject project = each.first; Module module = each.second; - return module.getModuleType().getName() + + return ModuleType.get(module).getName() + " '" + module.getName() + "' for Maven project '" + diff --git a/plugins/xpath/xpath-lang/src/org/intellij/lang/xpath/xslt/run/XsltRunSettingsEditor.java b/plugins/xpath/xpath-lang/src/org/intellij/lang/xpath/xslt/run/XsltRunSettingsEditor.java index a90e2a5cb26d..7cf3a0e245bf 100644 --- a/plugins/xpath/xpath-lang/src/org/intellij/lang/xpath/xslt/run/XsltRunSettingsEditor.java +++ b/plugins/xpath/xpath-lang/src/org/intellij/lang/xpath/xslt/run/XsltRunSettingsEditor.java @@ -25,6 +25,7 @@ import com.intellij.openapi.fileTypes.*; import com.intellij.openapi.fileTypes.impl.FileTypeRenderer; import com.intellij.openapi.module.Module; import com.intellij.openapi.module.ModuleManager; +import com.intellij.openapi.module.ModuleType; import com.intellij.openapi.options.ConfigurationException; import com.intellij.openapi.options.SettingsEditor; import com.intellij.openapi.project.Project; @@ -277,7 +278,7 @@ class XsltRunSettingsEditor extends SettingsEditor { return module.getName(); } })); - setIcon(module.getModuleType().getNodeIcon(true)); + setIcon(ModuleType.get(module).getNodeIcon(true)); } else if (value instanceof String) { setText((String)value); } diff --git a/plugins/xpath/xpath-view/src/org/intellij/plugins/xpathView/search/ScopePanel.java b/plugins/xpath/xpath-view/src/org/intellij/plugins/xpathView/search/ScopePanel.java index ab813d6e8d35..2d79e7571fad 100644 --- a/plugins/xpath/xpath-view/src/org/intellij/plugins/xpathView/search/ScopePanel.java +++ b/plugins/xpath/xpath-view/src/org/intellij/plugins/xpathView/search/ScopePanel.java @@ -21,6 +21,7 @@ import com.intellij.openapi.Disposable; import com.intellij.openapi.fileChooser.FileChooserDescriptorFactory; import com.intellij.openapi.module.Module; import com.intellij.openapi.module.ModuleManager; +import com.intellij.openapi.module.ModuleType; import com.intellij.openapi.project.Project; import com.intellij.openapi.ui.ComboBox; import com.intellij.openapi.ui.TextFieldWithBrowseButton; @@ -95,7 +96,7 @@ public class ScopePanel extends JPanel implements Disposable{ @Override public void customize(JList list, Module m, int index, boolean selected, boolean hasFocus) { if (m != null) { - setIcon(m.getModuleType().getNodeIcon(true)); + setIcon(ModuleType.get(m).getNodeIcon(true)); setText(m.getName()); } } From 62a68d49fa50f07e7190647c520db58ff27e9e47 Mon Sep 17 00:00:00 2001 From: Dmitry Jemerov Date: Fri, 19 Aug 2011 19:52:12 +0400 Subject: [PATCH 36/78] move scope constructors to GlobalSearchScopes --- .../intellij/images/index/ImageInfoIndex.java | 5 +- .../javaCompiler/BackendCompilerWrapper.java | 4 +- .../UnusedLibrariesInspection.java | 3 +- .../psi/impl/source/PsiJavaFileImpl.java | 3 +- .../typeMigration/ui/TypeMigrationDialog.java | 4 +- .../com/intellij/analysis/AnalysisScope.java | 7 +- .../psi/search/GlobalSearchScope.java | 264 +--------------- .../psi/search/GlobalSearchScopes.java | 288 ++++++++++++++++++ .../intellij/find/impl/FindInProjectUtil.java | 4 +- .../ide/hierarchy/HierarchyTreeStructure.java | 7 +- .../ide/util/PlatformPackageUtil.java | 5 +- .../util/scopeChooser/ScopeChooserCombo.java | 15 +- .../cache/impl/IndexCacheManagerImpl.java | 3 +- .../psi/impl/file/impl/FileManagerImpl.java | 3 +- .../src/com/intellij/psi/stubs/StubTree.java | 5 +- .../ObsoleteCollectionInspection.java | 4 +- .../GroovyConstructorUsagesSearcher.java | 5 +- .../execution/junit/TestDirectory.java | 6 +- .../DuplicatePropertyInspection.java | 3 +- 19 files changed, 341 insertions(+), 297 deletions(-) create mode 100644 platform/lang-api/src/com/intellij/psi/search/GlobalSearchScopes.java diff --git a/images/src/org/intellij/images/index/ImageInfoIndex.java b/images/src/org/intellij/images/index/ImageInfoIndex.java index 5413e4adfe54..94026bc8de64 100644 --- a/images/src/org/intellij/images/index/ImageInfoIndex.java +++ b/images/src/org/intellij/images/index/ImageInfoIndex.java @@ -19,7 +19,7 @@ import com.intellij.openapi.project.Project; import com.intellij.openapi.vfs.LocalFileSystem; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.openapi.vfs.ex.temp.TempFileSystem; -import com.intellij.psi.search.GlobalSearchScope; +import com.intellij.psi.search.GlobalSearchScopes; import com.intellij.util.indexing.*; import com.intellij.util.io.DataExternalizer; import org.intellij.images.fileTypes.ImageFileTypeManager; @@ -71,7 +71,8 @@ public class ImageInfoIndex extends SingleEntryFileBasedIndexExtension processor, Project project) { - FileBasedIndex.getInstance().processValues(INDEX_ID, Math.abs(FileBasedIndex.getFileId(virtualFile)), virtualFile, processor, GlobalSearchScope.fileScope(project, virtualFile)); + FileBasedIndex.getInstance().processValues(INDEX_ID, Math.abs(FileBasedIndex.getFileId(virtualFile)), virtualFile, processor, GlobalSearchScopes + .fileScope(project, virtualFile)); } public DataExternalizer getValueExternalizer() { diff --git a/java/compiler/impl/src/com/intellij/compiler/impl/javaCompiler/BackendCompilerWrapper.java b/java/compiler/impl/src/com/intellij/compiler/impl/javaCompiler/BackendCompilerWrapper.java index 033bec365cd4..c0a04a997893 100644 --- a/java/compiler/impl/src/com/intellij/compiler/impl/javaCompiler/BackendCompilerWrapper.java +++ b/java/compiler/impl/src/com/intellij/compiler/impl/javaCompiler/BackendCompilerWrapper.java @@ -60,6 +60,7 @@ import com.intellij.openapi.vfs.VirtualFile; import com.intellij.psi.JavaPsiFacade; import com.intellij.psi.PsiClass; import com.intellij.psi.search.GlobalSearchScope; +import com.intellij.psi.search.GlobalSearchScopes; import com.intellij.util.Chunk; import com.intellij.util.cls.ClsFormatException; import gnu.trove.THashMap; @@ -584,7 +585,8 @@ public class BackendCompilerWrapper { final String packagePrefix, final List filesToRefresh, final Map> results) throws CacheCorruptedException { final Ref exRef = new Ref(null); final ModuleFileIndex fileIndex = ModuleRootManager.getInstance(module).getFileIndex(); - final GlobalSearchScope srcRootScope = GlobalSearchScope.moduleScope(module).intersectWith(GlobalSearchScope.directoryScope(myProject, sourceRoot, true)); + final GlobalSearchScope srcRootScope = GlobalSearchScope.moduleScope(module).intersectWith( + GlobalSearchScopes.directoryScope(myProject, sourceRoot, true)); final ContentIterator contentIterator = new ContentIterator() { public boolean processFile(final VirtualFile child) { diff --git a/java/java-impl/src/com/intellij/codeInspection/unusedLibraries/UnusedLibrariesInspection.java b/java/java-impl/src/com/intellij/codeInspection/unusedLibraries/UnusedLibrariesInspection.java index 177b52540e65..27f8765d911d 100644 --- a/java/java-impl/src/com/intellij/codeInspection/unusedLibraries/UnusedLibrariesInspection.java +++ b/java/java-impl/src/com/intellij/codeInspection/unusedLibraries/UnusedLibrariesInspection.java @@ -48,6 +48,7 @@ import com.intellij.psi.PsiCompiledElement; import com.intellij.psi.PsiFile; import com.intellij.psi.PsiRecursiveElementVisitor; import com.intellij.psi.search.GlobalSearchScope; +import com.intellij.psi.search.GlobalSearchScopes; import com.intellij.psi.search.scope.packageSet.NamedScope; import com.intellij.psi.search.scope.packageSet.PackageSetFactory; import com.intellij.psi.search.scope.packageSet.ParsingException; @@ -94,7 +95,7 @@ public class UnusedLibrariesInspection extends DescriptorProviderInspection { GlobalSearchScope searchScope; try { @NonNls final String libsName = "libs"; - searchScope = GlobalSearchScope.filterScope(project, new NamedScope(libsName, PackageSetFactory.getInstance().compile("lib:*..*"))); + searchScope = GlobalSearchScopes.filterScope(project, new NamedScope(libsName, PackageSetFactory.getInstance().compile("lib:*..*"))); } catch (ParsingException e) { //can't be diff --git a/java/java-impl/src/com/intellij/psi/impl/source/PsiJavaFileImpl.java b/java/java-impl/src/com/intellij/psi/impl/source/PsiJavaFileImpl.java index 7dd47f61f9b0..f491e6407f9e 100644 --- a/java/java-impl/src/com/intellij/psi/impl/source/PsiJavaFileImpl.java +++ b/java/java-impl/src/com/intellij/psi/impl/source/PsiJavaFileImpl.java @@ -28,6 +28,7 @@ import com.intellij.psi.PsiElementFactory; import com.intellij.psi.PsiPackageStatement; import com.intellij.psi.impl.java.stubs.JavaStubElementTypes; import com.intellij.psi.search.GlobalSearchScope; +import com.intellij.psi.search.GlobalSearchScopes; import com.intellij.util.IncorrectOperationException; import com.intellij.testFramework.LightVirtualFile; import org.jetbrains.annotations.NotNull; @@ -52,7 +53,7 @@ public class PsiJavaFileImpl extends PsiJavaFileBaseImpl { if (file != null && !(file instanceof LightVirtualFile)) { final ProjectFileIndex index = ProjectRootManager.getInstance(getProject()).getFileIndex(); if (!index.isInSource(file) && !index.isInLibraryClasses(file)) { - return GlobalSearchScope.fileScope(this); + return GlobalSearchScopes.fileScope(this); } } return super.getResolveScope(); diff --git a/java/java-impl/src/com/intellij/refactoring/typeMigration/ui/TypeMigrationDialog.java b/java/java-impl/src/com/intellij/refactoring/typeMigration/ui/TypeMigrationDialog.java index 8ffdffd2c6a8..edbb70b0756c 100644 --- a/java/java-impl/src/com/intellij/refactoring/typeMigration/ui/TypeMigrationDialog.java +++ b/java/java-impl/src/com/intellij/refactoring/typeMigration/ui/TypeMigrationDialog.java @@ -31,7 +31,7 @@ import com.intellij.openapi.util.Comparing; import com.intellij.openapi.util.Disposer; import com.intellij.pom.java.LanguageLevel; import com.intellij.psi.*; -import com.intellij.psi.search.GlobalSearchScope; +import com.intellij.psi.search.GlobalSearchScopes; import com.intellij.psi.search.searches.ReferencesSearch; import com.intellij.psi.util.PsiTreeUtil; import com.intellij.psi.util.PsiUtil; @@ -145,7 +145,7 @@ public class TypeMigrationDialog extends RefactoringDialog { if (VisibilityUtil.compare(VisibilityUtil.getVisibilityModifier(modifierList), PsiModifier.PRIVATE) < 0) return null; } - for (PsiReference reference : ReferencesSearch.search(root, GlobalSearchScope.fileScope(root.getContainingFile()))) { + for (PsiReference reference : ReferencesSearch.search(root, GlobalSearchScopes.fileScope(root.getContainingFile()))) { final PsiElement element = reference.getElement(); final PsiExpression expr = PsiTreeUtil.getParentOfType(element, PsiExpression.class, false); if (expr != null) { diff --git a/platform/lang-api/src/com/intellij/analysis/AnalysisScope.java b/platform/lang-api/src/com/intellij/analysis/AnalysisScope.java index 0613ad7247d3..d26c90300257 100644 --- a/platform/lang-api/src/com/intellij/analysis/AnalysisScope.java +++ b/platform/lang-api/src/com/intellij/analysis/AnalysisScope.java @@ -38,6 +38,7 @@ import com.intellij.openapi.vfs.VirtualFileFilter; import com.intellij.profile.ProjectProfileManager; import com.intellij.psi.*; import com.intellij.psi.search.GlobalSearchScope; +import com.intellij.psi.search.GlobalSearchScopes; import com.intellij.psi.search.LocalSearchScope; import com.intellij.psi.search.SearchScope; import com.intellij.util.ArrayUtil; @@ -637,14 +638,14 @@ public class AnalysisScope { case CUSTOM: return myScope; case DIRECTORY: - return GlobalSearchScope.directoryScope((PsiDirectory)myElement, true); + return GlobalSearchScopes.directoryScope((PsiDirectory)myElement, true); case FILE: return new LocalSearchScope(myElement); case INVALID: return LocalSearchScope.EMPTY; case MODULE: GlobalSearchScope moduleScope = GlobalSearchScope.moduleScope(myModule); - return myIncludeTestSource ? moduleScope : GlobalSearchScope.notScope(GlobalSearchScope.projectTestScope(myModule.getProject())).intersectWith(moduleScope); + return myIncludeTestSource ? moduleScope : GlobalSearchScope.notScope(GlobalSearchScopes.projectTestScope(myModule.getProject())).intersectWith(moduleScope); case MODULES: SearchScope scope = GlobalSearchScope.EMPTY_SCOPE; for (Module module : myModules) { @@ -652,7 +653,7 @@ public class AnalysisScope { } return scope; case PROJECT: - return myIncludeTestSource ? GlobalSearchScope.projectScope(myProject) : GlobalSearchScope.projectProductionScope(myProject); + return myIncludeTestSource ? GlobalSearchScope.projectScope(myProject) : GlobalSearchScopes.projectProductionScope(myProject); case VIRTUAL_FILES: return new GlobalSearchScope() { @Override diff --git a/platform/lang-api/src/com/intellij/psi/search/GlobalSearchScope.java b/platform/lang-api/src/com/intellij/psi/search/GlobalSearchScope.java index 7bde88aaab5a..46997bf6d60d 100644 --- a/platform/lang-api/src/com/intellij/psi/search/GlobalSearchScope.java +++ b/platform/lang-api/src/com/intellij/psi/search/GlobalSearchScope.java @@ -20,21 +20,15 @@ import com.intellij.openapi.fileTypes.FileType; import com.intellij.openapi.fileTypes.FileTypeManager; import com.intellij.openapi.module.Module; import com.intellij.openapi.project.Project; -import com.intellij.openapi.roots.ProjectFileIndex; -import com.intellij.openapi.roots.ProjectRootManager; -import com.intellij.openapi.util.Comparing; -import com.intellij.openapi.vfs.VfsUtil; import com.intellij.openapi.vfs.VirtualFile; -import com.intellij.psi.*; -import com.intellij.psi.search.scope.packageSet.*; -import com.intellij.psi.util.PsiUtilBase; +import com.intellij.psi.PsiBundle; +import com.intellij.psi.PsiElement; import com.intellij.util.ArrayUtil; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import java.util.ArrayList; import java.util.Arrays; -import java.util.Collection; import java.util.List; public abstract class GlobalSearchScope extends SearchScope implements ProjectAwareFileFilter { @@ -109,7 +103,7 @@ public abstract class GlobalSearchScope extends SearchScope implements ProjectAw result.add(element2); } } - return new LocalSearchScope(PsiUtilBase.toPsiElementArray(result), null, localScope2.isIgnoreInjectedPsi()); + return new LocalSearchScope(result.toArray(new PsiElement[result.size()]), null, localScope2.isIgnoreInjectedPsi()); } @NotNull @@ -161,22 +155,6 @@ public abstract class GlobalSearchScope extends SearchScope implements ProjectAw return ProjectScope.getProjectScope(project); } - public static GlobalSearchScope projectProductionScope(@NotNull Project project) { - return new IntersectionScope(projectScope(project), - new ProductionScopeFilter(project), - PsiBundle.message("psi.search.scope.production.files")); - } - - public static GlobalSearchScope projectTestScope(@NotNull Project project) { - return new IntersectionScope(projectScope(project), - new TestScopeFilter(project), - PsiBundle.message("psi.search.scope.test.files")); - } - - public static GlobalSearchScope filterScope(@NotNull Project project, @NotNull NamedScope set) { - return new FilterScopeAdapter(project, set); - } - public static GlobalSearchScope notScope(@NotNull final GlobalSearchScope scope) { return new DelegatingGlobalSearchScope(scope) { public boolean contains(final VirtualFile file) { @@ -240,33 +218,12 @@ public abstract class GlobalSearchScope extends SearchScope implements ProjectAw return module.getModuleWithDependentsScope(); } - public static GlobalSearchScope directoryScope(@NotNull PsiDirectory directory, final boolean withSubdirectories) { - return new DirectoryScope(directory, withSubdirectories); - } - - public static GlobalSearchScope directoryScope(@NotNull Project project, @NotNull VirtualFile directory, final boolean withSubdirectories) { - return new DirectoryScope(project, directory, withSubdirectories); - } - - public static GlobalSearchScope fileScope(@NotNull PsiFile psiFile) { - return new FileScope(psiFile.getProject(), psiFile.getVirtualFile()); - } - - public static GlobalSearchScope fileScope(final Project project, final VirtualFile virtualFile) { - return new FileScope(project, virtualFile); - } - - public static GlobalSearchScope filesScope(final Project project, final Collection files) { - if (files.isEmpty()) return EMPTY_SCOPE; - return files.size() == 1? fileScope(project, files.iterator().next()) : new FilesScope(project, files); - } - - private static class IntersectionScope extends GlobalSearchScope { + static class IntersectionScope extends GlobalSearchScope { private final GlobalSearchScope myScope1; private final GlobalSearchScope myScope2; private final String myDisplayName; - private IntersectionScope(@NotNull GlobalSearchScope scope1, @NotNull GlobalSearchScope scope2, String displayName) { + IntersectionScope(@NotNull GlobalSearchScope scope1, @NotNull GlobalSearchScope scope2, String displayName) { super(scope1.getProject() == null ? scope2.getProject() : scope1.getProject()); myScope1 = scope1; myScope2 = scope2; @@ -414,217 +371,6 @@ public abstract class GlobalSearchScope extends SearchScope implements ProjectAw } } - private static class ProductionScopeFilter extends GlobalSearchScope { - private final ProjectFileIndex myFileIndex; - - private ProductionScopeFilter(@NotNull Project project) { - super(project); - myFileIndex = ProjectRootManager.getInstance(project).getFileIndex(); - } - - public boolean contains(VirtualFile file) { - return myFileIndex.isInSourceContent(file) && !myFileIndex.isInTestSourceContent(file); - } - - public int compare(VirtualFile file1, VirtualFile file2) { - return 0; - } - - public boolean isSearchInModuleContent(@NotNull Module aModule) { - return true; - } - - public boolean isSearchInModuleContent(@NotNull final Module aModule, final boolean testSources) { - return !testSources; - } - - public boolean isSearchInLibraries() { - return false; - } - } - - private static class TestScopeFilter extends GlobalSearchScope { - private final ProjectFileIndex myFileIndex; - - private TestScopeFilter(@NotNull Project project) { - super(project); - myFileIndex = ProjectRootManager.getInstance(project).getFileIndex(); - } - - public boolean contains(VirtualFile file) { - return myFileIndex.isInTestSourceContent(file); - } - - public int compare(VirtualFile file1, VirtualFile file2) { - return 0; - } - - public boolean isSearchInModuleContent(@NotNull Module aModule) { - return true; - } - - public boolean isSearchInModuleContent(@NotNull final Module aModule, final boolean testSources) { - return testSources; - } - - public boolean isSearchInLibraries() { - return false; - } - } - - private static class DirectoryScope extends GlobalSearchScope { - private final VirtualFile myDirectory; - private final boolean myWithSubdirectories; - - private DirectoryScope(@NotNull PsiDirectory directory, final boolean withSubdirectories) { - super(directory.getProject()); - myWithSubdirectories = withSubdirectories; - myDirectory = directory.getVirtualFile(); - } - - private DirectoryScope(@NotNull Project project, @NotNull VirtualFile directory, final boolean withSubdirectories) { - super(project); - myWithSubdirectories = withSubdirectories; - myDirectory = directory; - } - - public boolean contains(VirtualFile file) { - if (myWithSubdirectories) { - return VfsUtil.isAncestor(myDirectory, file, false); - } - else { - return myDirectory.equals(file.getParent()); - } - } - - public int compare(VirtualFile file1, VirtualFile file2) { - return 0; - } - - public boolean isSearchInModuleContent(@NotNull Module aModule) { - return true; - } - - public boolean isSearchInLibraries() { - return false; - } - - public String toString() { - //noinspection HardCodedStringLiteral - return "directory scope: " + myDirectory + "; withSubdirs:"+myWithSubdirectories; - } - } - - private static class FileScope extends GlobalSearchScope { - private final VirtualFile myVirtualFile; - private final Module myModule; - - private FileScope(final Project project, final VirtualFile virtualFile) { - super(project); - myVirtualFile = virtualFile; - ProjectFileIndex fileIndex = ProjectRootManager.getInstance(project).getFileIndex(); - myModule = myVirtualFile != null ? fileIndex.getModuleForFile(myVirtualFile) : null; - } - - public boolean contains(VirtualFile file) { - return Comparing.equal(myVirtualFile, file); - } - - public int compare(VirtualFile file1, VirtualFile file2) { - return 0; - } - - public boolean isSearchInModuleContent(@NotNull Module aModule) { - return aModule == myModule; - } - - public boolean isSearchInLibraries() { - return myModule == null; - } - } - - private static class FilesScope extends GlobalSearchScope { - private final Collection myFiles; - - public FilesScope(final Project project, final Collection files) { - super(project); - myFiles = files; - } - - @Override - public boolean contains(final VirtualFile file) { - return myFiles.contains(file); - } - - @Override - public int compare(final VirtualFile file1, final VirtualFile file2) { - return 0; - } - - @Override - public boolean isSearchInModuleContent(@NotNull Module aModule) { - return true; - } - - @Override - public boolean isSearchInLibraries() { - return false; - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof FilesScope)) return false; - - return myFiles.equals(((FilesScope)o).myFiles); - } - - @Override - public int hashCode() { - return myFiles.hashCode(); - } - } - - private static class FilterScopeAdapter extends GlobalSearchScope { - private final NamedScope mySet; - private final PsiManager myManager; - - private FilterScopeAdapter(@NotNull Project project, @NotNull NamedScope set) { - super(project); - mySet = set; - myManager = PsiManager.getInstance(project); - } - - public boolean contains(VirtualFile file) { - NamedScopesHolder holder = NamedScopeManager.getInstance(getProject()); - final PackageSet packageSet = mySet.getValue(); - if (packageSet != null) { - if (packageSet instanceof PackageSetBase) return ((PackageSetBase)packageSet).contains(file, holder); - PsiFile psiFile = myManager.findFile(file); - if (psiFile == null) return false; - return packageSet.contains(psiFile, holder); - } - return false; - } - - public String getDisplayName() { - return mySet.getName(); - } - - public int compare(VirtualFile file1, VirtualFile file2) { - return 0; - - } - - public boolean isSearchInModuleContent(@NotNull Module aModule) { - return true; //TODO (optimization?) - } - - public boolean isSearchInLibraries() { - return true; //TODO (optimization?) - } - } - @NotNull public static GlobalSearchScope getScopeRestrictedByFileTypes (@NotNull GlobalSearchScope scope, final FileType... fileTypes) { LOG.assertTrue(fileTypes.length > 0); diff --git a/platform/lang-api/src/com/intellij/psi/search/GlobalSearchScopes.java b/platform/lang-api/src/com/intellij/psi/search/GlobalSearchScopes.java new file mode 100644 index 000000000000..e1e550aced24 --- /dev/null +++ b/platform/lang-api/src/com/intellij/psi/search/GlobalSearchScopes.java @@ -0,0 +1,288 @@ +/* + * Copyright 2000-2011 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.intellij.psi.search; + +import com.intellij.openapi.module.Module; +import com.intellij.openapi.project.Project; +import com.intellij.openapi.roots.ProjectFileIndex; +import com.intellij.openapi.roots.ProjectRootManager; +import com.intellij.openapi.util.Comparing; +import com.intellij.openapi.vfs.VfsUtil; +import com.intellij.openapi.vfs.VirtualFile; +import com.intellij.psi.PsiBundle; +import com.intellij.psi.PsiDirectory; +import com.intellij.psi.PsiFile; +import com.intellij.psi.PsiManager; +import com.intellij.psi.search.scope.packageSet.*; +import org.jetbrains.annotations.NotNull; + +import java.util.Collection; + +/** + * @author yole + */ +public class GlobalSearchScopes { + private GlobalSearchScopes() { + } + + public static GlobalSearchScope projectProductionScope(@NotNull Project project) { + return new GlobalSearchScope.IntersectionScope(GlobalSearchScope.projectScope(project), + new ProductionScopeFilter(project), + PsiBundle.message("psi.search.scope.production.files")); + } + + public static GlobalSearchScope projectTestScope(@NotNull Project project) { + return new GlobalSearchScope.IntersectionScope(GlobalSearchScope.projectScope(project), + new TestScopeFilter(project), + PsiBundle.message("psi.search.scope.test.files")); + } + + public static GlobalSearchScope directoryScope(@NotNull PsiDirectory directory, final boolean withSubdirectories) { + return new DirectoryScope(directory, withSubdirectories); + } + + public static GlobalSearchScope directoryScope(@NotNull Project project, @NotNull VirtualFile directory, final boolean withSubdirectories) { + return new DirectoryScope(project, directory, withSubdirectories); + } + + public static GlobalSearchScope fileScope(@NotNull PsiFile psiFile) { + return new FileScope(psiFile.getProject(), psiFile.getVirtualFile()); + } + + public static GlobalSearchScope fileScope(final Project project, final VirtualFile virtualFile) { + return new FileScope(project, virtualFile); + } + + public static GlobalSearchScope filesScope(final Project project, final Collection files) { + if (files.isEmpty()) return GlobalSearchScope.EMPTY_SCOPE; + return files.size() == 1? fileScope(project, files.iterator().next()) : new FilesScope(project, files); + } + + private static class FilterScopeAdapter extends GlobalSearchScope { + private final NamedScope mySet; + private final PsiManager myManager; + + private FilterScopeAdapter(@NotNull Project project, @NotNull NamedScope set) { + super(project); + mySet = set; + myManager = PsiManager.getInstance(project); + } + + public boolean contains(VirtualFile file) { + NamedScopesHolder holder = NamedScopeManager.getInstance(getProject()); + final PackageSet packageSet = mySet.getValue(); + if (packageSet != null) { + if (packageSet instanceof PackageSetBase) return ((PackageSetBase)packageSet).contains(file, holder); + PsiFile psiFile = myManager.findFile(file); + if (psiFile == null) return false; + return packageSet.contains(psiFile, holder); + } + return false; + } + + public String getDisplayName() { + return mySet.getName(); + } + + public int compare(VirtualFile file1, VirtualFile file2) { + return 0; + + } + + public boolean isSearchInModuleContent(@NotNull Module aModule) { + return true; //TODO (optimization?) + } + + public boolean isSearchInLibraries() { + return true; //TODO (optimization?) + } + } + + public static GlobalSearchScope filterScope(@NotNull Project project, @NotNull NamedScope set) { + return new FilterScopeAdapter(project, set); + } + + private static class ProductionScopeFilter extends GlobalSearchScope { + private final ProjectFileIndex myFileIndex; + + private ProductionScopeFilter(@NotNull Project project) { + super(project); + myFileIndex = ProjectRootManager.getInstance(project).getFileIndex(); + } + + public boolean contains(VirtualFile file) { + return myFileIndex.isInSourceContent(file) && !myFileIndex.isInTestSourceContent(file); + } + + public int compare(VirtualFile file1, VirtualFile file2) { + return 0; + } + + public boolean isSearchInModuleContent(@NotNull Module aModule) { + return true; + } + + public boolean isSearchInModuleContent(@NotNull final Module aModule, final boolean testSources) { + return !testSources; + } + + public boolean isSearchInLibraries() { + return false; + } + } + + private static class TestScopeFilter extends GlobalSearchScope { + private final ProjectFileIndex myFileIndex; + + private TestScopeFilter(@NotNull Project project) { + super(project); + myFileIndex = ProjectRootManager.getInstance(project).getFileIndex(); + } + + public boolean contains(VirtualFile file) { + return myFileIndex.isInTestSourceContent(file); + } + + public int compare(VirtualFile file1, VirtualFile file2) { + return 0; + } + + public boolean isSearchInModuleContent(@NotNull Module aModule) { + return true; + } + + public boolean isSearchInModuleContent(@NotNull final Module aModule, final boolean testSources) { + return testSources; + } + + public boolean isSearchInLibraries() { + return false; + } + } + + private static class DirectoryScope extends GlobalSearchScope { + private final VirtualFile myDirectory; + private final boolean myWithSubdirectories; + + private DirectoryScope(@NotNull PsiDirectory directory, final boolean withSubdirectories) { + super(directory.getProject()); + myWithSubdirectories = withSubdirectories; + myDirectory = directory.getVirtualFile(); + } + + private DirectoryScope(@NotNull Project project, @NotNull VirtualFile directory, final boolean withSubdirectories) { + super(project); + myWithSubdirectories = withSubdirectories; + myDirectory = directory; + } + + public boolean contains(VirtualFile file) { + if (myWithSubdirectories) { + return VfsUtil.isAncestor(myDirectory, file, false); + } + else { + return myDirectory.equals(file.getParent()); + } + } + + public int compare(VirtualFile file1, VirtualFile file2) { + return 0; + } + + public boolean isSearchInModuleContent(@NotNull Module aModule) { + return true; + } + + public boolean isSearchInLibraries() { + return false; + } + + public String toString() { + //noinspection HardCodedStringLiteral + return "directory scope: " + myDirectory + "; withSubdirs:"+myWithSubdirectories; + } + } + + private static class FileScope extends GlobalSearchScope { + private final VirtualFile myVirtualFile; + private final Module myModule; + + private FileScope(final Project project, final VirtualFile virtualFile) { + super(project); + myVirtualFile = virtualFile; + ProjectFileIndex fileIndex = ProjectRootManager.getInstance(project).getFileIndex(); + myModule = myVirtualFile != null ? fileIndex.getModuleForFile(myVirtualFile) : null; + } + + public boolean contains(VirtualFile file) { + return Comparing.equal(myVirtualFile, file); + } + + public int compare(VirtualFile file1, VirtualFile file2) { + return 0; + } + + public boolean isSearchInModuleContent(@NotNull Module aModule) { + return aModule == myModule; + } + + public boolean isSearchInLibraries() { + return myModule == null; + } + } + + private static class FilesScope extends GlobalSearchScope { + private final Collection myFiles; + + public FilesScope(final Project project, final Collection files) { + super(project); + myFiles = files; + } + + @Override + public boolean contains(final VirtualFile file) { + return myFiles.contains(file); + } + + @Override + public int compare(final VirtualFile file1, final VirtualFile file2) { + return 0; + } + + @Override + public boolean isSearchInModuleContent(@NotNull Module aModule) { + return true; + } + + @Override + public boolean isSearchInLibraries() { + return false; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (!(o instanceof FilesScope)) return false; + + return myFiles.equals(((FilesScope)o).myFiles); + } + + @Override + public int hashCode() { + return myFiles.hashCode(); + } + } +} diff --git a/platform/lang-impl/src/com/intellij/find/impl/FindInProjectUtil.java b/platform/lang-impl/src/com/intellij/find/impl/FindInProjectUtil.java index 71a459a6c037..0383f854bc5d 100644 --- a/platform/lang-impl/src/com/intellij/find/impl/FindInProjectUtil.java +++ b/platform/lang-impl/src/com/intellij/find/impl/FindInProjectUtil.java @@ -447,7 +447,7 @@ public class FindInProjectUtil { CacheManager cacheManager = ((PsiManagerEx)pm).getCacheManager(); SearchScope customScope = findModel.getCustomScope(); @NotNull GlobalSearchScope scope = psiDirectory != null - ? GlobalSearchScope.directoryScope(psiDirectory, true) + ? GlobalSearchScopes.directoryScope(psiDirectory, true) : module != null ? moduleContentScope(module) : customScope instanceof GlobalSearchScope @@ -534,7 +534,7 @@ public class FindInProjectUtil { for (VirtualFile root : contentRoots) { PsiDirectory directory = psiManager.findDirectory(root); if (directory != null) { - GlobalSearchScope moduleContent = GlobalSearchScope.directoryScope(directory, true); + GlobalSearchScope moduleContent = GlobalSearchScopes.directoryScope(directory, true); result = result == null ? moduleContent : result.uniteWith(moduleContent); } } diff --git a/platform/lang-impl/src/com/intellij/ide/hierarchy/HierarchyTreeStructure.java b/platform/lang-impl/src/com/intellij/ide/hierarchy/HierarchyTreeStructure.java index 12ca4c836848..dc8d8709ce97 100644 --- a/platform/lang-impl/src/com/intellij/ide/hierarchy/HierarchyTreeStructure.java +++ b/platform/lang-impl/src/com/intellij/ide/hierarchy/HierarchyTreeStructure.java @@ -25,6 +25,7 @@ import com.intellij.psi.PsiDocumentManager; import com.intellij.psi.PsiElement; import com.intellij.psi.PsiFile; import com.intellij.psi.search.GlobalSearchScope; +import com.intellij.psi.search.GlobalSearchScopes; import com.intellij.psi.search.LocalSearchScope; import com.intellij.psi.search.SearchScope; import com.intellij.psi.search.scope.packageSet.NamedScope; @@ -142,14 +143,14 @@ public abstract class HierarchyTreeStructure extends AbstractTreeStructure { searchScope = new LocalSearchScope(thisClass); } else if (HierarchyBrowserBaseEx.SCOPE_PROJECT.equals(scopeType)) { - searchScope = GlobalSearchScope.projectProductionScope(myProject); + searchScope = GlobalSearchScopes.projectProductionScope(myProject); } else if (HierarchyBrowserBaseEx.SCOPE_TEST.equals(scopeType)) { - searchScope = GlobalSearchScope.projectTestScope(myProject); + searchScope = GlobalSearchScopes.projectTestScope(myProject); } else { final NamedScope namedScope = NamedScopesHolder.getScope(myProject, scopeType); if (namedScope != null) { - searchScope = GlobalSearchScope.filterScope(myProject, namedScope); + searchScope = GlobalSearchScopes.filterScope(myProject, namedScope); } } return searchScope; diff --git a/platform/lang-impl/src/com/intellij/ide/util/PlatformPackageUtil.java b/platform/lang-impl/src/com/intellij/ide/util/PlatformPackageUtil.java index 62c13ef62938..4d152236e64a 100644 --- a/platform/lang-impl/src/com/intellij/ide/util/PlatformPackageUtil.java +++ b/platform/lang-impl/src/com/intellij/ide/util/PlatformPackageUtil.java @@ -35,6 +35,7 @@ import com.intellij.psi.PsiElement; import com.intellij.psi.PsiFile; import com.intellij.psi.PsiManager; import com.intellij.psi.search.GlobalSearchScope; +import com.intellij.psi.search.GlobalSearchScopes; import com.intellij.util.*; import com.intellij.util.containers.ContainerUtil; import org.jetbrains.annotations.NotNull; @@ -183,12 +184,12 @@ public class PlatformPackageUtil { final ProjectFileIndex fileIndex = ProjectRootManager.getInstance(baseDir.getProject()).getFileIndex(); if (fileIndex.isInTestSourceContent(baseDir.getVirtualFile())) { if (skipSourceDirsForBaseTestDirectory) { - return scope.intersectWith(GlobalSearchScope.projectTestScope(baseDir.getProject())); + return scope.intersectWith(GlobalSearchScopes.projectTestScope(baseDir.getProject())); } } else { if (skipTestDirsForBaseSourceDirectory) { - return scope.intersectWith(GlobalSearchScope.projectProductionScope(baseDir.getProject())); + return scope.intersectWith(GlobalSearchScopes.projectProductionScope(baseDir.getProject())); } } } diff --git a/platform/lang-impl/src/com/intellij/ide/util/scopeChooser/ScopeChooserCombo.java b/platform/lang-impl/src/com/intellij/ide/util/scopeChooser/ScopeChooserCombo.java index 7bc8fd2d72b3..de1fa0f00566 100644 --- a/platform/lang-impl/src/com/intellij/ide/util/scopeChooser/ScopeChooserCombo.java +++ b/platform/lang-impl/src/com/intellij/ide/util/scopeChooser/ScopeChooserCombo.java @@ -36,10 +36,7 @@ import com.intellij.psi.PsiDocumentManager; import com.intellij.psi.PsiElement; import com.intellij.psi.PsiFile; import com.intellij.psi.PsiWhiteSpace; -import com.intellij.psi.search.DelegatingGlobalSearchScope; -import com.intellij.psi.search.GlobalSearchScope; -import com.intellij.psi.search.LocalSearchScope; -import com.intellij.psi.search.SearchScope; +import com.intellij.psi.search.*; import com.intellij.psi.search.scope.packageSet.NamedScope; import com.intellij.psi.search.scope.packageSet.NamedScopeManager; import com.intellij.psi.search.scope.packageSet.NamedScopesHolder; @@ -165,13 +162,13 @@ public class ScopeChooserCombo extends ComboboxWithBrowseButton implements Dispo List changeLists = ChangeListsScopesProvider.getInstance(myProject).getCustomScopes(); for (NamedScope changeListScope : changeLists) { - model.addElement(new ScopeDescriptor(GlobalSearchScope.filterScope(myProject, changeListScope))); + model.addElement(new ScopeDescriptor(GlobalSearchScopes.filterScope(myProject, changeListScope))); } final NamedScopesHolder[] holders = NamedScopesHolder.getAllNamedScopeHolders(myProject); for (NamedScopesHolder holder : holders) { NamedScope[] scopes = holder.getEditableScopes(); //predefined scopes already included for (NamedScope scope : scopes) { - model.addElement(new ScopeDescriptor(GlobalSearchScope.filterScope(myProject, scope))); + model.addElement(new ScopeDescriptor(GlobalSearchScopes.filterScope(myProject, scope))); } } @@ -201,8 +198,8 @@ public class ScopeChooserCombo extends ComboboxWithBrowseButton implements Dispo if (suggestSearchInLibs) { result.add(GlobalSearchScope.allScope(project)); } - result.add(GlobalSearchScope.projectProductionScope(project)); - result.add(GlobalSearchScope.projectTestScope(project)); + result.add(GlobalSearchScopes.projectProductionScope(project)); + result.add(GlobalSearchScopes.projectTestScope(project)); if (dataContext != null) { PsiElement dataContextElement = getDataContextElement(dataContext); @@ -350,7 +347,7 @@ public class ScopeChooserCombo extends ComboboxWithBrowseButton implements Dispo final VirtualFile[] files = PlatformDataKeys.VIRTUAL_FILE_ARRAY.getData(dataContext); if (files != null) { final List openFiles = Arrays.asList(files); - result.add(new DelegatingGlobalSearchScope(GlobalSearchScope.filesScope(project, openFiles)){ + result.add(new DelegatingGlobalSearchScope(GlobalSearchScopes.filesScope(project, openFiles)){ @Override public String getDisplayName() { return "Selected files"; diff --git a/platform/lang-impl/src/com/intellij/psi/impl/cache/impl/IndexCacheManagerImpl.java b/platform/lang-impl/src/com/intellij/psi/impl/cache/impl/IndexCacheManagerImpl.java index 07a62799ea0e..2d63018bfa56 100644 --- a/platform/lang-impl/src/com/intellij/psi/impl/cache/impl/IndexCacheManagerImpl.java +++ b/platform/lang-impl/src/com/intellij/psi/impl/cache/impl/IndexCacheManagerImpl.java @@ -36,6 +36,7 @@ import com.intellij.psi.impl.cache.impl.id.IdIndexEntry; import com.intellij.psi.impl.cache.impl.todo.TodoIndex; import com.intellij.psi.impl.cache.impl.todo.TodoIndexEntry; import com.intellij.psi.search.GlobalSearchScope; +import com.intellij.psi.search.GlobalSearchScopes; import com.intellij.psi.search.IndexPattern; import com.intellij.psi.search.IndexPatternProvider; import com.intellij.psi.util.PsiUtilBase; @@ -188,7 +189,7 @@ public class IndexCacheManagerImpl implements CacheManager{ count[0] += value.intValue(); return true; } - }, GlobalSearchScope.fileScope(myProject, file)); + }, GlobalSearchScopes.fileScope(myProject, file)); return count[0]; } diff --git a/platform/lang-impl/src/com/intellij/psi/impl/file/impl/FileManagerImpl.java b/platform/lang-impl/src/com/intellij/psi/impl/file/impl/FileManagerImpl.java index a1fb032c7a78..638553369d2d 100644 --- a/platform/lang-impl/src/com/intellij/psi/impl/file/impl/FileManagerImpl.java +++ b/platform/lang-impl/src/com/intellij/psi/impl/file/impl/FileManagerImpl.java @@ -47,6 +47,7 @@ import com.intellij.psi.impl.smartPointers.SmartPointerManagerImpl; import com.intellij.psi.impl.source.PsiFileImpl; import com.intellij.psi.impl.source.resolve.FileContextUtil; import com.intellij.psi.search.GlobalSearchScope; +import com.intellij.psi.search.GlobalSearchScopes; import com.intellij.psi.search.SearchScope; import com.intellij.util.ConcurrencyUtil; import com.intellij.util.FileContentUtil; @@ -480,7 +481,7 @@ public class FileManagerImpl implements FileManager { final VirtualFile vf = f == null ? null : f.getVirtualFile(); return f == null || vf == null || vf.isDirectory() || allScope.contains(vf) - ? allScope : GlobalSearchScope.fileScope(f).uniteWith(allScope); + ? allScope : GlobalSearchScopes.fileScope(f).uniteWith(allScope); } } diff --git a/platform/lang-impl/src/com/intellij/psi/stubs/StubTree.java b/platform/lang-impl/src/com/intellij/psi/stubs/StubTree.java index 14a04b93b02d..b45f7df53397 100644 --- a/platform/lang-impl/src/com/intellij/psi/stubs/StubTree.java +++ b/platform/lang-impl/src/com/intellij/psi/stubs/StubTree.java @@ -27,7 +27,7 @@ import com.intellij.openapi.fileEditor.FileDocumentManager; import com.intellij.openapi.project.DumbService; import com.intellij.openapi.project.Project; import com.intellij.openapi.vfs.VirtualFile; -import com.intellij.psi.search.GlobalSearchScope; +import com.intellij.psi.search.GlobalSearchScopes; import com.intellij.util.indexing.FileBasedIndex; import com.intellij.util.indexing.FileContent; import com.intellij.util.indexing.FileContentImpl; @@ -133,7 +133,8 @@ public class StubTree { final int id = Math.abs(FileBasedIndex.getFileId(vFile)); if (id > 0) { - final List datas = FileBasedIndex.getInstance().getValues(StubUpdatingIndex.INDEX_ID, id, GlobalSearchScope.fileScope(project, vFile)); + final List datas = FileBasedIndex.getInstance().getValues(StubUpdatingIndex.INDEX_ID, id, GlobalSearchScopes + .fileScope(project, vFile)); final int size = datas.size(); if (size == 1) { diff --git a/plugins/InspectionGadgets/src/com/siyeh/ig/maturity/ObsoleteCollectionInspection.java b/plugins/InspectionGadgets/src/com/siyeh/ig/maturity/ObsoleteCollectionInspection.java index c99600adb7d4..4d6de46f0887 100644 --- a/plugins/InspectionGadgets/src/com/siyeh/ig/maturity/ObsoleteCollectionInspection.java +++ b/plugins/InspectionGadgets/src/com/siyeh/ig/maturity/ObsoleteCollectionInspection.java @@ -16,7 +16,7 @@ package com.siyeh.ig.maturity; import com.intellij.psi.*; -import com.intellij.psi.search.GlobalSearchScope; +import com.intellij.psi.search.GlobalSearchScopes; import com.intellij.psi.search.searches.ReferencesSearch; import com.intellij.psi.util.PsiTreeUtil; import com.intellij.util.Query; @@ -150,7 +150,7 @@ public class ObsoleteCollectionInspection extends BaseInspection { final PsiFile containingFile = namedElement.getContainingFile(); final Query query = ReferencesSearch.search(namedElement, - GlobalSearchScope.fileScope(containingFile)); + GlobalSearchScopes.fileScope(containingFile)); for (PsiReference reference : query) { final PsiElement element = reference.getElement(); if (isRequiredObsoleteCollectionElement(element)) { diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/findUsages/GroovyConstructorUsagesSearcher.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/findUsages/GroovyConstructorUsagesSearcher.java index cdd8870a25df..425261b0e149 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/findUsages/GroovyConstructorUsagesSearcher.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/findUsages/GroovyConstructorUsagesSearcher.java @@ -201,7 +201,8 @@ public class GroovyConstructorUsagesSearcher extends QueryExecutorBase Date: Fri, 19 Aug 2011 19:56:42 +0400 Subject: [PATCH 37/78] use FileTypeRegistry instead of FileTypeManager --- .../src/com/intellij/psi/search/GlobalSearchScope.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/platform/lang-api/src/com/intellij/psi/search/GlobalSearchScope.java b/platform/lang-api/src/com/intellij/psi/search/GlobalSearchScope.java index 46997bf6d60d..d5c664fac9b3 100644 --- a/platform/lang-api/src/com/intellij/psi/search/GlobalSearchScope.java +++ b/platform/lang-api/src/com/intellij/psi/search/GlobalSearchScope.java @@ -17,7 +17,7 @@ package com.intellij.psi.search; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.fileTypes.FileType; -import com.intellij.openapi.fileTypes.FileTypeManager; +import com.intellij.openapi.fileTypes.FileTypeRegistry; import com.intellij.openapi.module.Module; import com.intellij.openapi.project.Project; import com.intellij.openapi.vfs.VirtualFile; @@ -388,7 +388,7 @@ public abstract class GlobalSearchScope extends SearchScope implements ProjectAw public boolean contains(VirtualFile file) { if (!super.contains(file)) return false; - final FileType fileType = FileTypeManager.getInstance().getFileTypeByFile(file); + final FileType fileType = FileTypeRegistry.getInstance().getFileTypeByFile(file); for (FileType otherFileType : myFileTypes) { if (fileType.equals(otherFileType)) return true; } From 08c71ffebd320a2adc2dcb4a3ef996b415f6a9be Mon Sep 17 00:00:00 2001 From: Dmitry Jemerov Date: Fri, 19 Aug 2011 20:06:02 +0400 Subject: [PATCH 38/78] use ProgressIndicatorProvider instead of ProgressManager in PSI API --- .../lang-api/src/com/intellij/psi/PsiElementVisitor.java | 3 ++- .../src/com/intellij/psi/PsiRecursiveElementVisitor.java | 6 +++--- .../com/intellij/psi/PsiRecursiveElementWalkingVisitor.java | 4 ++-- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/platform/lang-api/src/com/intellij/psi/PsiElementVisitor.java b/platform/lang-api/src/com/intellij/psi/PsiElementVisitor.java index d5d662916159..5367e935bd1d 100644 --- a/platform/lang-api/src/com/intellij/psi/PsiElementVisitor.java +++ b/platform/lang-api/src/com/intellij/psi/PsiElementVisitor.java @@ -15,6 +15,7 @@ */ package com.intellij.psi; +import com.intellij.openapi.progress.ProgressIndicatorProvider; import com.intellij.openapi.progress.ProgressManager; import com.intellij.psi.templateLanguages.OuterLanguageElement; @@ -25,7 +26,7 @@ import com.intellij.psi.templateLanguages.OuterLanguageElement; */ public abstract class PsiElementVisitor { public void visitElement(PsiElement element) { - ProgressManager.checkCanceled(); + ProgressIndicatorProvider.checkCanceled(); } public void visitFile(PsiFile file) { diff --git a/platform/lang-api/src/com/intellij/psi/PsiRecursiveElementVisitor.java b/platform/lang-api/src/com/intellij/psi/PsiRecursiveElementVisitor.java index 6ec50dd49f4f..000d3ee4037e 100644 --- a/platform/lang-api/src/com/intellij/psi/PsiRecursiveElementVisitor.java +++ b/platform/lang-api/src/com/intellij/psi/PsiRecursiveElementVisitor.java @@ -15,7 +15,7 @@ */ package com.intellij.psi; -import com.intellij.openapi.progress.ProgressManager; +import com.intellij.openapi.progress.ProgressIndicatorProvider; import java.util.List; @@ -35,7 +35,7 @@ public abstract class PsiRecursiveElementVisitor extends PsiElementVisitor { } public void visitElement(final PsiElement element) { - ProgressManager.checkCanceled(); + ProgressIndicatorProvider.checkCanceled(); element.acceptChildren(this); } @@ -47,7 +47,7 @@ public abstract class PsiRecursiveElementVisitor extends PsiElementVisitor { if (allFiles.size() > 1) { if (file == viewProvider.getPsi(viewProvider.getBaseLanguage())) { for (PsiFile lFile : allFiles) { - ProgressManager.checkCanceled(); + ProgressIndicatorProvider.checkCanceled(); lFile.acceptChildren(this); } return; diff --git a/platform/lang-api/src/com/intellij/psi/PsiRecursiveElementWalkingVisitor.java b/platform/lang-api/src/com/intellij/psi/PsiRecursiveElementWalkingVisitor.java index 344a6a739287..8309829cf393 100644 --- a/platform/lang-api/src/com/intellij/psi/PsiRecursiveElementWalkingVisitor.java +++ b/platform/lang-api/src/com/intellij/psi/PsiRecursiveElementWalkingVisitor.java @@ -15,7 +15,7 @@ */ package com.intellij.psi; -import com.intellij.openapi.progress.ProgressManager; +import com.intellij.openapi.progress.ProgressIndicatorProvider; import org.jetbrains.annotations.NotNull; import java.util.List; @@ -41,7 +41,7 @@ public abstract class PsiRecursiveElementWalkingVisitor extends PsiElementVisito } public void visitElement(final PsiElement element) { - ProgressManager.checkCanceled(); + ProgressIndicatorProvider.checkCanceled(); myWalkingState.elementStarted(element); } From 4d8c37b4d841f1bea235bdeceabcd501f8b8ca8a Mon Sep 17 00:00:00 2001 From: Dmitry Jemerov Date: Fri, 19 Aug 2011 20:06:53 +0400 Subject: [PATCH 39/78] optimize imports --- platform/lang-api/src/com/intellij/psi/PsiElementVisitor.java | 1 - 1 file changed, 1 deletion(-) diff --git a/platform/lang-api/src/com/intellij/psi/PsiElementVisitor.java b/platform/lang-api/src/com/intellij/psi/PsiElementVisitor.java index 5367e935bd1d..da0d1127efb1 100644 --- a/platform/lang-api/src/com/intellij/psi/PsiElementVisitor.java +++ b/platform/lang-api/src/com/intellij/psi/PsiElementVisitor.java @@ -16,7 +16,6 @@ package com.intellij.psi; import com.intellij.openapi.progress.ProgressIndicatorProvider; -import com.intellij.openapi.progress.ProgressManager; import com.intellij.psi.templateLanguages.OuterLanguageElement; /** From 7c55c56d91b9125abf382d7d0b082d973fd469ca Mon Sep 17 00:00:00 2001 From: Dmitry Jemerov Date: Fri, 19 Aug 2011 20:14:12 +0400 Subject: [PATCH 40/78] don't expose specific type in API --- java/java-impl/src/com/intellij/psi/ClassFileViewProvider.java | 3 ++- platform/lang-api/src/com/intellij/psi/FileViewProvider.java | 3 +-- .../src/com/intellij/psi/DummyHolderViewProvider.java | 3 ++- .../psi/MultiplePsiFilesPerDocumentFileViewProvider.java | 3 ++- .../src/com/intellij/psi/SingleRootFileViewProvider.java | 3 ++- 5 files changed, 9 insertions(+), 6 deletions(-) diff --git a/java/java-impl/src/com/intellij/psi/ClassFileViewProvider.java b/java/java-impl/src/com/intellij/psi/ClassFileViewProvider.java index 9628111f74e5..cba11dd3caa3 100644 --- a/java/java-impl/src/com/intellij/psi/ClassFileViewProvider.java +++ b/java/java-impl/src/com/intellij/psi/ClassFileViewProvider.java @@ -56,7 +56,8 @@ public class ClassFileViewProvider extends SingleRootFileViewProvider { } @NotNull - public SingleRootFileViewProvider createCopy(final LightVirtualFile copy) { + @Override + public SingleRootFileViewProvider createCopy(final VirtualFile copy) { return new ClassFileViewProvider(getManager(), copy, false); } } \ No newline at end of file diff --git a/platform/lang-api/src/com/intellij/psi/FileViewProvider.java b/platform/lang-api/src/com/intellij/psi/FileViewProvider.java index ae9d4dafb3c7..ac646747f19e 100644 --- a/platform/lang-api/src/com/intellij/psi/FileViewProvider.java +++ b/platform/lang-api/src/com/intellij/psi/FileViewProvider.java @@ -19,7 +19,6 @@ import com.intellij.lang.Language; import com.intellij.openapi.editor.Document; import com.intellij.openapi.util.UserDataHolder; import com.intellij.openapi.vfs.VirtualFile; -import com.intellij.testFramework.LightVirtualFile; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -81,5 +80,5 @@ public interface FileViewProvider extends Cloneable, UserDataHolder { boolean isLockedByPsiOperations(); @NotNull - FileViewProvider createCopy(LightVirtualFile copy); + FileViewProvider createCopy(VirtualFile copy); } diff --git a/platform/lang-impl/src/com/intellij/psi/DummyHolderViewProvider.java b/platform/lang-impl/src/com/intellij/psi/DummyHolderViewProvider.java index cb0c4342970c..1a7a7e1d7517 100644 --- a/platform/lang-impl/src/com/intellij/psi/DummyHolderViewProvider.java +++ b/platform/lang-impl/src/com/intellij/psi/DummyHolderViewProvider.java @@ -141,7 +141,8 @@ public class DummyHolderViewProvider extends UserDataHolderBase implements FileV } @NotNull - public FileViewProvider createCopy(final LightVirtualFile copy) { + @Override + public FileViewProvider createCopy(final VirtualFile copy) { throw new RuntimeException("Clone is not supported for DummyHolderProviders. Use DummyHolder clone directly."); } diff --git a/platform/lang-impl/src/com/intellij/psi/MultiplePsiFilesPerDocumentFileViewProvider.java b/platform/lang-impl/src/com/intellij/psi/MultiplePsiFilesPerDocumentFileViewProvider.java index 68e9a0e19b28..b47360c3f1eb 100644 --- a/platform/lang-impl/src/com/intellij/psi/MultiplePsiFilesPerDocumentFileViewProvider.java +++ b/platform/lang-impl/src/com/intellij/psi/MultiplePsiFilesPerDocumentFileViewProvider.java @@ -123,7 +123,8 @@ public abstract class MultiplePsiFilesPerDocumentFileViewProvider extends Single } @NotNull - public final MultiplePsiFilesPerDocumentFileViewProvider createCopy(final LightVirtualFile fileCopy) { + @Override + public final MultiplePsiFilesPerDocumentFileViewProvider createCopy(final VirtualFile fileCopy) { final MultiplePsiFilesPerDocumentFileViewProvider copy = cloneInner(fileCopy); copy.myOriginal = myOriginal == null ? this : myOriginal; return copy; diff --git a/platform/lang-impl/src/com/intellij/psi/SingleRootFileViewProvider.java b/platform/lang-impl/src/com/intellij/psi/SingleRootFileViewProvider.java index 3ff629e7e250..094062b4c51c 100644 --- a/platform/lang-impl/src/com/intellij/psi/SingleRootFileViewProvider.java +++ b/platform/lang-impl/src/com/intellij/psi/SingleRootFileViewProvider.java @@ -337,7 +337,8 @@ public class SingleRootFileViewProvider extends UserDataHolderBase implements Fi } @NotNull - public SingleRootFileViewProvider createCopy(final LightVirtualFile copy) { + @Override + public SingleRootFileViewProvider createCopy(final VirtualFile copy) { return new SingleRootFileViewProvider(getManager(), copy, false, myBaseLanguage); } From 103c0084bac774b7e3860798b4c382e2e17ef3a4 Mon Sep 17 00:00:00 2001 From: Dmitry Jemerov Date: Fri, 19 Aug 2011 20:16:13 +0400 Subject: [PATCH 41/78] unused import --- platform/lang-api/src/com/intellij/psi/PsiReference.java | 1 - 1 file changed, 1 deletion(-) diff --git a/platform/lang-api/src/com/intellij/psi/PsiReference.java b/platform/lang-api/src/com/intellij/psi/PsiReference.java index b73db89ac638..b1012da42688 100644 --- a/platform/lang-api/src/com/intellij/psi/PsiReference.java +++ b/platform/lang-api/src/com/intellij/psi/PsiReference.java @@ -17,7 +17,6 @@ package com.intellij.psi; import com.intellij.openapi.util.TextRange; import com.intellij.util.IncorrectOperationException; -import com.intellij.codeInsight.lookup.LookupElement; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; From 505e1dec16f739532d54548d0bb95d0074c38f6f Mon Sep 17 00:00:00 2001 From: Alexander Doroshko Date: Fri, 19 Aug 2011 22:22:38 +0400 Subject: [PATCH 42/78] Flex IDE settings (initial) --- .../ProjectStructureConfigurable.java | 6 +- .../BaseStructureConfigurable.java | 57 +++++++---- .../ModuleStructureConfigurable.java | 96 ++++++++++++++++++- .../projectRoot/ModuleStructureExtension.java | 60 ++++++++++++ resources/src/idea/RichPlatformPlugin.xml | 1 + 5 files changed, 193 insertions(+), 27 deletions(-) create mode 100644 java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/projectRoot/ModuleStructureExtension.java diff --git a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/ProjectStructureConfigurable.java b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/ProjectStructureConfigurable.java index 1db3b05fecf3..cfaf748cf0ea 100644 --- a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/ProjectStructureConfigurable.java +++ b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/ProjectStructureConfigurable.java @@ -68,7 +68,7 @@ public class ProjectStructureConfigurable extends BaseConfigurable implements Se private final UIState myUiState = new UIState(); private Splitter mySplitter; private JComponent myToolbarComponent; - @NonNls private static final String CATEGORY = "category"; + @NonNls public static final String CATEGORY = "category"; private JComponent myToFocus; private boolean myWasUiDisposed; private ConfigurationErrorsComponent myErrorsComponent; @@ -324,6 +324,10 @@ public class ProjectStructureConfigurable extends BaseConfigurable implements Se } } + public void hideSidePanel() { + mySplitter.getFirstComponent().setVisible(false); + } + public void disposeUIResources() { if (!myWasIntialized) return; final PropertiesComponent propertiesComponent = PropertiesComponent.getInstance(myProject); diff --git a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/projectRoot/BaseStructureConfigurable.java b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/projectRoot/BaseStructureConfigurable.java index 604ef4b11b02..ec95a460d317 100644 --- a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/projectRoot/BaseStructureConfigurable.java +++ b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/projectRoot/BaseStructureConfigurable.java @@ -368,12 +368,7 @@ public abstract class BaseStructureConfigurable extends MasterDetailsComponent i if (object instanceof MyNode) { final NamedConfigurable namedConfigurable = ((MyNode)object).getConfigurable(); if (namedConfigurable != null) { - final Object editableObject = namedConfigurable.getEditableObject(); - if (editableObject instanceof Sdk || editableObject instanceof Module || editableObject instanceof Facet || editableObject instanceof Artifact) return true; - if (editableObject instanceof Library) { - final LibraryTable table = ((Library)editableObject).getTable(); - return table == null || table.isEditable(); - } + return canBeRemoved(namedConfigurable.getEditableObject()); } } return false; @@ -402,23 +397,43 @@ public abstract class BaseStructureConfigurable extends MasterDetailsComponent i final MyNode node = (MyNode)last; final NamedConfigurable configurable = node.getConfigurable(); final Object editableObject = configurable.getEditableObject(); - if (editableObject instanceof Sdk) { - removeJdk((Sdk)editableObject); - } - else if (editableObject instanceof Module) { - if (!removeModule((Module)editableObject)) return false; - } - else if (editableObject instanceof Facet) { - if (removeFacet((Facet)editableObject).isEmpty()) return false; - } - else if (editableObject instanceof Library) { - if (!removeLibrary((Library)editableObject)) return false; - } - else if (editableObject instanceof Artifact) { - removeArtifact((Artifact)editableObject); - } + + return removeObject(editableObject); + } + } + + protected boolean canBeRemoved(final Object editableObject) { + if (editableObject instanceof Sdk || + editableObject instanceof Module || + editableObject instanceof Facet || + editableObject instanceof Artifact) { return true; } + if (editableObject instanceof Library) { + final LibraryTable table = ((Library)editableObject).getTable(); + return table == null || table.isEditable(); + } + return false; + } + + protected boolean removeObject(final Object editableObject) { + // todo keep only removeModule() and removeFacet() here because other removeXXX() are empty here and overridden in subclasses? Override removeObject() instead? + if (editableObject instanceof Sdk) { + removeJdk((Sdk)editableObject); + } + else if (editableObject instanceof Module) { + if (!removeModule((Module)editableObject)) return false; + } + else if (editableObject instanceof Facet) { + if (removeFacet((Facet)editableObject).isEmpty()) return false; + } + else if (editableObject instanceof Library) { + if (!removeLibrary((Library)editableObject)) return false; + } + else if (editableObject instanceof Artifact) { + removeArtifact((Artifact)editableObject); + } + return true; } protected void removeArtifact(Artifact artifact) { diff --git a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/projectRoot/ModuleStructureConfigurable.java b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/projectRoot/ModuleStructureConfigurable.java index f3fbc2e4c43c..86d81c7e6abe 100644 --- a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/projectRoot/ModuleStructureConfigurable.java +++ b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/projectRoot/ModuleStructureConfigurable.java @@ -54,6 +54,7 @@ import com.intellij.openapi.ui.DialogWrapper; import com.intellij.openapi.ui.Messages; import com.intellij.openapi.ui.NamedConfigurable; import com.intellij.openapi.util.Comparing; +import com.intellij.openapi.util.Computable; import com.intellij.openapi.util.IconLoader; import com.intellij.openapi.util.text.StringUtil; import com.intellij.openapi.vfs.LocalFileSystem; @@ -218,8 +219,9 @@ public class ModuleStructureConfigurable extends BaseStructureConfigurable imple for (final Module module : modules) { ModuleConfigurable configurable = new ModuleConfigurable(myContext.myModulesConfigurator, module, TREE_UPDATER); final MyNode moduleNode = new MyNode(configurable); - final boolean facetsExist = myFacetEditorFacade.addFacetsNodes(module, moduleNode); - if (facetsExist) { + boolean nodesAdded = myFacetEditorFacade.addFacetsNodes(module, moduleNode); + nodesAdded |= addNodesFromExtensions(module, moduleNode); + if (nodesAdded) { myTree.setShowsRootHandles(true); } final String[] groupPath = myPlainMode ? null : myContext.myModulesConfigurator.getModuleModel().getModuleGroupPath(module); @@ -254,6 +256,14 @@ public class ModuleStructureConfigurable extends BaseStructureConfigurable imple //myProjectNode.add(myLevel2Nodes.get(LibraryTablesRegistrar.PROJECT_LEVEL)); } + private boolean addNodesFromExtensions(final Module module, final MyNode moduleNode) { + boolean nodesAdded= false; + for (final ModuleStructureExtension extension : ModuleStructureExtension.EP_NAME.getExtensions()) { + nodesAdded |= extension.addModuleNodeChildren(module, moduleNode, TREE_UPDATER); + } + return nodesAdded; + } + public boolean updateProjectTree(final Module[] modules, final ModuleGroup group) { if (myRoot.getChildCount() == 0) return false; //isn't visible final MyNode [] nodes = new MyNode[modules.length]; @@ -290,6 +300,7 @@ public class ModuleStructureConfigurable extends BaseStructureConfigurable imple addNode(moduleNode, moduleGroupNode); } myFacetEditorFacade.addFacetsNodes((Module)moduleNode.getConfigurable().getEditableObject(), moduleNode); + addNodesFromExtensions((Module)moduleNode.getConfigurable().getEditableObject(), moduleNode); } ((DefaultTreeModel)myTree.getModel()).reload(myRoot); return true; @@ -326,6 +337,9 @@ public class ModuleStructureConfigurable extends BaseStructureConfigurable imple public void reset() { super.reset(); + for (final ModuleStructureExtension extension : ModuleStructureExtension.EP_NAME.getExtensions()) { + extension.reset(); + } } @@ -335,10 +349,24 @@ public class ModuleStructureConfigurable extends BaseStructureConfigurable imple checkApply(roots, ProjectBundle.message("rename.message.prefix.module"), ProjectBundle.message("rename.module.title")); if (myContext.myModulesConfigurator.isModified()) myContext.myModulesConfigurator.apply(); + + for (final ModuleStructureExtension extension : ModuleStructureExtension.EP_NAME.getExtensions()) { + extension.apply(); + } } public boolean isModified() { - return myContext.myModulesConfigurator.isModified(); + if (myContext.myModulesConfigurator.isModified()) { + return true; + } + + for (final ModuleStructureExtension extension : ModuleStructureExtension.EP_NAME.getExtensions()) { + if (extension.isModified()) { + return true; + } + } + + return false; } public void disposeUIResources() { @@ -346,6 +374,10 @@ public class ModuleStructureConfigurable extends BaseStructureConfigurable imple myFacetEditorFacade.clearMaps(true); myContext.myModulesConfigurator.disposeUIResources(); ModuleStructureConfigurable.super.disposeUIResources(); + + for (final ModuleStructureExtension extension : ModuleStructureExtension.EP_NAME.getExtensions()) { + extension.disposeUIResources(); + } } public void dispose() {} @@ -494,6 +526,7 @@ public class ModuleStructureConfigurable extends BaseStructureConfigurable imple if (parent == null) parent = myRoot; addNode(node, parent); myFacetEditorFacade.addFacetsNodes(module, node); + addNodesFromExtensions(module, node); ((DefaultTreeModel)myTree.getModel()).reload(parent); selectNodeInTree(node); final ProjectStructureDaemonAnalyzer daemonAnalyzer = myContext.getDaemonAnalyzer(); @@ -545,6 +578,43 @@ public class ModuleStructureConfigurable extends BaseStructureConfigurable imple PlatformIcons.OPENED_MODULE_GROUP_ICON, PlatformIcons.CLOSED_MODULE_GROUP_ICON); } + protected boolean canBeRemoved(final Object editableObject) { + if (super.canBeRemoved(editableObject)) { + return true; + } + for (final ModuleStructureExtension extension : ModuleStructureExtension.EP_NAME.getExtensions()) { + if (extension.canBeRemoved(editableObject)) { + return true; + } + } + + return false; + } + + protected boolean removeObject(final Object editableObject) { + for (final ModuleStructureExtension extension : ModuleStructureExtension.EP_NAME.getExtensions()) { + if (extension.removeObject(editableObject)) { + return true; + } + } + return super.removeObject(editableObject); + } + + private boolean canBeCopiedByExtension(final NamedConfigurable confugurable) { + for (final ModuleStructureExtension extension : ModuleStructureExtension.EP_NAME.getExtensions()) { + if (extension.canBeCopied(confugurable)) { + return true; + } + } + return false; + } + + private void copyByExtension(final NamedConfigurable configurable) { + for (final ModuleStructureExtension extension : ModuleStructureExtension.EP_NAME.getExtensions()) { + extension.copy(configurable, TREE_UPDATER); + } + } + private class MyDataProviderWrapper extends JPanel implements DataProvider { public MyDataProviderWrapper(final JComponent component) { super(new BorderLayout()); @@ -659,6 +729,15 @@ public class ModuleStructureConfigurable extends BaseStructureConfigurable imple result.addAll(libraryActions); } + final Computable selectedObjectRetriever = new Computable() { + public Object compute() { + return getSelectedObject(); + } + }; + for (final ModuleStructureExtension extension : ModuleStructureExtension.EP_NAME.getExtensions()) { + result.addAll(extension.createAddActions(selectedObjectRetriever, TREE_UPDATER)); + } + return result.toArray(new AnAction[result.size()]); } }; @@ -679,6 +758,10 @@ public class ModuleStructureConfigurable extends BaseStructureConfigurable imple List removed = modulesConfigurator.getFacetsConfigurator().removeAllFacets(module); FacetStructureConfigurable.getInstance(myProject).removeFacetNodes(removed); myContext.getDaemonAnalyzer().removeElement(new ModuleProjectStructureElement(myContext, module)); + + for (final ModuleStructureExtension extension : ModuleStructureExtension.EP_NAME.getExtensions()) { + extension.moduleRemoved(module); + } return true; } @@ -785,6 +868,9 @@ public class ModuleStructureConfigurable extends BaseStructureConfigurable imple LOG.error(e1); } } + else { + copyByExtension(namedConfigurable); + } } public void update(final AnActionEvent e) { @@ -792,12 +878,12 @@ public class ModuleStructureConfigurable extends BaseStructureConfigurable imple if (selectionPaths == null || selectionPaths.length != 1) { e.getPresentation().setEnabled(false); } else { - e.getPresentation().setEnabled(getSelectedConfugurable() instanceof ModuleConfigurable); + final NamedConfigurable selectedConfigurable = getSelectedConfugurable(); + e.getPresentation().setEnabled(selectedConfigurable instanceof ModuleConfigurable || canBeCopiedByExtension(selectedConfigurable)); } } } - private class AddModuleAction extends AnAction implements DumbAware { public AddModuleAction() { super(ProjectBundle.message("add.new.module.text.full"), null, IconLoader.getIcon("/actions/modul.png")); diff --git a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/projectRoot/ModuleStructureExtension.java b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/projectRoot/ModuleStructureExtension.java new file mode 100644 index 000000000000..c4dc15da4b9b --- /dev/null +++ b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/projectRoot/ModuleStructureExtension.java @@ -0,0 +1,60 @@ +package com.intellij.openapi.roots.ui.configuration.projectRoot; + +import com.intellij.openapi.actionSystem.AnAction; +import com.intellij.openapi.extensions.ExtensionPointName; +import com.intellij.openapi.module.Module; +import com.intellij.openapi.options.ConfigurationException; +import com.intellij.openapi.ui.MasterDetailsComponent; +import com.intellij.openapi.ui.NamedConfigurable; +import com.intellij.openapi.util.Computable; + +import java.util.Collection; +import java.util.Collections; + +public abstract class ModuleStructureExtension { + + public static final ExtensionPointName EP_NAME = + ExtensionPointName.create("com.intellij.configuration.ModuleStructureExtension"); + + public void reset() { + } + + public boolean addModuleNodeChildren(Module module, MasterDetailsComponent.MyNode moduleNode, Runnable treeNodeNameUpdater) { + return false; + } + + //public void moduleAdded(final Module module, final Runnable treeNodeNameUpdater) { + //} + + public void moduleRemoved(final Module module) { + } + + public boolean isModified() { + return false; + } + + public void apply() throws ConfigurationException { + } + + public void disposeUIResources() { + } + + public boolean canBeRemoved(final Object editableObject) { + return false; + } + + public boolean removeObject(final Object editableObject) { + return false; + } + + public Collection createAddActions(final Computable selectedObjectRetriever, final Runnable treeNodeNameUpdater) { + return Collections.emptyList(); + } + + public boolean canBeCopied(final NamedConfigurable confugurable) { + return false; + } + + public void copy(final NamedConfigurable confugurable, final Runnable treeNodeNameUpdater) { + } +} diff --git a/resources/src/idea/RichPlatformPlugin.xml b/resources/src/idea/RichPlatformPlugin.xml index 111ede4a6194..1ae56a9e8d54 100644 --- a/resources/src/idea/RichPlatformPlugin.xml +++ b/resources/src/idea/RichPlatformPlugin.xml @@ -88,6 +88,7 @@ + From 0729b111f20699a63f68ca3974fd05608943df8f Mon Sep 17 00:00:00 2001 From: Bas Leijdekkers Date: Fri, 19 Aug 2011 20:49:53 +0200 Subject: [PATCH 43/78] fix natural compare for string with big numbers --- .../openapi/util/text/StringUtil.java | 37 +++++++++++++------ .../intellij/util/text/StringUtilTest.java | 2 +- 2 files changed, 27 insertions(+), 12 deletions(-) diff --git a/platform/util/src/com/intellij/openapi/util/text/StringUtil.java b/platform/util/src/com/intellij/openapi/util/text/StringUtil.java index 776f513229a6..924f215f57b9 100644 --- a/platform/util/src/com/intellij/openapi/util/text/StringUtil.java +++ b/platform/util/src/com/intellij/openapi/util/text/StringUtil.java @@ -1971,19 +1971,34 @@ public class StringUtil { final int string1Length = string1.length(); final int string2Length = string2.length(); for(int i = 0, j = 0; i < string1Length && j < string2Length; i++, j++) { - final char ch1 = string1.charAt(i); - final char ch2 = string2.charAt(j); - if (isDigit(ch1) && isDigit(ch2)) { + char ch1 = string1.charAt(i); + char ch2 = string2.charAt(j); + if ((isDigit(ch1) || ch1 == ' ') && (isDigit(ch2) || ch2 == ' ')) { int startNum1 = i; + while (ch1 == ' ' || ch1 == '0') { // skip leading spaces and zeros + startNum1++; + if (startNum1 >= string1Length) break; + ch1 = string1.charAt(startNum1); + } int startNum2 = j; - i++; - j++; + while (ch2 == ' ' || ch2 == '0') { + startNum2++; + if (startNum2 >= string2Length) break; + ch2 = string2.charAt(startNum2); + } + i = startNum1; + j = startNum2; while (i < string1Length && isDigit(string1.charAt(i))) i++; while (j < string2Length && isDigit(string2.charAt(j))) j++; - final int difference = Integer.parseInt(string1.substring(startNum1, i)) - - Integer.parseInt(string2.substring(startNum2, j)); - if (difference != 0) { - return difference; + final int lengthDiff = (i - startNum1) - (j - startNum2); + if (lengthDiff != 0) { + return lengthDiff; + } + for (; startNum1 < i; startNum1++, startNum2++) { + final int diff = string1.charAt(startNum1) - string2.charAt(startNum2); + if (diff != 0) { + return diff; + } } } else { if (caseSensitive) { @@ -2007,8 +2022,8 @@ public class StringUtil { return string1Length - string2Length; } - public static boolean isDigit(char c) { - return c >= '0' && c <= '9'; + private static boolean isDigit(char c) { + return (c >= '0' && c <= '9'); } public static int compare(@Nullable String s1, @Nullable String s2, boolean ignoreCase) { diff --git a/platform/util/testSrc/com/intellij/util/text/StringUtilTest.java b/platform/util/testSrc/com/intellij/util/text/StringUtilTest.java index 721b81254c63..92dd9046dfb6 100644 --- a/platform/util/testSrc/com/intellij/util/text/StringUtilTest.java +++ b/platform/util/testSrc/com/intellij/util/text/StringUtilTest.java @@ -81,7 +81,7 @@ public class StringUtilTest extends TestCase { } }; Collections.sort(strings, c); - assertEquals(Arrays.asList("1.2.9.1", "1.2.10.5", "tes0", "test", "test 3", "test0", "test1", "test2", "test10", "test10a", + assertEquals(Arrays.asList("1.2.9.1", "1.2.10.5", "tes0", "test", "test0", "test1", "test2", "test 3", "test10", "test10a", "test011", "Test99", "test99", "testing"), strings); final List strings2 = new ArrayList(Arrays.asList("t1", "t001", "T2", "T002", "T1", "t2")); Collections.sort(strings2, c); From 65134a292a95566cf1c338886b24719b3617fe56 Mon Sep 17 00:00:00 2001 From: Bas Leijdekkers Date: Fri, 19 Aug 2011 21:03:59 +0200 Subject: [PATCH 44/78] test --- platform/util/testSrc/com/intellij/util/text/StringUtilTest.java | 1 + 1 file changed, 1 insertion(+) diff --git a/platform/util/testSrc/com/intellij/util/text/StringUtilTest.java b/platform/util/testSrc/com/intellij/util/text/StringUtilTest.java index 92dd9046dfb6..7fcf7e528165 100644 --- a/platform/util/testSrc/com/intellij/util/text/StringUtilTest.java +++ b/platform/util/testSrc/com/intellij/util/text/StringUtilTest.java @@ -86,5 +86,6 @@ public class StringUtilTest extends TestCase { final List strings2 = new ArrayList(Arrays.asList("t1", "t001", "T2", "T002", "T1", "t2")); Collections.sort(strings2, c); assertEquals(Arrays.asList("T1", "t1", "t001", "T2", "t2", "T002"), strings2); + assertEquals(1 ,StringUtil.naturalCompare("7403515080361171695", "07403515080361171694")); } } From 9ccddbfdadff44170792255a91047c2efd0533f0 Mon Sep 17 00:00:00 2001 From: anna Date: Fri, 19 Aug 2011 21:00:36 +0200 Subject: [PATCH 45/78] very big and long compilation fix --- platform/lang-api/src/com/intellij/psi/PsiManager.java | 3 +++ .../src/com/intellij/psi/search/GlobalSearchScope.java | 3 +++ .../platform-api/src/com/intellij/openapi/vfs/VfsUtil.java | 2 +- 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/platform/lang-api/src/com/intellij/psi/PsiManager.java b/platform/lang-api/src/com/intellij/psi/PsiManager.java index 706979e4d128..ca2d5e3b521e 100644 --- a/platform/lang-api/src/com/intellij/psi/PsiManager.java +++ b/platform/lang-api/src/com/intellij/psi/PsiManager.java @@ -20,6 +20,8 @@ import com.intellij.openapi.project.Project; import com.intellij.openapi.util.Computable; import com.intellij.openapi.util.UserDataHolderBase; import com.intellij.openapi.vfs.VirtualFile; +import com.intellij.psi.codeStyle.CodeStyleManager; +import com.intellij.psi.search.PsiSearchHelper; import com.intellij.psi.util.CachedValuesManager; import com.intellij.psi.util.PsiModificationTracker; import com.intellij.util.IncorrectOperationException; @@ -31,6 +33,7 @@ import org.jetbrains.annotations.Nullable; * The main entry point for accessing the PSI services for a project. */ public abstract class PsiManager extends UserDataHolderBase { + /** * Returns the PSI manager instance for the specified project. * diff --git a/platform/lang-api/src/com/intellij/psi/search/GlobalSearchScope.java b/platform/lang-api/src/com/intellij/psi/search/GlobalSearchScope.java index d5c664fac9b3..053f16ffafa7 100644 --- a/platform/lang-api/src/com/intellij/psi/search/GlobalSearchScope.java +++ b/platform/lang-api/src/com/intellij/psi/search/GlobalSearchScope.java @@ -23,6 +23,8 @@ import com.intellij.openapi.project.Project; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.psi.PsiBundle; import com.intellij.psi.PsiElement; +import com.intellij.psi.PsiFile; +import com.intellij.psi.search.scope.packageSet.NamedScope; import com.intellij.util.ArrayUtil; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -30,6 +32,7 @@ import org.jetbrains.annotations.Nullable; import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import java.util.Set; public abstract class GlobalSearchScope extends SearchScope implements ProjectAwareFileFilter { private static final Logger LOG = Logger.getInstance("#com.intellij.psi.search.GlobalSearchScope"); diff --git a/platform/platform-api/src/com/intellij/openapi/vfs/VfsUtil.java b/platform/platform-api/src/com/intellij/openapi/vfs/VfsUtil.java index e612fe0a7d06..032c6e4ee7bc 100644 --- a/platform/platform-api/src/com/intellij/openapi/vfs/VfsUtil.java +++ b/platform/platform-api/src/com/intellij/openapi/vfs/VfsUtil.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2011 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. From 3f144f08b4f31ff5a5a77e088fc1ea2ef39bda4f Mon Sep 17 00:00:00 2001 From: anna Date: Thu, 18 Aug 2011 13:18:40 +0200 Subject: [PATCH 46/78] move instance methods: leave this refs inside anonymous classes untouched (IDEA-71575) --- .../move/MoveInstanceMembersUtil.java | 2 +- .../MoveInstanceMethodProcessor.java | 2 +- .../moveInstanceMethod/ThisInAnonymous.java | 16 ++++++++++++++++ .../ThisInAnonymous.java.after | 17 +++++++++++++++++ .../moveMethod/MoveInstanceMethodTest.java | 2 ++ 5 files changed, 37 insertions(+), 2 deletions(-) create mode 100644 java/java-tests/testData/refactoring/moveInstanceMethod/ThisInAnonymous.java create mode 100644 java/java-tests/testData/refactoring/moveInstanceMethod/ThisInAnonymous.java.after diff --git a/java/java-impl/src/com/intellij/refactoring/move/MoveInstanceMembersUtil.java b/java/java-impl/src/com/intellij/refactoring/move/MoveInstanceMembersUtil.java index 597855ed0128..826e88980865 100644 --- a/java/java-impl/src/com/intellij/refactoring/move/MoveInstanceMembersUtil.java +++ b/java/java-impl/src/com/intellij/refactoring/move/MoveInstanceMembersUtil.java @@ -61,7 +61,7 @@ public class MoveInstanceMembersUtil { if (expression instanceof PsiThisExpression) { final PsiJavaCodeReferenceElement thisQualifier = ((PsiThisExpression)expression).getQualifier(); PsiClass thisClass = thisQualifier == null ? PsiTreeUtil.getParentOfType(expression, PsiClass.class, true) : ((PsiClass)thisQualifier.resolve()); - if (thisClass != null) { + if (thisClass != null && !PsiTreeUtil.isAncestor( refMember,thisClass, false)) { addReferencedMember(map, thisClass, null); } } diff --git a/java/java-impl/src/com/intellij/refactoring/move/moveInstanceMethod/MoveInstanceMethodProcessor.java b/java/java-impl/src/com/intellij/refactoring/move/moveInstanceMethod/MoveInstanceMethodProcessor.java index a67d424c2c3c..ba3a15a58e89 100644 --- a/java/java-impl/src/com/intellij/refactoring/move/moveInstanceMethod/MoveInstanceMethodProcessor.java +++ b/java/java-impl/src/com/intellij/refactoring/move/moveInstanceMethod/MoveInstanceMethodProcessor.java @@ -372,7 +372,7 @@ public class MoveInstanceMethodProcessor extends BaseRefactoringProcessor{ body.accept(new JavaRecursiveElementVisitor() { @Override public void visitThisExpression(PsiThisExpression expression) { final PsiClass classReferencedByThis = MoveInstanceMembersUtil.getClassReferencedByThis(expression); - if (classReferencedByThis != null) { + if (classReferencedByThis != null && !PsiTreeUtil.isAncestor(myMethod, classReferencedByThis, false)) { final PsiElementFactory factory = JavaPsiFacade.getInstance(myProject).getElementFactory(); String paramName = getParameterNameToCreate(classReferencedByThis); try { diff --git a/java/java-tests/testData/refactoring/moveInstanceMethod/ThisInAnonymous.java b/java/java-tests/testData/refactoring/moveInstanceMethod/ThisInAnonymous.java new file mode 100644 index 000000000000..875475dc3657 --- /dev/null +++ b/java/java-tests/testData/refactoring/moveInstanceMethod/ThisInAnonymous.java @@ -0,0 +1,16 @@ +public class Test { + private void prepareAnonymousClasses(JetElement aClass) { + aClass.acceptChildren(new JetVisitor() { + public void visitJetElement(JetElement element) { + element.acceptChildren(this); + } + }); + } +} + + +class JetElement { + void acceptChildren(JetVisitor v) {} +} + +class JetVisitor {} \ No newline at end of file diff --git a/java/java-tests/testData/refactoring/moveInstanceMethod/ThisInAnonymous.java.after b/java/java-tests/testData/refactoring/moveInstanceMethod/ThisInAnonymous.java.after new file mode 100644 index 000000000000..918098f6df17 --- /dev/null +++ b/java/java-tests/testData/refactoring/moveInstanceMethod/ThisInAnonymous.java.after @@ -0,0 +1,17 @@ +public class Test { +} + + +class JetElement { + void acceptChildren(JetVisitor v) {} + + private void prepareAnonymousClasses() { + acceptChildren(new JetVisitor() { + public void visitJetElement(JetElement element) { + element.acceptChildren(this); + } + }); + } +} + +class JetVisitor {} \ No newline at end of file diff --git a/java/java-tests/testSrc/com/intellij/refactoring/moveMethod/MoveInstanceMethodTest.java b/java/java-tests/testSrc/com/intellij/refactoring/moveMethod/MoveInstanceMethodTest.java index b03fb6f22442..6ee17f90bba2 100644 --- a/java/java-tests/testSrc/com/intellij/refactoring/moveMethod/MoveInstanceMethodTest.java +++ b/java/java-tests/testSrc/com/intellij/refactoring/moveMethod/MoveInstanceMethodTest.java @@ -47,6 +47,8 @@ public class MoveInstanceMethodTest extends LightCodeInsightTestCase { public void testIDEADEV11257() throws Exception { doTest(true, 0); } + public void testThisInAnonymous() throws Exception { doTest(true, 0); } + public void testEscalateVisibility() throws Exception { doTest(true, 0, VisibilityUtil.ESCALATE_VISIBILITY); } From a02dca8ecad634dba364ab8393389f44f52a7f7a Mon Sep 17 00:00:00 2001 From: anna Date: Thu, 18 Aug 2011 14:19:11 +0200 Subject: [PATCH 47/78] allow to create field inside static inner class when outer class has the field with the same name (IDEA-71841) --- .../daemon/impl/analysis/HighlightUtil.java | 3 +++ .../impl/quickfix/CreateFieldFromUsageFix.java | 6 ------ .../impl/quickfix/CreateVarFromUsageFix.java | 4 ++-- .../afterInsideStaticInnerClass.java | 14 ++++++++++++++ .../beforeInsideStaticInnerClass.java | 12 ++++++++++++ .../daemon/quickFix/CreateFieldFromUsageTest.java | 1 + 6 files changed, 32 insertions(+), 8 deletions(-) create mode 100644 java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/createFieldFromUsage/afterInsideStaticInnerClass.java create mode 100644 java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/createFieldFromUsage/beforeInsideStaticInnerClass.java diff --git a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/analysis/HighlightUtil.java b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/analysis/HighlightUtil.java index 5c276d0cd9cd..4c8d53375291 100644 --- a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/analysis/HighlightUtil.java +++ b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/analysis/HighlightUtil.java @@ -1168,6 +1168,9 @@ public class HighlightUtil { if (staticParent != null && isInstanceReference(place)) { QuickFixAction.registerQuickFixAction(errorResult, QUICK_FIX_FACTORY.createModifierListFix(staticParent, PsiModifier.STATIC, false, false)); } + if (place instanceof PsiReferenceExpression && refElement instanceof PsiField) { + QuickFixAction.registerQuickFixAction(errorResult, new CreateFieldFromUsageFix((PsiReferenceExpression)place)); + } } private static boolean isInstanceReference(PsiJavaCodeReferenceElement place) { diff --git a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/CreateFieldFromUsageFix.java b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/CreateFieldFromUsageFix.java index 20ec50c5225a..85ea2a611336 100644 --- a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/CreateFieldFromUsageFix.java +++ b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/CreateFieldFromUsageFix.java @@ -22,7 +22,6 @@ import com.intellij.codeInsight.template.Template; import com.intellij.codeInsight.template.TemplateBuilderImpl; import com.intellij.codeInsight.template.TemplateEditingAdapter; import com.intellij.openapi.application.ApplicationManager; -import com.intellij.openapi.command.undo.UndoUtil; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.editor.Editor; import com.intellij.openapi.project.Project; @@ -32,7 +31,6 @@ import com.intellij.psi.codeStyle.CodeStyleManager; import com.intellij.psi.impl.source.codeStyle.CodeEditUtil; import com.intellij.psi.util.PsiTreeUtil; import com.intellij.psi.util.PsiUtil; -import com.intellij.util.IncorrectOperationException; import org.jetbrains.annotations.NotNull; /** @@ -54,10 +52,6 @@ public class CreateFieldFromUsageFix extends CreateVarFromUsageFix { } protected void invokeImpl(final PsiClass targetClass) { - if (CreateFromUsageUtils.isValidReference(myReferenceExpression, true)) { - return; - } - final Project project = myReferenceExpression.getProject(); PsiElementFactory factory = JavaPsiFacade.getInstance(project).getElementFactory(); diff --git a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/CreateVarFromUsageFix.java b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/CreateVarFromUsageFix.java index bf5bb7c82284..7833c300205b 100644 --- a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/CreateVarFromUsageFix.java +++ b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/CreateVarFromUsageFix.java @@ -37,7 +37,7 @@ public abstract class CreateVarFromUsageFix extends CreateFromUsageBaseFix { protected boolean isValidElement(PsiElement element) { PsiReferenceExpression expression = (PsiReferenceExpression) element; - return CreateFromUsageUtils.isValidReference(expression, true); + return CreateFromUsageUtils.isValidReference(expression, false); } protected PsiElement getElement() { @@ -48,7 +48,7 @@ public abstract class CreateVarFromUsageFix extends CreateFromUsageBaseFix { if (parent instanceof PsiMethodCallExpression) return null; if (myReferenceExpression.getReferenceNameElement() != null) { - if (!CreateFromUsageUtils.isValidReference(myReferenceExpression, true)) { + if (!CreateFromUsageUtils.isValidReference(myReferenceExpression, false)) { return myReferenceExpression; } } diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/createFieldFromUsage/afterInsideStaticInnerClass.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/createFieldFromUsage/afterInsideStaticInnerClass.java new file mode 100644 index 000000000000..1477ec14a8d6 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/createFieldFromUsage/afterInsideStaticInnerClass.java @@ -0,0 +1,14 @@ +// "Create Field 'field'" "true" +class A { + String field; + + static class Foo { + private Object field; + + Foo() { + field; + } + } + +} + diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/createFieldFromUsage/beforeInsideStaticInnerClass.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/createFieldFromUsage/beforeInsideStaticInnerClass.java new file mode 100644 index 000000000000..607a2a3e36af --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/createFieldFromUsage/beforeInsideStaticInnerClass.java @@ -0,0 +1,12 @@ +// "Create Field 'field'" "true" +class A { + String field; + + static class Foo { + Foo() { + field; + } + } + +} + diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/quickFix/CreateFieldFromUsageTest.java b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/quickFix/CreateFieldFromUsageTest.java index 723a940f256e..a6531805e1df 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/quickFix/CreateFieldFromUsageTest.java +++ b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/quickFix/CreateFieldFromUsageTest.java @@ -18,6 +18,7 @@ public class CreateFieldFromUsageTest extends LightQuickFixTestCase{ public void testParametericMethod() throws Exception { doSingleTest(); } public void testQualifyInner() throws Exception { doSingleTest(); } public void testTypeArgsFormatted() throws Exception { doSingleTest(); } + public void testInsideStaticInnerClass() throws Exception { doSingleTest(); } public void testSortByRelevance() throws Exception { new WriteCommandAction(getProject()) { From f9318c277854c253e34ca3bf42ac2dcf826d3fc9 Mon Sep 17 00:00:00 2001 From: anna Date: Thu, 18 Aug 2011 15:01:22 +0200 Subject: [PATCH 48/78] live templates: provide code insight during editing (IDEA-71378) --- .../template/JavaCodeContextType.java | 14 ++++++++ .../template/TemplateContextType.java | 7 ++++ .../template/impl/EditTemplateDialog.java | 2 +- .../template/impl/TemplateEditorUtil.java | 32 +++++++++++++++++-- 4 files changed, 51 insertions(+), 4 deletions(-) diff --git a/java/java-impl/src/com/intellij/codeInsight/template/JavaCodeContextType.java b/java/java-impl/src/com/intellij/codeInsight/template/JavaCodeContextType.java index 20cec001fc04..8f9126648094 100644 --- a/java/java-impl/src/com/intellij/codeInsight/template/JavaCodeContextType.java +++ b/java/java-impl/src/com/intellij/codeInsight/template/JavaCodeContextType.java @@ -16,11 +16,15 @@ package com.intellij.codeInsight.template; import com.intellij.codeInsight.CodeInsightBundle; +import com.intellij.ide.DataManager; import com.intellij.ide.highlighter.JavaFileHighlighter; import com.intellij.lang.StdLanguages; +import com.intellij.openapi.actionSystem.PlatformDataKeys; +import com.intellij.openapi.editor.Document; import com.intellij.openapi.fileTypes.FileType; import com.intellij.openapi.fileTypes.StdFileTypes; import com.intellij.openapi.fileTypes.SyntaxHighlighter; +import com.intellij.openapi.project.Project; import com.intellij.psi.*; import com.intellij.psi.util.PsiTreeUtil; import com.intellij.psi.util.PsiUtilBase; @@ -62,4 +66,14 @@ public class JavaCodeContextType extends TemplateContextType { return new JavaFileHighlighter(); } + @Override + public Document createDocument(CharSequence text, Project project) { + if (project == null) { + return super.createDocument(text, project); + } + final JavaPsiFacade psiFacade = JavaPsiFacade.getInstance(project); + final PsiElementFactory factory = psiFacade.getElementFactory(); + final JavaCodeFragment fragment = factory.createCodeBlockCodeFragment((String)text, psiFacade.findPackage(""), true); + return PsiDocumentManager.getInstance(project).getDocument(fragment); + } } diff --git a/platform/lang-impl/src/com/intellij/codeInsight/template/TemplateContextType.java b/platform/lang-impl/src/com/intellij/codeInsight/template/TemplateContextType.java index 126f263248ac..bd17c61d48f0 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/template/TemplateContextType.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/template/TemplateContextType.java @@ -16,9 +16,12 @@ package com.intellij.codeInsight.template; +import com.intellij.openapi.editor.Document; +import com.intellij.openapi.editor.EditorFactory; import com.intellij.openapi.extensions.ExtensionPointName; import com.intellij.openapi.fileTypes.FileType; import com.intellij.openapi.fileTypes.SyntaxHighlighter; +import com.intellij.openapi.project.Project; import com.intellij.psi.PsiFile; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; @@ -77,4 +80,8 @@ public abstract class TemplateContextType { public TemplateContextType getBaseContextType() { return myBaseContextType != null ? EP_NAME.findExtension(myBaseContextType) : null; } + + public Document createDocument(CharSequence text, Project project) { + return EditorFactory.getInstance().createDocument(text); + } } diff --git a/platform/lang-impl/src/com/intellij/codeInsight/template/impl/EditTemplateDialog.java b/platform/lang-impl/src/com/intellij/codeInsight/template/impl/EditTemplateDialog.java index b8c14eda4145..2d2a464ab025 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/template/impl/EditTemplateDialog.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/template/impl/EditTemplateDialog.java @@ -88,7 +88,7 @@ public class EditTemplateDialog extends DialogWrapper { myKeyField=new JTextField(); myDescription=new JTextField(); myGroupCombo=new ComboBox(-1); - myTemplateEditor = TemplateEditorUtil.createEditor(false, myTemplate.getString()); + myTemplateEditor = TemplateEditorUtil.createEditor(false, myTemplate.getString(), context); init(); reset(); diff --git a/platform/lang-impl/src/com/intellij/codeInsight/template/impl/TemplateEditorUtil.java b/platform/lang-impl/src/com/intellij/codeInsight/template/impl/TemplateEditorUtil.java index 17f88f199c63..4d219df8e294 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/template/impl/TemplateEditorUtil.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/template/impl/TemplateEditorUtil.java @@ -17,9 +17,11 @@ package com.intellij.codeInsight.template.impl; import com.intellij.codeInsight.template.TemplateContextType; +import com.intellij.ide.DataManager; import com.intellij.lexer.CompositeLexer; import com.intellij.lexer.Lexer; import com.intellij.lexer.MergingLexerAdapter; +import com.intellij.openapi.actionSystem.PlatformDataKeys; import com.intellij.openapi.editor.Document; import com.intellij.openapi.editor.Editor; import com.intellij.openapi.editor.EditorFactory; @@ -33,15 +35,39 @@ import com.intellij.openapi.editor.ex.util.LexerEditorHighlighter; import com.intellij.openapi.fileTypes.PlainSyntaxHighlighter; import com.intellij.openapi.fileTypes.SyntaxHighlighter; import com.intellij.openapi.fileTypes.SyntaxHighlighterBase; +import com.intellij.openapi.project.Project; import com.intellij.psi.tree.IElementType; import com.intellij.psi.tree.TokenSet; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.util.Map; public class TemplateEditorUtil { - public static Editor createEditor(boolean isReadOnly, final CharSequence text) { + private TemplateEditorUtil() {} + + public static Editor createEditor(boolean isReadOnly, CharSequence text) { + return createEditor(isReadOnly, text, null); + } + + public static Editor createEditor(boolean isReadOnly, CharSequence text, @Nullable Map context) { + Document doc = EditorFactory.getInstance().createDocument(text); + final Project project = PlatformDataKeys.PROJECT.getData(DataManager.getInstance().getDataContext()); + if (context != null) { + for (Map.Entry entry : context.entrySet()) { + if (entry.getValue()) { + doc = entry.getKey().createDocument(text, project); + break; + } + } + } + + return createEditor(isReadOnly, doc, project); + } + + private static Editor createEditor(boolean isReadOnly, final Document document, final Project project) { EditorFactory editorFactory = EditorFactory.getInstance(); - Document doc = editorFactory.createDocument(text); - Editor editor = (isReadOnly ? editorFactory.createViewer(doc) : editorFactory.createEditor(doc)); + Editor editor = (isReadOnly ? editorFactory.createViewer(document, project) : editorFactory.createEditor(document, project)); EditorSettings editorSettings = editor.getSettings(); editorSettings.setVirtualSpace(false); From 21b905537996e3fa487861bf45fa9a60c0b9a3a5 Mon Sep 17 00:00:00 2001 From: anna Date: Thu, 18 Aug 2011 21:24:33 +0200 Subject: [PATCH 49/78] replace old style Assert (leave fqns in file after last fix if any) IDEA-70790 --- .../com/siyeh/ig/InspectionGadgetsPlugin.java | 1 + .../junit/UseOfObsoleteAssertInspection.java | 221 ++++++++++++++++++ .../extendsTestCase.after.java | 9 + .../useOfObsoleteAssert/extendsTestCase.java | 8 + .../onDemandStaticImport.after.java | 10 + .../onDemandStaticImport.java | 8 + .../singleStaticAccess.after.java | 7 + .../singleStaticAccess.java | 7 + .../staticAccess.after.java | 8 + .../useOfObsoleteAssert/staticAccess.java | 8 + .../staticImport.after.java | 10 + .../useOfObsoleteAssert/staticImport.java | 8 + .../UseOfObsoleteAssertInspectionTest.java | 66 ++++++ 13 files changed, 371 insertions(+) create mode 100644 plugins/InspectionGadgets/src/com/siyeh/ig/junit/UseOfObsoleteAssertInspection.java create mode 100644 plugins/InspectionGadgets/test/com/siyeh/igfixes/junit/useOfObsoleteAssert/extendsTestCase.after.java create mode 100644 plugins/InspectionGadgets/test/com/siyeh/igfixes/junit/useOfObsoleteAssert/extendsTestCase.java create mode 100644 plugins/InspectionGadgets/test/com/siyeh/igfixes/junit/useOfObsoleteAssert/onDemandStaticImport.after.java create mode 100644 plugins/InspectionGadgets/test/com/siyeh/igfixes/junit/useOfObsoleteAssert/onDemandStaticImport.java create mode 100644 plugins/InspectionGadgets/test/com/siyeh/igfixes/junit/useOfObsoleteAssert/singleStaticAccess.after.java create mode 100644 plugins/InspectionGadgets/test/com/siyeh/igfixes/junit/useOfObsoleteAssert/singleStaticAccess.java create mode 100644 plugins/InspectionGadgets/test/com/siyeh/igfixes/junit/useOfObsoleteAssert/staticAccess.after.java create mode 100644 plugins/InspectionGadgets/test/com/siyeh/igfixes/junit/useOfObsoleteAssert/staticAccess.java create mode 100644 plugins/InspectionGadgets/test/com/siyeh/igfixes/junit/useOfObsoleteAssert/staticImport.after.java create mode 100644 plugins/InspectionGadgets/test/com/siyeh/igfixes/junit/useOfObsoleteAssert/staticImport.java create mode 100644 plugins/InspectionGadgets/testsrc/com/siyeh/ig/fixes/junit/UseOfObsoleteAssertInspectionTest.java diff --git a/plugins/InspectionGadgets/src/com/siyeh/ig/InspectionGadgetsPlugin.java b/plugins/InspectionGadgets/src/com/siyeh/ig/InspectionGadgetsPlugin.java index 78330d1cbdad..da077133c654 100644 --- a/plugins/InspectionGadgets/src/com/siyeh/ig/InspectionGadgetsPlugin.java +++ b/plugins/InspectionGadgets/src/com/siyeh/ig/InspectionGadgetsPlugin.java @@ -769,6 +769,7 @@ public class InspectionGadgetsPlugin implements ApplicationComponent, m_inspectionClasses.add(TestMethodIsPublicVoidNoArgInspection.class); m_inspectionClasses.add(TestMethodWithoutAssertionInspection.class); m_inspectionClasses.add(UnconstructableTestCaseInspection.class); + m_inspectionClasses.add(UseOfObsoleteAssertInspection.class); } private void registerJavaBeansInspections() { diff --git a/plugins/InspectionGadgets/src/com/siyeh/ig/junit/UseOfObsoleteAssertInspection.java b/plugins/InspectionGadgets/src/com/siyeh/ig/junit/UseOfObsoleteAssertInspection.java new file mode 100644 index 000000000000..856badaab4fc --- /dev/null +++ b/plugins/InspectionGadgets/src/com/siyeh/ig/junit/UseOfObsoleteAssertInspection.java @@ -0,0 +1,221 @@ +/* + * Copyright 2003-2011 Dave Griffith, Bas Leijdekkers + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.siyeh.ig.junit; + +import com.intellij.codeInspection.ProblemDescriptor; +import com.intellij.openapi.module.Module; +import com.intellij.openapi.module.ModuleUtil; +import com.intellij.openapi.project.Project; +import com.intellij.openapi.util.Comparing; +import com.intellij.psi.*; +import com.intellij.psi.codeStyle.JavaCodeStyleManager; +import com.intellij.psi.search.GlobalSearchScope; +import com.intellij.psi.search.LocalSearchScope; +import com.intellij.psi.search.searches.ReferencesSearch; +import com.intellij.psi.util.PsiTreeUtil; +import com.intellij.util.IncorrectOperationException; +import com.siyeh.ig.BaseInspection; +import com.siyeh.ig.BaseInspectionVisitor; +import com.siyeh.ig.InspectionGadgetsFix; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +public class UseOfObsoleteAssertInspection extends BaseInspection { + + @Override + @NotNull + public String getDisplayName() { + return "Usage of obsolete junit.framework.Assert"; + } + + @Override + @NotNull + protected String buildErrorString(Object... infos) { + return "#ref() should be replaced with org.junit.Assert"; + } + + @Override + protected InspectionGadgetsFix buildFix(Object... infos) { + return new ReplaceObsoleteAssertsFix(); + } + + @Override + public BaseInspectionVisitor buildVisitor() { + return new UseOfObsoleteAssertVisitor(); + } + + private static class UseOfObsoleteAssertVisitor extends BaseInspectionVisitor { + + @Override + public void visitMethodCallExpression(PsiMethodCallExpression expression) { + final Project project = expression.getProject(); + final Module module = ModuleUtil.findModuleForPsiElement(expression); + if (module != null) { + final PsiClass newAssertClass = JavaPsiFacade.getInstance(project) + .findClass("org.junit.Assert", GlobalSearchScope.moduleWithDependenciesAndLibrariesScope(module)); + if (newAssertClass != null) { + final PsiMethod psiMethod = expression.resolveMethod(); + if (psiMethod != null && psiMethod.hasModifierProperty(PsiModifier.STATIC)) { + final PsiClass containingClass = psiMethod.getContainingClass(); + if (containingClass != null && Comparing.strEqual(containingClass.getQualifiedName(), "junit.framework.Assert")) { + registerMethodCallError(expression); + } + } + } + } + } + } + + private static class ReplaceObsoleteAssertsFix extends InspectionGadgetsFix { + @Override + protected void doFix(Project project, ProblemDescriptor descriptor) throws IncorrectOperationException { + final PsiElement psiElement = PsiTreeUtil.getParentOfType(descriptor.getPsiElement(), PsiMethodCallExpression.class); + if (psiElement instanceof PsiMethodCallExpression) { + final PsiClass newAssertClass = + JavaPsiFacade.getInstance(project).findClass("org.junit.Assert", GlobalSearchScope.allScope(project)); + final PsiClass oldAssertClass = + JavaPsiFacade.getInstance(project).findClass("junit.framework.Assert", GlobalSearchScope.allScope(project)); + + if (newAssertClass != null) { + final PsiMethodCallExpression methodCallExpression = (PsiMethodCallExpression)psiElement; + final PsiReferenceExpression methodExpression = methodCallExpression.getMethodExpression(); + final PsiExpression qualifierExpression = methodExpression.getQualifierExpression(); + final PsiElement usedImport = qualifierExpression instanceof PsiReferenceExpression ? + ((PsiReferenceExpression)qualifierExpression).advancedResolve(true).getCurrentFileResolveScope() : + methodExpression.advancedResolve(true).getCurrentFileResolveScope(); + final PsiMethod psiMethod = methodCallExpression.resolveMethod(); + + final boolean isImportUnused = isImportBecomeUnused(methodCallExpression, usedImport, psiMethod); + + PsiImportStaticStatement staticStatement = null; + if (qualifierExpression == null) { + staticStatement = staticallyImported(oldAssertClass, methodExpression); + } + + final JavaCodeStyleManager styleManager = JavaCodeStyleManager.getInstance(project); + if (staticStatement == null) { + methodExpression.setQualifierExpression(JavaPsiFacade.getElementFactory(project).createReferenceExpression(newAssertClass)); + + if (isImportUnused && usedImport instanceof PsiImportStatementBase) { + usedImport.delete(); + } + + styleManager.shortenClassReferences(methodExpression); + } + else { + if (isImportUnused) { + final PsiJavaCodeReferenceElement importReference = staticStatement.getImportReference(); + if (importReference != null) { + if (staticStatement.isOnDemand()) { + importReference.bindToElement(newAssertClass); + } + else { + final PsiExpression importQExpression = ((PsiReferenceExpression)importReference).getQualifierExpression(); + if (importQExpression instanceof PsiReferenceExpression) { + ((PsiReferenceExpression)importQExpression).bindToElement(newAssertClass); + } + } + } + } + else { + methodExpression + .setQualifierExpression(JavaPsiFacade.getElementFactory(project).createReferenceExpression(newAssertClass)); + styleManager.shortenClassReferences(methodExpression); + } + } + + /* + //refs can be optimized now but should we really? + if (isImportUnused) { + for (PsiReference reference : ReferencesSearch.search(newAssertClass, new LocalSearchScope(methodCallExpression.getContainingFile()))) { + final PsiElement element = reference.getElement(); + styleManager.shortenClassReferences(element); + } + }*/ + } + } + } + + private static boolean isImportBecomeUnused(final PsiMethodCallExpression methodCallExpression, + final PsiElement usedImport, + final PsiMethod psiMethod) { + final boolean[] proceed = new boolean[]{true}; + methodCallExpression.getContainingFile().accept(new JavaRecursiveElementWalkingVisitor() { + @Override + public void visitElement(PsiElement element) { + if (proceed[0]) { + super.visitElement(element); + } + } + + @Override + public void visitMethodCallExpression(PsiMethodCallExpression expression) { + super.visitMethodCallExpression(expression); + if (expression != methodCallExpression) { + final PsiMethod resolved = expression.resolveMethod(); + if (resolved == psiMethod) { + proceed[0] = false; + } + else { + final PsiElement resolveScope = + expression.getMethodExpression().advancedResolve(false).getCurrentFileResolveScope(); + if (resolveScope == usedImport) { + proceed[0] = false; + } + } + } + } + }); + return proceed[0]; + } + + @Nullable + private static PsiImportStaticStatement staticallyImported(PsiClass oldAssertClass, PsiReferenceExpression methodExpression) { + final String referenceName = methodExpression.getReferenceName(); + final PsiFile containingFile = methodExpression.getContainingFile(); + if (containingFile instanceof PsiJavaFile) { + final PsiImportList importList = ((PsiJavaFile)containingFile).getImportList(); + if (importList != null) { + final PsiImportStaticStatement[] statements = importList.getImportStaticStatements(); + for (PsiImportStaticStatement statement : statements) { + if (oldAssertClass == statement.resolveTargetClass()) { + final String importRefName = statement.getReferenceName(); + final PsiJavaCodeReferenceElement importReference = statement.getImportReference(); + if (importReference != null) { + if (Comparing.strEqual(importRefName, referenceName)) { + final PsiElement qualifier = importReference.getQualifier(); + if (qualifier instanceof PsiJavaCodeReferenceElement) { + return statement; + } + } + else if (importRefName == null) { + return statement; + } + } + } + } + } + } + return null; + } + + @NotNull + @Override + public String getName() { + return "Replace with org.junit.Assert"; + } + } +} \ No newline at end of file diff --git a/plugins/InspectionGadgets/test/com/siyeh/igfixes/junit/useOfObsoleteAssert/extendsTestCase.after.java b/plugins/InspectionGadgets/test/com/siyeh/igfixes/junit/useOfObsoleteAssert/extendsTestCase.after.java new file mode 100644 index 000000000000..f0c176200bde --- /dev/null +++ b/plugins/InspectionGadgets/test/com/siyeh/igfixes/junit/useOfObsoleteAssert/extendsTestCase.after.java @@ -0,0 +1,9 @@ +import junit.framework.TestCase; +import org.junit.Assert; + +class MyTest extends TestCase { + public void test() { + Assert.fail(); + fail(); + } +} \ No newline at end of file diff --git a/plugins/InspectionGadgets/test/com/siyeh/igfixes/junit/useOfObsoleteAssert/extendsTestCase.java b/plugins/InspectionGadgets/test/com/siyeh/igfixes/junit/useOfObsoleteAssert/extendsTestCase.java new file mode 100644 index 000000000000..64124a4320e1 --- /dev/null +++ b/plugins/InspectionGadgets/test/com/siyeh/igfixes/junit/useOfObsoleteAssert/extendsTestCase.java @@ -0,0 +1,8 @@ +import junit.framework.TestCase; + +class MyTest extends TestCase { + public void test() { + fail(); + fail(); + } +} \ No newline at end of file diff --git a/plugins/InspectionGadgets/test/com/siyeh/igfixes/junit/useOfObsoleteAssert/onDemandStaticImport.after.java b/plugins/InspectionGadgets/test/com/siyeh/igfixes/junit/useOfObsoleteAssert/onDemandStaticImport.after.java new file mode 100644 index 000000000000..7f9c618b11cf --- /dev/null +++ b/plugins/InspectionGadgets/test/com/siyeh/igfixes/junit/useOfObsoleteAssert/onDemandStaticImport.after.java @@ -0,0 +1,10 @@ +import org.junit.Assert; + +import static junit.framework.Assert.*; + +class MyTest { + public void test() { + Assert.fail(); + fail(); + } +} \ No newline at end of file diff --git a/plugins/InspectionGadgets/test/com/siyeh/igfixes/junit/useOfObsoleteAssert/onDemandStaticImport.java b/plugins/InspectionGadgets/test/com/siyeh/igfixes/junit/useOfObsoleteAssert/onDemandStaticImport.java new file mode 100644 index 000000000000..e36dec6cf832 --- /dev/null +++ b/plugins/InspectionGadgets/test/com/siyeh/igfixes/junit/useOfObsoleteAssert/onDemandStaticImport.java @@ -0,0 +1,8 @@ +import static junit.framework.Assert.*; + +class MyTest { + public void test() { + fail(); + fail(); + } +} \ No newline at end of file diff --git a/plugins/InspectionGadgets/test/com/siyeh/igfixes/junit/useOfObsoleteAssert/singleStaticAccess.after.java b/plugins/InspectionGadgets/test/com/siyeh/igfixes/junit/useOfObsoleteAssert/singleStaticAccess.after.java new file mode 100644 index 000000000000..997fc560f8c2 --- /dev/null +++ b/plugins/InspectionGadgets/test/com/siyeh/igfixes/junit/useOfObsoleteAssert/singleStaticAccess.after.java @@ -0,0 +1,7 @@ +import org.junit.Assert; + +class MyTest { + public void test() { + Assert.fail(); + } +} \ No newline at end of file diff --git a/plugins/InspectionGadgets/test/com/siyeh/igfixes/junit/useOfObsoleteAssert/singleStaticAccess.java b/plugins/InspectionGadgets/test/com/siyeh/igfixes/junit/useOfObsoleteAssert/singleStaticAccess.java new file mode 100644 index 000000000000..c7aa55e4b43b --- /dev/null +++ b/plugins/InspectionGadgets/test/com/siyeh/igfixes/junit/useOfObsoleteAssert/singleStaticAccess.java @@ -0,0 +1,7 @@ +import junit.framework.Assert; + +class MyTest { + public void test() { + Assert.fail(); + } +} \ No newline at end of file diff --git a/plugins/InspectionGadgets/test/com/siyeh/igfixes/junit/useOfObsoleteAssert/staticAccess.after.java b/plugins/InspectionGadgets/test/com/siyeh/igfixes/junit/useOfObsoleteAssert/staticAccess.after.java new file mode 100644 index 000000000000..4341a60ac53e --- /dev/null +++ b/plugins/InspectionGadgets/test/com/siyeh/igfixes/junit/useOfObsoleteAssert/staticAccess.after.java @@ -0,0 +1,8 @@ +import junit.framework.Assert; + +class MyTest { + public void test() { + Assert.fail(); + org.junit.Assert.fail(); + } +} \ No newline at end of file diff --git a/plugins/InspectionGadgets/test/com/siyeh/igfixes/junit/useOfObsoleteAssert/staticAccess.java b/plugins/InspectionGadgets/test/com/siyeh/igfixes/junit/useOfObsoleteAssert/staticAccess.java new file mode 100644 index 000000000000..80bace0bcba5 --- /dev/null +++ b/plugins/InspectionGadgets/test/com/siyeh/igfixes/junit/useOfObsoleteAssert/staticAccess.java @@ -0,0 +1,8 @@ +import junit.framework.Assert; + +class MyTest { + public void test() { + Assert.fail(); + Assert.fail(); + } +} \ No newline at end of file diff --git a/plugins/InspectionGadgets/test/com/siyeh/igfixes/junit/useOfObsoleteAssert/staticImport.after.java b/plugins/InspectionGadgets/test/com/siyeh/igfixes/junit/useOfObsoleteAssert/staticImport.after.java new file mode 100644 index 000000000000..ff06c148ae81 --- /dev/null +++ b/plugins/InspectionGadgets/test/com/siyeh/igfixes/junit/useOfObsoleteAssert/staticImport.after.java @@ -0,0 +1,10 @@ +import org.junit.Assert; + +import static junit.framework.Assert.fail; + +class MyTest { + public void test() { + fail(); + Assert.fail(); + } +} \ No newline at end of file diff --git a/plugins/InspectionGadgets/test/com/siyeh/igfixes/junit/useOfObsoleteAssert/staticImport.java b/plugins/InspectionGadgets/test/com/siyeh/igfixes/junit/useOfObsoleteAssert/staticImport.java new file mode 100644 index 000000000000..f7d2cf672cb8 --- /dev/null +++ b/plugins/InspectionGadgets/test/com/siyeh/igfixes/junit/useOfObsoleteAssert/staticImport.java @@ -0,0 +1,8 @@ +import static junit.framework.Assert.fail; + +class MyTest { + public void test() { + fail(); + fail(); + } +} \ No newline at end of file diff --git a/plugins/InspectionGadgets/testsrc/com/siyeh/ig/fixes/junit/UseOfObsoleteAssertInspectionTest.java b/plugins/InspectionGadgets/testsrc/com/siyeh/ig/fixes/junit/UseOfObsoleteAssertInspectionTest.java new file mode 100644 index 000000000000..d5604e093bba --- /dev/null +++ b/plugins/InspectionGadgets/testsrc/com/siyeh/ig/fixes/junit/UseOfObsoleteAssertInspectionTest.java @@ -0,0 +1,66 @@ +/* + * Copyright 2000-2011 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.siyeh.ig.fixes.junit; + +import com.siyeh.ig.IGQuickFixesTestCase; +import com.siyeh.ig.junit.UseOfObsoleteAssertInspection; + +/** + * User: anna + * Date: 8/18/11 + */ +public class UseOfObsoleteAssertInspectionTest extends IGQuickFixesTestCase { + @Override + public void setUp() throws Exception { + super.setUp(); + + myFixture.addClass("package junit.framework; public class Assert { public static void fail(){}}"); + + myFixture.addClass("package junit.framework; public class TestCase extends Assert {}"); + myFixture.addClass("package org.junit; public class Assert { public static void fail(){}}"); + + myFixture.enableInspections(new UseOfObsoleteAssertInspection()); + } + + public void testExtendsTestCase() { + doFixTest(); + } + + public void testStaticAccess() { + doFixTest(); + } + + public void testSingleStaticAccess() { + doFixTest(); + } + + public void testOnDemandStaticImport() { + doFixTest(); + } + + public void testStaticImport() { + doFixTest(); + } + + private void doFixTest() { + doTest(getTestName(true), "Replace with org.junit.Assert"); + } + + @Override + protected String getRelativePath() { + return "junit/useOfObsoleteAssert"; + } +} From edcc4a17e0217acc1c66931560e35c02ace1d7ae Mon Sep 17 00:00:00 2001 From: anna Date: Fri, 19 Aug 2011 11:24:48 +0200 Subject: [PATCH 50/78] introduce parameter object: no need to change signature for overriders as they would be changed anyway; correct varargs method processing (IDEA-68920 ) --- .../IntroduceParameterObjectProcessor.java | 8 ++--- .../usageInfo/MergeMethodArguments.java | 22 +++++++++----- .../sameTypeAndVarargs/after/Param.java | 17 +++++++++++ .../sameTypeAndVarargs/after/Test.java | 30 +++++++++++++++++++ .../sameTypeAndVarargs/before/Test.java | 30 +++++++++++++++++++ .../IntroduceParameterObjectTest.java | 18 +++++++++++ 6 files changed, 113 insertions(+), 12 deletions(-) create mode 100644 java/java-tests/testData/refactoring/introduceParameterObject/sameTypeAndVarargs/after/Param.java create mode 100644 java/java-tests/testData/refactoring/introduceParameterObject/sameTypeAndVarargs/after/Test.java create mode 100644 java/java-tests/testData/refactoring/introduceParameterObject/sameTypeAndVarargs/before/Test.java diff --git a/java/java-impl/src/com/intellij/refactoring/introduceparameterobject/IntroduceParameterObjectProcessor.java b/java/java-impl/src/com/intellij/refactoring/introduceparameterobject/IntroduceParameterObjectProcessor.java index 75d5a63971d6..babbae72a9a7 100644 --- a/java/java-impl/src/com/intellij/refactoring/introduceparameterobject/IntroduceParameterObjectProcessor.java +++ b/java/java-impl/src/com/intellij/refactoring/introduceparameterobject/IntroduceParameterObjectProcessor.java @@ -164,7 +164,7 @@ public class IntroduceParameterObjectProcessor extends FixableUsagesRefactoringP if (myUseExistingClass && existingClass != null) { myExistingClassCompatibleConstructor = existingClassIsCompatible(existingClass, parameters); } - findUsagesForMethod(method, usages); + findUsagesForMethod(method, usages, true); if (myUseExistingClass && existingClass != null && !(paramsNeedingGetters.isEmpty() && paramsNeedingSetters.isEmpty())) { usages.add(new AppendAccessorsUsageInfo(existingClass, myGenerateAccessors, paramsNeedingGetters, paramsNeedingSetters, parameters)); @@ -172,7 +172,7 @@ public class IntroduceParameterObjectProcessor extends FixableUsagesRefactoringP final PsiMethod[] overridingMethods = OverridingMethodsSearch.search(method, method.getUseScope(), true).toArray(PsiMethod.EMPTY_ARRAY); for (PsiMethod siblingMethod : overridingMethods) { - findUsagesForMethod(siblingMethod, usages); + findUsagesForMethod(siblingMethod, usages, false); } if (myNewVisibility != null) { @@ -180,7 +180,7 @@ public class IntroduceParameterObjectProcessor extends FixableUsagesRefactoringP } } - private void findUsagesForMethod(PsiMethod overridingMethod, List usages) { + private void findUsagesForMethod(PsiMethod overridingMethod, List usages, boolean changeSignature) { final PsiCodeBlock body = overridingMethod.getBody(); final String baseParameterName = StringUtil.decapitalize(className); final String fixedParamName = @@ -188,7 +188,7 @@ public class IntroduceParameterObjectProcessor extends FixableUsagesRefactoringP ? JavaCodeStyleManager.getInstance(myProject).suggestUniqueVariableName(baseParameterName, body.getLBrace(), true) : JavaCodeStyleManager.getInstance(myProject).propertyNameToVariableName(baseParameterName, VariableKind.PARAMETER); - usages.add(new MergeMethodArguments(overridingMethod, className, packageName, fixedParamName, paramsToMerge, typeParams, keepMethodAsDelegate, myCreateInnerClass ? method.getContainingClass() : null)); + usages.add(new MergeMethodArguments(overridingMethod, className, packageName, fixedParamName, paramsToMerge, typeParams, keepMethodAsDelegate, myCreateInnerClass ? method.getContainingClass() : null, changeSignature)); final ParamUsageVisitor visitor = new ParamUsageVisitor(overridingMethod, paramsToMerge); overridingMethod.accept(visitor); diff --git a/java/java-impl/src/com/intellij/refactoring/introduceparameterobject/usageInfo/MergeMethodArguments.java b/java/java-impl/src/com/intellij/refactoring/introduceparameterobject/usageInfo/MergeMethodArguments.java index 87fcf8bb7207..992bff67c21e 100644 --- a/java/java-impl/src/com/intellij/refactoring/introduceparameterobject/usageInfo/MergeMethodArguments.java +++ b/java/java-impl/src/com/intellij/refactoring/introduceparameterobject/usageInfo/MergeMethodArguments.java @@ -22,6 +22,8 @@ import com.intellij.psi.*; import com.intellij.psi.codeStyle.JavaCodeStyleManager; import com.intellij.psi.impl.source.PsiImmediateClassType; import com.intellij.psi.search.GlobalSearchScope; +import com.intellij.psi.search.searches.ReferencesSearch; +import com.intellij.psi.util.PsiTreeUtil; import com.intellij.psi.util.TypeConversionUtil; import com.intellij.refactoring.changeSignature.ChangeSignatureProcessor; import com.intellij.refactoring.changeSignature.ParameterInfoImpl; @@ -36,6 +38,7 @@ import java.util.*; public class MergeMethodArguments extends FixableUsageInfo { private final PsiMethod method; private final PsiClass myContainingClass; + private final boolean myChangeSignature; private final boolean myKeepMethodAsDelegate; private final List typeParams; private final String className; @@ -50,7 +53,7 @@ public class MergeMethodArguments extends FixableUsageInfo { String parameterName, int[] paramsToMerge, List typeParams, - final boolean keepMethodAsDelegate, final PsiClass containingClass) { + final boolean keepMethodAsDelegate, final PsiClass containingClass, boolean changeSignature) { super(method); this.paramsToMerge = paramsToMerge; this.packageName = packageName; @@ -58,7 +61,8 @@ public class MergeMethodArguments extends FixableUsageInfo { this.parameterName = parameterName; this.method = method; myContainingClass = containingClass; - lastParamIsVararg = method.isVarArgs(); + myChangeSignature = changeSignature; + lastParamIsVararg = method.isVarArgs() && isParameterToMerge(method.getParameterList().getParametersCount() - 1); myKeepMethodAsDelegate = keepMethodAsDelegate; this.typeParams = new ArrayList(typeParams); } @@ -111,12 +115,14 @@ public class MergeMethodArguments extends FixableUsageInfo { public void run() { final PsiMethod psiMethod = meth.getElement(); if (psiMethod == null) return; - final ChangeSignatureProcessor changeSignatureProcessor = - new ChangeSignatureProcessor(psiMethod.getProject(), psiMethod, - myKeepMethodAsDelegate, null, psiMethod.getName(), - psiMethod.getReturnType(), - parametersInfo.toArray(new ParameterInfoImpl[parametersInfo.size()])); - changeSignatureProcessor.run(); + if (myChangeSignature) { + final ChangeSignatureProcessor changeSignatureProcessor = + new ChangeSignatureProcessor(psiMethod.getProject(), psiMethod, + myKeepMethodAsDelegate, null, psiMethod.getName(), + psiMethod.getReturnType(), + parametersInfo.toArray(new ParameterInfoImpl[parametersInfo.size()])); + changeSignatureProcessor.run(); + } } }; if (ApplicationManager.getApplication().isUnitTestMode()) { diff --git a/java/java-tests/testData/refactoring/introduceParameterObject/sameTypeAndVarargs/after/Param.java b/java/java-tests/testData/refactoring/introduceParameterObject/sameTypeAndVarargs/after/Param.java new file mode 100644 index 000000000000..894b76127061 --- /dev/null +++ b/java/java-tests/testData/refactoring/introduceParameterObject/sameTypeAndVarargs/after/Param.java @@ -0,0 +1,17 @@ +public class Param { + private final String a; + private final String b; + + public Param(String a, String b) { + this.a = a; + this.b = b; + } + + public String getA() { + return a; + } + + public String getB() { + return b; + } +} diff --git a/java/java-tests/testData/refactoring/introduceParameterObject/sameTypeAndVarargs/after/Test.java b/java/java-tests/testData/refactoring/introduceParameterObject/sameTypeAndVarargs/after/Test.java new file mode 100644 index 000000000000..db7dbdac5a3a --- /dev/null +++ b/java/java-tests/testData/refactoring/introduceParameterObject/sameTypeAndVarargs/after/Test.java @@ -0,0 +1,30 @@ +/* +* Copyright 2000-2011 JetBrains s.r.o. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +interface Test { + void foo(Param param, String... v); +} + +class TestImpl implements Test { + @Override + public void foo(Param param, String... v) { + } + + void bar(){ + foo(new Param("a", "b"), "c"); + foo(new Param("a", "b")); + foo(new Param("a", "b"), "c", "d"); + } +} \ No newline at end of file diff --git a/java/java-tests/testData/refactoring/introduceParameterObject/sameTypeAndVarargs/before/Test.java b/java/java-tests/testData/refactoring/introduceParameterObject/sameTypeAndVarargs/before/Test.java new file mode 100644 index 000000000000..24bebbf315bf --- /dev/null +++ b/java/java-tests/testData/refactoring/introduceParameterObject/sameTypeAndVarargs/before/Test.java @@ -0,0 +1,30 @@ +/* +* Copyright 2000-2011 JetBrains s.r.o. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +interface Test { + void foo(String a, String b, String... v); +} + +class TestImpl implements Test { + @Override + public void foo(String a, String b, String... v) { + } + + void bar(){ + foo("a", "b", "c"); + foo("a", "b"); + foo("a", "b", "c", "d"); + } +} \ No newline at end of file diff --git a/java/java-tests/testSrc/com/intellij/refactoring/IntroduceParameterObjectTest.java b/java/java-tests/testSrc/com/intellij/refactoring/IntroduceParameterObjectTest.java index 8c18910bf254..95ba680e5892 100644 --- a/java/java-tests/testSrc/com/intellij/refactoring/IntroduceParameterObjectTest.java +++ b/java/java-tests/testSrc/com/intellij/refactoring/IntroduceParameterObjectTest.java @@ -115,6 +115,24 @@ public class IntroduceParameterObjectTest extends MultiFileTestCase{ doTest(); } + public void testSameTypeAndVarargs() throws Exception { + doTest(false, false, new Function() { + @Override + public ParameterTablePanel.VariableData[] fun(PsiMethod method) { + final PsiParameter[] parameters = method.getParameterList().getParameters(); + + final ParameterTablePanel.VariableData[] datas = new ParameterTablePanel.VariableData[parameters.length - 1]; + for (int i = 0; i < parameters.length - 1; i++) { + PsiParameter parameter = parameters[i]; + datas[i] = new ParameterTablePanel.VariableData(parameter); + datas[i].name = parameter.getName(); + datas[i].passAsParameter = true; + } + return datas; + } + }); + } + public void testTypeParametersWithChosenSubtype() throws Exception { doTest(false, true, new Function() { @Override From 129d370f24eac9fda48dbd95d2380635d806f2bb Mon Sep 17 00:00:00 2001 From: anna Date: Fri, 19 Aug 2011 12:45:24 +0200 Subject: [PATCH 51/78] surround with runnable: check if name unique; start inplace rename; place caret after --- .../JavaWithRunnableSurrounder.java | 36 ++++++++++++++++--- ...mmentAsFirstRunnableSurroundStatement.java | 2 +- ...sFirstRunnableSurroundStatement_after.java | 2 +- 3 files changed, 34 insertions(+), 6 deletions(-) diff --git a/java/java-impl/src/com/intellij/codeInsight/generation/surroundWith/JavaWithRunnableSurrounder.java b/java/java-impl/src/com/intellij/codeInsight/generation/surroundWith/JavaWithRunnableSurrounder.java index 5c0bddf016ef..a40e612f80e8 100644 --- a/java/java-impl/src/com/intellij/codeInsight/generation/surroundWith/JavaWithRunnableSurrounder.java +++ b/java/java-impl/src/com/intellij/codeInsight/generation/surroundWith/JavaWithRunnableSurrounder.java @@ -17,14 +17,21 @@ package com.intellij.codeInsight.generation.surroundWith; import com.intellij.codeInsight.CodeInsightBundle; +import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.editor.Editor; +import com.intellij.openapi.editor.RangeMarker; import com.intellij.openapi.project.Project; +import com.intellij.openapi.util.Comparing; import com.intellij.openapi.util.TextRange; import com.intellij.psi.*; import com.intellij.psi.codeStyle.CodeStyleManager; +import com.intellij.psi.codeStyle.JavaCodeStyleManager; import com.intellij.psi.search.LocalSearchScope; import com.intellij.psi.search.searches.ReferencesSearch; +import com.intellij.psi.util.PsiTreeUtil; import com.intellij.psi.util.PsiUtil; +import com.intellij.refactoring.rename.inplace.VariableInplaceRenameHandler; +import com.intellij.refactoring.rename.inplace.VariableInplaceRenamer; import com.intellij.util.IncorrectOperationException; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; @@ -37,10 +44,12 @@ public class JavaWithRunnableSurrounder extends JavaStatementsSurrounder{ return CodeInsightBundle.message("surround.with.runnable.template"); } - public TextRange surroundStatements(Project project, Editor editor, PsiElement container, PsiElement[] statements) throws IncorrectOperationException{ + public TextRange surroundStatements(Project project, final Editor editor, PsiElement container, PsiElement[] statements) throws IncorrectOperationException{ PsiManager manager = container.getManager(); PsiElementFactory factory = JavaPsiFacade.getInstance(manager.getProject()).getElementFactory(); CodeStyleManager codeStyleManager = CodeStyleManager.getInstance(project); + final String baseName = "runnable"; + final String uniqueName = JavaCodeStyleManager.getInstance(project).suggestUniqueVariableName(baseName, container, false); @NonNls String text = "Runnable runnable = new Runnable(){\npublic void run(){\n}};"; PsiDeclarationStatement declarationStatement = (PsiDeclarationStatement)factory.createStatementFromText(text, null); @@ -48,7 +57,12 @@ public class JavaWithRunnableSurrounder extends JavaStatementsSurrounder{ declarationStatement = (PsiDeclarationStatement)container.addAfter(declarationStatement, statements[statements.length - 1]); - PsiVariable variable = (PsiVariable)declarationStatement.getDeclaredElements()[0]; + final PsiVariable variable = (PsiVariable)declarationStatement.getDeclaredElements()[0]; + + if (!Comparing.strEqual(uniqueName, baseName)) { + variable.setName(uniqueName); + } + PsiNewExpression newExpression = (PsiNewExpression)variable.getInitializer(); PsiElement[] children = newExpression.getChildren(); PsiAnonymousClass anonymousClass = (PsiAnonymousClass)children[children.length - 1]; @@ -59,8 +73,22 @@ public class JavaWithRunnableSurrounder extends JavaStatementsSurrounder{ makeVariablesFinal(body, body); - TextRange range = variable.getNameIdentifier().getTextRange(); - return range; + final int textOffset = variable.getNameIdentifier().getTextOffset(); + PsiDocumentManager.getInstance(project).doPostponedOperationsAndUnblockDocument(editor.getDocument()); + editor.getCaretModel().moveToOffset(textOffset); + new VariableInplaceRenamer(variable, editor){ + @Override + protected void moveOffsetAfter(boolean success) { + super.moveOffsetAfter(success); + if (success) { + final PsiNamedElement renamedVariable = getVariable(); + if (renamedVariable != null) { + editor.getCaretModel().moveToOffset(renamedVariable.getTextRange().getEndOffset()); + } + } + } + }.performInplaceRename(); + return null; } private static void makeVariablesFinal(PsiElement scope, PsiCodeBlock body) throws IncorrectOperationException{ diff --git a/java/java-tests/testData/codeInsight/generation/surroundWith/java/CommentAsFirstRunnableSurroundStatement.java b/java/java-tests/testData/codeInsight/generation/surroundWith/java/CommentAsFirstRunnableSurroundStatement.java index cddd0140e554..820d27d6923e 100644 --- a/java/java-tests/testData/codeInsight/generation/surroundWith/java/CommentAsFirstRunnableSurroundStatement.java +++ b/java/java-tests/testData/codeInsight/generation/surroundWith/java/CommentAsFirstRunnableSurroundStatement.java @@ -1,6 +1,6 @@ class Test { void foo() { - // This is comment" + // This is comment" int i = 1; } } \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/generation/surroundWith/java/CommentAsFirstRunnableSurroundStatement_after.java b/java/java-tests/testData/codeInsight/generation/surroundWith/java/CommentAsFirstRunnableSurroundStatement_after.java index 1762cd0c715f..30ae98a335fc 100644 --- a/java/java-tests/testData/codeInsight/generation/surroundWith/java/CommentAsFirstRunnableSurroundStatement_after.java +++ b/java/java-tests/testData/codeInsight/generation/surroundWith/java/CommentAsFirstRunnableSurroundStatement_after.java @@ -1,6 +1,6 @@ class Test { void foo() { - Runnable runnable = new Runnable() { + Runnable runnable = new Runnable() { public void run() { // This is comment" int i = 1; From 3f9b5874c21fda0054c429af6da7964f8e72c0b8 Mon Sep 17 00:00:00 2001 From: anna Date: Fri, 19 Aug 2011 13:09:47 +0200 Subject: [PATCH 52/78] implement abstract method: allow multiple selections to insert default body everywhere (IDEA-69773) --- .../impl/ImplementAbstractMethodHandler.java | 50 +++++++++---------- 1 file changed, 23 insertions(+), 27 deletions(-) diff --git a/java/java-impl/src/com/intellij/codeInsight/intention/impl/ImplementAbstractMethodHandler.java b/java/java-impl/src/com/intellij/codeInsight/intention/impl/ImplementAbstractMethodHandler.java index 05df29af2350..8586deff095f 100644 --- a/java/java-impl/src/com/intellij/codeInsight/intention/impl/ImplementAbstractMethodHandler.java +++ b/java/java-impl/src/com/intellij/codeInsight/intention/impl/ImplementAbstractMethodHandler.java @@ -47,10 +47,7 @@ import com.intellij.ui.components.JBList; import com.intellij.util.IncorrectOperationException; import javax.swing.*; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Comparator; -import java.util.List; +import java.util.*; public class ImplementAbstractMethodHandler { private static final Logger LOG = Logger.getInstance("#com.intellij.codeInsight.intention.impl.ImplementAbstractMethodHandler"); @@ -107,18 +104,17 @@ public class ImplementAbstractMethodHandler { } if (result[0].length == 1) { - implementInClass(result[0][0]); + implementInClass(new Object[] {result[0][0]}); return; } myList = new JBList(result[0]); - myList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); + myList.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); final Runnable runnable = new Runnable(){ public void run() { int index = myList.getSelectedIndex(); if (index < 0) return; - PsiElement element = (PsiElement)myList.getSelectedValue(); - implementInClass(element); + implementInClass(myList.getSelectedValues()); } }; final PsiElementListCellRenderer elementListCellRenderer = new MyPsiElementListCellRenderer(result[0]); @@ -133,31 +129,31 @@ public class ImplementAbstractMethodHandler { showInBestPositionFor(myEditor); } - private void implementInClass(final PsiElement psiClassOrEnumConstant) { - if (!psiClassOrEnumConstant.isValid()) return; - - final Document document = PsiDocumentManager.getInstance(myProject).getDocument(psiClassOrEnumConstant.getContainingFile()); - if (!FileDocumentManager.getInstance().requestWriting(document, myProject)) { - MessagesEx.fileIsReadOnly(myProject, psiClassOrEnumConstant.getContainingFile().getVirtualFile()).showNow(); - return; + private void implementInClass(final Object[] selection) { + for (Object o : selection) { + if (!((PsiElement)o).isValid()) return; } - CommandProcessor.getInstance().executeCommand(myProject, new Runnable() { public void run() { + final LinkedHashSet classes = new LinkedHashSet(); + for (Object o : selection) { + if (o instanceof PsiEnumConstant) { + classes.add(((PsiEnumConstant)o).getOrCreateInitializingClass()); + } + else { + classes.add((PsiClass)o); + } + } + if (!CodeInsightUtilBase.preparePsiElementsForWrite(classes)) return; ApplicationManager.getApplication().runWriteAction(new Runnable() { public void run() { - try { - PsiClass psiClass; - if (psiClassOrEnumConstant instanceof PsiEnumConstant) { - psiClass = ((PsiEnumConstant)psiClassOrEnumConstant).getOrCreateInitializingClass(); - } else { - psiClass = (PsiClass)psiClassOrEnumConstant; + for (PsiClass psiClass : classes) { + try { + OverrideImplementUtil.overrideOrImplement(psiClass, myMethod); + } + catch (IncorrectOperationException e) { + LOG.error(e); } - CodeInsightUtilBase.prepareFileForWrite(psiClass.getContainingFile()); - OverrideImplementUtil.overrideOrImplement(psiClass, myMethod); - } - catch (IncorrectOperationException e) { - LOG.error(e); } } }); From 6aba03f21cdefd4b665aa60165ab84373cd03eca Mon Sep 17 00:00:00 2001 From: anna Date: Fri, 19 Aug 2011 16:14:36 +0200 Subject: [PATCH 53/78] expand static import to class qualification (IDEA-68853) --- .../impl/ExpandStaticImportAction.java | 163 ++++++++++++++++++ .../afterMultipleViaOnDemand.java | 9 + .../expandStaticImport/afterSingle.java | 8 + .../afterSingleViaOnDemand.java | 8 + .../beforeMultipleViaOnDemand.java | 9 + .../expandStaticImport/beforeSingle.java | 8 + .../beforeSingleViaOnDemand.java | 8 + .../ExpandStaticImportActionTest.java | 28 +++ .../after.java.template | 7 + .../before.java.template | 7 + .../ExpandStaticImportAction/description.html | 6 + resources/src/META-INF/IdeaPlugin.xml | 5 +- 12 files changed, 265 insertions(+), 1 deletion(-) create mode 100644 java/java-impl/src/com/intellij/codeInsight/intention/impl/ExpandStaticImportAction.java create mode 100644 java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/expandStaticImport/afterMultipleViaOnDemand.java create mode 100644 java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/expandStaticImport/afterSingle.java create mode 100644 java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/expandStaticImport/afterSingleViaOnDemand.java create mode 100644 java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/expandStaticImport/beforeMultipleViaOnDemand.java create mode 100644 java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/expandStaticImport/beforeSingle.java create mode 100644 java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/expandStaticImport/beforeSingleViaOnDemand.java create mode 100644 java/java-tests/testSrc/com/intellij/codeInsight/intention/ExpandStaticImportActionTest.java create mode 100644 resources-en/src/intentionDescriptions/ExpandStaticImportAction/after.java.template create mode 100644 resources-en/src/intentionDescriptions/ExpandStaticImportAction/before.java.template create mode 100644 resources-en/src/intentionDescriptions/ExpandStaticImportAction/description.html diff --git a/java/java-impl/src/com/intellij/codeInsight/intention/impl/ExpandStaticImportAction.java b/java/java-impl/src/com/intellij/codeInsight/intention/impl/ExpandStaticImportAction.java new file mode 100644 index 000000000000..a90c1d0b360f --- /dev/null +++ b/java/java-impl/src/com/intellij/codeInsight/intention/impl/ExpandStaticImportAction.java @@ -0,0 +1,163 @@ +/* + * Copyright 2000-2011 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.intellij.codeInsight.intention.impl; + +import com.intellij.codeInsight.CodeInsightBundle; +import com.intellij.codeInsight.CodeInsightUtilBase; +import com.intellij.codeInsight.highlighting.HighlightManager; +import com.intellij.codeInsight.intention.PsiElementBaseIntentionAction; +import com.intellij.openapi.application.ApplicationManager; +import com.intellij.openapi.application.Result; +import com.intellij.openapi.command.WriteCommandAction; +import com.intellij.openapi.diagnostic.Logger; +import com.intellij.openapi.editor.Editor; +import com.intellij.openapi.editor.colors.EditorColors; +import com.intellij.openapi.editor.colors.EditorColorsManager; +import com.intellij.openapi.project.Project; +import com.intellij.openapi.ui.popup.JBPopupFactory; +import com.intellij.openapi.ui.popup.PopupChooserBuilder; +import com.intellij.openapi.ui.popup.PopupStep; +import com.intellij.openapi.ui.popup.util.BaseListPopupStep; +import com.intellij.psi.*; +import com.intellij.psi.util.PsiTreeUtil; +import com.intellij.psi.util.PsiUtil; +import com.intellij.util.IncorrectOperationException; +import com.sun.org.apache.xalan.internal.xsltc.compiler.util.StringStack; +import gnu.trove.TIntArrayList; +import gnu.trove.TIntProcedure; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; +import java.util.List; + +public class ExpandStaticImportAction extends PsiElementBaseIntentionAction { + private static final Logger LOG = Logger.getInstance("#" + ExpandStaticImportAction.class.getName()); + private static final String REPLACE_THIS_OCCURRENCE = "Replace this occurrence and keep the method"; + private static final String REPLACE_ALL_AND_DELETE_IMPORT = "Replace all and delete the import"; + + @NotNull + public String getFamilyName() { + return "Expand Static Import"; + } + + public boolean isAvailable(@NotNull Project project, Editor editor, @NotNull PsiElement element) { + if (!PsiUtil.isLanguageLevel5OrHigher(element)) return false; + final PsiElement parent = element.getParent(); + if (!(element instanceof PsiIdentifier) || !(parent instanceof PsiJavaCodeReferenceElement)) { + return false; + } + final PsiJavaCodeReferenceElement referenceElement = (PsiJavaCodeReferenceElement)parent; + final PsiElement resolveScope = referenceElement.advancedResolve(true).getCurrentFileResolveScope(); + if (resolveScope instanceof PsiImportStaticStatement) { + final PsiClass targetClass = ((PsiImportStaticStatement)resolveScope).resolveTargetClass(); + if (targetClass == null) return false; + setText("Expand static import to " + targetClass.getName() + "." + referenceElement.getReferenceName()); + return true; + } + return false; + } + + public void invoke(final Project project, final PsiFile file, final Editor editor, PsiElement element) { + if (!CodeInsightUtilBase.prepareFileForWrite(file)) return; + + final PsiJavaCodeReferenceElement refExpr = (PsiJavaCodeReferenceElement)element.getParent(); + + final PsiImportStaticStatement staticImport = (PsiImportStaticStatement)refExpr.advancedResolve(true).getCurrentFileResolveScope(); + + + final List expressionToExpand = new ArrayList(); + file.accept(new JavaRecursiveElementWalkingVisitor() { + @Override + public void visitReferenceElement(PsiJavaCodeReferenceElement expression) { + if (refExpr != expression) { + final PsiElement resolveScope = expression.advancedResolve(true).getCurrentFileResolveScope(); + if (resolveScope == staticImport) { + expressionToExpand.add(expression); + } + } + super.visitElement(expression); + } + }); + + + if (expressionToExpand.isEmpty()) { + expand(refExpr, staticImport); + staticImport.delete(); + } + else { + if (ApplicationManager.getApplication().isUnitTestMode()) { + replaceAllAndDeleteImport(expressionToExpand, refExpr, staticImport); + } + else { + final BaseListPopupStep step = + new BaseListPopupStep("Multiple Similar Calls Found", + new String[]{REPLACE_THIS_OCCURRENCE, REPLACE_ALL_AND_DELETE_IMPORT}) { + @Override + public PopupStep onChosen(final String selectedValue, boolean finalChoice) { + new WriteCommandAction(project, ExpandStaticImportAction.this.getText()) { + @Override + protected void run(Result result) throws Throwable { + if (selectedValue == REPLACE_THIS_OCCURRENCE) { + expand(refExpr, staticImport); + } + else { + replaceAllAndDeleteImport(expressionToExpand, refExpr, staticImport); + } + } + }.execute(); + return FINAL_CHOICE; + } + }; + JBPopupFactory.getInstance().createListPopup(step).showInBestPositionFor(editor); + } + } + } + + private static void replaceAllAndDeleteImport(List expressionToExpand, + PsiJavaCodeReferenceElement refExpr, + PsiImportStaticStatement staticImport) { + expressionToExpand.add(refExpr); + Collections.sort(expressionToExpand, new Comparator() { + @Override + public int compare(PsiJavaCodeReferenceElement o1, PsiJavaCodeReferenceElement o2) { + return o2.getTextOffset() - o1.getTextOffset(); + } + }); + for (PsiJavaCodeReferenceElement expression : expressionToExpand) { + expand(expression, staticImport); + } + staticImport.delete(); + } + + private static void expand(PsiJavaCodeReferenceElement refExpr, PsiImportStaticStatement staticImport) { + final PsiElementFactory elementFactory = JavaPsiFacade.getElementFactory(refExpr.getProject()); + final PsiReferenceExpression referenceExpression = elementFactory.createReferenceExpression(staticImport.resolveTargetClass()); + if (refExpr instanceof PsiReferenceExpression) { + ((PsiReferenceExpression)refExpr).setQualifierExpression(referenceExpression); + } + else { + refExpr.replace(elementFactory.createReferenceFromText(referenceExpression.getText() + "." + refExpr.getText(), refExpr)); + } + } + + public void invoke(@NotNull final Project project, final Editor editor, PsiFile file) throws IncorrectOperationException { + PsiElement element = file.findElementAt(editor.getCaretModel().getOffset()); + invoke(project, file, editor, element); + } +} diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/expandStaticImport/afterMultipleViaOnDemand.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/expandStaticImport/afterMultipleViaOnDemand.java new file mode 100644 index 000000000000..12a62b4d3c14 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/expandStaticImport/afterMultipleViaOnDemand.java @@ -0,0 +1,9 @@ +// "Expand static import to Arrays.sort" "true" +import java.util.Arrays; + +class Test { + public void sendMessage(String... destinationAddressNames) { + Arrays.sort(destinationAddressNames); + Arrays.asList(destinationAddressNames) + } +} \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/expandStaticImport/afterSingle.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/expandStaticImport/afterSingle.java new file mode 100644 index 000000000000..729b346e3f03 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/expandStaticImport/afterSingle.java @@ -0,0 +1,8 @@ +// "Expand static import to Arrays.sort" "true" +import java.util.Arrays; + +class Test { + public void sendMessage(String... destinationAddressNames) { + Arrays.sort(destinationAddressNames); + } +} \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/expandStaticImport/afterSingleViaOnDemand.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/expandStaticImport/afterSingleViaOnDemand.java new file mode 100644 index 000000000000..729b346e3f03 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/expandStaticImport/afterSingleViaOnDemand.java @@ -0,0 +1,8 @@ +// "Expand static import to Arrays.sort" "true" +import java.util.Arrays; + +class Test { + public void sendMessage(String... destinationAddressNames) { + Arrays.sort(destinationAddressNames); + } +} \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/expandStaticImport/beforeMultipleViaOnDemand.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/expandStaticImport/beforeMultipleViaOnDemand.java new file mode 100644 index 000000000000..6d186681e72e --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/expandStaticImport/beforeMultipleViaOnDemand.java @@ -0,0 +1,9 @@ +// "Expand static import to Arrays.sort" "true" +import static java.util.Arrays.*; + +class Test { + public void sendMessage(String... destinationAddressNames) { + sort(destinationAddressNames); + asList(destinationAddressNames) + } +} \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/expandStaticImport/beforeSingle.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/expandStaticImport/beforeSingle.java new file mode 100644 index 000000000000..22e342362b4c --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/expandStaticImport/beforeSingle.java @@ -0,0 +1,8 @@ +// "Expand static import to Arrays.sort" "true" +import static java.util.Arrays.sort; + +class Test { + public void sendMessage(String... destinationAddressNames) { + sort(destinationAddressNames); + } +} \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/expandStaticImport/beforeSingleViaOnDemand.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/expandStaticImport/beforeSingleViaOnDemand.java new file mode 100644 index 000000000000..fc52442d2f92 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/expandStaticImport/beforeSingleViaOnDemand.java @@ -0,0 +1,8 @@ +// "Expand static import to Arrays.sort" "true" +import static java.util.Arrays.*; + +class Test { + public void sendMessage(String... destinationAddressNames) { + sort(destinationAddressNames); + } +} \ No newline at end of file diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/intention/ExpandStaticImportActionTest.java b/java/java-tests/testSrc/com/intellij/codeInsight/intention/ExpandStaticImportActionTest.java new file mode 100644 index 000000000000..1b0f0074bcac --- /dev/null +++ b/java/java-tests/testSrc/com/intellij/codeInsight/intention/ExpandStaticImportActionTest.java @@ -0,0 +1,28 @@ +/* + * Copyright 2000-2011 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.intellij.codeInsight.intention; + +import com.intellij.codeInsight.daemon.LightIntentionActionTestCase; + +public class ExpandStaticImportActionTest extends LightIntentionActionTestCase { + + public void test() throws Exception { doAllTests(); } + + @Override + protected String getBasePath() { + return "/codeInsight/daemonCodeAnalyzer/quickFix/expandStaticImport"; + } +} diff --git a/resources-en/src/intentionDescriptions/ExpandStaticImportAction/after.java.template b/resources-en/src/intentionDescriptions/ExpandStaticImportAction/after.java.template new file mode 100644 index 000000000000..1af96f6a8ed0 --- /dev/null +++ b/resources-en/src/intentionDescriptions/ExpandStaticImportAction/after.java.template @@ -0,0 +1,7 @@ +import java.util.Arrays; + +class Foo { + public void foo(String... args) { + Arrays.sort(args); + } +} \ No newline at end of file diff --git a/resources-en/src/intentionDescriptions/ExpandStaticImportAction/before.java.template b/resources-en/src/intentionDescriptions/ExpandStaticImportAction/before.java.template new file mode 100644 index 000000000000..5db1418cdfb3 --- /dev/null +++ b/resources-en/src/intentionDescriptions/ExpandStaticImportAction/before.java.template @@ -0,0 +1,7 @@ +import static java.util.Arrays.sort; + +class Foo { + public void foo(String... args) { + sort(args); + } +} \ No newline at end of file diff --git a/resources-en/src/intentionDescriptions/ExpandStaticImportAction/description.html b/resources-en/src/intentionDescriptions/ExpandStaticImportAction/description.html new file mode 100644 index 000000000000..16b31cc736e9 --- /dev/null +++ b/resources-en/src/intentionDescriptions/ExpandStaticImportAction/description.html @@ -0,0 +1,6 @@ + + +This intention expands statically imported method call to explicit class qualification. + When multiple calls use corresponding static import, it is possible to replace them all or to change current one only. + + \ No newline at end of file diff --git a/resources/src/META-INF/IdeaPlugin.xml b/resources/src/META-INF/IdeaPlugin.xml index f42d2f5e592c..b21ef356a174 100644 --- a/resources/src/META-INF/IdeaPlugin.xml +++ b/resources/src/META-INF/IdeaPlugin.xml @@ -438,7 +438,10 @@ com.intellij.codeInsight.intention.impl.AddSingleMemberStaticImportAction Imports - + + com.intellij.codeInsight.intention.impl.ExpandStaticImportAction + Imports + com.intellij.codeInspection.actions.UnimplementInterfaceAction From 0d9ab2de82f8ad0d8a3e20c574d7f5411b9bbb51 Mon Sep 17 00:00:00 2001 From: anna Date: Fri, 19 Aug 2011 16:26:21 +0200 Subject: [PATCH 54/78] NPE --- .../src/com/intellij/ide/scopeView/ScopeTreeViewPanel.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/platform/lang-impl/src/com/intellij/ide/scopeView/ScopeTreeViewPanel.java b/platform/lang-impl/src/com/intellij/ide/scopeView/ScopeTreeViewPanel.java index ebf32de8a978..66ee79c41741 100644 --- a/platform/lang-impl/src/com/intellij/ide/scopeView/ScopeTreeViewPanel.java +++ b/platform/lang-impl/src/com/intellij/ide/scopeView/ScopeTreeViewPanel.java @@ -511,7 +511,10 @@ public class ScopeTreeViewPanel extends JPanel implements Disposable { processNodeCreation(child); } } else { - reload((DefaultMutableTreeNode)myBuilder.addDirNode((PsiDirectory)psiElement).getParent()); + final PackageDependenciesNode node = myBuilder.addDirNode((PsiDirectory)psiElement); + if (node != null) { + reload((DefaultMutableTreeNode)node.getParent()); + } } } } From c9568538b6c9c9b10b857c6109428e42b7771392 Mon Sep 17 00:00:00 2001 From: anna Date: Fri, 19 Aug 2011 17:33:31 +0200 Subject: [PATCH 55/78] scopes: compacted dirs with complicated source roots fixed (IDEA-73133 ;IDEA-73288 ) --- .../intellij/packageDependencies/ui/FileTreeModelBuilder.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/platform/lang-impl/src/com/intellij/packageDependencies/ui/FileTreeModelBuilder.java b/platform/lang-impl/src/com/intellij/packageDependencies/ui/FileTreeModelBuilder.java index 5e091640d84b..031ddba4f9b9 100644 --- a/platform/lang-impl/src/com/intellij/packageDependencies/ui/FileTreeModelBuilder.java +++ b/platform/lang-impl/src/com/intellij/packageDependencies/ui/FileTreeModelBuilder.java @@ -497,7 +497,7 @@ public class FileTreeModelBuilder { DirectoryNode parentDirectoryNode = myModuleDirNodes.get(directory); if (parentDirectoryNode != null || !myCompactEmptyMiddlePackages - || (sourceRoot != null && VfsUtil.isAncestor(directory, sourceRoot, false)) + || sourceRoot == directory || directory == contentRoot) { getModuleDirNode(directory, module, (DirectoryNode)directoryNode).add(directoryNode); } From d52dc6f56c8f6b8c3a5342b1dc01314d88ba5109 Mon Sep 17 00:00:00 2001 From: anna Date: Fri, 19 Aug 2011 18:01:49 +0200 Subject: [PATCH 56/78] read access for shorter read action (EA-29181 - assert: DumbServiceImpl.waitForSmartMode) --- .../search/AnnotatedElementsSearcher.java | 26 +++++++-- .../intellij/execution/ConfigurationUtil.java | 54 ++++++++++--------- 2 files changed, 50 insertions(+), 30 deletions(-) diff --git a/java/java-impl/src/com/intellij/psi/impl/search/AnnotatedElementsSearcher.java b/java/java-impl/src/com/intellij/psi/impl/search/AnnotatedElementsSearcher.java index 8d489df3c774..ae56ee660763 100644 --- a/java/java-impl/src/com/intellij/psi/impl/search/AnnotatedElementsSearcher.java +++ b/java/java-impl/src/com/intellij/psi/impl/search/AnnotatedElementsSearcher.java @@ -1,6 +1,8 @@ package com.intellij.psi.impl.search; +import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.diagnostic.Logger; +import com.intellij.openapi.util.Computable; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.psi.*; import com.intellij.psi.impl.PsiManagerImpl; @@ -35,12 +37,23 @@ public class AnnotatedElementsSearcher implements QueryExecutor[] types = p.getTypes(); final GlobalSearchScope scope = useScope instanceof GlobalSearchScope ? (GlobalSearchScope)useScope : null; - final Collection annotations = JavaAnnotationIndex.getInstance().get(annClass.getName(), annClass.getProject(), scope); + final Collection annotations = ApplicationManager.getApplication().runReadAction( + new Computable>() { + @Override + public Collection compute() { + return JavaAnnotationIndex.getInstance().get(annClass.getName(), annClass.getProject(), scope); + } + }); for (PsiElement elt : annotations) { if (notAnnotation(elt)) continue; - PsiAnnotation ann = (PsiAnnotation)elt; - final PsiJavaCodeReferenceElement ref = ann.getNameReferenceElement(); + final PsiAnnotation ann = (PsiAnnotation)elt; + final PsiJavaCodeReferenceElement ref = ApplicationManager.getApplication().runReadAction(new Computable() { + @Override + public PsiJavaCodeReferenceElement compute() { + return ann.getNameReferenceElement(); + } + }); if (ref == null) continue; PsiElement parent = ann.getParent(); @@ -56,7 +69,12 @@ public class AnnotatedElementsSearcher implements QueryExecutor() { + @Override + public PsiElement compute() { + return ref.resolve(); + } + }), annClass)) continue; if (useScope instanceof GlobalSearchScope && !((GlobalSearchScope)useScope).contains(candidate.getContainingFile().getVirtualFile())) { continue; diff --git a/plugins/junit/src/com/intellij/execution/ConfigurationUtil.java b/plugins/junit/src/com/intellij/execution/ConfigurationUtil.java index b2da9f1c85fb..47a46f16712f 100644 --- a/plugins/junit/src/com/intellij/execution/ConfigurationUtil.java +++ b/plugins/junit/src/com/intellij/execution/ConfigurationUtil.java @@ -94,32 +94,34 @@ public class ConfigurationUtil { } ); if (testAnnotation != null) { - ApplicationManager.getApplication().runReadAction(new Runnable() { - public void run(){ - AnnotatedMembersSearch.search(testAnnotation, GlobalSearchScope.allScope(manager.getProject())).forEach(new Processor() { - public boolean process(final PsiMember annotated) { - PsiClass containingClass = annotated instanceof PsiClass ? (PsiClass)annotated : annotated.getContainingClass(); - if (containingClass != null && annotated instanceof PsiMethod == isMethod) { - if (scope.contains(PsiUtilBase.getVirtualFile(containingClass)) && testClassFilter.isAccepted(containingClass)) { - found.add(containingClass); - isJUnit4.set(Boolean.TRUE); - } - ClassInheritorsSearch.search(containingClass, scope, true).forEach(new PsiElementProcessorAdapter(new PsiElementProcessor() { - public boolean execute(final PsiClass aClass) { - if (testClassFilter.isAccepted(aClass)) { - found.add(aClass); - isJUnit4.set(Boolean.TRUE); - } - return true; - } - })); - } - return true; - } - }); - } - }); - + AnnotatedMembersSearch.search(testAnnotation, GlobalSearchScope.allScope(manager.getProject())).forEach(new Processor() { + public boolean process(final PsiMember annotated) { + final PsiClass containingClass = annotated instanceof PsiClass ? (PsiClass)annotated : annotated.getContainingClass(); + if (containingClass != null && annotated instanceof PsiMethod == isMethod) { + if (scope.contains(PsiUtilBase.getVirtualFile(containingClass)) && ApplicationManager.getApplication().runReadAction( + new Computable() { + @Override + public Boolean compute() { + return testClassFilter.isAccepted(containingClass); + } + })) { + found.add(containingClass); + isJUnit4.set(Boolean.TRUE); + } + ClassInheritorsSearch.search(containingClass, scope, true) + .forEach(new PsiElementProcessorAdapter(new PsiElementProcessor() { + public boolean execute(final PsiClass aClass) { + if (testClassFilter.isAccepted(aClass)) { + found.add(aClass); + isJUnit4.set(Boolean.TRUE); + } + return true; + } + })); + } + return true; + } + }); } return isJUnit4.get().booleanValue(); From 43146fa7bc239830a2e029b8ebf124cebef5f40f Mon Sep 17 00:00:00 2001 From: anna Date: Fri, 19 Aug 2011 18:25:00 +0200 Subject: [PATCH 57/78] scopes: restore tree selection under reloaded root if any (IDEA-73285 ) --- .../src/com/intellij/ide/scopeView/ScopeTreeViewPanel.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/platform/lang-impl/src/com/intellij/ide/scopeView/ScopeTreeViewPanel.java b/platform/lang-impl/src/com/intellij/ide/scopeView/ScopeTreeViewPanel.java index 66ee79c41741..2c5c679941b9 100644 --- a/platform/lang-impl/src/com/intellij/ide/scopeView/ScopeTreeViewPanel.java +++ b/platform/lang-impl/src/com/intellij/ide/scopeView/ScopeTreeViewPanel.java @@ -402,6 +402,7 @@ public class ScopeTreeViewPanel extends JPanel implements Disposable { final DefaultTreeModel treeModel = (DefaultTreeModel)myTree.getModel(); if (rootToReload != null && rootToReload != treeModel.getRoot()) { final List treePaths = TreeUtil.collectExpandedPaths(myTree, new TreePath(rootToReload.getPath())); + final List selectionPaths = TreeUtil.collectSelectedPaths(myTree, new TreePath(rootToReload.getPath())); treeModel.reload(rootToReload); final TreePath path = new TreePath(rootToReload.getPath()); final boolean wasCollapsed = myTree.isCollapsed(path); @@ -412,6 +413,9 @@ public class ScopeTreeViewPanel extends JPanel implements Disposable { for (TreePath treePath : treePaths) { myTree.expandPath(treePath); } + for (TreePath selectionPath : selectionPaths) { + TreeUtil.selectPath(myTree, selectionPath); + } } TreeUtil.sort(rootToReload, getNodeComparator()); } From 0ebb8ba8a396a38ab3c7f747660506775e6a474d Mon Sep 17 00:00:00 2001 From: anna Date: Fri, 19 Aug 2011 19:02:06 +0200 Subject: [PATCH 58/78] javadoc: correct end section detection for jdk7 javadoc format --- .../codeInsight/documentation/AbstractExternalFilter.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/platform/lang-impl/src/com/intellij/codeInsight/documentation/AbstractExternalFilter.java b/platform/lang-impl/src/com/intellij/codeInsight/documentation/AbstractExternalFilter.java index 6c9db5b43234..e3f88e9d5f24 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/documentation/AbstractExternalFilter.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/documentation/AbstractExternalFilter.java @@ -293,7 +293,9 @@ public abstract class AbstractExternalFilter { data.append(P); } - while (((read = buf.readLine()) != null) && read.indexOf(endSection) == -1 && read.indexOf(greatestEndSection) == -1) { + while (((read = buf.readLine()) != null) && + StringUtil.indexOfIgnoreCase(read, endSection, 0) == -1 && + StringUtil.indexOfIgnoreCase(read, greatestEndSection, 0) == -1) { if (read.toUpperCase().indexOf(HR) == -1) { appendLine(data, read); } From 6a08717423866f78499a8ca24f8c5d9ac0205a98 Mon Sep 17 00:00:00 2001 From: Dmitry Jemerov Date: Fri, 19 Aug 2011 23:32:54 +0200 Subject: [PATCH 59/78] rollback change to VfsUtil.createDirectories() which is now unnecessary --- .../src/com/intellij/openapi/vfs/VfsUtil.java | 21 +++++++------------ 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/platform/platform-api/src/com/intellij/openapi/vfs/VfsUtil.java b/platform/platform-api/src/com/intellij/openapi/vfs/VfsUtil.java index 032c6e4ee7bc..1c8364c7db04 100644 --- a/platform/platform-api/src/com/intellij/openapi/vfs/VfsUtil.java +++ b/platform/platform-api/src/com/intellij/openapi/vfs/VfsUtil.java @@ -16,6 +16,8 @@ package com.intellij.openapi.vfs; import com.intellij.openapi.application.ApplicationManager; +import com.intellij.openapi.application.Result; +import com.intellij.openapi.application.WriteAction; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.fileTypes.FileTypeManager; import com.intellij.openapi.fileTypes.FileTypes; @@ -639,20 +641,13 @@ public class VfsUtil { } public static VirtualFile createDirectories(@NotNull final String dir) throws IOException { - final Ref err = new Ref(); - VirtualFile result = ApplicationManager.getApplication().runWriteAction(new Computable() { - public VirtualFile compute() { - try { - return createDirectoryIfMissing(dir); - } - catch (IOException e) { - err.set(e); - return null; - } + return new WriteAction() { + @Override + protected void run(Result result) throws Throwable { + VirtualFile res = createDirectoryIfMissing(dir); + result.setResult(res); } - }); - if (!err.isNull()) throw err.get(); - return result; + }.execute().throwException().getResultObject(); } public static VirtualFile createDirectoryIfMissing(VirtualFile parent, String relativePath) throws IOException { From 988312fcb8de2f9cb8a5501d6ffd633d87ba82c5 Mon Sep 17 00:00:00 2001 From: Bas Leijdekkers Date: Sun, 21 Aug 2011 12:44:34 +0200 Subject: [PATCH 60/78] i18n, added description --- .../siyeh/InspectionGadgetsBundle.properties | 3 + .../junit/UseOfObsoleteAssertInspection.java | 197 +++++++++--------- .../UseOfObsoleteAssert.html | 8 + 3 files changed, 113 insertions(+), 95 deletions(-) create mode 100644 plugins/InspectionGadgets/src/inspectionDescriptions/UseOfObsoleteAssert.html diff --git a/plugins/InspectionGadgets/src/com/siyeh/InspectionGadgetsBundle.properties b/plugins/InspectionGadgets/src/com/siyeh/InspectionGadgetsBundle.properties index 4338ebede38b..e6a2401bbfb9 100644 --- a/plugins/InspectionGadgets/src/com/siyeh/InspectionGadgetsBundle.properties +++ b/plugins/InspectionGadgets/src/com/siyeh/InspectionGadgetsBundle.properties @@ -1930,3 +1930,6 @@ static.variable.of.concrete.class.option=Ignore static fields whose type is an a class.only.used.in.one.package.display.name=Class only used from one other package class.only.used.in.one.package.problem.descriptor=Class #ref has only dependencies on and/or dependents in package ''{0}'' #loc unnecessary.return.option=Ignore in then branch branch of if statement with else branch +usage.of.obsolete.assert.display.name=Usage of obsolete 'junit.framework.Assert' +use.of.obsolete.assert.problem.descriptor=Call to #ref() from 'org.junit.framework.Assert' should be replaced with call to method from 'org.junit.Assert' +use.of.obsolete.assert.quickfix=Replace with 'org.junit.Assert' method call diff --git a/plugins/InspectionGadgets/src/com/siyeh/ig/junit/UseOfObsoleteAssertInspection.java b/plugins/InspectionGadgets/src/com/siyeh/ig/junit/UseOfObsoleteAssertInspection.java index 856badaab4fc..c58fd7ed83cf 100644 --- a/plugins/InspectionGadgets/src/com/siyeh/ig/junit/UseOfObsoleteAssertInspection.java +++ b/plugins/InspectionGadgets/src/com/siyeh/ig/junit/UseOfObsoleteAssertInspection.java @@ -23,11 +23,9 @@ import com.intellij.openapi.util.Comparing; import com.intellij.psi.*; import com.intellij.psi.codeStyle.JavaCodeStyleManager; import com.intellij.psi.search.GlobalSearchScope; -import com.intellij.psi.search.LocalSearchScope; -import com.intellij.psi.search.searches.ReferencesSearch; import com.intellij.psi.util.PsiTreeUtil; import com.intellij.util.IncorrectOperationException; -import com.siyeh.ig.BaseInspection; +import com.siyeh.InspectionGadgetsBundle;import com.siyeh.ig.BaseInspection; import com.siyeh.ig.BaseInspectionVisitor; import com.siyeh.ig.InspectionGadgetsFix; import org.jetbrains.annotations.NotNull; @@ -38,13 +36,13 @@ public class UseOfObsoleteAssertInspection extends BaseInspection { @Override @NotNull public String getDisplayName() { - return "Usage of obsolete junit.framework.Assert"; + return InspectionGadgetsBundle.message("usage.of.obsolete.assert.display.name"); } @Override @NotNull protected String buildErrorString(Object... infos) { - return "#ref() should be replaced with org.junit.Assert"; + return InspectionGadgetsBundle.message("use.of.obsolete.assert.problem.descriptor"); } @Override @@ -63,18 +61,21 @@ public class UseOfObsoleteAssertInspection extends BaseInspection { public void visitMethodCallExpression(PsiMethodCallExpression expression) { final Project project = expression.getProject(); final Module module = ModuleUtil.findModuleForPsiElement(expression); - if (module != null) { - final PsiClass newAssertClass = JavaPsiFacade.getInstance(project) - .findClass("org.junit.Assert", GlobalSearchScope.moduleWithDependenciesAndLibrariesScope(module)); - if (newAssertClass != null) { - final PsiMethod psiMethod = expression.resolveMethod(); - if (psiMethod != null && psiMethod.hasModifierProperty(PsiModifier.STATIC)) { - final PsiClass containingClass = psiMethod.getContainingClass(); - if (containingClass != null && Comparing.strEqual(containingClass.getQualifiedName(), "junit.framework.Assert")) { - registerMethodCallError(expression); - } - } - } + if (module == null) { + return; + } + final PsiClass newAssertClass = JavaPsiFacade.getInstance(project) + .findClass("org.junit.Assert", GlobalSearchScope.moduleWithDependenciesAndLibrariesScope(module)); + if (newAssertClass == null) { + return; + } + final PsiMethod psiMethod = expression.resolveMethod(); + if (psiMethod == null || !psiMethod.hasModifierProperty(PsiModifier.STATIC)) { + return; + } + final PsiClass containingClass = psiMethod.getContainingClass(); + if (containingClass != null && Comparing.strEqual(containingClass.getQualifiedName(), "junit.framework.Assert")) { + registerMethodCallError(expression); } } } @@ -83,61 +84,64 @@ public class UseOfObsoleteAssertInspection extends BaseInspection { @Override protected void doFix(Project project, ProblemDescriptor descriptor) throws IncorrectOperationException { final PsiElement psiElement = PsiTreeUtil.getParentOfType(descriptor.getPsiElement(), PsiMethodCallExpression.class); - if (psiElement instanceof PsiMethodCallExpression) { - final PsiClass newAssertClass = - JavaPsiFacade.getInstance(project).findClass("org.junit.Assert", GlobalSearchScope.allScope(project)); - final PsiClass oldAssertClass = - JavaPsiFacade.getInstance(project).findClass("junit.framework.Assert", GlobalSearchScope.allScope(project)); + if (!(psiElement instanceof PsiMethodCallExpression)) { + return; + } + final PsiClass newAssertClass = + JavaPsiFacade.getInstance(project).findClass("org.junit.Assert", GlobalSearchScope.allScope(project)); + final PsiClass oldAssertClass = + JavaPsiFacade.getInstance(project).findClass("junit.framework.Assert", GlobalSearchScope.allScope(project)); - if (newAssertClass != null) { - final PsiMethodCallExpression methodCallExpression = (PsiMethodCallExpression)psiElement; - final PsiReferenceExpression methodExpression = methodCallExpression.getMethodExpression(); - final PsiExpression qualifierExpression = methodExpression.getQualifierExpression(); - final PsiElement usedImport = qualifierExpression instanceof PsiReferenceExpression ? - ((PsiReferenceExpression)qualifierExpression).advancedResolve(true).getCurrentFileResolveScope() : - methodExpression.advancedResolve(true).getCurrentFileResolveScope(); - final PsiMethod psiMethod = methodCallExpression.resolveMethod(); + if (newAssertClass == null) { + return; + } + final PsiMethodCallExpression methodCallExpression = (PsiMethodCallExpression)psiElement; + final PsiReferenceExpression methodExpression = methodCallExpression.getMethodExpression(); + final PsiExpression qualifierExpression = methodExpression.getQualifierExpression(); + final PsiElement usedImport = qualifierExpression instanceof PsiReferenceExpression ? + ((PsiReferenceExpression)qualifierExpression).advancedResolve(true).getCurrentFileResolveScope() : + methodExpression.advancedResolve(true).getCurrentFileResolveScope(); + final PsiMethod psiMethod = methodCallExpression.resolveMethod(); - final boolean isImportUnused = isImportBecomeUnused(methodCallExpression, usedImport, psiMethod); + final boolean isImportUnused = isImportBecomeUnused(methodCallExpression, usedImport, psiMethod); - PsiImportStaticStatement staticStatement = null; - if (qualifierExpression == null) { - staticStatement = staticallyImported(oldAssertClass, methodExpression); - } + PsiImportStaticStatement staticStatement = null; + if (qualifierExpression == null) { + staticStatement = staticallyImported(oldAssertClass, methodExpression); + } - final JavaCodeStyleManager styleManager = JavaCodeStyleManager.getInstance(project); - if (staticStatement == null) { - methodExpression.setQualifierExpression(JavaPsiFacade.getElementFactory(project).createReferenceExpression(newAssertClass)); + final JavaCodeStyleManager styleManager = JavaCodeStyleManager.getInstance(project); + if (staticStatement == null) { + methodExpression.setQualifierExpression(JavaPsiFacade.getElementFactory(project).createReferenceExpression(newAssertClass)); - if (isImportUnused && usedImport instanceof PsiImportStatementBase) { - usedImport.delete(); - } + if (isImportUnused && usedImport instanceof PsiImportStatementBase) { + usedImport.delete(); + } - styleManager.shortenClassReferences(methodExpression); - } - else { - if (isImportUnused) { - final PsiJavaCodeReferenceElement importReference = staticStatement.getImportReference(); - if (importReference != null) { - if (staticStatement.isOnDemand()) { - importReference.bindToElement(newAssertClass); - } - else { - final PsiExpression importQExpression = ((PsiReferenceExpression)importReference).getQualifierExpression(); - if (importQExpression instanceof PsiReferenceExpression) { - ((PsiReferenceExpression)importQExpression).bindToElement(newAssertClass); - } - } - } + styleManager.shortenClassReferences(methodExpression); + } + else { + if (isImportUnused) { + final PsiJavaCodeReferenceElement importReference = staticStatement.getImportReference(); + if (importReference != null) { + if (staticStatement.isOnDemand()) { + importReference.bindToElement(newAssertClass); } else { - methodExpression - .setQualifierExpression(JavaPsiFacade.getElementFactory(project).createReferenceExpression(newAssertClass)); - styleManager.shortenClassReferences(methodExpression); + final PsiExpression importQExpression = ((PsiReferenceExpression)importReference).getQualifierExpression(); + if (importQExpression instanceof PsiReferenceExpression) { + ((PsiReferenceExpression)importQExpression).bindToElement(newAssertClass); + } } } - - /* + } + else { + methodExpression + .setQualifierExpression(JavaPsiFacade.getElementFactory(project).createReferenceExpression(newAssertClass)); + styleManager.shortenClassReferences(methodExpression); + } + } + /* //refs can be optimized now but should we really? if (isImportUnused) { for (PsiReference reference : ReferencesSearch.search(newAssertClass, new LocalSearchScope(methodCallExpression.getContainingFile()))) { @@ -145,8 +149,6 @@ public class UseOfObsoleteAssertInspection extends BaseInspection { styleManager.shortenClassReferences(element); } }*/ - } - } } private static boolean isImportBecomeUnused(final PsiMethodCallExpression methodCallExpression, @@ -164,18 +166,19 @@ public class UseOfObsoleteAssertInspection extends BaseInspection { @Override public void visitMethodCallExpression(PsiMethodCallExpression expression) { super.visitMethodCallExpression(expression); - if (expression != methodCallExpression) { - final PsiMethod resolved = expression.resolveMethod(); - if (resolved == psiMethod) { + if (expression == methodCallExpression) { + return; + } + final PsiMethod resolved = expression.resolveMethod(); + if (resolved == psiMethod) { + proceed[0] = false; + } + else { + final PsiElement resolveScope = + expression.getMethodExpression().advancedResolve(false).getCurrentFileResolveScope(); + if (resolveScope == usedImport) { proceed[0] = false; } - else { - final PsiElement resolveScope = - expression.getMethodExpression().advancedResolve(false).getCurrentFileResolveScope(); - if (resolveScope == usedImport) { - proceed[0] = false; - } - } } } }); @@ -186,28 +189,32 @@ public class UseOfObsoleteAssertInspection extends BaseInspection { private static PsiImportStaticStatement staticallyImported(PsiClass oldAssertClass, PsiReferenceExpression methodExpression) { final String referenceName = methodExpression.getReferenceName(); final PsiFile containingFile = methodExpression.getContainingFile(); - if (containingFile instanceof PsiJavaFile) { - final PsiImportList importList = ((PsiJavaFile)containingFile).getImportList(); - if (importList != null) { - final PsiImportStaticStatement[] statements = importList.getImportStaticStatements(); - for (PsiImportStaticStatement statement : statements) { - if (oldAssertClass == statement.resolveTargetClass()) { - final String importRefName = statement.getReferenceName(); - final PsiJavaCodeReferenceElement importReference = statement.getImportReference(); - if (importReference != null) { - if (Comparing.strEqual(importRefName, referenceName)) { - final PsiElement qualifier = importReference.getQualifier(); - if (qualifier instanceof PsiJavaCodeReferenceElement) { - return statement; - } - } - else if (importRefName == null) { - return statement; - } - } - } + if (!(containingFile instanceof PsiJavaFile)) { + return null; + } + final PsiImportList importList = ((PsiJavaFile)containingFile).getImportList(); + if (importList == null) { + return null; + } + final PsiImportStaticStatement[] statements = importList.getImportStaticStatements(); + for (PsiImportStaticStatement statement : statements) { + if (oldAssertClass != statement.resolveTargetClass()) { + continue; + } + final String importRefName = statement.getReferenceName(); + final PsiJavaCodeReferenceElement importReference = statement.getImportReference(); + if (importReference == null) { + continue; + } + if (Comparing.strEqual(importRefName, referenceName)) { + final PsiElement qualifier = importReference.getQualifier(); + if (qualifier instanceof PsiJavaCodeReferenceElement) { + return statement; } } + else if (importRefName == null) { + return statement; + } } return null; } @@ -215,7 +222,7 @@ public class UseOfObsoleteAssertInspection extends BaseInspection { @NotNull @Override public String getName() { - return "Replace with org.junit.Assert"; + return InspectionGadgetsBundle.message("use.of.obsolete.assert.quickfix"); } } } \ No newline at end of file diff --git a/plugins/InspectionGadgets/src/inspectionDescriptions/UseOfObsoleteAssert.html b/plugins/InspectionGadgets/src/inspectionDescriptions/UseOfObsoleteAssert.html new file mode 100644 index 000000000000..8f75339f6c37 --- /dev/null +++ b/plugins/InspectionGadgets/src/inspectionDescriptions/UseOfObsoleteAssert.html @@ -0,0 +1,8 @@ + + +This inspection reports any calls to methods from the junit.framework.Assert class. This class is +obsolete and the calls can be replaced by calls to methods from the org.junit.Assert class. +

+New in 11, Powered by InspectionGadgets + + \ No newline at end of file From 2a1f09810fec52606dd389be8602a3865f681678 Mon Sep 17 00:00:00 2001 From: anna Date: Sun, 21 Aug 2011 13:40:15 +0200 Subject: [PATCH 61/78] EA-29126 - assert: FileManagerImpl.findFile --- .../src/com/intellij/packageDependencies/ui/FileNode.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/platform/lang-impl/src/com/intellij/packageDependencies/ui/FileNode.java b/platform/lang-impl/src/com/intellij/packageDependencies/ui/FileNode.java index bb8a48730cb6..faa4a7324296 100644 --- a/platform/lang-impl/src/com/intellij/packageDependencies/ui/FileNode.java +++ b/platform/lang-impl/src/com/intellij/packageDependencies/ui/FileNode.java @@ -122,6 +122,6 @@ public class FileNode extends PackageDependenciesNode { @Nullable private PsiFile getFile() { - return PsiManager.getInstance(myProject).findFile(myVFile); + return myVFile.isValid() ? PsiManager.getInstance(myProject).findFile(myVFile) : null; } } From 1ed82c560976cbcbaf21dc8b6fdc0a082a46b497 Mon Sep 17 00:00:00 2001 From: anna Date: Sun, 21 Aug 2011 14:46:36 +0200 Subject: [PATCH 62/78] introduce parameter: replace field access with getter: correct anonymous class access; check qualifier --- .../OldReferenceResolver.java | 16 ++++++++----- .../afterGetterQualifier.java | 23 +++++++++++++++++++ .../beforeGetterQualifier.java | 22 ++++++++++++++++++ .../refactoring/IntroduceParameterTest.java | 4 ++++ 4 files changed, 59 insertions(+), 6 deletions(-) create mode 100644 java/java-tests/testData/refactoring/introduceParameter/afterGetterQualifier.java create mode 100644 java/java-tests/testData/refactoring/introduceParameter/beforeGetterQualifier.java diff --git a/java/java-impl/src/com/intellij/refactoring/introduceParameter/OldReferenceResolver.java b/java/java-impl/src/com/intellij/refactoring/introduceParameter/OldReferenceResolver.java index c86e04e8eef8..70820656c8a0 100644 --- a/java/java-impl/src/com/intellij/refactoring/introduceParameter/OldReferenceResolver.java +++ b/java/java-impl/src/com/intellij/refactoring/introduceParameter/OldReferenceResolver.java @@ -150,13 +150,13 @@ public class OldReferenceResolver { } } - if (subj instanceof PsiField && PsiTreeUtil.isAncestor(clss, scope, false)) { + if (subj instanceof PsiField && PsiTreeUtil.isAncestor(scope, clss, false)) { // probably replacing field with a getter if (myReplaceFieldsWithGetters != IntroduceParameterRefactoring.REPLACE_FIELDS_WITH_GETTERS_NONE) { if (myReplaceFieldsWithGetters == IntroduceParameterRefactoring.REPLACE_FIELDS_WITH_GETTERS_ALL || myReplaceFieldsWithGetters == IntroduceParameterRefactoring.REPLACE_FIELDS_WITH_GETTERS_INACCESSIBLE && !JavaPsiFacade.getInstance(myProject).getResolveHelper().isAccessible((PsiMember)subj, newExpr, null)) { - newExpr = replaceFieldWithGetter(newExpr, (PsiField)subj); + newExpr = replaceFieldWithGetter(newExpr, (PsiField)subj, oldRef.getQualifierExpression() == null && !((PsiField)subj).hasModifierProperty(PsiModifier.STATIC)); } } } @@ -210,7 +210,7 @@ public class OldReferenceResolver { } } - private PsiElement replaceFieldWithGetter(PsiElement expr, PsiField psiField) throws IncorrectOperationException { + private PsiElement replaceFieldWithGetter(PsiElement expr, PsiField psiField, boolean qualify) throws IncorrectOperationException { if (RefactoringUtil.isAssignmentLHS(expr)) { // todo: warning return expr; @@ -228,9 +228,13 @@ public class OldReferenceResolver { String id = getter.getName(); String qualifier = null; if (newExpr instanceof PsiReferenceExpression) { - final PsiExpression qualifierExpression = ((PsiReferenceExpression)newExpr).getQualifierExpression(); - if (qualifierExpression != null) { - qualifier = qualifierExpression.getText(); + if (qualify) { + qualifier = getInstanceRef(factory).getText(); + } else { + final PsiExpression qualifierExpression = ((PsiReferenceExpression)newExpr).getQualifierExpression(); + if (qualifierExpression != null) { + qualifier = qualifierExpression.getText(); + } } } PsiMethodCallExpression getterCall = diff --git a/java/java-tests/testData/refactoring/introduceParameter/afterGetterQualifier.java b/java/java-tests/testData/refactoring/introduceParameter/afterGetterQualifier.java new file mode 100644 index 000000000000..a0ce8c1f4a0b --- /dev/null +++ b/java/java-tests/testData/refactoring/introduceParameter/afterGetterQualifier.java @@ -0,0 +1,23 @@ +public class Test { + private String myStr; + + public String getMyStr() { + return myStr; + } + + void foo(String anObject) { + new Runnable(){ + @Override + public void run() { + System.out.println(anObject); + } + }; + } +} + +class X { + public void n() { + final Test test = new Test(); + test.foo(test.getMyStr()); + } +} \ No newline at end of file diff --git a/java/java-tests/testData/refactoring/introduceParameter/beforeGetterQualifier.java b/java/java-tests/testData/refactoring/introduceParameter/beforeGetterQualifier.java new file mode 100644 index 000000000000..ac937dc29041 --- /dev/null +++ b/java/java-tests/testData/refactoring/introduceParameter/beforeGetterQualifier.java @@ -0,0 +1,22 @@ +public class Test { + private String myStr; + + public String getMyStr() { + return myStr; + } + + void foo() { + new Runnable(){ + @Override + public void run() { + System.out.println(myStr); + } + }; + } +} + +class X { + public void n() { + new Test().foo(); + } +} \ No newline at end of file diff --git a/java/java-tests/testSrc/com/intellij/refactoring/IntroduceParameterTest.java b/java/java-tests/testSrc/com/intellij/refactoring/IntroduceParameterTest.java index 653e997218ea..8033fb3795d6 100644 --- a/java/java-tests/testSrc/com/intellij/refactoring/IntroduceParameterTest.java +++ b/java/java-tests/testSrc/com/intellij/refactoring/IntroduceParameterTest.java @@ -244,6 +244,10 @@ public class IntroduceParameterTest extends LightCodeInsightTestCase { doTest(IntroduceParameterRefactoring.REPLACE_FIELDS_WITH_GETTERS_NONE, false, false, false, false); } + public void testGetterQualifier() throws Exception { + doTest(IntroduceParameterRefactoring.REPLACE_FIELDS_WITH_GETTERS_INACCESSIBLE, false, false, false, false); + } + public void testIncompleteEnumDefinition() throws Exception { doTest(IntroduceParameterRefactoring.REPLACE_FIELDS_WITH_GETTERS_NONE, true, false, false, false, "Incomplete call(Root()): 2 parameters expected but only 0 found\n" + "Incomplete call(Root()): expected to delete the 1 parameter but only 0 parameters found"); From ed9b7d65233b7d5a5bf0d6d78c4a46ccf337895b Mon Sep 17 00:00:00 2001 From: anna Date: Sun, 21 Aug 2011 14:54:20 +0200 Subject: [PATCH 63/78] assertions for EA-29121 - AIOOBE: PsiElementFactoryImpl.createMethod --- .../psi/impl/PsiElementFactoryImpl.java | 23 +++++++++++++------ 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/java/java-impl/src/com/intellij/psi/impl/PsiElementFactoryImpl.java b/java/java-impl/src/com/intellij/psi/impl/PsiElementFactoryImpl.java index 34e0ab24b863..c8d8faa795d0 100644 --- a/java/java-impl/src/com/intellij/psi/impl/PsiElementFactoryImpl.java +++ b/java/java-impl/src/com/intellij/psi/impl/PsiElementFactoryImpl.java @@ -186,8 +186,8 @@ public class PsiElementFactoryImpl extends PsiJavaParserFacadeImpl implements Ps if (fields.length < 1) { throw new IncorrectOperationException("Field was not created " + text); } - final PsiField field = fields[0]; - JavaCodeStyleManager.getInstance(myManager.getProject()).shortenClassReferences(field); + PsiField field = fields[0]; + field = (PsiField)JavaCodeStyleManager.getInstance(myManager.getProject()).shortenClassReferences(field); return (PsiField)CodeStyleManager.getInstance(myManager.getProject()).reformat(field); } @@ -199,9 +199,18 @@ public class PsiElementFactoryImpl extends PsiJavaParserFacadeImpl implements Ps throw new IncorrectOperationException("Cannot create method with type \"null\"."); } - final PsiJavaFile aFile = createDummyJavaFile(join("class _Dummy_ { public " + returnType.getCanonicalText(), " ", name, "() {} }")); - final PsiMethod method = aFile.getClasses()[0].getMethods()[0]; - JavaCodeStyleManager.getInstance(myManager.getProject()).shortenClassReferences(method); + final String canonicalText = returnType.getCanonicalText(); + final PsiJavaFile aFile = createDummyJavaFile(join("class _Dummy_ { public " + canonicalText, " ", name, "() {} }")); + final PsiClass[] classes = aFile.getClasses(); + if (classes.length < 1) { + throw new IncorrectOperationException("Class was not created. Method name: " + name + "; return type: " + canonicalText); + } + final PsiMethod[] methods = classes[0].getMethods(); + if (methods.length < 1) { + throw new IncorrectOperationException("Method was not created. Method name: " + name + "; return type: " + canonicalText); + } + PsiMethod method = methods[0]; + method = (PsiMethod)JavaCodeStyleManager.getInstance(myManager.getProject()).shortenClassReferences(method); return (PsiMethod)CodeStyleManager.getInstance(myManager.getProject()).reformat(method); } @@ -230,12 +239,12 @@ public class PsiElementFactoryImpl extends PsiJavaParserFacadeImpl implements Ps } final String text = join(type.getCanonicalText() + " " + name); - final PsiParameter parameter = createParameterFromText(text, null); + PsiParameter parameter = createParameterFromText(text, null); final CodeStyleManager codeStyleManager = CodeStyleManager.getInstance(myManager.getProject()); PsiUtil.setModifierProperty(parameter, PsiModifier.FINAL, CodeStyleSettingsManager.getSettings(myManager.getProject()).GENERATE_FINAL_PARAMETERS); markGenerated(parameter); - JavaCodeStyleManager.getInstance(myManager.getProject()).shortenClassReferences(parameter); + parameter = (PsiParameter)JavaCodeStyleManager.getInstance(myManager.getProject()).shortenClassReferences(parameter); return (PsiParameter)codeStyleManager.reformat(parameter); } From 9e7f81c8e55016705ca5ec692f5c6b0d230c276a Mon Sep 17 00:00:00 2001 From: anna Date: Sun, 21 Aug 2011 14:55:32 +0200 Subject: [PATCH 64/78] fix tests --- .../ig/fixes/junit/UseOfObsoleteAssertInspectionTest.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/plugins/InspectionGadgets/testsrc/com/siyeh/ig/fixes/junit/UseOfObsoleteAssertInspectionTest.java b/plugins/InspectionGadgets/testsrc/com/siyeh/ig/fixes/junit/UseOfObsoleteAssertInspectionTest.java index d5604e093bba..544f71b6e5cf 100644 --- a/plugins/InspectionGadgets/testsrc/com/siyeh/ig/fixes/junit/UseOfObsoleteAssertInspectionTest.java +++ b/plugins/InspectionGadgets/testsrc/com/siyeh/ig/fixes/junit/UseOfObsoleteAssertInspectionTest.java @@ -15,6 +15,7 @@ */ package com.siyeh.ig.fixes.junit; +import com.siyeh.InspectionGadgetsBundle; import com.siyeh.ig.IGQuickFixesTestCase; import com.siyeh.ig.junit.UseOfObsoleteAssertInspection; @@ -56,7 +57,7 @@ public class UseOfObsoleteAssertInspectionTest extends IGQuickFixesTestCase { } private void doFixTest() { - doTest(getTestName(true), "Replace with org.junit.Assert"); + doTest(getTestName(true), InspectionGadgetsBundle.message("use.of.obsolete.assert.quickfix")); } @Override From 0bbf4ee0d4809078a339d8fc6bbcaaae5c155640 Mon Sep 17 00:00:00 2001 From: anna Date: Sun, 21 Aug 2011 15:11:16 +0200 Subject: [PATCH 65/78] NPE --- .../src/com/intellij/codeInsight/ExpectedTypesProvider.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/java/java-impl/src/com/intellij/codeInsight/ExpectedTypesProvider.java b/java/java-impl/src/com/intellij/codeInsight/ExpectedTypesProvider.java index b15c2381b54f..b4111d23d682 100644 --- a/java/java-impl/src/com/intellij/codeInsight/ExpectedTypesProvider.java +++ b/java/java-impl/src/com/intellij/codeInsight/ExpectedTypesProvider.java @@ -118,7 +118,9 @@ public class ExpectedTypesProvider { parent = parent.getParent(); } MyParentVisitor visitor = new MyParentVisitor(expr, forCompletion, classProvider, voidable, usedAfter); - parent.accept(visitor); + if (parent != null) { + parent.accept(visitor); + } return visitor.getResult(); } From a74d18b25c1bf578d8ca25c6b9019ea524817d1b Mon Sep 17 00:00:00 2001 From: Bas Leijdekkers Date: Sun, 21 Aug 2011 17:11:42 +0200 Subject: [PATCH 66/78] fix test --- .../com/intellij/openapi/util/text/StringUtil.java | 12 +++++++----- .../com/intellij/util/text/StringUtilTest.java | 1 + 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/platform/util/src/com/intellij/openapi/util/text/StringUtil.java b/platform/util/src/com/intellij/openapi/util/text/StringUtil.java index 924f215f57b9..a75857118f0b 100644 --- a/platform/util/src/com/intellij/openapi/util/text/StringUtil.java +++ b/platform/util/src/com/intellij/openapi/util/text/StringUtil.java @@ -2005,11 +2005,13 @@ public class StringUtil { return ch1 - ch2; } else { // similar logic to charsMatch() below - final int diff1 = Character.toUpperCase(ch1) - Character.toUpperCase(ch2); - if (diff1 != 0) { - final int diff2 = Character.toLowerCase(ch1) - Character.toLowerCase(ch2); - if (diff2 != 0) { - return diff1; + if (ch1 != ch2) { + final int diff1 = Character.toUpperCase(ch1) - Character.toUpperCase(ch2); + if (diff1 != 0) { + final int diff2 = Character.toLowerCase(ch1) - Character.toLowerCase(ch2); + if (diff2 != 0) { + return diff2; + } } } } diff --git a/platform/util/testSrc/com/intellij/util/text/StringUtilTest.java b/platform/util/testSrc/com/intellij/util/text/StringUtilTest.java index 7fcf7e528165..0fd8dbb0a499 100644 --- a/platform/util/testSrc/com/intellij/util/text/StringUtilTest.java +++ b/platform/util/testSrc/com/intellij/util/text/StringUtilTest.java @@ -87,5 +87,6 @@ public class StringUtilTest extends TestCase { Collections.sort(strings2, c); assertEquals(Arrays.asList("T1", "t1", "t001", "T2", "t2", "T002"), strings2); assertEquals(1 ,StringUtil.naturalCompare("7403515080361171695", "07403515080361171694")); + assertEquals(14, StringUtil.naturalCompare("_firstField", "myField1")); } } From 253912e033283f0e6dd30da60bd4929374ee6ee7 Mon Sep 17 00:00:00 2001 From: anna Date: Sun, 21 Aug 2011 15:15:22 +0200 Subject: [PATCH 67/78] inplace refactorings: no need to move caret to invalid offset after cancel the template (e.g. backspace everything to the file beginning) --- .../introduce/inplace/AbstractInplaceIntroducer.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/platform/lang-impl/src/com/intellij/refactoring/introduce/inplace/AbstractInplaceIntroducer.java b/platform/lang-impl/src/com/intellij/refactoring/introduce/inplace/AbstractInplaceIntroducer.java index 5821890d256f..f6b94827be0f 100644 --- a/platform/lang-impl/src/com/intellij/refactoring/introduce/inplace/AbstractInplaceIntroducer.java +++ b/platform/lang-impl/src/com/intellij/refactoring/introduce/inplace/AbstractInplaceIntroducer.java @@ -450,8 +450,11 @@ public abstract class AbstractInplaceIntroducer Date: Sun, 21 Aug 2011 15:59:53 +0200 Subject: [PATCH 68/78] inplace introduce parameter: no need to choose method when you only want to tweak settings in the dialog --- .../InplaceIntroduceParameterPopup.java | 8 ++++++++ .../introduceParameter/IntroduceParameterHandler.java | 7 +++++++ 2 files changed, 15 insertions(+) diff --git a/java/java-impl/src/com/intellij/refactoring/introduceParameter/InplaceIntroduceParameterPopup.java b/java/java-impl/src/com/intellij/refactoring/introduceParameter/InplaceIntroduceParameterPopup.java index 165cfa8eab5c..9ad45a24d8fa 100644 --- a/java/java-impl/src/com/intellij/refactoring/introduceParameter/InplaceIntroduceParameterPopup.java +++ b/java/java-impl/src/com/intellij/refactoring/introduceParameter/InplaceIntroduceParameterPopup.java @@ -291,4 +291,12 @@ public class InplaceIntroduceParameterPopup extends AbstractJavaInplaceIntroduce public void setReplaceAllOccurrences(boolean replaceAll) { myPanel.setReplaceAllOccurrences(replaceAll); } + + public PsiMethod getMethodToIntroduceParameter() { + return myMethod; + } + + public PsiMethod getMethodToSearchFor() { + return myMethodToSearchFor; + } } diff --git a/java/java-impl/src/com/intellij/refactoring/introduceParameter/IntroduceParameterHandler.java b/java/java-impl/src/com/intellij/refactoring/introduceParameter/IntroduceParameterHandler.java index a96489adbbdb..72804dca4e95 100644 --- a/java/java-impl/src/com/intellij/refactoring/introduceParameter/IntroduceParameterHandler.java +++ b/java/java-impl/src/com/intellij/refactoring/introduceParameter/IntroduceParameterHandler.java @@ -182,6 +182,13 @@ public class IntroduceParameterHandler extends IntroduceHandlerBase implements R private void chooseMethodToIntroduceParameter(final Editor editor, final List validEnclosingMethods, final Introducer introducer) { + final AbstractInplaceIntroducer inplaceIntroducer = AbstractInplaceIntroducer.getActiveIntroducer(editor); + if (inplaceIntroducer instanceof InplaceIntroduceParameterPopup) { + final InplaceIntroduceParameterPopup introduceParameterPopup = (InplaceIntroduceParameterPopup)inplaceIntroducer; + introducer.introduceParameter(introduceParameterPopup.getMethodToIntroduceParameter(), + introduceParameterPopup.getMethodToSearchFor()); + return; + } final JPanel panel = new JPanel(new BorderLayout()); final JCheckBox superMethod = new JCheckBox("Use super method of", true); superMethod.setMnemonic('U'); From 386cb944a674ef986e2a13d3445d71f6157b5025 Mon Sep 17 00:00:00 2001 From: anna Date: Sun, 21 Aug 2011 16:33:20 +0200 Subject: [PATCH 69/78] wording --- .../introduceParameter/IntroduceParameterHandler.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 72804dca4e95..692295ab092d 100644 --- a/java/java-impl/src/com/intellij/refactoring/introduceParameter/IntroduceParameterHandler.java +++ b/java/java-impl/src/com/intellij/refactoring/introduceParameter/IntroduceParameterHandler.java @@ -190,7 +190,7 @@ public class IntroduceParameterHandler extends IntroduceHandlerBase implements R return; } final JPanel panel = new JPanel(new BorderLayout()); - final JCheckBox superMethod = new JCheckBox("Use super method of", true); + final JCheckBox superMethod = new JCheckBox("Use super method", true); superMethod.setMnemonic('U'); panel.add(superMethod, BorderLayout.SOUTH); final JBList list = new JBList(validEnclosingMethods.toArray()); From 12e8bcbd5da140e893a0270575b6444dbb0b4066 Mon Sep 17 00:00:00 2001 From: anna Date: Sun, 21 Aug 2011 16:39:02 +0200 Subject: [PATCH 70/78] field can be local: exclude all fields used in fields initializers (IDEA-72649 ) --- .../FieldCanBeLocalInspection.java | 13 +++++-------- .../fieldUsedInConstantInitialization/expected.xml | 3 +++ .../fieldUsedInConstantInitialization/src/Test.java | 9 +++++++++ .../codeInspection/FieldCanBeLocalTest.java | 1 + 4 files changed, 18 insertions(+), 8 deletions(-) create mode 100644 java/java-tests/testData/inspection/fieldCanBeLocal/fieldUsedInConstantInitialization/expected.xml create mode 100644 java/java-tests/testData/inspection/fieldCanBeLocal/fieldUsedInConstantInitialization/src/Test.java diff --git a/java/java-impl/src/com/intellij/codeInspection/varScopeCanBeNarrowed/FieldCanBeLocalInspection.java b/java/java-impl/src/com/intellij/codeInspection/varScopeCanBeNarrowed/FieldCanBeLocalInspection.java index 07cce89f5c9e..d16812c94366 100644 --- a/java/java-impl/src/com/intellij/codeInspection/varScopeCanBeNarrowed/FieldCanBeLocalInspection.java +++ b/java/java-impl/src/com/intellij/codeInspection/varScopeCanBeNarrowed/FieldCanBeLocalInspection.java @@ -229,14 +229,11 @@ public class FieldCanBeLocalInspection extends BaseLocalInspectionTool { } @Override public void visitReferenceExpression(PsiReferenceExpression expression) { - final PsiExpression qualifier = expression.getQualifierExpression(); - if (qualifier == null || qualifier instanceof PsiThisExpression) { - final PsiElement resolved = expression.resolve(); - if (resolved instanceof PsiField) { - final PsiField field = (PsiField)resolved; - if (aClass.equals(field.getContainingClass())) { - candidates.remove(field); - } + final PsiElement resolved = expression.resolve(); + if (resolved instanceof PsiField) { + final PsiField field = (PsiField)resolved; + if (aClass.equals(field.getContainingClass())) { + candidates.remove(field); } } diff --git a/java/java-tests/testData/inspection/fieldCanBeLocal/fieldUsedInConstantInitialization/expected.xml b/java/java-tests/testData/inspection/fieldCanBeLocal/fieldUsedInConstantInitialization/expected.xml new file mode 100644 index 000000000000..580a889dbfd6 --- /dev/null +++ b/java/java-tests/testData/inspection/fieldCanBeLocal/fieldUsedInConstantInitialization/expected.xml @@ -0,0 +1,3 @@ + + + diff --git a/java/java-tests/testData/inspection/fieldCanBeLocal/fieldUsedInConstantInitialization/src/Test.java b/java/java-tests/testData/inspection/fieldCanBeLocal/fieldUsedInConstantInitialization/src/Test.java new file mode 100644 index 000000000000..6adc318926ac --- /dev/null +++ b/java/java-tests/testData/inspection/fieldCanBeLocal/fieldUsedInConstantInitialization/src/Test.java @@ -0,0 +1,9 @@ +class Test { + public static final Object FOO = new Test().foo; + + private final String foo; + + private Test() { + foo = "some text"; + } +} diff --git a/java/java-tests/testSrc/com/intellij/codeInspection/FieldCanBeLocalTest.java b/java/java-tests/testSrc/com/intellij/codeInspection/FieldCanBeLocalTest.java index 07076a6d6321..0a3039b5a4c1 100644 --- a/java/java-tests/testSrc/com/intellij/codeInspection/FieldCanBeLocalTest.java +++ b/java/java-tests/testSrc/com/intellij/codeInspection/FieldCanBeLocalTest.java @@ -30,6 +30,7 @@ public class FieldCanBeLocalTest extends InspectionTestCase { public void testLocalStateVar2InnerClass() throws Exception { doTest(); } public void testNotConstantInitializer() throws Exception {doTest();} public void testInnerClassFieldInitializer() throws Exception {doTest();} + public void testFieldUsedInConstantInitialization() throws Exception {doTest();} public void testFieldWithImmutableType() throws Exception {doTest();} public void testIgnoreAnnotated() throws Exception { final FieldCanBeLocalInspection inspection = new FieldCanBeLocalInspection(); From c71a873d1d6bf4596f5b5c71da11c1b640473851 Mon Sep 17 00:00:00 2001 From: anna Date: Sun, 21 Aug 2011 17:01:03 +0200 Subject: [PATCH 71/78] i18n && wording (IDEA-72585 ) --- .../impl/quickfix/ChangeMethodSignatureFromUsageFix.java | 6 +++--- .../quickFix/changeMethodSignatureFromUsage/after1.java | 2 +- .../quickFix/changeMethodSignatureFromUsage/after10.java | 2 +- .../quickFix/changeMethodSignatureFromUsage/after3.java | 2 +- .../quickFix/changeMethodSignatureFromUsage/after5.java | 2 +- .../quickFix/changeMethodSignatureFromUsage/after6.java | 2 +- .../quickFix/changeMethodSignatureFromUsage/after9.java | 2 +- .../afterEraseTypeIfSubstitutionNotFound.java | 2 +- ...afterEraseTypeIfSubstitutionNotFoundNotAConstructor.java | 2 +- .../changeMethodSignatureFromUsage/afterNewParamName.java | 2 +- .../changeMethodSignatureFromUsage/afterQualifiedTypes.java | 2 +- .../changeMethodSignatureFromUsage/afterVarargs1.java | 2 +- .../changeMethodSignatureFromUsage/afterVarargs2.java | 2 +- .../quickFix/changeMethodSignatureFromUsage/before1.java | 2 +- .../quickFix/changeMethodSignatureFromUsage/before10.java | 2 +- .../quickFix/changeMethodSignatureFromUsage/before3.java | 2 +- .../quickFix/changeMethodSignatureFromUsage/before5.java | 2 +- .../quickFix/changeMethodSignatureFromUsage/before6.java | 2 +- .../quickFix/changeMethodSignatureFromUsage/before9.java | 2 +- .../beforeEraseTypeIfSubstitutionNotFound.java | 2 +- ...eforeEraseTypeIfSubstitutionNotFoundNotAConstructor.java | 2 +- .../beforeExistSignature.java | 2 +- .../changeMethodSignatureFromUsage/beforeNewParamName.java | 2 +- .../changeMethodSignatureFromUsage/beforeNotAvailable.java | 2 +- .../beforeQualifiedTypes.java | 2 +- .../changeMethodSignatureFromUsage/beforeVarargs1.java | 2 +- .../changeMethodSignatureFromUsage/beforeVarargs2.java | 2 +- .../changeMethodSignatureFromUsage/beforeVarargs2Array.java | 2 +- resources-en/src/messages/QuickFixBundle.properties | 3 +++ 29 files changed, 33 insertions(+), 30 deletions(-) diff --git a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/ChangeMethodSignatureFromUsageFix.java b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/ChangeMethodSignatureFromUsageFix.java index e6485a72f24d..365ffac25a33 100644 --- a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/ChangeMethodSignatureFromUsageFix.java +++ b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/ChangeMethodSignatureFromUsageFix.java @@ -109,15 +109,15 @@ public class ChangeMethodSignatureFromUsageFix implements IntentionAction, HighP if (myTargetMethod.getContainingClass().findMethodsByName(targetMethodName, true).length == 1) { if (newParams.size() == 1) { final ParameterInfoImpl p = newParams.iterator().next(); - return "Add " + p.getTypeText() + " as " + (ArrayUtil.find(myNewParametersInfo, p) + 1) + " parameter to method " + targetMethodName; + return QuickFixBundle.message("add.parameter.from.usage.text", p.getTypeText(), (ArrayUtil.find(myNewParametersInfo, p) + 1), targetMethodName); } if (removedParams.size() == 1) { final ParameterInfoImpl p = removedParams.iterator().next(); - return "Remove " + (p.getOldIndex() + 1) + " parameter from method " + targetMethodName; + return QuickFixBundle.message("remove.parameter.from.usage.text", (p.getOldIndex() + 1), targetMethodName); } if (changedParams.size() == 1) { final ParameterInfoImpl p = changedParams.iterator().next(); - return "Change " + (p.getOldIndex() + 1)+ " parameter of method " +targetMethodName + " from " + myTargetMethod.getParameterList().getParameters()[p.getOldIndex()].getType().getPresentableText() + " to " + p.getTypeText(); + return QuickFixBundle.message("change.parameter.from.usage.text", (p.getOldIndex() + 1), targetMethodName, myTargetMethod.getParameterList().getParameters()[p.getOldIndex()].getType().getPresentableText(), p.getTypeText()); } } return " Change signature of " + targetMethodName + "(" + buf.toString() + ")"; diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/changeMethodSignatureFromUsage/after1.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/changeMethodSignatureFromUsage/after1.java index e0f952b64ec0..7360e006df98 100644 --- a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/changeMethodSignatureFromUsage/after1.java +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/changeMethodSignatureFromUsage/after1.java @@ -1,4 +1,4 @@ -// "Remove 1 parameter from method f" "true" +// "Remove 1st parameter from method 'f'" "true" class A { void f() {} public void foo() { diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/changeMethodSignatureFromUsage/after10.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/changeMethodSignatureFromUsage/after10.java index 63a621850328..108be299a769 100644 --- a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/changeMethodSignatureFromUsage/after10.java +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/changeMethodSignatureFromUsage/after10.java @@ -1,4 +1,4 @@ -// "Add String as 2 parameter to method set" "true" +// "Add 'String' as 2nd parameter to method 'set'" "true" import java.util.List; public class X { diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/changeMethodSignatureFromUsage/after3.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/changeMethodSignatureFromUsage/after3.java index b9b2da617f5c..bd42e46883e3 100644 --- a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/changeMethodSignatureFromUsage/after3.java +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/changeMethodSignatureFromUsage/after3.java @@ -1,4 +1,4 @@ -// "Add char as 2 parameter to method f" "true" +// "Add 'char' as 2nd parameter to method 'f'" "true" class A { void f(int i, char c, String s) {} public void foo() { diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/changeMethodSignatureFromUsage/after5.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/changeMethodSignatureFromUsage/after5.java index 41e0fdb48fd9..5acfab54d0b8 100644 --- a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/changeMethodSignatureFromUsage/after5.java +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/changeMethodSignatureFromUsage/after5.java @@ -1,4 +1,4 @@ -// "Remove 2 parameter from method f" "true" +// "Remove 2nd parameter from method 'f'" "true" class A { void f(int i, int i2) {} public void foo() { diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/changeMethodSignatureFromUsage/after6.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/changeMethodSignatureFromUsage/after6.java index 6d80ad364866..2fb3e8123f88 100644 --- a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/changeMethodSignatureFromUsage/after6.java +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/changeMethodSignatureFromUsage/after6.java @@ -1,4 +1,4 @@ -// "Change 2 parameter of method f from String to int" "true" +// "Change 2nd parameter of method 'f' from 'String' to 'int'" "true" class A { void f(int i, int s, int i2) {} public void foo() { diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/changeMethodSignatureFromUsage/after9.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/changeMethodSignatureFromUsage/after9.java index ac46bd572573..67b0c44e7856 100644 --- a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/changeMethodSignatureFromUsage/after9.java +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/changeMethodSignatureFromUsage/after9.java @@ -1,4 +1,4 @@ -// "Add int as 2 parameter to method f" "true" +// "Add 'int' as 2nd parameter to method 'f'" "true" public class S { void f(int k, int i, int... args) { f(1,1,null);// -> f(1,1,null) diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/changeMethodSignatureFromUsage/afterEraseTypeIfSubstitutionNotFound.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/changeMethodSignatureFromUsage/afterEraseTypeIfSubstitutionNotFound.java index 81fec921cc21..20f02d1ef2b1 100644 --- a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/changeMethodSignatureFromUsage/afterEraseTypeIfSubstitutionNotFound.java +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/changeMethodSignatureFromUsage/afterEraseTypeIfSubstitutionNotFound.java @@ -1,4 +1,4 @@ -// "Add Foo as 1 parameter to method Bar" "true" +// "Add 'Foo' as 1st parameter to method 'Bar'" "true" public class Bar { Bar(Foo typeParamNameFoo, String args) { diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/changeMethodSignatureFromUsage/afterEraseTypeIfSubstitutionNotFoundNotAConstructor.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/changeMethodSignatureFromUsage/afterEraseTypeIfSubstitutionNotFoundNotAConstructor.java index 59448b0ef9d9..98fd75fe9927 100644 --- a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/changeMethodSignatureFromUsage/afterEraseTypeIfSubstitutionNotFoundNotAConstructor.java +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/changeMethodSignatureFromUsage/afterEraseTypeIfSubstitutionNotFoundNotAConstructor.java @@ -1,4 +1,4 @@ -// "Add Foo as 1 parameter to method bar" "true" +// "Add 'Foo' as 1st parameter to method 'bar'" "true" public class Bar { static void bar(Foo typeParamNameFoo, String args) { diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/changeMethodSignatureFromUsage/afterNewParamName.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/changeMethodSignatureFromUsage/afterNewParamName.java index 227aaf2512b5..c3397418e3e3 100644 --- a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/changeMethodSignatureFromUsage/afterNewParamName.java +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/changeMethodSignatureFromUsage/afterNewParamName.java @@ -1,4 +1,4 @@ -// "Add int as 1 parameter to method f" "true" +// "Add 'int' as 1st parameter to method 'f'" "true" public class S { void f(int i, String args) { diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/changeMethodSignatureFromUsage/afterQualifiedTypes.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/changeMethodSignatureFromUsage/afterQualifiedTypes.java index 292baec43a73..80a544095fb5 100644 --- a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/changeMethodSignatureFromUsage/afterQualifiedTypes.java +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/changeMethodSignatureFromUsage/afterQualifiedTypes.java @@ -1,4 +1,4 @@ -// "Add Inner1 as 1 parameter to method Inner2" "true" +// "Add 'Inner1' as 1st parameter to method 'Inner2'" "true" class CoolTest { class Inner1 {} diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/changeMethodSignatureFromUsage/afterVarargs1.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/changeMethodSignatureFromUsage/afterVarargs1.java index f735bdd63db8..dcd3ce636a3a 100644 --- a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/changeMethodSignatureFromUsage/afterVarargs1.java +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/changeMethodSignatureFromUsage/afterVarargs1.java @@ -1,4 +1,4 @@ -// "Add String as 1 parameter to method f" "true" +// "Add 'String' as 1st parameter to method 'f'" "true" public class S { void f(String s, int... args) { f("",1,1); diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/changeMethodSignatureFromUsage/afterVarargs2.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/changeMethodSignatureFromUsage/afterVarargs2.java index d76e42fbb52b..55ab07ef2008 100644 --- a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/changeMethodSignatureFromUsage/afterVarargs2.java +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/changeMethodSignatureFromUsage/afterVarargs2.java @@ -1,4 +1,4 @@ -// "Add String as 1 parameter to method f" "true" +// "Add 'String' as 1st parameter to method 'f'" "true" public class S { void f(String s, int... args) { f("",null); diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/changeMethodSignatureFromUsage/before1.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/changeMethodSignatureFromUsage/before1.java index 184d20bfcfe5..3df2f76bf1e7 100644 --- a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/changeMethodSignatureFromUsage/before1.java +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/changeMethodSignatureFromUsage/before1.java @@ -1,4 +1,4 @@ -// "Remove 1 parameter from method f" "true" +// "Remove 1st parameter from method 'f'" "true" class A { void f(int i) {} public void foo() { diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/changeMethodSignatureFromUsage/before10.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/changeMethodSignatureFromUsage/before10.java index 2026129a4e98..5d966d846a0a 100644 --- a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/changeMethodSignatureFromUsage/before10.java +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/changeMethodSignatureFromUsage/before10.java @@ -1,4 +1,4 @@ -// "Add String as 2 parameter to method set" "true" +// "Add 'String' as 2nd parameter to method 'set'" "true" import java.util.List; public class X { diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/changeMethodSignatureFromUsage/before3.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/changeMethodSignatureFromUsage/before3.java index b75ee1a0e287..4e10744529a1 100644 --- a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/changeMethodSignatureFromUsage/before3.java +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/changeMethodSignatureFromUsage/before3.java @@ -1,4 +1,4 @@ -// "Add char as 2 parameter to method f" "true" +// "Add 'char' as 2nd parameter to method 'f'" "true" class A { void f(int i,String s) {} public void foo() { diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/changeMethodSignatureFromUsage/before5.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/changeMethodSignatureFromUsage/before5.java index 89e8dadd5c16..17e6682fcad9 100644 --- a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/changeMethodSignatureFromUsage/before5.java +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/changeMethodSignatureFromUsage/before5.java @@ -1,4 +1,4 @@ -// "Remove 2 parameter from method f" "true" +// "Remove 2nd parameter from method 'f'" "true" class A { void f(int i, String s, int i2) {} public void foo() { diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/changeMethodSignatureFromUsage/before6.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/changeMethodSignatureFromUsage/before6.java index da0e6178e093..628a6eccb800 100644 --- a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/changeMethodSignatureFromUsage/before6.java +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/changeMethodSignatureFromUsage/before6.java @@ -1,4 +1,4 @@ -// "Change 2 parameter of method f from String to int" "true" +// "Change 2nd parameter of method 'f' from 'String' to 'int'" "true" class A { void f(int i, String s, int i2) {} public void foo() { diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/changeMethodSignatureFromUsage/before9.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/changeMethodSignatureFromUsage/before9.java index 7dea4a36c6c8..d212efbcc9ef 100644 --- a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/changeMethodSignatureFromUsage/before9.java +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/changeMethodSignatureFromUsage/before9.java @@ -1,4 +1,4 @@ -// "Add int as 2 parameter to method f" "true" +// "Add 'int' as 2nd parameter to method 'f'" "true" public class S { void f(int k, int... args) { f(1,1,null);// -> f(1,1,null) diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/changeMethodSignatureFromUsage/beforeEraseTypeIfSubstitutionNotFound.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/changeMethodSignatureFromUsage/beforeEraseTypeIfSubstitutionNotFound.java index 54cfb7c19e12..6194d001d6ca 100644 --- a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/changeMethodSignatureFromUsage/beforeEraseTypeIfSubstitutionNotFound.java +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/changeMethodSignatureFromUsage/beforeEraseTypeIfSubstitutionNotFound.java @@ -1,4 +1,4 @@ -// "Add Foo as 1 parameter to method Bar" "true" +// "Add 'Foo' as 1st parameter to method 'Bar'" "true" public class Bar { Bar(String args) { diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/changeMethodSignatureFromUsage/beforeEraseTypeIfSubstitutionNotFoundNotAConstructor.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/changeMethodSignatureFromUsage/beforeEraseTypeIfSubstitutionNotFoundNotAConstructor.java index 3142f0b403a7..99623c4fdf08 100644 --- a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/changeMethodSignatureFromUsage/beforeEraseTypeIfSubstitutionNotFoundNotAConstructor.java +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/changeMethodSignatureFromUsage/beforeEraseTypeIfSubstitutionNotFoundNotAConstructor.java @@ -1,4 +1,4 @@ -// "Add Foo as 1 parameter to method bar" "true" +// "Add 'Foo' as 1st parameter to method 'bar'" "true" public class Bar { static void bar(String args) { diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/changeMethodSignatureFromUsage/beforeExistSignature.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/changeMethodSignatureFromUsage/beforeExistSignature.java index 7c26677ccf83..fe9dc930ee36 100644 --- a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/changeMethodSignatureFromUsage/beforeExistSignature.java +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/changeMethodSignatureFromUsage/beforeExistSignature.java @@ -1,4 +1,4 @@ -// "Add int as 1 parameter to method f" "false" +// "Add 'int' as 1st parameter to method 'f'" "false" public class Foo { void foo(Bar f) { f.f(2); diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/changeMethodSignatureFromUsage/beforeNewParamName.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/changeMethodSignatureFromUsage/beforeNewParamName.java index 37513c8d8e4a..5419bc85ef24 100644 --- a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/changeMethodSignatureFromUsage/beforeNewParamName.java +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/changeMethodSignatureFromUsage/beforeNewParamName.java @@ -1,4 +1,4 @@ -// "Add int as 1 parameter to method f" "true" +// "Add 'int' as 1st parameter to method 'f'" "true" public class S { void f(String args) { diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/changeMethodSignatureFromUsage/beforeNotAvailable.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/changeMethodSignatureFromUsage/beforeNotAvailable.java index 95bb03e7dbce..231855754787 100644 --- a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/changeMethodSignatureFromUsage/beforeNotAvailable.java +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/changeMethodSignatureFromUsage/beforeNotAvailable.java @@ -1,4 +1,4 @@ -// "Change 1 parameter of method parseInt from String to int" "false" +// "Change 1st parameter of method 'parseInt' from 'String' to 'int'" "false" class A { public void foo() { Integer.parseInt(1); diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/changeMethodSignatureFromUsage/beforeQualifiedTypes.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/changeMethodSignatureFromUsage/beforeQualifiedTypes.java index 124acc2a73d2..e64cd9737f1b 100644 --- a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/changeMethodSignatureFromUsage/beforeQualifiedTypes.java +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/changeMethodSignatureFromUsage/beforeQualifiedTypes.java @@ -1,4 +1,4 @@ -// "Add Inner1 as 1 parameter to method Inner2" "true" +// "Add 'Inner1' as 1st parameter to method 'Inner2'" "true" class CoolTest { class Inner1 {} diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/changeMethodSignatureFromUsage/beforeVarargs1.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/changeMethodSignatureFromUsage/beforeVarargs1.java index 4fce1077da3d..4ea15adc5d87 100644 --- a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/changeMethodSignatureFromUsage/beforeVarargs1.java +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/changeMethodSignatureFromUsage/beforeVarargs1.java @@ -1,4 +1,4 @@ -// "Add String as 1 parameter to method f" "true" +// "Add 'String' as 1st parameter to method 'f'" "true" public class S { void f(int... args) { f("",1,1); diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/changeMethodSignatureFromUsage/beforeVarargs2.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/changeMethodSignatureFromUsage/beforeVarargs2.java index e8f8013ac809..23362d91fdec 100644 --- a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/changeMethodSignatureFromUsage/beforeVarargs2.java +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/changeMethodSignatureFromUsage/beforeVarargs2.java @@ -1,4 +1,4 @@ -// "Add String as 1 parameter to method f" "true" +// "Add 'String' as 1st parameter to method 'f'" "true" public class S { void f(int... args) { f("",null); diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/changeMethodSignatureFromUsage/beforeVarargs2Array.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/changeMethodSignatureFromUsage/beforeVarargs2Array.java index ec86800c409f..af463ee4e1b5 100644 --- a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/changeMethodSignatureFromUsage/beforeVarargs2Array.java +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/changeMethodSignatureFromUsage/beforeVarargs2Array.java @@ -1,4 +1,4 @@ -// "Add String as 2nd parameter to method f" "false" +// "Add 'String' as 2nd parameter to method 'f'" "false" public class S { void f(int... args) { f(1,1, ""); diff --git a/resources-en/src/messages/QuickFixBundle.properties b/resources-en/src/messages/QuickFixBundle.properties index 3b9f912d78e2..697dc582a731 100644 --- a/resources-en/src/messages/QuickFixBundle.properties +++ b/resources-en/src/messages/QuickFixBundle.properties @@ -45,6 +45,9 @@ change.method.signature.from.usage.family=Change method signature from usage # {0} - original method signature including name, {1} - method name, {2} - proposed new parameters list change.method.signature.from.usage.text=Change signature of ''{0}'' to ''{1}({2})'' +add.parameter.from.usage.text=Add ''{0}'' as {1, choice, 1#1st|2#2nd|3#3rd|4#{0,number}th} parameter to method ''{2}'' +remove.parameter.from.usage.text=Remove {0, choice, 1#1st|2#2nd|3#3rd|4#{0,number}th} parameter from method ''{1}'' +change.parameter.from.usage.text=Change {0, choice, 1#1st|2#2nd|3#3rd|4#{0,number}th} parameter of method ''{1}'' from ''{2}'' to ''{3}'' searching.for.usages.progress.title=Searching For Usages... create.class.from.new.family=Create Class from New create.class.from.new.text=Create Class ''{0}'' From 5db84b0821bbad41ad0291aec7e6e583e59b2b29 Mon Sep 17 00:00:00 2001 From: anna Date: Sun, 21 Aug 2011 17:38:39 +0200 Subject: [PATCH 72/78] field can be local: preserve javadoc if any (IDEA-72663 ) --- .../FieldCanBeLocalInspection.java | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/java/java-impl/src/com/intellij/codeInspection/varScopeCanBeNarrowed/FieldCanBeLocalInspection.java b/java/java-impl/src/com/intellij/codeInspection/varScopeCanBeNarrowed/FieldCanBeLocalInspection.java index d16812c94366..bdd975abc162 100644 --- a/java/java-impl/src/com/intellij/codeInspection/varScopeCanBeNarrowed/FieldCanBeLocalInspection.java +++ b/java/java-impl/src/com/intellij/codeInspection/varScopeCanBeNarrowed/FieldCanBeLocalInspection.java @@ -25,6 +25,7 @@ import com.intellij.codeInspection.ProblemDescriptor; import com.intellij.codeInspection.ProblemsHolder; import com.intellij.codeInspection.ex.BaseLocalInspectionTool; import com.intellij.codeInspection.util.SpecialAnnotationsUtil; +import com.intellij.lang.java.JavaCommenter; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.editor.Editor; import com.intellij.openapi.editor.ScrollType; @@ -39,6 +40,7 @@ import com.intellij.psi.*; import com.intellij.psi.codeStyle.JavaCodeStyleManager; import com.intellij.psi.codeStyle.VariableKind; import com.intellij.psi.controlFlow.*; +import com.intellij.psi.javadoc.PsiDocComment; import com.intellij.psi.search.searches.ReferencesSearch; import com.intellij.psi.util.PsiTreeUtil; import com.intellij.psi.util.PsiUtil; @@ -262,6 +264,7 @@ public class FieldCanBeLocalInspection extends BaseLocalInspectionTool { PsiField myField = PsiTreeUtil.getParentOfType(element, PsiField.class); if (myField == null || !myField.isValid()) return; //weird. should not get here when field becomes invalid + final PsiDocComment docComment = myField.getDocComment(); final Collection refs = ReferencesSearch.search(myField).findAll(); if (refs.isEmpty()) return; Set refsSet = new HashSet(refs); @@ -308,6 +311,20 @@ public class FieldCanBeLocalInspection extends BaseLocalInspectionTool { } if (newDeclaration != null) { + if (docComment != null) { + final StringBuilder buf = new StringBuilder(); + for (PsiElement psiElement : docComment.getDescriptionElements()) { + buf.append(psiElement.getText()); + } + if (buf.length() > 0) { + final JavaCommenter commenter = new JavaCommenter(); + final PsiComment comment = JavaPsiFacade.getElementFactory(project) + .createCommentFromText(commenter.getBlockCommentPrefix() + + buf.toString() + + commenter.getBlockCommentSuffix(), newDeclaration); + newDeclaration.getParent().addBefore(comment, newDeclaration); + } + } final PsiFile psiFile = myField.getContainingFile(); final Editor editor = FileEditorManager.getInstance(project).getSelectedTextEditor(); if (editor != null && IJSwingUtilities.hasFocus(editor.getComponent())) { From ffad82a5d3300d867a338214383f81fa1dcc271d Mon Sep 17 00:00:00 2001 From: Bas Leijdekkers Date: Sun, 21 Aug 2011 18:12:41 +0200 Subject: [PATCH 73/78] fixing the test fix --- .../util/testSrc/com/intellij/util/text/StringUtilTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/platform/util/testSrc/com/intellij/util/text/StringUtilTest.java b/platform/util/testSrc/com/intellij/util/text/StringUtilTest.java index 0fd8dbb0a499..fef119fc77fb 100644 --- a/platform/util/testSrc/com/intellij/util/text/StringUtilTest.java +++ b/platform/util/testSrc/com/intellij/util/text/StringUtilTest.java @@ -87,6 +87,6 @@ public class StringUtilTest extends TestCase { Collections.sort(strings2, c); assertEquals(Arrays.asList("T1", "t1", "t001", "T2", "t2", "T002"), strings2); assertEquals(1 ,StringUtil.naturalCompare("7403515080361171695", "07403515080361171694")); - assertEquals(14, StringUtil.naturalCompare("_firstField", "myField1")); + assertEquals(-14, StringUtil.naturalCompare("_firstField", "myField1")); } } From aef6dc570d3294e75f6df39e823539e5b8a96eae Mon Sep 17 00:00:00 2001 From: Sergey Evdokimov Date: Sun, 21 Aug 2011 22:46:25 +0400 Subject: [PATCH 74/78] Minor code changes: the variable to hold Recursion guard instance should be static. --- .../groovy/lang/psi/impl/statements/GrVariableBaseImpl.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/statements/GrVariableBaseImpl.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/statements/GrVariableBaseImpl.java index a31a7714ebac..334b19bceb9d 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/statements/GrVariableBaseImpl.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/statements/GrVariableBaseImpl.java @@ -60,7 +60,7 @@ import javax.swing.*; public abstract class GrVariableBaseImpl extends GrStubElementBase implements GrVariable { public static final Logger LOG = Logger.getInstance("org.jetbrains.plugins.groovy.lang.psi.impl.statements.GrVariableImpl"); - private final RecursionGuard myGuard = RecursionManager.createGuard("grVariableInitializer"); + private static final RecursionGuard ourGuard = RecursionManager.createGuard("grVariableInitializer"); public GrVariableBaseImpl(ASTNode node) { super(node); @@ -165,7 +165,7 @@ public abstract class GrVariableBaseImpl extends GrStubEl } if (initializer != null) { - PsiType initializerType = myGuard.doPreventingRecursion(this, true, new NullableComputable() { + PsiType initializerType = ourGuard.doPreventingRecursion(this, true, new NullableComputable() { @Override public PsiType compute() { return initializer.getType(); From b993c3238b0bef4b1b534039912b40761ffe7b90 Mon Sep 17 00:00:00 2001 From: Sergey Evdokimov Date: Sun, 21 Aug 2011 22:56:22 +0400 Subject: [PATCH 75/78] Extension 'methodDescriptor' should allow specify that method return type is a type what return closure passed as parameter. Example: --- .../GrDescriptorReturnTypeCalculator.java | 32 ++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/statements/expressions/path/GrDescriptorReturnTypeCalculator.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/statements/expressions/path/GrDescriptorReturnTypeCalculator.java index 73bfac77f632..a76274b97507 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/statements/expressions/path/GrDescriptorReturnTypeCalculator.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/statements/expressions/path/GrDescriptorReturnTypeCalculator.java @@ -1,12 +1,17 @@ package org.jetbrains.plugins.groovy.lang.psi.impl.statements.expressions.path; +import com.intellij.openapi.util.Computable; import com.intellij.openapi.util.Pair; +import com.intellij.openapi.util.RecursionGuard; +import com.intellij.openapi.util.RecursionManager; import com.intellij.openapi.util.text.StringUtil; import com.intellij.psi.*; import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; +import org.jetbrains.plugins.groovy.lang.psi.api.statements.blocks.GrClosableBlock; +import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression; import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrMethodCall; import org.jetbrains.plugins.groovy.lang.psi.impl.statements.expressions.TypesUtil; +import org.jetbrains.plugins.groovy.lang.psi.util.PsiUtil; import java.util.ArrayList; import java.util.HashMap; @@ -18,6 +23,8 @@ import java.util.Map; */ public class GrDescriptorReturnTypeCalculator extends GrCallExpressionTypeCalculator { + private static final RecursionGuard ourGuard = RecursionManager.createGuard("GrDescriptorReturnTypeCalculator getClosureReturnType"); + private Map>>> map; private Map>>> getMap() { @@ -107,6 +114,29 @@ public class GrDescriptorReturnTypeCalculator extends GrCallExpressionTypeCalcul if (typeName == null) return null; + if (typeName.equals("!closure")) { + GrExpression[] allArguments = PsiUtil.getAllArguments(callExpression); + GrClosableBlock closure = null; + + for (GrExpression argument : allArguments) { + if (argument instanceof GrClosableBlock) { + closure = (GrClosableBlock)argument; + break; + } + } + + if (closure == null) return null; + + final GrClosableBlock finalClosure = closure; + + return ourGuard.doPreventingRecursion(callExpression, true, new Computable() { + @Override + public PsiType compute() { + return finalClosure.getReturnType(); + } + }); + } + if (typeName.endsWith("[]")) { PsiClassType type = TypesUtil.createType(typeName.substring(0, typeName.length() - 2), callExpression); return type.createArrayType(); From 68a6163709f107ab5469c8d604f50217cfd409df Mon Sep 17 00:00:00 2001 From: Sergey Evdokimov Date: Sun, 21 Aug 2011 23:16:12 +0400 Subject: [PATCH 76/78] Simplifying methodDescriptor bean. --- .../path/GrDescriptorReturnTypeCalculator.java | 18 +++++++++--------- .../path/GrMethodReturnTypeDescriptor.java | 9 ++------- 2 files changed, 11 insertions(+), 16 deletions(-) diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/statements/expressions/path/GrDescriptorReturnTypeCalculator.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/statements/expressions/path/GrDescriptorReturnTypeCalculator.java index a76274b97507..d01d5fb4239c 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/statements/expressions/path/GrDescriptorReturnTypeCalculator.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/statements/expressions/path/GrDescriptorReturnTypeCalculator.java @@ -49,21 +49,21 @@ public class GrDescriptorReturnTypeCalculator extends GrCallExpressionTypeCalcul GrMethodReturnTypeDescriptor.Param[] params; - if (descriptor.anyParams != null) { - assert descriptor.anyParams.length == 1; - assert descriptor.params == null; - assert pairs.isEmpty(); - - params = null; - } - else { + if (descriptor.params != null) { params = descriptor.params; - if (params == null) params = GrMethodReturnTypeDescriptor.Param.EMPTY_ARRAY; + assert params != null; + assert (descriptor.checkParamsType == null || descriptor.checkParamsType); for (GrMethodReturnTypeDescriptor.Param param : params) { assert StringUtil.isNotEmpty(param.type); } } + else if (descriptor.checkParamsType != null && descriptor.checkParamsType) { + params = GrMethodReturnTypeDescriptor.Param.EMPTY_ARRAY; + } + else { + params = null; + } assert StringUtil.isNotEmpty(descriptor.returnType); pairs.add(new Pair(params, descriptor.returnType)); diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/statements/expressions/path/GrMethodReturnTypeDescriptor.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/statements/expressions/path/GrMethodReturnTypeDescriptor.java index 791670457750..1b0c49c5d2fc 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/statements/expressions/path/GrMethodReturnTypeDescriptor.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/statements/expressions/path/GrMethodReturnTypeDescriptor.java @@ -23,9 +23,8 @@ public class GrMethodReturnTypeDescriptor { @Attribute("returnType") public String returnType; - @Property(surroundWithTag = false) - @AbstractCollection(surroundWithTag = false) - public AnyParams[] anyParams; + @Attribute("checkParamsType") + public Boolean checkParamsType; @Property(surroundWithTag = false) @AbstractCollection(surroundWithTag = false) @@ -40,8 +39,4 @@ public class GrMethodReturnTypeDescriptor { public String type; } - @Tag("anyParams") - public static class AnyParams { - - } } From 3923e63f05e583f640a0ee23db091fc7164ef8d1 Mon Sep 17 00:00:00 2001 From: Sergey Evdokimov Date: Mon, 22 Aug 2011 00:16:46 +0400 Subject: [PATCH 77/78] Provide return types and named argument lists for methods provided by Gorm*Api. --- .../path/GrDescriptorReturnTypeCalculator.java | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/statements/expressions/path/GrDescriptorReturnTypeCalculator.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/statements/expressions/path/GrDescriptorReturnTypeCalculator.java index d01d5fb4239c..0f825eeaf434 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/statements/expressions/path/GrDescriptorReturnTypeCalculator.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/statements/expressions/path/GrDescriptorReturnTypeCalculator.java @@ -132,16 +132,13 @@ public class GrDescriptorReturnTypeCalculator extends GrCallExpressionTypeCalcul return ourGuard.doPreventingRecursion(callExpression, true, new Computable() { @Override public PsiType compute() { - return finalClosure.getReturnType(); + PsiType returnType = finalClosure.getReturnType(); + if (returnType == PsiType.VOID) return null; + return returnType; } }); } - if (typeName.endsWith("[]")) { - PsiClassType type = TypesUtil.createType(typeName.substring(0, typeName.length() - 2), callExpression); - return type.createArrayType(); - } - - return TypesUtil.createType(typeName, callExpression); + return JavaPsiFacade.getElementFactory(containingClass.getProject()).createTypeFromText(typeName, callExpression); } } From 30cca7b694fa2ac5f5019d8531c6b80dea6d62cc Mon Sep 17 00:00:00 2001 From: "Kirill.Safonov" Date: Fri, 19 Aug 2011 15:05:41 +0400 Subject: [PATCH 78/78] attachments table columns names --- .../intellij/diagnostic/errordialog/AttachmentsTabForm.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/platform/platform-impl/src/com/intellij/diagnostic/errordialog/AttachmentsTabForm.java b/platform/platform-impl/src/com/intellij/diagnostic/errordialog/AttachmentsTabForm.java index acfbe588c5a5..218cad59484f 100644 --- a/platform/platform-impl/src/com/intellij/diagnostic/errordialog/AttachmentsTabForm.java +++ b/platform/platform-impl/src/com/intellij/diagnostic/errordialog/AttachmentsTabForm.java @@ -25,7 +25,7 @@ public class AttachmentsTabForm { private LabeledTextComponent myFileTextArea; private final ColumnInfo ENABLED_COLUMN = - new ColumnInfo(DiagnosticBundle.message("error.dialog.attachment.path.column.title")) { + new ColumnInfo(DiagnosticBundle.message("error.dialog.attachment.include.column.title")) { @Override public Boolean valueOf(Attachment attachment) { return attachment.isIncluded(); @@ -53,7 +53,7 @@ public class AttachmentsTabForm { }; private static final ColumnInfo PATH_COLUMN = - new ColumnInfo(DiagnosticBundle.message("error.dialog.attachment.include.column.title")) { + new ColumnInfo(DiagnosticBundle.message("error.dialog.attachment.path.column.title")) { @Override public String valueOf(Attachment attachment) { return attachment.getPath();