Java Code Examples for org.eclipse.jdt.core.dom.PrefixExpression#setOperand()

The following examples show how to use org.eclipse.jdt.core.dom.PrefixExpression#setOperand() . 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: GenerateHashCodeEqualsOperation.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 7 votes vote down vote up
private Statement createArrayComparison(String name) {
	MethodInvocation invoc= fAst.newMethodInvocation();
	invoc.setName(fAst.newSimpleName(METHODNAME_EQUALS));
	invoc.setExpression(getQualifiedName(JAVA_UTIL_ARRAYS));
	invoc.arguments().add(getThisAccessForEquals(name));
	invoc.arguments().add(getOtherAccess(name));

	PrefixExpression pe= fAst.newPrefixExpression();
	pe.setOperator(PrefixExpression.Operator.NOT);
	pe.setOperand(invoc);

	IfStatement ifSt= fAst.newIfStatement();
	ifSt.setExpression(pe);
	ifSt.setThenStatement(getThenStatement(getReturnFalse()));

	return ifSt;
}
 
Example 2
Source File: GenerateHashCodeEqualsOperation.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private Statement createOuterComparison() {
	MethodInvocation outer1= fAst.newMethodInvocation();
	outer1.setName(fAst.newSimpleName(METHODNAME_OUTER_TYPE));

	MethodInvocation outer2= fAst.newMethodInvocation();
	outer2.setName(fAst.newSimpleName(METHODNAME_OUTER_TYPE));
	outer2.setExpression(fAst.newSimpleName(VARIABLE_NAME_EQUALS_CASTED));

	MethodInvocation outerEql= fAst.newMethodInvocation();
	outerEql.setName(fAst.newSimpleName(METHODNAME_EQUALS));
	outerEql.setExpression(outer1);
	outerEql.arguments().add(outer2);

	PrefixExpression not= fAst.newPrefixExpression();
	not.setOperand(outerEql);
	not.setOperator(PrefixExpression.Operator.NOT);

	IfStatement notEqNull= fAst.newIfStatement();
	notEqNull.setExpression(not);
	notEqNull.setThenStatement(getThenStatement(getReturnFalse()));
	return notEqNull;
}
 
Example 3
Source File: GenerateHashCodeEqualsOperation.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private Statement createMultiArrayComparison(String name) {
	MethodInvocation invoc= fAst.newMethodInvocation();
	invoc.setName(fAst.newSimpleName(METHODNAME_DEEP_EQUALS));
	invoc.setExpression(getQualifiedName(JAVA_UTIL_ARRAYS));
	invoc.arguments().add(getThisAccessForEquals(name));
	invoc.arguments().add(getOtherAccess(name));

	PrefixExpression pe= fAst.newPrefixExpression();
	pe.setOperator(PrefixExpression.Operator.NOT);
	pe.setOperand(invoc);

	IfStatement ifSt= fAst.newIfStatement();
	ifSt.setExpression(pe);
	ifSt.setThenStatement(getThenStatement(getReturnFalse()));

	return ifSt;
}
 
Example 4
Source File: InvertBooleanUtility.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
private static Expression getInversedNotExpression(ASTRewrite rewrite, Expression expression, AST ast) {
	PrefixExpression prefixExpression = ast.newPrefixExpression();
	prefixExpression.setOperator(PrefixExpression.Operator.NOT);
	ParenthesizedExpression parenthesizedExpression = getParenthesizedExpression(ast, (Expression) rewrite.createCopyTarget(expression));
	prefixExpression.setOperand(parenthesizedExpression);
	return prefixExpression;
}
 
Example 5
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 6
Source File: AdvancedQuickAssistProcessor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private static Expression getInversedNotExpression(ASTRewrite rewrite, Expression expression, AST ast) {
	PrefixExpression prefixExpression= ast.newPrefixExpression();
	prefixExpression.setOperator(PrefixExpression.Operator.NOT);
	ParenthesizedExpression parenthesizedExpression= getParenthesizedExpression(ast, (Expression)rewrite.createCopyTarget(expression));
	prefixExpression.setOperand(parenthesizedExpression);
	return prefixExpression;
}
 
Example 7
Source File: AdvancedQuickAssistProcessor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private static boolean getPullNegationUpProposals(IInvocationContext context, ArrayList<ASTNode> coveredNodes, Collection<ICommandAccess> resultingCollections) {
	if (coveredNodes.size() != 1) {
		return false;
	}
	//
	ASTNode fullyCoveredNode= coveredNodes.get(0);

	Expression expression= getBooleanExpression(fullyCoveredNode);
	if (expression == null || (!(expression instanceof InfixExpression) && !(expression instanceof ConditionalExpression))) {
		return false;
	}
	//  we could produce quick assist
	if (resultingCollections == null) {
		return true;
	}
	//
	AST ast= expression.getAST();
	final ASTRewrite rewrite= ASTRewrite.create(ast);
	// prepared inverted expression
	Expression inversedExpression= getInversedExpression(rewrite, expression);
	// prepare ParenthesizedExpression
	ParenthesizedExpression parenthesizedExpression= ast.newParenthesizedExpression();
	parenthesizedExpression.setExpression(inversedExpression);
	// prepare NOT prefix expression
	PrefixExpression prefixExpression= ast.newPrefixExpression();
	prefixExpression.setOperator(PrefixExpression.Operator.NOT);
	prefixExpression.setOperand(parenthesizedExpression);
	// replace old expression
	rewrite.replace(expression, prefixExpression, null);
	// add correction proposal
	String label= CorrectionMessages.AdvancedQuickAssistProcessor_pullNegationUp;
	Image image= JavaPluginImages.get(JavaPluginImages.IMG_CORRECTION_CHANGE);
	ASTRewriteCorrectionProposal proposal= new ASTRewriteCorrectionProposal(label, context.getCompilationUnit(), rewrite, IProposalRelevance.PULL_NEGATION_UP, image);
	resultingCollections.add(proposal);
	return true;
}
 
Example 8
Source File: GenerateHashCodeEqualsOperation.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Creates a comparison of reference types.
 *
 * <pre>
 * if (this.a == null) {
 * 	if (other.a != null)
 * 		return false;
 * } else {
 * 	if (!this.a.equals(other.a))
 * 		return false;
 * }
 * </pre>
 * @param name the field name
 * @return the comparison statement
 */
private Statement createQualifiedComparison(String name) {
	InfixExpression newCondition= fAst.newInfixExpression();
	newCondition.setOperator(Operator.EQUALS);
	newCondition.setLeftOperand(getThisAccessForEquals(name));
	newCondition.setRightOperand(fAst.newNullLiteral());

	// THEN
	InfixExpression notEqNull= fAst.newInfixExpression();
	notEqNull.setOperator(Operator.NOT_EQUALS);
	notEqNull.setLeftOperand(getOtherAccess(name));
	notEqNull.setRightOperand(fAst.newNullLiteral());

	IfStatement thenPart= fAst.newIfStatement();
	thenPart.setExpression(notEqNull);
	thenPart.setThenStatement(getThenStatement(getReturnFalse()));

	Block thenPart2= fAst.newBlock();
	thenPart2.statements().add(thenPart);

	// ELSE
	MethodInvocation invoc= fAst.newMethodInvocation();
	invoc.setName(fAst.newSimpleName(METHODNAME_EQUALS));
	invoc.setExpression(getThisAccessForEquals(name));
	invoc.arguments().add(getOtherAccess(name));

	PrefixExpression pe= fAst.newPrefixExpression();
	pe.setOperator(PrefixExpression.Operator.NOT);
	pe.setOperand(invoc);

	IfStatement elsePart= fAst.newIfStatement();
	elsePart.setExpression(pe);
	elsePart.setThenStatement(getThenStatement(getReturnFalse()));

	// ALL
	IfStatement isNull= fAst.newIfStatement();
	isNull.setExpression(newCondition);
	isNull.setThenStatement(thenPart2);
	isNull.setElseStatement(elsePart);

	return isNull;
}