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

- Add a base class for derived annotations using the new ide-dev tools (see Simon's Mail)

- Adjust all annotations that inherited from IDerivedAnnotation to use the new DerivedAnnotationBase class
- EOperation cleanup
- Move getValue() from org.fortiss.tooling.base.utils.AnnotationUtils to org.fortiss.tooling.base.model.base.impl.DerivedAnnotationBaseStaticImpl
parent da02276b
No related branches found
No related tags found
No related merge requests found
......@@ -161,7 +161,6 @@
<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 preferred, 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>
......@@ -174,13 +173,11 @@
<eOperations name="getDerivedFeature" eType="ecore:EClass http://www.eclipse.org/emf/2002/Ecore#//EStructuralFeature">
<eAnnotations source="http://www.eclipse.org/emf/2002/GenModel">
<details key="documentation" value="Returns the {@link EStructuralFeature} that stores the annotation of the model element associated with this {@link IDerivedAnnotation}. Returns null if no element specific behavior is desired."/>
<details key="body" value="return null;"/>
</eAnnotations>
</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 behavior is desired."/>
<details key="body" value="return true;"/>
</eAnnotations>
</eOperations>
<eOperations name="getUserAnnotatedValue">
......@@ -332,5 +329,33 @@
</eAnnotations>
</eOperations>
</eClassifiers>
<eClassifiers xsi:type="ecore:EClass" name="DerivedAnnotationBase" abstract="true">
<eTypeParameters name="T"/>
<eOperations name="getValue">
<eAnnotations source="http://www.eclipse.org/emf/2002/GenModel">
<details key="body" value="return DerivedAnnotationBaseStaticImpl.getValue(this);"/>
</eAnnotations>
<eGenericType eTypeParameter="#//base/DerivedAnnotationBase/T"/>
</eOperations>
<eOperations name="getDerivedFeature" eType="ecore:EClass http://www.eclipse.org/emf/2002/Ecore#//EStructuralFeature">
<eAnnotations source="http://www.eclipse.org/emf/2002/GenModel">
<details key="body" value="return null;"/>
</eAnnotations>
</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="body" value="return true;"/>
</eAnnotations>
</eOperations>
<eOperations name="getUserAnnotatedValue">
<eAnnotations source="http://www.eclipse.org/emf/2002/GenModel">
<details key="body" value="return null;"/>
</eAnnotations>
<eGenericType eTypeParameter="#//base/DerivedAnnotationBase/T"/>
</eOperations>
<eGenericSuperTypes eClassifier="#//element/IDerivedAnnotation">
<eTypeArguments eTypeParameter="#//base/DerivedAnnotationBase/T"/>
</eGenericSuperTypes>
</eClassifiers>
</eSubpackages>
</ecore:EPackage>
......@@ -105,6 +105,13 @@
<genOperations ecoreOperation="base.ecore#//base/LibraryElementBase/getURI"/>
<genOperations ecoreOperation="base.ecore#//base/LibraryElementBase/getName"/>
</genClasses>
<genClasses image="false" ecoreClass="base.ecore#//base/DerivedAnnotationBase">
<genTypeParameters ecoreTypeParameter="base.ecore#//base/DerivedAnnotationBase/T"/>
<genOperations ecoreOperation="base.ecore#//base/DerivedAnnotationBase/getValue"/>
<genOperations ecoreOperation="base.ecore#//base/DerivedAnnotationBase/getDerivedFeature"/>
<genOperations ecoreOperation="base.ecore#//base/DerivedAnnotationBase/isUserAnnotatedValuePreferred"/>
<genOperations ecoreOperation="base.ecore#//base/DerivedAnnotationBase/getUserAnnotatedValue"/>
</genClasses>
</nestedGenPackages>
</genPackages>
</genmodel:GenModel>
/*--------------------------------------------------------------------------+
$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.model.base.impl;
import org.fortiss.tooling.base.model.base.DerivedAnnotationBase;
import org.fortiss.tooling.base.model.element.IDerivedAnnotation;
/**
* Static implementation for the {@link DerivedAnnotationBase}.
*
* @author diewald
* @author $Author$
* @version $Rev$
* @ConQAT.Rating RED Hash: 975D2018E6732836293829A472BF0C75
*/
public class DerivedAnnotationBaseStaticImpl {
/**
* 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.
*
* @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();
}
}
......@@ -28,7 +28,6 @@ import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.util.EcoreUtil;
import org.fortiss.tooling.base.model.element.IAnnotatedSpecification;
import org.fortiss.tooling.base.model.element.IDerivedAnnotation;
import org.fortiss.tooling.base.model.element.IModelElement;
import org.fortiss.tooling.kernel.extension.data.ITopLevelElement;
import org.fortiss.tooling.kernel.service.IPersistencyService;
......@@ -45,29 +44,6 @@ import org.fortiss.tooling.kernel.service.IPersistencyService;
*/
public class AnnotationUtils {
// TODO This function is a workaround which might no longer be required. Before the IDE dev
// tools update on 2014/12/01, the EMF code generator failed when generic abstract base
// classes are referenced from another ecore file.
/**
* 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.
*
* @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();
}
/**
* Returns the annotation of a given {@link EClass} from a given {@code modelElement}. If the
* annotation does not exist yet, it is created and added to the specification list of the
......
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