@Test public void testGenerateSerialVersionUID() { AST ast = AST.newAST(AST.JLS3); TypeDeclaration td = ast.newTypeDeclaration(); td.setName(ast.newSimpleName("Company")); exceptionGenerator.generateSerialVersionUID(clazz, ast, td); assertEquals( "class Company {\n private static final long serialVersionUID=1L;\n}\n", td.toString()); }
@SuppressWarnings("unchecked") public void generateSerialVersionUID(Classifier clazz, AST ast, TypeDeclaration td) { VariableDeclarationFragment fragment = ast .newVariableDeclarationFragment(); SimpleName variableName = ast.newSimpleName("serialVersionUID"); fragment.setName(variableName); NumberLiteral initializer = ast.newNumberLiteral(); initializer.setToken("1L"); fragment.setInitializer(initializer); FieldDeclaration fieldDeclaration = ast.newFieldDeclaration(fragment); fieldDeclaration.modifiers().add( ast.newModifier(Modifier.ModifierKeyword.PRIVATE_KEYWORD)); fieldDeclaration.modifiers().add( ast.newModifier(Modifier.ModifierKeyword.STATIC_KEYWORD)); fieldDeclaration.modifiers().add( ast.newModifier(Modifier.ModifierKeyword.FINAL_KEYWORD)); fieldDeclaration.setType(ast.newPrimitiveType(PrimitiveType.LONG)); td.bodyDeclarations().add(fieldDeclaration); }
ExceptionGenerator { @SuppressWarnings("unchecked") public void generateSerialVersionUID(Classifier clazz, AST ast, TypeDeclaration td) { VariableDeclarationFragment fragment = ast .newVariableDeclarationFragment(); SimpleName variableName = ast.newSimpleName("serialVersionUID"); fragment.setName(variableName); NumberLiteral initializer = ast.newNumberLiteral(); initializer.setToken("1L"); fragment.setInitializer(initializer); FieldDeclaration fieldDeclaration = ast.newFieldDeclaration(fragment); fieldDeclaration.modifiers().add( ast.newModifier(Modifier.ModifierKeyword.PRIVATE_KEYWORD)); fieldDeclaration.modifiers().add( ast.newModifier(Modifier.ModifierKeyword.STATIC_KEYWORD)); fieldDeclaration.modifiers().add( ast.newModifier(Modifier.ModifierKeyword.FINAL_KEYWORD)); fieldDeclaration.setType(ast.newPrimitiveType(PrimitiveType.LONG)); td.bodyDeclarations().add(fieldDeclaration); } }
ExceptionGenerator { @SuppressWarnings("unchecked") public void generateSerialVersionUID(Classifier clazz, AST ast, TypeDeclaration td) { VariableDeclarationFragment fragment = ast .newVariableDeclarationFragment(); SimpleName variableName = ast.newSimpleName("serialVersionUID"); fragment.setName(variableName); NumberLiteral initializer = ast.newNumberLiteral(); initializer.setToken("1L"); fragment.setInitializer(initializer); FieldDeclaration fieldDeclaration = ast.newFieldDeclaration(fragment); fieldDeclaration.modifiers().add( ast.newModifier(Modifier.ModifierKeyword.PRIVATE_KEYWORD)); fieldDeclaration.modifiers().add( ast.newModifier(Modifier.ModifierKeyword.STATIC_KEYWORD)); fieldDeclaration.modifiers().add( ast.newModifier(Modifier.ModifierKeyword.FINAL_KEYWORD)); fieldDeclaration.setType(ast.newPrimitiveType(PrimitiveType.LONG)); td.bodyDeclarations().add(fieldDeclaration); }  }
ExceptionGenerator { @SuppressWarnings("unchecked") public void generateSerialVersionUID(Classifier clazz, AST ast, TypeDeclaration td) { VariableDeclarationFragment fragment = ast .newVariableDeclarationFragment(); SimpleName variableName = ast.newSimpleName("serialVersionUID"); fragment.setName(variableName); NumberLiteral initializer = ast.newNumberLiteral(); initializer.setToken("1L"); fragment.setInitializer(initializer); FieldDeclaration fieldDeclaration = ast.newFieldDeclaration(fragment); fieldDeclaration.modifiers().add( ast.newModifier(Modifier.ModifierKeyword.PRIVATE_KEYWORD)); fieldDeclaration.modifiers().add( ast.newModifier(Modifier.ModifierKeyword.STATIC_KEYWORD)); fieldDeclaration.modifiers().add( ast.newModifier(Modifier.ModifierKeyword.FINAL_KEYWORD)); fieldDeclaration.setType(ast.newPrimitiveType(PrimitiveType.LONG)); td.bodyDeclarations().add(fieldDeclaration); }  void setCheckedException(boolean isCheckedException); CompilationUnit generateCheckedException(Classifier clazz,
			String sourceDirectoryPackageName); CompilationUnit generateUncheckedException(Classifier clazz,
			String sourceDirectoryPackageName); @SuppressWarnings("unchecked") void generateSerialVersionUID(Classifier clazz, AST ast,
			TypeDeclaration td); @SuppressWarnings("unchecked") TypeDeclaration generateClass(Classifier clazz, AST ast,
			CompilationUnit cu); void generateConstructors(Classifier clazz, AST ast,
			TypeDeclaration td); @SuppressWarnings("unchecked") void generateConstructorWithParams(Classifier clazz, AST ast,
			TypeDeclaration td, String[] varTypes, String[] varNames); }
ExceptionGenerator { @SuppressWarnings("unchecked") public void generateSerialVersionUID(Classifier clazz, AST ast, TypeDeclaration td) { VariableDeclarationFragment fragment = ast .newVariableDeclarationFragment(); SimpleName variableName = ast.newSimpleName("serialVersionUID"); fragment.setName(variableName); NumberLiteral initializer = ast.newNumberLiteral(); initializer.setToken("1L"); fragment.setInitializer(initializer); FieldDeclaration fieldDeclaration = ast.newFieldDeclaration(fragment); fieldDeclaration.modifiers().add( ast.newModifier(Modifier.ModifierKeyword.PRIVATE_KEYWORD)); fieldDeclaration.modifiers().add( ast.newModifier(Modifier.ModifierKeyword.STATIC_KEYWORD)); fieldDeclaration.modifiers().add( ast.newModifier(Modifier.ModifierKeyword.FINAL_KEYWORD)); fieldDeclaration.setType(ast.newPrimitiveType(PrimitiveType.LONG)); td.bodyDeclarations().add(fieldDeclaration); }  void setCheckedException(boolean isCheckedException); CompilationUnit generateCheckedException(Classifier clazz,
			String sourceDirectoryPackageName); CompilationUnit generateUncheckedException(Classifier clazz,
			String sourceDirectoryPackageName); @SuppressWarnings("unchecked") void generateSerialVersionUID(Classifier clazz, AST ast,
			TypeDeclaration td); @SuppressWarnings("unchecked") TypeDeclaration generateClass(Classifier clazz, AST ast,
			CompilationUnit cu); void generateConstructors(Classifier clazz, AST ast,
			TypeDeclaration td); @SuppressWarnings("unchecked") void generateConstructorWithParams(Classifier clazz, AST ast,
			TypeDeclaration td, String[] varTypes, String[] varNames);  }