1 /* |
1 /* |
2 * Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 1999, 2012, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * |
4 * |
5 * This code is free software; you can redistribute it and/or modify it |
5 * This code is free software; you can redistribute it and/or modify it |
6 * under the terms of the GNU General Public License version 2 only, as |
6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. Oracle designates this |
7 * published by the Free Software Foundation. Oracle designates this |
2112 * @param site The class whose methods are checked. |
2112 * @param site The class whose methods are checked. |
2113 * @param sym The method symbol to be checked. |
2113 * @param sym The method symbol to be checked. |
2114 */ |
2114 */ |
2115 void checkOverrideClashes(DiagnosticPosition pos, Type site, MethodSymbol sym) { |
2115 void checkOverrideClashes(DiagnosticPosition pos, Type site, MethodSymbol sym) { |
2116 ClashFilter cf = new ClashFilter(site); |
2116 ClashFilter cf = new ClashFilter(site); |
2117 //for each method m1 that is a member of 'site'... |
2117 //for each method m1 that is overridden (directly or indirectly) |
2118 for (Symbol s1 : types.membersClosure(site, false).getElementsByName(sym.name, cf)) { |
2118 //by method 'sym' in 'site'... |
2119 //...find another method m2 that is overridden (directly or indirectly) |
2119 for (Symbol m1 : types.membersClosure(site, false).getElementsByName(sym.name, cf)) { |
2120 //by method 'sym' in 'site' |
2120 if (!sym.overrides(m1, site.tsym, types, false)) continue; |
2121 for (Symbol s2 : types.membersClosure(site, false).getElementsByName(sym.name, cf)) { |
2121 //...check each method m2 that is a member of 'site' |
2122 if (s1 == s2 || !sym.overrides(s2, site.tsym, types, false)) continue; |
2122 for (Symbol m2 : types.membersClosure(site, false).getElementsByName(sym.name, cf)) { |
|
2123 if (m2 == m1) continue; |
2123 //if (i) the signature of 'sym' is not a subsignature of m1 (seen as |
2124 //if (i) the signature of 'sym' is not a subsignature of m1 (seen as |
2124 //a member of 'site') and (ii) m1 has the same erasure as m2, issue an error |
2125 //a member of 'site') and (ii) m1 has the same erasure as m2, issue an error |
2125 if (!types.isSubSignature(sym.type, types.memberType(site, s1), false) && |
2126 if (!types.isSubSignature(sym.type, types.memberType(site, m2), false) && |
2126 types.hasSameArgs(s1.erasure(types), s2.erasure(types))) { |
2127 types.hasSameArgs(m2.erasure(types), m1.erasure(types))) { |
2127 sym.flags_field |= CLASH; |
2128 sym.flags_field |= CLASH; |
2128 String key = s2 == sym ? |
2129 String key = m1 == sym ? |
2129 "name.clash.same.erasure.no.override" : |
2130 "name.clash.same.erasure.no.override" : |
2130 "name.clash.same.erasure.no.override.1"; |
2131 "name.clash.same.erasure.no.override.1"; |
2131 log.error(pos, |
2132 log.error(pos, |
2132 key, |
2133 key, |
2133 sym, sym.location(), |
2134 sym, sym.location(), |
2134 s1, s1.location(), |
2135 m2, m2.location(), |
2135 s2, s2.location()); |
2136 m1, m1.location()); |
2136 return; |
2137 return; |
2137 } |
2138 } |
2138 } |
2139 } |
2139 } |
2140 } |
2140 } |
2141 } |