public IType checkAttribute(Context context, CategoryDeclaration decl, String name) { if (decl.Storable && "dbId" == name) { return(AnyType.Instance); } else if (decl.hasAttribute(context, name)) { AttributeDeclaration ad = context.getRegisteredDeclaration <AttributeDeclaration>(name); if (ad == null) { throw new SyntaxError("Unknown atttribute:" + name); } else { return(ad.GetIType(context)); } } else if ("text" == name) { return(TextType.Instance); } else if (decl.hasMethod(context, name)) { IMethodDeclaration method = decl.getMemberMethods(context, name).GetFirst(); return(new MethodType(method)); } else { throw new SyntaxError("No attribute:" + name + " in category:" + GetTypeName()); } }
public bool isDerivedFromAnonymous(Context context, CategoryDeclaration thisDecl, CategoryDeclaration otherDecl) { // an anonymous category extends 1 and only 1 category String baseName = otherDecl.getDerivedFrom()[0]; // check we derive from root category (if not extending 'any') if (!"any".Equals(baseName) && !thisDecl.isDerivedFrom(context, new CategoryType(baseName))) { return(false); } foreach (String attribute in otherDecl.GetAllAttributes(context)) { if (!thisDecl.hasAttribute(context, attribute)) { return(false); } } return(true); }
public override Comparer <IValue> getComparer(Context context, IExpression key, bool descending) { if (key == null) { key = new UnresolvedIdentifier("key", Dialect.E); } IDeclaration d = getDeclaration(context); if (d is CategoryDeclaration) { CategoryDeclaration decl = (CategoryDeclaration)d; if (decl.hasAttribute(context, key.ToString())) { return(new AttributeComparer(context, key.ToString(), descending)); } else if (decl.hasMethod(context, key.ToString())) { return(new CategoryMethodComparer(context, key.ToString(), descending)); } else if (globalMethodExists(context, key.ToString())) // TODO support 2 args { return(new GlobalMethodComparer(context, key.ToString(), descending, this)); } else if (key is ArrowExpression) { return(((ArrowExpression)key).GetComparer(context, this, descending)); } else { return(new ExpressionComparer(context, key, descending)); } } else { throw new Exception("Unsupported!"); } }