List of usage examples for com.google.gwt.user.rebind SourceWriter println
void println(String s);
From source file:de.knightsoftnet.validators.rebind.ValidatorCreator.java
License:Apache License
private void writeValidateProperty(final SourceWriter sw, final BeanHelper bean) { this.writeIfInstanceofBeanType(sw, bean); sw.indent();//from w w w. j a v a 2 s . co m this.writeContext(sw, bean, "object"); // return PersonValidator.INSTANCE sw.print("return "); sw.println(bean.getFullyQualifiedValidatorName() + ".INSTANCE"); sw.indent(); sw.indent(); // .validateProperty(context, (MyBean) object, propertyName, groups); sw.print(".validateProperty(context, ("); sw.print(bean.getTypeCanonicalName()); sw.print(") object, propertyName, "); sw.println("groups);"); sw.outdent(); sw.outdent(); // } sw.outdent(); sw.println("}"); }
From source file:de.knightsoftnet.validators.rebind.ValidatorCreator.java
License:Apache License
private void writeValidateValue(final SourceWriter sw) { sw.println("public <T> Set<ConstraintViolation<T>> validateValue(Class<T> beanType, " + "String propertyName, Object value, Class<?>... groups) {"); sw.indent();/*from w ww .j a v a 2 s .c o m*/ sw.println("checkNotNull(beanType, \"beanType\");"); sw.println("checkNotNull(propertyName, \"propertyName\");"); sw.println("checkNotNull(groups, \"groups\");"); sw.println("checkGroups(groups);"); for (final BeanHelper bean : this.beansToValidate) { this.writeValidateValue(sw, bean); } this.writeThrowIllegalArgumnet(sw, "beanType.getName()"); sw.outdent(); sw.println("}"); }
From source file:de.knightsoftnet.validators.rebind.ValidatorCreator.java
License:Apache License
private void writeValidateValue(final SourceWriter sw, final BeanHelper bean) { sw.println("if (beanType.equals(" + bean.getTypeCanonicalName() + ".class)) {"); sw.indent();//w w w .j a v a 2 s.c om this.writeContext(sw, bean, "null"); // return PersonValidator.INSTANCE sw.print("return "); sw.println(bean.getFullyQualifiedValidatorName() + ".INSTANCE"); sw.indent(); sw.indent(); // .validateValue(context, (Class<MyBean> beanType, propertyName, value, // groups); sw.print(".validateValue(context, (Class<"); sw.print(bean.getTypeCanonicalName()); sw.println(">)beanType, propertyName, value, groups);"); sw.outdent(); sw.outdent(); // } sw.outdent(); sw.println("}"); }
From source file:de.swm.commons.mobile.generator.OsDetectionGenerator.java
License:Apache License
/** * {@inheritDoc}/*from w w w.ja va2 s . c o m*/ */ @Override public String generate(TreeLogger logger, GeneratorContext context, String typeName) throws UnableToCompleteException { // get the property oracle PropertyOracle propertyOracle = context.getPropertyOracle(); SelectionProperty property = null; try { // get mgwt.os variable property = propertyOracle.getSelectionProperty(logger, "swmmmobile.os"); } catch (BadPropertyValueException e) { // if we can`t find it die logger.log(TreeLogger.ERROR, "can not resolve mgwt.os variable", e); throw new UnableToCompleteException(); } JClassType classType = null; try { // get the type we are looking for classType = context.getTypeOracle().getType(typeName); } catch (NotFoundException e) { // if we can`t get it die logger.log(TreeLogger.ERROR, "can not find type: '" + typeName + "'", e); throw new UnableToCompleteException(); } // get value of mmobile.os String mmobileProperty = property.getCurrentValue(); // get the package name String packageName = classType.getPackage().getName(); // build name for implementation class String simpleName = classType.getSimpleSourceName() + "_" + property.getCurrentValue(); // combine package name and simple name to full qualified String fullName = packageName + "." + simpleName; ClassSourceFileComposerFactory composer = new ClassSourceFileComposerFactory(packageName, simpleName); composer.addImplementedInterface(typeName); composer.addImport(typeName); PrintWriter printWriter = context.tryCreate(logger, packageName, simpleName); if (printWriter == null) { return fullName; } // start writing the implementation SourceWriter writer = composer.createSourceWriter(context, printWriter); writer.println("public boolean isAndroid() {"); writer.println("return isAndroidTablet() || isAndroidPhone();"); writer.println("}"); writer.println("public boolean isIPhone() {"); writer.println( "return " + mmobileProperty.equals("iphone") + " || " + mmobileProperty.equals("retina") + ";"); writer.println("}"); writer.println("public boolean isIPad() {"); writer.println("return " + mmobileProperty.equals("ipad") + ";"); writer.println("}"); writer.println("public boolean isIOs() {"); writer.println("return isIPhone() || isIPad();"); writer.println("}"); writer.println("public boolean isDesktop() {"); writer.println("return " + mmobileProperty.equals("desktop") + ";"); writer.println("}"); writer.println("public boolean isBlackBerry() {"); writer.println("return " + mmobileProperty.equals("blackberry") + ";"); writer.println("}"); writer.println("public boolean isTablet() {"); writer.println("return isDesktop() || isIPad() || isAndroidTablet();"); writer.println("}"); writer.println("public boolean isPhone() {"); writer.println("return isIPhone() || isAndroidPhone() || isBlackBerry();"); writer.println("}"); writer.println("public boolean isAndroidTablet() {"); writer.println("return " + mmobileProperty.equals("android_tablet") + ";"); writer.println("}"); writer.println("public boolean isAndroidPhone() {"); writer.println("return " + mmobileProperty.equals("android") + ";"); writer.println("}"); writer.println("public boolean isRetina() {"); writer.println("return " + mmobileProperty.equals("retina") + ";"); writer.println("}"); writer.commit(logger); return fullName; }
From source file:eml.studio.client.ui.binding.TextBinderGenerator.java
License:Open Source License
/** * Generate method bind/*w ww .j a va 2s. c o m*/ */ private void composeBindMethod(TreeLogger logger, SourceWriter sourceWriter) { logger.log(TreeLogger.INFO, ""); String line = "public void bind(" + parameterizedType1.getQualifiedSourceName() + " text, " + parameterizedType2.getQualifiedSourceName() + " obj){"; sourceWriter.println(line); logger.log(TreeLogger.INFO, line); line = " System.out.println(\"Implement it now:)\");"; sourceWriter.println(line); logger.log(TreeLogger.INFO, line); ArrayList<JField> fields = new ArrayList<JField>(); JClassType curtype = parameterizedType2; do { for (JField filed : curtype.getFields()) { fields.add(filed); } curtype = curtype.getSuperclass(); } while (!curtype.getName().equals("Object")); for (JField field : fields) { String name = field.getName(); String Name = name.substring(0, 1).toUpperCase() + name.substring(1); line = " text.setText(\"" + name + "\", obj.get" + Name + "().toString() );"; sourceWriter.println(line); logger.log(TreeLogger.INFO, line); } line = "}"; sourceWriter.println(line); logger.log(TreeLogger.INFO, line); }
From source file:eml.studio.client.ui.binding.TextBinderGenerator.java
License:Open Source License
/** * Generate method sync/* www . j a v a 2s.c om*/ */ private void composeSyncMethod(TreeLogger logger, SourceWriter sourceWriter) { logger.log(TreeLogger.INFO, ""); String line = "public void sync(" + parameterizedType1.getQualifiedSourceName() + " text, " + parameterizedType2.getQualifiedSourceName() + " obj){"; sourceWriter.println(line); logger.log(TreeLogger.INFO, line); line = " System.out.println(\"Implement it now:)\");"; sourceWriter.println(line); logger.log(TreeLogger.INFO, line); ArrayList<JField> fields = new ArrayList<JField>(); JClassType curtype = parameterizedType2; do { for (JField filed : curtype.getFields()) { fields.add(filed); } curtype = curtype.getSuperclass(); } while (!curtype.getName().equals("Object")); for (JField field : fields) { String name = field.getName(); String Name = name.substring(0, 1).toUpperCase() + name.substring(1); String type = field.getType().getQualifiedSourceName(); String simType = field.getType().getSimpleSourceName(); if ("java.lang.String".equals(type)) line = " if( text.getText(\"" + name + "\") != null )obj.set" + Name + "( text.getText(\"" + name + "\") );"; else line = " if( text.getText(\"" + name + "\") != null )obj.set" + Name + "( " + type + ".parse" + simType + "( text.getText(\"" + name + "\")) );"; sourceWriter.println(line); logger.log(TreeLogger.INFO, line); } line = "}"; sourceWriter.println(line); logger.log(TreeLogger.INFO, line); }
From source file:fi.jasoft.draganddrop.configurations.DragAndDropConfigurationManagerGenerator.java
License:Apache License
@Override public String generate(TreeLogger logger, GeneratorContext context, String typeName) throws UnableToCompleteException { TypeOracle typeOracle = context.getTypeOracle(); JClassType functionType = typeOracle.findType(typeName); assert DragAndDropConfigurationManager.class.equals(functionType.getClass()); ClassSourceFileComposerFactory composerFactory = new ClassSourceFileComposerFactory(IMPL_PACKAGE_NAME, IMPL_TYPE_NAME);//from ww w . ja va 2s . c om composerFactory.addImport(DragAndDropConfigurationManager.class.getCanonicalName()); composerFactory.addImplementedInterface(DragAndDropConfigurationManager.class.getName()); composerFactory.addImport(Map.class.getCanonicalName()); composerFactory.addImport(HashMap.class.getCanonicalName()); composerFactory.addImport(AbstractDragAndDropConfiguration.class.getCanonicalName()); composerFactory.addImport(ComponentConnector.class.getCanonicalName()); // Get all connectors and configurations List<JClassType> connectors = new ArrayList<JClassType>(); List<JClassType> configurations = new ArrayList<JClassType>(); for (JClassType type : typeOracle.getTypes()) { if (type.getAnnotation(Connect.class) != null) { connectors.add(type); } if (type.getAnnotation(DragAndDropConfiguration.class) != null) { configurations.add(type); } } // Map connector to configuration Map<JClassType, JClassType> connectorToConfigurationMap = new HashMap<JClassType, JClassType>(); for (JClassType connectorType : connectors) { Connect connect = connectorType.getAnnotation(Connect.class); for (JClassType confType : configurations) { DragAndDropConfiguration conf = confType.getAnnotation(DragAndDropConfiguration.class); Class<?> dropHandler = conf.value(); DragAndDropHandler ddHandler = dropHandler.getAnnotation(DragAndDropHandler.class); if (connect.value() == ddHandler.value()) { connectorToConfigurationMap.put(connectorType, confType); composerFactory.addImport(confType.getQualifiedSourceName()); } } } PrintWriter printWriter = context.tryCreate(logger, IMPL_PACKAGE_NAME, IMPL_TYPE_NAME); if (printWriter != null) { SourceWriter sourceWriter = composerFactory.createSourceWriter(context, printWriter); sourceWriter.println("@Override"); sourceWriter.println( "public Map<String, AbstractDragAndDropConfiguration<? extends ComponentConnector>> getConfigurations(){"); sourceWriter.indent(); sourceWriter.println( "Map<String, AbstractDragAndDropConfiguration<? extends ComponentConnector>> configurations = new HashMap<String, AbstractDragAndDropConfiguration<? extends ComponentConnector>>();"); for (Entry<JClassType, JClassType> e : connectorToConfigurationMap.entrySet()) { sourceWriter.println("configurations.put(\"" + e.getKey().getQualifiedSourceName() + "\", new " + e.getValue().getSimpleSourceName() + "());"); } sourceWriter.println("return configurations;"); sourceWriter.outdent(); sourceWriter.println("}"); sourceWriter.commit(logger); } return IMPL_PACKAGE_NAME + "." + IMPL_TYPE_NAME; }
From source file:forplay.rebind.AutoClientBundleGenerator.java
License:Apache License
@Override public String generate(TreeLogger logger, GeneratorContext context, String typeName) throws UnableToCompleteException { TypeOracle typeOracle = context.getTypeOracle(); JClassType userType;//from ww w .ja v a2 s . c om try { userType = typeOracle.getType(typeName); } catch (NotFoundException e) { logger.log(TreeLogger.ERROR, "Unable to find metadata for type: " + typeName, e); throw new UnableToCompleteException(); } String packageName = userType.getPackage().getName(); String className = userType.getName(); className = className.replace('.', '_'); if (userType.isInterface() == null) { logger.log(TreeLogger.ERROR, userType.getQualifiedSourceName() + " is not an interface", null); throw new UnableToCompleteException(); } ClassSourceFileComposerFactory composerFactory = new ClassSourceFileComposerFactory(packageName, className + "Impl"); composerFactory.addImplementedInterface(userType.getQualifiedSourceName()); composerFactory.addImport(ClientBundleWithLookup.class.getName()); composerFactory.addImport(DataResource.class.getName()); composerFactory.addImport(GWT.class.getName()); composerFactory.addImport(ImageResource.class.getName()); composerFactory.addImport(ResourcePrototype.class.getName()); composerFactory.addImport(TextResource.class.getName()); File warDirectory = getWarDirectory(logger); Asserts.check(warDirectory.isDirectory()); File classesDirectory = new File(warDirectory, WEB_INF_CLASSES); Asserts.check(classesDirectory.isDirectory()); File resourcesDirectory = new File(classesDirectory, packageName.replace('.', '/')); Asserts.check(resourcesDirectory.isDirectory()); String baseClassesPath = classesDirectory.getPath(); logger.log(TreeLogger.DEBUG, "baseClassesPath: " + baseClassesPath); Set<File> files = preferMp3(getFiles(resourcesDirectory, fileFilter)); Set<String> methodNames = new HashSet<String>(); PrintWriter pw = context.tryCreate(logger, packageName, className + "Impl"); if (pw != null) { SourceWriter sw = composerFactory.createSourceWriter(context, pw); // write out jump methods sw.println("public ResourcePrototype[] getResources() {"); sw.indent(); sw.println("return MyBundle.INSTANCE.getResources();"); sw.outdent(); sw.println("}"); sw.println("public ResourcePrototype getResource(String name) {"); sw.indent(); sw.println("return MyBundle.INSTANCE.getResource(name);"); sw.outdent(); sw.println("}"); // write out static ClientBundle interface sw.println("static interface MyBundle extends ClientBundleWithLookup {"); sw.indent(); sw.println("MyBundle INSTANCE = GWT.create(MyBundle.class);"); for (File file : files) { String filepath = file.getPath(); String relativePath = filepath.replace(baseClassesPath, "").replace('\\', '/').replaceFirst("^/", ""); String filename = file.getName(); String contentType = getContentType(logger, file); String methodName = stripExtension(filename); if (!isValidMethodName(methodName)) { logger.log(TreeLogger.WARN, "Skipping invalid method name (" + methodName + ") due to: " + relativePath); continue; } if (!methodNames.add(methodName)) { logger.log(TreeLogger.WARN, "Skipping duplicate method name due to: " + relativePath); continue; } logger.log(TreeLogger.DEBUG, "Generating method for: " + relativePath); Class<? extends ResourcePrototype> returnType = getResourcePrototype(contentType); // generate method sw.println(); if (returnType == DataResource.class) { if (contentType.startsWith("audio/")) { // Prevent the use of data URLs, which Flash won't play sw.println("@DataResource.DoNotEmbed"); } else { // Specify an explicit MIME type, for use in the data URL sw.println("@DataResource.MimeType(\"" + contentType + "\")"); } } sw.println("@Source(\"" + relativePath + "\")"); sw.println(returnType.getName() + " " + methodName + "();"); } sw.outdent(); sw.println("}"); sw.commit(logger); } return composerFactory.getCreatedClassName(); }
From source file:fr.putnami.pwt.core.inject.rebind.delegate.InjectDecoratorPresenterCreator.java
License:Open Source License
@Override public void writePresent(SourceWriter srcWriter) { srcWriter.println("presentDecoratedView(place);"); }
From source file:fr.putnami.pwt.core.inject.rebind.delegate.InjectDecoratorPresenterCreator.java
License:Open Source License
@Override public void writeMethods(SourceWriter srcWriter) { srcWriter.println("public void presentDecoratedView(Place place) {"); srcWriter.indent();//w w w. ja v a 2 s.c o m srcWriter.println("if (view instanceof Presenter) {"); srcWriter.indent(); srcWriter.println("Presenter presenter = (Presenter) view;"); srcWriter.println("presenter.present(place, this);"); srcWriter.outdent(); srcWriter.println("}"); srcWriter.outdent(); srcWriter.println("}"); }