@NotNull private static List<PsiMethod> findMethodsBySignature( @NotNull PsiClass aClass, @NotNull PsiMethod patternMethod, boolean checkBases, boolean stopOnFirst) { final PsiMethod[] methodsByName = aClass.findMethodsByName(patternMethod.getName(), checkBases); if (methodsByName.length == 0) return Collections.emptyList(); final List<PsiMethod> methods = new SmartList<PsiMethod>(); final MethodSignature patternSignature = patternMethod.getSignature(PsiSubstitutor.EMPTY); for (final PsiMethod method : methodsByName) { final PsiClass superClass = method.getContainingClass(); final PsiSubstitutor substitutor; if (checkBases && !aClass.equals(superClass)) { substitutor = TypeConversionUtil.getSuperClassSubstitutor(superClass, aClass, PsiSubstitutor.EMPTY); } else { substitutor = PsiSubstitutor.EMPTY; } final MethodSignature signature = method.getSignature(substitutor); if (signature.equals(patternSignature)) { methods.add(method); if (stopOnFirst) { break; } } } return methods; }
private static void addSuperSignatureElements( final PsiClass parent, boolean implemented, CompletionResultSet result, Set<MethodSignature> addedSignatures) { for (CandidateInfo candidate : OverrideImplementExploreUtil.getMethodsToOverrideImplement(parent, implemented)) { PsiMethod baseMethod = (PsiMethod) candidate.getElement(); PsiClass baseClass = baseMethod.getContainingClass(); PsiSubstitutor substitutor = candidate.getSubstitutor(); if (!baseMethod.isConstructor() && baseClass != null && addedSignatures.add(baseMethod.getSignature(substitutor))) { result.addElement( createOverridingLookupElement(implemented, baseMethod, baseClass, substitutor)); } } }
public static boolean isMainOrPremainMethod(@NotNull PsiMethod method) { if (!PsiType.VOID.equals(method.getReturnType())) return false; String name = method.getName(); if (!("main".equals(name) || "premain".equals(name))) return false; PsiElementFactory factory = JavaPsiFacade.getInstance(method.getProject()).getElementFactory(); MethodSignature signature = method.getSignature(PsiSubstitutor.EMPTY); try { MethodSignature main = createSignatureFromText(factory, "void main(String[] args);"); if (MethodSignatureUtil.areSignaturesEqual(signature, main)) return true; MethodSignature premain = createSignatureFromText( factory, "void premain(String args, java.lang.instrument.Instrumentation i);"); if (MethodSignatureUtil.areSignaturesEqual(signature, premain)) return true; } catch (IncorrectOperationException e) { LOG.error(e); } return false; }
private static void addGetterSetterElements( CompletionResultSet result, PsiClass parent, Set<MethodSignature> addedSignatures) { int count = 0; for (PsiField field : parent.getFields()) { if (field instanceof PsiEnumConstant) continue; List<PsiMethod> prototypes = ContainerUtil.newSmartList(); Collections.addAll( prototypes, GetterSetterPrototypeProvider.generateGetterSetters(field, true)); Collections.addAll( prototypes, GetterSetterPrototypeProvider.generateGetterSetters(field, false)); for (final PsiMethod prototype : prototypes) { if (parent.findMethodBySignature(prototype, false) == null && addedSignatures.add(prototype.getSignature(PsiSubstitutor.EMPTY))) { Icon icon = prototype.getIcon(Iconable.ICON_FLAG_VISIBILITY); result.addElement( createGenerateMethodElement( prototype, PsiSubstitutor.EMPTY, icon, "", new InsertHandler<LookupElement>() { @Override public void handleInsert(InsertionContext context, LookupElement item) { removeLookupString(context); insertGenerationInfos( context, Collections.singletonList(new PsiGenerationInfo<PsiMethod>(prototype))); } })); if (count++ > 100) return; } } } }