Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions besser/BUML/metamodel/behavioral/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from .behavioral import *
356 changes: 356 additions & 0 deletions besser/BUML/metamodel/behavioral/behavioral.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,356 @@

from ..structural import Element
from typing import List
from datetime import datetime

class SyntaxElement(Element):
"""
Represents a named syntactic element in a model, such as a variable, function, or class.

Attributes:
name (str): The name of the syntax element.
synonyms (List[str]): Alternative names or aliases for the element.
visibility (str): Visibility scope of the element (e.g., 'public', 'private').
is_derived (bool): Indicates whether the element is derived.
timestamp (datetime): The creation or modification time of the element.
"""
def __init__(self, name: str, timestamp: datetime = None, synonyms: List[str] = None,
visibility: str = "public", is_derived: bool = False):
super().__init__(timestamp, is_derived)
self.name: str = name
self.synonyms: List[str] = synonyms
self.visibility: str = visibility

class ElementReference:
"""
Represents a reference to another model element, including metadata such as type and visibility.

Attributes:
referent: The actual element being referenced.
type: The type of the referenced element.
visibility: The visibility of the reference.
multiplicity: The multiplicity of the reference (e.g., one-to-many).
"""
def __init__(self, referent=None, type=None, visibility=None, multiplicity=None):
self.referent = referent
self.type = type
self.visibility = visibility
self.multiplicity = multiplicity

def get_referent(self):
return self.referent

def set_referent(self, referent):
self.referent = referent

def get_type(self):
return self.type

def set_type(self, type):
self.type = type

def get_visibility(self):
return self.visibility

def set_visibility(self, visibility):
self.visibility = visibility

def get_multiplicity(self):
return self.multiplicity

def set_multiplicity(self, multiplicity):
self.multiplicity = multiplicity


class Statement:
"""
Base class for all statement types in the model.

Attributes:
source: The source element of the statement.
target: The target element of the statement.
annotations: Optional metadata or comments associated with the statement.
"""
def __init__(self, source=None, target=None, annotations=None):
self.source = source
self.target = target
self.annotations = annotations

def get_source(self):
return self.source

def set_source(self, source):
self.source = source

def get_target(self):
return self.target

def set_target(self, target):
self.target = target

def get_annotations(self):
return self.annotations

def set_annotations(self, annotations):
self.annotations = annotations


class Expression:
"""
Base class for all expressions in the model.

Attributes:
type: The type of the expression (e.g., 'Literal', 'Name').
operand: The operands involved in the expression.
operator: The operator used in the expression.
"""
def __init__(self, type=None, operand=None, operator=None):
self.type = type
self.operand = operand
self.operator = operator

def get_type(self):
return self.type

def set_type(self, type):
self.type = type

def get_operand(self):
return self.operand

def set_operand(self, operand):
self.operand = operand

def get_operator(self):
return self.operator

def set_operator(self, operator):
self.operator = operator


class AssignmentExpression(Expression):
"""
Represents an assignment expression with a left-hand side and right-hand side.

Attributes:
leftHandSide: The variable or location being assigned to.
rightHandSide: The value or expression being assigned.
operator: The assignment operator (e.g., '=', '+=').
"""
def __init__(self, leftHandSide=None, rightHandSide=None, operator=None):
super().__init__(type='Assignment', operand=[leftHandSide, rightHandSide], operator=operator)
self.leftHandSide = leftHandSide
self.rightHandSide = rightHandSide

def get_leftHandSide(self):
return self.leftHandSide

def set_leftHandSide(self, leftHandSide):
self.leftHandSide = leftHandSide

def get_rightHandSide(self):
return self.rightHandSide

def set_rightHandSide(self, rightHandSide):
self.rightHandSide = rightHandSide


class IfStatement(Statement):
"""
Represents a conditional 'if' statement.

Attributes:
condition: The condition expression to evaluate.
thenClause: The statement(s) to execute if the condition is true.
elseClause: The statement(s) to execute if the condition is false.
"""
def __init__(self, condition=None, thenClause=None, elseClause=None):
super().__init__()
self.condition = condition
self.thenClause = thenClause
self.elseClause = elseClause

def get_condition(self):
return self.condition

def set_condition(self, condition):
self.condition = condition

def get_thenClause(self):
return self.thenClause

def set_thenClause(self, thenClause):
self.thenClause = thenClause

def get_elseClause(self):
return self.elseClause

def set_elseClause(self, elseClause):
self.elseClause = elseClause


class WhileStatement(Statement):
"""
Represents a 'while' loop statement.

Attributes:
condition: The loop continuation condition.
body: The body of the loop to execute while the condition is true.
"""
def __init__(self, condition=None, body=None):
super().__init__()
self.condition = condition
self.body = body

def get_condition(self):
return self.condition

def set_condition(self, condition):
self.condition = condition

def get_body(self):
return self.body

def set_body(self, body):
self.body = body


class ForStatement(Statement):
"""
Represents a 'for' loop statement.

Attributes:
loopVariable: The loop control variable.
expression: The iterable or range expression.
body: The body of the loop to execute for each iteration.
"""
def __init__(self, loopVariable=None, expression=None, body=None):
super().__init__()
self.loopVariable = loopVariable
self.expression = expression
self.body = body

def get_loopVariable(self):
return self.loopVariable

def set_loopVariable(self, loopVariable):
self.loopVariable = loopVariable

def get_expression(self):
return self.expression

def set_expression(self, expression):
self.expression = expression

def get_body(self):
return self.body

def set_body(self, body):
self.body = body


class Block(Statement):
"""
Represents a block of statements grouped together.

Attributes:
statements: A list of statements contained in the block.
"""
def __init__(self, statements=None):
super().__init__()
self.statements = statements if statements is not None else []

def get_statements(self):
return self.statements

def set_statements(self, statements):
self.statements = statements


class InvocationExpression(Expression):
"""
Represents a function or method invocation expression.

Attributes:
target: The function or method being called.
arguments: The list of arguments passed to the invocation.
"""
def __init__(self, target=None, arguments=None):
super().__init__(type='Invocation', operand=[target] + (arguments if arguments is not None else []))
self.target = target
self.arguments = arguments if arguments is not None else []

def get_target(self):
return self.target

def set_target(self, target):
self.target = target

def get_arguments(self):
return self.arguments

def set_arguments(self, arguments):
self.arguments = arguments


class NameExpression(Expression):
"""
Represents an expression that refers to a named element.

Attributes:
name: The name of the element.
referent: The actual element being referred to.
"""
def __init__(self, name=None, referent=None):
super().__init__(type='Name', operand=[name])
self.name = name
self.referent = referent

def get_name(self):
return self.name

def set_name(self, name):
self.name = name

def get_referent(self):
return self.referent

def set_referent(self, referent):
self.referent = referent


class LiteralExpression(Expression):
"""
Represents a literal value in an expression.

Attributes:
value: The literal value (e.g., number, string).
type: The type of the literal (e.g., int, str).
"""
def __init__(self, value=None, type=None):
super().__init__(type='Literal', operand=[value])
self.value = value

def get_value(self):
return self.value

def set_value(self, value):
self.value = value


class ReturnStatement(Statement):
"""
Represents a return statement in a function or method.

Attributes:
expression: The expression to return.
"""
def __init__(self, expression=None):
super().__init__()
self.expression = expression

def get_expression(self):
return self.expression

def set_expression(self, expression):
self.expression = expression
1 change: 1 addition & 0 deletions besser/BUML/metamodel/structural/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from .structural import *
Binary file not shown.
Binary file not shown.
Loading