001/*
002 * Copyright (c) 1998, 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.util;
027
028import java.util.*;
029
030import javax.lang.model.element.Element;
031
032import org.jdrupes.mdoclet.internal.doclets.toolkit.BaseConfiguration;
033
034/**
035 * Build list of all the deprecated packages, classes, constructors, fields and methods.
036 */
037public class DeprecatedAPIListBuilder extends SummaryAPIListBuilder {
038
039    private SortedSet<Element> forRemoval;
040    public final List<String> releases;
041    private final Set<String> foundReleases;
042
043    /**
044     * Constructor.
045     *
046     * @param configuration the current configuration of the doclet
047     * @param since list of releases passed via <code>--since</code> option
048     */
049    public DeprecatedAPIListBuilder(BaseConfiguration configuration,
050            List<String> since) {
051        super(configuration, configuration.utils::isDeprecated);
052        this.foundReleases = new HashSet<>();
053        buildSummaryAPIInfo();
054        // The releases list is set to the intersection of releases defined via
055        // `--since` option
056        // and actually occurring values of `Deprecated.since` in documented
057        // deprecated elements.
058        // If there are `Deprecated.since` values not contained in the `--since`
059        // option list
060        // an empty string is added to the releases list which causes the writer
061        // to generate
062        // a checkbox for other (unlisted) releases.
063        List<String> releases = new ArrayList<>(since);
064        if (!releases.isEmpty()) {
065            releases.retainAll(foundReleases);
066            if (!releases.containsAll(foundReleases)) {
067                // Empty string is added for other releases, including the
068                // default value ""
069                releases.add("");
070            }
071        }
072        this.releases = Collections.unmodifiableList(releases);
073    }
074
075    public SortedSet<Element> getForRemoval() {
076        if (forRemoval == null) {
077            forRemoval = createSummarySet();
078        }
079        return forRemoval;
080    }
081
082    @Override
083    protected void handleElement(Element e) {
084        foundReleases.add(utils.getDeprecatedSince(e));
085        if (utils.isDeprecatedForRemoval(e)) {
086            getForRemoval().add(e);
087        }
088    }
089}