001/*license*\ 002 Codelet: Copyright (C) 2014, Jeff Epstein (aliteralmind __DASH__ github __AT__ yahoo __DOT__ com) 003 004 This software is dual-licensed under the: 005 - Lesser General Public License (LGPL) version 3.0 or, at your option, any later version; 006 - Apache Software License (ASL) version 2.0. 007 008 Either license may be applied at your discretion. More information may be found at 009 - http://en.wikipedia.org/wiki/Multi-licensing. 010 011 The text of both licenses is available in the root directory of this project, under the names "LICENSE_lgpl-3.0.txt" and "LICENSE_asl-2.0.txt". The latest copies may be downloaded at: 012 - LGPL 3.0: https://www.gnu.org/licenses/lgpl-3.0.txt 013 - ASL 2.0: http://www.apache.org/licenses/LICENSE-2.0.txt 014\*license*/ 015package com.github.aliteralmind.codelet.taglet; 016 import com.github.aliteralmind.codelet.CodeletFormatException; 017 import com.github.aliteralmind.codelet.CodeletInstance; 018 import com.github.aliteralmind.codelet.TagletProcessor; 019 import com.sun.javadoc.Doc; 020 import com.sun.javadoc.SourcePosition; 021 import com.sun.javadoc.Tag; 022 import java.nio.file.AccessDeniedException; 023 import java.nio.file.NoSuchFileException; 024/** 025 <p>The interface between Java {@code com.sun.javadoc.*} and {@code com.github.aliteralmind.codelet.*}. The only dependencies on {@code com.sun.javadoc.*} are in this {@code com.github.aliteralmind.codelet.taglet} package. This is done in the interest of <a href="http://stackoverflow.com/questions/23138806/how-to-make-inline-taglets-which-require-com-sun-more-cross-platform-is-there">minimizing the dependency</a> on {@code com.sun.javadoc}, which is not as cross-platform as Java itself.</p> 026 027 * @since 0.1.0 028 * @author Copyright (C) 2014, Jeff Epstein ({@code aliteralmind __DASH__ github __AT__ yahoo __DOT__ com}), dual-licensed under the LGPL (version 3.0 or later) or the ASL (version 2.0). See source code for details. <a href="http://codelet.aliteralmind.com">{@code http://codelet.aliteralmind.com}</a>, <a href="https://github.com/aliteralmind/codelet">{@code https://github.com/aliteralmind/codelet}</a> 029 **/ 030public enum CodletComSunJavadocTagProcessor { 031 INSTANCE; 032 /* 033 To avoid configuration from being loaded repeatedly. 034 private static TagletProcessor FIRST_TAGLET_PROC_INSTANCE; 035 */ 036 /** 037 <p>Passes all taglet information to the codelet processor (without any references to {@code com.sun.javadoc}) and returns the text that replaces the taglet in the JavaDoc.</p> 038 039 @return <code>(new {@link com.github.aliteralmind.codelet.TagletProcessor#TagletProcessor(CodeletInstance) TagletProcessor}(instance)).{@link com.github.aliteralmind.codelet.TagletProcessor#get() get}()</code></p> 040 041 <p>where<ul> 042 <li>{@code instance} is a 043<blockquote><pre>new {@link com.github.aliteralmind.codelet.CodeletInstance#CodeletInstance(String, String, String, File, int, String, String) CodeletInstance}(tag.{@link com.sun.javadoc.Tag#name() name}().substring(1), 044 {@link com.github.aliteralmind.codelet.taglet.ComSunJavaDocUtil}.{@link com.github.aliteralmind.codelet.taglet.ComSunJavaDocUtil#getEnclosingPackageName(Tag) getEnclosingPackageName}(tag), 045 ComSunJavaDocUtil.{@link com.github.aliteralmind.codelet.taglet.ComSunJavaDocUtil#getEnclosingSimpleName(Tag, IncludePostClassName) getEnclosingSimpleName}(tag, {@link IncludePostClassName}.{@link IncludePostClassName#NO NO}), 046 pos.{@link com.sun.javadoc.SourcePosition#file() file}(), pos.{@link com.sun.javadoc.SourcePosition#line() line}(), tag.{@link com.sun.javadoc.Tag#text() text}(), 047 ComSunJavaDocUtil.{@link com.github.aliteralmind.codelet.taglet.ComSunJavaDocUtil#getRelativeUrlToDocRoot(Tag) getRelativeUrlToDocRoot}(tag))</pre></blockquote></li> 048 <li>{@code holder} is <code>tag.{@link com.sun.javadoc.Tag#holder() holder}()</code>, and</li> 049 <li>{@code pos} is <code>holder.{@link com.sun.javadoc.Doc#position() position}()</code></li> 050 </ul>{@code name}().substring(1)} is to eliminate the trailing at-sign ({@code '@'}). Don't understand what that's part of it.</p> 051 052 @param tag May not be {@code null}. 053 @exception RuntimeException If the taglet is not successfully processed, for any reason. Get the causing exception with {@link java.lang.RuntimeException#getCause() getCause}{@code ()}. 054 */ 055 public static final String get(Tag tag) { 056 Doc holder = tag.holder(); 057 SourcePosition pos = holder.position(); 058 String namePostAtSign = tag.name().substring(1); 059 CodeletInstance instance = new CodeletInstance(namePostAtSign, 060 ComSunJavaDocUtil.getEnclosingPackageName(tag), 061 ComSunJavaDocUtil.getEnclosingSimpleName(tag, IncludePostClassName.NO), 062 pos.file(), pos.line(), tag.text(), 063 ComSunJavaDocUtil.getRelativeUrlToDocRoot(tag)); 064 065 try { 066 TagletProcessor tproc = (new TagletProcessor(instance)); 067 /* 068 if(FIRST_TAGLET_PROC_INSTANCE == null) { 069 To avoid configuration from being loaded repeatedly. This block is not synchronized, because it doesn't matter which instance is held--just that *an* instance is held. 070 FIRST_TAGLET_PROC_INSTANCE = tproc; 071 } 072 */ 073 return tproc.get(); 074 } catch(CodeletFormatException | ClassNotFoundException | 075 NoSuchMethodException | NoSuchFileException | 076 AccessDeniedException | InterruptedException x) { 077 throw new RuntimeException(x); 078 } 079 } 080}