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

(-)a/java.hints/src/org/netbeans/modules/java/hints/errors/AddParameterOrLocalFix.java (-1 / +5 lines)
Lines 43-48 Link Here
43
43
44
import com.sun.source.tree.AssignmentTree;
44
import com.sun.source.tree.AssignmentTree;
45
import com.sun.source.tree.BlockTree;
45
import com.sun.source.tree.BlockTree;
46
import com.sun.source.tree.EnhancedForLoopTree;
46
import com.sun.source.tree.ExpressionStatementTree;
47
import com.sun.source.tree.ExpressionStatementTree;
47
import com.sun.source.tree.ExpressionTree;
48
import com.sun.source.tree.ExpressionTree;
48
import com.sun.source.tree.IdentifierTree;
49
import com.sun.source.tree.IdentifierTree;
Lines 298-304 Link Here
298
        Tree statementParent = firstUse.getParentPath().getLeaf();
299
        Tree statementParent = firstUse.getParentPath().getLeaf();
299
        VariableTree vt = make.Variable(make.Modifiers(EnumSet.noneOf(Modifier.class)), name, make.Type(proposedType), null);
300
        VariableTree vt = make.Variable(make.Modifiers(EnumSet.noneOf(Modifier.class)), name, make.Type(proposedType), null);
300
301
301
        if (statementParent.getKind() == Kind.BLOCK) {
302
        if (statement.getKind() == Kind.ENHANCED_FOR_LOOP){
303
            EnhancedForLoopTree forTree = (EnhancedForLoopTree) statement;
304
            wc.rewrite(forTree.getVariable(), vt);
305
        } else if (statementParent.getKind() == Kind.BLOCK) {
302
            BlockTree block = (BlockTree) statementParent;
306
            BlockTree block = (BlockTree) statementParent;
303
307
304
            FirstUsage fu = new FirstUsage();
308
            FirstUsage fu = new FirstUsage();
(-)a/java.hints/src/org/netbeans/modules/java/hints/errors/CreateElementUtilities.java (-6 / +19 lines)
Lines 456-468 Link Here
456
            
456
            
457
            return Collections.singletonList(info.getTrees().getTypeMirror(new TreePath(parent, vt.getType())));
457
            return Collections.singletonList(info.getTrees().getTypeMirror(new TreePath(parent, vt.getType())));
458
        }
458
        }
459
        
459
460
        if (vt.getType() == error) {
460
        TreePath context = parent.getParentPath();
461
            types.add(ElementKind.CLASS);
461
        if (vt.getType() != error || context == null) {
462
            return Collections.<TypeMirror>emptyList();
462
            return null;
463
        }
463
        }
464
        
464
465
        return null;
465
        switch (context.getLeaf().getKind()) {
466
            case ENHANCED_FOR_LOOP:
467
                ExpressionTree iterable = ((EnhancedForLoopTree) context.getLeaf()).getExpression();
468
                TypeMirror iterableType = info.getTrees().getTypeMirror(new TreePath(context, iterable));
469
                if (iterableType == null) {
470
                    return null;
471
                }
472
                types.add(ElementKind.LOCAL_VARIABLE);
473
                // hack for testing
474
                return Collections.singletonList(info.getElements().getTypeElement("java.lang.Object").asType()); //NOI18N
475
            default:
476
                types.add(ElementKind.CLASS);
477
                return Collections.<TypeMirror>emptyList();
478
        }
466
    }
479
    }
467
    
480
    
468
    private static List<? extends TypeMirror> computeAssert(Set<ElementKind> types, CompilationInfo info, TreePath parent, Tree error, int offset) {
481
    private static List<? extends TypeMirror> computeAssert(Set<ElementKind> types, CompilationInfo info, TreePath parent, Tree error, int offset) {

Return to bug 142381