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


Java TypedVar类代码示例

本文整理汇总了Java中com.google.javascript.jscomp.TypedVar的典型用法代码示例。如果您正苦于以下问题:Java TypedVar类的具体用法?Java TypedVar怎么用?Java TypedVar使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


TypedVar类属于com.google.javascript.jscomp包,在下文中一共展示了TypedVar类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: collectTypedefs

import com.google.javascript.jscomp.TypedVar; //导入依赖的package包/类
/**
 * Finds all typedefs in the program and build a Type -> typedef name mapping. The mapping is
 * needed because when walking type definitions closure inlines the typedefs values.
 */
void collectTypedefs() {
  for (TypedVar var : compiler.getTopScope().getAllSymbols()) {
    if (shouldSkipVar(var)) {
      continue;
    }
    // In Closure, unlike TypeScript there is no pure type space. Thus even typedefs declare
    // symbols. The type of the symbol corresponding to the typedef is *not* the same as the type
    // declared by the typedef.
    JSType type = var.getType();
    if (type == null
        || !isTypedef(type)
        || var.getName().startsWith("window.")
        || isPrivate(var.getJSDocInfo())) {
      continue;
    }

    JSType realType = compiler.getTypeRegistry().getType(var.getName());
    if (realType != null
        && shouldEmitTypedefByName(realType)
        && !typedefs.containsKey(realType)) {
      typedefs.put(realType, var.getName());
    }
  }
}
 
开发者ID:angular,项目名称:clutz,代码行数:29,代码来源:DeclarationGenerator.java

示例2: needsAlias

import com.google.javascript.jscomp.TypedVar; //导入依赖的package包/类
private boolean needsAlias(Set<String> shadowedSymbols, String provide, TypedVar symbol) {
  if (!shadowedSymbols.contains(provide)) {
    return false;
  }
  // Emit var foo : any for provided but not declared symbols.
  if (symbol == null) {
    return true;
  }
  JSType type = symbol.getType();
  if (type == null) {
    return false;
  }

  // Emit var foo : PrivateType for private symbols.
  if (isPrivate(type.getJSDocInfo()) && !isConstructor(type.getJSDocInfo())) {
    return true;
  }
  // Only var declarations have collisions, while class, interface, function, and typedef can
  // coexist with namespaces.
  if (type.isInterface() || type.isConstructor() || type.isFunctionType() || isTypedef(type)) {
    return false;
  }
  return isDefaultExport(symbol);
}
 
开发者ID:angular,项目名称:clutz,代码行数:25,代码来源:DeclarationGenerator.java

示例3: accept

import com.google.javascript.jscomp.TypedVar; //导入依赖的package包/类
public void accept(TypedScope scope) {
  pushCurrentJavaType(scope.getTypeOfThis());
  if (visitTopScope(scope)) {
    for (TypedVar symbol : scope.getVarIterable()) {
      if (isDefinedInExternFiles(symbol) && isNotNamespaced(symbol)) {
        accept(symbol, true);
      }
    }
  }
  popCurrentJavaType();
}
 
开发者ID:google,项目名称:jsinterop-generator,代码行数:12,代码来源:AbstractClosureVisitor.java

示例4: precomputeChildLists

import com.google.javascript.jscomp.TypedVar; //导入依赖的package包/类
/**
 * Precompute the list of children symbols for all top-scope symbols.
 *
 * <p>I.e. For each x.y -> [x.y.z, x.y.w]
 */
void precomputeChildLists() {
  for (TypedVar var : compiler.getTopScope().getAllSymbols()) {
    String namespace = getNamespace(var.getName());
    if (!namespace.equals("")) {
      childListMap.put(namespace, var);
    }
  }
}
 
开发者ID:angular,项目名称:clutz,代码行数:14,代码来源:DeclarationGenerator.java

示例5: isDefaultExport

import com.google.javascript.jscomp.TypedVar; //导入依赖的package包/类
private boolean isDefaultExport(TypedVar symbol) {
  if (symbol.getType() == null) return true;
  ObjectType otype = symbol.getType().toMaybeObjectType();
  if (otype != null && otype.getOwnPropertyNames().size() == 0) return true;
  return !symbol.getType().isObject()
      || symbol.getType().isInterface()
      || symbol.getType().isInstanceType()
      || symbol.getType().isEnumType()
      || symbol.getType().isFunctionType()
      || isTypedef(symbol.getType());
}
 
开发者ID:angular,项目名称:clutz,代码行数:12,代码来源:DeclarationGenerator.java

示例6: isPrototypeMethod

import com.google.javascript.jscomp.TypedVar; //导入依赖的package包/类
private boolean isPrototypeMethod(TypedVar other) {
  if (other.getType() != null && other.getType().isOrdinaryFunction()) {
    JSType typeOfThis = ((FunctionType) other.getType()).getTypeOfThis();
    if (typeOfThis != null && !typeOfThis.isUnknownType()) {
      return true;
    }
  }
  return false;
}
 
开发者ID:angular,项目名称:clutz,代码行数:10,代码来源:DeclarationGenerator.java

示例7: isNotNamespaced

import com.google.javascript.jscomp.TypedVar; //导入依赖的package包/类
private static boolean isNotNamespaced(TypedVar symbol) {
  return !symbol.getName().contains(".");
}
 
开发者ID:google,项目名称:jsinterop-generator,代码行数:4,代码来源:AbstractClosureVisitor.java

示例8: isDefinedInExternFiles

import com.google.javascript.jscomp.TypedVar; //导入依赖的package包/类
private boolean isDefinedInExternFiles(TypedVar symbol) {
  return externFileNamesSet.contains(symbol.getInputName());
}
 
开发者ID:google,项目名称:jsinterop-generator,代码行数:4,代码来源:AbstractClosureVisitor.java

示例9: shouldSkipVar

import com.google.javascript.jscomp.TypedVar; //导入依赖的package包/类
/**
 * Skip emit & use for variables that will not be emitted due to {@link Options#skipEmitPattern}.
 */
private boolean shouldSkipVar(TypedVar var) {
  return opts.skipEmitPattern != null
      && opts.skipEmitPattern.matcher(var.getInputName()).matches();
}
 
开发者ID:angular,项目名称:clutz,代码行数:8,代码来源:DeclarationGenerator.java

示例10: processReservedSymbols

import com.google.javascript.jscomp.TypedVar; //导入依赖的package包/类
/**
 * Reserved words are problematic because they cannot be used as var declarations, but are valid
 * properties. For example:
 *
 * <pre>
 * var switch = 0;  // parses badly in JS.
 * foo.switch = 0;  // ok.
 * </pre>
 *
 * This means that closure code is allowed to goog.provide('ng.components.switch'), which cannot
 * trivially translate in TS to:
 *
 * <pre>
 * namespace ng.components {
 *   var switch : ...;
 * }
 * </pre>
 *
 * Instead, go one step higher and generate:
 *
 * <pre>
 * namespace ng {
 *   var components : {switch: ..., };
 * }
 * </pre>
 *
 * This turns a namespace into a property of its parent namespace. Note: this violates the
 * invariant that generated namespaces are 1-1 with getNamespace of goog.provides.
 */
private void processReservedSymbols(TreeSet<String> provides, TypedScope topScope) {
  Set<String> collapsedNamespaces = new TreeSet<>();
  for (String reservedProvide : provides) {
    if (RESERVED_JS_WORDS.contains(getUnqualifiedName(reservedProvide))) {
      String namespace = getNamespace(reservedProvide);
      if (collapsedNamespaces.contains(namespace)) continue;
      collapsedNamespaces.add(namespace);
      Set<String> properties = getSubNamespace(provides, namespace);
      emitNamespaceBegin(getNamespace(namespace));
      emit("var");
      emit(getUnqualifiedName(namespace));
      emit(": {");
      Iterator<String> bundledIt = properties.iterator();
      while (bundledIt.hasNext()) {
        emit(getUnqualifiedName(bundledIt.next()));
        emit(":");
        TypedVar var = topScope.getOwnSlot(reservedProvide);
        if (var != null) {
          TreeWalker walker = new TreeWalker(compiler.getTypeRegistry(), provides, false, false);
          walker.visitType(var.getType());
        } else {
          emit("any");
        }
        if (bundledIt.hasNext()) emit(",");
      }
      emit("};");
      emitBreak();
      emitNamespaceEnd();
      for (String property : properties) {
        // Assume that all symbols that are siblings of the reserved word are default exports.
        declareModule(property, true, property, true);
      }
    }
  }
  // Remove the symbols that we have emitted above.
  Iterator<String> it = provides.iterator();
  while (it.hasNext()) {
    if (collapsedNamespaces.contains(getNamespace(it.next()))) it.remove();
  }
}
 
开发者ID:angular,项目名称:clutz,代码行数:70,代码来源:DeclarationGenerator.java

示例11: isArrayLike

import com.google.javascript.jscomp.TypedVar; //导入依赖的package包/类
private boolean isArrayLike(TypedVar symbol) {
  return symbol.getName().endsWith(".ArrayLike");
}
 
开发者ID:angular,项目名称:clutz,代码行数:4,代码来源:DeclarationGenerator.java

示例12: processUnprovidedTypes

import com.google.javascript.jscomp.TypedVar; //导入依赖的package包/类
/**
 * Closure does not require all types to be explicitly provided, if they are only used in type
 * positions. However, our emit phases only emits goog.provided symbols and namespaces, so this
 * extra pass is required, in order to have valid output.
 */
private void processUnprovidedTypes(Set<String> provides, Set<String> transitiveProvides) {
  /**
   * A new set of types can be discovered while visiting unprovided types. To prevent an infinite
   * loop in a pathological case, limit to a number of passes.
   *
   * <p>TODO(rado): investigate https://github.com/angular/clutz/pull/246 and removing this pass
   * altogether.
   */
  int maxTypeUsedDepth = 5;
  Set<String> typesEmitted = new LinkedHashSet<>();
  while (maxTypeUsedDepth > 0) {
    int typesUsedCount = typesUsed.size();
    // AFAICT, there is no api for going from type to symbol, so iterate all symbols first.
    for (TypedVar symbol : compiler.getTopScope().getAllSymbols()) {
      String name = symbol.getName();
      String namespace = getNamespace(name);
      // skip unused symbols, symbols already emitted or symbols whose namespace is emitted
      // (unless the symbols have their own provide).
      if (!typesUsed.contains(name)
          || typesEmitted.contains(name)
          || (!transitiveProvides.contains(name) && typesEmitted.contains(namespace))) {
        continue;
      }

      // skip provided symbols (as default or in an namespace).
      if (provides.contains(name)
          || (!transitiveProvides.contains(name) && provides.contains(namespace))) {
        continue;
      }

      // skip extern symbols (they have a separate pass).
      CompilerInput symbolInput = this.compiler.getInput(new InputId(symbol.getInputName()));
      if (symbolInput != null && symbolInput.isExtern()) continue;

      if (shouldSkipVar(symbol)) {
        continue;
      }

      // Symbols in partial_goog_base.js are just stand ins for the real symbols, so don't emit
      if (symbol.getInputName().endsWith("partial_goog_base.js")) {
        continue;
      }

      declareNamespace(
          namespace,
          symbol,
          name,
          /* isDefault */ true,
          Collections.<String>emptySet(),
          /* isExtern */ false);
      typesEmitted.add(name);
    }
    // if no new types seen, safely break out.
    if (typesUsed.size() == typesUsedCount) break;
    maxTypeUsedDepth--;
  }
}
 
开发者ID:angular,项目名称:clutz,代码行数:63,代码来源:DeclarationGenerator.java

示例13: sortSymbols

import com.google.javascript.jscomp.TypedVar; //导入依赖的package包/类
private void sortSymbols(List<TypedVar> symbols) {
  Collections.sort(symbols, BY_VAR_NAME);
}
 
开发者ID:angular,项目名称:clutz,代码行数:4,代码来源:DeclarationGenerator.java

示例14: isPrivate

import com.google.javascript.jscomp.TypedVar; //导入依赖的package包/类
private boolean isPrivate(String name) {
  TypedVar var = compiler.getTopScope().getOwnSlot(name);
  if (var == null) return false;
  return isPrivate(var.getJSDocInfo());
}
 
开发者ID:angular,项目名称:clutz,代码行数:6,代码来源:DeclarationGenerator.java

示例15: getUnqualifiedName

import com.google.javascript.jscomp.TypedVar; //导入依赖的package包/类
private String getUnqualifiedName(TypedVar symbol) {
  return getUnqualifiedName(symbol.getName());
}
 
开发者ID:angular,项目名称:clutz,代码行数:4,代码来源:DeclarationGenerator.java


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