当前位置: 首页>>代码示例>>Java>>正文


Java Assignment.getOperator方法代码示例

本文整理汇总了Java中org.eclipse.jdt.core.dom.Assignment.getOperator方法的典型用法代码示例。如果您正苦于以下问题:Java Assignment.getOperator方法的具体用法?Java Assignment.getOperator怎么用?Java Assignment.getOperator使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.eclipse.jdt.core.dom.Assignment的用法示例。


在下文中一共展示了Assignment.getOperator方法的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;
}
 
开发者ID:andre-santos-pt,项目名称:pandionj,代码行数:25,代码来源:VarParser.java

示例2: endVisit

import org.eclipse.jdt.core.dom.Assignment; //导入方法依赖的package包/类
@Override
public void endVisit(Assignment node) {
	if (skipNode(node)) {
		return;
	}
	FlowInfo lhs = getFlowInfo(node.getLeftHandSide());
	FlowInfo rhs = getFlowInfo(node.getRightHandSide());
	if (lhs instanceof LocalFlowInfo) {
		LocalFlowInfo llhs = (LocalFlowInfo) lhs;
		llhs.setWriteAccess(fFlowContext);
		if (node.getOperator() != Assignment.Operator.ASSIGN) {
			GenericSequentialFlowInfo tmp = createSequential();
			tmp.merge(new LocalFlowInfo(llhs, FlowInfo.READ, fFlowContext), fFlowContext);
			tmp.merge(rhs, fFlowContext);
			rhs = tmp;
		}
	}
	GenericSequentialFlowInfo info = createSequential(node);
	// first process right and side and then left hand side.
	info.merge(rhs, fFlowContext);
	info.merge(lhs, fFlowContext);
}
 
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:23,代码来源:FlowAnalyzer.java

示例3: 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

示例4: endVisit

import org.eclipse.jdt.core.dom.Assignment; //导入方法依赖的package包/类
@Override
public void endVisit(Assignment node) {
	if (skipNode(node))
		return;
	FlowInfo lhs= getFlowInfo(node.getLeftHandSide());
	FlowInfo rhs= getFlowInfo(node.getRightHandSide());
	if (lhs instanceof LocalFlowInfo) {
		LocalFlowInfo llhs= (LocalFlowInfo)lhs;
		llhs.setWriteAccess(fFlowContext);
		if (node.getOperator() != Assignment.Operator.ASSIGN) {
			GenericSequentialFlowInfo tmp= createSequential();
			tmp.merge(new LocalFlowInfo(llhs, FlowInfo.READ, fFlowContext), fFlowContext);
			tmp.merge(rhs, fFlowContext);
			rhs= tmp;
		}
	}
	GenericSequentialFlowInfo info= createSequential(node);
	// first process right and side and then left hand side.
	info.merge(rhs, fFlowContext);
	info.merge(lhs, fFlowContext);
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:22,代码来源:FlowAnalyzer.java

示例5: 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:eclipse,项目名称:che,代码行数:28,代码来源:InferTypeArgumentsConstraintCreator.java

示例6: 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;
}
 
开发者ID:eclipse,项目名称:che,代码行数:45,代码来源:AccessAnalyzer.java

示例7: visit

import org.eclipse.jdt.core.dom.Assignment; //导入方法依赖的package包/类
/**
 * We only need to investigate the right hand side of an assignment.
 */
public boolean visit(Assignment node){
	node.getRightHandSide().accept(this);
	/* If the operator uses the original variable, then
	 * we need to add it as well (ie. anything operator except
	 * regular assignment) */
	if(node.getOperator() != Assignment.Operator.ASSIGN)
		node.getLeftHandSide().accept(this);
	return false;
}
 
开发者ID:qhanam,项目名称:Slicer,代码行数:13,代码来源:FDDVisitor.java

示例8: write

import org.eclipse.jdt.core.dom.Assignment; //导入方法依赖的package包/类
@Override
public void write(Assignment assignment) {
    Assignment.Operator operator = assignment.getOperator();

    writeNode(assignment.getLeftHandSide());

    copySpaceAndComments();
    if (operator == Assignment.Operator.ASSIGN)
        matchAndWrite("=");
    else if (operator == Assignment.Operator.PLUS_ASSIGN)
        matchAndWrite("+=");
    else if (operator == Assignment.Operator.MINUS_ASSIGN)
        matchAndWrite("-=");
    else if (operator == Assignment.Operator.TIMES_ASSIGN)
        matchAndWrite("*=");
    else if (operator == Assignment.Operator.DIVIDE_ASSIGN)
        matchAndWrite("/=");
    else if (operator == Assignment.Operator.BIT_AND_ASSIGN)
        matchAndWrite("&=");
    else if (operator == Assignment.Operator.BIT_OR_ASSIGN)
        matchAndWrite("|=");
    else if (operator == Assignment.Operator.BIT_XOR_ASSIGN)
        matchAndWrite("^=");
    else if (operator == Assignment.Operator.REMAINDER_ASSIGN)
        matchAndWrite("%=");
    else if (operator == Assignment.Operator.LEFT_SHIFT_ASSIGN)
        matchAndWrite("<<=");
    else if (operator == Assignment.Operator.RIGHT_SHIFT_SIGNED_ASSIGN)
        matchAndWrite(">>=");
    else if (operator == Assignment.Operator.RIGHT_SHIFT_UNSIGNED_ASSIGN)
        throw sourceNotSupported(">>>= operator not supported; change Java of the form 'a >>>= b' to 'a = a >>> b' instead, which is supported");

    copySpaceAndComments();
    writeNode(assignment.getRightHandSide());
}
 
开发者ID:juniversal,项目名称:juniversal,代码行数:36,代码来源:AssignmentWriter.java

示例9: visitAssign

import org.eclipse.jdt.core.dom.Assignment; //导入方法依赖的package包/类
/**
 * lhs op rhs
 */
private void visitAssign(final Assignment node)
{
  final int lineNo = lineStart(node);
  // new dependence
  final IResolvedLine rd = createDependence(LK_ASSIGNMENT, lineNo, mdg.parent());
  // separate the variable definition from any additional expressions
  final Expression lhs = node.getLeftHandSide();
  // field access, super field access, or name
  final Expression def = lhsDef(lhs);
  // new variable
  final IResolvedData rv = factory.resolveExpression(def, node, null, true, true);
  // map this definition
  rd.definitions().add(rv);
  // process the qualifying expressions of the def as left hand side uses
  final Expression qualifier = getQualifier(lhs);
  if (qualifier != null)
  {
    appendDependences(rd, qualifier, rv, true);
  }
  // append RHS data dependences
  appendDependences(rd, node.getRightHandSide(), null, false);
  // append implicit data dependence
  if (node.getOperator() != Assignment.Operator.ASSIGN)
  {
    rd.uses().add(rv);
  }
}
 
开发者ID:UBPL,项目名称:jive,代码行数:31,代码来源:StatementVisitor.java

示例10: 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;
}
 
开发者ID:kjlubick,项目名称:fb-contrib-eclipse-quick-fixes,代码行数:15,代码来源:UnnecessaryStoreResolution.java

示例11: 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;
}
 
开发者ID:andre-santos-pt,项目名称:pandionj,代码行数:43,代码来源:VarParser.java

示例12: 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;
}
 
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:69,代码来源:GetterSetterUtil.java

示例13: 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;
}
 
开发者ID:eclipse,项目名称:che,代码行数:67,代码来源:GetterSetterUtil.java

示例14: 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;
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:45,代码来源:AccessAnalyzer.java

示例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;
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:56,代码来源:GetterSetterUtil.java


注:本文中的org.eclipse.jdt.core.dom.Assignment.getOperator方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。