added help for Smarty commands params into code completion help
authorMartin Fousek <marfous@netbeans.org>
Wed, 09 Jun 2010 17:37:11 +0200
changeset 163261c495c035be2
parent 16325 7aa21f42a190
child 16327 c742b6c9bc54
added help for Smarty commands params into code completion help
php.smarty/manifest.mf
php.smarty/src/org/netbeans/modules/php/smarty/editor/completion/entries/CodeCompletionEntries.java
php.smarty/src/org/netbeans/modules/php/smarty/editor/completion/entries/TplCodeCompletionData.java
php.smarty/src/org/netbeans/modules/php/smarty/editor/completion/entries/defs/variable-modifiers.xml
     1.1 --- a/php.smarty/manifest.mf	Tue Jun 08 15:20:50 2010 +0200
     1.2 +++ b/php.smarty/manifest.mf	Wed Jun 09 17:37:11 2010 +0200
     1.3 @@ -2,5 +2,5 @@
     1.4  OpenIDE-Module: org.netbeans.modules.php.smarty
     1.5  OpenIDE-Module-Layer: org/netbeans/modules/php/smarty/resources/layer.xml
     1.6  OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/php/smarty/resources/Bundle.properties
     1.7 -OpenIDE-Module-Specification-Version: 1.28
     1.8 +OpenIDE-Module-Specification-Version: 1.29
     1.9  
     2.1 --- a/php.smarty/src/org/netbeans/modules/php/smarty/editor/completion/entries/CodeCompletionEntries.java	Tue Jun 08 15:20:50 2010 +0200
     2.2 +++ b/php.smarty/src/org/netbeans/modules/php/smarty/editor/completion/entries/CodeCompletionEntries.java	Wed Jun 09 17:37:11 2010 +0200
     2.3 @@ -36,7 +36,6 @@
     2.4   *
     2.5   * Portions Copyrighted 2010 Sun Microsystems, Inc.
     2.6   */
     2.7 -
     2.8  package org.netbeans.modules.php.smarty.editor.completion.entries;
     2.9  
    2.10  import java.io.IOException;
    2.11 @@ -64,29 +63,83 @@
    2.12      public CodeCompletionEntries() {
    2.13      }
    2.14  
    2.15 -    protected static Collection<EntryMetadata> readAllCodeCompletionEntriesFromXML(InputStream inputStream) throws IOException, ParserConfigurationException, SAXException {
    2.16 -        Collection<EntryMetadata> ccEntries = null;
    2.17 -        if (ccEntries == null) {
    2.18 -            ccEntries = new ArrayList<EntryMetadata>();
    2.19 -            DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
    2.20 -            DocumentBuilder db = dbf.newDocumentBuilder();
    2.21 -            Document doc = db.parse(inputStream);
    2.22 -            doc.getDocumentElement().normalize();
    2.23 +    protected static Collection<EntryMetadata> readAllCodeCompletionEntriesFromXML(InputStream inputStream, String completionType) throws IOException, ParserConfigurationException, SAXException {
    2.24 +        Collection<EntryMetadata> ccEntries = new ArrayList<EntryMetadata>();
    2.25 +        DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
    2.26 +        DocumentBuilder db = dbf.newDocumentBuilder();
    2.27 +        Document doc = db.parse(inputStream);
    2.28 +        doc.getDocumentElement().normalize();
    2.29  
    2.30 -            NodeList allEntriesList = doc.getElementsByTagName("entry");
    2.31 -            for (int i = 0; i < allEntriesList.getLength(); i++) {
    2.32 -                Node ccNode = allEntriesList.item(i);
    2.33 +        NodeList allEntriesList = doc.getElementsByTagName("entry");
    2.34 +        for (int i = 0; i < allEntriesList.getLength(); i++) {
    2.35 +            Node ccNode = allEntriesList.item(i);
    2.36  
    2.37 -                if (ccNode.getNodeType() == Node.ELEMENT_NODE){
    2.38 -                    Element elem = (Element) ccNode;
    2.39 -                    NodeList desc = elem.getElementsByTagName("description");
    2.40 -                    NodeList url = elem.getElementsByTagName("url");
    2.41 -                    ccEntries.add(new CCDataBuiltInFunction(elem.getAttribute("name"), desc.item(0).getTextContent(), url.item(0).getTextContent()));
    2.42 +            if (ccNode.getNodeType() == Node.ELEMENT_NODE) {
    2.43 +                Element elem = (Element) ccNode;
    2.44 +                String desc = elem.getElementsByTagName("description").item(0).getTextContent();
    2.45 +                String url = elem.getElementsByTagName("url").item(0).getTextContent();
    2.46 +                String help = "";
    2.47 +                NodeList attributes = elem.getElementsByTagName("attributes");
    2.48 +                if (completionType.equals("built-in-functions")) {
    2.49 +                    help = generateHelpForBuiltInFunctions(desc, attributes);
    2.50 +                } else {
    2.51 +                    help = generateHelpForVariableModifiers(desc, attributes);
    2.52                  }
    2.53 +                ccEntries.add(new CCDataBuiltInFunction(elem.getAttribute("name"), help, url));
    2.54              }
    2.55          }
    2.56  
    2.57          return ccEntries;
    2.58      }
    2.59 -    
    2.60 +
    2.61 +    private static String generateHelpForBuiltInFunctions(String desc, NodeList attributesRoot) {
    2.62 +        Element parent = (Element) (attributesRoot.item(0));
    2.63 +        if (parent != null) {
    2.64 +            String help = desc + "<br><br><table border=1>"
    2.65 +                    + "<tr style=\"font-weight:bold\"><td>Attribute name</td><td>Type</td><td>Required</td><td>Default</td><td>Description</td></tr>";
    2.66 +            NodeList attributes = parent.getChildNodes();
    2.67 +            for (int i = 0; i < attributes.getLength(); i++) {
    2.68 +                if (attributes.item(i).getNodeType() == Node.ELEMENT_NODE) {
    2.69 +                    Element attribute = (Element) attributes.item(i);
    2.70 +                    help += "<tr><td>" + attribute.getAttribute("name") + "</td>";
    2.71 +                    help += getRestOfAttributeParams(attribute);
    2.72 +                    help += "</tr>";
    2.73 +                }
    2.74 +            }
    2.75 +            help += "</table>";
    2.76 +            return help;
    2.77 +        } else {
    2.78 +            return desc;
    2.79 +        }
    2.80 +    }
    2.81 +
    2.82 +    private static String generateHelpForVariableModifiers(String desc, NodeList attributesRoot) {
    2.83 +        Element parent = (Element) (attributesRoot.item(0));
    2.84 +        if (parent != null) {
    2.85 +            String help = desc + "<br><br><table border=1>"
    2.86 +                    + "<tr style=\"font-weight:bold\"><td>Parameter Position</td><td>Type</td><td>Required</td><td>Default</td><td>Description</td></tr>";
    2.87 +            NodeList attributes = parent.getChildNodes();
    2.88 +            for (int i = 0; i < attributes.getLength(); i++) {
    2.89 +                if (attributes.item(i).getNodeType() == Node.ELEMENT_NODE) {
    2.90 +                    Element attribute = (Element) attributes.item(i);
    2.91 +                    help += "<tr><td>" + attribute.getAttribute("position") + "</td>";
    2.92 +                    help += getRestOfAttributeParams(attribute);
    2.93 +                    help += "</tr>";
    2.94 +                }
    2.95 +            }
    2.96 +            help += "</table>";
    2.97 +            return help;
    2.98 +        } else {
    2.99 +            return desc;
   2.100 +        }
   2.101 +    }
   2.102 +
   2.103 +    private static String getRestOfAttributeParams(Element attributeParams) {
   2.104 +        String help = "";
   2.105 +        help += "<td>" + attributeParams.getElementsByTagName("type").item(0).getTextContent() + "</td>";
   2.106 +        help += "<td>" + attributeParams.getElementsByTagName("required").item(0).getTextContent() + "</td>";
   2.107 +        help += "<td>" + attributeParams.getElementsByTagName("default").item(0).getTextContent() + "</td>";
   2.108 +        help += "<td>" + attributeParams.getElementsByTagName("description").item(0).getTextContent() + "</td>";
   2.109 +        return help;
   2.110 +    }
   2.111  }
     3.1 --- a/php.smarty/src/org/netbeans/modules/php/smarty/editor/completion/entries/TplCodeCompletionData.java	Tue Jun 08 15:20:50 2010 +0200
     3.2 +++ b/php.smarty/src/org/netbeans/modules/php/smarty/editor/completion/entries/TplCodeCompletionData.java	Wed Jun 09 17:37:11 2010 +0200
     3.3 @@ -89,7 +89,7 @@
     3.4          InputStream inputStream = TplCodeCompletionData.class.getResourceAsStream("defs/" + filePath + ".xml"); //NOI18N
     3.5  
     3.6          try {
     3.7 -            Collection<EntryMetadata> ccData = CodeCompletionEntries.readAllCodeCompletionEntriesFromXML(inputStream);
     3.8 +            Collection<EntryMetadata> ccData = CodeCompletionEntries.readAllCodeCompletionEntriesFromXML(inputStream, filePath);
     3.9              ccList.addAll(ccData);
    3.10  
    3.11          } catch (Exception ex) {
     4.1 --- a/php.smarty/src/org/netbeans/modules/php/smarty/editor/completion/entries/defs/variable-modifiers.xml	Tue Jun 08 15:20:50 2010 +0200
     4.2 +++ b/php.smarty/src/org/netbeans/modules/php/smarty/editor/completion/entries/defs/variable-modifiers.xml	Wed Jun 09 17:37:11 2010 +0200
     4.3 @@ -102,7 +102,6 @@
     4.4              <attribute position="1">
     4.5                  <type>string</type>
     4.6                  <required>no</required>
     4.7 -                <possible_values>No	html, htmlall, url, urlpathinfo, quotes, hex, hexentity, javascript, mail</possible_values>
     4.8                  <default>html</default>
     4.9                  <description>This is the escape format to use.</description>
    4.10              </attribute>
    4.11 @@ -110,7 +109,6 @@
    4.12              <attribute position="2">
    4.13                  <type>string</type>
    4.14                  <required>no</required>
    4.15 -                <possible_values>ISO-8859-1, UTF-8, and any character set supported by  htmlentities()  </possible_values>
    4.16                  <default>ISO-8859-1</default>
    4.17                  <description>The character set encoding passed to htmlentities() et. al.</description>
    4.18              </attribute>