Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
prisma-core
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Descartes Research
prisma-core
Commits
aada6752
Commit
aada6752
authored
9 years ago
by
Simon Spinner
Browse files
Options
Downloads
Patches
Plain Diff
Add a Status flag to distinguish between CREATE, EXISTS and REMOVE.
parent
5327e74e
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
tools.descartes.prisma.core/src/tools/descartes/prisma/core/templates/ModelTemplate.java
+47
-19
47 additions, 19 deletions
.../tools/descartes/prisma/core/templates/ModelTemplate.java
with
47 additions
and
19 deletions
tools.descartes.prisma.core/src/tools/descartes/prisma/core/templates/ModelTemplate.java
+
47
−
19
View file @
aada6752
...
...
@@ -10,13 +10,23 @@ import org.eclipse.emf.ecore.EStructuralFeature;
public
abstract
class
ModelTemplate
<
P
extends
EObject
,
E
extends
EObject
>
{
public
enum
Status
{
CREATE
,
EXISTS
,
REMOVE
}
private
final
EStructuralFeature
container
;
private
final
Class
<
E
>
elementType
;
private
TemplateContext
context
;
private
TemplateContext
context
;
private
final
Status
status
;
protected
ModelTemplate
(
EStructuralFeature
container
,
Class
<
E
>
elementType
)
{
public
ModelTemplate
(
EStructuralFeature
container
,
Class
<
E
>
elementType
)
{
this
(
Status
.
CREATE
,
container
,
elementType
);
}
public
ModelTemplate
(
Status
status
,
EStructuralFeature
container
,
Class
<
E
>
elementType
)
{
this
.
container
=
container
;
this
.
elementType
=
elementType
;
this
.
status
=
status
;
}
public
void
setContext
(
TemplateContext
ctx
)
{
...
...
@@ -32,34 +42,44 @@ public abstract class ModelTemplate<P extends EObject, E extends EObject> {
public
abstract
boolean
matches
(
E
object
);
protected
E
matchesWithCast
(
Object
object
)
{
if
(
elementType
.
isAssignableFrom
(
object
.
getClass
()))
{
E
casted
=
elementType
.
cast
(
object
);
if
(
matches
(
casted
))
{
return
casted
;
}
}
return
null
;
}
public
E
find
(
P
parent
)
{
if
(
parent
==
null
)
{
return
null
;
}
if
(
container
.
isMany
())
{
return
find
((
Collection
<?>)
parent
.
eGet
(
container
));
return
find
((
List
<?>)
parent
.
eGet
(
container
)
,
0
);
}
else
{
Object
value
=
parent
.
eGet
(
container
);
if
(
value
!=
null
)
{
if
(
elementType
.
isAssignableFrom
(
value
.
getClass
()))
{
E
casted
=
elementType
.
cast
(
value
);
if
(
matches
(
casted
))
{
return
casted
;
}
E
casted
=
matchesWithCast
(
value
);
if
(
casted
!=
null
)
{
return
casted
;
}
}
return
null
;
}
}
protected
E
find
(
Collection
<?>
list
)
{
for
(
Object
cur
:
list
)
{
if
(
elementType
.
isAssignableFrom
(
cur
.
getClass
()))
{
E
casted
=
elementType
.
cast
(
cur
);
if
(
matches
(
casted
))
{
return
casted
;
}
protected
E
find
(
List
<?>
list
)
{
return
find
(
list
,
0
);
}
protected
E
find
(
List
<?>
list
,
int
startIdx
)
{
for
(
int
i
=
startIdx
;
i
<
list
.
size
();
i
++)
{
E
casted
=
matchesWithCast
(
list
.
get
(
i
));
if
(
casted
!=
null
)
{
return
casted
;
}
}
return
null
;
...
...
@@ -86,20 +106,28 @@ public abstract class ModelTemplate<P extends EObject, E extends EObject> {
public
void
apply
(
P
parent
)
{
E
current
=
get
(
parent
);
for
(
ModelTemplate
<?
super
E
,
?>
cmd
:
getChildCommands
())
{
cmd
.
apply
(
current
);
if
(
current
!=
null
)
{
for
(
ModelTemplate
<?
super
E
,
?>
cmd
:
getChildCommands
())
{
cmd
.
apply
(
current
);
}
}
}
public
E
get
(
P
parent
)
{
E
ret
=
find
(
parent
);
if
(
ret
==
null
)
{
if
((
status
==
Status
.
CREATE
)
&&
(
ret
==
null
)
)
{
ret
=
create
(
parent
);
insert
(
parent
,
ret
);
if
(
ret
!=
null
)
{
insert
(
parent
,
ret
);
}
}
return
ret
;
}
public
Status
getStatus
()
{
return
status
;
}
protected
Class
<
E
>
getElementType
()
{
return
elementType
;
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment