581 } |
581 } |
582 } |
582 } |
583 return declarations; |
583 return declarations; |
584 } |
584 } |
585 |
585 |
586 private static void checkResolveMethod(ResolvedJavaType type, ResolvedJavaType context, ResolvedJavaMethod decl, ResolvedJavaMethod expected) { |
|
587 ResolvedJavaMethod impl = type.resolveConcreteMethod(decl, context); |
|
588 assertEquals(expected, impl); |
|
589 } |
|
590 |
|
591 @Test |
586 @Test |
592 public void resolveMethodTest() { |
587 public void resolveMethodTest() { |
593 ResolvedJavaType context = metaAccess.lookupJavaType(TestResolvedJavaType.class); |
588 ResolvedJavaType context = metaAccess.lookupJavaType(TestResolvedJavaType.class); |
594 for (Class<?> c : classes) { |
589 for (Class<?> c : classes) { |
595 if (c.isInterface() || c.isPrimitive()) { |
590 ResolvedJavaType type = metaAccess.lookupJavaType(c); |
596 ResolvedJavaType type = metaAccess.lookupJavaType(c); |
591 if (c.isInterface()) { |
597 for (Method m : c.getDeclaredMethods()) { |
592 for (Method m : c.getDeclaredMethods()) { |
598 if (JAVA_VERSION <= 1.7D || (!isStatic(m.getModifiers()) && !isPrivate(m.getModifiers()))) { |
593 ResolvedJavaMethod resolved = metaAccess.lookupJavaMethod(m); |
599 ResolvedJavaMethod resolved = metaAccess.lookupJavaMethod(m); |
594 ResolvedJavaMethod impl = type.resolveMethod(resolved, context); |
600 ResolvedJavaMethod impl = type.resolveMethod(resolved, context); |
595 assertEquals(m.toString(), null, impl); |
601 ResolvedJavaMethod expected = resolved.isDefault() || resolved.isAbstract() ? resolved : null; |
596 } |
602 assertEquals(m.toString(), expected, impl); |
597 } else if (c.isPrimitive()) { |
603 } else { |
598 assertEquals("No methods expected", c.getDeclaredMethods().length, 0); |
604 // As of JDK 8, interfaces can have static and private methods |
|
605 } |
|
606 } |
|
607 } else { |
599 } else { |
608 ResolvedJavaType type = metaAccess.lookupJavaType(c); |
|
609 VTable vtable = getVTable(c); |
600 VTable vtable = getVTable(c); |
610 for (Method impl : vtable.methods.values()) { |
601 for (Method impl : vtable.methods.values()) { |
611 Set<Method> decls = findDeclarations(impl, c); |
602 Set<Method> decls = findDeclarations(impl, c); |
612 for (Method decl : decls) { |
603 for (Method decl : decls) { |
613 ResolvedJavaMethod m = metaAccess.lookupJavaMethod(decl); |
604 ResolvedJavaMethod m = metaAccess.lookupJavaMethod(decl); |
614 if (m.isPublic()) { |
605 if (m.isPublic()) { |
615 ResolvedJavaMethod i = metaAccess.lookupJavaMethod(impl); |
606 ResolvedJavaMethod i = metaAccess.lookupJavaMethod(impl); |
616 checkResolveMethod(type, context, m, i); |
607 assertEquals(m.toString(), i, type.resolveMethod(m, context)); |
617 } |
608 } |
618 } |
609 } |
619 } |
610 } |
620 } |
611 } |
621 } |
612 } |
623 |
614 |
624 @Test |
615 @Test |
625 public void resolveConcreteMethodTest() { |
616 public void resolveConcreteMethodTest() { |
626 ResolvedJavaType context = metaAccess.lookupJavaType(TestResolvedJavaType.class); |
617 ResolvedJavaType context = metaAccess.lookupJavaType(TestResolvedJavaType.class); |
627 for (Class<?> c : classes) { |
618 for (Class<?> c : classes) { |
628 if (c.isInterface() || c.isPrimitive()) { |
619 ResolvedJavaType type = metaAccess.lookupJavaType(c); |
629 ResolvedJavaType type = metaAccess.lookupJavaType(c); |
620 if (c.isInterface()) { |
630 for (Method m : c.getDeclaredMethods()) { |
621 for (Method m : c.getDeclaredMethods()) { |
631 if (JAVA_VERSION <= 1.7D || (!isStatic(m.getModifiers()) && !isPrivate(m.getModifiers()))) { |
622 ResolvedJavaMethod resolved = metaAccess.lookupJavaMethod(m); |
632 ResolvedJavaMethod resolved = metaAccess.lookupJavaMethod(m); |
623 ResolvedJavaMethod impl = type.resolveConcreteMethod(resolved, context); |
633 ResolvedJavaMethod impl = type.resolveConcreteMethod(resolved, context); |
624 assertEquals(m.toString(), null, impl); |
634 ResolvedJavaMethod expected = resolved.isDefault() ? resolved : null; |
625 } |
635 assertEquals(m.toString(), expected, impl); |
626 } else if (c.isPrimitive()) { |
636 } else { |
627 assertEquals("No methods expected", c.getDeclaredMethods().length, 0); |
637 // As of JDK 8, interfaces can have static and private methods |
|
638 } |
|
639 } |
|
640 } else { |
628 } else { |
641 ResolvedJavaType type = metaAccess.lookupJavaType(c); |
|
642 VTable vtable = getVTable(c); |
629 VTable vtable = getVTable(c); |
643 for (Method impl : vtable.methods.values()) { |
630 for (Method impl : vtable.methods.values()) { |
644 Set<Method> decls = findDeclarations(impl, c); |
631 Set<Method> decls = findDeclarations(impl, c); |
645 for (Method decl : decls) { |
632 for (Method decl : decls) { |
646 ResolvedJavaMethod m = metaAccess.lookupJavaMethod(decl); |
633 ResolvedJavaMethod m = metaAccess.lookupJavaMethod(decl); |
647 if (m.isPublic()) { |
634 if (m.isPublic()) { |
648 ResolvedJavaMethod i = metaAccess.lookupJavaMethod(impl); |
635 ResolvedJavaMethod i = metaAccess.lookupJavaMethod(impl); |
649 checkResolveMethod(type, context, m, i); |
636 assertEquals(i, type.resolveConcreteMethod(m, context)); |
650 } |
637 } |
651 } |
638 } |
652 } |
639 } |
653 for (Method m : c.getDeclaredMethods()) { |
640 for (Method m : c.getDeclaredMethods()) { |
654 ResolvedJavaMethod impl = type.resolveConcreteMethod(metaAccess.lookupJavaMethod(m), context); |
641 ResolvedJavaMethod impl = type.resolveConcreteMethod(metaAccess.lookupJavaMethod(m), context); |