下面列出了怎么用org.eclipse.jdt.core.dom.PrefixExpression.Operator的API类实例代码及写法,或者点击链接到github查看源代码。
@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;
}
@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;
}
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);
}
}
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;
}