本文整理汇总了Java中com.google.javascript.jscomp.DefinitionsRemover.Definition.getLValue方法的典型用法代码示例。如果您正苦于以下问题:Java Definition.getLValue方法的具体用法?Java Definition.getLValue怎么用?Java Definition.getLValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.javascript.jscomp.DefinitionsRemover.Definition
的用法示例。
在下文中一共展示了Definition.getLValue方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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();
}
示例2: visit
import com.google.javascript.jscomp.DefinitionsRemover.Definition; //导入方法依赖的package包/类
@Override
public void visit(NodeTraversal traversal, Node node, Node parent) {
if (!node.isCall() && !node.isNew()) {
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.setSideEffectFlags(Node.NO_SIDE_EFFECTS);
}
示例3: isExported
import com.google.javascript.jscomp.DefinitionsRemover.Definition; //导入方法依赖的package包/类
/**
* @return Whether the definition is directly exported.
*/
private boolean isExported(Definition definition) {
// Assume an exported method result is used.
Node lValue = definition.getLValue();
if (lValue == null) {
return true;
}
String partialName;
if (lValue.isGetProp()) {
partialName = lValue.getLastChild().getString();
} else if (lValue.isName()) {
partialName = lValue.getString();
} else {
// GETELEM is assumed to be an export or other expression are unknown
// uses.
return true;
}
CodingConvention codingConvention = compiler.getCodingConvention();
if (codingConvention.isExported(partialName)) {
return true;
}
return false;
}
示例4: visitExterns
import com.google.javascript.jscomp.DefinitionsRemover.Definition; //导入方法依赖的package包/类
private void visitExterns(NodeTraversal traversal, Node node) {
if (node.getJSDocInfo() != null) {
for (Node typeRoot : node.getJSDocInfo().getTypeNodes()) {
traversal.traverse(typeRoot);
}
}
Definition definition = DefinitionsRemover.getDefinition(node, true);
if (definition != null) {
String name = definition.getSimplifiedName();
if (name != null) {
Node rValue = definition.getRValue();
if ((rValue != null) && !NodeUtil.isImmutableValue(rValue) && !rValue.isFunction()) {
// Unhandled complex expression
Definition unknownDefinition = new UnknownDefinition(definition.getLValue(), true);
definition = unknownDefinition;
}
addDefinition(name, definition, node, traversal);
}
}
}
示例5: addDefinition
import com.google.javascript.jscomp.DefinitionsRemover.Definition; //导入方法依赖的package包/类
private void addDefinition(
String name, Definition definition, Node definitionSiteNode, NodeTraversal traversal) {
Node definitionNode = definition.getLValue();
definitionNodes.add(definitionNode);
definitionsByName.put(name, definition);
DefinitionSite definitionSite =
new DefinitionSite(
definitionSiteNode,
definition,
traversal.getModule(),
traversal.inGlobalScope(),
definition.isExtern());
definitionSitesByDefinitionSiteNode.put(definitionSiteNode, definitionSite);
Node scopeNode = NodeUtil.getEnclosingChangeScopeRoot(definitionSiteNode);
definitionSitesByScopeNode.put(scopeNode, definitionSite);
}
示例6: isExported
import com.google.javascript.jscomp.DefinitionsRemover.Definition; //导入方法依赖的package包/类
/** @return Whether the definition is directly exported. */
private boolean isExported(Definition definition) {
// Assume an exported method result is used.
Node lValue = definition.getLValue();
if (lValue == null) {
return true;
}
String partialName;
if (lValue.isGetProp()) {
partialName = lValue.getLastChild().getString();
} else if (lValue.isName()) {
partialName = lValue.getString();
} else {
// GETELEM is assumed to be an export or other expression are unknown
// uses.
return true;
}
CodingConvention codingConvention = compiler.getCodingConvention();
return codingConvention.isExported(partialName);
}
示例7: dropUntypedExterns
import com.google.javascript.jscomp.DefinitionsRemover.Definition; //导入方法依赖的package包/类
/**
* Drop untyped stub definitions (ExternalNameOnlyDefinition) in externs if a typed extern of the
* same qualified name also exists and has type annotations.
*
* <p>TODO: This hack is mostly for the purpose of preventing untyped stubs from showing up in the
* {@link PureFunctionIdentifier} and causing unknown side effects from propagating everywhere.
* This should probably be solved in one of the following ways instead:
*
* <p>a) Have a pass earlier in the compiler that goes in and removes these stub definitions.
*
* <p>b) Fix all extern files so that there are no untyped stubs mixed with typed ones and add a
* restriction to the compiler to prevent this.
*
* <p>c) Drop these stubs in the {@link PureFunctionIdentifier} instead. This "DefinitionProvider"
* should not have to drop definitions itself.
*/
private void dropUntypedExterns() {
for (String name : definitionsByName.keySet()) {
for (Definition definition : new ArrayList<>(definitionsByName.get(name))) {
if (!(definition instanceof ExternalNameOnlyDefinition)) {
continue;
}
Node definitionNode = definition.getLValue();
if (jsdocContainsDeclarations(definitionNode)) {
continue;
}
for (Definition previousDefinition : definitionsByName.get(name)) {
if (previousDefinition != definition
&& definitionNode.matchesQualifiedName(previousDefinition.getLValue())) {
// *DON'T* remove from definitionNodes since it is desired to retain references to
// stub definitions.
definitionsByName.remove(name, definition);
DefinitionSite definitionSite =
definitionSitesByDefinitionSiteNode.remove(definitionNode);
Node scopeNode = NodeUtil.getEnclosingChangeScopeRoot(definitionNode);
definitionSitesByScopeNode.remove(scopeNode, definitionSite);
// Since it's a stub we know its keyed by the name/getProp node.
checkNotNull(definitionSite);
break;
}
}
}
}
}
示例8: buildGraph
import com.google.javascript.jscomp.DefinitionsRemover.Definition; //导入方法依赖的package包/类
/**
* When propagating side effects we construct a graph from every function definition A to every
* function definition B that calls A(). Since the definition provider cannot always provide a
* unique definition for a name, there may be many possible definitions for a given call site. In
* the case where multiple defs share the same node in the graph.
*
* <p>We need to build the map {@link PureFunctionIdentifier#functionInfoByName} to get a
* reference to the side effects for a call and we need the map {@link
* PureFunctionIdentifier#functionSideEffectMap} to get a reference to the side effects for a
* given function node.
*/
private void buildGraph() {
final FunctionInformation unknownDefinitionFunction = new FunctionInformation();
unknownDefinitionFunction.setTaintsGlobalState();
unknownDefinitionFunction.setFunctionThrows();
unknownDefinitionFunction.setTaintsReturn();
unknownDefinitionFunction.graphNode = sideEffectGraph.createNode(unknownDefinitionFunction);
for (DefinitionSite site : definitionProvider.getDefinitionSites()) {
Definition definition = site.definition;
if (definition.getLValue() != null) {
Node getOrName = definition.getLValue();
checkArgument(getOrName.isGetProp() || getOrName.isName(), getOrName);
String name = NameBasedDefinitionProvider.getSimplifiedName(getOrName);
checkNotNull(name);
if (isSupportedFunctionDefinition(definition.getRValue())) {
addSupportedDefinition(site, name);
} else {
// Unsupported function definition. Mark a global side effect here since we don't
// actually know anything about what's being defined.
FunctionInformation info = functionInfoByName.get(name);
if (info != null) {
info.setTaintsGlobalState();
info.setFunctionThrows();
info.setTaintsReturn();
} else {
functionInfoByName.put(name, unknownDefinitionFunction);
}
}
}
}
}
示例9: visit
import com.google.javascript.jscomp.DefinitionsRemover.Definition; //导入方法依赖的package包/类
@Override
public void visit(NodeTraversal traversal, Node node, Node parent) {
if (!NodeUtil.isCallOrNew(node)) {
return;
}
Node nameNode = node.getFirstChild();
// This is the result of an anonymous function execution. function() {}();
if (!nameNode.isName() && !nameNode.isGetProp()) {
return;
}
Collection<Definition> definitions = defFinder.getDefinitionsReferencedAt(nameNode);
if (definitions == null) {
return;
}
boolean maybeFunction = false;
for (Definition def : definitions) {
Node lValue = def.getLValue();
checkNotNull(lValue);
if (definitionTypeContainsFunctionType(def)) {
maybeFunction = true;
if (!noSideEffectFunctionNames.contains(lValue)) {
return;
}
}
}
if (maybeFunction) {
if (node.getSideEffectFlags() != Node.NO_SIDE_EFFECTS) {
node.setSideEffectFlags(Node.NO_SIDE_EFFECTS);
compiler.reportChangeToEnclosingScope(node);
}
}
}
示例10: visit
import com.google.javascript.jscomp.DefinitionsRemover.Definition; //导入方法依赖的package包/类
@Override
public void visit(NodeTraversal traversal, Node node, Node parent) {
if (!node.isCall() && !node.isNew()) {
return;
}
Collection<Definition> definitions =
defFinder.getDefinitionsReferencedAt(node.getFirstChild());
if (definitions == null) {
return;
}
boolean maybeFunction = false;
for (Definition def : definitions) {
Node lValue = def.getLValue();
Preconditions.checkNotNull(lValue);
if (definitionTypeContainsFunctionType(def)) {
maybeFunction = true;
if (!noSideEffectFunctionNames.contains(lValue)) {
return;
}
}
}
if (maybeFunction) {
node.setSideEffectFlags(Node.NO_SIDE_EFFECTS);
}
}
示例11: isEligibleDefinition
import com.google.javascript.jscomp.DefinitionsRemover.Definition; //导入方法依赖的package包/类
/**
* Determines if a method definition is eligible for rewrite as a
* global function. In order to be eligible for rewrite, the
* definition must:
*
* - Refer to a function that takes a fixed number of arguments.
* - Function must not be exported.
* - Function must be used at least once.
* - Property is never accesed outside a function call context.
* - The definition under consideration must be the only possible
* choice at each call site.
* - Definition must happen in a module loaded before the first use.
*/
private boolean isEligibleDefinition(SimpleDefinitionFinder defFinder,
DefinitionSite definitionSite) {
Definition definition = definitionSite.definition;
JSModule definitionModule = definitionSite.module;
// Only functions may be rewritten.
// Functions that access "arguments" are not eligible since
// rewrite changes the structure of this object.
Node rValue = definition.getRValue();
if (rValue == null ||
!NodeUtil.isFunction(rValue) ||
NodeUtil.isVarArgsFunction(rValue)) {
return false;
}
// Exporting a method prevents rewrite.
Node lValue = definition.getLValue();
if ((lValue == null) ||
!NodeUtil.isGetProp(lValue)) {
return false;
}
CodingConvention codingConvention = compiler.getCodingConvention();
if (codingConvention.isExported(lValue.getLastChild().getString())) {
return false;
}
Collection<UseSite> useSites = defFinder.getUseSites(definition);
// Rewriting unused methods is not sound.
if (useSites.isEmpty()) {
return false;
}
JSModuleGraph moduleGraph = compiler.getModuleGraph();
for (UseSite site : useSites) {
// Accessing the property directly prevents rewrite.
if (!isCall(site)) {
return false;
}
// Multiple definitions prevent rewrite.
Node nameNode = site.node;
Collection<Definition> singleSiteDefinitions =
defFinder.getDefinitionsReferencedAt(nameNode);
if (singleSiteDefinitions.size() > 1) {
return false;
}
Preconditions.checkState(!singleSiteDefinitions.isEmpty());
Preconditions.checkState(singleSiteDefinitions.contains(definition));
// Accessing the property in a module loaded before the
// definition module prevents rewrite; accessing a variable
// before definition results in a parse error.
JSModule callModule = site.module;
if ((definitionModule != callModule) &&
((callModule == null) ||
!moduleGraph.dependsOn(callModule, definitionModule))) {
return false;
}
}
return true;
}