[Gambas-user] Gambas 3 IDE features request

Benoît Minisini gambas at ...1...
Sat Dec 18 15:55:36 CET 2010


> 2010/12/17 Fabián Flores Vadell <fabianfloresvadell at ...626...>:
> > Hi. There are two features I beleave could be fine in Gambas 3 IDE:
> > 
> > 1. Add an option named "create getters and setters" (or similar) to
> > the context menu in the code editor, so the IDE can take care of this
> > boring work. A simple comment can define attributes than will have
> > accessor and modifiers, like that:
> > 
> > 'cgs is for create getter and setter
> > PRIVATE Name AS String 'cgs
> 
> I think that a method like this could do the job (I eliminated the "c"
> for "create"):
> 
> Public Function makeGettersANDSetters(code As String) As String
>   Dim acode As String[]
>   Dim linecode, attribName, setter, getter, gettersAndsetters As String
>   Dim set, get As Boolean
>   Dim posPrivate, posComment, posAttribName 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)
>           attribName = UCase(Left(attribName)) &
> LCase(Right(attribName, Len(attribName) - 1))
>         Endif
> 
>         If set Then
>           setter = "\n\n" & "PUBLIC SUB set" & attribName & "(Value AS
> type)" & "\n\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\n" & "END"
>           gettersAndsetters &= getter
>           getter = ""
>           get = False
>         Endif
>         attribName = ""
> 
>       Endif
> 
>     Endif
> 
>   Next
> 
>   Return gettersAndsetters
> 
> End

I think that already exists: it's named "Property". :-)

-- 
Benoît Minisini




More information about the User mailing list