/** * For debugging use only. */ @Override public String toString() { if (this == UNREFERENCED_EXTERNAL) { return "Unreferenced external class name"; } else { return method.getName() + "=" + obfuscatedClassName; } } }
/** * Write the CssResource accessor method for simple String return values. */ private void writeClassAssignment(SourceWriter sw, JMethod toImplement, Map<JMethod, String> classReplacements) { String replacement = classReplacements.get(toImplement); assert replacement != null : "Missing replacement for " + toImplement.getName(); writeSimpleGetter(toImplement, "\"" + replacement + "\"", sw); }
public ImageResourceDeclaration(JMethod method) { super(key(method)); this.name = method.getName(); this.method = method; this.options = method.getAnnotation(ImageOptions.class); }
private String getClassName(JMethod method) { String name = method.getName(); ClassName classNameOverride = method.getAnnotation(ClassName.class); if (classNameOverride != null) { name = classNameOverride.value(); } return name; }
private static String key(JMethod method) { return method.getEnclosingType().getQualifiedSourceName() + "." + method.getName(); }
@Override public void prepare(TreeLogger logger, ResourceContext context, ClientBundleRequirements requirements, JMethod method) throws UnableToCompleteException { URL[] urls = ResourceGeneratorUtil.findResources(logger, context, method); if (urls.length != 1) { logger.log(TreeLogger.ERROR, "Exactly one resource must be specified", null); throw new UnableToCompleteException(); } URL resource = urls[0]; String toWrite = Util.readURLAsString(resource); // This de-duplicates strings in the bundle. if (!hashes.containsKey(toWrite)) { hashes.put(toWrite, currentIndex++); if (!first) { data.append(",\n"); } else { first = false; } data.append('"'); data.append(Generator.escape(toWrite)); data.append('"'); } // Store the (possibly n:1) mapping of resource function to bundle index. offsets.put(method.getName(), hashes.get(toWrite)); }
protected void writeGetName(JMethod method, SourceWriter sw) { sw.println("public String getName() {"); sw.indentln("return \"" + method.getName() + "\";"); sw.println("}"); }
String qualifiedMethodName = bundleType.getQualifiedSourceName() + "." + method.getName(); for (Map.Entry<JMethod, String> replacement : actualReplacements.entrySet()) { String qualifiedName = replacement.getKey().getEnclosingType().getQualifiedSourceName(); String baseName = replacement.getKey().getName(); writer.write(qualifiedName.replaceAll("[.$]", "-") + "-" + baseName); writer.write(",");
@Override public String createAssignment(TreeLogger logger, ResourceContext context, JMethod method) throws UnableToCompleteException { String name = method.getName(); SourceWriter sw = new StringSourceWriter(); sw.println("new " + ExternalTextResourcePrototype.class.getName() + "("); sw.indent(); sw.println('"' + name + "\","); // These are field names sw.println(UriUtils.class.getName() + ".fromTrustedString(" + externalTextUrlIdent + "),"); sw.println(externalTextCacheIdent + ", "); sw.println(offsets.get(method.getName()).toString()); if (shouldUseJsonp(context, logger)) { sw.println(", \"" + getMd5HashOfData() + "\""); } sw.outdent(); sw.print(")"); return sw.toString(); }
String methodName = userMethod.getName(); logger.log(Type.ERROR, "The return type of the method [" + userMethod.getName() + "] must " + "be java.lang.String."); throw new UnableToCompleteException(); "The following method [" + userMethod.getName() + "()] doesn't match a constant" + " nor a style class. You could fix that by adding ." + className + " {}" );
String name = toImplement.getName(); if (ignoredMethods.contains(name)) { continue; if (defs.contains(toImplement.getName()) && toImplement.getParameters().length == 0) { writeDefAssignment(logger, sw, toImplement, sheet); } else { logger.log(TreeLogger.ERROR, "Don't know how to implement method " + toImplement.getName()); throw new UnableToCompleteException();
private boolean writeClassMethod(TreeLogger logger, JMethod userMethod, Map<String, String> substitutionMap, SourceWriter sw) throws UnableToCompleteException { if (userMethod.getParameters().length > 0) { logger.log(Type.ERROR, "The method [" + userMethod.getName() + "] shouldn't contain any " + "parameters"); throw new UnableToCompleteException(); } String name = getClassName(userMethod); String value = substitutionMap.get(name); if (value == null) { logger.log(Type.ERROR, "The following style class [" + name + "] is missing from the source" + " CSS file"); return false; } else { writeSimpleGetter(userMethod, "\"" + value + "\"", sw); } return true; }
String name = method.getName(); if (ignoredMethods.contains(name)) { continue;
writer.addStatement("%1$s.%2$s(%3$s);", fieldName, method.getName(), UiBinderWriter.asCommaSeparatedList(parameters));
sw.println('"' + method.getName() + "\","); sw.println(UriUtils.class.getName() + ".fromTrustedString(" + outputUrlExpression + ")"); sw.outdent();
@Override public String createAssignment(TreeLogger logger, ResourceContext context, JMethod method) throws UnableToCompleteException { JParameterizedType returnType = method.getReturnType().isParameterized(); assert returnType != null; JClassType args[] = returnType.getTypeArgs(); assert args.length == 1; ClassType override = method.getAnnotation(ClassType.class); JClassType toCreate; if (override != null) { toCreate = context.getGeneratorContext().getTypeOracle().findType( override.value().getName().replace('$', '.')); assert toCreate != null; } else { toCreate = args[0]; } JClassType gwtType = context.getGeneratorContext().getTypeOracle().findType( GWT.class.getName()); assert gwtType != null; return "new " + returnType.getParameterizedQualifiedSourceName() + "() {\n public " + toCreate.getQualifiedSourceName() + " create() {\n return " + gwtType.getQualifiedSourceName() + ".create(" + toCreate.getQualifiedSourceName() + ".class);}\n" + "public String getName() { return \"" + method.getName() + "\";}}"; } }
@Override public String createAssignment(TreeLogger logger, ResourceContext context, JMethod method) throws UnableToCompleteException { String name = method.getName(); ImageResourceDeclaration image = new ImageResourceDeclaration(method); DisplayedImage bundle = getImage(image); SourceWriter sw = new StringSourceWriter(); sw.println("new " + bundle.getResourceType().getCanonicalName() + "("); sw.indent(); sw.println('"' + name + "\","); ImageRect rect = bundle.getImageRect(image); if (rect == null) { throw new NullPointerException("No ImageRect ever computed for " + name); } String[] urlExpressions = new String[] {bundle.getNormalContentsFieldName(), bundle.getRtlContentsFieldName()}; assert urlExpressions[0] != null : "No primary URL expression for " + name; if (urlExpressions[1] == null) { sw.println(UriUtils.class.getName() + ".fromTrustedString(" + urlExpressions[0] + "),"); } else { sw.println(UriUtils.class.getName() + ".fromTrustedString(" + "com.google.gwt.i18n.client.LocaleInfo.getCurrentLocale().isRTL() ?" + urlExpressions[1] + " : " + urlExpressions[0] + "),"); } sw.println(rect.getLeft() + ", " + rect.getTop() + ", " + rect.getWidth() + ", " + rect.getHeight() + ", " + rect.isAnimated() + ", " + rect.isLossy()); sw.outdent(); sw.print(")"); return sw.toString(); }
sw.println("return \"" + method.getName() + "\";"); sw.outdent(); sw.println("}");