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

The following examples show how to use org.eclipse.jdt.core.dom.PrefixExpression. 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: GenerateHashCodeEqualsOperation.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 7 votes vote down vote up
private Statement createArrayComparison(String name) {
	MethodInvocation invoc= fAst.newMethodInvocation();
	invoc.setName(fAst.newSimpleName(METHODNAME_EQUALS));
	invoc.setExpression(getQualifiedName(JAVA_UTIL_ARRAYS));
	invoc.arguments().add(getThisAccessForEquals(name));
	invoc.arguments().add(getOtherAccess(name));

	PrefixExpression pe= fAst.newPrefixExpression();
	pe.setOperator(PrefixExpression.Operator.NOT);
	pe.setOperand(invoc);

	IfStatement ifSt= fAst.newIfStatement();
	ifSt.setExpression(pe);
	ifSt.setThenStatement(getThenStatement(getReturnFalse()));

	return ifSt;
}
 
Example #2
Source File: CodeBlock.java    From SimFix with GNU General Public License v2.0 6 votes vote down vote up
private PrefixExpr visit(PrefixExpression node) {
	int startLine = _cunit.getLineNumber(node.getStartPosition());
	int endLine = _cunit.getLineNumber(node.getStartPosition() + node.getLength());
	PrefixExpr prefixExpr = new PrefixExpr(startLine, endLine, node);
	
	Expr expression = (Expr) process(node.getOperand());
	expression.setParent(prefixExpr);
	prefixExpr.setExpression(expression);
	
	prefixExpr.setOperator(node.getOperator());
	
	Type type = NodeUtils.parseExprType(null, node.getOperator().toString(), expression);
	prefixExpr.setType(type);
	
	return prefixExpr;
}
 
Example #3
Source File: GenerateHashCodeEqualsOperation.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private Statement createMultiArrayComparison(String name) {
	MethodInvocation invoc= fAst.newMethodInvocation();
	invoc.setName(fAst.newSimpleName(METHODNAME_DEEP_EQUALS));
	invoc.setExpression(getQualifiedName(JAVA_UTIL_ARRAYS));
	invoc.arguments().add(getThisAccessForEquals(name));
	invoc.arguments().add(getOtherAccess(name));

	PrefixExpression pe= fAst.newPrefixExpression();
	pe.setOperator(PrefixExpression.Operator.NOT);
	pe.setOperand(invoc);

	IfStatement ifSt= fAst.newIfStatement();
	ifSt.setExpression(pe);
	ifSt.setThenStatement(getThenStatement(getReturnFalse()));

	return ifSt;
}
 
Example #4
Source File: GenerateHashCodeEqualsOperation.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private Statement createOuterComparison() {
	MethodInvocation outer1= fAst.newMethodInvocation();
	outer1.setName(fAst.newSimpleName(METHODNAME_OUTER_TYPE));

	MethodInvocation outer2= fAst.newMethodInvocation();
	outer2.setName(fAst.newSimpleName(METHODNAME_OUTER_TYPE));
	outer2.setExpression(fAst.newSimpleName(VARIABLE_NAME_EQUALS_CASTED));

	MethodInvocation outerEql= fAst.newMethodInvocation();
	outerEql.setName(fAst.newSimpleName(METHODNAME_EQUALS));
	outerEql.setExpression(outer1);
	outerEql.arguments().add(outer2);

	PrefixExpression not= fAst.newPrefixExpression();
	not.setOperand(outerEql);
	not.setOperator(PrefixExpression.Operator.NOT);

	IfStatement notEqNull= fAst.newIfStatement();
	notEqNull.setExpression(not);
	notEqNull.setThenStatement(getThenStatement(getReturnFalse()));
	return notEqNull;
}
 
Example #5
Source File: PreconditionExaminer.java    From JDeodorant with MIT License 6 votes vote down vote up
private boolean isUpdated(Expression expr) {
	if(expr.getParent() instanceof Assignment) {
		Assignment assignment = (Assignment)expr.getParent();
		if(assignment.getLeftHandSide().equals(expr)) {
			return true;
		}
	}
	else if(expr.getParent() instanceof PostfixExpression) {
		return true;
	}
	else if(expr.getParent() instanceof PrefixExpression) {
		PrefixExpression prefix = (PrefixExpression)expr.getParent();
		if(prefix.getOperator().equals(PrefixExpression.Operator.INCREMENT) ||
				prefix.getOperator().equals(PrefixExpression.Operator.DECREMENT)) {
			return true;
		}
	}
	return false;
}
 
Example #6
Source File: ASTNodeMatcher.java    From JDeodorant with MIT License 6 votes vote down vote up
protected boolean isTypeHolder(Object o) {
	if(o.getClass().equals(MethodInvocation.class) || o.getClass().equals(SuperMethodInvocation.class)			
			|| o.getClass().equals(NumberLiteral.class) || o.getClass().equals(StringLiteral.class)
			|| o.getClass().equals(CharacterLiteral.class) || o.getClass().equals(BooleanLiteral.class)
			|| o.getClass().equals(TypeLiteral.class) || o.getClass().equals(NullLiteral.class)
			|| o.getClass().equals(ArrayCreation.class)
			|| o.getClass().equals(ClassInstanceCreation.class)
			|| o.getClass().equals(ArrayAccess.class) || o.getClass().equals(FieldAccess.class)
			|| o.getClass().equals(SuperFieldAccess.class) || o.getClass().equals(ParenthesizedExpression.class)
			|| o.getClass().equals(SimpleName.class) || o.getClass().equals(QualifiedName.class)
			|| o.getClass().equals(CastExpression.class) || o.getClass().equals(InfixExpression.class)
			|| o.getClass().equals(PrefixExpression.class) || o.getClass().equals(InstanceofExpression.class)
			|| o.getClass().equals(ThisExpression.class) || o.getClass().equals(ConditionalExpression.class))
		return true;
	return false;
}
 
Example #7
Source File: AccessAnalyzer.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public boolean visit(PrefixExpression node) {
	Expression operand= node.getOperand();
	if (!considerBinding(resolveBinding(operand), operand))
		return true;

	PrefixExpression.Operator operator= node.getOperator();
	if (operator != PrefixExpression.Operator.INCREMENT && operator != PrefixExpression.Operator.DECREMENT)
		return true;

	checkParent(node);

	fRewriter.replace(node,
		createInvocation(node.getAST(), node.getOperand(), node.getOperator().toString()),
		createGroupDescription(PREFIX_ACCESS));
	return false;
}
 
Example #8
Source File: AbstractLoopUtilities.java    From JDeodorant with MIT License 6 votes vote down vote up
public static boolean isUpdatingVariable(Expression updater, SimpleName variable)
{
	if (updater instanceof PrefixExpression)
	{
		PrefixExpression prefixExpression = (PrefixExpression) updater;
		return isSameVariable(prefixExpression.getOperand(), variable);
	}
	else if (updater instanceof PostfixExpression)
	{
		PostfixExpression postfixExpression = (PostfixExpression) updater;
		return isSameVariable(postfixExpression.getOperand(), variable);			
	}
	else if (updater instanceof Assignment)
	{
		Assignment assignment = (Assignment) updater;
		return isSameVariable(assignment.getLeftHandSide(), variable);
	}
	else if (updater instanceof MethodInvocation)
	{
		MethodInvocation methodInvocation = (MethodInvocation) updater;
		return isSameVariable(methodInvocation.getExpression(), variable);
	}
	return false;
}
 
Example #9
Source File: AbstractLoopUtilities.java    From JDeodorant with MIT License 6 votes vote down vote up
public static Integer getUpdateValue(Expression updater)
{
	if (updater instanceof PrefixExpression || updater instanceof PostfixExpression)
	{
		return AbstractLoopUtilities.getIncrementValue(updater);
	}
	else if (updater instanceof Assignment)
	{
		Assignment assignment = (Assignment) updater;
		return assignmentUpdateValue(assignment);
	}
	else if (updater instanceof MethodInvocation)
	{
		MethodInvocation methodInvocation = (MethodInvocation) updater;
		AbstractLoopBindingInformation bindingInformation = AbstractLoopBindingInformation.getInstance();
		return bindingInformation.getUpdateMethodValue(methodInvocation.resolveMethodBinding().getMethodDeclaration().getKey());
	}
	return null;
}
 
Example #10
Source File: AbstractLoopUtilities.java    From JDeodorant with MIT License 6 votes vote down vote up
private static Integer getIncrementValue(Expression expression)
{
	Integer incrementValue = null;
	String operator = null;
	if (expression instanceof PrefixExpression)
	{
		PrefixExpression prefixExpression  = (PrefixExpression) expression;
		operator = prefixExpression.getOperator().toString();
	}
	else if (expression instanceof PostfixExpression)
	{
		PostfixExpression postfixExpression = (PostfixExpression) expression;
		operator = postfixExpression.getOperator().toString();
	}
	if (operator != null && operator.equals("++"))
	{
		incrementValue = 1;
	}
	else if (operator != null && operator.equals("--"))
	{
		incrementValue = (-1);
	}
	return incrementValue;
}
 
Example #11
Source File: ExtractTempRefactoring.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private static boolean isLeftValue(ASTNode node) {
	ASTNode parent= node.getParent();
	if (parent instanceof Assignment) {
		Assignment assignment= (Assignment) parent;
		if (assignment.getLeftHandSide() == node)
			return true;
	}
	if (parent instanceof PostfixExpression)
		return true;
	if (parent instanceof PrefixExpression) {
		PrefixExpression.Operator op= ((PrefixExpression) parent).getOperator();
		if (op.equals(PrefixExpression.Operator.DECREMENT))
			return true;
		if (op.equals(PrefixExpression.Operator.INCREMENT))
			return true;
		return false;
	}
	return false;
}
 
Example #12
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 #13
Source File: JdtUtils.java    From j2cl with Apache License 2.0 6 votes vote down vote up
public static PrefixOperator getPrefixOperator(PrefixExpression.Operator operator) {
  switch (operator.toString()) {
    case "++":
      return PrefixOperator.INCREMENT;
    case "--":
      return PrefixOperator.DECREMENT;
    case "+":
      return PrefixOperator.PLUS;
    case "-":
      return PrefixOperator.MINUS;
    case "~":
      return PrefixOperator.COMPLEMENT;
    case "!":
      return PrefixOperator.NOT;
    default:
      return null;
  }
}
 
Example #14
Source File: ExtractTempRefactoring.java    From eclipse.jdt.ls with Eclipse Public License 2.0 6 votes vote down vote up
private static boolean isLeftValue(ASTNode node) {
	ASTNode parent = node.getParent();
	if (parent instanceof Assignment) {
		Assignment assignment = (Assignment) parent;
		if (assignment.getLeftHandSide() == node) {
			return true;
		}
	}
	if (parent instanceof PostfixExpression) {
		return true;
	}
	if (parent instanceof PrefixExpression) {
		PrefixExpression.Operator op = ((PrefixExpression) parent).getOperator();
		if (op.equals(PrefixExpression.Operator.DECREMENT)) {
			return true;
		}
		if (op.equals(PrefixExpression.Operator.INCREMENT)) {
			return true;
		}
		return false;
	}
	return false;
}
 
Example #15
Source File: AccessAnalyzer.java    From eclipse.jdt.ls with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public boolean visit(PrefixExpression node) {
	Expression operand = node.getOperand();
	if (!considerBinding(resolveBinding(operand), operand)) {
		return true;
	}

	PrefixExpression.Operator operator = node.getOperator();
	if (operator != PrefixExpression.Operator.INCREMENT && operator != PrefixExpression.Operator.DECREMENT) {
		return true;
	}

	checkParent(node);

	fRewriter.replace(node, createInvocation(node.getAST(), node.getOperand(), node.getOperator().toString()), createGroupDescription(PREFIX_ACCESS));
	return false;
}
 
Example #16
Source File: ExtractFieldRefactoring.java    From eclipse.jdt.ls with Eclipse Public License 2.0 6 votes vote down vote up
private static boolean isLeftValue(ASTNode node) {
	ASTNode parent = node.getParent();
	if (parent instanceof Assignment) {
		Assignment assignment = (Assignment) parent;
		if (assignment.getLeftHandSide() == node) {
			return true;
		}
	}
	if (parent instanceof PostfixExpression) {
		return true;
	}
	if (parent instanceof PrefixExpression) {
		PrefixExpression.Operator op = ((PrefixExpression) parent).getOperator();
		if (op.equals(PrefixExpression.Operator.DECREMENT)) {
			return true;
		}
		if (op.equals(PrefixExpression.Operator.INCREMENT)) {
			return true;
		}
		return false;
	}
	return false;
}
 
Example #17
Source File: ASTFlattenerUtils.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
public Boolean isAssignedInBody(final Block scope, final SimpleName nameToLookFor) {
  final Function1<Expression, Boolean> _function = (Expression it) -> {
    Expression simpleName = null;
    boolean _matched = false;
    if (it instanceof Assignment) {
      _matched=true;
      simpleName = ((Assignment)it).getLeftHandSide();
    }
    if (!_matched) {
      if (it instanceof PrefixExpression) {
        _matched=true;
        simpleName = ((PrefixExpression)it).getOperand();
      }
    }
    if (!_matched) {
      if (it instanceof PostfixExpression) {
        _matched=true;
        simpleName = ((PostfixExpression)it).getOperand();
      }
    }
    if ((simpleName instanceof SimpleName)) {
      return Boolean.valueOf(((simpleName != null) && nameToLookFor.getIdentifier().equals(((SimpleName)simpleName).getIdentifier())));
    }
    return Boolean.valueOf(false);
  };
  boolean _isEmpty = IterableExtensions.isEmpty(this.findAssignmentsInBlock(scope, _function));
  return Boolean.valueOf((!_isEmpty));
}
 
Example #18
Source File: RemoveDeclarationCorrectionProposal.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public boolean visit(PrefixExpression node) {
	Object operator= node.getOperator();
	if (operator == PrefixExpression.Operator.INCREMENT || operator == PrefixExpression.Operator.DECREMENT) {
		fSideEffectNodes.add(node);
	}
	return false;
}
 
Example #19
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;
}
 
Example #20
Source File: AdvancedQuickAssistProcessor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private static Expression getBooleanExpression(ASTNode node) {
	if (!(node instanceof Expression)) {
		return null;
	}

	// check if the node is a location where it can be negated
	StructuralPropertyDescriptor locationInParent= node.getLocationInParent();
	if (locationInParent == QualifiedName.NAME_PROPERTY) {
		node= node.getParent();
		locationInParent= node.getLocationInParent();
	}
	while (locationInParent == ParenthesizedExpression.EXPRESSION_PROPERTY) {
		node= node.getParent();
		locationInParent= node.getLocationInParent();
	}
	Expression expression= (Expression) node;
	if (!isBoolean(expression)) {
		return null;
	}
	if (expression.getParent() instanceof InfixExpression) {
		return expression;
	}
	if (locationInParent == Assignment.RIGHT_HAND_SIDE_PROPERTY || locationInParent == IfStatement.EXPRESSION_PROPERTY
			|| locationInParent == WhileStatement.EXPRESSION_PROPERTY || locationInParent == DoStatement.EXPRESSION_PROPERTY
			|| locationInParent == ReturnStatement.EXPRESSION_PROPERTY || locationInParent == ForStatement.EXPRESSION_PROPERTY
			|| locationInParent == AssertStatement.EXPRESSION_PROPERTY || locationInParent == MethodInvocation.ARGUMENTS_PROPERTY
			|| locationInParent == ConstructorInvocation.ARGUMENTS_PROPERTY || locationInParent == SuperMethodInvocation.ARGUMENTS_PROPERTY
			|| locationInParent == EnumConstantDeclaration.ARGUMENTS_PROPERTY || locationInParent == SuperConstructorInvocation.ARGUMENTS_PROPERTY
			|| locationInParent == ClassInstanceCreation.ARGUMENTS_PROPERTY || locationInParent == ConditionalExpression.EXPRESSION_PROPERTY
			|| locationInParent == PrefixExpression.OPERAND_PROPERTY) {
		return expression;
	}
	return null;
}
 
Example #21
Source File: AdvancedQuickAssistProcessor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private static boolean isNegated(Expression expression) {
	if (!(expression.getParent() instanceof ParenthesizedExpression))
		return false;

	ParenthesizedExpression parenthesis= (ParenthesizedExpression) expression.getParent();
	if (!(parenthesis.getParent() instanceof PrefixExpression))
		return false;

	PrefixExpression prefix= (PrefixExpression) parenthesis.getParent();
	if (!(prefix.getOperator() == PrefixExpression.Operator.NOT))
		return false;

	return true;
}
 
Example #22
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 #23
Source File: ASTResolving.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public static boolean isWriteAccess(Name selectedNode) {
	ASTNode curr= selectedNode;
	ASTNode parent= curr.getParent();
	while (parent != null) {
		switch (parent.getNodeType()) {
			case ASTNode.QUALIFIED_NAME:
				if (((QualifiedName) parent).getQualifier() == curr) {
					return false;
				}
				break;
			case ASTNode.FIELD_ACCESS:
				if (((FieldAccess) parent).getExpression() == curr) {
					return false;
				}
				break;
			case ASTNode.SUPER_FIELD_ACCESS:
				break;
			case ASTNode.ASSIGNMENT:
				return ((Assignment) parent).getLeftHandSide() == curr;
			case ASTNode.VARIABLE_DECLARATION_FRAGMENT:
			case ASTNode.SINGLE_VARIABLE_DECLARATION:
				return ((VariableDeclaration) parent).getName() == curr;
			case ASTNode.POSTFIX_EXPRESSION:
				return true;
			case ASTNode.PREFIX_EXPRESSION:
				PrefixExpression.Operator op= ((PrefixExpression) parent).getOperator();
				return op == PrefixExpression.Operator.DECREMENT || op == PrefixExpression.Operator.INCREMENT;
			default:
				return false;
		}

		curr= parent;
		parent= curr.getParent();
	}
	return false;
}
 
Example #24
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 #25
Source File: UnusedCodeFix.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public boolean visit(PrefixExpression node) {
	Object operator= node.getOperator();
	if (operator == PrefixExpression.Operator.INCREMENT || operator == PrefixExpression.Operator.DECREMENT) {
		fSideEffectNodes.add(node);
		return false;
	}
	return true;
}
 
Example #26
Source File: StyledStringVisitor.java    From JDeodorant with MIT License 5 votes vote down vote up
public boolean visit(PrefixExpression expr) {
	/*
	 * PrefixExpression: PrefixOperator Expression
	 */
	activateDiffStyle(expr);
	styledString.append(expr.getOperator().toString(), determineDiffStyle(expr, new StyledStringStyler(ordinaryStyle)));
	handleExpression((Expression) expr.getOperand());
	deactivateDiffStyle(expr);
	return false;
}
 
Example #27
Source File: FlowAnalyzer.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void endVisit(PrefixExpression node) {
	PrefixExpression.Operator op = node.getOperator();
	if (PrefixExpression.Operator.INCREMENT.equals(op) || PrefixExpression.Operator.DECREMENT.equals(op)) {
		endVisitIncDecOperation(node, node.getOperand());
	} else {
		assignFlowInfo(node, node.getOperand());
	}
}
 
Example #28
Source File: AbstractMethodFragment.java    From JDeodorant with MIT License 5 votes vote down vote up
private Set<PrefixExpression> getMatchingPrefixAssignments(SimpleName simpleName, List<Expression> prefixExpressions) {
	Set<PrefixExpression> matchingPrefixAssignments = new LinkedHashSet<PrefixExpression>();
	for(Expression expression : prefixExpressions) {
		PrefixExpression prefixExpression = (PrefixExpression)expression;
		Expression operand = prefixExpression.getOperand();
		PrefixExpression.Operator operator = prefixExpression.getOperator();
		SimpleName operandName = MethodDeclarationUtility.getRightMostSimpleName(operand);
		if(operandName != null && operandName.equals(simpleName) &&
				(operator.equals(PrefixExpression.Operator.INCREMENT) ||
				operator.equals(PrefixExpression.Operator.DECREMENT))) {
			matchingPrefixAssignments.add(prefixExpression);
		}
	}
	return matchingPrefixAssignments;
}
 
Example #29
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 #30
Source File: ASTFlattenerUtils.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
public Iterable<Expression> findAssignmentsInBlock(final Block scope, final VariableDeclaration varDecl) {
  final Function1<Expression, Boolean> _function = (Expression it) -> {
    Expression name = null;
    boolean _matched = false;
    if (it instanceof Assignment) {
      _matched=true;
      name = ((Assignment)it).getLeftHandSide();
    }
    if (!_matched) {
      if (it instanceof PrefixExpression) {
        _matched=true;
        name = ((PrefixExpression)it).getOperand();
      }
    }
    if (!_matched) {
      if (it instanceof PostfixExpression) {
        _matched=true;
        name = ((PostfixExpression)it).getOperand();
      }
    }
    if ((name instanceof Name)) {
      final IBinding binding = ((Name)name).resolveBinding();
      if ((binding instanceof IVariableBinding)) {
        final IVariableBinding declBinding = varDecl.resolveBinding();
        return Boolean.valueOf((varDecl.getName().getIdentifier().equals(this.toSimpleName(((Name)name))) && ((IVariableBinding)binding).equals(declBinding)));
      }
    }
    return Boolean.valueOf(false);
  };
  return this.findAssignmentsInBlock(scope, _function);
}