diff options
author | Hans Bolinder <[email protected]> | 2014-04-28 12:05:38 +0200 |
---|---|---|
committer | Hans Bolinder <[email protected]> | 2014-04-28 12:05:38 +0200 |
commit | 683a293321b42ff6159637b2e0171c397db9a872 (patch) | |
tree | b7414677fed503f2db33adbc47b1cb44a8e6f23b /lib/edoc/src | |
parent | 3be1dc100140139b2542cd327cf4f8453d43aca1 (diff) | |
parent | eafe7f889a4ff60d9e3155518bda095740efe143 (diff) | |
download | otp-683a293321b42ff6159637b2e0171c397db9a872.tar.gz otp-683a293321b42ff6159637b2e0171c397db9a872.tar.bz2 otp-683a293321b42ff6159637b2e0171c397db9a872.zip |
Merge branch 'hb/optional_callbacks/OTP-11861'
* hb/optional_callbacks/OTP-11861:
[edoc] Handle optional behaviour callbacks
[syntax_tools] Let erl_syntax:concrete() accept the F/A syntax
Introduce the attribute -optional_callbacks in the context of behaviours
Diffstat (limited to 'lib/edoc/src')
-rw-r--r-- | lib/edoc/src/edoc_data.erl | 37 | ||||
-rw-r--r-- | lib/edoc/src/edoc_layout.erl | 25 |
2 files changed, 44 insertions, 18 deletions
diff --git a/lib/edoc/src/edoc_data.erl b/lib/edoc/src/edoc_data.erl index f88ba05f4b..eceb5cb1bd 100644 --- a/lib/edoc/src/edoc_data.erl +++ b/lib/edoc/src/edoc_data.erl @@ -173,21 +173,34 @@ callbacks(Es, Module, Env, Opts) -> lists:keymember(callback, 1, Module#module.attributes) of true -> - try (Module#module.name):behaviour_info(callbacks) of - Fs -> - Fs1 = [{F,A} || {F,A} <- Fs, is_atom(F), is_integer(A)], - if Fs1 =:= [] -> - []; - true -> - [{callbacks, - [callback(F, Env, Opts) || F <- Fs1]}] - end - catch - _:_ -> [] - end; + M = Module#module.name, + Fs = get_callback_functions(M, callbacks), + Os1 = get_callback_functions(M, optional_callbacks), + Fs1 = [FA || FA <- Fs, not lists:member(FA, Os1)], + Req = if Fs1 =:= [] -> + []; + true -> + [{callbacks, + [callback(FA, Env, Opts) || FA <- Fs1]}] + end, + Opt = if Os1 =:= [] -> + []; + true -> + [{optional_callbacks, + [callback(FA, Env, Opts) || FA <- Os1]}] + end, + Req ++ Opt; false -> [] end. +get_callback_functions(M, Callbacks) -> + try + [FA || {F, A} = FA <- M:behaviour_info(Callbacks), + is_atom(F), is_integer(A), A >= 0] + catch + _:_ -> [] + end. + %% <!ELEMENT callback EMPTY> %% <!ATTLIST callback %% name CDATA #REQUIRED diff --git a/lib/edoc/src/edoc_layout.erl b/lib/edoc/src/edoc_layout.erl index e164ff060f..87018af25a 100644 --- a/lib/edoc/src/edoc_layout.erl +++ b/lib/edoc/src/edoc_layout.erl @@ -701,6 +701,8 @@ deprecated(Es, S) -> end. behaviours(Es, Name) -> + CBs = get_content(callbacks, Es), + OCBs = get_content(optional_callbacks, Es), (case get_elem(behaviour, Es) of [] -> []; Es1 -> @@ -709,13 +711,24 @@ behaviours(Es, Name) -> ?NL] end ++ - case get_content(callbacks, Es) of - [] -> []; - Es1 -> + if CBs =:= [], OCBs =:= [] -> + []; + true -> + Req = if CBs =:= [] -> + []; + true -> + [br, " Required callback functions: "] + ++ seq(fun callback/1, CBs, ["."]) + end, + Opt = if OCBs =:= [] -> + []; + true -> + [br, " Optional callback functions: "] + ++ seq(fun callback/1, OCBs, ["."]) + end, [{p, ([{b, ["This module defines the ", {tt, [Name]}, - " behaviour."]}, - br, " Required callback functions: "] - ++ seq(fun callback/1, Es1, ["."]))}, + " behaviour."]}] + ++ Req ++ Opt)}, ?NL] end). |