本文整理汇总了Java中com.google.javascript.jscomp.NameReferenceGraph.Reference类的典型用法代码示例。如果您正苦于以下问题:Java Reference类的具体用法?Java Reference怎么用?Java Reference使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Reference类属于com.google.javascript.jscomp.NameReferenceGraph包,在下文中一共展示了Reference类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: process
import com.google.javascript.jscomp.NameReferenceGraph.Reference; //导入依赖的package包/类
@Override
public void process(Node externs, Node root) {
if (nameGraph == null) {
NameReferenceGraphConstruction c =
new NameReferenceGraphConstruction(compiler);
c.process(externs, root);
nameGraph = c.getNameReferenceGraph();
}
for (DiGraphNode<Name, Reference> node :
nameGraph.getDirectedGraphNodes()) {
Name name = node.getValue();
if (name.canChangeSignature()) {
List<DiGraphEdge<Name, Reference>> edges = node.getInEdges();
tryEliminateConstantArgs(name, edges);
tryEliminateOptionalArgs(name, edges);
}
}
}
开发者ID:andyjko,项目名称:feedlack,代码行数:20,代码来源:OptimizeParameters.java
示例2: tryEliminateOptionalArgs
import com.google.javascript.jscomp.NameReferenceGraph.Reference; //导入依赖的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
示例3: generateEdgeReport
import com.google.javascript.jscomp.NameReferenceGraph.Reference; //导入依赖的package包/类
/**
* Generate a description of a specific edge between two nodes.
* For each edge, name the element being linked, the location of the
* reference in the source file, and the type of the reference.
*
* @param builder contents of the report to be generated
* @param referencedDecl name of the declaration being referenced
* @param edge the graph edge being described
*/
private void generateEdgeReport(StringBuilder builder,
Name referencedDecl, DiGraphEdge<Name, Reference> edge) {
String srcDeclName = referencedDecl.getQualifiedName();
builder.append("<li><A HREF=\"#" + srcDeclName + "\">");
builder.append(srcDeclName);
builder.append("</a> ");
Node def = edge.getValue().getSite();
int lineNumber = def.getLineno();
int columnNumber = def.getCharno();
String sourceFile = getSourceFile(def);
generateSourceReferenceLink(builder, sourceFile, lineNumber, columnNumber);
JSType defType = edge.getValue().getSite().getJSType();
generateType(builder, defType);
}
开发者ID:ehsan,项目名称:js-symbolic-executor,代码行数:27,代码来源:NameReferenceGraphReport.java
示例4: compare
import com.google.javascript.jscomp.NameReferenceGraph.Reference; //导入依赖的package包/类
public int compare(DiGraphNode<Name, Reference> node1,
DiGraphNode<Name, Reference> node2) {
Preconditions.checkNotNull(node1.getValue());
Preconditions.checkNotNull(node2.getValue());
if ((node1.getValue().getQualifiedName() == null) &&
(node2.getValue().getQualifiedName() == null)) {
return 0;
}
// Node 1, if null, comes before node 2.
if (node1.getValue().getQualifiedName() == null) {
return -1;
}
// Node 2, if null, comes before node 1.
if (node2.getValue().getQualifiedName() == null) {
return 1;
}
return node1.getValue().getQualifiedName().compareTo(
node2.getValue().getQualifiedName());
}
开发者ID:ehsan,项目名称:js-symbolic-executor,代码行数:24,代码来源:NameReferenceGraphReport.java
示例5: process
import com.google.javascript.jscomp.NameReferenceGraph.Reference; //导入依赖的package包/类
@Override
public void process(Node externs, Node root) {
if (nameGraph == null) {
NameReferenceGraphConstruction c =
new NameReferenceGraphConstruction(compiler);
c.process(externs, root);
nameGraph = c.getNameReferenceGraph();
}
for (DiGraphNode<Name, Reference> node :
nameGraph.getDirectedGraphNodes()) {
Name name = node.getValue();
if (name.canChangeSignature()) {
List<DiGraphEdge<Name, Reference>> edges = node.getInEdges();
tryEliminateConstantArgs(name, edges);
tryEliminateOptionalArgs(name, edges);
}
}
}
开发者ID:ehsan,项目名称:js-symbolic-executor,代码行数:20,代码来源:OptimizeParameters.java
示例6: tryEliminateOptionalArgs
import com.google.javascript.jscomp.NameReferenceGraph.Reference; //导入依赖的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
示例7: compare
import com.google.javascript.jscomp.NameReferenceGraph.Reference; //导入依赖的package包/类
@Override
public int compare(DiGraphNode<Name, Reference> node1,
DiGraphNode<Name, Reference> node2) {
Preconditions.checkNotNull(node1.getValue());
Preconditions.checkNotNull(node2.getValue());
if ((node1.getValue().getQualifiedName() == null) &&
(node2.getValue().getQualifiedName() == null)) {
return 0;
}
// Node 1, if null, comes before node 2.
if (node1.getValue().getQualifiedName() == null) {
return -1;
}
// Node 2, if null, comes before node 1.
if (node2.getValue().getQualifiedName() == null) {
return 1;
}
return node1.getValue().getQualifiedName().compareTo(
node2.getValue().getQualifiedName());
}
开发者ID:SpoonLabs,项目名称:astor,代码行数:25,代码来源:NameReferenceGraphReport.java
示例8: recordStaticNameUse
import com.google.javascript.jscomp.NameReferenceGraph.Reference; //导入依赖的package包/类
private Reference recordStaticNameUse(
NodeTraversal t, Node n, Node parent) {
if (isExtern) {
// Don't count reference in extern as a use.
return null;
} else {
Reference reference = new Reference(n, parent);
Name name = graph.defineNameIfNotExists(n.getQualifiedName(), isExtern);
name.setType(getType(n));
graph.connect(getNamedContainingFunction(), reference, name);
return reference;
}
}
开发者ID:andyjko,项目名称:feedlack,代码行数:14,代码来源:NameReferenceGraphConstruction.java
示例9: recordPrototypePropUse
import com.google.javascript.jscomp.NameReferenceGraph.Reference; //导入依赖的package包/类
private void recordPrototypePropUse(
NodeTraversal t, Node n, Node parent) {
Preconditions.checkArgument(NodeUtil.isGetProp(n));
Node instance = n.getFirstChild();
JSType instanceType = getType(instance);
JSType boxedType = instanceType.autoboxesTo();
instanceType = boxedType != null ? boxedType : instanceType;
// Retrieves the property.
ObjectType objType = instanceType.toObjectType();
Preconditions.checkState(objType != null);
if (!isExtern) {
// Don't count reference in extern as a use.
Reference ref = new Reference(n, parent);
FunctionType constructor = objType.getConstructor();
if (constructor != null) {
String propName = n.getLastChild().getString();
if (!constructor.getPrototype().hasOwnProperty(propName)) {
recordSuperClassPrototypePropUse(constructor, propName, ref);
}
// TODO(user): TightenType can help a whole lot here.
recordSubclassPrototypePropUse(constructor, propName, ref);
} else {
recordUnknownUse(t, n, parent);
}
}
}
开发者ID:andyjko,项目名称:feedlack,代码行数:31,代码来源:NameReferenceGraphConstruction.java
示例10: recordSuperClassPrototypePropUse
import com.google.javascript.jscomp.NameReferenceGraph.Reference; //导入依赖的package包/类
/**
* Look for the super class implementation up the tree.
*/
private void recordSuperClassPrototypePropUse(
FunctionType classType, String prop, Reference ref) {
FunctionType superClass = classType.getSuperClassConstructor();
while (superClass != null) {
if (superClass.getPrototype().hasOwnProperty(prop)) {
graph.connect(getNamedContainingFunction(), ref,
graph.defineNameIfNotExists(
superClass.getReferenceName() + ".prototype." + prop, false));
return;
} else {
superClass = superClass.getSuperClassConstructor();
}
}
}
开发者ID:andyjko,项目名称:feedlack,代码行数:18,代码来源:NameReferenceGraphConstruction.java
示例11: recordSubclassPrototypePropUse
import com.google.javascript.jscomp.NameReferenceGraph.Reference; //导入依赖的package包/类
/**
* Conservatively assumes that all subclass implementation of this property
* might be called.
*/
private void recordSubclassPrototypePropUse(
FunctionType classType, String prop, Reference ref) {
if (classType.getPrototype().hasOwnProperty(prop)) {
graph.connect(getNamedContainingFunction(), ref,
graph.defineNameIfNotExists(
classType.getReferenceName() + ".prototype." + prop, false));
}
if (classType.getSubTypes() != null) {
for (FunctionType subclass : classType.getSubTypes()) {
recordSubclassPrototypePropUse(subclass, prop, ref);
}
}
}
开发者ID:andyjko,项目名称:feedlack,代码行数:18,代码来源:NameReferenceGraphConstruction.java
示例12: recordUnknownUse
import com.google.javascript.jscomp.NameReferenceGraph.Reference; //导入依赖的package包/类
private void recordUnknownUse(NodeTraversal t, Node n, Node parent) {
if (isExtern) {
// Don't count reference in extern as a use.
return;
} else {
Preconditions.checkArgument(NodeUtil.isGetProp(n));
Reference ref = new Reference(n, parent);
ref.setUnknown(true);
unknownNameUse.put(n.getLastChild().getString(),
new NameUse(getNamedContainingFunction(), ref));
}
}
开发者ID:andyjko,项目名称:feedlack,代码行数:13,代码来源:NameReferenceGraphConstruction.java
示例13: connectUnknowns
import com.google.javascript.jscomp.NameReferenceGraph.Reference; //导入依赖的package包/类
private void connectUnknowns() {
for (GraphNode<Name, Reference> node : graph.getNodes()) {
Name name = node.getValue();
String propName = name.getPropertyName();
if (propName == null) {
continue;
}
Collection<NameUse> uses = unknownNameUse.get(propName);
if (uses != null) {
for (NameUse use : uses) {
graph.connect(use.name, use.reference, name);
}
}
}
}
开发者ID:andyjko,项目名称:feedlack,代码行数:16,代码来源:NameReferenceGraphConstruction.java
示例14: removeUnusedProperties
import com.google.javascript.jscomp.NameReferenceGraph.Reference; //导入依赖的package包/类
/**
* Remove all properties under a given name if the property name is
* never referenced.
*/
private void removeUnusedProperties(NameReferenceGraph graph) {
for (GraphNode<Name, Reference> node : graph.getNodes()) {
Name name = node.getValue();
NameInfo nameInfo = node.getAnnotation();
if (nameInfo == null || !nameInfo.isReferenced()) {
name.remove();
compiler.reportCodeChange();
logger.fine("Removed unused name" + name);
}
}
}
开发者ID:andyjko,项目名称:feedlack,代码行数:16,代码来源:RemoveUnusedNames.java
示例15: isCallSite
import com.google.javascript.jscomp.NameReferenceGraph.Reference; //导入依赖的package包/类
/**
* @param ref A reference to a function.
* @return true, if it's safe to optimize this function.
*/
private boolean isCallSite(Reference ref) {
Node call = ref.parent;
// We need to make sure we're dealing with a call to the function we're
// optimizing. If the the first child of the parent is not the site, this
// is a nested call and it's a call to another function.
return isCallOrNew(call) && call.getFirstChild() == ref.site;
}
开发者ID:andyjko,项目名称:feedlack,代码行数:12,代码来源:OptimizeParameters.java
示例16: process
import com.google.javascript.jscomp.NameReferenceGraph.Reference; //导入依赖的package包/类
@Override
public void process(Node externs, Node root) {
NameReferenceGraphConstruction gc =
new NameReferenceGraphConstruction(compiler);
gc.process(externs, root);
graph = gc.getNameReferenceGraph();
FixedPointGraphTraversal<Name, Reference> t =
FixedPointGraphTraversal.newTraversal(new PropagateReferences());
getInfo(graph.MAIN).markReference(null);
t.computeFixedPoint(graph, Sets.newHashSet(graph.MAIN));
}
开发者ID:andyjko,项目名称:feedlack,代码行数:12,代码来源:AnalyzeNameReferences.java
示例17: traverseEdge
import com.google.javascript.jscomp.NameReferenceGraph.Reference; //导入依赖的package包/类
public boolean traverseEdge(Name start, Reference edge, Name dest) {
NameInfo startInfo = getInfo(start);
NameInfo destInfo = getInfo(dest);
if (startInfo.isReferenced()) {
JSModule startModule = startInfo.getDeepestCommonModuleRef();
if (startModule != null &&
moduleGraph.dependsOn(startModule, edge.getModule())) {
return destInfo.markReference(startModule);
} else {
return destInfo.markReference(edge.getModule());
}
}
return false;
}
开发者ID:andyjko,项目名称:feedlack,代码行数:15,代码来源:AnalyzeNameReferences.java
示例18: getInfo
import com.google.javascript.jscomp.NameReferenceGraph.Reference; //导入依赖的package包/类
private NameInfo getInfo(Name symbol) {
GraphNode<Name, Reference> name = graph.getNode(symbol);
NameInfo info = name.getAnnotation();
if (info == null) {
info = new NameInfo();
name.setAnnotation(info);
}
return info;
}
开发者ID:andyjko,项目名称:feedlack,代码行数:10,代码来源:AnalyzeNameReferences.java
示例19: generateDeclarationReport
import com.google.javascript.jscomp.NameReferenceGraph.Reference; //导入依赖的package包/类
/**
* Generate the HTML for describing a specific declaration.
* @param builder contents of report to be generated
* @param declarationNode declaration to describe
*/
private void generateDeclarationReport(StringBuilder builder,
DiGraphNode<Name, Reference> declarationNode) {
// Provide the name and location of declaration,
// with an anchor to allow navigation to this declaration.
String declName = declarationNode.getValue().getQualifiedName();
JSType declType = declarationNode.getValue().getType();
builder.append("<LI> ");
builder.append("<A NAME=\"" + declName + "\">");
builder.append(declName);
builder.append("\n");
// Provide the type of the declaration.
// This is helpful for debugging.
generateType(builder, declType);
// List all the definitions of this name that were found in the code.
// For each, list
List<DefinitionsRemover.Definition> defs =
declarationNode.getValue().getDeclarations();
if (defs.size() == 0) {
builder.append("<br>No definitions found<br>");
} else {
// Otherwise, provide a list of definitions in a dotted list.
// For each definition, print the location where that definition is
// found.
builder.append("<ul>");
for (DefinitionsRemover.Definition def : defs) {
Node fnDef = def.getRValue();
String sourceFileName = getSourceFile(fnDef);
builder.append("<li> Defined: ");
generateSourceReferenceLink(builder,
sourceFileName, fnDef.getLineno(), fnDef.getCharno());
}
builder.append("</ul>");
}
}
开发者ID:ehsan,项目名称:js-symbolic-executor,代码行数:44,代码来源:NameReferenceGraphReport.java
示例20: removeUnusedProperties
import com.google.javascript.jscomp.NameReferenceGraph.Reference; //导入依赖的package包/类
/**
* Remove all properties under a given name if the property name is
* never referenced.
*/
private void removeUnusedProperties(NameReferenceGraph graph) {
for (GraphNode<Name, Reference> node : graph.getNodes()) {
Name name = node.getValue();
NameInfo nameInfo = node.getAnnotation();
if (nameInfo == null || !nameInfo.isReferenced()) {
if (canModifyExterns || !name.isExtern()) {
name.remove();
compiler.reportCodeChange();
logger.fine("Removed unused name" + name);
}
}
}
}
开发者ID:ehsan,项目名称:js-symbolic-executor,代码行数:18,代码来源:RemoveUnusedNames.java
注:本文中的com.google.javascript.jscomp.NameReferenceGraph.Reference类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论