model

package
v0.0.0-...-67a34a8 Latest Latest
Warning

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

Go to latest
Published: May 22, 2019 License: MIT Imports: 9 Imported by: 2

Documentation

Overview

Package model refers to model part of mvc. It performs abstraction of datamodel and encapsulates save and retrieves.

Package model refers to model part of mvc. It performs abstraction of datamodel and encapsulates save and retrieves.

Index

Constants

This section is empty.

Variables

View Source
var DB = &MongoDB{"mongodb://localhost", "CodeVis3D", "gitRepository"}

DB is a mongo database with name CodeVis3D and collection gitRepository

View Source
var JavaParserPath string

JavaParserPath is the path where is java parser is stored.

View Source
var RepoPath string

RepoPath is the path where git repositories are stored.

Functions

This section is empty.

Types

type AccessSpecifierModel

type AccessSpecifierModel struct {
	Name      string          `json:"name"`
	Classes   []ClassModel    `json:"classes,omitempty"`
	Functions []FunctionModel `json:"functions,omitempty"`
	Variables []VariableModel `json:"variables,omitempty"`
}

AccessSpecifierModel represents code for a single access specifier

type CallModel

type CallModel struct {
	Identifier string       `json:"identifier"`
	Scope      []ScopeModel `json:"scopes,omitempty"`
}

CallModel represents a function call from code.

type ClassModel

type ClassModel struct {
	Name                  string                 `json:"name"`
	AccessSpecifierModels []AccessSpecifierModel `json:"access_specifiers,omitempty"`
	Parents               []string               `json:"parents,omitempty"`
}

ClassModel represents code for a single calss

type CodeSnippetModel

type CodeSnippetModel struct {
	FilePath  string        `json:"file_path"`              // File name to be searched through.
	ID        bson.ObjectId `json:"-" bson:"_id,omitempty"` // Folder name where repo is stored
	StartLine int           `json:"start_line"`
	EndLine   int           `json:"end_line"`
}

CodeSnippetModel represents metadata for a file from a git project.

func (CodeSnippetModel) FetchLinesOfCode

func (codeSnippet CodeSnippetModel) FetchLinesOfCode() (string, error)

FetchLinesOfCode fetch loc from specified range.

type FileModel

type FileModel struct {
	Parsed          bool                  `json:"parsed"`
	FileName        string                `json:"file_name"`
	Functions       []FunctionModel       `json:"functions,omitempty"`
	Namespaces      []NamespaceModel      `json:"namespaces,omitempty"`
	UsingNamespaces []UsingNamespaceModel `json:"using_namespaces,omitempty"`
	Includes        []string              `json:"includes,omitempty"`
	Classes         []ClassModel          `json:"classes,omitempty"`
	Variables       []VariableModel       `json:"variables,omitempty"`
	LinesInFile     int                   `json:"linesInFile"`
}

FileModel represents a single code file

type FileWrapperModel

type FileWrapperModel struct {
	File FileModel `json:"file"`
}

FileWrapperModel is a wrapper for FileModel for json parsing

type FunctionBodyModel

type FunctionBodyModel struct {
	Calls     []CallModel     `json:"calls,omitempty"`
	Variables []VariableModel `json:"variables,omitempty"`
}

FunctionBodyModel represents calls and variable from a function.

type FunctionModel

type FunctionModel struct {
	Name         string            `json:"name"`
	DeclID       string            `json:"declrator_id"`
	ReturnType   string            `json:"return_type,omitempty"`
	FunctionBody FunctionBodyModel `json:"function_body,omitempty"`
	Parameters   []ParameterModel  `json:"parameters,omitempty"`
	Scope        string            `json:"scope,omitempty"`
	StartLine    int               `json:"start_line"`
	EndLine      int               `json:"end_line"`
}

FunctionModel represents code for a single function

type MongoDB

type MongoDB struct {
	DatabaseURL  string
	DatabaseName string
	RepoColl     string
}

MongoDB stores the details of the DB connection.

func (*MongoDB) Add

func (db *MongoDB) Add(rm *RepoModel) error

Add adds rm to db if it is not already in it.

func (*MongoDB) Count

func (db *MongoDB) Count() int

Count returns number of items in the collection.

func (*MongoDB) DropDB

func (db *MongoDB) DropDB() (err error)

DropDB deletes the database

func (*MongoDB) FindAllURI

func (db *MongoDB) FindAllURI() (repos []bson.M, err error)

FindAllURI finds and returns all the repos stored in DB.

func (*MongoDB) FindRepoByID

func (db *MongoDB) FindRepoByID(id string) (repo RepoModel, err error)

FindRepoByID takes the repo with field id as given id. It returns empty repo if it is not in db.

func (*MongoDB) Init

func (db *MongoDB) Init() error

Init - initializes the mongoDB database

func (*MongoDB) Update

func (db *MongoDB) Update(rm *RepoModel) error

Update updates the repo model matching rm.

type NamespaceModel

type NamespaceModel struct {
	NamespaceName   string                `json:"name"`
	Functions       []FunctionModel       `json:"functions,omitempty"`
	Namespaces      []NamespaceModel      `json:"namespaces,omitempty"`
	UsingNamespaces []UsingNamespaceModel `json:"using_namespaces,omitempty"`
	Includes        []string              `json:"includes,omitempty"`
	Classes         []ClassModel          `json:"classes,omitempty"`
	Variables       []VariableModel       `json:"variables,omitempty"`
}

NamespaceModel represents code for a single namespace

type ParameterModel

type ParameterModel struct {
	Name string `json:"name"`
	Type string `json:"type"`
}

ParameterModel represents a parameter from code.

type ParseResponse

type ParseResponse struct {
	StatusText       string
	Err              error
	CurrentFile      string
	ParsedFileCount  int
	SkippedFileCount int
	FileCount        int
	Result           ProjectModel
}

ParseResponse is used by ParseDataFromFiles to update channel used by go routine to indicate status of request and result

type ProjectModel

type ProjectModel struct {
	Files []FileModel `json:"files"`
}

ProjectModel represent the codebase in a repository

type RepoModel

type RepoModel struct {
	URI        string        `json:"uri"`                     // Where the repository was found
	ID         bson.ObjectId `json:"id" bson:"_id,omitempty"` // Folder name where repo is stored
	ParsedRepo ProjectModel  `json:"parsedrepo,omitempty"`    // Parsed repository in json format
}

RepoModel represents metadata for a git repository.

func (RepoModel) FetchAll

func (repo RepoModel) FetchAll() (repoModels []bson.M, err error)

FetchAll fetches all the repositories.

func (RepoModel) GetRepoByID

func (repo RepoModel) GetRepoByID(id string) (rep RepoModel, err error)

GetRepoByID finds repo in database and returns.

func (RepoModel) GetRepoFiles

func (repo RepoModel) GetRepoFiles() (files string, err error)

GetRepoFiles finds and returns all files stored in repository directory. Excludes directories them selfs (as files) and anything from ".git" folder

func (RepoModel) Load

func (repo RepoModel) Load(file string, target string) (data FileModel, err error)

Load loads java application to parse a specified file.

func (RepoModel) ParseDataFromFiles

func (repo RepoModel) ParseDataFromFiles(files string, responsePerNFiles int, c chan ParseResponse)

ParseDataFromFiles fetch all functions from gives files set.

func (RepoModel) SanitizeFilePaths

func (repo RepoModel) SanitizeFilePaths(projectModel ProjectModel)

SanitizeFilePaths removes the repopath from the filepaths.

func (RepoModel) Save

func (repo RepoModel) Save(c chan SaveResponse)

Save is expected to run as a go rutine writing to a c.

func (RepoModel) UpdateRepo

func (repo RepoModel) UpdateRepo() error

UpdateRepo updates the repo model with repo in db.

type SaveResponse

type SaveResponse struct {
	ID         string
	StatusText string
	Err        error
}

SaveResponse is used by save function to update channel used by go routine to indicate status of the save request.

type ScopeModel

type ScopeModel struct {
	Identifier string `json:"identifier"`
	Type       string `json:"type,omitempty"`
}

ScopeModel represents the scope and name of the function call.

type UsingNamespaceModel

type UsingNamespaceModel struct {
	Name   string `json:"name"`
	LineNr int    `json:"lineNr"`
}

UsingNamespaceModel represents the use of namespace.

type VariableModel

type VariableModel struct {
	Name string `json:"name"`
	Type string `json:"type"`
}

VariableModel represents a variable from code.

Jump to

Keyboard shortcuts

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