Search in sources :

Example 11 with ArrayType

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

the class Attr method visitNewArray.

public void visitNewArray(JCNewArray tree) {
    Type owntype = types.createErrorType(tree.type);
    Type elemtype;
    if (tree.elemtype != null) {
        elemtype = attribType(tree.elemtype, env);
        chk.validate(tree.elemtype, env);
        owntype = elemtype;
        for (List<JCExpression> l = tree.dims; l.nonEmpty(); l = l.tail) {
            attribExpr(l.head, env, syms.intType);
            owntype = new ArrayType(owntype, syms.arrayClass);
        }
    } else {
        // this is allowed only if the prototype is an array
        if (pt.tag == ARRAY) {
            elemtype = types.elemtype(pt);
        } else {
            if (pt.tag != ERROR) {
                log.error(tree.pos(), "illegal.initializer.for.type", pt);
            }
            elemtype = types.createErrorType(pt);
        }
    }
    if (tree.elems != null) {
        attribExprs(tree.elems, env, elemtype);
        owntype = new ArrayType(elemtype, syms.arrayClass);
    }
    if (!types.isReifiable(elemtype))
        log.error(tree.pos(), "generic.array.creation");
    result = check(tree, owntype, VAL, pkind, pt);
}
Also used : ArrayType(com.sun.tools.javac.code.Type.ArrayType) ClassType(com.sun.tools.javac.code.Type.ClassType) MethodType(com.sun.tools.javac.code.Type.MethodType) WildcardType(com.sun.tools.javac.code.Type.WildcardType) Type(com.sun.tools.javac.code.Type) ArrayType(com.sun.tools.javac.code.Type.ArrayType) UnionClassType(com.sun.tools.javac.code.Type.UnionClassType) JCExpression(com.sun.tools.javac.tree.JCTree.JCExpression)

Example 12 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

ArrayType (com.sun.tools.javac.code.Type.ArrayType)12 Type (com.sun.tools.javac.code.Type)10 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 VarSymbol (com.sun.tools.javac.code.Symbol.VarSymbol)2 JCExpression (com.sun.tools.javac.tree.JCTree.JCExpression)2 TypeMirror (javax.lang.model.type.TypeMirror)2 AnnotationFieldType (scenelib.annotations.field.AnnotationFieldType)2 ArrayAFT (scenelib.annotations.field.ArrayAFT)2 ProvidesFix (com.google.errorprone.BugPattern.ProvidesFix)1 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