Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 339035 - @SuppressWarning("unchecked") missing for delegating operations
Summary: @SuppressWarning("unchecked") missing for delegating operations
Status: CLOSED FIXED
Alias: None
Product: EMF
Classification: Modeling
Component: Core (show other bugs)
Version: unspecified   Edit
Hardware: PC Windows 7
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Ed Merks CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks: 323181
  Show dependency tree
 
Reported: 2011-03-06 03:57 EST by Axel Uhl CLA
Modified: 2011-05-10 11:57 EDT (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Axel Uhl CLA 2011-03-06 03:57:56 EST
Based on CVS HEAD of 2011-03-06 when using delegate operations, e.g., with OCL, and the operation has a many-valued EObject-like return type, a cast to an EList<X> type is generated. JDT usually marks this with a warning about an unchecked cast. The patch below fixes this for us, adding a @SuppressWarning("unchecked") in case of such constellations.

### Eclipse Workspace Patch 1.0
#P org.eclipse.emf.codegen.ecore
Index: templates/model/Class.javajet
===================================================================
RCS file: /cvsroot/modeling/org.eclipse.emf/org.eclipse.emf/plugins/org.eclipse.emf.codegen.ecore/templates/model/Class.javajet,v
retrieving revision 1.91
diff -u -r1.91 Class.javajet
--- templates/model/Class.javajet	28 Apr 2010 20:38:15 -0000	1.91
+++ templates/model/Class.javajet	6 Mar 2011 08:50:19 -0000
@@ -1497,8 +1497,13 @@
 		{
     <%if (genOperation.isVoid()) {%>
 			<%=CodeGenUtil.upperName(genClass.getUniqueName(genOperation), genModel.getLocale())%>__EINVOCATION_DELEGATE.dynamicInvoke(this, <%if (size > 0) {%>new <%=genModel.getImportedName("org.eclipse.emf.common.util.BasicEList")%>.UnmodifiableEList<Object>(<%=size%>, <%=genOperation.getParametersArray(genClass)%>)<%} else {%>null<%}%>);
-    <%} else {%>
-			return <%if (!isJDK50 && genOperation.isPrimitiveType()) {%>(<%}%>(<%=genOperation.getObjectType(genClass)%>)<%=CodeGenUtil.upperName(genClass.getUniqueName(genOperation), genModel.getLocale())%>__EINVOCATION_DELEGATE.dynamicInvoke(this, <%if (size > 0) {%>new <%=genModel.getImportedName("org.eclipse.emf.common.util.BasicEList")%>.UnmodifiableEList<Object>(<%=size%>, <%=genOperation.getParametersArray(genClass)%>)<%} else {%>null<%}%>)<%if (!isJDK50 && genOperation.isPrimitiveType()) {%>).<%=genOperation.getPrimitiveValueFunction()%>()<%}%>;
+    <%} else {
+        if (genOperation.isUncheckedCast(genClass)) {
+            // means that this is a generic type and the cast is unsafe %>
+            @SuppressWarnings("unchecked")<%
+        }%>
+			<%=genOperation.getObjectType(genClass)%> result = <%if (!isJDK50 && genOperation.isPrimitiveType()) {%>(<%}%>(<%=genOperation.getObjectType(genClass)%>) <%=CodeGenUtil.upperName(genClass.getUniqueName(genOperation), genModel.getLocale())%>__EINVOCATION_DELEGATE.dynamicInvoke(this, <%if (size > 0) {%>new <%=genModel.getImportedName("org.eclipse.emf.common.util.BasicEList")%>.UnmodifiableEList<Object>(<%=size%>, <%=genOperation.getParametersArray(genClass)%>)<%} else {%>null<%}%>)<%if (!isJDK50 && genOperation.isPrimitiveType()) {%>).<%=genOperation.getPrimitiveValueFunction()%>()<%}%>;
+			return result;
     <%}%>
 		}
 		catch (<%=genModel.getImportedName(isGWT ? "org.eclipse.emf.common.util.InvocationTargetException" : "java.lang.reflect.InvocationTargetException")%> ite)
Comment 1 Ed Merks CLA 2011-04-07 15:59:12 EDT
A fix is committed to CVS for 2.7.
Comment 2 Ed Merks CLA 2011-05-10 11:57:49 EDT
The changes are available in EMF 2.7 M7 or an earlier build.