001/*
002 * Copyright (c) 2003, 2022, Oracle and/or its affiliates. All rights reserved.
003 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004 *
005 * This code is free software; you can redistribute it and/or modify it
006 * under the terms of the GNU General Public License version 2 only, as
007 * published by the Free Software Foundation.  Oracle designates this
008 * particular file as subject to the "Classpath" exception as provided
009 * by Oracle in the LICENSE file that accompanied this code.
010 *
011 * This code is distributed in the hope that it will be useful, but WITHOUT
012 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
014 * version 2 for more details (a copy is included in the LICENSE file that
015 * accompanied this code).
016 *
017 * You should have received a copy of the GNU General Public License version
018 * 2 along with this work; if not, write to the Free Software Foundation,
019 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020 *
021 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
022 * or visit www.oracle.com if you need additional information or have any
023 * questions.
024 */
025
026package org.jdrupes.mdoclet.internal.doclets.toolkit.builders;
027
028import java.util.List;
029import javax.lang.model.element.Element;
030import javax.lang.model.element.TypeElement;
031
032import org.jdrupes.mdoclet.internal.doclets.toolkit.Content;
033import org.jdrupes.mdoclet.internal.doclets.toolkit.DocletException;
034import org.jdrupes.mdoclet.internal.doclets.toolkit.util.VisibleMemberTable;
035import org.jdrupes.mdoclet.internal.doclets.toolkit.util.VisibleMemberTable.Kind;
036
037/**
038 * The superclass for all member builders.  Member builders are only executed
039 * within Class Builders.  They essentially build subcomponents.  For example,
040 * method documentation is a subcomponent of class documentation.
041 */
042public abstract class AbstractMemberBuilder extends AbstractBuilder {
043
044    protected final TypeElement typeElement;
045
046    protected final VisibleMemberTable visibleMemberTable;
047
048    /**
049     * Construct a SubBuilder.
050     * @param context a context object, providing information used in this run
051     *        of the doclet.
052     */
053    public AbstractMemberBuilder(Context context, TypeElement typeElement) {
054        super(context);
055        this.typeElement = typeElement;
056        visibleMemberTable = configuration.getVisibleMemberTable(typeElement);
057    }
058
059    /**
060     * This method is not supported by subbuilders.
061     *
062     * @throws AssertionError always
063     */
064    @Override
065    public void build() {
066        // You may not call the build method in a subbuilder.
067        throw new AssertionError();
068    }
069
070    /**
071     * Build the documentation.
072     *
073     * @param target the content into which to add the documentation
074     * @throws DocletException if there is a problem building the documentation
075     */
076    public abstract void build(Content target) throws DocletException;
077
078    /**
079     * Returns true if this subbuilder has anything to document.
080     *
081     * @return true if this subbuilder has anything to document
082     */
083    public abstract boolean hasMembersToDocument();
084
085    /**
086     * Returns a list of visible elements of the specified kind in this
087     * type element.
088     * @param kind of members
089     * @return a list of members
090     */
091    protected List<Element> getVisibleMembers(Kind kind) {
092        return visibleMemberTable.getVisibleMembers(kind);
093    }
094}