本文整理汇总了Golang中github.com/gordonklaus/flux/go/types.Object类的典型用法代码示例。如果您正苦于以下问题:Golang Object类的具体用法?Golang Object怎么用?Golang Object使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Object类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: qualifiedName
func (w writer) qualifiedName(obj types.Object) string {
n := obj.GetName()
if p, ok := w.pkgNames[obj.GetPkg()]; ok {
return p + "." + n
}
return n
}
示例2: newValueNode
func newValueNode(obj types.Object, currentPkg *types.Package, set bool) *valueNode {
n := &valueNode{obj: obj, set: set}
n.nodeBase = newNodeBase(n)
dot := ""
switch obj.(type) {
case field, *types.Func, nil:
if _, ok := obj.(*types.Func); !ok || isMethod(obj) {
n.x = n.newInput(nil)
if obj == nil {
n.x.connsChanged = n.connsChanged
}
dot = "."
}
}
if obj != nil {
if p := obj.GetPkg(); p != currentPkg && p != nil && dot == "" {
n.pkg.setPkg(p)
}
n.text.SetText(dot + obj.GetName())
}
n.text.SetTextColor(color(&types.Var{}, true, false))
if set {
n.y = n.newInput(nil)
} else {
n.y = n.newOutput(nil)
}
n.addSeqPorts()
n.connsChanged()
return n
}
示例3: objLess
func objLess(o1, o2 types.Object) bool {
n1, n2 := o1.GetName(), o2.GetName()
switch o1.(type) {
case special:
switch o2.(type) {
case special:
return n1 < n2
default:
return true
}
case *types.TypeName:
switch o2.(type) {
case special:
return false
case *types.TypeName:
return n1 < n2
default:
return true
}
case *types.Func, *types.Builtin:
switch o2.(type) {
case special, *types.TypeName:
return false
case *types.Func, *types.Builtin:
return n1 < n2
default:
return true
}
case *types.Var, field:
switch o2.(type) {
default:
return false
case *types.Var, field:
return n1 < n2
case *types.Const, *pkgObject:
return true
}
case *types.Const:
switch o2.(type) {
default:
return false
case *types.Const:
return n1 < n2
case *pkgObject:
return true
}
case *pkgObject:
switch o2.(type) {
default:
return false
case *pkgObject:
return n1 < n2
}
}
panic("unreachable")
}
示例4: isCompositeType
func isCompositeType(obj types.Object) bool {
switch obj {
case protoArray, protoSlice, protoMap, protoStruct:
return true
}
if obj, ok := obj.(*types.TypeName); ok {
switch underlying(obj.GetType()).(type) {
case *types.Array, *types.Slice, *types.Map, *types.Struct:
return true
}
}
return false
}
示例5: isMakeableType
func isMakeableType(obj types.Object) bool {
switch obj {
case protoSlice, protoMap, protoChan:
return true
}
if obj, ok := obj.(*types.TypeName); ok {
switch underlying(obj.GetType()).(type) {
case *types.Slice, *types.Map, *types.Chan:
return true
}
}
return false
}
示例6: setObjectName
func setObjectName(obj types.Object, name string) {
switch obj := obj.(type) {
case *pkgObject:
obj.name = name
case *types.TypeName:
obj.Name = name
case *types.Func:
obj.Name = name
case *types.Var:
obj.Name = name
case *types.Const:
obj.Name = name
}
}
示例7: loadFunc
func loadFunc(obj types.Object) *funcNode {
f := newFuncNode(obj, nil)
fset := token.NewFileSet()
file, err := parser.ParseFile(fset, fluxPath(obj), nil, parser.ParseComments)
if err == nil {
r := &reader{fset, obj.GetPkg(), types.NewScope(obj.GetPkg().Scope()), map[string]*port{}, map[string][]*connection{}, ast.NewCommentMap(fset, file, file.Comments), map[int]node{}}
for _, i := range file.Imports {
path, _ := strconv.Unquote(i.Path.Value)
pkg, err := getPackage(path)
if err != nil {
fmt.Printf("error importing %s: %s\n", i.Path.Value, err)
continue
}
name := pkg.Name
if i.Name != nil {
name = i.Name.Name
}
r.scope.Insert(types.NewPkgName(0, pkg, name))
}
decl := file.Decls[len(file.Decls)-1].(*ast.FuncDecl) // get param and result var names from the source, as the obj names might not match
if decl.Recv != nil {
r.out(decl.Recv.List[0].Names[0], f.inputsNode.newOutput(obj.GetType().(*types.Signature).Recv))
}
r.fun(f, decl.Type, decl.Body)
} else {
// this is a new func; save it
if isMethod(obj) {
f.inputsNode.newOutput(obj.GetType().(*types.Signature).Recv)
}
saveFunc(f)
}
return f
}
示例8: newOperatorNode
func newOperatorNode(obj types.Object) *operatorNode {
n := &operatorNode{op: obj.GetName()}
n.nodeBase = newNodeBase(n)
n.text.SetText(n.op)
n.text.SetTextColor(color(&types.Func{}, true, false))
n.newInput(nil).connsChanged = n.connsChanged
if n.op != "!" {
n.newInput(nil).connsChanged = n.connsChanged
}
n.newOutput(nil)
n.connsChanged()
return n
}
示例9: newWriter
func newWriter(obj types.Object) *writer {
src, err := os.Create(fluxPath(obj))
if err != nil {
fmt.Printf("error creating %s: %s\n", fluxPath(obj), err)
return nil
}
w := &writer{src, obj.GetPkg(), map[*types.Package]string{}, map[string]int{}, 0, map[node]int{}, 0}
fluxObjs[obj] = true
w.write("// Generated by Flux, not meant for human consumption. Editing may make it unreadable by Flux.\n\n")
w.write("package %s\n\n", w.pkg.Name)
for _, name := range append(types.Universe.Names(), w.pkg.Scope().Names()...) {
w.name(name)
}
return w
}
示例10: unknown
func unknown(obj types.Object) bool {
switch obj := obj.(type) {
case field:
fm, _, _ := types.LookupFieldOrMethod(obj.recv, obj.Pkg, obj.Name)
_, ok := fm.(*types.Var)
return !ok
case *types.Func:
if sig, ok := obj.Type.(*types.Signature); ok && sig.Recv != nil {
fm, _, _ := types.LookupFieldOrMethod(sig.Recv.Type, obj.Pkg, obj.Name)
_, ok := fm.(*types.Func)
return !ok
}
}
pkg := obj.GetPkg()
return pkg != nil && pkg.Scope().Lookup(obj.GetName()) == nil
}
示例11: isGoDeferrable
func isGoDeferrable(obj types.Object) bool {
switch obj := obj.(type) {
case special:
return obj.Name == "call"
case *types.Builtin:
switch obj.Name {
case "close", "copy", "delete", "panic", "recover":
return true
}
case *types.Func:
return !isOperator(obj)
case *types.TypeName:
_, ok := obj.GetType().(*types.Named)
return ok
}
return false
}
示例12: color
func color(obj types.Object, bright, funcAsVal bool) Color {
alpha := .7
if bright {
alpha = 1
}
switch obj.(type) {
case special:
return Color{1, 1, .6, alpha}
case *pkgObject:
return Color{1, 1, 1, alpha}
case *types.TypeName:
return Color{.6, 1, .6, alpha}
case *types.Func, *types.Builtin:
if funcAsVal && obj.GetPkg() != nil { //Pkg==nil == builtin
return color(&types.Var{}, bright, funcAsVal)
}
return Color{1, .6, .6, alpha}
case *types.Var, *types.Const, field:
return Color{.6, .6, 1, alpha}
}
panic(fmt.Sprintf("unknown object type %T", obj))
}
示例13: fluxPath
func fluxPath(obj types.Object) string {
pkg, err := build.Import(obj.GetPkg().Path, "", build.FindOnly)
if err != nil {
fmt.Println("error importing \"%s\": %s\n", obj.GetPkg().Path, err)
return ""
}
name := obj.GetName()
if !obj.IsExported() { // unexported names are suffixed with "-" to avoid possible conflicts on case-insensitive systems
name += "-"
}
if isMethod(obj) {
t, _ := indirect(obj.GetType().(*types.Signature).Recv.Type)
recv := t.(*types.Named).Obj
typeName := recv.Name
if !recv.IsExported() {
typeName += "-"
}
name = typeName + "." + name
}
return filepath.Join(pkg.Dir, name+".flux.go")
}
示例14: deleteObj
func deleteObj(obj types.Object) bool {
if p, ok := obj.(*pkgObject); ok {
if p, err := getPackage(p.importPath); err == nil {
for _, obj := range p.Scope().Objects {
deleteObj(obj)
}
}
dir := p.fullPath()
os.Remove(filepath.Join(dir, "package.flux.go"))
os.Remove(filepath.Join(dir, ".DS_Store"))
if files, err := ioutil.ReadDir(dir); err != nil || len(files) > 0 || trash.Trash(dir) != nil {
return false
}
delete(pkgObjects, p.importPath)
delete(pkgs, p.importPath)
return true
}
if !fluxObjs[obj] {
return false
}
if t, ok := obj.(*types.TypeName); ok {
t := t.Type.(*types.Named)
for _, m := range t.Methods {
deleteObj(m)
}
if len(t.Methods) > 0 {
return false
}
}
if trash.Trash(fluxPath(obj)) != nil {
return false
}
if objs := obj.GetPkg().Scope().Objects; objs[obj.GetName()] == obj {
delete(objs, obj.GetName())
} else {
t, _ := indirect(obj.(*types.Func).Type.(*types.Signature).Recv.Type)
n := t.(*types.Named)
for i, f2 := range n.Methods {
if f2 == obj {
n.Methods = append(n.Methods[:i], n.Methods[i+1:]...)
break
}
}
}
delete(fluxObjs, obj)
return true
}
示例15: newNode
func (b *block) newNode(obj types.Object, funcAsVal bool, godefer string) node {
var n node
currentPkg := b.func_().pkg()
switch obj := obj.(type) {
case special:
switch obj.Name {
case "break", "continue", "return":
n = newBranchNode(obj.Name)
case "call":
n = newCallNode(nil, currentPkg, godefer)
case "convert":
n = newConvertNode(currentPkg)
case "func":
n = newFuncNode(nil, b.childArranged)
case "go", "defer":
godefer = obj.Name + " "
browser := newBrowser(browserOptions{objFilter: isGoDeferrable, enterTypes: true}, b)
browser.Move(Center(b))
browser.accepted = func(obj types.Object) {
browser.Close()
b.newNode(obj, false, godefer)
}
browser.canceled = func() {
browser.Close()
SetKeyFocus(b)
}
b.Add(browser)
SetKeyFocus(browser)
return nil
case "if":
i := newIfNode(b.childArranged)
i.newBlock()
n = i
case "loop":
n = newLoopNode(b.childArranged)
case "select":
n = newSelectNode(b.childArranged)
case "typeAssert":
n = newTypeAssertNode(currentPkg)
}
case *types.Func, *types.Builtin:
if obj.GetName() == "[]" {
n = newIndexNode(false)
} else if obj.GetName() == "[:]" {
n = newSliceNode()
} else if obj.GetName() == "<-" {
n = newChanNode(true)
} else if isOperator(obj) {
n = newOperatorNode(obj)
} else if funcAsVal && obj.GetPkg() != nil { //Pkg==nil == builtin
n = newValueNode(obj, currentPkg, false)
} else {
n = newCallNode(obj, currentPkg, godefer)
}
case *types.Var, *types.Const, field:
switch obj.GetName() {
default:
n = newValueNode(obj, currentPkg, false)
case "=":
n = newValueNode(nil, nil, true)
case "*":
n = newValueNode(nil, nil, false)
}
}
b.addNode(n)
MoveCenter(n, Center(b))
if nn, ok := n.(interface {
editType()
}); ok {
nn.editType()
} else {
SetKeyFocus(n)
}
return n
}