private String resolveTypeDiscriminatorForBackReference(Member m) {
   Method me =
       ReflectionUtils.findMethod(
           m.getDeclaringClass(), "get" + firstCharToUpperCase(m.getName()));
   if (me != null) {
     return resolveTypeDiscriminator(resolveReturnType(me));
   }
   return "";
 }
 /** Special constructor called from Class. */
 NamedIterator(Vector v, Object type, int modifierMask) {
   // Using type 'Object' instead of 'java.lang.Class' for parameter type
   // is a workaround to avoid having to generate fully qualified class names
   // when applying BeatyJ to this code. (Otherwise, would confuse with class
   // 'Class' in this package.)
   this();
   for (Enumeration e = v.elements(); e.hasMoreElements(); ) {
     Member m = (Member) e.nextElement();
     int mod = m.getModifier();
     if (((modifierMask & mod) != 0) && (m.getClass().isAssignableFrom((java.lang.Class) type))) {
       data.addElement(m);
     }
   }
   reset();
   lockReadonly(); // read-only in this mode
 }
  private void generateSetBasedDocRefView(
      Map<String, org.ektorp.support.DesignDocument.View> views,
      Member me,
      DocumentReferences referenceMetaData) {
    String fieldName = firstCharToLowerCase(me.getName());
    String orderBy = referenceMetaData.orderBy();
    String backRef = referenceMetaData.backReference();
    if (backRef.length() == 0) {
      throw new ViewGenerationException(
          String.format(
              "The DocumentReferences annotation in %s must specify a backReference",
              me.getDeclaringClass()));
    }
    String viewName = NameConventions.backReferenceViewName(fieldName);
    String typeDiscriminator = resolveTypeDiscriminatorForBackReference(me);
    if (orderBy.length() > 0) {

      views.put(
          viewName,
          generateDocRefsAsSetWithOrderByView(backRef, fieldName, orderBy, typeDiscriminator));
    } else {
      views.put(viewName, generateDocRefsAsSetView(backRef, fieldName, typeDiscriminator));
    }
  }
Exemple #4
0
  /** Parsing members means creating new members for definitions with more than one declarator. */
  public void parse() {
    boolean clone_and_parse = true;

    if (extendVector == null) throw new RuntimeException("Compiler Error: extendVector not set!");

    if (type_spec.typeSpec() instanceof ScopedName) {
      token = type_spec.typeSpec().get_token();
      type_spec = ((ScopedName) type_spec.typeSpec()).resolvedTypeSpec();
      clone_and_parse = false;
      if (type_spec instanceof ConstrTypeSpec) {
        if (((ConstrTypeSpec) type_spec.typeSpec()).c_type_spec instanceof StructType) {
          //	System.out.println("Struct " + containing_struct.typeName() + " contains struct " +
          // ((ConstrTypeSpec)type_spec.typeSpec()).typeName());
          if (((ConstrTypeSpec) type_spec.typeSpec())
              .c_type_spec
              .typeName()
              .equals(containing_struct.typeName())) {
            parser.fatal_error(
                "Illegal recursion in struct (use sequence<"
                    + containing_struct.typeName()
                    + "> instead)",
                token);
          }
        }
      }

    } else if (type_spec.typeSpec() instanceof SequenceType) {
      TypeSpec ts = ((SequenceType) type_spec.typeSpec()).elementTypeSpec().typeSpec();
      SequenceType seqTs = (SequenceType) type_spec.typeSpec();
      while (ts instanceof SequenceType) {
        seqTs = (SequenceType) ts;
        ts = ((SequenceType) ts.typeSpec()).elementTypeSpec().typeSpec();
      }

      //           if( ts.typeName().equals( containing_struct.typeName()) ||
      if (ScopedName.isRecursionScope(ts.typeName())) {
        seqTs.setRecursive();
      }
    } else if (type_spec instanceof ConstrTypeSpec) {
      type_spec.parse();
    }

    for (Enumeration e = declarators.v.elements(); e.hasMoreElements(); ) {
      Declarator d = (Declarator) e.nextElement();

      // we don't parse the declarator itself
      // as that would result in its name getting defined
      // we define the declarator's name as a type name indirectly
      // through the cloned type specs.

      Member m = new Member(new_num());
      m.declarator = d;

      TypeSpec ts = type_spec.typeSpec();

      /* create a separate type spec copy for every declarator
         if the type spec is a new type definition, i.e. a
         struct, enum, union, sequence or the declarator is
         an array declarator
      */

      //			if( clone_and_parse && !(ts instanceof BaseType) )
      if (clone_and_parse || d.d instanceof ArrayDeclarator) {
        /* arrays need special treatment */

        if (d.d instanceof ArrayDeclarator) {
          ts = new ArrayTypeSpec(new_num(), ts, (ArrayDeclarator) d.d, pack_name);
          ts.parse();
        } else if (!(ts instanceof BaseType)) {
          ts = (TypeSpec) ts.clone();
          if (!(ts instanceof ConstrTypeSpec)) ts.set_name(d.name());

          /* important: only parse type specs once (we do it for the last
          declarator only) */
          if (!e.hasMoreElements()) ts.parse();
        }
      }

      //            else
      if (!(d.d instanceof ArrayDeclarator)) {
        try {
          NameTable.define(containing_struct + "." + d.name(), "declarator");
        } catch (NameAlreadyDefined nad) {
          parser.error("Declarator " + d.name() + " already defined in scope.", token);
        }
      }

      /* if the type spec is a scoped name, it is already parsed and
       * the type name is defined
       */
      //			if( clone_and_parse )
      //				ts.parse();

      m.type_spec = ts;
      m.pack_name = this.pack_name;
      m.name = this.name;
      extendVector.addElement(m);
    }
    declarators = null;
  }