B4J Library [BANanoCodeHandler] A B4X Source Code Handling Class

Hi there

In case anyone needs something similar. I am using this to maintain my BANano Custom Views and whilst its BANano related code, it is just b4x code after-all and can be adopted for any scenario.

Use For

1. Format b4x source code (beautify)
2. Insert #Event declarations
3. Insert #DesignerProperty
4. Insert Code on any Subroutine e.g. Class_Globals / Initialize
5. Code Stock taking
6. Insert Code between [If Props <> Null Then] and [End If] in DesignerCreateView
7. Insert code after [End If] in DesignerCreateView
8. DesignerProperty returned as a Map
etc
etc

Example Usage - SourceCode is the contents of your source code e.g. bas file.

B4X:
Dim sch As BANanoCodeHandler
ch.Initialize
BANano.Await(ch.ScanWait(sourceCode))
BANano.Await(ch.BeautifyWait)
return ch.Transactions

log(sch.Properties)
log(sch.Signatures)
log(sch.Events)
log(sch.ClassGlobalsCode)
log(sch.InitializeCode)
log(sch.CreateViewCode)
log(sch.DesignerKeys)
log(sch.Comments)
log(sch.Lines)
 

Attachments

  • BANanoCodeHandler.bas
    64.6 KB · Views: 85

Mashiane

Expert
Licensed User
Longtime User
BANanoCodeHandler
  • RefreshWait As Boolean
    prepare the file for saving
  • InsertLines (newLines As List)
    insert lines, does not refresh
  • ReplaceLine (pos As Int, newLine As String)
    replace a line, does not refresh
  • DeleteLines (startPos As Int, numLines As Int)
    delete lines, does not refresh
  • AddFromString (strValue As String)
    add content from a string
  • ScanWait (sourceCode As String) As Boolean
    scan the source code
  • GetLinesWait As List
    see if we can get the lines
  • HasCreateViewWait (sFind As String) As Boolean
    determine if the create view code has some code line
  • HasPropertyWait (sFind As String) As Boolean
    determine if the properties code has some code line
  • HasClassGlobalsWait (sFind As String) As Boolean
    determine if the class globals code has some code line
  • HasSignatureWait (sStuff As String) As Boolean
    Has a signature
  • HasEventWait (sStuff As String) As Boolean
    Has an event
  • HasSubRoutineWait (sSubName As String) As Boolean
    has a subroutine
  • GetSubRoutineWait (sSubName As String) As Map
    returns a map with code and signature items
  • GetSubRoutineCodeWait (sSubName As String) As List
    return code of a particular subroutine
  • ScanSubRoutineWait (startPos As Int) As List
    scan a subroutine code from this position
  • ScanCodeEndingWait (startPos As Int, endsWith1 As String) As Long
    scan code starting at pos and ending a pos
  • CStr (o As Object) As String
    convert object to string
  • GetKeyFromDesignerCodeWait (scode As String) As String
    keys from designer properties
  • ParseDesignerKeyCodeWait (sCode As String) As Map
    parse designer properties
  • HasDesignerKeyWait (propKey As String) As Boolean
    has a designer key
  • Space1 (HM As Int) As String
    Description: Return Space made of number of
    Tags: space
  • IsBlockStart (strLine As String) As Boolean
    is block start
  • InStr2 (iStart As Int, Text As String, sFind As String) As Int
    instr
  • Replace1 (Text As String, sFind As String, sReplaceWith As String) As String
    Description: Replace a string within a string
    Tags: Replace function, string
  • UCase1 (Text As String) As String
    Description: Return a string in uppercase
    Tags: upper case, ucase
  • IsBlockEnd (strLine As String) As Boolean
    is block end
  • RemoveSubRoutinesWait (SubsToRemove As List) As Boolean
    remove these sub routines
  • CommentSubRoutineWait (SubName As String) As Boolean
    comment this sub routines
  • RemoveSubRoutineWait (SubName As String) As Boolean
    comment this sub routines
  • AddClassGlobalsWait (sLine As String) As Boolean
    add line to class globals
  • AddInitializeWait (sLine As String) As Boolean
    add a line to initialize
  • RemoveCommentsWait As Boolean
    remove comments and wait
  • BuildPropertyWithList (m As Map) As String
    build a property from a map
  • parseNull (v As Object) As String
    parse null
  • GetSubroutesWait (exclude As List) As Map
    get the contents of these sub-routes for use later
  • AddCommentsWait (kvs As Map) As Boolean
    add comment on line containing text
  • AddDesignerPropertyAwait (propLine As String, atTop As Boolean) As Boolean
    add a designer property line to the file
  • AddSubRoutineLineAfterWait (subName As String, codeToFind As String, sLine As String) As Boolean
    add a line of code after a subroutine name, after line
  • RemoveExactLinesWait (delLines As List) As Boolean
    remove exact lines
  • ReplaceExactLinesWait (findLine As String, putLine As String) As Boolean
    replace exact lines
  • CommentExactLineWait (findLine As String) As Boolean
    comment a line
  • AddSubroutesWait (SubRoutinesM As Map) As Boolean
    add subroutines copied using subroutine name & code
  • AddSubrouteWait (subName As String, subCode As String) As Boolean
    add a single sub routine with code
  • CodeLineCommentAt (pos As Int)
    comment a line at position
  • CodeLineUnCommentAt (pos As Int)
    uncomment a code line
  • MidS (Text As String, iStart As Int) As String
    mid
  • CodeLineFindWait (sLine As String) As Int
    find a code line
  • CodeLineFindStartAtWait (startPos As Int, sLine As String) As Int
    find a code line
  • CodeLineFindStartAtStartWithWait (startPos As Int, wordSearch As String) As Int
    find a code line
  • ListHasMatchWait (lst As List, wordSearch As String) As Int
    do a lowercase match
  • ListHasMatchStartAtWait (lst As List, startPos As Int, wordSearch As String) As Int
    do a lowercase match
  • GetCodeBetweenLinesWait (lst As List, startPos As Int, endPos As Int) As List
    get lines between positions
  • AddDesignerCreateViewAfterWait (sLine As String, sAfter As String) As Boolean
    add this text after on condition that the next line contents are not what we are adding
  • AddCodeAfterWait (codeToFind As String, codeToAdd As String) As Boolean
    add this text after on condition that the next line contents are not what we are adding
  • BuildBindingInit (nvarName As String, varType As String) As signment
    build the binding name to be used for this
    pass it the variable name and the type of binding e.g show, disabled
  • Code_Clear
    code writer
  • Code_Add (s As String)
    code writer
  • Code_Comment (s As String)
    code writer
  • Code_ToString As String
    code writer
 
Top