mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IG: don't warn about unqualified static usage inside enum switch case (IDEA-209226)
This commit is contained in:
+12
-17
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2003-2018 Dave Griffith, Bas Leijdekkers
|
||||
* Copyright 2003-2019 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.
|
||||
@@ -179,26 +179,19 @@ public class UnqualifiedStaticUsageInspection extends BaseInspection implements
|
||||
registerError(expression, expression);
|
||||
}
|
||||
|
||||
private boolean isUnqualifiedStaticAccess(
|
||||
PsiReferenceExpression expression) {
|
||||
private boolean isUnqualifiedStaticAccess(PsiReferenceExpression expression) {
|
||||
if (m_ignoreStaticAccessFromStaticContext) {
|
||||
final PsiMember member =
|
||||
PsiTreeUtil.getParentOfType(expression,
|
||||
PsiMember.class);
|
||||
if (member != null &&
|
||||
member.hasModifierProperty(PsiModifier.STATIC)) {
|
||||
final PsiMember member = PsiTreeUtil.getParentOfType(expression, PsiMember.class);
|
||||
if (member != null && member.hasModifierProperty(PsiModifier.STATIC)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
final PsiExpression qualifierExpression =
|
||||
expression.getQualifierExpression();
|
||||
final PsiExpression qualifierExpression = expression.getQualifierExpression();
|
||||
if (qualifierExpression != null) {
|
||||
return false;
|
||||
}
|
||||
final JavaResolveResult resolveResult =
|
||||
expression.advancedResolve(false);
|
||||
final PsiElement currentFileResolveScope =
|
||||
resolveResult.getCurrentFileResolveScope();
|
||||
final JavaResolveResult resolveResult = expression.advancedResolve(false);
|
||||
final PsiElement currentFileResolveScope = resolveResult.getCurrentFileResolveScope();
|
||||
if (currentFileResolveScope instanceof PsiImportStaticStatement) {
|
||||
return false;
|
||||
}
|
||||
@@ -208,9 +201,11 @@ public class UnqualifiedStaticUsageInspection extends BaseInspection implements
|
||||
return false;
|
||||
}
|
||||
final PsiMember member = (PsiMember)element;
|
||||
if (member instanceof PsiEnumConstant &&
|
||||
expression.getParent() instanceof PsiSwitchLabelStatement) {
|
||||
return false;
|
||||
if (member instanceof PsiEnumConstant) {
|
||||
PsiElement parent = expression.getParent();
|
||||
if (parent instanceof PsiExpressionList && parent.getParent() instanceof PsiSwitchLabelStatementBase) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return member.hasModifierProperty(PsiModifier.STATIC);
|
||||
}
|
||||
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
enum UnqualifiedStaticUsage {
|
||||
RED, BLUE;
|
||||
|
||||
int switches(UnqualifiedStaticUsage c) {
|
||||
System.out.println(<warning descr="Unqualified static field access 'RED'">RED</warning>);
|
||||
System.out.println(UnqualifiedStaticUsage.BLUE);
|
||||
switch (c) {
|
||||
case RED: break;
|
||||
case BLUE: break;
|
||||
}
|
||||
return switch (c) {
|
||||
case RED -> 1;
|
||||
case BLUE -> 2;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
+32
@@ -0,0 +1,32 @@
|
||||
// Copyright 2000-2019 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.ig.style;
|
||||
|
||||
import com.intellij.codeInspection.InspectionProfileEntry;
|
||||
import com.intellij.testFramework.LightPlatformCodeInsightTestCase;
|
||||
import com.intellij.testFramework.LightProjectDescriptor;
|
||||
import com.siyeh.ig.LightInspectionTestCase;
|
||||
import junit.framework.TestCase;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* @author Bas Leijdekkers
|
||||
*/
|
||||
public class UnqualifiedStaticUsageInspectionTest extends LightInspectionTestCase {
|
||||
|
||||
public void testUnqualifiedStaticUsage() {
|
||||
doTest();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
protected InspectionProfileEntry getInspection() {
|
||||
return new UnqualifiedStaticUsageInspection();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
protected LightProjectDescriptor getProjectDescriptor() {
|
||||
return JAVA_12;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user