Golang butler-null.GetString类(方法)实例源码

下面列出了Golang butler-null.GetString 类(方法)源码代码实例,从而了解它的用法。

作者:nmakiy    项目:tritiu   
func (pkg *Package) resolveHeader(function *tp.Function) {
	returnType := null.GetString(function.ReturnType)
	if len(returnType) > 0 {
		function.ReturnTypeId = proto.Int32(int32(pkg.findTypeIndex(returnType)))
		function.ReturnType = nil
	}

	scopeType := null.GetString(function.ScopeType)
	if len(scopeType) > 0 {
		function.ScopeTypeId = proto.Int32(int32(pkg.findTypeIndex(scopeType)))
		function.ScopeType = nil
	}

	opensType := null.GetString(function.OpensType)
	if len(opensType) > 0 {
		function.OpensTypeId = proto.Int32(int32(pkg.findTypeIndex(opensType)))
		function.OpensType = nil
	}

	for _, arg := range function.Args {
		typeName := null.GetString(arg.TypeString)
		if len(typeName) > 0 {
			arg.TypeId = proto.Int32(int32(pkg.findTypeIndex(typeName)))
			arg.TypeString = nil
		}
	}
}

作者:nmakiy    项目:tritiu   
func (m *Mixer) Write(path string) (outputPath string, err error) {

	name := null.GetString(m.Name)
	version := null.GetString(m.Version)
	outputPath = filepath.Join(path, name+"-"+version+".mxr")

	bytes, err := pb.Marshal(m)
	if err != nil {
		return
	}

	bytes = crypto.Encrypt(bytes)

	err = os.MkdirAll(path, fileutil.DIR_PERMS)
	if err != nil {
		return
	}

	err = ioutil.WriteFile(outputPath, bytes, fileutil.FILE_PERMS)
	if err != nil {
		return
	}

	return
}

作者:nmakiy    项目:tritiu   
func (pkg *Package) Merge(otherPackage *tp.Package) {

	if otherPackage == nil {
		return
	}

	//// Reflection would make this code cleaner:

	var existingTypeId int

	for _, someType := range otherPackage.Types {
		existingTypeId = pkg.GetTypeId(null.GetString(someType.Name))
		if existingTypeId == -1 {
			pkg.Types = append(pkg.Types, someType)
		}
	}

	for _, function := range otherPackage.Functions {

		if null.GetBool(function.BuiltIn) {
			pkg.resolveHeader(function)
		} else {
			resolveDefinition(pkg.Package, function, "")
		}
		pkg.Package.Functions = append(pkg.Package.Functions, function)
	}

	for _, dependency := range otherPackage.Dependencies {
		pkg.Dependencies = append(pkg.Dependencies, dependency)
	}

	otherName := null.GetString(otherPackage.Name)
	pkg.Dependencies = append(pkg.Dependencies, otherName)
	pkg.Log.Infof("Added dependency (" + otherName + ") to " + null.GetString(pkg.Name) + "'s loaded dependencies")
}

作者:nmakiy    项目:tritiu   
func ancestralFuncStub(pkg *tp.Package, fun *tp.Function) *string {
	foundAncestor := false

	name := null.GetString(fun.Name)
	args := ""
	for _, arg := range fun.Args {
		argType := null.GetInt32(arg.TypeId)
		ancestralArgType := FindAncestralType(pkg, argType)

		if ancestralArgType != -1 {
			foundAncestor = true
			argType = ancestralArgType
		}

		argTypeString := pkg.GetTypeName(argType)

		argName := argTypeString
		argName = argName + " %" + null.GetString(arg.Name)
		args = args + ", " + argName
	}
	if len(args) > 1 {
		args = args[2:]
	}

	returnType := null.GetInt32(fun.ReturnTypeId)
	ancestralReturnType := FindAncestralType(pkg, returnType)

	if ancestralReturnType != -1 {
		foundAncestor = true
		returnType = ancestralReturnType
	}

	returnTypeString := pkg.GetTypeName(returnType)
	returnVal := name + "(" + args + ") " + returnTypeString + " "

	opensType := null.GetInt32(fun.OpensTypeId)
	ancestralOpensType := FindAncestralType(pkg, opensType)

	if ancestralOpensType != -1 {
		foundAncestor = true
		opensType = ancestralOpensType
	}

	opensTypeString := pkg.GetTypeName(opensType)

	if opensTypeString != "Base" {
		returnVal = returnVal + opensTypeString
	}

	if foundAncestor {
		return &returnVal
	}
	return nil

}

作者:nmakiy    项目:tritiu   
func BuildMixer(buildPath string, name string, dataPath string) *Mixer {
	rawPath, err := findInBuildPath(buildPath, name)

	if err != nil {
		panic(err.Error())
	}

	path := *rawPath

	raw_mixer := tp.NewMixer(filepath.Clean(path))
	mixer := &Mixer{
		Mixer:          raw_mixer,
		LibraryPath:    buildPath,
		DefinitionPath: path,
		DataPath:       dataPath,
	}
	// println("func BuildMixer")
	// println("build path:", buildPath)
	// println("definition path:", path)
	// println()

	rewritersDirectory := filepath.Join(path, "/rewriters")
	mixer.Rewriters = tp.CollectFiles(rewritersDirectory)

	packageDirectory := filepath.Join(path, "/package")
	mixer.RootPackage = NewRootPackage(packageDirectory, null.GetString(mixer.Name), dataPath)

	mixer.loadDependentMixers()

	error := BuildRootPackage(mixer.RootPackage, packageDirectory, null.GetString(mixer.Name))

	if error == nil {
		//mixer.RootPackage = pkg
		// Now that we're done resolving, slice off the members! (Ouch)
		mixer.Package = mixer.RootPackage.Package

	} else if error.Code != NOT_FOUND {
		//TODO : Put this into a debug log
		panic(error.Message)
	}

	versionFile := filepath.Join(mixer.DefinitionPath, "..", "..", "JENKINS")
	buildNumber, err := ioutil.ReadFile(versionFile)

	if err == nil {
		mixer.Version = proto.String(null.GetString(mixer.Version) + "." + strings.Trim(string(buildNumber), "\n\r "))
	}

	return mixer
}

作者:nmakiy    项目:tritiu   
func (result *CheckResult) CheckForLocationExport(script *tp.ScriptObject) {
	iterate(script, func(ins *tp.Instruction) {
		if *ins.Type == constants.Instruction_FUNCTION_CALL {
			name := null.GetString(ins.Value)
			if name == "export" {
				if ins.Arguments != nil {
					if null.GetString(ins.Arguments[0].Value) == "location" {
						result.AddScriptWarning(script, ins, "Incorrect export of location! Use \"Location\" not \"location\"")
					}
				}
			}
		}
	})
}

作者:nmakiy    项目:tritiu   
func ShortFuncStub(pkg *tp.Package, fun *tp.Function) string {
	name := null.GetString(fun.Name)
	args := ""
	for _, arg := range fun.Args {
		t := pkg.Types[int(null.GetInt32(arg.TypeId))]
		argName := null.GetString(t.Name)
		argName = argName
		args = args + ", " + argName
	}
	if len(args) > 1 {
		args = args[2:]
	}
	returnVal := name + "(" + args + ")"
	return returnVal
}

作者:nmakiy    项目:tritiu   
func (f *Function) BaseSignature(pkg2 protoface.Package) string {
	pkg := pkg2.(*Package)
	args := "("
	for i, arg := range f.Args {
		argName := null.GetString(arg.TypeString)
		if argName == "" {
			t := pkg.Types[int(null.GetInt32(arg.TypeId))]
			argName = null.GetString(t.Name)
		}
		if i != 0 {
			args += ","
		}
		args += argName
	}
	return fmt.Sprintf("%s.%s%s)", pkg.GetTypeName(f.GetScopeTypeId()), f.GetName(), args)
}

作者:nmakiy    项目:tritiu   
func (pkg *Package) GetTypeId(name string) int {
	for id, typ := range pkg.Types {
		if null.GetString(typ.Name) == name {
			return id
		}
	}
	return -1
}

作者:nmakiy    项目:tritiu   
func (f *Function) Stub(pkg2 protoface.Package) string {
	pkg := pkg2.(*Package)
	ns := f.GetNamespace()
	if len(ns) == 0 {
		ns = "tritium"
	}
	fname := fmt.Sprintf("%s.%s", ns, f.GetName())
	args := ""
	for _, arg := range f.Args {
		argName := null.GetString(arg.TypeString)
		if argName == "" {
			t := pkg.Types[int(null.GetInt32(arg.TypeId))]
			argName = null.GetString(t.Name)
		}
		args = args + "," + argName
	}
	return fname + args
}

作者:nmakiy    项目:tritiu   
func (result *CheckResult) CheckForSelectText(script *tp.ScriptObject) {
	tester := MustCompile("([^\\[\\(^]|^)(text|comment)\\(\\)([^=]|$)")
	iterate(script, func(ins *tp.Instruction) {
		if *ins.Type == constants.Instruction_FUNCTION_CALL {
			name := null.GetString(ins.Value)
			if name == "$" || name == "select" || name == "move_here" || name == "move_to" || name == "move" {

				for _, arg := range ins.Arguments {
					xpath := null.GetString(arg.Value)
					if tester.Match([]byte(xpath)) {
						result.AddScriptWarning(script, ins, "Shouldn't use comment()/text() in '"+xpath+"'")
					}
				}
			}
		}

	})
}

作者:nmakiy    项目:tritiu   
func (m *Mixer) Inspect(printFunctions bool) {
	println("\tRewriters:")
	for _, rewriter := range m.Rewriters {
		fmt.Printf("\t\t -- %v\n", null.GetString(rewriter.Path))
	}

	println("\tRoot Package:")
	fmt.Printf(m.packageSummary(printFunctions))
}

作者:nmakiy    项目:tritiu   
func (m *Mixer) Merge(otherMixer *Mixer) {
	// TODO(SJ) : Make sure there are no name collision in the following unions
	if len(otherMixer.Rewriters) > 0 {

		if len(m.Rewriters) > 0 {
			thisName := null.GetString(m.Name)
			otherName := null.GetString(otherMixer.Name)
			panic(fmt.Sprintf("Duplicate sets of rewriters. Mixer (%v) and mixer (%v) both define rewriters.", thisName, otherName))
		}

		m.Rewriters = otherMixer.Rewriters
	}

	// Merge only exists on (tritium) packager.Package
	m.RootPackage.Merge(otherMixer.Package)

	//	m.RootPackage.Dependencies = append(m.RootPackage.Dependencies, null.GetString(otherMixer.Name) )

}

作者:nmakiy    项目:tritiu   
func FuncStub(pkg *tp.Package, fun *tp.Function) string {
	name := null.GetString(fun.Name)
	args := ""
	for _, arg := range fun.Args {
		t := pkg.Types[int(null.GetInt32(arg.TypeId))]
		argName := null.GetString(t.Name)
		argName = argName + " %" + null.GetString(arg.Name)
		args = args + ", " + argName
	}
	if len(args) > 1 {
		args = args[2:]
	}
	returnVal := name + "(" + args + ") " + fun.ReturnTypeString(pkg) + " "
	opens := fun.OpensTypeString(pkg)
	if opens != "Base" {
		returnVal = returnVal + opens
	}
	return returnVal
}

作者:nmakiy    项目:tritiu   
func (pkg *Package) findTypeIndex(name string) int {
	for index, typeObj := range pkg.Types {
		if name == null.GetString(typeObj.Name) {
			return index
		}
	}

	log.Panic("Bad type load order, type ", name, " unknown")
	return -1
}

作者:nmakiy    项目:tritiu   
func getRawTemplate(segmentName string, mixer *tp.Mixer) (rawTemplate []uint8, err error) {

	for _, segment := range mixer.Rewriters {
		_, thisName := filepath.Split(null.GetString(segment.Path))
		if thisName == segmentName {
			return segment.Data, nil
		}
	}

	return nil, errors.New(fmt.Sprintf("Could not find rewriter: %v", segmentName))
}

作者:nmakiy    项目:tritiu   
func (result *CheckResult) CheckForNotMisuse(script *tp.ScriptObject) {
	iterate(script, func(ins *tp.Instruction) {
		if *ins.Type == constants.Instruction_FUNCTION_CALL {
			name := null.GetString(ins.Value)
			if name == "match" || name == "with" {
				if ins.Arguments != nil {
					for _, arg := range ins.Arguments {
						if *arg.Type == constants.Instruction_FUNCTION_CALL {
							if null.GetString(arg.Value) == "not" {
								result.AddScriptWarning(script, ins, "Possible misuse of not()– remember not is the opposite of with!")
							}
						}
					}
				}

			}
		}

	})
}

作者:nmakiy    项目:tritiu   
func (fun *Function) Clone() protoface.Function {
	bytes, err := pb.Marshal(fun)

	if err != nil {
		panic("Couldn't clone function" + null.GetString(fun.Name))
	}

	newFun := &Function{}
	pb.Unmarshal(bytes, newFun)

	return newFun
}

作者:nmakiy    项目:tritiu   
func Process(pkg *tp.Package) string {
	for tindex, ttype := range pkg.Types {
		ttypeString := null.GetString(ttype.Name)
		println()
		for _, fun := range pkg.Functions {
			if tindex == int(null.GetInt32(fun.ScopeTypeId)) {
				println(ttypeString + "." + FuncStub(pkg, fun))
			}
		}
	}
	return ""
}

作者:nmakiy    项目:tritiu   
func (result *CheckResult) CheckXpath(script *tp.ScriptObject) {
	iterate(script, func(ins *tp.Instruction) {
		if *ins.Type == constants.Instruction_FUNCTION_CALL {
			name := null.GetString(ins.Value)
			// These all take xpath as the first param
			for _, xpath_func := range xpath_funcs {
				if name == xpath_func {
					if ins.Arguments != nil {
						if len(ins.Arguments) > 0 {
							test_xpath := null.GetString(ins.Arguments[0].Value)
							err := xpath.Check(test_xpath)
							if err != nil {
								result.AddXpathWarning(script, ins, err.Error())
							}
						}
					}
				}
			}
		}
	})
}


问题


面经


文章

微信
公众号

扫码关注公众号