use of org.eclipse.ceylon.langtools.tools.javac.code.Symbol in project ceylon by eclipse.
the class Attr method visitSwitch.
public void visitSwitch(JCSwitch tree) {
Type seltype = attribExpr(tree.selector, env);
Env<AttrContext> switchEnv = env.dup(tree, env.info.dup(env.info.scope.dup()));
try {
boolean enumSwitch = allowEnums && (seltype.tsym.flags() & Flags.ENUM) != 0;
boolean stringSwitch = false;
if (types.isSameType(seltype, syms.stringType)) {
if (allowStringsInSwitch) {
stringSwitch = true;
} else {
log.error(tree.selector.pos(), "string.switch.not.supported.in.source", sourceName);
}
}
if (!enumSwitch && !stringSwitch)
seltype = chk.checkType(tree.selector.pos(), seltype, syms.intType);
// Attribute all cases and
// check that there are no duplicate case labels or default clauses.
// The set of case labels.
Set<Object> labels = new HashSet<Object>();
// Is there a default label?
boolean hasDefault = false;
for (List<JCCase> l = tree.cases; l.nonEmpty(); l = l.tail) {
JCCase c = l.head;
Env<AttrContext> caseEnv = switchEnv.dup(c, env.info.dup(switchEnv.info.scope.dup()));
try {
if (c.pat != null) {
if (enumSwitch) {
Symbol sym = enumConstant(c.pat, seltype);
if (sym == null) {
log.error(c.pat.pos(), "enum.label.must.be.unqualified.enum");
} else if (!labels.add(sym)) {
log.error(c.pos(), "duplicate.case.label");
}
} else {
Type pattype = attribExpr(c.pat, switchEnv, seltype);
if (!pattype.hasTag(ERROR)) {
if (pattype.constValue() == null) {
log.error(c.pat.pos(), (stringSwitch ? "string.const.req" : "const.expr.req"));
} else if (labels.contains(pattype.constValue())) {
log.error(c.pos(), "duplicate.case.label");
} else {
labels.add(pattype.constValue());
}
}
}
} else if (hasDefault) {
log.error(c.pos(), "duplicate.default.label");
} else {
hasDefault = true;
}
attribStats(c.stats, caseEnv);
} finally {
caseEnv.info.scope.leave();
addVars(c.stats, switchEnv.info.scope);
}
}
result = null;
} finally {
switchEnv.info.scope.leave();
}
}
use of org.eclipse.ceylon.langtools.tools.javac.code.Symbol in project ceylon by eclipse.
the class Attr method enumConstant.
// where
/**
* Return the selected enumeration constant symbol, or null.
*/
private Symbol enumConstant(JCTree tree, Type enumType) {
if (!tree.hasTag(IDENT)) {
log.error(tree.pos(), "enum.label.must.be.unqualified.enum");
return syms.errSymbol;
}
JCIdent ident = (JCIdent) tree;
Name name = ident.name;
for (Scope.Entry e = enumType.tsym.members().lookup(name); e.scope != null; e = e.next()) {
if (e.sym.kind == VAR) {
Symbol s = ident.sym = e.sym;
// ensure initializer is evaluated
((VarSymbol) s).getConstValue();
ident.type = s.type;
return ((s.flags_field & Flags.ENUM) == 0) ? null : s;
}
}
return null;
}
use of org.eclipse.ceylon.langtools.tools.javac.code.Symbol in project ceylon by eclipse.
the class Attr method checkAutoCloseable.
void checkAutoCloseable(DiagnosticPosition pos, Env<AttrContext> env, Type resource) {
if (!resource.isErroneous() && types.asSuper(resource, syms.autoCloseableType.tsym) != null && !types.isSameType(resource, syms.autoCloseableType)) {
// Don't emit warning for AutoCloseable itself
Symbol close = syms.noSymbol;
Log.DiagnosticHandler discardHandler = new Log.DiscardDiagnosticHandler(log);
try {
close = rs.resolveQualifiedMethod(pos, env, resource, names.close, List.<Type>nil(), List.<Type>nil());
} finally {
log.popDiagnosticHandler(discardHandler);
}
if (close.kind == MTH && close.overrides(syms.autoCloseableClose, resource.tsym, types, true) && chk.isHandled(syms.interruptedExceptionType, types.memberType(resource, close).getThrownTypes()) && env.info.lint.isEnabled(LintCategory.TRY)) {
log.warning(LintCategory.TRY, pos, "try.resource.throws.interrupted.exc", resource);
}
}
}
use of org.eclipse.ceylon.langtools.tools.javac.code.Symbol in project ceylon by eclipse.
the class Attr method checkLambdaCandidate.
private void checkLambdaCandidate(JCNewClass tree, ClassSymbol csym, Type clazztype) {
if (allowLambda && identifyLambdaCandidate && clazztype.hasTag(CLASS) && !pt().hasTag(NONE) && types.isFunctionalInterface(clazztype.tsym)) {
Symbol descriptor = types.findDescriptorSymbol(clazztype.tsym);
int count = 0;
boolean found = false;
for (Symbol sym : csym.members().getElements()) {
if ((sym.flags() & SYNTHETIC) != 0 || sym.isConstructor())
continue;
count++;
if (sym.kind != MTH || !sym.name.equals(descriptor.name))
continue;
Type mtype = types.memberType(clazztype, sym);
if (types.overrideEquivalent(mtype, types.memberType(clazztype, descriptor))) {
found = true;
}
}
if (found && count == 1) {
log.note(tree.def, "potential.lambda.found");
}
}
}
use of org.eclipse.ceylon.langtools.tools.javac.code.Symbol in project ceylon by eclipse.
the class Attr method visitParens.
public void visitParens(JCParens tree) {
Type owntype = attribTree(tree.expr, env, resultInfo);
result = check(tree, owntype, pkind(), resultInfo);
Symbol sym = TreeInfo.symbol(tree);
if (sym != null && (sym.kind & (TYP | PCK)) != 0)
log.error(tree.pos(), "illegal.start.of.type");
}
Aggregations