Search in sources :

Example 6 with ArrayType

use of com.sun.tools.javac.code.Type.ArrayType in project error-prone by google.

the class ArraysAsListPrimitiveArray method matchMethodInvocation.

@Override
public Description matchMethodInvocation(MethodInvocationTree tree, VisitorState state) {
    if (!ARRAYS_AS_LIST_SINGLE_ARRAY.matches(tree, state)) {
        return NO_MATCH;
    }
    ExpressionTree array = Iterables.getOnlyElement(tree.getArguments());
    Type componentType = ((ArrayType) ASTHelpers.getType(array)).getComponentType();
    if (!componentType.isPrimitive()) {
        return NO_MATCH;
    }
    String guavaUtils = GUAVA_UTILS.get(componentType.getKind());
    if (guavaUtils == null) {
        return NO_MATCH;
    }
    Fix fix = SuggestedFix.builder().addImport("com.google.common.primitives." + guavaUtils).replace(tree.getMethodSelect(), guavaUtils + ".asList").build();
    return describeMatch(tree, fix);
}
Also used : ArrayType(com.sun.tools.javac.code.Type.ArrayType) ArrayType(com.sun.tools.javac.code.Type.ArrayType) Type(com.sun.tools.javac.code.Type) SuggestedFix(com.google.errorprone.fixes.SuggestedFix) Fix(com.google.errorprone.fixes.Fix) ExpressionTree(com.sun.source.tree.ExpressionTree)

Example 7 with ArrayType

use of com.sun.tools.javac.code.Type.ArrayType in project ceylon-compiler by ceylon.

the class JavacType method getComponentType.

@Override
public TypeMirror getComponentType() {
    if (!componentTypeSet && type instanceof ArrayType) {
        Type compType = ((ArrayType) type).getComponentType();
        if (compType != null) {
            componentType = new JavacType(compType);
        }
        componentTypeSet = true;
    }
    return componentType;
}
Also used : ArrayType(com.sun.tools.javac.code.Type.ArrayType) ArrayType(com.sun.tools.javac.code.Type.ArrayType) WildcardType(com.sun.tools.javac.code.Type.WildcardType) Type(com.sun.tools.javac.code.Type)

Aggregations

Type (com.sun.tools.javac.code.Type)7 ArrayType (com.sun.tools.javac.code.Type.ArrayType)7 WildcardType (com.sun.tools.javac.code.Type.WildcardType)5 ClassType (com.sun.tools.javac.code.Type.ClassType)4 MethodType (com.sun.tools.javac.code.Type.MethodType)3 UnionClassType (com.sun.tools.javac.code.Type.UnionClassType)3 JCExpression (com.sun.tools.javac.tree.JCTree.JCExpression)2 Fix (com.google.errorprone.fixes.Fix)1 SuggestedFix (com.google.errorprone.fixes.SuggestedFix)1 Matchers.isArrayType (com.google.errorprone.matchers.Matchers.isArrayType)1 Matchers.isPrimitiveType (com.google.errorprone.matchers.Matchers.isPrimitiveType)1 Matchers.isSameType (com.google.errorprone.matchers.Matchers.isSameType)1 ASTHelpers.getType (com.google.errorprone.util.ASTHelpers.getType)1 ExpressionTree (com.sun.source.tree.ExpressionTree)1 Tree (com.sun.source.tree.Tree)1 TypeCastTree (com.sun.source.tree.TypeCastTree)1 Lint (com.sun.tools.javac.code.Lint)1 Symbol (com.sun.tools.javac.code.Symbol)1 ClassSymbol (com.sun.tools.javac.code.Symbol.ClassSymbol)1 DynamicMethodSymbol (com.sun.tools.javac.code.Symbol.DynamicMethodSymbol)1