use of ceylon.language.AssertionError in project ceylon by eclipse.
the class ClassOrInterfaceImpl method lookupMember.
@SuppressWarnings("unchecked")
private <T extends NestableDeclarationImpl, Container> MemberLookup<T, Container> lookupMember(@Ignore TypeDescriptor $reifiedT, @Ignore TypeDescriptor $reifiedContainer, org.eclipse.ceylon.model.typechecker.model.Type reifiedContainer, T value) {
ClassOrInterfaceImpl<Container> containerMetamodel;
org.eclipse.ceylon.model.typechecker.model.Type qualifyingType;
if ($reifiedContainer == TypeDescriptor.NothingType) {
// wildcard: everything goes
qualifyingType = this.producedType.getSupertype((TypeDeclaration) value.declaration.getContainer());
} else {
// get the declaration as seen from the container
Declaration memberInContainer = reifiedContainer.getDeclaration().getMember(value.getName(), null, false);
// cheaper this way than through reflection type checks
if ($reifiedT == ValueDeclarationImpl.$TypeDescriptor$) {
if (memberInContainer instanceof org.eclipse.ceylon.model.typechecker.model.Value == false)
return null;
} else if ($reifiedT == FunctionDeclarationImpl.$TypeDescriptor$) {
if (memberInContainer instanceof org.eclipse.ceylon.model.typechecker.model.Function == false)
return null;
} else if ($reifiedT == InterfaceDeclarationImpl.$TypeDescriptor$) {
if (memberInContainer instanceof org.eclipse.ceylon.model.typechecker.model.Interface == false)
return null;
} else if ($reifiedT == ClassDeclarationImpl.$TypeDescriptor$) {
if (memberInContainer instanceof org.eclipse.ceylon.model.typechecker.model.Class == false)
return null;
} else if ($reifiedT == ClassOrInterfaceDeclarationImpl.$TypeDescriptor$) {
if (memberInContainer instanceof org.eclipse.ceylon.model.typechecker.model.ClassOrInterface == false)
return null;
} else {
throw new AssertionError("Member type not supported: " + $reifiedT);
}
// get the right container type
qualifyingType = reifiedContainer.getSupertype((TypeDeclaration) memberInContainer.getContainer());
}
if (qualifyingType == null)
throw new AssertionError("Could not find qualifying type for reifiedContainer: " + $reifiedContainer);
// now get the right metamodel for the qualifying type
containerMetamodel = (ClassOrInterfaceImpl<Container>) Metamodel.getAppliedMetamodel(qualifyingType);
if (containerMetamodel == null)
throw new AssertionError("Could not find metamodel for qualifying type: " + qualifyingType);
// we already have the right member for the wildcard
if ($reifiedContainer != TypeDescriptor.NothingType) {
// now get the right member
value = ((ClassOrInterfaceDeclarationImpl) containerMetamodel.getDeclaration()).findDeclaredDeclaration($reifiedT, value.getName());
}
return new MemberLookup<T, Container>($reifiedT, $reifiedContainer, value, qualifyingType, containerMetamodel);
}
use of ceylon.language.AssertionError in project ceylon by eclipse.
the class ClassOrInterfaceImpl method getCaseValues.
@Override
@TypeInfo("ceylon.language::Sequential<Type>")
public ceylon.language.Sequential<? extends Type> getCaseValues() {
if (!((ClassOrInterface) declaration.declaration).isAbstract()) {
// optimization: a concrete class cannot have cases
return (Sequential) empty_.get_();
}
Sequential<? extends ceylon.language.meta.declaration.OpenType> caseTypeDeclarations = getDeclaration().getCaseTypes();
Iterator<? extends ceylon.language.meta.declaration.OpenType> iterator = caseTypeDeclarations.iterator();
Object it;
Array<Type> ret = new Array<Type>($reifiedType, (int) caseTypeDeclarations.getSize(), (Type) null);
int count = 0;
while ((it = iterator.next()) != finished_.get_()) {
if (it instanceof ceylon.language.meta.declaration.OpenClassType == false)
continue;
ceylon.language.meta.declaration.OpenClassType caseClassType = (ceylon.language.meta.declaration.OpenClassType) it;
ceylon.language.meta.declaration.ClassDeclaration caseClass = caseClassType.getDeclaration();
if (!caseClass.getAnonymous())
continue;
Type value = null;
Object container = caseClass.getContainer();
while (true) {
if (container instanceof ceylon.language.meta.declaration.Package) {
ValueDeclaration valueDeclaration = ((ceylon.language.meta.declaration.Package) container).getValue(caseClass.getName());
ceylon.language.meta.model.Value<? extends Type, ? super Object> valueModel = valueDeclaration.<Type, Object>apply($reifiedType, TypeDescriptor.NothingType);
value = valueModel.get();
break;
} else {
if (container instanceof ClassOrInterfaceDeclaration) {
ValueDeclaration valueDeclaration = ((ClassOrInterfaceDeclaration) container).getMemberDeclaration(ValueDeclaration.$TypeDescriptor$, caseClass.getName());
Attribute a = valueDeclaration.memberApply($reifiedType, $reifiedType, Nothing.NothingType, this);
value = (Type) a.bind(null).get();
}
// other nestable decls can't contain members, so keep looking up scopes
container = ((NestableDeclaration) container).getContainer();
}
if (value != null) {
break;
}
}
if (value == null && !producedType.isNull()) {
throw new AssertionError("case " + caseClassType + " of " + this + " not found");
}
ret.set(count++, value);
}
return ret.take(count).sequence();
}
use of ceylon.language.AssertionError in project ceylon by eclipse.
the class PartialImpl method initializeObject.
protected <Id> void initializeObject(TypeDescriptor $reified$Id, DeserializationContextImpl<Id> context, Serializable instance) {
NativeMap<ReachableReference, Id> state = (NativeMap<ReachableReference, Id>) getState();
// TODO If it were a map of java.lang.String we'd avoid pointless extra boxing
java.util.Collection<ReachableReference> reachables = instance.$references$();
int numLate = 0;
for (ReachableReference r : reachables) {
if (r instanceof Member && ((Member) r).getAttribute().getLate()) {
numLate++;
} else if (r instanceof Outer) {
numLate++;
}
}
if (state.getSize() < reachables.size() - numLate) {
HashSet<ReachableReference> missingNames = new HashSet<ReachableReference>();
java.util.Iterator<ReachableReference> it = reachables.iterator();
while (it.hasNext()) {
missingNames.add(it.next());
}
ceylon.language.Iterator<? extends ReachableReference> it2 = state.getKeys().iterator();
Object next;
while (((next = it2.next()) instanceof ReachableReference)) {
missingNames.remove(next);
}
throw insufficiantState(missingNames);
}
for (ReachableReference reference : reachables) {
if (reference instanceof Member) {
Member member = (Member) reference;
if (member.getAttribute().getLate() && !state.contains(member) || state.get(member) == uninitializedLateValue_.get_()) {
continue;
}
TypeDescriptor.Class classTypeDescriptor = getClassTypeDescriptor();
Entry<TypeDescriptor.Class, String> cacheKey = new Entry<TypeDescriptor.Class, String>(TypeDescriptor.klass(TypeDescriptor.Class.class), String.$TypeDescriptor$, classTypeDescriptor, String.instance(member.getAttribute().getQualifiedName()));
Type memberType = (Type) context.getMemberTypeCache().get(cacheKey);
if (memberType == null) {
Type pt = Metamodel.getModuleManager().getCachedType(classTypeDescriptor);
while (!pt.getDeclaration().getQualifiedNameString().equals(((ClassDeclaration) member.getAttribute().getContainer()).getQualifiedName())) {
pt = pt.getExtendedType();
}
FunctionOrValue attributeDeclaration = (FunctionOrValue) ((TypeDeclaration) pt.getDeclaration()).getMember(member.getAttribute().getName(), null, false);
TypedReference attributeType = pt.getTypedMember(attributeDeclaration, Collections.<Type>emptyList(), true);
memberType = attributeType.getType();
context.getMemberTypeCache().put(cacheKey, memberType);
}
Object referredInstance = getReferredInstance(context, state, member);
if (referredInstance instanceof Tuple) {
// Because tuples are special wrt reified types...
Id referredId = state.get(member);
Object r = context.leakInstance(referredId);
if (r instanceof PartialImpl) {
((PartialImpl) r).initialize($reified$Id, context);
}
}
Type instanceType = Metamodel.getModuleManager().getCachedType(Metamodel.getTypeDescriptor(referredInstance));
if (!instanceType.isSubtypeOf(memberType)) {
throw notAssignable(member, memberType, instanceType);
}
instance.$set$(member, referredInstance);
// the JVM will check the assignability, but we need to
// check assignability at the ceylon level, so we need to know
// / type of the attribute an the type that we're assigning.
// XXX this check is really expensive!
// we should cache the attribute type on the context
// when can we avoid this check.
// XXX we can cache MethodHandle setters on the context!
} else if (reference instanceof Outer) {
// instantiating member classes
continue;
} else {
throw new AssertionError("unexpected ReachableReference " + reference);
}
}
}
use of ceylon.language.AssertionError in project ceylon by eclipse.
the class Util method sequentialWrapperBoxed.
/**
* <p>Return a {@link Sequential Sequential<Character>} copying the
* given {@code char[]} elements
* (subsequent changes to the array will not be visible in
* the returned {@link Sequential}).</p>
*
* <p>Used to obtain a {@code Sequential<Character>} from a {@code char[]}.</p>
*/
@SuppressWarnings({ "unchecked", "rawtypes" })
public static Sequential<? extends ceylon.language.Character> sequentialWrapperBoxed(char[] elements) {
if (elements.length == 0) {
return (Sequential) empty_.get_();
}
int total = Character.codePointCount(elements, 0, elements.length);
java.lang.Object[] newArray = new java.lang.Object[total];
int i = 0;
char lastHighSurrogate = 0;
for (char element : elements) {
if (lastHighSurrogate != 0) {
if (Character.isLowSurrogate(element)) {
newArray[i++] = ceylon.language.Character.instance(Character.toCodePoint(lastHighSurrogate, element));
lastHighSurrogate = 0;
} else {
throw new AssertionError("Illegal low surrogate value " + element + " after high surrogate value " + lastHighSurrogate);
}
} else if (Character.isHighSurrogate(element)) {
lastHighSurrogate = element;
} else if (Character.isLowSurrogate(element)) {
throw new AssertionError("Illegal low surrogate value " + element + " after no high surrogate value");
} else {
newArray[i++] = ceylon.language.Character.instance(element);
}
}
if (lastHighSurrogate != 0)
throw new AssertionError("Missing low surrogate value after high surrogate value " + lastHighSurrogate);
return new Tuple(ceylon.language.Character.$TypeDescriptor$, newArray);
}
use of ceylon.language.AssertionError in project ceylon by eclipse.
the class TypeDescriptor method intersection.
public static TypeDescriptor intersection(TypeDescriptor... members) {
if (members == null || members.length == 0)
throw new AssertionError("members can't be null or empty");
members = flattenUnionOrIntersection(members, false);
TypeDescriptor single = getSingleTypeDescriptorIfUnique(members);
if (single != null)
return single;
members = removeDuplicates(members);
return new Intersection(members);
}
Aggregations