java 1.4 descriptor introduced;

ignore removeAll without generics
EA-57871 - assert: PsiElementFactoryImpl.createType
This commit is contained in:
Anna Kozlova
2014-07-02 19:20:55 +02:00
parent 5eac0f8d45
commit f715cf9ca8
4 changed files with 76 additions and 6 deletions
@@ -18,11 +18,9 @@ package com.intellij.codeInspection.miscGenerics;
import com.intellij.codeInsight.daemon.impl.analysis.JavaGenericsUtil;
import com.intellij.codeInspection.InspectionsBundle;
import com.intellij.psi.*;
import com.intellij.psi.impl.PsiImplUtil;
import com.intellij.psi.search.GlobalSearchScope;
import com.intellij.psi.util.*;
import com.intellij.util.containers.IntArrayList;
import com.sun.corba.se.impl.corba.TCUtility;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -47,10 +45,12 @@ public class SuspiciousMethodCallUtil {
PsiMethod contains = MethodSignatureUtil.findMethodBySignature(collectionClass, containsSignature, false);
addMethod(contains, 0, patternMethods, indices);
PsiClassType wildcardCollection = javaPsiFacade.getElementFactory().createType(collectionClass, PsiWildcardType.createUnbounded(manager));
MethodSignature removeAllSignature = MethodSignatureUtil.createMethodSignature("removeAll", new PsiType[] {wildcardCollection}, PsiTypeParameter.EMPTY_ARRAY, PsiSubstitutor.EMPTY);
PsiMethod removeAll = MethodSignatureUtil.findMethodBySignature(collectionClass, removeAllSignature, false);
addMethod(removeAll, 0, patternMethods, indices);
if (PsiUtil.isLanguageLevel5OrHigher(collectionClass)) {
PsiClassType wildcardCollection = javaPsiFacade.getElementFactory().createType(collectionClass, PsiWildcardType.createUnbounded(manager));
MethodSignature removeAllSignature = MethodSignatureUtil.createMethodSignature("removeAll", new PsiType[] {wildcardCollection}, PsiTypeParameter.EMPTY_ARRAY, PsiSubstitutor.EMPTY);
PsiMethod removeAll = MethodSignatureUtil.findMethodBySignature(collectionClass, removeAllSignature, false);
addMethod(removeAll, 0, patternMethods, indices);
}
}
final PsiClass listClass = javaPsiFacade.findClass(CommonClassNames.JAVA_UTIL_LIST, searchScope);
@@ -0,0 +1,14 @@
import java.util.*;
class Simple {
public static void main(Set set, Set setO) {
class O {}
Map someData = new HashMap();
set.removeAll(someData.keySet());
setO.removeAll(someData.keySet());
}
}
@@ -0,0 +1,44 @@
/*
* Copyright 2000-2014 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.
*/
package com.intellij.codeInspection;
import com.intellij.JavaTestUtil;
import com.intellij.codeInspection.miscGenerics.SuspiciousCollectionsMethodCallsInspection;
import com.intellij.testFramework.LightProjectDescriptor;
import com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase;
import org.jetbrains.annotations.NotNull;
public class SuspiciousCollectionMethodCalls14Test extends LightCodeInsightFixtureTestCase {
private final SuspiciousCollectionsMethodCallsInspection myTool = new SuspiciousCollectionsMethodCallsInspection();
@Override
protected String getBasePath() {
return JavaTestUtil.getRelativeJavaTestDataPath() + "/inspection/suspiciousCalls";
}
private void doTest() throws Exception {
myFixture.enableInspections(myTool);
myFixture.testHighlighting(getTestName(false) + ".java");
}
public void testRemoveAll14() throws Exception { doTest(); }
@NotNull
@Override
protected LightProjectDescriptor getProjectDescriptor() {
return JAVA_1_4;
}
}
@@ -36,6 +36,18 @@ import java.io.File;
* @author peter
*/
public abstract class LightCodeInsightFixtureTestCase extends UsefulTestCase{
public static final LightProjectDescriptor JAVA_1_4 = new DefaultLightProjectDescriptor() {
@Override
public void configureModule(Module module, ModifiableRootModel model, ContentEntry contentEntry) {
model.getModuleExtension(LanguageLevelModuleExtension.class).setLanguageLevel(LanguageLevel.JDK_1_6);
}
};
public static final LightProjectDescriptor JAVA_1_5 = new DefaultLightProjectDescriptor() {
@Override
public void configureModule(Module module, ModifiableRootModel model, ContentEntry contentEntry) {
model.getModuleExtension(LanguageLevelModuleExtension.class).setLanguageLevel(LanguageLevel.JDK_1_6);
}
};
public static final LightProjectDescriptor JAVA_1_6 = new DefaultLightProjectDescriptor() {
@Override
public void configureModule(Module module, ModifiableRootModel model, ContentEntry contentEntry) {