[Gambas-user] Gambas 3 IDE features request
Fabián Flores Vadell
fabianfloresvadell at ...626...
Sat Dec 18 17:05:12 CET 2010
2010/12/18 Benoît Minisini <gambas at ...1...>:
>
> I think that already exists: it's named "Property". :-)
>
> --
> Benoît Minisini
Hi Benoît. I know that property exists, but:
1) In some situations (rare I admit, but real) could be necessary
write a setter and unnecessary write a getter, but properties are
both: write and read or only read, there's no option to automatically
write only the code for property write
2) Properties, forces to have more code
3) Properties, forces to use the dot notation or to write getters and
setter by hand
4) Write and Read methods are generated while code is being write. I
would appreciate can write sketch code for a class without Write/Read
or getters/setters methods, and when I finished the class design can
generate that code automatically by one step.
5) I'm providing the code, so just a little bit effort is required from you :-)
' I had forgotten to set the data types, assignment inside setter, and
return the value inside getter. This code is more complete.
Public Function makeGettersANDSetters(code As String) As String
Dim acode As String[]
Dim linecode, attribName, setter, getter, gettersAndsetters, type,
firstChar, tailName As String
Dim set, get, $inAttribName? As Boolean
Dim posPrivate, posComment, posAttribName, posType As Integer
acode = Split(code, "\n", "", True)
For Each linecode In acode
linecode = UCase(linecode)
posPrivate = InStr(linecode, "PRIVATE")
If posPrivate <> 0 Then
posComment = InStr(linecode, "'")
If posComment <> 0 Then
set = InStr(linecode, "S", posComment + 1) > 0
get = InStr(linecode, "G", posComment + 1) > 0
posAttribName = posPrivate + Len("PRIVATE") + 1
If get Or If set Then
attribName = Mid(linecode, posAttribName, InStr(linecode, "
", posPrivate + Len("PRIVATE") + 1) - posAttribName)
firstChar = Left(attribName)
$inAttribName? = (firstChar = "$")
firstChar = If($inAttribName?, Mid(attribName, 2, 1), firstChar)
tailName = Right(attribName, Len(attribName) -
If($inAttribName?, 2, 1))
tailName = LCase(tailName)
attribName = UCase(firstChar) & tailName
posType = InStr(linecode, "AS", posAttribName +
Len(AttribName) + 1) + 2
type = Mid(linecode, posType, InStr(linecode, " ", posType +
1) - posType)
Endif
If set Then
setter = "\n\n" & "PUBLIC SUB set" & attribName & "(Value AS
" & type & ")" &
"\n\n " & If($inAttribName?, "$", "") & attribName
& " = Value" & "\n\n" & "END"
gettersAndsetters &= setter
setter = ""
set = False
Endif
If get Then
getter = "\n\n" & "PUBLIC FUNCTION get" & attribName &
"(Value AS " & type & ") AS " & Type & "\n\n" & " RETURN " &
attribName & "\n\n" & "END"
gettersAndsetters &= getter
getter = ""
get = False
Endif
attribName = ""
Endif
Endif
Next
Return gettersAndsetters
End
--
Fabián Flores Vadell
www.comoprogramarcongambas.blogspot.com
www.speedbooksargentina.blogspot.com
More information about the User
mailing list