From 8f68586d5efe1a6cafee2dffc571213427f56df0 Mon Sep 17 00:00:00 2001 From: Anna Kozlova Date: Sun, 4 Nov 2012 18:36:30 +0100 Subject: [PATCH] java 7 vs java 6 & primitive varargs (IDEA-70370) --- .../JavaMethodsConflictResolver.java | 15 ++++++++------- .../genericsHighlighting/IDEA70370.java | 13 +++++++++++++ .../daemon/GenericsHighlightingTest.java | 1 + 3 files changed, 22 insertions(+), 7 deletions(-) create mode 100644 java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting/IDEA70370.java diff --git a/java/java-psi-impl/src/com/intellij/psi/scope/conflictResolvers/JavaMethodsConflictResolver.java b/java/java-psi-impl/src/com/intellij/psi/scope/conflictResolvers/JavaMethodsConflictResolver.java index f067e1c42185..81ca7fb7eaee 100644 --- a/java/java-psi-impl/src/com/intellij/psi/scope/conflictResolvers/JavaMethodsConflictResolver.java +++ b/java/java-psi-impl/src/com/intellij/psi/scope/conflictResolvers/JavaMethodsConflictResolver.java @@ -649,9 +649,10 @@ public class JavaMethodsConflictResolver implements PsiConflictResolver{ return substitutor; } - public static void checkPrimitiveVarargs(final List conflicts, - final int argumentsCount) { - PsiMethod objectVararg = null; + public void checkPrimitiveVarargs(final List conflicts, + final int argumentsCount) { + if (JavaVersionService.getInstance().isAtLeast(myArgumentsList, JavaSdkVersion.JDK_1_7)) return; + CandidateInfo objectVararg = null; for (CandidateInfo conflict : conflicts) { final PsiMethod method = (PsiMethod)conflict.getElement(); final int parametersCount = method.getParameterList().getParametersCount(); @@ -660,21 +661,21 @@ public class JavaMethodsConflictResolver implements PsiConflictResolver{ final PsiType componentType = ((PsiArrayType)type).getComponentType(); final PsiClassType classType = PsiType.getJavaLangObject(method.getManager(), GlobalSearchScope.allScope(method.getProject())); if (Comparing.equal(componentType, classType)) { - objectVararg = method; + objectVararg = conflict; } } } if (objectVararg != null) { - for (Iterator iterator = conflicts.iterator(); iterator.hasNext(); ) { - CandidateInfo conflict = iterator.next(); + for (CandidateInfo conflict : conflicts) { PsiMethod method = (PsiMethod)conflict.getElement(); if (method != objectVararg && method != null && method.isVarArgs()) { final int paramsCount = method.getParameterList().getParametersCount(); final PsiType type = method.getParameterList().getParameters()[paramsCount - 1].getType(); final PsiType componentType = ((PsiArrayType)type).getComponentType(); if (argumentsCount == paramsCount - 1 && componentType instanceof PsiPrimitiveType) { - iterator.remove(); + conflicts.remove(objectVararg); + break; } } } diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting/IDEA70370.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting/IDEA70370.java new file mode 100644 index 000000000000..a1c9331d6568 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting/IDEA70370.java @@ -0,0 +1,13 @@ +class Devk1 { + public void main(String args[]) { + foo(); + } + + private void foo(Object... objects) { + System.out.println("OBJECTS" + objects); + } + + private void foo(int... ints) { + System.out.println("INTS" + ints); + } +} diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/GenericsHighlightingTest.java b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/GenericsHighlightingTest.java index c1b8ab34b118..0e483262b032 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/GenericsHighlightingTest.java +++ b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/GenericsHighlightingTest.java @@ -181,6 +181,7 @@ public class GenericsHighlightingTest extends LightDaemonAnalyzerTestCase { public void testIDEA57311() throws Exception { doTest(false); } public void testIDEA57309() throws Exception { doTest(false); } public void testIDEA90802() throws Exception { doTest(false); } + public void testIDEA70370() throws Exception { doTest(true); } public void testInaccessibleThroughWildcard() throws Exception { doTest17Incompatibility();} public void testInconvertibleTypes() throws Exception { doTest(false); } public void testIncompatibleReturnType() throws Exception { doTest(false); }