Skip to content

Commit a0bd981

Browse files
authored
Merge pull request #79 from armanbilge/feature/static3
Add `@static3`
2 parents 6f79b35 + 600c84a commit a0bd981

File tree

7 files changed

+106
-0
lines changed

7 files changed

+106
-0
lines changed

annotation/src/main/scala-2.12/org/typelevel/scalaccompat/annotation/package.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ package object annotation {
2727
type nowarn213 = nowarnIgnored
2828
type nowarn3 = nowarnIgnored
2929

30+
type static3 = staticIgnored
31+
3032
type targetName3 = targetNameIgnored
3133

3234
type threadUnsafe3 = threadUnsafeIgnored

annotation/src/main/scala-2.13/org/typelevel/scalaccompat/annotation/package.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ package object annotation {
2727
type nowarn213 = nowarn
2828
type nowarn3 = nowarnIgnored
2929

30+
type static3 = staticIgnored
31+
3032
type targetName3 = targetNameIgnored
3133

3234
type threadUnsafe3 = threadUnsafeIgnored

annotation/src/main/scala-3/org/typelevel/scalaccompat/annotation/package.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ package object annotation {
2727
type nowarn213 = nowarnIgnored
2828
type nowarn3 = nowarn
2929

30+
type static3 = scala.annotation.static
31+
3032
type targetName3 = scala.annotation.targetName
3133

3234
type threadUnsafe3 = scala.annotation.threadUnsafe
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/*
2+
* Copyright 2022 Typelevel
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.typelevel.scalaccompat.annotation
18+
package internal
19+
20+
private[annotation] class staticIgnored extends scala.annotation.Annotation
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/*
2+
* Copyright 2022 Typelevel
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.typelevel.scalaccompat.annotation
18+
19+
object CustomStaticHelper {
20+
final val isScala3 = false
21+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/*
2+
* Copyright 2022 Typelevel
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.typelevel.scalaccompat.annotation
18+
19+
object CustomStaticHelper {
20+
final val isScala3 = true
21+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
* Copyright 2022 Typelevel
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.typelevel.scalaccompat.annotation
18+
19+
import munit.FunSuite
20+
21+
class CustomStaticDemo
22+
object CustomStaticDemo {
23+
@static3 val foo = new Object
24+
}
25+
26+
class CustomStaticSuite extends FunSuite {
27+
28+
test("static3 respected on Scala 3 only") {
29+
val fields = classOf[CustomStaticDemo].getFields().map(_.getName).toList
30+
31+
if (CustomStaticHelper.isScala3) {
32+
assertEquals(fields, List("foo"))
33+
} else { // Scala 2
34+
assertEquals(fields, Nil)
35+
}
36+
}
37+
38+
}

0 commit comments

Comments
 (0)