Each struct has three variants of presence:
1) Struct is not defined, because one of it's optional parent fields is null
2) Struct is null
3) Struct is defined and not empty.
760046
public static BooleanList calculateStructOffsets(
            Field field,
            int[] fieldDefinitionLevels,
            int[] fieldRepetitionLevels)
    {
        int maxDefinitionLevel = field.getDefinitionLevel();
        int maxRepetitionLevel = field.getRepetitionLevel();
        BooleanList structIsNull = new BooleanArrayList();
        boolean required = field.isRequired();
        if (fieldDefinitionLevels == null) {
            return structIsNull;
        }
        for (int i = 0; i < fieldDefinitionLevels.length; i++) {
            if (fieldRepetitionLevels[i] <= maxRepetitionLevel) {
                if (isValueNull(required, fieldDefinitionLevels[i], maxDefinitionLevel)) {
                    // Struct is null
                    structIsNull.add(true);
                }
                else if (fieldDefinitionLevels[i] >= maxDefinitionLevel) {
                    // Struct is defined and not empty
                    structIsNull.add(false);
                }
            }
        }
        return structIsNull;
    }
1001128
func (s *Struct) structFields() []reflect.StructField {
	t := s.value.Type()

	var f []reflect.StructField

	for i := 0; i < t.NumField(); i++ {
		field := t.Field(i)
		// we can't access the value of unexported fields
		if field.PkgPath != "" {
			continue
		}

		// don't check if it's omitted
		if tag := field.Tag.Get(s.TagName); tag == "-" {
			continue
		}

		f = append(f, field)
	}

	return f
}
97013
private static StructrTypeDefinition determineType(final StructrSchemaDefinition root, final String name, final Map<String, Object> source) {

		if (source.containsKey(JsonSchema.KEY_RELATIONSHIP)) {

			final StructrRelationshipTypeDefinition def = new StructrRelationshipTypeDefinition(root, name);
			def.deserialize(source);

			return def;

		} else {

			final StructrNodeTypeDefinition def = new StructrNodeTypeDefinition(root, name);
			def.deserialize(source);

			return def;
		}
	}
936845
private void storeField(Field field, StructImpl fieldsMap) {
	String fieldName = field.getName();
	Object o = fieldsMap.get(fieldName, null);
	Field[] args;
	if (o == null) {
	    args = new Field[1];
	    fieldsMap.setEL(fieldName, args);
	}
	else {
	    Field[] fs = (Field[]) o;
	    args = new Field[fs.length + 1];
	    for (int i = 0; i < fs.length; i++) {
		fs[i].setAccessible(true);
		args[i] = fs[i];
	    }
	    fieldsMap.setEL(fieldName, args);
	}
	args[args.length - 1] = field;
    }
403410
private boolean isNullOrEmpty(Object paramValue) {
        boolean isNullOrEmpty = false;
        if (paramValue == null) {
            isNullOrEmpty = true;
        }
        if (paramValue instanceof String) {
            if (((String) paramValue).trim().equalsIgnoreCase("")) {
                isNullOrEmpty = true;
            }
        } else if (paramValue instanceof List) {
            return ((List) paramValue).isEmpty();
        }
        return isNullOrEmpty;
    }
1167963
def struct_namespace(namespace = Undefined)
      if namespace.equal?(Undefined)
        options[:struct_namespace]
      else
        with(struct_namespace: namespace)
      end
    end
999343
private StructrPath checkPath(final Path obj) {

		if (obj == null) {
			throw new NullPointerException();
		}

		if (!(obj instanceof StructrPath)) {
			throw new ProviderMismatchException();
		}

		return (StructrPath)obj;
	}
28760
def parse_struct(s):
    
    docs = s['comment']
    code = '<span class="k">struct</span> <span class="gs">%s</span>' % s['name']
    if s['extends']:
        code += ' extends <span class="gs">%s</span>' % s['extends']
    code += ' {\n'
    namelen = 0
    typelen = 0
    for v in s["fields"]:
        tlen = len(format_type(v, includeOptional=False))
        if len(v['name']) > namelen:
            namelen = len(v['name'])
        if tlen > typelen:
          typelen = tlen

    namelen += 1
    typelen += 1

    formatstr = '    <span class="nv">%s</span><span class="kt">%s %s</span>\n'

    i = 0
    for v in s["fields"]:
        if v.has_key('comment') and v['comment']:
            if i > 0: code += "\n"
            for line in v['comment'].split("\n"):
                code += '    <span class="c1">// %s</span>\n' % line
        opt = ""
        if v.has_key('optional') and v['optional'] == True:
          opt = " [optional]"
        code += formatstr % (string.ljust(v['name'], namelen), string.ljust(format_type(v, includeOptional=False), typelen), opt)
        i += 1
    code += "}"

    return to_section(docs, code)
222217
@SuppressWarnings({ "unchecked", "rawtypes" })
    public static Object get(TBase<?, ?> struct, TFieldIdEnum field) {
        final Object value = ((TBase) struct).getFieldValue(field);
        if (value instanceof byte[]) {
            return ByteBuffer.wrap((byte[]) value);
        } else {
            return value;
        }
    }

    /**
     * Sets the value of the specified struct field.
     */
    @SuppressWarnings({ "unchecked", "rawtypes" })
    public static void set(TBase<?, ?> struct, TFieldIdEnum field, Object value) {
        ((TBase) struct).setFieldValue(field, value);
    }

    /**
     * Tells whether the specified struct field is set or not.
     */
    @SuppressWarnings({ "unchecked", "rawtypes" })
    public static boolean isSet(TBase<?, ?> struct, TFieldIdEnum field) {
        return ((TBase) struct).isSet(field);
    }

    private ThriftFieldAccess() {}
}
1170431
private boolean canScanNode(StructuralNode node) {
        if (node == null) {
            if (log.isDebugEnabled()) {
                log.debug("Ignoring null node");
            }
            return false;
        }

        HistoryReference hRef = node.getHistoryReference();
        if (hRef == null) {
            if (log.isDebugEnabled()) {
                log.debug("Ignoring null history reference for node: " + node.getName());
            }
            return false;
        }

        if (HistoryReference.TYPE_SCANNER == hRef.getHistoryType()) {
            if (log.isDebugEnabled()) {
                log.debug("Ignoring \"scanner\" type href [id=" + hRef.getHistoryId() + ", URL=" + hRef.getURI() + "]");
            }
            return false;
        }

        if (!nodeInScope(node.getName())) {
            if (log.isDebugEnabled()) {
                log.debug("Ignoring node not in scope: " + node.getName());
            }
            return false;
        }

        return true;
    }
773864
function getStruct (type) {
  // First check if a regular name was passed in
  var rtn = structCache[type];

  if (rtn) return rtn;

  // If the struct type name has already been created, return that one
  var name = parseStructName(type);

  rtn = structCache[name];
  if (rtn) return rtn;

  if(knownStructs[name]) type = knownStructs[name];
  // Next parse the type structure
  var parsed = parseStruct(type);
  // Otherwise we need to create a new Struct constructor
  var props = [];
  parsed.props.forEach(function (prop) {
    props.push([ map(prop[1]), prop[0] ])
  });
  var z;
  try { z = Struct(props); } catch(e) { }
  return structCache[parsed.name] = z;
}
872534
func Struct(name string, opts ...FieldOpt) FieldOpt {
	return func(em *eventMetadata, ed *eventData) {
		em.writeStruct(name, uint8(len(opts)), 0)
		for _, opt := range opts {
			opt(em, ed)
		}
	}
}
725292
function tuple(schema, defaults, options) {
  if (kindOf(schema) !== 'array') {
    if (process.env.NODE_ENV !== 'production') {
      throw new Error(
        `Tuple structs must be defined as an array, but you passed: ${schema}`
      )
    } else {
      throw new Error(`Invalid schema: ${schema}`)
    }
  }

  const kinds = schema.map(s => any(s, undefined, options))
  const array = scalar('array', undefined, options)
  const name = 'tuple'
  const type = `[${kinds.map(k => k.type).join()}]`
  const validate = (value = resolveDefaults(defaults)) => {
    const [error] = array.validate(value)

    if (error) {
      error.type = type
      return [error]
    }

    const ret = []
    const errors = []
    const length = Math.max(value.length, kinds.length)

    for (let i = 0; i < length; i++) {
      const kind = kinds[i]
      const v = value[i]

      if (!kind) {
        const e = { data: value, path: [i], value: v }
        errors.push(e)
        continue
      }

      const [e, r] = kind.validate(v)

      if (e) {
        const allE = e.errors || [e]
        allE.forEach(singleE => {
          singleE.path = [i].concat(singleE.path)
          singleE.data = value
          errors.push(singleE)
        })
        continue
      }

      ret[i] = r
    }

    if (errors.length) {
      const first = errors[0]
      first.errors = errors
      return [first]
    }

    return [undefined, ret]
  }

  return new Kind(name, type, validate)
}
1106169
private void defineWriteStructMethod()
    {
        MethodDefinition write = new MethodDefinition(
                a(PUBLIC),
                "write",
                null,
                arg("struct", structType),
                arg("protocol", TProtocol.class)
        );

        classDefinition.addMethod(write);

        // TProtocolReader reader = new TProtocolReader(protocol);
        write.addLocalVariable(type(TProtocolWriter.class), "writer");
        write.newObject(TProtocolWriter.class);
        write.dup();
        write.loadVariable("protocol");
        write.invokeConstructor(type(TProtocolWriter.class), type(TProtocol.class));
        write.storeVariable("writer");

        LocalVariableDefinition protocol = write.getLocalVariable("writer");

        // protocol.writeStructBegin("bonk");
        write.loadVariable(protocol)
                .loadConstant(metadata.getStructName())
                .invokeVirtual(TProtocolWriter.class, "writeStructBegin", void.class, String.class);

        // write fields
        for (ThriftFieldMetadata field : metadata.getFields(THRIFT_FIELD)) {
            writeField(write, protocol, field);
        }

        write.loadVariable(protocol)
                .invokeVirtual(TProtocolWriter.class, "writeStructEnd", void.class);

        write.ret();
    }
1093435
def determine_struct_tree_subtype(self, data_type, obj):
        
        if '.tag' not in obj:
            raise bv.ValidationError("missing '.tag' key")
        if not isinstance(obj['.tag'], six.string_types):
            raise bv.ValidationError('expected string, got %s' %
                                     bv.generic_type_name(obj['.tag']),
                                     parent='.tag')

        # Find the subtype the tags refer to
        full_tags_tuple = (obj['.tag'],)
        if full_tags_tuple in data_type.definition._tag_to_subtype_:
            subtype = data_type.definition._tag_to_subtype_[full_tags_tuple]
            if isinstance(subtype, bv.StructTree):
                raise bv.ValidationError("tag '%s' refers to non-leaf subtype" %
                                         ('.'.join(full_tags_tuple)))
            return subtype
        else:
            if self.strict:
                # In strict mode, the entirety of the tag hierarchy should
                # point to a known subtype.
                raise bv.ValidationError("unknown subtype '%s'" %
                                         '.'.join(full_tags_tuple))
            else:
                # If subtype was not found, use the base.
                if data_type.definition._is_catch_all_:
                    return data_type
                else:
                    raise bv.ValidationError(
                        "unknown subtype '%s' and '%s' is not a catch-all" %
                        ('.'.join(full_tags_tuple), data_type.definition.__name__))
993242
public static Node<PluralType> findChild(Struct<PluralType> parent, PluralType type) {
    for (Node<PluralType> n : parent.nodes()) {
      if (n.type() == type) {
        return n;
      }
    }
    return null;
  }
772519
@Check
	public void checkContainerType(SarlCapacity capacity) {
		final XtendTypeDeclaration declaringType = capacity.getDeclaringType();
		if (declaringType != null) {
			final String name = canonicalName(declaringType);
			assert name != null;
			error(MessageFormat.format(Messages.SARLValidator_30, name),
					capacity,
					null,
					INVALID_NESTED_DEFINITION);
		}
	}