@Nullable public static ErlangFunction getZeroArityFunction(@Nullable PsiElement psiElement) { ErlangFunction function = psiElement instanceof ErlangFunction ? (ErlangFunction) psiElement : PsiTreeUtil.getParentOfType(psiElement, ErlangFunction.class); int arity = function == null ? -1 : function.getArity(); return 0 == arity ? function : null; }
private static void assertResolvesTo( @Nullable PsiReference reference, @NotNull String file, @NotNull String function, int arity) { assertNotNull(reference); ErlangFunction resolvedFunction = ObjectUtils.tryCast(reference.resolve(), ErlangFunction.class); assertNotNull(resolvedFunction); String actualFile = resolvedFunction.getContainingFile().getName(); assertEquals(file, actualFile); assertEquals(function, resolvedFunction.getName()); assertEquals(arity, resolvedFunction.getArity()); }
@NotNull public static ErlangExpressionType calculateFunctionType(@NotNull ErlangFunction function) { ErlangSpecification spec = function.findSpecification(); if (spec == null) return UNKNOWN; ErlangFunTypeSigs signature = ErlangPsiImplUtil.getSignature(spec); if (signature == null) return UNKNOWN; for (ErlangTypeSig typeSig : signature.getTypeSigList()) { ErlangFunType funType = typeSig.getFunType(); ErlangTopTypeClause typeClause = funType.getTopTypeClause(); ErlangType type = PsiTreeUtil.getChildOfType(typeClause, ErlangType.class); ErlangTypeRef typeRef = type != null ? type.getTypeRef() : null; String text = typeRef != null ? typeRef.getText() : null; ErlangExpressionType expressionType = TYPE_MAP.get(text); if (expressionType != null) return expressionType; } return UNKNOWN; }