/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.apache.sis.internal.taglet;

import com.sun.javadoc.Tag;
import com.sun.javadoc.RootDoc;
import com.sun.javadoc.SourcePosition;
import com.sun.tools.doclets.Taglet;
import com.sun.tools.doclets.internal.toolkit.Configuration;
import com.sun.tools.doclets.formats.html.ConfigurationImpl;


/**
 * Base class of inline taglets.
 *
 * @author  Martin Desruisseaux (Geomatys)
 * @since   0.3
 * @version 0.3
 * @module
 */
abstract class InlineTaglet implements Taglet {
    /**
     * Returns the doclet configuration.
     */
    private static synchronized Configuration getConfiguration() {
        return ConfigurationImpl.getInstance();
    }

    /**
     * Constructs a default inline taglet.
     */
    InlineTaglet() {
    }

    /**
     * Returns {@code true} since SIS taglets can be used in overview.
     *
     * @return Default to {@code true}.
     */
    @Override
    public boolean inOverview() {
        return true;
    }

    /**
     * Returns {@code true} since SIS taglets can be used in package documentation.
     *
     * @return Default to {@code true}.
     */
    @Override
    public boolean inPackage() {
        return true;
    }

    /**
     * Returns {@code true} since SIS taglets can be used in type documentation
     * (classes or interfaces).
     *
     * @return Default to {@code true}.
     */
    @Override
    public boolean inType() {
        return true;
    }

    /**
     * Returns {@code true} since SIS taglets can be used in constructor
     *
     * @return Default to {@code true}.
     */
    @Override
    public boolean inConstructor() {
        return true;
    }

    /**
     * Returns {@code true} since SIS taglets can be used in method documentation.
     *
     * @return Default to {@code true}.
     */
    @Override
    public boolean inMethod() {
        return true;
    }

    /**
     * Returns {@code true} since SIS taglets can be used in field documentation.
     *
     * @return Default to {@code true}.
     */
    @Override
    public boolean inField() {
        return true;
    }

    /**
     * Returns {@code true} since this base class is all about inline tags.
     *
     * @return Always {@code true}.
     */
    @Override
    public final boolean isInlineTag() {
        return true;
    }

    /**
     * Given an array of {@code Tag}s representing this custom tag, return its string
     * representation. This method should not be called since arrays of inline tags do
     * not exist. However we define it as a matter of principle.
     *
     * @param  tags The tags to format.
     * @return A string representation of the given tags.
     */
    @Override
    public final String toString(final Tag[] tags) {
        final StringBuilder buffer = new StringBuilder(64);
        for (int i=0; i<tags.length; i++) {
            buffer.append(toString(tags[i]));
        }
        return buffer.toString();
    }

    /**
     * Prints a warning message.
     */
    static void printWarning(final SourcePosition position, final String message) {
        final RootDoc root = getConfiguration().root;
        if (root != null) {
            root.printWarning(position, message);
        } else {
            System.err.println(message);
        }
    }

    /**
     * Prints an error message.
     */
    static void printError(final SourcePosition position, final String message) {
        final RootDoc root = getConfiguration().root;
        if (root != null) {
            root.printError(position, message);
        } else {
            System.err.println(message);
        }
    }
}

@@ -1293,163 +1293,1182 @@
   * 
-Returns the doclet configuration.%0A     */%0A    private static synchronized Configuration getConfiguration() %7B%0A        return ConfigurationImpl.getInstance()
+The doclet configuration, created when first needed for reporting warnings.%0A     */%0A    private static Configuration configuration;%0A%0A    /**%0A     * Returns the root document, or %7B@code null%7D if none.%0A     */%0A    private static synchronized RootDoc getRootDoc() %7B%0A        if (configuration == null) %7B%0A            /*%0A             * Try to invoke ConfigurationImpl.getInstance(), which exists on JDK6 and JDK7 but not on JDK8.%0A             * If we fail, fallback on direct instantiation of ConfigurationImpl(), which is possible only%0A             * in JDK8 (because the constructor is private on JDK6 and JDK7).%0A             */%0A            try %7B%0A                configuration = (Configuration) ConfigurationImpl.class.getMethod(%22getInstance%22).invoke(null);%0A            %7D catch (Exception e) %7B // ReflectiveOperationException on the JDK7 branch%0A                try %7B%0A                    configuration = ConfigurationImpl.class.newInstance();%0A                %7D catch (Exception e2) %7B // ReflectiveOperationException on the JDK7 branch%0A                    return null; // Allowed by this method contract.%0A                %7D%0A            %7D%0A        %7D%0A        return configuration.root
 ;%0A  
@@ -4901,36 +4901,25 @@
 ot = get
-Configuration().root
+RootDoc()
 ;%0A      
@@ -5231,28 +5231,17 @@
  get
-Configuration().root
+RootDoc()
 ;%0A  

Make the JDK6 branch compilable with the JDK7 and JDK8 compilers.