本文整理汇总了Java中org.eclipse.jdt.core.dom.Assignment.getRightHandSide方法的典型用法代码示例。如果您正苦于以下问题:Java Assignment.getRightHandSide方法的具体用法?Java Assignment.getRightHandSide怎么用?Java Assignment.getRightHandSide使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.eclipse.jdt.core.dom.Assignment
的用法示例。
在下文中一共展示了Assignment.getRightHandSide方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: isAcumulationAssign
import org.eclipse.jdt.core.dom.Assignment; //导入方法依赖的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;
}
示例2: endVisit
import org.eclipse.jdt.core.dom.Assignment; //导入方法依赖的package包/类
/** {@inheritDoc} */
@Override
public void endVisit(Assignment assignment) {
if ((assignment.getRightHandSide() instanceof MethodInvocation)
|| (assignment.getRightHandSide() instanceof ClassInstanceCreation)) {
// treated in respective endVisit methods
return;
}
VariableReference varRef = retrieveVariableReference(assignment.getLeftHandSide(),
null);
varRef.setOriginalCode(assignment.getLeftHandSide().toString());
VariableReference newAssignment = retrieveVariableReference(assignment.getRightHandSide(),
null);
newAssignment.setOriginalCode(assignment.getRightHandSide().toString());
if (varRef instanceof ArrayIndex) {
AssignmentStatement assignmentStatement = new AssignmentStatement(
testCase.getReference(), varRef, newAssignment);
testCase.addStatement(assignmentStatement);
return;
}
testCase.variableAssignment(varRef, newAssignment);
}
示例3: handleSimpleNameAssignment
import org.eclipse.jdt.core.dom.Assignment; //导入方法依赖的package包/类
private Expression handleSimpleNameAssignment(ASTNode replaceNode, ParameterObjectFactory pof, String parameterName, AST ast, IJavaProject javaProject, boolean useSuper) {
if (replaceNode instanceof Assignment) {
Assignment assignment= (Assignment) replaceNode;
Expression rightHandSide= assignment.getRightHandSide();
if (rightHandSide.getNodeType() == ASTNode.SIMPLE_NAME) {
SimpleName sn= (SimpleName) rightHandSide;
IVariableBinding binding= ASTNodes.getVariableBinding(sn);
if (binding != null && binding.isField()) {
if (fDescriptor.getType().getFullyQualifiedName().equals(binding.getDeclaringClass().getQualifiedName())) {
FieldInfo fieldInfo= getFieldInfo(binding.getName());
if (fieldInfo != null && binding == fieldInfo.pi.getOldBinding()) {
return pof.createFieldReadAccess(fieldInfo.pi, parameterName, ast, javaProject, useSuper, null);
}
}
}
}
}
return null;
}
示例4: endVisit
import org.eclipse.jdt.core.dom.Assignment; //导入方法依赖的package包/类
@Override
public void endVisit(Assignment node) {
Expression lhs= node.getLeftHandSide();
Expression rhs= node.getRightHandSide();
ConstraintVariable2 left= getConstraintVariable(lhs);
ConstraintVariable2 right= getConstraintVariable(rhs);
if (node.resolveBoxing()) {
ImmutableTypeVariable2 boxed= fTCModel.makeImmutableTypeVariable(node.resolveTypeBinding(), node);
setConstraintVariable(node, boxed);
} else {
setConstraintVariable(node, left); // type of assignement is type of 'left'
}
if (left == null || right == null)
return;
Assignment.Operator op= node.getOperator();
if (op == Assignment.Operator.PLUS_ASSIGN && (lhs.resolveTypeBinding() == node.getAST().resolveWellKnownType("java.lang.String"))) { //$NON-NLS-1$
//Special handling for automatic String conversion: do nothing; the RHS can be anything.
} else {
fTCModel.createElementEqualsConstraints(left, right);
fTCModel.createSubtypeConstraint(right, left); // left= right; --> [right] <= [left]
}
//TODO: other implicit conversions: numeric promotion, autoboxing?
}
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:26,代码来源:InferTypeArgumentsConstraintCreator.java
示例5: hasSideEffect
import org.eclipse.jdt.core.dom.Assignment; //导入方法依赖的package包/类
private static boolean hasSideEffect(SimpleName reference) {
ASTNode parent= reference.getParent();
while (parent instanceof QualifiedName) {
parent= parent.getParent();
}
if (parent instanceof FieldAccess) {
parent= parent.getParent();
}
ASTNode node= null;
int nameParentType= parent.getNodeType();
if (nameParentType == ASTNode.ASSIGNMENT) {
Assignment assignment= (Assignment) parent;
node= assignment.getRightHandSide();
} else if (nameParentType == ASTNode.SINGLE_VARIABLE_DECLARATION) {
SingleVariableDeclaration decl= (SingleVariableDeclaration)parent;
node= decl.getInitializer();
if (node == null) {
return false;
}
} else if (nameParentType == ASTNode.VARIABLE_DECLARATION_FRAGMENT) {
node= parent;
} else {
return false;
}
ArrayList<Expression> sideEffects= new ArrayList<>();
node.accept(new SideEffectFinder(sideEffects));
return sideEffects.size() > 0;
}
示例6: hasSideEffect
import org.eclipse.jdt.core.dom.Assignment; //导入方法依赖的package包/类
private static boolean hasSideEffect(SimpleName reference) {
ASTNode parent = reference.getParent();
while (parent instanceof QualifiedName) {
parent = parent.getParent();
}
if (parent instanceof FieldAccess) {
parent = parent.getParent();
}
ASTNode node = null;
int nameParentType = parent.getNodeType();
if (nameParentType == ASTNode.ASSIGNMENT) {
Assignment assignment = (Assignment) parent;
node = assignment.getRightHandSide();
} else if (nameParentType == ASTNode.SINGLE_VARIABLE_DECLARATION) {
SingleVariableDeclaration decl = (SingleVariableDeclaration) parent;
node = decl.getInitializer();
if (node == null) return false;
} else if (nameParentType == ASTNode.VARIABLE_DECLARATION_FRAGMENT) {
node = parent;
} else {
return false;
}
ArrayList<Expression> sideEffects = new ArrayList<Expression>();
node.accept(new SideEffectFinder(sideEffects));
return sideEffects.size() > 0;
}
示例7: endVisit
import org.eclipse.jdt.core.dom.Assignment; //导入方法依赖的package包/类
@Override
public void endVisit(Assignment node) {
Expression lhs = node.getLeftHandSide();
Expression rhs = node.getRightHandSide();
ConstraintVariable2 left = getConstraintVariable(lhs);
ConstraintVariable2 right = getConstraintVariable(rhs);
if (node.resolveBoxing()) {
ImmutableTypeVariable2 boxed =
fTCModel.makeImmutableTypeVariable(node.resolveTypeBinding(), node);
setConstraintVariable(node, boxed);
} else {
setConstraintVariable(node, left); // type of assignement is type of 'left'
}
if (left == null || right == null) return;
Assignment.Operator op = node.getOperator();
if (op == Assignment.Operator.PLUS_ASSIGN
&& (lhs.resolveTypeBinding()
== node.getAST().resolveWellKnownType("java.lang.String"))) { // $NON-NLS-1$
// Special handling for automatic String conversion: do nothing; the RHS can be anything.
} else {
fTCModel.createElementEqualsConstraints(left, right);
fTCModel.createSubtypeConstraint(right, left); // left= right; --> [right] <= [left]
}
// TODO: other implicit conversions: numeric promotion, autoboxing?
}
示例8: visit
import org.eclipse.jdt.core.dom.Assignment; //导入方法依赖的package包/类
@Override
public boolean visit(Assignment node) {
Expression leftHandSide = node.getLeftHandSide();
if (!considerBinding(resolveBinding(leftHandSide), leftHandSide)) return true;
checkParent(node);
Expression rightHandSide = node.getRightHandSide();
if (!fIsFieldFinal) {
// Write access.
AST ast = node.getAST();
MethodInvocation invocation = ast.newMethodInvocation();
invocation.setName(ast.newSimpleName(fSetter));
fReferencingSetter = true;
Expression receiver = getReceiver(leftHandSide);
if (receiver != null)
invocation.setExpression((Expression) fRewriter.createCopyTarget(receiver));
List<Expression> arguments = invocation.arguments();
if (node.getOperator() == Assignment.Operator.ASSIGN) {
arguments.add((Expression) fRewriter.createCopyTarget(rightHandSide));
} else {
// This is the compound assignment case: field+= 10;
InfixExpression exp = ast.newInfixExpression();
exp.setOperator(ASTNodes.convertToInfixOperator(node.getOperator()));
MethodInvocation getter = ast.newMethodInvocation();
getter.setName(ast.newSimpleName(fGetter));
fReferencingGetter = true;
if (receiver != null)
getter.setExpression((Expression) fRewriter.createCopyTarget(receiver));
exp.setLeftOperand(getter);
Expression rhs = (Expression) fRewriter.createCopyTarget(rightHandSide);
if (NecessaryParenthesesChecker.needsParenthesesForRightOperand(
rightHandSide, exp, leftHandSide.resolveTypeBinding())) {
ParenthesizedExpression p = ast.newParenthesizedExpression();
p.setExpression(rhs);
rhs = p;
}
exp.setRightOperand(rhs);
arguments.add(exp);
}
fRewriter.replace(node, invocation, createGroupDescription(WRITE_ACCESS));
}
rightHandSide.accept(this);
return false;
}
示例9: removeVariableReferences
import org.eclipse.jdt.core.dom.Assignment; //导入方法依赖的package包/类
/**
* Remove the field or variable declaration including the initializer.
*
* @param rewrite the ast rewrite
* @param reference the reference
*/
private void removeVariableReferences(ASTRewrite rewrite, SimpleName reference) {
ASTNode parent = reference.getParent();
while (parent instanceof QualifiedName) {
parent = parent.getParent();
}
if (parent instanceof FieldAccess) {
parent = parent.getParent();
}
int nameParentType = parent.getNodeType();
if (nameParentType == ASTNode.ASSIGNMENT) {
Assignment assignment = (Assignment) parent;
Expression rightHand = assignment.getRightHandSide();
ASTNode assignParent = assignment.getParent();
if (assignParent.getNodeType() == ASTNode.EXPRESSION_STATEMENT
&& rightHand.getNodeType() != ASTNode.ASSIGNMENT) {
removeVariableWithInitializer(rewrite, rightHand, assignParent);
} else {
rewrite.replace(assignment, rewrite.createCopyTarget(rightHand), null);
}
} else if (nameParentType == ASTNode.SINGLE_VARIABLE_DECLARATION) {
rewrite.remove(parent, null);
} else if (nameParentType == ASTNode.VARIABLE_DECLARATION_FRAGMENT) {
VariableDeclarationFragment frag = (VariableDeclarationFragment) parent;
ASTNode varDecl = frag.getParent();
List<VariableDeclarationFragment> fragments;
if (varDecl instanceof VariableDeclarationExpression) {
fragments = ((VariableDeclarationExpression) varDecl).fragments();
} else if (varDecl instanceof FieldDeclaration) {
fragments = ((FieldDeclaration) varDecl).fragments();
} else {
fragments = ((VariableDeclarationStatement) varDecl).fragments();
}
if (fragments.size() == 1) {
rewrite.remove(varDecl, null);
} else {
rewrite.remove(frag, null); // don't try to preserve
}
}
}
示例10: hasSideEffect
import org.eclipse.jdt.core.dom.Assignment; //导入方法依赖的package包/类
private static boolean hasSideEffect(SimpleName reference) {
ASTNode parent= reference.getParent();
while (parent instanceof QualifiedName) {
parent= parent.getParent();
}
if (parent instanceof FieldAccess) {
parent= parent.getParent();
}
ASTNode node= null;
int nameParentType= parent.getNodeType();
if (nameParentType == ASTNode.ASSIGNMENT) {
Assignment assignment= (Assignment) parent;
node= assignment.getRightHandSide();
} else if (nameParentType == ASTNode.SINGLE_VARIABLE_DECLARATION) {
SingleVariableDeclaration decl= (SingleVariableDeclaration)parent;
node= decl.getInitializer();
if (node == null)
return false;
} else if (nameParentType == ASTNode.VARIABLE_DECLARATION_FRAGMENT) {
node= parent;
} else {
return false;
}
ArrayList<Expression> sideEffects= new ArrayList<Expression>();
node.accept(new SideEffectFinder(sideEffects));
return sideEffects.size() > 0;
}
示例11: splitStatementAndInitializer
import org.eclipse.jdt.core.dom.Assignment; //导入方法依赖的package包/类
private boolean splitStatementAndInitializer(ExpressionStatement storeStatement) {
Expression storeExpression = storeStatement.getExpression();
if (storeExpression instanceof Assignment) {
Assignment assignment = (Assignment) storeExpression;
this.unnecessaryStoreStatement = storeStatement;
this.storedVariable = assignment.getLeftHandSide();
this.unnecessaryStoreOperator = assignment.getOperator();
this.unnecessaryStoreExpression = assignment.getRightHandSide();
return true;
}
return false;
}
示例12: findClassInstanceCreationInAssignment
import org.eclipse.jdt.core.dom.Assignment; //导入方法依赖的package包/类
private ClassInstanceCreation findClassInstanceCreationInAssignment(SimpleName collectionName,
ExpressionStatement statement) throws EnumParsingException {
// this ExpressionStatement is expected to be a wrapped assignment
Expression expression = statement.getExpression();
if (expression instanceof Assignment) {
Assignment assignment = (Assignment) expression;
if (areNamesEqual(collectionName, findNameOfCollection(assignment.getLeftHandSide()))) {
if (assignment.getRightHandSide() instanceof ClassInstanceCreation) {
return (ClassInstanceCreation) assignment.getRightHandSide();
}
}
}
throw new EnumParsingException();
}
示例13: visit
import org.eclipse.jdt.core.dom.Assignment; //导入方法依赖的package包/类
@Override
public boolean visit(Assignment node) {
if(node.getLeftHandSide() instanceof SimpleName) {
String varName = node.getLeftHandSide().toString();
VariableOperation.Type op = null;
if(node.getOperator() == Assignment.Operator.PLUS_ASSIGN && node.getRightHandSide() instanceof NumberLiteral ||
isAcumulationAssign(node, InfixExpression.Operator.PLUS, (e) -> e instanceof NumberLiteral))
op = Type.INC;
else if(node.getOperator() == Assignment.Operator.MINUS_ASSIGN && node.getRightHandSide() instanceof NumberLiteral ||
isAcumulationAssign(node, InfixExpression.Operator.MINUS, (e) -> e instanceof NumberLiteral))
op = Type.DEC;
if(op != null)
current.addOperation(new VariableOperation(varName, op));
else {
op = Type.SUBS;
Object[] params = new Object[0];
if(node.getOperator() == Assignment.Operator.PLUS_ASSIGN ||
isAcumulationAssign(node, InfixExpression.Operator.PLUS, (e) -> true)) {
op = Type.ACC;
params = new Object[] {GathererType.SUM};
}
else if(node.getOperator() == Assignment.Operator.MINUS_ASSIGN ||
isAcumulationAssign(node, InfixExpression.Operator.MINUS, (e) -> true)) {
op = Type.ACC;
params = new Object[] {GathererType.MINUS};
}
else if(node.getOperator() == Assignment.Operator.TIMES_ASSIGN ||
isAcumulationAssign(node, InfixExpression.Operator.TIMES, (e) -> true)) {
// node.getOperator() == Assignment.Operator.DIVIDE_ASSIGN ||
// isAcumulationAssign(node, InfixExpression.Operator.DIVIDE, (e) -> true)) {
op = Type.ACC;
params = new Object[] {GathererType.PROD};
}
current.addOperation(new VariableOperation(varName, op, params));
}
}
return true;
}
示例14: getAssignedValue
import org.eclipse.jdt.core.dom.Assignment; //导入方法依赖的package包/类
/**
* Converts an assignment, postfix expression or prefix expression into an
* assignable equivalent expression using the getter.
*
* @param node
* the assignment/prefix/postfix node
* @param astRewrite
* the astRewrite to use
* @param getterExpression
* the expression to insert for read accesses or
* <code>null</code> if such an expression does not exist
* @param variableType
* the type of the variable that the result will be assigned to
* @param is50OrHigher
* <code>true</code> if a 5.0 or higher environment can be used
* @return an expression that can be assigned to the type variableType with
* node being replaced by a equivalent expression using the getter
*/
public static Expression getAssignedValue(ASTNode node, ASTRewrite astRewrite, Expression getterExpression, ITypeBinding variableType, boolean is50OrHigher) {
InfixExpression.Operator op = null;
AST ast = astRewrite.getAST();
if (isNotInBlock(node)) {
return null;
}
if (node.getNodeType() == ASTNode.ASSIGNMENT) {
Assignment assignment = ((Assignment) node);
Expression rightHandSide = assignment.getRightHandSide();
Expression copiedRightOp = (Expression) astRewrite.createCopyTarget(rightHandSide);
if (assignment.getOperator() == Operator.ASSIGN) {
ITypeBinding rightHandSideType = rightHandSide.resolveTypeBinding();
copiedRightOp = createNarrowCastIfNessecary(copiedRightOp, rightHandSideType, ast, variableType, is50OrHigher);
return copiedRightOp;
}
if (getterExpression != null) {
InfixExpression infix = ast.newInfixExpression();
infix.setLeftOperand(getterExpression);
infix.setOperator(ASTNodes.convertToInfixOperator(assignment.getOperator()));
ITypeBinding infixType = infix.resolveTypeBinding();
if (NecessaryParenthesesChecker.needsParenthesesForRightOperand(rightHandSide, infix, variableType)) {
ParenthesizedExpression p = ast.newParenthesizedExpression();
p.setExpression(copiedRightOp);
copiedRightOp = p;
}
infix.setRightOperand(copiedRightOp);
return createNarrowCastIfNessecary(infix, infixType, ast, variableType, is50OrHigher);
}
} else if (node.getNodeType() == ASTNode.POSTFIX_EXPRESSION) {
PostfixExpression po = (PostfixExpression) node;
if (po.getOperator() == PostfixExpression.Operator.INCREMENT) {
op = InfixExpression.Operator.PLUS;
}
if (po.getOperator() == PostfixExpression.Operator.DECREMENT) {
op = InfixExpression.Operator.MINUS;
}
} else if (node.getNodeType() == ASTNode.PREFIX_EXPRESSION) {
PrefixExpression pe = (PrefixExpression) node;
if (pe.getOperator() == PrefixExpression.Operator.INCREMENT) {
op = InfixExpression.Operator.PLUS;
}
if (pe.getOperator() == PrefixExpression.Operator.DECREMENT) {
op= InfixExpression.Operator.MINUS;
}
}
if (op != null && getterExpression != null) {
return createInfixInvocationFromPostPrefixExpression(op, getterExpression, ast, variableType, is50OrHigher);
}
return null;
}
示例15: getAssignedValue
import org.eclipse.jdt.core.dom.Assignment; //导入方法依赖的package包/类
/**
* Converts an assignment, postfix expression or prefix expression into an assignable equivalent
* expression using the getter.
*
* @param node the assignment/prefix/postfix node
* @param astRewrite the astRewrite to use
* @param getterExpression the expression to insert for read accesses or <code>null</code> if such
* an expression does not exist
* @param variableType the type of the variable that the result will be assigned to
* @param is50OrHigher <code>true</code> if a 5.0 or higher environment can be used
* @return an expression that can be assigned to the type variableType with node being replaced by
* a equivalent expression using the getter
*/
public static Expression getAssignedValue(
ASTNode node,
ASTRewrite astRewrite,
Expression getterExpression,
ITypeBinding variableType,
boolean is50OrHigher) {
InfixExpression.Operator op = null;
AST ast = astRewrite.getAST();
if (isNotInBlock(node)) return null;
if (node.getNodeType() == ASTNode.ASSIGNMENT) {
Assignment assignment = ((Assignment) node);
Expression rightHandSide = assignment.getRightHandSide();
Expression copiedRightOp = (Expression) astRewrite.createCopyTarget(rightHandSide);
if (assignment.getOperator() == Operator.ASSIGN) {
ITypeBinding rightHandSideType = rightHandSide.resolveTypeBinding();
copiedRightOp =
createNarrowCastIfNessecary(
copiedRightOp, rightHandSideType, ast, variableType, is50OrHigher);
return copiedRightOp;
}
if (getterExpression != null) {
InfixExpression infix = ast.newInfixExpression();
infix.setLeftOperand(getterExpression);
infix.setOperator(ASTNodes.convertToInfixOperator(assignment.getOperator()));
ITypeBinding infixType = infix.resolveTypeBinding();
if (NecessaryParenthesesChecker.needsParenthesesForRightOperand(
rightHandSide, infix, variableType)) {
ParenthesizedExpression p = ast.newParenthesizedExpression();
p.setExpression(copiedRightOp);
copiedRightOp = p;
}
infix.setRightOperand(copiedRightOp);
return createNarrowCastIfNessecary(infix, infixType, ast, variableType, is50OrHigher);
}
} else if (node.getNodeType() == ASTNode.POSTFIX_EXPRESSION) {
PostfixExpression po = (PostfixExpression) node;
if (po.getOperator() == PostfixExpression.Operator.INCREMENT)
op = InfixExpression.Operator.PLUS;
if (po.getOperator() == PostfixExpression.Operator.DECREMENT)
op = InfixExpression.Operator.MINUS;
} else if (node.getNodeType() == ASTNode.PREFIX_EXPRESSION) {
PrefixExpression pe = (PrefixExpression) node;
if (pe.getOperator() == PrefixExpression.Operator.INCREMENT)
op = InfixExpression.Operator.PLUS;
if (pe.getOperator() == PrefixExpression.Operator.DECREMENT)
op = InfixExpression.Operator.MINUS;
}
if (op != null && getterExpression != null) {
return createInfixInvocationFromPostPrefixExpression(
op, getterExpression, ast, variableType, is50OrHigher);
}
return null;
}