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

The following examples show how to use org.eclipse.jdt.core.dom.AssertStatement. 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: StyledStringVisitor.java    From JDeodorant with MIT License 6 votes vote down vote up
public boolean visit(AssertStatement stmnt) {
	/*
	 * assert Expression [ : Expression ] ;
	 */
	styledString.append("assert", new StyledStringStyler(keywordStyle));
	appendSpace();
	handleExpression((Expression) stmnt.getExpression());
	if (stmnt.getMessage() != null) {
		appendSpace();
		appendColon();
		appendSpace();
		handleExpression((Expression) stmnt.getMessage());
	}
	appendSemicolon();
	return false;
}
 
Example #2
Source File: NecessaryParenthesesChecker.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private static boolean locationNeedsParentheses(StructuralPropertyDescriptor locationInParent) {
	if (locationInParent instanceof ChildListPropertyDescriptor && locationInParent != InfixExpression.EXTENDED_OPERANDS_PROPERTY) {
		// e.g. argument lists of MethodInvocation, ClassInstanceCreation, dimensions of ArrayCreation ...
		return false;
	}
	if (locationInParent == VariableDeclarationFragment.INITIALIZER_PROPERTY
			|| locationInParent == SingleVariableDeclaration.INITIALIZER_PROPERTY
			|| locationInParent == ReturnStatement.EXPRESSION_PROPERTY
			|| locationInParent == EnhancedForStatement.EXPRESSION_PROPERTY
			|| locationInParent == ForStatement.EXPRESSION_PROPERTY
			|| locationInParent == WhileStatement.EXPRESSION_PROPERTY
			|| locationInParent == DoStatement.EXPRESSION_PROPERTY
			|| locationInParent == AssertStatement.EXPRESSION_PROPERTY
			|| locationInParent == AssertStatement.MESSAGE_PROPERTY
			|| locationInParent == IfStatement.EXPRESSION_PROPERTY
			|| locationInParent == SwitchStatement.EXPRESSION_PROPERTY
			|| locationInParent == SwitchCase.EXPRESSION_PROPERTY
			|| locationInParent == ArrayAccess.INDEX_PROPERTY
			|| locationInParent == ThrowStatement.EXPRESSION_PROPERTY
			|| locationInParent == SynchronizedStatement.EXPRESSION_PROPERTY
			|| locationInParent == ParenthesizedExpression.EXPRESSION_PROPERTY) {
		return false;
	}
	return true;
}
 
Example #3
Source File: CodeBlock.java    From SimFix with GNU General Public License v2.0 5 votes vote down vote up
/************************** visit start : Statement ***********************/
private AssertStmt visit(AssertStatement node) {
	int start = _cunit.getLineNumber(node.getStartPosition());
	int end = _cunit.getLineNumber(node.getStartPosition() + node.getLength());
	AssertStmt assertStmt = new AssertStmt(start, end, node);
	return assertStmt;
}
 
Example #4
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 #5
Source File: FlowAnalyzer.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void endVisit(AssertStatement node) {
	if (skipNode(node))
		return;
	IfFlowInfo info= new IfFlowInfo();
	setFlowInfo(node, info);
	info.mergeCondition(getFlowInfo(node.getExpression()), fFlowContext);
	info.merge(getFlowInfo(node.getMessage()), null, fFlowContext);
}
 
Example #6
Source File: JavaASTFlattener.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public boolean visit(final AssertStatement node) {
  this.appendToBuffer("if(!(");
  node.getExpression().accept(this);
  this.appendToBuffer(")) {");
  this.appendToBuffer("throw new AssertionError(");
  Expression _message = node.getMessage();
  boolean _tripleNotEquals = (_message != null);
  if (_tripleNotEquals) {
    node.getMessage().accept(this);
  }
  this.appendToBuffer(")}");
  return false;
}
 
Example #7
Source File: InvertBooleanUtility.java    From eclipse.jdt.ls with Eclipse Public License 2.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 #8
Source File: FlowAnalyzer.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void endVisit(AssertStatement node) {
	if (skipNode(node)) {
		return;
	}
	IfFlowInfo info = new IfFlowInfo();
	setFlowInfo(node, info);
	info.mergeCondition(getFlowInfo(node.getExpression()), fFlowContext);
	info.merge(getFlowInfo(node.getMessage()), null, fFlowContext);
}
 
Example #9
Source File: CodeSearch.java    From SimFix with GNU General Public License v2.0 5 votes vote down vote up
public boolean visit(AssertStatement node) {
	int start = _unit.getLineNumber(node.getStartPosition());
	if(start == _extendedLine){
		_extendedStatement = node;
		return false;
	}
	return true;
}
 
Example #10
Source File: AstMatchingNodeFinder.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
@Override
public boolean visit(AssertStatement node) {
	if (node.subtreeMatch(fMatcher, fNodeToMatch))
		return matches(node);
	return super.visit(node);
}
 
Example #11
Source File: ConstraintCollector.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
@Override
public boolean visit(AssertStatement node) {
	add(fCreator.create(node));
	return true;
}
 
Example #12
Source File: GenericVisitor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
@Override
public void endVisit(AssertStatement node) {
	endVisitNode(node);
}
 
Example #13
Source File: GenericVisitor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
@Override
public boolean visit(AssertStatement node) {
	return visitNode(node);
}
 
Example #14
Source File: AssertVisitor.java    From aDoctor with MIT License 4 votes vote down vote up
@Override
public boolean visit(AssertStatement node) {
    asserts.add(node);

    return super.visit(node);
}
 
Example #15
Source File: StatementCollector.java    From JDeodorant with MIT License 4 votes vote down vote up
public boolean visit(AssertStatement node) {
	statementList.add(node);
	return false;
}
 
Example #16
Source File: ExtractStatementsVisitor.java    From JDeodorant with MIT License 4 votes vote down vote up
public boolean visit(AssertStatement node) {
	statementsList.add(node);
	
	return false;
}
 
Example #17
Source File: ConstraintCreator.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 2 votes vote down vote up
/**
 * @param node the AST node
 * @return array of type constraints, may be empty
 * @see org.eclipse.jdt.core.dom.ASTVisitor#visit(org.eclipse.jdt.core.dom.AssertStatement)
 */
public ITypeConstraint[] create(AssertStatement node) {
	return EMPTY_ARRAY;
}
 
Example #18
Source File: AssertVisitor.java    From aDoctor with MIT License 2 votes vote down vote up
/**
 * This method allows to get all the Blocks for the Class on which it is;
 *
 * @return a List of all Blocks;
 */
public Collection<AssertStatement> getAsserts() {
    return asserts;
}