Example #1
0
// parseVariableComment method parse variable comment data and return
// variable struct
func parseVariableComment(name, value string, data []string) *Variable {
	if len(data) == 0 || sliceutil.Contains([]string{"private", "PRIVATE", "-"}, strings.TrimRight(data[0], " ")) {
		return nil
	}

	variable := &Variable{
		Name:  name,
		Value: value,
	}

	data, t := getVariableType(data)

	if t == VAR_TYPE_UKNOWN {
		t = guessVariableType(value)
	}

	variable.Type = t
	variable.Desc = data

	return variable
}
Example #2
0
// parseMethodComment method parse method comment data and return
// method struct
func parseMethodComment(name string, data []string) *Method {
	if len(data) == 0 || sliceutil.Contains([]string{"private", "PRIVATE", "-"}, strings.TrimRight(data[0], " ")) {
		return nil
	}

	method := &Method{Name: name}

	for index, line := range data {
		if methodArgRegExp.MatchString(line) {
			if method.Desc == nil {
				method.Desc = extractMethodDesc(data, index)
			}

			method.Arguments = append(method.Arguments, parseArgumentComment(line))

			continue
		}

		if strings.HasPrefix(line, "Code:") {
			if method.Desc == nil {
				method.Desc = extractMethodDesc(data, index)
			}

			retValue := line[6:]

			if negativeValRegexp.MatchString(retValue) {
				continue
			}

			method.ResultCode = true
		}

		if strings.HasPrefix(line, "Echo:") {
			if method.Desc == nil {
				method.Desc = extractMethodDesc(data, index)
			}

			echoValue := line[6:]

			if negativeValRegexp.MatchString(echoValue) {
				continue
			}

			method.ResultEcho = parseVariableComment("", "", []string{echoValue})
		}

		if strings.HasPrefix(line, "Example:") {
			if method.Desc == nil {
				method.Desc = extractMethodDesc(data, index)
			}

			method.Example = getCleanData(data[index+1:])
			break // Example is last part of comment
		}
	}

	if method.Desc == nil {
		method.Desc = extractMethodDesc(data, len(data))
	}

	return method
}