Previous Topic

Book Contents

Book Index

Next Topic

Specifying Target Class Explicitly

Unfortunately, it is not always possible to automatically detect the target class of a variable, for instance when the variable is an argument of a function declared in the script. (This is because Python, unlike Java or C++, is not a declarative language and variable classes are not known until we execute the script.)

  • In the following example, the variable 'objectType' is an argument of a function and we cannot determine its target class as there is no assignment (objectType = …). To work around this problem, you can specify the target class of an argument in a special comment after the method declaration in the format #%variableName:targetClassName

    Help Image

  • We run into the same problem when trying the determine the target class of an input variable coming along a transition whose source class is not known, for instance a variable coming from another script. To work around the problem, specify the return class of the input variable in the comment at the beginning of the script:

    Help Image

  • In some cases it is possible to determine the target class of an input variable automatically, for instance if the input variable comes from the activity StartFromCalalog along the transition selectedObject (whose target type is known: ApiBObject).
  • Finally, we run into the same problem when trying the determine the return class of a function defined in the script. To work around the problem, specify the return class of the function in the comment after the method declaration in the format #%functionName():returnClassName

    Help Image

Note: One line can contain one or more such comments but each variable or function name must start with #%. The separator can be anything, e.g. a space or a comma.

Troubleshooting

If you type '.' and press <Ctrl+spac> but the popup does not display any methods, then one of the following might have happened:

  • the target class is a primitive type or void. It’s normal that the popup doesn’t display any methods.
  • the target type could not be found because:
    • it is impossible to determine the target type automatically – the word before the dot is a function argument, a function call or an input variable whose target class is unknown. Workaround: specify the target class explicitly using a special comment.
    • one of the words before the dot is an unknown variable, method/function/constructor call or class name. Make sure you have spelled it correctly.
    • one of the words before the dot is a constructor call or a class name but the import for the class is missing or the package of the import is incorrect

See Also

Code Completion

Completion of Methods