本文整理了Java中org.mozilla.javascript.ast.UnaryExpression
类的一些代码示例,展示了UnaryExpression
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。UnaryExpression
类的具体详情如下:
包路径:org.mozilla.javascript.ast.UnaryExpression
类名称:UnaryExpression
[英]AST node representing unary operators such as ++, ~, typeof and delete. The type field is set to the appropriate Token type for the operator. The node length spans from the operator to the end of the operand (for prefix operators) or from the start of the operand to the operator (for postfix).
The default xml namespace = <expr> statement in E4X (JavaScript 1.6) is represented as a UnaryExpression of node type Token#DEFAULTNAMESPACE, wrapped with an ExpressionStatement.
[中]表示一元运算符的AST节点,如++、~、typeof和delete。类型字段被设置为操作员的适当令牌类型。节点长度从运算符到操作数结尾(对于前缀运算符)或从操作数开头到运算符(对于后缀运算符)。
E4X(JavaScript 1.6)中的默认xml namespace=<expr>语句表示为节点类型Token#DEFAULTNAMESPACE的一个单变量表达式,用ExpressionStatement包装。
代码示例来源:origin: konsoletyper/teavm
private void printUnary(UnaryExpression node, int precedence) throws IOException {
int innerPrecedence = node.isPostfix() ? PRECEDENCE_POSTFIX : PRECEDENCE_PREFIX;
if (innerPrecedence > precedence) {
writer.append('(');
}
if (!node.isPostfix()) {
String op = AstNode.operatorToString(node.getType());
if (op.startsWith("-")) {
writer.append(' ');
}
writer.append(op);
if (requiresWhitespaces(node.getType())) {
writer.append(' ');
}
}
print(node.getOperand(), innerPrecedence);
if (node.isPostfix()) {
writer.append(AstNode.operatorToString(node.getType()));
}
if (innerPrecedence > precedence) {
writer.append(')');
}
}
代码示例来源:origin: pmd/pmd
public boolean isPrefix() {
return node.isPrefix();
}
代码示例来源:origin: ro.isdc.wro4j/rhino
private Node transformUnary(UnaryExpression node) {
int type = node.getType();
if (type == Token.DEFAULTNAMESPACE) {
return transformDefaultXmlNamepace(node);
}
if (node.isPrefix()) {
decompiler.addToken(type);
}
Node child = transform(node.getOperand());
if (node.isPostfix()) {
decompiler.addToken(type);
}
if (type == Token.INC || type == Token.DEC) {
return createIncDec(type, node.isPostfix(), child);
}
return createUnary(type, child);
}
代码示例来源:origin: ro.isdc.wro4j/rhino
/**
* Constructs a new UnaryExpression with the specified operator
* and operand. It sets the parent of the operand, and sets its own bounds
* to encompass the operator and operand.
* @param operator the node type
* @param operatorPosition the absolute position of the operator.
* @param operand the operand expression
* @param postFix true if the operator follows the operand. Int
* @throws IllegalArgumentException} if {@code operand} is {@code null}
*/
public UnaryExpression(int operator, int operatorPosition,
AstNode operand, boolean postFix) {
assertNotNull(operand);
int beg = postFix ? operand.getPosition() : operatorPosition;
// JavaScript only has ++ and -- postfix operators, so length is 2
int end = postFix
? operatorPosition + 2
: operand.getPosition() + operand.getLength();
setBounds(beg, end);
setOperator(operator);
setOperand(operand);
isPostfix = postFix;
}
代码示例来源:origin: geogebra/geogebra
private AstNode defaultXmlNamespace()
throws IOException
{
if (currentToken != Token.DEFAULT) codeBug();
consumeToken();
mustHaveXML();
setRequiresActivation();
int lineno = ts.lineno, pos = ts.tokenBeg;
if (!(matchToken(Token.NAME) && "xml".equals(ts.getString()))) {
reportError("msg.bad.namespace");
}
if (!(matchToken(Token.NAME) && "namespace".equals(ts.getString()))) {
reportError("msg.bad.namespace");
}
if (!matchToken(Token.ASSIGN)) {
reportError("msg.bad.namespace");
}
AstNode e = expr();
UnaryExpression dxmln = new UnaryExpression(pos, getNodeEnd(e) - pos);
dxmln.setOperator(Token.DEFAULTNAMESPACE);
dxmln.setOperand(e);
dxmln.setLineno(lineno);
ExpressionStatement es = new ExpressionStatement(dxmln, true);
return es;
}
代码示例来源:origin: com.github.tntim96/rhino
@Override
public String toSource(int depth) {
StringBuilder sb = new StringBuilder();
sb.append(makeIndent(depth));
int type = getType();
if (!isPostfix) {
sb.append(operatorToString(type));
if (type == Token.TYPEOF || type == Token.DELPROP || type == Token.VOID) {
sb.append(" ");
}
}
sb.append(operand.toSource());
if (isPostfix) {
sb.append(operatorToString(type));
}
return sb.toString();
}
代码示例来源:origin: io.apigee/rhino
private void checkBadIncDec(UnaryExpression expr) {
AstNode op = removeParens(expr.getOperand());
int tt = op.getType();
if (!(tt == Token.NAME
|| tt == Token.GETPROP
|| tt == Token.GETELEM
|| tt == Token.GET_REF
|| tt == Token.CALL))
reportError(expr.getType() == Token.INC
? "msg.bad.incr"
: "msg.bad.decr");
}
代码示例来源:origin: wala/WALA
@Override
public CAstNode visitUnaryExpression(UnaryExpression node, WalkContext arg) {
if (node.getType() == Token.INC || node.getType() == Token.DEC) {
CAstNode op = (node.getType() == Token.DEC) ? CAstOperator.OP_SUB : CAstOperator.OP_ADD;
AstNode l = node.getOperand();
CAstNode last = visit(l, arg);
return Ast.makeNode((node.isPostfix() ? CAstNode.ASSIGN_POST_OP : CAstNode.ASSIGN_PRE_OP), last,
Ast.makeConstant(1), op);
} else if (node.getType() == Token.TYPEOFNAME) {
return Ast.makeNode(CAstNode.TYPE_OF, Ast.makeNode(CAstNode.VAR, Ast.makeConstant(node.getString())));
} else if (node.getType() == Token.TYPEOF) {
return Ast.makeNode(CAstNode.TYPE_OF, visit(node.getOperand(), arg));
} else if (node.getType() == Token.DELPROP) {
AstNode expr = node.getOperand();
if (expr instanceof FunctionCall) {
expr = ((FunctionCall) expr).getTarget();
assert expr instanceof PropertyGet;
}
return Ast.makeNode(CAstNode.ASSIGN, visit(expr, arg), Ast.makeConstant(null));
} else if (node.getType() == Token.VOID) {
return Ast.makeConstant(null);
} else {
return Ast.makeNode(CAstNode.UNARY_EXPR, translateOpcode(node.getOperator()), visit(node.getOperand(), arg));
}
}
代码示例来源:origin: geogebra/geogebra
case Token.TYPEOF:
consumeToken();
node = new UnaryExpression(tt, ts.tokenBeg, unaryExpr());
node.setLineno(line);
return node;
node = new UnaryExpression(Token.POS, ts.tokenBeg, unaryExpr());
node.setLineno(line);
return node;
node = new UnaryExpression(Token.NEG, ts.tokenBeg, unaryExpr());
node.setLineno(line);
return node;
case Token.DEC:
consumeToken();
UnaryExpression expr = new UnaryExpression(tt, ts.tokenBeg,
memberExpr(true));
expr.setLineno(line);
checkBadIncDec(expr);
return expr;
node = new UnaryExpression(tt, ts.tokenBeg, unaryExpr());
node.setLineno(line);
return node;
new UnaryExpression(tt, ts.tokenBeg, pn, true);
uexpr.setLineno(line);
checkBadIncDec(uexpr);
代码示例来源:origin: geogebra/geogebra
private Node transformDefaultXmlNamepace(UnaryExpression node) {
decompiler.addToken(Token.DEFAULT);
decompiler.addName(" xml");
decompiler.addName(" namespace");
decompiler.addToken(Token.ASSIGN);
Node child = transform(node.getOperand());
return createUnary(Token.DEFAULTNAMESPACE, child);
}
代码示例来源:origin: pmd/pmd
public boolean isPostfix() {
return node.isPostfix();
}
}
代码示例来源:origin: geogebra/geogebra
/**
* Sets the operand, and sets its parent to be this node.
* @throws IllegalArgumentException} if {@code operand} is {@code null}
*/
public void setOperand(AstNode operand) {
assertNotNull(operand);
this.operand = operand;
operand.setParent(this);
}
代码示例来源:origin: geogebra/geogebra
private Node transformUnary(UnaryExpression node) {
int type = node.getType();
if (type == Token.DEFAULTNAMESPACE) {
return transformDefaultXmlNamepace(node);
}
if (node.isPrefix()) {
decompiler.addToken(type);
}
Node child = transform(node.getOperand());
if (node.isPostfix()) {
decompiler.addToken(type);
}
if (type == Token.INC || type == Token.DEC) {
return createIncDec(type, node.isPostfix(), child);
}
return createUnary(type, child);
}
代码示例来源:origin: com.github.tntim96/rhino
/**
* Constructs a new UnaryExpression with the specified operator
* and operand. It sets the parent of the operand, and sets its own bounds
* to encompass the operator and operand.
* @param operator the node type
* @param operatorPosition the absolute position of the operator.
* @param operand the operand expression
* @param postFix true if the operator follows the operand. Int
* @throws IllegalArgumentException} if {@code operand} is {@code null}
*/
public UnaryExpression(int operator, int operatorPosition,
AstNode operand, boolean postFix) {
assertNotNull(operand);
int beg = postFix ? operand.getPosition() : operatorPosition;
// JavaScript only has ++ and -- postfix operators, so length is 2
int end = postFix
? operatorPosition + 2
: operand.getPosition() + operand.getLength();
setBounds(beg, end);
setOperator(operator);
setOperand(operand);
isPostfix = postFix;
}
代码示例来源:origin: ro.isdc.wro4j/rhino
private AstNode defaultXmlNamespace()
throws IOException
{
if (currentToken != Token.DEFAULT) codeBug();
consumeToken();
mustHaveXML();
setRequiresActivation();
int lineno = ts.lineno, pos = ts.tokenBeg;
if (!(matchToken(Token.NAME) && "xml".equals(ts.getString()))) {
reportError("msg.bad.namespace");
}
if (!(matchToken(Token.NAME) && "namespace".equals(ts.getString()))) {
reportError("msg.bad.namespace");
}
if (!matchToken(Token.ASSIGN)) {
reportError("msg.bad.namespace");
}
AstNode e = expr();
UnaryExpression dxmln = new UnaryExpression(pos, getNodeEnd(e) - pos);
dxmln.setOperator(Token.DEFAULTNAMESPACE);
dxmln.setOperand(e);
dxmln.setLineno(lineno);
ExpressionStatement es = new ExpressionStatement(dxmln, true);
return es;
}
代码示例来源:origin: geogebra/geogebra
@Override
public String toSource(int depth) {
StringBuilder sb = new StringBuilder();
sb.append(makeIndent(depth));
int type = getType();
if (!isPostfix) {
sb.append(operatorToString(type));
if (type == Token.TYPEOF || type == Token.DELPROP || type == Token.VOID) {
sb.append(" ");
}
}
sb.append(operand.toSource());
if (isPostfix) {
sb.append(operatorToString(type));
}
return sb.toString();
}
代码示例来源:origin: geogebra/geogebra
private void checkBadIncDec(UnaryExpression expr) {
AstNode op = removeParens(expr.getOperand());
int tt = op.getType();
if (!(tt == Token.NAME
|| tt == Token.GETPROP
|| tt == Token.GETELEM
|| tt == Token.GET_REF
|| tt == Token.CALL))
reportError(expr.getType() == Token.INC
? "msg.bad.incr"
: "msg.bad.decr");
}
代码示例来源:origin: ro.isdc.wro4j/rhino
case Token.TYPEOF:
consumeToken();
node = new UnaryExpression(tt, ts.tokenBeg, unaryExpr());
node.setLineno(line);
return node;
node = new UnaryExpression(Token.POS, ts.tokenBeg, unaryExpr());
node.setLineno(line);
return node;
node = new UnaryExpression(Token.NEG, ts.tokenBeg, unaryExpr());
node.setLineno(line);
return node;
case Token.DEC:
consumeToken();
UnaryExpression expr = new UnaryExpression(tt, ts.tokenBeg,
memberExpr(true));
expr.setLineno(line);
checkBadIncDec(expr);
return expr;
node = new UnaryExpression(tt, ts.tokenBeg, unaryExpr());
node.setLineno(line);
return node;
new UnaryExpression(tt, ts.tokenBeg, pn, true);
uexpr.setLineno(line);
checkBadIncDec(uexpr);
代码示例来源:origin: ro.isdc.wro4j/rhino
private Node transformDefaultXmlNamepace(UnaryExpression node) {
decompiler.addToken(Token.DEFAULT);
decompiler.addName(" xml");
decompiler.addName(" namespace");
decompiler.addToken(Token.ASSIGN);
Node child = transform(node.getOperand());
return createUnary(Token.DEFAULTNAMESPACE, child);
}
代码示例来源:origin: io.apigee/rhino
/**
* Sets the operand, and sets its parent to be this node.
* @throws IllegalArgumentException} if {@code operand} is {@code null}
*/
public void setOperand(AstNode operand) {
assertNotNull(operand);
this.operand = operand;
operand.setParent(this);
}
内容来源于网络,如有侵权,请联系作者删除!