use of org.eclipse.ceylon.model.typechecker.model.Setter in project ceylon by eclipse.
the class ExpressionVisitor method visit.
@Override
public void visit(Tree.AttributeSetterDefinition that) {
Setter set = that.getDeclarationModel();
Declaration od = beginReturnDeclaration(set);
Tree.Type rt = beginReturnScope(that.getType());
super.visit(that);
endReturnScope(rt, set);
endReturnDeclaration(od);
Tree.SpecifierExpression se = that.getSpecifierExpression();
if (se != null) {
Tree.Expression e = se.getExpression();
if (e != null) {
if (!isSatementExpression(e)) {
se.addError("specified expression must be a statement: '" + set.getName() + "'");
}
}
}
}
use of org.eclipse.ceylon.model.typechecker.model.Setter in project ceylon by eclipse.
the class Metamodel method getTypeDescriptorForProducedType.
public static TypeDescriptor getTypeDescriptorForProducedType(org.eclipse.ceylon.model.typechecker.model.Type type) {
TypeDeclaration declaration = type.getDeclaration();
if (type.isNothing()) {
return TypeDescriptor.NothingType;
}
if (type.isUnion()) {
TypeDescriptor[] tdArgs = getTypeDescriptorsForProducedTypes(type.getCaseTypes());
return TypeDescriptor.union(tdArgs);
}
if (type.isIntersection()) {
TypeDescriptor[] tdArgs = getTypeDescriptorsForProducedTypes(type.getSatisfiedTypes());
return TypeDescriptor.intersection(tdArgs);
}
if (declaration instanceof LazyClass) {
ReflectionClass classMirror = (ReflectionClass) ((LazyClass) declaration).classMirror;
TypeDescriptor[] tdArgs = getTypeDescriptorsForProducedTypes(type.getTypeArgumentList());
TypeDescriptor ret = TypeDescriptor.klass(classMirror.klass, tdArgs);
if (type.getQualifyingType() != null)
return TypeDescriptor.member(getTypeDescriptorForProducedType(type.getQualifyingType()), ret);
return ret;
}
if (declaration instanceof LazyInterface) {
ReflectionClass classMirror = (ReflectionClass) ((LazyInterface) declaration).classMirror;
TypeDescriptor[] tdArgs = getTypeDescriptorsForProducedTypes(type.getTypeArgumentList());
TypeDescriptor ret = TypeDescriptor.klass(classMirror.klass, tdArgs);
if (type.getQualifyingType() != null)
return TypeDescriptor.member(getTypeDescriptorForProducedType(type.getQualifyingType()), ret);
return ret;
}
if (declaration instanceof FunctionOrValueInterface) {
TypedDeclaration underlyingDeclaration = ((FunctionOrValueInterface) declaration).getUnderlyingDeclaration();
TypeDescriptor[] tdArgs = getTypeDescriptorsForProducedTypes(type.getTypeArgumentList());
TypeDescriptor ret;
if (underlyingDeclaration.isToplevel()) {
ReflectionClass classMirror;
// type arguments
if (underlyingDeclaration instanceof Setter)
underlyingDeclaration = ((Setter) underlyingDeclaration).getGetter();
if (underlyingDeclaration instanceof LazyValue)
classMirror = (ReflectionClass) ((LazyValue) underlyingDeclaration).classMirror;
else if (underlyingDeclaration instanceof LazyFunction)
classMirror = (ReflectionClass) ((LazyFunction) underlyingDeclaration).classMirror;
else
throw Metamodel.newModelError("Unsupported underlying declaration type: " + underlyingDeclaration);
ret = TypeDescriptor.functionOrValue(classMirror.klass, tdArgs);
} else
ret = TypeDescriptor.functionOrValue(underlyingDeclaration.getPrefixedName(), tdArgs);
if (type.getQualifyingType() != null)
return TypeDescriptor.member(getTypeDescriptorForProducedType(type.getQualifyingType()), ret);
return ret;
}
if (declaration instanceof UnknownType) {
((UnknownType) declaration).reportErrors();
}
throw Metamodel.newModelError("Unsupported declaration type: " + (declaration == null ? "null" : declaration.getClass()));
}
use of org.eclipse.ceylon.model.typechecker.model.Setter in project ceylon by eclipse.
the class CeylonEnter method typeCheck.
private void typeCheck() {
final java.util.List<PhasedUnit> listOfUnits = phasedUnits.getPhasedUnits();
Module jdk = modelLoader.getJDKBaseModule();
Package javaLangPackage = jdk.getPackage("java.lang");
for (PhasedUnit pu : listOfUnits) {
pu.getUnit().setJavaLangPackage(javaLangPackage);
}
// Delegate to an external typechecker (e.g. the IDE build)
compilerDelegate.typeCheck(listOfUnits);
if (sp != null) {
sp.clearLine();
sp.log("Preparation phase");
}
int size = listOfUnits.size();
int i = 1;
// This phase is proper to the Java backend
ForcedCaptureVisitor fcv = new ForcedCaptureVisitor();
for (PhasedUnit pu : listOfUnits) {
if (sp != null)
progressPreparation(1, i++, size, pu);
Unit unit = pu.getUnit();
final CompilationUnit compilationUnit = pu.getCompilationUnit();
compilationUnit.visit(fcv);
for (Declaration d : unit.getDeclarations()) {
if (d instanceof TypedDeclaration && !(d instanceof Setter) && // skip already captured members
!d.isCaptured()) {
compilationUnit.visit(new MethodOrValueReferenceVisitor((TypedDeclaration) d));
}
}
}
EeVisitor eeVisitor = gen.getEeVisitor();
UnsupportedVisitor uv = new UnsupportedVisitor(eeVisitor);
JvmMissingNativeVisitor mnv = new JvmMissingNativeVisitor();
BoxingDeclarationVisitor boxingDeclarationVisitor = new CompilerBoxingDeclarationVisitor(gen);
BoxingVisitor boxingVisitor = new CompilerBoxingVisitor(gen);
SmallDeclarationVisitor smallDeclarationVisitor = new SmallDeclarationVisitor();
SmallVisitor smallVisitor = new SmallVisitor();
DeferredVisitor deferredVisitor = new DeferredVisitor();
AnnotationDeclarationVisitor adv = new AnnotationDeclarationVisitor(gen);
AnnotationModelVisitor amv = new AnnotationModelVisitor(gen);
DefiniteAssignmentVisitor dav = new DefiniteAssignmentVisitor();
TypeParameterCaptureVisitor tpCaptureVisitor = new TypeParameterCaptureVisitor();
InterfaceVisitor localInterfaceVisitor = new InterfaceVisitor();
// Extra phases for the compiler
// boxing visitor depends on boxing decl
i = 1;
for (PhasedUnit pu : listOfUnits) {
if (sp != null)
progressPreparation(2, i++, size, pu);
pu.getCompilationUnit().visit(eeVisitor);
pu.getCompilationUnit().visit(uv);
pu.getCompilationUnit().visit(adv);
}
i = 1;
for (PhasedUnit pu : listOfUnits) {
if (sp != null)
progressPreparation(3, i++, size, pu);
pu.getCompilationUnit().visit(boxingDeclarationVisitor);
pu.getCompilationUnit().visit(smallDeclarationVisitor);
pu.getCompilationUnit().visit(amv);
}
i = 1;
// the others can run at the same time
for (PhasedUnit pu : listOfUnits) {
if (sp != null)
progressPreparation(4, i++, size, pu);
CompilationUnit compilationUnit = pu.getCompilationUnit();
compilationUnit.visit(mnv);
compilationUnit.visit(boxingVisitor);
compilationUnit.visit(smallVisitor);
compilationUnit.visit(deferredVisitor);
compilationUnit.visit(dav);
compilationUnit.visit(tpCaptureVisitor);
compilationUnit.visit(localInterfaceVisitor);
}
i = 1;
for (PhasedUnit pu : listOfUnits) {
if (sp != null)
progressPreparation(5, i++, size, pu);
CompilationUnit compilationUnit = pu.getCompilationUnit();
compilationUnit.visit(new WarningSuppressionVisitor<Warning>(Warning.class, pu.getSuppressedWarnings()));
}
collectTreeErrors(true, true);
}
use of org.eclipse.ceylon.model.typechecker.model.Setter in project ceylon by eclipse.
the class RefinementVisitor method checkMember.
private void checkMember(Tree.Declaration that, Declaration member) {
String name = member.getName();
if (name == null) {
return;
}
if (member instanceof Setter) {
Setter setter = (Setter) member;
Value getter = setter.getGetter();
Declaration rd = getter.getRefinedDeclaration();
member.setRefinedDeclaration(rd);
return;
}
ClassOrInterface type = (ClassOrInterface) member.getContainer();
if (member.isFormal() && type instanceof Class) {
Class c = (Class) type;
if (!c.isAbstract() && !c.isFormal()) {
if (c.isClassOrInterfaceMember()) {
that.addError("formal member belongs to concrete nested class: '" + member.getName() + "' is a member of class '" + c.getName() + "' which is neither 'abstract' nor 'formal'", 1100);
} else {
that.addError("formal member belongs to concrete class: '" + member.getName() + "' is a member of class '" + c.getName() + "' which is not annotated 'abstract'", 1100);
}
}
}
if (member.isStatic() && !type.isToplevel()) {
that.addError("static member belongs to a nested class: '" + member.getName() + "' is a member of nested type '" + type.getName() + "'");
}
if (type.isDynamic()) {
if (member instanceof Class) {
that.addError("member class belongs to dynamic interface");
} else if (!member.isFormal()) {
that.addError("non-formal member belongs to dynamic interface");
}
}
if (member instanceof Functional && !that.hasErrors() && isOverloadedVersion(member)) {
checkOverloadedAnnotation(that, member);
checkOverloadedParameters(that, member);
}
checkRefinement(that, member, type);
}
use of org.eclipse.ceylon.model.typechecker.model.Setter in project ceylon by eclipse.
the class DeclarationVisitor method checkForNativeAnnotation.
private void checkForNativeAnnotation(Tree.Declaration that, Declaration model, Scope scope) {
Unit unit = model.getUnit();
if (model.isNative()) {
Backends mbackends = model.getNativeBackends();
boolean isHeader = model.isNativeHeader();
String name = model.getName();
boolean canBeNative = canBeNative(that);
if (canBeNative) {
Backends moduleBackends = unit.getPackage().getModule().getNativeBackends();
Backends backends = model.getScope().getScopedBackends();
if (!isHeader && !moduleBackends.none() && !mbackends.supports(moduleBackends)) {
that.addError("native backend name on declaration conflicts with module descriptor: '\"" + mbackends.names() + "\"' is not '\"" + moduleBackends.names() + "\"' for '" + name + "'");
} else if (!isHeader && !backends.none() && !backends.supports(mbackends)) {
that.addError("native backend for declaration conflicts with its scope: native implementation '" + name + "' for '\"" + mbackends.names() + "\"' occurs in a scope which only supports '\"" + backends.names() + "\"'");
}
if (isHeader && existImplementations(model)) {
that.addError("native header must be declared before its implementations: the native header '" + name + "' is declared after an implementation");
}
if (model instanceof Interface && ((Interface) model).isAlias()) {
that.addError("interface alias may not be marked native: '" + name + "' (add a body if a native interface was intended)");
}
model.setNativeBackends(mbackends);
Declaration member = getNativeHeader(model);
if (member == null || member.isNativeImplementation()) {
// it's not shared
if (!isHeader && mustHaveHeader(model) && !moduleBackends.equals(mbackends)) {
that.addError("shared native implementation must have a header: '" + model.getName() + "' has no native header");
}
}
if (member == null) {
if (model.isNativeHeader()) {
handleNativeHeader(model, name);
if (that instanceof Tree.ObjectDefinition) {
Tree.ObjectDefinition od = (Tree.ObjectDefinition) that;
handleNativeHeader(od.getAnonymousClass(), name);
} else if (that instanceof Tree.Constructor) {
Tree.Constructor c = (Tree.Constructor) that;
handleNativeHeader(c.getConstructor(), name);
}
} else {
member = model.getContainer().getDirectMemberForBackend(model.getName(), mbackends);
if (member != null && member != model) {
that.addError("duplicate native implementation: the implementation '" + name + "' for '\"" + mbackends.names() + "\"' is not unique");
unit.getDuplicateDeclarations().add(member);
}
}
} else {
if (member.isNative()) {
List<Declaration> overloads = member.getOverloads();
if (isHeader && member.isNativeHeader()) {
that.addError("duplicate native header: the header for '" + name + "' is not unique");
unit.getDuplicateDeclarations().add(member);
} else {
Declaration overload = findOverloadForBackend(mbackends, model, overloads);
if (overload != null) {
that.addError("duplicate native implementation: the implementation '" + name + "' for '\"" + mbackends.names() + "\"' is not unique");
unit.getDuplicateDeclarations().add(overload);
}
}
if (isAllowedToChangeModel(member) && !hasModelInOverloads(model, overloads)) {
overloads.add(model);
if (that instanceof Tree.ObjectDefinition) {
Tree.ObjectDefinition od = (Tree.ObjectDefinition) that;
Declaration objImplCls = od.getAnonymousClass();
Value value = (Value) member;
Class objHdrCls = (Class) value.getType().getDeclaration();
objHdrCls.getOverloads().add(objImplCls);
} else if (that instanceof Tree.Constructor) {
Tree.Constructor c = (Tree.Constructor) that;
Declaration cd = c.getConstructor();
FunctionOrValue fov = (FunctionOrValue) member;
Constructor hdr = (Constructor) fov.getType().getDeclaration();
hdr.getOverloads().add(cd);
}
}
} else {
if (isHeader) {
that.addError("native header for non-native declaration: '" + name + "' is not declared native");
} else {
that.addError("native implementation for non-native header: '" + name + "' is not declared native");
}
}
}
} else if (!(model instanceof Setter) && !isHeader) {
if (!canBeNative) {
that.addError("native declaration is not a class, constructor, method, attribute or object: '" + name + "' may not be annotated 'native'");
}
}
}
}
Aggregations