[Nice-commit] Nice/src/bossa/syntax OverloadedSymbolExp.java,1.68,1.69
Brought to you by:
bonniot
From: Daniel B. <bo...@us...> - 2004-06-10 13:40:36
|
Update of /cvsroot/nice/Nice/src/bossa/syntax In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv18889/src/bossa/syntax Modified Files: OverloadedSymbolExp.java Log Message: Allow calls to Java methods defined in a Java class that implements several Java interfaces declaring that same method, like java.io.ObjectOutputStream.flush() Index: OverloadedSymbolExp.java =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/OverloadedSymbolExp.java,v retrieving revision 1.68 retrieving revision 1.69 diff -C2 -d -r1.68 -r1.69 *** OverloadedSymbolExp.java 26 Feb 2004 22:17:39 -0000 1.68 --- OverloadedSymbolExp.java 10 Jun 2004 13:40:27 -0000 1.69 *************** *** 196,199 **** --- 196,200 ---- removeNonMinimal(symbols, arguments); + removeOverlappingJavaMethods(symbols); if (symbols.size() == 1) *************** *** 523,526 **** --- 524,567 ---- } + /** + When a Java class implements two interfaces, + there is no ambiguity between methods of the same signature + defined in both interfaces, since they are implemented by the same + method in the class. So this method removes all but one of the + overlapping methods. + */ + private static void removeOverlappingJavaMethods(List symbols) + { + // optimization + if(symbols.size()<2) + return; + + int len = symbols.size(); + VarSymbol[] syms = (VarSymbol[]) + symbols.toArray(new VarSymbol[len]); + + for (int i = 0; i < syms.length; i++) + for (int j = i+1; j < syms.length; j++) + if (overlappingJavaMethods(syms[i].getMethodDeclaration(), + syms[j].getMethodDeclaration())) + { + // We can remove either, since they lead to the same implementation + symbols.remove(syms[i]); + // Since we removed i, we don't need to continue this loop. + // This would not be true if we decided to remove j. + break; + } + } + + private static boolean overlappingJavaMethods(MethodDeclaration m1, + MethodDeclaration m2) + { + if (! (m1 instanceof JavaMethod) || + ! (m2 instanceof JavaMethod)) + return false; + + return Arrays.equals(m1.javaArgTypes(), m2.javaArgTypes()); + } + void computeType() { |