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

(-)a/java.source/apichanges.xml (+14 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="treeutilities-parse-errors">
112
             <api name="general"/>
113
             <summary>TreeUtilities.parse{Statement,Expression,VariableInitializer,StaticBlock} has been extended to provide parse errors</summary>
114
             <version major="0" minor="71"/>
115
             <date day="25" month="11" year="2010"/>
116
             <author login="jlahoda"/>
117
             <compatibility binary="compatible" deletion="no" deprecation="no" modification="no" addition="yes" semantic="compatible" source="compatible"/>
118
             <description>
119
                 <code>org.netbeans.api.java.source.TreeUtilities</code> has been extended with variants
120
                 of parseStatement,parseExpression,parseVariableInitializer and parseStaticBlock that
121
                 return compilation errors produced during parsing.
122
             </description>
123
             <class package="org.netbeans.api.java.source" name="TreeUtilities"/>
124
        </change>
111
        <change id="jdk7-update-2">
125
        <change id="jdk7-update-2">
112
             <api name="general"/>
126
             <api name="general"/>
113
             <summary>DisjointTypeTree renamed to DisjunctiveTypeTree, AnnotationTypeTree has been removed</summary>
127
             <summary>DisjointTypeTree renamed to DisjunctiveTypeTree, AnnotationTypeTree has been removed</summary>
(-)a/java.source/nbproject/project.properties (-1 / +1 lines)
Lines 46-52 Link Here
46
javadoc.title=Java Source
46
javadoc.title=Java Source
47
javadoc.arch=${basedir}/arch.xml
47
javadoc.arch=${basedir}/arch.xml
48
javadoc.apichanges=${basedir}/apichanges.xml
48
javadoc.apichanges=${basedir}/apichanges.xml
49
spec.version.base=0.70.0
49
spec.version.base=0.71.0
50
test.qa-functional.cp.extra=${refactoring.java.dir}/modules/ext/javac-api-nb-7.0-b07.jar
50
test.qa-functional.cp.extra=${refactoring.java.dir}/modules/ext/javac-api-nb-7.0-b07.jar
51
test.unit.run.cp.extra=${o.n.core.dir}/core/core.jar:\
51
test.unit.run.cp.extra=${o.n.core.dir}/core/core.jar:\
52
    ${o.n.core.dir}/lib/boot.jar:\
52
    ${o.n.core.dir}/lib/boot.jar:\
(-)a/java.source/src/org/netbeans/api/java/source/TreeUtilities.java (-6 / +69 lines)
Lines 62-67 Link Here
62
import com.sun.tools.javac.tree.JCTree.JCMethodDecl;
62
import com.sun.tools.javac.tree.JCTree.JCMethodDecl;
63
import com.sun.tools.javac.util.Context;
63
import com.sun.tools.javac.util.Context;
64
import java.util.*;
64
import java.util.*;
65
import java.util.ArrayList;
65
import java.util.logging.Level;
66
import java.util.logging.Level;
66
import java.util.logging.Logger;
67
import java.util.logging.Logger;
67
import javax.lang.model.SourceVersion;
68
import javax.lang.model.SourceVersion;
Lines 69-74 Link Here
69
import javax.lang.model.type.TypeKind;
70
import javax.lang.model.type.TypeKind;
70
import javax.lang.model.type.TypeMirror;
71
import javax.lang.model.type.TypeMirror;
71
import javax.lang.model.util.Types;
72
import javax.lang.model.util.Types;
73
import javax.tools.Diagnostic;
74
import javax.tools.DiagnosticListener;
75
import javax.tools.JavaFileObject;
72
import org.netbeans.api.annotations.common.NonNull;
76
import org.netbeans.api.annotations.common.NonNull;
73
import org.netbeans.api.java.lexer.JavaTokenId;
77
import org.netbeans.api.java.lexer.JavaTokenId;
74
import org.netbeans.api.java.source.JavaSource.Phase;
78
import org.netbeans.api.java.source.JavaSource.Phase;
Lines 388-404 Link Here
388
    }
392
    }
389
    
393
    
390
    /**Parses given statement.
394
    /**Parses given statement.
391
     * 
395
     *
392
     * @param stmt statement code
396
     * @param stmt statement code
393
     * @param sourcePositions return value - new SourcePositions for the new tree
397
     * @param sourcePositions return value - new SourcePositions for the new tree
394
     * @return parsed {@link StatementTree} or null?
398
     * @return parsed {@link StatementTree} or null?
395
     */
399
     */
396
    public StatementTree parseStatement(String stmt, SourcePositions[] sourcePositions) {
400
    public StatementTree parseStatement(String stmt, SourcePositions[] sourcePositions) {
401
        return parseStatement(stmt, sourcePositions, new ArrayList<Diagnostic<?>>());
402
    }
403
404
    /**Parses given statement.
405
     * 
406
     * @param stmt statement code
407
     * @param sourcePositions return value - new SourcePositions for the new tree
408
     * @param errors return value - Diagnostics found while parsing the given code
409
     * @return parsed {@link StatementTree} or null?
410
     * @since 0.71
411
     */
412
    public StatementTree parseStatement(String stmt, SourcePositions[] sourcePositions, List<? super Diagnostic<?>> errors) {
397
        com.sun.tools.javac.tree.TreeMaker jcMaker = com.sun.tools.javac.tree.TreeMaker.instance(info.impl.getJavacTask().getContext());
413
        com.sun.tools.javac.tree.TreeMaker jcMaker = com.sun.tools.javac.tree.TreeMaker.instance(info.impl.getJavacTask().getContext());
398
        int oldPos = jcMaker.pos;
414
        int oldPos = jcMaker.pos;
399
        
415
        
400
        try {
416
        try {
401
            return (StatementTree)info.impl.getJavacTask().parseStatement(stmt, sourcePositions);
417
            return (StatementTree)info.impl.getJavacTask().parseStatement(stmt, sourcePositions, new CollectingDiagnosticListener(errors));
402
        } finally {
418
        } finally {
403
            jcMaker.pos = oldPos;
419
            jcMaker.pos = oldPos;
404
        }
420
        }
Lines 411-421 Link Here
411
     * @return parsed {@link ExpressionTree} or null?
427
     * @return parsed {@link ExpressionTree} or null?
412
     */
428
     */
413
    public ExpressionTree parseExpression(String expr, SourcePositions[] sourcePositions) {
429
    public ExpressionTree parseExpression(String expr, SourcePositions[] sourcePositions) {
430
        return parseExpression(expr, sourcePositions, new ArrayList<Diagnostic<?>>());
431
    }
432
433
    /**Parses given expression.
434
     *
435
     * @param expr expression code
436
     * @param sourcePositions return value - new SourcePositions for the new tree
437
     * @param errors return value - Diagnostics found while parsing the given code
438
     * @return parsed {@link ExpressionTree} or null?
439
     * @since 0.71
440
     */
441
    public ExpressionTree parseExpression(String expr, SourcePositions[] sourcePositions, List<? super Diagnostic<?>> errors) {
414
        com.sun.tools.javac.tree.TreeMaker jcMaker = com.sun.tools.javac.tree.TreeMaker.instance(info.impl.getJavacTask().getContext());
442
        com.sun.tools.javac.tree.TreeMaker jcMaker = com.sun.tools.javac.tree.TreeMaker.instance(info.impl.getJavacTask().getContext());
415
        int oldPos = jcMaker.pos;
443
        int oldPos = jcMaker.pos;
416
        
444
        
417
        try {
445
        try {
418
            return (ExpressionTree) info.impl.getJavacTask().parseExpression(expr, sourcePositions);
446
            return (ExpressionTree) info.impl.getJavacTask().parseExpression(expr, sourcePositions, new CollectingDiagnosticListener(errors));
419
        } finally {
447
        } finally {
420
            jcMaker.pos = oldPos;
448
            jcMaker.pos = oldPos;
421
        }
449
        }
Lines 428-460 Link Here
428
     * @return parsed {@link ExpressionTree} or null?
456
     * @return parsed {@link ExpressionTree} or null?
429
     */
457
     */
430
    public ExpressionTree parseVariableInitializer(String init, SourcePositions[] sourcePositions) {
458
    public ExpressionTree parseVariableInitializer(String init, SourcePositions[] sourcePositions) {
459
        return parseVariableInitializer(init, sourcePositions, new ArrayList<Diagnostic<?>>());
460
    }
461
462
    /**Parses given variable initializer.
463
     *
464
     * @param init initializer code
465
     * @param sourcePositions return value - new SourcePositions for the new tree
466
     * @param errors return value - Diagnostics found while parsing the given code
467
     * @return parsed {@link ExpressionTree} or null?
468
     * @since 0.71
469
     */
470
    public ExpressionTree parseVariableInitializer(String init, SourcePositions[] sourcePositions, List<? super Diagnostic<?>> errors) {
431
        com.sun.tools.javac.tree.TreeMaker jcMaker = com.sun.tools.javac.tree.TreeMaker.instance(info.impl.getJavacTask().getContext());
471
        com.sun.tools.javac.tree.TreeMaker jcMaker = com.sun.tools.javac.tree.TreeMaker.instance(info.impl.getJavacTask().getContext());
432
        int oldPos = jcMaker.pos;
472
        int oldPos = jcMaker.pos;
433
        
473
        
434
        try {
474
        try {
435
            return (ExpressionTree)info.impl.getJavacTask().parseVariableInitializer(init, sourcePositions);
475
            return (ExpressionTree)info.impl.getJavacTask().parseVariableInitializer(init, sourcePositions, new CollectingDiagnosticListener(errors));
436
        } finally {
476
        } finally {
437
            jcMaker.pos = oldPos;
477
            jcMaker.pos = oldPos;
438
        }
478
        }
439
    }
479
    }
440
480
441
    /**Parses given static block.
481
    /**Parses given static block.
442
     * 
482
     *
443
     * @param block block code
483
     * @param block block code
444
     * @param sourcePositions return value - new SourcePositions for the new tree
484
     * @param sourcePositions return value - new SourcePositions for the new tree
445
     * @return parsed {@link BlockTree} or null?
485
     * @return parsed {@link BlockTree} or null?
446
     */
486
     */
447
    public BlockTree parseStaticBlock(String block, SourcePositions[] sourcePositions) {
487
    public BlockTree parseStaticBlock(String block, SourcePositions[] sourcePositions) {
488
        return parseStaticBlock(block, sourcePositions, new ArrayList<Diagnostic<?>>());
489
    }
490
491
    /**Parses given static block.
492
     * 
493
     * @param block block code
494
     * @param sourcePositions return value - new SourcePositions for the new tree
495
     * @param errors return value - Diagnostics found while parsing the given code
496
     * @return parsed {@link BlockTree} or null?
497
     * @since 0.71
498
     */
499
    public BlockTree parseStaticBlock(String block, SourcePositions[] sourcePositions, List<? super Diagnostic<?>> errors) {
448
        com.sun.tools.javac.tree.TreeMaker jcMaker = com.sun.tools.javac.tree.TreeMaker.instance(info.impl.getJavacTask().getContext());
500
        com.sun.tools.javac.tree.TreeMaker jcMaker = com.sun.tools.javac.tree.TreeMaker.instance(info.impl.getJavacTask().getContext());
449
        int oldPos = jcMaker.pos;
501
        int oldPos = jcMaker.pos;
450
        
502
        
451
        try {
503
        try {
452
            return (BlockTree)info.impl.getJavacTask().parseStaticBlock(block, sourcePositions);
504
            return (BlockTree)info.impl.getJavacTask().parseStaticBlock(block, sourcePositions, new CollectingDiagnosticListener(errors));
453
        } finally {
505
        } finally {
454
            jcMaker.pos = oldPos;
506
            jcMaker.pos = oldPos;
455
        }
507
        }
456
    }
508
    }
457
509
510
    private static final class CollectingDiagnosticListener implements DiagnosticListener<JavaFileObject>  {
511
        private final List<? super Diagnostic<?>> errors;
512
        public CollectingDiagnosticListener(List<? super Diagnostic<?>> errors) {
513
            this.errors = errors;
514
        }
515
        @Override
516
        public void report(Diagnostic<? extends JavaFileObject> diagnostic) {
517
            errors.add(diagnostic);
518
        }
519
    }
520
458
    //XXX: parseAnnotationValue
521
    //XXX: parseAnnotationValue
459
    
522
    
460
    /**Computes {@link Scope} for the given position.
523
    /**Computes {@link Scope} for the given position.

Return to bug 190904