View | Details | Raw Unified | Return to bug 109636 | Differences between
and this patch

Collapse All | Expand All

(-)formatter/org/eclipse/jdt/internal/formatter/comment/Java2HTMLEntityReader.java (-18 / +37 lines)
Lines 62-91 Link Here
62
	 * @see org.eclipse.jdt.internal.ui.text.SubstitutionTextReader#computeSubstitution(int)
62
	 * @see org.eclipse.jdt.internal.ui.text.SubstitutionTextReader#computeSubstitution(int)
63
	 */
63
	 */
64
	protected String computeSubstitution(int c) throws IOException {
64
	protected String computeSubstitution(int c) throws IOException {
65
		/*
65
		StringBuffer buf = new StringBuffer();
66
		 * When @ is first on a line, translate it to @ so it isn't
66
		// Accumulate *s into the buffer until we see something other than *.
67
		 * misinterpreted as a Javadoc tag.
67
		while (c == '*') {
68
		 * See https://bugs.eclipse.org/bugs/show_bug.cgi?id=197169
69
		 */
70
		if (c == '@') {
71
			return (this.bits & BEGIN_LINE) != 0 ? "@" : null; //$NON-NLS-1$
72
		}
73
		if (c == '*') {
74
			this.bits &= ~BEGIN_LINE;
68
			this.bits &= ~BEGIN_LINE;
75
			int next = nextChar();
69
			c = nextChar();
76
			if (next == '/') {
70
			buf.append('*');
77
				return "*/"; //$NON-NLS-1$
71
		}
78
			}
72
		if (c == -1)
79
			if (next == -1) {
73
			// Snippet must have ended with *s.  Just return them.
80
				return "*"; //$NON-NLS-1$
74
			return buf.toString();
81
			}
75
		if (c == '/' && buf.length() > 0) {
82
			return "*" + (char) next; //$NON-NLS-1$
76
			/*
77
			 * Translate a * that precedes a / to * so it isn't
78
			 * misinterpreted as the end of the Javadoc comment that contains
79
			 * the code we are formatting.
80
			 * See https://bugs.eclipse.org/bugs/show_bug.cgi?id=109636
81
			 */
82
			buf.setLength(buf.length() - 1);
83
			buf.append("*/"); //$NON-NLS-1$
84
		} else if (c == '@' && (this.bits & BEGIN_LINE) != 0) {
85
			/*
86
			 * When @ is first on a line, translate it to @ so it isn't
87
			 * misinterpreted as a Javadoc tag.
88
			 * See https://bugs.eclipse.org/bugs/show_bug.cgi?id=197169
89
			 */
90
			buf.append("@"); //$NON-NLS-1$
91
		} else {
92
			/*
93
			 * Ordinary processing.  If the character needs an entity in HTML,
94
			 * add the entity, otherwise add the character.
95
			 */
96
			String entity = (String) fgEntityLookup.get(String.valueOf((char) c));
97
			if (entity != null)
98
				buf.append(entity);
99
			else
100
				buf.append((char) c);
83
		}
101
		}
102
		// Update bits for the benefit of the next character.
84
		if (c == '\n' || c == '\r') {
103
		if (c == '\n' || c == '\r') {
85
			this.bits |= BEGIN_LINE;
104
			this.bits |= BEGIN_LINE;
86
		} else if (!ScannerHelper.isWhitespace((char) c)) {
105
		} else if (!ScannerHelper.isWhitespace((char) c)) {
87
			this.bits &= ~BEGIN_LINE;
106
			this.bits &= ~BEGIN_LINE;
88
		}
107
		}
89
		return (String) fgEntityLookup.get(String.valueOf((char) c));
108
		return buf.toString();
90
	}
109
	}
91
}
110
}
(-)formatter/org/eclipse/jdt/internal/formatter/comment/SubstitutionTextReader.java (-1 / +1 lines)
Lines 113-119 Link Here
113
		do {
113
		do {
114
			
114
			
115
			c= nextChar();
115
			c= nextChar();
116
			while (!fReadFromBuffer) {
116
			while (!fReadFromBuffer && c != -1) {
117
				String s= computeSubstitution(c);
117
				String s= computeSubstitution(c);
118
				if (s == null)
118
				if (s == null)
119
					break;
119
					break;
(-)src/org/eclipse/jdt/core/tests/formatter/comment/JavaDocTestCase.java (-2 / +2 lines)
Lines 892-898 Link Here
892
		assertEquals(expected, result);
892
		assertEquals(expected, result);
893
	}
893
	}
894
894
895
	public void _test109636_2() {
895
	public void test109636_2() {
896
		Map options = DefaultCodeFormatterConstants.getEclipseDefaultSettings();
896
		Map options = DefaultCodeFormatterConstants.getEclipseDefaultSettings();
897
897
898
		String input =
898
		String input =
Lines 907-913 Link Here
907
			"/**" + DELIMITER + 
907
			"/**" + DELIMITER + 
908
			" * <pre>" + DELIMITER + 
908
			" * <pre>" + DELIMITER + 
909
			" * /* Comment ending in multiple stars *&#42;/" + DELIMITER + 
909
			" * /* Comment ending in multiple stars *&#42;/" + DELIMITER + 
910
			" * /* Entity-needing character after a star *< &#42;/" + DELIMITER + 
910
			" * /* Entity-needing character after a star *&lt; &#42;/" + DELIMITER + 
911
			" * </pre>" + DELIMITER + 
911
			" * </pre>" + DELIMITER + 
912
			" */";
912
			" */";
913
		String result=testFormat(input, options);
913
		String result=testFormat(input, options);

Return to bug 109636