(component ComponentDefinition, NameSpace string, ClassIdentifier string, BaseName string, outputFolder string, indentString string, stubIdentifier string, forceRecreation bool, defaultImplementation []string)
| 1301 | } |
| 1302 | |
| 1303 | func buildPascalStub(component ComponentDefinition, NameSpace string, ClassIdentifier string, BaseName string, outputFolder string, indentString string, stubIdentifier string, forceRecreation bool, defaultImplementation []string) error { |
| 1304 | |
| 1305 | pascalBaseClassName := "T" + ClassIdentifier + NameSpace + component.baseClass().ClassName |
| 1306 | |
| 1307 | var baseClassMethods [5]ComponentDefinitionMethod |
| 1308 | baseClassMethods[0] = GetLastErrorMessageMethod() |
| 1309 | baseClassMethods[1] = ClearErrorMessageMethod() |
| 1310 | baseClassMethods[2] = RegisterErrorMessageMethod() |
| 1311 | baseClassMethods[3] = IncRefCountMethod() |
| 1312 | baseClassMethods[4] = DecRefCountMethod() |
| 1313 | |
| 1314 | var baseClassMethodImplementation [5][]string |
| 1315 | baseClassMethodImplementation[0] = append(baseClassMethodImplementation[0], "result := (FMessages.Count>0);") |
| 1316 | baseClassMethodImplementation[0] = append(baseClassMethodImplementation[0], "if (result) then") |
| 1317 | baseClassMethodImplementation[0] = append(baseClassMethodImplementation[0], " AErrorMessage := FMessages[FMessages.Count-1];") |
| 1318 | baseClassMethodImplementation[1] = append(baseClassMethodImplementation[1], "FMessages.Clear();") |
| 1319 | baseClassMethodImplementation[2] = append(baseClassMethodImplementation[2], "FMessages.Add(AErrorMessage);") |
| 1320 | |
| 1321 | baseClassMethodImplementation[3] = append(baseClassMethodImplementation[3], "inc(FReferenceCount);") |
| 1322 | |
| 1323 | baseClassMethodImplementation[4] = append(baseClassMethodImplementation[4], "dec(FReferenceCount);") |
| 1324 | baseClassMethodImplementation[4] = append(baseClassMethodImplementation[4], "if (FReferenceCount = 0) then begin") |
| 1325 | baseClassMethodImplementation[4] = append(baseClassMethodImplementation[4], " self.Destroy();") |
| 1326 | baseClassMethodImplementation[4] = append(baseClassMethodImplementation[4], " result := true;") |
| 1327 | baseClassMethodImplementation[4] = append(baseClassMethodImplementation[4], "end") |
| 1328 | baseClassMethodImplementation[4] = append(baseClassMethodImplementation[4], "else") |
| 1329 | baseClassMethodImplementation[4] = append(baseClassMethodImplementation[4], " result := false;") |
| 1330 | |
| 1331 | for i := 0; i < len(component.Classes); i++ { |
| 1332 | class := component.Classes[i] |
| 1333 | outClassName := "T" + ClassIdentifier + NameSpace + class.ClassName |
| 1334 | |
| 1335 | outparentClassName := "" |
| 1336 | |
| 1337 | if class.ParentClass != "" { |
| 1338 | outparentClassName = "T" + ClassIdentifier + NameSpace + class.ParentClass |
| 1339 | } else { |
| 1340 | outparentClassName = pascalBaseClassName |
| 1341 | } |
| 1342 | |
| 1343 | StubFileName := path.Join(outputFolder, BaseName+stubIdentifier+"_"+strings.ToLower(class.ClassName)+".pas") |
| 1344 | if !forceRecreation && (FileExists(StubFileName)) { |
| 1345 | log.Printf("Omitting recreation of Stub implementation for \"%s\"", outClassName) |
| 1346 | continue |
| 1347 | } |
| 1348 | |
| 1349 | log.Printf("Creating \"%s\"", StubFileName) |
| 1350 | w, err := CreateLanguageFile(StubFileName, indentString) |
| 1351 | if err != nil { |
| 1352 | return err |
| 1353 | } |
| 1354 | w.WritePascalLicenseHeader(component, |
| 1355 | fmt.Sprintf("This is the class declaration of %s", outClassName), |
| 1356 | false) |
| 1357 | |
| 1358 | w.Writeln("{$MODE DELPHI}") |
| 1359 | w.Writeln("unit %s%s_%s;", BaseName, stubIdentifier, strings.ToLower(class.ClassName)) |
| 1360 | w.Writeln("") |
no test coverage detected