use of org.autorefactor.util.IllegalArgumentException in project AutoRefactor by JnRouvignac.
the class ASTBuilder method infixExpr.
/**
* Builds a new {@link InfixExpression} instance.
*
* @param operator the infix operator
* @param allOperands the operands
* @return a new infix expression
*/
public InfixExpression infixExpr(InfixExpression.Operator operator, Collection<? extends Expression> allOperands) {
if (allOperands.size() < 2) {
throw new IllegalArgumentException(null, "Not enough operands for an infix expression: " + "needed at least 2, but got " + allOperands.size());
}
final Iterator<? extends Expression> it = allOperands.iterator();
final InfixExpression ie = ast.newInfixExpression();
ie.setLeftOperand(it.next());
ie.setOperator(operator);
ie.setRightOperand(it.next());
while (it.hasNext()) {
extendedOperands(ie).add(it.next());
}
return ie;
}
use of org.autorefactor.util.IllegalArgumentException in project AutoRefactor by JnRouvignac.
the class ASTBuilder method toType.
/**
* Converts a type binding into a type.
*
* @param typeBinding the type binding to convert
* @param typeNameDecider decides on how the type should be referenced (simple name or qualified name)
* @return a new type
*/
public Type toType(ITypeBinding typeBinding, TypeNameDecider typeNameDecider) {
if (typeBinding == null) {
throw new IllegalArgumentException(null, "typeBinding cannot be null");
}
if (typeBinding.isParameterizedType()) {
final ParameterizedType type = ast.newParameterizedType(toType(typeBinding.getErasure(), typeNameDecider));
final List<Type> typeArgs = typeArguments(type);
for (ITypeBinding typeArg : typeBinding.getTypeArguments()) {
typeArgs.add(toType(typeArg, typeNameDecider));
}
return type;
} else if (typeBinding.isPrimitive()) {
return type(typeBinding.getName());
} else if (typeBinding.isClass() || typeBinding.isInterface() || typeBinding.isEnum() || typeBinding.isAnnotation() || typeBinding.isNullType() || typeBinding.isRawType()) {
return type(typeNameDecider.useSimplestPossibleName(typeBinding));
} else if (typeBinding.isArray()) {
return ast.newArrayType(toType(typeBinding.getElementType(), typeNameDecider));
} else if (typeBinding.isWildcardType()) {
final WildcardType type = ast.newWildcardType();
if (typeBinding.getBound() != null) {
type.setBound(toType(typeBinding.getBound(), typeNameDecider), typeBinding.isUpperbound());
}
return type;
} else if (typeBinding.isTypeVariable()) {
return type(typeBinding.getName());
} else if (typeBinding.isCapture()) {
if (typeBinding.getTypeBounds().length > 1) {
throw new NotImplementedException(null, "because it violates the javadoc of `ITypeBinding.getTypeBounds()`: " + "\"Note that per construction, it can only contain one class or array type, " + "at most, and then it is located in first position.\"");
}
return toType(typeBinding.getWildcard(), typeNameDecider);
}
throw new NotImplementedException(null, " for the type binding '" + typeBinding + "'");
}
Aggregations