当前位置: 首页>>代码示例>>Java>>正文


Java Operator类代码示例

本文整理汇总了Java中org.eclipse.jdt.core.dom.InfixExpression.Operator的典型用法代码示例。如果您正苦于以下问题:Java Operator类的具体用法?Java Operator怎么用?Java Operator使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


Operator类属于org.eclipse.jdt.core.dom.InfixExpression包,在下文中一共展示了Operator类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: visit

import org.eclipse.jdt.core.dom.InfixExpression.Operator; //导入依赖的package包/类
@Override
public boolean visit(PostfixExpression exp) {
	if(exp.getOperand() instanceof SimpleName) {
		String varName = exp.getOperand().toString(); 
		VariableOperation op = null;
		if(exp.getOperator() == PostfixExpression.Operator.INCREMENT)
			op = new VariableOperation(varName, VariableOperation.Type.INC);

		else if(exp.getOperator() == PostfixExpression.Operator.DECREMENT)
			op = new VariableOperation(varName, VariableOperation.Type.DEC);

		if(op != null)
			current.addOperation(op);
	}
	return true;
}
 
开发者ID:andre-santos-pt,项目名称:pandionj,代码行数:17,代码来源:VarParser.java

示例2: isAcumulationAssign

import org.eclipse.jdt.core.dom.InfixExpression.Operator; //导入依赖的package包/类
private static boolean isAcumulationAssign(Assignment assignment, InfixExpression.Operator op, Predicate<Expression> acceptExpression) {
	if(!(
			assignment.getRightHandSide() instanceof InfixExpression && 
			assignment.getLeftHandSide() instanceof SimpleName &&
			assignment.getOperator() == Assignment.Operator.ASSIGN))
		return false;

	InfixExpression exp = (InfixExpression) assignment.getRightHandSide();
	if(exp.getOperator() != op)
		return false;

	String assignVar = assignment.getLeftHandSide().toString();
	if(	exp.getLeftOperand() instanceof SimpleName &&
			exp.getLeftOperand().toString().equals(assignVar) &&
			acceptExpression.test(exp.getRightOperand()))
		return true;

	if(	exp.getRightOperand() instanceof SimpleName && 
			exp.getRightOperand().toString().equals(assignVar) &&
			acceptExpression.test(exp.getLeftOperand()))
		return true;

	return false;
}
 
开发者ID:andre-santos-pt,项目名称:pandionj,代码行数:25,代码来源:VarParser.java

示例3: isAssociative

import org.eclipse.jdt.core.dom.InfixExpression.Operator; //导入依赖的package包/类
private static boolean isAssociative(InfixExpression.Operator operator, ITypeBinding infixExprType, boolean isAllOperandsHaveSameType) {
	if (operator == InfixExpression.Operator.PLUS) {
		return isStringType(infixExprType) || isIntegerType(infixExprType) && isAllOperandsHaveSameType;
	}

	if (operator == InfixExpression.Operator.TIMES) {
		return isIntegerType(infixExprType) && isAllOperandsHaveSameType;
	}

	if (operator == InfixExpression.Operator.CONDITIONAL_AND
			|| operator == InfixExpression.Operator.CONDITIONAL_OR
			|| operator == InfixExpression.Operator.AND
			|| operator == InfixExpression.Operator.OR
			|| operator == InfixExpression.Operator.XOR) {
		return true;
	}

	return false;
}
 
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:20,代码来源:NecessaryParenthesesChecker.java

示例4: getInfixExpressionType

import org.eclipse.jdt.core.dom.InfixExpression.Operator; //导入依赖的package包/类
/**
 * Returns the type of infix expression based on its operands and operator.
 *
 * @param operator the operator of infix expression
 * @param leftOperandType the type of left operand of infix expression
 * @param rightOperandType the type of right operand of infix expression
 * @return the type of infix expression if the type of both the operands is same or if the type
 *         of either operand of a + operator is String, <code>null</code> otherwise.
 *
 * @since 3.9
 */
private static ITypeBinding getInfixExpressionType(InfixExpression.Operator operator, ITypeBinding leftOperandType, ITypeBinding rightOperandType) {
	if (leftOperandType == rightOperandType) {
		return leftOperandType;
	}
	if (operator == InfixExpression.Operator.PLUS) {
		if (isStringType(leftOperandType)) {
			return leftOperandType;
		} else if (isStringType(rightOperandType)) {
			return rightOperandType;
		}
	}
	// If the left and right operand types are different, we assume that parentheses are needed.
	// This is to avoid complications of numeric promotions and for readability of complicated code.
	return null;
}
 
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:27,代码来源:NecessaryParenthesesChecker.java

示例5: getOperatorPrecedence

import org.eclipse.jdt.core.dom.InfixExpression.Operator; //导入依赖的package包/类
/**
 * Returns the precedence of an infix operator. Operators
 * with higher precedence are executed before expressions
 * with lower precedence.
 * <br>
 * i.e. in: <br>
 * <code>3 + 4 - 5 * 6;</code><br>
 * the  precedence order is
 * <ul>
 * <li>*</li>
 * <li>+</li>
 * <li>-</li>
 * </ul>
 * 1. 5,6 -(*)-> 30<br>
 * 2. 3,4 -(+)-> 7<br>
 * 3. 7,30 -(-)-> -23<br>
 *
 * @param operator the expression to determine the precedence for
 * @return the precedence the higher to stronger the binding to its operands
 */
public static int getOperatorPrecedence(Operator operator) {
	if (operator == Operator.CONDITIONAL_OR) {
		return CONDITIONAL_OR;
	} else if (operator == Operator.CONDITIONAL_AND) {
		return CONDITIONAL_AND;
	} else if (operator == Operator.OR) {
		return BITWISE_INCLUSIVE_OR;
	} else if (operator == Operator.XOR) {
		return BITWISE_EXCLUSIVE_OR;
	} else if (operator == Operator.AND) {
		return BITWISE_AND;
	} else if (operator == Operator.EQUALS || operator == Operator.NOT_EQUALS) {
		return EQUALITY;
	} else if (operator == Operator.LESS || operator == Operator.LESS_EQUALS || operator == Operator.GREATER || operator == Operator.GREATER_EQUALS) {
		return RELATIONAL;
	} else if (operator == Operator.LEFT_SHIFT || operator == Operator.RIGHT_SHIFT_SIGNED || operator == Operator.RIGHT_SHIFT_UNSIGNED) {
		return SHIFT;
	} else if (operator == Operator.PLUS || operator == Operator.MINUS) {
		return ADDITIVE;
	} else if (operator == Operator.REMAINDER || operator == Operator.DIVIDE || operator == Operator.TIMES) {
		return MULTIPLICATIVE;
	}
	return Integer.MAX_VALUE;
}
 
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:45,代码来源:OperatorPrecedence.java

示例6: getNumber

import org.eclipse.jdt.core.dom.InfixExpression.Operator; //导入依赖的package包/类
protected String getNumber(PrefixExpression prefixExpression) {
String number = null;

Expression operand = prefixExpression.getOperand();
if (operand.getNodeType() == ASTNode.NUMBER_LITERAL) {
    org.eclipse.jdt.core.dom.PrefixExpression.Operator operator = prefixExpression
	    .getOperator();

    if (org.eclipse.jdt.core.dom.PrefixExpression.Operator.MINUS
	    .equals(operator)) {
	number = "-" + operand.toString();
    } else if (org.eclipse.jdt.core.dom.PrefixExpression.Operator.PLUS
	    .equals(operator)
	    || org.eclipse.jdt.core.dom.PrefixExpression.Operator.DECREMENT
		    .equals(operator)
	    || org.eclipse.jdt.core.dom.PrefixExpression.Operator.INCREMENT
		    .equals(operator)) {
	number = operand.toString();
    } else {
	number = "0";
    }

}

return number;
   }
 
开发者ID:junit-tools-team,项目名称:junit-tools,代码行数:27,代码来源:TestCasesGenerator.java

示例7: isAssociative

import org.eclipse.jdt.core.dom.InfixExpression.Operator; //导入依赖的package包/类
private static boolean isAssociative(
    InfixExpression.Operator operator,
    ITypeBinding infixExprType,
    boolean isAllOperandsHaveSameType) {
  if (operator == InfixExpression.Operator.PLUS)
    return isStringType(infixExprType)
        || isIntegerType(infixExprType) && isAllOperandsHaveSameType;

  if (operator == InfixExpression.Operator.TIMES)
    return isIntegerType(infixExprType) && isAllOperandsHaveSameType;

  if (operator == InfixExpression.Operator.CONDITIONAL_AND
      || operator == InfixExpression.Operator.CONDITIONAL_OR
      || operator == InfixExpression.Operator.AND
      || operator == InfixExpression.Operator.OR
      || operator == InfixExpression.Operator.XOR) return true;

  return false;
}
 
开发者ID:eclipse,项目名称:che,代码行数:20,代码来源:NecessaryParenthesesChecker.java

示例8: getInfixExpressionType

import org.eclipse.jdt.core.dom.InfixExpression.Operator; //导入依赖的package包/类
/**
 * Returns the type of infix expression based on its operands and operator.
 *
 * @param operator the operator of infix expression
 * @param leftOperandType the type of left operand of infix expression
 * @param rightOperandType the type of right operand of infix expression
 * @return the type of infix expression if the type of both the operands is same or if the type of
 *     either operand of a + operator is String, <code>null</code> otherwise.
 * @since 3.9
 */
private static ITypeBinding getInfixExpressionType(
    InfixExpression.Operator operator,
    ITypeBinding leftOperandType,
    ITypeBinding rightOperandType) {
  if (leftOperandType == rightOperandType) {
    return leftOperandType;
  }
  if (operator == InfixExpression.Operator.PLUS) {
    if (isStringType(leftOperandType)) {
      return leftOperandType;
    } else if (isStringType(rightOperandType)) {
      return rightOperandType;
    }
  }
  // If the left and right operand types are different, we assume that parentheses are needed.
  // This is to avoid complications of numeric promotions and for readability of complicated code.
  return null;
}
 
开发者ID:eclipse,项目名称:che,代码行数:29,代码来源:NecessaryParenthesesChecker.java

示例9: getInversedAndOrExpression

import org.eclipse.jdt.core.dom.InfixExpression.Operator; //导入依赖的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

示例10: combineOperands

import org.eclipse.jdt.core.dom.InfixExpression.Operator; //导入依赖的package包/类
private static Expression combineOperands(
    ASTRewrite rewrite,
    Expression existing,
    Expression originalNode,
    boolean removeParentheses,
    Operator operator) {
  if (existing == null && removeParentheses) {
    while (originalNode instanceof ParenthesizedExpression) {
      originalNode = ((ParenthesizedExpression) originalNode).getExpression();
    }
  }
  Expression newRight = (Expression) rewrite.createMoveTarget(originalNode);
  if (originalNode instanceof InfixExpression) {
    ((InfixExpression) newRight).setOperator(((InfixExpression) originalNode).getOperator());
  }

  if (existing == null) {
    return newRight;
  }
  AST ast = rewrite.getAST();
  InfixExpression infix = ast.newInfixExpression();
  infix.setOperator(operator);
  infix.setLeftOperand(existing);
  infix.setRightOperand(newRight);
  return infix;
}
 
开发者ID:eclipse,项目名称:che,代码行数:27,代码来源:AdvancedQuickAssistProcessor.java

示例11: isAssociative

import org.eclipse.jdt.core.dom.InfixExpression.Operator; //导入依赖的package包/类
private static boolean isAssociative(InfixExpression.Operator operator, ITypeBinding infixExprType, boolean isAllOperandsHaveSameType) {
	if (operator == InfixExpression.Operator.PLUS)
		return isStringType(infixExprType) || isIntegerType(infixExprType) && isAllOperandsHaveSameType;

	if (operator == InfixExpression.Operator.TIMES)
		return isIntegerType(infixExprType) && isAllOperandsHaveSameType;

	if (operator == InfixExpression.Operator.CONDITIONAL_AND
			|| operator == InfixExpression.Operator.CONDITIONAL_OR
			|| operator == InfixExpression.Operator.AND
			|| operator == InfixExpression.Operator.OR
			|| operator == InfixExpression.Operator.XOR)
		return true;

	return false;
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:17,代码来源:NecessaryParenthesesChecker.java

示例12: getInfixExpressionType

import org.eclipse.jdt.core.dom.InfixExpression.Operator; //导入依赖的package包/类
/**
 * Returns the type of infix expression based on its operands and operator.
 * 
 * @param operator the operator of infix expression
 * @param leftOperandType the type of left operand of infix expression
 * @param rightOperandType the type of right operand of infix expression
 * @return the type of infix expression if the type of both the operands is same or if the type
 *         of either operand of a + operator is String, <code>null</code> otherwise.
 * 
 * @since 3.9
 */
private static ITypeBinding getInfixExpressionType(InfixExpression.Operator operator, ITypeBinding leftOperandType, ITypeBinding rightOperandType) {
	if (leftOperandType == rightOperandType) {
		return leftOperandType;
	}
	if (operator == InfixExpression.Operator.PLUS) {
		if (isStringType(leftOperandType)) {
			return leftOperandType;
		} else if (isStringType(rightOperandType)) {
			return rightOperandType;
		}
	}
	// If the left and right operand types are different, we assume that parentheses are needed.
	// This is to avoid complications of numeric promotions and for readability of complicated code.
	return null;
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:27,代码来源:NecessaryParenthesesChecker.java

示例13: addMemberCheckNull

import org.eclipse.jdt.core.dom.InfixExpression.Operator; //导入依赖的package包/类
@Override
protected void addMemberCheckNull(Object member, boolean addSeparator) {
	IfStatement ifStatement= fAst.newIfStatement();
	ifStatement.setExpression(createInfixExpression(createMemberAccessExpression(member, true, true), Operator.NOT_EQUALS, fAst.newNullLiteral()));
	Block thenBlock= fAst.newBlock();
	flushBuffer(null);
	String[] arrayString= getContext().getTemplateParser().getBody();
	for (int i= 0; i < arrayString.length; i++) {
		addElement(processElement(arrayString[i], member), thenBlock);
	}
	if (addSeparator)
		addElement(getContext().getTemplateParser().getSeparator(), thenBlock);
	flushBuffer(thenBlock);

	if (thenBlock.statements().size() == 1 && !getContext().isForceBlocks()) {
		ifStatement.setThenStatement((Statement)ASTNode.copySubtree(fAst, (ASTNode)thenBlock.statements().get(0)));
	} else {
		ifStatement.setThenStatement(thenBlock);
	}
	toStringMethod.getBody().statements().add(ifStatement);
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:22,代码来源:StringBuilderGenerator.java

示例14: addMemberCheckNull

import org.eclipse.jdt.core.dom.InfixExpression.Operator; //导入依赖的package包/类
@Override
protected void addMemberCheckNull(Object member, boolean addSeparator) {
	IfStatement ifStatement= fAst.newIfStatement();
	ifStatement.setExpression(createInfixExpression(createMemberAccessExpression(member, true, true), Operator.NOT_EQUALS, fAst.newNullLiteral()));
	Block thenBlock= fAst.newBlock();
	flushTemporaryExpression();
	String[] arrayString= getContext().getTemplateParser().getBody();
	for (int i= 0; i < arrayString.length; i++) {
		addElement(processElement(arrayString[i], member), thenBlock);
	}
	if (addSeparator)
		addElement(getContext().getTemplateParser().getSeparator(), thenBlock);
	flushTemporaryExpression();

	if (thenBlock.statements().size() == 1 && !getContext().isForceBlocks()) {
		ifStatement.setThenStatement((Statement)ASTNode.copySubtree(fAst, (ASTNode)thenBlock.statements().get(0)));
	} else {
		ifStatement.setThenStatement(thenBlock);
	}
	toStringMethod.getBody().statements().add(ifStatement);
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:22,代码来源:StringBuilderChainGenerator.java

示例15: createAddQualifiedHashCode

import org.eclipse.jdt.core.dom.InfixExpression.Operator; //导入依赖的package包/类
private Statement createAddQualifiedHashCode(IVariableBinding binding) {

		MethodInvocation invoc= fAst.newMethodInvocation();
		invoc.setExpression(getThisAccessForHashCode(binding.getName()));
		invoc.setName(fAst.newSimpleName(METHODNAME_HASH_CODE));

		InfixExpression expr= fAst.newInfixExpression();
		expr.setOperator(Operator.EQUALS);
		expr.setLeftOperand(getThisAccessForHashCode(binding.getName()));
		expr.setRightOperand(fAst.newNullLiteral());

		ConditionalExpression cexpr= fAst.newConditionalExpression();
		cexpr.setThenExpression(fAst.newNumberLiteral("0")); //$NON-NLS-1$
		cexpr.setElseExpression(invoc);
		cexpr.setExpression(parenthesize(expr));

		return prepareAssignment(parenthesize(cexpr));
	}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:19,代码来源:GenerateHashCodeEqualsOperation.java


注:本文中的org.eclipse.jdt.core.dom.InfixExpression.Operator类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。