private void validateTypeparam(Element typeparam) { if (memberKind == MemberKind.Type) { var name = typeparam.getAttribute("name"); if (!type.GenericArguments.any(p => p.FullName.equals(name))) { context.addWarning(CompileErrorId.InvalidTypeparamNameAttribute, node, name); } } else if (memberKind == MemberKind.Method) { var name = typeparam.getAttribute("name"); if (Helper.isNullOrEmpty(name)) { context.addWarning(CompileErrorId.MissingDocAttribute, node, "name", typeparam.getLocalName()); } else if (!method.GenericArguments.any(p => p.FullName.equals(name))) { context.addWarning(CompileErrorId.InvalidTypeparamNameAttribute, node, name); } } else { context.addWarning(CompileErrorId.InvalidTypeparamElement, node); } }
private void include(Element include, Element parent, bool nested) { var dir = PathHelper.getDirectoryName(node.Filename); var file = include.getAttribute("file"); if (Helper.isNullOrEmpty(file)) { context.addWarning(CompileErrorId.MissingDocAttribute, node, "file", "include"); parent.appendChild(document.importNode(include, true)); return; } var path = include.getAttribute("path"); if (Helper.isNullOrEmpty(file)) { context.addWarning(CompileErrorId.MissingDocAttribute, node, "path", "include"); parent.appendChild(document.importNode(include, true)); return; } var filename = PathHelper.combine(dir, include.getAttribute("file")); var includeFile = new File(filename); try { var doc = XmlHelper.load(new FileInputStream(includeFile)); var nodeList = doc.getNodeList(path); for (int i = 0; i < nodeList.getLength(); i++) { var node = nodeList.item(i); if (node.getNodeType() == Node.ELEMENT_NODE) { if (nested) { copyNestedElement((Element)node, parent); } else { copyTopLevelElement((Element)node, parent); } } else { parent.appendChild(document.importNode(include, true)); } } } catch (XPathExpressionException) { context.addWarning(CompileErrorId.IncludePathInvalid, node, path); parent.appendChild(document.importNode(include, true)); } catch (org.xml.sax.SAXException) { context.addWarning(CompileErrorId.IncludeFileInvalid, node, filename); parent.appendChild(document.importNode(include, true)); } catch (IOException) { context.addWarning(CompileErrorId.IncludeFileNotFound, node, filename); parent.appendChild(document.importNode(include, true)); } }
static java.util.Properties loadFilePrefsImpl(java.io.File file) { Properties result = new Properties(); if (!file.exists()) { file.getParentFile().mkdirs(); return(result); } if (file.canRead()) { java.io.InputStream inJ = null; java.nio.channels.FileLock lockJ = null; try { java.io.FileInputStream istream = new java.io.FileInputStream(file); inJ = new java.io.BufferedInputStream(istream); java.nio.channels.FileChannel channel = istream.getChannel(); lockJ = channel.lockJ(0L, java.lang.Long.MAX_VALUE, true); org.w3c.dom.Document doc = builder.parse(inJ); org.w3c.dom.NodeList entries = org.apache.xpath.XPathAPI.selectNodeList(doc .getDocumentElement(), "entry"); //$NON-NLS-1$ int length = entries.getLength(); for (int i = 0; i < length; i++) { org.w3c.dom.Element node = (org.w3c.dom.Element)entries.item(i); String key = node.getAttribute("key"); //$NON-NLS-1$ String value = node.getAttribute("value"); //$NON-NLS-1$ result.setProperty(key, value); } return(result); } catch (java.io.IOException e) { } catch (org.xml.sax.SAXException e) { } catch (javax.xml.transform.TransformerException e) { // transform shouldn't fail for xpath call throw new java.lang.AssertionError(e); } finally { releaseQuietly(lockJ); closeQuietly(inJ); } } else { file.delete(); } return(result); }
private void replaceCref(Element element, bool exception, TypeInfo type, String suffix, String arguments) { if (suffix == null) { if (arguments != null) { context.addWarning(CompileErrorId.UnresolvedCref, node, element.getAttribute("cref")); element.setAttribute("cref", "!" + element.getAttribute("cref")); return; } if (exception) { if (!context.TypeSystem.getType("java/lang/Throwable").isAssignableFrom(type)) { context.addWarning(CompileErrorId.ExpectedExceptionInCref, node, element.getAttribute("cref")); element.setAttribute("cref", "!" + element.getAttribute("cref")); return; } } element.setAttribute("cref", getIdString(type)); } else { int idx = suffix.indexOf('.'); String name; if (idx == -1) { name = suffix; suffix = null; } else { name = suffix.substring(0, idx); suffix = suffix.substring(idx + 1); } var members = MemberInfo.getMembers(context.AnnotatedTypeSystem, context.CurrentType, type, name, true); replaceCref(element, exception, members, suffix, arguments); } }
private static void loadNode(Preferences prefs, org.w3c.dom.Element node) { //throws TransformerException { // load preferences org.w3c.dom.NodeList children = org.apache.xpath.XPathAPI.selectNodeList(node, "node"); //$NON-NLS-1$ org.w3c.dom.NodeList entries = org.apache.xpath.XPathAPI.selectNodeList(node, "map/entry"); //$NON-NLS-1$ int childNumber = children.getLength(); Preferences[] prefChildren = new Preferences[childNumber]; int entryNumber = entries.getLength(); lock (((AbstractPreferences)prefs).lockJ) { if (((AbstractPreferences)prefs).isRemoved()) { return; } for (int i = 0; i < entryNumber; i++) { org.w3c.dom.Element entry = (org.w3c.dom.Element)entries.item(i); String key = entry.getAttribute("key"); //$NON-NLS-1$ String value = entry.getAttribute("value"); //$NON-NLS-1$ prefs.put(key, value); } // get children preferences node for (int i = 0; i < childNumber; i++) { org.w3c.dom.Element child = (org.w3c.dom.Element)children.item(i); String name = child.getAttribute("name"); //$NON-NLS-1$ prefChildren [i] = prefs.node(name); } } // load children nodes after unlock for (int i = 0; i < childNumber; i++) { loadNode(prefChildren [i], (org.w3c.dom.Element)children.item(i)); } }
private void validateParam(Element param) { if (memberKind != MemberKind.Method && memberKind != MemberKind.Indexer) { context.addWarning(CompileErrorId.InvalidParamElement, node); } else { var name = param.getAttribute("name"); if (Helper.isNullOrEmpty(name)) { context.addWarning(CompileErrorId.MissingDocAttribute, node, "name", param.getLocalName()); } else if (!method.Parameters.any(p => p.Name.equals(name))) { context.addWarning(CompileErrorId.InvalidParamNameAttribute, node, name); } } }
/* * Utilities for Preferences import */ internal static void importPrefs(java.io.InputStream inJ) //throws IOException, { //InvalidPreferencesFormatException { try { // load XML document org.w3c.dom.Document doc = builder.parse(new org.xml.sax.InputSource(inJ)); // check preferences' export version org.w3c.dom.Element preferences; preferences = doc.getDocumentElement(); String version = preferences.getAttribute("EXTERNAL_XML_VERSION"); //$NON-NLS-1$ if (version != null && java.lang.Float.parseFloat(version) > XML_VERSION) { // prefs.2=This preferences exported version is not // supported:{0} throw new java.util.prefs.InvalidPreferencesFormatException("his preferences exported version is not supported:" + version); //$NON-NLS-1$ } // check preferences root's type org.w3c.dom.Element root = (org.w3c.dom.Element)preferences .getElementsByTagName("root").item(0); //$NON-NLS-1$ Preferences prefsRoot = null; String type = root.getAttribute("type"); //$NON-NLS-1$ if (type.equals("user")) //$NON-NLS-1$ { prefsRoot = Preferences.userRoot(); } else { prefsRoot = Preferences.systemRoot(); } // load node loadNode(prefsRoot, root); } catch (javax.xml.parsers.FactoryConfigurationError e) { throw new InvalidPreferencesFormatException(e); } catch (org.xml.sax.SAXException e) { throw new InvalidPreferencesFormatException(e); } catch (javax.xml.transform.TransformerException e) { throw new InvalidPreferencesFormatException(e); } }
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; } }
private void replaceCref(Element element, bool exception) { var cref = element.getAttribute("cref"); if (Helper.isNullOrEmpty(cref)) { context.addWarning(CompileErrorId.MissingDocAttribute, node, "cref", element.getLocalName()); } else { if (cref.length() > 1 && cref[1] == ':') { return; } String arguments = null; int idx = cref.indexOf('('); if (idx != -1) { arguments = cref.substring(idx); cref = cref.substring(0, idx); } idx = cref.indexOf('.'); String name; if (idx == -1) { name = cref; cref = null; } else { name = cref.substring(0, idx); cref = cref.substring(idx + 1); } var members = context.MemberResolver.resolveName(context.CurrentType, name, Query.empty <TypeInfo>()).toList(); if (!members.any()) { if (cref == null) { context.addWarning(CompileErrorId.UnresolvedCref, node, element.getAttribute("cref")); element.setAttribute("cref", "!" + element.getAttribute("cref")); return; } var packageName = context.MemberResolver.getPackageFromAlias(name); if (packageName == null) { if (context.MemberResolver.TypeFinder.getSubPackages(name).any() || context.MemberResolver.TypeFinder.getClasses(name).any()) { packageName = name; } else { context.addWarning(CompileErrorId.UnresolvedCref, node, element.getAttribute("cref")); element.setAttribute("cref", "!" + element.getAttribute("cref")); return; } } bool found; do { idx = cref.indexOf('.'); if (idx == -1) { name = cref; cref = null; } else { name = cref.substring(0, idx); cref = cref.substring(idx + 1); } found = false; foreach (var s in context.MemberResolver.TypeFinder.getSubPackages(packageName)) { if (s.equals(name)) { packageName = packageName + '/' + name; found = true; break; } } if (!found && !context.MemberResolver.TypeFinder.getClasses(packageName).contains(name)) { context.addWarning(CompileErrorId.UnresolvedCref, node, element.getAttribute("cref")); element.setAttribute("cref", "!" + element.getAttribute("cref")); return; } } while (cref != null && found); var type = context.TypeSystem.getType(packageName + '/' + name); replaceCref(element, exception, type, cref, arguments); } else { replaceCref(element, exception, members, cref, arguments); } } }
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; } }
private void replaceCref(Element element, bool exception) { var cref = element.getAttribute("cref"); if (Helper.isNullOrEmpty(cref)) { context.addWarning(CompileErrorId.MissingDocAttribute, node, "cref", element.getLocalName()); } else { if (cref.length() > 1 && cref[1] == ':') { return; } String arguments = null; int idx = cref.indexOf('('); if (idx != -1) { arguments = cref.substring(idx); cref = cref.substring(0, idx); } idx = cref.indexOf('.'); String name; if (idx == -1) { name = cref; cref = null; } else { name = cref.substring(0, idx); cref = cref.substring(idx + 1); } var members = context.MemberResolver.resolveName(context.CurrentType, name, Query.empty<TypeInfo>()).toList(); if (!members.any()) { if (cref == null) { context.addWarning(CompileErrorId.UnresolvedCref, node, element.getAttribute("cref")); element.setAttribute("cref", "!" + element.getAttribute("cref")); return; } var packageName = context.MemberResolver.getPackageFromAlias(name); if (packageName == null) { if (context.MemberResolver.TypeFinder.getSubPackages(name).any() || context.MemberResolver.TypeFinder.getClasses(name).any()) { packageName = name; } else { context.addWarning(CompileErrorId.UnresolvedCref, node, element.getAttribute("cref")); element.setAttribute("cref", "!" + element.getAttribute("cref")); return; } } bool found; do { idx = cref.indexOf('.'); if (idx == -1) { name = cref; cref = null; } else { name = cref.substring(0, idx); cref = cref.substring(idx + 1); } found = false; foreach (var s in context.MemberResolver.TypeFinder.getSubPackages(packageName)) { if (s.equals(name)) { packageName = packageName + '/' + name; found = true; break; } } if (!found && !context.MemberResolver.TypeFinder.getClasses(packageName).contains(name)) { context.addWarning(CompileErrorId.UnresolvedCref, node, element.getAttribute("cref")); element.setAttribute("cref", "!" + element.getAttribute("cref")); return; } } while (cref != null && found); var type = context.TypeSystem.getType(packageName + '/' + name); replaceCref(element, exception, type, cref, arguments); } else { replaceCref(element, exception, members, cref, arguments); } } }