use of org.eclipse.ceylon.model.typechecker.model.Constructor in project ceylon by eclipse.
the class SpecificationVisitor method visit.
@Override
public void visit(Tree.Enumerated that) {
Value v = that.getDeclarationModel();
Constructor e = that.getEnumerated();
if (v == declaration || e == declaration) {
declare();
specify();
}
super.visit(that);
if (declaration.getContainer() == e.getContainer() && that == lastConstructor && initedByEveryConstructor) {
definitely = true;
}
}
use of org.eclipse.ceylon.model.typechecker.model.Constructor in project ceylon by eclipse.
the class SpecificationVisitor method visit.
@Override
public void visit(Tree.Declaration that) {
boolean oe = endsInReturnThrow;
boolean of = endsInBreak;
Tree.Continue olc = lastContinue;
lastContinue = null;
endsInReturnThrow = false;
endsInBreak = false;
if (isSameDeclaration(that)) {
loopDepth = 0;
brokenLoopDepth = 0;
specificationDisabled = true;
withinDeclaration = true;
declare();
super.visit(that);
withinDeclaration = false;
specificationDisabled = false;
loopDepth = 0;
brokenLoopDepth = 0;
} else {
int l = loopDepth;
int bl = brokenLoopDepth;
loopDepth = 0;
brokenLoopDepth = 0;
Scope scope = that.getScope();
boolean constructor = scope instanceof Constructor;
boolean valueWithInitializer = scope instanceof Value && !((Value) scope).isTransient();
boolean c = false;
if (!constructor) {
c = specificationDisabled;
specificationDisabled = true;
}
boolean d = declared;
if (valueWithInitializer) {
super.visit(that);
} else {
boolean odefinitely = definitely;
boolean opossibly = possibly;
boolean opossiblyExited = possiblyExited;
boolean odefinitelyExited = definitelyExited;
boolean odefinitelyByLoopBreaks = definitelyByLoopBreaks;
boolean opossiblyByLoopBreaks = possiblyByLoopBreaks;
beginSpecificationScope();
super.visit(that);
definitely = odefinitely;
possibly = opossibly;
possiblyExited = opossiblyExited;
definitelyExited = odefinitelyExited;
definitelyByLoopBreaks = odefinitelyByLoopBreaks;
possiblyByLoopBreaks = opossiblyByLoopBreaks;
}
declared = d;
if (!constructor) {
specificationDisabled = c;
}
loopDepth = l;
brokenLoopDepth = bl;
}
endsInReturnThrow = oe;
endsInBreak = of;
lastContinue = olc;
}
use of org.eclipse.ceylon.model.typechecker.model.Constructor in project ceylon by eclipse.
the class SpecificationVisitor method visit.
@Override
public void visit(Tree.Block that) {
Scope scope = that.getScope();
if (scope instanceof Constructor) {
if (definitelyInitedBy.contains(delegatedConstructor)) {
definitely = true;
}
if (possiblyInitedBy.contains(delegatedConstructor)) {
possibly = true;
}
delegatedConstructor = null;
}
boolean of = endsInBreak;
boolean oe = endsInReturnThrow;
Tree.Continue olc = lastContinue;
Tree.Statement olcs = lastContinueStatement;
// rather nasty way of detecting that the continue
// occurs in another conditional branch of the
// statement containing this block, even though we
// did not find it in _this_ branch
boolean continueInSomeBranchOfCurrentConditional = lastContinue != null && lastContinueStatement == null;
boolean blockEndsInReturnThrow = blockEndsInReturnThrow(that);
boolean blockEndsInBreak = blockEndsInBreak(that);
endsInBreak = endsInBreak || blockEndsInBreak;
endsInReturnThrow = endsInReturnThrow || blockEndsInReturnThrow;
Tree.Continue last = null;
Tree.Statement lastStatement = null;
for (Tree.Statement st : that.getStatements()) {
ContinueVisitor cv = new ContinueVisitor(olc);
st.visit(cv);
if (cv.node != null) {
last = cv.node;
lastStatement = st;
}
if (cv.found) {
olc = null;
olcs = null;
}
}
if (blockEndsInReturnThrow || blockEndsInBreak || continueInSomeBranchOfCurrentConditional) {
lastContinue = last;
lastContinueStatement = lastStatement;
}
super.visit(that);
endsInBreak = of;
endsInReturnThrow = oe;
lastContinue = olc;
lastContinueStatement = olcs;
if (scope instanceof Constructor) {
Constructor c = (Constructor) scope;
if (definitely) {
definitelyInitedBy.add(c);
}
if (possibly) {
possiblyInitedBy.add(c);
}
}
if (isNonPartialConstructor(scope) && declaration.getContainer() == scope.getContainer()) {
if (!definitely) {
initedByEveryConstructor = false;
}
}
}
use of org.eclipse.ceylon.model.typechecker.model.Constructor 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) + "'");
}
}
}
use of org.eclipse.ceylon.model.typechecker.model.Constructor in project ceylon by eclipse.
the class InheritanceVisitor method collectCaseValues.
void collectCaseValues(Tree.CaseTypes that, TypeDeclaration td) {
Unit unit = that.getUnit();
Set<Declaration> valueSet = new HashSet<Declaration>();
for (Tree.StaticMemberOrTypeExpression bme : that.getBaseMemberExpressions()) {
String name = name(bme.getIdentifier());
TypedDeclaration value = bme instanceof Tree.BaseMemberExpression ? getTypedDeclaration(bme.getScope(), name, null, false, unit) : getPackageTypedDeclaration(name, null, false, unit);
if (value != null) {
if (value != null && !valueSet.add(value)) {
// this error is not really truly necessary
bme.addError("duplicate case: '" + value.getName(unit) + "' of '" + td.getName() + "'");
}
Type type = value.getType();
if (type != null) {
TypeDeclaration caseDec = type.getDeclaration();
if (caseDec instanceof Constructor) {
Scope scope = caseDec.getContainer();
if (scope instanceof Class) {
// enumerated singleton constructors
Constructor cons = (Constructor) caseDec;
Class c = (Class) scope;
if (!c.isToplevel() && !c.isStatic()) {
bme.addError("case must be a value constructor of a toplevel or static class: '" + c.getName(unit) + "' is not toplevel");
} else if (!cons.getParameterLists().isEmpty()) {
bme.addError("case must be a value constructor of a toplevel or static class: '" + cons.getName(unit) + "' is not a value constructor");
}
/*else if (!c.inherits(unit.getIdentifiableDeclaration())) {
bme.addError("case must be a value constructor of an identifiable class: '" +
c.getName(unit) +
"' is not a subtype of 'Identifiable'");
}*/
}
} else {
// enumerated anonymous subclasses
if (!caseDec.isObjectClass()) {
bme.addError("case must be a toplevel or static anonymous class: '" + value.getName(unit) + "' is not an anonymous class");
} else if (!value.isToplevel() && !value.isStatic()) {
bme.addError("case must be a toplevel or static anonymous class: '" + value.getName(unit) + "' is neither static nor toplevel");
}
}
if (checkDirectSubtype(td, bme, type)) {
checkAssignable(type, td.getType(), bme, getCaseTypeExplanation(td, type));
}
}
}
}
}
Aggregations