diff --git a/java/java-analysis-api/src/com/intellij/codeInsight/intention/QuickFixFactory.java b/java/java-analysis-api/src/com/intellij/codeInsight/intention/QuickFixFactory.java index ecc901141990..1a54284d17a3 100644 --- a/java/java-analysis-api/src/com/intellij/codeInsight/intention/QuickFixFactory.java +++ b/java/java-analysis-api/src/com/intellij/codeInsight/intention/QuickFixFactory.java @@ -260,4 +260,6 @@ public abstract class QuickFixFactory { public abstract IntentionAction createAddMissingRequiredAnnotationParametersFix(@NotNull PsiAnnotation annotation, @NotNull PsiMethod[] annotationMethods, @NotNull Collection missedElements); + @NotNull + public abstract IntentionAction createSurroundWithQuotesAnnotationParameterValueFix(@NotNull PsiAnnotationMemberValue value, @NotNull PsiType expectedType); } diff --git a/java/java-analysis-impl/src/com/intellij/codeInsight/daemon/impl/analysis/AnnotationsHighlightUtil.java b/java/java-analysis-impl/src/com/intellij/codeInsight/daemon/impl/analysis/AnnotationsHighlightUtil.java index ace1a768cc55..ad17594a8c1f 100644 --- a/java/java-analysis-impl/src/com/intellij/codeInsight/daemon/impl/analysis/AnnotationsHighlightUtil.java +++ b/java/java-analysis-impl/src/com/intellij/codeInsight/daemon/impl/analysis/AnnotationsHighlightUtil.java @@ -153,7 +153,10 @@ public class AnnotationsHighlightUtil { String description = JavaErrorMessages.message("annotation.incompatible.types", JavaHighlightUtil.formatType(type), JavaHighlightUtil.formatType(expectedType)); - return HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(value).descriptionAndTooltip(description).create(); + final HighlightInfo info = + HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(value).descriptionAndTooltip(description).create(); + QuickFixAction.registerQuickFixAction(info, QuickFixFactory.getInstance().createSurroundWithQuotesAnnotationParameterValueFix(value, expectedType)); + return info; } LOG.error("Unknown annotation member value: " + value); diff --git a/java/java-analysis-impl/src/com/intellij/codeInsight/intention/EmptyQuickFixFactory.java b/java/java-analysis-impl/src/com/intellij/codeInsight/intention/EmptyQuickFixFactory.java index 475d278d3e8f..a69603bdcecd 100644 --- a/java/java-analysis-impl/src/com/intellij/codeInsight/intention/EmptyQuickFixFactory.java +++ b/java/java-analysis-impl/src/com/intellij/codeInsight/intention/EmptyQuickFixFactory.java @@ -595,4 +595,11 @@ public class EmptyQuickFixFactory extends QuickFixFactory { public IntentionAction createAddMissingRequiredAnnotationParametersFix(@NotNull PsiAnnotation psiAnnotation, @NotNull PsiMethod[] psiMethods, @NotNull Collection strings) { return QuickFixes.EMPTY_FIX; } + + @NotNull + @Override + public IntentionAction createSurroundWithQuotesAnnotationParameterValueFix(@NotNull PsiAnnotationMemberValue value, + @NotNull PsiType expectedType) { + return QuickFixes.EMPTY_FIX; + } } diff --git a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/SurroundWithQuotesAnnotationParameterValueFix.java b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/SurroundWithQuotesAnnotationParameterValueFix.java new file mode 100644 index 000000000000..a920d16126e0 --- /dev/null +++ b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/SurroundWithQuotesAnnotationParameterValueFix.java @@ -0,0 +1,76 @@ +/* + * Copyright 2000-2014 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.daemon.impl.quickfix; + +import com.intellij.codeInsight.intention.IntentionAction; +import com.intellij.openapi.editor.Editor; +import com.intellij.openapi.project.Project; +import com.intellij.openapi.util.text.StringUtil; +import com.intellij.psi.*; +import com.intellij.psi.util.PsiTreeUtil; +import com.intellij.util.IncorrectOperationException; +import org.jetbrains.annotations.NotNull; + +/** + * @author Dmitry Batkovich + */ +public class SurroundWithQuotesAnnotationParameterValueFix implements IntentionAction { + private final PsiAnnotationMemberValue myValue; + private final PsiType myExpectedType; + + public SurroundWithQuotesAnnotationParameterValueFix(final PsiAnnotationMemberValue value, final PsiType expectedType) { + myValue = value; + myExpectedType = expectedType; + } + + @Override + public boolean isAvailable(@NotNull Project project, Editor editor, PsiFile file) { + if (!myValue.isValid() || !(myExpectedType instanceof PsiClassType)) { + return false; + } + final PsiClass resolvedType = ((PsiClassType)myExpectedType).resolve(); + return resolvedType != null && CommonClassNames.JAVA_LANG_STRING.equals(resolvedType.getQualifiedName()) && myValue instanceof PsiLiteralExpression; + } + + @Override + public void invoke(@NotNull Project project, Editor editor, PsiFile file) throws IncorrectOperationException { + String newText = myValue.getText(); + newText = StringUtil.stripQuotesAroundValue(newText); + newText = "\"" + newText + "\""; + PsiElement newToken = JavaPsiFacade.getInstance(project).getElementFactory().createExpressionFromText(newText, null); + final PsiElement newElement = myValue.replace(newToken); + editor.getCaretModel().moveToOffset(newElement.getTextOffset() + newElement.getTextLength()); + } + + @NotNull + @Override + public String getFamilyName() { + return "Surround annotation parameter value with quotes"; + } + + @NotNull + @Override + public String getText() { + return getFamilyName(); + } + + @Override + public boolean startInWriteAction() { + return true; + } + + +} diff --git a/java/java-impl/src/com/intellij/codeInsight/intention/impl/CreateSwitchIntention.java b/java/java-impl/src/com/intellij/codeInsight/intention/impl/CreateSwitchIntention.java index 2e1e1b16bd49..63426b8f1ada 100644 --- a/java/java-impl/src/com/intellij/codeInsight/intention/impl/CreateSwitchIntention.java +++ b/java/java-impl/src/com/intellij/codeInsight/intention/impl/CreateSwitchIntention.java @@ -15,13 +15,15 @@ */ package com.intellij.codeInsight.intention.impl; +import com.intellij.codeInsight.FileModificationService; import com.intellij.codeInsight.intention.BaseElementAtCaretIntentionAction; -import com.intellij.codeInsight.intention.PsiElementBaseIntentionAction; import com.intellij.openapi.editor.Document; 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.PsiTreeUtil; +import com.intellij.psi.util.PsiUtil; import com.intellij.util.IncorrectOperationException; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -34,11 +36,15 @@ public class CreateSwitchIntention extends BaseElementAtCaretIntentionAction { @Override public void invoke(@NotNull final Project project, final Editor editor, @NotNull final PsiElement element) throws IncorrectOperationException { + if (!FileModificationService.getInstance().preparePsiElementsForWrite(element)) { + return; + } final PsiExpressionStatement expressionStatement = resolveExpressionStatement(element); final PsiElementFactory elementFactory = JavaPsiFacade.getInstance(project).getElementFactory(); PsiSwitchStatement switchStatement = (PsiSwitchStatement)elementFactory .createStatementFromText(String.format("switch (%s) {\n$MARKER$\n}", expressionStatement.getExpression().getText()), null); switchStatement = (PsiSwitchStatement)expressionStatement.replace(switchStatement); + CodeStyleManager.getInstance(project).reformat(switchStatement); for (final PsiStatement psiStatement : switchStatement.getBody().getStatements()) { if (psiStatement.getText().equals("$MARKER$")) { @@ -55,7 +61,7 @@ public class CreateSwitchIntention extends BaseElementAtCaretIntentionAction { @Override public boolean isAvailable(@NotNull final Project project, final Editor editor, @NotNull final PsiElement element) { final PsiExpressionStatement expressionStatement = resolveExpressionStatement(element); - return expressionStatement != null && isValidTypeForSwitch(expressionStatement.getExpression().getType()); + return expressionStatement != null && isValidTypeForSwitch(expressionStatement.getExpression().getType(), expressionStatement); } private static PsiExpressionStatement resolveExpressionStatement(final PsiElement element) { @@ -67,7 +73,7 @@ public class CreateSwitchIntention extends BaseElementAtCaretIntentionAction { } } - private static boolean isValidTypeForSwitch(@Nullable final PsiType type) { + private static boolean isValidTypeForSwitch(@Nullable final PsiType type, final PsiElement context) { if (type == null) { return false; } @@ -77,7 +83,8 @@ public class CreateSwitchIntention extends BaseElementAtCaretIntentionAction { if (resolvedClass == null) { return false; } - return resolvedClass.isEnum() || (CommonClassNames.JAVA_LANG_STRING.equals(resolvedClass.getQualifiedName())); + return (PsiUtil.isLanguageLevel5OrHigher(context) && resolvedClass.isEnum()) + || (PsiUtil.isLanguageLevel7OrHigher(context) && CommonClassNames.JAVA_LANG_STRING.equals(resolvedClass.getQualifiedName())); } return type.equals(PsiType.INT) || type.equals(PsiType.BYTE) || type.equals(PsiType.SHORT) || type.equals(PsiType.CHAR); } diff --git a/java/java-impl/src/com/intellij/codeInsight/intention/impl/SurroundWithQuotesStringAnnotationParameterValueIntention.java b/java/java-impl/src/com/intellij/codeInsight/intention/impl/SurroundWithQuotesStringAnnotationParameterValueIntention.java deleted file mode 100644 index abda3c42dc6f..000000000000 --- a/java/java-impl/src/com/intellij/codeInsight/intention/impl/SurroundWithQuotesStringAnnotationParameterValueIntention.java +++ /dev/null @@ -1,105 +0,0 @@ -/* -* Copyright 2000-2014 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.intention.PsiElementBaseIntentionAction; -import com.intellij.openapi.editor.Editor; -import com.intellij.openapi.project.Project; -import com.intellij.psi.*; -import com.intellij.psi.tree.IElementType; -import com.intellij.psi.util.PsiTreeUtil; -import com.intellij.util.IncorrectOperationException; -import com.intellij.util.containers.ContainerUtil; -import org.jetbrains.annotations.NotNull; - -import java.util.Set; - -/** -* @author Dmitry Batkovich -*/ -public class SurroundWithQuotesStringAnnotationParameterValueIntention extends PsiElementBaseIntentionAction { - private static final Set SUITABLE_TYPES = ContainerUtil.newHashSet(JavaTokenType.LONG_LITERAL, - JavaTokenType.FLOAT_LITERAL, - JavaTokenType.INTEGER_LITERAL, - JavaTokenType.DOUBLE_LITERAL, - JavaTokenType.CHARACTER_LITERAL, - JavaTokenType.TRUE_KEYWORD, - JavaTokenType.FALSE_KEYWORD); - - @Override - public void invoke(@NotNull Project project, Editor editor, @NotNull PsiElement element) throws IncorrectOperationException { - String newText = element.getText(); - if (((PsiJavaToken)element).getTokenType().equals(JavaTokenType.CHARACTER_LITERAL)) { - newText = newText.substring(1, newText.length() - 1); - } - newText = "\"" + newText + "\""; - PsiElement newToken = JavaPsiFacade.getInstance(project).getElementFactory().createExpressionFromText(newText, null).getFirstChild(); - final PsiElement newElement = element.replace(newToken); - editor.getCaretModel().moveToOffset(newElement.getTextOffset() + newElement.getTextLength()); - } - - @Override - public boolean isAvailable(@NotNull Project project, Editor editor, @NotNull PsiElement element) { - if (!(element instanceof PsiJavaToken && SUITABLE_TYPES.contains(((PsiJavaToken)element).getTokenType()))) { - return false; - } - final PsiElement literalExpression = element.getParent(); - if (literalExpression == null) { - return false; - } - final PsiElement nameValuePair = literalExpression.getParent(); - if (!(nameValuePair instanceof PsiNameValuePair)) { - return false; - } - final PsiAnnotation annotation = PsiTreeUtil.getParentOfType(nameValuePair, PsiAnnotation.class); - if (annotation == null) { - return false; - } - final PsiJavaCodeReferenceElement nameRef = annotation.getNameReferenceElement(); - if (nameRef == null) { - return false; - } - final PsiElement resolved = nameRef.resolve(); - if (!(resolved instanceof PsiClass)) { - return false; - } - final String parameterName = ((PsiNameValuePair)nameValuePair).getName(); - final PsiMethod[] methods = - ((PsiClass)resolved).findMethodsByName(parameterName == null ? PsiAnnotation.DEFAULT_REFERENCED_METHOD_NAME : parameterName, false); - if (methods.length != 1) { - return false; - } - final PsiType methodReturnType = methods[0].getReturnType(); - if (!(methodReturnType instanceof PsiClassType)) { - return false; - } - final PsiClass returnTypeClass = ((PsiClassType)methodReturnType).resolve(); - return returnTypeClass != null && CommonClassNames.JAVA_LANG_STRING.equals(returnTypeClass.getQualifiedName()); - } - - - @NotNull - @Override - public String getFamilyName() { - return "Surround annotation parameter value with quotes"; - } - - @NotNull - @Override - public String getText() { - return getFamilyName(); - } -} diff --git a/java/java-impl/src/com/intellij/codeInsight/intention/impl/config/QuickFixFactoryImpl.java b/java/java-impl/src/com/intellij/codeInsight/intention/impl/config/QuickFixFactoryImpl.java index 0073576adcfc..e934a9f387cf 100644 --- a/java/java-impl/src/com/intellij/codeInsight/intention/impl/config/QuickFixFactoryImpl.java +++ b/java/java-impl/src/com/intellij/codeInsight/intention/impl/config/QuickFixFactoryImpl.java @@ -755,6 +755,13 @@ public class QuickFixFactoryImpl extends QuickFixFactory { return new AddMissingRequiredAnnotationParametersFix(annotation, annotationMethods, missedElements); } + @NotNull + @Override + public IntentionAction createSurroundWithQuotesAnnotationParameterValueFix(@NotNull PsiAnnotationMemberValue value, + @NotNull PsiType expectedType) { + return new SurroundWithQuotesAnnotationParameterValueFix(value, expectedType); + } + private static boolean timeToOptimizeImports(@NotNull PsiFile file) { if (!CodeInsightSettings.getInstance().OPTIMIZE_IMPORTS_ON_THE_FLY) return false; diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/intention/SurroundWithQuotesStringAnnotationParameterValueTest.java b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/quickFix/SurroundWithQuotesStringAnnotationParameterValueTest.java similarity index 95% rename from java/java-tests/testSrc/com/intellij/codeInsight/intention/SurroundWithQuotesStringAnnotationParameterValueTest.java rename to java/java-tests/testSrc/com/intellij/codeInsight/daemon/quickFix/SurroundWithQuotesStringAnnotationParameterValueTest.java index b420a8819c5f..15c3de5b7931 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/intention/SurroundWithQuotesStringAnnotationParameterValueTest.java +++ b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/quickFix/SurroundWithQuotesStringAnnotationParameterValueTest.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.intellij.codeInsight.intention; +package com.intellij.codeInsight.daemon.quickFix; import com.intellij.codeInsight.daemon.LightIntentionActionTestCase; diff --git a/platform/lang-impl/src/com/intellij/application/options/codeStyle/CodeStyleMainPanel.java b/platform/lang-impl/src/com/intellij/application/options/codeStyle/CodeStyleMainPanel.java index 4db811b4fdb9..3a710fd96277 100644 --- a/platform/lang-impl/src/com/intellij/application/options/codeStyle/CodeStyleMainPanel.java +++ b/platform/lang-impl/src/com/intellij/application/options/codeStyle/CodeStyleMainPanel.java @@ -226,7 +226,6 @@ public class CodeStyleMainPanel extends JPanel implements LanguageSelectorListen panel.setModel(myModel); mySettingsPanels.put(name, panel); mySettingsPanel.add(scheme.getName(), panel); - mySchemesPanel.setCodeStyleSettingsPanel(panel); panel.setLanguage(myLangSelector.getLanguage()); } diff --git a/platform/lang-impl/src/com/intellij/application/options/codeStyle/CodeStyleSchemesPanel.java b/platform/lang-impl/src/com/intellij/application/options/codeStyle/CodeStyleSchemesPanel.java index 0f3ad0fcf674..b4a2a2476a00 100644 --- a/platform/lang-impl/src/com/intellij/application/options/codeStyle/CodeStyleSchemesPanel.java +++ b/platform/lang-impl/src/com/intellij/application/options/codeStyle/CodeStyleSchemesPanel.java @@ -20,6 +20,7 @@ package com.intellij.application.options.codeStyle; import com.intellij.openapi.application.ApplicationManager; import com.intellij.psi.codeStyle.CodeStyleScheme; import com.intellij.ui.ListCellRendererWrapper; +import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import javax.swing.*; @@ -29,7 +30,7 @@ import java.awt.event.ActionListener; import java.util.ArrayList; import java.util.List; -public class CodeStyleSchemesPanel{ +public class CodeStyleSchemesPanel { private JComboBox myCombo; private final CodeStyleSchemesModel myModel; @@ -37,7 +38,6 @@ public class CodeStyleSchemesPanel{ private JButton myManageButton; private boolean myIsReset = false; - private NewCodeStyleSettingsPanel mySettingsPanel; private final Font myDefaultComboFont; private final Font myBoldComboFont; @@ -48,7 +48,7 @@ public class CodeStyleSchemesPanel{ myBoldComboFont = myDefaultComboFont.deriveFont(Font.BOLD); myCombo.addActionListener(new ActionListener() { @Override - public void actionPerformed(ActionEvent e) { + public void actionPerformed(@NotNull ActionEvent e) { if (!myIsReset) { ApplicationManager.getApplication().invokeLater(new Runnable() { @Override @@ -75,7 +75,7 @@ public class CodeStyleSchemesPanel{ myManageButton.addActionListener(new ActionListener() { @Override - public void actionPerformed(ActionEvent e) { + public void actionPerformed(@NotNull ActionEvent e) { showManageSchemesDialog(); } }); @@ -148,10 +148,6 @@ public class CodeStyleSchemesPanel{ return myPanel; } - public void setCodeStyleSettingsPanel(NewCodeStyleSettingsPanel settingsPanel) { - mySettingsPanel = settingsPanel; - } - private void showManageSchemesDialog() { ManageCodeStyleSchemesDialog manageSchemesDialog = new ManageCodeStyleSchemesDialog(myPanel, myModel); manageSchemesDialog.show(); diff --git a/platform/lang-impl/src/com/intellij/application/options/codeStyle/ManageCodeStyleSchemesDialog.java b/platform/lang-impl/src/com/intellij/application/options/codeStyle/ManageCodeStyleSchemesDialog.java index 67b99f1cc29c..1ef5b29eba24 100644 --- a/platform/lang-impl/src/com/intellij/application/options/codeStyle/ManageCodeStyleSchemesDialog.java +++ b/platform/lang-impl/src/com/intellij/application/options/codeStyle/ManageCodeStyleSchemesDialog.java @@ -82,7 +82,7 @@ public class ManageCodeStyleSchemesDialog extends DialogWrapper { mySchemesTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); mySchemesTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() { @Override - public void valueChanged(ListSelectionEvent e) { + public void valueChanged(@NotNull ListSelectionEvent e) { updateActions(); } }); @@ -91,25 +91,25 @@ public class ManageCodeStyleSchemesDialog extends DialogWrapper { myDeleteButton.addActionListener(new ActionListener() { @Override - public void actionPerformed(ActionEvent e) { + public void actionPerformed(@NotNull ActionEvent e) { deleteSelected(); } }); mySaveAsButton.addActionListener(new ActionListener() { @Override - public void actionPerformed(ActionEvent e) { + public void actionPerformed(@NotNull ActionEvent e) { onSaveAs(); } }); myCopyToProjectButton.addActionListener(new ActionListener() { @Override - public void actionPerformed(ActionEvent e) { + public void actionPerformed(@NotNull ActionEvent e) { onCopyToProject(); } }); myCloseButton.addActionListener(new ActionListener(){ @Override - public void actionPerformed(ActionEvent e) { + public void actionPerformed(@NotNull ActionEvent e) { doCancelAction(); } }); @@ -120,7 +120,7 @@ public class ManageCodeStyleSchemesDialog extends DialogWrapper { myExportButton.setVisible(true); myExportButton.addActionListener(new ActionListener() { @Override - public void actionPerformed(final ActionEvent e) { + public void actionPerformed(@NotNull final ActionEvent e) { CodeStyleScheme selected = getSelectedScheme(); ExportSchemeAction.doExport((CodeStyleSchemeImpl)selected, mySchemesManager); } @@ -135,7 +135,7 @@ public class ManageCodeStyleSchemesDialog extends DialogWrapper { myImportButton.setVisible(true); myImportButton.addActionListener(new ActionListener() { @Override - public void actionPerformed(final ActionEvent e) { + public void actionPerformed(@NotNull final ActionEvent e) { chooseAndImport(); } }); @@ -326,8 +326,9 @@ public class ManageCodeStyleSchemesDialog extends DialogWrapper { private MySchemesTable() { myFixedItemsRenderer = new DefaultTableCellRenderer() { + @NotNull @Override - public Component getTableCellRendererComponent(JTable table, + public Component getTableCellRendererComponent(@NotNull JTable table, Object value, boolean isSelected, boolean hasFocus, @@ -361,6 +362,7 @@ public class ManageCodeStyleSchemesDialog extends DialogWrapper { updateSchemes(); } + @NotNull @Override public String getColumnName(int column) { assert column == 0; @@ -479,7 +481,7 @@ public class ManageCodeStyleSchemesDialog extends DialogWrapper { for (CodeStyleScheme scheme : schemes) { names.add(scheme.getName()); } - SaveSchemeDialog saveDialog = new SaveSchemeDialog(myParent, ApplicationBundle.message("title.save.code.style.scheme.as"), names); + SaveSchemeDialog saveDialog = new SaveSchemeDialog(myParent, ApplicationBundle.message("title.save.code.style.scheme.as"), names, ""); saveDialog.show(); if (saveDialog.isOK()) { int row = mySchemesTableModel.createNewScheme(getSelectedScheme(), saveDialog.getSchemeName()); diff --git a/platform/lang-impl/src/com/intellij/application/options/colors/SchemesPanel.java b/platform/lang-impl/src/com/intellij/application/options/colors/SchemesPanel.java index c373fa2b28f2..bcf6c4160aac 100644 --- a/platform/lang-impl/src/com/intellij/application/options/colors/SchemesPanel.java +++ b/platform/lang-impl/src/com/intellij/application/options/colors/SchemesPanel.java @@ -29,7 +29,9 @@ import com.intellij.openapi.extensions.Extensions; import com.intellij.openapi.options.SchemesManager; import com.intellij.util.Consumer; import com.intellij.util.EventDispatcher; -import org.jetbrains.annotations.Nullable; +import com.intellij.util.containers.ContainerUtil; +import com.intellij.util.text.UniqueNameGenerator; +import org.jetbrains.annotations.NotNull; import javax.swing.*; import java.awt.*; @@ -61,7 +63,7 @@ public class SchemesPanel extends JPanel implements SkipSelfSearchComponent { mySchemeComboBox.addActionListener(new ActionListener() { @Override - public void actionPerformed(ActionEvent e) { + public void actionPerformed(@NotNull ActionEvent e) { if (mySchemeComboBox.getSelectedIndex() != -1) { EditorColorsScheme selected = myOptions.selectScheme((String)mySchemeComboBox.getSelectedItem()); if (ColorAndFontOptions.isReadOnly(selected)) { @@ -97,16 +99,6 @@ public class SchemesPanel extends JPanel implements SkipSelfSearchComponent { return myListLoaded; } - public void clearSearch() { - } - - @Nullable - @SuppressWarnings({"unchecked"}) - public static T safeCast(final Object obj, final Class expectedClass) { - if (expectedClass.isInstance(obj)) return (T)obj; - return null; - } - private JPanel createSchemePanel() { JPanel panel = new JPanel(new GridBagLayout()); @@ -124,7 +116,7 @@ public class SchemesPanel extends JPanel implements SkipSelfSearchComponent { JButton saveAsButton = new JButton(ApplicationBundle.message("button.save.as")); saveAsButton.addActionListener(new ActionListener() { @Override - public void actionPerformed(ActionEvent e) { + public void actionPerformed(@NotNull ActionEvent e) { showSaveAsDialog(); } }); @@ -135,7 +127,7 @@ public class SchemesPanel extends JPanel implements SkipSelfSearchComponent { myDeleteButton = new JButton(ApplicationBundle.message("button.delete")); myDeleteButton.addActionListener(new ActionListener() { @Override - public void actionPerformed(ActionEvent e) { + public void actionPerformed(@NotNull ActionEvent e) { if (mySchemeComboBox.getSelectedIndex() != -1) { myOptions.removeScheme((String)mySchemeComboBox.getSelectedItem()); } @@ -151,7 +143,7 @@ public class SchemesPanel extends JPanel implements SkipSelfSearchComponent { myExportButton = new JButton("Share..."); myExportButton.addActionListener(new ActionListener() { @Override - public void actionPerformed(final ActionEvent e) { + public void actionPerformed(@NotNull final ActionEvent e) { EditorColorsScheme selected = myOptions.getOriginalSelectedScheme(); ExportSchemeAction .doExport((EditorColorsSchemeImpl)selected, ((EditorColorsManagerImpl)EditorColorsManager.getInstance()).getSchemesManager()); @@ -170,7 +162,7 @@ public class SchemesPanel extends JPanel implements SkipSelfSearchComponent { myImportButton.setMnemonic('I'); myImportButton.addActionListener(new ActionListener() { @Override - public void actionPerformed(final ActionEvent e) { + public void actionPerformed(@NotNull final ActionEvent e) { SchemesToImportPopup popup = new SchemesToImportPopup(SchemesPanel.this) { @Override @@ -196,7 +188,7 @@ public class SchemesPanel extends JPanel implements SkipSelfSearchComponent { final JButton button = new JButton(importHandler.getTitle()); button.addActionListener(new ActionListener() { @Override - public void actionPerformed(ActionEvent e) { + public void actionPerformed(@NotNull ActionEvent e) { importHandler.performImport(button, new Consumer() { @Override public void consume(EditorColorsScheme scheme) { @@ -214,14 +206,18 @@ public class SchemesPanel extends JPanel implements SkipSelfSearchComponent { } private void showSaveAsDialog() { - ArrayList names = new ArrayList(); - EditorColorsScheme[] allSchemes = EditorColorsManager.getInstance().getAllSchemes(); + ComboBoxModel model = mySchemeComboBox.getModel(); - for (EditorColorsScheme scheme : allSchemes) { - names.add(scheme.getName()); + int size = model.getSize(); + ArrayList names = ContainerUtil.newArrayListWithCapacity(size); + for (int i = 0; i < size; i++) { + Object at = model.getElementAt(i); + if (at instanceof String) names.add((String)at); } - SaveSchemeDialog dialog = new SaveSchemeDialog(this, ApplicationBundle.message("title.save.color.scheme.as"), names); + String selectedName = myOptions.getSelectedScheme().getName(); + String defaultName = UniqueNameGenerator.generateUniqueName(selectedName + " copy", names); + SaveSchemeDialog dialog = new SaveSchemeDialog(this, ApplicationBundle.message("title.save.color.scheme.as"), names, defaultName); dialog.show(); if (dialog.isOK()) { myOptions.saveSchemeAs(dialog.getSchemeName()); diff --git a/platform/platform-impl/src/com/intellij/application/options/SaveSchemeDialog.java b/platform/platform-impl/src/com/intellij/application/options/SaveSchemeDialog.java index 5433b279d5e1..bf0c5b99ab6b 100644 --- a/platform/platform-impl/src/com/intellij/application/options/SaveSchemeDialog.java +++ b/platform/platform-impl/src/com/intellij/application/options/SaveSchemeDialog.java @@ -32,10 +32,11 @@ public class SaveSchemeDialog extends DialogWrapper { private final JTextField mySchemeName = new JTextField(); private final ArrayList myInvalidNames; - public SaveSchemeDialog(Component parent, String title, ArrayList invalidNames){ + public SaveSchemeDialog(Component parent, String title, ArrayList invalidNames, String selectedName){ super(parent, false); myInvalidNames = invalidNames; setTitle(title); + mySchemeName.setText(selectedName); init(); } diff --git a/platform/platform-impl/src/com/intellij/ide/customize/IdSet.java b/platform/platform-impl/src/com/intellij/ide/customize/IdSet.java index af4da5358aac..47f8863b9ceb 100644 --- a/platform/platform-impl/src/com/intellij/ide/customize/IdSet.java +++ b/platform/platform-impl/src/com/intellij/ide/customize/IdSet.java @@ -16,7 +16,6 @@ package com.intellij.ide.customize; import com.intellij.openapi.util.Condition; -import com.intellij.util.ArrayUtil; import com.intellij.util.containers.ContainerUtil; import org.jetbrains.annotations.Nullable; @@ -36,11 +35,6 @@ class IdSet { description = description.substring(i + 1, description.length()); } myIds = description.split(","); - for (String id : myIds) { - if (PluginGroups.getInstance().findPlugin(id) == null) { - myIds = ArrayUtil.remove(myIds, id); - } - } myIds = ContainerUtil.filter(myIds, new Condition() { @Override public boolean value(String id) { @@ -65,7 +59,7 @@ class IdSet { @Override public String toString() { - return String.valueOf(myTitle) + ": " + myIds.length; + return String.valueOf(myTitle) + ": " + (myIds != null ? myIds.length : 0); } @Nullable diff --git a/platform/platform-impl/src/com/intellij/ide/passwordSafe/impl/providers/masterKey/PasswordComponentBase.form b/platform/platform-impl/src/com/intellij/ide/passwordSafe/impl/providers/masterKey/PasswordComponentBase.form index 083237ad092d..d1a28d249433 100644 --- a/platform/platform-impl/src/com/intellij/ide/passwordSafe/impl/providers/masterKey/PasswordComponentBase.form +++ b/platform/platform-impl/src/com/intellij/ide/passwordSafe/impl/providers/masterKey/PasswordComponentBase.form @@ -89,7 +89,7 @@ - + diff --git a/platform/platform-impl/src/com/intellij/ide/ui/laf/darcula/ui/DarculaTextFieldUI.java b/platform/platform-impl/src/com/intellij/ide/ui/laf/darcula/ui/DarculaTextFieldUI.java index 6d5bb3b40c43..5381ff9f1275 100644 --- a/platform/platform-impl/src/com/intellij/ide/ui/laf/darcula/ui/DarculaTextFieldUI.java +++ b/platform/platform-impl/src/com/intellij/ide/ui/laf/darcula/ui/DarculaTextFieldUI.java @@ -96,10 +96,11 @@ public class DarculaTextFieldUI extends BasicTextFieldUI { } protected void showSearchPopup() { - final Object value = getComponent().getClientProperty("JTextField.Search.FindPopup"); + final JTextComponent component = getComponent(); + final Object value = component == null ? null : component.getClientProperty("JTextField.Search.FindPopup"); if (value instanceof JPopupMenu) { final JPopupMenu popup = (JPopupMenu)value; - popup.show(getComponent(), getSearchIconCoord().x, getComponent().getHeight()); + popup.show(component, getSearchIconCoord().x, component.getHeight()); } } diff --git a/platform/platform-impl/src/com/intellij/ide/ui/search/DefaultSearchableConfigurable.java b/platform/platform-impl/src/com/intellij/ide/ui/search/DefaultSearchableConfigurable.java deleted file mode 100644 index 503d8753e6eb..000000000000 --- a/platform/platform-impl/src/com/intellij/ide/ui/search/DefaultSearchableConfigurable.java +++ /dev/null @@ -1,90 +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.ide.ui.search; - -import com.intellij.openapi.options.Configurable; -import com.intellij.openapi.options.ConfigurationException; -import com.intellij.openapi.options.SearchableConfigurable; -import org.jetbrains.annotations.NonNls; -import org.jetbrains.annotations.Nullable; - -import javax.swing.*; - -/** - * User: anna - * Date: 17-Mar-2006 - */ -public class DefaultSearchableConfigurable implements Configurable { - private final SearchableConfigurable myDelegate; - private JComponent myComponent; - - public DefaultSearchableConfigurable(final SearchableConfigurable delegate) { - myDelegate = delegate; - } - - @NonNls - public String getId() { - return myDelegate.getId(); - } - - public void clearSearch() { - } - - public void enableSearch(String option) { - Runnable runnable = myDelegate.enableSearch(option); - if (runnable != null){ - runnable.run(); - } - } - - public String getDisplayName() { - return myDelegate.getDisplayName(); - } - - @Nullable - @NonNls - public String getHelpTopic() { - return myDelegate.getHelpTopic(); - } - - public JComponent createComponent() { - myComponent = myDelegate.createComponent(); - return myComponent; - } - - public boolean isModified() { - return myDelegate.isModified(); - } - - public void apply() throws ConfigurationException { - myDelegate.apply(); - } - - public void reset() { - myDelegate.reset(); - } - - public void disposeUIResources() { - myComponent = null; - myDelegate.disposeUIResources(); - } - - public Configurable getDelegate() { - return myDelegate; - } - -} diff --git a/platform/util/src/com/intellij/openapi/util/io/FileSystemUtil.java b/platform/util/src/com/intellij/openapi/util/io/FileSystemUtil.java index 34e90b2ab54e..d734d4b4faa7 100644 --- a/platform/util/src/com/intellij/openapi/util/io/FileSystemUtil.java +++ b/platform/util/src/com/intellij/openapi/util/io/FileSystemUtil.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2013 JetBrains s.r.o. + * Copyright 2000-2014 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. @@ -44,8 +44,8 @@ import static com.intellij.util.BitUtil.notSet; * @version 11.1 */ public class FileSystemUtil { - private static final String FORCE_USE_NIO2_KEY = "idea.io.use.nio2"; - private static final String COARSE_TIMESTAMP = "idea.io.coarse.ts"; + static final String FORCE_USE_NIO2_KEY = "idea.io.use.nio2"; + static final String COARSE_TIMESTAMP = "idea.io.coarse.ts"; private static final Logger LOG = Logger.getInstance("#com.intellij.openapi.util.io.FileSystemUtil"); @@ -424,8 +424,8 @@ public class FileSystemUtil { return new File(path).getCanonicalPath(); } catch (IOException e) { - final String message = e.getMessage(); - if (message != null && message.toLowerCase().contains("too many levels of symbolic links")) { + String message = e.getMessage(); + if (message != null && message.toLowerCase(Locale.US).contains("too many levels of symbolic links")) { LOG.debug(e); return null; } diff --git a/platform/util/testSrc/com/intellij/openapi/util/io/FileAttributesNio2ReadingTest.java b/platform/util/testSrc/com/intellij/openapi/util/io/FileAttributesNio2ReadingTest.java index 6d00daf2412b..b750f891d1fc 100644 --- a/platform/util/testSrc/com/intellij/openapi/util/io/FileAttributesNio2ReadingTest.java +++ b/platform/util/testSrc/com/intellij/openapi/util/io/FileAttributesNio2ReadingTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2013 JetBrains s.r.o. + * Copyright 2000-2014 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. @@ -19,36 +19,22 @@ import com.intellij.openapi.util.SystemInfo; import org.junit.AfterClass; import org.junit.BeforeClass; -import java.lang.reflect.Field; - import static org.junit.Assert.assertEquals; import static org.junit.Assume.assumeTrue; public class FileAttributesNio2ReadingTest extends FileAttributesReadingTest { - private static final String FORCE_USE_NIO_2_KEY; - static { - try { - Field field = FileSystemUtil.class.getDeclaredField("FORCE_USE_NIO2_KEY"); - field.setAccessible(true); - FORCE_USE_NIO_2_KEY = (String)field.get(null); - } - catch (Exception e) { - throw new AssertionError("Please keep constants in sync: " + e.getMessage()); - } - } - @BeforeClass public static void setUpClass() throws Exception { assumeTrue(SystemInfo.isJavaVersionAtLeast("1.7")); - System.setProperty(FORCE_USE_NIO_2_KEY, "true"); + System.setProperty(FileSystemUtil.FORCE_USE_NIO2_KEY, "true"); FileSystemUtil.resetMediator(); assertEquals("Nio2", FileSystemUtil.getMediatorName()); } @AfterClass public static void tearDownClass() throws Exception { - System.setProperty(FORCE_USE_NIO_2_KEY, ""); + System.clearProperty(FileSystemUtil.FORCE_USE_NIO2_KEY); FileSystemUtil.resetMediator(); } } diff --git a/resources-en/src/intentionDescriptions/SurroundWithQuotesStringAnnotationParameterValueIntention/after.java.template b/resources-en/src/intentionDescriptions/SurroundWithQuotesStringAnnotationParameterValueIntention/after.java.template deleted file mode 100644 index 7cede3965d49..000000000000 --- a/resources-en/src/intentionDescriptions/SurroundWithQuotesStringAnnotationParameterValueIntention/after.java.template +++ /dev/null @@ -1,10 +0,0 @@ -class X { - - @interface Foo { - String value(); - } - - @Foo("123") - void m() { - } -} \ No newline at end of file diff --git a/resources-en/src/intentionDescriptions/SurroundWithQuotesStringAnnotationParameterValueIntention/before.java.template b/resources-en/src/intentionDescriptions/SurroundWithQuotesStringAnnotationParameterValueIntention/before.java.template deleted file mode 100644 index 2ca81f1308ed..000000000000 --- a/resources-en/src/intentionDescriptions/SurroundWithQuotesStringAnnotationParameterValueIntention/before.java.template +++ /dev/null @@ -1,10 +0,0 @@ -class X { - - @interface Foo { - String value(); - } - - @Foo(123) - void m() { - } -} \ No newline at end of file diff --git a/resources-en/src/intentionDescriptions/SurroundWithQuotesStringAnnotationParameterValueIntention/description.html b/resources-en/src/intentionDescriptions/SurroundWithQuotesStringAnnotationParameterValueIntention/description.html deleted file mode 100644 index 0baa5b625d56..000000000000 --- a/resources-en/src/intentionDescriptions/SurroundWithQuotesStringAnnotationParameterValueIntention/description.html +++ /dev/null @@ -1,5 +0,0 @@ - - -Intention surrounds annotation parameter value with quotes - - \ No newline at end of file