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

(-)a/java.source/apichanges.xml (+14 lines)
Lines 105-110 Link Here
105
    <!-- ACTUAL CHANGES BEGIN HERE: -->
105
    <!-- ACTUAL CHANGES BEGIN HERE: -->
106
106
107
    <changes>
107
    <changes>
108
        <change id="GeneratorUtilities.copyComments">
109
             <api name="general"/>
110
             <summary>Added GeneratorUtilities.copyComments method.</summary>
111
             <version major="0" minor="50"/>
112
             <date day="20" month="10" year="2009"/>
113
             <author login="jlahoda"/>
114
             <compatibility addition="yes" binary="compatible" deletion="no" deprecation="no" modification="no" semantic="compatible" source="compatible"/>
115
             <description>
116
                 Added <code>GeneratorUtilities.copyComments</code> method, which
117
                 copies comments from one tree to another tree.
118
             </description>
119
             <class package="org.netbeans.api.java.source" name="GeneratorUtilities"/>
120
             <issue number="170213"/>
121
        </change>
108
        <change id="TreeUtilities.isEnumConstant">
122
        <change id="TreeUtilities.isEnumConstant">
109
             <api name="general"/>
123
             <api name="general"/>
110
             <summary>Added TreeUtilities.isEnumConstant() method.</summary>
124
             <summary>Added TreeUtilities.isEnumConstant() method.</summary>
(-)a/java.source/nbproject/project.properties (-1 / +1 lines)
Lines 43-49 Link Here
43
javadoc.title=Java Source
43
javadoc.title=Java Source
44
javadoc.arch=${basedir}/arch.xml
44
javadoc.arch=${basedir}/arch.xml
45
javadoc.apichanges=${basedir}/apichanges.xml
45
javadoc.apichanges=${basedir}/apichanges.xml
46
spec.version.base=0.49.0
46
spec.version.base=0.50.0
47
test.qa-functional.cp.extra=${refactoring.java.dir}/modules/ext/javac-api-nb-7.0-b07.jar
47
test.qa-functional.cp.extra=${refactoring.java.dir}/modules/ext/javac-api-nb-7.0-b07.jar
48
test.unit.run.cp.extra=${o.n.core.dir}/core/core.jar:\
48
test.unit.run.cp.extra=${o.n.core.dir}/core/core.jar:\
49
    ${o.n.core.dir}/lib/boot.jar:\
49
    ${o.n.core.dir}/lib/boot.jar:\
(-)a/java.source/src/org/netbeans/api/java/source/GeneratorUtilities.java (-1 / +27 lines)
Lines 90-96 Link Here
90
import org.netbeans.api.java.queries.SourceLevelQuery;
90
import org.netbeans.api.java.queries.SourceLevelQuery;
91
import org.netbeans.api.lexer.TokenSequence;
91
import org.netbeans.api.lexer.TokenSequence;
92
import org.netbeans.editor.GuardedDocument;
92
import org.netbeans.editor.GuardedDocument;
93
import org.netbeans.modules.java.source.builder.CommentHandlerService;
94
import org.netbeans.modules.java.source.builder.CommentSetImpl;
93
import org.netbeans.modules.java.source.parsing.SourceFileObject;
95
import org.netbeans.modules.java.source.parsing.SourceFileObject;
96
import org.netbeans.modules.java.source.query.CommentSet.RelativePosition;
94
import org.openide.cookies.EditorCookie;
97
import org.openide.cookies.EditorCookie;
95
import org.openide.loaders.DataObject;
98
import org.openide.loaders.DataObject;
96
import org.openide.modules.SpecificationVersion;
99
import org.openide.modules.SpecificationVersion;
Lines 519-525 Link Here
519
        }
522
        }
520
        return original;
523
        return original;
521
    }
524
    }
522
    
525
526
    /**
527
     * Copy comments from source tree to target tree.
528
     *
529
     * @param source tree to copy comments from
530
     * @param target tree to copy comments to
531
     * @param preceding true iff preceding comments should be copied
532
     * @since 0.50
533
     */
534
    public void copyComments(Tree source, Tree target, boolean preceding) {
535
        CommentHandlerService handler = CommentHandlerService.instance(copy.impl.getJavacTask().getContext());
536
        CommentSetImpl s = handler.getComments(source);
537
538
        TreeUtilities.ensureCommentsMapped(copy, source, s);
539
540
        CommentSetImpl t = handler.getComments(target);
541
542
        if (preceding) {
543
            t.addComments(RelativePosition.PRECEDING, s.getComments(RelativePosition.PRECEDING));
544
        } else {
545
            t.addComments(RelativePosition.INLINE, s.getComments(RelativePosition.INLINE));
546
            t.addComments(RelativePosition.TRAILING, s.getComments(RelativePosition.TRAILING));
547
        }
548
    }
523
    
549
    
524
    // private implementation --------------------------------------------------
550
    // private implementation --------------------------------------------------
525
551
(-)a/java.source/src/org/netbeans/api/java/source/TreeUtilities.java (-9 / +14 lines)
Lines 72-77 Link Here
72
import org.netbeans.modules.java.source.builder.CommentHandlerService;
72
import org.netbeans.modules.java.source.builder.CommentHandlerService;
73
import org.netbeans.modules.java.source.builder.CommentSetImpl;
73
import org.netbeans.modules.java.source.builder.CommentSetImpl;
74
import org.netbeans.modules.java.source.parsing.SourceFileObject;
74
import org.netbeans.modules.java.source.parsing.SourceFileObject;
75
import org.netbeans.modules.java.source.query.CommentSet.RelativePosition;
75
import org.openide.util.Exceptions;
76
import org.openide.util.Exceptions;
76
77
77
/**
78
/**
Lines 184-206 Link Here
184
     */
185
     */
185
    public List<Comment> getComments(Tree tree, boolean preceding) {
186
    public List<Comment> getComments(Tree tree, boolean preceding) {
186
        CommentSetImpl set = handler.getComments(tree);
187
        CommentSetImpl set = handler.getComments(tree);
188
189
        ensureCommentsMapped(info, tree, set);
190
191
        List<Comment> comments = preceding ? set.getPrecedingComments() : set.getTrailingComments();
187
        
192
        
193
        return Collections.unmodifiableList(comments);
194
    }
195
196
    static void ensureCommentsMapped(CompilationInfo info, Tree tree, CommentSetImpl set) {
188
        if (!set.areCommentsMapped()) {
197
        if (!set.areCommentsMapped()) {
189
            boolean assertsEnabled = false;
198
            boolean assertsEnabled = false;
190
            boolean automap = true;
199
            boolean automap = true;
191
            
200
192
            assert assertsEnabled = true;
201
            assert assertsEnabled = true;
193
            
202
194
            if (assertsEnabled) {
203
            if (assertsEnabled) {
195
                TreePath tp = info.getCompilationUnit() == tree ? new TreePath(info.getCompilationUnit()) : TreePath.getPath(info.getCompilationUnit(), tree);
204
                TreePath tp = info.getCompilationUnit() == tree ? new TreePath(info.getCompilationUnit()) : TreePath.getPath(info.getCompilationUnit(), tree);
196
                
205
197
                if (tp == null) {
206
                if (tp == null) {
198
                    Logger.getLogger(TreeUtilities.class.getName()).log(Level.WARNING, "Comment automap requested for Tree not from the root compilation info. Please, make sure to call GeneratorUtilities.importComments before Treeutilities.getComments. Tree: {0}", tree);
207
                    Logger.getLogger(TreeUtilities.class.getName()).log(Level.WARNING, "Comment automap requested for Tree not from the root compilation info. Please, make sure to call GeneratorUtilities.importComments before Treeutilities.getComments. Tree: {0}", tree);
199
                    Logger.getLogger(TreeUtilities.class.getName()).log(Level.INFO, "Caller", new Exception());
208
                    Logger.getLogger(TreeUtilities.class.getName()).log(Level.INFO, "Caller", new Exception());
200
                    automap = false;
209
                    automap = false;
201
                }
210
                }
202
            }
211
            }
203
            
212
204
            if (automap) {
213
            if (automap) {
205
                try {
214
                try {
206
                    TokenSequence<JavaTokenId> seq = ((SourceFileObject) info.getCompilationUnit().getSourceFile()).getTokenHierarchy().tokenSequence(JavaTokenId.language());
215
                    TokenSequence<JavaTokenId> seq = ((SourceFileObject) info.getCompilationUnit().getSourceFile()).getTokenHierarchy().tokenSequence(JavaTokenId.language());
Lines 210-221 Link Here
210
                }
219
                }
211
            }
220
            }
212
        }
221
        }
213
        
214
        List<Comment> comments = preceding ? set.getPrecedingComments() : set.getTrailingComments();
215
        
216
        return Collections.unmodifiableList(comments);
217
    }
222
    }
218
    
223
219
    public TreePath pathFor(int pos) {
224
    public TreePath pathFor(int pos) {
220
        return pathFor(new TreePath(info.getCompilationUnit()), pos);
225
        return pathFor(new TreePath(info.getCompilationUnit()), pos);
221
    }
226
    }
(-)a/java.source/src/org/netbeans/modules/java/source/builder/CommentSetImpl.java (+6 lines)
Lines 138-143 Link Here
138
        commentsMapped();
138
        commentsMapped();
139
    }
139
    }
140
140
141
    public void addComments(RelativePosition positioning, Iterable<? extends Comment> comments) {
142
        for (Comment c : comments) {
143
            addComment(positioning, c);
144
        }
145
    }
146
    
141
    public List<Comment> getComments(RelativePosition positioning) {
147
    public List<Comment> getComments(RelativePosition positioning) {
142
        if (commentsMap.containsKey(positioning)) {
148
        if (commentsMap.containsKey(positioning)) {
143
            return Collections.unmodifiableList(commentsMap.get(positioning));
149
            return Collections.unmodifiableList(commentsMap.get(positioning));

Return to bug 175020