本文整理汇总了Java中com.google.javascript.jscomp.ExpressionDecomposer.DecompositionType.DECOMPOSABLE属性的典型用法代码示例。如果您正苦于以下问题:Java DecompositionType.DECOMPOSABLE属性的具体用法?Java DecompositionType.DECOMPOSABLE怎么用?Java DecompositionType.DECOMPOSABLE使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类com.google.javascript.jscomp.ExpressionDecomposer.DecompositionType
的用法示例。
在下文中一共展示了DecompositionType.DECOMPOSABLE属性的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: classifyCallSite
/**
* Determine which, if any, of the supported types the call site is.
*/
private CallSiteType classifyCallSite(Node callNode) {
Node parent = callNode.getParent();
Node grandParent = parent.getParent();
// Verify the call site:
if (NodeUtil.isExprCall(parent)) {
// This is a simple call? Example: "foo();".
return CallSiteType.SIMPLE_CALL;
} else if (NodeUtil.isExprAssign(grandParent)
&& !NodeUtil.isLhs(callNode, parent)
&& parent.getFirstChild().getType() == Token.NAME
&& !NodeUtil.isConstantName(parent.getFirstChild())) {
// This is a simple assignment. Example: "x = foo();"
return CallSiteType.SIMPLE_ASSIGNMENT;
} else if (parent.getType() == Token.NAME
&& !NodeUtil.isConstantName(parent)
&& grandParent.getType() == Token.VAR
&& grandParent.hasOneChild()) {
// This is a var declaration. Example: "var x = foo();"
// TODO(johnlenz): Should we be checking for constants on the
// left-hand-side of the assignments (and handling them as EXPRESSION?
return CallSiteType.VAR_DECL_SIMPLE_ASSIGNMENT;
} else {
Node expressionRoot = ExpressionDecomposer.findExpressionRoot(callNode);
if (expressionRoot != null) {
ExpressionDecomposer decomposer = new ExpressionDecomposer(
compiler, safeNameIdSupplier, knownConstants);
DecompositionType type = decomposer.canExposeExpression(
callNode);
if (type == DecompositionType.MOVABLE) {
return CallSiteType.EXPRESSION;
} else if (type == DecompositionType.DECOMPOSABLE) {
return CallSiteType.DECOMPOSABLE_EXPRESSION;
} else {
Preconditions.checkState(type == DecompositionType.UNDECOMPOSABLE);
}
}
}
return CallSiteType.UNSUPPORTED;
}
示例2: classifyCallSite
/**
* Determine which, if any, of the supported types the call site is.
*/
private CallSiteType classifyCallSite(Node callNode) {
Node parent = callNode.getParent();
Node grandParent = parent.getParent();
// Verify the call site:
if (NodeUtil.isExprCall(parent)) {
// This is a simple call? Example: "foo();".
return CallSiteType.SIMPLE_CALL;
} else if (NodeUtil.isExprAssign(grandParent)
&& !NodeUtil.isVarOrSimpleAssignLhs(callNode, parent)
&& parent.getFirstChild().isName()
&& !NodeUtil.isConstantName(parent.getFirstChild())) {
// This is a simple assignment. Example: "x = foo();"
return CallSiteType.SIMPLE_ASSIGNMENT;
} else if (parent.isName()
&& !NodeUtil.isConstantName(parent)
&& grandParent.isVar()
&& grandParent.hasOneChild()) {
// This is a var declaration. Example: "var x = foo();"
// TODO(johnlenz): Should we be checking for constants on the
// left-hand-side of the assignments and handling them as EXPRESSION?
return CallSiteType.VAR_DECL_SIMPLE_ASSIGNMENT;
} else {
Node expressionRoot = ExpressionDecomposer.findExpressionRoot(callNode);
if (expressionRoot != null) {
ExpressionDecomposer decomposer = new ExpressionDecomposer(
compiler, safeNameIdSupplier, knownConstants);
DecompositionType type = decomposer.canExposeExpression(
callNode);
if (type == DecompositionType.MOVABLE) {
return CallSiteType.EXPRESSION;
} else if (type == DecompositionType.DECOMPOSABLE) {
return CallSiteType.DECOMPOSABLE_EXPRESSION;
} else {
Preconditions.checkState(type == DecompositionType.UNDECOMPOSABLE);
}
}
}
return CallSiteType.UNSUPPORTED;
}
示例3: classifyCallSite
/**
* Determine which, if any, of the supported types the call site is.
*
* Constant vars are treated differently so that we don't break their
* const-ness when we decompose the expression. Once the CONSTANT_VAR
* annotation is used everywhere instead of coding conventions, we should just
* teach this pass how to remove the annotation.
*/
private CallSiteType classifyCallSite(Reference ref) {
Node callNode = ref.callNode;
Node parent = callNode.getParent();
Node grandParent = parent.getParent();
// Verify the call site:
if (NodeUtil.isExprCall(parent)) {
// This is a simple call? Example: "foo();".
return CallSiteType.SIMPLE_CALL;
} else if (NodeUtil.isExprAssign(grandParent)
&& !NodeUtil.isNameDeclOrSimpleAssignLhs(callNode, parent)
&& parent.getFirstChild().isName()
// TODO(nicksantos): Remove this once everyone is using
// the CONSTANT_VAR annotation. We know how to remove that.
&& !NodeUtil.isConstantName(parent.getFirstChild())) {
// This is a simple assignment. Example: "x = foo();"
return CallSiteType.SIMPLE_ASSIGNMENT;
} else if (parent.isName()
// TODO(nicksantos): Remove this once everyone is using the CONSTANT_VAR annotation.
&& !NodeUtil.isConstantName(parent)
&& (grandParent.isVar() || grandParent.isLet())
&& grandParent.hasOneChild()) {
// This is a var/let declaration. Example: "var x = foo();"
// TODO(johnlenz): Should we be checking for constants on the
// left-hand-side of the assignments and handling them as EXPRESSION?
return CallSiteType.VAR_DECL_SIMPLE_ASSIGNMENT;
} else {
Node expressionRoot = ExpressionDecomposer.findExpressionRoot(callNode);
if (expressionRoot != null) {
ExpressionDecomposer decomposer = getDecomposer(ref.scope);
DecompositionType type = decomposer.canExposeExpression(callNode);
if (type == DecompositionType.MOVABLE) {
return CallSiteType.EXPRESSION;
} else if (type == DecompositionType.DECOMPOSABLE) {
return CallSiteType.DECOMPOSABLE_EXPRESSION;
} else {
checkState(type == DecompositionType.UNDECOMPOSABLE);
}
}
}
return CallSiteType.UNSUPPORTED;
}
示例4: classifyCallSite
/**
* Determine which, if any, of the supported types the call site is.
*
* Constant vars are treated differently so that we don't break their
* const-ness when we decompose the expression. Once the CONSTANT_VAR
* annotation is used everywhere instead of coding conventions, we should just
* teach this pass how to remove the annotation.
*/
private CallSiteType classifyCallSite(Reference ref) {
Node callNode = ref.callNode;
Node parent = callNode.getParent();
Node grandParent = parent.getParent();
// Verify the call site:
if (NodeUtil.isExprCall(parent)) {
// This is a simple call? Example: "foo();".
return CallSiteType.SIMPLE_CALL;
} else if (NodeUtil.isExprAssign(grandParent)
&& !NodeUtil.isVarOrSimpleAssignLhs(callNode, parent)
&& parent.getFirstChild().isName()
// TODO(nicksantos): Remove this once everyone is using
// the CONSTANT_VAR annotation. We know how to remove that.
&& !NodeUtil.isConstantName(parent.getFirstChild())) {
// This is a simple assignment. Example: "x = foo();"
return CallSiteType.SIMPLE_ASSIGNMENT;
} else if (parent.isName()
// TODO(nicksantos): Remove this once everyone is using
// the CONSTANT_VAR annotation.
&& !NodeUtil.isConstantName(parent)
&& grandParent.isVar()
&& grandParent.hasOneChild()) {
// This is a var declaration. Example: "var x = foo();"
// TODO(johnlenz): Should we be checking for constants on the
// left-hand-side of the assignments and handling them as EXPRESSION?
return CallSiteType.VAR_DECL_SIMPLE_ASSIGNMENT;
} else {
Node expressionRoot = ExpressionDecomposer.findExpressionRoot(callNode);
if (expressionRoot != null) {
ExpressionDecomposer decomposer = new ExpressionDecomposer(
compiler, safeNameIdSupplier, knownConstants, ref.scope);
DecompositionType type = decomposer.canExposeExpression(
callNode);
if (type == DecompositionType.MOVABLE) {
return CallSiteType.EXPRESSION;
} else if (type == DecompositionType.DECOMPOSABLE) {
return CallSiteType.DECOMPOSABLE_EXPRESSION;
} else {
Preconditions.checkState(type == DecompositionType.UNDECOMPOSABLE);
}
}
}
return CallSiteType.UNSUPPORTED;
}