use of org.eclipse.ceylon.model.typechecker.model.TypeDeclaration in project ceylon by eclipse.
the class ExpressionVisitor method visit.
@Override
public void visit(Tree.QualifiedTypeExpression that) {
super.visit(that);
boolean notIndirectlyInvoked = !that.getIndirectlyInvoked();
boolean notDirectlyInvoked = !that.getDirectlyInvoked();
TypeDeclaration type = resolveQualifiedTypeExpression(that, notIndirectlyInvoked);
boolean inferrableAnyway = !notDirectlyInvoked && inferrableAnyway(type);
if (type != null && notDirectlyInvoked || inferrableAnyway) {
Tree.Primary primary = that.getPrimary();
Tree.TypeArguments tal = that.getTypeArguments();
Type receiverType = primary.getTypeModel().resolveAliases();
List<Type> typeArgs;
if (explicitTypeArguments(type, tal)) {
typeArgs = getTypeArguments(tal, receiverType, type.getTypeParameters());
} else {
typeArgs = new TypeArgumentInference(unit).getInferredTypeArgsForFunctionRef(that, receiverType, inferrableAnyway);
}
if (typeArgs != null) {
tal.setTypeModels(typeArgs);
if (primary instanceof Tree.Package) {
visitBaseTypeExpression(that, type, typeArgs, tal, null);
} else {
visitQualifiedTypeExpression(that, receiverType, type, typeArgs, tal);
}
} else if (notDirectlyInvoked) {
if (!that.getStaticMethodReferencePrimary()) {
if (primary instanceof Tree.Package) {
visitGenericBaseTypeReference(that, type);
} else {
visitGenericQualifiedTypeReference(that, receiverType, type);
}
}
}
if (that.getStaticMethodReference()) {
handleStaticReferenceImplicitTypeArguments(that);
}
// otherwise infer type arguments later
}
}
use of org.eclipse.ceylon.model.typechecker.model.TypeDeclaration in project ceylon by eclipse.
the class ExpressionVisitor method resolveQualifiedTypeExpression.
private TypeDeclaration resolveQualifiedTypeExpression(Tree.QualifiedTypeExpression that, boolean error) {
if (checkMember(that)) {
Tree.Primary primary = that.getPrimary();
Tree.Identifier id = that.getIdentifier();
List<Type> signature = that.getSignature();
boolean spread = that.getEllipsis();
String name = name(id);
String container;
boolean ambiguous;
TypeDeclaration type;
Type pt;
if (primary instanceof Tree.Package) {
Package pack = unit.getPackage();
container = "package '" + pack.getNameAsString() + "'";
type = getPackageTypeDeclaration(name, signature, spread, unit);
ambiguous = false;
pt = null;
} else {
pt = primary.getTypeModel().resolveAliases();
TypeDeclaration d = getDeclaration(that, pt);
if (d instanceof Constructor) {
d = d.getExtendedType().getDeclaration();
}
container = "type '" + d.getName(unit) + "'";
Scope scope = that.getScope();
type = getTypeMember(d, name, signature, spread, unit, scope);
ambiguous = type == null && d.isMemberAmbiguous(name, unit, signature, spread);
if (type == null) {
container += memberCorrectionMessage(name, d, scope, unit, cancellable);
}
}
if (type == null) {
if (error) {
if (ambiguous) {
that.addError("member type is ambiguous: '" + name + "' for " + container);
} else {
that.addError("member type is not defined: '" + name + "' in " + container, 100);
unit.setUnresolvedReferences();
}
}
} else {
type = (TypeDeclaration) handleAbstractionOrHeader(type, that, error);
if (error) {
checkStaticPrimary(that, primary, type, pt);
}
that.setDeclaration(type);
resetSuperReference(that);
if (!isSelfReference(primary) && !type.isShared()) {
type.setOtherInstanceAccess(true);
}
if (error) {
if (checkConcreteClass(type, that)) {
if (checkVisibleConstructor(that, type)) {
checkQualifiedTypeAndConstructorVisibility(that, type, name, container);
}
}
if (!inExtendsClause) {
checkSuperMember(that, signature, spread);
}
}
}
return type;
} else {
return null;
}
}
use of org.eclipse.ceylon.model.typechecker.model.TypeDeclaration in project ceylon by eclipse.
the class ExpressionVisitor method checkStaticPrimary.
private void checkStaticPrimary(Tree.QualifiedMemberOrTypeExpression that, Tree.Primary primary, Declaration member, Type pt) {
if (member.isStatic() && !that.getStaticMethodReference()) {
Tree.MemberOperator mo = that.getMemberOperator();
TypeDeclaration outer = (TypeDeclaration) member.getContainer();
if (member.isJava()) {
primary.addUsageWarning(Warning.syntaxDeprecation, "reference to static member should be qualified by type: '" + member.getName(unit) + "' is a static member of '" + outer.getName(unit) + "'");
} else if (!(mo instanceof Tree.MemberOp)) {
mo.addError("operator '" + mo.getText() + "' may not be followed by reference to static member: '" + member.getName(unit) + "' is a static member of '" + outer.getName(unit) + "'");
} else {
primary.addError("reference to static member must be qualified by type: '" + member.getName(unit) + "' is a static member of '" + pt.getSupertype(outer).asString(unit) + "'", 14000);
}
}
}
use of org.eclipse.ceylon.model.typechecker.model.TypeDeclaration in project ceylon by eclipse.
the class ExpressionVisitor method checkDelegatedConstructor.
protected void checkDelegatedConstructor(Tree.DelegatedConstructor dc, Constructor c, Node node) {
if (dc == null) {
if (c.isClassMember()) {
Class clazz = (Class) c.getContainer();
Type et = clazz.getExtendedType();
if (et != null && !et.isBasic()) {
TypeDeclaration superclass = et.getDeclaration();
if (superclass != null) {
node.addError("constructor must explicitly delegate to some superclass constructor: '" + clazz.getName() + "' extends '" + superclass.getName() + "'");
}
}
}
}
}
use of org.eclipse.ceylon.model.typechecker.model.TypeDeclaration in project ceylon by eclipse.
the class ExpressionVisitor method visit.
@Override
public void visit(Tree.ClassDeclaration that) {
super.visit(that);
Class alias = that.getDeclarationModel();
Type et = alias.getExtendedType();
Tree.ClassSpecifier cs = that.getClassSpecifier();
if (cs != null && et != null) {
TypeDeclaration etd = et.getDeclaration();
if (etd instanceof Constructor) {
etd = etd.getExtendedType().getDeclaration();
}
if (etd instanceof Class) {
// TODO: some of this belongs in InheritanceVisitor!
Class c = (Class) etd;
if (c.isAbstract()) {
if (!alias.isFormal() && !alias.isAbstract()) {
that.addError("alias of abstract class must be annotated abstract", 310);
}
}
if (c.isAbstraction()) {
that.addError("class alias may not alias overloaded class");
} else {
Tree.InvocationExpression ie = cs.getInvocationExpression();
if (ie != null) {
checkClassAliasParameters(alias, that, ie);
}
}
}
}
}
Aggregations