Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorpelder2009-04-13 13:22:07 -0400
committerpelder2009-04-13 13:22:07 -0400
commit44f59b38e6f80ae3240f7d99c231d51d70fe9557 (patch)
tree05976a1523da285c1c6d7580c402f7406f01c064
parent793ed28d9476395ec60026f423fcf2911eb22123 (diff)
downloadorg.eclipse.jet-44f59b38e6f80ae3240f7d99c231d51d70fe9557.tar.gz
org.eclipse.jet-44f59b38e6f80ae3240f7d99c231d51d70fe9557.tar.xz
org.eclipse.jet-44f59b38e6f80ae3240f7d99c231d51d70fe9557.zip
[272045] f:indent tag looses information on user-regions embedded with in it
-rw-r--r--plugins/org.eclipse.jet/plugin.xml5
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/internal/compiler/V2CodeGenVisitor.java54
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/format/IndentTag.java82
3 files changed, 76 insertions, 65 deletions
diff --git a/plugins/org.eclipse.jet/plugin.xml b/plugins/org.eclipse.jet/plugin.xml
index b152912..222cf29 100644
--- a/plugins/org.eclipse.jet/plugin.xml
+++ b/plugins/org.eclipse.jet/plugin.xml
@@ -1039,10 +1039,11 @@ This tag may occur only once in a template.
</attribute>
<description>Formats and writes out the current date and time</description>
</emptyTag>
- <functionTag
+ <containerTag
allowAsEmpty="false"
class="org.eclipse.jet.internal.taglib.format.IndentTag"
name="indent"
+ processContents="custom"
whenContainingLineIsEmpty="remove">
<description>
Indent the tag contents the specified number of times.
@@ -1063,7 +1064,7 @@ This tag may occur only once in a template.
Specifies the indentation text.
</description>
</attribute>
- </functionTag><functionTag class="org.eclipse.jet.internal.taglib.format.LowerCaseTag" name="lc">
+ </containerTag><functionTag class="org.eclipse.jet.internal.taglib.format.LowerCaseTag" name="lc">
<attribute name="offset" use="optional">
<description>
The starting offset (0-based) of the conversion. When omitted, 0 (the start of the content to be converted) is assumed.
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/compiler/V2CodeGenVisitor.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/compiler/V2CodeGenVisitor.java
index 6c5c10f..4f7c1fe 100644
--- a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/compiler/V2CodeGenVisitor.java
+++ b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/compiler/V2CodeGenVisitor.java
@@ -1,7 +1,7 @@
/**
* <copyright>
*
- * Copyright (c) 2007 IBM Corporation and others.
+ * Copyright (c) 2007, 2009 IBM Corporation 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
@@ -12,7 +12,7 @@
*
* </copyright>
*
- * $Id: V2CodeGenVisitor.java,v 1.3 2008/05/22 15:07:11 pelder Exp $
+ * $Id: V2CodeGenVisitor.java,v 1.4 2009/04/13 17:22:07 pelder Exp $
*/
package org.eclipse.jet.internal.compiler;
@@ -25,7 +25,6 @@ import org.eclipse.jet.core.parser.ast.JETASTElement;
import org.eclipse.jet.core.parser.ast.TextElement;
import org.eclipse.jet.core.parser.ast.XMLElement;
import org.eclipse.jet.internal.JavaUtil;
-import org.eclipse.jet.internal.taglib.format.IndentTag;
/**
* AST Visitor used by code generation
@@ -133,6 +132,7 @@ public class V2CodeGenVisitor extends SafeJETASTVisitor
private static final String NL_REGEX = "([\\n][\\r]?|[\\r][\\n]?)"; //$NON-NLS-1$
private static final Pattern NL_PATTERN = Pattern.compile(NL_REGEX, Pattern.MULTILINE);
+ private static final String NL = System.getProperty("line.separator"); //$NON-NLS-1$
protected boolean isClassComment(String comment) {
final String text = getFirstCommentLine(comment);
@@ -153,7 +153,7 @@ public class V2CodeGenVisitor extends SafeJETASTVisitor
if(!isNormalComment(text)) {
text = text.replaceFirst("(?ms)^.*?$.*?^", ""); //$NON-NLS-1$ //$NON-NLS-2$
}
- return IndentTag.indent(text, leadIn, 1);
+ return indent(text, leadIn, 1);
}
private String getFirstCommentLine(String text)
@@ -169,4 +169,50 @@ public class V2CodeGenVisitor extends SafeJETASTVisitor
return firstLine;
}
+ public static String indent(String content, String indent, int depth) {
+ final String totalIndent = computeTotalIndent(indent, depth);
+ if(totalIndent.length() == 0) {
+ return content;
+ }
+ boolean indentIsWhitespace = totalIndent.matches("\\s*"); //$NON-NLS-1$
+
+ final Matcher matcher = NL_PATTERN.matcher(content);
+ final StringBuffer result = new StringBuffer(content.length() * 2); // a guess
+ int lineStart;
+ for(lineStart = 0; matcher.find(lineStart); lineStart = matcher.end()) {
+ String line = content.substring(lineStart, matcher.start());
+ if(line.length() > 0 || !indentIsWhitespace) {
+ result.append(totalIndent);
+ }
+ result.append(line);
+ result.append(NL);
+ lineStart = matcher.end();
+ }
+
+ // look for final line without a NL character...
+ if(lineStart < content.length()) {
+ String line = content.substring(lineStart);
+ result.append(totalIndent).append(line).append(NL);
+ }
+
+ return result.toString();
+ }
+
+ /**
+ * @param indent
+ * @param depth
+ * @return
+ */
+ private static String computeTotalIndent(String indent, int depth)
+ {
+ final StringBuffer buffer = new StringBuffer(
+ depth * indent.length()
+ );
+ if(indent != null) {
+ for(int i = 0; i < depth; i++) {
+ buffer.append(indent);
+ }
+ }
+ return buffer.toString();
+ }
}
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/format/IndentTag.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/format/IndentTag.java
index b495515..3d863a4 100644
--- a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/format/IndentTag.java
+++ b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/format/IndentTag.java
@@ -1,7 +1,7 @@
/**
* <copyright>
*
- * Copyright (c) 2008 IBM Corporation and others.
+ * Copyright (c) 2008, 2009 IBM Corporation 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
@@ -12,16 +12,16 @@
*
* </copyright>
*
- * $Id: IndentTag.java,v 1.2 2008/05/22 15:07:11 pelder Exp $
+ * $Id: IndentTag.java,v 1.3 2009/04/13 17:22:07 pelder Exp $
*/
package org.eclipse.jet.internal.taglib.format;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-
+import org.eclipse.jet.BufferedJET2Writer;
import org.eclipse.jet.JET2Context;
+import org.eclipse.jet.JET2Writer;
import org.eclipse.jet.internal.l10n.JET2Messages;
-import org.eclipse.jet.taglib.AbstractFunctionTag;
+import org.eclipse.jet.internal.taglib.DocumentHelper;
+import org.eclipse.jet.taglib.AbstractContainerTag;
import org.eclipse.jet.taglib.JET2TagException;
import org.eclipse.jet.taglib.TagInfo;
import org.eclipse.osgi.util.NLS;
@@ -29,77 +29,41 @@ import org.eclipse.osgi.util.NLS;
/**
* Implement &lt;f:indent text="..." [depth="n"]&gt;content&lt;/f:indent&gt;
*/
-public class IndentTag extends AbstractFunctionTag
+public class IndentTag extends AbstractContainerTag
{
private static final String TEXT_ATTR = "text"; //$NON-NLS-1$
private static final String DEPTH_ATTR = "depth"; //$NON-NLS-1$
- private static final String NL_REGEX = "([\\n][\\r]?|[\\r][\\n]?)"; //$NON-NLS-1$
- private static final Pattern NL_PATTERN = Pattern.compile(NL_REGEX, Pattern.MULTILINE);
- private static final String NL = System.getProperty("line.separator"); //$NON-NLS-1$
+
+ public void doBeforeBody(TagInfo td, JET2Context context, JET2Writer out) throws JET2TagException
+ {
+ // do nothing
+ }
+
- /* (non-Javadoc)
- * @see org.eclipse.jet.taglib.FunctionTag#doFunction(org.eclipse.jet.taglib.TagInfo, org.eclipse.jet.JET2Context, java.lang.String)
- */
- public String doFunction(TagInfo td, JET2Context context, String bodyContent) throws JET2TagException
+ public void setBodyContent(JET2Writer bodyContent)
{
final String indentText = getAttribute(TEXT_ATTR);
final String depthValue = getAttribute(DEPTH_ATTR);
try
{
final int depth = depthValue == null ? 1 : Integer.decode(depthValue).intValue();
- return indent(bodyContent, indentText, depth);
+ DocumentHelper.indent((BufferedJET2Writer)bodyContent, depth, indentText);
+
}
catch (NumberFormatException e)
{
throw new JET2TagException(NLS.bind(JET2Messages.IndentTag_AttributeValueMustBeInteger, DEPTH_ATTR, depthValue));
}
- }
-
- public static String indent(String content, String indent, int depth) {
- final String totalIndent = computeTotalIndent(indent, depth);
- if(totalIndent.length() == 0) {
- return content;
- }
- boolean indentIsWhitespace = totalIndent.matches("\\s*"); //$NON-NLS-1$
-
- final Matcher matcher = NL_PATTERN.matcher(content);
- final StringBuffer result = new StringBuffer(content.length() * 2); // a guess
- int lineStart;
- for(lineStart = 0; matcher.find(lineStart); lineStart = matcher.end()) {
- String line = content.substring(lineStart, matcher.start());
- if(line.length() > 0 || !indentIsWhitespace) {
- result.append(totalIndent);
- }
- result.append(line);
- result.append(NL);
- lineStart = matcher.end();
+ finally {
+ super.setBodyContent(bodyContent);
}
-
- // look for final line without a NL character...
- if(lineStart < content.length()) {
- String line = content.substring(lineStart);
- result.append(totalIndent).append(line).append(NL);
- }
-
- return result.toString();
}
-
- /**
- * @param indent
- * @param depth
- * @return
- */
- private static String computeTotalIndent(String indent, int depth)
+
+ public void doAfterBody(TagInfo td, JET2Context context, JET2Writer out) throws JET2TagException
{
- final StringBuffer buffer = new StringBuffer(
- depth * indent.length()
- );
- if(indent != null) {
- for(int i = 0; i < depth; i++) {
- buffer.append(indent);
- }
- }
- return buffer.toString();
+ // do nothing
}
+
+
}

Back to the top