Ejemplo n.º 1
0
  public static long computeDefaultSUID(final GeneratedTypeBuilderBase<?> to) {
    final ByteArrayOutputStream bout = new ByteArrayOutputStream();
    try (final DataOutputStream dout = new DataOutputStream(bout)) {
      dout.writeUTF(to.getName());
      dout.writeInt(to.isAbstract() ? 3 : 7);

      for (Type ifc : sortedCollection(SUID_NAME_COMPARATOR, to.getImplementsTypes())) {
        dout.writeUTF(ifc.getFullyQualifiedName());
      }

      for (GeneratedPropertyBuilder gp :
          sortedCollection(SUID_MEMBER_COMPARATOR, to.getProperties())) {
        dout.writeUTF(gp.getName());
      }

      for (MethodSignatureBuilder m :
          sortedCollection(SUID_MEMBER_COMPARATOR, to.getMethodDefinitions())) {
        if (!(m.getAccessModifier().equals(AccessModifier.PRIVATE))) {
          dout.writeUTF(m.getName());
          dout.write(m.getAccessModifier().ordinal());
        }
      }

      dout.flush();
    } catch (IOException e) {
      throw new IllegalStateException("Failed to hash object " + to, e);
    }

    final byte[] hashBytes = SHA1_MD.get().digest(bout.toByteArray());
    long hash = 0;
    for (int i = Math.min(hashBytes.length, 8) - 1; i >= 0; i--) {
      hash = (hash << 8) | (hashBytes[i] & 0xFF);
    }
    return hash;
  }
Ejemplo n.º 2
0
 /*
  * (non-Javadoc)
  *
  * @see java.lang.Object#toString()
  */
 @Override
 public String toString() {
   StringBuilder builder = new StringBuilder();
   builder.append("MethodParameter [name=");
   builder.append(name);
   builder.append(", type=");
   builder.append(type.getPackageName());
   builder.append(".");
   builder.append(type.getName());
   builder.append("]");
   return builder.toString();
 }
  @Test
  public void testInnerClassCreationForBitsAndUnionsInLeafes() throws URISyntaxException {
    final URI yangTypesPath = getClass().getResource("/bit_and_union_in_leaf.yang").toURI();

    final SchemaContext context = resolveSchemaContextFromFiles(yangTypesPath);
    assertTrue(context != null);

    final BindingGenerator bindingGen = new BindingGeneratorImpl();
    final List<Type> genTypes = bindingGen.generateTypes(context);
    assertTrue(genTypes != null);

    boolean parentContainerFound = false;
    boolean bitLeafTOFound = false;
    boolean unionLeafTOFound = false;

    boolean firstBitPropertyFound = false;
    boolean secondBitPropertyFound = false;
    boolean thirdBitPropertyFound = false;

    boolean firstBitPropertyTypeOK = false;
    boolean secondBitPropertyTypeOK = false;
    boolean thirdBitPropertyTypeOK = false;

    boolean int32UnionPropertyFound = false;
    boolean int32UnionPropertyTypeOK = false;
    boolean stringUnionPropertyFound = false;
    boolean stringUnionPropertyTypeOK = false;
    boolean uint8UnionPropertyFound = false;
    boolean uint8UnionPropertyTypeOK = false;

    for (Type type : genTypes) {
      if (type instanceof GeneratedType && !(type instanceof GeneratedTransferObject)) {
        if (type.getName().equals("ParentContainer")) {
          parentContainerFound = true;
          GeneratedType parentContainer = (GeneratedType) type;
          List<GeneratedType> enclosedTypes = parentContainer.getEnclosedTypes();
          for (GeneratedType genType : enclosedTypes) {
            if (genType instanceof GeneratedTransferObject) {
              if (genType.getName().equals("BitLeaf")) {
                bitLeafTOFound = true;
                GeneratedTransferObject bitLeafTO = (GeneratedTransferObject) genType;

                List<GeneratedProperty> bitLeafProperties = bitLeafTO.getProperties();
                for (GeneratedProperty bitLeafProperty : bitLeafProperties) {
                  String bitLeafPropertyType = bitLeafProperty.getReturnType().getName();
                  if (bitLeafProperty.getName().equals("firstBit")) {
                    firstBitPropertyFound = true;
                    if (bitLeafPropertyType.equals("Boolean")) {
                      firstBitPropertyTypeOK = true;
                    }
                  } else if (bitLeafProperty.getName().equals("secondBit")) {
                    secondBitPropertyFound = true;
                    if (bitLeafPropertyType.equals("Boolean")) {
                      secondBitPropertyTypeOK = true;
                    }
                  } else if (bitLeafProperty.getName().equals("thirdBit")) {
                    thirdBitPropertyFound = true;
                    if (bitLeafPropertyType.equals("Boolean")) {
                      thirdBitPropertyTypeOK = true;
                    }
                  }
                }

              } else if (genType.getName().equals("UnionLeaf")) {
                unionLeafTOFound = true;
                GeneratedTransferObject unionLeafTO = (GeneratedTransferObject) genType;

                List<GeneratedProperty> unionLeafProperties = unionLeafTO.getProperties();
                for (GeneratedProperty unionLeafProperty : unionLeafProperties) {
                  String unionLeafPropertyType = unionLeafProperty.getReturnType().getName();
                  if (unionLeafProperty.getName().equals("int32")) {
                    int32UnionPropertyFound = true;
                    if (unionLeafPropertyType.equals("Integer")) {
                      int32UnionPropertyTypeOK = true;
                    }
                  } else if (unionLeafProperty.getName().equals("string")) {
                    stringUnionPropertyFound = true;
                    if (unionLeafPropertyType.equals("String")) {
                      stringUnionPropertyTypeOK = true;
                    }
                  } else if (unionLeafProperty.getName().equals("uint8")) {
                    uint8UnionPropertyFound = true;
                    if (unionLeafPropertyType.equals("Short")) {
                      uint8UnionPropertyTypeOK = true;
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
    assertTrue(parentContainerFound);

    assertTrue(bitLeafTOFound);
    assertTrue(firstBitPropertyFound);
    assertTrue(secondBitPropertyFound);
    assertTrue(thirdBitPropertyFound);

    assertTrue(firstBitPropertyTypeOK);
    assertTrue(secondBitPropertyTypeOK);
    assertTrue(thirdBitPropertyTypeOK);

    assertTrue(unionLeafTOFound);
    assertTrue(int32UnionPropertyFound);
    assertTrue(int32UnionPropertyTypeOK);
    assertTrue(stringUnionPropertyFound);
    assertTrue(stringUnionPropertyTypeOK);
    assertTrue(uint8UnionPropertyFound);
    assertTrue(uint8UnionPropertyTypeOK);
  }