001package ball.tools.javadoc;
002/*-
003 * ##########################################################################
004 * Utilities
005 * $Id: LinkThisTaglet.html 5431 2020-02-12 19:03:17Z ball $
006 * $HeadURL: svn+ssh://svn.hcf.dev/var/spool/scm/repository.svn/hcf-dev/blog/2019-03-30-java-interface-facades/src/main/resources/javadoc/src-html/ball/tools/javadoc/LinkThisTaglet.html $
007 * %%
008 * Copyright (C) 2008 - 2020 Allen D. Ball
009 * %%
010 * Licensed under the Apache License, Version 2.0 (the "License");
011 * you may not use this file except in compliance with the License.
012 * You may obtain a copy of the License at
013 *
014 *      http://www.apache.org/licenses/LICENSE-2.0
015 *
016 * Unless required by applicable law or agreed to in writing, software
017 * distributed under the License is distributed on an "AS IS" BASIS,
018 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
019 * See the License for the specific language governing permissions and
020 * limitations under the License.
021 * ##########################################################################
022 */
023import ball.annotation.ServiceProviderFor;
024import ball.lang.Keyword;
025import ball.xml.FluentNode;
026import com.sun.javadoc.Tag;
027import com.sun.tools.doclets.Taglet;
028import java.util.Map;
029import lombok.NoArgsConstructor;
030import lombok.ToString;
031
032import static org.apache.commons.lang3.StringUtils.isNotEmpty;
033
034/**
035 * Inline {@link Taglet} to provide {@link.this} links.
036 *
037 * @author {@link.uri mailto:ball@hcf.dev Allen D. Ball}
038 * @version $Revision: 5431 $
039 */
040@ServiceProviderFor({ Taglet.class })
041@TagletName("link.this")
042@NoArgsConstructor @ToString
043public class LinkThisTaglet extends AbstractInlineTaglet
044                            implements SunToolsInternalToolkitTaglet {
045    private static final LinkThisTaglet INSTANCE = new LinkThisTaglet();
046
047    public static void register(Map<Object,Object> map) {
048        register(map, INSTANCE);
049    }
050
051    @Override
052    public FluentNode toNode(Tag tag) throws Throwable {
053        if (isNotEmpty(tag.text().trim())) {
054            throw new IllegalArgumentException("Invalid argument");
055        }
056
057        return a(tag,
058                 getClassFor(getContainingClassDocFor(tag)),
059                 Keyword.THIS.lexeme());
060    }
061}