From 3c337530d3244cf3e55d49b00f2e2900eaabc049 Mon Sep 17 00:00:00 2001 From: anna Date: Wed, 3 Aug 2011 21:56:31 +0400 Subject: [PATCH] scopes: preserve invalid patterns (IDEA-72839) --- .../scope/packageSet/InvalidPackageSet.java | 34 +++++++++++++++++++ .../scope/packageSet/NamedScopesHolder.java | 7 ++-- .../util/scopeChooser/ScopeConfigurable.java | 13 +++---- .../util/scopeChooser/ScopeEditorPanel.java | 7 ++-- 4 files changed, 47 insertions(+), 14 deletions(-) create mode 100644 platform/lang-api/src/com/intellij/psi/search/scope/packageSet/InvalidPackageSet.java diff --git a/platform/lang-api/src/com/intellij/psi/search/scope/packageSet/InvalidPackageSet.java b/platform/lang-api/src/com/intellij/psi/search/scope/packageSet/InvalidPackageSet.java new file mode 100644 index 000000000000..000097d10a6a --- /dev/null +++ b/platform/lang-api/src/com/intellij/psi/search/scope/packageSet/InvalidPackageSet.java @@ -0,0 +1,34 @@ +/* + * 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.scope.packageSet; + +import com.intellij.openapi.vfs.VirtualFile; +import org.jetbrains.annotations.NotNull; + +/** + * User: anna + */ +public class InvalidPackageSet extends AbstractPackageSet { + + public InvalidPackageSet(@NotNull String text) { + super(text); + } + + @Override + public boolean contains(VirtualFile file, NamedScopesHolder holder) { + return false; + } +} diff --git a/platform/lang-api/src/com/intellij/psi/search/scope/packageSet/NamedScopesHolder.java b/platform/lang-api/src/com/intellij/psi/search/scope/packageSet/NamedScopesHolder.java index a263f9650368..bad77d1febbe 100644 --- a/platform/lang-api/src/com/intellij/psi/search/scope/packageSet/NamedScopesHolder.java +++ b/platform/lang-api/src/com/intellij/psi/search/scope/packageSet/NamedScopesHolder.java @@ -145,12 +145,13 @@ public abstract class NamedScopesHolder implements PersistentStateComponent { public boolean isModified() { if (mySharedCheckbox.isSelected() != myShareScope) return true; - final PackageSet currentScope = myPanel.getCurrentScope(); - return !Comparing.strEqual(myPackageSet, currentScope != null ? currentScope.getText() : null); + final String currentScope = myPanel.getPatternText(); + return !Comparing.strEqual(myPackageSet, currentScope); } public void apply() throws ConfigurationException { try { myPanel.apply(); final PackageSet packageSet = myPanel.getCurrentScope(); - myScope = new NamedScope(myScope.getName(), packageSet); - myPackageSet = packageSet != null ? packageSet.getText() : null; + myPackageSet = myPanel.getPatternText(); + myScope = new NamedScope(myScope.getName(), packageSet == null ? new InvalidPackageSet(myPackageSet) : packageSet); myShareScope = mySharedCheckbox.isSelected(); } catch (ConfigurationException e) { diff --git a/platform/lang-impl/src/com/intellij/ide/util/scopeChooser/ScopeEditorPanel.java b/platform/lang-impl/src/com/intellij/ide/util/scopeChooser/ScopeEditorPanel.java index 48fb8732323b..fa62f20c1c38 100644 --- a/platform/lang-impl/src/com/intellij/ide/util/scopeChooser/ScopeEditorPanel.java +++ b/platform/lang-impl/src/com/intellij/ide/util/scopeChooser/ScopeEditorPanel.java @@ -496,15 +496,16 @@ public class ScopeEditorPanel { } public void apply() throws ConfigurationException { - if (myCurrentScope == null) { - throw new ConfigurationException(IdeBundle.message("error.correct.pattern.syntax.errors.first")); - } } public PackageSet getCurrentScope() { return myCurrentScope; } + public String getPatternText() { + return myPatternField.getText(); + } + public void reset(PackageSet packageSet, @Nullable Runnable runnable) { myCurrentScope = packageSet; myPatternField.setText(myCurrentScope == null ? "" : myCurrentScope.getText());