Java Code Examples for org.eclipse.jdt.core.dom.AST#newPrefixExpression()

The following examples show how to use org.eclipse.jdt.core.dom.AST#newPrefixExpression() . 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: 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 2
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 3
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 4
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;
}