List of usage examples for com.google.gwt.user.rebind SourceWriter println
void println(String s);
From source file:com.vaadin.server.widgetsetutils.AcceptCriteriaFactoryGenerator.java
License:Apache License
private void generateInstantiatorMethod(SourceWriter sourceWriter, GeneratorContext context, TreeLogger logger) {/*w w w . j a v a2s . co m*/ sourceWriter.println("public VAcceptCriterion get(String name) {"); sourceWriter.indent(); sourceWriter.println("name = name.intern();"); JClassType criteriaType = context.getTypeOracle().findType(VAcceptCriterion.class.getName()); JClassType[] subtypes = criteriaType.getSubtypes(); Arrays.sort(subtypes, ConnectorBundle.jClassComparator); for (JClassType clientClass : subtypes) { AcceptCriterion annotation = clientClass.getAnnotation(AcceptCriterion.class); if (annotation != null) { String clientClassName = clientClass.getQualifiedSourceName(); Class<?> serverClass = clientClass.getAnnotation(AcceptCriterion.class).value(); String serverClassName = serverClass.getCanonicalName(); logger.log(Type.INFO, "creating mapping for " + serverClassName); sourceWriter.print("if (\""); sourceWriter.print(serverClassName); sourceWriter.print("\" == name) return GWT.create("); sourceWriter.print(clientClassName); sourceWriter.println(".class );"); sourceWriter.print("else "); } } sourceWriter.println("return null;"); sourceWriter.outdent(); sourceWriter.println("}"); }
From source file:com.vaadin.server.widgetsetutils.ConnectorBundleLoaderFactory.java
License:Apache License
private void generateClass(TreeLogger logger, GeneratorContext context, String packageName, String className, String requestedType) throws Exception { PrintWriter printWriter = context.tryCreate(logger, packageName, className); if (printWriter == null) { return;/*ww w . j a v a 2s . c o m*/ } List<CValUiInfo> cvalInfos = null; try { if (cvalChecker != null) { cvalInfos = cvalChecker.run(); // Don't run twice cvalChecker = null; } } catch (InvalidCvalException e) { System.err.println("\n\n\n\n" + CvalChecker.LINE); for (String line : e.getMessage().split("\n")) { System.err.println(line); } System.err.println(CvalChecker.LINE + "\n\n\n\n"); System.exit(1); throw new UnableToCompleteException(); } List<ConnectorBundle> bundles = buildBundles(logger, context.getTypeOracle()); ClassSourceFileComposerFactory composer = new ClassSourceFileComposerFactory(packageName, className); composer.setSuperclass(requestedType); SourceWriter w = composer.createSourceWriter(context, printWriter); w.println("public void init() {"); w.indent(); for (ConnectorBundle bundle : bundles) { detectBadProperties(bundle, logger); String name = bundle.getName(); boolean isEager = name.equals(ConnectorBundleLoader.EAGER_BUNDLE_NAME); w.print("addAsyncBlockLoader(new AsyncBundleLoader(\""); w.print(escape(name)); w.print("\", "); w.print("new String[] {"); for (Entry<JClassType, Set<String>> entry : bundle.getIdentifiers().entrySet()) { Set<String> identifiers = entry.getValue(); for (String id : identifiers) { w.print("\""); w.print(escape(id)); w.print("\","); } } w.println("}) {"); w.indent(); w.print("protected void load(final "); w.print(TypeDataStore.class.getName()); w.println(" store) {"); w.indent(); if (!isEager) { w.print(GWT.class.getName()); w.print(".runAsync("); } w.println("new %s() {", RunAsyncCallback.class.getName()); w.indent(); w.println("public void onSuccess() {"); w.indent(); w.println("load();"); w.println("%s.get().setLoaded(getName());", ConnectorBundleLoader.class.getName()); // Close onSuccess method w.outdent(); w.println("}"); w.println("private void load() {"); w.indent(); String loadNativeJsBundle = "loadJsBundle"; printBundleData(logger, w, bundle, loadNativeJsBundle); // Close load method w.outdent(); w.println("}"); // Separate method for loading native JS stuff (e.g. callbacks) String loadNativeJsMethodName = "loadNativeJs"; // To support fields of type long (#13692) w.println("@com.google.gwt.core.client.UnsafeNativeLong"); w.println("private native void %s(%s store) /*-{", loadNativeJsMethodName, TypeDataStore.class.getName()); w.indent(); List<String> jsMethodNames = printJsBundleData(logger, w, bundle, loadNativeJsMethodName); w.outdent(); w.println("}-*/;"); // Call all generated native method inside one Java method to avoid // refercences inside native methods to each other w.println("private void %s(%s store) {", loadNativeJsBundle, TypeDataStore.class.getName()); w.indent(); printLoadJsBundleData(w, loadNativeJsBundle, jsMethodNames); w.outdent(); w.println("}"); // onFailure method declaration starts w.println("public void onFailure(Throwable reason) {"); w.indent(); w.println("%s.get().setLoadFailure(getName(), reason);", ConnectorBundleLoader.class.getName()); w.outdent(); w.println("}"); // Close new RunAsyncCallback() {} w.outdent(); w.print("}"); if (isEager) { w.println(".onSuccess();"); } else { w.println(");"); } // Close load method w.outdent(); w.println("}"); // Close add(new ... w.outdent(); w.println("});"); } if (cvalInfos != null && !cvalInfos.isEmpty()) { w.println("{"); for (CValUiInfo c : cvalInfos) { if ("evaluation".equals(c.type)) { w.println("cvals.add(new CValUiInfo(\"" + c.product + "\", \"" + c.version + "\", \"" + c.widgetset + "\", null));"); } } w.println("}"); } w.outdent(); w.println("}"); w.commit(logger); }
From source file:com.vaadin.server.widgetsetutils.metadata.ArraySerializer.java
License:Apache License
@Override protected void printDeserializerBody(TreeLogger logger, SourceWriter w, String type, String jsonValue, String connection) {/*w w w . j av a 2s. c om*/ JType leafType = arrayType.getLeafType(); int rank = arrayType.getRank(); w.println(JsonArray.class.getName() + " jsonArray = (" + JsonArray.class.getName() + ")" + jsonValue + ";"); // Type value = new Type[jsonArray.size()][][]; w.print(arrayType.getQualifiedSourceName() + " value = new " + leafType.getQualifiedSourceName() + "[jsonArray.length()]"); for (int i = 1; i < rank; i++) { w.print("[]"); } w.println(";"); w.println("for(int i = 0 ; i < value.length; i++) {"); w.indent(); JType componentType = arrayType.getComponentType(); w.print("value[i] = (" + ConnectorBundleLoaderFactory.getBoxedTypeName(componentType) + ") " + JsonDecoder.class.getName() + ".decodeValue("); ConnectorBundleLoaderFactory.writeTypeCreator(w, componentType); w.print(", jsonArray.get(i), null, " + connection + ")"); w.println(";"); w.outdent(); w.println("}"); w.println("return value;"); }
From source file:com.vaadin.server.widgetsetutils.metadata.ArraySerializer.java
License:Apache License
@Override protected void printSerializerBody(TreeLogger logger, SourceWriter w, String value, String applicationConnection) { JType componentType = arrayType.getComponentType(); w.println(JsonArray.class.getName() + " values = " + Json.class.getName() + ".createArray();"); // JPrimitiveType primitive = componentType.isPrimitive(); w.println("for (int i = 0; i < " + value + ".length; i++) {"); w.indent();/*from ww w . j av a 2s . c o m*/ w.print("values.set(i, "); w.print(JsonEncoder.class.getName() + ".encode(" + value + "[i],"); ConnectorBundleLoaderFactory.writeTypeCreator(w, componentType); w.print(", " + applicationConnection + ")"); w.println(");"); w.outdent(); w.println("}"); w.println("return values;"); }
From source file:com.vaadin.server.widgetsetutils.metadata.CustomSerializer.java
License:Apache License
@Override public void writeSerializerInstantiator(TreeLogger logger, SourceWriter w) throws UnableToCompleteException { w.print("return "); w.print(GWT.class.getCanonicalName()); w.print(".create("); ConnectorBundleLoaderFactory.writeClassLiteral(w, serializerType); w.println(");"); }
From source file:com.vaadin.server.widgetsetutils.metadata.EnumSerializer.java
License:Apache License
@Override protected void printDeserializerBody(TreeLogger logger, SourceWriter w, String type, String jsonValue, String connection) {/*from w w w. ja v a 2 s . co m*/ w.println("String enumIdentifier = " + jsonValue + ".asString();"); for (JEnumConstant e : enumType.getEnumConstants()) { w.println("if (\"" + e.getName() + "\".equals(enumIdentifier)) {"); w.indent(); w.println("return " + enumType.getQualifiedSourceName() + "." + e.getName() + ";"); w.outdent(); w.println("}"); } w.println("return null;"); }
From source file:com.vaadin.server.widgetsetutils.metadata.EnumSerializer.java
License:Apache License
@Override protected void printSerializerBody(TreeLogger logger, SourceWriter w, String value, String applicationConnection) { // return Json.create(castedValue.name()); w.println("return " + Json.class.getName() + ".create(" + value + ".name());"); }
From source file:com.vaadin.server.widgetsetutils.metadata.FieldProperty.java
License:Apache License
@Override public void writeGetterBody(TreeLogger logger, SourceWriter w, String beanVariable) { String value = String.format("%s.@%s::%s", beanVariable, getBeanType().getQualifiedSourceName(), getName()); w.print("return "); w.print(boxValue(value));/*from ww w . j a va 2s . c o m*/ w.println(";"); }
From source file:com.vaadin.server.widgetsetutils.metadata.JsonSerializer.java
License:Apache License
@Override public void writeSerializerInstantiator(TreeLogger logger, SourceWriter w) throws UnableToCompleteException { w.print("return new "); w.print(JSONSerializer.class.getCanonicalName()); w.print("<"); w.print(type.getQualifiedSourceName()); w.println(">() {"); w.indent();//from w ww. j av a 2 s . co m writeSerializerBody(logger, w); w.outdent(); w.println("};"); }
From source file:com.vaadin.server.widgetsetutils.metadata.JsonSerializer.java
License:Apache License
protected void writeSerializerBody(TreeLogger logger, SourceWriter w) { String qualifiedSourceName = type.getQualifiedSourceName(); w.println("public " + JsonValue.class.getName() + " serialize(" + qualifiedSourceName + " value, " + ApplicationConnection.class.getName() + " connection) {"); w.indent();//from ww w. j a v a 2s.c o m // MouseEventDetails castedValue = (MouseEventDetails) value; w.println(qualifiedSourceName + " castedValue = (" + qualifiedSourceName + ") value;"); printSerializerBody(logger, w, "castedValue", "connection"); // End of serializer method w.outdent(); w.println("}"); // Deserializer // T deserialize(Type type, JSONValue jsonValue, ApplicationConnection // connection); w.println("public " + qualifiedSourceName + " deserialize(Type type, " + JsonValue.class.getName() + " jsonValue, " + ApplicationConnection.class.getName() + " connection) {"); w.indent(); printDeserializerBody(logger, w, "type", "jsonValue", "connection"); w.outdent(); w.println("}"); }