本文整理汇总了Java中com.google.javascript.rhino.Token.THIS属性的典型用法代码示例。如果您正苦于以下问题:Java Token.THIS属性的具体用法?Java Token.THIS怎么用?Java Token.THIS使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类com.google.javascript.rhino.Token
的用法示例。
在下文中一共展示了Token.THIS属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: enterScope
@Override
public void enterScope(NodeTraversal t) {
ControlFlowGraph<Node> cfg = t.getControlFlowGraph();
for (DiGraphEdge<Node, Branch> s : cfg.getImplicitReturn().getInEdges()) {
Node exitNode = s.getSource().getValue();
if (exitNode.getType() != Token.RETURN ||
exitNode.getFirstChild() == null ||
exitNode.getFirstChild().getType() != Token.THIS) {
badFunctionNodes.add(t.getScopeRoot());
return;
}
}
goodFunctionNodes.add(t.getScopeRoot());
}
示例2: isPropertyTree
/**
* Returns true if the provided node is a getprop for
* which the left child is this or a valid property tree
* and for which the right side is a string.
*/
private static boolean isPropertyTree(Node expectedGetprop) {
if (expectedGetprop.getType() != Token.GETPROP) {
return false;
}
Node leftChild = expectedGetprop.getFirstChild();
if (leftChild.getType() != Token.THIS &&
!isPropertyTree(leftChild)) {
return false;
}
Node retVal = leftChild.getNext();
if (NodeUtil.getStringValue(retVal) == null) {
return false;
}
return true;
}
示例3: maybeCollectMember
private void maybeCollectMember(NodeTraversal t,
Node member, Node nodeWithJsDocInfo) {
JSDocInfo info = nodeWithJsDocInfo.getJSDocInfo();
// Do nothing if there is no JSDoc type info, or
// if the node is not a member expression, or
// if the member expression is not of the form: this.someProperty.
if (info == null ||
member.getType() != Token.GETPROP ||
member.getFirstChild().getType() != Token.THIS) {
return;
}
member.getFirstChild().setJSType(thisType);
JSType jsType = getDeclaredTypeInAnnotation(t, member, info);
Node name = member.getLastChild();
if (jsType != null &&
(name.getType() == Token.NAME || name.getType() == Token.STRING)) {
thisType.defineDeclaredProperty(
name.getString(),
jsType,
false /* functions with implementations are not in externs */);
}
}
示例4: isCollapsibleValue
/**
* Determines whether we know enough about the given value to be able
* to collapse it into subsequent expressions.
*
* For example, we can collapse booleans and variable names:
* <code>
* x = 3; y = x; // y = x = 3;
* a = true; b = true; // b = a = true;
* <code>
* But we won't try to collapse complex expressions.
*
* @param value The value node.
* @param isLValue Whether it's on the left-hand side of an expr.
*/
private boolean isCollapsibleValue(Node value, boolean isLValue) {
switch (value.getType()) {
case Token.GETPROP:
// Do not collapse GETPROPs on arbitrary objects, because
// they may be implemented setter functions, and oftentimes
// setter functions fail on native objects. This is ok for "THIS"
// objects, because we assume that they are non-native.
return !isLValue || value.getFirstChild().getType() == Token.THIS;
case Token.NAME:
case Token.NUMBER:
case Token.TRUE:
case Token.FALSE:
case Token.NULL:
case Token.STRING:
return true;
}
return false;
}
示例5: determineType
@Override
public TypeInfo determineType() {
if(node.getType() == Token.NUMBER) return new TypeInfo(this, JavaScriptDictionary.NUMBER);
else if(node.getType() == Token.STRING) return new TypeInfo(this, JavaScriptDictionary.STRING);
else if(node.getType() == Token.TRUE || node.getType() == Token.FALSE) return new TypeInfo(this, JavaScriptDictionary.BOOL);
else if(node.getType() == Token.THIS) {
// Is this "this" reference declared in a function declared in an object literal? If so, it's type info
// should include the scope of the object literal, so that functions called with respect to "this" first
// search the object literal for matching functions. Not infallible, but a good guess.
CFGFunction function = getFunction();
ScriptOrFnNode funNode = function.getFunctionNode();
if(funNode.getParent() != null && funNode.getParent().getType() == Token.OBJECTLIT) {
JavaScriptType type = getFunction().getFeedlack().getObjectLiteralType(funNode.getParent());
if(type != null)
return new TypeInfo(this, type);
}
return new TypeInfo(this, JavaScriptDictionary.NONE);
}
else return new TypeInfo(this, JavaScriptDictionary.NONE);
}
示例6: getCodeString
@Override
public String getCodeString() {
if(node.getType() == Token.NUMBER) return "" + node.getDouble();
else if(node.getType() == Token.STRING) return "" + node.getString();
else if(node.getType() == Token.THIS) return "this";
else return "[BasicNode " + Token.name(node.getType()) + "]";
}
示例7: replaceThis
/**
* Finds the occurence of "this" in the provided property tree and replaces
* it with replacement
*/
private static void replaceThis(Node expectedGetprop, Node replacement) {
Node leftChild = expectedGetprop.getFirstChild();
if (leftChild.getType() == Token.THIS) {
expectedGetprop.replaceChild(leftChild, replacement);
} else {
replaceThis(leftChild, replacement);
}
}
示例8: isSupportedCallType
/**
* Only ".call" calls and direct calls to functions are supported.
* @param callNode The call evaluate.
* @return Whether the call is of a type that is supported.
*/
private boolean isSupportedCallType(Node callNode) {
if (callNode.getFirstChild().getType() != Token.NAME) {
if (NodeUtil.isFunctionObjectCall(callNode)) {
Node thisValue = callNode.getFirstChild().getNext();
if (thisValue == null || thisValue.getType() != Token.THIS) {
return false;
}
} else if (NodeUtil.isFunctionObjectApply(callNode)) {
return false;
}
}
return true;
}
示例9: isGlobalThisObject
private boolean isGlobalThisObject(NodeTraversal t, Node n) {
if (n.getType() == Token.THIS) {
return t.inGlobalScope();
} else if (n.getType() == Token.NAME && !NodeUtil.isLabelName(n)) {
String varName = n.getString();
if (varName.equals(GLOBAL_THIS_NAME)) {
return true;
}
}
return false;
}
示例10: visit
public void visit(NodeTraversal t, Node n, Node parent) {
if (assignLhsChild != null && n.getType() == Token.THIS) {
compiler.report(JSError.make(t, n, level, GLOBAL_THIS));
}
if (n == assignLhsChild) {
assignLhsChild = null;
}
}
示例11: precedence
static int precedence(int type) {
switch (type) {
case Token.COMMA: return 0;
case Token.ASSIGN_BITOR:
case Token.ASSIGN_BITXOR:
case Token.ASSIGN_BITAND:
case Token.ASSIGN_LSH:
case Token.ASSIGN_RSH:
case Token.ASSIGN_URSH:
case Token.ASSIGN_ADD:
case Token.ASSIGN_SUB:
case Token.ASSIGN_MUL:
case Token.ASSIGN_DIV:
case Token.ASSIGN_MOD:
case Token.ASSIGN: return 1;
case Token.HOOK: return 2; // ?: operator
case Token.OR: return 3;
case Token.AND: return 4;
case Token.BITOR: return 5;
case Token.BITXOR: return 6;
case Token.BITAND: return 7;
case Token.EQ:
case Token.NE:
case Token.SHEQ:
case Token.SHNE: return 8;
case Token.LT:
case Token.GT:
case Token.LE:
case Token.GE:
case Token.INSTANCEOF:
case Token.IN: return 9;
case Token.LSH:
case Token.RSH:
case Token.URSH: return 10;
case Token.SUB:
case Token.ADD: return 11;
case Token.MUL:
case Token.MOD:
case Token.DIV: return 12;
case Token.INC:
case Token.DEC:
case Token.NEW:
case Token.DELPROP:
case Token.TYPEOF:
case Token.VOID:
case Token.NOT:
case Token.BITNOT:
case Token.POS:
case Token.NEG: return 13;
case Token.ARRAYLIT:
case Token.CALL:
case Token.EMPTY:
case Token.FALSE:
case Token.FUNCTION:
case Token.GETELEM:
case Token.GETPROP:
case Token.GET_REF:
case Token.IF:
case Token.LP:
case Token.NAME:
case Token.NULL:
case Token.NUMBER:
case Token.OBJECTLIT:
case Token.REGEXP:
case Token.RETURN:
case Token.STRING:
case Token.THIS:
case Token.TRUE:
return 15;
default: throw new Error("Unknown precedence for " +
Node.tokenToName(type) +
" (type " + type + ")");
}
}
示例12: isThis
/**
* Is this a THIS node?
*/
static boolean isThis(Node node) {
return node.getType() == Token.THIS;
}
示例13: getDeclaredTypeInAnnotation
JSType getDeclaredTypeInAnnotation(String sourceName,
Node node, JSDocInfo info) {
JSType jsType = null;
Node objNode = node.getType() == Token.GETPROP ?
node.getFirstChild() : null;
if (info != null) {
if (info.hasType()) {
jsType = info.getType().evaluate(scope);
} else if (FunctionTypeBuilder.isFunctionTypeDeclaration(info)) {
String fnName = node.getQualifiedName();
// constructors are often handled separately.
if (info.isConstructor() && typeRegistry.getType(fnName) != null) {
return null;
}
FunctionTypeBuilder builder =
new FunctionTypeBuilder(
fnName, compiler, node, sourceName, scope)
.inferTemplateTypeName(info)
.inferReturnType(info)
.inferParameterTypes(info)
.inferInheritance(info);
// Infer the context type.
boolean searchedForThisType = false;
if (objNode != null) {
if (objNode.getType() == Token.GETPROP &&
objNode.getLastChild().getString().equals("prototype")) {
builder.inferThisType(info, objNode.getFirstChild());
searchedForThisType = true;
} else if (objNode.getType() == Token.THIS) {
builder.inferThisType(info, objNode.getJSType());
searchedForThisType = true;
}
}
if (!searchedForThisType) {
builder.inferThisType(info, (Node) null);
}
jsType = builder.buildAndRegister();
}
}
return jsType;
}
示例14: getName
/**
* Returns a qualified name of the specified node. Dots and brackets
* are changed to the delimiter passed in when constructing the
* NodeNameExtractor object. We also replace ".prototype" with the
* delimiter to keep names short, while still differentiating them
* from static properties. (Prototype properties will end up
* looking like "a$b$$c" if this.delimiter = '$'.)
*/
String getName(Node node) {
switch (node.getType()) {
case Token.FUNCTION:
Node functionNameNode = node.getFirstChild();
return functionNameNode.getString();
case Token.GETPROP:
Node lhsOfDot = node.getFirstChild();
Node rhsOfDot = lhsOfDot.getNext();
String lhsOfDotName = getName(lhsOfDot);
String rhsOfDotName = getName(rhsOfDot);
if ("prototype".equals(rhsOfDotName)) {
return lhsOfDotName + delimiter;
} else {
return lhsOfDotName + delimiter + rhsOfDotName;
}
case Token.GETELEM:
Node outsideBrackets = node.getFirstChild();
Node insideBrackets = outsideBrackets.getNext();
String nameOutsideBrackets = getName(outsideBrackets);
String nameInsideBrackets = getName(insideBrackets);
if ("prototype".equals(nameInsideBrackets)) {
return nameOutsideBrackets + delimiter;
} else {
return nameOutsideBrackets + delimiter + nameInsideBrackets;
}
case Token.NAME:
return node.getString();
case Token.STRING:
return TokenStream.isJSIdentifier(node.getString()) ?
node.getString() : ("__" + nextUniqueInt++);
case Token.NUMBER:
return NodeUtil.getStringValue(node);
case Token.THIS:
return "this";
case Token.CALL:
return getName(node.getFirstChild());
default:
StringBuilder sb = new StringBuilder();
for (Node child = node.getFirstChild(); child != null;
child = child.getNext()) {
if (sb.length() > 0) {
sb.append(delimiter);
}
sb.append(getName(child));
}
return sb.toString();
}
}
示例15: ensurePropertyDefined
/**
* Defines a property if the property has not been defined yet.
*/
private void ensurePropertyDefined(Node getprop, JSType rightType) {
ObjectType objectType = ObjectType.cast(
getJSType(getprop.getFirstChild()).restrictByNotNullOrUndefined());
if (objectType != null) {
if (ensurePropertyDeclaredHelper(getprop, objectType)) {
return;
}
String propName = getprop.getLastChild().getString();
if (!objectType.isPropertyTypeDeclared(propName)) {
// We do not want a "stray" assign to define an inferred property
// for every object of this type in the program. So we use a heuristic
// approach to determine whether to infer the propery.
//
// 1) If the property is already defined, join it with the previously
// inferred type.
// 2) If this isn't an instance object, define it.
// 3) If the property of an object is being assigned in the constructor,
// define it.
// 4) If this is a stub, define it.
// 5) Otherwise, do not define the type, but declare it in the registry
// so that we can use it for missing property checks.
if (objectType.hasProperty(propName) ||
!objectType.isInstanceType()) {
if ("prototype".equals(propName)) {
objectType.defineDeclaredProperty(propName, rightType, false);
} else {
objectType.defineInferredProperty(propName, rightType, false);
}
} else {
if (getprop.getFirstChild().getType() == Token.THIS &&
getJSType(syntacticScope.getRootNode()).isConstructor()) {
objectType.defineInferredProperty(propName, rightType, false);
} else {
registry.registerPropertyOnType(propName, objectType);
}
}
}
}
}