*/
package org.opendaylight.yangtools.sal.java.api.generator;
+import static com.google.common.base.Preconditions.checkArgument;
import static org.opendaylight.yangtools.sal.java.api.generator.Constants.COMMA;
import java.util.ArrayList;
import org.opendaylight.yangtools.binding.generator.util.TypeConstants;
import org.opendaylight.yangtools.binding.generator.util.Types;
+import org.opendaylight.yangtools.sal.binding.model.api.AnnotationType;
import org.opendaylight.yangtools.sal.binding.model.api.Constant;
import org.opendaylight.yangtools.sal.binding.model.api.GeneratedProperty;
import org.opendaylight.yangtools.sal.binding.model.api.GeneratedTransferObject;
import org.opendaylight.yangtools.sal.binding.model.api.ParameterizedType;
import org.opendaylight.yangtools.sal.binding.model.api.Type;
import org.opendaylight.yangtools.sal.binding.model.api.WildcardType;
-import static com.google.common.base.Preconditions.*;
public final class GeneratorUtil {
* name. To the map are added packages for <code>genType</code> and for all
* enclosed types, constants, methods (parameter types, return values),
* implemented types.
- *
+ *
* @param genType
* generated type for which the map of the imports is created
* @return map of the necessary imports
}
}
- final List<Constant> constants = genType.getConstantDefinitions();
- final List<MethodSignature> methods = genType.getMethodDefinitions();
- final List<Type> impl = genType.getImplements();
-
- // CONSTANTS
- if (constants != null) {
- for (final Constant constant : constants) {
- final Type constantType = constant.getType();
- putTypeIntoImports(genType, constantType, imports);
- }
- }
-
// REGULAR EXPRESSION
if (genType instanceof GeneratedTransferObject
&& isConstantInTO(TypeConstants.PATTERN_CONSTANT_NAME, (GeneratedTransferObject) genType)) {
putTypeIntoImports(genType, Types.typeForClass(java.util.ArrayList.class), imports);
}
+ final List<MethodSignature> methods = genType.getMethodDefinitions();
// METHODS
if (methods != null) {
for (final MethodSignature method : methods) {
for (final MethodSignature.Parameter methodParam : method.getParameters()) {
putTypeIntoImports(genType, methodParam.getType(), imports);
}
+ for (final AnnotationType at : method.getAnnotations()) {
+ putTypeIntoImports(genType, at, imports);
+ }
}
}
* Evaluates if it is necessary to add the package name for
* <code>type</code> to the map of imports for <code>parentGenType</code>.
* If it is so the package name is saved to the map <code>imports</code>.
- *
+ *
* @param parentGenType
* generated type for which is the map of the necessary imports
* built
if (type instanceof ParameterizedType) {
final ParameterizedType paramType = (ParameterizedType) type;
final Type[] params = paramType.getActualTypeArguments();
- for (Type param : params) {
- putTypeIntoImports(parentGenType, param, imports);
+ if (params != null) {
+ for (Type param : params) {
+ putTypeIntoImports(parentGenType, param, imports);
+ }
}
}
}
/**
* Checks if the constant with the name <code>constName</code> is in the
* list of the constant definition for <code>genTO</code>.
- *
+ *
* @param constName
* string with the name of constant which is sought
* @param genTO
* Creates the map which maps the type name to package name and contains
* only package names for enclosed types of <code>genType</code> and
* recursivelly their enclosed types.
- *
+ *
* @param genType
* JAVA <code>Type</code> for which is the map created
* @return map of the package names for all the enclosed types and
* Builds the string which contains either the full path to the type
* (package name with type) or only type name if the package is among
* <code>imports</code>.
- *
+ *
* @param parentGenType
* generated type which contains <code>type</code>
* @param type
* Adds actual type parameters from <code>type</code> to
* <code>builder</code> if <code>type</code> is
* <code>ParametrizedType</code>.
- *
+ *
* @param builder
* string builder which contains type name
* @param type
/**
* Generates the string with all actual type parameters from
* <code>pTypes</code>
- *
+ *
* @param parentGenType
* generated type for which is the JAVA code generated
* @param pTypes
*/
private static String getParameters(final GeneratedType parentGenType, final Type[] pTypes,
Map<String, String> availableImports) {
+ if (pTypes == null || pTypes.length == 0) {
+ return "?";
+ }
final StringBuilder builder = new StringBuilder();
for (int i = 0; i < pTypes.length; i++) {
final Type t = pTypes[i];
/**
* Returns the reference to highest (top parent) Generated Transfer Object.
- *
+ *
* @param childTransportObject
* is generated transfer object which can be extended by other
* generated transfer object
/**
* Selects from input list of properties only those which have read only
* attribute set to true.
- *
+ *
* @param properties
* list of properties of generated transfer object
* @return subset of <code>properties</code> which have read only attribute
* Returns the list of the read only properties of all extending generated
* transfer object from <code>genTO</code> to highest parent generated
* transfer object
- *
+ *
* @param genTO
* generated transfer object for which is the list of read only
* properties generated