This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

View | Details | Raw Unified | Return to bug 221844
Collapse All | Expand All

(-)a/editor.guards/apichanges.xml (+17 lines)
Lines 108-113 Link Here
108
    <!-- ACTUAL CHANGES BEGIN HERE: -->
108
    <!-- ACTUAL CHANGES BEGIN HERE: -->
109
109
110
    <changes>
110
    <changes>
111
        <change id="AbstractGuardedSectionsProvider-useReadersWritersOnSet">
112
            <api name="general"/>
113
            <summary>Ability run guarded readers/writers when the content of the guarded section's content is set</summary>
114
            <version major="1" minor="20"/>
115
            <date day="23" month="11" year="2012"/>
116
            <author login="jlahoda"/>
117
            <compatibility addition="yes" binary="compatible" deletion="no" deprecation="no" modification="no"/>
118
            <description>
119
                <p>When this option is set, setting the content of a GuardedSection will pass the data through the given
120
                guarded writer and back through the given guarded reader, to ensure the result is the same
121
                as if it would be read from the disk.</p>
122
                <p>Note that this new mode is not fully compatible with the original mode, e.g. all the set methods
123
                of all the GuardedSection classes will throw IllegalStateException if invoked inside the write&amp;read part.</p>
124
            </description>
125
            <issue number="221844"/>
126
        </change>
127
        
111
        <change id="GuardedSectionsProvider-Charset">
128
        <change id="GuardedSectionsProvider-Charset">
112
            <api name="general"/>
129
            <api name="general"/>
113
            <summary>GuardedSectionsProvider supports Charset</summary>
130
            <summary>GuardedSectionsProvider supports Charset</summary>
(-)a/editor.guards/manifest.mf (-1 / +1 lines)
Lines 1-5 Link Here
1
Manifest-Version: 1.0
1
Manifest-Version: 1.0
2
OpenIDE-Module: org.netbeans.modules.editor.guards/1
2
OpenIDE-Module: org.netbeans.modules.editor.guards/1
3
OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/editor/guards/Bundle.properties
3
OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/editor/guards/Bundle.properties
4
OpenIDE-Module-Specification-Version: 1.19
4
OpenIDE-Module-Specification-Version: 1.20
5
5
(-)a/editor.guards/src/org/netbeans/api/editor/guards/GuardedSection.java (-8 / +39 lines)
Lines 50-58 Link Here
50
/**
50
/**
51
 * Represents one guarded section.
51
 * Represents one guarded section.
52
 */
52
 */
53
public class GuardedSection {
53
public abstract class GuardedSection {
54
    
54
    
55
    private final GuardedSectionImpl impl;
55
    private final GuardedSectionImpl impl;
56
    private final GuardedSection delegate;
57
            final int offset;
56
58
57
    /**
59
    /**
58
     * Creates new section.
60
     * Creates new section.
Lines 62-67 Link Here
62
        assert impl != null;
64
        assert impl != null;
63
        this.impl = impl;
65
        this.impl = impl;
64
        impl.attach(this);
66
        impl.attach(this);
67
        this.delegate = null;
68
        this.offset = 0;
69
    }
70
    
71
    GuardedSection(GuardedSection delegate, int offset) {
72
        this.impl = null;
73
        this.delegate = delegate;
74
        this.offset = offset;
65
    }
75
    }
66
    
76
    
67
    /**
77
    /**
Lines 69-75 Link Here
69
     * @return the name
79
     * @return the name
70
     */
80
     */
71
    public String getName() {
81
    public String getName() {
72
        return impl.getName();
82
        return impl != null ? impl.getName() : delegate.getName();
73
    }
83
    }
74
84
75
    /**
85
    /**
Lines 78-83 Link Here
78
     * @exception PropertyVetoException if the new name is already in use
88
     * @exception PropertyVetoException if the new name is already in use
79
     */
89
     */
80
    public void setName(String name) throws PropertyVetoException {
90
    public void setName(String name) throws PropertyVetoException {
91
        if (impl == null) throw new IllegalStateException();
81
        impl.setName(name);
92
        impl.setName(name);
82
    }
93
    }
83
94
Lines 87-92 Link Here
87
     * and it will be impossible to use its methods.
98
     * and it will be impossible to use its methods.
88
     */
99
     */
89
    public void deleteSection() {
100
    public void deleteSection() {
101
        if (impl == null) throw new IllegalStateException();
90
        impl.deleteSection();
102
        impl.deleteSection();
91
    }
103
    }
92
104
Lines 95-101 Link Here
95
     * source.
107
     * source.
96
     */
108
     */
97
    public boolean isValid() {
109
    public boolean isValid() {
98
        return impl.isValid();
110
        return impl != null ? impl.isValid() : delegate.isValid();
99
    }
111
    }
100
112
101
    /**
113
    /**
Lines 104-109 Link Here
104
     * instead of calling NbDocument.
116
     * instead of calling NbDocument.
105
     */
117
     */
106
    public void removeSection() {
118
    public void removeSection() {
119
        if (impl == null) throw new IllegalStateException();
107
        impl.removeSection();
120
        impl.removeSection();
108
    }
121
    }
109
    
122
    
Lines 113-119 Link Here
113
     * @return the position to place the caret.
126
     * @return the position to place the caret.
114
     */
127
     */
115
    public Position getCaretPosition() {
128
    public Position getCaretPosition() {
116
        return impl.getCaretPosition();
129
        return impl != null ? impl.getCaretPosition() : new OffsetPosition(delegate.getCaretPosition(), offset);
117
    }
130
    }
118
    
131
    
119
    /**
132
    /**
Lines 121-127 Link Here
121
     * @return The text contained in the section.
134
     * @return The text contained in the section.
122
     */
135
     */
123
    public String getText() {
136
    public String getText() {
124
        return impl.getText();
137
        return impl != null ? impl.getText() : delegate.getText();
125
    }
138
    }
126
139
127
    /**
140
    /**
Lines 134-140 Link Here
134
     * @return <code>true</code> if the position is inside section.
147
     * @return <code>true</code> if the position is inside section.
135
     */
148
     */
136
    public boolean contains(Position pos, boolean permitHoles) {
149
    public boolean contains(Position pos, boolean permitHoles) {
137
        return impl.contains(pos, permitHoles);
150
        return impl != null ? impl.contains(pos, permitHoles) : delegate.contains(new OffsetPosition(pos, -offset), permitHoles);
138
    }
151
    }
139
    
152
    
140
    /**
153
    /**
Lines 142-148 Link Here
142
     * @return the end position of the guarded section.
155
     * @return the end position of the guarded section.
143
     */
156
     */
144
    public Position getEndPosition() {
157
    public Position getEndPosition() {
145
        return impl.getEndPosition();
158
        return impl != null ? impl.getEndPosition() : new OffsetPosition(delegate.getEndPosition(), offset);
146
    }
159
    }
147
    
160
    
148
    /** 
161
    /** 
Lines 150-160 Link Here
150
     * @return the start position of the guarded section.
163
     * @return the start position of the guarded section.
151
     */
164
     */
152
    public Position getStartPosition() {
165
    public Position getStartPosition() {
153
        return impl.getStartPosition();
166
        return impl != null ? impl.getStartPosition() : new OffsetPosition(delegate.getStartPosition(), offset);
154
    }
167
    }
155
    
168
    
156
    GuardedSectionImpl getImpl() {
169
    GuardedSectionImpl getImpl() {
157
        return impl;
170
        return impl;
158
    }
171
    }
159
172
173
    GuardedSection getDelegate() {
174
        return delegate;
175
    }
176
177
    abstract GuardedSection clone(int offset);
178
179
    static class OffsetPosition implements Position {
180
        private final Position delegate;
181
        private final int offset;
182
        public OffsetPosition(Position delegate, int offset) {
183
            this.delegate = delegate;
184
            this.offset = offset;
185
        }
186
        @Override public int getOffset() {
187
            return delegate.getOffset() - offset;
188
        }
189
        
190
    }
160
}
191
}
(-)a/editor.guards/src/org/netbeans/api/editor/guards/GuardedSectionManager.java (+5 lines)
Lines 156-161 Link Here
156
            public GuardedSectionImpl getImpl(GuardedSection gs) {
156
            public GuardedSectionImpl getImpl(GuardedSection gs) {
157
                return gs.getImpl();
157
                return gs.getImpl();
158
            }
158
            }
159
160
            @Override
161
            public GuardedSection clone(GuardedSection gs, int offset) {
162
                return gs.clone(offset);
163
            }
159
            
164
            
160
        };
165
        };
161
    }
166
    }
(-)a/editor.guards/src/org/netbeans/api/editor/guards/InteriorSection.java (+22 lines)
Lines 60-70 Link Here
60
        super(impl);
60
        super(impl);
61
    }
61
    }
62
62
63
    InteriorSection(GuardedSection delegate, int offset) {
64
        super(delegate, offset);
65
    }
66
    
63
    /**
67
    /**
64
     * Sets the text of the body.
68
     * Sets the text of the body.
65
     * @param text the new text
69
     * @param text the new text
66
     */
70
     */
67
    public void setBody(String text) {
71
    public void setBody(String text) {
72
        if (getImpl() == null) throw new IllegalStateException();
68
        getImpl().setBody(text);
73
        getImpl().setBody(text);
69
    }
74
    }
70
    
75
    
Lines 74-79 Link Here
74
     * @return contents of the body or null, if the section is not valid.
79
     * @return contents of the body or null, if the section is not valid.
75
     */
80
     */
76
    public String getBody() {
81
    public String getBody() {
82
        if (getImpl() == null) return getDelegate().getBody();
77
        return getImpl().getBody();
83
        return getImpl().getBody();
78
    }
84
    }
79
85
Lines 82-87 Link Here
82
     * @param text the new text
88
     * @param text the new text
83
     */
89
     */
84
    public void setHeader(String text) {
90
    public void setHeader(String text) {
91
        if (getImpl() == null) throw new IllegalStateException();
85
        getImpl().setHeader(text);
92
        getImpl().setHeader(text);
86
    }
93
    }
87
94
Lines 91-96 Link Here
91
     * @return contents of the header or null, if the section is not valid.
98
     * @return contents of the header or null, if the section is not valid.
92
     */
99
     */
93
    public String getHeader() {
100
    public String getHeader() {
101
        if (getImpl() == null) return getDelegate().getHeader();
94
        return getImpl().getHeader();
102
        return getImpl().getHeader();
95
    }
103
    }
96
104
Lines 102-107 Link Here
102
     * @param text the new text
110
     * @param text the new text
103
     */
111
     */
104
    public void setFooter(String text) {
112
    public void setFooter(String text) {
113
        if (getImpl() == null) throw new IllegalStateException();
105
        getImpl().setFooter(text);
114
        getImpl().setFooter(text);
106
    }
115
    }
107
116
Lines 111-116 Link Here
111
     * @return contents of the footer part, or null if the section is not valid.
120
     * @return contents of the footer part, or null if the section is not valid.
112
     */
121
     */
113
    public String getFooter() {
122
    public String getFooter() {
123
        if (getImpl() == null) return getDelegate().getFooter();
114
        return getImpl().getFooter();
124
        return getImpl().getFooter();
115
    }
125
    }
116
    
126
    
Lines 119-124 Link Here
119
     * @return the start position of the body part
129
     * @return the start position of the body part
120
     */
130
     */
121
    public Position getBodyStartPosition() {
131
    public Position getBodyStartPosition() {
132
        if (getImpl() == null) return new OffsetPosition(getDelegate().getBodyStartPosition(), offset);
122
        return getImpl().getBodyStartPosition();
133
        return getImpl().getBodyStartPosition();
123
    }
134
    }
124
    
135
    
Lines 127-132 Link Here
127
     * @return the end position of the body part
138
     * @return the end position of the body part
128
     */
139
     */
129
    public Position getBodyEndPosition() {
140
    public Position getBodyEndPosition() {
141
        if (getImpl() == null) return new OffsetPosition(getDelegate().getBodyEndPosition(), offset);
130
        return getImpl().getBodyEndPosition();
142
        return getImpl().getBodyEndPosition();
131
    }
143
    }
132
    
144
    
Lines 154-157 Link Here
154
      }
166
      }
155
      return buf.toString();
167
      return buf.toString();
156
    }*/
168
    }*/
169
170
    @Override
171
    InteriorSection getDelegate() {
172
        return (InteriorSection) super.getDelegate();
173
    }
174
175
    @Override
176
    GuardedSection clone(int offset) {
177
        return new InteriorSection(this, offset);
178
    }
157
}
179
}
(-)a/editor.guards/src/org/netbeans/api/editor/guards/SimpleSection.java (+10 lines)
Lines 61-71 Link Here
61
        super(impl);
61
        super(impl);
62
    }
62
    }
63
63
64
    SimpleSection(GuardedSection delegate, int offset) {
65
        super(delegate, offset);
66
    }
67
64
    /**
68
    /**
65
     * Sets the text of the section.
69
     * Sets the text of the section.
66
     * @param text the new text
70
     * @param text the new text
67
     */
71
     */
68
    public void setText(String text) {
72
    public void setText(String text) {
73
        if (getImpl() == null) throw new IllegalStateException();
69
        getImpl().setText(text);
74
        getImpl().setText(text);
70
    }
75
    }
71
76
Lines 87-90 Link Here
87
    SimpleSectionImpl getImpl() {
92
    SimpleSectionImpl getImpl() {
88
        return (SimpleSectionImpl) super.getImpl();
93
        return (SimpleSectionImpl) super.getImpl();
89
    }
94
    }
95
96
    @Override
97
    GuardedSection clone(int offset) {
98
        return new SimpleSection(this, offset);
99
    }
90
}
100
}
(-)a/editor.guards/src/org/netbeans/modules/editor/guards/GuardedReader.java (-1 / +1 lines)
Lines 189-195 Link Here
189
            isClosed = true;
189
            isClosed = true;
190
            reader.close();
190
            reader.close();
191
            if (this.result != null) {
191
            if (this.result != null) {
192
                callback.fillSections(this.result.getGuardedSections(), newLineStream.getNewLineType());
192
                callback.fillSections(gr, this.result.getGuardedSections(), newLineStream.getNewLineType());
193
            }
193
            }
194
        }
194
        }
195
    }
195
    }
(-)a/editor.guards/src/org/netbeans/modules/editor/guards/GuardedSectionImpl.java (+8 lines)
Lines 46-51 Link Here
46
46
47
import java.beans.PropertyChangeEvent;
47
import java.beans.PropertyChangeEvent;
48
import java.beans.PropertyVetoException;
48
import java.beans.PropertyVetoException;
49
import java.io.ByteArrayOutputStream;
50
import java.nio.charset.Charset;
51
import java.util.Collections;
49
import javax.swing.text.BadLocationException;
52
import javax.swing.text.BadLocationException;
50
import javax.swing.text.Position;
53
import javax.swing.text.Position;
51
import javax.swing.text.StyledDocument;
54
import javax.swing.text.StyledDocument;
Lines 179-184 Link Here
179
        
182
        
180
        try {
183
        try {
181
            bounds.setText(text);
184
            bounds.setText(text);
185
            if (guards.gr != null) {
186
                char[] data = guards.gr.writeSections(Collections.singletonList(GuardsAccessor.DEFAULT.clone(guard, bounds.getBegin().getOffset())), (bounds.getText() + "\n").toCharArray());
187
                data = guards.gr.readSections(data).getContent();
188
                bounds.setText(new String(data, 0, data.length - 1));
189
            }
182
            return true;
190
            return true;
183
        } catch (BadLocationException e) {
191
        } catch (BadLocationException e) {
184
        }
192
        }
(-)a/editor.guards/src/org/netbeans/modules/editor/guards/GuardedSectionsImpl.java (-1 / +4 lines)
Lines 254-266 Link Here
254
    
254
    
255
    // package
255
    // package
256
    
256
    
257
    AbstractGuardedSectionsProvider gr;
258
    
257
    /** Takes the section descriptors from the GuardedReader and
259
    /** Takes the section descriptors from the GuardedReader and
258
    * fills the table 'sections', also marks as guarded all sections
260
    * fills the table 'sections', also marks as guarded all sections
259
    * in the given document.
261
    * in the given document.
260
    * @param is Where to take the guarded section descriptions.
262
    * @param is Where to take the guarded section descriptions.
261
    * @param doc Where to mark guarded.
263
    * @param doc Where to mark guarded.
262
    */
264
    */
263
    void fillSections(List<GuardedSection> l, NewLine newLineType) {
265
    void fillSections(AbstractGuardedSectionsProvider gr, List<GuardedSection> l, NewLine newLineType) {
266
        this.gr = gr;
264
        this.newLineType = newLineType;
267
        this.newLineType = newLineType;
265
        // XXX this should invalidate removed GS instances
268
        // XXX this should invalidate removed GS instances
266
        // XXX maybe would be useful to map new list to old list to keep track of valid instances as much as possible
269
        // XXX maybe would be useful to map new list to old list to keep track of valid instances as much as possible
(-)a/editor.guards/src/org/netbeans/modules/editor/guards/GuardsAccessor.java (+2 lines)
Lines 74-77 Link Here
74
    
74
    
75
    public abstract GuardedSectionImpl getImpl(GuardedSection gs);
75
    public abstract GuardedSectionImpl getImpl(GuardedSection gs);
76
    
76
    
77
    public abstract GuardedSection clone(GuardedSection gs, int offset);
78
    
77
}
79
}
(-)a/editor.guards/src/org/netbeans/spi/editor/guards/support/AbstractGuardedSectionsProvider.java (+12 lines)
Lines 69-81 Link Here
69
public abstract class AbstractGuardedSectionsProvider implements GuardedSectionsProvider {
69
public abstract class AbstractGuardedSectionsProvider implements GuardedSectionsProvider {
70
70
71
    private final GuardedSectionsImpl impl;
71
    private final GuardedSectionsImpl impl;
72
    private final boolean useReadersWritersOnSet;
72
    
73
    
73
    /**
74
    /**
74
     * Creates an AbstractGuardedSectionsProvider.
75
     * Creates an AbstractGuardedSectionsProvider.
75
     * @param editor an editor abstraction
76
     * @param editor an editor abstraction
76
     */
77
     */
77
    protected AbstractGuardedSectionsProvider(GuardedEditorSupport editor) {
78
    protected AbstractGuardedSectionsProvider(GuardedEditorSupport editor) {
79
        this(editor, false);
80
    }
81
    
82
    /**
83
     * Creates an AbstractGuardedSectionsProvider.
84
     * @param editor an editor abstraction
85
     * @param useReadersWritersOnSet if readers and writers should be used when the content of the guarded section's text is set
86
     * @since 1.20
87
     */
88
    protected AbstractGuardedSectionsProvider(GuardedEditorSupport editor, boolean useReadersWritersOnSet) {
78
        this.impl = new GuardedSectionsImpl(editor);
89
        this.impl = new GuardedSectionsImpl(editor);
90
        this.useReadersWritersOnSet = useReadersWritersOnSet;
79
    }
91
    }
80
92
81
    public final Reader createGuardedReader(InputStream stream, Charset charset) {
93
    public final Reader createGuardedReader(InputStream stream, Charset charset) {
(-)a/java.guards/nbproject/project.xml (-1 / +1 lines)
Lines 55-61 Link Here
55
                    <compile-dependency/>
55
                    <compile-dependency/>
56
                    <run-dependency>
56
                    <run-dependency>
57
                        <release-version>1</release-version>
57
                        <release-version>1</release-version>
58
                        <specification-version>1.0</specification-version>
58
                        <specification-version>1.20</specification-version>
59
                    </run-dependency>
59
                    </run-dependency>
60
                </dependency>
60
                </dependency>
61
                <dependency>
61
                <dependency>
(-)a/java.guards/src/org/netbeans/modules/java/guards/JavaGuardedReader.java (-22 / +9 lines)
Lines 78-94 Link Here
78
     * 2. Replace the comments with spaces to hide them from user but to preserve
78
     * 2. Replace the comments with spaces to hide them from user but to preserve
79
     *    overall length and positions.
79
     *    overall length and positions.
80
     * 3. Remove the comments completely.
80
     * 3. Remove the comments completely.
81
     * Default is #3, can be changed via branding. For a long time #2 used to be
81
     * 
82
     * the default, but neither 1 nor 2 is reliable since artificial chars are
82
     * Option #3 causes that offsets inside the editor differ from the offsets on disk,
83
     * made part of the sections' content which the clients do not know about.
83
     * which then breaks many clients that create PositionRefs for a closed file and then
84
     * Once a client changes the section content, the artificial comments or spaces
84
     * use it for an opened file, and vice versa.
85
     * are gone from the document, but they get written to the file on saving and
85
     * 
86
     * so the file is then inconsistent with the document just like in case of #3.
86
     * Default is #2.
87
     */
87
     */
88
    private static boolean KEEP_GUARD_COMMENTS    // not final only for tests
88
    private static boolean KEEP_GUARD_COMMENTS    // not final only for tests
89
            = getPresetValue("KEEP_GUARD_COMMENTS", false); // NOI18N
89
            = getPresetValue("KEEP_GUARD_COMMENTS", false); // NOI18N
90
    private static boolean REPLACE_GUARD_COMMENTS_WITH_SPACES    // not final only for tests
91
            = getPresetValue("REPLACE_GUARD_COMMENTS_WITH_SPACES", false); // NOI18N
92
90
93
    /** The list of the SectionsDesc. */
91
    /** The list of the SectionsDesc. */
94
    private final LinkedList<SectionDescriptor> list;
92
    private final LinkedList<SectionDescriptor> list;
Lines 219-231 Link Here
219
                    if (KEEP_GUARD_COMMENTS) { // keep guard comment (content unchanged)
217
                    if (KEEP_GUARD_COMMENTS) { // keep guard comment (content unchanged)
220
                        i -= match.length();
218
                        i -= match.length();
221
                        charBuffPtr += MAGICLEN;
219
                        charBuffPtr += MAGICLEN;
222
                    } else if (REPLACE_GUARD_COMMENTS_WITH_SPACES) {
220
                    } else {
223
                        i += toNl;
221
                        i += toNl;
224
                        Arrays.fill(charBuff,charBuffPtr,charBuffPtr+sectionSize,' ');
222
                        Arrays.fill(charBuff,charBuffPtr,charBuffPtr+sectionSize,' ');
225
                        charBuffPtr+=sectionSize;
223
                        charBuffPtr+=sectionSize;
226
                    } else { // remove the guard comment
227
                        i += toNl;
228
                        desc.setEnd(charBuffPtr);
229
                    }
224
                    }
230
                }
225
                }
231
            }
226
            }
Lines 400-414 Link Here
400
        return defaultValue;
395
        return defaultValue;
401
    }
396
    }
402
397
403
    static void setGuardCommentProcessingForTest(int type) {
398
    static void setKeepGuardCommentsForTest(boolean keep) {
404
        if (type == 1) {
399
        KEEP_GUARD_COMMENTS = keep;
405
            KEEP_GUARD_COMMENTS = true;
406
        } else if (type == 2) {
407
            KEEP_GUARD_COMMENTS = false;
408
            REPLACE_GUARD_COMMENTS_WITH_SPACES = true;
409
        } else if (type == 3) {
410
            KEEP_GUARD_COMMENTS = false;
411
            REPLACE_GUARD_COMMENTS_WITH_SPACES = false;
412
        }
413
    }
400
    }
414
}
401
}
(-)a/java.guards/src/org/netbeans/modules/java/guards/JavaGuardedSectionsProvider.java (-1 / +1 lines)
Lines 56-62 Link Here
56
public final class JavaGuardedSectionsProvider extends AbstractGuardedSectionsProvider {
56
public final class JavaGuardedSectionsProvider extends AbstractGuardedSectionsProvider {
57
    
57
    
58
    public JavaGuardedSectionsProvider(GuardedEditorSupport editor) {
58
    public JavaGuardedSectionsProvider(GuardedEditorSupport editor) {
59
        super(editor);
59
        super(editor, true);
60
    }
60
    }
61
61
62
    public char[] writeSections(List<GuardedSection> sections, char[] buff) {
62
    public char[] writeSections(List<GuardedSection> sections, char[] buff) {
(-)a/java.guards/test/unit/src/org/netbeans/modules/java/guards/JavaGuardedReaderTest.java (-26 / +2 lines)
Lines 71-77 Link Here
71
        provider = new JavaGuardedSectionsProvider(editor);
71
        provider = new JavaGuardedSectionsProvider(editor);
72
        
72
        
73
        instance = new JavaGuardedReader(provider);
73
        instance = new JavaGuardedReader(provider);
74
        JavaGuardedReader.setGuardCommentProcessingForTest(2);
75
    }
74
    }
76
75
77
    protected void tearDown() throws Exception {
76
    protected void tearDown() throws Exception {
Lines 124-130 Link Here
124
        String expStr =  "\nclass A {//" + "GEN-BEGIN:hu\n\n}//" + "GEN-END:hu\n";
123
        String expStr =  "\nclass A {//" + "GEN-BEGIN:hu\n\n}//" + "GEN-END:hu\n";
125
        char[] readBuff = readStr.toCharArray();
124
        char[] readBuff = readStr.toCharArray();
126
125
127
        JavaGuardedReader.setGuardCommentProcessingForTest(1);
126
        JavaGuardedReader.setKeepGuardCommentsForTest(true);
128
        char[] result = instance.translateToCharBuff(readBuff);
127
        char[] result = instance.translateToCharBuff(readBuff);
129
        List<GuardedSection> sections = instance.getGuardedSections();
128
        List<GuardedSection> sections = instance.getGuardedSections();
130
        
129
        
Lines 147-176 Link Here
147
        String expStr =  "\nclass A {  " + "            \n\n}  " + "          \n";
146
        String expStr =  "\nclass A {  " + "            \n\n}  " + "          \n";
148
        char[] readBuff = readStr.toCharArray();
147
        char[] readBuff = readStr.toCharArray();
149
        
148
        
150
        JavaGuardedReader.setGuardCommentProcessingForTest(2);
149
        JavaGuardedReader.setKeepGuardCommentsForTest(false);
151
        char[] result = instance.translateToCharBuff(readBuff);
152
        List<GuardedSection> sections = instance.getGuardedSections();
153
        
154
        assertEquals(expStr, String.valueOf(result));
155
        assertEquals("sections", 1, sections.size());
156
        
157
        GuardedSection expSection = sections.get(0);
158
        assertEquals(SimpleSection.class, expSection.getClass());
159
        assertEquals("section valid", true, expSection.isValid());
160
        assertEquals("section name", "hu", expSection.getName());
161
        assertEquals("begin", 1, expSection.getStartPosition().getOffset());
162
        assertEquals("end", expStr.length() - 1, expSection.getEndPosition().getOffset());
163
    }
164
165
    public void testTranslateBEGIN_END3() {
166
        System.out.println("read //" + "GEN-BEGIN_END3:");
167
        
168
        String readStr = "\nclass A {//" + "GEN-BEGIN:hu\n\n}//" + "GEN-END:hu\n";
169
        editor.setStringContent(readStr);
170
        String expStr =  "\nclass A {" +               "\n\n}" +              "\n";
171
        char[] readBuff = readStr.toCharArray();
172
        
173
        JavaGuardedReader.setGuardCommentProcessingForTest(3);
174
        char[] result = instance.translateToCharBuff(readBuff);
150
        char[] result = instance.translateToCharBuff(readBuff);
175
        List<GuardedSection> sections = instance.getGuardedSections();
151
        List<GuardedSection> sections = instance.getGuardedSections();
176
        
152
        

Return to bug 221844