Exemple #1
0
func isValidObject(obj types.Object, ident *ast.Ident, ctx *getDefinitionsContext) bool {
	if obj == nil {
		return false
	}
	position := ctx.fset.Position(ident.Pos())
	typeOf := reflect.TypeOf(obj)
	fullName := getFullName(obj, ctx, false)
	if !position.IsValid() {
		util.Warn("position object is invalid for %s", ident.Name)
		return false
	}
	if len(fullName) == 0 {
		util.Warn("warning: cann't get full name for %s: %v", ident.Name, typeOf)
		return false
	}
	if typeOf == nil {
		return false
	}
	if ctx.defs[fullName] != nil {
		return false
	}
	return true
}
Exemple #2
0
//Fill usages inside all definitions. The special case is functions
//where all params should be processed.
func processUses(info *types.Info, ctx *getDefinitionsContext) {
	for ident, obj := range info.Uses {
		useName := getFullName(obj, ctx, false)
		if ctx.defs[useName] != nil {
			ctx.defs[useName].addUsage(ctx.fset.Position(ident.Pos()))
		} else {
			util.Warn("can't find usage for [%s] %s\n\tObject definition - %s", useName, posToStr(ctx.fset, ident.Pos()), posToStr(ctx.fset, obj.Pos()))
		}
		switch obj.Type().(type) {
		case *types.Signature:
			s := obj.Type().(*types.Signature)
			if tuple := s.Params(); tuple != nil {
				for i := 0; i < tuple.Len(); i++ {
					v := tuple.At(i)
					useName := getFullName(v, ctx, true)
					if ctx.defs[useName] != nil {
						ctx.defs[useName].addUsage(ctx.fset.Position(ident.Pos()))
					}
				}
			}
		}
	}
}
Exemple #3
0
func (*CollectInfoImporter) errorHandler(err error) {
	util.Warn("error while checking source: %v", err)
}