# HG changeset patch # User devjani.ray@oracle.com # Date 1304708138 14400 # Node ID 34ec90cc612cf94a2ac67904c7e78471f79d8a0d # Parent 3c730b38d1b015bc4b195686c3696e957d8865d7 adrgen5 - documentation generator diff -r 3c730b38d1b0 -r 34ec90cc612c usr/src/java/adr/org/opensolaris/os/adr/ADRError.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/usr/src/java/adr/org/opensolaris/os/adr/ADRError.java Fri May 06 14:55:38 2011 -0400 @@ -0,0 +1,52 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License (the "License"). + * You may not use this file except in compliance with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ + +/* + * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. + */ + +package org.opensolaris.os.adr; + +/** + * An error returned by an adr method or property getter/setter. + * The error {@code Type} must be a subclass of {@code Type.ComplexType}, + * with two exceptions. + * If it is {@code null}, the operation can't fail. + * If it is {@code StdType.VOID}, the operation may fail but errors + * don't include structured data. + */ +public class ADRError extends SimpleHasType { + + private Doc doc_; + + public ADRError(Type type, Doc doc) { + super(type, false); + doc_ = doc; + } + + public ADRError(Type type) { + this(type, null); + } + + public Doc getDoc() { + return doc_; + } +} diff -r 3c730b38d1b0 -r 34ec90cc612c usr/src/java/adr/org/opensolaris/os/adr/API.java --- a/usr/src/java/adr/org/opensolaris/os/adr/API.java Thu May 05 13:16:34 2011 -0700 +++ b/usr/src/java/adr/org/opensolaris/os/adr/API.java Fri May 06 14:55:38 2011 -0400 @@ -36,16 +36,18 @@ private Map props_, allProps_; private Map methods_, allMethods_; private Map events_, allEvents_; + private Doc doc_; private List parents_; private Interface interface_; public API(String name, Map vers, Map props, Map methods, - Map events, List parents) { + Map events, List parents, Doc doc) { name_ = name; vers_ = vers; parents_ = parents; + doc_ = doc; props_ = props; allProps_ = new HashMap(props_); @@ -71,6 +73,12 @@ } } + public API(String name, Map vers, + Map props, Map methods, + Map events, List parents) { + this(name, vers, props, methods, events, parents, null); + } + public String getName() { return name_; } @@ -123,6 +131,10 @@ return allEvents_.get(name); } + public Doc getDoc() { + return doc_; + } + /* * Definition defintions */ diff -r 3c730b38d1b0 -r 34ec90cc612c usr/src/java/adr/org/opensolaris/os/adr/Argument.java --- a/usr/src/java/adr/org/opensolaris/os/adr/Argument.java Thu May 05 13:16:34 2011 -0700 +++ b/usr/src/java/adr/org/opensolaris/os/adr/Argument.java Fri May 06 14:55:38 2011 -0400 @@ -20,14 +20,17 @@ */ /* - * Copyright 2009 Sun Microsystems, Inc. All rights reserved. - * Use is subject to license terms. + * Copyright (c) 2009, 2011, Oracle and/or its affiliates. All rights reserved. */ package org.opensolaris.os.adr; public class Argument extends Feature { + public Argument(String name, Type t, boolean optional, Doc doc) { + super(name, t, optional, doc); + } + public Argument(String name, Type t, boolean optional) { - super(name, t, optional); + this(name, t, optional, null); } } diff -r 3c730b38d1b0 -r 34ec90cc612c usr/src/java/adr/org/opensolaris/os/adr/Doc.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/usr/src/java/adr/org/opensolaris/os/adr/Doc.java Fri May 06 14:55:38 2011 -0400 @@ -0,0 +1,55 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License (the "License"). + * You may not use this file except in compliance with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ + +/* + * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. + */ + +package org.opensolaris.os.adr; + +import org.w3c.dom.DOMException; +import org.w3c.dom.Element; +import org.w3c.dom.Node; + +public class Doc { + + private Element summary_; + private Element detail_; + private String lang_; + + public Doc(Element summary, Element detail, String lang) { + detail_ = detail; + summary_ = summary; + lang_ = lang; + } + + public Doc(Element summary, Element detail) { + this(summary, detail, "en"); + } + + public Element getSummary() { + return summary_; + } + + public Element getDetail() { + return detail_; + } +} diff -r 3c730b38d1b0 -r 34ec90cc612c usr/src/java/adr/org/opensolaris/os/adr/Event.java --- a/usr/src/java/adr/org/opensolaris/os/adr/Event.java Thu May 05 13:16:34 2011 -0700 +++ b/usr/src/java/adr/org/opensolaris/os/adr/Event.java Fri May 06 14:55:38 2011 -0400 @@ -20,13 +20,17 @@ */ /* - * Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2009, 2011, Oracle and/or its affiliates. All rights reserved. */ package org.opensolaris.os.adr; public class Event extends Feature { + public Event(String name, Stability stability, Type t, Doc doc) { + super(name, stability, t, false, doc); + } + public Event(String name, Stability stability, Type t) { - super(name, stability, t, false); + this(name, stability, t, null); } } diff -r 3c730b38d1b0 -r 34ec90cc612c usr/src/java/adr/org/opensolaris/os/adr/Feature.java --- a/usr/src/java/adr/org/opensolaris/os/adr/Feature.java Thu May 05 13:16:34 2011 -0700 +++ b/usr/src/java/adr/org/opensolaris/os/adr/Feature.java Fri May 06 14:55:38 2011 -0400 @@ -25,25 +25,31 @@ package org.opensolaris.os.adr; -public abstract class Feature implements HasType { +public abstract class Feature extends SimpleHasType { private API api_ = null; protected String name_; protected Stability stability_; - protected Type type_; - protected boolean optional_; + protected Doc doc_; + + public Feature(String name, Stability s, Type t, boolean optional, + Doc doc) { + super(t, optional); + name_ = name; + stability_ = s; + doc_ = doc; + } + + public Feature(String name, Type t, boolean optional, Doc doc) { + this(name, Stability.UNDEFINED, t, optional, doc); + } public Feature(String name, Stability s, Type t, boolean optional) { - name_ = name; - stability_ = s; - type_ = t; - optional_ = optional; - if (t != null && t.getSource() == Type.Source.FORWARD) - ((Type.ForwardType)t).addReference(this); + this(name, s, t, optional, null); } public Feature(String name, Type t, boolean optional) { - this(name, Stability.UNDEFINED, t, optional); + this(name, Stability.UNDEFINED, t, optional, null); } public API getAPI() { @@ -64,17 +70,7 @@ return stability_; } - @Override - public Type getType() { - return type_; - } - - @Override - public void setType(Type type) { - type_ = type; - } - - public boolean isOptional() { - return optional_; + public Doc getDoc() { + return doc_; } } diff -r 3c730b38d1b0 -r 34ec90cc612c usr/src/java/adr/org/opensolaris/os/adr/Field.java --- a/usr/src/java/adr/org/opensolaris/os/adr/Field.java Thu May 05 13:16:34 2011 -0700 +++ b/usr/src/java/adr/org/opensolaris/os/adr/Field.java Fri May 06 14:55:38 2011 -0400 @@ -20,8 +20,7 @@ */ /* - * Copyright 2009 Sun Microsystems, Inc. All rights reserved. - * Use is subject to license terms. + * Copyright (c) 2009, 2011, Oracle and/or its affiliates. All rights reserved. */ package org.opensolaris.os.adr; @@ -32,33 +31,26 @@ * will likely add properties to a Feature that shouldn't be added to * Fields. */ -public class Field implements HasType { +public class Field extends SimpleHasType { private String name_; - private Type type_; - private boolean optional_; + private Doc doc_; + + public Field(String name, Type type, boolean optional, Doc doc) { + super(type, optional); + name_ = name; + doc_ = doc; + } public Field(String name, Type type, boolean optional) { - name_ = name; - type_ = type; - optional_ = optional; - if (type.getSource() == Type.Source.FORWARD) - ((Type.ForwardType)type).addReference(this); + this(name, type, optional, null); } public String getName() { return name_; } - public void setType(Type type) { - type_ = type; - } - - public Type getType() { - return type_; - } - - public boolean isOptional() { - return optional_; + public Doc getDoc() { + return doc_; } } diff -r 3c730b38d1b0 -r 34ec90cc612c usr/src/java/adr/org/opensolaris/os/adr/HasError.java --- a/usr/src/java/adr/org/opensolaris/os/adr/HasError.java Thu May 05 13:16:34 2011 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,40 +0,0 @@ -/* - * CDDL HEADER START - * - * The contents of this file are subject to the terms of the - * Common Development and Distribution License (the "License"). - * You may not use this file except in compliance with the License. - * - * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE - * or http://www.opensolaris.org/os/licensing. - * See the License for the specific language governing permissions - * and limitations under the License. - * - * When distributing Covered Code, include this CDDL HEADER in each - * file and include the License file at usr/src/OPENSOLARIS.LICENSE. - * If applicable, add the following below this CDDL HEADER, with the - * fields enclosed by brackets "[]" replaced with your own identifying - * information: Portions Copyright [yyyy] [name of copyright owner] - * - * CDDL HEADER END - */ - -/* - * Copyright 2009 Sun Microsystems, Inc. All rights reserved. - * Use is subject to license terms. - */ - -package org.opensolaris.os.adr; - -public interface HasError { - /** - * Obtains the type of error returned by this operation. Must be a - * subclass of {@code Type.ComplexType}, with two exceptions. - * If this returns {@code null}, the operation can't fail. - * If this returns {@code StdType.VOID}, the operation may fail but - * errors don't include structured data. - * - * @return the error type - */ - Type getError(); -} diff -r 3c730b38d1b0 -r 34ec90cc612c usr/src/java/adr/org/opensolaris/os/adr/Interface.java --- a/usr/src/java/adr/org/opensolaris/os/adr/Interface.java Thu May 05 13:16:34 2011 -0700 +++ b/usr/src/java/adr/org/opensolaris/os/adr/Interface.java Fri May 06 14:55:38 2011 -0400 @@ -36,6 +36,7 @@ */ public class Interface { private String name_; + private Doc doc_; private Map allTypes_ = new HashMap(); private Map arrayTypes_ = new HashMap(); @@ -128,6 +129,24 @@ return (at); } + /** + * Adds documentation to the interface element. + * + * @param doc documentation content + */ + public void setDoc(Doc doc) { + doc_ = doc; + } + + /** + * Obtains the documentation associated with this interface + * element. + * + * @return documentation content + */ + public Doc getDoc() { + return doc_; + } /** * Obtains a specific structured type by name. diff -r 3c730b38d1b0 -r 34ec90cc612c usr/src/java/adr/org/opensolaris/os/adr/Method.java --- a/usr/src/java/adr/org/opensolaris/os/adr/Method.java Thu May 05 13:16:34 2011 -0700 +++ b/usr/src/java/adr/org/opensolaris/os/adr/Method.java Fri May 06 14:55:38 2011 -0400 @@ -20,32 +20,49 @@ */ /* - * Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2009, 2011, Oracle and/or its affiliates. All rights reserved. */ package org.opensolaris.os.adr; import java.util.List; -public class Method extends Feature implements HasError { +public class Method extends Feature { + private Result result_; private List args_; - private Type error_; + private ADRError error_; - public Method(String name, Stability stability, Type t, boolean optional, - List args, Type error) { + public Method(String name, Stability stability, Result result, + List args, ADRError error, Doc doc) { - super(name, stability, t, optional); + super(name, stability, result.getType(), result.isOptional(), doc); + result_ = result; args_ = args; error_ = error; } + public Method(String name, Stability stability, Result result, + List args, ADRError error) { + this(name, stability, result, args, error, null); + } + public List getArguments() { return args_; } - @Override - public Type getError() { + public Result getResult() { + return result_; + } + + /* + * If the method operation cannot fail, the error can be null. + */ + public ADRError getError() { return error_; } + + public Type getErrorType() { + return error_ != null ? error_.getType() : null; + } } diff -r 3c730b38d1b0 -r 34ec90cc612c usr/src/java/adr/org/opensolaris/os/adr/MethodDiff.java --- a/usr/src/java/adr/org/opensolaris/os/adr/MethodDiff.java Thu May 05 13:16:34 2011 -0700 +++ b/usr/src/java/adr/org/opensolaris/os/adr/MethodDiff.java Fri May 06 14:55:38 2011 -0400 @@ -20,7 +20,7 @@ */ /* - * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2010, 2011, Oracle and/or its affiliates. All rights reserved. */ package org.opensolaris.os.adr; @@ -44,10 +44,9 @@ Method mOld = methodsOld.get(mname); Method mNew = methodsNew.get(mname); assert (mOld != null && mNew != null); - updateFeatureDiffs(mOld, mNew, true, false); updateDiffs(mOld.getStability(), - diffTypeError(mOld.getError(), mNew.getError())); + diffTypeError(mOld.getErrorType(), mNew.getErrorType())); updateDiffs(mOld.getStability(), diffArgs(mOld.getArguments(), mNew.getArguments())); } diff -r 3c730b38d1b0 -r 34ec90cc612c usr/src/java/adr/org/opensolaris/os/adr/Property.java --- a/usr/src/java/adr/org/opensolaris/os/adr/Property.java Thu May 05 13:16:34 2011 -0700 +++ b/usr/src/java/adr/org/opensolaris/os/adr/Property.java Fri May 06 14:55:38 2011 -0400 @@ -20,28 +20,36 @@ */ /* - * Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2009, 2011, Oracle and/or its affiliates. All rights reserved. */ package org.opensolaris.os.adr; -public class Property extends Feature implements PropertyError { +public class Property extends Feature { private boolean readable_; private boolean writable_; - private Type readError_; - private Type writeError_; + private ADRError readError_; + private ADRError writeError_; + private Doc doc_; public Property(String name, Stability stability, Type t, boolean optional, - boolean readable, boolean writable, Type rerror, Type werror) { + boolean readable, boolean writable, ADRError rerror, + ADRError werror, Doc doc) { - super(name, stability, t, optional); + super(name, stability, t, optional, doc); assert (readable || writable); readable_ = readable; writable_ = writable; - readError_ = rerror; writeError_ = werror; + doc_ = doc; + } + + public Property(String name, Stability stability, Type t, boolean optional, + boolean readable, boolean writable, ADRError rerror, ADRError werror) { + this(name, stability, t, optional, readable, writable, rerror, werror, + null); } public boolean isReadable() { @@ -52,13 +60,22 @@ return writable_; } - @Override - public Type getReadError() { - return readError_; + /* + * If the operation cannot fail, the error can be null. + */ + public ADRError getReadError() { + return readError_; } - @Override - public Type getWriteError() { - return writeError_; + public Type getReadErrorType() { + return readError_ != null ? readError_.getType() : null; + } + + public ADRError getWriteError() { + return writeError_; + } + + public Type getWriteErrorType() { + return writeError_ != null ? writeError_.getType() : null; } } diff -r 3c730b38d1b0 -r 34ec90cc612c usr/src/java/adr/org/opensolaris/os/adr/PropertyDiff.java --- a/usr/src/java/adr/org/opensolaris/os/adr/PropertyDiff.java Thu May 05 13:16:34 2011 -0700 +++ b/usr/src/java/adr/org/opensolaris/os/adr/PropertyDiff.java Fri May 06 14:55:38 2011 -0400 @@ -20,7 +20,7 @@ */ /* - * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2010, 2011, Oracle and/or its affiliates. All rights reserved. */ package org.opensolaris.os.adr; @@ -43,18 +43,17 @@ Property pOld = propsOld.get(pname); Property pNew = propsNew.get(pname); assert (pOld != null && pNew != null); - boolean reads = pOld.isReadable() && pNew.isReadable(); boolean writes = pOld.isWritable() && pNew.isWritable(); updateFeatureDiffs(pOld, pNew, reads, writes); updateDiffs(pOld.getStability(), diffAccess(pOld, pNew)); if (reads) { - updateDiffs(pOld.getStability(), - diffTypeError(pOld.getReadError(), pNew.getReadError())); + updateDiffs(pOld.getStability(), diffTypeError( + pOld.getReadErrorType(), pNew.getReadErrorType())); } if (writes) { - updateDiffs(pOld.getStability(), - diffTypeError(pOld.getWriteError(), pNew.getWriteError())); + updateDiffs(pOld.getStability(), diffTypeError( + pOld.getWriteErrorType(), pNew.getWriteErrorType())); } } } diff -r 3c730b38d1b0 -r 34ec90cc612c usr/src/java/adr/org/opensolaris/os/adr/PropertyError.java --- a/usr/src/java/adr/org/opensolaris/os/adr/PropertyError.java Thu May 05 13:16:34 2011 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,50 +0,0 @@ -/* - * CDDL HEADER START - * - * The contents of this file are subject to the terms of the - * Common Development and Distribution License (the "License"). - * You may not use this file except in compliance with the License. - * - * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE - * or http://www.opensolaris.org/os/licensing. - * See the License for the specific language governing permissions - * and limitations under the License. - * - * When distributing Covered Code, include this CDDL HEADER in each - * file and include the License file at usr/src/OPENSOLARIS.LICENSE. - * If applicable, add the following below this CDDL HEADER, with the - * fields enclosed by brackets "[]" replaced with your own identifying - * information: Portions Copyright [yyyy] [name of copyright owner] - * - * CDDL HEADER END - */ - -/* - * Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved. - */ - -package org.opensolaris.os.adr; - -public interface PropertyError { - /** - * Obtains the type of error returned by the getter of the given property. - * Must be a subclass of {@code Type.ComplexType}, with two exceptions. - * If this returns {@code null}, the operation can't fail. - * If this returns {@code StdType.VOID}, the operation may fail but - * errors don't include structured data. - * - * @return the error type - */ - Type getReadError(); - - /** - * Obtains the type of error returned by the setter of the given property. - * Must be a subclass of {@code Type.ComplexType}, with two exceptions. - * If this returns {@code null}, the operation can't fail. - * If this returns {@code StdType.VOID}, the operation may fail but - * errors don't include structured data. - * - * @return the error type - */ - Type getWriteError(); -} diff -r 3c730b38d1b0 -r 34ec90cc612c usr/src/java/adr/org/opensolaris/os/adr/Result.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/usr/src/java/adr/org/opensolaris/os/adr/Result.java Fri May 06 14:55:38 2011 -0400 @@ -0,0 +1,45 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License (the "License"). + * You may not use this file except in compliance with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ + +/* + * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. + */ + +package org.opensolaris.os.adr; + + +public class Result extends SimpleHasType { + + private Doc doc_; + + public Result(Type type, boolean optional, Doc doc) { + super(type, optional); + doc_ = doc; + } + + public Result(Type type, boolean optional) { + this(type, optional, null); + } + + public Doc getDoc() { + return doc_; + } +} diff -r 3c730b38d1b0 -r 34ec90cc612c usr/src/java/adr/org/opensolaris/os/adr/SimpleHasType.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/usr/src/java/adr/org/opensolaris/os/adr/SimpleHasType.java Fri May 06 14:55:38 2011 -0400 @@ -0,0 +1,54 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License (the "License"). + * You may not use this file except in compliance with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ + +/* + * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. + */ + +package org.opensolaris.os.adr; + +public class SimpleHasType implements HasType { + + protected Type type_; + protected boolean optional_; + + public SimpleHasType(Type t, boolean optional) { + type_ = t; + optional_ = optional; + if (t != null && t.getSource() == Type.Source.FORWARD) + ((Type.ForwardType)t).addReference(this); + } + + @Override + public Type getType() { + return type_; + } + + @Override + public void setType(Type type) { + type_ = type; + } + + @Override + public boolean isOptional() { + return optional_; + } +} diff -r 3c730b38d1b0 -r 34ec90cc612c usr/src/java/adr/org/opensolaris/os/adr/Type.java --- a/usr/src/java/adr/org/opensolaris/os/adr/Type.java Thu May 05 13:16:34 2011 -0700 +++ b/usr/src/java/adr/org/opensolaris/os/adr/Type.java Fri May 06 14:55:38 2011 -0400 @@ -48,7 +48,7 @@ @Override public String toString() { - return type_.toString(); + return type_.toString().toLowerCase(); } } @@ -81,13 +81,20 @@ public static class ComplexType extends DefinedType { private List fields_; private List parents_; + private Doc doc_; public ComplexType(String name, List fields, - List parents) { + List parents, Doc doc) { super(Source.COMPLEX, name); fields_ = fields; parents_ = parents; + doc_ = doc; + } + + public ComplexType(String name, List fields, + List parents) { + this(name, fields, parents, null); } public List getFields() { @@ -98,6 +105,10 @@ return parents_; } + public Doc getDoc() { + return doc_; + } + public List getAllFields() { if (parents_ == null) return fields_; @@ -134,10 +145,16 @@ public static class EnumValue { private String name_; private int value_; + private Doc doc_; + + public EnumValue(String name, int value, Doc doc) { + name_ = name; + value_ = value; + doc_ = doc; + } public EnumValue(String name, int value) { - name_ = name; - value_ = value; + this(name, value, null); } public String getName() { @@ -147,16 +164,28 @@ public int getValue() { return value_; } + + public Doc getDoc() { + return doc_; + } } public static class EnumType extends DefinedType { private List values_; private EnumValue fallback_; + private Doc doc_; - public EnumType(String name, List values, String fallback) { + public EnumType(String name, List values, EnumValue fallback, + Doc doc) { super(Source.ENUM, name); values_ = values; - fallback_ = fallback != null ? new EnumValue(fallback, 0) : null; + fallback_ = fallback; + doc_ = doc; + } + + public EnumType(String name, List values, + EnumValue fallback) { + this(name, values, fallback, null); } public List getValues() { @@ -167,6 +196,10 @@ return fallback_; } + public Doc getDoc() { + return doc_; + } + @Override public String toString() { return "enum " + getName(); @@ -182,21 +215,24 @@ ((Type.ForwardType)type).addReference(this); } + @Override public void setType(Type type) { type_ = type; } + @Override public Type getType() { return (type_); } + @Override public boolean isOptional() { return false; } @Override public String toString() { - return "array of " + type_.toString(); + return type_.toString() + "[]"; } } diff -r 3c730b38d1b0 -r 34ec90cc612c usr/src/java/adr/org/opensolaris/os/adr/adrgen/ADRGen.java --- a/usr/src/java/adr/org/opensolaris/os/adr/adrgen/ADRGen.java Thu May 05 13:16:34 2011 -0700 +++ b/usr/src/java/adr/org/opensolaris/os/adr/adrgen/ADRGen.java Fri May 06 14:55:38 2011 -0400 @@ -35,6 +35,7 @@ import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; +import javax.xml.transform.TransformerException; import javax.xml.validation.SchemaFactory; import org.w3c.dom.Document; import org.w3c.dom.Element; @@ -45,6 +46,9 @@ import org.xml.sax.SAXParseException; public class ADRGen { + private static final String ADRGEN_USAGE = "Usage: adrgen [-N]" + + " [-c [-r [-m][-s]]] [-j dir [-i]] [-o {docbook | text | none}]" + + " [-d baseline.xml] spec.xml"; private static final EnumSet NULLABLE = EnumSet.of( StdType.STRING, StdType.OBJECT, StdType.OPAQUE, StdType.PASSWORD); @@ -55,6 +59,7 @@ Map pragmas_ = new HashMap(); String basename_; Interface iface_; + Document doc_; private boolean checkNullable_ = true; @@ -194,8 +199,8 @@ if (optional && !validOptional(type)) throw new ParseException("Field \"" + name + "\" specifies invalid optional type: " + type); - - return new Field(name, type, optional); + Doc doc = parseDocElements(field); + return new Field(name, type, optional, doc); } private Stability parseStability(Element e) throws ParseException { @@ -259,8 +264,9 @@ List fields = new LinkedList(); List parents = new LinkedList(); Set names = new HashSet(); + Doc tdoc = parseDocElements(type); + for (Element e : getChildElements(type)) { - parseDocChildren(e); String nname = e.getNodeName(); if (nname.equals("field")) { Field f = parseField(e); @@ -271,14 +277,13 @@ } else if (nname.equals("include")) { assert (fields.size() == 0); /* Schema enforced */ parents.add(parseInclude(e, iface_.types_)); - } else if (nname.equals("doc") || nname.equals("summary")) { - parseDoc(e); - } else { + } else if (!nname.equals("doc") && !nname.equals("summary")) { throw new ParseException("UNKNOWN ELEMENT: " + nname); } } - Type.ComplexType newtype = new Type.ComplexType(name, fields, parents); + Type.ComplexType newtype = new Type.ComplexType( + name, fields, parents, tdoc); /* * Since we only look up types in forwardTypes if we don't find @@ -306,17 +311,16 @@ private Type.EnumType parseEnum(Element type) throws ParseException { String name = type.getAttribute("name"); + Doc edoc = parseDocElements(type); List values = new LinkedList(); int nextValue = 0; - String fallback = null; + Type.EnumValue fallback = null; for (Element e : getChildElements(type)) { - parseDocChildren(e); String nname = e.getNodeName(); if (nname.equals("value")) { String ename = e.getAttribute("name"); int value = nextValue++; - String eval = e.getAttribute("value"); if (eval.length() > 0) { try { @@ -326,21 +330,23 @@ throw new ParseException("bogus enum value: " + eval); } } - values.add(new Type.EnumValue(ename, value)); + Doc vdoc = parseDocElements(e); + values.add(new Type.EnumValue(ename, value, vdoc)); } else if (nname.equals("fallback")) { if (fallback != null) throw new ParseException(String.format( "enum \"%s\" specifies multiple fallback values", name)); - fallback = e.getAttribute("name"); - } else if (nname.equals("doc") || nname.equals("summary")) { - parseDoc(e); - } else { + String fname = e.getAttribute("name"); + Doc fdoc = parseDocElements(e); + fallback = new Type.EnumValue(fname, 0, fdoc); + } else if (!nname.equals("doc") && !nname.equals("summary")) { throw new ParseException("UNKNOWN ELEMENT: " + nname); } } - Type.EnumType newtype = new Type.EnumType(name, values, fallback); + Type.EnumType newtype = new Type.EnumType(name, values, fallback, + edoc); Type.ForwardType ft = forwardTypes_.remove(name); if (ft != null) { @@ -368,10 +374,9 @@ Map methods = new TreeMap(); Map events = new TreeMap(); List parents = new LinkedList(); + Doc adoc = parseDocElements(type); - parseDocChildren(type); for (Element e : getChildElements(type)) { - parseDocChildren(e); String nname = e.getNodeName(); if (nname.equals("version")) { int major = -1; @@ -409,16 +414,16 @@ boolean both = access.equals("rw"); boolean writable = both || access.equals("wo"); boolean readable = both || access.equals("ro"); + Doc pdoc = parseDocElements(e); if (optional && !validOptional(t)) throw new ParseException("Property \"" + pname + "\" specifies invalid optional type: " + type); // process error elements - Type readError = null; - Type writeError = null; + ADRError readError = null; + ADRError writeError = null; for (Element f : getChildElements(e, "error")) { - parseDocChildren(f); String efor = f.getAttribute("for"); if ((efor == null) || (efor.trim().length() == 0)) efor = access; @@ -429,44 +434,45 @@ if (efor.equals("rw") && access.equals("rw")) { if ((readError != null) || (writeError != null)) - throw new ParseException("A read or write " + - "error is already assigned to this " + - "property - " + pname); + throw new ParseException("A read or write error " + + "is already assigned to this property - " + + pname); - writeError = theError; - readError = theError; + Doc doc = parseDocElements(f); + readError = writeError = new ADRError(theError, doc); } else if (efor.equals("ro") && (access.equals("rw") || access.equals("ro"))) { if (readError != null) - throw new ParseException("A read error is " + - "already assigned to this property - " + - pname); + throw new ParseException("A read error is " + + "already assigned to this property - " + pname); - readError = theError; + Doc doc = parseDocElements(f); + readError = new ADRError(theError, doc); } else if (efor.equals("wo") && (access.equals("rw") || access.equals("wo"))) { if (writeError != null) - throw new ParseException("A write error is " + - "already assigned to this property - " + - pname); + throw new ParseException("A write error is " + + "already assigned to this property - " + pname); - writeError = theError; + Doc doc = parseDocElements(f); + writeError = new ADRError(theError, doc); } else { throw new ParseException(efor + " error cannot be " + - " assigned to a " + access + " property." + pname); + "assigned to a " + access + " property - " + pname); } } - props.put(pname, new Property(pname, stability, t, optional, - readable, writable, readError, writeError)); + Property prop = new Property(pname, stability, t, optional, + readable, writable, readError, writeError, pdoc); + props.put(pname, prop); } else if (nname.equals("method")) { List args = new LinkedList(); String mname = e.getAttribute("name"); Stability stability = parseStability(e); - Type result = null; - Type error = null; - boolean optresult = false; + Result result = null; + ADRError error = null; + Doc mdoc = parseDocElements(e); + for (Element f : getChildElements(e)) { - parseDocChildren(f); String nnname = f.getNodeName(); if (nnname.equals("result")) { if (result != null) @@ -479,14 +485,14 @@ throw new ParseException("Method \"" + mname + "\" specifies invalid optional return type: " + t); - - result = t; - optresult = optional; + Doc doc = parseDocElements(f); + result = new Result(t, optional, doc); } else if (nnname.equals("error")) { assert (error == null); /* Schema enforced */ Type.ComplexType t = parseRef(f, iface_.types_); - if ((error = t) == null) - error = Type.getType(StdType.VOID); + Type etype = t != null ? t : Type.getType(StdType.VOID); + Doc doc = parseDocElements(f); + error = new ADRError(etype, doc); } else if (nnname.equals("argument")) { String aname = f.getAttribute("name"); Type t = parseTypedOrListed(f); @@ -495,21 +501,24 @@ throw new ParseException("Method \"" + mname + "\" specifies invalid optional argument type: " + t); - args.add(new Argument(aname, t, optional)); + Doc doc = parseDocElements(f); + args.add(new Argument(aname, t, optional, doc)); } } if (result == null) - result = Type.getType(StdType.VOID); - methods.put(mname, new Method(mname, stability, result, - optresult, args, error)); + result = new Result(Type.getType(StdType.VOID), false); + Method meth = new Method(mname, stability, result, args, error, + mdoc); + methods.put(mname, meth); } else if (nname.equals("event")) { String ename = e.getAttribute("name"); + Doc edoc = parseDocElements(e); events.put(ename, new Event(ename, parseStability(e), - parseTypedOrListed(e))); + parseTypedOrListed(e), edoc)); } } - API api = new API(name, vers, props, methods, events, parents); + API api = new API(name, vers, props, methods, events, parents, adoc); if (!iface_.addAPI(api)) throw new ParseException("API redefined: " + name); @@ -530,18 +539,15 @@ pragmas_.put(domain + ":" + name, value); } - private void parseDoc(Element doc) { - /* Do nothing for now */ - return; - } + private Doc parseDocElements(Element parent) + throws ParseException { - private void parseDocChildren(Element e) throws ParseException { - Element doc; - if ((doc = getSingleChild(e, "summary", false)) != null) - parseDoc(doc); - if ((doc = getSingleChild(e, "doc", false)) != null) - parseDoc(doc); - return; + Element esummary = getSingleChild(parent, "summary", false); + Element edetail = getSingleChild(parent, "doc", false); + + if (esummary != null || edetail != null) + return new Doc(esummary, edetail); + return null; } public ADRGen(DocumentBuilder builder, File file, boolean checkNullable) @@ -556,17 +562,17 @@ /* * Parse file. */ - Document doc = null; try { - doc = builder.parse(file); + doc_ = builder.parse(file); } catch (SAXException ex) { throw new ParseException(ex.getMessage()); } catch (IOException ex) { throw new ParseException(file + ": read error"); } - Element docelement = doc.getDocumentElement(); + Element docelement = doc_.getDocumentElement(); iface_ = new Interface(docelement.getAttribute("name")); + iface_.setDoc(parseDocElements(docelement)); /* XXX: get data from document element */ @@ -581,9 +587,7 @@ parseApi(e); } else if (nname.equals("pragma")) { parsePragma(e); - } else if (nname.equals("doc") || nname.equals("summary")) { - parseDoc(e); - } else { + } else if (!nname.equals("doc") && !nname.equals("summary")) { throw new ParseException("UNKNOWN NODE: " + nname); } } @@ -686,11 +690,12 @@ boolean generate_diff = false; boolean generate_common = false; boolean check_nullable = true; + DocGenerator.Format doc_fmt = null; String java_dir = "java"; String baseline = ""; List