org.eclipse.jdt.core.dom.InfixExpression Java Examples

The following examples show how to use org.eclipse.jdt.core.dom.InfixExpression. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: NecessaryParenthesesChecker.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
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;
}
 
Example #2
Source File: AssociativeInfixExpressionFragment.java    From eclipse.jdt.ls with Eclipse Public License 2.0 6 votes vote down vote up
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);
}
 
Example #3
Source File: BaseTranslator.java    From junion with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public Expression getLongAddress(MethodInvocation mi) {
	Expression indexExpr = getLongAddressBase(mi);
	
	NumberLiteral lit = (NumberLiteral)mi.arguments().get(2);
	if(offset != Integer.parseInt(lit.getToken()))
		throw new IllegalArgumentException("offset != " + lit);
	
	Expression args;
	if(offset == 0) args = indexExpr;
	else {
		InfixExpression add = ast.newInfixExpression();
		add.setOperator(InfixExpression.Operator.PLUS);
		add.setLeftOperand(indexExpr);
		add.setRightOperand(returnInt(offset));
		args = add;
	}
	return args;
}
 
Example #4
Source File: SourceView.java    From lapse-plus with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Tests whether a given expression is a String contant.
 * */
boolean isStringContant(Expression arg) {
	if(arg instanceof StringLiteral) {
		return true;
	} else
	if(arg instanceof InfixExpression) {
		InfixExpression infixExpr = (InfixExpression) arg;
		if(!isStringContant(infixExpr.getLeftOperand())) return false; 
		if(!isStringContant(infixExpr.getRightOperand())) return false;
					
		for(Iterator iter2 = infixExpr.extendedOperands().iterator(); iter2.hasNext(); ) {
			if(!isStringContant((Expression) iter2.next())) {
				return false;
			}
		}
		return true;
	}
	
	return false;	
}
 
Example #5
Source File: ExpressionsFix.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
public static ExpressionsFix createAddParanoidalParenthesisFix(CompilationUnit compilationUnit, ASTNode[] coveredNodes) {
	if (coveredNodes == null)
		return null;

	if (coveredNodes.length == 0)
		return null;
	// check sub-expressions in fully covered nodes
	final ArrayList<ASTNode> changedNodes = new ArrayList<ASTNode>();
	for (int i= 0; i < coveredNodes.length; i++) {
		ASTNode covered = coveredNodes[i];
		if (covered instanceof InfixExpression)
			covered.accept(new MissingParenthesisVisitor(changedNodes));
	}
	if (changedNodes.isEmpty() || (changedNodes.size() == 1 && changedNodes.get(0).equals(coveredNodes[0])))
		return null;


	CompilationUnitRewriteOperation op= new AddParenthesisOperation(changedNodes.toArray(new Expression[changedNodes.size()]));
	return new ExpressionsFix(FixMessages.ExpressionsFix_addParanoiacParentheses_description, compilationUnit, new CompilationUnitRewriteOperation[] {op});
}
 
Example #6
Source File: PolymorphismRefactoring.java    From JDeodorant with MIT License 6 votes vote down vote up
protected Expression constructExpression(AST ast, DefaultMutableTreeNode node) {
	Object object = node.getUserObject();
	if(object instanceof InfixExpression.Operator) {
		InfixExpression.Operator operator = (InfixExpression.Operator)object;
		InfixExpression infixExpression = ast.newInfixExpression();
		infixExpression.setOperator(operator);
		DefaultMutableTreeNode leftChild = (DefaultMutableTreeNode)node.getChildAt(0);
		DefaultMutableTreeNode rightChild = (DefaultMutableTreeNode)node.getChildAt(1);
		infixExpression.setLeftOperand(constructExpression(ast, leftChild));
		infixExpression.setRightOperand(constructExpression(ast, rightChild));
		return infixExpression;
	}
	else if(object instanceof Expression) {
		Expression expression = (Expression)object;
		return expression;
	}
	return null;
}
 
Example #7
Source File: StyledStringVisitor.java    From JDeodorant with MIT License 6 votes vote down vote up
public boolean visit(InfixExpression expr) {
	/*
	 * InfixExpression: Expression InfixOperator Expression { InfixOperator Expression }
	 */
	activateDiffStyle(expr);
	StyledStringStyler styler = determineDiffStyle(expr, new StyledStringStyler(ordinaryStyle));
	
	Expression leftExpression = expr.getLeftOperand();
	handleExpression(leftExpression);
	appendSpace();
	styledString.append(expr.getOperator().toString(), styler);
	appendSpace();
	Expression rightExpression = expr.getRightOperand();
	handleExpression(rightExpression);
	for (int i = 0; i < expr.extendedOperands().size(); i++){
		appendSpace();
		styledString.append(expr.getOperator().toString(), styler);
		appendSpace();
		handleExpression((Expression) expr.extendedOperands().get(i));
	}
	
	deactivateDiffStyle(expr);
	return false;
}
 
Example #8
Source File: GenerateHashCodeEqualsOperation.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private Statement createAddQualifiedHashCode(IVariableBinding binding) {

		MethodInvocation invoc= fAst.newMethodInvocation();
		invoc.setExpression(getThisAccessForHashCode(binding.getName()));
		invoc.setName(fAst.newSimpleName(METHODNAME_HASH_CODE));

		InfixExpression expr= fAst.newInfixExpression();
		expr.setOperator(Operator.EQUALS);
		expr.setLeftOperand(getThisAccessForHashCode(binding.getName()));
		expr.setRightOperand(fAst.newNullLiteral());

		ConditionalExpression cexpr= fAst.newConditionalExpression();
		cexpr.setThenExpression(fAst.newNumberLiteral("0")); //$NON-NLS-1$
		cexpr.setElseExpression(invoc);
		cexpr.setExpression(parenthesize(expr));

		return prepareAssignment(parenthesize(cexpr));
	}
 
Example #9
Source File: GenerateHashCodeEqualsOperation.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private Statement prepareAssignment(Expression rightHand) {
	// result = PRIME*result + (...)
	InfixExpression mul= fAst.newInfixExpression();
	mul.setLeftOperand(fAst.newSimpleName(VARIABLE_NAME_PRIME));
	mul.setRightOperand(fAst.newSimpleName(VARIABLE_NAME_RESULT));
	mul.setOperator(Operator.TIMES);

	Assignment ass= fAst.newAssignment();
	ass.setLeftHandSide(fAst.newSimpleName(VARIABLE_NAME_RESULT));

	InfixExpression plus= fAst.newInfixExpression();
	plus.setLeftOperand(mul);
	plus.setOperator(Operator.PLUS);
	plus.setRightOperand(rightHand);

	ass.setRightHandSide(plus);

	return fAst.newExpressionStatement(ass);
}
 
Example #10
Source File: GenerateForLoopAssistProposal.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Helper to generate an index based <code>for</code> loop to iterate over a {@link List}
 * implementation.
 * 
 * @param ast the current {@link AST} instance to generate the {@link ASTRewrite} for
 * @return an applicable {@link ASTRewrite} instance
 */
private ASTRewrite generateIndexBasedForRewrite(AST ast) {
	ASTRewrite rewrite= ASTRewrite.create(ast);

	ForStatement loopStatement= ast.newForStatement();
	SimpleName loopVariableName= resolveLinkedVariableNameWithProposals(rewrite, "int", null, true); //$NON-NLS-1$
	loopStatement.initializers().add(getForInitializer(ast, loopVariableName));

	MethodInvocation listSizeExpression= ast.newMethodInvocation();
	listSizeExpression.setName(ast.newSimpleName("size")); //$NON-NLS-1$
	Expression listExpression= (Expression) rewrite.createCopyTarget(fCurrentExpression);
	listSizeExpression.setExpression(listExpression);

	loopStatement.setExpression(getLinkedInfixExpression(rewrite, loopVariableName.getIdentifier(), listSizeExpression, InfixExpression.Operator.LESS));
	loopStatement.updaters().add(getLinkedIncrementExpression(rewrite, loopVariableName.getIdentifier()));

	Block forLoopBody= ast.newBlock();
	forLoopBody.statements().add(ast.newExpressionStatement(getIndexBasedForBodyAssignment(rewrite, loopVariableName)));
	forLoopBody.statements().add(createBlankLineStatementWithCursorPosition(rewrite));
	loopStatement.setBody(forLoopBody);
	rewrite.replace(fCurrentNode, loopStatement, null);

	return rewrite;
}
 
Example #11
Source File: CreateAndOddnessCheckResolution.java    From spotbugs with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Creates the new <CODE>InfixExpression</CODE> <CODE>(x &amp; 1) == 1</CODE>.
 */
@Override
protected InfixExpression createCorrectOddnessCheck(ASTRewrite rewrite, Expression numberExpression) {
    Assert.isNotNull(rewrite);
    Assert.isNotNull(numberExpression);

    final AST ast = rewrite.getAST();
    InfixExpression andOddnessCheck = ast.newInfixExpression();
    ParenthesizedExpression parenthesizedExpression = ast.newParenthesizedExpression();
    InfixExpression andExpression = ast.newInfixExpression();

    andExpression.setLeftOperand((Expression) rewrite.createMoveTarget(numberExpression));
    andExpression.setOperator(AND);
    andExpression.setRightOperand(ast.newNumberLiteral("1"));
    parenthesizedExpression.setExpression(andExpression);
    andOddnessCheck.setLeftOperand(parenthesizedExpression);
    andOddnessCheck.setOperator(EQUALS);
    andOddnessCheck.setRightOperand(ast.newNumberLiteral("1"));

    return andOddnessCheck;

}
 
Example #12
Source File: ExpressionsFix.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
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;
}
 
Example #13
Source File: CorrectOddnessCheckResolution.java    From spotbugs with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Override
protected void repairBug(ASTRewrite rewrite, CompilationUnit workingUnit, BugInstance bug) throws BugResolutionException {
    Assert.isNotNull(rewrite);
    Assert.isNotNull(workingUnit);
    Assert.isNotNull(bug);

    InfixExpression oddnessCheck = findOddnessCheck(getASTNode(workingUnit, bug.getPrimarySourceLineAnnotation()));
    if (oddnessCheck == null) {
        throw new BugResolutionException("No matching oddness check found at the specified source line.");
    }
    Expression numberExpression = findNumberExpression(oddnessCheck);
    if (numberExpression == null) {
        throw new BugResolutionException();
    }
    InfixExpression correctOddnessCheck = createCorrectOddnessCheck(rewrite, numberExpression);
    rewrite.replace(oddnessCheck, correctOddnessCheck, null);
}
 
Example #14
Source File: InfixExpressionWriter.java    From juniversal with MIT License 5 votes vote down vote up
@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);
			}
		}
	}
}
 
Example #15
Source File: CorrectOddnessCheckResolution.java    From spotbugs with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public boolean visit(InfixExpression node) {
    if (numberExpression == null) {
        if (!isRemainderExp(node)) {
            return true;
        }
        numberExpression = node.getLeftOperand();
    }
    return false;
}
 
Example #16
Source File: LocalCorrectionsSubProcessor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public static void addUnnecessaryInstanceofProposal(IInvocationContext context, IProblemLocation problem, Collection<ICommandAccess> proposals) {
	ASTNode selectedNode= problem.getCoveringNode(context.getASTRoot());

	ASTNode curr= selectedNode;
	while (curr instanceof ParenthesizedExpression) {
		curr= ((ParenthesizedExpression) curr).getExpression();
	}

	if (curr instanceof InstanceofExpression) {
		AST ast= curr.getAST();

		ASTRewrite rewrite= ASTRewrite.create(ast);

		InstanceofExpression inst= (InstanceofExpression) curr;

		InfixExpression expression= ast.newInfixExpression();
		expression.setLeftOperand((Expression) rewrite.createCopyTarget(inst.getLeftOperand()));
		expression.setOperator(InfixExpression.Operator.NOT_EQUALS);
		expression.setRightOperand(ast.newNullLiteral());

		rewrite.replace(inst, expression, null);

		String label= CorrectionMessages.LocalCorrectionsSubProcessor_unnecessaryinstanceof_description;
		Image image= JavaPluginImages.get(JavaPluginImages.IMG_CORRECTION_CHANGE);
		ASTRewriteCorrectionProposal proposal= new ASTRewriteCorrectionProposal(label, context.getCompilationUnit(), rewrite, IProposalRelevance.UNNECESSARY_INSTANCEOF, image);
		proposals.add(proposal);
	}

}
 
Example #17
Source File: JavaASTFlattener.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
public void appendAsRichString(final Expression expression) {
  if ((expression instanceof StringLiteral)) {
    this.appendToBuffer(this.richTextValue(((StringLiteral)expression)));
  } else {
    final boolean stringConcat = ((expression instanceof InfixExpression) && 
      this._aSTFlattenerUtils.canConvertToRichText(((InfixExpression) expression)));
    if ((!stringConcat)) {
      this.appendToBuffer("�");
    }
    expression.accept(this);
    if ((!stringConcat)) {
      this.appendToBuffer("�");
    }
  }
}
 
Example #18
Source File: AdvancedQuickAssistProcessor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private static Expression getInversedInfixExpression(ASTRewrite rewrite, InfixExpression expression, InfixExpression.Operator newOperator, SimpleNameRenameProvider provider) {
	InfixExpression newExpression= rewrite.getAST().newInfixExpression();
	newExpression.setOperator(newOperator);
	newExpression.setLeftOperand(getRenamedNameCopy(provider, rewrite, expression.getLeftOperand()));
	newExpression.setRightOperand(getRenamedNameCopy(provider, rewrite, expression.getRightOperand()));
	return newExpression;
}
 
Example #19
Source File: CorrectOddnessCheckResolution.java    From spotbugs with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public boolean visit(InfixExpression node) {
    if (oddnessCheck == null) {
        if (!isOddnessCheck(node)) {
            return true;
        }
        oddnessCheck = node;
    }
    return false;
}
 
Example #20
Source File: QuickAssistProcessor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private static void collectInfixPlusOperands(Expression expression, List<Expression> collector) {
	if (expression instanceof InfixExpression && ((InfixExpression)expression).getOperator() == InfixExpression.Operator.PLUS) {
		InfixExpression infixExpression= (InfixExpression)expression;
		
		collectInfixPlusOperands(infixExpression.getLeftOperand(), collector);
		collectInfixPlusOperands(infixExpression.getRightOperand(), collector);
		List<Expression> extendedOperands= infixExpression.extendedOperands();
		for (Iterator<Expression> iter= extendedOperands.iterator(); iter.hasNext();) {
			collectInfixPlusOperands(iter.next(), collector);
		}
		
	} else {
		collector.add(expression);
	}
}
 
Example #21
Source File: ExpressionsFix.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public static ExpressionsFix createRemoveUnnecessaryParenthesisFix(CompilationUnit compilationUnit, ASTNode[] nodes) {
	// check sub-expressions in fully covered nodes
	final ArrayList<ParenthesizedExpression> changedNodes= new ArrayList<ParenthesizedExpression>();
	for (int i= 0; i < nodes.length; i++) {
		ASTNode covered= nodes[i];
		if (covered instanceof ParenthesizedExpression || covered instanceof InfixExpression)
			covered.accept(new UnnecessaryParenthesisVisitor(changedNodes));
	}
	if (changedNodes.isEmpty())
		return null;

	HashSet<ParenthesizedExpression> expressions= new HashSet<ParenthesizedExpression>(changedNodes);
	RemoveParenthesisOperation op= new RemoveParenthesisOperation(expressions);
	return new ExpressionsFix(FixMessages.ExpressionsFix_removeUnnecessaryParentheses_description, compilationUnit, new CompilationUnitRewriteOperation[] {op});
}
 
Example #22
Source File: AssociativeInfixExpressionFragment.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
@Override
protected boolean visitNode(ASTNode node) {
	if (node instanceof InfixExpression && ((InfixExpression) node).getOperator() == fGroupRoot.getOperator())
		return true;

	fMembersInOrder.add((Expression) node);
	return false;
}
 
Example #23
Source File: TreedMapper.java    From compiler with Apache License 2.0 5 votes vote down vote up
private boolean labelMatch(ASTNode nodeM, ASTNode nodeN) {
	if (nodeM.getNodeType() != nodeN.getNodeType())
		return false;
	if (nodeM instanceof Assignment)
		return labelMatch((Assignment) nodeM, (Assignment) nodeN);
	if (nodeM instanceof InfixExpression)
		return labelMatch((InfixExpression) nodeM, (InfixExpression) nodeN);
	if (nodeM instanceof PostfixExpression)
		return labelMatch((PostfixExpression) nodeM, (PostfixExpression) nodeN);
	if (nodeM instanceof PrefixExpression)
		return labelMatch((PrefixExpression) nodeM, (PrefixExpression) nodeN);
	return true;
}
 
Example #24
Source File: LocalCorrectionsSubProcessor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
@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;
}
 
Example #25
Source File: UseEqualsResolution.java    From spotbugs with GNU Lesser General Public License v2.1 5 votes vote down vote up
protected Expression createNotEqualsExpression(ASTRewrite rewrite, InfixExpression stringEqualityCheck) {
    Expression equalsExpression = createEqualsExpression(rewrite, stringEqualityCheck);

    final AST ast = rewrite.getAST();
    PrefixExpression prefixExpression = ast.newPrefixExpression();
    prefixExpression.setOperator(PrefixExpression.Operator.NOT);
    prefixExpression.setOperand(equalsExpression);
    return prefixExpression;
}
 
Example #26
Source File: BaseTranslator.java    From junion with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public Expression addLongAddressOffset(Expression e) {
	Expression args;
	if(offset == 0) args = e;
	else {
		InfixExpression add = ast.newInfixExpression();
		add.setOperator(InfixExpression.Operator.PLUS);
		add.setLeftOperand(e);
		add.setRightOperand(returnInt(offset));
		args = add;
	}
	return args;
}
 
Example #27
Source File: BaseTranslator.java    From junion with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public Expression addOffset(Expression e, int offset) {
	if(offset == 0) return e;
	InfixExpression add = ast.newInfixExpression();
	add.setOperator(InfixExpression.Operator.PLUS);
	add.setLeftOperand(e);
	add.setRightOperand(returnInt(offset));
	return add;
}
 
Example #28
Source File: LocalCorrectionsSubProcessor.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
private static ThrowStatement getThrowForUnexpectedDefault(Expression switchExpression, AST ast, ASTRewrite astRewrite) {
	ThrowStatement newThrowStatement = ast.newThrowStatement();
	ClassInstanceCreation newCic = ast.newClassInstanceCreation();
	newCic.setType(ast.newSimpleType(ast.newSimpleName("IllegalArgumentException"))); //$NON-NLS-1$
	InfixExpression newInfixExpr = ast.newInfixExpression();
	StringLiteral newStringLiteral = ast.newStringLiteral();
	newStringLiteral.setLiteralValue("Unexpected value: "); //$NON-NLS-1$
	newInfixExpr.setLeftOperand(newStringLiteral);
	newInfixExpr.setOperator(InfixExpression.Operator.PLUS);
	newInfixExpr.setRightOperand((Expression) astRewrite.createCopyTarget(switchExpression));
	newCic.arguments().add(newInfixExpr);
	newThrowStatement.setExpression(newCic);
	return newThrowStatement;
}
 
Example #29
Source File: AccessAnalyzer.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
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;
}
 
Example #30
Source File: AssociativeInfixExpressionFragment.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private static boolean isOperatorAssociative(InfixExpression.Operator operator) {
	return    operator == InfixExpression.Operator.PLUS
	        || operator == InfixExpression.Operator.TIMES
	        || operator == InfixExpression.Operator.XOR
	        || operator == InfixExpression.Operator.OR
	        || operator == InfixExpression.Operator.AND
	        || operator == InfixExpression.Operator.CONDITIONAL_OR
	        || operator == InfixExpression.Operator.CONDITIONAL_AND;
}