org.eclipse.jdt.core.dom.PrefixExpression.Operator Java Examples

The following examples show how to use org.eclipse.jdt.core.dom.PrefixExpression.Operator. 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: TempAssignmentFinder.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public boolean visit(PrefixExpression prefixExpression) {
	if (prefixExpression.getOperand() == null)
		return true;
	if (! (prefixExpression.getOperand() instanceof SimpleName))
		return true;
	if (! prefixExpression.getOperator().equals(Operator.DECREMENT) &&
		! prefixExpression.getOperator().equals(Operator.INCREMENT))
		return true;
	SimpleName simpleName= (SimpleName)prefixExpression.getOperand();
	if (! isNameReferenceToTemp(simpleName))
		return true;

	fFirstAssignment= prefixExpression;
	return false;
}
 
Example #2
Source File: OccurrencesFinder.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public boolean visit(PrefixExpression node) {
	PrefixExpression.Operator operator= node.getOperator();
	if (operator == Operator.INCREMENT || operator == Operator.DECREMENT) {
		SimpleName name= getSimpleName(node.getOperand());
		if (name != null)
			addWrite(name, name.resolveBinding());
	}
	return true;
}
 
Example #3
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 #4
Source File: QuickAssistProcessor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
private static boolean getConvertStringConcatenationProposals(IInvocationContext context, Collection<ICommandAccess> resultingCollections) {
	ASTNode node= context.getCoveringNode();
	BodyDeclaration parentDecl= ASTResolving.findParentBodyDeclaration(node);
	if (!(parentDecl instanceof MethodDeclaration || parentDecl instanceof Initializer))
		return false;

	AST ast= node.getAST();
	ITypeBinding stringBinding= ast.resolveWellKnownType("java.lang.String"); //$NON-NLS-1$

	if (node instanceof Expression && !(node instanceof InfixExpression)) {
		node= node.getParent();
	}
	if (node instanceof VariableDeclarationFragment) {
		node= ((VariableDeclarationFragment) node).getInitializer();
	} else if (node instanceof Assignment) {
		node= ((Assignment) node).getRightHandSide();
	}

	InfixExpression oldInfixExpression= null;
	while (node instanceof InfixExpression) {
		InfixExpression curr= (InfixExpression) node;
		if (curr.resolveTypeBinding() == stringBinding && curr.getOperator() == InfixExpression.Operator.PLUS) {
			oldInfixExpression= curr; // is a infix expression we can use
		} else {
			break;
		}
		node= node.getParent();
	}
	if (oldInfixExpression == null)
		return false;

	if (resultingCollections == null) {
		return true;
	}

	LinkedCorrectionProposal stringBufferProposal= getConvertToStringBufferProposal(context, ast, oldInfixExpression);
	resultingCollections.add(stringBufferProposal);

	ASTRewriteCorrectionProposal messageFormatProposal= getConvertToMessageFormatProposal(context, ast, oldInfixExpression);
	if (messageFormatProposal != null)
		resultingCollections.add(messageFormatProposal);

	return true;
}