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 326420
Collapse All | Expand All

(-)src/org/eclipse/wst/jsdt/web/core/javascript/JsTranslator.java (-3 / +23 lines)
Lines 48-56 Link Here
48
import org.eclipse.jface.text.IDocumentExtension4;
48
import org.eclipse.jface.text.IDocumentExtension4;
49
import org.eclipse.jface.text.IDocumentListener;
49
import org.eclipse.jface.text.IDocumentListener;
50
import org.eclipse.jface.text.IDocumentRewriteSessionListener;
50
import org.eclipse.jface.text.IDocumentRewriteSessionListener;
51
import org.eclipse.jface.text.IRegion;
51
import org.eclipse.jface.text.Position;
52
import org.eclipse.jface.text.Position;
52
import org.eclipse.jface.text.Region;
53
import org.eclipse.jface.text.Region;
53
import org.eclipse.wst.jsdt.core.IBuffer;
54
import org.eclipse.wst.jsdt.core.IBuffer;
55
import org.eclipse.wst.jsdt.web.core.internal.Logger;
54
import org.eclipse.wst.sse.core.StructuredModelManager;
56
import org.eclipse.wst.sse.core.StructuredModelManager;
55
import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument;
57
import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument;
56
import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion;
58
import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion;
Lines 513-519 Link Here
513
				// skip over XML/HTML comment starts
515
				// skip over XML/HTML comment starts
514
				if (regionText.indexOf(XML_COMMENT_START) >= 0) {
516
				if (regionText.indexOf(XML_COMMENT_START) >= 0) {
515
					int index = regionText.indexOf(XML_COMMENT_START);
517
					int index = regionText.indexOf(XML_COMMENT_START);
516
					int leadingTrimPlusCommentStart = index + XML_COMMENT_START.length();
518
					
517
					boolean replaceCommentStart = true;
519
					boolean replaceCommentStart = true;
518
					for (int i = 0; i < index; i++) {
520
					for (int i = 0; i < index; i++) {
519
						/*
521
						/*
Lines 522-532 Link Here
522
						 */
524
						 */
523
						replaceCommentStart = replaceCommentStart && Character.isWhitespace(regionText.charAt(i));
525
						replaceCommentStart = replaceCommentStart && Character.isWhitespace(regionText.charAt(i));
524
					}
526
					}
527
					
525
					if (replaceCommentStart) {
528
					if (replaceCommentStart) {
529
						IRegion line;
530
						int end;
531
						int length;
532
						try {
533
							line = container.getParentDocument().getLineInformationOfOffset(index + scriptStart);
534
							end = line.getOffset() + line.getLength() - scriptStart;
535
							if(end > regionText.length()) {
536
								end = regionText.length()-1;
537
							}
538
							length = end - index;
539
						} catch (BadLocationException e) {
540
							Logger.logException("Could not get HTML style comment line information", e); //$NON-NLS-1$
541
							
542
							end = index + XML_COMMENT_START.length();
543
							length = XML_COMMENT_START.length();
544
						}
545
						
526
						StringBuffer newRegionText = new StringBuffer(regionText.substring(0, index));
546
						StringBuffer newRegionText = new StringBuffer(regionText.substring(0, index));
527
						spaces = Util.getPad(XML_COMMENT_START.length());
547
						spaces = Util.getPad(length);
528
						newRegionText.append(spaces);
548
						newRegionText.append(spaces);
529
						newRegionText.append(regionText.substring(leadingTrimPlusCommentStart));
549
						newRegionText.append(regionText.substring(end));
530
						regionText = newRegionText.toString();
550
						regionText = newRegionText.toString();
531
					}
551
					}
532
				}
552
				}
(-)src/org/eclipse/wst/jsdt/web/ui/internal/format/FormattingStrategyJSDT.java (-13 / +8 lines)
Lines 56-69 Link Here
56
* (repeatedly) as the API evolves.
56
* (repeatedly) as the API evolves.
57
*/
57
*/
58
public class FormattingStrategyJSDT extends ContextBasedFormattingStrategy {
58
public class FormattingStrategyJSDT extends ContextBasedFormattingStrategy {
59
	private static final String XML_COMMENT_START = "<!--"; //$NON-NLS-1$
59
	/** matches on //--> at end of script region */
60
	private static final String XML_COMMENT_END = "//-->"; //$NON-NLS-1$
60
	private static final Pattern END_PATTERN = Pattern.compile("((//.*-->\\s*)\\z)");
61
	
62
	/** matches on <!-- at beginning of script region */
63
	private static final Pattern START_PATTERN = Pattern.compile("(\\A(\\s*<!--))");
64
	
65
	/** matches on //--> or --> at end of script region */
66
	private static final Pattern END_PATTERN = Pattern.compile("(((//\\s*)?-->\\s*)\\z)");
67
	
61
	
68
	private static final int regionStartIndentLevel = 1;
62
	private static final int regionStartIndentLevel = 1;
69
	/** Documents to be formatted by this strategy */
63
	/** Documents to be formatted by this strategy */
Lines 114-130 Link Here
114
				String postText = lineDelim;
108
				String postText = lineDelim;
115
109
116
				//find start comment tag
110
				//find start comment tag
117
				Matcher matcher = START_PATTERN.matcher(jsTextNotTranslated);
111
				Pattern startPattern = Pattern.compile("(\\A(\\s*<!--.*(" + lineDelim + ")?))");
112
				Matcher matcher = startPattern.matcher(jsTextNotTranslated);
118
				if(matcher.find()) {
113
				if(matcher.find()) {
119
					jsTextNotTranslated = matcher.replaceAll("");
114
					jsTextNotTranslated = matcher.replaceFirst("");
120
					preText = lineDelim + XML_COMMENT_START;
115
					preText = lineDelim + matcher.group().trim();
121
				}
116
				}
122
				
117
				
123
				//find end tag
118
				//find end tag
124
				matcher = END_PATTERN.matcher(jsTextNotTranslated);
119
				matcher = END_PATTERN.matcher(jsTextNotTranslated);
125
				if(matcher.find()) {
120
				if(matcher.find()) {
126
					jsTextNotTranslated = matcher.replaceAll("");
121
					jsTextNotTranslated = matcher.replaceFirst("");
127
					postText = lineDelim + XML_COMMENT_END + lineDelim;
122
					postText = lineDelim + matcher.group().trim() + lineDelim;
128
				}
123
				}
129
				
124
				
130
				//replace the text in the document with the none-translated JS text but without HTML leading and trailing comments
125
				//replace the text in the document with the none-translated JS text but without HTML leading and trailing comments

Return to bug 326420