allow @Replace for constructors (fix #339)

This commit is contained in:
Renaud Pawlak 2017-08-17 09:52:11 +02:00
parent e017ac98be
commit 5c6562d93f
7 changed files with 26 additions and 14 deletions

View File

@ -5,7 +5,7 @@
<artifactId>jsweet-core</artifactId>
<name>JSweet Core Lib</name>
<description>JavaScript API for JSweet</description>
<version>5-20170726</version>
<version>5-SNAPSHOT</version>
<build>
<plugins>
<plugin>

View File

@ -23,8 +23,8 @@ import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* This annotation allows the programmer to substitute a method body
* implementation by a TypeScript implementation.
* This annotation allows the programmer to substitute a method or constructor
* body implementation by a TypeScript implementation.
*
* <p>
* The annotation's value contains TypeScript which is generated as is by the
@ -50,14 +50,14 @@ import java.lang.annotation.Target;
* @author Renaud Pawlak
*/
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
@Target({ ElementType.METHOD, ElementType.CONSTRUCTOR })
@Documented
public @interface Replace {
/**
* The code that will be generated by the transpiler in place of the
* annotated method body.
*/
java.lang.String value();
/**
* The code that will be generated by the transpiler in place of the
* annotated method body.
*/
java.lang.String value();
}

View File

@ -5,7 +5,7 @@
<artifactId>jsweet-core</artifactId>
<name>JSweet Core Lib</name>
<description>JavaScript API for JSweet</description>
<version>6-20170726</version>
<version>6-SNAPSHOT</version>
<properties>
<jsweet.transpiler.version>2.0.0</jsweet.transpiler.version>
</properties>

View File

@ -23,8 +23,8 @@ import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* This annotation allows the programmer to substitute a method body
* implementation by a TypeScript implementation.
* This annotation allows the programmer to substitute a method or constructor
* body implementation by a TypeScript implementation.
*
* <p>
* The annotation's value contains TypeScript which is generated as is by the
@ -50,7 +50,7 @@ import java.lang.annotation.Target;
* @author Renaud Pawlak
*/
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
@Target({ ElementType.METHOD, ElementType.CONSTRUCTOR })
@Documented
public @interface Replace {

View File

@ -217,7 +217,7 @@
<dependency>
<groupId>org.jsweet</groupId>
<artifactId>jsweet-core</artifactId>
<version>5-20170726</version>
<version>5-SNAPSHOT</version>
<scope>test</scope>
<optional>true</optional>
</dependency>

View File

@ -362,6 +362,7 @@ public class StructuralTests extends AbstractTest {
assertEquals(3, (int) r.get("test2"));
assertEquals(1, (int) r.get("test3"));
assertEquals(3, (int) r.get("test4"));
assertEquals(3, (int) r.get("test5"));
}, getSourceFile(ReplaceAnnotation.class));
createTranspiler(new JSweetFactory());
}

View File

@ -11,10 +11,16 @@ public class ReplaceAnnotation {
$export("test2", new ReplaceAnnotation().m2());
$export("test3", new ReplaceAnnotation().m3());
$export("test4", new ReplaceAnnotation().m4());
$export("test5", new ReplaceAnnotation().m5());
}
int i = 1;
int j = 2;
@Replace("this.j = 3;")
public ReplaceAnnotation() {
}
@Replace("return this.i + 1;")
public int m1() {
return i;
@ -32,4 +38,9 @@ public class ReplaceAnnotation {
return i;
}
public int m5() {
return j;
}
}