Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTran Le2012-10-29 18:25:30 +0000
committerTran Le2012-10-29 18:25:30 +0000
commite6008d071075605bd63684be308b41229baa2c6e (patch)
treee39255b404be5633353a4e9cc919e956b73fdc5c /common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common
parent57b6dcc572d02bcd9303526050ac36fbed0c27ae (diff)
downloadwebtools.dali-e6008d071075605bd63684be308b41229baa2c6e.tar.gz
webtools.dali-e6008d071075605bd63684be308b41229baa2c6e.tar.xz
webtools.dali-e6008d071075605bd63684be308b41229baa2c6e.zip
389940 - Metamodel generation should use appropriate text file line
delimiters
Diffstat (limited to 'common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common')
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/io/IndentingPrintWriter.java20
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/io/JptPrintWriter.java58
2 files changed, 72 insertions, 6 deletions
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/io/IndentingPrintWriter.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/io/IndentingPrintWriter.java
index 06cfbdf396..d42d789f7f 100644
--- a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/io/IndentingPrintWriter.java
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/io/IndentingPrintWriter.java
@@ -9,11 +9,11 @@
******************************************************************************/
package org.eclipse.jpt.common.utility.io;
-import java.io.PrintWriter;
import java.io.Writer;
+import org.eclipse.jpt.common.utility.internal.StringTools;
/**
- * Extend {@link PrintWriter} to automatically indent new lines.
+ * Extend {@link JptPrintWriter} to automatically indent new lines.
* <p>
* Provisional API: This interface is part of an interim API that is still
* under development and expected to change significantly before reaching
@@ -22,7 +22,7 @@ import java.io.Writer;
* will almost certainly be broken (repeatedly) as the API evolves.
*/
public class IndentingPrintWriter
- extends PrintWriter
+ extends JptPrintWriter
{
private final String indent;
private int indentLevel;
@@ -35,14 +35,18 @@ public class IndentingPrintWriter
* Construct a writer that indents with tabs.
*/
public IndentingPrintWriter(Writer out) {
- this(out, DEFAULT_INDENT);
+ this(out, DEFAULT_INDENT, StringTools.CR);
}
/**
* Construct a writer that indents with the specified string.
*/
public IndentingPrintWriter(Writer out, String indent) {
- this(out, indent, 0);
+ this(out, indent, 0, StringTools.CR);
+ }
+
+ public IndentingPrintWriter(Writer out, String indent, String lineSeparator) {
+ this(out, indent, 0, lineSeparator);
}
/**
@@ -50,7 +54,11 @@ public class IndentingPrintWriter
* and begins with the specified indent level.
*/
public IndentingPrintWriter(Writer out, String indent, int initialIndentLevel) {
- super(out);
+ this(out, indent, initialIndentLevel, StringTools.CR);
+ }
+
+ public IndentingPrintWriter(Writer out, String indent, int initialIndentLevel, String lineSeparator) {
+ super(out, lineSeparator);
if (indent == null) {
throw new NullPointerException();
}
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/io/JptPrintWriter.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/io/JptPrintWriter.java
new file mode 100644
index 0000000000..9973fdb71a
--- /dev/null
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/io/JptPrintWriter.java
@@ -0,0 +1,58 @@
+/*******************************************************************************
+ * Copyright (c) 2012 Oracle. 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:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.common.utility.io;
+
+import java.io.IOException;
+import java.io.InterruptedIOException;
+import java.io.PrintWriter;
+import java.io.Writer;
+import org.eclipse.jpt.common.utility.internal.StringTools;
+
+/**
+ * Extend {@link PrintWriter} to give the option to select a line separator.
+ * <p>
+ * Provisional API: This interface is part of an interim API that is still
+ * under development and expected to change significantly before reaching
+ * stability. It is available at this early stage to solicit feedback from
+ * pioneering adopters on the understanding that any code that uses this API
+ * will almost certainly be broken (repeatedly) as the API evolves.
+ */
+public class JptPrintWriter
+ extends PrintWriter
+{
+ private String lineSeparator;
+
+ public JptPrintWriter(Writer out) {
+ this(out, StringTools.CR); // use system property by default
+ }
+
+ public JptPrintWriter(Writer out, String lineSeparator) {
+ super(out);
+ this.lineSeparator = lineSeparator;
+ }
+
+ @Override
+ public void println() {
+ try {
+ synchronized (this.lock) {
+ if (this.out == null) {
+ throw new IOException("Stream closed"); //$NON-NLS-1$
+ }
+ this.out.write(this.lineSeparator);
+ }
+ }
+ catch (InterruptedIOException e) {
+ Thread.currentThread().interrupt();
+ }
+ catch (IOException e) {
+ this.setError();
+ }
+ }
+}

Back to the top