From 653c18cf45ced5dee91ba5080eb8d930e8bf0d6a Mon Sep 17 00:00:00 2001 From: Bas Leijdekkers Date: Fri, 19 Aug 2011 10:48:54 +0200 Subject: [PATCH] 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(); } }