Skip to content

Commit

Permalink
Updated dependency versions and fixed Scala 2.13 incompatibility. (#2567
Browse files Browse the repository at this point in the history
)

* Updated dependency versions and fixed Scala 2.13 incompatibility.

* Fixes bug because of new AssertJ API

* Fixes whitespace
  • Loading branch information
danieldietrich committed Mar 13, 2020
1 parent b30ea16 commit 1063d56
Show file tree
Hide file tree
Showing 58 changed files with 27 additions and 240 deletions.
12 changes: 5 additions & 7 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ apply plugin: 'jacoco'
apply plugin: 'maven'
apply plugin: 'signing'

ext.ammoniteScalaVersion = '2.12' // Currently, generator/Generator.sc does not build with Scala 2.13
ext.ammoniteVersion = '1.6.9'
ext.assertjVersion = '3.11.1'
ext.junitVersion = '4.13-beta-3'
ext.ammoniteScalaVersion = '2.13' // Currently, generator/Generator.sc does not build with Scala 2.13
ext.ammoniteVersion = '2.0.4'
ext.assertjVersion = '3.15.0'
ext.junitVersion = '4.13'

repositories {
mavenLocal()
Expand Down Expand Up @@ -60,9 +60,7 @@ task generateSources() {
}
}

compileJava {
dependsOn 'generateSources'
}
compileJava.dependsOn 'generateSources'

tasks.withType(JavaCompile) {
sourceCompatibility = 8
Expand Down
34 changes: 16 additions & 18 deletions generator/Generator.sc
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import JavaGenerator._

import collection.immutable.ListMap
import scala.language.implicitConversions
import scala.reflect.macros.whitebox

val N = 8
val VARARGS = 10
Expand Down Expand Up @@ -1531,8 +1532,7 @@ def generateMainClasses(): Unit = {
/$javadoc
* Returns a function that always returns the constant
* value that you give in parameter.
*
${(1 to i).gen(j => s"* @param <T$j> generic parameter type $j of the resulting function")("\n")}
${(0 to i).gen(j => if (j == 0) "*" else s"* @param <T$j> generic parameter type $j of the resulting function")("\n")}
* @param <R> the result type
* @param value the value to be returned
* @return a function always returning the given value
Expand Down Expand Up @@ -2208,7 +2208,7 @@ def generateMainClasses(): Unit = {
return false;
} else {
final $className$untyped that = ($className$untyped) o;
return ${(1 to i).gen(j => s"${im.getType("java.util.Objects")}.equals(this._$j, that._$j)")("\n && ")};
return ${(1 to i).gen(j => s"${im.getType("java.util.Objects")}.equals(this._$j, that._$j)")("\n && ")};
}"""
}
}
Expand Down Expand Up @@ -3801,9 +3801,9 @@ object JavaGenerator {
def getImports: String = {

def optimizeImports(imports: Seq[String], static: Boolean): String = {
val counts = imports.map(getPackageName).groupBy(s => s).map { case (s, list) => s -> list.length }
val directImports = imports.filter(s => counts(getPackageName(s)) <= wildcardThreshold)
val wildcardImports = counts.filter { case (_, count) => count > wildcardThreshold }.keySet.toIndexedSeq.map(s => s"$s.*")
val counts: Map[String, Int] = imports.map(getPackageName).groupBy(s => s).map { case (s: String, list: Seq[String]) => s -> list.length }
val directImports: Seq[String] = imports.filter(s => counts(getPackageName(s)) <= wildcardThreshold)
val wildcardImports: Seq[String] = counts.filter { case (_, count) => count > wildcardThreshold }.keySet.toIndexedSeq.map(s => s"$s.*")
(directImports ++ wildcardImports).sorted.map(fqn => s"import ${static.gen("static ")}$fqn;").mkString("\n")
}

Expand Down Expand Up @@ -4080,24 +4080,19 @@ object Generator {
* @param args StringContext parts
* @return An aligned String
*/
def xs(args: Any*): String = align(sc.s, args)
def xs(args: Any*): String = align(sc.s(indentedArgs(args:_*):_*))

/**
* Formats raw/unescaped strings.
*
* @param args StringContext parts
* @return An aligned String
*/
def xraw(args: Any*): String = align(sc.raw, args)
def xraw(args: Any*): String = align(sc.raw(indentedArgs(args:_*):_*))

/**
* Indenting a rich string, removing first and last newline.
* A rich string consists of arguments surrounded by text parts.
*/
private def align(interpolator: Seq[Any] => String, args: collection.Seq[Any]): String = {

// indent embedded strings, invariant: parts.length = args.length + 1
val indentedArgs = for {
// indent embedded strings, invariant: parts.length = args.length + 1
private def indentedArgs(args: Any*): Seq[String] =
for {
(part, arg) <- sc.parts zip args.map(s => if (s == null) "" else s.toString)
} yield {
// get the leading space of last line of current part
Expand All @@ -4109,9 +4104,12 @@ object Generator {
}
}

private def align(interpolated: String): String = {

// remove first and last newline and split string into separate lines
// adding termination symbol \u0000 in order to preserve empty strings between last newlines when splitting
val split = (interpolator(indentedArgs).replaceAll( """(^[ \t]*\r?\n)|(\r?\n[ \t]*$)""", "") + '\u0000').split("\r?\n")
val split = (interpolated.replaceAll( """(^[ \t]*\r?\n)|(\r?\n[ \t]*$)""", "") + '\u0000')
.split("\r?\n")

// find smallest indentation
val prefix = split filter (!_.trim().isEmpty) map { s =>
Expand All @@ -4129,7 +4127,7 @@ object Generator {
} mkString lineSeparator dropRight 1 // dropping termination character \u0000

// combine multiple newlines to two
aligned.replaceAll("""[ \t]*\r?\n([ \t]*\r?\n)+""", lineSeparator * 2)
aligned.replaceAll("""([ \t]*\r?\n){2,}""", lineSeparator * 2)
}
}
}
5 changes: 0 additions & 5 deletions src-gen/main/java/io/vavr/CheckedFunction0.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ public interface CheckedFunction0<R> extends Serializable {
* Returns a function that always returns the constant
* value that you give in parameter.
*
* @param <R> the result type
* @param value the value to be returned
* @return a function always returning the given value
Expand Down Expand Up @@ -131,7 +130,6 @@ static <R> CheckedFunction0<R> narrow(CheckedFunction0<? extends R> f) {
return (CheckedFunction0<R>) f;
}


/**
* Applies this function to no arguments and returns the result.
*
Expand All @@ -140,7 +138,6 @@ static <R> CheckedFunction0<R> narrow(CheckedFunction0<? extends R> f) {
*/
R apply() throws Throwable;


/**
* Returns the number of function arguments.
* @return an int value &gt;= 0
Expand Down Expand Up @@ -215,7 +212,6 @@ default boolean isMemoized() {
return this instanceof Memoized;
}


/**
* Return a composed function that first applies this CheckedFunction0 to the given arguments and in case of throwable
* try to get value from {@code recover} function with same arguments and throwable information.
Expand Down Expand Up @@ -266,7 +262,6 @@ default <V> CheckedFunction0<V> andThen(CheckedFunction1<? super R, ? extends V>
return () -> after.apply(apply());
}


}

interface CheckedFunction0Module {
Expand Down
2 changes: 0 additions & 2 deletions src-gen/main/java/io/vavr/CheckedFunction1.java
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,6 @@ static <T> CheckedFunction1<T, T> identity() {
*/
R apply(T1 t1) throws Throwable;


/**
* Returns the number of function arguments.
* @return an int value &gt;= 0
Expand Down Expand Up @@ -229,7 +228,6 @@ default boolean isMemoized() {
return this instanceof Memoized;
}


/**
* Return a composed function that first applies this CheckedFunction1 to the given arguments and in case of throwable
* try to get value from {@code recover} function with same arguments and throwable information.
Expand Down
4 changes: 0 additions & 4 deletions src-gen/main/java/io/vavr/CheckedFunction2.java
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,6 @@ static <T1, T2, R> CheckedFunction2<T1, T2, R> narrow(CheckedFunction2<? super T
return (CheckedFunction2<T1, T2, R>) f;
}


/**
* Applies this function to two arguments and returns the result.
*
Expand All @@ -165,7 +164,6 @@ default CheckedFunction1<T2, R> apply(T1 t1) {
return (T2 t2) -> apply(t1, t2);
}


/**
* Returns the number of function arguments.
* @return an int value &gt;= 0
Expand Down Expand Up @@ -239,7 +237,6 @@ default boolean isMemoized() {
return this instanceof Memoized;
}


/**
* Return a composed function that first applies this CheckedFunction2 to the given arguments and in case of throwable
* try to get value from {@code recover} function with same arguments and throwable information.
Expand Down Expand Up @@ -290,7 +287,6 @@ default <V> CheckedFunction2<T1, T2, V> andThen(CheckedFunction1<? super R, ? ex
return (t1, t2) -> after.apply(apply(t1, t2));
}


}

interface CheckedFunction2Module {
Expand Down
4 changes: 0 additions & 4 deletions src-gen/main/java/io/vavr/CheckedFunction3.java
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,6 @@ static <T1, T2, T3, R> CheckedFunction3<T1, T2, T3, R> narrow(CheckedFunction3<?
return (CheckedFunction3<T1, T2, T3, R>) f;
}


/**
* Applies this function to three arguments and returns the result.
*
Expand Down Expand Up @@ -182,7 +181,6 @@ default CheckedFunction1<T3, R> apply(T1 t1, T2 t2) {
return (T3 t3) -> apply(t1, t2, t3);
}


/**
* Returns the number of function arguments.
* @return an int value &gt;= 0
Expand Down Expand Up @@ -256,7 +254,6 @@ default boolean isMemoized() {
return this instanceof Memoized;
}


/**
* Return a composed function that first applies this CheckedFunction3 to the given arguments and in case of throwable
* try to get value from {@code recover} function with same arguments and throwable information.
Expand Down Expand Up @@ -307,7 +304,6 @@ default <V> CheckedFunction3<T1, T2, T3, V> andThen(CheckedFunction1<? super R,
return (t1, t2, t3) -> after.apply(apply(t1, t2, t3));
}


}

interface CheckedFunction3Module {
Expand Down
4 changes: 0 additions & 4 deletions src-gen/main/java/io/vavr/CheckedFunction4.java
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,6 @@ static <T1, T2, T3, T4, R> CheckedFunction4<T1, T2, T3, T4, R> narrow(CheckedFun
return (CheckedFunction4<T1, T2, T3, T4, R>) f;
}


/**
* Applies this function to 4 arguments and returns the result.
*
Expand Down Expand Up @@ -201,7 +200,6 @@ default CheckedFunction1<T4, R> apply(T1 t1, T2 t2, T3 t3) {
return (T4 t4) -> apply(t1, t2, t3, t4);
}


/**
* Returns the number of function arguments.
* @return an int value &gt;= 0
Expand Down Expand Up @@ -275,7 +273,6 @@ default boolean isMemoized() {
return this instanceof Memoized;
}


/**
* Return a composed function that first applies this CheckedFunction4 to the given arguments and in case of throwable
* try to get value from {@code recover} function with same arguments and throwable information.
Expand Down Expand Up @@ -326,7 +323,6 @@ default <V> CheckedFunction4<T1, T2, T3, T4, V> andThen(CheckedFunction1<? super
return (t1, t2, t3, t4) -> after.apply(apply(t1, t2, t3, t4));
}


}

interface CheckedFunction4Module {
Expand Down
4 changes: 0 additions & 4 deletions src-gen/main/java/io/vavr/CheckedFunction5.java
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,6 @@ static <T1, T2, T3, T4, T5, R> CheckedFunction5<T1, T2, T3, T4, T5, R> narrow(Ch
return (CheckedFunction5<T1, T2, T3, T4, T5, R>) f;
}


/**
* Applies this function to 5 arguments and returns the result.
*
Expand Down Expand Up @@ -221,7 +220,6 @@ default CheckedFunction1<T5, R> apply(T1 t1, T2 t2, T3 t3, T4 t4) {
return (T5 t5) -> apply(t1, t2, t3, t4, t5);
}


/**
* Returns the number of function arguments.
* @return an int value &gt;= 0
Expand Down Expand Up @@ -295,7 +293,6 @@ default boolean isMemoized() {
return this instanceof Memoized;
}


/**
* Return a composed function that first applies this CheckedFunction5 to the given arguments and in case of throwable
* try to get value from {@code recover} function with same arguments and throwable information.
Expand Down Expand Up @@ -346,7 +343,6 @@ default <V> CheckedFunction5<T1, T2, T3, T4, T5, V> andThen(CheckedFunction1<? s
return (t1, t2, t3, t4, t5) -> after.apply(apply(t1, t2, t3, t4, t5));
}


}

interface CheckedFunction5Module {
Expand Down
4 changes: 0 additions & 4 deletions src-gen/main/java/io/vavr/CheckedFunction6.java
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,6 @@ static <T1, T2, T3, T4, T5, T6, R> CheckedFunction6<T1, T2, T3, T4, T5, T6, R> n
return (CheckedFunction6<T1, T2, T3, T4, T5, T6, R>) f;
}


/**
* Applies this function to 6 arguments and returns the result.
*
Expand Down Expand Up @@ -242,7 +241,6 @@ default CheckedFunction1<T6, R> apply(T1 t1, T2 t2, T3 t3, T4 t4, T5 t5) {
return (T6 t6) -> apply(t1, t2, t3, t4, t5, t6);
}


/**
* Returns the number of function arguments.
* @return an int value &gt;= 0
Expand Down Expand Up @@ -316,7 +314,6 @@ default boolean isMemoized() {
return this instanceof Memoized;
}


/**
* Return a composed function that first applies this CheckedFunction6 to the given arguments and in case of throwable
* try to get value from {@code recover} function with same arguments and throwable information.
Expand Down Expand Up @@ -367,7 +364,6 @@ default <V> CheckedFunction6<T1, T2, T3, T4, T5, T6, V> andThen(CheckedFunction1
return (t1, t2, t3, t4, t5, t6) -> after.apply(apply(t1, t2, t3, t4, t5, t6));
}


}

interface CheckedFunction6Module {
Expand Down
4 changes: 0 additions & 4 deletions src-gen/main/java/io/vavr/CheckedFunction7.java
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,6 @@ static <T1, T2, T3, T4, T5, T6, T7, R> CheckedFunction7<T1, T2, T3, T4, T5, T6,
return (CheckedFunction7<T1, T2, T3, T4, T5, T6, T7, R>) f;
}


/**
* Applies this function to 7 arguments and returns the result.
*
Expand Down Expand Up @@ -264,7 +263,6 @@ default CheckedFunction1<T7, R> apply(T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6)
return (T7 t7) -> apply(t1, t2, t3, t4, t5, t6, t7);
}


/**
* Returns the number of function arguments.
* @return an int value &gt;= 0
Expand Down Expand Up @@ -338,7 +336,6 @@ default boolean isMemoized() {
return this instanceof Memoized;
}


/**
* Return a composed function that first applies this CheckedFunction7 to the given arguments and in case of throwable
* try to get value from {@code recover} function with same arguments and throwable information.
Expand Down Expand Up @@ -389,7 +386,6 @@ default <V> CheckedFunction7<T1, T2, T3, T4, T5, T6, T7, V> andThen(CheckedFunct
return (t1, t2, t3, t4, t5, t6, t7) -> after.apply(apply(t1, t2, t3, t4, t5, t6, t7));
}


}

interface CheckedFunction7Module {
Expand Down
4 changes: 0 additions & 4 deletions src-gen/main/java/io/vavr/CheckedFunction8.java
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,6 @@ static <T1, T2, T3, T4, T5, T6, T7, T8, R> CheckedFunction8<T1, T2, T3, T4, T5,
return (CheckedFunction8<T1, T2, T3, T4, T5, T6, T7, T8, R>) f;
}


/**
* Applies this function to 8 arguments and returns the result.
*
Expand Down Expand Up @@ -287,7 +286,6 @@ default CheckedFunction1<T8, R> apply(T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6,
return (T8 t8) -> apply(t1, t2, t3, t4, t5, t6, t7, t8);
}


/**
* Returns the number of function arguments.
* @return an int value &gt;= 0
Expand Down Expand Up @@ -361,7 +359,6 @@ default boolean isMemoized() {
return this instanceof Memoized;
}


/**
* Return a composed function that first applies this CheckedFunction8 to the given arguments and in case of throwable
* try to get value from {@code recover} function with same arguments and throwable information.
Expand Down Expand Up @@ -412,7 +409,6 @@ default <V> CheckedFunction8<T1, T2, T3, T4, T5, T6, T7, T8, V> andThen(CheckedF
return (t1, t2, t3, t4, t5, t6, t7, t8) -> after.apply(apply(t1, t2, t3, t4, t5, t6, t7, t8));
}


}

interface CheckedFunction8Module {
Expand Down
Loading

0 comments on commit 1063d56

Please sign in to comment.