[195264] Add formatter preference to close tags without space before '/>'
diff --git a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/formatter/DefaultXMLPartitionFormatter.java b/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/formatter/DefaultXMLPartitionFormatter.java
index 0c64fd9..a09a4e0 100644
--- a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/formatter/DefaultXMLPartitionFormatter.java
+++ b/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/formatter/DefaultXMLPartitionFormatter.java
@@ -801,7 +801,8 @@
deleteTrailingSpaces(textEdit, currentTextRegion, currentDocumentRegion);
availableLineWidth -= (currentTextRegion.getTextLength() + 2);
}
- else {
+ // insert a space and collapse ONLY IF it's specified
+ else if (oneSpaceInTagName) {
insertSpaceAndCollapse(textEdit, currentDocumentRegion, availableLineWidth, currentTextRegion);
availableLineWidth -= (currentTextRegion.getTextLength() + 3);
}
@@ -1229,12 +1230,17 @@
// it
// out.
- //BUG214516 - Fixed NPE that was causing document formatting to fail if
- // an xml:space="preserve" attribute was found
+ //BUG214516/196544 - Fixed NPE that was caused by an attr having
+ // a null attr type
String defaultValue = null;
-
- if(attributeDeclaration.getAttrType() != null)
- defaultValue = attributeDeclaration.getAttrType().getImpliedValue();
+ CMDataType attrType = attributeDeclaration.getAttrType();
+ if(attrType != null) {
+ if((attrType.getImpliedValueKind() != CMDataType.IMPLIED_VALUE_NONE) && attrType.getImpliedValue() != null)
+ defaultValue = attrType.getImpliedValue();
+ else if ((attrType.getEnumeratedValues() != null) && (attrType.getEnumeratedValues().length > 0)) {
+ defaultValue = attrType.getEnumeratedValues()[0];
+ }
+ }
// xml:space="preserve" means preserve
// space,
diff --git a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/formatter/XMLFormattingPreferences.java b/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/formatter/XMLFormattingPreferences.java
index 81db640..93a3896 100644
--- a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/formatter/XMLFormattingPreferences.java
+++ b/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/formatter/XMLFormattingPreferences.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007 IBM Corporation and others.
+ * Copyright (c) 2007, 2008 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
@@ -42,7 +42,8 @@
setMaxLineWidth(preferences.getInt(XMLCorePreferenceNames.LINE_WIDTH));
setIndentMultipleAttributes(preferences.getBoolean(XMLCorePreferenceNames.SPLIT_MULTI_ATTRS));
setAlignFinalBracket(preferences.getBoolean(XMLCorePreferenceNames.ALIGN_END_BRACKET));
-
+ setSpaceBeforeEmptyCloseTag(preferences.getBoolean(XMLCorePreferenceNames.SPACE_BEFORE_EMPTY_CLOSE_TAG));
+
boolean preservepcdata = preferences.getBoolean(XMLCorePreferenceNames.PRESERVE_CDATACONTENT);
if (preservepcdata)
fPCDataWhitespaceStrategy = XMLFormattingPreferences.PRESERVE;
@@ -75,7 +76,7 @@
public boolean getSpaceBeforeEmptyCloseTag() {
return fSpaceBeforeEmptyCloseTag;
}
-
+
public boolean getIndentMultipleAttributes() {
return fIndentMultipleAttributes;
}
@@ -99,6 +100,10 @@
public String getElementWhitespaceStrategy() {
return fElementWhitespaceStrategy;
}
+
+ public void setSpaceBeforeEmptyCloseTag(boolean spaceBeforeEmptyCloseTag) {
+ fSpaceBeforeEmptyCloseTag = spaceBeforeEmptyCloseTag;
+ }
public void setIndentMultipleAttributes(boolean indentMultipleAttributes) {
fIndentMultipleAttributes = indentMultipleAttributes;
diff --git a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/preferences/XMLCorePreferenceInitializer.java b/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/preferences/XMLCorePreferenceInitializer.java
index e92287d..39d88f9 100644
--- a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/preferences/XMLCorePreferenceInitializer.java
+++ b/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/preferences/XMLCorePreferenceInitializer.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2005, 2007 IBM Corporation and others.
+ * Copyright (c) 2005, 2008 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
@@ -37,7 +37,8 @@
node.putBoolean(XMLCorePreferenceNames.SPLIT_MULTI_ATTRS, false);
node.putBoolean(XMLCorePreferenceNames.ALIGN_END_BRACKET, false);
node.putBoolean(XMLCorePreferenceNames.PRESERVE_CDATACONTENT, false);
-
+ node.putBoolean(XMLCorePreferenceNames.SPACE_BEFORE_EMPTY_CLOSE_TAG, true);
+
// cleanup preferences
node.putBoolean(XMLCorePreferenceNames.COMPRESS_EMPTY_ELEMENT_TAGS, true);
node.putBoolean(XMLCorePreferenceNames.INSERT_REQUIRED_ATTRS, true);
diff --git a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/preferences/XMLCorePreferenceNames.java b/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/preferences/XMLCorePreferenceNames.java
index 41d7b30..7e5b13e 100644
--- a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/preferences/XMLCorePreferenceNames.java
+++ b/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/preferences/XMLCorePreferenceNames.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2005, 2007 IBM Corporation and others.
+ * Copyright (c) 2005, 2008 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
@@ -180,4 +180,13 @@
* </p>
*/
public static final String ALIGN_END_BRACKET = "alignEndBracket";//$NON-NLS-1$
+
+ /**
+ * Indicates if an empty close tag should have a space inserted before
+ * closing.
+ * <p>
+ * Value is of type <code>Boolean</code>
+ * </p>
+ */
+ public static final String SPACE_BEFORE_EMPTY_CLOSE_TAG = "spaceBeforeEmptyCloseTag";//$NON-NLS-1$
}
diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/XMLUIMessages.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/XMLUIMessages.java
index a583891..22e93e8 100644
--- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/XMLUIMessages.java
+++ b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/XMLUIMessages.java
@@ -1,5 +1,5 @@
/**********************************************************************
- * Copyright (c) 2005, 2007 IBM Corporation and others. All rights reserved. This
+ * Copyright (c) 2005, 2008 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 http://www.eclipse.org/legal/epl-v10.html
@@ -225,6 +225,7 @@
public static String Split_multiple_attributes;
public static String Align_final_bracket;
public static String Preserve_PCDATA_Content;
+ public static String Space_before_empty_close_tag;
public static String Indent_using_tabs;
public static String Indent_using_spaces;
public static String Indentation_size;
diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/XMLUIPluginResources.properties b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/XMLUIPluginResources.properties
index 27a01d0..fade2ff 100644
--- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/XMLUIPluginResources.properties
+++ b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/XMLUIPluginResources.properties
@@ -1,5 +1,5 @@
###############################################################################
-# Copyright (c) 2001, 2007 IBM Corporation and others.
+# Copyright (c) 2001, 2008 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
@@ -255,6 +255,7 @@
Split_multiple_attributes=Split &multiple attributes each on a new line
Align_final_bracket=&Align final bracket in multi-line element tags
Preserve_PCDATA_Content=&Preserve whitespace in tags with PCDATA content
+Space_before_empty_close_tag=Ins&ert whitespace before closing empty end-tags
Indent_using_tabs=&Indent using tabs
Indent_using_spaces=I&ndent using spaces
Indentation_size=In&dentation size:
diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/preferences/XMLSourcePreferencePage.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/preferences/XMLSourcePreferencePage.java
index 06e7340..db51310 100644
--- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/preferences/XMLSourcePreferencePage.java
+++ b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/preferences/XMLSourcePreferencePage.java
@@ -61,6 +61,8 @@
private Spinner fIndentationSize;
private Button fPreservePCDATAContent;
private Button fAlignEndBracket;
+ // BUG195264 - Support for removing/adding a space before empty close tags
+ private Button fSpaceBeforeEmptyCloseTag;
// grammar constraints
protected Button fUseInferredGrammar;
@@ -122,7 +124,9 @@
((GridData) fPreservePCDATAContent.getLayoutData()).horizontalSpan = 2;
fClearAllBlankLines = createCheckBox(formattingGroup, XMLUIMessages.Clear_all_blank_lines_UI_);
((GridData) fClearAllBlankLines.getLayoutData()).horizontalSpan = 2;
-
+ fSpaceBeforeEmptyCloseTag = createCheckBox(formattingGroup, XMLUIMessages.Space_before_empty_close_tag);
+ ((GridData) fSpaceBeforeEmptyCloseTag.getLayoutData()).horizontalSpan = 2;
+
fIndentUsingTabs = createRadioButton(formattingGroup, XMLUIMessages.Indent_using_tabs);
((GridData) fIndentUsingTabs.getLayoutData()).horizontalSpan = 2;
@@ -214,7 +218,8 @@
fAlignEndBracket.setSelection(getModelPreferences().getBoolean(XMLCorePreferenceNames.ALIGN_END_BRACKET));
fClearAllBlankLines.setSelection(getModelPreferences().getBoolean(XMLCorePreferenceNames.CLEAR_ALL_BLANK_LINES));
fPreservePCDATAContent.setSelection(getModelPreferences().getBoolean(XMLCorePreferenceNames.PRESERVE_CDATACONTENT));
-
+ fSpaceBeforeEmptyCloseTag.setSelection(getModelPreferences().getBoolean(XMLCorePreferenceNames.SPACE_BEFORE_EMPTY_CLOSE_TAG));
+
if (XMLCorePreferenceNames.TAB.equals(getModelPreferences().getString(XMLCorePreferenceNames.INDENTATION_CHAR))) {
fIndentUsingTabs.setSelection(true);
fIndentUsingSpaces.setSelection(false);
@@ -262,7 +267,9 @@
fAlignEndBracket.setSelection(getModelPreferences().getDefaultBoolean(XMLCorePreferenceNames.ALIGN_END_BRACKET));
fClearAllBlankLines.setSelection(getModelPreferences().getDefaultBoolean(XMLCorePreferenceNames.CLEAR_ALL_BLANK_LINES));
fPreservePCDATAContent.setSelection(getModelPreferences().getDefaultBoolean(XMLCorePreferenceNames.PRESERVE_CDATACONTENT));
-
+ // BUG195264 - Support for removing/adding a space before empty close tags
+ fSpaceBeforeEmptyCloseTag.setSelection(getModelPreferences().getDefaultBoolean(XMLCorePreferenceNames.SPACE_BEFORE_EMPTY_CLOSE_TAG));
+
if (XMLCorePreferenceNames.TAB.equals(getModelPreferences().getDefaultString(XMLCorePreferenceNames.INDENTATION_CHAR))) {
fIndentUsingTabs.setSelection(true);
fIndentUsingSpaces.setSelection(false);
@@ -322,7 +329,9 @@
getModelPreferences().setValue(XMLCorePreferenceNames.ALIGN_END_BRACKET, fAlignEndBracket.getSelection());
getModelPreferences().setValue(XMLCorePreferenceNames.CLEAR_ALL_BLANK_LINES, fClearAllBlankLines.getSelection());
getModelPreferences().setValue(XMLCorePreferenceNames.PRESERVE_CDATACONTENT, fPreservePCDATAContent.getSelection());
-
+ // BUG195264 - Support for removing/adding a space before empty close tags
+ getModelPreferences().setValue(XMLCorePreferenceNames.SPACE_BEFORE_EMPTY_CLOSE_TAG, fSpaceBeforeEmptyCloseTag.getSelection());
+
if (fIndentUsingTabs.getSelection()) {
getModelPreferences().setValue(XMLCorePreferenceNames.INDENTATION_CHAR, XMLCorePreferenceNames.TAB);
}