本文整理汇总了Java中com.google.javascript.jscomp.ReferenceCollectingCallback.Reference类的典型用法代码示例。如果您正苦于以下问题:Java Reference类的具体用法?Java Reference怎么用?Java Reference使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Reference类属于com.google.javascript.jscomp.ReferenceCollectingCallback包,在下文中一共展示了Reference类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: collectAliasCandidates
import com.google.javascript.jscomp.ReferenceCollectingCallback.Reference; //导入依赖的package包/类
/**
* If any of the variables are well-defined and alias other variables,
* mark them as aliasing candidates.
*/
private void collectAliasCandidates(NodeTraversal t,
Map<Var, ReferenceCollection> referenceMap) {
if (mode != Mode.CONSTANTS_ONLY) {
for (Iterator<Var> it = t.getScope().getVars(); it.hasNext();) {
Var v = it.next();
ReferenceCollection referenceInfo = referenceMap.get(v);
// NOTE(nicksantos): Don't handle variables that are never used.
// The tests are much easier to write if you don't, and there's
// another pass that handles unused variables much more elegantly.
if (referenceInfo != null && referenceInfo.references.size() >= 2 &&
referenceInfo.isWellDefined() &&
referenceInfo.isAssignedOnce()) {
Reference init = referenceInfo.getInitializingReference();
Node value = init.getAssignedValue();
if (value != null && value.getType() == Token.NAME) {
aliasCandidates.put(value, new AliasCandidate(v, referenceInfo));
}
}
}
}
}
开发者ID:andyjko,项目名称:feedlack,代码行数:27,代码来源:InlineVariables.java
示例2: inlineDeclaredConstant
import com.google.javascript.jscomp.ReferenceCollectingCallback.Reference; //导入依赖的package包/类
/**
* Inline a declared constant.
*/
private void inlineDeclaredConstant(Var v, Node value,
List<Reference> refSet) {
// Replace the references with the constant value
Reference decl = null;
for (Reference r : refSet) {
if (r.getNameNode() == v.getNameNode()) {
decl = r;
} else {
inlineValue(v, r, value.cloneTree());
}
}
removeDeclaration(decl);
}
开发者ID:andyjko,项目名称:feedlack,代码行数:19,代码来源:InlineVariables.java
示例3: isStringWorthInlining
import com.google.javascript.jscomp.ReferenceCollectingCallback.Reference; //导入依赖的package包/类
/**
* Compute whether the given string is worth inlining.
*/
private boolean isStringWorthInlining(Var var, List<Reference> refs) {
if (!inlineAllStrings && !var.isDefine()) {
int len = var.getInitialValue().getString().length() + "''".length();
// if not inlined: var xx="value"; .. xx .. xx ..
// The 4 bytes per reference is just a heuristic:
// 2 bytes per var name plus maybe 2 bytes if we don't inline, e.g.
// in the case of "foo " + CONST + " bar"
int noInlineBytes = "var xx=;".length() + len +
4 * (refs.size() - 1);
// if inlined:
// I'm going to assume that half of the quotes will be eliminated
// thanks to constant folding, therefore I subtract 1 (2/2=1) from
// the string length.
int inlineBytes = (len - 1) * (refs.size() - 1);
// Not inlining if doing so uses more bytes, or this constant is being
// defined.
return noInlineBytes >= inlineBytes;
}
return true;
}
开发者ID:andyjko,项目名称:feedlack,代码行数:28,代码来源:InlineVariables.java
示例4: collectAliasCandidates
import com.google.javascript.jscomp.ReferenceCollectingCallback.Reference; //导入依赖的package包/类
/**
* If any of the variables are well-defined and alias other variables,
* mark them as aliasing candidates.
*/
private void collectAliasCandidates(NodeTraversal t,
Map<Var, ReferenceCollection> referenceMap) {
if (mode != Mode.CONSTANTS_ONLY) {
for (Iterator<Var> it = t.getScope().getVars(); it.hasNext();) {
Var v = it.next();
ReferenceCollection referenceInfo = referenceMap.get(v);
// NOTE(nicksantos): Don't handle variables that are never used.
// The tests are much easier to write if you don't, and there's
// another pass that handles unused variables much more elegantly.
if (referenceInfo != null && referenceInfo.references.size() >= 2 &&
referenceInfo.isWellDefined() &&
referenceInfo.isAssignedOnceInLifetime()) {
Reference init = referenceInfo.getInitializingReference();
Node value = init.getAssignedValue();
if (value != null && value.getType() == Token.NAME) {
aliasCandidates.put(value, new AliasCandidate(v, referenceInfo));
}
}
}
}
}
开发者ID:ehsan,项目名称:js-symbolic-executor,代码行数:27,代码来源:InlineVariables.java
示例5: inline
import com.google.javascript.jscomp.ReferenceCollectingCallback.Reference; //导入依赖的package包/类
/**
* Do the actual work of inlining a single declaration into a single
* reference.
*/
private void inline(Var v, Reference declaration,
Reference init, Reference reference) {
Node value = init.getAssignedValue();
Preconditions.checkState(value != null);
// Check for function declarations before the value is moved in the AST.
boolean isFunctionDeclaration = NodeUtil.isFunctionDeclaration(value);
inlineValue(v, reference, value.detachFromParent());
if (declaration != init) {
Node expressRoot = init.getGrandparent();
Preconditions.checkState(expressRoot.getType() == Token.EXPR_RESULT);
NodeUtil.removeChild(expressRoot.getParent(), expressRoot);
}
// Function declarations have already been removed.
if (!isFunctionDeclaration) {
removeDeclaration(declaration);
} else {
compiler.reportCodeChange();
}
}
开发者ID:ehsan,项目名称:js-symbolic-executor,代码行数:26,代码来源:InlineVariables.java
示例6: isValidInitialization
import com.google.javascript.jscomp.ReferenceCollectingCallback.Reference; //导入依赖的package包/类
/**
* @return Whether there is a initial value.
*/
private boolean isValidInitialization(Reference initialization) {
if (initialization == null) {
return false;
} else if (initialization.isDeclaration()) {
// The reference is a FUNCTION declaration or normal VAR declaration
// with a value.
return NodeUtil.isFunctionDeclaration(initialization.getParent())
|| initialization.getNameNode().getFirstChild() != null;
} else {
Node parent = initialization.getParent();
Preconditions.checkState(
parent.getType() == Token.ASSIGN
&& parent.getFirstChild() == initialization.getNameNode());
return true;
}
}
开发者ID:ehsan,项目名称:js-symbolic-executor,代码行数:20,代码来源:InlineVariables.java
示例7: mapUses
import com.google.javascript.jscomp.ReferenceCollectingCallback.Reference; //导入依赖的package包/类
/**
* Adds a map from each use NAME in {@code root} to its corresponding
* declaring name, *provided the declaration is also under root*.
*
* If the declaration is not under root, then the reference will
* not be added to the map.
*/
public void mapUses(Node root) {
referencesByNameNode = Maps.newHashMap();
ReferenceCollectingCallback callback =
new ReferenceCollectingCallback(compiler,
ReferenceCollectingCallback.DO_NOTHING_BEHAVIOR);
NodeTraversal.traverse(compiler, root, callback);
for (Var variable : callback.getReferencedVariables()) {
ReferenceCollection referenceCollection =
callback.getReferenceCollection(variable);
for (Reference reference : referenceCollection.references) {
Node referenceNameNode = reference.getNameNode();
// Note that this counts a declaration as a reference to itself
referencesByNameNode.put(referenceNameNode, variable.getNameNode());
}
}
}
开发者ID:ehsan,项目名称:js-symbolic-executor,代码行数:29,代码来源:SideEffectsAnalysis.java
示例8: collectAliasCandidates
import com.google.javascript.jscomp.ReferenceCollectingCallback.Reference; //导入依赖的package包/类
/**
* If any of the variables are well-defined and alias other variables,
* mark them as aliasing candidates.
*/
private void collectAliasCandidates(NodeTraversal t,
ReferenceMap referenceMap) {
if (mode != Mode.CONSTANTS_ONLY) {
for (Iterator<Var> it = t.getScope().getVars(); it.hasNext();) {
Var v = it.next();
ReferenceCollection referenceInfo = referenceMap.getReferences(v);
// NOTE(nicksantos): Don't handle variables that are never used.
// The tests are much easier to write if you don't, and there's
// another pass that handles unused variables much more elegantly.
if (referenceInfo != null && referenceInfo.references.size() >= 2 &&
referenceInfo.isWellDefined() &&
referenceInfo.isAssignedOnceInLifetime()) {
Reference init = referenceInfo.getInitializingReference();
Node value = init.getAssignedValue();
if (value != null && value.isName()) {
aliasCandidates.put(value, new AliasCandidate(v, referenceInfo));
}
}
}
}
}
开发者ID:SpoonLabs,项目名称:astor,代码行数:27,代码来源:InlineVariables.java
示例9: maybeEscapedOrModifiedArguments
import com.google.javascript.jscomp.ReferenceCollectingCallback.Reference; //导入依赖的package包/类
private boolean maybeEscapedOrModifiedArguments(
Scope scope, ReferenceMap referenceMap) {
if (scope.isLocal()) {
Var arguments = scope.getArgumentsVar();
ReferenceCollection refs = referenceMap.getReferences(arguments);
if (refs != null && !refs.references.isEmpty()) {
for (Reference ref : refs.references) {
Node refNode = ref.getNode();
Node refParent = ref.getParent();
// Any reference that is not a read of the arguments property
// consider a escape of the arguments object.
if (!(NodeUtil.isGet(refParent)
&& refNode == ref.getParent().getFirstChild()
&& !isLValue(refParent))) {
return true;
}
}
}
}
return false;
}
开发者ID:SpoonLabs,项目名称:astor,代码行数:22,代码来源:InlineVariables.java
示例10: inline
import com.google.javascript.jscomp.ReferenceCollectingCallback.Reference; //导入依赖的package包/类
/**
* Do the actual work of inlining a single declaration into a single
* reference.
*/
private void inline(Var v, Reference declaration,
Reference init, Reference reference) {
Node value = init.getAssignedValue();
Preconditions.checkState(value != null);
// Check for function declarations before the value is moved in the AST.
boolean isFunctionDeclaration = NodeUtil.isFunctionDeclaration(value);
inlineValue(v, reference, value.detachFromParent());
if (declaration != init) {
Node expressRoot = init.getGrandparent();
Preconditions.checkState(expressRoot.isExprResult());
NodeUtil.removeChild(expressRoot.getParent(), expressRoot);
}
// Function declarations have already been removed.
if (!isFunctionDeclaration) {
removeDeclaration(declaration);
} else {
compiler.reportCodeChange();
}
}
开发者ID:SpoonLabs,项目名称:astor,代码行数:26,代码来源:InlineVariables.java
示例11: inlineDeclaredConstant
import com.google.javascript.jscomp.ReferenceCollectingCallback.Reference; //导入依赖的package包/类
/**
* Inline a declared constant.
*/
private void inlineDeclaredConstant(Var v, Node value,
List<Reference> refSet) {
// Replace the references with the constant value
Reference decl = null;
for (Reference r : refSet) {
if (r.getNode() == v.getNameNode()) {
decl = r;
} else {
inlineValue(v, r, value.cloneTree());
}
}
removeDeclaration(decl);
}
开发者ID:SpoonLabs,项目名称:astor,代码行数:19,代码来源:InlineVariables.java
示例12: isValidInitialization
import com.google.javascript.jscomp.ReferenceCollectingCallback.Reference; //导入依赖的package包/类
/**
* @return Whether there is a initial value.
*/
private boolean isValidInitialization(Reference initialization) {
if (initialization == null) {
return false;
} else if (initialization.isDeclaration()) {
// The reference is a FUNCTION declaration or normal VAR declaration
// with a value.
if (!NodeUtil.isFunctionDeclaration(initialization.getParent())
&& initialization.getNode().getFirstChild() == null) {
return false;
}
} else {
Node parent = initialization.getParent();
Preconditions.checkState(
parent.isAssign()
&& parent.getFirstChild() == initialization.getNode());
}
Node n = initialization.getAssignedValue();
if (n.isFunction()) {
return compiler.getCodingConvention().isInlinableFunction(n);
}
return true;
}
开发者ID:SpoonLabs,项目名称:astor,代码行数:28,代码来源:InlineVariables.java
示例13: afterExitScope
import com.google.javascript.jscomp.ReferenceCollectingCallback.Reference; //导入依赖的package包/类
@Override
public void afterExitScope(NodeTraversal t, ReferenceMap referenceMap) {
for (Iterator<Var> it = t.getScope().getVars(); it.hasNext();) {
Var v = it.next();
if (isVarInlineForbidden(v)) {
continue;
}
ReferenceCollection referenceInfo = referenceMap.getReferences(v);
if (isInlinableObject(referenceInfo.references)) {
// Blacklist the object itself, as well as any other values
// that it refers to, since they will have been moved around.
staleVars.add(v);
Reference declaration = referenceInfo.references.get(0);
Reference init = referenceInfo.getInitializingReference();
// Split up the object into individual variables if the object
// is never referenced directly in full.
splitObject(v, declaration, init, referenceInfo);
}
}
}
开发者ID:SpoonLabs,项目名称:astor,代码行数:26,代码来源:InlineObjectLiterals.java
示例14: mapUses
import com.google.javascript.jscomp.ReferenceCollectingCallback.Reference; //导入依赖的package包/类
/**
* Adds a map from each use NAME in {@code root} to its corresponding
* declaring name, *provided the declaration is also under root*.
*
* If the declaration is not under root, then the reference will
* not be added to the map.
*/
public void mapUses(Node root) {
referencesByNameNode = Maps.newHashMap();
ReferenceCollectingCallback callback =
new ReferenceCollectingCallback(compiler,
ReferenceCollectingCallback.DO_NOTHING_BEHAVIOR);
NodeTraversal.traverse(compiler, root, callback);
for (Var variable : callback.getAllSymbols()) {
ReferenceCollection referenceCollection =
callback.getReferences(variable);
for (Reference reference : referenceCollection.references) {
Node referenceNameNode = reference.getNode();
// Note that this counts a declaration as a reference to itself
referencesByNameNode.put(referenceNameNode, variable.getNameNode());
}
}
}
开发者ID:SpoonLabs,项目名称:astor,代码行数:29,代码来源:SideEffectsAnalysis.java
示例15: removeScriptReferences
import com.google.javascript.jscomp.ReferenceCollectingCallback.Reference; //导入依赖的package包/类
private void removeScriptReferences(InputId inputId) {
Preconditions.checkNotNull(inputId);
if (!inputOrder.containsKey(inputId)) {
return; // Input did not exist when last computed, so skip
}
// TODO(bashir): If this is too slow it is not too difficult to make it
// faster with keeping an index for variables accessed in sourceName.
for (ReferenceCollection collection : refMap.values()) {
if (collection == null) {
continue;
}
List<Reference> oldRefs = collection.references;
SourceRefRange range = findSourceRefRange(oldRefs, inputId);
List<Reference> newRefs = Lists.newArrayList(range.refsBefore());
newRefs.addAll(range.refsAfter());
collection.references = newRefs;
}
}
开发者ID:SpoonLabs,项目名称:astor,代码行数:20,代码来源:GlobalVarReferenceMap.java
示例16: replaceReferences
import com.google.javascript.jscomp.ReferenceCollectingCallback.Reference; //导入依赖的package包/类
private void replaceReferences(String varName, InputId inputId,
ReferenceCollection newSourceCollection) {
ReferenceCollection combined = new ReferenceCollection();
List<Reference> combinedRefs = combined.references;
ReferenceCollection oldCollection = refMap.get(varName);
refMap.put(varName, combined);
if (oldCollection == null) {
combinedRefs.addAll(newSourceCollection.references);
return;
}
// otherwise replace previous references that are from sourceName
SourceRefRange range = findSourceRefRange(oldCollection.references,
inputId);
combinedRefs.addAll(range.refsBefore());
combinedRefs.addAll(newSourceCollection.references);
combinedRefs.addAll(range.refsAfter());
}
开发者ID:SpoonLabs,项目名称:astor,代码行数:18,代码来源:GlobalVarReferenceMap.java
示例17: findSourceRefRange
import com.google.javascript.jscomp.ReferenceCollectingCallback.Reference; //导入依赖的package包/类
/**
* Finds the range of references associated to {@code sourceName}. Note that
* even if there is no sourceName references the returned information can be
* used to decide where to insert new sourceName refs.
*/
private SourceRefRange findSourceRefRange(List<Reference> refList,
InputId inputId) {
Preconditions.checkNotNull(inputId);
// TODO(bashir): We can do binary search here, but since this is fast enough
// right now, we just do a linear search for simplicity.
int lastBefore = -1;
int firstAfter = refList.size();
int index = 0;
Preconditions.checkState(inputOrder.containsKey(inputId), inputId.getIdName());
int sourceInputOrder = inputOrder.get(inputId);
for (Reference ref : refList) {
Preconditions.checkNotNull(ref.getInputId());
int order = inputOrder.get(ref.getInputId());
if (order < sourceInputOrder) {
lastBefore = index;
} else if (order > sourceInputOrder) {
firstAfter = index;
break;
}
index++;
}
return new SourceRefRange(refList, lastBefore, firstAfter);
}
开发者ID:SpoonLabs,项目名称:astor,代码行数:31,代码来源:GlobalVarReferenceMap.java
示例18: inline
import com.google.javascript.jscomp.ReferenceCollectingCallback.Reference; //导入依赖的package包/类
/**
* Do the actual work of inlining a single declaration into a single
* reference.
*/
private void inline(Var v, Reference decl, Reference init, Reference ref) {
Node value = init.getAssignedValue();
Preconditions.checkState(value != null);
// Check for function declarations before the value is moved in the AST.
boolean isFunctionDeclaration = NodeUtil.isFunctionDeclaration(value);
compiler.reportChangeToEnclosingScope(ref.getNode());
inlineValue(v, ref, value.detachFromParent());
if (decl != init) {
Node expressRoot = init.getGrandparent();
Preconditions.checkState(expressRoot.isExprResult());
NodeUtil.removeChild(expressRoot.getParent(), expressRoot);
}
// Function declarations have already been removed.
if (!isFunctionDeclaration) {
compiler.reportChangeToEnclosingScope(decl.getNode());
removeDeclaration(decl);
}
}
开发者ID:nicks,项目名称:closure-compiler-old,代码行数:23,代码来源:InlineVariables.java
示例19: collectReferences
import com.google.javascript.jscomp.ReferenceCollectingCallback.Reference; //导入依赖的package包/类
private void collectReferences(Node root) {
ReferenceCollectingCallback collector = new ReferenceCollectingCallback(
compiler, ReferenceCollectingCallback.DO_NOTHING_BEHAVIOR,
new Predicate<Var>() {
@Override public boolean apply(Var var) {
// Only collect global and non-exported names.
return var.isGlobal() &&
!compiler.getCodingConvention().isExported(var.getName());
}
});
NodeTraversal.traverse(compiler, root, collector);
for (Var v : collector.getAllSymbols()) {
ReferenceCollection refCollection = collector.getReferences(v);
NamedInfo info = getNamedInfo(v);
for (Reference ref : refCollection) {
processReference(collector, ref, info);
}
}
}
开发者ID:nicks,项目名称:closure-compiler-old,代码行数:21,代码来源:CrossModuleCodeMotion.java
示例20: processReference
import com.google.javascript.jscomp.ReferenceCollectingCallback.Reference; //导入依赖的package包/类
private void processReference(
ReferenceCollectingCallback collector, Reference ref, NamedInfo info) {
Node n = ref.getNode();
Node parent = n.getParent();
if (info.allowMove) {
if (maybeProcessDeclaration(collector, ref, info)) {
// Check to see if the declaration is conditional starting at the
// grandparent of the name node. Since a function declaration
// is considered conditional (the function might not be called)
// we would need to skip the parent in this check as the name could
// just be a function itself.
if (hasConditionalAncestor(parent.getParent())) {
info.allowMove = false;
}
} else {
if (parentModuleCanSeeSymbolsDeclaredInChildren &&
parent.isInstanceOf() && parent.getLastChild() == n) {
instanceofNodes.put(parent, new InstanceofInfo(getModule(ref), info));
} else {
// Otherwise, it's a read
processRead(ref, info);
}
}
}
}
开发者ID:nicks,项目名称:closure-compiler-old,代码行数:26,代码来源:CrossModuleCodeMotion.java
注:本文中的com.google.javascript.jscomp.ReferenceCollectingCallback.Reference类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论