Author: [email protected] Date: Sun May 24 18:37:00 2009 New Revision: 5468 Added: branches/snapshot-2009.05.12-r5406/user/test/com/google/gwt/dev/jjs/test/singlejso/ - copied from r5466, /trunk/user/test/com/google/gwt/dev/jjs/test/singlejso/ branches/snapshot-2009.05.12-r5406/user/test/com/google/gwt/dev/jjs/test/singlejso/A.java - copied unchanged from r5466, /trunk/user/test/com/google/gwt/dev/jjs/test/singlejso/A.java branches/snapshot-2009.05.12-r5406/user/test/com/google/gwt/dev/jjs/test/singlejso/B1.java - copied unchanged from r5466, /trunk/user/test/com/google/gwt/dev/jjs/test/singlejso/B1.java branches/snapshot-2009.05.12-r5406/user/test/com/google/gwt/dev/jjs/test/singlejso/B2.java - copied unchanged from r5466, /trunk/user/test/com/google/gwt/dev/jjs/test/singlejso/B2.java branches/snapshot-2009.05.12-r5406/user/test/com/google/gwt/dev/jjs/test/singlejso/IA.java - copied unchanged from r5466, /trunk/user/test/com/google/gwt/dev/jjs/test/singlejso/IA.java branches/snapshot-2009.05.12-r5406/user/test/com/google/gwt/dev/jjs/test/singlejso/IB.java - copied unchanged from r5466, /trunk/user/test/com/google/gwt/dev/jjs/test/singlejso/IB.java branches/snapshot-2009.05.12-r5406/user/test/com/google/gwt/dev/jjs/test/singlejso/TypeHierarchyTest.java - copied unchanged from r5466, /trunk/user/test/com/google/gwt/dev/jjs/test/singlejso/TypeHierarchyTest.java Modified: branches/snapshot-2009.05.12-r5406/ (props changed) branches/snapshot-2009.05.12-r5406/dev/core/src/com/google/gwt/core/ext/ServletContainer.java (props changed) branches/snapshot-2009.05.12-r5406/dev/core/src/com/google/gwt/core/ext/ServletContainerLauncher.java (props changed) branches/snapshot-2009.05.12-r5406/dev/core/src/com/google/gwt/dev/jjs/ast/JTypeOracle.java branches/snapshot-2009.05.12-r5406/dev/core/src/com/google/gwt/dev/jjs/impl/CastNormalizer.java branches/snapshot-2009.05.12-r5406/dev/core/src/com/google/gwt/dev/jjs/impl/ControlFlowAnalyzer.java branches/snapshot-2009.05.12-r5406/dev/core/src/com/google/gwt/dev/shell/CompilingClassLoader.java branches/snapshot-2009.05.12-r5406/dev/core/src/com/google/gwt/dev/shell/rewrite/HostedModeClassRewriter.java branches/snapshot-2009.05.12-r5406/dev/core/src/com/google/gwt/dev/shell/rewrite/RewriteSingleJsoImplDispatches.java (contents, props changed) branches/snapshot-2009.05.12-r5406/dev/core/src/com/google/gwt/dev/util/arg/ArgHandlerDisableAggressiveOptimization.java (props changed) branches/snapshot-2009.05.12-r5406/dev/core/src/com/google/gwt/dev/util/arg/ArgHandlerEnableAssertions.java (props changed) branches/snapshot-2009.05.12-r5406/dev/core/src/com/google/gwt/dev/util/arg/ArgHandlerOutDir.java (props changed) branches/snapshot-2009.05.12-r5406/dev/core/src/com/google/gwt/dev/util/arg/ArgHandlerWorkDirOptional.java (props changed) branches/snapshot-2009.05.12-r5406/dev/core/src/com/google/gwt/dev/util/arg/ArgHandlerWorkDirRequired.java (props changed) branches/snapshot-2009.05.12-r5406/distro-source/linux/src/webAppCreator (props changed) branches/snapshot-2009.05.12-r5406/distro-source/mac/src/webAppCreator (props changed) branches/snapshot-2009.05.12-r5406/distro-source/windows/src/webAppCreator.cmd (props changed) branches/snapshot-2009.05.12-r5406/eclipse/samples/Hello/Hello-gwtc.launch (props changed) branches/snapshot-2009.05.12-r5406/samples/dynatable/war/DynaTable.css (props changed) branches/snapshot-2009.05.12-r5406/samples/dynatable/war/DynaTable.html (props changed) branches/snapshot-2009.05.12-r5406/samples/hello/war/Hello.html (props changed) branches/snapshot-2009.05.12-r5406/samples/i18n/war/I18N.css (props changed) branches/snapshot-2009.05.12-r5406/samples/i18n/war/I18N.html (props changed) branches/snapshot-2009.05.12-r5406/samples/json/war/JSON.css (props changed) branches/snapshot-2009.05.12-r5406/samples/json/war/JSON.html (props changed) branches/snapshot-2009.05.12-r5406/samples/mail/war/Mail.css (props changed) branches/snapshot-2009.05.12-r5406/samples/mail/war/Mail.html (props changed) branches/snapshot-2009.05.12-r5406/samples/mail/war/gradient.gif (props changed) branches/snapshot-2009.05.12-r5406/samples/mail/war/leftCorner.gif (props changed) branches/snapshot-2009.05.12-r5406/samples/mail/war/rightCorner.gif (props changed) branches/snapshot-2009.05.12-r5406/samples/showcase/war/Showcase.html (props changed) branches/snapshot-2009.05.12-r5406/samples/simplerpc/war/SimpleRPC.css (props changed) branches/snapshot-2009.05.12-r5406/samples/simplerpc/war/SimpleRPC.html (props changed) branches/snapshot-2009.05.12-r5406/samples/simplexml/war/SimpleXML.css (props changed) branches/snapshot-2009.05.12-r5406/samples/simplexml/war/SimpleXML.html (props changed) branches/snapshot-2009.05.12-r5406/user/src/com/google/gwt/core/client/HttpThrowableReporter.java (props changed) branches/snapshot-2009.05.12-r5406/user/src/com/google/gwt/core/client/JsonUtils.java (props changed) branches/snapshot-2009.05.12-r5406/user/src/com/google/gwt/event/dom/client/HandlesAllFocusEvents.java (props changed) branches/snapshot-2009.05.12-r5406/user/src/com/google/gwt/event/dom/client/HandlesAllKeyEvents.java (props changed) branches/snapshot-2009.05.12-r5406/user/src/com/google/gwt/event/dom/client/HandlesAllMouseEvents.java (props changed) branches/snapshot-2009.05.12-r5406/user/src/com/google/gwt/event/dom/client/KeyCodes.java (props changed) branches/snapshot-2009.05.12-r5406/user/src/com/google/gwt/event/dom/client/PrivateMap.java (props changed) branches/snapshot-2009.05.12-r5406/user/src/com/google/gwt/event/logical/shared/HasValueChangeHandlers.java (props changed) branches/snapshot-2009.05.12-r5406/user/src/com/google/gwt/event/logical/shared/ValueChangeEvent.java (props changed) branches/snapshot-2009.05.12-r5406/user/src/com/google/gwt/event/logical/shared/ValueChangeHandler.java (props changed) branches/snapshot-2009.05.12-r5406/user/src/com/google/gwt/event/shared/DefaultHandlerRegistration.java (props changed) branches/snapshot-2009.05.12-r5406/user/src/com/google/gwt/event/shared/GwtEvent.java (props changed) branches/snapshot-2009.05.12-r5406/user/src/com/google/gwt/event/shared/HandlerRegistration.java (props changed) branches/snapshot-2009.05.12-r5406/user/src/com/google/gwt/resources/ (props changed) branches/snapshot-2009.05.12-r5406/user/src/com/google/gwt/resources/client/ClientBundle.java (props changed) branches/snapshot-2009.05.12-r5406/user/src/com/google/gwt/resources/ext/ClientBundleFields.java (props changed) branches/snapshot-2009.05.12-r5406/user/src/com/google/gwt/resources/ext/ClientBundleRequirements.java (props changed) branches/snapshot-2009.05.12-r5406/user/src/com/google/gwt/resources/rebind/context/AbstractClientBundleGenerator.java (props changed) branches/snapshot-2009.05.12-r5406/user/src/com/google/gwt/resources/rebind/context/InlineClientBundleGenerator.java (props changed) branches/snapshot-2009.05.12-r5406/user/src/com/google/gwt/resources/rebind/context/StaticClientBundleGenerator.java (props changed) branches/snapshot-2009.05.12-r5406/user/src/com/google/gwt/user/RemoteServiceObfuscateTypeNames.gwt.xml (props changed) branches/snapshot-2009.05.12-r5406/user/src/com/google/gwt/user/client/ui/ListenerWrapper.java (props changed) branches/snapshot-2009.05.12-r5406/user/src/com/google/gwt/user/rebind/StringSourceWriter.java (props changed) branches/snapshot-2009.05.12-r5406/user/src/com/google/gwt/user/tools/WebAppCreator.java (props changed) branches/snapshot-2009.05.12-r5406/user/test/com/google/gwt/core/client/HttpThrowableReporterTest.java (props changed) branches/snapshot-2009.05.12-r5406/user/test/com/google/gwt/dev/jjs/CompilerSuite.java branches/snapshot-2009.05.12-r5406/user/test/com/google/gwt/dev/jjs/test/SingleJsoImplTest.java branches/snapshot-2009.05.12-r5406/user/test/com/google/gwt/dev/jjs/test/jsoimpls/UnreferencedImplOfJsoInterface.java (props changed) branches/snapshot-2009.05.12-r5406/user/test/com/google/gwt/dev/jjs/test/jsointfs/JsoInterfaceWithUnreferencedImpl.java (props changed) branches/snapshot-2009.05.12-r5406/user/test/com/google/gwt/event/dom/client/DomEventTest.java (props changed) branches/snapshot-2009.05.12-r5406/user/test/com/google/gwt/event/logical/shared/LogicalEventsTest.java (props changed) branches/snapshot-2009.05.12-r5406/user/test/com/google/gwt/resources/ (props changed) branches/snapshot-2009.05.12-r5406/user/test/com/google/gwt/user/RPCSuiteWithObfuscation.gwt.xml (props changed) branches/snapshot-2009.05.12-r5406/user/test/com/google/gwt/user/client/rpc/CollectionsTestWithTypeObfuscation.java (props changed) branches/snapshot-2009.05.12-r5406/user/test/com/google/gwt/user/client/rpc/CustomFieldSerializerTestWithTypeObfuscation.java (props changed) branches/snapshot-2009.05.12-r5406/user/test/com/google/gwt/user/client/rpc/EnumsTestWithTypeObfuscation.java (props changed) branches/snapshot-2009.05.12-r5406/user/test/com/google/gwt/user/client/rpc/InheritanceTestWithTypeObfuscation.java (props changed) branches/snapshot-2009.05.12-r5406/user/test/com/google/gwt/user/client/rpc/ObjectGraphTestWithTypeObfuscation.java (props changed) branches/snapshot-2009.05.12-r5406/user/test/com/google/gwt/user/client/rpc/RemoteServiceServletTestWithTypeObfuscation.java (props changed) branches/snapshot-2009.05.12-r5406/user/test/com/google/gwt/user/client/rpc/UnicodeEscapingTestWithTypeObfuscation.java (props changed) branches/snapshot-2009.05.12-r5406/user/test/com/google/gwt/user/client/rpc/ValueTypesTestWithTypeObfuscation.java (props changed)
Log: Merge SingleJso fixes into 2009.5.12 snapshot. svn merge -c5466,5467 http://google-web-toolkit.googlecode.com/svn/trunk/ . Modified: branches/snapshot-2009.05.12-r5406/dev/core/src/com/google/gwt/dev/jjs/ast/JTypeOracle.java ============================================================================== --- branches/snapshot-2009.05.12-r5406/dev/core/src/com/google/gwt/dev/jjs/ast/JTypeOracle.java (original) +++ branches/snapshot-2009.05.12-r5406/dev/core/src/com/google/gwt/dev/jjs/ast/JTypeOracle.java Sun May 24 18:37:00 2009 @@ -183,8 +183,8 @@ * * @param type any type * @param instantiatedTypes a set of types assumed to be instantiated. If - * <code>null</code>, then there are no assumptions about which - * types are instantiated. + * <code>null</code>, then there are no assumptions about which types + * are instantiated. * @return whether the type is instantiated */ private static boolean isInstantiatedType(JReferenceType type, @@ -536,6 +536,25 @@ } /** + * Computes the set of all interfaces implemented by a type. + */ + private Set<JInterfaceType> allSuperInterfaces(JDeclaredType type) { + Set<JInterfaceType> toReturn = new IdentityHashSet<JInterfaceType>(); + List<JInterfaceType> q = new LinkedList<JInterfaceType>(); + q.addAll(type.getImplements()); + + while (!q.isEmpty()) { + JInterfaceType t = q.remove(0); + + if (toReturn.add(t)) { + q.addAll(t.getImplements()); + } + } + + return toReturn; + } + + /** * Compute all of the things I might conceivably implement, either through * super types or sub types. */ @@ -653,7 +672,7 @@ for (JDeclaredType type : program.getDeclaredTypes()) { if (!program.isJavaScriptObject(type)) { if (type instanceof JClassType) { - dualImpl.addAll(type.getImplements()); + dualImpl.addAll(allSuperInterfaces(type)); } continue; } @@ -673,7 +692,15 @@ assert intr.getMethods().size() == 0 || intr.getMethods().get(0).getName().equals("$clinit"); jsoSingleImpls.put(intr, program.getJavaScriptObject()); + + /* + * Pretend JSO had always implemented the tag interface. This helps + * simplify cast operations. + */ jsoType.addImplements(intr); + add(couldBeImplementedMap, intr, jsoType); + add(isImplementedMap, intr, jsoType); + add(implementsMap, jsoType, intr); continue; } Modified: branches/snapshot-2009.05.12-r5406/dev/core/src/com/google/gwt/dev/jjs/impl/CastNormalizer.java ============================================================================== --- branches/snapshot-2009.05.12-r5406/dev/core/src/com/google/gwt/dev/jjs/impl/CastNormalizer.java (original) +++ branches/snapshot-2009.05.12-r5406/dev/core/src/com/google/gwt/dev/jjs/impl/CastNormalizer.java Sun May 24 18:37:00 2009 @@ -27,7 +27,6 @@ import com.google.gwt.dev.jjs.ast.JExpression; import com.google.gwt.dev.jjs.ast.JInstanceOf; import com.google.gwt.dev.jjs.ast.JIntLiteral; -import com.google.gwt.dev.jjs.ast.JInterfaceType; import com.google.gwt.dev.jjs.ast.JMethod; import com.google.gwt.dev.jjs.ast.JMethodCall; import com.google.gwt.dev.jjs.ast.JModVisitor; @@ -412,12 +411,6 @@ */ private class ReplaceTypeChecksVisitor extends JModVisitor { - private final Set<JInterfaceType> dualImpls; - - public ReplaceTypeChecksVisitor(JProgram program) { - dualImpls = program.typeOracle.getInterfacesWithJavaAndJsoImpls(); - } - @Override public void endVisit(JCastOperation x, Context ctx) { JExpression replaceExpr; @@ -455,10 +448,10 @@ JMethod method; boolean isJsoCast = program.isJavaScriptObject(toType); if (isJsoCast) { - // A cast to JSO + // A cast to a concrete JSO subtype method = program.getIndexedMethod("Cast.dynamicCastJso"); - } else if (dualImpls.contains(toType)) { - // A cast that may succeed when the object is a JSO + } else if (program.typeOracle.getSingleJsoImpls().containsKey(toType)) { + // An interface that should succeed when the object is a JSO method = program.getIndexedMethod("Cast.dynamicCastAllowJso"); } else { // A regular cast @@ -569,11 +562,12 @@ ctx.replaceMe(eq); } else { JMethod method; - boolean isJsoCast = program.isJavaScriptObject(toType); - if (isJsoCast) { - method = program.getIndexedMethod("Cast.instanceOfJso"); - } else if (dualImpls.contains(toType)) { + boolean isJsoCast = false; + if (program.typeOracle.getSingleJsoImpls().containsKey(toType)) { method = program.getIndexedMethod("Cast.instanceOfOrJso"); + } else if (program.isJavaScriptObject(toType)) { + isJsoCast = true; + method = program.getIndexedMethod("Cast.instanceOfJso"); } else { method = program.getIndexedMethod("Cast.instanceOf"); } @@ -618,7 +612,7 @@ assigner.computeTypeIds(); } { - ReplaceTypeChecksVisitor replacer = new ReplaceTypeChecksVisitor(program); + ReplaceTypeChecksVisitor replacer = new ReplaceTypeChecksVisitor(); replacer.accept(program); } } Modified: branches/snapshot-2009.05.12-r5406/dev/core/src/com/google/gwt/dev/jjs/impl/ControlFlowAnalyzer.java ============================================================================== --- branches/snapshot-2009.05.12-r5406/dev/core/src/com/google/gwt/dev/jjs/impl/ControlFlowAnalyzer.java (original) +++ branches/snapshot-2009.05.12-r5406/dev/core/src/com/google/gwt/dev/jjs/impl/ControlFlowAnalyzer.java Sun May 24 18:37:00 2009 @@ -175,7 +175,23 @@ JType targetType = x.getCastType(); if (program.isJavaScriptObject(targetType)) { rescue((JReferenceType) targetType, true, true); + } else { + /* + * If there's a cast to a SingleJso interface, rescue the implementing + * JSO type. If the JSO type isn't rescued (and there's no other regular + * Java type implementing the interface), then the cast operation will + * be replaced with a throwCCEUnlessNull() call, since there's no type + * left in the type system that implements the interface. If there is an + * implementing Java type, then a dynamicCast() will be emitted which + * will throw a CCE if it hits a JSO type. + */ + JClassType maybeSingleJso = program.typeOracle.getSingleJsoImpls().get( + targetType); + if (maybeSingleJso != null) { + rescue(maybeSingleJso, true, true); + } } + return true; } Modified: branches/snapshot-2009.05.12-r5406/dev/core/src/com/google/gwt/dev/shell/CompilingClassLoader.java ============================================================================== --- branches/snapshot-2009.05.12-r5406/dev/core/src/com/google/gwt/dev/shell/CompilingClassLoader.java (original) +++ branches/snapshot-2009.05.12-r5406/dev/core/src/com/google/gwt/dev/shell/CompilingClassLoader.java Sun May 24 18:37:00 2009 @@ -983,7 +983,7 @@ if (unit != null) { anonymousClassMap = unit.getAnonymousClassMap(); } - byte[] newBytes = classRewriter.rewrite(className, classBytes, + byte[] newBytes = classRewriter.rewrite(this, className, classBytes, anonymousClassMap); if (CLASS_DUMP) { if (!Arrays.equals(classBytes, newBytes)) { Modified: branches/snapshot-2009.05.12-r5406/dev/core/src/com/google/gwt/dev/shell/rewrite/HostedModeClassRewriter.java ============================================================================== --- branches/snapshot-2009.05.12-r5406/dev/core/src/com/google/gwt/dev/shell/rewrite/HostedModeClassRewriter.java (original) +++ branches/snapshot-2009.05.12-r5406/dev/core/src/com/google/gwt/dev/shell/rewrite/HostedModeClassRewriter.java Sun May 24 18:37:00 2009 @@ -183,12 +183,13 @@ /** * Performs rewriting transformations on a class. * + * @param ccl the ClassLoader requesting the rewrite * @param className the name of the class * @param classBytes the bytes of the class * @param anonymousClassMap a map between the anonymous class names of java * compiler used to compile code and jdt. Emma-specific. */ - public byte[] rewrite(String className, byte[] classBytes, + public byte[] rewrite(ClassLoader ccl, String className, byte[] classBytes, Map<String, String> anonymousClassMap) { String desc = toDescriptor(className); assert (!jsoIntfDescs.contains(desc)); @@ -200,7 +201,7 @@ // v = new CheckClassAdapter(v); // v = new TraceClassVisitor(v, new PrintWriter(System.out)); - v = new RewriteSingleJsoImplDispatches(v, singleJsoImplTypes, + v = new RewriteSingleJsoImplDispatches(v, ccl, singleJsoImplTypes, mangledNamesToImplementations); v = new RewriteRefsToJsoClasses(v, jsoIntfDescs, mapper); Modified: branches/snapshot-2009.05.12-r5406/dev/core/src/com/google/gwt/dev/shell/rewrite/RewriteSingleJsoImplDispatches.java ============================================================================== --- branches/snapshot-2009.05.12-r5406/dev/core/src/com/google/gwt/dev/shell/rewrite/RewriteSingleJsoImplDispatches.java (original) +++ branches/snapshot-2009.05.12-r5406/dev/core/src/com/google/gwt/dev/shell/rewrite/RewriteSingleJsoImplDispatches.java Sun May 24 18:37:00 2009 @@ -23,9 +23,9 @@ import com.google.gwt.dev.asm.Type; import com.google.gwt.dev.asm.commons.Method; -import java.util.ArrayList; import java.util.Collections; import java.util.HashSet; +import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.Set; @@ -62,8 +62,57 @@ @Override public void visitMethodInsn(int opcode, String owner, String name, String desc) { - if (singleJsoImplTypes.contains(owner)) { - name = owner.replace('/', '_') + "_" + name; + if (opcode == Opcodes.INVOKEINTERFACE) { + if (singleJsoImplTypes.contains(owner)) { + // Simple case; referring directly to a SingleJso interface. + name = owner.replace('/', '_') + "_" + name; + assert mangledNamesToImplementations.containsKey(name) : "Missing " + + name; + + } else { + /* + * Might be referring to a subtype of a SingleJso interface: + * + * interface IA { void foo() } + * + * interface JA extends JSO implements IA; + * + * interface IB extends IA {} + * + * void bar() { ((IB) object).foo(); } + */ + for (String intf : computeAllInterfaces(owner)) { + if (singleJsoImplTypes.contains(intf)) { + /* + * Check that it really should be mangled and is not a reference + * to a method defined in a non-singleJso super-interface. If + * there are two super-interfaces that define methods with + * identical names and descriptors, the choice of implementation + * is undefined. + */ + String maybeMangled = intf.replace('/', '_') + "_" + name; + Method method = mangledNamesToImplementations.get(maybeMangled); + if (method != null) { + /* + * Found a method with the right name, but we need to check the + * parameters and the return type. In order to do this, we'll + * look at the arguments and return type of the target method, + * removing the first argument, which is the instance. + */ + assert method.getArgumentTypes().length >= 1; + Type[] argumentTypes = new Type[method.getArgumentTypes().length - 1]; + System.arraycopy(method.getArgumentTypes(), 1, argumentTypes, + 0, argumentTypes.length); + String maybeDescriptor = Type.getMethodDescriptor( + method.getReturnType(), argumentTypes); + if (maybeDescriptor.equals(desc)) { + name = maybeMangled; + break; + } + } + } + } + } } super.visitMethodInsn(opcode, owner, name, desc); @@ -76,10 +125,13 @@ private final Set<String> singleJsoImplTypes; private boolean inSingleJsoImplInterfaceType; - public RewriteSingleJsoImplDispatches(ClassVisitor v, + private final ClassLoader ccl; + + public RewriteSingleJsoImplDispatches(ClassVisitor v, ClassLoader ccl, Set<String> singleJsoImplTypes, SortedMap<String, Method> mangledNamesToImplementations) { super(v); + this.ccl = ccl; this.singleJsoImplTypes = Collections.unmodifiableSet(singleJsoImplTypes); this.mangledNamesToImplementations = Collections.unmodifiableSortedMap(mangledNamesToImplementations); } @@ -90,6 +142,15 @@ assert currentTypeName == null; super.visit(version, access, name, signature, superName, interfaces); + /* + * This visitor would mangle JSO$ since it acts as a roll-up of all + * SingleJso types and the result would be repeated method definitions due + * to the trampoline methods this visitor would create. + */ + if (name.equals(HostedModeClassRewriter.JAVASCRIPTOBJECT_IMPL_DESC)) { + return; + } + currentTypeName = name; inSingleJsoImplInterfaceType = singleJsoImplTypes.contains(name); @@ -100,8 +161,7 @@ * original methods. */ if (interfaces != null && (access & Opcodes.ACC_INTERFACE) == 0) { - List<String> toStub = new ArrayList<String>(); - Collections.addAll(toStub, interfaces); + Set<String> toStub = computeAllInterfaces(interfaces); toStub.retainAll(singleJsoImplTypes); for (String stubIntr : toStub) { @@ -144,6 +204,29 @@ } return new MyMethodVisitor(mv); + } + + private Set<String> computeAllInterfaces(String... interfaces) { + Set<String> toReturn = new HashSet<String>(); + List<String> q = new LinkedList<String>(); + Collections.addAll(q, interfaces); + + while (!q.isEmpty()) { + String intf = q.remove(0); + if (toReturn.add(intf)) { + try { + Class<?> intfClass = Class.forName(intf.replace('/', '.'), false, ccl); + for (Class<?> i : intfClass.getInterfaces()) { + q.add(i.getName().replace('.', '/')); + } + } catch (ClassNotFoundException e) { + assert false : intf; + e.printStackTrace(); + } + } + } + + return toReturn; } /** Modified: branches/snapshot-2009.05.12-r5406/user/test/com/google/gwt/dev/jjs/CompilerSuite.java ============================================================================== --- branches/snapshot-2009.05.12-r5406/user/test/com/google/gwt/dev/jjs/CompilerSuite.java (original) +++ branches/snapshot-2009.05.12-r5406/user/test/com/google/gwt/dev/jjs/CompilerSuite.java Sun May 24 18:37:00 2009 @@ -44,6 +44,7 @@ import com.google.gwt.dev.jjs.test.SingleJsoImplTest; import com.google.gwt.dev.jjs.test.UnstableGeneratorTest; import com.google.gwt.dev.jjs.test.VarargsTest; +import com.google.gwt.dev.jjs.test.singlejso.TypeHierarchyTest; import com.google.gwt.junit.tools.GWTTestSuite; import junit.framework.Test; @@ -84,6 +85,7 @@ suite.addTestSuite(RunAsyncFailureTest.class); suite.addTestSuite(RunAsyncTest.class); suite.addTestSuite(SingleJsoImplTest.class); + suite.addTestSuite(TypeHierarchyTest.class); suite.addTestSuite(UnstableGeneratorTest.class); suite.addTestSuite(VarargsTest.class); // $JUnit-END$ Modified: branches/snapshot-2009.05.12-r5406/user/test/com/google/gwt/dev/jjs/test/SingleJsoImplTest.java ============================================================================== --- branches/snapshot-2009.05.12-r5406/user/test/com/google/gwt/dev/jjs/test/SingleJsoImplTest.java (original) +++ branches/snapshot-2009.05.12-r5406/user/test/com/google/gwt/dev/jjs/test/SingleJsoImplTest.java Sun May 24 18:37:00 2009 @@ -66,6 +66,17 @@ String call(int a, int b); } + interface CreatedWithCast { + String foo(); + } + + interface CreatedWithCastToTag { + } + + interface CreatedWithCastToTagSub extends CreatedWithCastToTag { + String foo(); + } + interface Divider extends Multiplier { int divide(int a, int b); } @@ -81,6 +92,22 @@ } /** + * Even though this type is never instantiated, it's necessary to ensure that + * the CreatedWithCast test isn't short-circuited due to type tightening. + */ + static class JavaCreatedWithCast implements CreatedWithCast { + public String foo() { + return "foo"; + } + } + + static class JavaCreatedWithCastToTag implements CreatedWithCastToTagSub { + public String foo() { + return "foo"; + } + } + + /** * The extra declaration of implementing Multiplier should still be legal. */ static class JavaDivider extends JavaMultiplier implements Divider, @@ -189,6 +216,26 @@ } } + static class JsoCreatedWithCast extends JavaScriptObject implements + CreatedWithCast { + protected JsoCreatedWithCast() { + } + + public final String foo() { + return "foo"; + } + } + + static class JsoCreatedWithCastToTag extends JavaScriptObject implements + CreatedWithCastToTagSub { + protected JsoCreatedWithCastToTag() { + } + + public final String foo() { + return "foo"; + } + } + static class JsoDivider extends JsoMultiplier implements Divider, Tag { protected JsoDivider() { } @@ -450,6 +497,25 @@ a.acceptString3Array(a.returnString3Array()); a.acceptObjectArray(a.returnStringArray()); a.acceptObject3Array(a.returnString3Array()); + } + + /** + * Ensure that SingleJSO types that are referred to only via a cast to the + * interface type are retained. If the JsoCreatedWithCast type isn't rescued + * correctly, the cast in this test will throw a ClassCastException since the + * compiler would assume there are types that implement the interface. + */ + public void testCreatedWithCast() { + try { + Object a = (CreatedWithCast) JavaScriptObject.createObject(); + } catch (ClassCastException e) { + fail("a"); + } + try { + Object b = (CreatedWithCastToTag) JavaScriptObject.createObject(); + } catch (ClassCastException e) { + fail("b"); + } } public void testDualCase() { --~--~---------~--~----~------------~-------~--~----~ http://groups.google.com/group/Google-Web-Toolkit-Contributors -~----------~----~----~----~------~----~------~--~---
