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
                tp.getParentPath().getLeaf().equals(((EnhancedForLoopTree) statement).getVariable())) {
304
            wc.rewrite(tp.getParentPath().getLeaf(), 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 (-4 / +34 lines)
Lines 93-98 Link Here
93
import org.netbeans.modules.java.editor.semantic.Utilities;
93
import org.netbeans.modules.java.editor.semantic.Utilities;
94
import org.netbeans.modules.java.hints.infrastructure.ErrorHintsProvider;
94
import org.netbeans.modules.java.hints.infrastructure.ErrorHintsProvider;
95
import org.openide.ErrorManager;
95
import org.openide.ErrorManager;
96
import static org.netbeans.modules.java.hints.errors.Utilities.resolveCapturedType;
96
97
97
/**
98
/**
98
 *
99
 *
Lines 457-468 Link Here
457
            return Collections.singletonList(info.getTrees().getTypeMirror(new TreePath(parent, vt.getType())));
458
            return Collections.singletonList(info.getTrees().getTypeMirror(new TreePath(parent, vt.getType())));
458
        }
459
        }
459
        
460
        
460
        if (vt.getType() == error) {
461
        TreePath context = parent.getParentPath();
461
            types.add(ElementKind.CLASS);
462
        if (vt.getType() != error || context == null) {
462
            return Collections.<TypeMirror>emptyList();
463
            return null;
463
        }
464
        }
464
        
465
        
465
        return null;
466
        switch (context.getLeaf().getKind()) {
467
            case ENHANCED_FOR_LOOP:
468
                TypeElement iterableElement = info.getElements().getTypeElement("java.lang.Iterable"); //NOI18N
469
                ExpressionTree iterable = ((EnhancedForLoopTree) context.getLeaf()).getExpression();
470
                TypeMirror iterableType = info.getTrees().getTypeMirror(new TreePath(context, iterable));
471
                if (iterableType == null) {
472
                    return null;
473
                }
474
                TypeMirror designedType = null;
475
                if (iterableType.getKind() == TypeKind.DECLARED) {
476
                    DeclaredType iterableDeclaredType = (DeclaredType) iterableType;
477
                    if (!info.getTypes().isSubtype(info.getTypes().erasure(iterableDeclaredType), info.getTypes().erasure(iterableElement.asType()))) {
478
                        return null;
479
                    }
480
                    ExecutableElement iteratorMethod = (ExecutableElement) iterableElement.getEnclosedElements().get(0); //XXX
481
                    ExecutableType iteratorMethodType = (ExecutableType) info.getTypes().asMemberOf(iterableDeclaredType, iteratorMethod);
482
                    designedType = ((DeclaredType) iteratorMethodType.getReturnType()).getTypeArguments().get(0); //XXX: assuming the method are correct...
483
                } else if (iterableType.getKind() == TypeKind.ARRAY) {
484
                    designedType = ((ArrayType) iterableType).getComponentType();
485
                }
486
                if (designedType == null) {
487
                    return null;
488
                }
489
                designedType = resolveCapturedType(info, designedType);
490
                types.add(ElementKind.LOCAL_VARIABLE);
491
                return Collections.singletonList(designedType);
492
            default:
493
                types.add(ElementKind.CLASS);
494
                return Collections.<TypeMirror>emptyList();
495
        }
466
    }
496
    }
467
    
497
    
468
    private static List<? extends TypeMirror> computeAssert(Set<ElementKind> types, CompilationInfo info, TreePath parent, Tree error, int offset) {
498
    private static List<? extends TypeMirror> computeAssert(Set<ElementKind> types, CompilationInfo info, TreePath parent, Tree error, int offset) {

Return to bug 142381