List of usage examples for com.google.gwt.user.rebind SourceWriter outdent
void outdent();
From source file:org.kjots.json.object.gwt.rebind.GwtJsonObjectGenerator.java
License:Apache License
/** * Write a set Java character primitive property method for the property with the given name. * * @param sourceWriter The source writer. * @param methodName The name of the method. * @param propertyName The name of the property. */// www . ja v a 2s . c o m private void writeSetJavaCharacterPrimitivePropertyMethod(SourceWriter sourceWriter, String methodName, String propertyName) { sourceWriter.println("@Override"); sourceWriter.println("public final void " + methodName + "(char " + propertyName + ") {"); sourceWriter.indent(); sourceWriter.println("this.setStringProperty(\"" + propertyName + "\", java.lang.Character.toString(" + propertyName + "));"); sourceWriter.outdent(); sourceWriter.println("}"); }
From source file:org.kjots.json.object.gwt.rebind.GwtJsonObjectGenerator.java
License:Apache License
/** * Write a get object property method for the property with the given name. * * @param sourceWriter The source writer. * @param methodName The name of the method. * @param propertyName The name of the property. * @param propertyTypeName The name of the property type. *//* w w w . j ava 2 s .co m*/ private void writeGetObjectPropertyMethod(SourceWriter sourceWriter, String methodName, String propertyName, String propertyTypeName) { sourceWriter.println("@Override"); sourceWriter.println("public final " + propertyTypeName + " " + methodName + "() {"); sourceWriter.indent(); sourceWriter.println( "return this.getObjectProperty(\"" + propertyName + "\", " + propertyTypeName + ".class);"); sourceWriter.outdent(); sourceWriter.println("}"); }
From source file:org.kjots.json.object.gwt.rebind.GwtJsonObjectGenerator.java
License:Apache License
/** * Write a set object property method for the property with the given name. * * @param sourceWriter The source writer. * @param methodName The name of the method. * @param propertyName The name of the property. * @param propertyTypeName The name of the property type. */// w ww.j a v a2s. co m private void writeSetObjectPropertyMethod(SourceWriter sourceWriter, String methodName, String propertyName, String propertyTypeName) { sourceWriter.println("@Override"); sourceWriter .println("public final void " + methodName + "(" + propertyTypeName + " " + propertyName + ") {"); sourceWriter.indent(); sourceWriter.println("this.setObjectProperty(\"" + propertyName + "\", " + propertyName + ");"); sourceWriter.outdent(); sourceWriter.println("}"); }
From source file:org.kjots.json.object.gwt.rebind.GwtJsonObjectGenerator.java
License:Apache License
/** * Write a get object composite property method for the property with the given name. * * @param sourceWriter The source writer. * @param methodName The name of the method. * @param propertyName The name of the property. * @param propertyTypeName The name of the property type. *//*from w w w . java2 s .c o m*/ private void writeGetObjectCompositePropertyMethod(SourceWriter sourceWriter, String methodName, String propertyName, String propertyTypeName, String elementTypeName) { sourceWriter.println("@Override"); sourceWriter.println("public final " + propertyTypeName + " " + methodName + "() {"); sourceWriter.indent(); sourceWriter.println(propertyTypeName + " _" + propertyName + " = this.getObjectProperty(\"" + propertyName + "\", " + propertyTypeName + ".class);"); sourceWriter.println(); sourceWriter.println("return _" + propertyName + " != null ? _" + propertyName + ".castElement(" + elementTypeName + ".class) : null;"); sourceWriter.outdent(); sourceWriter.println("}"); }
From source file:org.kjots.json.object.gwt.rebind.GwtJsonObjectGenerator.java
License:Apache License
/** * Write a get adapted property method for the property with the given name. * * @param sourceWriter The source writer. * @param logger The logger./*from w ww .ja v a 2 s .c o m*/ * @param context The context. * @param methodName The name of the method. * @param propertyName The name of the property. * @param propertyTypeName The name of the property type. * @param adapterTypeName The name of the adapter type. * @throws UnableToCompleteException */ private void writeGetAdaptedPropertyMethod(SourceWriter sourceWriter, TreeLogger logger, GeneratorContext context, String methodName, String propertyName, String propertyTypeName, String adapterTypeName) throws UnableToCompleteException { sourceWriter.println("@Override"); sourceWriter.println("public final " + propertyTypeName + " " + methodName + "() {"); sourceWriter.indent(); JClassType adapterType = this.getType(logger, context, adapterTypeName); if (adapterType.isAssignableTo(this.getType(logger, context, JsonBooleanPropertyAdapter.class.getName()))) { sourceWriter .println("boolean _" + propertyName + " = this.getBooleanProperty(\"" + propertyName + "\");"); } else if (adapterType .isAssignableTo(this.getType(logger, context, JsonNumberPropertyAdapter.class.getName()))) { sourceWriter.println(Number.class.getName() + " _" + propertyName + " = this.getNumberProperty(\"" + propertyName + "\");"); } else if (adapterType .isAssignableTo(this.getType(logger, context, JsonStringPropertyAdapter.class.getName()))) { sourceWriter.println(String.class.getName() + " _" + propertyName + " = this.getStringProperty(\"" + propertyName + "\");"); } else if (adapterType .isAssignableTo(this.getType(logger, context, JsonObjectPropertyAdapter.class.getName()))) { JParameterizedType jsonObjectPropertyType = (JParameterizedType) this .getImplementedInterface(adapterType, JsonObjectPropertyAdapter.class.getName()); JClassType jsonObjectType = jsonObjectPropertyType.getTypeArgs()[1]; sourceWriter.println( jsonObjectType.getQualifiedSourceName() + " _" + propertyName + " = this.getObjectProperty(\"" + propertyName + "\", " + jsonObjectType.getQualifiedSourceName() + ".class);"); } else { logger.log(TreeLogger.ERROR, "Unsupported adapter type " + adapterTypeName, null); throw new UnableToCompleteException(); } sourceWriter.println(); sourceWriter.println("return " + JsonObjectFactory.class.getName() + ".get().getJsonPropertyAdapter(" + adapterType.getQualifiedSourceName() + ".class).fromJsonProperty(_" + propertyName + ");"); sourceWriter.outdent(); sourceWriter.println("}"); }
From source file:org.kjots.json.object.gwt.rebind.GwtJsonObjectGenerator.java
License:Apache License
/** * Write a set adapted property method for the property with the given name. * * @param sourceWriter The source writer. * @param logger The logger.//ww w. j a v a 2 s. c o m * @param context The context. * @param methodName The name of the method. * @param propertyName The name of the property. * @param propertyTypeName The name of the property type. * @param adapterTypeName The name of the adapter type. * @throws UnableToCompleteException */ private void writeSetAdaptedPropertyMethod(SourceWriter sourceWriter, TreeLogger logger, GeneratorContext context, String methodName, String propertyName, String propertyTypeName, String adapterTypeName) throws UnableToCompleteException { sourceWriter.println("@Override"); sourceWriter .println("public final void " + methodName + "(" + propertyTypeName + " " + propertyName + ") {"); sourceWriter.indent(); JClassType adapterType = this.getType(logger, context, adapterTypeName); if (adapterType.isAssignableTo(this.getType(logger, context, JsonBooleanPropertyAdapter.class.getName()))) { sourceWriter.println("boolean _" + propertyName + " = " + JsonObjectFactory.class.getName() + ".get().getJsonPropertyAdapter(" + adapterType.getQualifiedSourceName() + ".class).toJsonProperty(" + propertyName + ");"); sourceWriter.println(); sourceWriter.println("this.setBooleanProperty(\"" + propertyName + "\", _" + propertyName + ");"); } else if (adapterType .isAssignableTo(this.getType(logger, context, JsonNumberPropertyAdapter.class.getName()))) { sourceWriter.println(Number.class.getName() + " _" + propertyName + " = " + JsonObjectFactory.class.getName() + ".get().getJsonPropertyAdapter(" + adapterType.getQualifiedSourceName() + ".class).toJsonProperty(" + propertyName + ");"); sourceWriter.println(); sourceWriter.println("this.setNumberProperty(\"" + propertyName + "\", _" + propertyName + ");"); } else if (adapterType .isAssignableTo(this.getType(logger, context, JsonStringPropertyAdapter.class.getName()))) { sourceWriter.println(String.class.getName() + " _" + propertyName + " = " + JsonObjectFactory.class.getName() + ".get().getJsonPropertyAdapter(" + adapterType.getQualifiedSourceName() + ".class).toJsonProperty(" + propertyName + ");"); sourceWriter.println(); sourceWriter.println("this.setStringProperty(\"" + propertyName + "\", _" + propertyName + ");"); } else if (adapterType .isAssignableTo(this.getType(logger, context, JsonObjectPropertyAdapter.class.getName()))) { JParameterizedType jsonObjectPropertyType = (JParameterizedType) this .getImplementedInterface(adapterType, JsonObjectPropertyAdapter.class.getName()); JClassType jsonObjectType = jsonObjectPropertyType.getTypeArgs()[1]; sourceWriter.println(jsonObjectType.getQualifiedSourceName() + " _" + propertyName + " = " + JsonObjectFactory.class.getName() + ".get().getJsonPropertyAdapter(" + adapterType.getQualifiedSourceName() + ".class).toJsonProperty(" + propertyName + ");"); sourceWriter.println(); sourceWriter.println("this.setObjectProperty(\"" + propertyName + "\", _" + propertyName + ");"); } else { logger.log(TreeLogger.ERROR, "Unsupported adapter type " + adapterTypeName, null); throw new UnableToCompleteException(); } sourceWriter.outdent(); sourceWriter.println("}"); }
From source file:org.lirazs.gbackbone.gen.reflection.ReflectAllInOneCreator.java
License:Apache License
@Override public void createSource(SourceWriter source, JClassType classType) { //ClassType -->> the interface name created automatically Map<JClassType, String> typeNameMap = new HashMap<JClassType, String>(); genAllClasses(source, typeNameMap);//from www.j a va 2s . c o m // source.println("public " + getSimpleUnitName(classType) + "(){"); // source.indent(); // // for (String classname : allGeneratedClassNames){ // source.println("new " + classname + "();"); // } // source.outdent(); // source.println("}"); source.println("public org.lirazs.gbackbone.reflection.client.Type doGetType(String name) {"); source.indent(); //source.println("org.lirazs.gbackbone.reflection.client.Type resultType = super.doGetType(name);"); //source.println("if (resultType != null) {return resultType;}"); for (JClassType type : typeNameMap.keySet()) { source.println("if (name.equals( \"" + type.getQualifiedSourceName() + "\")){return GWT.create(" + typeNameMap.get(type) + ".class);}"); } source.println(); source.println("return null;"); source.outdent(); source.print("}"); }
From source file:org.lirazs.gbackbone.generator.ReflectionGenerator.java
License:Apache License
private void printFactoryMethod(List<JClassType> clazzes, SourceWriter sourceWriter) { sourceWriter.println();/*from w ww . j a v a 2 s. co m*/ sourceWriter.println( "public <T, V extends T> T instantiateModel( Class<V> clazz, Options attributes, Options options ) {"); for (JClassType classType : clazzes) { if (classType.isAbstract()) continue; JConstructor[] constructors = classType.getConstructors(); if (constructors.length > 0) { Arrays.sort(constructors, new Comparator<JConstructor>() { @Override public int compare(JConstructor o1, JConstructor o2) { ModelConstructorType modelConstructorType1 = getModelConstructorType(o1); ModelConstructorType modelConstructorType2 = getModelConstructorType(o2); return modelConstructorType1.compareTo(modelConstructorType2); } }); for (JConstructor constructor : constructors) { ModelConstructorType modelConstructorType = getModelConstructorType(constructor); if (modelConstructorType == ModelConstructorType.ATTRIBUTES_AND_OPTIONS) { sourceWriter.println(); sourceWriter.indent(); sourceWriter.println("if (clazz.getName().endsWith(\"." + classType.getName() + "\")) {"); sourceWriter.indent(); sourceWriter.println("return (T) new " + classType.getQualifiedSourceName() + "( attributes, options );"); sourceWriter.outdent(); sourceWriter.println("}"); sourceWriter.outdent(); sourceWriter.println(); } if (modelConstructorType == ModelConstructorType.ATTRIBUTES) { sourceWriter.println(); sourceWriter.indent(); sourceWriter.println("if (clazz.getName().endsWith(\"." + classType.getName() + "\")) {"); sourceWriter.indent(); sourceWriter.println( "return (T) new " + classType.getQualifiedSourceName() + "( attributes );"); sourceWriter.outdent(); sourceWriter.println("}"); sourceWriter.outdent(); sourceWriter.println(); } if (modelConstructorType == ModelConstructorType.JSON_OBJECT_AND_OPTIONS) { sourceWriter.println(); sourceWriter.indent(); sourceWriter.println("if (clazz.getName().endsWith(\"." + classType.getName() + "\")) {"); sourceWriter.indent(); sourceWriter.println("return (T) new " + classType.getQualifiedSourceName() + "( attributes.toJsonObject(), options );"); sourceWriter.outdent(); sourceWriter.println("}"); sourceWriter.outdent(); sourceWriter.println(); } if (modelConstructorType == ModelConstructorType.JSON_OBJECT) { sourceWriter.println(); sourceWriter.indent(); sourceWriter.println("if (clazz.getName().endsWith(\"." + classType.getName() + "\")) {"); sourceWriter.indent(); sourceWriter.println("return (T) new " + classType.getQualifiedSourceName() + "( attributes.toJsonObject() );"); sourceWriter.outdent(); sourceWriter.println("}"); sourceWriter.outdent(); sourceWriter.println(); } if (modelConstructorType == ModelConstructorType.EMPTY) { sourceWriter.println(); sourceWriter.indent(); sourceWriter.println("if (clazz.getName().endsWith(\"." + classType.getName() + "\")) {"); sourceWriter.indent(); sourceWriter.println("return (T) new " + classType.getQualifiedSourceName() + "( );"); sourceWriter.outdent(); sourceWriter.println("}"); sourceWriter.outdent(); sourceWriter.println(); } } } else { sourceWriter.println(); sourceWriter.indent(); sourceWriter.println("if (clazz.getName().endsWith(\"." + classType.getName() + "\")) {"); sourceWriter.indent(); sourceWriter.println("return (T) new " + classType.getQualifiedSourceName() + "( );"); sourceWriter.outdent(); sourceWriter.println("}"); sourceWriter.outdent(); sourceWriter.println(); } } sourceWriter.indent(); sourceWriter.println("return (T) null;"); sourceWriter.outdent(); sourceWriter.println(); sourceWriter.println("}"); sourceWriter.outdent(); sourceWriter.println(); }
From source file:org.lirazs.gbackbone.generator.ReflectionGenerator.java
License:Apache License
private void printJSONFactoryMethod(List<JClassType> clazzes, SourceWriter sourceWriter) { sourceWriter.println();//from w w w. j a v a2s. c o m sourceWriter.println( "public <T, V extends T> T instantiateModel( Class<V> clazz, JSONObject attributes, Options options ) {"); for (JClassType classType : clazzes) { if (classType.isAbstract()) continue; JConstructor[] constructors = classType.getConstructors(); if (constructors.length > 0) { Arrays.sort(constructors, new Comparator<JConstructor>() { @Override public int compare(JConstructor o1, JConstructor o2) { ModelConstructorType modelConstructorType1 = getModelConstructorType(o1); ModelConstructorType modelConstructorType2 = getModelConstructorType(o2); // json object methods gain priority since a JSONObject is provided if (modelConstructorType1 == ModelConstructorType.JSON_OBJECT) return -1; if (modelConstructorType1 == ModelConstructorType.JSON_OBJECT_AND_OPTIONS) return -1; return modelConstructorType1.compareTo(modelConstructorType2); } }); for (JConstructor constructor : constructors) { ModelConstructorType modelConstructorType = getModelConstructorType(constructor); if (modelConstructorType == ModelConstructorType.JSON_OBJECT_AND_OPTIONS) { sourceWriter.println(); sourceWriter.indent(); sourceWriter.println("if (clazz.getName().endsWith(\"." + classType.getName() + "\")) {"); sourceWriter.indent(); sourceWriter.println("return (T) new " + classType.getQualifiedSourceName() + "( attributes, options );"); sourceWriter.outdent(); sourceWriter.println("}"); sourceWriter.outdent(); sourceWriter.println(); } if (modelConstructorType == ModelConstructorType.JSON_OBJECT) { sourceWriter.println(); sourceWriter.indent(); sourceWriter.println("if (clazz.getName().endsWith(\"." + classType.getName() + "\")) {"); sourceWriter.indent(); sourceWriter.println( "return (T) new " + classType.getQualifiedSourceName() + "( attributes );"); sourceWriter.outdent(); sourceWriter.println("}"); sourceWriter.outdent(); sourceWriter.println(); } if (modelConstructorType == ModelConstructorType.ATTRIBUTES_AND_OPTIONS) { sourceWriter.println(); sourceWriter.indent(); sourceWriter.println("if (clazz.getName().endsWith(\"." + classType.getName() + "\")) {"); sourceWriter.indent(); sourceWriter.println("return (T) new " + classType.getQualifiedSourceName() + "( new Options(attributes), options );"); sourceWriter.outdent(); sourceWriter.println("}"); sourceWriter.outdent(); sourceWriter.println(); } if (modelConstructorType == ModelConstructorType.ATTRIBUTES) { sourceWriter.println(); sourceWriter.indent(); sourceWriter.println("if (clazz.getName().endsWith(\"." + classType.getName() + "\")) {"); sourceWriter.indent(); sourceWriter.println("return (T) new " + classType.getQualifiedSourceName() + "( new Options(attributes) );"); sourceWriter.outdent(); sourceWriter.println("}"); sourceWriter.outdent(); sourceWriter.println(); } if (modelConstructorType == ModelConstructorType.EMPTY) { sourceWriter.println(); sourceWriter.indent(); sourceWriter.println("if (clazz.getName().endsWith(\"." + classType.getName() + "\")) {"); sourceWriter.indent(); sourceWriter.println("return (T) new " + classType.getQualifiedSourceName() + "( );"); sourceWriter.outdent(); sourceWriter.println("}"); sourceWriter.outdent(); sourceWriter.println(); } } } else { sourceWriter.println(); sourceWriter.indent(); sourceWriter.println("if (clazz.getName().endsWith(\"." + classType.getName() + "\")) {"); sourceWriter.indent(); sourceWriter.println("return (T) new " + classType.getQualifiedSourceName() + "( );"); sourceWriter.outdent(); sourceWriter.println("}"); sourceWriter.outdent(); sourceWriter.println(); } } sourceWriter.indent(); sourceWriter.println("return (T) null;"); sourceWriter.outdent(); sourceWriter.println(); sourceWriter.println("}"); sourceWriter.outdent(); sourceWriter.println(); }
From source file:org.lirazs.gbackbone.generator.ReflectionGenerator.java
License:Apache License
private void printArrayFactoryMethod(List<JClassType> clazzes, SourceWriter sourceWriter) { sourceWriter.println();/*from www . j a v a 2 s . c om*/ sourceWriter.println("public <T, V extends T> T[] instantiateArray( Class<V> clazz, int length ) {"); for (JClassType classType : clazzes) { if (classType.isAbstract()) continue; sourceWriter.println(); sourceWriter.indent(); sourceWriter.println("if (clazz.getName().endsWith(\"." + classType.getName() + "\")) {"); sourceWriter.indent(); sourceWriter.println("return (T[]) new " + classType.getQualifiedSourceName() + "[length];"); sourceWriter.outdent(); sourceWriter.println("}"); sourceWriter.outdent(); sourceWriter.println(); } sourceWriter.indent(); sourceWriter.println("return (T[]) null;"); sourceWriter.outdent(); sourceWriter.println(); sourceWriter.println("}"); sourceWriter.outdent(); sourceWriter.println(); }