Skip to content
Snippets Groups Projects
Commit 6086120c authored by Simon Barner's avatar Simon Barner
Browse files

Introduce "derived" annotation, i.e. based on calculations instead of explicit...

Introduce "derived" annotation, i.e. based on calculations instead of explicit annotations / model contents can be implemented

- DerivedAnnotationBase meta-model element, with getValue() EOperation, and a extensive documentation.
- Corresponding DerivedAnnotationValueProviderBase, implementing a read-only, text-view of the calculation result
- To implement the above, move handling of annotation EClass & factory to ValueProviderBase

refs 1841
parent 4355629c
No related branches found
No related tags found
No related merge requests found
/*--------------------------------------------------------------------------+
$Id$
| |
| Copyright 2014 ForTISS GmbH |
| |
| Licensed under the Apache License, Version 2.0 (the "License"); |
| you may not use this file except in compliance with the License. |
| You may obtain a copy of the License at |
| |
| http://www.apache.org/licenses/LICENSE-2.0 |
| |
| Unless required by applicable law or agreed to in writing, software |
| distributed under the License is distributed on an "AS IS" BASIS, |
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| See the License for the specific language governing permissions and |
| limitations under the License. |
+--------------------------------------------------------------------------*/
package org.fortiss.tooling.base.ui.annotation.valueprovider;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.EFactory;
import org.eclipse.jface.viewers.ColumnViewer;
import org.eclipse.jface.viewers.EditingSupport;
import org.fortiss.tooling.base.model.base.DerivedAnnotationBase;
import org.fortiss.tooling.base.model.element.IAnnotatedSpecification;
/**
* Base class for {@link IAnnotationValueProvider} for derived annotations (i.e., based on
* {@link DerivedAnnotationBase}).
*
* @author barner
* @author $Author$
* @version $Rev$
* @ConQAT.Rating RED Hash:
*/
public abstract class DerivedAnnotationValueProviderBase<T extends DerivedAnnotationBase> extends
ValueProviderBase<T> {
/**
* Constructs a {@link IAnnotationValueProvider} for derived annotations (i.e., based on
* {@link DerivedAnnotationBase}).
*/
public DerivedAnnotationValueProviderBase(EClass annotatedSpecificationEClass,
EFactory annotationFactory) {
super(annotatedSpecificationEClass, annotationFactory);
}
/** {@inheritDoc} */
@SuppressWarnings("unchecked")
@Override
public <U> U getAnnotationValue(T specification) {
// Delegate retrieval of annotation value to {@link EOperation} to be provided for the
// concrete @link DerivedAnnotationBase}.
return (U)specification.getValue();
}
/** {@inheritDoc} */
@Override
public EditingSupport createEditingSupport(ColumnViewer viewer,
Class<? extends IAnnotatedSpecification> clazz, String instanceKey) {
// Derived annotations are results of calculations can thus cannot be edited.
return null;
}
}
......@@ -25,7 +25,6 @@ import org.eclipse.emf.ecore.EReference;
import org.eclipse.emf.ecore.EStructuralFeature;
import org.fortiss.tooling.base.model.element.IAnnotatedSpecification;
import org.fortiss.tooling.base.model.element.IModelElement;
import org.fortiss.tooling.base.model.element.IModelElementSpecification;
/**
* Base class for {@link IAnnotationValueProvider}s that manages a single {@link EStructuralFeature}
......@@ -39,18 +38,6 @@ import org.fortiss.tooling.base.model.element.IModelElementSpecification;
public abstract class SingleEStructuralFeatureValueProviderBase<T extends IAnnotatedSpecification>
extends ValueProviderBase<T> {
/**
* {@link EClass} of {@link IAnnotatedSpecification} that contains the respective structural
* feature and that is managed by this {@link IAnnotationValueProvider}.
*/
final protected EClass annotatedSpecificationEClass;
/**
* {@link EFactory} of ECore model that contains {@link IAnnotatedSpecification} identified by
* {@code annotatedSpecificationEClass} (used to create new instances of the annotation).
*/
final protected EFactory annotationFactory;
/**
* The structural feature of the {@link IAnnotatedSpecification} that is managed by this
* {@link IAnnotationValueProvider}.
......@@ -88,8 +75,8 @@ public abstract class SingleEStructuralFeatureValueProviderBase<T extends IAnnot
EFactory annotationFactory, EStructuralFeature structuralFeature,
EFactory structuralFeatureFactory, final String structuralFeatureDefaultValue) {
this.annotatedSpecificationEClass = annotatedSpecificationEClass;
this.annotationFactory = annotationFactory;
super(annotatedSpecificationEClass, annotationFactory);
this.structuralFeature = structuralFeature;
this.structuralFeatureFactory = structuralFeatureFactory;
this.structuralFeatureDefaultValue = structuralFeatureDefaultValue;
......@@ -186,35 +173,13 @@ public abstract class SingleEStructuralFeatureValueProviderBase<T extends IAnnot
}
/** {@inheritDoc} */
@SuppressWarnings("unchecked")
@Override
public T getAnnotatedSpecificationForModelElement(IModelElement element) throws Exception {
// Return existing annotation
for(IModelElementSpecification specification : element.getSpecifications()) {
if(annotatedSpecificationEClass.equals(specification.eClass())) {
return (T)specification;
}
}
// Create annotation
T specification = (T)annotationFactory.create(annotatedSpecificationEClass);
protected void decorateAnnotationSpecification(T specification) throws Exception {
// Create and set structural feature implementing the annotation
Object structuralFeatureVal = createStructuralFeatureInstance();
if(structuralFeatureVal != null) {
specification.eSet(structuralFeature, structuralFeatureVal);
}
// Hook specification to model element
element.addSpecification(specification);
return specification;
}
/** {@inheritDoc} */
@SuppressWarnings("unchecked")
@Override
public Class<T> getAnnotationClazz() {
return (Class<T>)annotatedSpecificationEClass.getClass();
}
}
......@@ -19,10 +19,14 @@ package org.fortiss.tooling.base.ui.annotation.valueprovider;
import java.util.List;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.EFactory;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.jface.viewers.ColumnViewer;
import org.eclipse.jface.viewers.EditingSupport;
import org.fortiss.tooling.base.model.element.IAnnotatedSpecification;
import org.fortiss.tooling.base.model.element.IModelElement;
import org.fortiss.tooling.base.model.element.IModelElementSpecification;
import org.fortiss.tooling.base.ui.annotation.editingsupport.TextEditingSupport;
/**
......@@ -36,6 +40,26 @@ import org.fortiss.tooling.base.ui.annotation.editingsupport.TextEditingSupport;
public abstract class ValueProviderBase<T extends IAnnotatedSpecification> implements
IAnnotationValueProvider<T> {
/**
* {@link EClass} of {@link IAnnotatedSpecification} that contains the respective structural
* feature and that is managed by this {@link IAnnotationValueProvider}.
*/
protected final EClass annotatedSpecificationEClass;
/**
* {@link EFactory} of ECore model that contains {@link IAnnotatedSpecification} identified by
* {@code annotatedSpecificationEClass} (used to create new instances of the annotation).
*/
protected final EFactory annotationFactory;
/**
* Constructs a new {@link IAnnotationValueProvider} for an annotation specified in a given
* {@link EClass}, and constructed using a given {@link EFactory}.
*/
public ValueProviderBase(EClass annotatedSpecificationEClass, EFactory annotationFactory) {
this.annotatedSpecificationEClass = annotatedSpecificationEClass;
this.annotationFactory = annotationFactory;
}
/** {@inheritDoc} */
@Override
public boolean setAnnotationName(String name, T specification) {
......@@ -110,4 +134,43 @@ public abstract class ValueProviderBase<T extends IAnnotatedSpecification> imple
return null;
}
/**
* Add decorations to an annotation when its instance is newly created by
* {@link #getAnnotatedSpecificationForModelElement(IModelElement)}.
*
* @param specification
* annotation to be decorated
*/
protected void decorateAnnotationSpecification(T specification) throws Exception {
// No decoration
}
/** {@inheritDoc} */
@SuppressWarnings("unchecked")
@Override
public T getAnnotatedSpecificationForModelElement(IModelElement element) throws Exception {
// Return existing annotation
for(IModelElementSpecification specification : element.getSpecifications()) {
if(annotatedSpecificationEClass.equals(specification.eClass())) {
return (T)specification;
}
}
// Create annotation
T specification = (T)annotationFactory.create(annotatedSpecificationEClass);
decorateAnnotationSpecification(specification);
// Hook specification to model element
element.addSpecification(specification);
return specification;
}
/** {@inheritDoc} */
@SuppressWarnings("unchecked")
@Override
public Class<T> getAnnotationClazz() {
return (Class<T>)annotatedSpecificationEClass.getClass();
}
}
......@@ -294,5 +294,16 @@
</eAnnotations>
</eOperations>
</eClassifiers>
<eClassifiers xsi:type="ecore:EClass" name="DerivedAnnotationBase" abstract="true"
eSuperTypes="#//element/IAnnotatedSpecification #//element/IHiddenSpecification">
<eAnnotations source="http://www.eclipse.org/emf/2002/GenModel">
<details key="documentation" value="Base class for {@link IAnnotationSpecification}s that are derived from the state of other annotations and/or model elements.&#xD;&#xA;&#xD;&#xA;&lt;ul>&#xD;&#xA;&lt;li>Concrete specifications must provide a specialized getValue() {@link EOperation}s that perform the required calculation. Example: Calculation of {@link Component} WCET for current deployment (if available) based on {@link Component} instruction count and performance (e.g., MIPS) of {@link ExecutionUnit}, some warning indicator otherwise. &lt;/li>&#xD;&#xA;&lt;li>Concrete specifications may provide additional {@link EOperation} that provide an advanced query interface to the annoation. Example: WCET for an explicitly specified {@link ExecutionUnit}. This can be used e.g. in a DSE to explore different deployments.&lt;/li>&#xD;&#xA;&lt;li>The corresponding {@link IAnnotationValueProvider} should be based on {@link DerivedAnnotationValueProviderBase}.&#xD;&#xA;&lt;/ul>"/>
</eAnnotations>
<eOperations name="getValue" lowerBound="1" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EJavaObject">
<eAnnotations source="http://www.eclipse.org/emf/2002/GenModel">
<details key="body" value="return null;"/>
</eAnnotations>
</eOperations>
</eClassifiers>
</eSubpackages>
</ecore:EPackage>
......@@ -97,6 +97,9 @@
<genOperations ecoreOperation="base.ecore#//base/LibraryElementBase/getURI"/>
<genOperations ecoreOperation="base.ecore#//base/LibraryElementBase/getName"/>
</genClasses>
<genClasses image="false" ecoreClass="base.ecore#//base/DerivedAnnotationBase">
<genOperations ecoreOperation="base.ecore#//base/DerivedAnnotationBase/getValue"/>
</genClasses>
</nestedGenPackages>
</genPackages>
</genmodel:GenModel>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment