Esempio n. 1
0
        private void replaceCref(Element element, bool exception, Iterable <MemberInfo> members, String suffix, String arguments)
        {
            if (members.count() > 1 && !members.all(p => p.MemberKind == MemberKind.Method))
            {
                context.addWarning(CompileErrorId.UnresolvedCref, node, element.getAttribute("cref"));
                element.setAttribute("cref", "!" + element.getAttribute("cref"));
                return;
            }
            var member = members.first();

            switch (member.MemberKind)
            {
            case Type:
                replaceCref(element, exception, member.Type, suffix, arguments);
                break;

            case Field:
                if (exception)
                {
                    context.addWarning(CompileErrorId.ExpectedExceptionInCref, node, element.getAttribute("cref"));
                    element.setAttribute("cref", "!" + element.getAttribute("cref"));
                    return;
                }
                if (suffix != null || arguments != null)
                {
                    context.addWarning(CompileErrorId.UnresolvedCref, node, element.getAttribute("cref"));
                    element.setAttribute("cref", "!" + element.getAttribute("cref"));
                    return;
                }
                element.setAttribute("cref", getIdString(member.Field));
                break;

            case Property:
                if (exception)
                {
                    context.addWarning(CompileErrorId.ExpectedExceptionInCref, node, element.getAttribute("cref"));
                    element.setAttribute("cref", "!" + element.getAttribute("cref"));
                    return;
                }
                if (suffix != null || arguments != null)
                {
                    context.addWarning(CompileErrorId.UnresolvedCref, node, element.getAttribute("cref"));
                    element.setAttribute("cref", "!" + element.getAttribute("cref"));
                    return;
                }
                element.setAttribute("cref", getIdString(member.GetAccessor ?? member.SetAccessor));
                break;

            case Method:
                if (!exception && suffix == null)
                {
                    if (arguments == null && members.count() == 1)
                    {
                        element.setAttribute("cref", getIdString(member.Method));
                        return;
                    }
                    else if (arguments != null && arguments.endsWith(")"))
                    {
                        var args = new ArrayList <TypeInfo>();
                        if (arguments.length() > 2)
                        {
                            arguments = arguments.substring(1, arguments.length() - 1);
                            int idx;
                            while ((idx = arguments.indexOf(',')) != -1)
                            {
                                var name = arguments.substring(0, idx);
                                arguments = arguments.substring(idx + 1);
                                var type = getType(name);
                                if (type == null)
                                {
                                    goto failed;
                                }
                                args.add(type);
                            }
                            if (arguments.length() == 0)
                            {
                                goto failed;
                            }
                            var type = getType(arguments);
                            if (type == null)
                            {
                                goto failed;
                            }
                            args.add(type);
                        }
                        foreach (var m in members)
                        {
                            if (m.Method.Parameters.select(p => p.Type).sequenceEqual(args))
                            {
                                element.setAttribute("cref", getIdString(m.Method));
                                return;
                            }
                        }
                    }
                }
failed:
                context.addWarning(CompileErrorId.UnresolvedCref, node, element.getAttribute("cref"));
                element.setAttribute("cref", "!" + element.getAttribute("cref"));
                break;

            default:
                break;
            }
        }
	bool method(Iterable<string> si) {
		return si.all(s => strings.contains(s));
	}
 private void replaceCref(Element element, bool exception, Iterable<MemberInfo> members, String suffix, String arguments) {
     if (members.count() > 1 && !members.all(p => p.MemberKind == MemberKind.Method)) {
         context.addWarning(CompileErrorId.UnresolvedCref, node, element.getAttribute("cref"));
         element.setAttribute("cref", "!" + element.getAttribute("cref"));
         return;
     }
     var member = members.first();
     switch (member.MemberKind) {
     case Type:
         replaceCref(element, exception, member.Type, suffix, arguments);
         break;
     case Field:
         if (exception) {
             context.addWarning(CompileErrorId.ExpectedExceptionInCref, node, element.getAttribute("cref"));
             element.setAttribute("cref", "!" + element.getAttribute("cref"));
             return;
         }
         if (suffix != null || arguments != null) {
             context.addWarning(CompileErrorId.UnresolvedCref, node, element.getAttribute("cref"));
             element.setAttribute("cref", "!" + element.getAttribute("cref"));
             return;
         }
         element.setAttribute("cref", getIdString(member.Field));
         break;
     
     case Property:
         if (exception) {
             context.addWarning(CompileErrorId.ExpectedExceptionInCref, node, element.getAttribute("cref"));
             element.setAttribute("cref", "!" + element.getAttribute("cref"));
             return;
         }
         if (suffix != null || arguments != null) {
             context.addWarning(CompileErrorId.UnresolvedCref, node, element.getAttribute("cref"));
             element.setAttribute("cref", "!" + element.getAttribute("cref"));
             return;
         }
         element.setAttribute("cref", getIdString(member.GetAccessor ?? member.SetAccessor));
         break;
     
     case Method:
         if (!exception && suffix == null) {
             if (arguments == null && members.count() == 1) {
                 element.setAttribute("cref", getIdString(member.Method));
                 return;
             } else if (arguments != null && arguments.endsWith(")")) {
                 var args = new ArrayList<TypeInfo>();
                 if (arguments.length() > 2) {
                     arguments = arguments.substring(1, arguments.length() - 1);
                     int idx;
                     while ((idx = arguments.indexOf(',')) != -1) {
                         var name = arguments.substring(0, idx);
                         arguments = arguments.substring(idx + 1);
                         var type = getType(name);
                         if (type == null) {
                             goto failed;
                         }
                         args.add(type);
                     }
                     if (arguments.length() == 0) {
                         goto failed;
                     }
                     var type = getType(arguments);
                     if (type == null) {
                         goto failed;
                     }
                     args.add(type);
                 }
                 foreach (var m in members) {
                     if (m.Method.Parameters.select(p => p.Type).sequenceEqual(args)) {
                         element.setAttribute("cref", getIdString(m.Method));
                         return;
                     }
                 }
             }
         }
     failed:
         context.addWarning(CompileErrorId.UnresolvedCref, node, element.getAttribute("cref"));
         element.setAttribute("cref", "!" + element.getAttribute("cref"));
         break;
         
     default:
         break;
     }
 }
 bool method(Iterable <string> si)
 {
     return(si.all(s => strings.contains(s)));
 }