diff --git a/plugins/IntentionPowerPak/src/com/siyeh/ipp/enumswitch/EnumSwitchPredicate.java b/plugins/IntentionPowerPak/src/com/siyeh/ipp/enumswitch/EnumSwitchPredicate.java index d6e266cfe292..1986d6fc0637 100644 --- a/plugins/IntentionPowerPak/src/com/siyeh/ipp/enumswitch/EnumSwitchPredicate.java +++ b/plugins/IntentionPowerPak/src/com/siyeh/ipp/enumswitch/EnumSwitchPredicate.java @@ -1,5 +1,5 @@ /* - * Copyright 2003-2013 Dave Griffith, Bas Leijdekkers + * Copyright 2003-2018 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. @@ -57,15 +57,11 @@ class EnumSwitchPredicate implements PsiElementPredicate { } final Set enumElements = new HashSet<>(fields.length); for (final PsiField field : fields) { - final PsiType fieldType = field.getType(); - if (!fieldType.equals(type)) { - continue; + if (field instanceof PsiEnumConstant) { + enumElements.add(field.getName()); } - final String fieldName = field.getName(); - enumElements.add(fieldName); } - final PsiStatement[] statements = body.getStatements(); - for (PsiStatement statement : statements) { + for (PsiStatement statement : body.getStatements()) { if (!(statement instanceof PsiSwitchLabelStatement)) { continue; } diff --git a/plugins/IntentionPowerPak/test/com/siyeh/ipp/enumswitch/NotAvailable.java b/plugins/IntentionPowerPak/test/com/siyeh/ipp/enumswitch/NotAvailable.java new file mode 100644 index 000000000000..88a4b93ec1e2 --- /dev/null +++ b/plugins/IntentionPowerPak/test/com/siyeh/ipp/enumswitch/NotAvailable.java @@ -0,0 +1,13 @@ +enum E { + foo, bar; + + private E e; + + int foo() { + switch (this) { + case foo: return 1; + case bar: return 2; + default: return 3; + } + } +} \ No newline at end of file diff --git a/plugins/IntentionPowerPak/testSrc/com/siyeh/ipp/enumswitch/EnumSwitchBranchesIntentionTest.java b/plugins/IntentionPowerPak/testSrc/com/siyeh/ipp/enumswitch/EnumSwitchBranchesIntentionTest.java index 9a7d0f79688b..64c25544ea36 100644 --- a/plugins/IntentionPowerPak/testSrc/com/siyeh/ipp/enumswitch/EnumSwitchBranchesIntentionTest.java +++ b/plugins/IntentionPowerPak/testSrc/com/siyeh/ipp/enumswitch/EnumSwitchBranchesIntentionTest.java @@ -1,18 +1,4 @@ -/* - * Copyright 2000-2016 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. - */ +// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.siyeh.ipp.enumswitch; import com.siyeh.IntentionPowerPackBundle; @@ -28,6 +14,7 @@ public class EnumSwitchBranchesIntentionTest extends IPPTestCase { public void testBeforeFallthrough() { doTest(); } public void testMultiple() { doTest(); } public void testNoActionAfterBraces() { assertIntentionNotAvailable(); } + public void testNotAvailable() { assertIntentionNotAvailable(); } @Override protected String getIntentionName() {