Parses an enum type definition

@param fieldDoc
@return
192773
protected EnumConstant parseEnumConstant(FieldDoc fieldDoc) {
		EnumConstant enumConstant = objectFactory.createEnumConstant();
		enumConstant.setName(fieldDoc.name());
		String comment = fieldDoc.commentText();
		if (comment.length() > 0) {
			enumConstant.setComment(comment);
		}

		for (AnnotationDesc annotationDesc : fieldDoc.annotations()) {
			enumConstant.getAnnotation().add(parseAnnotationDesc(annotationDesc, fieldDoc.qualifiedName()));
		}

		for (Tag tag : fieldDoc.tags()) {
			enumConstant.getTag().add(parseTag(tag));
		}

		return enumConstant;
	}
1272714
private String parse(DocumentContext document) throws ParseException {
    if (document.namespaceDeclaration() != null) {
      setCurrentNamespace(
        document.namespaceDeclaration().qualifiedIdentifier().value);
    } else {
      setCurrentNamespace("");
    }

    setCurrentImports(document.importDeclarations());
    NamedDataSchema schema = parseNamedType(document.namedTypeDeclaration());
    topLevelSchemas.add(schema);
    return schema.getFullName();
  }
874690
private String parseValue(String fieldType, Object value) {
		if (TypeConver.isBasicType(fieldType)) {
			if (value != null) {
				return value.toString();
			} else {
				return null;
			}
		}
		return null;
	}
111704
private TableFieldSchema parseFieldAnnotations(Field field) {
    TableFieldSchema tf = new TableFieldSchema();
    String name = getFieldName(field);
    String desc = getFieldDescription(field);
    String fieldMode = getFieldMode(field);

    return tf.setName(name).setDescription(desc).setMode(fieldMode);
  }
1227709
private static Fields toFieldEnum(Field field) {
        Class<?> clazz = field.getType();
        String name = clazz.getSimpleName().toLowerCase();

        if (name.equals("int") || name.equals("integer")) {
            return Fields.INT;
        } else if (name.equals("long")) {
            return Fields.LONG;
        } else if (name.equals("float")) {
            return Fields.FLOAT;
        } else if (name.equals("double")) {
            return Fields.DOUBLE;
        } else if (CharSequence.class.isAssignableFrom(clazz)) {
            return Fields.STRING;
        } else if (name.equals("boolean")) {
            return Fields.BOOLEAN;
        } else if (clazz.isAssignableFrom(List.class)) {
            ParameterizedType listType = (ParameterizedType) field.getGenericType();
            Class<?> listClass = (Class<?>) listType.getActualTypeArguments()[0];

            if (listClass.toString().equals("class java.lang.String")) {
                return Fields.LIST;
            }
        }

        throw new RuntimeException("Field not found!");
    }
1032499
private static DescriptorProtoPOJO getDescritorProtoPOJO(FileDescriptorProtoPOJO fileDescriptorProto,
            MessageElement typeElement, Set<String> messageSet, Set<String> enumSet) {

        DescriptorProtoPOJO ret = new DescriptorProtoPOJO();
        ret.name = typeElement.name();
        ret.fields = new ArrayList<FieldDescriptorProtoPOJO>();
        ret.nestedTypes = new ArrayList<DescriptorProtoPOJO>();
        ret.enumTypes = new ArrayList<EnumDescriptorProtoPOJO>();
        ret.extensionRanges = new ArrayList<ExtensionRangePOJO>();
        ret.extensions = new ArrayList<FieldDescriptorProtoPOJO>();
        ret.options = new ArrayList<MessageOptionsPOJO>();
        ret.oneofDecls = new ArrayList<OneofDescriptorProtoPOJO>();

        List<FieldElement> fields = typeElement.fields();
        if (fields != null) {
            FieldDescriptorProtoPOJO fieldDescriptorProto;
            for (FieldElement fieldElement : fields) {
                fieldDescriptorProto = new FieldDescriptorProtoPOJO();
                fieldDescriptorProto.name = fieldElement.name();
                fieldDescriptorProto.extendee = null; // XXX
                fieldDescriptorProto.number = fieldElement.tag();

                FieldElement.Label label = fieldElement.label();
                if (label == FieldElement.Label.OPTIONAL) {
                    fieldDescriptorProto.label = Label.LABEL_OPTIONAL;
                } else if (label == FieldElement.Label.REQUIRED) {
                    fieldDescriptorProto.label = Label.LABEL_REQUIRED;
                } else if (label == FieldElement.Label.REPEATED) {
                    fieldDescriptorProto.label = Label.LABEL_REPEATED;
                }

                DataType type = fieldElement.type();
                if (type.kind() == Kind.MAP) {
                    String messageName = StringUtils.capitalize(fieldDescriptorProto.name) + MAP_ENTRY_SUFFIX;
                    fieldDescriptorProto.type = Type.TYPE_MESSAGE;
                    fieldDescriptorProto.typeName = CodeGenerator.PACKAGE_SPLIT + fileDescriptorProto.pkg
                            + CodeGenerator.PACKAGE_SPLIT + ret.name + CodeGenerator.PACKAGE_SPLIT + messageName;
                    // refix label type
                    fieldDescriptorProto.label = Label.LABEL_REPEATED;

                    // here should add key and value type message type
                    DataType.MapType mapType = (DataType.MapType) type;

                    MessageElement messageElement = getMapKVMessageElements(messageName, mapType);

                    ret.nestedTypes
                            .add(getDescritorProtoPOJO(fileDescriptorProto, messageElement, messageSet, enumSet));

                } else if (type.kind() == Kind.MAP || type.kind() == Kind.NAMED) {
                    fieldDescriptorProto.typeName = ((DataType.NamedType) type).name();
                    if (messageSet.contains(fieldDescriptorProto.typeName)) {
                        fieldDescriptorProto.type = Type.TYPE_MESSAGE;
                    } else {
                        fieldDescriptorProto.type = Type.TYPE_ENUM;
                    }
                } else {
                    fieldDescriptorProto.type = Type.valueOf("TYPE_" + ((DataType.ScalarType) type).name());
                }

                ret.fields.add(fieldDescriptorProto);
            }
        }

        List<TypeElement> nestedElements = typeElement.nestedElements();
        if (nestedElements != null) {

            for (TypeElement nestedTypeElement : nestedElements) {
                if (nestedTypeElement instanceof MessageElement) {
                    ret.nestedTypes.add(getDescritorProtoPOJO(fileDescriptorProto, (MessageElement) nestedTypeElement,
                            messageSet, enumSet));
                } else if (nestedTypeElement instanceof EnumElement) {
                    ret.enumTypes.add(getDescritorProtoPOJO(fileDescriptorProto, (EnumElement) nestedTypeElement,
                            messageSet, enumSet));
                }
            }
        }

        return ret;
    }
923394
public static String getDefaultValue(Field field) {
        FieldType type = field.getType();
        if (type instanceof ScalarFieldType) {
            return ScalarFieldTypeUtil.getDefaultValue((ScalarFieldType) type);
        }
        if (type instanceof Message) {
            Message m = (Message) type;
            return UserTypeUtil.getCanonicalName(m) + ".getDefaultInstance()";
        }
        if (type instanceof Enum) {
            Enum anEnum = (Enum) type;
            String defaultValue;
            List<EnumConstant> constants = anEnum.getConstants();
            if (constants.isEmpty()) {
                defaultValue = "UNRECOGNIZED";
            } else {
                DynamicMessage options = field.getOptions();
                defaultValue = options.containsKey(DEFAULT) ? options.get(DEFAULT).getEnumName() : constants.get(0).getName();
            }
            return UserTypeUtil.getCanonicalName(anEnum) + "." + defaultValue;
        }
        throw new IllegalArgumentException(String.valueOf(type));
    }
445714
public static Matcher enumDefinition() {
    return new Matcher() {
      @Override public boolean matches(Node node, NodeMetadata metadata) {
        JSType jsType = node.getJSType();
        return jsType != null && jsType.isEnumType();
      }
    };
  }
44886
private Node parseFieldType(JsDocToken token) {
    Node fieldName = parseFieldName(token);

    if (fieldName == null) {
      return null;
    }

    skipEOLs();
    if (!match(JsDocToken.COLON)) {
      return fieldName;
    }

    // Move to the colon.
    next();

    // Move to the token after the colon and parse
    // the type expression.
    skipEOLs();
    Node typeExpression = parseTypeExpression(next());

    if (typeExpression == null) {
      return null;
    }

    Node fieldType = newNode(Token.COLON);
    fieldType.addChildToBack(fieldName);
    fieldType.addChildToBack(typeExpression);
    return fieldType;
  }
992810
public static boolean isScalarNullableType(Field field) {
        FieldType type = field.getType();
        return STRING.equals(type) || BYTES.equals(type) || type instanceof io.protostuff.compiler.model.Enum;
    }
412290
def code(field, enum)
      code_field_name = :"#{field}_code"
      validates code_field_name, inclusion: enum.all.map { |item| item.code }
      instance_eval do
        define_method field do
          enum.select { |item| item.code==send(code_field_name.to_sym) }.first
        end
        define_method "#{field}=" do |value|
          send "#{code_field_name}=".to_sym, value.code
        end
      end
    end
1351436
private Node parseFieldTypeList(JsDocToken token) {
    Node fieldTypeList = newNode(Token.LB);

    Set<String> names = new HashSet<>();

    do {
      Node fieldType = parseFieldType(token);

      if (fieldType == null) {
        return null;
      }

      String name = fieldType.isStringKey() ? fieldType.getString()
          : fieldType.getFirstChild().getString();
      if (names.add(name)) {
        fieldTypeList.addChildToBack(fieldType);
      } else {
        addTypeWarning("msg.jsdoc.type.record.duplicate", name);
      }

      skipEOLs();
      if (!match(JsDocToken.COMMA)) {
        break;
      }

      // Move to the comma token.
      next();

      // Move to the token past the comma
      skipEOLs();

      if (match(JsDocToken.RIGHT_CURLY)) {
        // Allow trailing comma (ie, right curly following the comma)
        break;
      }

      token = next();
    } while (true);

    return fieldTypeList;
  }
233060
private static function createEnumFilter(Endpoint $endpoint, FieldDefinition $field, string $enumName, array $enumValues): Filter
    {
        $name = "{$enumName}ComparisonExpression";
        if ($endpoint->hasType($name)) {
            $condition = $endpoint->getType($name);
        } else {
            /** @var InputObjectDefinition $condition */
            $condition = unserialize(serialize($endpoint->getType(EnumComparisonExpression::class)), ['allowed_classes' => true]);
            $condition->setName($name);
            $condition->getField('values')->setType($enumName)->setList(true);
            $description = $condition->getDescription();
            $description = str_replace('\'{VALUE_1}\'', array_values($enumValues)[0], $description);
            if (isset(array_values($enumValues)[1])) {
                $description = str_replace('\'{VALUE_2}\'', array_values($enumValues)[1], $description);
            } else {
                $description = str_replace(', \'{VALUE_2}\'', null, $description);
            }
            $condition->setDescription($description);
            $endpoint->add($condition);
        }
        $filter = new Filter();
        $filter->name = $filter->field = $field->getName();
        $filter->resolver = EnumFilter::class;
        $filter->type = $condition->getName();

        return $filter;
    }
1158985
private FieldElement readField(String documentation, FieldElement.Label label) {
    DataType type = readDataType();
    String name = readName();
    if (readChar() != '=') throw unexpected("expected '='");
    int tag = readInt();

    FieldElement.Builder builder = FieldElement.builder()
        .label(label)
        .type(type)
        .name(name)
        .tag(tag);

    if (peekChar() == '[') {
      pos++;
      while (true) {
        builder.addOption(readOption('='));

        // Check for optional ',' or closing ']'
        char c = peekChar();
        if (c == ']') {
          pos++;
          break;
        } else if (c == ',') {
          pos++;
        }
      }
    }
    if (readChar() != ';') {
      throw unexpected("expected ';'");
    }
    documentation = tryAppendTrailingDocumentation(documentation);
    return builder.documentation(documentation).build();
  }
1163085
public Root parseRootDoc(RootDoc rootDoc) {
		Root rootNode = objectFactory.createRoot();

		for (ClassDoc classDoc : rootDoc.classes()) {
			PackageDoc packageDoc = classDoc.containingPackage();

			Package packageNode = packages.get(packageDoc.name());
			if (packageNode == null) {
				packageNode = parsePackage(packageDoc);
				packages.put(packageDoc.name(), packageNode);
				rootNode.getPackage().add(packageNode);
			}

			if (classDoc instanceof AnnotationTypeDoc) {
				packageNode.getAnnotation().add(parseAnnotationTypeDoc((AnnotationTypeDoc) classDoc));
			} else if (classDoc.isEnum()) {
				packageNode.getEnum().add(parseEnum(classDoc));
			} else if (classDoc.isInterface()) {
				packageNode.getInterface().add(parseInterface(classDoc));
			} else {
				packageNode.getClazz().add(parseClass(classDoc));
			}
		}

		return rootNode;
	}
1265683
private EnumConstantElement readEnumConstant(
      String documentation, Location location, String label) {
    reader.require('=');

    int tag = reader.readInt();

    List<OptionElement> options = new OptionReader(reader).readOptions();
    reader.require(';');
    documentation = reader.tryAppendTrailingDocumentation(documentation);

    return new EnumConstantElement(
        location,
        label,
        tag,
        documentation,
        options);
  }
484375
public final ProtoParser.enum_field_return enum_field(Proto proto, Message message, EnumGroup enumGroup) throws RecognitionException {
        ProtoParser.enum_field_return retval = new ProtoParser.enum_field_return();
        retval.start = input.LT(1);

        Object root_0 = null;

        Token ID127=null;
        Token ASSIGN128=null;
        Token NUMINT129=null;
        Token SEMICOLON131=null;
        ProtoParser.enum_options_return enum_options130 = null;


        Object ID127_tree=null;
        Object ASSIGN128_tree=null;
        Object NUMINT129_tree=null;
        Object SEMICOLON131_tree=null;


            EnumGroup.Value v = null;

        try {
            // com/dyuproject/protostuff/parser/ProtoParser.g:547:5: ( ID ASSIGN NUMINT ( enum_options[proto, enumGroup, v] )? SEMICOLON )
            // com/dyuproject/protostuff/parser/ProtoParser.g:547:9: ID ASSIGN NUMINT ( enum_options[proto, enumGroup, v] )? SEMICOLON
            {
            root_0 = (Object)adaptor.nil();

            ID127=(Token)match(input,ID,FOLLOW_ID_in_enum_field2181); if (state.failed) return retval;
            if ( state.backtracking==0 ) {
            ID127_tree = (Object)adaptor.create(ID127);
            adaptor.addChild(root_0, ID127_tree);
            }
            ASSIGN128=(Token)match(input,ASSIGN,FOLLOW_ASSIGN_in_enum_field2183); if (state.failed) return retval;
            if ( state.backtracking==0 ) {
            ASSIGN128_tree = (Object)adaptor.create(ASSIGN128);
            adaptor.addChild(root_0, ASSIGN128_tree);
            }
            NUMINT129=(Token)match(input,NUMINT,FOLLOW_NUMINT_in_enum_field2185); if (state.failed) return retval;
            if ( state.backtracking==0 ) {
            NUMINT129_tree = (Object)adaptor.create(NUMINT129);
            adaptor.addChild(root_0, NUMINT129_tree);
            }
            if ( state.backtracking==0 ) {

                          v = new EnumGroup.Value((ID127!=null?ID127.getText():null), Integer.parseInt((NUMINT129!=null?NUMINT129.getText():null)), enumGroup);
                          proto.addAnnotationsTo(v);
                      
            }
            // com/dyuproject/protostuff/parser/ProtoParser.g:550:11: ( enum_options[proto, enumGroup, v] )?
            int alt25=2;
            switch ( input.LA(1) ) {
                case LEFTSQUARE:
                    {
                    alt25=1;
                    }
                    break;
            }

            switch (alt25) {
                case 1 :
                    // com/dyuproject/protostuff/parser/ProtoParser.g:550:12: enum_options[proto, enumGroup, v]
                    {
                    pushFollow(FOLLOW_enum_options_in_enum_field2190);
                    enum_options130=enum_options(proto, enumGroup, v);

                    state._fsp--;
                    if (state.failed) return retval;
                    if ( state.backtracking==0 ) adaptor.addChild(root_0, enum_options130.getTree());

                    }
                    break;

            }

            SEMICOLON131=(Token)match(input,SEMICOLON,FOLLOW_SEMICOLON_in_enum_field2195); if (state.failed) return retval;

            }

            retval.stop = input.LT(-1);

            if ( state.backtracking==0 ) {

            retval.tree = (Object)adaptor.rulePostProcessing(root_0);
            adaptor.setTokenBoundaries(retval.tree, retval.start, retval.stop);
            }
        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
    	retval.tree = (Object)adaptor.errorNode(input, retval.start, input.LT(-1), re);

        }
        finally {
        }
        return retval;
    }