Skip to content

Commit f8a9c43

Browse files
committed
Change default capability listing to annotation
1 parent 4565f69 commit f8a9c43

File tree

1 file changed

+21
-9
lines changed

1 file changed

+21
-9
lines changed

src/main/java/org/kitteh/irc/client/library/feature/CapabilityManager.java

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@
3939
import org.kitteh.irc.client.library.util.RiskyBusiness;
4040
import org.kitteh.irc.client.library.util.Sanity;
4141

42+
import java.lang.annotation.Retention;
43+
import java.lang.annotation.RetentionPolicy;
4244
import java.lang.reflect.Field;
4345
import java.lang.reflect.Modifier;
4446
import java.util.ArrayList;
@@ -53,10 +55,14 @@
5355
* Provides information on IRCv3 extensions available and in use.
5456
*/
5557
public interface CapabilityManager {
58+
@Retention(RetentionPolicy.RUNTIME)
59+
@interface Conditional {
60+
}
61+
5662
/**
5763
* Contains the capabilities natively supported by KICL, which will be
58-
* requested automatically upon availability. Defaults defined as
59-
* transient are not requested unless additional functionality is
64+
* requested automatically upon availability. Defaults defined with the
65+
* {@link Conditional} annotation are not requested unless additional functionality is
6066
* enabled, as documented here.
6167
*/
6268
final class Defaults {
@@ -91,12 +97,14 @@ final class Defaults {
9197
* when "CAP LS 302" (or higher version) is sent and therefore it
9298
* is not requested by the default capability manager.
9399
*/
94-
public static final transient String CAP_NOTIFY = "cap-notify";
100+
@Conditional
101+
public static final String CAP_NOTIFY = "cap-notify";
95102

96103
/**
97104
* Self-sent message echoing, not utilized unless requested.
98105
*/
99-
public static final transient String ECHO_MESSAGE = "echo-message";
106+
@Conditional
107+
public static final String ECHO_MESSAGE = "echo-message";
100108

101109
/**
102110
* Account listed in join message.
@@ -115,7 +123,8 @@ final class Defaults {
115123
*
116124
* @see ChannelInviteEvent
117125
*/
118-
public static final transient String INVITE_NOTIFY = "invite-notify";
126+
@Conditional
127+
public static final String INVITE_NOTIFY = "invite-notify";
119128

120129
/**
121130
* Labeled responses, which also requires the {@link #BATCH}
@@ -167,7 +176,8 @@ final class Defaults {
167176
* @see SaslPlain
168177
* @see SaslEcdsaNist256PChallenge
169178
*/
170-
public static final transient String SASL = "sasl";
179+
@Conditional
180+
public static final String SASL = "sasl";
171181

172182
/**
173183
* User hosts sent in NAMES, allowing User creation prior to WHO.
@@ -191,7 +201,7 @@ public static List<String> getDefaults() {
191201

192202
static {
193203
DEFAULTS = Collections.unmodifiableList(Arrays.stream(Defaults.class.getDeclaredFields())
194-
.filter(field -> Modifier.isPublic(field.getModifiers()) && !Modifier.isTransient(field.getModifiers()))
204+
.filter(field -> Modifier.isPublic(field.getModifiers()) && field.getAnnotation(Conditional.class) == null)
195205
.map(Defaults::getStringForCapabilityField).collect(Collectors.toCollection(Defaults.SUPPLIER)));
196206
}
197207

@@ -255,7 +265,8 @@ interface WithManagement extends CapabilityManager, Resettable {
255265
* @return the capabilities currently enabled
256266
* @see CapabilityRequestCommand
257267
*/
258-
@NonNull List<CapabilityState> getCapabilities();
268+
@NonNull
269+
List<CapabilityState> getCapabilities();
259270

260271
/**
261272
* Gets an enabled capability by name.
@@ -274,7 +285,8 @@ interface WithManagement extends CapabilityManager, Resettable {
274285
* @return the capabilities supported
275286
* @see CapabilityRequestCommand
276287
*/
277-
@NonNull List<CapabilityState> getSupportedCapabilities();
288+
@NonNull
289+
List<CapabilityState> getSupportedCapabilities();
278290

279291
/**
280292
* Gets a supported capability by name.

0 commit comments

Comments
 (0)