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> <artifactId>jsweet-core</artifactId>
<name>JSweet Core Lib</name> <name>JSweet Core Lib</name>
<description>JavaScript API for JSweet</description> <description>JavaScript API for JSweet</description>
<version>5-20170726</version> <version>5-SNAPSHOT</version>
<build> <build>
<plugins> <plugins>
<plugin> <plugin>

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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