本文整理汇总了Java中org.eclipse.jdt.internal.corext.refactoring.code.OperatorPrecedence类的典型用法代码示例。如果您正苦于以下问题:Java OperatorPrecedence类的具体用法?Java OperatorPrecedence怎么用?Java OperatorPrecedence使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
OperatorPrecedence类属于org.eclipse.jdt.internal.corext.refactoring.code包,在下文中一共展示了OperatorPrecedence类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: getInversedAndOrExpression
import org.eclipse.jdt.internal.corext.refactoring.code.OperatorPrecedence; //导入依赖的package包/类
private static Expression getInversedAndOrExpression(
ASTRewrite rewrite,
InfixExpression infixExpression,
Operator newOperator,
SimpleNameRenameProvider provider) {
InfixExpression newExpression = rewrite.getAST().newInfixExpression();
newExpression.setOperator(newOperator);
int newOperatorPrecedence = OperatorPrecedence.getOperatorPrecedence(newOperator);
//
Expression leftOperand =
getInversedExpression(rewrite, infixExpression.getLeftOperand(), provider);
newExpression.setLeftOperand(parenthesizeIfRequired(leftOperand, newOperatorPrecedence));
Expression rightOperand =
getInversedExpression(rewrite, infixExpression.getRightOperand(), provider);
newExpression.setRightOperand(parenthesizeIfRequired(rightOperand, newOperatorPrecedence));
List<Expression> extraOperands = infixExpression.extendedOperands();
List<Expression> newExtraOperands = newExpression.extendedOperands();
for (int i = 0; i < extraOperands.size(); i++) {
Expression extraOperand = getInversedExpression(rewrite, extraOperands.get(i), provider);
newExtraOperands.add(parenthesizeIfRequired(extraOperand, newOperatorPrecedence));
}
return newExpression;
}
开发者ID:eclipse,项目名称:che,代码行数:27,代码来源:AdvancedQuickAssistProcessor.java
示例2: getInversedAndOrExpression
import org.eclipse.jdt.internal.corext.refactoring.code.OperatorPrecedence; //导入依赖的package包/类
private static Expression getInversedAndOrExpression(ASTRewrite rewrite, InfixExpression infixExpression, Operator newOperator, SimpleNameRenameProvider provider) {
InfixExpression newExpression= rewrite.getAST().newInfixExpression();
newExpression.setOperator(newOperator);
int newOperatorPrecedence= OperatorPrecedence.getOperatorPrecedence(newOperator);
//
Expression leftOperand= getInversedExpression(rewrite, infixExpression.getLeftOperand(), provider);
newExpression.setLeftOperand(parenthesizeIfRequired(leftOperand, newOperatorPrecedence));
Expression rightOperand= getInversedExpression(rewrite, infixExpression.getRightOperand(), provider);
newExpression.setRightOperand(parenthesizeIfRequired(rightOperand, newOperatorPrecedence));
List<Expression> extraOperands= infixExpression.extendedOperands();
List<Expression> newExtraOperands= newExpression.extendedOperands();
for (int i= 0; i < extraOperands.size(); i++) {
Expression extraOperand= getInversedExpression(rewrite, extraOperands.get(i), provider);
newExtraOperands.add(parenthesizeIfRequired(extraOperand, newOperatorPrecedence));
}
return newExpression;
}
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:21,代码来源:AdvancedQuickAssistProcessor.java
示例3: needsParentheses
import org.eclipse.jdt.internal.corext.refactoring.code.OperatorPrecedence; //导入依赖的package包/类
/**
* Does the <code>expression</code> need parentheses when inserted into <code>parent</code> at
* <code>locationInParent</code> ?
*
* <p>
* <b>Note:</b> The expression can be an unparented node.
* </p>
*
* @param expression the expression
* @param parent the parent node
* @param locationInParent location of expression in the parent
* @return <code>true</code> if the expression needs parentheses, <code>false</code> otherwise.
*/
public static boolean needsParentheses(Expression expression, ASTNode parent, StructuralPropertyDescriptor locationInParent) {
if (!expressionTypeNeedsParentheses(expression))
return false;
if (!locationNeedsParentheses(locationInParent)) {
return false;
}
if (parent instanceof Expression) {
Expression parentExpression= (Expression)parent;
int expressionPrecedence= OperatorPrecedence.getExpressionPrecedence(expression);
int parentPrecedence= OperatorPrecedence.getExpressionPrecedence(parentExpression);
if (expressionPrecedence > parentPrecedence)
//(opEx) opParent and opEx binds more -> parentheses not needed
return false;
if (expressionPrecedence < parentPrecedence)
//(opEx) opParent and opEx binds less -> parentheses needed
return true;
//(opEx) opParent binds equal
if (parentExpression instanceof InfixExpression) {
return needsParenthesesInInfixExpression(expression, (InfixExpression)parentExpression, locationInParent);
}
if (parentExpression instanceof ConditionalExpression && locationInParent == ConditionalExpression.EXPRESSION_PROPERTY) {
return true;
}
return false;
}
return true;
}
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion-Juno38,代码行数:51,代码来源:NecessaryParenthesesChecker.java
示例4: needsParentheses
import org.eclipse.jdt.internal.corext.refactoring.code.OperatorPrecedence; //导入依赖的package包/类
/**
* Does the <code>expression</code> need parentheses when inserted into <code>parent</code> at
* <code>locationInParent</code> ?
*
* @param expression the expression
* @param parent the parent node
* @param locationInParent location of expression in the parent
* @param leftOperandType the type of the left operand in <code>parent</code> if <code>parent
* </code> is an infix expression with no bindings and <code>expression</code> is the right
* operand in it, <code>null</code> otherwise
* @return <code>true</code> if <code>expression</code> needs parentheses, <code>false</code>
* otherwise.
* @since 3.9
*/
private static boolean needsParentheses(
Expression expression,
ASTNode parent,
StructuralPropertyDescriptor locationInParent,
ITypeBinding leftOperandType) {
if (!expressionTypeNeedsParentheses(expression)) return false;
if (!locationNeedsParentheses(locationInParent)) {
return false;
}
if (parent instanceof Expression) {
Expression parentExpression = (Expression) parent;
if (expression instanceof PrefixExpression) { // see bug 405096
return needsParenthesesForPrefixExpression(
parentExpression, ((PrefixExpression) expression).getOperator());
}
int expressionPrecedence = OperatorPrecedence.getExpressionPrecedence(expression);
int parentPrecedence = OperatorPrecedence.getExpressionPrecedence(parentExpression);
if (expressionPrecedence > parentPrecedence)
// (opEx) opParent and opEx binds more -> parentheses not needed
return false;
if (expressionPrecedence < parentPrecedence)
// (opEx) opParent and opEx binds less -> parentheses needed
return true;
// (opEx) opParent binds equal
if (parentExpression instanceof InfixExpression) {
return needsParenthesesInInfixExpression(
expression, (InfixExpression) parentExpression, locationInParent, leftOperandType);
}
if (parentExpression instanceof ConditionalExpression
&& locationInParent == ConditionalExpression.EXPRESSION_PROPERTY) {
return true;
}
return false;
}
return true;
}
开发者ID:eclipse,项目名称:che,代码行数:62,代码来源:NecessaryParenthesesChecker.java
示例5: parenthesizeIfRequired
import org.eclipse.jdt.internal.corext.refactoring.code.OperatorPrecedence; //导入依赖的package包/类
private static Expression parenthesizeIfRequired(Expression operand, int newOperatorPrecedence) {
if (newOperatorPrecedence > OperatorPrecedence.getExpressionPrecedence(operand)) {
return getParenthesizedExpression(operand.getAST(), operand);
}
return operand;
}
开发者ID:eclipse,项目名称:che,代码行数:7,代码来源:AdvancedQuickAssistProcessor.java
示例6: getPushNegationDownProposals
import org.eclipse.jdt.internal.corext.refactoring.code.OperatorPrecedence; //导入依赖的package包/类
private static boolean getPushNegationDownProposals(
IInvocationContext context,
ASTNode covering,
Collection<ICommandAccess> resultingCollections) {
PrefixExpression negationExpression = null;
ParenthesizedExpression parenthesizedExpression = null;
// check for case when cursor is on '!' before parentheses
if (covering instanceof PrefixExpression) {
PrefixExpression prefixExpression = (PrefixExpression) covering;
if (prefixExpression.getOperator() == PrefixExpression.Operator.NOT
&& prefixExpression.getOperand() instanceof ParenthesizedExpression) {
negationExpression = prefixExpression;
parenthesizedExpression = (ParenthesizedExpression) prefixExpression.getOperand();
}
}
// check for case when cursor is on parenthesized expression that is negated
if (covering instanceof ParenthesizedExpression
&& covering.getParent() instanceof PrefixExpression
&& ((PrefixExpression) covering.getParent()).getOperator()
== PrefixExpression.Operator.NOT) {
negationExpression = (PrefixExpression) covering.getParent();
parenthesizedExpression = (ParenthesizedExpression) covering;
}
if (negationExpression == null
|| (!(parenthesizedExpression.getExpression() instanceof InfixExpression)
&& !(parenthesizedExpression.getExpression() instanceof ConditionalExpression))) {
return false;
}
// we could produce quick assist
if (resultingCollections == null) {
return true;
}
//
final AST ast = covering.getAST();
final ASTRewrite rewrite = ASTRewrite.create(ast);
// prepared inverted expression
Expression inversedExpression =
getInversedExpression(rewrite, parenthesizedExpression.getExpression());
// check, may be we should keep parentheses
boolean keepParentheses = false;
if (negationExpression.getParent() instanceof Expression) {
int parentPrecedence =
OperatorPrecedence.getExpressionPrecedence(((Expression) negationExpression.getParent()));
int inversedExpressionPrecedence =
OperatorPrecedence.getExpressionPrecedence(inversedExpression);
keepParentheses = parentPrecedence > inversedExpressionPrecedence;
}
// replace negated expression with inverted one
if (keepParentheses) {
ParenthesizedExpression pe = ast.newParenthesizedExpression();
pe.setExpression(inversedExpression);
rewrite.replace(negationExpression, pe, null);
} else {
rewrite.replace(negationExpression, inversedExpression, null);
}
// add correction proposal
String label = CorrectionMessages.AdvancedQuickAssistProcessor_pushNegationDown;
Image image = JavaPluginImages.get(JavaPluginImages.IMG_CORRECTION_CHANGE);
ASTRewriteCorrectionProposal proposal =
new ASTRewriteCorrectionProposal(
label,
context.getCompilationUnit(),
rewrite,
IProposalRelevance.PULL_NEGATION_DOWN,
image);
resultingCollections.add(proposal);
return true;
}
开发者ID:eclipse,项目名称:che,代码行数:69,代码来源:AdvancedQuickAssistProcessor.java
示例7: needsParentheses
import org.eclipse.jdt.internal.corext.refactoring.code.OperatorPrecedence; //导入依赖的package包/类
/**
* Does the <code>expression</code> need parentheses when inserted into <code>parent</code> at
* <code>locationInParent</code> ?
*
* @param expression the expression
* @param parent the parent node
* @param locationInParent location of expression in the parent
* @param leftOperandType the type of the left operand in <code>parent</code> if
* <code>parent</code> is an infix expression with no bindings and
* <code>expression</code> is the right operand in it, <code>null</code> otherwise
* @return <code>true</code> if <code>expression</code> needs parentheses, <code>false</code>
* otherwise.
*
* @since 3.9
*/
private static boolean needsParentheses(Expression expression, ASTNode parent, StructuralPropertyDescriptor locationInParent, ITypeBinding leftOperandType) {
if (!expressionTypeNeedsParentheses(expression))
return false;
if (!locationNeedsParentheses(locationInParent)) {
return false;
}
if (parent instanceof Expression) {
Expression parentExpression= (Expression)parent;
if (expression instanceof PrefixExpression) { // see bug 405096
return needsParenthesesForPrefixExpression(parentExpression, ((PrefixExpression) expression).getOperator());
}
int expressionPrecedence= OperatorPrecedence.getExpressionPrecedence(expression);
int parentPrecedence= OperatorPrecedence.getExpressionPrecedence(parentExpression);
if (expressionPrecedence > parentPrecedence)
//(opEx) opParent and opEx binds more -> parentheses not needed
return false;
if (expressionPrecedence < parentPrecedence)
//(opEx) opParent and opEx binds less -> parentheses needed
return true;
//(opEx) opParent binds equal
if (parentExpression instanceof InfixExpression) {
return needsParenthesesInInfixExpression(expression, (InfixExpression) parentExpression, locationInParent, leftOperandType);
}
if (parentExpression instanceof ConditionalExpression && locationInParent == ConditionalExpression.EXPRESSION_PROPERTY) {
return true;
}
return false;
}
return true;
}
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:57,代码来源:NecessaryParenthesesChecker.java
示例8: parenthesizeIfRequired
import org.eclipse.jdt.internal.corext.refactoring.code.OperatorPrecedence; //导入依赖的package包/类
private static Expression parenthesizeIfRequired(Expression operand, int newOperatorPrecedence) {
if (newOperatorPrecedence > OperatorPrecedence.getExpressionPrecedence(operand)) {
return getParenthesizedExpression(operand.getAST(), operand);
}
return operand;
}
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:7,代码来源:AdvancedQuickAssistProcessor.java
注:本文中的org.eclipse.jdt.internal.corext.refactoring.code.OperatorPrecedence类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论