PropertyInfo propInfo = t.getSource();
TypeInfo parentInfo = (propInfo == null) ? null : propInfo.parent();
if (canBeDirectElementRef(t,tn) || ((!tn.getNamespaceURI().equals(uri) && tn.getNamespaceURI().length()>0) &&
(!((parentInfo instanceof ClassInfo) && (((ClassInfo)parentInfo).getTypeName() == null))))) { // see Issue 517
e.ref(tn);
} else {
e.name(tn.getLocalPart());
writeTypeRef(e,t, "type");
elementFormDefault.writeForm(e,tn);
}