20
20
/*
21
21
* Copyright (c) 2009, 2017, Oracle and/or its affiliates. All rights reserved.
22
22
* Portions Copyright 2011 Jens Elkner.
23
+ * Portions Copyright (c) 2017, Chris Fraire <[email protected] >.
23
24
*/
24
25
package org .opensolaris .opengrok .analysis ;
25
26
@@ -537,27 +538,31 @@ protected void startNewLine() throws IOException {
537
538
* @param keywords a set of keywords recognized by this analyzer (no links
538
539
* will be generated if the symbol is a keyword)
539
540
* @param line the line number on which the symbol appears
541
+ * @return true if the {@code symbol} was not in {@code keywords} or if
542
+ * {@code keywords} was null
540
543
* @throws IOException if an error occurs while writing to the stream
541
544
*/
542
- protected void writeSymbol (String symbol , Set <String > keywords , int line )
545
+ protected boolean writeSymbol (String symbol , Set <String > keywords , int line )
543
546
throws IOException {
544
- writeSymbol (symbol , keywords , line , true , false );
547
+ return writeSymbol (symbol , keywords , line , true , false );
545
548
}
546
549
547
- /**
550
+ /**
548
551
* Write a symbol and generate links as appropriate.
549
552
*
550
553
* @param symbol the symbol to write
551
554
* @param keywords a set of keywords recognized by this analyzer (no links
552
555
* will be generated if the symbol is a keyword)
553
556
* @param line the line number on which the symbol appears
554
557
* @param caseSensitive Whether the keyword list is case sensitive
558
+ * @return true if the {@code symbol} was not in {@code keywords} or if
559
+ * {@code keywords} was null
555
560
* @throws IOException if an error occurs while writing to the stream
556
561
*/
557
- protected void writeSymbol (
562
+ protected boolean writeSymbol (
558
563
String symbol , Set <String > keywords , int line , boolean caseSensitive )
559
564
throws IOException {
560
- writeSymbol (symbol , keywords , line , caseSensitive , false );
565
+ return writeSymbol (symbol , keywords , line , caseSensitive , false );
561
566
}
562
567
563
568
/**
@@ -569,21 +574,45 @@ protected void writeSymbol(
569
574
* @param line the line number on which the symbol appears
570
575
* @param caseSensitive Whether the keyword list is case sensitive
571
576
* @param quote Whether the symbol gets quoted in links or not
577
+ * @return true if the {@code symbol} was not in {@code keywords} or if
578
+ * {@code keywords} was null
579
+ * @throws IOException if an error occurs while writing to the stream
580
+ */
581
+ protected boolean writeSymbol (String symbol , Set <String > keywords ,
582
+ int line , boolean caseSensitive , boolean quote )
583
+ throws IOException {
584
+ return writeSymbol (symbol , keywords , line , caseSensitive , quote , false );
585
+ }
586
+
587
+ /**
588
+ * Write a symbol and generate links as appropriate.
589
+ *
590
+ * @param symbol the symbol to write
591
+ * @param keywords a set of keywords recognized by this analyzer (no links
592
+ * will be generated if the symbol is a keyword)
593
+ * @param line the line number on which the symbol appears
594
+ * @param caseSensitive Whether the keyword list is case sensitive
595
+ * @param quote Whether the symbol gets quoted in links or not
596
+ * @param isKeyword Whether the symbol is certainly a keyword without
597
+ * bothering to look up in a defined {@code keywords}
598
+ * @return true if the {@code symbol} was not in {@code keywords} or if
599
+ * {@code keywords} was null and if-and-only-if {@code isKeyword} is false
572
600
* @throws IOException if an error occurs while writing to the stream
573
601
*/
574
- protected void writeSymbol (
575
- String symbol , Set <String > keywords , int line , boolean caseSensitive , boolean quote )
602
+ protected boolean writeSymbol (
603
+ String symbol , Set <String > keywords , int line , boolean caseSensitive ,
604
+ boolean quote , boolean isKeyword )
576
605
throws IOException {
577
606
String [] strs = new String [1 ];
578
607
strs [0 ] = "" ;
579
608
String jsEscapedSymbol = symbol .replace ("'" , "\\ '" );
580
609
String qt = (quote ) ? """ : "" ;
581
610
582
611
String check = caseSensitive ? symbol : symbol .toLowerCase ();
583
- if (keywords != null && keywords .contains ( check )) {
612
+ if (isKeyword || ( keywords != null && keywords .contains ( check ) )) {
584
613
// This is a keyword, so we don't create a link.
585
614
out .append ("<b>" ).append (symbol ).append ("</b>" );
586
-
615
+ return false ;
587
616
} else if (defs != null && defs .hasDefinitionAt (symbol , line , strs )) {
588
617
// This is the definition of the symbol.
589
618
String type = strs [0 ];
@@ -658,6 +687,18 @@ protected void writeSymbol(
658
687
out .append (symbol );
659
688
out .append ("</a>" );
660
689
}
690
+ return true ;
691
+ }
692
+
693
+ /**
694
+ * Write an {@code htmlize()}d keyword symbol
695
+ *
696
+ * @param symbol the symbol to write
697
+ * @param line the line number on which the symbol appears
698
+ * @throws IOException if an error occurs while writing to the stream
699
+ */
700
+ protected void writeKeyword (String symbol , int line ) throws IOException {
701
+ writeSymbol (htmlize (symbol ), null , line , false , false , true );
661
702
}
662
703
663
704
/**
@@ -711,4 +752,14 @@ public void yypop() throws IOException {
711
752
out .write (popString );
712
753
}
713
754
}
755
+
756
+ /**
757
+ * reset current yy state, and clear stack
758
+ * @param newState state id
759
+ */
760
+ public void yyjump (int newState ) {
761
+ yybegin (newState );
762
+ this .stack .clear ();
763
+ this .stackPopString .clear ();
764
+ }
714
765
}
0 commit comments