List of usage examples for com.google.gwt.user.rebind StringSourceWriter outdent
public void outdent()
From source file:com.bramosystems.oss.player.core.rebind.PlatformPropertyGenerator.java
License:Apache License
@Override public String generate(TreeLogger logger, SortedSet<String> possibleValues, String fallback, SortedSet<ConfigurationProperty> configProperties) throws UnableToCompleteException { StringSourceWriter sw = new StringSourceWriter(); sw.println("{"); sw.indent();//from w w w. ja v a 2s. c o m sw.println("var pltf = navigator.platform.toLowerCase();"); Iterator<String> it = possibleValues.iterator(); if (it.hasNext()) { fillCode(sw, it.next()); sw.print("else "); while (it.hasNext()) { fillCode(sw, it.next()); sw.print("else "); } sw.println("{"); sw.indent(); sw.print("return 'other';"); sw.outdent(); sw.print("}"); } sw.outdent(); sw.println("}"); return sw.toString(); }
From source file:com.bramosystems.oss.player.core.rebind.PlatformPropertyGenerator.java
License:Apache License
private void fillCode(StringSourceWriter sw, String val) { sw.print("if(pltf.indexOf('"); sw.print(val); sw.println("')!=-1){"); sw.indent();//from w w w . j a va 2 s. co m sw.print("return '"); sw.print(val); sw.println("';"); sw.outdent(); sw.print("} "); }
From source file:com.googlecode.mgwt.useragent.rebind.UserAgentPropertyGenerator.java
License:Apache License
@Override public String generate(TreeLogger logger, SortedSet<String> possibleValues, String fallback, SortedSet<ConfigurationProperty> configProperties) { assertUserAgents(logger, possibleValues); StringSourceWriter body = new StringSourceWriter(); body.println("{"); body.indent();// w w w .j av a2 s . com writeUserAgentPropertyJavaScript(body, possibleValues, fallback); body.outdent(); body.println("}"); return body.toString(); }
From source file:com.guit.rebind.binder.contributor.KeyCodeContributor.java
License:Apache License
@Override public void contribute(BinderContext binderContext, TreeLogger logger, GeneratorContext context) throws UnableToCompleteException { JClassType eventType = binderContext.getEventType(); String eventName = eventType.getQualifiedSourceName(); if (!eventName.equals(KeyPressEvent.class.getCanonicalName()) && !eventName.equals(KeyDownEvent.class.getCanonicalName()) && !eventName.equals(KeyUpEvent.class.getCanonicalName())) { logger.log(Type.ERROR,/* w w w . j a v a 2 s . co m*/ String.format("The binder annotation %s is only valid in %s, %s or %s events. Found: %s.%s", KeyCode.class.getCanonicalName(), KeyPressEvent.class.getCanonicalName(), KeyDownEvent.class.getCanonicalName(), KeyUpEvent.class.getCanonicalName(), binderContext.getPresenterType().getQualifiedSourceName(), binderContext.getMethod().getName())); throw new UnableToCompleteException(); } int[] keycodes = binderContext.getMethod().getAnnotation(KeyCode.class).value(); StringBuilder condition = new StringBuilder(); for (int keyCode : keycodes) { if (condition.length() > 0) { condition.append(" && "); } condition.append("_____keyCode != " + keyCode); } StringSourceWriter writer = new StringSourceWriter(); writer.println("int _____keyCode = event.getNativeEvent().getKeyCode();"); writer.println("if (" + condition.toString() + ") {"); writer.indent(); writer.println("return;"); writer.outdent(); writer.println("}"); binderContext.addBeforeWrappers(writer); }
From source file:com.guit.rebind.binder.contributor.MouseButtonContributor.java
License:Apache License
@Override public void contribute(BinderContext binderContext, TreeLogger logger, GeneratorContext context) throws UnableToCompleteException { JClassType eventType = binderContext.getEventType(); String eventName = eventType.getQualifiedSourceName(); if (!eventName.equals(MouseDownEvent.class.getCanonicalName()) && !eventName.equals(MouseUpEvent.class.getCanonicalName())) { logger.log(Type.ERROR,//ww w.j av a2s. c om String.format("The binder annotation %s is only valid in %s or %s events. Found: %s.%s", MouseButton.class.getCanonicalName(), MouseDownEvent.class.getCanonicalName(), MouseUpEvent.class.getCanonicalName(), binderContext.getPresenterType().getQualifiedSourceName(), binderContext.getMethod().getName())); throw new UnableToCompleteException(); } MouseButtons[] keycodes = binderContext.getMethod().getAnnotation(MouseButton.class).value(); StringBuilder condition = new StringBuilder(); for (MouseButtons button : keycodes) { if (condition.length() > 0) { condition.append(" && "); } // LEFT by default int buttonNumber = 1; switch (button) { case MIDDLE: buttonNumber = 4; break; case RIGHT: buttonNumber = 2; break; default: break; } condition.append("_____mouseButton != " + buttonNumber); } StringSourceWriter writer = new StringSourceWriter(); writer.println("int _____mouseButton = event.getNativeEvent().getButton();"); writer.println("if (" + condition.toString() + ") {"); writer.indent(); writer.println("return;"); writer.outdent(); writer.println("}"); binderContext.addBeforeWrappers(writer); }
From source file:com.guit.rebind.binder.contributor.RunAsyncContributor.java
License:Apache License
@Override public void contribute(BinderContext binderContext, TreeLogger logger, GeneratorContext context) throws UnableToCompleteException { StringSourceWriter before = new StringSourceWriter(); before.println("GWT.runAsync(new " + AbstractRunAsyncCallback.class.getCanonicalName() + "() {"); before.indent();/*from ww w . j a v a 2 s.c o m*/ before.println("@Override"); before.println("public void success() {"); before.indent(); StringSourceWriter after = new StringSourceWriter(); after.outdent(); after.println("}"); after.outdent(); after.println("});"); binderContext.addWrapper(before, after); }
From source file:com.surevine.chat.view.linker.IE6ImagePropertyProviderGenerator.java
License:Open Source License
@Override public String generate(TreeLogger logger, SortedSet<String> possibleValues, String fallback, SortedSet<ConfigurationProperty> configProperties) throws UnableToCompleteException { StringSourceWriter body = new StringSourceWriter(); body.println("{"); body.indent();/*from www. j a v a 2 s . c o m*/ body.println("try {"); body.indent(); body.println("if(disableIE6PNGFix) { return 'false' };"); body.println(); body.println("var ua = navigator.userAgent.toLowerCase();"); body.println(); body.println("if(disableIE6PNGFixUAs && disableIE6PNGFixUAs.length) {"); body.indent(); body.println("for (var i = 0; i < disableIE6PNGFixUAs.length; ++i) {"); body.indent(); body.println("if(ua.indexOf(disableIE6PNGFixUAs[i]) != -1) { return 'false'; }"); body.outdent(); body.println("}"); body.outdent(); body.println("}"); body.outdent(); body.println("} catch(e) { } // Ignore"); body.println(); body.println("return 'true';"); body.outdent(); body.println("}"); return body.toString(); }
From source file:org.cruxframework.crux.core.rebind.crossdevice.DeviceFeaturesPropertyGenerator.java
License:Apache License
public String generate(TreeLogger logger, SortedSet<String> possibleValues, String fallback, SortedSet<ConfigurationProperty> configProperties) throws UnableToCompleteException { for (String value : possibleValues) { if (!VALID_VALUES.contains(value)) { throw new CruxGeneratorException( "Property device.features can not be assigned to value [" + value + "]."); }/* w w w.j a v a 2 s . c o m*/ } StringSourceWriter body = new StringSourceWriter(); body.println("{"); body.indent(); writeDeviceFeaturesPropertyJavaScript(body); body.outdent(); body.println("}"); return body.toString(); }
From source file:org.parallax3d.parallax.platforms.gwt.generator.SourceTextResourceGenerator.java
License:Open Source License
public String createAssignment(TreeLogger logger, ResourceContext context, JMethod method) throws UnableToCompleteException { URL[] resources = ResourceGeneratorUtil.findResources(logger, context, method); if (resources.length != 1) { logger.log(TreeLogger.ERROR, "Exactly one resource must be specified", (Throwable) null); throw new UnableToCompleteException(); } else {//from w ww . ja v a2s . c o m URL resource = resources[0]; StringSourceWriter sw = new StringSourceWriter(); sw.println("new " + SourceTextResource.class.getName() + "() {"); sw.indent(); if (!AbstractResourceGenerator.STRIP_COMMENTS) { sw.println("// " + resource.toExternalForm()); } sw.println("public String getText() {"); sw.indent(); String toWrite = Util.readURLAsString(resource); if (toWrite.length() > 16383) { this.writeLongString(sw, toWrite); } else { sw.println("return \"" + Generator.escape(toWrite) + "\";"); } sw.outdent(); sw.println("}"); sw.println("public String getName() {"); sw.indent(); sw.println("return \"" + method.getName() + "\";"); sw.outdent(); sw.println("}"); sw.outdent(); sw.println("}"); return sw.toString(); } }