Autoformat of UiBinderWriter, XMLElement and XMLAttribute in
anticipation of pending changes.
git-svn-id: https://google-web-toolkit.googlecode.com/svn/trunk@10523 8db76d5a-ed1c-0410-87a9-c151d255dfc7
diff --git a/user/src/com/google/gwt/uibinder/rebind/UiBinderWriter.java b/user/src/com/google/gwt/uibinder/rebind/UiBinderWriter.java
index 2cbe8f8..6b3232e 100644
--- a/user/src/com/google/gwt/uibinder/rebind/UiBinderWriter.java
+++ b/user/src/com/google/gwt/uibinder/rebind/UiBinderWriter.java
@@ -1,12 +1,12 @@
/*
* Copyright 2008 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
@@ -134,7 +134,7 @@
/**
* Returns a list of the given type and all its superclasses and implemented
* interfaces in a breadth-first traversal.
- *
+ *
* @param type the base type
* @return a breadth-first collection of its type hierarchy
*/
@@ -184,9 +184,9 @@
}
/**
- * Scans a class for a method named "render". Returns its parameters except for the
- * first one. See {@link #validateRenderParameters(JClassType)} for a method that
- * guarantees this method will succeed.
+ * Scans a class for a method named "render". Returns its parameters except
+ * for the first one. See {@link #validateRenderParameters(JClassType)} for a
+ * method that guarantees this method will succeed.
*/
private static JParameter[] findRenderParameters(JClassType owner) {
JMethod[] methods = owner.getMethods();
@@ -194,7 +194,7 @@
for (JMethod jMethod : methods) {
if (jMethod.getName().equals("render")) {
- renderMethod = jMethod;
+ renderMethod = jMethod;
}
}
@@ -203,8 +203,8 @@
}
/**
- * Determine the field name a getter is trying to retrieve. Assumes getters begin with
- * "get".
+ * Determine the field name a getter is trying to retrieve. Assumes getters
+ * begin with "get".
*/
private static String getterToFieldName(String name) {
String fieldName = name.substring(3);
@@ -305,12 +305,10 @@
private final String binderUri;
private final boolean isRenderer;
- public UiBinderWriter(JClassType baseClass, String implClassName,
- String templatePath, TypeOracle oracle, MortalLogger logger,
- FieldManager fieldManager, MessagesWriter messagesWriter,
- DesignTimeUtils designTime, UiBinderContext uiBinderCtx,
- boolean useSafeHtmlTemplates, boolean useLazyWidgetBuilders,
- String binderUri)
+ public UiBinderWriter(JClassType baseClass, String implClassName, String templatePath,
+ TypeOracle oracle, MortalLogger logger, FieldManager fieldManager,
+ MessagesWriter messagesWriter, DesignTimeUtils designTime, UiBinderContext uiBinderCtx,
+ boolean useSafeHtmlTemplates, boolean useLazyWidgetBuilders, String binderUri)
throws UnableToCompleteException {
this.baseClass = baseClass;
this.implClassName = implClassName;
@@ -335,8 +333,7 @@
JClassType[] uiBinderTypes = baseClass.getImplementedInterfaces();
if (uiBinderTypes.length == 0) {
- throw new RuntimeException("No implemented interfaces for "
- + baseClass.getName());
+ throw new RuntimeException("No implemented interfaces for " + baseClass.getName());
}
JClassType uiBinderType = uiBinderTypes[0];
@@ -347,18 +344,15 @@
JClassType uiRendererClass = getOracle().findType(UiRenderer.class.getName());
if (uiBinderType.isAssignableTo(uibinderItself)) {
if (typeArgs.length < 2) {
- throw new RuntimeException(
- "Root and owner type parameters are required for type %s"
- + binderType);
+ throw new RuntimeException("Root and owner type parameters are required for type %s"
+ + binderType);
}
uiRootType = typeArgs[0];
uiOwnerType = typeArgs[1];
isRenderer = false;
} else if (uiBinderType.isAssignableTo(uiRendererClass)) {
if (typeArgs.length < 1) {
- throw new RuntimeException(
- "Owner type parameter is required for type %s"
- + binderType);
+ throw new RuntimeException("Owner type parameter is required for type %s" + binderType);
}
if (!useSafeHtmlTemplates) {
die("Configuration property UiBinder.useSafeHtmlTemplates\n"
@@ -382,10 +376,10 @@
lazyDomElementClass = oracle.findType(LazyDomElement.class.getCanonicalName());
ownerClass = new OwnerClass(uiOwnerType, logger, uiBinderCtx);
- bundleClass = new ImplicitClientBundle(baseClass.getPackage().getName(),
- this.implClassName, CLIENT_BUNDLE_FIELD, logger);
- handlerEvaluator = new HandlerEvaluator(
- ownerClass, logger, oracle, useLazyWidgetBuilders);
+ bundleClass =
+ new ImplicitClientBundle(baseClass.getPackage().getName(), this.implClassName,
+ CLIENT_BUNDLE_FIELD, logger);
+ handlerEvaluator = new HandlerEvaluator(ownerClass, logger, oracle, useLazyWidgetBuilders);
attributeParsers = new AttributeParsers(oracle, fieldManager, logger);
}
@@ -394,7 +388,7 @@
* Add a statement to be executed right after the current attached element is
* detached. This is useful for doing things that might be expensive while the
* element is attached to the DOM.
- *
+ *
* @param format
* @param args
* @see #beginAttachedSection(String)
@@ -421,9 +415,9 @@
if (useLazyWidgetBuilders) {
/**
* I'm intentionally over-simplifying this and assuming that the input
- * comes always in the format: field.somestatement();
- * Thus, field can be extracted easily and the element parsers don't
- * need to be changed all at once.
+ * comes always in the format: field.somestatement(); Thus, field can be
+ * extracted easily and the element parsers don't need to be changed all
+ * at once.
*/
int idx = code.indexOf(".");
String fieldName = code.substring(0, idx);
@@ -442,7 +436,7 @@
* Succeeding calls made to {@link #ensureAttached} and
* {@link #ensureCurrentFieldAttached} must refer to children of this element,
* until {@link #endAttachedSection} is called.
- *
+ *
* @param element Java expression for the generated code that will return the
* dom element to be attached.
*/
@@ -460,7 +454,7 @@
* generate a unique dom id at runtime. Further code will be generated to be
* run after widgets are instantiated, to use that dom id in a getElementById
* call and assign the Element instance to its field.
- *
+ *
* @param fieldName The name of the field being declared
* @param ancestorField The name of fieldName parent
*/
@@ -479,14 +473,12 @@
* called in its ancestral.
*/
if (isOwnerFieldLazyDomElement(fieldName)) {
- field.setInitializer(formatCode("new %s(%s)",
- field.getQualifiedSourceName(),
+ field.setInitializer(formatCode("new %s(%s)", field.getQualifiedSourceName(),
fieldManager.convertFieldToGetter(name)));
} else {
field.setInitializer(formatCode("new %s(%s).get().cast()",
- LazyDomElement.class.getCanonicalName(),
- fieldManager.convertFieldToGetter(name)));
+ LazyDomElement.class.getCanonicalName(), fieldManager.convertFieldToGetter(name)));
// The dom must be created by its ancestor.
fieldManager.require(ancestorField).addAttachStatement(
@@ -494,8 +486,7 @@
}
} else {
setFieldInitializer(fieldName, "null");
- addInitStatement(
- "%s = com.google.gwt.dom.client.Document.get().getElementById(%s).cast();",
+ addInitStatement("%s = com.google.gwt.dom.client.Document.get().getElementById(%s).cast();",
fieldName, name);
addInitStatement("%s.removeAttribute(\"id\");", fieldName);
}
@@ -506,17 +497,18 @@
/**
* Declare a variable that will be filled at runtime with a unique id, safe
* for use as a dom element's id attribute. For {@code UiRenderer} based code,
- * elements corresponding to a ui:field, need and id initialized to a
- * value that depends on the {@code fieldName}. For all other cases let {@code fieldName}
- * be {@code null}.
- *
+ * elements corresponding to a ui:field, need and id initialized to a value
+ * that depends on the {@code fieldName}. For all other cases let
+ * {@code fieldName} be {@code null}.
+ *
* @param fieldName name of the field corresponding to this variable.
* @return that variable's name.
*/
public String declareDomIdHolder(String fieldName) throws UnableToCompleteException {
String domHolderName = "domId" + domId++;
- FieldWriter domField = fieldManager.registerField(FieldWriterType.DOM_ID_HOLDER,
- oracle.findType(String.class.getName()), domHolderName);
+ FieldWriter domField =
+ fieldManager.registerField(FieldWriterType.DOM_ID_HOLDER,
+ oracle.findType(String.class.getName()), domHolderName);
if (isRenderer && fieldName != null) {
domField.setInitializer("UiRendererUtilsImpl.buildInnerId(\"" + fieldName + "\", uiId)");
} else {
@@ -531,8 +523,7 @@
* field. If the element has a field or id attribute, use its value.
* Otherwise, create and return a new, private field name for it.
*/
- public String declareField(String typeName, XMLElement elem)
- throws UnableToCompleteException {
+ public String declareField(String typeName, XMLElement elem) throws UnableToCompleteException {
JClassType type = oracle.findType(typeName);
if (type == null) {
die(elem, "Unknown type %s", typeName);
@@ -555,11 +546,10 @@
* If this element has a gwt:field attribute, create a field for it of the
* appropriate type, and return the field name. If no gwt:field attribute is
* found, do nothing and return null
- *
+ *
* @return The new field name, or null if no field is created
*/
- public String declareFieldIfNeeded(XMLElement elem)
- throws UnableToCompleteException {
+ public String declareFieldIfNeeded(XMLElement elem) throws UnableToCompleteException {
String fieldName = getFieldName(elem);
if (fieldName != null) {
@@ -568,7 +558,8 @@
* respective owner field is a LazyDomElement.
*/
if (useLazyWidgetBuilders && isOwnerFieldLazyDomElement(fieldName)) {
- fieldManager.registerFieldForLazyDomElement(findFieldType(elem), ownerClass.getUiField(fieldName));
+ fieldManager.registerFieldForLazyDomElement(findFieldType(elem),
+ ownerClass.getUiField(fieldName));
} else {
fieldManager.registerField(findFieldType(elem), fieldName);
}
@@ -578,14 +569,16 @@
/**
* Declare a {@link RenderableStamper} instance that will be filled at runtime
- * with a unique token. This instance can then be used to stamp a single {@link IsRenderable}.
- *
+ * with a unique token. This instance can then be used to stamp a single
+ * {@link IsRenderable}.
+ *
* @return that variable's name.
*/
public String declareRenderableStamper() throws UnableToCompleteException {
String renderableStamperName = "renderableStamper" + renderableStamper++;
- FieldWriter domField = fieldManager.registerField(FieldWriterType.RENDERABLE_STAMPER,
- oracle.findType(RenderableStamper.class.getName()), renderableStamperName);
+ FieldWriter domField =
+ fieldManager.registerField(FieldWriterType.RENDERABLE_STAMPER,
+ oracle.findType(RenderableStamper.class.getName()), renderableStamperName);
domField.setInitializer(formatCode(
"new %s(com.google.gwt.dom.client.Document.get().createUniqueId())",
RenderableStamper.class.getName()));
@@ -595,12 +588,11 @@
/**
* Writes a new SafeHtml template to the generated BinderImpl.
- *
+ *
* @return The invocation of the SafeHtml template function with the arguments
- * filled in
+ * filled in
*/
- public String declareTemplateCall(String html, String fieldName)
- throws IllegalArgumentException {
+ public String declareTemplateCall(String html, String fieldName) throws IllegalArgumentException {
if (!useSafeHtmlTemplates) {
return '"' + html + '"';
}
@@ -610,12 +602,12 @@
}
/**
- * Given a string containing tokens returned by {@link #tokenForStringExpression},
- * {@link #tokenForSafeHtmlExpression} or {@link #declareDomField}, return a
- * string with those tokens replaced by the appropriate expressions. (It is
- * not normally necessary for an {@link XMLElement.Interpreter} or
- * {@link ElementParser} to make this call, as the tokens are typically
- * replaced by the TemplateWriter itself.)
+ * Given a string containing tokens returned by
+ * {@link #tokenForStringExpression}, {@link #tokenForSafeHtmlExpression} or
+ * {@link #declareDomField}, return a string with those tokens replaced by the
+ * appropriate expressions. (It is not normally necessary for an
+ * {@link XMLElement.Interpreter} or {@link ElementParser} to make this call,
+ * as the tokens are typically replaced by the TemplateWriter itself.)
*/
public String detokenate(String betokened) {
return tokenator.detokenate(betokened);
@@ -633,8 +625,7 @@
* Post an error message and halt processing. This method always throws an
* {@link UnableToCompleteException}
*/
- public void die(String message, Object... params)
- throws UnableToCompleteException {
+ public void die(String message, Object... params) throws UnableToCompleteException {
logger.die(message, params);
}
@@ -650,7 +641,7 @@
/**
* End the current attachable section. This will detach the element if it was
* ever attached and execute any detach statements.
- *
+ *
* @see #beginAttachedSection(String)
*/
public void endAttachedSection() {
@@ -667,15 +658,14 @@
/**
* Ensure that the specified element is attached to the DOM.
- *
+ *
* @see #beginAttachedSection(String)
*/
public void ensureAttached() {
String attachSectionElement = attachSectionElements.getFirst();
if (!attachedVars.containsKey(attachSectionElement)) {
String attachedVar = "attachRecord" + nextAttachVar;
- addInitStatement(
- "UiBinderUtil.TempAttachment %s = UiBinderUtil.attachToDom(%s);",
+ addInitStatement("UiBinderUtil.TempAttachment %s = UiBinderUtil.attachToDom(%s);",
attachedVar, attachSectionElement);
attachedVars.put(attachSectionElement, attachedVar);
nextAttachVar++;
@@ -686,7 +676,7 @@
* Ensure that the specified field is attached to the DOM. The field must hold
* an object that responds to Element getElement(). Convenience wrapper for
* {@link #ensureAttached}<code>(field + ".getElement()")</code>.
- *
+ *
* @see #beginAttachedSection(String)
*/
public void ensureCurrentFieldAttached() {
@@ -696,12 +686,11 @@
/**
* Finds the JClassType that corresponds to this XMLElement, which must be a
* Widget or an Element.
- *
+ *
* @throws UnableToCompleteException If no such widget class exists
* @throws RuntimeException if asked to handle a non-widget, non-DOM element
*/
- public JClassType findFieldType(XMLElement elem)
- throws UnableToCompleteException {
+ public JClassType findFieldType(XMLElement elem) throws UnableToCompleteException {
String tagName = elem.getLocalName();
if (!isImportedElement(elem)) {
@@ -739,15 +728,13 @@
* Java expression).
*/
public void genPropertySet(String fieldName, String propName, String value) {
- addStatement("%1$s.set%2$s(%3$s);", fieldName,
- capitalizePropName(propName), value);
+ addStatement("%1$s.set%2$s(%3$s);", fieldName, capitalizePropName(propName), value);
}
/**
* Generates the code to set a string property.
*/
- public void genStringPropertySet(String fieldName, String propName,
- String value) {
+ public void genStringPropertySet(String fieldName, String propName, String value) {
genPropertySet(fieldName, propName, "\"" + value + "\"");
}
@@ -817,7 +804,7 @@
public boolean isElementAssignableTo(XMLElement elem, JClassType possibleSupertype)
throws UnableToCompleteException {
/*
- * Things like <W extends IsWidget & IsPlaid>
+ * Things like <W extends IsWidget & IsPlaid>
*/
JTypeParameter typeParameter = possibleSupertype.isTypeParameter();
if (typeParameter != null) {
@@ -829,12 +816,11 @@
}
return true;
}
-
+
/*
- * Binder fields are always declared raw, so we're cheating if the
- * user is playing with parameterized types. We're happy enough if the
- * raw types match, and rely on them to make sure the specific types
- * really do work.
+ * Binder fields are always declared raw, so we're cheating if the user is
+ * playing with parameterized types. We're happy enough if the raw types
+ * match, and rely on them to make sure the specific types really do work.
*/
JParameterizedType parameterized = possibleSupertype.isParameterized();
if (parameterized != null) {
@@ -850,7 +836,7 @@
public boolean isImportedElement(XMLElement elem) {
String uri = elem.getNamespaceUri();
- return uri != null && uri.startsWith(PACKAGE_URI_SCHEME);
+ return uri != null && uri.startsWith(PACKAGE_URI_SCHEME);
}
/**
@@ -865,8 +851,7 @@
return lazyDomElementClass.isAssignableFrom(ownerField.getType().getRawType());
}
- public boolean isRenderableElement(XMLElement elem)
- throws UnableToCompleteException {
+ public boolean isRenderableElement(XMLElement elem) throws UnableToCompleteException {
return findFieldType(elem).isAssignableTo(isRenderableClassType);
}
@@ -883,19 +868,18 @@
* name of the field (possibly private) that will hold it. The element is
* likely to make recursive calls back to this method to have its children
* parsed.
- *
+ *
* @param elem the xml element to be parsed
* @return the name of the field containing the parsed widget
*/
- public String parseElementToField(XMLElement elem)
- throws UnableToCompleteException {
+ public String parseElementToField(XMLElement elem) throws UnableToCompleteException {
/**
* TODO(hermes,rjrjr,rdcastro): seems bad we have to run
- * parseElementToFieldWriter(), get the field writer and
- * then call fieldManager.convertFieldToGetter().
- *
+ * parseElementToFieldWriter(), get the field writer and then call
+ * fieldManager.convertFieldToGetter().
+ *
* Can't we move convertFieldToGetter() to FieldWriter?
- *
+ *
* The current answer is no because convertFieldToGetter() might be called
* before a given FieldWriter is actually created.
*/
@@ -907,12 +891,11 @@
* Parses the object associated with the specified element, and returns the
* field writer that will hold it. The element is likely to make recursive
* calls back to this method to have its children parsed.
- *
+ *
* @param elem the xml element to be parsed
* @return the field holder just created
*/
- public FieldWriter parseElementToFieldWriter(XMLElement elem)
- throws UnableToCompleteException {
+ public FieldWriter parseElementToFieldWriter(XMLElement elem) throws UnableToCompleteException {
if (elementParsers.isEmpty()) {
registerParsers();
}
@@ -942,7 +925,7 @@
/**
* Gives the writer the initializer to use for this field instead of the
* default GWT.create call.
- *
+ *
* @throws IllegalStateException if an initializer has already been set
*/
public void setFieldInitializer(String fieldName, String factoryMethod) {
@@ -952,15 +935,14 @@
/**
* Instructs the writer to initialize the field with a specific constructor
* invocation, instead of the default GWT.create call.
- *
+ *
* @param fieldName the field to initialize
* @param type the type of the field
* @param args arguments to the constructor call
*/
- public void setFieldInitializerAsConstructor(String fieldName,
- JClassType type, String... args) {
- setFieldInitializer(fieldName, formatCode("new %s(%s)",
- type.getQualifiedSourceName(), asCommaSeparatedList(args)));
+ public void setFieldInitializerAsConstructor(String fieldName, JClassType type, String... args) {
+ setFieldInitializer(fieldName, formatCode("new %s(%s)", type.getQualifiedSourceName(),
+ asCommaSeparatedList(args)));
}
/**
@@ -969,7 +951,7 @@
* like translated messages with simple formatting. Wrapped in a call to
* {@link com.google.gwt.safehtml.shared.SafeHtmlUtils#fromSafeConstant} to
* keep the expression from being escaped by the SafeHtml template.
- *
+ *
* @param expression must resolve to trusted HTML string
*/
public String tokenForSafeConstant(String expression) {
@@ -1004,7 +986,7 @@
* token, surrounded by plus signs. This is useful in strings to be handed to
* setInnerHTML() and setText() calls, to allow a unique dom id attribute or
* other runtime expression in the string.
- *
+ *
* @param expression must resolve to String
*/
public String tokenForStringExpression(String expression) {
@@ -1047,16 +1029,15 @@
* Entry point for the code generation logic. It generates the
* implementation's superstructure, and parses the root widget (leading to all
* of its children being parsed as well).
- *
+ *
* @param doc TODO
*/
- void parseDocument(Document doc, PrintWriter printWriter)
- throws UnableToCompleteException {
+ void parseDocument(Document doc, PrintWriter printWriter) throws UnableToCompleteException {
Element documentElement = doc.getDocumentElement();
gwtPrefix = documentElement.lookupPrefix(binderUri);
- XMLElement elem = new XMLElementProviderImpl(attributeParsers,
- oracle, logger, designTime).get(documentElement);
+ XMLElement elem =
+ new XMLElementProviderImpl(attributeParsers, oracle, logger, designTime).get(documentElement);
this.rendered = tokenator.detokenate(parseDocumentElement(elem));
printWriter.print(rendered);
}
@@ -1067,31 +1048,28 @@
private void addWidgetParser(String className) {
String gwtClass = "com.google.gwt.user.client.ui." + className;
- String parser = "com.google.gwt.uibinder.elementparsers." + className
- + "Parser";
+ String parser = "com.google.gwt.uibinder.elementparsers." + className + "Parser";
addElementParser(gwtClass, parser);
}
/**
* Ensures that all of the internal data structures are cleaned up correctly
* at the end of parsing the document.
- *
+ *
* @throws IllegalStateException
*/
private void ensureAttachmentCleanedUp() {
if (!attachSectionElements.isEmpty()) {
- throw new IllegalStateException("Attachments not cleaned up: "
- + attachSectionElements);
+ throw new IllegalStateException("Attachments not cleaned up: " + attachSectionElements);
}
if (!detachStatementsStack.isEmpty()) {
- throw new IllegalStateException("Detach not cleaned up: "
- + detachStatementsStack);
+ throw new IllegalStateException("Detach not cleaned up: " + detachStatementsStack);
}
}
/**
- * Evaluate whether all @UiField attributes are also defined in the
- * template. Dies if not.
+ * Evaluate whether all @UiField attributes are also defined in the template.
+ * Dies if not.
*/
private void evaluateUiFields() throws UnableToCompleteException {
if (designTime.isDesignTime()) {
@@ -1103,8 +1081,8 @@
if (fieldWriter == null) {
die("Template %s has no %s attribute for %s.%s#%s", templatePath,
- getUiFieldAttributeName(), uiOwnerType.getPackage().getName(),
- uiOwnerType.getName(), fieldName);
+ getUiFieldAttributeName(), uiOwnerType.getPackage().getName(), uiOwnerType.getName(),
+ fieldName);
}
}
}
@@ -1140,7 +1118,7 @@
/**
* Inspects this element for a gwt:field attribute. If one is found, the
* attribute is consumed and its value returned.
- *
+ *
* @return The field name declared by an element, or null if none is declared
*/
private String getFieldName(XMLElement elem) throws UnableToCompleteException {
@@ -1151,8 +1129,8 @@
// If an id is specified on the element, use that.
fieldName = elem.consumeRawAttribute("id");
warn(elem, "Deprecated use of id=\"%1$s\" for field name. "
- + "Please switch to gwt:field=\"%1$s\" instead. "
- + "This will soon be a compile error!", fieldName);
+ + "Please switch to gwt:field=\"%1$s\" instead. " + "This will soon be a compile error!",
+ fieldName);
}
if (elem.hasAttribute(getUiFieldAttributeName())) {
if (hasOldSchoolId) {
@@ -1183,7 +1161,7 @@
/**
* Find a set of element parsers for the given ui type.
- *
+ *
* The list of parsers will be returned in order from most- to least-specific.
*/
private Iterable<ElementParser> getParsersForClass(JClassType type) {
@@ -1192,7 +1170,7 @@
/*
* Let this non-widget parser go first (it finds <m:attribute/> elements).
* Any other such should land here too.
- *
+ *
* TODO(rjrjr) Need a scheme to associate these with a namespace uri or
* something?
*/
@@ -1207,11 +1185,9 @@
parsers.add(parser);
}
} catch (InstantiationException e) {
- throw new RuntimeException(
- "Unable to instantiate " + curType.getName(), e);
+ throw new RuntimeException("Unable to instantiate " + curType.getName(), e);
} catch (IllegalAccessException e) {
- throw new RuntimeException(
- "Unable to instantiate " + curType.getName(), e);
+ throw new RuntimeException("Unable to instantiate " + curType.getName(), e);
}
}
@@ -1225,9 +1201,8 @@
* Writes a field setter if the field is not provided and the field class is
* compatible with its respective template field.
*/
- private void maybeWriteFieldSetter(IndentedWriter niceWriter,
- OwnerField ownerField, JClassType templateClass, String templateField)
- throws UnableToCompleteException {
+ private void maybeWriteFieldSetter(IndentedWriter niceWriter, OwnerField ownerField,
+ JClassType templateClass, String templateField) throws UnableToCompleteException {
JClassType fieldType = ownerField.getType().getRawType();
if (!ownerField.isProvided()) {
@@ -1236,27 +1211,23 @@
* the @UiField annotated field in the owning class
*/
if (!templateClass.isAssignableTo(fieldType)) {
- die(
- "In @UiField %s, template field and owner field types don't match: %s is not assignable to %s",
+ die("In @UiField %s, template field and owner field types don't match: %s is not assignable to %s",
ownerField.getName(), templateClass.getQualifiedSourceName(),
fieldType.getQualifiedSourceName());
}
/*
* And initialize the field
*/
- niceWriter.write("owner.%1$s = %2$s;", ownerField.getName(),
- templateField);
+ niceWriter.write("owner.%1$s = %2$s;", ownerField.getName(), templateField);
} else {
/*
* But with @UiField(provided=true) the user builds it, so reverse the
* direction of the assignability check and do no init.
*/
if (!fieldType.isAssignableTo(templateClass)) {
- die(
- "In UiField(provided = true) %s, template field and field types don't match: "
- + "@UiField(provided=true)%s is not assignable to %s",
- ownerField.getName(), fieldType.getQualifiedSourceName(),
- templateClass.getQualifiedSourceName());
+ die("In UiField(provided = true) %s, template field and field types don't match: "
+ + "@UiField(provided=true)%s is not assignable to %s", ownerField.getName(),
+ fieldType.getQualifiedSourceName(), templateClass.getQualifiedSourceName());
}
}
}
@@ -1272,23 +1243,19 @@
* Parse the document element and return the source of the Java class that
* will implement its UiBinder.
*/
- private String parseDocumentElement(XMLElement elem)
- throws UnableToCompleteException {
- fieldManager.registerFieldOfGeneratedType(
- oracle.findType(ClientBundle.class.getName()),
- bundleClass.getPackageName(), bundleClass.getClassName(),
- bundleClass.getFieldName());
+ private String parseDocumentElement(XMLElement elem) throws UnableToCompleteException {
+ fieldManager.registerFieldOfGeneratedType(oracle.findType(ClientBundle.class.getName()),
+ bundleClass.getPackageName(), bundleClass.getClassName(), bundleClass.getFieldName());
// Allow GWT.create() to init the field, the default behavior
- String rootField = new UiBinderParser(this, messages, fieldManager, oracle,
- bundleClass, binderUri).parse(elem);
+ String rootField =
+ new UiBinderParser(this, messages, fieldManager, oracle, bundleClass, binderUri).parse(elem);
fieldManager.validate();
StringWriter stringWriter = new StringWriter();
- IndentedWriter niceWriter = new IndentedWriter(
- new PrintWriter(stringWriter));
+ IndentedWriter niceWriter = new IndentedWriter(new PrintWriter(stringWriter));
if (isRenderer) {
writeRenderer(niceWriter, rootField);
@@ -1308,11 +1275,10 @@
/**
* Parses a package uri (e.g., package://com.google...).
- *
+ *
* @throws UnableToCompleteException on bad package name
*/
- private JPackage parseNamespacePackage(String ns)
- throws UnableToCompleteException {
+ private JPackage parseNamespacePackage(String ns) throws UnableToCompleteException {
if (ns.startsWith(PACKAGE_URI_SCHEME)) {
String pkgName = ns.substring(PACKAGE_URI_SCHEME.length());
@@ -1369,26 +1335,25 @@
/**
* Scan the base class for the getter methods. Assumes getters begin with
- * "get" and validates that each corresponds to a field declared with {@code ui:field},
- * it has a single parameter, the parameter type is assignable to {@code Element} and
- * its return type is assignable to {@code Element}.
+ * "get" and validates that each corresponds to a field declared with
+ * {@code ui:field}, it has a single parameter, the parameter type is
+ * assignable to {@code Element} and its return type is assignable to
+ * {@code Element}.
*/
private void validateRendererGetters(JClassType owner) throws UnableToCompleteException {
for (JMethod jMethod : owner.getMethods()) {
String getterName = jMethod.getName();
if (getterName.startsWith("get")) {
if (jMethod.getParameterTypes().length != 1) {
- die("Getter %s must have exactly one parameter",
- getterName);
+ die("Getter %s must have exactly one parameter", getterName);
}
String elementClassName = com.google.gwt.dom.client.Element.class.getCanonicalName();
JClassType elementType = oracle.findType(elementClassName);
- JClassType getterParamType = jMethod.getParameterTypes()[0].getErasedType()
- .isClassOrInterface();
+ JClassType getterParamType =
+ jMethod.getParameterTypes()[0].getErasedType().isClassOrInterface();
if (!elementType.isAssignableFrom(getterParamType)) {
- die("Getter %s must have exactly one parameter of type assignable to %s",
- getterName,
+ die("Getter %s must have exactly one parameter of type assignable to %s", getterName,
elementClassName);
}
String fieldName = getterToFieldName(getterName);
@@ -1416,8 +1381,7 @@
if (renderMethod == null) {
renderMethod = jMethod;
} else {
- die("%s declares more than one method named render",
- baseClass.getQualifiedSourceName());
+ die("%s declares more than one method named render", baseClass.getQualifiedSourceName());
}
}
}
@@ -1430,8 +1394,7 @@
baseClass.getQualifiedSourceName());
}
if (!JPrimitiveType.VOID.equals(renderMethod.getReturnType())) {
- die("%s#render(SafeHtmlBuilder ...) does not return void",
- baseClass.getQualifiedSourceName());
+ die("%s#render(SafeHtmlBuilder ...) does not return void", baseClass.getQualifiedSourceName());
}
}
@@ -1449,8 +1412,7 @@
/**
* Writes the UiBinder's source.
*/
- private void writeBinder(IndentedWriter w, String rootField)
- throws UnableToCompleteException {
+ private void writeBinder(IndentedWriter w, String rootField) throws UnableToCompleteException {
writePackage(w);
writeImports(w);
@@ -1497,11 +1459,10 @@
}
/**
- * Writes a different optimized UiBinder's source for the renderable
- * strategy.
+ * Writes a different optimized UiBinder's source for the renderable strategy.
*/
- private void writeBinderForRenderableStrategy(
- IndentedWriter w, String rootField) throws UnableToCompleteException {
+ private void writeBinderForRenderableStrategy(IndentedWriter w, String rootField)
+ throws UnableToCompleteException {
writePackage(w);
writeImports(w);
@@ -1554,8 +1515,7 @@
evaluateUiFields();
- fieldManager.writeFieldDefinitions(
- w, getOracle(), getOwnerClass(), getDesignTime());
+ fieldManager.writeFieldDefinitions(w, getOracle(), getOwnerClass(), getDesignTime());
w.outdent();
w.write("}");
@@ -1573,8 +1533,7 @@
baseClass.getParameterizedQualifiedSourceName());
} else {
w.write("public class %s extends %s<%s> implements %s {", implClassName,
- AbstractUiRenderer.class.getName(),
- uiOwnerType.getParameterizedQualifiedSourceName(),
+ AbstractUiRenderer.class.getName(), uiOwnerType.getParameterizedQualifiedSourceName(),
baseClass.getParameterizedQualifiedSourceName());
}
w.indent();
@@ -1582,8 +1541,7 @@
private void writeCssInjectors(IndentedWriter w) {
for (ImplicitCssResource css : bundleClass.getCssMethods()) {
- w.write("%s.%s().ensureInjected();", bundleClass.getFieldName(),
- css.getName());
+ w.write("%s.%s().ensureInjected();", bundleClass.getFieldName(), css.getName());
}
w.newline();
}
@@ -1593,11 +1551,10 @@
* gwt:field in the template. For those that have not had constructor
* generation suppressed, emit GWT.create() calls instantiating them (or die
* if they have no default constructor).
- *
+ *
* @throws UnableToCompleteException on constructor problem
*/
- private void writeGwtFields(IndentedWriter niceWriter)
- throws UnableToCompleteException {
+ private void writeGwtFields(IndentedWriter niceWriter) throws UnableToCompleteException {
// For each provided field in the owner class, initialize from the owner
Collection<OwnerField> ownerFields = getOwnerClass().getUiFields();
for (OwnerField ownerField : ownerFields) {
@@ -1610,8 +1567,7 @@
String initializer;
if (designTime.isDesignTime()) {
String typeName = ownerField.getType().getRawType().getQualifiedSourceName();
- initializer = designTime.getProvidedField(typeName,
- ownerField.getName());
+ initializer = designTime.getProvidedField(typeName, ownerField.getName());
} else {
initializer = formatCode("owner.%1$s", fieldName);
}
@@ -1644,8 +1600,7 @@
if (!isRenderer) {
w.write("import com.google.gwt.uibinder.client.UiBinder;");
w.write("import com.google.gwt.uibinder.client.UiBinderUtil;");
- w.write("import %s.%s;", uiRootType.getPackage().getName(),
- uiRootType.getName());
+ w.write("import %s.%s;", uiRootType.getPackage().getName(), uiRootType.getName());
} else {
w.write("import com.google.gwt.text.shared.AbstractSafeHtmlRenderer;");
w.write("import com.google.gwt.uibinder.client.UiRendererUtilsImpl;");
@@ -1665,8 +1620,7 @@
/**
* Write the statements to fill in the fields of the UI owner.
*/
- private void writeOwnerFieldSetters(IndentedWriter niceWriter)
- throws UnableToCompleteException {
+ private void writeOwnerFieldSetters(IndentedWriter niceWriter) throws UnableToCompleteException {
if (designTime.isDesignTime()) {
return;
}
@@ -1678,8 +1632,8 @@
// ownerField is a widget.
JClassType type = fieldWriter.getInstantiableType();
if (type != null) {
- maybeWriteFieldSetter(niceWriter, ownerField,
- fieldWriter.getInstantiableType(), fieldName);
+ maybeWriteFieldSetter(niceWriter, ownerField, fieldWriter.getInstantiableType(),
+ fieldName);
} else {
// Must be a generated type
if (!ownerField.isProvided()) {
@@ -1690,8 +1644,8 @@
} else {
// ownerField was not found as bundle resource or widget, must die.
die("Template %s has no %s attribute for %s.%s#%s", templatePath,
- getUiFieldAttributeName(), uiOwnerType.getPackage().getName(),
- uiOwnerType.getName(), fieldName);
+ getUiFieldAttributeName(), uiOwnerType.getPackage().getName(), uiOwnerType.getName(),
+ fieldName);
}
}
}
@@ -1705,8 +1659,7 @@
}
/**
- * Writes the UiRenderer's source for the renderable
- * strategy.
+ * Writes the UiRenderer's source for the renderable strategy.
*/
private void writeRenderer(IndentedWriter w, String rootField) throws UnableToCompleteException {
validateRendererGetters(baseClass);
@@ -1732,8 +1685,7 @@
String renderParameterDeclarations = renderMethodParameters(renderParameters);
w.write("public void render(final %s sb%s%s) {", SafeHtmlBuilder.class.getName(),
- renderParameterDeclarations.length() != 0 ? ", " : "",
- renderParameterDeclarations);
+ renderParameterDeclarations.length() != 0 ? ", " : "", renderParameterDeclarations);
w.indent();
w.newline();
@@ -1749,8 +1701,10 @@
String rootFieldName = rootField.substring(4, rootField.length() - 2);
String safeHtml = fieldManager.lookup(rootFieldName).getSafeHtml();
- // TODO(rchandia) it should be possible to add the attribute when parsing the UiBinder file
- w.write("sb.append(UiRendererUtilsImpl.stampUiRendererAttribute(%s, RENDERED_ATTRIBUTE, uiId));",
+ // TODO(rchandia) it should be possible to add the attribute when parsing
+ // the UiBinder file
+ w.write(
+ "sb.append(UiRendererUtilsImpl.stampUiRendererAttribute(%s, RENDERED_ATTRIBUTE, uiId));",
safeHtml);
w.outdent();
diff --git a/user/src/com/google/gwt/uibinder/rebind/XMLAttribute.java b/user/src/com/google/gwt/uibinder/rebind/XMLAttribute.java
index e584ac2..39862ce 100644
--- a/user/src/com/google/gwt/uibinder/rebind/XMLAttribute.java
+++ b/user/src/com/google/gwt/uibinder/rebind/XMLAttribute.java
@@ -1,12 +1,12 @@
/*
* Copyright 2008 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
@@ -21,8 +21,8 @@
import org.w3c.dom.Attr;
/**
- * Like {@link XMLElement}, a wrapper around {@link Attr} to keep
- * parser writers out of trouble.
+ * Like {@link XMLElement}, a wrapper around {@link Attr} to keep parser writers
+ * out of trouble.
*/
public class XMLAttribute {
private XMLElement xmlElem;
@@ -36,11 +36,11 @@
public String consumeRawValue() {
return xmlElem.consumeRawAttribute(w3cAttr.getName());
}
-
+
public String consumeSafeHtmlValue() throws UnableToCompleteException {
return xmlElem.consumeSafeHtmlAttribute(w3cAttr.getName());
}
-
+
public String consumeStringValue() throws UnableToCompleteException {
return xmlElem.consumeStringAttribute(w3cAttr.getName());
}
@@ -75,7 +75,7 @@
@Override
public String toString() {
- return String.format("<%s:%s ... %s=%s ...>", xmlElem.getPrefix(),
- xmlElem.getLocalName(), w3cAttr.getName(), w3cAttr.getValue());
+ return String.format("<%s:%s ... %s=%s ...>", xmlElem.getPrefix(), xmlElem.getLocalName(),
+ w3cAttr.getName(), w3cAttr.getValue());
}
}
diff --git a/user/src/com/google/gwt/uibinder/rebind/XMLElement.java b/user/src/com/google/gwt/uibinder/rebind/XMLElement.java
index dfa4e9d..64a9629 100644
--- a/user/src/com/google/gwt/uibinder/rebind/XMLElement.java
+++ b/user/src/com/google/gwt/uibinder/rebind/XMLElement.java
@@ -1,12 +1,12 @@
/*
* Copyright 2008 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
@@ -57,7 +57,7 @@
public interface Interpreter<T> {
/**
* Given an XMLElement, return its filtered value.
- *
+ *
* @throws UnableToCompleteException on error
*/
T interpretElement(XMLElement elem) throws UnableToCompleteException;
@@ -144,7 +144,7 @@
private JType intType;
private JType stringType;
private JType safeHtmlType;
-
+
{
// from com/google/gxp/compiler/schema/html.xml
NO_END_TAG.add("area");
@@ -163,10 +163,7 @@
NO_END_TAG.add("wbr");
}
- XMLElement(
- Element elem,
- AttributeParsers attributeParsers,
- TypeOracle oracle,
+ XMLElement(Element elem, AttributeParsers attributeParsers, TypeOracle oracle,
MortalLogger logger, DesignTimeUtils designTime, XMLElementProvider provider) {
this.elem = elem;
this.attributeParsers = attributeParsers;
@@ -180,7 +177,7 @@
/**
* Ensure that the receiver has no attributes left.
- *
+ *
* @throws UnableToCompleteException if it does
*/
public void assertNoAttributes() throws UnableToCompleteException {
@@ -201,13 +198,12 @@
/**
* Require that the receiver's body is empty of text and has no child nodes.
- *
+ *
* @throws UnableToCompleteException if it isn't
*/
public void assertNoBody() throws UnableToCompleteException {
consumeChildElements(new Interpreter<Boolean>() {
- public Boolean interpretElement(XMLElement elem)
- throws UnableToCompleteException {
+ public Boolean interpretElement(XMLElement elem) throws UnableToCompleteException {
logger.die(elem, "Found unexpected child element");
return false; // unreachable
}
@@ -217,12 +213,11 @@
/**
* Require that the receiver's body is empty of text.
- *
+ *
* @throws UnableToCompleteException if it isn't
*/
public void assertNoText() throws UnableToCompleteException {
- NoBrainInterpeter<String> nullInterpreter = new NoBrainInterpeter<String>(
- null);
+ NoBrainInterpeter<String> nullInterpreter = new NoBrainInterpeter<String>(null);
String s = consumeInnerTextEscapedAsHtmlStringLiteral(nullInterpreter);
if (!"".equals(s)) {
logger.die(this, "Unexpected text in element: \"%s\"", s);
@@ -232,22 +227,21 @@
/**
* Consumes the given attribute as a literal or field reference. The type
* parameter is required to determine how the value is parsed and validated.
- *
+ *
* @param name the attribute's full name (including prefix)
* @param type the type this attribute is expected to provide
* @return the attribute's value as a Java expression, or null if it is not
* set
* @throws UnableToCompleteException on parse failure
*/
- public String consumeAttribute(String name, JType type)
- throws UnableToCompleteException {
+ public String consumeAttribute(String name, JType type) throws UnableToCompleteException {
return consumeAttributeWithDefault(name, null, type);
}
/**
* Consumes the given attribute as a literal or field reference. The type
* parameter is required to determine how the value is parsed and validated.
- *
+ *
* @param name the attribute's full name (including prefix)
* @param defaultValue the value to @return if the attribute was unset
* @param type the type this attribute is expected to provide
@@ -255,8 +249,8 @@
* it was unset
* @throws UnableToCompleteException on parse failure
*/
- public String consumeAttributeWithDefault(String name, String defaultValue,
- JType type) throws UnableToCompleteException {
+ public String consumeAttributeWithDefault(String name, String defaultValue, JType type)
+ throws UnableToCompleteException {
return consumeAttributeWithDefault(name, defaultValue, new JType[]{type});
}
@@ -264,8 +258,8 @@
* Like {@link #consumeAttributeWithDefault(String, String, JType)}, but
* accommodates more complex type signatures.
*/
- public String consumeAttributeWithDefault(String name, String defaultValue,
- JType[] types) throws UnableToCompleteException {
+ public String consumeAttributeWithDefault(String name, String defaultValue, JType[] types)
+ throws UnableToCompleteException {
XMLAttribute attribute = getAttribute(name);
if (attribute == null) {
if (defaultValue != null) {
@@ -292,45 +286,42 @@
/**
* Convenience method for parsing the named attribute as a boolean value or
* reference.
- *
+ *
* @return an expression that will evaluate to a boolean value in the
* generated code, or null if there is no such attribute
- *
+ *
* @throws UnableToCompleteException on unparseable value
*/
- public String consumeBooleanAttribute(String name)
- throws UnableToCompleteException {
+ public String consumeBooleanAttribute(String name) throws UnableToCompleteException {
return consumeAttribute(name, getBooleanType());
}
/**
* Convenience method for parsing the named attribute as a boolean value or
* reference.
- *
+ *
* @param defaultValue value to return if attribute was not set
* @return an expression that will evaluate to a boolean value in the
* generated code, or defaultValue if there is no such attribute
- *
+ *
* @throws UnableToCompleteException on unparseable value
*/
public String consumeBooleanAttribute(String name, boolean defaultValue)
throws UnableToCompleteException {
- return consumeAttributeWithDefault(name, Boolean.toString(defaultValue),
- getBooleanType());
+ return consumeAttributeWithDefault(name, Boolean.toString(defaultValue), getBooleanType());
}
/**
* Consumes the named attribute as a boolean expression. This will not accept
* {field.reference} expressions. Useful for values that must be resolved at
* compile time, such as generated annotation values.
- *
+ *
* @return {@link Boolean#TRUE}, {@link Boolean#FALSE}, or null if no such
* attribute
- *
+ *
* @throws UnableToCompleteException on unparseable value
*/
- public Boolean consumeBooleanConstantAttribute(String name)
- throws UnableToCompleteException {
+ public Boolean consumeBooleanConstantAttribute(String name) throws UnableToCompleteException {
String value = consumeRawAttribute(name);
if (value == null) {
return null;
@@ -344,11 +335,10 @@
/**
* Consumes and returns all child elements.
- *
+ *
* @throws UnableToCompleteException if extra text nodes are found
*/
- public Iterable<XMLElement> consumeChildElements()
- throws UnableToCompleteException {
+ public Iterable<XMLElement> consumeChildElements() throws UnableToCompleteException {
Iterable<XMLElement> rtn = consumeChildElementsNoEmptyCheck();
assertNoText();
return rtn;
@@ -358,13 +348,13 @@
* Consumes and returns all child elements selected by the interpreter. Note
* that text nodes are not elements, and so are not presented for
* interpretation, and are not consumed.
- *
+ *
* @param interpreter Should return true for any child that should be consumed
* and returned by the consumeChildElements call
* @throws UnableToCompleteException
*/
- public Collection<XMLElement> consumeChildElements(
- Interpreter<Boolean> interpreter) throws UnableToCompleteException {
+ public Collection<XMLElement> consumeChildElements(Interpreter<Boolean> interpreter)
+ throws UnableToCompleteException {
List<XMLElement> elements = new ArrayList<XMLElement>();
List<Node> doomed = new ArrayList<Node>();
@@ -389,13 +379,12 @@
/**
* Convenience method for parsing the named attribute as an ImageResource
* value or reference.
- *
+ *
* @return an expression that will evaluate to an ImageResource value in the
* generated code, or null if there is no such attribute
* @throws UnableToCompleteException on unparseable value
*/
- public String consumeImageResourceAttribute(String name)
- throws UnableToCompleteException {
+ public String consumeImageResourceAttribute(String name) throws UnableToCompleteException {
return consumeAttribute(name, getImageResourceType());
}
@@ -409,16 +398,14 @@
* <p>
* This call requires an interpreter to make sense of any special children.
* The odds are you want to use
- * {@link com.google.gwt.uibinder.elementparsers.HtmlInterpreter}
- * for an HTML value, or
- * {@link com.google.gwt.uibinder.elementparsers.TextInterpreter}
+ * {@link com.google.gwt.uibinder.elementparsers.HtmlInterpreter} for an HTML
+ * value, or {@link com.google.gwt.uibinder.elementparsers.TextInterpreter}
* for text.
- *
+ *
* @param interpreter Called for each element, expected to return a string
* replacement for it, or null if it should be left as is
*/
- public String consumeInnerHtml(Interpreter<String> interpreter)
- throws UnableToCompleteException {
+ public String consumeInnerHtml(Interpreter<String> interpreter) throws UnableToCompleteException {
if (interpreter == null) {
throw new NullPointerException("interpreter must not be null");
}
@@ -458,26 +445,25 @@
* This call requires an interpreter to make sense of any special children.
* The odds are you want to use
* {@link com.google.gwt.uibinder.elementparsers.TextInterpreter}
- *
+ *
* @throws UnableToCompleteException If any elements present are not consumed
* by the interpreter
*/
- public String consumeInnerTextEscapedAsHtmlStringLiteral(
- Interpreter<String> interpreter) throws UnableToCompleteException {
+ public String consumeInnerTextEscapedAsHtmlStringLiteral(Interpreter<String> interpreter)
+ throws UnableToCompleteException {
if (interpreter == null) {
throw new NullPointerException("interpreter must not be null");
}
StringBuffer buf = new StringBuffer();
- GetEscapedInnerTextVisitor.getEscapedInnerText(elem, buf, interpreter,
- provider);
+ GetEscapedInnerTextVisitor.getEscapedInnerText(elem, buf, interpreter, provider);
// Make sure there are no children left but empty husks
for (XMLElement child : consumeChildElementsNoEmptyCheck()) {
if (child.hasChildNodes() || child.getAttributeCount() > 0) {
logger.die(this, "Illegal child %s in a text-only context. "
- + "Perhaps you are trying to use unescaped HTML "
- + "where text is required, as in a HasText widget?", child);
+ + "Perhaps you are trying to use unescaped HTML "
+ + "where text is required, as in a HasText widget?", child);
}
}
@@ -487,17 +473,15 @@
/**
* Convenience method for parsing the named attribute as a CSS length value.
- *
+ *
* @return a (double, Unit) pair literal, an expression that will evaluate to
* such a pair in the generated code, or null if there is no such
* attribute
- *
+ *
* @throws UnableToCompleteException on unparseable value
*/
- public String consumeLengthAttribute(String name)
- throws UnableToCompleteException {
- return consumeAttributeWithDefault(name, null, new JType[]{
- getDoubleType(), getUnitType()});
+ public String consumeLengthAttribute(String name) throws UnableToCompleteException {
+ return consumeAttributeWithDefault(name, null, new JType[]{getDoubleType(), getUnitType()});
}
/**
@@ -517,7 +501,7 @@
* Consumes the named attribute and parses it to an unparsed, unescaped array
* of Strings. The strings in the attribute may be comma or space separated
* (or a mix of both).
- *
+ *
* @return array of String, empty if the attribute was not set.
*/
public String[] consumeRawArrayAttribute(String name) {
@@ -532,7 +516,7 @@
/**
* Consumes the given attribute and returns its trimmed value, or null if it
* was unset. The returned string is not escaped.
- *
+ *
* @param name the attribute's full name (including prefix)
* @return the attribute's value, or ""
*/
@@ -548,7 +532,7 @@
/**
* Consumes the given attribute and returns its trimmed value, or the given
* default value if it was unset. The returned string is not escaped.
- *
+ *
* @param name the attribute's full name (including prefix)
* @param defaultValue the value to return if the attribute was unset
* @return the attribute's value, or defaultValue
@@ -565,7 +549,7 @@
* Consumes the given required attribute as a literal or field reference. The
* types parameters are required to determine how the value is parsed and
* validated.
- *
+ *
* @param name the attribute's full name (including prefix)
* @param types the type(s) this attribute is expected to provide
* @return the attribute's value as a Java expression
@@ -594,72 +578,68 @@
/**
* Convenience method for parsing the named required attribute as a double
* value or reference.
- *
+ *
* @return a double literal, an expression that will evaluate to a double
* value in the generated code
- *
+ *
* @throws UnableToCompleteException on unparseable value, or if the attribute
* is empty or unspecified
*/
- public String consumeRequiredDoubleAttribute(String name)
- throws UnableToCompleteException {
+ public String consumeRequiredDoubleAttribute(String name) throws UnableToCompleteException {
return consumeRequiredAttribute(name, getDoubleType());
}
/**
* Convenience method for parsing the named required attribute as a integer
* value or reference.
- *
+ *
* @return a integer literal, an expression that will evaluate to a integer
* value in the generated code
- *
+ *
* @throws UnableToCompleteException on unparseable value, or if the attribute
* is empty or unspecified
*/
- public String consumeRequiredIntAttribute(String name)
- throws UnableToCompleteException {
+ public String consumeRequiredIntAttribute(String name) throws UnableToCompleteException {
return consumeRequiredAttribute(name, getIntType());
}
/**
* Consumes the named attribute, or dies if it is missing.
*/
- public String consumeRequiredRawAttribute(String name)
- throws UnableToCompleteException {
+ public String consumeRequiredRawAttribute(String name) throws UnableToCompleteException {
String value = consumeRawAttribute(name);
if (value == null) {
failRequired(name);
}
return value;
}
-
+
/**
- * Convenience method for parsing the named attribute as a
- * {@link com.google.gwt.safehtml.shared.SafeHtml SafeHtml} value or reference.
- *
- * @return an expression that will evaluate to a
- * {@link com.google.gwt.safehtml.shared.SafeHtml SafeHtml} value in
- * the generated code, or null if there is no such attribute
- * @throws UnableToCompleteException on unparseable value
- */
- public String consumeSafeHtmlAttribute(String name)
- throws UnableToCompleteException {
+ * Convenience method for parsing the named attribute as a
+ * {@link com.google.gwt.safehtml.shared.SafeHtml SafeHtml} value or
+ * reference.
+ *
+ * @return an expression that will evaluate to a
+ * {@link com.google.gwt.safehtml.shared.SafeHtml SafeHtml} value in
+ * the generated code, or null if there is no such attribute
+ * @throws UnableToCompleteException on unparseable value
+ */
+ public String consumeSafeHtmlAttribute(String name) throws UnableToCompleteException {
return consumeAttribute(name, getSafeHtmlType());
}
+
/**
* Consumes a single child element, ignoring any text nodes and throwing an
* exception if no child is found, or more than one child element is found.
- *
+ *
* @throws UnableToCompleteException on no children, or too many
*/
- public XMLElement consumeSingleChildElement()
- throws UnableToCompleteException {
+ public XMLElement consumeSingleChildElement() throws UnableToCompleteException {
XMLElement ret = null;
for (XMLElement child : consumeChildElements()) {
if (ret != null) {
- logger.die(this,
- "Element may only contain a single child element, but "
- + "found %s and %s.", ret, child);
+ logger.die(this, "Element may only contain a single child element, but "
+ + "found %s and %s.", ret, child);
}
ret = child;
@@ -676,12 +656,11 @@
* Consumes the named attribute and parses it to an array of String
* expressions. The strings in the attribute may be comma or space separated
* (or a mix of both).
- *
+ *
* @return array of String expressions, empty if the attribute was not set.
* @throws UnableToCompleteException on unparseable value
*/
- public String[] consumeStringArrayAttribute(String name)
- throws UnableToCompleteException {
+ public String[] consumeStringArrayAttribute(String name) throws UnableToCompleteException {
AttributeParser parser = attributeParsers.get(getStringType());
String[] strings = consumeRawArrayAttribute(name);
@@ -700,20 +679,19 @@
/**
* Convenience method for parsing the named attribute as a String value or
* reference.
- *
+ *
* @return an expression that will evaluate to a String value in the generated
* code, or null if there is no such attribute
* @throws UnableToCompleteException on unparseable value
*/
- public String consumeStringAttribute(String name)
- throws UnableToCompleteException {
+ public String consumeStringAttribute(String name) throws UnableToCompleteException {
return consumeAttribute(name, getStringType());
}
/**
* Convenience method for parsing the named attribute as a String value or
* reference.
- *
+ *
* @return an expression that will evaluate to a String value in the generated
* code, or the given defaultValue if there is no such attribute
* @throws UnableToCompleteException on unparseable value
@@ -729,7 +707,7 @@
* <p>
* You probably want to use
* {@link #consumeInnerTextEscapedAsHtmlStringLiteral} instead.
- *
+ *
* @return the text
* @throws UnableToCompleteException if it held anything other than text nodes
*/
@@ -738,8 +716,7 @@
if (children.getLength() < 1) {
return "";
}
- if (children.getLength() > 1
- || Node.TEXT_NODE != children.item(0).getNodeType()) {
+ if (children.getLength() > 1 || Node.TEXT_NODE != children.item(0).getNodeType()) {
logger.die(this, "Element must contain only text");
}
Text t = (Text) children.item(0);
@@ -751,13 +728,12 @@
* remember to traverse them in reverse.
*/
public XMLAttribute getAttribute(int i) {
- return new XMLAttribute(XMLElement.this,
- (Attr) elem.getAttributes().item(i));
+ return new XMLAttribute(XMLElement.this, (Attr) elem.getAttributes().item(i));
}
/**
* Get the attribute with the given name.
- *
+ *
* @return the attribute, or null if there is none of that name
*/
public XMLAttribute getAttribute(String name) {
@@ -855,8 +831,7 @@
private Iterable<XMLElement> consumeChildElementsNoEmptyCheck() {
try {
- Iterable<XMLElement> rtn = consumeChildElements(new NoBrainInterpeter<Boolean>(
- true));
+ Iterable<XMLElement> rtn = consumeChildElements(new NoBrainInterpeter<Boolean>(true));
return rtn;
} catch (UnableToCompleteException e) {
throw new RuntimeException("Impossible exception", e);
@@ -930,7 +905,7 @@
}
return safeHtmlType;
}
-
+
private JType getStringType() {
if (stringType == null) {
stringType = oracle.findType(String.class.getCanonicalName());