1 /* |
1 /* |
2 * Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 1999, 2014, 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 |
465 return false; |
465 return false; |
466 } |
466 } |
467 |
467 |
468 private boolean hiddenIn(ClassSymbol clazz, Types types) { |
468 private boolean hiddenIn(ClassSymbol clazz, Types types) { |
469 Symbol sym = hiddenInInternal(clazz, types); |
469 Symbol sym = hiddenInInternal(clazz, types); |
470 return sym != null && sym != this; |
470 Assert.check(sym != null, "the result of hiddenInInternal() can't be null"); |
471 } |
471 /* If we find the current symbol then there is no symbol hiding it |
472 |
472 */ |
473 private Symbol hiddenInInternal(ClassSymbol c, Types types) { |
473 return sym != this; |
474 Scope.Entry e = c.members().lookup(name); |
474 } |
|
475 |
|
476 /** This method looks in the supertypes graph that has the current class as the |
|
477 * initial node, till it finds the current symbol or another symbol that hides it. |
|
478 * If the current class has more than one supertype (extends one class and |
|
479 * implements one or more interfaces) then null can be returned, meaning that |
|
480 * a wrong path in the supertypes graph was selected. Null can only be returned |
|
481 * as a temporary value, as a result of the recursive call. |
|
482 */ |
|
483 private Symbol hiddenInInternal(ClassSymbol currentClass, Types types) { |
|
484 if (currentClass == owner) { |
|
485 return this; |
|
486 } |
|
487 Scope.Entry e = currentClass.members().lookup(name); |
475 while (e.scope != null) { |
488 while (e.scope != null) { |
476 if (e.sym.kind == kind && |
489 if (e.sym.kind == kind && |
477 (kind != MTH || |
490 (kind != MTH || |
478 (e.sym.flags() & STATIC) != 0 && |
491 (e.sym.flags() & STATIC) != 0 && |
479 types.isSubSignature(e.sym.type, type))) { |
492 types.isSubSignature(e.sym.type, type))) { |
480 return e.sym; |
493 return e.sym; |
481 } |
494 } |
482 e = e.next(); |
495 e = e.next(); |
483 } |
496 } |
484 List<Symbol> hiddenSyms = List.nil(); |
497 Symbol hiddenSym = null; |
485 for (Type st : types.interfaces(c.type).prepend(types.supertype(c.type))) { |
498 for (Type st : types.interfaces(currentClass.type) |
|
499 .prepend(types.supertype(currentClass.type))) { |
486 if (st != null && (st.hasTag(CLASS))) { |
500 if (st != null && (st.hasTag(CLASS))) { |
487 Symbol sym = hiddenInInternal((ClassSymbol)st.tsym, types); |
501 Symbol sym = hiddenInInternal((ClassSymbol)st.tsym, types); |
488 if (sym != null) { |
502 if (sym == this) { |
489 hiddenSyms = hiddenSyms.prepend(hiddenInInternal((ClassSymbol)st.tsym, types)); |
503 return this; |
|
504 } else if (sym != null) { |
|
505 hiddenSym = sym; |
490 } |
506 } |
491 } |
507 } |
492 } |
508 } |
493 return hiddenSyms.contains(this) ? |
509 return hiddenSym; |
494 this : |
|
495 (hiddenSyms.isEmpty() ? null : hiddenSyms.head); |
|
496 } |
510 } |
497 |
511 |
498 /** Is this symbol inherited into a given class? |
512 /** Is this symbol inherited into a given class? |
499 * PRE: If symbol's owner is a interface, |
513 * PRE: If symbol's owner is a interface, |
500 * it is already assumed that the interface is a superinterface |
514 * it is already assumed that the interface is a superinterface |