Squash empty lists/maps
[mdsal.git] / binding / mdsal-binding-generator-api / src / main / java / org / opendaylight / mdsal / binding / model / api / MethodSignature.java
1 /*
2  * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.mdsal.binding.model.api;
9
10 import java.util.List;
11
12 /**
13  * The Method Signature interface contains simplified meta model for java method
14  * definition. Each method MUST be defined by name, return type, parameters and
15  * access modifier. <br>
16  * Additionally method MAY contain associated annotations and comment. By
17  * contract if method does not contain any comments or annotation definitions
18  * the {@link #getComment()} SHOULD rather return empty string and
19  * {@link #getAnnotations()} SHOULD rather return empty list than
20  * <code>null</code> values. <br>
21  * The defining Type contains the reference to Generated Type that declares
22  * Method Signature.
23  */
24 public interface MethodSignature extends TypeMember {
25     /**
26      * Returns <code>true</code> if the method signature is defined as abstract. <br>
27      * By default in java all method declarations in interface are defined as abstract, but the user does not need
28      * necessarily to declare abstract keyword in front of each method. <br>
29      * The abstract methods are allowed in Class definitions but only when the class is declared as abstract.
30      *
31      * @return <code>true</code> if the method signature is defined as abstract.
32      */
33     boolean isAbstract();
34
35     /**
36      * Returns {@code true} if this method is a {@code interface default} method.
37      *
38      * @return <code>true</code> if the method signature is defined as default.
39      */
40     boolean isDefault();
41
42     /**
43      * Returns the List of parameters that method declare. If the method does not contain any parameters, the method
44      * will return empty List.
45      *
46      * @return the List of parameters that method declare.
47      */
48     List<Parameter> getParameters();
49
50     /**
51      * Return the mechanics associated with this method.
52      *
53      * @return Associated mechanics
54      */
55     ValueMechanics getMechanics();
56
57     /**
58      * The Parameter interface is designed to hold the information of method
59      * Parameter(s). The parameter is defined by his Name which MUST be unique
60      * as java does not allow multiple parameters with same names for one method
61      * and Type that is associated with parameter.
62      */
63     interface Parameter {
64
65         /**
66          * Returns the parameter name.
67          *
68          * @return the parameter name.
69          */
70         String getName();
71
72         /**
73          * Returns Type that is bounded to parameter name.
74          *
75          * @return Type that is bounded to parameter name.
76          */
77         Type getType();
78     }
79
80     /**
81      * Method return type mechanics. This is a bit of an escape hatch for various behaviors which are supported by
82      * code generation.
83      */
84     enum ValueMechanics {
85         /**
86          * Usual mechanics, nothing special is going on.
87          */
88         NORMAL,
89         /**
90          * Mechanics signaling that the method should not be returning empty collections, but rather squash tham
91          * to null.
92          */
93         NULLIFY_EMPTY,
94     }
95 }