use of org.opendaylight.mdsal.binding.model.api.JavaTypeName in project mdsal by opendaylight.
the class TypeNameTest method testEquals.
@Test
public void testEquals() {
final JavaTypeName baseType1 = JavaTypeName.create("org.opendaylight.yangtools.test", "Test");
final JavaTypeName baseType2 = JavaTypeName.create("org.opendaylight.yangtools.test", "Test2");
final JavaTypeName baseType4 = JavaTypeName.create("org.opendaylight.yangtools.test", "Test");
final JavaTypeName baseType5 = JavaTypeName.create("org.opendaylight.yangtools.test1", "Test");
assertFalse(baseType1.equals(baseType2));
assertFalse(baseType1.equals(null));
assertTrue(baseType1.equals(baseType4));
assertFalse(baseType1.equals(baseType5));
assertFalse(baseType1.equals(null));
}
use of org.opendaylight.mdsal.binding.model.api.JavaTypeName in project mdsal by opendaylight.
the class AbstractOpaqueTest method assertOpaqueNode.
static void assertOpaqueNode(final List<GeneratedType> types, final String ns, final String pkg, final String name) {
final JavaTypeName typeName = JavaTypeName.create("org.opendaylight.yang.gen.v1." + ns + ".norev" + pkg, name);
final Optional<GeneratedType> optType = types.stream().filter(t -> typeName.equals(t.getIdentifier())).findFirst();
assertTrue(optType.isPresent());
final GeneratedType genType = optType.get();
final Iterator<Type> it = genType.getImplements().iterator();
final Type first = it.next();
assertTrue(first instanceof ParameterizedType);
assertEquals(JavaTypeName.create(OpaqueObject.class), ((ParameterizedType) first).getRawType().getIdentifier());
final Type second = it.next();
assertTrue(second instanceof ParameterizedType);
assertEquals(JavaTypeName.create(ChildOf.class), ((ParameterizedType) second).getRawType().getIdentifier());
assertFalse(it.hasNext());
}
use of org.opendaylight.mdsal.binding.model.api.JavaTypeName in project mdsal by opendaylight.
the class GeneratorUtil method getExplicitType.
/**
* 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 JAVA <code>Type</code> for which is the string with type info generated
* @param imports map of necessary imports for <code>parentGenType</code>
* @return string with type name for <code>type</code> in the full format or in the short format
* @throws IllegalArgumentException
* <ul>
* <li>if the <code>type</code> equals <code>null</code></li>
* <li>if the name of the <code>type</code> equals
* <code>null</code></li>
* <li>if the name of the package of the <code>type</code>
* equals <code>null</code></li>
* <li>if the <code>imports</code> equals <code>null</code></li>
* </ul>
*/
static String getExplicitType(final GeneratedType parentGenType, final Type type, final Map<String, JavaTypeName> imports) {
checkArgument(type != null, "Type parameter MUST be specified and cannot be NULL!");
checkArgument(imports != null, "Imports Map cannot be NULL!");
final JavaTypeName importedType = imports.get(type.getName());
final StringBuilder builder = new StringBuilder();
if (type.getIdentifier().equals(importedType)) {
builder.append(type.getName());
addActualTypeParameters(builder, type, parentGenType, imports);
if (builder.toString().equals("Void")) {
return "void";
}
} else {
if (type.equals(Types.voidType())) {
return "void";
}
builder.append(type.getFullyQualifiedName());
addActualTypeParameters(builder, type, parentGenType, imports);
}
return builder.toString();
}
use of org.opendaylight.mdsal.binding.model.api.JavaTypeName in project mdsal by opendaylight.
the class GeneratorUtil method createImports.
/**
* Returns the map of imports. The map maps the type name to the package 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
* @throws IllegalArgumentException if <code>genType</code> equals <code>null</code>
*/
static Map<String, JavaTypeName> createImports(final GeneratedType genType) {
if (genType == null) {
throw new IllegalArgumentException("Generated Type cannot be NULL!");
}
final Map<String, JavaTypeName> imports = new LinkedHashMap<>();
List<GeneratedType> childGeneratedTypes = genType.getEnclosedTypes();
if (!childGeneratedTypes.isEmpty()) {
for (GeneratedType genTypeChild : childGeneratedTypes) {
imports.putAll(createImports(genTypeChild));
}
}
// REGULAR EXPRESSION
if (genType instanceof GeneratedTransferObject && isConstantInTO(TypeConstants.PATTERN_CONSTANT_NAME, (GeneratedTransferObject) genType)) {
putTypeIntoImports(genType, PATTERN, imports);
}
final List<MethodSignature> methods = genType.getMethodDefinitions();
// METHODS
if (methods != null) {
for (final MethodSignature method : methods) {
final Type methodReturnType = method.getReturnType();
putTypeIntoImports(genType, methodReturnType, imports);
for (final MethodSignature.Parameter methodParam : method.getParameters()) {
putTypeIntoImports(genType, methodParam.getType(), imports);
}
for (final AnnotationType at : method.getAnnotations()) {
putTypeIntoImports(genType, at, imports);
}
}
}
// PROPERTIES
if (genType instanceof GeneratedTransferObject) {
final GeneratedTransferObject genTO = (GeneratedTransferObject) genType;
final List<GeneratedProperty> properties = genTO.getProperties();
if (properties != null) {
for (GeneratedProperty property : properties) {
final Type propertyType = property.getReturnType();
putTypeIntoImports(genType, propertyType, imports);
}
}
}
return imports;
}
use of org.opendaylight.mdsal.binding.model.api.JavaTypeName in project mdsal by opendaylight.
the class NestedJavaGeneratedType method findDescandantPath.
@SuppressFBWarnings(value = "NP_NONNULL_RETURN_VIOLATION", justification = "SpotBugs confusion @Nullable vs @NonNullByDefault")
@Nullable
private List<String> findDescandantPath(final JavaTypeName type) {
Optional<JavaTypeName> optEnclosing = type.immediatelyEnclosingClass();
verify(optEnclosing.isPresent());
final Deque<String> queue = new ArrayDeque<>();
queue.addFirst(type.simpleName());
while (optEnclosing.isPresent()) {
final JavaTypeName enclosing = optEnclosing.get();
if (enclosing.equals(getName())) {
return ImmutableList.copyOf(queue);
}
queue.addFirst(enclosing.simpleName());
optEnclosing = enclosing.immediatelyEnclosingClass();
}
return null;
}
Aggregations