model

package
v0.0.7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 3, 2024 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

package model provides *core* representations for different code structures. There should have no dependencies other than stdlib, so users of this package can freely import this without extra worry. This package should remain as minimal and substantial as possible.

Index

Constants

This section is empty.

Variables

View Source
var MergeAnnotationsInto func(res *ProjectAnnotation, annotations ...*ProjectAnnotation)

clone impl

Functions

func SortIBlocks

func SortIBlocks(blocks interface{})

blocks should be a slice of IBlockData

Types

type AnnotationType

type AnnotationType string
const (
	AnnotationType_Blocks       AnnotationType = "blocks"        // the File.Blocks
	AnnotationType_ChangeDetail AnnotationType = "change_detail" // the File.ChangeDetail

	// lines
	AnnotationType_LineEmpty          AnnotationType = "line_empty"           // the Line.Empty
	AnnotationType_LineBlockID        AnnotationType = "line_block_id"        // the Line.BlockID
	AnnotationType_LineFuncID         AnnotationType = "line_func_id"         // the Line.BlockID
	AnnotationType_LineChanges        AnnotationType = "line_changes"         // the Line.LineChanges
	AnnotationType_LineChanged        AnnotationType = "line_changed"         // the Line.Changed
	AnnotationType_LineOldLine        AnnotationType = "line_old_line"        // the Line.OldLine
	AnnotationType_LineLabels         AnnotationType = "line_labels"          // the Line.Labels
	AnnotationType_LineExecLabels     AnnotationType = "line_exec_labels"     // the Line.ExecLabels
	AnnotationType_LineCoverageLabels AnnotationType = "line_coverage_labels" // the Line.CoverageLabels
	AnnotationType_LineUncoverable    AnnotationType = "line_uncoverable"     // the Line.Uncoverable
	AnnotationType_LineCodeExcluded   AnnotationType = "line_code_excluded"   // the Line.Code.Excluded
	AnnotationType_LineRemark         AnnotationType = "line_remark"          // the Line.Remark

	// funcs
	AnnotationType_FileFuncs          AnnotationType = "funcs"                // the File.Funcs
	AnnotationType_FuncLabels         AnnotationType = "func_labels"          // the Line.ExecLabels
	AnnotationType_FuncExecLabels     AnnotationType = "func_exec_labels"     // the Line.ExecLabels
	AnnotationType_FuncCoverageLabels AnnotationType = "func_coverage_labels" // the Func.CoverageLabels
	AnnotationType_FuncChanged        AnnotationType = "func_changed"         // the Func.Changed
	AnnotationType_FuncCodeComments   AnnotationType = "func_code_comments"   // the Func.Code.Comments

	// Func.Code.Excluded is the exclude-flag by comment, there are some other
	// flags that can indicate whether a func is excluded:
	// func excluded = headLineExcluded || allLineExcluded || excludedByComment
	AnnotationType_FuncCodeExcluded AnnotationType = "func_code_excluded" // the Func.Code.Excluded

	// first line excluded
	AnnotationType_FirstLineExcluded AnnotationType = "func_first_line_excluded"
)

type Block

type Block struct {
	StartLine int `json:"startLine"`
	StartCol  int `json:"startCol"`
	EndLine   int `json:"endLine"`
	EndCol    int `json:"endCol"`
}

Block can be used as a unique key across one file

func (*Block) After

func (c *Block) After(b *Block) bool

func (*Block) Before

func (c *Block) Before(b *Block) bool

func (*Block) Clone

func (c *Block) Clone() *Block

func (*Block) Compare

func (a *Block) Compare(b *Block) int

func (*Block) ID

func (c *Block) ID() BlockID

func (*Block) SameBlock

func (c *Block) SameBlock(b *Block) bool

func (*Block) String

func (c *Block) String() string

type BlockAnnotation

type BlockAnnotation struct {
	Block  *Block `json:"block,omitempty"`
	FuncID FuncID `json:"funcID,omitempty"`
	// ExecLabels is the set of labels collected by runtime execution
	ExecLabels    StringSet   `json:"execLabels,omitempty"`
	BlockDataType string      `json:"blockDataType,omitempty"`
	BlockData     interface{} `json:"blockData,omitempty"` // extra block data
}

func (*BlockAnnotation) Simplify

func (c *BlockAnnotation) Simplify()

type BlockAnnotationMapping

type BlockAnnotationMapping map[BlockID]*BlockAnnotation

type BlockID

type BlockID string

func (*BlockID) UnmarshalJSON

func (c *BlockID) UnmarshalJSON(data []byte) error

type CodeAnnotation

type CodeAnnotation struct {
	// Labels     StringSet           `json:"labels,omitempty"`
	// ExecLabels StringSet           `json:"execLabels,omitempty"`
	Comments map[CommentLabel]*CodeComment `json:"comments,omitempty"` // example:  {labels: ["a","b","c"], "unreachable":true}

	Excluded bool `json:"excluded,omitempty"`
}

type CodeComment

type CodeComment struct {
	Author string   `json:"author,omitempty"`
	Values []string `json:"values,omitempty"`
}

func (*CodeComment) Clone

func (c *CodeComment) Clone() *CodeComment

type CodeSuggestion

type CodeSuggestion string
const (
	Suggestion_Other CodeSuggestion = "other"
)

type Comment

type Comment struct {
	Author string `json:"author,omitempty"`
	// UTC time
	CreateTime string `json:"createTime,omitempty"`
	Content    string `json:"content,omitempty"`
}

type CommentLabel

type CommentLabel string
const (
	CommentLabels_Labels      CommentLabel = "labels"
	CommentLabels_Unreachable CommentLabel = "unreachable"
	CommentLabels_NoCov       CommentLabel = "nocov"
	CommentLabels_Deprecated  CommentLabel = "deprecated"
)

type ExcludeReason

type ExcludeReason string
const (
	ExcludeReason_Other ExcludeReason = "other"
)

type FileAnnotation

type FileAnnotation struct {
	ChangeDetail *git.FileDetail        `json:"changeDetail,omitempty"`
	Lines        LineAnnotationMapping  `json:"lines,omitempty"`       // 1-based mapping
	LineChanges  *model.LineChanges     `json:"lineChanges,omitempty"` // optional
	DeletedLines map[int64]bool         `json:"deletedLines,omitempty"`
	Blocks       BlockAnnotationMapping `json:"blocks,omitempty"`
	Funcs        FuncAnnotationMapping  `json:"funcs,omitempty"` // by func id
	FileDataType string                 `json:"fileDataType,omitempty"`
	FileData     interface{}            `json:"fileData,omitempty"` // extra file data
}

func (*FileAnnotation) Simplify

func (c *FileAnnotation) Simplify()

type FileAnnotationMapping

type FileAnnotationMapping map[RelativeFile]*FileAnnotation

type FuncAnnotation

type FuncAnnotation struct {
	Block         *Block `json:"block,omitempty"`
	Name          string `json:"name,omitempty"`
	OwnerTypeName string `json:"ownerTypeName,omitempty"`
	Closure       bool   `json:"closure"` // a closure, without name
	Changed       bool   `json:"changed"` // derived from line changed
	Ptr           bool   `json:"ptr,omitempty"`

	// Labels inerited from lines
	Labels StringSet `json:"labels,omitempty"`

	// ExecLabels inherited from lines
	ExecLabels StringSet `json:"execLabels,omitempty"`

	CoverageLabels map[string]bool `json:"coverageLabels,omitempty"`
	Code           *CodeAnnotation `json:"code,omitempty"`

	FirstLineExcluded bool `json:"firstLineExcluded,omitempty"`
}

func (*FuncAnnotation) Simplify

func (c *FuncAnnotation) Simplify()

type FuncAnnotationMapping

type FuncAnnotationMapping map[FuncID]*FuncAnnotation

type FuncID

type FuncID = BlockID

FuncID and BlockID are globally unique within a file and a commit

type FuncInfoMapping added in v0.0.4

type FuncInfoMapping map[RelativeFile][]*FuncAnnotation

type IBlockData

type IBlockData interface {
	GetBlock() *Block
}

type LineAnnotation

type LineAnnotation struct {
	OldLine int64   `json:"oldLine,omitempty"` // if 0 or undefined, no oldLine. only effective when not changed
	Changed bool    `json:"changed,omitempty"` // is this line changed
	BlockID BlockID `json:"blockID,omitempty"` // related blockID, can not be zero
	Empty   bool    `json:"empty,omitempty"`   // is this an empty line

	// Labels tells what code sets this line matches
	// a map to make merge easier
	Labels StringSet `json:"labels,omitempty"`

	// ExecLabels is the set of labels collected by runtime execution
	ExecLabels StringSet `json:"execLabels,omitempty"`

	// CoverageLabels true->has cover, false->has no cover
	// examples: ALL:true, RC:true|false
	// NOTE: it's not a StringSet, its just a map derived from Labels & ExecLabels and other options
	CoverageLabels map[string]bool `json:"coverageLabels,omitempty"`

	FuncID FuncID `json:"funcID,omitempty"`

	// Uncoverable empty or non-block or just a simple "}", or it has been marked unreachable
	Uncoverable bool `json:"uncoverable,omitempty"`

	Code *CodeAnnotation `json:"code,omitempty"`

	Remark *Remark `json:"remark,omitempty"`

	LineDataType string      `json:"lineDataType,omitempty"`
	LineData     interface{} `json:"lineData,omitempty"` // extra line data
}

func (*LineAnnotation) Simplify

func (c *LineAnnotation) Simplify()

type LineAnnotationMapping

type LineAnnotationMapping map[LineNum]*LineAnnotation

type LineNum

type LineNum int64

type ProjectAnnotation

type ProjectAnnotation struct {
	// short file -> annotations
	Files           FileAnnotationMapping   `json:"files,omitempty"`
	Types           map[AnnotationType]bool `json:"types,omitempty"` // types indicator
	CommitHash      string                  `json:"commitHash,omitempty"`
	ProjectDataType string                  `json:"projectDataType,omitempty"`
	ProjectData     interface{}             `json:"projectData,omitempty"` // extra project data
}

func (*ProjectAnnotation) Clone

func (*ProjectAnnotation) Has

func (c *ProjectAnnotation) Has(annotationType AnnotationType) bool

func (*ProjectAnnotation) MustHave

func (c *ProjectAnnotation) MustHave(reason string, annotationTypes ...AnnotationType)

func (*ProjectAnnotation) Set

func (c *ProjectAnnotation) Set(annotationType AnnotationType)

func (*ProjectAnnotation) ShouldHave added in v0.0.2

func (c *ProjectAnnotation) ShouldHave(reason string, annotationTypes ...AnnotationType) error

func (*ProjectAnnotation) Simplified

func (c *ProjectAnnotation) Simplified() *ProjectAnnotation

func (*ProjectAnnotation) Simplify

func (c *ProjectAnnotation) Simplify()

type RelativeFile

type RelativeFile string

type RemapRequest

type RemapRequest struct {
	Include       []string           `json:"include"`
	Exclude       []string           `json:"exclude"`
	GitURL        string             `json:"gitURL"`
	CommitHash    string             `json:"commitHash"`
	OldCommitHash string             `json:"oldCommitHash"`
	Annotation    *ProjectAnnotation `json:"annotation"`
}

type RemapResponse

type RemapResponse struct {
	Annotation *ProjectAnnotation `json:"annotation"`
}

type Remark

type Remark struct {
	Excluded   bool           `json:"excluded,omitempty"`
	Reason     ExcludeReason  `json:"reason,omitempty"`
	Suggestion CodeSuggestion `json:"suggestion,omitempty"`
	Comments   []*Comment     `json:"comments,omitempty"`
	CreateTime string         `json:"createTime,omitempty"`
	Creator    string         `json:"creator,omitempty"`
	UpdateTime string         `json:"updateTime,omitempty"`
	Updater    string         `json:"updater,omitempty"`
}

type StringSet

type StringSet = map[string]bool

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL