List of usage examples for org.eclipse.jdt.core.dom AssertStatement setMessage
public void setMessage(Expression expression)
From source file:java5totext.input.JDTVisitor.java
License:Open Source License
@Override public void endVisit(org.eclipse.jdt.core.dom.AssertStatement node) { AssertStatement element = (AssertStatement) this.binding.get(node); this.initializeNode(element, node); if (this.binding.get(node.getMessage()) != null) element.setMessage((Expression) this.binding.get(node.getMessage())); if (this.binding.get(node.getExpression()) != null) element.setExpression((Expression) this.binding.get(node.getExpression())); }
From source file:org.decojer.cavaj.transformers.TrControlFlowStmts.java
License:Open Source License
private AssertStatement transformAssert(@Nonnull final E out, @Nonnull final Expression expression) { // has to be done after Control Flow Analysis! Could be a manually thrown AssertionError in // combination with other structs (like directly behind pre-loop) if (getCfg().getCu().check(DFlag.IGNORE_ASSERT)) { return null; }// ww w .ja v a 2s . c o m // if (!DecTestAsserts.$assertionsDisabled && (l1 > 0L ? l1 >= l2 : l1 > l2)) // throw new AssertionError("complex expression " + l1 - l2); final BB bb = out.getEnd(); if (bb.getStmts() != 1) { return null; } final Statement throwStmt = bb.getStmt(0); if (!(throwStmt instanceof ThrowStatement)) { return null; } final Expression exceptionExpression = ((ThrowStatement) throwStmt).getExpression(); if (!(exceptionExpression instanceof ClassInstanceCreation)) { return null; } final ClassInstanceCreation classInstanceCreation = (ClassInstanceCreation) exceptionExpression; final Type type = classInstanceCreation.getType(); if (!(type instanceof SimpleType)) { return null; } final Name name = ((SimpleType) type).getName(); if (!(name instanceof SimpleName)) { return null; } if (!"AssertionError".equals(((SimpleName) name).getIdentifier())) { return null; } final Expression messageExpression; final List<Expression> arguments = classInstanceCreation.arguments(); if (arguments.isEmpty()) { messageExpression = null; } else { if (arguments.size() > 1) { return null; } messageExpression = arguments.get(0); } Expression assertExpression = expression; if (expression instanceof InfixExpression) { final InfixExpression infixExpression = (InfixExpression) expression; if (infixExpression.getOperator() == InfixExpression.Operator.CONDITIONAL_OR) { final Expression leftOperand = infixExpression.getLeftOperand(); if (leftOperand instanceof QualifiedName && leftOperand.toString().endsWith(".$assertionsDisabled")) { assertExpression = infixExpression.getRightOperand(); assert assertExpression != null; } } } else if (expression instanceof QualifiedName && ((QualifiedName) expression).toString().endsWith(".$assertionsDisabled")) { assertExpression = getAst().newBooleanLiteral(false); assert assertExpression != null; } final AssertStatement assertStatement = setOp(getAst().newAssertStatement(), getOp(throwStmt)); assertStatement.setExpression(wrap(not(assertExpression))); if (messageExpression != null) { assertStatement.setMessage(wrap(messageExpression)); } return assertStatement; }
From source file:org.eclipse.jdt.core.dom.ASTConverter.java
License:Open Source License
public AssertStatement convert(org.eclipse.jdt.internal.compiler.ast.AssertStatement statement) { AssertStatement assertStatement = new AssertStatement(this.ast); final Expression assertExpression = convert(statement.assertExpression); Expression searchingNode = assertExpression; assertStatement.setExpression(assertExpression); org.eclipse.jdt.internal.compiler.ast.Expression exceptionArgument = statement.exceptionArgument; if (exceptionArgument != null) { final Expression exceptionMessage = convert(exceptionArgument); assertStatement.setMessage(exceptionMessage); searchingNode = exceptionMessage; }/* w ww . jav a2 s .c o m*/ int start = statement.sourceStart; int sourceEnd = retrieveSemiColonPosition(searchingNode); if (sourceEnd == -1) { sourceEnd = searchingNode.getStartPosition() + searchingNode.getLength() - 1; assertStatement.setSourceRange(start, sourceEnd - start + 1); } else { assertStatement.setSourceRange(start, sourceEnd - start + 1); } return assertStatement; }
From source file:org.eclipse.modisco.java.discoverer.internal.io.java.JDTVisitor.java
License:Open Source License
@Override public void endVisit(final org.eclipse.jdt.core.dom.AssertStatement node) { AssertStatement element = (AssertStatement) this.binding.get(node); initializeNode(element, node);//ww w . j av a 2 s .c o m if (this.binding.get(node.getMessage()) != null) { element.setMessage(JDTVisitorUtils.completeExpression(this.binding.get(node.getMessage()), this)); } if (this.binding.get(node.getExpression()) != null) { element.setExpression(JDTVisitorUtils.completeExpression(this.binding.get(node.getExpression()), this)); } }