diff -r 41a66a42791b -r 31822b475baa src/share/classes/com/sun/codemodel/internal/JDefinedClass.java --- a/src/share/classes/com/sun/codemodel/internal/JDefinedClass.java Mon Mar 09 13:34:04 2009 -0700 +++ b/src/share/classes/com/sun/codemodel/internal/JDefinedClass.java Mon Apr 20 15:14:39 2009 -0700 @@ -1,5 +1,5 @@ /* - * Copyright 2006 Sun Microsystems, Inc. All Rights Reserved. + * Copyright 2005-2006 Sun Microsystems, Inc. All Rights Reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -251,6 +251,13 @@ if (superClass == null) throw new NullPointerException(); + for( JClass o=superClass.outer(); o!=null; o=o.outer() ){ + if(this==o){ + throw new IllegalArgumentException("Illegal class inheritance loop." + + " Outer class " + this.name + " may not subclass from inner class: " + o.name()); + } + } + this.superClass = superClass; return this; } @@ -307,8 +314,9 @@ } /** - * This method generates reference to the JEnumConstant in - * the class + * If the named enum already exists, the reference to it is returned. + * Otherwise this method generates a new enum reference with the given + * name and returns it. * * @param name * The name of the constant. @@ -316,8 +324,11 @@ * The generated type-safe enum constant. */ public JEnumConstant enumConstant(String name){ - JEnumConstant ec = new JEnumConstant(this, name); - enumConstantsByName.put(name, ec); + JEnumConstant ec = enumConstantsByName.get(name); + if (null == ec) { + ec = new JEnumConstant(this, name); + enumConstantsByName.put(name, ec); + } return ec; } @@ -417,7 +428,6 @@ * newly created Annotation Type Declaration * @exception JClassAlreadyExistsException * When the specified class/interface was already created. - */ public JDefinedClass _annotationTypeDeclaration(String name) throws JClassAlreadyExistsException { return _class (JMod.PUBLIC,name,ClassType.ANNOTATION_TYPE_DECL); @@ -576,7 +586,6 @@ * null if not found. */ public JMethod getMethod(String name, JType[] argTypes) { - outer : for (JMethod m : methods) { if (!m.name().equals(name)) continue; @@ -740,8 +749,8 @@ f.nl().g(jdoc); if (annotations != null){ - for( int i=0; i