use of org.eclipse.ceylon.model.typechecker.model.Scope in project ceylon by eclipse.
the class ExpressionVisitor method visitGenericBaseTypeReference.
private void visitGenericBaseTypeReference(Tree.StaticMemberOrTypeExpression that, TypeDeclaration type) {
if (type instanceof Class && type.isParameterized()) {
Class generic = (Class) type;
Scope scope = that.getScope();
Type outerType = scope.getDeclaringType(type);
Type target = type.appliedType(outerType, typeParametersAsArgList(generic));
that.setTarget(target);
Type functionType = genericFunctionType(generic, scope, type, target, unit);
that.setTypeModel(functionType);
checkNotJvm(that, "type functions are not supported on the JVM: '" + type.getName(unit) + "' is generic (specify explicit type arguments)");
}
}
use of org.eclipse.ceylon.model.typechecker.model.Scope in project ceylon by eclipse.
the class ExpressionVisitor method resolveBaseMemberExpression.
private TypedDeclaration resolveBaseMemberExpression(Tree.BaseMemberExpression that, boolean error) {
Tree.Identifier id = that.getIdentifier();
String name = name(id);
Scope scope = that.getScope();
TypedDeclaration member = getTypedDeclaration(scope, name, that.getSignature(), that.getEllipsis(), that.getUnit());
if (member == null) {
if (!dynamic && !isNativeForWrongBackend(scope, unit) && error) {
that.addError("function or value is not defined: '" + name + "'" + correctionMessage(name, scope, unit, cancellable), 100);
unit.setUnresolvedReferences();
}
} else {
member = (TypedDeclaration) handleAbstractionOrHeader(member, that, error);
that.setDeclaration(member);
if (error) {
if (checkConcreteConstructor(member, that)) {
checkBaseVisibility(that, member, name);
}
}
}
return member;
}
use of org.eclipse.ceylon.model.typechecker.model.Scope in project ceylon by eclipse.
the class ExpressionVisitor method warnIfCustomEquals.
private void warnIfCustomEquals(Node node, TypeDeclaration dec) {
// reasonable definitions of equality
if (!dec.isJavaEnum()) {
Declaration eq = dec.getMember("equals", Arrays.asList(unit.getObjectType()), false);
if (eq != null) {
Scope container = eq.getContainer();
if (container instanceof TypeDeclaration) {
TypeDeclaration td = (TypeDeclaration) container;
Interface id = unit.getIdentifiableDeclaration();
if (!container.equals(id)) {
node.addUsageWarning(Warning.valueEqualityIgnored, "value equality defined by type '" + td.getName(unit) + "' ignored (identity equality is used to match value case)");
}
}
}
}
}
use of org.eclipse.ceylon.model.typechecker.model.Scope in project ceylon by eclipse.
the class RefinementVisitor method refineMethod.
private void refineMethod(Function assignedMethod, Tree.BaseMemberExpression bme, Tree.SpecifierStatement that, ClassOrInterface c) {
if (!assignedMethod.isFormal() && !assignedMethod.isDefault() && !assignedMethod.isShortcutRefinement()) {
// this condition is here to squash a dupe message
bme.addError("inherited method may not be refined: " + message(assignedMethod) + " is declared neither 'formal' nor 'default'", 510);
// return;
}
ClassOrInterface ci = (ClassOrInterface) assignedMethod.getContainer();
String name = assignedMethod.getName();
List<Type> signature = getSignature(assignedMethod);
boolean variadic = isVariadic(assignedMethod);
Declaration refined = ci.getRefinedMember(name, signature, variadic);
Function root = refined instanceof Function ? (Function) refined : assignedMethod;
Reference rm = getRefinedMemberReference(assignedMethod, c);
Function method = new Function();
method.setName(name);
List<Tree.ParameterList> paramLists;
List<TypeParameter> typeParams;
Tree.Term me = that.getBaseMemberExpression();
if (me instanceof Tree.ParameterizedExpression) {
Tree.ParameterizedExpression pe = (Tree.ParameterizedExpression) me;
paramLists = pe.getParameterLists();
Tree.TypeParameterList typeParameterList = pe.getTypeParameterList();
if (typeParameterList != null) {
typeParams = new ArrayList<TypeParameter>();
for (Tree.TypeParameterDeclaration tpd : typeParameterList.getTypeParameterDeclarations()) {
typeParams.add(tpd.getDeclarationModel());
}
} else {
typeParams = null;
}
} else {
paramLists = emptyList();
typeParams = null;
}
Unit unit = that.getUnit();
final Map<TypeParameter, Type> subs;
if (typeParams != null) {
// the type parameters are written
// down in the shortcut refinement
method.setTypeParameters(typeParams);
// TODO: check 'em!!
// no need to check them because
// this case is actually disallowed
// elsewhere (specification statements
// may not have type parameters)
subs = NO_SUBSTITUTIONS;
} else if (assignedMethod.isParameterized()) {
if (me instanceof Tree.ParameterizedExpression) {
// we have parameters, but no type parameters
bme.addError("refined method is generic: '" + assignedMethod.getName(unit) + "' declares type parameters");
subs = NO_SUBSTITUTIONS;
} else {
// we're assigning a method reference
// so we need to magic up some "fake"
// type parameters
subs = copyTypeParametersFromRefined(assignedMethod, method, unit);
}
} else {
subs = NO_SUBSTITUTIONS;
}
int i = 0;
for (ParameterList pl : assignedMethod.getParameterLists()) {
Tree.ParameterList params = paramLists.size() <= i ? null : paramLists.get(i++);
createRefiningParameterList(rm, method, params, unit, subs, pl);
}
method.setShared(true);
method.setActual(true);
method.getAnnotations().add(new Annotation("shared"));
method.getAnnotations().add(new Annotation("actual"));
method.setRefinedDeclaration(root);
method.setUnit(unit);
method.setContainer(c);
method.setScope(c);
method.setShortcutRefinement(true);
method.setDeclaredVoid(assignedMethod.isDeclaredVoid());
Declaration rmd = rm.getDeclaration();
if (rmd instanceof TypedDeclaration) {
TypedDeclaration rmtd = (TypedDeclaration) rmd;
method.setUncheckedNullType(rmtd.hasUncheckedNullType());
}
ModelUtil.setVisibleScope(method);
c.addMember(method);
that.setRefinement(true);
that.setDeclaration(method);
that.setRefined(root);
unit.addDeclaration(method);
Scope scope = that.getScope();
if (scope instanceof Specification) {
Specification spec = (Specification) scope;
spec.setDeclaration(method);
}
setRefiningType(c, ci, name, signature, variadic, root, method, unit, subs);
inheritDefaultedArguments(method);
}
use of org.eclipse.ceylon.model.typechecker.model.Scope in project ceylon by eclipse.
the class DeclarationVisitor method visit.
@Override
public void visit(Tree.AnyClass that) {
Class c = that.getDeclarationModel();
visitDeclaration(that, c);
Scope o = enterScope(c);
super.visit(that);
exitScope(o);
Tree.ParameterList pl = that.getParameterList();
if (pl != null) {
pl.getModel().setFirst(true);
c.addParameterList(pl.getModel());
}
// TODO: is this still necessary??
if (c.isClassOrInterfaceMember() && c.getContainer() instanceof TypedDeclaration) {
that.addUnsupportedError("nested classes of inner classes are not yet supported");
}
Tree.Identifier identifier = that.getIdentifier();
if (c.isAbstract() && c.isFinal()) {
that.addError("class may not be both 'abstract' and 'final': '" + name(identifier) + "'");
}
if (c.isFormal() && c.isFinal()) {
that.addError("class may not be both 'formal' and 'final': '" + name(identifier) + "'");
}
if (hasAnnotation(that.getAnnotationList(), "service", that.getUnit())) {
if (!c.getTypeParameters().isEmpty()) {
that.addError("service class may not be generic");
}
}
}
Aggregations