Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian Pontesegger2015-02-22 19:09:16 +0000
committerChristian Pontesegger2015-02-22 19:09:16 +0000
commit1afe0914b3bb04622284020045992647c603c3aa (patch)
tree2bfe4070a5aff3196bd7bf13ad02fede82b5530f
parenteb5212ea41f506d4f8426edc3b24a01b7bc8153d (diff)
downloadorg.eclipse.ease.scripts-ease-0.2.x.tar.gz
org.eclipse.ease.scripts-ease-0.2.x.tar.xz
org.eclipse.ease.scripts-ease-0.2.x.zip
added script to format source filesease_0.2.0ease-0.2.x
-rw-r--r--JavaScript Snippets/Java helpers/Format source.js31
1 files changed, 31 insertions, 0 deletions
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);
+}

Back to the top