| 1 |
/******************************************************************************* |
| 2 |
* Copyright (c) 2015 Walter Harley and others |
| 3 |
* |
| 4 |
* This program and the accompanying materials |
| 5 |
* are made available under the terms of the Eclipse Public License 2.0 |
| 6 |
* which accompanies this distribution, and is available at |
| 7 |
* https://www.eclipse.org/legal/epl-2.0/ |
| 8 |
* |
| 9 |
* SPDX-License-Identifier: EPL-2.0 |
| 10 |
*******************************************************************************/ |
| 11 |
package targets.model.pc; |
| 12 |
|
| 13 |
/** |
| 14 |
* Bug 382590 says that Types.asMemberOf(x, y) should work when x is a subclass |
| 15 |
* of the class containing y. |
| 16 |
* |
| 17 |
* See TypeUtilsProc.java, which gets exercised by ModelUtilTests.testTypes*(). |
| 18 |
*/ |
| 19 |
public class AsMemberOf<T> { |
| 20 |
private T f; |
| 21 |
protected T m(T[] t1, T t2) { return f; } |
| 22 |
E<Integer> e = new E<Integer>(); |
| 23 |
|
| 24 |
// Type parameter 'T' of static class is unrelated to 'T' of containing class |
| 25 |
private static class C<T> { |
| 26 |
T x() { return null; } |
| 27 |
} |
| 28 |
|
| 29 |
// Type parameter 'T' of inner class is inherited from the containing class |
| 30 |
private class D { |
| 31 |
T x() { return null; } |
| 32 |
} |
| 33 |
|
| 34 |
// Both container and contained are parameterized |
| 35 |
class E<T2> { |
| 36 |
T x() { return null; } |
| 37 |
T2 y() { return null; } |
| 38 |
} |
| 39 |
|
| 40 |
// Need this so that compiler doesn't complain about unused private members. |
| 41 |
// Members are private to verify that asMemberOf() does not consider visibility, |
| 42 |
// even when accesed through a subclass; this is not explicitly specified, but |
| 43 |
// is true for javac 1.6. |
| 44 |
T publicize() { |
| 45 |
return (m(null, null) == null) ? new C<T>().x() : new D().x(); |
| 46 |
} |
| 47 |
} |
| 48 |
|
| 49 |
interface IAsMemberOf<T> { |
| 50 |
// Types.asMemberOf() should find members in superinterfaces |
| 51 |
void m2(); |
| 52 |
} |
| 53 |
|
| 54 |
abstract class AsMemberOfSub extends AsMemberOf<Long> implements IAsMemberOf<Long> { |
| 55 |
// m2 not implemented; thus class must be abstract |
| 56 |
// f2() intentionally not defined; negative test |
| 57 |
} |
| 58 |
|