本文整理汇总了Java中org.codehaus.groovy.ast.expr.BinaryExpression.getLeftExpression方法的典型用法代码示例。如果您正苦于以下问题:Java BinaryExpression.getLeftExpression方法的具体用法?Java BinaryExpression.getLeftExpression怎么用?Java BinaryExpression.getLeftExpression使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.codehaus.groovy.ast.expr.BinaryExpression
的用法示例。
在下文中一共展示了BinaryExpression.getLeftExpression方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: parseLine
import org.codehaus.groovy.ast.expr.BinaryExpression; //导入方法依赖的package包/类
List<T> parseLine(BinaryExpression exp, Class<T> cls) {
List<T> constantExpressions = new LinkedList<>();
Expression leftExpression = exp.getLeftExpression();
if (leftExpression.getClass().equals(cls)) {
T leftConstantExpression = (T) leftExpression;
constantExpressions.add(leftConstantExpression);
} else {
BinaryExpression leftBinaryExpression = (BinaryExpression) leftExpression;
List<T> leftConstantExpressions = parseLine(leftBinaryExpression, cls);
constantExpressions.addAll(leftConstantExpressions);
}
T rightExpression = (T) exp.getRightExpression();
constantExpressions.add(rightExpression);
return constantExpressions;
}
示例2: getArgsModifiers
import org.codehaus.groovy.ast.expr.BinaryExpression; //导入方法依赖的package包/类
public static YMap<String, YSet<String>> getArgsModifiers(MethodNode methodNode, YMap<String, YSet<String>> result) {
for (Parameter parameter : methodNode.getParameters()) if (!isPrimitive(translateType(parameter.getText()))) {
YList<Boolean> rewritten = al(false);
CodeVisitorSupport detectRewrittenVisitor = new CodeVisitorSupport() {
@Override
public void visitBinaryExpression(BinaryExpression expression) {
if (expression.getOperation().getText().equals("=")) {
Expression left = expression.getLeftExpression();
if (left instanceof VariableExpression) {
if (((VariableExpression) left).getName().equals(parameter.getName())) {
rewritten.set(0, true);
}
}
}
super.visitBinaryExpression(expression);
}
};
detectRewrittenVisitor.visitBlockStatement((BlockStatement) methodNode.getCode());
if (rewritten.get(0)) System.out.println(parameter.getName() + " rewritten!");
}
return result;
}
示例3: doAssignmentToLocalVariable
import org.codehaus.groovy.ast.expr.BinaryExpression; //导入方法依赖的package包/类
private boolean doAssignmentToLocalVariable(String method, BinaryExpression binExp) {
Expression left = binExp.getLeftExpression();
if (left instanceof VariableExpression) {
VariableExpression ve = (VariableExpression) left;
Variable v = ve.getAccessedVariable();
if (v instanceof DynamicVariable) return false;
if (v instanceof PropertyExpression) return false;
/* field and declaration we don't return false */
} else {
return false;
}
evaluateBinaryExpression(method, binExp);
getController().getOperandStack().dup();
getController().getCompileStack().pushLHS(true);
binExp.getLeftExpression().visit(getController().getAcg());
getController().getCompileStack().popLHS();
return true;
}
示例4: transformDeclarationExpression
import org.codehaus.groovy.ast.expr.BinaryExpression; //导入方法依赖的package包/类
private static Expression transformDeclarationExpression(final BinaryExpression bin) {
Expression leftExpression = bin.getLeftExpression();
if (leftExpression instanceof VariableExpression) {
if (ClassHelper.char_TYPE.equals(((VariableExpression) leftExpression).getOriginType())) {
Expression rightExpression = bin.getRightExpression();
if (rightExpression instanceof ConstantExpression && ClassHelper.STRING_TYPE.equals(rightExpression.getType())) {
String text = (String) ((ConstantExpression) rightExpression).getValue();
if (text.length() == 1) {
// optimize char initialization
ConstantExpression ce = new ConstantExpression(
text.charAt(0),
true
);
ce.setSourcePosition(rightExpression);
bin.setRightExpression(ce);
return bin;
}
}
}
}
return null;
}
示例5: transformBinaryExpression
import org.codehaus.groovy.ast.expr.BinaryExpression; //导入方法依赖的package包/类
private Expression transformBinaryExpression(final BinaryExpression exp) {
final int op = exp.getOperation().getType();
int token = TokenUtil.removeAssignment(op);
if (token == op) {
// no transform needed
return super.transform(exp);
}
BinaryExpression operation = new BinaryExpression(
exp.getLeftExpression(),
Token.newSymbol(token, -1, -1),
exp.getRightExpression()
);
operation.setSourcePosition(exp);
BinaryExpression result = new BinaryExpression(
exp.getLeftExpression(),
Token.newSymbol(EQUAL, -1, -1),
operation
);
result.setSourcePosition(exp);
return result;
}
示例6: visitBinaryExpression
import org.codehaus.groovy.ast.expr.BinaryExpression; //导入方法依赖的package包/类
@Override
public void visitBinaryExpression(final BinaryExpression expression) {
boolean assignment = StaticTypeCheckingSupport.isAssignment(expression.getOperation().getType());
boolean isDeclaration = expression instanceof DeclarationExpression;
Expression leftExpression = expression.getLeftExpression();
Expression rightExpression = expression.getRightExpression();
if (isDeclaration) {
recordFinalVars(leftExpression);
}
// visit RHS first for expressions like a = b = 0
inAssignment = assignment;
rightExpression.visit(this);
inAssignment = false;
leftExpression.visit(this);
if (assignment) {
recordAssignments(expression, isDeclaration, leftExpression, rightExpression);
}
}
示例7: evaluateCompareTo
import org.codehaus.groovy.ast.expr.BinaryExpression; //导入方法依赖的package包/类
private void evaluateCompareTo(BinaryExpression expression) {
Expression leftExpression = expression.getLeftExpression();
AsmClassGenerator acg = controller.getAcg();
OperandStack operandStack = controller.getOperandStack();
leftExpression.visit(acg);
operandStack.box();
// if the right hand side is a boolean expression, we need to autobox
Expression rightExpression = expression.getRightExpression();
rightExpression.visit(acg);
operandStack.box();
compareToMethod.call(controller.getMethodVisitor());
operandStack.replace(ClassHelper.Integer_TYPE,2);
}
示例8: evaluateBinaryExpressionWithAssignment
import org.codehaus.groovy.ast.expr.BinaryExpression; //导入方法依赖的package包/类
protected void evaluateBinaryExpressionWithAssignment(String method, BinaryExpression expression) {
Expression leftExpression = expression.getLeftExpression();
AsmClassGenerator acg = controller.getAcg();
OperandStack operandStack = controller.getOperandStack();
if (leftExpression instanceof BinaryExpression) {
BinaryExpression leftBinExpr = (BinaryExpression) leftExpression;
if (leftBinExpr.getOperation().getType() == Types.LEFT_SQUARE_BRACKET) {
evaluateArrayAssignmentWithOperator(method, expression, leftBinExpr);
return;
}
}
evaluateBinaryExpression(method, expression);
// br to leave a copy of rvalue on the stack. see also isPopRequired()
operandStack.dup();
controller.getCompileStack().pushLHS(true);
leftExpression.visit(acg);
controller.getCompileStack().popLHS();
}
示例9: evaluateEqual
import org.codehaus.groovy.ast.expr.BinaryExpression; //导入方法依赖的package包/类
@Override
public void evaluateEqual(final BinaryExpression expression, final boolean defineVariable) {
if (!defineVariable) {
Expression leftExpression = expression.getLeftExpression();
if (leftExpression instanceof PropertyExpression) {
PropertyExpression pexp = (PropertyExpression) leftExpression;
if (makeSetProperty(
pexp.getObjectExpression(),
pexp.getProperty(),
expression.getRightExpression(),
pexp.isSafe(),
pexp.isSpreadSafe(),
pexp.isImplicitThis(),
pexp instanceof AttributeExpression)) return;
}
}
// GROOVY-5620: Spread safe/Null safe operator on LHS is not supported
if (expression.getLeftExpression() instanceof PropertyExpression
&& ((PropertyExpression) expression.getLeftExpression()).isSpreadSafe()
&& StaticTypeCheckingSupport.isAssignment(expression.getOperation().getType())) {
// rewrite it so that it can be statically compiled
transformSpreadOnLHS(expression);
return;
}
super.evaluateEqual(expression, defineVariable);
}
示例10: doPrimitiveCompare
import org.codehaus.groovy.ast.expr.BinaryExpression; //导入方法依赖的package包/类
protected boolean doPrimitiveCompare(ClassNode leftType, ClassNode rightType, BinaryExpression binExp) {
Expression leftExp = binExp.getLeftExpression();
Expression rightExp = binExp.getRightExpression();
int operation = binExp.getOperation().getType();
int operationType = getOperandConversionType(leftType,rightType);
BinaryExpressionWriter bew = binExpWriter[operationType];
if (!bew.write(operation, true)) return false;
AsmClassGenerator acg = getController().getAcg();
OperandStack os = getController().getOperandStack();
leftExp.visit(acg);
os.doGroovyCast(bew.getNormalOpResultType());
rightExp.visit(acg);
os.doGroovyCast(bew.getNormalOpResultType());
bew.write(operation, false);
return true;
}
示例11: checkForTargetType
import org.codehaus.groovy.ast.expr.BinaryExpression; //导入方法依赖的package包/类
private ClassNode checkForTargetType(final Expression expr, final ClassNode type) {
BinaryExpression enclosingBinaryExpression = typeCheckingContext.getEnclosingBinaryExpression();
if (enclosingBinaryExpression != null && enclosingBinaryExpression instanceof DeclarationExpression
&& isEmptyCollection(expr) && isAssignment(enclosingBinaryExpression.getOperation().getType())) {
VariableExpression target = (VariableExpression) enclosingBinaryExpression.getLeftExpression();
return adjustForTargetType(target.getType(), type);
}
if (currentField != null) {
return adjustForTargetType(currentField.getType(), type);
}
if (currentProperty != null) {
return adjustForTargetType(currentProperty.getType(), type);
}
return type;
}
示例12: evaluateCompareExpression
import org.codehaus.groovy.ast.expr.BinaryExpression; //导入方法依赖的package包/类
@Override
protected void evaluateCompareExpression(final MethodCaller compareMethod, BinaryExpression binExp) {
ClassNode current = getController().getClassNode();
TypeChooser typeChooser = getController().getTypeChooser();
Expression leftExp = binExp.getLeftExpression();
ClassNode leftType = typeChooser.resolveType(leftExp, current);
Expression rightExp = binExp.getRightExpression();
ClassNode rightType = typeChooser.resolveType(rightExp, current);
if (!doPrimitiveCompare(leftType, rightType, binExp)) {
super.evaluateCompareExpression(compareMethod, binExp);
}
}
示例13: evaluateElvisEqual
import org.codehaus.groovy.ast.expr.BinaryExpression; //导入方法依赖的package包/类
public void evaluateElvisEqual(BinaryExpression expression) {
Token operation = expression.getOperation();
BinaryExpression elvisAssignmentExpression =
new BinaryExpression(
expression.getLeftExpression(),
Token.newSymbol(Types.EQUAL, operation.getStartLine(), operation.getStartColumn()),
new ElvisOperatorExpression(expression.getLeftExpression(), expression.getRightExpression())
);
this.evaluateEqual(elvisAssignmentExpression, false);
}
示例14: evaluateCompareExpression
import org.codehaus.groovy.ast.expr.BinaryExpression; //导入方法依赖的package包/类
protected void evaluateCompareExpression(MethodCaller compareMethod, BinaryExpression expression) {
Expression leftExp = expression.getLeftExpression();
TypeChooser typeChooser = controller.getTypeChooser();
ClassNode cn = controller.getClassNode();
ClassNode leftType = typeChooser.resolveType(leftExp,cn);
Expression rightExp = expression.getRightExpression();
ClassNode rightType = typeChooser.resolveType(rightExp,cn);
boolean done = false;
if ( ClassHelper.isPrimitiveType(leftType) &&
ClassHelper.isPrimitiveType(rightType))
{
BinaryExpressionMultiTypeDispatcher helper = new BinaryExpressionMultiTypeDispatcher(getController());
done = helper.doPrimitiveCompare(leftType, rightType, expression);
}
if (!done) {
AsmClassGenerator acg = controller.getAcg();
OperandStack operandStack = controller.getOperandStack();
leftExp.visit(acg);
operandStack.box();
rightExp.visit(acg);
operandStack.box();
compareMethod.call(controller.getMethodVisitor());
ClassNode resType = ClassHelper.boolean_TYPE;
if (compareMethod==findRegexMethod) {
resType = ClassHelper.OBJECT_TYPE;
}
operandStack.replace(resType,2);
}
}
示例15: evaluateBinaryExpression
import org.codehaus.groovy.ast.expr.BinaryExpression; //导入方法依赖的package包/类
protected void evaluateBinaryExpression(String message, BinaryExpression binExp) {
CompileStack compileStack = controller.getCompileStack();
Expression receiver = binExp.getLeftExpression();
Expression arguments = binExp.getRightExpression();
// ensure VariableArguments are read, not stored
compileStack.pushLHS(false);
controller.getInvocationWriter().makeSingleArgumentCall(receiver, message, arguments, binExp.isSafe());
compileStack.popLHS();
}