added script to format source files

Change-Id: I711975c2775038910348c3729f2a7f5520c65f82
diff --git a/JavaScript Snippets/Java helpers/Format source.js b/JavaScript Snippets/Java helpers/Format source.js
new file mode 100644
index 0000000..ef10c5d
--- /dev/null
+++ b/JavaScript Snippets/Java helpers/Format source.js
@@ -0,0 +1,31 @@
+/*******************************************************************************
+ * Copyright (c) 2015 Christian Pontesegger and others. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ * 
+ * Contributors: Christian Pontesegger - initial API and implementation
+ * 
+ * name : Format source file description : Applies the current Java code
+ * formatter settings to a given source file.
+ ******************************************************************************/
+
+function formatUnitSourceCode(file) {
+	unit = org.eclipse.jdt.core.JavaCore.create(file);
+
+	unit.becomeWorkingCopy(null);
+
+	formatter = org.eclipse.jdt.core.ToolFactory.createCodeFormatter(null);
+	range = unit.getSourceRange();
+	formatEdit = formatter
+			.format(
+					org.eclipse.jdt.core.formatter.CodeFormatter.K_COMPILATION_UNIT
+							| org.eclipse.jdt.core.formatter.CodeFormatter.F_INCLUDE_COMMENTS,
+					unit.getSource(), 0, unit.getSource().length(), 0, null);
+	if (formatEdit.hasChildren()) {
+		unit.applyTextEdit(formatEdit, null);
+		unit.reconcile(org.eclipse.jdt.core.dom.AST.JLS4, false, null, null);
+	}
+
+	unit.commitWorkingCopy(true, null);
+}