static void setupPatternMethods( PsiManager manager, GlobalSearchScope searchScope, List<PsiMethod> patternMethods, IntArrayList indices) { final JavaPsiFacade javaPsiFacade = JavaPsiFacade.getInstance(manager.getProject()); final PsiClass collectionClass = javaPsiFacade.findClass(CommonClassNames.JAVA_UTIL_COLLECTION, searchScope); PsiType[] javaLangObject = {PsiType.getJavaLangObject(manager, searchScope)}; MethodSignature removeSignature = MethodSignatureUtil.createMethodSignature( "remove", javaLangObject, PsiTypeParameter.EMPTY_ARRAY, PsiSubstitutor.EMPTY); if (collectionClass != null) { PsiMethod remove = MethodSignatureUtil.findMethodBySignature(collectionClass, removeSignature, false); addMethod(remove, 0, patternMethods, indices); MethodSignature containsSignature = MethodSignatureUtil.createMethodSignature( "contains", javaLangObject, PsiTypeParameter.EMPTY_ARRAY, PsiSubstitutor.EMPTY); PsiMethod contains = MethodSignatureUtil.findMethodBySignature(collectionClass, containsSignature, false); addMethod(contains, 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); if (listClass != null) { MethodSignature indexofSignature = MethodSignatureUtil.createMethodSignature( "indexOf", javaLangObject, PsiTypeParameter.EMPTY_ARRAY, PsiSubstitutor.EMPTY); PsiMethod indexof = MethodSignatureUtil.findMethodBySignature(listClass, indexofSignature, false); addMethod(indexof, 0, patternMethods, indices); MethodSignature lastindexofSignature = MethodSignatureUtil.createMethodSignature( "lastIndexOf", javaLangObject, PsiTypeParameter.EMPTY_ARRAY, PsiSubstitutor.EMPTY); PsiMethod lastindexof = MethodSignatureUtil.findMethodBySignature(listClass, lastindexofSignature, false); addMethod(lastindexof, 0, patternMethods, indices); } final PsiClass mapClass = javaPsiFacade.findClass(CommonClassNames.JAVA_UTIL_MAP, searchScope); if (mapClass != null) { PsiMethod remove = MethodSignatureUtil.findMethodBySignature(mapClass, removeSignature, false); addMethod(remove, 0, patternMethods, indices); MethodSignature getSignature = MethodSignatureUtil.createMethodSignature( "get", javaLangObject, PsiTypeParameter.EMPTY_ARRAY, PsiSubstitutor.EMPTY); PsiMethod get = MethodSignatureUtil.findMethodBySignature(mapClass, getSignature, false); addMethod(get, 0, patternMethods, indices); MethodSignature containsKeySignature = MethodSignatureUtil.createMethodSignature( "containsKey", javaLangObject, PsiTypeParameter.EMPTY_ARRAY, PsiSubstitutor.EMPTY); PsiMethod containsKey = MethodSignatureUtil.findMethodBySignature(mapClass, containsKeySignature, false); addMethod(containsKey, 0, patternMethods, indices); MethodSignature containsValueSignature = MethodSignatureUtil.createMethodSignature( "containsValue", javaLangObject, PsiTypeParameter.EMPTY_ARRAY, PsiSubstitutor.EMPTY); PsiMethod containsValue = MethodSignatureUtil.findMethodBySignature(mapClass, containsValueSignature, false); addMethod(containsValue, 1, patternMethods, indices); } final PsiClass concurrentMapClass = javaPsiFacade.findClass(CommonClassNames.JAVA_UTIL_CONCURRENT_HASH_MAP, searchScope); if (concurrentMapClass != null) { MethodSignature containsSignature = MethodSignatureUtil.createMethodSignature( "contains", javaLangObject, PsiTypeParameter.EMPTY_ARRAY, PsiSubstitutor.EMPTY); PsiMethod contains = MethodSignatureUtil.findMethodBySignature(concurrentMapClass, containsSignature, false); addMethod(contains, 1, patternMethods, indices); } }
private static void setupPatternMethods( PsiManager manager, GlobalSearchScope searchScope, List<PsiMethod> patternMethods, IntArrayList indices) { final PsiClass collectionClass = JavaPsiFacade.getInstance(manager.getProject()) .findClass("java.util.Collection", searchScope); PsiType[] javaLangObject = {PsiType.getJavaLangObject(manager, searchScope)}; MethodSignature removeSignature = MethodSignatureUtil.createMethodSignature( "remove", javaLangObject, PsiTypeParameter.EMPTY_ARRAY, PsiSubstitutor.EMPTY); if (collectionClass != null) { PsiMethod remove = MethodSignatureUtil.findMethodBySignature(collectionClass, removeSignature, false); addMethod(remove, 0, patternMethods, indices); MethodSignature containsSignature = MethodSignatureUtil.createMethodSignature( "contains", javaLangObject, PsiTypeParameter.EMPTY_ARRAY, PsiSubstitutor.EMPTY); PsiMethod contains = MethodSignatureUtil.findMethodBySignature(collectionClass, containsSignature, false); addMethod(contains, 0, patternMethods, indices); } final PsiClass listClass = JavaPsiFacade.getInstance(manager.getProject()).findClass("java.util.List", searchScope); if (listClass != null) { MethodSignature indexofSignature = MethodSignatureUtil.createMethodSignature( "indexOf", javaLangObject, PsiTypeParameter.EMPTY_ARRAY, PsiSubstitutor.EMPTY); PsiMethod indexof = MethodSignatureUtil.findMethodBySignature(listClass, indexofSignature, false); addMethod(indexof, 0, patternMethods, indices); MethodSignature lastindexofSignature = MethodSignatureUtil.createMethodSignature( "lastIndexOf", javaLangObject, PsiTypeParameter.EMPTY_ARRAY, PsiSubstitutor.EMPTY); PsiMethod lastindexof = MethodSignatureUtil.findMethodBySignature(listClass, lastindexofSignature, false); addMethod(lastindexof, 0, patternMethods, indices); } final PsiClass mapClass = JavaPsiFacade.getInstance(manager.getProject()).findClass("java.util.Map", searchScope); if (mapClass != null) { PsiMethod remove = MethodSignatureUtil.findMethodBySignature(mapClass, removeSignature, false); addMethod(remove, 0, patternMethods, indices); MethodSignature getSignature = MethodSignatureUtil.createMethodSignature( "get", javaLangObject, PsiTypeParameter.EMPTY_ARRAY, PsiSubstitutor.EMPTY); PsiMethod get = MethodSignatureUtil.findMethodBySignature(mapClass, getSignature, false); addMethod(get, 0, patternMethods, indices); MethodSignature containsKeySignature = MethodSignatureUtil.createMethodSignature( "containsKey", javaLangObject, PsiTypeParameter.EMPTY_ARRAY, PsiSubstitutor.EMPTY); PsiMethod containsKey = MethodSignatureUtil.findMethodBySignature(mapClass, containsKeySignature, false); addMethod(containsKey, 0, patternMethods, indices); MethodSignature containsValueSignature = MethodSignatureUtil.createMethodSignature( "containsValue", javaLangObject, PsiTypeParameter.EMPTY_ARRAY, PsiSubstitutor.EMPTY); PsiMethod containsValue = MethodSignatureUtil.findMethodBySignature(mapClass, containsValueSignature, false); addMethod(containsValue, 1, patternMethods, indices); } }