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 Element copyContainer(Element container) { var result = (Element)document.importNode(container, false); copyNestedElementChildren(result, container); return(result); }
private Element copyException(Element exception) { var result = (Element)document.importNode(exception, true); replaceCref(result, true); copyNestedElementChildren(result, exception); return(result); }
private Element copySeealso(Element seealso) { var result = (Element)document.importNode(seealso, false); replaceCref(result, false); copyNestedElementChildren(result, seealso); return(result); }
private Element copyParamref(Element paramref) { var result = (Element)document.importNode(paramref, false); validateParam(paramref); copyNestedElementChildren(result, paramref); return(result); }
private Element copyTypeparamref(Element typeparamref) { var result = (Element)document.importNode(typeparamref, false); validateTypeparam(typeparamref); copyNestedElementChildren(result, typeparamref); return(result); }
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)); } }
private void copyNestedElementChildren(Element copy, Element nested) { for (var n = nested.getFirstChild(); n != null; n = n.getNextSibling()) { if (n.getNodeType() == Node.ELEMENT_NODE) { copyNestedElement((Element)n, copy); } else { copy.appendChild(document.importNode(n, 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 copyTopLevelElement(Element e, Element parent) { if (e.getNamespaceURI() == null) { switch (e.getLocalName()) { case "summary": case "remarks": case "value": case "returns": case "example": parent.appendChild(copyContainer(e)); break; case "include": include(e, parent, false); break; case "exception": parent.appendChild(copyException(e)); break; case "param": parent.appendChild(copyParam(e)); break; case "typeparam": parent.appendChild(copyTypeparam(e)); break; case "seealso": parent.appendChild(copySeealso(e)); break; case "code": default: parent.appendChild((Element)document.importNode(e, true)); break; } } else { parent.appendChild((Element)document.importNode(e, true)); } }
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); } } }
private void copyNestedElement(Element nested, Element parent) { if (nested.getNamespaceURI() == null) { switch (nested.getLocalName()) { case "c": case "para": case "list": case "listheader": case "item": case "term": case "description": parent.appendChild(copyContainer(nested)); break; case "include": include(nested, parent, true); break; case "see": parent.appendChild(copySee(nested)); break; case "paramref": parent.appendChild(copyParamref(nested)); break; case "typeparamref": parent.appendChild(copyTypeparamref(nested)); break; default: parent.appendChild((Element)document.importNode(nested, true)); break; } } else { parent.appendChild((Element)document.importNode(nested, true)); } }
/** * Registers the element's attribute specified by the namespace URI and * local name to be of type ID. The attribute must have a non-empty value. * * <p>This implementation uses an internal {@link HashMap} to map the * attribute's value to the specified element. * * @param element the element * @param namespaceURI the namespace URI of the attribute (specify * <code>null</code> if not applicable) * @param localName the local name of the attribute * @throws IllegalArgumentException if <code>localName</code> is not an * attribute of the specified element or it does not contain a specific * value * @throws NullPointerException if <code>element</code> or * <code>localName</code> is <code>null</code> * @see #getElementById */ public void setIdAttributeNS(org.w3c.dom.Element element, String namespaceURI, String localName) { if (element == null) { throw new java.lang.NullPointerException("element is null"); } if (localName == null) { throw new java.lang.NullPointerException("localName is null"); } String idValue = element.getAttributeNS(namespaceURI, localName); if (idValue == null || idValue.length() == 0) { throw new java.lang.IllegalArgumentException(localName + " is not an " + "attribute"); } idMap.put(idValue, element); }
/* * 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, 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)); } }
// DocumentCSS public CSSStyleDeclaration getOverrideStyle(Element elt, string pseudoElt) { return(default(CSSStyleDeclaration)); }
DocumentationBuilder(CompilerContext context, Element members) { this.context = context; this.members = members; this.document = members.getOwnerDocument(); }
public void addElement(Element element) {}
public short startElement(Element elementArg) { return(default(short)); }
public void addElement(Element element) { }
public bool drawFocusRing(Element element, float xCaret, float yCaret) { return default(bool); }
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 Element copyException(Element exception) { var result = (Element)document.importNode(exception, true); replaceCref(result, true); copyNestedElementChildren(result, exception); return result; }
private Element copyContainer(Element container) { var result = (Element)document.importNode(container, false); copyNestedElementChildren(result, container); return result; }
public CSSStyleDeclaration getComputedStyle(Element elt, string pseudoElt) { return default(CSSStyleDeclaration); }
private Element copySeealso(Element seealso) { var result = (Element)document.importNode(seealso, false); replaceCref(result, false); copyNestedElementChildren(result, seealso); return result; }
public void setDragImage(Element image, int x, int y) { }
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; } }
public void setDragImage(Element image, int x, int y) {}
public bool drawFocusRing(Element element, float xCaret, float yCaret) { return(default(bool)); }
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); } } }
public bool drawFocusRing(Element element, float xCaret, float yCaret, bool canDrawCustom) { return default(bool); }
public short startElement(Element elementArg) { return default(short); }
public bool drawFocusRing(Element element, float xCaret, float yCaret, bool canDrawCustom) { return(default(bool)); }
public CSSStyleDeclaration getComputedStyle(Element elt, string pseudoElt) { return(default(CSSStyleDeclaration)); }
private Element copyParamref(Element paramref) { var result = (Element)document.importNode(paramref, false); validateParam(paramref); copyNestedElementChildren(result, paramref); return result; }
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 Element copyTypeparamref(Element typeparamref) { var result = (Element)document.importNode(typeparamref, false); validateTypeparam(typeparamref); copyNestedElementChildren(result, typeparamref); return result; }
// DocumentCSS public CSSStyleDeclaration getOverrideStyle(Element elt, string pseudoElt) { return default(CSSStyleDeclaration); }