Exemple #1
0
func _AttachAnnotation(node ast.Node, annotations ...*ast.Annotation) {

	anns := Annotations(node)

	anns = append(anns, annotations...)

	node.SetExtra(ExtraAnnotation, anns)
}
Exemple #2
0
// Annotations .
func Annotations(node ast.Node) (anns []*ast.Annotation) {

	val, ok := node.GetExtra(ExtraAnnotation)

	if ok {
		anns = val.([]*ast.Annotation)
	}

	return
}
Exemple #3
0
// Annotations .
func _RemoveAnnotation(node ast.Node, annotation *ast.Annotation) {

	anns := Annotations(node)

	var newanns []*ast.Annotation

	for _, ann := range anns {
		if ann == annotation {
			continue
		}
		newanns = append(newanns, ann)
	}
	node.SetExtra(ExtraAnnotation, anns)
}
Exemple #4
0
// Pos .
func Pos(node ast.Node) (start lexer.Position, end lexer.Position) {
	val, ok := node.GetExtra(ExtraStartPos)

	if ok {
		start = val.(lexer.Position)
	}

	val, ok = node.GetExtra(ExtraEndPos)

	if ok {
		end = val.(lexer.Position)
	}

	return
}
Exemple #5
0
func _AttachComment(node ast.Node, comment *ast.Comment) bool {
	nodeStart, nodeEnd := Pos(node)

	commentStart, commentEnd := Pos(comment)

	if nodeStart.Lines == commentEnd.Lines ||
		nodeStart.Lines == commentEnd.Lines+1 ||
		nodeEnd.Lines == commentStart.Lines {

		node.SetExtra(ExtraComment, comment)

		return true
	}

	return false
}
Exemple #6
0
// FindAnnotations .
func FindAnnotations(node ast.Node, name string) (retval []*ast.Annotation) {

	val, ok := node.GetExtra(ExtraAnnotation)

	if ok {
		anns := val.([]*ast.Annotation)

		for _, ann := range anns {

			if ann.Type.Ref == nil {
				continue
			}

			if ann.Type.Ref.FullName() == name {
				retval = append(retval, ann)
			}
		}
	}

	return
}
Exemple #7
0
// FindAnnotation .
func FindAnnotation(node ast.Node, name string) (*ast.Annotation, bool) {

	val, ok := node.GetExtra(ExtraAnnotation)

	if ok {
		anns := val.([]*ast.Annotation)

		for _, ann := range anns {

			if ann.Type.Ref == nil {
				continue
			}

			if ann.Type.Ref.FullName() == name {
				return ann, true
			}
		}
	}

	return nil, false
}
Exemple #8
0
func _setNodePos(node ast.Node, start lexer.Position, end lexer.Position) {
	node.SetExtra(ExtraStartPos, start)
	node.SetExtra(ExtraEndPos, end)
}