2010/12/17 Fabián Flores Vadell <fabianfloresvad...@gmail.com>:
> 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


-- 
Fabián Flores Vadell
www.comoprogramarcongambas.blogspot.com
www.speedbooksargentina.blogspot.com

------------------------------------------------------------------------------
Lotusphere 2011
Register now for Lotusphere 2011 and learn how
to connect the dots, take your collaborative environment
to the next level, and enter the era of Social Business.
http://p.sf.net/sfu/lotusphere-d2d
_______________________________________________
Gambas-user mailing list
Gambas-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/gambas-user

Reply via email to