use of org.eclipse.ceylon.model.typechecker.model.ClassOrInterface in project ceylon by eclipse.
the class TestModuleManager method tmptest.
@Test
public void tmptest() {
System.out.println("-----------------------");
ClassOrInterface d0 = (ClassOrInterface) srclang.getDirectMember("Iterable", null, false);
Assert.assertNotNull("ContainerWithFirstElement from srclang", d0);
ClassOrInterface d1 = (ClassOrInterface) jslang.getDirectMember("Iterable", null, false);
Assert.assertNotNull("ContainerWithFirstElement from jslang", d1);
Type seq0 = null, seq1 = null;
for (Type pt : d0.getSatisfiedTypes()) {
System.out.println(d0 + " satisfies " + pt);
if (pt.asString().startsWith("Null[]")) {
seq0 = pt;
break;
}
}
for (Type pt : d1.getSatisfiedTypes()) {
if (pt.asString().startsWith("Null[]")) {
seq1 = pt;
break;
}
}
compareTypes(seq0, seq1, new ArrayList<String>());
System.out.println("src " + seq0 + " - js " + seq1);
compareTypeDeclarations(d0, d1);
FunctionOrValue m0 = (FunctionOrValue) d0.getDirectMember("last", null, false);
FunctionOrValue m1 = (FunctionOrValue) d1.getDirectMember("last", null, false);
System.out.println("Iterable.last " + m0 + " vs " + m1);
System.out.println("refined member " + d0.getRefinedMember("last", null, false).getContainer() + " vs " + d1.getRefinedMember("last", null, false).getContainer());
System.out.println("last is transient? " + m0.isTransient() + " vs " + m1.isTransient());
System.out.println("refined " + m0.getRefinedDeclaration().getContainer() + " vs " + m1.getRefinedDeclaration().getContainer());
}
use of org.eclipse.ceylon.model.typechecker.model.ClassOrInterface in project ceylon by eclipse.
the class RefinementVisitor method checkNonMember.
private void checkNonMember(Tree.Declaration that, Declaration dec) {
boolean mayBeShared = !(dec instanceof TypeParameter);
boolean nonTypeMember = !dec.isClassOrInterfaceMember();
String name = dec.getName();
if (dec.isStatic()) {
if (nonTypeMember) {
that.addError("static declaration is not a member of a class or interface: '" + name + "' is not defined directly in the body of a class or interface");
} else {
ClassOrInterface type = (ClassOrInterface) dec.getContainer();
if (!type.isToplevel()) {
that.addError("static declaration belongs to a nested a class or interface: '" + name + "' is a member of nested type '" + type.getName() + "'");
}
}
}
if (nonTypeMember && mayBeShared) {
if (dec.isActual()) {
that.addError("actual declaration is not a member of a class or interface: '" + name + "'", 1301);
}
if (dec.isFormal()) {
that.addError("formal declaration is not a member of a class or interface: '" + name + "'", 1302);
}
if (dec.isDefault()) {
that.addError("default declaration is not a member of a class or interface: '" + name + "'", 1303);
}
} else if (!dec.isShared() && mayBeShared) {
if (dec.isActual()) {
that.addError("actual declaration must be shared: '" + name + "'", 701);
}
if (dec.isFormal()) {
that.addError("formal declaration must be shared: '" + name + "'", 702);
}
if (dec.isDefault()) {
that.addError("default declaration must be shared: '" + name + "'", 703);
}
} else {
if (dec.isActual()) {
that.addError("declaration may not be actual: '" + name + "'", 1301);
}
if (dec.isFormal()) {
that.addError("declaration may not be formal: '" + name + "'", 1302);
}
if (dec.isDefault()) {
that.addError("declaration may not be default: '" + name + "'", 1303);
}
}
if (isOverloadedVersion(dec)) {
if (isConstructor(dec)) {
checkOverloadedAnnotation(that, dec);
checkOverloadedParameters(that, dec);
} else {
that.addError("duplicate declaration: the name '" + name + "' is not unique in this scope");
}
} else if (isAbstraction(dec)) {
// that is considered overloaded in the model
if (that instanceof Tree.ClassDefinition && !that.hasErrors()) {
Tree.ClassDefinition def = (Tree.ClassDefinition) that;
// this is an abstraction
Class abs = (Class) dec;
// correctly located)
for (Tree.Statement st : def.getClassBody().getStatements()) {
if (st instanceof Tree.Constructor) {
Tree.Constructor node = (Tree.Constructor) st;
if (node.getIdentifier() == null) {
Constructor con = node.getConstructor();
// get the corresponding overloaded version
Class cla = classOverloadForConstructor(abs, con);
checkOverloadedAnnotation(node, con);
checkOverloadedParameters(node, cla);
}
}
}
}
}
if (isConstructor(dec) && dec.isShared()) {
Scope container = dec.getContainer();
if (container instanceof Class) {
Class clazz = (Class) container;
Declaration member = intersectionOfSupertypes(clazz).getDeclaration().getMember(name, null, false);
if (member != null && member.isShared() && !isConstructor(member)) {
Declaration supertype = (Declaration) member.getContainer();
that.addError("constructor has same name as an inherited member '" + clazz.getName() + "' inherits '" + member.getName() + "' from '" + supertype.getName(that.getUnit()) + "'");
}
}
}
}
use of org.eclipse.ceylon.model.typechecker.model.ClassOrInterface in project ceylon by eclipse.
the class RefinementVisitor method visit.
@Override
public void visit(Tree.SpecifierStatement that) {
super.visit(that);
List<Type> sig = new ArrayList<Type>();
Tree.Term term = that.getBaseMemberExpression();
while (term instanceof Tree.ParameterizedExpression) {
sig.clear();
Tree.ParameterizedExpression pe = (Tree.ParameterizedExpression) term;
Tree.TypeParameterList typeParameterList = pe.getTypeParameterList();
if (typeParameterList != null) {
// TODO: remove this for #1329
typeParameterList.addError("specification statements may not have type parameters");
}
Tree.ParameterList pl = pe.getParameterLists().get(0);
for (Tree.Parameter p : pl.getParameters()) {
if (p == null) {
sig.add(null);
} else {
Parameter model = p.getParameterModel();
if (model != null) {
sig.add(model.getType());
} else {
sig.add(null);
}
}
}
term = pe.getPrimary();
}
if (term instanceof Tree.BaseMemberExpression) {
Tree.BaseMemberExpression bme = (Tree.BaseMemberExpression) term;
Unit unit = that.getUnit();
TypedDeclaration td = getTypedDeclaration(bme.getScope(), name(bme.getIdentifier()), sig, false, unit);
if (td != null) {
that.setDeclaration(td);
Scope scope = that.getScope();
Scope container = scope.getContainer();
Scope realScope = getRealScope(container);
if (realScope instanceof ClassOrInterface) {
ClassOrInterface ci = (ClassOrInterface) realScope;
Scope tdcontainer = td.getContainer();
if (td.isClassOrInterfaceMember()) {
ClassOrInterface tdci = (ClassOrInterface) tdcontainer;
if (!tdcontainer.equals(realScope) && ci.inherits(tdci)) {
boolean lazy = that.getSpecifierExpression() instanceof Tree.LazySpecifierExpression;
if (!lazy && td.isVariable() && td.isJava()) {
// allow assignment to variable
// member of Java supertype
} else // refinement of an inherited member
if (tdcontainer == scope) {
that.addError("parameter declaration hides refining member: '" + td.getName(unit) + "' (rename parameter)");
} else if (td instanceof Value) {
refineAttribute((Value) td, bme, that, ci);
} else if (td instanceof Function) {
refineMethod((Function) td, bme, that, ci);
} else {
// TODO!
bme.addError("not a reference to a formal attribute: '" + td.getName(unit) + "'");
}
}
}
}
}
}
}
use of org.eclipse.ceylon.model.typechecker.model.ClassOrInterface in project ceylon by eclipse.
the class TypeArgumentInference method inferNullaryFunctionCallTypeArgs.
/**
* Infer type arguments for the invocation of a
* nullary function that occurs as an argument.
* The parameter to which it is an argument isn't
* a callable parameter.
*/
private List<Type> inferNullaryFunctionCallTypeArgs(Tree.StaticMemberOrTypeExpression smte, Type receiverType, Declaration reference, List<TypeParameter> typeParameters, Type paramType, Declaration parameterizedDec) {
Reference arg = appliedReference(smte);
List<Type> inferredTypes = new ArrayList<Type>(typeParameters.size());
Type argType = arg.getType();
TypeDeclaration ptd = paramType.getDeclaration();
Type template = // all supertypes of argType?
ptd instanceof ClassOrInterface ? argType.getSupertype(ptd) : argType;
for (TypeParameter tp : typeParameters) {
boolean covariant = template.occursCovariantly(tp) && !template.occursContravariantly(tp);
boolean contravariant = template.occursContravariantly(tp) && !template.occursCovariantly(tp);
Type it = inferNullaryFunctionCallTypeArg(smte, tp, paramType, parameterizedDec, template, covariant, contravariant);
inferredTypes.add(it);
}
return constrainInferredTypes(typeParameters, inferredTypes, receiverType, reference);
}
use of org.eclipse.ceylon.model.typechecker.model.ClassOrInterface in project ceylon by eclipse.
the class InheritanceVisitor method checkExtensionOfMemberType.
private void checkExtensionOfMemberType(Node that, TypeDeclaration td, Type type) {
Type qt = type.getQualifyingType();
if (qt != null && td instanceof ClassOrInterface) {
Unit unit = that.getUnit();
TypeDeclaration d = type.getDeclaration();
if (d.isStatic() || d instanceof Constructor) {
checkExtensionOfMemberType(that, td, qt);
} else {
Scope s = td;
while (s != null) {
s = s.getContainer();
if (s instanceof TypeDeclaration) {
TypeDeclaration otd = (TypeDeclaration) s;
if (otd.getType().isSubtypeOf(qt)) {
return;
}
}
}
that.addError("qualifying type '" + qt.asString(unit) + "' of supertype '" + type.asString(unit) + "' is not an outer type or supertype of any outer type of '" + td.getName(unit) + "'");
}
}
}
Aggregations