@Nullable public static List<? extends PsiElement> getAllPsiElements(final LookupElement item) { List<PsiMethod> allMethods = getAllMethods(item); if (allMethods != null) return allMethods; if (item.getObject() instanceof PsiElement) return Collections.singletonList((PsiElement) item.getObject()); return null; }
@Nullable private PyType createCoroutineType(@Nullable PyType returnType) { final PyBuiltinCache cache = PyBuiltinCache.getInstance(this); if (returnType instanceof PyClassLikeType && PyNames.FAKE_COROUTINE.equals(((PyClassLikeType) returnType).getClassQName())) { return returnType; } final PyClass generator = cache.getClass(PyNames.FAKE_COROUTINE); return generator != null ? new PyCollectionTypeImpl(generator, false, Collections.singletonList(returnType)) : null; }
private static List<? extends LookupElement> createLookupElements( CompletionElement completionElement, PsiJavaReference reference) { Object completion = completionElement.getElement(); assert !(completion instanceof LookupElement); if (reference instanceof PsiJavaCodeReferenceElement) { if (completion instanceof PsiMethod && ((PsiJavaCodeReferenceElement) reference).getParent() instanceof PsiImportStaticStatement) { return Collections.singletonList( JavaLookupElementBuilder.forMethod((PsiMethod) completion, PsiSubstitutor.EMPTY)); } if (completion instanceof PsiClass) { return JavaClassNameCompletionContributor.createClassLookupItems( (PsiClass) completion, JavaClassNameCompletionContributor.AFTER_NEW.accepts(reference), JavaClassNameInsertHandler.JAVA_CLASS_INSERT_HANDLER, Conditions.<PsiClass>alwaysTrue()); } } if (reference instanceof PsiMethodReferenceExpression && completion instanceof PsiMethod && ((PsiMethod) completion).isConstructor()) { return Collections.singletonList( JavaLookupElementBuilder.forMethod( (PsiMethod) completion, "new", PsiSubstitutor.EMPTY, null)); } LookupElement _ret = LookupItemUtil.objectToLookupItem(completion); if (_ret instanceof LookupItem) { final PsiSubstitutor substitutor = completionElement.getSubstitutor(); if (substitutor != null) { ((LookupItem<?>) _ret).setAttribute(LookupItem.SUBSTITUTOR, substitutor); } } return Collections.singletonList(_ret); }
public static List<PsiExpression> getReturnExpressions(PsiLambdaExpression lambdaExpression) { final PsiElement body = lambdaExpression.getBody(); if (body instanceof PsiExpression) { // if (((PsiExpression)body).getType() != PsiType.VOID) return Collections.emptyList(); return Collections.singletonList((PsiExpression) body); } final List<PsiExpression> result = new ArrayList<PsiExpression>(); for (PsiReturnStatement returnStatement : getReturnStatements(lambdaExpression)) { final PsiExpression returnValue = returnStatement.getReturnValue(); if (returnValue != null) { result.add(returnValue); } } return result; }
@Nullable private static List<MethodSignature> hasSubsignature(List<MethodSignature> signatures) { for (MethodSignature signature : signatures) { boolean subsignature = true; for (MethodSignature methodSignature : signatures) { if (!signature.equals(methodSignature)) { if (!MethodSignatureUtil.isSubsignature(signature, methodSignature)) { subsignature = false; break; } } } if (subsignature) return Collections.singletonList(signature); } return signatures; }
/** @return (super method, sub class) or null if can't find any siblings */ @Nullable public static SiblingInfo getSiblingInfoInheritedViaSubClass(@NotNull final PsiMethod method) { return getSiblingInheritanceInfos(Collections.singletonList(method)).get(method); }