Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 115716 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/wst/xml/core/internal/provisional/format/NodeFormatter.java (-9 / +19 lines)
Lines 161-167 Link Here
161
161
162
	protected void formatIndentationAfterNode(IDOMNode node, IStructuredFormatContraints formatContraints) {
162
	protected void formatIndentationAfterNode(IDOMNode node, IStructuredFormatContraints formatContraints) {
163
		// [111674] If inside xml:space="preserve" element, we bail
163
		// [111674] If inside xml:space="preserve" element, we bail
164
		if (formatContraints.getInPreserveSpaceElement()) return;
164
		if (formatContraints.getInPreserveSpaceElement())
165
			return;
165
		if (node != null) {
166
		if (node != null) {
166
			IDOMNode nextSibling = (IDOMNode) node.getNextSibling();
167
			IDOMNode nextSibling = (IDOMNode) node.getNextSibling();
167
			IStructuredDocument doc = node.getModel().getStructuredDocument();
168
			IStructuredDocument doc = node.getModel().getStructuredDocument();
Lines 169-181 Link Here
169
			String lineDelimiter = doc.getLineDelimiter();
170
			String lineDelimiter = doc.getLineDelimiter();
170
			try {
171
			try {
171
				lineDelimiter = doc.getLineDelimiter(line);
172
				lineDelimiter = doc.getLineDelimiter(line);
172
				if (lineDelimiter == null)
173
					lineDelimiter = ""; //$NON-NLS-1$
174
			}
173
			}
175
			catch (BadLocationException e) {
174
			catch (BadLocationException e) {
176
				// log for now, unless we find reason not to
175
				// log for now, unless we find reason not to
177
				Logger.log(Logger.INFO, e.getMessage());
176
				Logger.log(Logger.INFO, e.getMessage());
178
			}
177
			}
178
			// BUG115716: if cannot get line delimiter from current line, just
179
			// use default line delimiter
180
			if (lineDelimiter == null)
181
				lineDelimiter = doc.getLineDelimiter();
179
182
180
			if (node.getParentNode() != null) {
183
			if (node.getParentNode() != null) {
181
				if (node.getParentNode().getNodeType() == Node.DOCUMENT_NODE)
184
				if (node.getParentNode().getNodeType() == Node.DOCUMENT_NODE)
Lines 232-239 Link Here
232
								insertAfterNode(lastChild, lineDelimiter + lineIndent);
235
								insertAfterNode(lastChild, lineDelimiter + lineIndent);
233
							}
236
							}
234
						else {
237
						else {
235
							// append indentation
238
							// as long as not at the end of the document
236
							insertAfterNode(lastChild, lineDelimiter + lineIndent);
239
							IStructuredDocumentRegion endRegion = node.getLastStructuredDocumentRegion();
240
							if (endRegion != null && endRegion.getNext() != null)
241
								// append indentation
242
								insertAfterNode(lastChild, lineDelimiter + lineIndent);
237
						}
243
						}
238
					}
244
					}
239
				}
245
				}
Lines 243-249 Link Here
243
249
244
	protected void formatIndentationBeforeNode(IDOMNode node, IStructuredFormatContraints formatContraints) {
250
	protected void formatIndentationBeforeNode(IDOMNode node, IStructuredFormatContraints formatContraints) {
245
		// [111674] If inside xml:space="preserve" element, we bail
251
		// [111674] If inside xml:space="preserve" element, we bail
246
		if (formatContraints.getInPreserveSpaceElement()) return;
252
		if (formatContraints.getInPreserveSpaceElement())
253
			return;
247
		if (node != null) {
254
		if (node != null) {
248
			IDOMNode previousSibling = (IDOMNode) node.getPreviousSibling();
255
			IDOMNode previousSibling = (IDOMNode) node.getPreviousSibling();
249
			IStructuredDocument doc = node.getModel().getStructuredDocument();
256
			IStructuredDocument doc = node.getModel().getStructuredDocument();
Lines 252-265 Link Here
252
			try {
259
			try {
253
				if (line > 0) {
260
				if (line > 0) {
254
					lineDelimiter = doc.getLineDelimiter(line - 1);
261
					lineDelimiter = doc.getLineDelimiter(line - 1);
255
					if (lineDelimiter == null)
256
						lineDelimiter = ""; //$NON-NLS-1$
257
				}
262
				}
258
			}
263
			}
259
			catch (BadLocationException e) {
264
			catch (BadLocationException e) {
260
				// log for now, unless we find reason not to
265
				// log for now, unless we find reason not to
261
				Logger.log(Logger.INFO, e.getMessage());
266
				Logger.log(Logger.INFO, e.getMessage());
262
			}
267
			}
268
			// BUG115716: if cannot get line delimiter from current line, just
269
			// use default line delimiter
270
			if (lineDelimiter == null)
271
				lineDelimiter = doc.getLineDelimiter();
263
			String lineIndent = formatContraints.getCurrentIndent();
272
			String lineIndent = formatContraints.getCurrentIndent();
264
273
265
			if (node.getParentNode() != null) {
274
			if (node.getParentNode() != null) {
Lines 328-334 Link Here
328
	 */
337
	 */
329
	protected void formatTrailingText(IDOMNode node, IStructuredFormatContraints formatContraints) {
338
	protected void formatTrailingText(IDOMNode node, IStructuredFormatContraints formatContraints) {
330
		// [111674] If inside xml:space="preserve" element, we bail
339
		// [111674] If inside xml:space="preserve" element, we bail
331
		if (formatContraints.getInPreserveSpaceElement()) return;
340
		if (formatContraints.getInPreserveSpaceElement())
341
			return;
332
342
333
		String lineDelimiter = node.getModel().getStructuredDocument().getLineDelimiter();
343
		String lineDelimiter = node.getModel().getStructuredDocument().getLineDelimiter();
334
		String lineIndent = formatContraints.getCurrentIndent();
344
		String lineIndent = formatContraints.getCurrentIndent();
(-)src/org/eclipse/wst/xml/core/internal/provisional/format/ElementNodeFormatter.java (-16 / +20 lines)
Lines 129-136 Link Here
129
			}
129
			}
130
130
131
			formatContraints.setInPreserveSpaceElement(currentlyInXmlSpacePreserve);
131
			formatContraints.setInPreserveSpaceElement(currentlyInXmlSpacePreserve);
132
			// format indentation after node
132
			// only indent if not at last node
133
			formatIndentationAfterNode(newNode, formatContraints);
133
			if (newNode != null && newNode.getNextSibling() != null)
134
				// format indentation after node
135
				formatIndentationAfterNode(newNode, formatContraints);
134
		}
136
		}
135
	}
137
	}
136
138
Lines 170-176 Link Here
170
			int attrLength = attributes.getLength();
172
			int attrLength = attributes.getLength();
171
			int lastUndefinedRegionOffset = 0;
173
			int lastUndefinedRegionOffset = 0;
172
			boolean sawXmlSpace = false;
174
			boolean sawXmlSpace = false;
173
			
175
174
			for (int i = 0; i < attrLength; i++) {
176
			for (int i = 0; i < attrLength; i++) {
175
				AttrImpl attr = (AttrImpl) attributes.item(i);
177
				AttrImpl attr = (AttrImpl) attributes.item(i);
176
				ITextRegion nameRegion = attr.getNameRegion();
178
				ITextRegion nameRegion = attr.getNameRegion();
Lines 185-193 Link Here
185
				// check for xml:space attribute
187
				// check for xml:space attribute
186
				if (flatNode.getText(nameRegion).compareTo(XML_SPACE) == 0) {
188
				if (flatNode.getText(nameRegion).compareTo(XML_SPACE) == 0) {
187
					if (valueRegion == null) {
189
					if (valueRegion == null) {
188
						// [111674] If nothing has been written yet, treat as preserve, but only as hint
190
						// [111674] If nothing has been written yet, treat as
191
						// preserve, but only as hint
189
						formatContraints.setInPreserveSpaceElement(true);
192
						formatContraints.setInPreserveSpaceElement(true);
190
						// Note we don't set 'sawXmlSpace', so that default or fixed DTD/XSD values may override.
193
						// Note we don't set 'sawXmlSpace', so that default or
194
						// fixed DTD/XSD values may override.
191
					}
195
					}
192
					else {
196
					else {
193
						ISourceGenerator generator = node.getModel().getGenerator();
197
						ISourceGenerator generator = node.getModel().getGenerator();
Lines 327-353 Link Here
327
				}
331
				}
328
			}
332
			}
329
333
330
			
334
331
			replace(structuredDocument, offset, length, stringBuffer.toString());
335
			replace(structuredDocument, offset, length, stringBuffer.toString());
332
336
333
			// If we didn't see a xml:space attribute above, we'll look for one in the DTD.
337
			// If we didn't see a xml:space attribute above, we'll look for
338
			// one in the DTD.
334
			// We do not check for a conflict between a DTD's 'fixed' value
339
			// We do not check for a conflict between a DTD's 'fixed' value
335
			// and the attribute value found in the instance document, we leave that to the validator.
340
			// and the attribute value found in the instance document, we
336
			if (! sawXmlSpace)
341
			// leave that to the validator.
337
			{
342
			if (!sawXmlSpace) {
338
				ModelQueryAdapter adapter = (ModelQueryAdapter) ((IDOMDocument) node.getOwnerDocument()).getAdapterFor(ModelQueryAdapter.class);
343
				ModelQueryAdapter adapter = (ModelQueryAdapter) ((IDOMDocument) node.getOwnerDocument()).getAdapterFor(ModelQueryAdapter.class);
339
				CMElementDeclaration elementDeclaration = (CMElementDeclaration) adapter.getModelQuery().getCMNode(node);
344
				CMElementDeclaration elementDeclaration = (CMElementDeclaration) adapter.getModelQuery().getCMNode(node);
340
				if (elementDeclaration != null)
345
				if (elementDeclaration != null) {
341
				{
342
					CMNamedNodeMap cmAttributes = elementDeclaration.getAttributes();
346
					CMNamedNodeMap cmAttributes = elementDeclaration.getAttributes();
343
					// Check implied values from the DTD way.
347
					// Check implied values from the DTD way.
344
					CMAttributeDeclaration attributeDeclaration = (CMAttributeDeclaration) cmAttributes.getNamedItem(XML_SPACE);
348
					CMAttributeDeclaration attributeDeclaration = (CMAttributeDeclaration) cmAttributes.getNamedItem(XML_SPACE);
345
					if (attributeDeclaration != null)
349
					if (attributeDeclaration != null) {
346
					{
347
						// CMAttributeDeclaration found, check it out.
350
						// CMAttributeDeclaration found, check it out.
348
						String defaultValue = attributeDeclaration.getAttrType().getImpliedValue();
351
						String defaultValue = attributeDeclaration.getAttrType().getImpliedValue();
349
						
352
350
						// xml:space="preserve" means preserve space, everything else means back to default.
353
						// xml:space="preserve" means preserve space,
354
						// everything else means back to default.
351
						if (defaultValue.compareTo(PRESERVE) == 0)
355
						if (defaultValue.compareTo(PRESERVE) == 0)
352
							formatContraints.setInPreserveSpaceElement(true);
356
							formatContraints.setInPreserveSpaceElement(true);
353
						else
357
						else

Return to bug 115716