Package org.destecs.tools.jprotocolgenerator.ast

Examples of org.destecs.tools.jprotocolgenerator.ast.ClassDefinition


  private String generateExtendedMethod(Method m)
  {

    StringBuffer sb = new StringBuffer();
    List<ClassDefinition> defs = new Vector<ClassDefinition>();
    ClassDefinition returnClass = null;

    if (m.javaDoc != null)
    {
      sb.append(m.javaDoc);
      sb.append("\n\t");
    }
    sb.append("public ");
    if (m.returnType instanceof MapType)
    {
      returnClass = new ClassDefinition();
      returnClass.setName(m.name + "Struct");
      returnClass.packageName = structPackageName;
      returnClass.imports.add(new Type(Map.class));
      returnClass.imports.add(new Type(List.class));
      returnClass.implemented.add(stryctInterface);
      sb.append(returnClass.getName());
    } else
    {

      sb.append(m.returnType.toSource());
    }
    sb.append(" ");
    sb.append(m.name);
    sb.append("(");

    Parameter p1 = m.parameters.get(0);

    MapType type = (MapType) p1.type;

    Map<String, ClassDefinition> structs = new Hashtable<String, ClassDefinition>();

    for (String key : type.possibleEntries.keySet())
    {
      ITypeNode t = type.possibleEntries.get(key);
      if ((t instanceof ListType
          && ((ListType) t).type instanceof MapType || t instanceof MapType))
      {

        ClassDefinition pClass = new ClassDefinition();
        pClass.setName(m.name + key + "StructParam");
        pClass.packageName = structPackageName;
        pClass.imports.add(new Type(Map.class));
        pClass.imports.add(new Type(List.class));
        pClass.implemented.add(stryctInterface);
        defs.add(pClass);
        structs.put(key, pClass);
        MapType mType = null;
        if (t instanceof ListType)
        {
          mType = (MapType) ((ListType) t).type;
        } else
        {
          mType = (MapType) t;
        }
        defs.addAll(generateStructs(pClass, structPackageName, mType));

        if (t instanceof ListType)
        {
          sb.append("List<" + pClass.getName() + ">");
        } else
        {

          sb.append(pClass.getName());
        }
      } else
      {

        sb.append(type.possibleEntries.get(key).toSource());
View Full Code Here


      if (type instanceof ListType)
      {
        if (((ListType) type).type instanceof MapType)
        {
          swa.warnings.add(WarningTypes.unchecked);
          ClassDefinition newRet = new ClassDefinition();
          newRet.setName(m.name + p + appendName);
          newRet.packageName = packageName2;
          newRet.imports.add(new Type(Map.class));
          newRet.imports.add(new Type(List.class));
          newRet.implemented.add(stryctInterface);
          returnClass.imports.add(new Type(Vector.class));

          defs.addAll(generateStructs(newRet, packageName2, (MapType) ((ListType) type).type, isParameter));
          defs.add(newRet);
          f.type = new ListType(newRet);
          m.body += f.type.getName() + " tmp" + count
              + " = new Vector<" + newRet.getName()
              + ">();\n\t\t";

          m.body += "if( value.keySet().contains(\"" + f.getName()
              + "\" ))\n\t\t";
          m.body += "{\n\t\t\t";

          if (map.valueType instanceof List
              || map.valueType instanceof ListType)
          {
            m.body += "Object tmpL" + count + " = value.get(\""
                + f.getName() + "\");\n\t\t\t";
            m.body += "for( Object m : (Object[])tmpL" + count
                + ")\n\t\t\t";

          } else
          {
            m.body += "for( Object m : (Object[])value.get(\""
                + f.getName() + "\"))\n\t\t\t";
          }

          m.body += "{\n\t\t\t\t";

          m.body += "tmp" + count + ".add( new " + newRet.getName()
              + "( (" + ((ListType) type).type + ") m)";
          m.body += ");\n\t\t\t";

          m.body += "}\n\t\t";

          m.body += "}\n\t\t";

          m.body += "this." + f.getName() + " = tmp" + count
              + ";\n\n\n\t\t\t";

        } else
        {
          f.type = map.possibleEntries.get(p);
          // m.body += "this." + f.getName() + " = (" + f.type.getName()
          // + ") value.get(value.keySet().toArray()[" + count
          // + "]);\n\t\t";
          m.body += "if( value.keySet().contains(\"" + f.getName()
              + "\" ))\n\t\t";
          m.body += "{\n\t\t\t";

          if (map.valueType instanceof List
              || map.valueType instanceof ListType)
          {
            m.body += "Object tmpL" + count + " = value.get(\""
                + f.getName() + "\");\n\t\t\t";
            m.body += "for( Object m : (Object[])tmpL" + count
                + ")\n\t\t\t";

          } else
          {
            m.body += "for( Object m : (Object[])value.get(\""
                + f.getName() + "\"))\n\t\t\t";
          }

          m.body += "{\n\t\t\t\t";

          m.body += "this." + f.getName() + ".add(("
              + ((ListType) type).type + ") m";
          m.body += ");\n\t\t\t";

          m.body += "}\n\t\t";

          m.body += "}\n\t\t";

        }
      } else if (type instanceof MapType)
      {
        ClassDefinition newRet = new ClassDefinition();
        newRet.setName(m.name + p + appendName);
        newRet.packageName = packageName2;
        newRet.imports.add(new Type(Map.class));
        newRet.imports.add(new Type(List.class));
        newRet.implemented.add(stryctInterface);

        defs.addAll(generateStructs(newRet, packageName2, (MapType) type, isParameter));
        defs.add(newRet);
        f.type = newRet;
        m.body += "this." + f.getName() + " = new " + newRet.getName()
            + "( (" + f.type.getName() + ") value.get(" + count
            + "));\n\t\t";
      } else
      {
        f.type = map.possibleEntries.get(p);
View Full Code Here

      // newM.returnType = returnType.possibleEntries.get(returnType.possibleEntries.keySet().toArray()[0]);
      // addCast = true;
      //
      // } else
      // {
      ClassDefinition returnClass = null;
      returnClass = new ClassDefinition();
      returnClass.setName(m.name + "Struct");
      returnClass.packageName = structPackageName;
      returnClass.imports.add(new Type(Map.class));
      returnClass.imports.add(new Type(List.class));
      returnClass.implemented.add(stryctInterface);
      newM.returnType = returnClass;

      sb.append("new " + returnClass.getName() + "(");
      List<ClassDefinition> defs = generateStructs(returnClass, structPackageName, (MapType) m.returnType);
      defs.add(returnClass);
      printClasses(defs);
      // }
View Full Code Here

TOP

Related Classes of org.destecs.tools.jprotocolgenerator.ast.ClassDefinition

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.