annotated imports

Download Annotated imports

If you can't read please download the document

Upload: ruslan-shevchenko

Post on 16-Apr-2017

330 views

Category:

Technology


0 download

TRANSCRIPT

Annotated import

SIP - ???

http://bit.ly/TLZYKb

https://github.com/rssh/scala-annotated-import-example

Annotated import

Problem:Imports not composable

Set of implicit variables often configured through import.

SolutionAllow annotations before import statement

@exported import x._ => export x and all exported imports inside one.

Problem Example:

File Aimport com.mongodb.casbah.Imports._

import com.novus.salat._

import com.mycompany.salatcontext._

..............

File B import com.mongodb.casbah.Imports._

import com.novus.salat._

import com.novus.salat.global._

.................

Problem Example:

File Aimport com.mongodb.casbah.Imports._

import com.novus.salat._

import com.mycompany.salatcontext._

..............

File B import com.mongodb.casbah.Imports._

import com.novus.salat._

import com.novus.salat.global._

.................

Proposed Solution

Allow annotations before import

@exported import X._Members of X

@exported imports from X:

Proposed solution

package com.mycompany package object mongo {@exported import com.mongodb.casbah.Imports.@exported import com.novus.salat._@exported import com.mycompany.salatcontext._

}

File A: import com.mycompany.mongo._

File B:import com.mycompany.mongo._

Application module config:

package object my.app{@exported import all.required.libraries

@exported import language._

// disable some annotations

class unchecked extends Annotation {}

}

Common usage patterns:

Application writers: encapsulate all external dependencies in one package object

Library writers:Don't use, provide one module which application writers will use.

Import via inheritance:

X should exported imports in X be visible in Y trait X{ @exported import something.Interesting}

trait Y { .. use something.Interesting }

Import via inheritance

PROPeople actually emulate this approach by defining aliases for imported methods in traits.

CONTRAComplexity, ... impossible to disable simple.(provide own imports instead exported will work)

Implementation

CompilerCore, Scaladoc, Tests,

(new SIP-18 style implicit ?)

ReflectionClassfile format

Symbols/Tree API

Implementation

https://github.com/rssh/scalaBranch annotated-import

https://github.com/rssh/scala-annotated-import-example(scala-annotated-import-example)

StateCore : mostly done

Scaladoc: in progress

What needed:

Pre-SIP reviewhttp://bit.ly/TLZYKb

Examples of usage(just fork scala-import-annotations-example)

Welcome to hack.

Related things

@deprecated import ....(add warning, should not be hard)

@generated(generator) importMacros API ?

Thanks

Ruslan Shevchenko

https://github.com/rssh/

[email protected]

@rssh1