当前位置: 首页>>代码示例>>Java>>正文


Java Generator类代码示例

本文整理汇总了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);
  }
}
 
开发者ID:google-code-export,项目名称:google-gin,代码行数:25,代码来源:BindConstantBinding.java

示例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;
}
 
开发者ID:jDramaix,项目名称:gss.gwt,代码行数:18,代码来源:CssDotPathNode.java

示例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();
}
 
开发者ID:WeTheInternet,项目名称:xapi,代码行数:30,代码来源:MagicClassInjector.java

示例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;
}
 
开发者ID:jDramaix,项目名称:gss.gwt,代码行数:12,代码来源:CssPrinter.java

示例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.");
  }
}
 
开发者ID:ManfredTremmel,项目名称:gwt-bean-validators,代码行数:58,代码来源:GwtSpecificValidatorCreator.java

示例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());
}
 
开发者ID:WeTheInternet,项目名称:xapi,代码行数:7,代码来源:ElementalGenerator.java

示例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;
}
 
开发者ID:WeTheInternet,项目名称:xapi,代码行数:58,代码来源:MagicMethods.java

示例8: toCss

import com.google.gwt.core.ext.Generator; //导入依赖的package包/类
@Override
public String toCss() {
  return Generator.escape(value);
}
 
开发者ID:jDramaix,项目名称:gss.gwt,代码行数:5,代码来源:SimpleValue.java

示例9: escape

import com.google.gwt.core.ext.Generator; //导入依赖的package包/类
/**
 * @param text
 * @return
 */
protected String escape(final String text) {
  return Generator.escape(text);
}
 
开发者ID:WeTheInternet,项目名称:xapi,代码行数:8,代码来源:AbstractHtmlGenerator.java


注:本文中的com.google.gwt.core.ext.Generator类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。