mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IPP: recognize enum constants correctly (IDEA-196541)
in "Create Enum Switch Branches" intention
This commit is contained in:
@@ -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<String> 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;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
enum E {
|
||||
foo, bar;
|
||||
|
||||
private E e;
|
||||
|
||||
int foo() {
|
||||
switch (this) {
|
||||
case foo: return 1;
|
||||
case bar: return 2;
|
||||
<caret>default: return 3;
|
||||
}
|
||||
}
|
||||
}
|
||||
+2
-15
@@ -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() {
|
||||
|
||||
Reference in New Issue
Block a user