本文整理汇总了Java中com.google.gwt.core.ext.Generator类的典型用法代码示例。如果您正苦于以下问题:Java Generator类的具体用法?Java Generator怎么用?Java Generator使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Generator类属于com.google.gwt.core.ext包,在下文中一共展示了Generator类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getValueToOutput
import com.google.gwt.core.ext.Generator; //导入依赖的package包/类
private static <T> String getValueToOutput(Key<T> key, T instance) {
Type type = key.getTypeLiteral().getType();
if (type == String.class) {
return "\"" + Generator.escape(instance.toString()) + "\"";
} else if (type == Class.class) {
return toClassReference((Class<?>) instance);
} else if (type == Character.class) {
return "'" + (Character.valueOf('\'').equals(instance) ? "\\" : "") + instance + "'";
} else if (type == Float.class) {
return instance.toString() + "f";
} else if (type == Long.class) {
return instance.toString() + "L";
} else if (type == Double.class) {
return instance.toString() + "d";
} else if (instance instanceof Number || instance instanceof Boolean) {
return instance.toString(); // Includes int & short.
} else if (instance instanceof Enum) {
return toEnumReference(((Enum<?>) instance));
} else {
throw new IllegalArgumentException("Attempted to create a constant binding with a "
+ "non-constant type: " + type);
}
}
示例2: resolveExpression
import com.google.gwt.core.ext.Generator; //导入依赖的package包/类
public static String resolveExpression(String instance, String path, String prefix, String suffix) {
String expression = path.replace(".", "().") + "()";
if (!Strings.isNullOrEmpty(instance)) {
expression = instance + "." + expression;
}
if (!Strings.isNullOrEmpty(prefix)) {
expression = "\"" + Generator.escape(prefix) + "\" + " + expression;
}
if (!Strings.isNullOrEmpty(suffix)) {
expression += " + \"" + Generator.escape(suffix) + "\"";
}
return expression;
}
示例3: doRebind
import com.google.gwt.core.ext.Generator; //导入依赖的package包/类
public JExpression doRebind(final String clsName, final ReflectionGeneratorContext params) throws UnableToCompleteException {
// generate
params.getLogger().log(Type.INFO, "Binding magic class for " + clsName);
// JType type = params.getClazz().getRefType();
final JDeclaredType type = params.getAst().searchForTypeBySource(params.getClazz().getRefType().getName());
final StandardGeneratorContext ctx = params.getGeneratorContext();
final Class<? extends Generator> generator = MagicClassGenerator.class;
final String result = ctx.runGenerator(params.getLogger(), generator,
SourceUtil.toSourceName(type.getName()));
ctx.finish(params.getLogger());
params.getLogger().log(Type.INFO, "Generated Class Enhancer: " + result);
final JDeclaredType success = params.getAst().searchForTypeBySource(result);
// Okay, we've generated the correct magic class subtype;
// Now pull off its static accessor method to grab our generated class.
for (final JMethod method : success.getMethods()) {
if (method.isStatic() && method.getName().equals("enhanceClass")) {
final JMethodCall call = new JMethodCall(method.getSourceInfo(), null, method);
call.addArg(params.getClazz().makeStatement().getExpr());
return call;
}
}
params.getLogger().log(Type.ERROR, "Unable to load " + result + ".enhanceClass()");
throw new UnableToCompleteException();
}
示例4: flushInternalStringBuilder
import com.google.gwt.core.ext.Generator; //导入依赖的package包/类
/**
* Read what the internal StringBuilder used by the CompactPrinter has already built. Escape it.
* and reset the internal StringBuilder
* @return
*/
private String flushInternalStringBuilder() {
String content = "\"" + Generator.escape(sb.toString()) + "\"";
sb = new StringBuilder();
return content;
}
示例5: asLiteral
import com.google.gwt.core.ext.Generator; //导入依赖的package包/类
/**
* Returns the literal value of an object that is suitable for inclusion in Java Source code.
*
* <p>
* Supports all types that {@link Annotation} value can have.
* </p>
*
*
* @throws IllegalArgumentException if the type of the object does not have a java literal form.
*/
public static String asLiteral(final Object value) throws IllegalArgumentException {
final Class<?> clazz = value.getClass();
if (clazz.isArray()) {
final StringBuilder sb = new StringBuilder();
final Object[] array = (Object[]) value;
sb.append("new " + clazz.getComponentType().getCanonicalName() + "[] {");
boolean first = true;
for (final Object object : array) {
if (first) {
first = false;
} else {
sb.append(',');
}
sb.append(asLiteral(object));
}
sb.append('}');
return sb.toString();
}
if (value instanceof Boolean) {
return JBooleanLiteral.get(((Boolean) value).booleanValue()).toSource();
} else if (value instanceof Byte) {
return JIntLiteral.get(((Byte) value).byteValue()).toSource();
} else if (value instanceof Character) {
return JCharLiteral.get(((Character) value).charValue()).toSource();
} else if (value instanceof Class<?>) {
return ((Class<?>) (Class<?>) value).getCanonicalName() + ".class";
} else if (value instanceof Double) {
return JDoubleLiteral.get(((Double) value).doubleValue()).toSource();
} else if (value instanceof Enum) {
return value.getClass().getCanonicalName() + "." + ((Enum<?>) value).name();
} else if (value instanceof Float) {
return JFloatLiteral.get(((Float) value).floatValue()).toSource();
} else if (value instanceof Integer) {
return JIntLiteral.get(((Integer) value).intValue()).toSource();
} else if (value instanceof Long) {
return JLongLiteral.get(((Long) value).longValue()).toSource();
} else if (value instanceof String) {
return '"' + Generator.escape((String) value) + '"';
} else {
// TODO(nchalko) handle Annotation types
throw new IllegalArgumentException(
value.getClass() + " can not be represented as a Java Literal.");
}
}
示例6: translate
import com.google.gwt.core.ext.Generator; //导入依赖的package包/类
private String translate(final String encoded) {
return Generator.escape(new LexerForMarkup()
.setLinkAttributes("class=\"local-link\"")
.lex(encoded)
.toSource());
}
示例7: injectSingletonAsync
import com.google.gwt.core.ext.Generator; //导入依赖的package包/类
private static JDeclaredType injectSingletonAsync(final TreeLogger logger, final JClassLiteral classLiteral,
final JMethodCall methodCall, final UnifyAstView ast) throws UnableToCompleteException {
final JDeclaredType type = (JDeclaredType)classLiteral.getRefType();
final String[] names = type.getShortName().split("[$]");
// TODO: stop stripping the enclosing class name (need to update generators)
// String reqType = JGwtCreate.nameOf(type);
String answer = classLiteral.getRefType().getName();
answer = answer.substring(0, answer.lastIndexOf('.') + 1) + "impl.AsyncFor_" + names[names.length - 1];
JDeclaredType answerType = null;
final JDeclaredType knownType = ast.getProgram().getFromTypeMap(answer);
if (knownType != null) {
return ast.searchForTypeBySource(answer);
} else {// we need to generate the singleton on the fly, without updating rebind cache
final StandardGeneratorContext ctx = ast.getRebindPermutationOracle().getGeneratorContext();
// make sure the requested interface is compiled for the generator
ast.searchForTypeBySource(type.getName());
try {
// our hardcoded class is definitely a generator ;-}
final Class<? extends Generator> generator = AsyncInjectionGenerator.class;
// (Class<? extends Generator>) Class
// .forName("xapi.dev.generators.AsyncInjectionGenerator");
// creates the singleton and provider
final RebindResult rebindResult = ctx.runGeneratorIncrementally(logger, generator, type.getName());
// commit the generator result, w/out updating rebind cache (to allow GWT.create() rebinds)
ctx.finish(logger);
// pull back the LazySingeton provider
answerType = ast.searchForTypeBySource(rebindResult.getResultTypeName());
// sanity check
if (answerType == null) {
ast.error(methodCall, "Rebind result '" + answer + "' could not be found. Please be sure that " +
type.getName() +
" has a subclass on the classpath which contains @SingletonOverride or @SingletonDefault annotations.");
throw new UnableToCompleteException();
}
} catch (final UnableToCompleteException e) {
logger.log(Type.ERROR, "Error trying to generator provider for " + type.getName() + ". " +
"\nPlease make sure this class is non-abstract, or that a concrete class on the classpath " +
"is annotated with @SingletonOverride or @SingletonDefault", e);
ast.error(methodCall, "Rebind result '" + answer + "' could not be found");
throw new UnableToCompleteException();
}
}
if (!(answerType instanceof JClassType)) {
ast.error(methodCall, "Rebind result '" + answer + "' must be a class");
throw new UnableToCompleteException();
}
if (answerType.isAbstract()) {
ast.error(methodCall, "Rebind result '" + answer + "' cannot be abstract");
throw new UnableToCompleteException();
}
logger.log(logLevel(), "Injecting asynchronous singleton for " + type.getName() + " -> " + answerType);
return answerType;
}
示例8: toCss
import com.google.gwt.core.ext.Generator; //导入依赖的package包/类
@Override
public String toCss() {
return Generator.escape(value);
}
示例9: escape
import com.google.gwt.core.ext.Generator; //导入依赖的package包/类
/**
* @param text
* @return
*/
protected String escape(final String text) {
return Generator.escape(text);
}