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) { |