Java Reference
In-Depth Information
};
source :=
object
java::Statement {
source := 'this.' +
self
.name + ' = ' +
self
.name + ';';
};
}
/**
* Creates method from operation
* TODO: handle parameters
*/
mapping
oocore::Operation::toMethod() : java::Method {
name :=
self
.name;
eType :=
self
.type.
map
toClass();
javaVisibility :=
self
.visibility.toVisibility();
source :=
object
java::Block {
contents +=
object
java::Comment {
source := 'TODO: Implement this method';
};
contents +=
self
.type.
map
toReturnStatement();
};
}
/**
* Creates default return statement for method
*/
mapping
oocore::Classifier::toReturnStatement() : java::Statement {
init {
var
statement :
String
:=
null
;
switch
{
(
self
.
oclIsUndefined
()) ? statement := '';
(
self
.
oclIsKindOf
(oocore::Class)) ? statement := 'return null;';
(
self
.
oclIsTypeOf
(oocore::Datatype)) ? statement := 'return ' +
➥
self
.
oclAsType
(oocore::Datatype).defaultLiteral + ';';
else
?
assert
fatal (
false
)
with log
('No return type found',
➥
self
);
};
}
source := statement;
}
/**
* Creates class and packaging with 'library' annotation
*/
mapping String
::toClass() : java::JavaClass {
init
{
var
segment :
String
:=
null
;
var
pkg : java::JavaPackage :=
null
;
var
parentPkg : java::JavaPackage :=
null
;
var
pos :
Integer
:= 1;
while
(
self
.indexOf('.', pos) <> -1) {
segment :=
self
.substring(pos,
self
.indexOf('.', pos));
pos :=
self
.indexOf('.', pos) + 2;
pkg := segment.
map
toPackage();
if
parentPkg =
null then
{
parentPkg := pkg;
Search WWH ::
Custom Search