Search in sources :

Example 1 with IllegalArgumentException

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;
}
Also used : InfixExpression(org.eclipse.jdt.core.dom.InfixExpression) IllegalArgumentException(org.autorefactor.util.IllegalArgumentException)

Example 2 with IllegalArgumentException

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 + "'");
}
Also used : ParameterizedType(org.eclipse.jdt.core.dom.ParameterizedType) ArrayType(org.eclipse.jdt.core.dom.ArrayType) ParameterizedType(org.eclipse.jdt.core.dom.ParameterizedType) SimpleType(org.eclipse.jdt.core.dom.SimpleType) Type(org.eclipse.jdt.core.dom.Type) WildcardType(org.eclipse.jdt.core.dom.WildcardType) PrimitiveType(org.eclipse.jdt.core.dom.PrimitiveType) WildcardType(org.eclipse.jdt.core.dom.WildcardType) ITypeBinding(org.eclipse.jdt.core.dom.ITypeBinding) NotImplementedException(org.autorefactor.util.NotImplementedException) IllegalArgumentException(org.autorefactor.util.IllegalArgumentException)

Aggregations

IllegalArgumentException (org.autorefactor.util.IllegalArgumentException)2 NotImplementedException (org.autorefactor.util.NotImplementedException)1 ArrayType (org.eclipse.jdt.core.dom.ArrayType)1 ITypeBinding (org.eclipse.jdt.core.dom.ITypeBinding)1 InfixExpression (org.eclipse.jdt.core.dom.InfixExpression)1 ParameterizedType (org.eclipse.jdt.core.dom.ParameterizedType)1 PrimitiveType (org.eclipse.jdt.core.dom.PrimitiveType)1 SimpleType (org.eclipse.jdt.core.dom.SimpleType)1 Type (org.eclipse.jdt.core.dom.Type)1 WildcardType (org.eclipse.jdt.core.dom.WildcardType)1