コード例 #1
0
 @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;
 }
コード例 #2
0
  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());
  }
コード例 #3
0
 @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;
 }