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.examples;
016   import  com.github.aliteralmind.codelet.CodeletInstance;
017   import  com.github.aliteralmind.codelet.CodeletType;
018   import  com.github.aliteralmind.codelet.CustomizationInstructions;
019   import  com.github.aliteralmind.codelet.NewLineFilterFor;
020   import  com.github.aliteralmind.codelet.alter.NewJDLinkForWordOccuranceNum;
021   import  com.github.aliteralmind.codelet.alter.NewLineAltererFor;
022   import  com.github.aliteralmind.codelet.examples.adder.Adder;
023   import  com.github.aliteralmind.codelet.type.SourceCodeTemplate;
024   import  com.github.xbn.analyze.alter.AlterationRequired;
025   import  com.github.xbn.analyze.alter.ExpirableElements;
026   import  com.github.xbn.analyze.alter.MultiAlterType;
027   import  com.github.xbn.array.NullElement;
028   import  com.github.xbn.linefilter.FilteredLineIterator;
029   import  com.github.xbn.linefilter.alter.NewTextLineAltererFor;
030   import  com.github.xbn.linefilter.alter.TextLineAlterer;
031   import  com.github.xbn.regexutil.ReplacedInEachInput;
032   import  java.util.regex.Pattern;
033   import  static com.github.aliteralmind.codelet.CodeletBaseConfig.*;
034/**
035   <P style="font-size: 150%;"><b><a href="{@docRoot}/overview-summary.html#xmpl_links"><FONT SIZE="+1"><code><IMG SRC="{@docRoot}/resources/left_arrow.gif"/> GO BACK</code></FONT></a> &nbsp; &nbsp; Codelet: Example: Advanced customization: Making relevant functions into clickable JavaDoc links</b></p>
036
037   <h3><u>Taglet:</u></h3>
038
039   <P style="font-size: 125%;"><b>{@code {@.codelet.and.out com.github.aliteralmind.codelet.examples.adder.AdderDemo%adderDemo_lineSnippetWithLinks()}}</b></p>
040
041   <h3><u>Replaced with:</u></h3>
042
043   <p><i>(Output begins and ends between the horizontal lines.)</i></p>
044
045   <HR/>
046{@.codelet.and.out com.github.aliteralmind.codelet.examples.adder.AdderDemo%adderDemo_lineSnippetWithLinks()}
047   <HR/>
048
049   <h3><u>Original source code:</u></h3>
050
051{@.codelet com.github.aliteralmind.codelet.examples.adder.AdderDemo}
052
053 * @since  0.1.0
054 * @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>
055 **/
056public class LineRangeWithLinksCompact  {
057   private static final CustomizationInstructions<SourceCodeTemplate> adderDemo_lineSnippetWithLinks(CodeletInstance instance, CodeletType needed_defaultAlterType)  {
058      FilteredLineIterator filter = NewLineFilterFor.lineRange(
059         1, false, "Adder adder", null, null,
060         2, false, "println(adder", null, null,
061         null, null, null);
062
063      TextLineAlterer[] alterers = {
064         NewTextLineAltererFor.escapeHtml(),
065         NewLineAltererFor.eliminateIndentationOrNull("^      ", null),
066         NewJDLinkForWordOccuranceNum.constructor(instance,
067            1, Adder.class, "(*)", null, null, null, null),
068         NewJDLinkForWordOccuranceNum.method(instance,
069            1, Adder.class, "getSum()", null, null, null, null)};
070
071      return  new CustomizationInstructions<SourceCodeTemplate>(instance,
072            needed_defaultAlterType).
073         filter(filter).
074         orderedAlterers(null, NullElement.OK, ExpirableElements.OPTIONAL,
075            MultiAlterType.CUMULATIVE, alterers).
076         defaultOrOverrideTemplate(null).
077         build();
078   }  //End snippet
079
080   private static final CustomizationInstructions<SourceCodeTemplate> LineRangeWithLinksCompact_adderDemo_lineRangeWithLinks(CodeletInstance instance, CodeletType needed_defaultAlterType, Boolean do_highlightDbgOnOff)  {
081      String debugPrefix = "LineRangeWithLinksCompact.LineRangeWithLinksCompact_adderDemo_lineRangeWithLinks";
082      FilteredLineIterator filter = NewLineFilterFor.lineRangeWithReplace(instance,
083         debugPrefix,
084                   //Chopped in half, so this string isn't mistaken for the match
085         1, true, "(<SourceCodeTemplate> ad"+"derDemo_lineSnippetWithLinks)", "$1",
086               ReplacedInEachInput.FIRST,
087         1, true, "\\} +//End snippet$", "}", ReplacedInEachInput.FIRST);
088
089      TextLineAlterer[] alterers = {
090         NewTextLineAltererFor.escapeHtml(),
091         NewLineAltererFor.eliminateIndentationOrNull("^   ", null),
092         NewJDLinkForWordOccuranceNum.method(instance, debugPrefix, null,
093            1, NewLineFilterFor.class, "lineRange(int, *)"),
094         NewJDLinkForWordOccuranceNum.method(instance, debugPrefix, null,
095            1, NewLineAltererFor.class, "eliminateIndentationOrNull(*)"),
096         NewJDLinkForWordOccuranceNum.method(instance, debugPrefix, null,
097            1, NewJDLinkForWordOccuranceNum.class, "constructor(*, Appendable)"),
098         NewJDLinkForWordOccuranceNum.method(instance, debugPrefix, null,
099            1, NewJDLinkForWordOccuranceNum.class, "method(*, String, Appendable, *)"),
100         NewJDLinkForWordOccuranceNum.method(instance, debugPrefix, null,
101            1, CustomizationInstructions.class, "filter(*)"),
102         NewJDLinkForWordOccuranceNum.method(instance, debugPrefix, null,
103            1, CustomizationInstructions.class, "orderedAlterers(*)"),
104         NewJDLinkForWordOccuranceNum.method(instance, debugPrefix, null,
105            1, CustomizationInstructions.class, "defaultOrOverrideTemplate(*)"),
106         ((!do_highlightDbgOnOff) ? null
107            :  NewTextLineAltererFor.replacement(AlterationRequired.YES,
108                  Pattern.compile("(on=System.out, off=null)"), "<span style=\"background-color: #FFFF00\">$1</span>",
109                  ReplacedInEachInput.FIRST,
110                  getDebugApblIfOn(instance, debugPrefix + ".highlightonoff"),
111                  null))};
112      return  new CustomizationInstructions<SourceCodeTemplate>(instance,
113            needed_defaultAlterType).
114         filter(filter).
115         orderedAlterers(
116            getDebugApblIfOn(instance, debugPrefix + ".allalterer"),
117            NullElement.OK, ExpirableElements.OPTIONAL,
118            MultiAlterType.CUMULATIVE, alterers).
119         defaultOrOverrideTemplate(
120            getDebugApblIfOn(instance, debugPrefix + ".template")).
121         build();
122   }
123}