From d80b0241948f4f48c554bf4252f3e9454e342f09 Mon Sep 17 00:00:00 2001 From: Bas Leijdekkers Date: Mon, 10 May 2010 22:14:49 +0200 Subject: [PATCH] IDEA-52848 (EnumMap intention false positive when LHS type doesn't match) --- .../MapReplaceableByEnumMapInspection.java | 21 ++++++++++--------- .../SetReplaceableByEnumSetInspection.java | 12 +++++++---- 2 files changed, 19 insertions(+), 14 deletions(-) diff --git a/plugins/InspectionGadgets/src/com/siyeh/ig/performance/MapReplaceableByEnumMapInspection.java b/plugins/InspectionGadgets/src/com/siyeh/ig/performance/MapReplaceableByEnumMapInspection.java index e5fc54c4183c..99a1fbf2f1ee 100644 --- a/plugins/InspectionGadgets/src/com/siyeh/ig/performance/MapReplaceableByEnumMapInspection.java +++ b/plugins/InspectionGadgets/src/com/siyeh/ig/performance/MapReplaceableByEnumMapInspection.java @@ -1,5 +1,5 @@ /* - * Copyright 2003-2007 Dave Griffith, Bas Leijdekkers + * Copyright 2003-2010 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. @@ -27,18 +27,21 @@ import org.jetbrains.annotations.NotNull; public class MapReplaceableByEnumMapInspection extends BaseInspection { + @Override @NotNull public String getDisplayName() { return InspectionGadgetsBundle.message( "map.replaceable.by.enum.map.display.name"); } + @Override @NotNull protected String buildErrorString(Object... infos) { return InspectionGadgetsBundle.message( "map.replaceable.by.enum.map.problem.descriptor"); } + @Override public BaseInspectionVisitor buildVisitor() { return new SetReplaceableByEnumSetVisitor(); } @@ -46,7 +49,8 @@ public class MapReplaceableByEnumMapInspection extends BaseInspection { private static class SetReplaceableByEnumSetVisitor extends BaseInspectionVisitor { - @Override public void visitNewExpression(@NotNull PsiNewExpression expression) { + @Override public void visitNewExpression( + @NotNull PsiNewExpression expression) { super.visitNewExpression(expression); final PsiType type = expression.getType(); if (!(type instanceof PsiClassType)) { @@ -65,19 +69,16 @@ public class MapReplaceableByEnumMapInspection extends BaseInspection { return; } if (!TypeUtils.expressionHasTypeOrSubtype(expression, - "java.util.Map")) { + "java.util.Map")) { return; } - if (TypeUtils.expressionHasTypeOrSubtype(expression, - "java.util.EnumMap")) { - return; + if (null != TypeUtils.expressionHasTypeOrSubtype(expression, + "java.util.EnumMap", "java.util.concurrent.ConcurrentMap")) { + return; } final PsiClassType argumentClassType = (PsiClassType)argumentType; final PsiClass argumentClass = argumentClassType.resolve(); - if (argumentClass == null) { - return; - } - if (!argumentClass.isEnum()) { + if (argumentClass == null || !argumentClass.isEnum()) { return; } registerNewExpressionError(expression); diff --git a/plugins/InspectionGadgets/src/com/siyeh/ig/performance/SetReplaceableByEnumSetInspection.java b/plugins/InspectionGadgets/src/com/siyeh/ig/performance/SetReplaceableByEnumSetInspection.java index cbf4cd68668c..1ad5ad6152d5 100644 --- a/plugins/InspectionGadgets/src/com/siyeh/ig/performance/SetReplaceableByEnumSetInspection.java +++ b/plugins/InspectionGadgets/src/com/siyeh/ig/performance/SetReplaceableByEnumSetInspection.java @@ -1,5 +1,5 @@ /* - * Copyright 2003-2007 Dave Griffith, Bas Leijdekkers + * Copyright 2003-2010 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. @@ -27,18 +27,21 @@ import org.jetbrains.annotations.NotNull; public class SetReplaceableByEnumSetInspection extends BaseInspection { + @Override @NotNull public String getDisplayName() { return InspectionGadgetsBundle.message( "set.replaceable.by.enum.set.display.name"); } + @Override @NotNull protected String buildErrorString(Object... infos) { return InspectionGadgetsBundle.message( "set.replaceable.by.enum.set.problem.descriptor"); } + @Override public BaseInspectionVisitor buildVisitor() { return new SetReplaceableByEnumSetVisitor(); } @@ -46,7 +49,8 @@ public class SetReplaceableByEnumSetInspection extends BaseInspection { private static class SetReplaceableByEnumSetVisitor extends BaseInspectionVisitor { - @Override public void visitNewExpression(@NotNull PsiNewExpression expression) { + @Override public void visitNewExpression( + @NotNull PsiNewExpression expression) { super.visitNewExpression(expression); final PsiType type = expression.getType(); if (!(type instanceof PsiClassType)) { @@ -65,11 +69,11 @@ public class SetReplaceableByEnumSetInspection extends BaseInspection { return; } if (!TypeUtils.expressionHasTypeOrSubtype(expression, - "java.util.Set")) { + "java.util.Set")) { return; } if (TypeUtils.expressionHasTypeOrSubtype(expression, - "java.util.EnumSet")) { + "java.util.EnumSet")) { return; } final PsiClassType argumentClassType = (PsiClassType)argumentType;