public FieldWriterOfGeneratedCssResource(FieldManager manager, JType stringType, ImplicitCssResource css, MortalLogger logger) { super(manager, FieldWriterType.GENERATED_CSS, css.getName(), logger); this.stringType = stringType; this.css = css; }
/** * Called to declare a new CssResource accessor on this bundle. * * @param name the method name and the ui:field name * @param source path to the .css file resource * @param extendedInterface the public interface implemented by this * CssResource, or null * @param body the inline css text * @param importTypes for the {@literal @}Import annotation, if any. LinkedHashSet * to enforce deterministic order across recompiles * @param gss indicates that GSS is used or not * @param resourceOracle from which to load resources * @return the newly-created CssResource */ public ImplicitCssResource createCssResource(String name, String[] source, JClassType extendedInterface, String body, LinkedHashSet<JClassType> importTypes, Boolean gss, ResourceOracle resourceOracle) { ImplicitCssResource css = new ImplicitCssResource(packageName, cssBaseName + name, name, source, extendedInterface, body, logger, importTypes, gss, resourceOracle); cssMethods.add(css); return css; }
private File getGeneratedFile() { if (body.length() == 0) { return null; } if (generatedFile == null) { try { File f = File.createTempFile(String.format("uiBinder_%s_%s", packageName, className), "." + getCssFileExtension()); f.deleteOnExit(); BufferedWriter out = new BufferedWriter(new FileWriter(f)); out.write(body); out.close(); generatedFile = f; } catch (IOException e) { throw new RuntimeException(e); } ResourceGeneratorUtil.addNamedFile(getBodyFileName(), generatedFile); } return generatedFile; }
private String getBodyFileName() { String bodyFileName = String.format("uibinder.%s.%s.%s", packageName, className, getCssFileExtension()); // To verify that the resulting file can be retrieved out of zip files using a URL reference. assert isValidUrl("file:/" + bodyFileName); return bodyFileName; }
public void write() throws UnableToCompleteException { // Package declaration String packageName = css.getPackageName(); if (packageName.length() > 0) { writer.write("package %1$s;", packageName); writer.newline(); } JClassType superType = css.getExtendedInterface(); if (superType == null) { superType = cssResourceType; } writer.write("import %s;", superType.getQualifiedSourceName()); writer.newline(); // Open interface writer.write("public interface %s extends %s {", css.getClassName(), superType.getSimpleSourceName()); writer.indent(); writeCssMethods(superType); // Close interface. writer.outdent(); writer.write("}"); }
/** * Returns the set of CSS classnames in the underlying css or gss files. * * @throws UnableToCompleteException if the user has called for a css/gss file we * can't find. */ public Set<String> getCssClassNames() throws UnableToCompleteException { List<URL> urls = getExternalCss(); if (cssClassNames == null) { final File bodyFile = getGeneratedFile(); if (bodyFile != null) { try { urls.add(bodyFile.toURI().toURL()); } catch (MalformedURLException e) { throw new RuntimeException(e); } } assert urls.size() > 0; if (gss) { return getCssClassNames(bodyFile.getName(), body, imports, logger.getTreeLogger()); } else { CssStylesheet sheet = GenerateCssAst.exec(logger.getTreeLogger(), urls.toArray(new URL[urls.size()])); cssClassNames = ExtractClassNamesVisitor.exec(sheet, imports.toArray(new JClassType[imports.size()])); } } return cssClassNames; }
writeCssSource(css); writeCssImports(css); writer.write("%s %s();", css.getClassName(), css.getName()); writer.newline();
@Override public JType getReturnType(String[] path, MonitoredLogger logger) { if (path.length == 2) { String maybeCssClass = path[1]; Set<String> cssClassNames = null; try { cssClassNames = css.getCssClassNames(); if (cssClassNames.contains(maybeCssClass) || cssClassNames.contains(nameConverter.convertName(maybeCssClass)) || css.getNormalizedCssClassNames().contains(maybeCssClass)) { return stringType; } } catch (UnableToCompleteException e) { logger.error("Can't interpret CSS"); } } return super.getReturnType(path, logger); }
/** * Returns css class names with dashed-names normalized like so: dashedNames. */ public Set<String> getNormalizedCssClassNames() throws UnableToCompleteException { if (normalizedCssClassNames == null) { Set<String> rawNames = getCssClassNames(); normalizedCssClassNames = new HashSet<String>(); for (String rawName : rawNames) { normalizedCssClassNames.add(nameConverter.convertName(rawName)); } } return normalizedCssClassNames; }
public void write() throws UnableToCompleteException { writeBundleClass(); for (ImplicitCssResource css : bundleClass.getCssMethods()) { new CssResourceWriter(css, types, writerManager.makePrintWriterFor(css.getClassName()), logger).write(); } }
/** * Returns the name of the css or gss file(s), separate by white space. */ public Collection<String> getSource() { if (body.length() == 0) { return Collections.unmodifiableCollection(sources); } List<String> rtn = new ArrayList<String>(sources); rtn.add(getBodyFileName()); return rtn; }
public JClassType getAssignableType() { return css.getExtendedInterface(); }
private void writeCssImports(ImplicitCssResource css) { Set<JClassType> importTypes = css.getImports(); int numImports = importTypes.size(); if (numImports > 0) { if (numImports == 1) { writer.write("@Import(%s.class)", importTypes.iterator().next().getQualifiedSourceName()); } else { StringBuffer b = new StringBuffer(); for (JClassType importType : importTypes) { if (b.length() > 0) { b.append(", "); } b.append(importType.getQualifiedSourceName()).append(".class"); } writer.write("@Import({%s})", b); } } }
public void write() throws UnableToCompleteException { // Package declaration String packageName = css.getPackageName(); if (packageName.length() > 0) { writer.write("package %1$s;", packageName); writer.newline(); } JClassType superType = css.getExtendedInterface(); if (superType == null) { superType = cssResourceType; } writer.write("import %s;", superType.getQualifiedSourceName()); writer.newline(); // Open interface writer.write("public interface %s extends %s {", css.getClassName(), superType.getSimpleSourceName()); writer.indent(); writeCssMethods(superType); // Close interface. writer.outdent(); writer.write("}"); }
/** * Returns the set of CSS classnames in the underlying css or gss files. * * @throws UnableToCompleteException if the user has called for a css/gss file we * can't find. */ public Set<String> getCssClassNames() throws UnableToCompleteException { List<URL> urls = getExternalCss(); if (cssClassNames == null) { final File bodyFile = getGeneratedFile(); if (bodyFile != null) { try { urls.add(bodyFile.toURI().toURL()); } catch (MalformedURLException e) { throw new RuntimeException(e); } } assert urls.size() > 0; if (gss) { return GssWrapper.getCssClassNames(bodyFile.getName(), body, imports, logger.getTreeLogger()); } else { CssStylesheet sheet = GenerateCssAst.exec(logger.getTreeLogger(), urls.toArray(new URL[urls.size()])); cssClassNames = ExtractClassNamesVisitor.exec(sheet, imports.toArray(new JClassType[imports.size()])); } } return cssClassNames; }
writeCssSource(css); writeCssImports(css); writer.write("%s %s();", css.getClassName(), css.getName()); writer.newline();
private String getBodyFileName() { String bodyFileName = String.format("uibinder.%s.%s.%s", packageName, className, getCssFileExtension()); // To verify that the resulting file can be retrieved out of zip files using a URL reference. assert isValidUrl("file:/" + bodyFileName); return bodyFileName; }
@Override public JType getReturnType(String[] path, MonitoredLogger logger) { if (path.length == 2) { String maybeCssClass = path[1]; Set<String> cssClassNames = null; try { cssClassNames = css.getCssClassNames(); if (cssClassNames.contains(maybeCssClass) || cssClassNames.contains(nameConverter.convertName(maybeCssClass)) || css.getNormalizedCssClassNames().contains(maybeCssClass)) { return stringType; } } catch (UnableToCompleteException e) { logger.error("Can't interpret CSS"); } } return super.getReturnType(path, logger); }
/** * Returns css class names with dashed-names normalized like so: dashedNames. */ public Set<String> getNormalizedCssClassNames() throws UnableToCompleteException { if (normalizedCssClassNames == null) { Set<String> rawNames = getCssClassNames(); normalizedCssClassNames = new HashSet<String>(); for (String rawName : rawNames) { normalizedCssClassNames.add(nameConverter.convertName(rawName)); } } return normalizedCssClassNames; }
public void write() throws UnableToCompleteException { writeBundleClass(); for (ImplicitCssResource css : bundleClass.getCssMethods()) { new CssResourceWriter(css, types, writerManager.makePrintWriterFor(css.getClassName()), logger).write(); } }