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


Java Definition类代码示例

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


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

示例1: getCallableDefinitions

import com.google.javascript.jscomp.DefinitionsRemover.Definition; //导入依赖的package包/类
/**
 * Query the DefinitionProvider for the list of definitions that
 * correspond to a given qualified name subtree.  Return null if
 * DefinitionProvider does not contain an entry for a given name,
 * one or more of the values returned by getDeclarations is not
 * callable, or the "name" node is not a GETPROP or NAME.
 *
 * @param definitionProvider The name reference graph
 * @param name Query node
 * @return non-empty definition list or null
 */
private static Collection<Definition> getCallableDefinitions(
    DefinitionProvider definitionProvider, Node name) {
  List<Definition> result = Lists.newArrayList();

  if (!NodeUtil.isGetProp(name) && !NodeUtil.isName(name)) {
    return null;
  }

  Collection<Definition> decls =
      definitionProvider.getDefinitionsReferencedAt(name);
  if (decls == null) {
    return null;
  }

  for (Definition current : decls) {
    Node rValue = current.getRValue();
    if ((rValue != null) && NodeUtil.isFunction(rValue)) {
      result.add(current);
    } else {
      return null;
    }
  }

  return result;
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:37,代码来源:PureFunctionIdentifier.java

示例2: getDefinitionsReferencedAt

import com.google.javascript.jscomp.DefinitionsRemover.Definition; //导入依赖的package包/类
@Override
public Collection<Definition> getDefinitionsReferencedAt(Node useSite) {
  List<Name> nameRefs = getReferencesAt(useSite);
  if (nameRefs.isEmpty()) {
    return null;
  }

  List<Definition> result = Lists.newArrayList();
  for (Name nameRef : nameRefs) {
    List<Definition> decls = nameRef.getDeclarations();
    if (!decls.isEmpty()) {
      result.addAll(decls);
    } else {
      result.add(new UnknownDefinition(useSite));
    }
  }

  if (!result.isEmpty()) {
    return result;
  } else {
    return null;
  }
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:24,代码来源:NameReferenceGraph.java

示例3: rewriteCallSites

import com.google.javascript.jscomp.DefinitionsRemover.Definition; //导入依赖的package包/类
/**
 * Rewrites object method call sites as calls to global functions
 * that take "this" as their first argument.
 *
 * Before:
 *   o.foo(a, b, c)
 *
 * After:
 *   foo(o, a, b, c)
 */
private void rewriteCallSites(SimpleDefinitionFinder defFinder,
                              Definition definition,
                              String newMethodName) {
  Collection<UseSite> useSites = defFinder.getUseSites(definition);
  for (UseSite site : useSites) {
    Node node = site.node;
    Node parent = node.getParent();

    Node objectNode = node.getFirstChild();
    node.removeChild(objectNode);
    parent.replaceChild(node, objectNode);
    parent.addChildToFront(Node.newString(Token.NAME, newMethodName));
    compiler.reportCodeChange();
  }
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:26,代码来源:DevirtualizePrototypeMethods.java

示例4: tryEliminateOptionalArgs

import com.google.javascript.jscomp.DefinitionsRemover.Definition; //导入依赖的package包/类
/**
 * Removes any optional parameters if no callers specifies it as an argument.
 * @param name The name of the function to optimize. 
 * @param edges All the references to this name.
 */
private void tryEliminateOptionalArgs(Name name,
    List<DiGraphEdge<Name, Reference>> edges) {
  
  // Count the maximum number of arguments passed into this function all
  // all points of the program.
  int maxArgs = -1;

  for (DiGraphEdge<Name, Reference> refEdge : edges) {
    Reference ref = refEdge.getValue();
    Node call = ref.parent;

    if (isCallSite(ref)) {
      int numArgs = call.getChildCount() - 1;
      if (numArgs > maxArgs) {
        maxArgs = numArgs;
      }
    } // else this is a definition or a dereference, ignore it.
  }

  for (Definition definition : name.getDeclarations()) {
    eliminateParamsAfter(definition.getRValue(), maxArgs);
  }
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:29,代码来源:OptimizeParameters.java

示例5: definitionTypeContainsFunctionType

import com.google.javascript.jscomp.DefinitionsRemover.Definition; //导入依赖的package包/类
/**
 * Determines if the type of the value of the rhs expression can
 * be a function node.
 */
private static boolean definitionTypeContainsFunctionType(Definition def) {
  Node rhs = def.getRValue();
  if (rhs == null) {
    return true;
  }

  switch (rhs.getType()) {
    case Token.ASSIGN:
    case Token.AND:
    case Token.CALL:
    case Token.GETPROP:
    case Token.GETELEM:
    case Token.FUNCTION:
    case Token.HOOK:
    case Token.NAME:
    case Token.NEW:
    case Token.OR:
      return true;
    default:
      return false;
  }
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:27,代码来源:MarkNoSideEffectCalls.java

示例6: visit

import com.google.javascript.jscomp.DefinitionsRemover.Definition; //导入依赖的package包/类
@Override
public void visit(NodeTraversal traversal, Node node, Node parent) {
  if (!NodeUtil.isCall(node) && !NodeUtil.isNew(node)) {
    return;
  }

  Collection<Definition> definitions =
      defFinder.getDefinitionsReferencedAt(node.getFirstChild());
  if (definitions == null) {
    return;
  }

  for (Definition def : definitions) {
    Node lValue = def.getLValue();
    Preconditions.checkNotNull(lValue);
    if (!noSideEffectFunctionNames.contains(lValue) &&
        definitionTypeContainsFunctionType(def)) {
      return;
    }
  }

  node.setIsNoSideEffectsCall();
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:24,代码来源:MarkNoSideEffectCalls.java

示例7: getDefinitionsReferencedAt

import com.google.javascript.jscomp.DefinitionsRemover.Definition; //导入依赖的package包/类
@Override
public Collection<Definition> getDefinitionsReferencedAt(Node useSite) {
  if (definitionSiteMap.containsKey(useSite)) {
    return null;
  }

  if (NodeUtil.isGetProp(useSite)) {
    String propName = useSite.getLastChild().getString();
    if (propName.equals("apply") || propName.equals("call")) {
      useSite = useSite.getFirstChild();
    }
  }

  String name = getSimplifiedName(useSite);
  if (name != null) {
    Collection<Definition> defs = nameDefinitionMultimap.get(name);
    if (!defs.isEmpty()) {
      return defs;
    } else {
      return null;
    }
  } else {
    return null;
  }
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:26,代码来源:SimpleDefinitionFinder.java

示例8: visit

import com.google.javascript.jscomp.DefinitionsRemover.Definition; //导入依赖的package包/类
@Override
public void visit(NodeTraversal traversal, Node node, Node parent) {

  Collection<Definition> defs = getDefinitionsReferencedAt(node);
  if (defs == null) {
    return;
  }

  Definition first = defs.iterator().next();

  String name = getSimplifiedName(first.getLValue());
  Preconditions.checkNotNull(name);
  nameUseSiteMultimap.put(
      name,
      new UseSite(node, traversal.getModule()));
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:17,代码来源:SimpleDefinitionFinder.java

示例9: visit

import com.google.javascript.jscomp.DefinitionsRemover.Definition; //导入依赖的package包/类
public void visit(NodeTraversal traversal, Node node, Node parent) {
  Collection<Definition> defs =
      passUnderTest.getDefinitionsReferencedAt(node);
  if (defs != null) {
    StringBuffer sb = new StringBuffer();
    sb.append("USE ");
    sb.append(Token.name(node.getType()));
    sb.append(" ");
    sb.append(node.getQualifiedName());
    sb.append(" -> ");
    Multiset<String> defstrs = TreeMultiset.create();
    for (Definition def : defs) {
      Node rValue = def.getRValue();
      if (rValue != null) {
        defstrs.add(Token.name(rValue.getType()));
      } else {
        defstrs.add("<null>");
      }
    }

    sb.append(defstrs.toString());
    found.add(sb.toString());
  }
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:25,代码来源:SimpleDefinitionFinderTest.java

示例10: lookupDefinitionsForTargetsOfCall

import com.google.javascript.jscomp.DefinitionsRemover.Definition; //导入依赖的package包/类
/**
 * Queries the definition provider for the definitions that could be the
 * targets of the given callsite node.
 * 
 * This is complicated by the fact that NameReferenceGraph and
 * SimpleDefinitionProvider (the two definition providers we currently
 * use) differ on the types of target nodes they will analyze.
 */
private Collection<Definition> lookupDefinitionsForTargetsOfCall(
    Node callsite, DefinitionProvider definitionProvider) {
  Preconditions.checkArgument(callsite.getType() == Token.CALL
      || callsite.getType() == Token.NEW);
  
  Node targetExpression = callsite.getFirstChild();
  
  // NameReferenceGraph throws an exception unless the node is
  // a GETPROP or a NAME
  if (!useNameReferenceGraph 
      || (NodeUtil.isGetProp(targetExpression)
      ||  NodeUtil.isName(targetExpression))) {
    
    Collection<Definition> definitions = 
      definitionProvider.getDefinitionsReferencedAt(targetExpression);
    
    if (definitions != null && !definitions.isEmpty()) {
      return definitions;
    }
  }
  
  return null;
}
 
开发者ID:ehsan,项目名称:js-symbolic-executor,代码行数:32,代码来源:CallGraph.java

示例11: getDefinitionsReferencedAt

import com.google.javascript.jscomp.DefinitionsRemover.Definition; //导入依赖的package包/类
@Override
public Collection<Definition> getDefinitionsReferencedAt(Node useSite) {
  List<Name> nameRefs = getReferencesAt(useSite);
  if (nameRefs.isEmpty()) {
    return null;
  }

  List<Definition> result = Lists.newArrayList();
  for (Name nameRef : nameRefs) {
    List<Definition> decls = nameRef.getDeclarations();
    if (!decls.isEmpty()) {
      result.addAll(decls);
    }
  }

  if (!result.isEmpty()) {
    return result;
  } else {
    return null;
  }
}
 
开发者ID:ehsan,项目名称:js-symbolic-executor,代码行数:22,代码来源:NameReferenceGraph.java

示例12: rewriteCallSites

import com.google.javascript.jscomp.DefinitionsRemover.Definition; //导入依赖的package包/类
/**
 * Rewrites object method call sites as calls to global functions
 * that take "this" as their first argument.
 *
 * Before:
 *   o.foo(a, b, c)
 *
 * After:
 *   foo(o, a, b, c)
 */
private void rewriteCallSites(SimpleDefinitionFinder defFinder,
                              Definition definition,
                              String newMethodName) {
  Collection<UseSite> useSites = defFinder.getUseSites(definition);
  for (UseSite site : useSites) {
    Node node = site.node;
    Node parent = node.getParent();

    Node objectNode = node.getFirstChild();
    node.removeChild(objectNode);
    parent.replaceChild(node, objectNode);
    parent.addChildToFront(
        Node.newString(Token.NAME, newMethodName)
            .copyInformationFrom(node));
    compiler.reportCodeChange();

    if (specializationState != null) {
      specializationState.reportSpecializedFunctionContainingNode(parent);
    }
  }
}
 
开发者ID:ehsan,项目名称:js-symbolic-executor,代码行数:32,代码来源:DevirtualizePrototypeMethods.java

示例13: analyze

import com.google.javascript.jscomp.DefinitionsRemover.Definition; //导入依赖的package包/类
/**
 * Uses the provided {@link SimpleDefinitionFinder} to determine
 * which functions are aliased or exposed to .call() or .apply().
 */
public void analyze(SimpleDefinitionFinder finder) {
  Preconditions.checkState(aliasedFunctions == null);
  
  aliasedFunctions = Sets.newHashSet();
  functionsExposedToCallOrApply = Sets.newHashSet();
  
  for (DefinitionSite definitionSite : finder.getDefinitionSites()) {
    Definition definition = definitionSite.definition;
    
    if (!definition.isExtern()) {
      Node rValue = definition.getRValue();
      
      if (rValue != null && NodeUtil.isFunction(rValue)) {
        // rValue is a Token.FUNCTION from a definition
        
        for (UseSite useSite : finder.getUseSites(definition)) {
          updateFunctionForUse(rValue, useSite.node);
        }          
      }     
    }
  }   
}
 
开发者ID:ehsan,项目名称:js-symbolic-executor,代码行数:27,代码来源:SimpleFunctionAliasAnalysis.java

示例14: tryEliminateOptionalArgs

import com.google.javascript.jscomp.DefinitionsRemover.Definition; //导入依赖的package包/类
/**
 * Removes any optional parameters if no callers specifies it as an argument.
 * @param name The name of the function to optimize.
 * @param edges All the references to this name.
 */
private void tryEliminateOptionalArgs(Name name,
    List<DiGraphEdge<Name, Reference>> edges) {

  // Count the maximum number of arguments passed into this function all
  // all points of the program.
  int maxArgs = -1;

  for (DiGraphEdge<Name, Reference> refEdge : edges) {
    Reference ref = refEdge.getValue();
    Node call = ref.parent;

    if (isCallSite(ref)) {
      int numArgs = call.getChildCount() - 1;
      if (numArgs > maxArgs) {
        maxArgs = numArgs;
      }
    } // else this is a definition or a dereference, ignore it.
  }

  for (Definition definition : name.getDeclarations()) {
    eliminateParamsAfter(definition.getRValue(), maxArgs);
  }
}
 
开发者ID:ehsan,项目名称:js-symbolic-executor,代码行数:29,代码来源:OptimizeParameters.java

示例15: lookupDefinitionsForTargetsOfCall

import com.google.javascript.jscomp.DefinitionsRemover.Definition; //导入依赖的package包/类
/**
 * Queries the definition provider for the definitions that could be the
 * targets of the given callsite node.
 *
 * This is complicated by the fact that NameReferenceGraph and
 * SimpleDefinitionProvider (the two definition providers we currently
 * use) differ on the types of target nodes they will analyze.
 */
private Collection<Definition> lookupDefinitionsForTargetsOfCall(
    Node callsite, DefinitionProvider definitionProvider) {
  Preconditions.checkArgument(callsite.isCall()
      || callsite.isNew());

  Node targetExpression = callsite.getFirstChild();

  // NameReferenceGraph throws an exception unless the node is
  // a GETPROP or a NAME
  if (!useNameReferenceGraph
      || (targetExpression.isGetProp()
      ||  targetExpression.isName())) {

    Collection<Definition> definitions =
      definitionProvider.getDefinitionsReferencedAt(targetExpression);

    if (definitions != null && !definitions.isEmpty()) {
      return definitions;
    }
  }

  return null;
}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:32,代码来源:CallGraph.java


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