[102495] JSP Formatter Adds Significant Whitespace
diff --git a/bundles/org.eclipse.jst.jsp.core/src/org/eclipse/jst/jsp/core/internal/java/JSPTranslationUtil.java b/bundles/org.eclipse.jst.jsp.core/src/org/eclipse/jst/jsp/core/internal/java/JSPTranslationUtil.java
index a791ece..2d72c36 100644
--- a/bundles/org.eclipse.jst.jsp.core/src/org/eclipse/jst/jsp/core/internal/java/JSPTranslationUtil.java
+++ b/bundles/org.eclipse.jst.jsp.core/src/org/eclipse/jst/jsp/core/internal/java/JSPTranslationUtil.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2004, 2006 IBM Corporation and others.
+ * Copyright (c) 2004, 2007 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,6 +12,7 @@
import org.eclipse.jdt.core.ICompilationUnit;
import org.eclipse.jface.text.IDocument;
+import org.eclipse.jst.jsp.core.internal.modelhandler.ModelHandlerForJSP;
import org.eclipse.text.edits.CopySourceEdit;
import org.eclipse.text.edits.CopyTargetEdit;
import org.eclipse.text.edits.DeleteEdit;
@@ -96,6 +97,7 @@
public JSPTranslationExtension getTranslation() {
if (fTranslation == null) {
IDOMModel xmlModel = (IDOMModel) getModelManager().getExistingModelForRead(fDocument);
+ ModelHandlerForJSP.ensureTranslationAdapterFactory(xmlModel);
try {
IDOMDocument xmlDoc = xmlModel.getDocument();
diff --git a/bundles/org.eclipse.wst.html.core/src/org/eclipse/wst/html/core/internal/format/HTMLFormatter.java b/bundles/org.eclipse.wst.html.core/src/org/eclipse/wst/html/core/internal/format/HTMLFormatter.java
index ba00f0b..f7b0012 100644
--- a/bundles/org.eclipse.wst.html.core/src/org/eclipse/wst/html/core/internal/format/HTMLFormatter.java
+++ b/bundles/org.eclipse.wst.html.core/src/org/eclipse/wst/html/core/internal/format/HTMLFormatter.java
@@ -32,6 +32,7 @@
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
+import org.w3c.dom.Text;
public class HTMLFormatter implements IStructuredFormatter {
@@ -96,6 +97,42 @@
return false;
Node next = node.getNextSibling();
+ // special exception if this node is a non-HTML tag (like JSP
+ // elements)
+ if (node.getPrefix() != null) {
+ boolean canInsertBreakBefore = false;
+ // if a whitespace does not exist after it, do not add one
+ if (next != null && next.getNodeType() == Node.TEXT_NODE) {
+ String theText = ((Text) next).getData();
+ if (theText != null && theText.length() > 0) {
+ char theChar = theText.charAt(0);
+ canInsertBreakBefore = Character.isWhitespace(theChar);
+ }
+ }
+ // if cannot insert break, go ahead and return false (otherwise,
+ // continue processing)
+ if (!canInsertBreakBefore)
+ return canInsertBreakBefore;
+ }
+
+ // special exception if next node is a non-HTML tag (like JSP
+ // elements)
+ if (next != null && next.getPrefix() != null) {
+ boolean canInsertBreakBefore = false;
+ // if a whitespace does not exist before it, do not add one
+ if (node.getNodeType() == Node.TEXT_NODE) {
+ String theText = ((Text) node).getData();
+ if (theText != null && theText.length() > 0) {
+ char theChar = theText.charAt(theText.length() - 1);
+ canInsertBreakBefore = Character.isWhitespace(theChar);
+ }
+ }
+ // if cannot insert break, go ahead and return false (otherwise,
+ // continue processing)
+ if (!canInsertBreakBefore)
+ return canInsertBreakBefore;
+ }
+
if (parent.getNodeType() == Node.DOCUMENT_NODE) {
if (node.getNodeType() == Node.ELEMENT_NODE) {
// do not insert break after unclosed tag
@@ -165,6 +202,42 @@
return false;
Node prev = node.getPreviousSibling();
+ // special exception if this node is a non-HTML tag (like JSP
+ // elements)
+ if (node.getPrefix() != null) {
+ boolean canInsertBreakBefore = false;
+ // if a whitespace does not exist before it, do not add one
+ if (prev != null && prev.getNodeType() == Node.TEXT_NODE) {
+ String theText = ((Text) prev).getData();
+ if (theText != null && theText.length() > 0) {
+ char theChar = theText.charAt(theText.length() - 1);
+ canInsertBreakBefore = Character.isWhitespace(theChar);
+ }
+ }
+ // if cannot insert break, go ahead and return false (otherwise,
+ // continue processing)
+ if (!canInsertBreakBefore)
+ return canInsertBreakBefore;
+ }
+
+ // special exception if previous node is a non-HTML tag (like JSP
+ // elements)
+ if (prev != null && prev.getPrefix() != null) {
+ boolean canInsertBreakBefore = false;
+ // if a whitespace does not exist after it, do not add one
+ if (node.getNodeType() == Node.TEXT_NODE) {
+ String theText = ((Text) node).getData();
+ if (theText != null && theText.length() > 0) {
+ char theChar = theText.charAt(0);
+ canInsertBreakBefore = Character.isWhitespace(theChar);
+ }
+ }
+ // if cannot insert break, go ahead and return false (otherwise,
+ // continue processing)
+ if (!canInsertBreakBefore)
+ return canInsertBreakBefore;
+ }
+
if (parent.getNodeType() == Node.DOCUMENT_NODE) {
if (prev == null)
return false;