mirror of
https://github.com/cincheo/jsweet.git
synced 2025-12-14 23:09:22 +00:00
add a switch parameter to the @Decorator annotation so that the decorator function can be made optional by the developer
This commit is contained in:
parent
49f67a25e3
commit
8e276782e8
@ -4,7 +4,7 @@
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>org.jsweet</groupId>
|
||||
<artifactId>jsweet-core</artifactId>
|
||||
<version>6.0.5</version>
|
||||
<version>6.0.6</version>
|
||||
<name>JSweet Core Lib</name>
|
||||
<description>JavaScript API for JSweet</description>
|
||||
<url>http://www.jsweet.org</url>
|
||||
|
||||
@ -58,4 +58,12 @@ import java.lang.annotation.Target;
|
||||
@Target({ ElementType.ANNOTATION_TYPE })
|
||||
@Documented
|
||||
public @interface Decorator {
|
||||
/**
|
||||
* Tells if the corresponding decorator function is expected to be found in the
|
||||
* transpiled source code. If the decorator function is declared externally, set
|
||||
* this parameter to false.
|
||||
*
|
||||
* @return true by default
|
||||
*/
|
||||
boolean value() default true;
|
||||
}
|
||||
|
||||
@ -260,7 +260,7 @@
|
||||
<dependency>
|
||||
<groupId>org.jsweet</groupId>
|
||||
<artifactId>jsweet-core</artifactId>
|
||||
<version>6.0.5</version>
|
||||
<version>6.0.6</version>
|
||||
<scope>test</scope>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
|
||||
@ -205,7 +205,7 @@ public class JSweetContext extends Context {
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a decorator annotation in the context.
|
||||
* Looks up a decorator annotation in the context.
|
||||
*/
|
||||
public JCClassDecl lookupDecoratorAnnotation(String fullyQualifiedName) {
|
||||
return decoratorAnnotations.get(fullyQualifiedName);
|
||||
|
||||
@ -1446,20 +1446,27 @@ public class Java2TypeScriptTranslator extends AbstractTreePrinter {
|
||||
}
|
||||
} else {
|
||||
if (context.lookupDecoratorAnnotation(classdecl.sym.getQualifiedName().toString()) != null) {
|
||||
JCTree[] globalDecoratorFunction = context
|
||||
.lookupGlobalMethod(classdecl.sym.getQualifiedName().toString());
|
||||
if (globalDecoratorFunction == null) {
|
||||
report(classdecl, JSweetProblem.CANNOT_FIND_GLOBAL_DECORATOR_FUNCTION,
|
||||
classdecl.sym.getQualifiedName());
|
||||
} else {
|
||||
getScope().decoratorScope = true;
|
||||
enter(globalDecoratorFunction[0]);
|
||||
print(globalDecoratorFunction[1]);
|
||||
exit();
|
||||
getScope().decoratorScope = false;
|
||||
}
|
||||
exitScope();
|
||||
return;
|
||||
boolean requiresDecoratorFunction = context.getAnnotationValue(classdecl.sym,
|
||||
JSweetConfig.ANNOTATION_DECORATOR, Boolean.class, true);
|
||||
boolean errorReported = false;
|
||||
if (requiresDecoratorFunction) {
|
||||
JCTree[] globalDecoratorFunction = context
|
||||
.lookupGlobalMethod(classdecl.sym.getQualifiedName().toString());
|
||||
if (globalDecoratorFunction == null) {
|
||||
report(classdecl, JSweetProblem.CANNOT_FIND_GLOBAL_DECORATOR_FUNCTION,
|
||||
classdecl.sym.getQualifiedName());
|
||||
errorReported = true;
|
||||
}
|
||||
if (!errorReported) {
|
||||
getScope().decoratorScope = true;
|
||||
enter(globalDecoratorFunction[0]);
|
||||
print(globalDecoratorFunction[1]);
|
||||
exit();
|
||||
getScope().decoratorScope = false;
|
||||
}
|
||||
exitScope();
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user