long (@NotNull PsiClass psiClass) { final Project project = psiClass.getProject(); final GlobalSearchScope scope = GlobalSearchScope.allScope(project); final JavaPsiFacade psiFacade = JavaPsiFacade.getInstance(project); final PsiClass serializable = psiFacade.findClass(CommonClassNames.JAVA_IO_SERIALIZABLE, scope); if (serializable == null) { // no jdk defined for project. return -1L; } final boolean isSerializable = psiClass.isInheritor(serializable, true); if (!isSerializable) { return 0L; } final SerialVersionUIDBuilder serialVersionUIDBuilder = new SerialVersionUIDBuilder(psiClass); try { final ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); final DataOutputStream dataOutputStream = new DataOutputStream(byteArrayOutputStream); final String className = PsiFormatUtil.getExternalName(psiClass); if (className != null) { dataOutputStream.writeUTF(className); } final PsiModifierList classModifierList = psiClass.getModifierList(); int classModifiers = classModifierList != null ? MemberSignature.calculateModifierBitmap(classModifierList) : 0; final MemberSignature[] methodSignatures = serialVersionUIDBuilder.getNonPrivateMethodSignatures(); if (psiClass.isInterface()) { classModifiers |= Modifier.INTERFACE; if (methodSignatures.length == 0) { // interfaces were not marked abstract when they did't have methods in java 1.0 // For serialization compatibility the abstract modifier is ignored. classModifiers &= ~Modifier.ABSTRACT; } } dataOutputStream.writeInt(classModifiers); final PsiClass[] interfaces = psiClass.getInterfaces(); Arrays.sort(interfaces, INTERFACE_COMPARATOR); for (PsiClass aInterfaces : interfaces) { final String name = aInterfaces.getQualifiedName(); if (name != null) { dataOutputStream.writeUTF(name); } } final MemberSignature[] fields = serialVersionUIDBuilder.getNonPrivateFields(); writeSignatures(fields, dataOutputStream); final MemberSignature[] staticInitializers = serialVersionUIDBuilder.getStaticInitializers(); writeSignatures(staticInitializers, dataOutputStream); final MemberSignature[] constructors = serialVersionUIDBuilder.getNonPrivateConstructors(); writeSignatures(constructors, dataOutputStream); writeSignatures(methodSignatures, dataOutputStream); dataOutputStream.flush(); @NonNls final String algorithm = "SHA"; final MessageDigest digest = MessageDigest.getInstance(algorithm); final byte[] digestBytes = digest.digest(byteArrayOutputStream.toByteArray()); long serialVersionUID = 0L; for (int i = Math.min(digestBytes.length, 8) - 1; i >= 0; i--) { serialVersionUID = serialVersionUID << 8 | digestBytes[i] & 0xFF; } return serialVersionUID; } catch (IOException exception) { throw new InternalError(exception.getMessage(), exception); } catch (NoSuchAlgorithmException exception) { throw new SecurityException(exception.getMessage(), exception); } }