| /* |
| * Copyright 2009 Google Inc. |
| * |
| * Licensed under the Apache License, Version 2.0 (the "License"); you may not |
| * use this file except in compliance with the License. You may obtain a copy of |
| * the License at |
| * |
| * http://www.apache.org/licenses/LICENSE-2.0 |
| * |
| * Unless required by applicable law or agreed to in writing, software |
| * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| * License for the specific language governing permissions and limitations under |
| * the License. |
| */ |
| package com.google.gwt.uibinder.rebind; |
| |
| import com.google.gwt.core.ext.typeinfo.TypeOracle; |
| import com.google.gwt.resources.client.ClientBundle; |
| import com.google.gwt.resources.client.CssResource.Strict; |
| import com.google.gwt.uibinder.rebind.model.ImplicitBundle; |
| import com.google.gwt.uibinder.rebind.model.CssResourceGetter; |
| |
| import java.io.PrintWriter; |
| |
| /** |
| * Writes source implementing a {@link ImplicitBundle} to a {@link PrintWriter}. |
| */ |
| public class BundleWriter { |
| |
| private final ImplicitBundle bundleClass; |
| private final IndentedWriter writer; |
| private final TypeOracle oracle; |
| |
| public BundleWriter(ImplicitBundle bundleClass, PrintWriter printWriter, |
| TypeOracle oracle) { |
| this.bundleClass = bundleClass; |
| this.writer = new IndentedWriter(printWriter); |
| this.oracle = oracle; |
| } |
| |
| public void write() { |
| // Package declaration |
| String packageName = bundleClass.getPackageName(); |
| if (packageName.length() > 0) { |
| writer.write("package %1$s;", packageName); |
| writer.newline(); |
| } |
| |
| // Imports |
| writer.write("import %s;", |
| oracle.findType(ClientBundle.class.getName()).getQualifiedSourceName()); |
| writer.write("import %s;", |
| oracle.findType(Strict.class.getCanonicalName()).getQualifiedSourceName()); |
| writer.newline(); |
| |
| // Open interface |
| writer.write("public interface %s extends ClientBundle {", |
| bundleClass.getClassName()); |
| writer.indent(); |
| |
| // Write css methods |
| for (CssResourceGetter css : bundleClass.getCssMethods()) { |
| writer.write("@Strict @Source(\"%s\")",css.getSource()); |
| writer.write("%s %s();", css.getExtendedInterface().getQualifiedSourceName(), css.getName()); |
| writer.newline(); |
| } |
| |
| // Close interface. |
| writer.outdent(); |
| writer.write("}"); |
| } |
| } |