varargs formal parameters inaccessible: extend for non-parameterized methods (IDEA...
authorAnna Kozlova <anna.kozlova@jetbrains.com>
Thu, 3 Sep 2015 14:58:58 +0000 (17:58 +0300)
committerAnna Kozlova <anna.kozlova@jetbrains.com>
Thu, 3 Sep 2015 17:30:57 +0000 (20:30 +0300)
java/java-analysis-impl/src/com/intellij/codeInsight/daemon/impl/analysis/HighlightMethodUtil.java
java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting7/InaccessibleInferredTypeForVarargsArgument.java

index bdd7901acdc6f97ec7fb4d852ee5cb8ad8de92bc..aa59638fd2fdebc0cb353e6d983f35caca1809bb 100644 (file)
@@ -1550,23 +1550,18 @@ public class HighlightMethodUtil {
   private static HighlightInfo checkVarargParameterErasureToBeAccessible(MethodCandidateInfo info, PsiCall place) {
     final PsiMethod method = info.getElement();
     if (info.isVarargs() || method.isVarArgs() && !PsiUtil.isLanguageLevel8OrHigher(place)) {
-      if (method.hasTypeParameters()) {
-        final PsiParameter[] parameters = method.getParameterList().getParameters();
-        final PsiType componentType = ((PsiEllipsisType)parameters[parameters.length - 1].getType()).getComponentType();
-        final PsiClass classOfComponent = PsiUtil.resolveClassInClassTypeOnly(componentType);
-        if (classOfComponent instanceof PsiTypeParameter) {
-          final PsiType substitutedTypeErasure = TypeConversionUtil.erasure(info.getSubstitutor().substitute(componentType));
-          final PsiClass targetClass = PsiUtil.resolveClassInClassTypeOnly(substitutedTypeErasure);
-          if (targetClass != null && !PsiUtil.isAccessible(targetClass, place, null)) {
-            final PsiExpressionList argumentList = place.getArgumentList();
-            return HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR)
-                         .descriptionAndTooltip("Formal varargs element type " +
-                                                PsiFormatUtil.formatClass(targetClass, PsiFormatUtilBase.SHOW_FQ_NAME) +
-                                                " is inaccessible here")
-                         .range(argumentList != null ? argumentList : place)
-                         .create();
-          }
-        }
+      final PsiParameter[] parameters = method.getParameterList().getParameters();
+      final PsiType componentType = ((PsiEllipsisType)parameters[parameters.length - 1].getType()).getComponentType();
+      final PsiType substitutedTypeErasure = TypeConversionUtil.erasure(info.getSubstitutor().substitute(componentType));
+      final PsiClass targetClass = PsiUtil.resolveClassInClassTypeOnly(substitutedTypeErasure);
+      if (targetClass != null && !PsiUtil.isAccessible(targetClass, place, null)) {
+        final PsiExpressionList argumentList = place.getArgumentList();
+        return HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR)
+          .descriptionAndTooltip("Formal varargs element type " +
+                                 PsiFormatUtil.formatClass(targetClass, PsiFormatUtilBase.SHOW_FQ_NAME) +
+                                 " is inaccessible here")
+          .range(argumentList != null ? argumentList : place)
+          .create();
       }
     }
     return null;
index 5ed7852fc7716ef41f7b31bb426773c54df17527..01b27976c594104865a8fbb7dc44590eea1b9cf5 100644 (file)
@@ -10,4 +10,15 @@ class Outer {
   private static class A {}
   public static class B extends A {}
   public static class C extends A {}
-}
\ No newline at end of file
+}
+
+class An {
+  private class B {}
+  public static void foo(B... x){}
+}
+
+class C {
+  {
+    An.foo<error descr="Formal varargs element type  is inaccessible here">()</error>;
+  }
+}