Skip to content

Commit

Permalink
BuiltinApplet: Add warnings for casting (processing-r#162)
Browse files Browse the repository at this point in the history
Signed-off-by: Ce Gao <[email protected]>
  • Loading branch information
gaocegege authored Jul 14, 2017
1 parent e43af9b commit c3b98be
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion src/rprocessing/applet/BuiltinApplet.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
*/
public class BuiltinApplet extends PApplet implements PConstants {

private static final boolean VERBOSE = Boolean.parseBoolean(System
.getenv("VERBOSE_RLANG_MODE"));

/*
* TODO: Check for the cast.
*/
Expand All @@ -27,38 +30,53 @@ public RenjinScriptEngine getRenjinEngine() {
return renjinEngine;
}

private static void log(String msg) {
if (!VERBOSE) {
return;
}
System.err.println(BuiltinApplet.class.getSimpleName() + ": " + msg);
}

public BuiltinApplet() {
AetherPackageLoader packageLoader = new AetherPackageLoader();
Session session =
new SessionBuilder().withDefaultPackages().setPackageLoader(packageLoader).build();
new SessionBuilder().withDefaultPackages().setPackageLoader(packageLoader)
.build();
this.renjinEngine = new RenjinScriptEngineFactory().getScriptEngine(session);
}

public void size(double width, double height) {
this.logWarningsforCast();
super.size((int) width, (int) height);
}

public void size(double width, double height, StringVector renderer) {
this.logWarningsforCast();
super.size((int) width, (int) height, renderer.asString());
}

public void bezierDetail(double detail) {
this.logWarningsforCast();
super.bezierDetail((int) detail);
}

public void colorMode(double mode) {
this.logWarningsforCast();
super.colorMode((int) mode);
}

public void colorMode(double mode, float max) {
this.logWarningsforCast();
super.colorMode((int) mode, max);
}

public void colorMode(double mode, float max1, float max2, float max3) {
this.logWarningsforCast();
super.colorMode((int) mode, max1, max2, max3);
}

public void colorMode(double mode, float max1, float max2, float max3, float maxA) {
this.logWarningsforCast();
super.colorMode((int) mode, max1, max2, max3, maxA);
}

Expand Down Expand Up @@ -157,4 +175,8 @@ protected void wrapKeyVariables() {
}
this.renjinEngine.put("keyCode", keyCode);
}

private void logWarningsforCast() {
log("WARNING: The function call casts double to int.");
}
}

0 comments on commit c3b98be

Please sign in to comment.