-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
contributes to #155 by adding a CompositeDynamicPartAccessor that allows to combine several IDynamicPartAccessor/IMutableFieldExtractor so they can provide an unified vision of the RTD to both the Variable view (ie.debugger) and the timeline (ie. generic trace manager) Signed-off-by: Didier Vojtisek <[email protected]>
- Loading branch information
Showing
5 changed files
with
175 additions
and
4 deletions.
There are no files selected for viewing
36 changes: 36 additions & 0 deletions
36
...gger/src/org/eclipse/gemoc/executionframework/debugger/CompositeDynamicPartAccessor.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 org.eclipse.gemoc.executionframework.debugger | ||
|
||
import org.eclipse.emf.ecore.EObject | ||
import java.util.ArrayList | ||
import java.util.List | ||
|
||
|
||
/** | ||
* Dynamic partAccessor that compose the behavior of several IDynamicPartAccessor | ||
* The order in which they are declared is used to ignore conflicting properties/features | ||
*/ | ||
class CompositeDynamicPartAccessor implements IDynamicPartAccessor { | ||
|
||
List<IDynamicPartAccessor> internalDynamicPartAccessors = new ArrayList<IDynamicPartAccessor>(); | ||
|
||
|
||
new(List<IDynamicPartAccessor> internalDynamicPartAccessors) { | ||
this.internalDynamicPartAccessors.addAll(internalDynamicPartAccessors); | ||
} | ||
|
||
override isDynamic(EObject obj) { | ||
return internalDynamicPartAccessors.exists[accessor | accessor.isDynamic(obj)] | ||
} | ||
|
||
override extractMutableField(EObject eObject) { | ||
val List<MutableField> res = new ArrayList<MutableField>(); | ||
for(IDynamicPartAccessor accessor : internalDynamicPartAccessors){ | ||
val List<MutableField> candidateMutableFields = accessor.extractMutableField(eObject) | ||
// consider mutable field only if there is no previously found mutable field with the same name | ||
val List<MutableField> acceptedMutableFields = candidateMutableFields.filter[mf1 | ! res.exists[mf2 | mf1.name == mf2.name]].toList | ||
res.addAll(acceptedMutableFields) | ||
} | ||
return res; | ||
} | ||
|
||
} |
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
135 changes: 135 additions & 0 deletions
135
...ugger/src/org/eclipse/gemoc/executionframework/debugger/K3AspectDynamicPartAccessor.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,135 @@ | ||
package org.eclipse.gemoc.executionframework.debugger | ||
|
||
import org.eclipse.gemoc.executionframework.debugger.IntrospectiveMutableFieldExtractor | ||
import org.eclipse.gemoc.executionframework.debugger.IDynamicPartAccessor | ||
import org.eclipse.emf.ecore.EObject | ||
import org.eclipse.gemoc.xdsmlframework.commons.DynamicAnnotationHelper | ||
import org.eclipse.gemoc.xdsmlframework.api.core.IExecutionEngine | ||
import java.util.List | ||
import java.util.ArrayList | ||
import org.eclipse.emf.ecore.EStructuralFeature | ||
import java.lang.reflect.Field | ||
import org.eclipse.emf.ecore.resource.Resource | ||
import org.eclipse.emf.common.util.URI | ||
import org.eclipse.emf.ecore.EClass | ||
import org.eclipse.emf.ecore.EPackage | ||
import org.eclipse.emf.ecore.EcoreFactory | ||
import org.eclipse.emf.transaction.util.TransactionUtil | ||
import org.eclipse.emf.transaction.RecordingCommand | ||
import org.eclipse.gemoc.executionframework.engine.core.CommandExecution | ||
|
||
class K3AspectDynamicPartAccessor extends IntrospectiveMutableFieldExtractor implements IDynamicPartAccessor { | ||
IExecutionEngine engine; | ||
|
||
Resource aspectEMFResource = null; | ||
|
||
new(String languageName, IExecutionEngine engine) { | ||
super(languageName) | ||
this.engine = engine | ||
} | ||
|
||
override isDynamic(EObject obj) { | ||
if(obj === null) { | ||
return false; | ||
} | ||
|
||
return DynamicAnnotationHelper.isDynamic(obj.eClass()); | ||
} | ||
|
||
protected override List<MutableField> getMutableFieldsFromAspect(EObject eObject, Class<?> properties, Class<?> aspect) { | ||
|
||
val result = new ArrayList | ||
|
||
val fields = properties.fields | ||
|
||
if (!fields.empty) { | ||
fields.forEach [ f | | ||
val methods = aspect.methods.filter[m|m.name.equals(f.name)] | ||
val getter = methods.findFirst[m|m.parameterCount == 1] | ||
val setter = methods.findFirst[m|m.parameterCount == 2] | ||
if (getter !== null && setter !== null) { | ||
val data = new MutableField( | ||
f.name+" ("+findDataName(eObject)+ " :"+eObject.eClass().getName() +")", | ||
eObject, | ||
getFeatureForField(aspect, f), | ||
[getter.invoke(null, eObject)], | ||
[t|setter.invoke(null, eObject, t)] | ||
) | ||
result.add(data) | ||
} | ||
] | ||
} | ||
|
||
return result | ||
} | ||
|
||
/* | ||
* | ||
*/ | ||
protected def EStructuralFeature getFeatureForField(Class<?> aspect, Field field){ | ||
val c = getAspectEClass(aspect) | ||
var res = getAspectEClass(aspect).EStructuralFeatures.filter(EStructuralFeature).findFirst[f | f.name == field.name] | ||
if( res === null) { | ||
val t = field.type | ||
// if ref | ||
val eRef = EcoreFactory.eINSTANCE.createEReference | ||
eRef.name = aspect.name | ||
val ed = TransactionUtil.getEditingDomain(getAspectResource()); | ||
var RecordingCommand command = new RecordingCommand(ed, | ||
"Creating EReference for aspect class coming from K3") { | ||
protected override void doExecute() { | ||
c.getEStructuralFeatures.add(eRef) | ||
} | ||
}; | ||
CommandExecution.execute(ed, command); | ||
|
||
// else if attribute | ||
// TODO | ||
res = eRef | ||
} | ||
return res | ||
} | ||
|
||
protected def EClass getAspectEClass(Class<?> aspect){ | ||
val p = getAspectEPackage(aspect) | ||
var res = p.EClassifiers.filter(EClass).findFirst[c | c.name == aspect.simpleName] | ||
if(res === null) { | ||
val c = EcoreFactory.eINSTANCE.createEClass | ||
c.name = aspect.simpleName | ||
val ed = TransactionUtil.getEditingDomain(getAspectResource()); | ||
var RecordingCommand command = new RecordingCommand(ed, | ||
"Creating EClass for aspect class coming from K3") { | ||
protected override void doExecute() { | ||
p.EClassifiers.add(c) | ||
} | ||
}; | ||
CommandExecution.execute(ed, command); | ||
|
||
res = c | ||
} | ||
return res | ||
} | ||
protected def EPackage getAspectEPackage(Class<?> aspect){ | ||
var res = getAspectResource().contents.filter(EPackage).findFirst[p | p.name == aspect.package.name] | ||
if(res === null) { | ||
val p = EcoreFactory.eINSTANCE.createEPackage | ||
p.name = aspect.package.name | ||
val ed = TransactionUtil.getEditingDomain(getAspectResource()); | ||
var RecordingCommand command = new RecordingCommand(ed, | ||
"Creating EPackage for aspect class coming from K3") { | ||
protected override void doExecute() { | ||
getAspectResource().contents.add(p) | ||
} | ||
}; | ||
CommandExecution.execute(ed, command); | ||
res = p | ||
} | ||
return res | ||
} | ||
protected def Resource getAspectResource() { | ||
if(aspectEMFResource === null) { | ||
aspectEMFResource = engine.executionContext.resourceModel.resourceSet.createResource(URI.createURI("dummyResourceForK3Aspects")); | ||
} | ||
return aspectEMFResource | ||
} | ||
} |
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