summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorkthoms2009-01-20 03:35:34 (EST)
committer kthoms2009-01-20 03:35:34 (EST)
commit3d5b4e339efe24b4330fb242eaddcd714caee2d2 (patch)
tree4e0a134edab4efb267995728061f7bbef731563b
parent3fadc0517a6705ab5612029536676ee675e08923 (diff)
downloadorg.eclipse.xpand-3d5b4e339efe24b4330fb242eaddcd714caee2d2.zip
org.eclipse.xpand-3d5b4e339efe24b4330fb242eaddcd714caee2d2.tar.gz
org.eclipse.xpand-3d5b4e339efe24b4330fb242eaddcd714caee2d2.tar.bz2
Javadoc
-rw-r--r--plugins/org.eclipse.xpand/src/org/eclipse/internal/xpand2/XpandUtil.java16
-rw-r--r--plugins/org.eclipse.xpand/src/org/eclipse/xpand2/output/BlankLineSkippingOutput.java20
2 files changed, 31 insertions, 5 deletions
diff --git a/plugins/org.eclipse.xpand/src/org/eclipse/internal/xpand2/XpandUtil.java b/plugins/org.eclipse.xpand/src/org/eclipse/internal/xpand2/XpandUtil.java
index d1d3da9..24d3a6c 100644
--- a/plugins/org.eclipse.xpand/src/org/eclipse/internal/xpand2/XpandUtil.java
+++ b/plugins/org.eclipse.xpand/src/org/eclipse/internal/xpand2/XpandUtil.java
@@ -13,10 +13,10 @@ package org.eclipse.internal.xpand2;
import org.eclipse.internal.xtend.expression.parser.SyntaxConstants;
/**
- *
+ * Xpand utility class. Contains static helper methods and constants.
* @author Sven Efftinge (http://www.efftinge.de) *
*/
-public class XpandUtil {
+public final class XpandUtil {
private static final String SLASH = "/";
@@ -28,12 +28,24 @@ public class XpandUtil {
return fqn.replaceAll(NS_DELIM, SLASH) + "." + TEMPLATE_EXTENSION;
}
+ /**
+ * Returns the name without its last segment.
+ * @param fqn Qualified name (foo::bar).
+ * @return <tt>fqn</tt> without the last segment. Returns <tt>null</tt> if <tt>fqn</tt> is null
+ * or the name does not contain a qualifier ('::').
+ */
public static String withoutLastSegment(final String fqn) {
if (fqn == null || fqn.lastIndexOf(SyntaxConstants.NS_DELIM) == -1)
return null;
return fqn.substring(0, fqn.lastIndexOf(SyntaxConstants.NS_DELIM));
}
+ /**
+ * Returns the last segment of a qualified name.
+ * @param fqn Qualified name (foo::bar).
+ * @return The last segment of <tt>fqn</tt>. Returns <tt>null</tt> if <tt>fqn</tt> is null.
+ * Returns <tt>fqn</tt> if the name does not contain a qualifier ('::').
+ */
public static String getLastSegment(final String fqn) {
if (fqn == null || fqn.lastIndexOf(SyntaxConstants.NS_DELIM) == -1)
return fqn;
diff --git a/plugins/org.eclipse.xpand/src/org/eclipse/xpand2/output/BlankLineSkippingOutput.java b/plugins/org.eclipse.xpand/src/org/eclipse/xpand2/output/BlankLineSkippingOutput.java
index a914073..437a35a 100644
--- a/plugins/org.eclipse.xpand/src/org/eclipse/xpand2/output/BlankLineSkippingOutput.java
+++ b/plugins/org.eclipse.xpand/src/org/eclipse/xpand2/output/BlankLineSkippingOutput.java
@@ -18,20 +18,27 @@ import org.eclipse.xpand2.XpandExecutionContext;
/**
* This output implementation avoids writing of unnecessary blank lines.
* @author Karsten Thoms
- * @since 4.1.2
*/
public class BlankLineSkippingOutput extends OutputImpl {
private final static char NEWLINE = '\n';
private StringBuffer buffer = null;
+
private boolean evaluateLine = false;
+
+ /**
+ * {@inheritDoc}
+ */
public void write(final String bytes) {
if (current() != null) {
int idxNL = bytes.indexOf(NEWLINE);
- if (buffer==null && idxNL>=0) {
+ if (buffer==null && idxNL>=0) { // No buffer yet; String contains newline
buffer = new StringBuffer();
+ // append string until the newline character
((StringBuffer) current().getBuffer()).append(bytes.substring(0, idxNL));
+ // append the rest
if (idxNL<bytes.length()) buffer.append(bytes.substring(idxNL));
- } else if (buffer!=null && idxNL>=0) {
+ } else if (buffer!=null && idxNL>=0) { // buffer exists; String contains newline
+ // append string until the newline character
buffer.append(bytes.substring(0, idxNL));
if (evaluateLine && !buffer.toString().trim().equals("")) {
((StringBuffer) current().getBuffer()).append (buffer.toString());
@@ -40,14 +47,21 @@ public class BlankLineSkippingOutput extends OutputImpl {
evaluateLine = false;
if (idxNL<bytes.length()) write(bytes.substring(idxNL));
} else if (buffer!=null) {
+ // String does not contain newline, so just append
buffer.append(bytes);
} else {
+ // we are not buffering yet and string does not contain newlines, so just
+ // append the string to the original output buffer
((StringBuffer) current().getBuffer()).append(bytes);
}
}
}
+ /**
+ * {@inheritDoc}
+ */
public void closeFile() {
+ // append the buffer
if (buffer!=null && current()!=null) {
((StringBuffer) current().getBuffer()).append(buffer);
buffer=null;