Thu, 31 Aug 2017 15:18:52 +0800
merge
aoqi@0 | 1 | /* |
aoqi@0 | 2 | * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved. |
aoqi@0 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
aoqi@0 | 4 | * |
aoqi@0 | 5 | * This code is free software; you can redistribute it and/or modify it |
aoqi@0 | 6 | * under the terms of the GNU General Public License version 2 only, as |
aoqi@0 | 7 | * published by the Free Software Foundation. Oracle designates this |
aoqi@0 | 8 | * particular file as subject to the "Classpath" exception as provided |
aoqi@0 | 9 | * by Oracle in the LICENSE file that accompanied this code. |
aoqi@0 | 10 | * |
aoqi@0 | 11 | * This code is distributed in the hope that it will be useful, but WITHOUT |
aoqi@0 | 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
aoqi@0 | 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
aoqi@0 | 14 | * version 2 for more details (a copy is included in the LICENSE file that |
aoqi@0 | 15 | * accompanied this code). |
aoqi@0 | 16 | * |
aoqi@0 | 17 | * You should have received a copy of the GNU General Public License version |
aoqi@0 | 18 | * 2 along with this work; if not, write to the Free Software Foundation, |
aoqi@0 | 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
aoqi@0 | 20 | * |
aoqi@0 | 21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
aoqi@0 | 22 | * or visit www.oracle.com if you need additional information or have any |
aoqi@0 | 23 | * questions. |
aoqi@0 | 24 | */ |
aoqi@0 | 25 | |
aoqi@0 | 26 | package com.sun.tools.internal.xjc.model; |
aoqi@0 | 27 | |
aoqi@0 | 28 | import java.util.ArrayList; |
aoqi@0 | 29 | import java.util.Collection; |
aoqi@0 | 30 | import java.util.HashSet; |
aoqi@0 | 31 | import java.util.Iterator; |
aoqi@0 | 32 | import java.util.List; |
aoqi@0 | 33 | import java.util.Set; |
aoqi@0 | 34 | |
aoqi@0 | 35 | import javax.xml.bind.annotation.XmlElement; |
aoqi@0 | 36 | import javax.xml.bind.annotation.XmlID; |
aoqi@0 | 37 | import javax.xml.bind.annotation.XmlIDREF; |
aoqi@0 | 38 | import javax.xml.bind.annotation.XmlRootElement; |
aoqi@0 | 39 | import javax.xml.namespace.QName; |
aoqi@0 | 40 | |
aoqi@0 | 41 | import com.sun.codemodel.internal.JClass; |
aoqi@0 | 42 | import com.sun.codemodel.internal.JCodeModel; |
aoqi@0 | 43 | import com.sun.codemodel.internal.JPackage; |
aoqi@0 | 44 | import com.sun.istack.internal.Nullable; |
aoqi@0 | 45 | import com.sun.tools.internal.xjc.Language; |
aoqi@0 | 46 | import com.sun.tools.internal.xjc.model.nav.NClass; |
aoqi@0 | 47 | import com.sun.tools.internal.xjc.model.nav.NType; |
aoqi@0 | 48 | import com.sun.tools.internal.xjc.outline.Aspect; |
aoqi@0 | 49 | import com.sun.tools.internal.xjc.outline.Outline; |
aoqi@0 | 50 | import com.sun.tools.internal.xjc.reader.Ring; |
aoqi@0 | 51 | import com.sun.tools.internal.xjc.reader.xmlschema.BGMBuilder; |
aoqi@0 | 52 | import com.sun.tools.internal.xjc.reader.xmlschema.bindinfo.BIFactoryMethod; |
aoqi@0 | 53 | import com.sun.xml.internal.bind.v2.model.core.ClassInfo; |
aoqi@0 | 54 | import com.sun.xml.internal.bind.v2.model.core.Element; |
aoqi@0 | 55 | import com.sun.xml.internal.xsom.XSComponent; |
aoqi@0 | 56 | |
aoqi@0 | 57 | import org.xml.sax.Locator; |
aoqi@0 | 58 | |
aoqi@0 | 59 | /** |
aoqi@0 | 60 | * Mutable {@link ClassInfo} represenatation. |
aoqi@0 | 61 | * |
aoqi@0 | 62 | * <p> |
aoqi@0 | 63 | * Schema parsers build these objects. |
aoqi@0 | 64 | * |
aoqi@0 | 65 | * @author Kohsuke Kawaguchi |
aoqi@0 | 66 | */ |
aoqi@0 | 67 | public final class CClassInfo extends AbstractCElement implements ClassInfo<NType,NClass>, CClassInfoParent, CClass, NClass { |
aoqi@0 | 68 | |
aoqi@0 | 69 | @XmlIDREF |
aoqi@0 | 70 | private CClass baseClass; |
aoqi@0 | 71 | |
aoqi@0 | 72 | /** |
aoqi@0 | 73 | * List of all subclasses, together with {@link #nextSibling}. |
aoqi@0 | 74 | * |
aoqi@0 | 75 | * If this class has no sub-class, this field is null. Otherwise, |
aoqi@0 | 76 | * this field points to a sub-class of this class. From there you can enumerate |
aoqi@0 | 77 | * all the sub-classes by using {@link #nextSibling}. |
aoqi@0 | 78 | */ |
aoqi@0 | 79 | private CClassInfo firstSubclass; |
aoqi@0 | 80 | |
aoqi@0 | 81 | /** |
aoqi@0 | 82 | * @see #firstSubclass |
aoqi@0 | 83 | */ |
aoqi@0 | 84 | private CClassInfo nextSibling = null; |
aoqi@0 | 85 | |
aoqi@0 | 86 | /** |
aoqi@0 | 87 | * @see #getTypeName() |
aoqi@0 | 88 | */ |
aoqi@0 | 89 | private final QName typeName; |
aoqi@0 | 90 | |
aoqi@0 | 91 | /** |
aoqi@0 | 92 | * Custom {@link #getSqueezedName() squeezed name}, if any. |
aoqi@0 | 93 | */ |
aoqi@0 | 94 | private /*almost final*/ @Nullable String squeezedName; |
aoqi@0 | 95 | |
aoqi@0 | 96 | /** |
aoqi@0 | 97 | * If this class also gets {@link XmlRootElement}, the class name. |
aoqi@0 | 98 | */ |
aoqi@0 | 99 | private final @Nullable QName elementName; |
aoqi@0 | 100 | |
aoqi@0 | 101 | private boolean isOrdered = true; |
aoqi@0 | 102 | |
aoqi@0 | 103 | private final List<CPropertyInfo> properties = new ArrayList<CPropertyInfo>(); |
aoqi@0 | 104 | |
aoqi@0 | 105 | /** |
aoqi@0 | 106 | * TODO: revisit this design. |
aoqi@0 | 107 | * we should at least do a basic encapsulation to avoid careless |
aoqi@0 | 108 | * mistakes. Maybe we should even differ the javadoc generation |
aoqi@0 | 109 | * by queueing runners. |
aoqi@0 | 110 | */ |
aoqi@0 | 111 | public String javadoc; |
aoqi@0 | 112 | |
aoqi@0 | 113 | @XmlIDREF |
aoqi@0 | 114 | private final CClassInfoParent parent; |
aoqi@0 | 115 | |
aoqi@0 | 116 | /** |
aoqi@0 | 117 | * short name. |
aoqi@0 | 118 | */ |
aoqi@0 | 119 | public final String shortName; |
aoqi@0 | 120 | |
aoqi@0 | 121 | /** |
aoqi@0 | 122 | * Optional user-specified implementation override class. |
aoqi@0 | 123 | */ |
aoqi@0 | 124 | private @Nullable String implClass; |
aoqi@0 | 125 | |
aoqi@0 | 126 | /** |
aoqi@0 | 127 | * The {@link Model} object to which this bean belongs. |
aoqi@0 | 128 | */ |
aoqi@0 | 129 | public final Model model; |
aoqi@0 | 130 | |
aoqi@0 | 131 | /** |
aoqi@0 | 132 | * @see #hasAttributeWildcard() |
aoqi@0 | 133 | */ |
aoqi@0 | 134 | private boolean hasAttributeWildcard; |
aoqi@0 | 135 | |
aoqi@0 | 136 | |
aoqi@0 | 137 | public CClassInfo(Model model,JPackage pkg, String shortName, Locator location, QName typeName, QName elementName, XSComponent source, CCustomizations customizations) { |
aoqi@0 | 138 | this(model,model.getPackage(pkg),shortName,location,typeName,elementName,source,customizations); |
aoqi@0 | 139 | } |
aoqi@0 | 140 | |
aoqi@0 | 141 | public CClassInfo(Model model,CClassInfoParent p, String shortName, Locator location, QName typeName, QName elementName, XSComponent source, CCustomizations customizations) { |
aoqi@0 | 142 | super(model,source,location,customizations); |
aoqi@0 | 143 | this.model = model; |
aoqi@0 | 144 | this.parent = p; |
aoqi@0 | 145 | this.shortName = model.allocator.assignClassName(parent,shortName); |
aoqi@0 | 146 | this.typeName = typeName; |
aoqi@0 | 147 | this.elementName = elementName; |
aoqi@0 | 148 | |
aoqi@0 | 149 | Language schemaLanguage = model.options.getSchemaLanguage(); |
aoqi@0 | 150 | if ((schemaLanguage != null) && |
aoqi@0 | 151 | (schemaLanguage.equals(Language.XMLSCHEMA) || schemaLanguage.equals(Language.WSDL))) { |
aoqi@0 | 152 | BIFactoryMethod factoryMethod = Ring.get(BGMBuilder.class).getBindInfo(source).get(BIFactoryMethod.class); |
aoqi@0 | 153 | if(factoryMethod!=null) { |
aoqi@0 | 154 | factoryMethod.markAsAcknowledged(); |
aoqi@0 | 155 | this.squeezedName = factoryMethod.name; |
aoqi@0 | 156 | } |
aoqi@0 | 157 | } |
aoqi@0 | 158 | |
aoqi@0 | 159 | model.add(this); |
aoqi@0 | 160 | } |
aoqi@0 | 161 | |
aoqi@0 | 162 | public CClassInfo(Model model,JCodeModel cm, String fullName, Locator location, QName typeName, QName elementName, XSComponent source, CCustomizations customizations) { |
aoqi@0 | 163 | super(model,source,location,customizations); |
aoqi@0 | 164 | this.model = model; |
aoqi@0 | 165 | int idx = fullName.indexOf('.'); |
aoqi@0 | 166 | if(idx<0) { |
aoqi@0 | 167 | this.parent = model.getPackage(cm.rootPackage()); |
aoqi@0 | 168 | this.shortName = model.allocator.assignClassName(parent,fullName); |
aoqi@0 | 169 | } else { |
aoqi@0 | 170 | this.parent = model.getPackage(cm._package(fullName.substring(0,idx))); |
aoqi@0 | 171 | this.shortName = model.allocator.assignClassName(parent,fullName.substring(idx+1)); |
aoqi@0 | 172 | } |
aoqi@0 | 173 | this.typeName = typeName; |
aoqi@0 | 174 | this.elementName = elementName; |
aoqi@0 | 175 | |
aoqi@0 | 176 | model.add(this); |
aoqi@0 | 177 | } |
aoqi@0 | 178 | |
aoqi@0 | 179 | public boolean hasAttributeWildcard() { |
aoqi@0 | 180 | return hasAttributeWildcard; |
aoqi@0 | 181 | } |
aoqi@0 | 182 | |
aoqi@0 | 183 | public void hasAttributeWildcard(boolean hasAttributeWildcard) { |
aoqi@0 | 184 | this.hasAttributeWildcard = hasAttributeWildcard; |
aoqi@0 | 185 | } |
aoqi@0 | 186 | |
aoqi@0 | 187 | public boolean hasSubClasses() { |
aoqi@0 | 188 | return firstSubclass!=null; |
aoqi@0 | 189 | } |
aoqi@0 | 190 | |
aoqi@0 | 191 | /** |
aoqi@0 | 192 | * Returns true if a new attribute wildcard property needs to be |
aoqi@0 | 193 | * declared on this class. |
aoqi@0 | 194 | */ |
aoqi@0 | 195 | public boolean declaresAttributeWildcard() { |
aoqi@0 | 196 | return hasAttributeWildcard && !inheritsAttributeWildcard(); |
aoqi@0 | 197 | } |
aoqi@0 | 198 | |
aoqi@0 | 199 | /** |
aoqi@0 | 200 | * Returns true if this class inherits a wildcard attribute property |
aoqi@0 | 201 | * from its ancestor classes. |
aoqi@0 | 202 | */ |
aoqi@0 | 203 | public boolean inheritsAttributeWildcard() { |
aoqi@0 | 204 | if (getRefBaseClass() != null) { |
aoqi@0 | 205 | CClassRef cref = (CClassRef)baseClass; |
aoqi@0 | 206 | if (cref.getSchemaComponent().getForeignAttributes().size() > 0) { |
aoqi@0 | 207 | return true; |
aoqi@0 | 208 | } |
aoqi@0 | 209 | } else { |
aoqi@0 | 210 | for( CClassInfo c=getBaseClass(); c!=null; c=c.getBaseClass() ) { |
aoqi@0 | 211 | if(c.hasAttributeWildcard) |
aoqi@0 | 212 | return true; |
aoqi@0 | 213 | } |
aoqi@0 | 214 | } |
aoqi@0 | 215 | return false; |
aoqi@0 | 216 | } |
aoqi@0 | 217 | |
aoqi@0 | 218 | |
aoqi@0 | 219 | public NClass getClazz() { |
aoqi@0 | 220 | return this; |
aoqi@0 | 221 | } |
aoqi@0 | 222 | |
aoqi@0 | 223 | public CClassInfo getScope() { |
aoqi@0 | 224 | return null; |
aoqi@0 | 225 | } |
aoqi@0 | 226 | |
aoqi@0 | 227 | @XmlID |
aoqi@0 | 228 | public String getName() { |
aoqi@0 | 229 | return fullName(); |
aoqi@0 | 230 | } |
aoqi@0 | 231 | |
aoqi@0 | 232 | /** |
aoqi@0 | 233 | * Returns the "squeezed name" of this bean token. |
aoqi@0 | 234 | * <p> |
aoqi@0 | 235 | * The squeezed name of a bean is the concatenation of |
aoqi@0 | 236 | * the names of its outer classes and itself. |
aoqi@0 | 237 | * <p> |
aoqi@0 | 238 | * Thus if the bean is "org.acme.foo.Bean", then the squeezed name is "Bean", |
aoqi@0 | 239 | * if the bean is "org.acme.foo.Outer1.Outer2.Bean", then "Outer1Outer2Bean". |
aoqi@0 | 240 | * <p> |
aoqi@0 | 241 | * This is used by the code generator |
aoqi@0 | 242 | */ |
aoqi@0 | 243 | @XmlElement |
aoqi@0 | 244 | public String getSqueezedName() { |
aoqi@0 | 245 | if (squeezedName != null) return squeezedName; |
aoqi@0 | 246 | return calcSqueezedName.onBean(this); |
aoqi@0 | 247 | } |
aoqi@0 | 248 | |
aoqi@0 | 249 | private static final CClassInfoParent.Visitor<String> calcSqueezedName = new Visitor<String>() { |
aoqi@0 | 250 | public String onBean(CClassInfo bean) { |
aoqi@0 | 251 | return bean.parent.accept(this)+bean.shortName; |
aoqi@0 | 252 | } |
aoqi@0 | 253 | |
aoqi@0 | 254 | public String onElement(CElementInfo element) { |
aoqi@0 | 255 | return element.parent.accept(this)+element.shortName(); |
aoqi@0 | 256 | } |
aoqi@0 | 257 | |
aoqi@0 | 258 | public String onPackage(JPackage pkg) { |
aoqi@0 | 259 | return ""; |
aoqi@0 | 260 | } |
aoqi@0 | 261 | }; |
aoqi@0 | 262 | |
aoqi@0 | 263 | /** |
aoqi@0 | 264 | * Returns a mutable list. |
aoqi@0 | 265 | */ |
aoqi@0 | 266 | public List<CPropertyInfo> getProperties() { |
aoqi@0 | 267 | return properties; |
aoqi@0 | 268 | } |
aoqi@0 | 269 | |
aoqi@0 | 270 | public boolean hasValueProperty() { |
aoqi@0 | 271 | throw new UnsupportedOperationException(); |
aoqi@0 | 272 | } |
aoqi@0 | 273 | |
aoqi@0 | 274 | /** |
aoqi@0 | 275 | * Gets a propery by name. |
aoqi@0 | 276 | */ |
aoqi@0 | 277 | public CPropertyInfo getProperty(String name) { |
aoqi@0 | 278 | // TODO: does this method need to be fast? |
aoqi@0 | 279 | for( CPropertyInfo p : properties ) |
aoqi@0 | 280 | if(p.getName(false).equals(name)) |
aoqi@0 | 281 | return p; |
aoqi@0 | 282 | return null; |
aoqi@0 | 283 | } |
aoqi@0 | 284 | |
aoqi@0 | 285 | public boolean hasProperties() { |
aoqi@0 | 286 | return !getProperties().isEmpty(); |
aoqi@0 | 287 | } |
aoqi@0 | 288 | |
aoqi@0 | 289 | public boolean isElement() { |
aoqi@0 | 290 | return elementName!=null; |
aoqi@0 | 291 | } |
aoqi@0 | 292 | |
aoqi@0 | 293 | /** |
aoqi@0 | 294 | * Guaranteed to return this. |
aoqi@0 | 295 | */ |
aoqi@0 | 296 | @Deprecated |
aoqi@0 | 297 | public CNonElement getInfo() { |
aoqi@0 | 298 | return this; |
aoqi@0 | 299 | } |
aoqi@0 | 300 | |
aoqi@0 | 301 | public Element<NType,NClass> asElement() { |
aoqi@0 | 302 | if(isElement()) |
aoqi@0 | 303 | return this; |
aoqi@0 | 304 | else |
aoqi@0 | 305 | return null; |
aoqi@0 | 306 | } |
aoqi@0 | 307 | |
aoqi@0 | 308 | public boolean isOrdered() { |
aoqi@0 | 309 | return isOrdered; |
aoqi@0 | 310 | } |
aoqi@0 | 311 | |
aoqi@0 | 312 | /** |
aoqi@0 | 313 | * @deprecated |
aoqi@0 | 314 | * if you are calling this method directly, you must be doing something wrong. |
aoqi@0 | 315 | */ |
aoqi@0 | 316 | public boolean isFinal() { |
aoqi@0 | 317 | return false; |
aoqi@0 | 318 | } |
aoqi@0 | 319 | |
aoqi@0 | 320 | public void setOrdered(boolean value) { |
aoqi@0 | 321 | isOrdered = value; |
aoqi@0 | 322 | } |
aoqi@0 | 323 | |
aoqi@0 | 324 | public QName getElementName() { |
aoqi@0 | 325 | return elementName; |
aoqi@0 | 326 | } |
aoqi@0 | 327 | |
aoqi@0 | 328 | public QName getTypeName() { |
aoqi@0 | 329 | return typeName; |
aoqi@0 | 330 | } |
aoqi@0 | 331 | |
aoqi@0 | 332 | public boolean isSimpleType() { |
aoqi@0 | 333 | throw new UnsupportedOperationException(); |
aoqi@0 | 334 | } |
aoqi@0 | 335 | |
aoqi@0 | 336 | /** |
aoqi@0 | 337 | * Returns the FQCN of this bean. |
aoqi@0 | 338 | */ |
aoqi@0 | 339 | public String fullName() { |
aoqi@0 | 340 | String r = parent.fullName(); |
aoqi@0 | 341 | if(r.length()==0) return shortName; |
aoqi@0 | 342 | else return r+'.'+shortName; |
aoqi@0 | 343 | } |
aoqi@0 | 344 | |
aoqi@0 | 345 | public CClassInfoParent parent() { |
aoqi@0 | 346 | return parent; |
aoqi@0 | 347 | } |
aoqi@0 | 348 | |
aoqi@0 | 349 | public void setUserSpecifiedImplClass(String implClass) { |
aoqi@0 | 350 | assert this.implClass==null; |
aoqi@0 | 351 | assert implClass!=null; |
aoqi@0 | 352 | this.implClass = implClass; |
aoqi@0 | 353 | } |
aoqi@0 | 354 | |
aoqi@0 | 355 | public String getUserSpecifiedImplClass() { |
aoqi@0 | 356 | return implClass; |
aoqi@0 | 357 | } |
aoqi@0 | 358 | |
aoqi@0 | 359 | |
aoqi@0 | 360 | /** |
aoqi@0 | 361 | * Adds a new property. |
aoqi@0 | 362 | */ |
aoqi@0 | 363 | public void addProperty(CPropertyInfo prop) { |
aoqi@0 | 364 | if(prop.ref().isEmpty()) |
aoqi@0 | 365 | // this property isn't contributing anything |
aoqi@0 | 366 | // this happens when you try to map an empty sequence to a property |
aoqi@0 | 367 | return; |
aoqi@0 | 368 | prop.setParent(this); |
aoqi@0 | 369 | properties.add(prop); |
aoqi@0 | 370 | } |
aoqi@0 | 371 | |
aoqi@0 | 372 | /** |
aoqi@0 | 373 | * This method accepts both {@link CClassInfo} (which means the base class |
aoqi@0 | 374 | * is also generated), or {@link CClassRef} (which means the base class is |
aoqi@0 | 375 | * already generated and simply referenced.) |
aoqi@0 | 376 | * |
aoqi@0 | 377 | * The latter is treated somewhat special --- from the rest of the model |
aoqi@0 | 378 | * this external base class is invisible. This modeling might need more |
aoqi@0 | 379 | * thoughts to get right. |
aoqi@0 | 380 | */ |
aoqi@0 | 381 | public void setBaseClass(CClass base) { |
aoqi@0 | 382 | assert baseClass==null; |
aoqi@0 | 383 | assert base!=null; |
aoqi@0 | 384 | baseClass = base; |
aoqi@0 | 385 | |
aoqi@0 | 386 | assert nextSibling==null; |
aoqi@0 | 387 | if (base instanceof CClassInfo) { |
aoqi@0 | 388 | CClassInfo realBase = (CClassInfo) base; |
aoqi@0 | 389 | this.nextSibling = realBase.firstSubclass; |
aoqi@0 | 390 | realBase.firstSubclass = this; |
aoqi@0 | 391 | } |
aoqi@0 | 392 | } |
aoqi@0 | 393 | |
aoqi@0 | 394 | /** |
aoqi@0 | 395 | * This inherited version returns null if this class extends from {@link CClassRef}. |
aoqi@0 | 396 | * |
aoqi@0 | 397 | * @see #getRefBaseClass() |
aoqi@0 | 398 | */ |
aoqi@0 | 399 | public CClassInfo getBaseClass() { |
aoqi@0 | 400 | if (baseClass instanceof CClassInfo) { |
aoqi@0 | 401 | return (CClassInfo) baseClass; |
aoqi@0 | 402 | } else { |
aoqi@0 | 403 | return null; |
aoqi@0 | 404 | } |
aoqi@0 | 405 | } |
aoqi@0 | 406 | |
aoqi@0 | 407 | public CClassRef getRefBaseClass() { |
aoqi@0 | 408 | if (baseClass instanceof CClassRef) { |
aoqi@0 | 409 | return (CClassRef) baseClass; |
aoqi@0 | 410 | } else { |
aoqi@0 | 411 | return null; |
aoqi@0 | 412 | } |
aoqi@0 | 413 | } |
aoqi@0 | 414 | |
aoqi@0 | 415 | /** |
aoqi@0 | 416 | * Enumerates all the sub-classes of this class. |
aoqi@0 | 417 | */ |
aoqi@0 | 418 | public Iterator<CClassInfo> listSubclasses() { |
aoqi@0 | 419 | return new Iterator<CClassInfo>() { |
aoqi@0 | 420 | CClassInfo cur = firstSubclass; |
aoqi@0 | 421 | public boolean hasNext() { |
aoqi@0 | 422 | return cur!=null; |
aoqi@0 | 423 | } |
aoqi@0 | 424 | |
aoqi@0 | 425 | public CClassInfo next() { |
aoqi@0 | 426 | CClassInfo r = cur; |
aoqi@0 | 427 | cur = cur.nextSibling; |
aoqi@0 | 428 | return r; |
aoqi@0 | 429 | } |
aoqi@0 | 430 | |
aoqi@0 | 431 | public void remove() { |
aoqi@0 | 432 | throw new UnsupportedOperationException(); |
aoqi@0 | 433 | } |
aoqi@0 | 434 | }; |
aoqi@0 | 435 | } |
aoqi@0 | 436 | |
aoqi@0 | 437 | public CClassInfo getSubstitutionHead() { |
aoqi@0 | 438 | CClassInfo c=getBaseClass(); |
aoqi@0 | 439 | while(c!=null && !c.isElement()) |
aoqi@0 | 440 | c=c.getBaseClass(); |
aoqi@0 | 441 | return c; |
aoqi@0 | 442 | } |
aoqi@0 | 443 | |
aoqi@0 | 444 | |
aoqi@0 | 445 | /** |
aoqi@0 | 446 | * Interfaces to be implemented. |
aoqi@0 | 447 | * Lazily constructed. |
aoqi@0 | 448 | */ |
aoqi@0 | 449 | private Set<JClass> _implements = null; |
aoqi@0 | 450 | |
aoqi@0 | 451 | public void _implements(JClass c) { |
aoqi@0 | 452 | if(_implements==null) |
aoqi@0 | 453 | _implements = new HashSet<JClass>(); |
aoqi@0 | 454 | _implements.add(c); |
aoqi@0 | 455 | } |
aoqi@0 | 456 | |
aoqi@0 | 457 | |
aoqi@0 | 458 | /** Constructor declarations. array of {@link Constructor}s. */ |
aoqi@0 | 459 | private final List<Constructor> constructors = new ArrayList<Constructor>(1); |
aoqi@0 | 460 | |
aoqi@0 | 461 | /** Creates a new constructor declaration and adds it. */ |
aoqi@0 | 462 | public void addConstructor( String... fieldNames ) { |
aoqi@0 | 463 | constructors.add(new Constructor(fieldNames)); |
aoqi@0 | 464 | } |
aoqi@0 | 465 | |
aoqi@0 | 466 | /** list all constructor declarations. */ |
aoqi@0 | 467 | public Collection<? extends Constructor> getConstructors() { |
aoqi@0 | 468 | return constructors; |
aoqi@0 | 469 | } |
aoqi@0 | 470 | |
aoqi@0 | 471 | public final <T> T accept(Visitor<T> visitor) { |
aoqi@0 | 472 | return visitor.onBean(this); |
aoqi@0 | 473 | } |
aoqi@0 | 474 | |
aoqi@0 | 475 | public JPackage getOwnerPackage() { |
aoqi@0 | 476 | return parent.getOwnerPackage(); |
aoqi@0 | 477 | } |
aoqi@0 | 478 | |
aoqi@0 | 479 | public final NClass getType() { |
aoqi@0 | 480 | return this; |
aoqi@0 | 481 | } |
aoqi@0 | 482 | |
aoqi@0 | 483 | public final JClass toType(Outline o, Aspect aspect) { |
aoqi@0 | 484 | switch(aspect) { |
aoqi@0 | 485 | case IMPLEMENTATION: |
aoqi@0 | 486 | return o.getClazz(this).implRef; |
aoqi@0 | 487 | case EXPOSED: |
aoqi@0 | 488 | return o.getClazz(this).ref; |
aoqi@0 | 489 | default: |
aoqi@0 | 490 | throw new IllegalStateException(); |
aoqi@0 | 491 | } |
aoqi@0 | 492 | } |
aoqi@0 | 493 | |
aoqi@0 | 494 | public boolean isBoxedType() { |
aoqi@0 | 495 | return false; |
aoqi@0 | 496 | } |
aoqi@0 | 497 | |
aoqi@0 | 498 | public String toString() { |
aoqi@0 | 499 | return fullName(); |
aoqi@0 | 500 | } |
aoqi@0 | 501 | } |