本文整理汇总了Java中org.eclipse.jdt.core.dom.InfixExpression类的典型用法代码示例。如果您正苦于以下问题:Java InfixExpression类的具体用法?Java InfixExpression怎么用?Java InfixExpression使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
InfixExpression类属于org.eclipse.jdt.core.dom包,在下文中一共展示了InfixExpression类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: locationNeedsParentheses
import org.eclipse.jdt.core.dom.InfixExpression; //导入依赖的package包/类
private static boolean locationNeedsParentheses(StructuralPropertyDescriptor locationInParent) {
if (locationInParent instanceof ChildListPropertyDescriptor && locationInParent != InfixExpression.EXTENDED_OPERANDS_PROPERTY) {
// e.g. argument lists of MethodInvocation, ClassInstanceCreation, dimensions of ArrayCreation ...
return false;
}
if (locationInParent == VariableDeclarationFragment.INITIALIZER_PROPERTY
|| locationInParent == SingleVariableDeclaration.INITIALIZER_PROPERTY
|| locationInParent == ReturnStatement.EXPRESSION_PROPERTY
|| locationInParent == EnhancedForStatement.EXPRESSION_PROPERTY
|| locationInParent == ForStatement.EXPRESSION_PROPERTY
|| locationInParent == WhileStatement.EXPRESSION_PROPERTY
|| locationInParent == DoStatement.EXPRESSION_PROPERTY
|| locationInParent == AssertStatement.EXPRESSION_PROPERTY
|| locationInParent == AssertStatement.MESSAGE_PROPERTY
|| locationInParent == IfStatement.EXPRESSION_PROPERTY
|| locationInParent == SwitchStatement.EXPRESSION_PROPERTY
|| locationInParent == SwitchCase.EXPRESSION_PROPERTY
|| locationInParent == ArrayAccess.INDEX_PROPERTY
|| locationInParent == ThrowStatement.EXPRESSION_PROPERTY
|| locationInParent == SynchronizedStatement.EXPRESSION_PROPERTY
|| locationInParent == ParenthesizedExpression.EXPRESSION_PROPERTY) {
return false;
}
return true;
}
示例2: createInvocation
import org.eclipse.jdt.core.dom.InfixExpression; //导入依赖的package包/类
private MethodInvocation createInvocation(AST ast, Expression operand, String operator) {
Expression receiver = getReceiver(operand);
MethodInvocation invocation = ast.newMethodInvocation();
invocation.setName(ast.newSimpleName(fSetter));
if (receiver != null)
invocation.setExpression((Expression) fRewriter.createCopyTarget(receiver));
InfixExpression argument = ast.newInfixExpression();
invocation.arguments().add(argument);
if ("++".equals(operator)) { // $NON-NLS-1$
argument.setOperator(InfixExpression.Operator.PLUS);
} else if ("--".equals(operator)) { // $NON-NLS-1$
argument.setOperator(InfixExpression.Operator.MINUS);
} else {
Assert.isTrue(false, "Should not happen"); // $NON-NLS-1$
}
MethodInvocation getter = ast.newMethodInvocation();
getter.setName(ast.newSimpleName(fGetter));
if (receiver != null) getter.setExpression((Expression) fRewriter.createCopyTarget(receiver));
argument.setLeftOperand(getter);
argument.setRightOperand(ast.newNumberLiteral("1")); // $NON-NLS-1$
fReferencingGetter = true;
fReferencingSetter = true;
return invocation;
}
示例3: apply
import org.eclipse.jdt.core.dom.InfixExpression; //导入依赖的package包/类
@Override
public InfixExpression apply(Object object, MethodInvocation methodInvocation) {
List arguments = methodInvocation.arguments();
if (arguments.size() == 2) {
return astNodeFactory.infixExpression(EQUALS,
argumentAsExpression(arguments.get(1)),
argumentAsExpression(arguments.get(0)));
}
if (arguments.size() == 3) {
return astNodeFactory.infixExpression(EQUALS,
argumentAsExpression(arguments.get(2)),
argumentAsExpression(arguments.get(1)));
}
throw new UnsupportedOperationException("Supported only 2-, 3-arity assertEquals/assertArrayEquals invocation");
}
示例4: apply
import org.eclipse.jdt.core.dom.InfixExpression; //导入依赖的package包/类
@Override
public InfixExpression apply(Object object, MethodInvocation methodInvocation) {
List arguments = methodInvocation.arguments();
if (arguments.size() == 1) {
return astNodeFactory.infixExpression(EQUALS,
argumentAsExpression(arguments.get(0)),
astNodeFactory.nullLiteral());
}
if (arguments.size() == 2) {
return astNodeFactory.infixExpression(EQUALS,
argumentAsExpression(arguments.get(1)),
astNodeFactory.nullLiteral());
}
throw new UnsupportedOperationException("Supported only 1-, 2-arity assertNull invocation");
}
示例5: apply
import org.eclipse.jdt.core.dom.InfixExpression; //导入依赖的package包/类
@Override
public InfixExpression apply(Object object, MethodInvocation methodInvocation) {
List arguments = methodInvocation.arguments();
if (arguments.size() == 1) {
return astNodeFactory.infixExpression(NOT_EQUALS,
argumentAsExpression(arguments.get(0)),
astNodeFactory.nullLiteral());
}
if (arguments.size() == 2) {
return astNodeFactory.infixExpression(NOT_EQUALS,
argumentAsExpression(arguments.get(1)),
astNodeFactory.nullLiteral());
}
throw new UnsupportedOperationException("Supported only 1-, 2-arity assertNotNull invocation");
}
示例6: apply
import org.eclipse.jdt.core.dom.InfixExpression; //导入依赖的package包/类
@Override
public InfixExpression apply(Object object, MethodInvocation verifyMethodInvocation) {
List arguments = verifyMethodInvocation.arguments();
return nodeFactory.infixExpression(TIMES,
nodeFactory.numberLiteral("0"),
nodeFactory.fieldAccess("_", nodeFactory.clone((Expression) arguments.get(0))));
}
示例7: apply
import org.eclipse.jdt.core.dom.InfixExpression; //导入依赖的package包/类
@Override
public InfixExpression apply(Object object, MethodInvocation verifyMethodInvocation) {
List arguments = verifyMethodInvocation.arguments();
MethodInvocation parentMethodInvocation = (MethodInvocation) verifyMethodInvocation.getParent();
return nodeFactory.infixExpression(TIMES,
cardinality(arguments.size() == 2 ? Optional.of(arguments.get(1)) : empty()),
nodeFactory.methodInvocation(parentMethodInvocation.getName().getFullyQualifiedName(),
(List<Expression>) parentMethodInvocation.arguments().stream()
.map(matcherHandler::applyMatchers).collect(toList()),
nodeFactory.clone((Expression) arguments.get(0))));
}
示例8: 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;
}
示例9: 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;
}
示例10: visit
import org.eclipse.jdt.core.dom.InfixExpression; //导入依赖的package包/类
@Override
public boolean visit(ArrayAccess node) {
String arrayName = node.getArray().toString();
List<String> iterators = iteratorsByArray.get(arrayName);
if(iterators == null) {
iterators= new ArrayList<>();
}
String iteratorName = node.getIndex().getNodeType() == ASTNode.INFIX_EXPRESSION ?
filterIteratorName((InfixExpression) node.getIndex()) : node.getIndex().toString();
if(!iterators.contains(iteratorName)) {
isArrayPrimitiveFigure = true;
iterators.add(iteratorName);
allIterators.add(iteratorName);
iteratorsByArray.put(arrayName, iterators);
System.out.println("A variavel " + iteratorName + " est� a iterar sobre a array: " + node.getArray().toString());
}
return super.visit(node);
}
示例11: isAllOperandsHaveSameType
import org.eclipse.jdt.core.dom.InfixExpression; //导入依赖的package包/类
private static boolean isAllOperandsHaveSameType(InfixExpression expression, ITypeBinding leftOperandType, ITypeBinding rightOperandType) {
ITypeBinding binding= leftOperandType;
if (binding == null) {
return false;
}
ITypeBinding current= rightOperandType;
if (binding != current) {
return false;
}
for (Iterator<Expression> iterator= expression.extendedOperands().iterator(); iterator.hasNext();) {
Expression operand= iterator.next();
current= operand.resolveTypeBinding();
if (binding != current) {
return false;
}
}
return true;
}
示例12: isAssociative
import org.eclipse.jdt.core.dom.InfixExpression; //导入依赖的package包/类
private static boolean isAssociative(InfixExpression.Operator operator, ITypeBinding infixExprType, boolean isAllOperandsHaveSameType) {
if (operator == InfixExpression.Operator.PLUS) {
return isStringType(infixExprType) || isIntegerType(infixExprType) && isAllOperandsHaveSameType;
}
if (operator == InfixExpression.Operator.TIMES) {
return isIntegerType(infixExprType) && isAllOperandsHaveSameType;
}
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;
}
示例13: getInfixExpressionType
import org.eclipse.jdt.core.dom.InfixExpression; //导入依赖的package包/类
/**
* Returns the type of infix expression based on its operands and operator.
*
* @param operator the operator of infix expression
* @param leftOperandType the type of left operand of infix expression
* @param rightOperandType the type of right operand of infix expression
* @return the type of infix expression if the type of both the operands is same or if the type
* of either operand of a + operator is String, <code>null</code> otherwise.
*
* @since 3.9
*/
private static ITypeBinding getInfixExpressionType(InfixExpression.Operator operator, ITypeBinding leftOperandType, ITypeBinding rightOperandType) {
if (leftOperandType == rightOperandType) {
return leftOperandType;
}
if (operator == InfixExpression.Operator.PLUS) {
if (isStringType(leftOperandType)) {
return leftOperandType;
} else if (isStringType(rightOperandType)) {
return rightOperandType;
}
}
// If the left and right operand types are different, we assume that parentheses are needed.
// This is to avoid complications of numeric promotions and for readability of complicated code.
return null;
}
示例14: rewriteInfixExpression
import org.eclipse.jdt.core.dom.InfixExpression; //导入依赖的package包/类
private RefactoringStatus rewriteInfixExpression(ASTRewrite astRewrite,
ImportRewrite importRewrite, InfixExpression ie,
String fullyQualifiedTypeName) {
final RefactoringStatus status = new RefactoringStatus();
final AST ast = ie.getAST();
final Expression leftExpCopy = (Expression) ASTNode.copySubtree(ast,
ie.getLeftOperand());
final Expression rightExpCopy = (Expression) ASTNode.copySubtree(ast,
ie.getRightOperand());
final NumberLiteral zero = ast.newNumberLiteral();
astRewrite.replace(ie.getRightOperand(), zero, null);
final MethodInvocation newInvocation = ast.newMethodInvocation();
newInvocation.setExpression(leftExpCopy);
newInvocation.setName(ast.newSimpleName("compareTo")); //$NON-NLS-1$
newInvocation.arguments().add(rightExpCopy);
astRewrite.replace(ie.getLeftOperand(), newInvocation, null);
if (((ASTNode) newInvocation.arguments().get(0)).getNodeType() == ASTNode.SIMPLE_NAME
&& this.fieldsToRefactor.contains(((SimpleName) ie
.getRightOperand()).resolveBinding().getJavaElement()))
this.rewriteReference(astRewrite, importRewrite,
(SimpleName) newInvocation.arguments().get(0),
fullyQualifiedTypeName);
if (((ASTNode) newInvocation.getExpression()).getNodeType() == ASTNode.SIMPLE_NAME
&& this.fieldsToRefactor.contains(((SimpleName) ie
.getLeftOperand()).resolveBinding().getJavaElement()))
this.rewriteReference(astRewrite, importRewrite,
(SimpleName) newInvocation.getExpression(),
fullyQualifiedTypeName);
return status;
}
开发者ID:ponder-lab,项目名称:Constants-to-Enum-Eclipse-Plugin,代码行数:38,代码来源:ConvertConstantsToEnumRefactoring.java
示例15: createSubPartFragmentBySourceRange
import org.eclipse.jdt.core.dom.InfixExpression; //导入依赖的package包/类
public static IExpressionFragment createSubPartFragmentBySourceRange(
InfixExpression node, ISourceRange range, ICompilationUnit cu) throws JavaModelException {
Assert.isNotNull(node);
Assert.isNotNull(range);
Assert.isTrue(!Util.covers(range, node));
Assert.isTrue(Util.covers(SourceRangeFactory.create(node), range));
if (!isAssociativeInfix(node)) return null;
InfixExpression groupRoot = findGroupRoot(node);
Assert.isTrue(isAGroupRoot(groupRoot));
List<Expression> groupMembers =
AssociativeInfixExpressionFragment.findGroupMembersInOrderFor(groupRoot);
List<Expression> subGroup = findSubGroupForSourceRange(groupMembers, range);
if (subGroup.isEmpty() || rangeIncludesExtraNonWhitespace(range, subGroup, cu)) return null;
return new AssociativeInfixExpressionFragment(groupRoot, subGroup);
}