-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Get extensions reflection separate sources
- Loading branch information
1 parent
d86860a
commit e9e1ee0
Showing
3 changed files
with
73 additions
and
13 deletions.
There are no files selected for viewing
35 changes: 35 additions & 0 deletions
35
modules/compiler-core/src-2/internals/ExtensionsPlatform.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* Copyright 2022 Disney Streaming | ||
* | ||
* Licensed under the Tomorrow Open Source Technology License, Version 1.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://disneystreaming.github.io/TOST-1.0.txt | ||
* | ||
* 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 smithytranslate.compiler | ||
package internals | ||
|
||
import scala.language.reflectiveCalls | ||
import scala.jdk.CollectionConverters._ | ||
|
||
trait ExtensionsPlatform { | ||
// Using reflective calls because openapi does not seem to have a common interface | ||
// that exposes the presence of extensions. | ||
type HasExtensions = { def getExtensions(): java.util.Map[String, Any] } | ||
object HasExtensions { | ||
def unsafeFrom(s: Any): HasExtensions = s.asInstanceOf[HasExtensions] | ||
} | ||
|
||
def getExtensions(s: HasExtensions) = | ||
Option(s) | ||
.flatMap(s => Option(s.getExtensions())) | ||
.map(_.asScala) | ||
.filterNot(_.isEmpty) | ||
} |
36 changes: 36 additions & 0 deletions
36
modules/compiler-core/src-3/internals/ExtensionsPlatform.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* Copyright 2022 Disney Streaming | ||
* | ||
* Licensed under the Tomorrow Open Source Technology License, Version 1.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://disneystreaming.github.io/TOST-1.0.txt | ||
* | ||
* 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 smithytranslate.compiler | ||
package internals | ||
|
||
import scala.language.reflectiveCalls | ||
import scala.jdk.CollectionConverters._ | ||
import reflect.Selectable.reflectiveSelectable | ||
|
||
trait ExtensionsPlatform { | ||
// Using reflective calls because openapi does not seem to have a common interface | ||
// that exposes the presence of extensions. | ||
type HasExtensions = { def getExtensions(): java.util.Map[String, Any] } | ||
object HasExtensions { | ||
def unsafeFrom(s: Any): HasExtensions = s.asInstanceOf[HasExtensions] | ||
} | ||
|
||
def getExtensions(s: HasExtensions) = | ||
Option(s) | ||
.flatMap(s => Option(s.getExtensions())) | ||
.map(_.asScala) | ||
.filterNot(_.isEmpty) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters