summaryrefslogtreecommitdiff
path: root/test/scaladoc/run/t5527.scala
blob: 770d4ad13f751daaff921cacd472ad6dada7111d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
import scala.tools.partest._
import java.io._
import scala.tools.nsc._
import scala.tools.cmd.CommandLineParser
import scala.tools.nsc.doc.{Settings, DocFactory}
import scala.tools.nsc.reporters.ConsoleReporter

object Test extends DirectTest {

  override def extraSettings: String = "-usejavacp -Xprint:parser -Yrangepos -Ystop-after:parser -d " + testOutput.path

  override def code = """
    // SI-5527
    object UselessComments {

      var z = 0

      def test1 = {
        /** Some comment here */
        object Maybe {
          /** Some comment inside */
          def nothing() = ()
        }
      }

      def test2 = {
        var x = 4
        if (true) {
          /** Testing 123 */
          x = 5
          val y = 6
        }
      }

      def test3 = {
        if (true)
         z = 3

        /** Calculate this result. */
        val t = 4
        for (i <- 0 to 4)
          println(i)
      }

      val test4 = ('a') match {
        /** Another digit is a giveaway. */
        case '0' | '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9'  =>
          true
        case _ =>
          false
      }

      def test5 {
        /** @martin is this right? It shouldn't flag me as scaladoc. */
        if (true) ???
      }

      def test6 = {
        /** Document this crucial constant for posterity.
         *  Don't forget to dedoc this comment if you refactor to a local.
         *  @author Paul Phillips
         */
        val u = 4
        for (i <- 0 to u)
          println(i)
      }
      def test7 = {
        /** Some standard tags are tolerated locally and shouldn't trigger a warning.
         *  @note Don't change this unless you know what you're doing. This means you.
         */
        val u = 4
        for (i <- 0 to u)
          println(i)
      }
      def test8 = {
        /*************************\
         * Fancy ASCII Art Block *
         *   @author som-snytt   *
        \*************************/
        // this is just a local
        val z = "fancy"
        z replace ("fanc", "arts")
      }
      def test9 = {
        val i = 10 */** Important!
                     *  We have to multiply here!
                     *  @author community
                     *  @see SI-1234
                     */
                10
        assert(i == 100)
      }
    }

    /** comments that we should keep */
    object UsefulComments {
      /** class A */
      class A {
        /** f */
        def f(i: Int) = i
        /** v */
        val v = 1
        /** u */
        var u = 2
      }     
      /** trait B */
      trait B {
        /** T */
        type T
        /** f */
        def f(i: Int)
        /** v */
        val v = 1
        /** u */
        var u = 2
      }     
      /** object C */
      object C {
        /** f */
        def f(i: Int) = i
        /** v */
        val v = 1
        /** u */
        var u = 2
      }
      /** class D */
      @deprecated("use ... instead", "2.10.0")
      class D

      /** Get the simple value.
       *  @return the default value
       */
      // an intervening line comment
      /* I had more to say, but didn't want to pollute the scaladoc. */
      def value: Int = 7
    }
  """.trim

  override def show(): Unit = {
    // redirect err to out, for logging
    val prevErr = System.err
    System.setErr(System.out)
    compile()
    System.setErr(prevErr)
  }

  override def newCompiler(args: String*): Global = {
    // we want the Scaladoc compiler here, because it keeps DocDef nodes in the tree
    val settings = new Settings(_ => ())
    val command = new ScalaDoc.Command((CommandLineParser tokenize extraSettings) ++ args.toList, settings)
    new DocFactory(new ConsoleReporter(settings), settings).compiler
  }

  override def isDebug = false // so we don't get the newSettings warning
}