Link Here
|
11 |
*******************************************************************************/ |
11 |
*******************************************************************************/ |
12 |
package org.eclipse.jdt.internal.formatter.comment; |
12 |
package org.eclipse.jdt.internal.formatter.comment; |
13 |
|
13 |
|
|
|
14 |
import java.io.IOException; |
14 |
import java.io.Reader; |
15 |
import java.io.Reader; |
15 |
import java.util.HashMap; |
16 |
import java.util.HashMap; |
16 |
import java.util.Map; |
17 |
import java.util.Map; |
Link Here
|
26 |
*/ |
27 |
*/ |
27 |
public class Java2HTMLEntityReader extends SubstitutionTextReader { |
28 |
public class Java2HTMLEntityReader extends SubstitutionTextReader { |
28 |
|
29 |
|
|
|
30 |
private static final int BEGIN_LINE = 0x01; |
31 |
|
29 |
/** The hardcoded entity map. */ |
32 |
/** The hardcoded entity map. */ |
30 |
private static final Map fgEntityLookup; |
33 |
private static final Map fgEntityLookup; |
31 |
|
34 |
|
Link Here
|
33 |
* True if we have not yet seen a non-whitespace character on the current |
36 |
* True if we have not yet seen a non-whitespace character on the current |
34 |
* line. |
37 |
* line. |
35 |
*/ |
38 |
*/ |
36 |
private boolean beginLine = true; |
39 |
private int bits = BEGIN_LINE; |
37 |
|
40 |
|
38 |
static { |
41 |
static { |
39 |
fgEntityLookup= new HashMap(7); |
42 |
fgEntityLookup= new HashMap(7); |
40 |
fgEntityLookup.put("<", "<"); //$NON-NLS-1$ //$NON-NLS-2$ |
43 |
fgEntityLookup.put("<", "<"); //$NON-NLS-1$ //$NON-NLS-2$ |
Link Here
|
58 |
/* |
61 |
/* |
59 |
* @see org.eclipse.jdt.internal.ui.text.SubstitutionTextReader#computeSubstitution(int) |
62 |
* @see org.eclipse.jdt.internal.ui.text.SubstitutionTextReader#computeSubstitution(int) |
60 |
*/ |
63 |
*/ |
61 |
protected String computeSubstitution(int c) { |
64 |
protected String computeSubstitution(int c) throws IOException { |
62 |
/* |
65 |
/* |
63 |
* When @ is first on a line, translate it to @ so it isn't |
66 |
* When @ is first on a line, translate it to @ so it isn't |
64 |
* misinterpreted as a Javadoc tag. |
67 |
* misinterpreted as a Javadoc tag. |
65 |
* See https://bugs.eclipse.org/bugs/show_bug.cgi?id=197169 |
68 |
* See https://bugs.eclipse.org/bugs/show_bug.cgi?id=197169 |
66 |
*/ |
69 |
*/ |
67 |
if (c == '@') |
70 |
if (c == '@') { |
68 |
return this.beginLine ? "@" : null; //$NON-NLS-1$ |
71 |
return (this.bits & BEGIN_LINE) != 0 ? "@" : null; //$NON-NLS-1$ |
69 |
else if (c == '\n' || c == '\r') |
72 |
} |
70 |
this.beginLine = true; |
73 |
if (c == '*') { |
71 |
else if (!ScannerHelper.isWhitespace((char) c)) { |
74 |
this.bits &= ~BEGIN_LINE; |
72 |
this.beginLine = false; |
75 |
int next = nextChar(); |
|
|
76 |
if (next == '/') { |
77 |
return "*/"; //$NON-NLS-1$ |
78 |
} |
79 |
if (next == -1) { |
80 |
return "*"; //$NON-NLS-1$ |
81 |
} |
82 |
return "*" + (char) next; //$NON-NLS-1$ |
83 |
} |
84 |
if (c == '\n' || c == '\r') { |
85 |
this.bits |= BEGIN_LINE; |
86 |
} else if (!ScannerHelper.isWhitespace((char) c)) { |
87 |
this.bits &= ~BEGIN_LINE; |
73 |
} |
88 |
} |
74 |
return (String) fgEntityLookup.get(String.valueOf((char) c)); |
89 |
return (String) fgEntityLookup.get(String.valueOf((char) c)); |
75 |
} |
90 |
} |