use of com.sun.tools.javac.code.Type.ClassType in project ceylon-compiler by ceylon.
the class Attr method attribDiamond.
Type attribDiamond(Env<AttrContext> env, JCNewClass tree, Type clazztype, Pair<Scope, Scope> mapping, List<Type> argtypes, List<Type> typeargtypes) {
if (clazztype.isErroneous() || clazztype.isInterface() || mapping == erroneousMapping) {
// mapping, return the (possibly erroneous) type unchanged
return clazztype;
}
// dup attribution environment and augment the set of inference variables
Env<AttrContext> localEnv = env.dup(tree);
localEnv.info.tvars = clazztype.tsym.type.getTypeArguments();
// if the type of the instance creation expression is a class type
// apply method resolution inference (JLS 15.12.2.7). The return type
// of the resolved constructor will be a partially instantiated type
((ClassSymbol) clazztype.tsym).members_field = mapping.snd;
Symbol constructor;
try {
constructor = rs.resolveDiamond(tree.pos(), localEnv, clazztype.tsym.type, argtypes, typeargtypes);
} finally {
((ClassSymbol) clazztype.tsym).members_field = mapping.fst;
}
if (constructor.kind == MTH) {
ClassType ct = new ClassType(clazztype.getEnclosingType(), clazztype.tsym.type.getTypeArguments(), clazztype.tsym);
clazztype = checkMethod(ct, constructor, localEnv, tree.args, argtypes, typeargtypes, localEnv.info.varArgs).getReturnType();
} else {
clazztype = syms.errType;
}
if (clazztype.tag == FORALL && !pt.isErroneous()) {
// bounds (JLS 15.12.2.8).
try {
clazztype = infer.instantiateExpr((ForAll) clazztype, pt.tag == NONE ? syms.objectType : pt, Warner.noWarnings);
} catch (Infer.InferenceException ex) {
// an error occurred while inferring uninstantiated type-variables
log.error(tree.clazz.pos(), "cant.apply.diamond.1", diags.fragment("diamond", clazztype.tsym), ex.diagnostic);
}
}
return chk.checkClassType(tree.clazz.pos(), clazztype, true);
}
use of com.sun.tools.javac.code.Type.ClassType in project ceylon-compiler by ceylon.
the class Attr method checkId.
/**
* Determine type of identifier or select expression and check that
* (1) the referenced symbol is not deprecated
* (2) the symbol's type is safe (@see checkSafe)
* (3) if symbol is a variable, check that its type and kind are
* compatible with the prototype and protokind.
* (4) if symbol is an instance field of a raw type,
* which is being assigned to, issue an unchecked warning if its
* type changes under erasure.
* (5) if symbol is an instance method of a raw type, issue an
* unchecked warning if its argument types change under erasure.
* If checks succeed:
* If symbol is a constant, return its constant type
* else if symbol is a method, return its result type
* otherwise return its type.
* Otherwise return errType.
*
* @param tree The syntax tree representing the identifier
* @param site If this is a select, the type of the selected
* expression, otherwise the type of the current class.
* @param sym The symbol representing the identifier.
* @param env The current environment.
* @param pkind The set of expected kinds.
* @param pt The expected type.
*/
Type checkId(JCTree tree, Type site, Symbol sym, Env<AttrContext> env, int pkind, Type pt, boolean useVarargs) {
if (pt.isErroneous())
return types.createErrorType(site);
// The computed type of this identifier occurrence.
Type owntype;
switch(sym.kind) {
case TYP:
// For types, the computed type equals the symbol's type,
// except for two situations:
owntype = sym.type;
if (owntype.tag == CLASS) {
Type ownOuter = owntype.getEnclosingType();
// We recover generic outer type later in visitTypeApply.
if (owntype.tsym.type.getTypeArguments().nonEmpty()) {
owntype = types.erasure(owntype);
} else // Tree<Point>.Visitor.
if (ownOuter.tag == CLASS && site != ownOuter) {
Type normOuter = site;
if (normOuter.tag == CLASS)
normOuter = types.asEnclosingSuper(site, ownOuter.tsym);
if (// perhaps from an import
normOuter == null)
normOuter = types.erasure(ownOuter);
if (normOuter != ownOuter)
owntype = new ClassType(normOuter, List.<Type>nil(), owntype.tsym);
}
}
break;
case VAR:
VarSymbol v = (VarSymbol) sym;
// its type changes under erasure.
if (allowGenerics && pkind == VAR && v.owner.kind == TYP && (v.flags() & STATIC) == 0 && (site.tag == CLASS || site.tag == TYPEVAR)) {
Type s = types.asOuterSuper(site, v.owner);
if (s != null && s.isRaw() && !types.isSameType(v.type, v.erasure(types))) {
chk.warnUnchecked(tree.pos(), "unchecked.assign.to.var", v, s);
}
}
// The computed type of a variable is the type of the
// variable symbol, taken as a member of the site type.
owntype = (sym.owner.kind == TYP && sym.name != names._this && sym.name != names._super) ? types.memberType(site, sym) : sym.type;
if (env.info.tvars.nonEmpty()) {
Type owntype1 = new ForAll(env.info.tvars, owntype);
for (List<Type> l = env.info.tvars; l.nonEmpty(); l = l.tail) if (!owntype.contains(l.head)) {
log.error(tree.pos(), "undetermined.type", owntype1);
owntype1 = types.createErrorType(owntype1);
}
owntype = owntype1;
}
// computed type.
if (v.getConstValue() != null && isStaticReference(tree))
owntype = owntype.constType(v.getConstValue());
if (pkind == VAL) {
// capture "names as expressions"
owntype = capture(owntype);
}
break;
case MTH:
{
JCMethodInvocation app = (JCMethodInvocation) env.tree;
owntype = checkMethod(site, sym, env, app.args, pt.getParameterTypes(), pt.getTypeArguments(), env.info.varArgs);
break;
}
case PCK:
case ERR:
owntype = sym.type;
break;
default:
throw new AssertionError("unexpected kind: " + sym.kind + " in tree " + tree);
}
if (sym.name != names.init) {
chk.checkDeprecated(tree.pos(), env.info.scope.owner, sym);
chk.checkSunAPI(tree.pos(), sym);
}
// kind are compatible with the prototype and protokind.
return check(tree, owntype, sym.kind, pkind, pt);
}
use of com.sun.tools.javac.code.Type.ClassType in project ceylon-compiler by ceylon.
the class ParameterizedTypeImpl method parameterizedTypeToString.
static String parameterizedTypeToString(DocEnv env, ClassType cl, boolean full) {
if (env.legacyDoclet) {
return TypeMaker.getTypeName(cl, full);
}
StringBuilder s = new StringBuilder();
if (cl.getEnclosingType().tag != CLASS) {
// if not an inner class...
s.append(TypeMaker.getTypeName(cl, full));
} else {
ClassType encl = (ClassType) cl.getEnclosingType();
s.append(parameterizedTypeToString(env, encl, full)).append('.').append(cl.tsym.name.toString());
}
s.append(TypeMaker.typeArgumentsString(env, cl, full));
return s.toString();
}
use of com.sun.tools.javac.code.Type.ClassType in project ceylon-compiler by ceylon.
the class TypeMaker method typeArgumentsString.
/**
* Return the actual type arguments of a parameterized type as an
* angle-bracketed string. Class name are qualified if "full" is true.
* Return "" if there are no type arguments or we're hiding generics.
*/
static String typeArgumentsString(DocEnv env, ClassType cl, boolean full) {
if (env.legacyDoclet || cl.getTypeArguments().isEmpty()) {
return "";
}
StringBuilder s = new StringBuilder();
for (Type t : cl.getTypeArguments()) {
s.append(s.length() == 0 ? "<" : ", ");
s.append(getTypeString(env, t, full));
}
s.append(">");
return s.toString();
}
Aggregations