Community
Participate
Working Groups
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)
A fix is committed to CVS for 2.7.
The changes are available in EMF 2.7 M7 or an earlier build.