List of usage examples for com.google.gwt.user.rebind SourceWriter outdent
void outdent();
From source file:de.knightsoftnet.validators.rebind.ValidatorCreator.java
License:Apache License
private void writeValidate(final SourceWriter sw, final BeanHelper bean) { this.writeIfInstanceofBeanType(sw, bean); sw.indent();//w w w .j a va2s . c om this.writeContext(sw, bean, "object"); // return PersonValidator.INSTANCE sw.print("return "); sw.println(bean.getFullyQualifiedValidatorName() + ".INSTANCE"); sw.indent(); sw.indent(); // .validate(context, (<<MyBean>>) object, groups); sw.print(".validate(context, "); sw.print("(" + bean.getTypeCanonicalName() + ") object, "); 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 writeValidateProperty(final SourceWriter sw) { sw.println("public <T> Set<ConstraintViolation<T>> validateProperty(" + "T object,String propertyName, Class<?>... groups) {"); sw.indent();/*from w w w .jav a 2s . c o m*/ sw.println("checkNotNull(object, \"object\");"); sw.println("checkNotNull(propertyName, \"propertyName\");"); sw.println("checkNotNull(groups, \"groups\");"); sw.println("checkGroups(groups);"); for (final BeanHelper bean : this.beansToValidate) { this.writeValidateProperty(sw, bean); } this.writeThrowIllegalArgumnet(sw, "object.getClass().getName()"); sw.outdent(); sw.println("}"); }
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 .ja v a2 s. c om*/ 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 a2 s .c om*/ 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();//from w w w. j av a 2 s .co m 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: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 w w w . j a va 2 s .c o m*/ 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;//w w w . j a va 2s . 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.base.AbstractInjectorCreator.java
License:Open Source License
public String create(TreeLogger logger, GeneratorContext context) { PrintWriter writer = context.tryCreate(logger, this.packageName, this.proxyName); if (writer == null) { return this.proxyQualifiedName; }/*ww w. j a v a2 s.co m*/ SourceWriter srcWriter = this.getSourceWriter(writer, context); srcWriter.indent(); this.doCreate(logger, context, srcWriter); srcWriter.outdent(); srcWriter.commit(logger); return this.proxyQualifiedName; }
From source file:fr.putnami.pwt.core.inject.rebind.base.AbstractInjectorCreator.java
License:Open Source License
protected void writeConstructor(TreeLogger logger, GeneratorContext context, SourceWriter srcWriter) { srcWriter.println("public %s() {", this.proxyName); srcWriter.indent();/*w w w .ja v a2s . c o m*/ for (InjectorWritterConstructor delegate : Iterables.filter(this.delegates, InjectorWritterConstructor.class)) { delegate.writeConstructor(srcWriter); } srcWriter.outdent(); srcWriter.println("}"); }
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();/*from w ww . j a v a 2 s. co 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("}"); }