use of org.eclipse.ceylon.langtools.tools.javac.code.Symbol in project ceylon by eclipse.
the class LambdaToMethod method deserGetter.
private JCExpression deserGetter(String func, Type type, List<Type> argTypes, List<JCExpression> args) {
MethodType getmt = new MethodType(argTypes, type, List.<Type>nil(), syms.methodClass);
Symbol getsym = rs.resolveQualifiedMethod(null, attrEnv, syms.serializedLambdaType, names.fromString(func), argTypes, List.<Type>nil());
return make.Apply(List.<JCExpression>nil(), make.Select(make.Ident(kInfo.deserParamSym).setType(syms.serializedLambdaType), getsym).setType(getmt), args).setType(type);
}
use of org.eclipse.ceylon.langtools.tools.javac.code.Symbol in project ceylon by eclipse.
the class Check method firstIncompatibility.
/**
* Return the first method which is defined with same args
* but different return types in two given interfaces, or null if none
* exists.
* @param t1 The first type.
* @param t2 The second type.
* @param site The most derived type.
* @returns symbol from t2 that conflicts with one in t1.
*/
private Symbol firstIncompatibility(DiagnosticPosition pos, Type t1, Type t2, Type site) {
Map<TypeSymbol, Type> interfaces1 = new HashMap<TypeSymbol, Type>();
closure(t1, interfaces1);
Map<TypeSymbol, Type> interfaces2;
if (t1 == t2)
interfaces2 = interfaces1;
else
closure(t2, interfaces1, interfaces2 = new HashMap<TypeSymbol, Type>());
for (Type t3 : interfaces1.values()) {
for (Type t4 : interfaces2.values()) {
Symbol s = firstDirectIncompatibility(pos, t3, t4, site);
if (s != null)
return s;
}
}
return null;
}
use of org.eclipse.ceylon.langtools.tools.javac.code.Symbol in project ceylon by eclipse.
the class Check method checkDefaultMethodClashes.
void checkDefaultMethodClashes(DiagnosticPosition pos, Type site) {
DefaultMethodClashFilter dcf = new DefaultMethodClashFilter(site);
for (Symbol m : types.membersClosure(site, false).getElements(dcf)) {
Assert.check(m.kind == MTH);
List<MethodSymbol> prov = types.interfaceCandidates(site, (MethodSymbol) m);
if (prov.size() > 1) {
ListBuffer<Symbol> abstracts = new ListBuffer<>();
ListBuffer<Symbol> defaults = new ListBuffer<>();
for (MethodSymbol provSym : prov) {
if ((provSym.flags() & DEFAULT) != 0) {
defaults = defaults.append(provSym);
} else if ((provSym.flags() & ABSTRACT) != 0) {
abstracts = abstracts.append(provSym);
}
if (defaults.nonEmpty() && defaults.size() + abstracts.size() >= 2) {
// strong semantics - issue an error if two sibling interfaces
// have two override-equivalent defaults - or if one is abstract
// and the other is default
String errKey;
Symbol s1 = defaults.first();
Symbol s2;
if (defaults.size() > 1) {
errKey = "types.incompatible.unrelated.defaults";
s2 = defaults.toList().tail.head;
} else {
errKey = "types.incompatible.abstract.default";
s2 = abstracts.first();
}
log.error(pos, errKey, Kinds.kindName(site.tsym), site, m.name, types.memberType(site, m).getParameterTypes(), s1.location(), s2.location());
break;
}
}
}
}
}
use of org.eclipse.ceylon.langtools.tools.javac.code.Symbol in project ceylon by eclipse.
the class Check method validateAnnotation.
private boolean validateAnnotation(JCAnnotation a) {
boolean isValid = true;
// collect an inventory of the annotation elements
Set<MethodSymbol> members = new LinkedHashSet<MethodSymbol>();
for (Scope.Entry e = a.annotationType.type.tsym.members().elems; e != null; e = e.sibling) if (e.sym.kind == MTH && e.sym.name != names.clinit && (e.sym.flags() & SYNTHETIC) == 0)
members.add((MethodSymbol) e.sym);
// remove the ones that are assigned values
for (JCTree arg : a.args) {
// recovery
if (!arg.hasTag(ASSIGN))
continue;
JCAssign assign = (JCAssign) arg;
Symbol m = TreeInfo.symbol(assign.lhs);
if (m == null || m.type.isErroneous())
continue;
if (!members.remove(m)) {
isValid = false;
log.error(assign.lhs.pos(), "duplicate.annotation.member.value", m.name, a.type);
}
}
// all the remaining ones better have default values
List<Name> missingDefaults = List.nil();
for (MethodSymbol m : members) {
if (m.defaultValue == null && !m.type.isErroneous()) {
missingDefaults = missingDefaults.append(m.name);
}
}
missingDefaults = missingDefaults.reverse();
if (missingDefaults.nonEmpty()) {
isValid = false;
String key = (missingDefaults.size() > 1) ? "annotation.missing.default.value.1" : "annotation.missing.default.value";
log.error(a.pos(), key, a.type, missingDefaults);
}
// repeated values in its value member
if (a.annotationType.type.tsym != syms.annotationTargetType.tsym || a.args.tail == null)
return isValid;
// error recovery
if (!a.args.head.hasTag(ASSIGN))
return false;
JCAssign assign = (JCAssign) a.args.head;
Symbol m = TreeInfo.symbol(assign.lhs);
if (m.name != names.value)
return false;
JCTree rhs = assign.rhs;
if (!rhs.hasTag(NEWARRAY))
return false;
JCNewArray na = (JCNewArray) rhs;
Set<Symbol> targets = new HashSet<Symbol>();
for (JCTree elem : na.elems) {
if (!targets.add(TreeInfo.symbol(elem))) {
isValid = false;
log.error(elem.pos(), "repeated.annotation.target");
}
}
return isValid;
}
use of org.eclipse.ceylon.langtools.tools.javac.code.Symbol in project ceylon by eclipse.
the class Check method checkCommonOverriderIn.
// WHERE
boolean checkCommonOverriderIn(Symbol s1, Symbol s2, Type site) {
Map<TypeSymbol, Type> supertypes = new HashMap<TypeSymbol, Type>();
Type st1 = types.memberType(site, s1);
Type st2 = types.memberType(site, s2);
closure(site, supertypes);
for (Type t : supertypes.values()) {
for (Scope.Entry e = t.tsym.members().lookup(s1.name); e.scope != null; e = e.next()) {
Symbol s3 = e.sym;
if (s3 == s1 || s3 == s2 || s3.kind != MTH || (s3.flags() & (BRIDGE | SYNTHETIC)) != 0)
continue;
Type st3 = types.memberType(site, s3);
if (types.overrideEquivalent(st3, st1) && types.overrideEquivalent(st3, st2) && types.returnTypeSubstitutable(st3, st1) && types.returnTypeSubstitutable(st3, st2)) {
return true;
}
}
}
return false;
}
Aggregations