private static LookupElementBuilder createOverridingLookupElement( boolean implemented, final PsiMethod baseMethod, PsiClass baseClass, PsiSubstitutor substitutor) { RowIcon icon = new RowIcon( baseMethod.getIcon(0), implemented ? AllIcons.Gutter.ImplementingMethod : AllIcons.Gutter.OverridingMethod); return createGenerateMethodElement( baseMethod, substitutor, icon, baseClass.getName(), new InsertHandler<LookupElement>() { @Override public void handleInsert(InsertionContext context, LookupElement item) { removeLookupString(context); final PsiClass parent = PsiTreeUtil.findElementOfClassAtOffset( context.getFile(), context.getStartOffset(), PsiClass.class, false); if (parent == null) return; List<PsiMethod> prototypes = OverrideImplementUtil.overrideOrImplementMethod(parent, baseMethod, false); insertGenerationInfos( context, OverrideImplementUtil.convert2GenerationInfos(prototypes)); } }); }
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; } } } }