summaryrefslogtreecommitdiffstats
path: root/container-di/src/main/scala/com/yahoo/container/di/package.scala
blob: ec621af3830d424ec1c594f288ee0b75a2a89e4d (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
// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.container

import com.yahoo.config.ConfigInstance
import com.yahoo.vespa.config.ConfigKey
import java.lang.reflect.Type
import com.google.inject.Key

/**
 *
 * @author gjoranv
 * @author tonytv
 */
package object di {
  type ConfigKeyT = ConfigKey[_ <: ConfigInstance]
  type GuiceInjector = com.google.inject.Injector
  type JavaAnnotation = java.lang.annotation.Annotation

  def createKey(instanceType: Type, annotation: JavaAnnotation) = {
    {if (annotation == null)
      Key.get(instanceType)
    else
      Key.get(instanceType, annotation)
    }.asInstanceOf[Key[AnyRef]]
  }

  implicit def makeClassCovariant[SUB, SUPER >: SUB](clazz: Class[SUB]) : Class[SUPER] = {
    clazz.asInstanceOf[Class[SUPER]]
  }

  def removeStackTrace(exception: Throwable): Throwable = {
    if (preserveStackTrace) exception
    else {
      exception.setStackTrace(Array())
      exception
    }
  }

  //For debug purposes only
  val preserveStackTrace: Boolean = Option(System.getProperty("jdisc.container.preserveStackTrace")).filterNot(_.isEmpty).isDefined
}