本文整理汇总了Java中org.eclipse.jdt.core.dom.InfixExpression.getOperator方法的典型用法代码示例。如果您正苦于以下问题:Java InfixExpression.getOperator方法的具体用法?Java InfixExpression.getOperator怎么用?Java InfixExpression.getOperator使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.eclipse.jdt.core.dom.InfixExpression
的用法示例。
在下文中一共展示了InfixExpression.getOperator方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: visit
import org.eclipse.jdt.core.dom.InfixExpression; //导入方法依赖的package包/类
public boolean visit(InfixExpression exp) {
Operator op = exp.getOperator();
if(isCompareOperator(op)) {
String leftExp = exp.getLeftOperand().toString();
String rightExp = exp.getRightOperand().toString();
Set<String> incVars = current.getOperations(VariableOperation.Type.INC, VariableOperation.Type.DEC);
if(exp.getLeftOperand() instanceof SimpleName && incVars.contains(leftExp))
aux(leftExp, op, exp.getRightOperand());
if(exp.getRightOperand() instanceof SimpleName && incVars.contains(rightExp))
aux(rightExp, op, exp.getLeftOperand());
}
return true;
}
示例2: isAcumulationAssign
import org.eclipse.jdt.core.dom.InfixExpression; //导入方法依赖的package包/类
private static boolean isAcumulationAssign(Assignment assignment, InfixExpression.Operator op, Predicate<Expression> acceptExpression) {
if(!(
assignment.getRightHandSide() instanceof InfixExpression &&
assignment.getLeftHandSide() instanceof SimpleName &&
assignment.getOperator() == Assignment.Operator.ASSIGN))
return false;
InfixExpression exp = (InfixExpression) assignment.getRightHandSide();
if(exp.getOperator() != op)
return false;
String assignVar = assignment.getLeftHandSide().toString();
if( exp.getLeftOperand() instanceof SimpleName &&
exp.getLeftOperand().toString().equals(assignVar) &&
acceptExpression.test(exp.getRightOperand()))
return true;
if( exp.getRightOperand() instanceof SimpleName &&
exp.getRightOperand().toString().equals(assignVar) &&
acceptExpression.test(exp.getLeftOperand()))
return true;
return false;
}
示例3: needsParentesis
import org.eclipse.jdt.core.dom.InfixExpression; //导入方法依赖的package包/类
private boolean needsParentesis(ASTNode node) {
if (!(node.getParent() instanceof InfixExpression))
return false;
if (node instanceof InstanceofExpression)
return true;
if (node instanceof InfixExpression) {
InfixExpression expression = (InfixExpression) node;
InfixExpression.Operator operator = expression.getOperator();
InfixExpression parentExpression = (InfixExpression) node.getParent();
InfixExpression.Operator parentOperator = parentExpression.getOperator();
if (parentOperator == operator)
return false;
return true;
}
return false;
}
示例4: visit
import org.eclipse.jdt.core.dom.InfixExpression; //导入方法依赖的package包/类
@Override
public boolean visit(InfixExpression node) {
if (!(node.getOperator() == InfixExpression.Operator.PLUS && STRING_IDENTIFIER.equals(node.resolveTypeBinding()
.getQualifiedName()))) {
return true;
}
this.infixExpression = node;
nodesBeingConcatenated.add(node.getLeftOperand());
nodesBeingConcatenated.add(node.getRightOperand());
@SuppressWarnings("unchecked")
List<Expression> extendedOperations = node.extendedOperands();
for (Expression expression : extendedOperations) {
nodesBeingConcatenated.add(expression);
}
return false; // prevent traversal to any String Literals
}
开发者ID:kjlubick,项目名称:fb-contrib-eclipse-quick-fixes,代码行数:20,代码来源:UseCharacterParameterizedMethodResolution.java
示例5: breakInfixOperationAtOperation
import org.eclipse.jdt.core.dom.InfixExpression; //导入方法依赖的package包/类
private static void breakInfixOperationAtOperation(ASTRewrite rewrite, Expression expression, Operator operator, int operatorOffset, boolean removeParentheses, Expression[] res) {
if (expression.getStartPosition() + expression.getLength() <= operatorOffset) {
// add to the left
res[0]= combineOperands(rewrite, res[0], expression, removeParentheses, operator);
return;
}
if (operatorOffset <= expression.getStartPosition()) {
// add to the right
res[1]= combineOperands(rewrite, res[1], expression, removeParentheses, operator);
return;
}
if (!(expression instanceof InfixExpression)) {
throw new IllegalArgumentException("Cannot break up non-infix expression"); //$NON-NLS-1$
}
InfixExpression infixExpression= (InfixExpression) expression;
if (infixExpression.getOperator() != operator) {
throw new IllegalArgumentException("Incompatible operator"); //$NON-NLS-1$
}
breakInfixOperationAtOperation(rewrite, infixExpression.getLeftOperand(), operator, operatorOffset, removeParentheses, res);
breakInfixOperationAtOperation(rewrite, infixExpression.getRightOperand(), operator, operatorOffset, removeParentheses, res);
List<Expression> extended= infixExpression.extendedOperands();
for (int i= 0; i < extended.size(); i++) {
breakInfixOperationAtOperation(rewrite, extended.get(i), operator, operatorOffset, removeParentheses, res);
}
}
示例6: isAssociative
import org.eclipse.jdt.core.dom.InfixExpression; //导入方法依赖的package包/类
private static boolean isAssociative(InfixExpression expression) {
Operator operator= expression.getOperator();
if (operator == InfixExpression.Operator.PLUS)
return isExpressionStringType(expression) || isExpressionIntegerType(expression) && isAllOperandsHaveSameType(expression);
if (operator == InfixExpression.Operator.TIMES)
return isExpressionIntegerType(expression) && isAllOperandsHaveSameType(expression);
if (operator == InfixExpression.Operator.CONDITIONAL_AND
|| operator == InfixExpression.Operator.CONDITIONAL_OR
|| operator == InfixExpression.Operator.AND
|| operator == InfixExpression.Operator.OR
|| operator == InfixExpression.Operator.XOR)
return true;
return false;
}
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion-Juno38,代码行数:19,代码来源:NecessaryParenthesesChecker.java
示例7: visit
import org.eclipse.jdt.core.dom.InfixExpression; //导入方法依赖的package包/类
@SuppressFBWarnings(value = "PRMC_POSSIBLY_REDUNDANT_METHOD_CALLS",
justification = "The extra local variables would make things more confusing.")
@Override
public boolean visit(InfixExpression node) {
if (node.getOperator() == InfixExpression.Operator.EQUALS ||
node.getOperator() == InfixExpression.Operator.NOT_EQUALS) {
Expression left = node.getLeftOperand();
Expression right = node.getRightOperand();
Object rightConst = right.resolveConstantExpressionValue();
Object leftConst = left.resolveConstantExpressionValue();
if (left instanceof MethodInvocation && rightConst instanceof Integer) {
if (rightConst.equals(0)) {
foundPotentialNewCollection((MethodInvocation) left, node);
}
} else if (right instanceof MethodInvocation && leftConst instanceof Integer) {
if (leftConst.equals(0)) {
foundPotentialNewCollection((MethodInvocation) right, node);
}
}
}
return true;
}
示例8: visit
import org.eclipse.jdt.core.dom.InfixExpression; //导入方法依赖的package包/类
@Override
public boolean visit(ConditionalExpression node) {
if (expressionToReplace != null) {
return false;
}
if (node.getExpression() instanceof InfixExpression) {
InfixExpression condExpr = (InfixExpression) node.getExpression();
boolean retVal = findFirstAndSecondFloat(node, condExpr);
if (condExpr.getOperator() == InfixExpression.Operator.GREATER) {
return retVal;
}
else if (condExpr.getOperator() == InfixExpression.Operator.LESS) {
swapFirstAndSecondFloat();
return retVal;
}
}
return true;
}
示例9: visit
import org.eclipse.jdt.core.dom.InfixExpression; //导入方法依赖的package包/类
@Override
public boolean visit(InfixExpression e) {
InfixExpression.Operator op= e.getOperator();
if (isBitOperation(op)) {
return true;
} else if (op == InfixExpression.Operator.EQUALS || op == InfixExpression.Operator.NOT_EQUALS) {
fCompareExpression= e;
return false;
}
return false;
}
示例10: visit
import org.eclipse.jdt.core.dom.InfixExpression; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public boolean visit(InfixExpression node) {
// for "Hello" + array + ':' + otherArray
if (node.getOperator() == Operator.PLUS &&
"java.lang.String".equals(node.resolveTypeBinding().getQualifiedName())) {
checkOperand(node.getLeftOperand());
checkOperand(node.getRightOperand());
List<Expression> extendedOps = node.extendedOperands();
for (Expression operand : extendedOps) {
checkOperand(operand);
}
}
return true;
}
示例11: write
import org.eclipse.jdt.core.dom.InfixExpression; //导入方法依赖的package包/类
@Override
public void write(InfixExpression infixExpression) {
InfixExpression.Operator operator = infixExpression.getOperator();
if (operator == InfixExpression.Operator.RIGHT_SHIFT_UNSIGNED) {
writeRightShiftUnsigned(infixExpression);
} else {
writeNode(infixExpression.getLeftOperand());
copySpaceAndComments();
String operatorToken = this.equivalentOperators.get(operator);
matchAndWrite(operatorToken);
copySpaceAndComments();
writeNode(infixExpression.getRightOperand());
if (infixExpression.hasExtendedOperands()) {
forEach(infixExpression.extendedOperands(), (Expression extendedOperand) -> {
copySpaceAndComments();
matchAndWrite(operatorToken);
copySpaceAndComments();
writeNode(extendedOperand);
});
}
}
}
示例12: write
import org.eclipse.jdt.core.dom.InfixExpression; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public void write(InfixExpression infixExpression) {
InfixExpression.Operator operator = infixExpression.getOperator();
if (operator == InfixExpression.Operator.RIGHT_SHIFT_UNSIGNED) {
write("rightShiftUnsigned(");
writeNode(infixExpression.getLeftOperand());
// Skip spaces before the >>> but if there's a newline (or comments) there, copy them
skipSpacesAndTabs();
copySpaceAndComments();
matchAndWrite(">>>", ",");
copySpaceAndComments();
writeNode(infixExpression.getRightOperand());
write(")");
}
else {
writeNode(infixExpression.getLeftOperand());
copySpaceAndComments();
String operatorToken = this.equivalentOperators.get(infixExpression.getOperator());
matchAndWrite(operatorToken);
copySpaceAndComments();
writeNode(infixExpression.getRightOperand());
if (infixExpression.hasExtendedOperands()) {
for (Expression extendedOperand : (List<Expression>) infixExpression.extendedOperands()) {
copySpaceAndComments();
matchAndWrite(operatorToken);
copySpaceAndComments();
writeNode(extendedOperand);
}
}
}
}
示例13: handleInfixEquals
import org.eclipse.jdt.core.dom.InfixExpression; //导入方法依赖的package包/类
private boolean handleInfixEquals(InfixExpression comparisonWithEquals) {
if (comparisonWithEquals.getOperator() != InfixExpression.Operator.EQUALS) {
return false;
}
bucketIntoExpectedActual(comparisonWithEquals.getLeftOperand(), comparisonWithEquals.getRightOperand());
return true;
}
示例14: findDiffAndFloats
import org.eclipse.jdt.core.dom.InfixExpression; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
private void findDiffAndFloats(SimpleName diffName) throws CouldntFindDiffException {
ConditionalExpression originalLine = TraversalUtil.findClosestAncestor(diffName, ConditionalExpression.class);
if (originalLine == null || !(originalLine.getExpression() instanceof InfixExpression)) {
throw new CouldntFindDiffException();
}
Block surroundingBlock = TraversalUtil.findClosestAncestor(originalLine, Block.class);
List<Statement> blockStatements = surroundingBlock.statements();
for (int i = blockStatements.size() - 1; i >= 0; i--) {
Statement statement = blockStatements.get(i);
if (statement instanceof VariableDeclarationStatement) {
List<VariableDeclarationFragment> frags = ((VariableDeclarationStatement) statement).fragments();
// I won't fix the the diff variable if it's nested with other frags, if they exist
// but we do need to look at them
VariableDeclarationFragment fragment = frags.get(0);
if (fragment.getName().getIdentifier().equals(diffName.getIdentifier())) {
Expression initializer = fragment.getInitializer();
if (initializer instanceof InfixExpression) {
InfixExpression subtraction = (InfixExpression) initializer;
if (subtraction.getOperator() == InfixExpression.Operator.MINUS &&
areNames(subtraction.getLeftOperand(), subtraction.getRightOperand())) {
this.firstFloat = (Name) subtraction.getLeftOperand();
this.secondFloat = (Name) subtraction.getRightOperand();
if (frags.size() == 1) {
this.optionalTempVariableToDelete = (VariableDeclarationStatement) statement;
}
return;
}
}
}
}
}
throw new CouldntFindDiffException();
}
示例15: needsParenthesesInInfixExpression
import org.eclipse.jdt.core.dom.InfixExpression; //导入方法依赖的package包/类
private static boolean needsParenthesesInInfixExpression(Expression expression, InfixExpression parentInfix, StructuralPropertyDescriptor locationInParent,
ITypeBinding leftOperandType) {
InfixExpression.Operator parentInfixOperator= parentInfix.getOperator();
ITypeBinding rightOperandType;
ITypeBinding parentInfixExprType;
if (leftOperandType == null) { // parentInfix has bindings
leftOperandType= parentInfix.getLeftOperand().resolveTypeBinding();
rightOperandType= parentInfix.getRightOperand().resolveTypeBinding();
parentInfixExprType= parentInfix.resolveTypeBinding();
} else {
rightOperandType= expression.resolveTypeBinding();
parentInfixExprType= getInfixExpressionType(parentInfixOperator, leftOperandType, rightOperandType);
}
boolean isAllOperandsHaveSameType= isAllOperandsHaveSameType(parentInfix, leftOperandType, rightOperandType);
if (locationInParent == InfixExpression.LEFT_OPERAND_PROPERTY) {
//we have (expr op expr) op expr
//infix expressions are evaluated from left to right -> parentheses not needed
return false;
} else if (isAssociative(parentInfixOperator, parentInfixExprType, isAllOperandsHaveSameType)) {
//we have parent op (expr op expr) and op is associative
//left op (right) == (right) op left == right op left
if (expression instanceof InfixExpression) {
InfixExpression infixExpression= (InfixExpression)expression;
Operator operator= infixExpression.getOperator();
if (isStringType(parentInfixExprType)) {
if (parentInfixOperator == InfixExpression.Operator.PLUS && operator == InfixExpression.Operator.PLUS && isStringType(infixExpression.resolveTypeBinding())) {
// 1 + ("" + 2) == 1 + "" + 2
// 1 + (2 + "") != 1 + 2 + ""
// "" + (2 + "") == "" + 2 + ""
return !isStringType(infixExpression.getLeftOperand().resolveTypeBinding()) && !isStringType(leftOperandType);
}
//"" + (1 + 2), "" + (1 - 2) etc
return true;
}
if (parentInfixOperator != InfixExpression.Operator.TIMES) {
return false;
}
if (operator == InfixExpression.Operator.TIMES) {
// x * (y * z) == x * y * z
return false;
}
if (operator == InfixExpression.Operator.REMAINDER || operator == InfixExpression.Operator.DIVIDE) {
// x * (y % z) != x * y % z , x * (y / z) == x * y / z rounding involved
return true;
}
return false;
}
return false;
} else {
return true;
}
}