本文整理汇总了Java中com.google.javascript.jscomp.NameReferenceGraph.Reference类的典型用法代码示例。如果您正苦于以下问题:Java Reference类的具体用法?Java Reference怎么用?Java Reference使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Reference类属于com.google.javascript.jscomp.NameReferenceGraph包,在下文中一共展示了Reference类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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);
}
}
}
示例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);
}
}
示例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);
}
示例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());
}
示例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);
}
}
}
示例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);
}
}
示例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());
}
示例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;
}
}
示例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);
}
}
}
示例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();
}
}
}
示例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);
}
}
}
示例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));
}
}
示例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);
}
}
}
}
示例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);
}
}
}
示例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;
}