src/share/classes/com/sun/codemodel/internal/JDefinedClass.java

changeset 45
31822b475baa
parent 1
0961a4a21176
child 50
42dfec6871f6
equal deleted inserted replaced
33:41a66a42791b 45:31822b475baa
1 /* 1 /*
2 * Copyright 2006 Sun Microsystems, Inc. All Rights Reserved. 2 * Copyright 2005-2006 Sun Microsystems, Inc. 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. Sun designates this 7 * published by the Free Software Foundation. Sun designates this
249 if (this.classType==ClassType.INTERFACE) 249 if (this.classType==ClassType.INTERFACE)
250 throw new IllegalArgumentException("unable to set the super class for an interface"); 250 throw new IllegalArgumentException("unable to set the super class for an interface");
251 if (superClass == null) 251 if (superClass == null)
252 throw new NullPointerException(); 252 throw new NullPointerException();
253 253
254 for( JClass o=superClass.outer(); o!=null; o=o.outer() ){
255 if(this==o){
256 throw new IllegalArgumentException("Illegal class inheritance loop." +
257 " Outer class " + this.name + " may not subclass from inner class: " + o.name());
258 }
259 }
260
254 this.superClass = superClass; 261 this.superClass = superClass;
255 return this; 262 return this;
256 } 263 }
257 264
258 public JDefinedClass _extends(Class superClass) { 265 public JDefinedClass _extends(Class superClass) {
305 public String name() { 312 public String name() {
306 return name; 313 return name;
307 } 314 }
308 315
309 /** 316 /**
310 * This method generates reference to the JEnumConstant in 317 * If the named enum already exists, the reference to it is returned.
311 * the class 318 * Otherwise this method generates a new enum reference with the given
319 * name and returns it.
312 * 320 *
313 * @param name 321 * @param name
314 * The name of the constant. 322 * The name of the constant.
315 * @return 323 * @return
316 * The generated type-safe enum constant. 324 * The generated type-safe enum constant.
317 */ 325 */
318 public JEnumConstant enumConstant(String name){ 326 public JEnumConstant enumConstant(String name){
319 JEnumConstant ec = new JEnumConstant(this, name); 327 JEnumConstant ec = enumConstantsByName.get(name);
320 enumConstantsByName.put(name, ec); 328 if (null == ec) {
329 ec = new JEnumConstant(this, name);
330 enumConstantsByName.put(name, ec);
331 }
321 return ec; 332 return ec;
322 } 333 }
323 334
324 /** 335 /**
325 * Gets the fully qualified name of this class. 336 * Gets the fully qualified name of this class.
415 * Name of the annotation Type declaration to be added to this package 426 * Name of the annotation Type declaration to be added to this package
416 * @return 427 * @return
417 * newly created Annotation Type Declaration 428 * newly created Annotation Type Declaration
418 * @exception JClassAlreadyExistsException 429 * @exception JClassAlreadyExistsException
419 * When the specified class/interface was already created. 430 * When the specified class/interface was already created.
420
421 */ 431 */
422 public JDefinedClass _annotationTypeDeclaration(String name) throws JClassAlreadyExistsException { 432 public JDefinedClass _annotationTypeDeclaration(String name) throws JClassAlreadyExistsException {
423 return _class (JMod.PUBLIC,name,ClassType.ANNOTATION_TYPE_DECL); 433 return _class (JMod.PUBLIC,name,ClassType.ANNOTATION_TYPE_DECL);
424 } 434 }
425 435
574 * 584 *
575 * @return 585 * @return
576 * null if not found. 586 * null if not found.
577 */ 587 */
578 public JMethod getMethod(String name, JType[] argTypes) { 588 public JMethod getMethod(String name, JType[] argTypes) {
579 outer :
580 for (JMethod m : methods) { 589 for (JMethod m : methods) {
581 if (!m.name().equals(name)) 590 if (!m.name().equals(name))
582 continue; 591 continue;
583 592
584 if (m.hasSignature(argTypes)) 593 if (m.hasSignature(argTypes))
738 public void declare(JFormatter f) { 747 public void declare(JFormatter f) {
739 if (jdoc != null) 748 if (jdoc != null)
740 f.nl().g(jdoc); 749 f.nl().g(jdoc);
741 750
742 if (annotations != null){ 751 if (annotations != null){
743 for( int i=0; i<annotations.size(); i++ ) 752 for (JAnnotationUse annotation : annotations)
744 f.g(annotations.get(i)).nl(); 753 f.g(annotation).nl();
745 } 754 }
746 755
747 f.g(mods).p(classType.declarationToken).id(name).d(generifiable); 756 f.g(mods).p(classType.declarationToken).id(name).d(generifiable);
748 757
749 if (superClass != null && superClass != owner().ref(Object.class)) 758 if (superClass != null && superClass != owner().ref(Object.class))

mercurial