-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#21 implemented class and field transformations
- Loading branch information
Showing
8 changed files
with
227 additions
and
101 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
...nsformation/src/com/incquerylabs/evm/jdt/java/transformation/rules/AssociationRules.xtend
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package com.incquerylabs.evm.jdt.java.transformation.rules | ||
|
||
import com.incquerylabs.evm.jdt.java.transformation.queries.util.AssociationOfClassQuerySpecification | ||
import com.incquerylabs.evm.jdt.jdtmanipulator.impl.JDTManipulator | ||
import java.util.Map | ||
import org.eclipse.incquery.runtime.evm.specific.Lifecycles | ||
import org.eclipse.incquery.runtime.evm.specific.event.IncQueryActivationStateEnum | ||
import org.eclipse.uml2.uml.Element | ||
|
||
import static extension com.incquerylabs.evm.jdt.java.transformation.util.QualifiedNameUtil.* | ||
|
||
class AssociationRules extends RuleProvider{ | ||
|
||
override initialize(JDTManipulator manipulator, Map<Element, String> elementNameRegistry) { | ||
addRule(ruleFactory.createRule.precondition(AssociationOfClassQuerySpecification::instance) | ||
.action(IncQueryActivationStateEnum.APPEARED) [ | ||
val containingClassQN = it.srcEnd.type.qualifiedName.toJDTQN | ||
val fieldName = it.trgEnd.name | ||
val typeQN = it.trgEnd.type.qualifiedName.toJDTQN | ||
manipulator.createField(containingClassQN, fieldName, typeQN) | ||
elementNameRegistry.put(it.trgEnd, it.trgEnd.name) | ||
].action(IncQueryActivationStateEnum.UPDATED) [ | ||
val fieldName = elementNameRegistry.get(it.trgEnd) | ||
manipulator.updateField((it.srcEnd.type.qualifiedName + "::" + fieldName).toJDTQN, it.trgEnd.type.qualifiedName.toJDTQN, it.trgEnd.name) | ||
elementNameRegistry.put(it.trgEnd, it.trgEnd.name) | ||
].action(IncQueryActivationStateEnum.DISAPPEARED) [ | ||
val fieldName = it.trgEnd.name | ||
// TODO: if a type gets deleted and an association points at it, this event gets triggered and the it.srcEnd.type will be null -> not so good behavior | ||
val fieldQN = (it.srcEnd.type.qualifiedName + "::" + fieldName).toJDTQN | ||
manipulator.deleteField(fieldQN) | ||
elementNameRegistry.remove(it.trgEnd.name) | ||
].addLifeCycle(Lifecycles::getDefault(true, true)).build, 1) | ||
} | ||
|
||
} |
46 changes: 46 additions & 0 deletions
46
...va.transformation/src/com/incquerylabs/evm/jdt/java/transformation/rules/ClassRules.xtend
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package com.incquerylabs.evm.jdt.java.transformation.rules | ||
|
||
import com.incquerylabs.evm.jdt.java.transformation.queries.util.UmlClassInModelQuerySpecification | ||
import com.incquerylabs.evm.jdt.java.transformation.queries.util.UmlClassInPackageQuerySpecification | ||
import com.incquerylabs.evm.jdt.jdtmanipulator.impl.JDTManipulator | ||
import java.util.Map | ||
import org.eclipse.incquery.runtime.evm.specific.Lifecycles | ||
import org.eclipse.incquery.runtime.evm.specific.event.IncQueryActivationStateEnum | ||
import org.eclipse.uml2.uml.Element | ||
|
||
import static extension com.incquerylabs.evm.jdt.java.transformation.util.QualifiedNameUtil.* | ||
|
||
class ClassRules extends RuleProvider { | ||
|
||
override initialize(JDTManipulator manipulator, Map<Element, String> elementNameRegistry) { | ||
addRule(ruleFactory.createRule.precondition(UmlClassInModelQuerySpecification::instance) | ||
.action(IncQueryActivationStateEnum.APPEARED) [ | ||
val qualifiedName = it.umlClass.qualifiedName.toJDTQN | ||
manipulator.createClass(qualifiedName) | ||
elementNameRegistry.put(it.umlClass, it.umlClass.name) | ||
].action(IncQueryActivationStateEnum.UPDATED) [ | ||
val clazzName = elementNameRegistry.get(it.umlClass) | ||
manipulator.updateClass((it.model.qualifiedName + "::" + clazzName).toJDTQN, it.umlClass.name) | ||
elementNameRegistry.put(it.umlClass, it.umlClass.name) | ||
].action(IncQueryActivationStateEnum.DISAPPEARED) [ | ||
val qualifiedName = (it.model.qualifiedName + "::" + it.umlClass.name).toJDTQN | ||
manipulator.deleteClass(qualifiedName) | ||
elementNameRegistry.remove(it.umlClass.name) | ||
].addLifeCycle(Lifecycles::getDefault(true, true)).build, 0) | ||
|
||
addRule(ruleFactory.createRule.precondition(UmlClassInPackageQuerySpecification::instance) | ||
.action(IncQueryActivationStateEnum.APPEARED) [ | ||
val qualifiedName = it.umlClass.qualifiedName.toJDTQN | ||
manipulator.createClass(qualifiedName) | ||
elementNameRegistry.put(it.umlClass, it.umlClass.name) | ||
].action(IncQueryActivationStateEnum.UPDATED) [ | ||
val clazzName = elementNameRegistry.get(it.umlClass) | ||
manipulator.updateClass((it.umlPackage.qualifiedName + "::" + clazzName).toJDTQN, it.umlClass.name) | ||
elementNameRegistry.put(it.umlClass, it.umlClass.name) | ||
].action(IncQueryActivationStateEnum.DISAPPEARED) [ | ||
val qualifiedName = (it.umlPackage.qualifiedName + "::" + it.umlClass.name).toJDTQN | ||
manipulator.deleteClass(qualifiedName) | ||
elementNameRegistry.remove(it.umlClass.name) | ||
].addLifeCycle(Lifecycles::getDefault(true, true)).build, 0) | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
....transformation/src/com/incquerylabs/evm/jdt/java/transformation/rules/RuleProvider.xtend
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package com.incquerylabs.evm.jdt.java.transformation.rules | ||
|
||
import com.incquerylabs.evm.jdt.jdtmanipulator.impl.JDTManipulator | ||
import java.util.Map | ||
import org.eclipse.incquery.runtime.evm.specific.resolver.InvertedDisappearancePriorityConflictResolver | ||
import org.eclipse.uml2.uml.Element | ||
import org.eclipse.viatra.emf.runtime.rules.eventdriven.EventDrivenTransformationRule | ||
import org.eclipse.viatra.emf.runtime.rules.eventdriven.EventDrivenTransformationRuleFactory | ||
import org.eclipse.viatra.emf.runtime.transformation.eventdriven.EventDrivenTransformation.EventDrivenTransformationBuilder | ||
import org.eclipse.xtend.lib.annotations.Data | ||
|
||
abstract class RuleProvider { | ||
|
||
val rules = <PrioritizedRule>newArrayList | ||
protected val ruleFactory = new EventDrivenTransformationRuleFactory | ||
|
||
abstract def void initialize(JDTManipulator manipulator, Map<Element, String> elementNameRegistry) | ||
|
||
protected def addRule(EventDrivenTransformationRule<?, ?> rule, int priority) { | ||
rules.add(new PrioritizedRule(rule, priority)) | ||
} | ||
|
||
final def void registerRules(InvertedDisappearancePriorityConflictResolver resolver) { | ||
rules.forEach[resolver.setPriority(rule.ruleSpecification, priority)] | ||
} | ||
|
||
final def void addRules(EventDrivenTransformationBuilder builder) { | ||
rules.forEach[builder.addRule(rule)] | ||
} | ||
} | ||
|
||
@Data | ||
class PrioritizedRule { | ||
EventDrivenTransformationRule<?, ?> rule | ||
int priority | ||
} |
Oops, something went wrong.