Skip to content
Snippets Groups Projects
Commit ca666004 authored by Alexander Diewald's avatar Alexander Diewald
Browse files

Extends the functionality of derived annotations to support user input.

refs 2150
parent 3bedbd4d
Branches
Tags
No related merge requests found
......@@ -155,10 +155,32 @@
<eClassifiers xsi:type="ecore:EClass" name="IDerivedAnnotation" abstract="true"
interface="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>"/>
<details key="documentation" value="Interface 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>
<eTypeParameters name="T"/>
<eOperations name="getValue">
<eAnnotations source="http://www.eclipse.org/emf/2002/GenModel">
<details key="documentation" value="Wrapper method for returning derived (calculated) values. It may return values annotated by the user if the calculation fails, or the user input is preffered, based on the configuration of the concrete annotation. "/>
<details key="body" value="if(getUserAnnotatedValue() != null &amp;&amp; (isUserAnnotatedValuePreferred() || getDerivedValue() == null)) {return getUserAnnotatedValue();} return getDerivedValue();"/>
</eAnnotations>
<eGenericType eTypeParameter="#//element/IDerivedAnnotation/T"/>
</eOperations>
<eOperations name="getDerivedValue">
<eAnnotations source="http://www.eclipse.org/emf/2002/GenModel">
<details key="documentation" value="Returns the actual derived (calculated) values. It may return values annotated by the user if the calculation fails, or the user input is preferred, based on the configuration of the concrete annotation. "/>
</eAnnotations>
<eGenericType eTypeParameter="#//element/IDerivedAnnotation/T"/>
</eOperations>
<eOperations name="isUserAnnotatedValuePreferred" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EBoolean">
<eAnnotations source="http://www.eclipse.org/emf/2002/GenModel">
<details key="documentation" value="Default implementation of a method indicating whether the user annotated value, if available, shall be preferred over the derived one. The default is 'true', i.e. user annotated values are preferred. Shall be overridden, if another bahaviour is desired."/>
<details key="body" value="return true;"/>
</eAnnotations>
</eOperations>
<eOperations name="getUserAnnotatedValue">
<eAnnotations source="http://www.eclipse.org/emf/2002/GenModel">
<details key="documentation" value="Returns the {@link EAttribute} which is used to store the user annotated values, if the concrete annotatin is designed therefore. By default, this function returns null, indicating no user annotated values are supported. This method must be re-implemented by concrete annotations if any other behavior is desired."/>
</eAnnotations>
<eGenericType eTypeParameter="#//element/IDerivedAnnotation/T"/>
</eOperations>
</eClassifiers>
......
......@@ -51,6 +51,9 @@
<genClasses image="false" ecoreClass="base.ecore#//element/IDerivedAnnotation">
<genTypeParameters ecoreTypeParameter="base.ecore#//element/IDerivedAnnotation/T"/>
<genOperations ecoreOperation="base.ecore#//element/IDerivedAnnotation/getValue"/>
<genOperations ecoreOperation="base.ecore#//element/IDerivedAnnotation/getDerivedValue"/>
<genOperations ecoreOperation="base.ecore#//element/IDerivedAnnotation/isUserAnnotatedValuePreferred"/>
<genOperations ecoreOperation="base.ecore#//element/IDerivedAnnotation/getUserAnnotatedValue"/>
</genClasses>
</nestedGenPackages>
<nestedGenPackages prefix="Layout" basePackage="org.fortiss.tooling.base.model"
......
/*--------------------------------------------------------------------------+
$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.utils;
import org.fortiss.tooling.base.model.element.IDerivedAnnotation;
/**
*
* @author diewald
* @author $Author$
* @version $Rev$
* @ConQAT.Rating RED Hash:
*/
public class AnnotationUtils {
/**
* Wrapper for returning derived values of {@link IDerivedAnnotation}s. If the user input is
* preferred by the concrete annotation, this function returns the user input if any is set.
* Otherwise it determines the calculated value, if the value can be calculated. If the value
* cannot be calculated, and a user input is given which is not preferred it is returned
* instead. If none of the previously mentioned cases applies, null is returned.
* This function is a workaround, since the EMF code generator fails when generic abstract base
* classes are referenced from another ecore file.
*
* @param annotation
* The annotation to which this wrapper shall be applied to.
* @return See above.
*/
public static <T> T getValue(IDerivedAnnotation<T> annotation) {
if(annotation.getUserAnnotatedValue() != null &&
(annotation.isUserAnnotatedValuePreferred() || annotation.getDerivedValue() == null)) {
return annotation.getUserAnnotatedValue();
}
return annotation.getDerivedValue();
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment