• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java Definition类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: canRemoveArgFromCallSites

import com.google.javascript.jscomp.DefinitionsRemover.Definition; //导入依赖的package包/类
/**
 * Remove all references to a parameter, otherwise simplify the known
 * references.
 * @return Whether all the references were removed.
 */
private boolean canRemoveArgFromCallSites(Node function, int argIndex) {
  Definition definition = getFunctionDefinition(function);

  // Check all the call sites.
  for (UseSite site : defFinder.getUseSites(definition)) {
    if (isModifiableCallSite(site)) {
      Node arg = getArgumentForCallOrNewOrDotCall(site, argIndex);
      // TODO(johnlenz): try to remove parameters with side-effects by
      // decomposing the call expression.
      if (arg != null && NodeUtil.mayHaveSideEffects(arg, compiler)) {
        return false;
      }
    } else {
      return false;
    }
  }

  return true;
}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:25,代码来源:RemoveUnusedVars.java


示例17: tryRemoveAllFollowingArgs

import com.google.javascript.jscomp.DefinitionsRemover.Definition; //导入依赖的package包/类
/**
 * Remove all the following parameters without side-effects
 */
private void tryRemoveAllFollowingArgs(Node function, final int argIndex) {
  Definition definition = getFunctionDefinition(function);
  for (UseSite site : defFinder.getUseSites(definition)) {
    if (!isModifiableCallSite(site)) {
      continue;
    }
    Node arg = getArgumentForCallOrNewOrDotCall(site, argIndex + 1);
    while (arg != null) {
      if (!NodeUtil.mayHaveSideEffects(arg)) {
        toRemove.add(arg);
      }
      arg = arg.getNext();
    }
  }
}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:19,代码来源:RemoveUnusedVars.java


示例18: canModifyCallers

import com.google.javascript.jscomp.DefinitionsRemover.Definition; //导入依赖的package包/类
/**
 * @param function
 * @return Whether the callers to this function can be modified in any way.
 */
boolean canModifyCallers(Node function) {
  if (NodeUtil.isVarArgsFunction(function)) {
    return false;
  }

  DefinitionSite defSite = defFinder.getDefinitionForFunction(function);
  if (defSite == null) {
    return false;
  }

  Definition definition = defSite.definition;

  // Be conservative, don't try to optimize any declaration that isn't as
  // simple function declaration or assignment.
  if (!SimpleDefinitionFinder.isSimpleFunctionDeclaration(function)) {
    return false;
  }

  return defFinder.canModifyDefinition(definition);
}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:25,代码来源:RemoveUnusedVars.java


示例19: 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(IR.name(newMethodName).srcref(node));
    Preconditions.checkState(parent.isCall());
    parent.putBooleanProp(Node.FREE_CALL, true);
    compiler.reportCodeChange();

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


示例20: 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 && rValue.isFunction()) {
        // rValue is a Token.FUNCTION from a definition

        for (UseSite useSite : finder.getUseSites(definition)) {
          updateFunctionForUse(rValue, useSite.node);
        }
      }
    }
  }
}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:27,代码来源:SimpleFunctionAliasAnalysis.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java Facets类代码示例发布时间:2022-05-22
下一篇:
Java DWithin类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap