Search in sources :

Example 1 with JavaTypeName

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));
}
Also used : JavaTypeName(org.opendaylight.mdsal.binding.model.api.JavaTypeName) Test(org.junit.Test)

Example 2 with JavaTypeName

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());
}
Also used : List(java.util.List) JavaTypeName(org.opendaylight.mdsal.binding.model.api.JavaTypeName) Iterator(java.util.Iterator) OpaqueObject(org.opendaylight.yangtools.yang.binding.OpaqueObject) Type(org.opendaylight.mdsal.binding.model.api.Type) Assert.assertFalse(org.junit.Assert.assertFalse) Assert.assertTrue(org.junit.Assert.assertTrue) Optional(java.util.Optional) ChildOf(org.opendaylight.yangtools.yang.binding.ChildOf) Assert.assertEquals(org.junit.Assert.assertEquals) ParameterizedType(org.opendaylight.mdsal.binding.model.api.ParameterizedType) GeneratedType(org.opendaylight.mdsal.binding.model.api.GeneratedType) ParameterizedType(org.opendaylight.mdsal.binding.model.api.ParameterizedType) ChildOf(org.opendaylight.yangtools.yang.binding.ChildOf) Type(org.opendaylight.mdsal.binding.model.api.Type) ParameterizedType(org.opendaylight.mdsal.binding.model.api.ParameterizedType) GeneratedType(org.opendaylight.mdsal.binding.model.api.GeneratedType) GeneratedType(org.opendaylight.mdsal.binding.model.api.GeneratedType) JavaTypeName(org.opendaylight.mdsal.binding.model.api.JavaTypeName) OpaqueObject(org.opendaylight.yangtools.yang.binding.OpaqueObject)

Example 3 with JavaTypeName

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();
}
Also used : JavaTypeName(org.opendaylight.mdsal.binding.model.api.JavaTypeName)

Example 4 with JavaTypeName

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;
}
Also used : MethodSignature(org.opendaylight.mdsal.binding.model.api.MethodSignature) GeneratedType(org.opendaylight.mdsal.binding.model.api.GeneratedType) GeneratedTransferObject(org.opendaylight.mdsal.binding.model.api.GeneratedTransferObject) AnnotationType(org.opendaylight.mdsal.binding.model.api.AnnotationType) LinkedHashMap(java.util.LinkedHashMap) AnnotationType(org.opendaylight.mdsal.binding.model.api.AnnotationType) Type(org.opendaylight.mdsal.binding.model.api.Type) WildcardType(org.opendaylight.mdsal.binding.model.api.WildcardType) ConcreteType(org.opendaylight.mdsal.binding.model.api.ConcreteType) ParameterizedType(org.opendaylight.mdsal.binding.model.api.ParameterizedType) GeneratedType(org.opendaylight.mdsal.binding.model.api.GeneratedType) JavaTypeName(org.opendaylight.mdsal.binding.model.api.JavaTypeName) GeneratedProperty(org.opendaylight.mdsal.binding.model.api.GeneratedProperty)

Example 5 with JavaTypeName

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;
}
Also used : JavaTypeName(org.opendaylight.mdsal.binding.model.api.JavaTypeName) ArrayDeque(java.util.ArrayDeque) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings) Nullable(org.eclipse.jdt.annotation.Nullable)

Aggregations

JavaTypeName (org.opendaylight.mdsal.binding.model.api.JavaTypeName)9 Test (org.junit.Test)3 GeneratedType (org.opendaylight.mdsal.binding.model.api.GeneratedType)3 Type (org.opendaylight.mdsal.binding.model.api.Type)3 List (java.util.List)2 Optional (java.util.Optional)2 Nullable (org.eclipse.jdt.annotation.Nullable)2 ConcreteType (org.opendaylight.mdsal.binding.model.api.ConcreteType)2 GeneratedProperty (org.opendaylight.mdsal.binding.model.api.GeneratedProperty)2 GeneratedTransferObject (org.opendaylight.mdsal.binding.model.api.GeneratedTransferObject)2 ParameterizedType (org.opendaylight.mdsal.binding.model.api.ParameterizedType)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 Preconditions.checkArgument (com.google.common.base.Preconditions.checkArgument)1 Verify.verify (com.google.common.base.Verify.verify)1 Verify.verifyNotNull (com.google.common.base.Verify.verifyNotNull)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 Maps (com.google.common.collect.Maps)1 SuppressFBWarnings (edu.umd.cs.findbugs.annotations.SuppressFBWarnings)1 ArrayDeque (java.util.ArrayDeque)1 ArrayList (java.util.ArrayList)1