The Script Editor[edit]

The Script Editor lets you write and execute scripts in Javascript.

With the Script Editor, you have access to the following resources of MiWorkplace.

  • document — editor content
  • selection — editor selection (selected text range of the editor instance)
  • ast — AST - abstract syntax tree of the editor content (a data model of the source)
var procedures = ast.listProcedures();

for each (var procedure in procedures) {

  print(procedure.name);

}

Editor Content[edit]

The editor content is available via the document variable. It is an instance of the Java class org.eclipse.jface.text.Document.

It provides many methods (RPG term: procedures).

  • get() — Get the whole editor content
  • get(start, length) — Get a part of the editor code
  • getLineLength(line) — Get the length of the line
  • getLineOffset(line) — Returns the offset of the line
  • getLineOfOffset(offset) — Returns the line number which the passed offset is part of
  • getNumberOfLines() — Returns the number of lines of the document
  • replace(position, length, text) — Replaces the position with passed text
  • set(text) — Replaces the content of the whole document

If you want to insert code, use the replace method and use 0 for the length.

Selection[edit]

The selection variable represents the text the user selected in the editor. The selection is a simple Point class which has two fields: x and y.

  • x — Start position of the selection
  • y — Length of the current editor selection

AST - Abstract Syntax Tree (a model of the source)[edit]

Depending on what type of source code the editor instance has loaded astrepresents different Java classes.

CL[edit]

  • listFiles() — returns a list of File objects
  • listLabels() — returns a list of labels (Token)
  • listSubroutines() — returns a list of Subroutine objects
  • listVariables() — returns a list of global variables declared in this CL program
  • listParameters() — returns a list of parameters
File[edit]

Represents a file declared in a CL with the keyword DCLF.

  • getFile() — file name
  • getLibrary() — library name (default: *LIBL)
  • getRecordFormat() — the used record format (default: *ALL)
  • getAllowNull() — value of parameter ALWNULL
  • getAllowGraphic() — value of parameter ALWGRAPHIC
  • getAllowVariableLength() — value of parameter ALWVARLEN
  • getDeclareBinaryFieldsToken() — value of parameter DCLBINFLD
  • getStatement() — returns Statement
Subroutine[edit]
  • getName() — returns the name of the subroutine
  • getStart() — returns the first token of the subroutine
  • getEnd() — returns the last token of the subroutine
  • list() — returns all Statement objects which make up this subroutine
Variable[edit]
  • getName() — returns the name of the variable
  • getType() — returns the type (Character, Integer, UnsignedInteger, Boolean, Decimal, Pointer)
  • getLength() — returns the declared length of the variable
  • getDecimalPositions() — returns the declared decimal positions of the variable
  • getStatement() — returns Statement
Parameter[edit]
  • getName() — returns the name of the parameter (withouth the leading & sign)
Statement[edit]

A statement consists of one or more tokens. A statement can be layed out on multiple lines.

  • list() — list of tokens
  • size() — number tokens in this statement
Token[edit]
  • offset — start position of this token in this line (zero-based)
  • line — line number (zero-based)
  • value — token value

Fixed Form RPG[edit]

  • getProcedures() — returns a list of Procedure objects
  • getSubroutines() — returns a list of Subroutine objects
Procedure[edit]
  • getName() — returns the name of the procedure
  • getStartLine() — returns the starting line of the procedure
  • isExported() mdash; returns true if the procedure is exported (keyword export)
Subroutine[edit]
  • getName() — returns the name of the subroutine
  • getStartLine() — returns the starting line of the subroutine

Free Form RPG[edit]

  • listConstants() — returns a list of Constant objects
  • listFiles() — returns a list of File objects
  • listIncludes() — returns a list of Include objects
  • listPrototypes() — returns a list of Prototype objects
  • listProcedures() — returns a list of Procedure objects
  • listSubroutines() — returns a list of Subroutine objects
  • listVariables() — returns a list of global variables as Variable objects
Constant[edit]
  • name — the name of the constant
  • value — the value of the constant (Strings are returned enclosed in ')
  • statement — Statement of this constant
File[edit]
  • isExternallyDescribed() — true if externally described else false
  • isQualified() — true if the file is to be used with qualified naming and data structures for IO (keyword qualified)
  • isStaticFile() — true if the file is static (keyword static)
  • isTemplate() — true if the file is only a template (keyword template)
  • getFilename() — returns the filename
  • getStatement() — returns the Statement object
  • getType() — returns the type of the file (Disk, Printer, Workstation)
Include[edit]
  • getFile() — returns the copy book (may include quotes)
  • getFileUnquoted() — returns the copy book (without quotes)
  • getStatement() — returns the Statement object
Prototype[edit]
  • getExternalProcedure() — returns the declared external procedure name
  • getExternalProgram() — returns the declared external program name
  • getName() — returns the name of the prototype
  • getParameters() — returns a list of Parameter objects
  • getReturnValue() — returns a Variable or DataStructure
  • getStatements() — returns a list of Statement objects
  • isReturnParameter() — true if the prototype is declared with the keyword rtnparm
Parameter[edit]

A Parameter can either be a Variable or a DataStructure.

  • isPassedByRef() — true if parameter is defined with const
  • isPassedByValue() — true if parameter is defined with value
  • getOptions() — returns a list of options
Procedure[edit]
  • getName() — returns the name of the procedure
  • getProcedureInterface() — returns the ProcedureInterface
  • isExported() — returns true if the procedure is exported (keyword export)
  • listConstants() — returns a list of Constant objects
  • listFiles() — returns a list of File objects
  • listIncludes() — returns a list of Include objects
  • listPrototypes() — returns a list of Prototype objects
  • listSubroutines() — returns a list of Subroutine objects
  • listVariables() — returns a list of global variables as Variable objects
ProcedureInterface[edit]
  • isReturnParameter() — true if the prototype is declared with the keyword rtnparm
  • getParameters() — returns a list of Parameter object
  • getStatements() — returns a list of Statement objects
  • getReturnValue() — returns a Variable or DataStructure
Subroutine[edit]
  • name() — returns the name of the subroutine
  • list() — returns a list of Statement objects
Variable[edit]
  • getArraySize() — returns the array size (defined with the keyword dim)
  • getBased() — returns the name of the based pointer
  • getCcsid() — returns the declared ccsid
  • getCompileTimeArray — returns true if the variable is declared as a compile time array
  • getDecimalPositions() — returns the decimal positions
  • getExported() — returns true if the variable is declared as exported
  • getExternalName() — returns the external name if the variable is exported or imported
  • getImported() — returns true if the variable is declared as imported
  • getLength() — returns the length of the variable
  • getLengthAdjustment() — returns the length adjustment
  • getLike() — returns the field name which is used as a template for this variable
  • getName() — returns the variable name
  • getStatement() — returns the Statement object
  • getType() — returns the type of the variable (Character, Integer, UnsignedInteger, Boolean, Zoned, Packed, Pointer, Time, Timestamp, Date, Graph, UCS2, Varchar, BinaryDecimal, Float, Object)
  • isInitialized() — returns true if the variable is declared with an initial value (keyword inz)
DataStructure[edit]
  • getArraySize() — returns the array size (defined with the keyword dim)
  • getBased() — returns the name of the based pointer
  • getExported() — returns true if the data structure is declared as exported
  • getExternalName() — returns the external name if the data structure is exported or imported
  • getImported() — returns true if the variable is declared as imported
  • getLength() — returns the length of the data structure
  • getLikeRecord() — returns the record name which is used as a template for this data structure
  • getName() — returns the data structure name
  • getStatements()) — returns a list of Statements objects
  • getSubfields() — returns a list of objects, either Variable or DataStructure
  • isInitialized() — returns true if the data structure is declared with an initial value (keyword inz)
  • isQualified() — true if the data structure is to be used with qualified naming for accessing subfields (keyword qualified)
  • isTemplate() — true if the data structure is only a template (keyword template)
Statement[edit]
  • getFirstLine() — returns the staring line number of this statement
  • getFirstToken() — returns the first token of this line
  • list() — returns a list of Token objects
  • size() — returns the number of tokens in this statement
  • startsWith(string) — checks if the statements starts with the given string (case insensitive)
Token[edit]
  • line — line number
  • lineOffset — offset of the token in this line
  • offset — offset of the token in the whole program code
  • value — token value

DDS[edit]

  • listRecordFormats() — returns a list of record formats
RecordFormat[edit]
  • line — returns the line number of the record format (zero-based)
  • name — returns the name of the record format

Console[edit]

Besides the Script Editor view there is also the Console view which displays the output of the script done with the print function.

print(document.get());