lbownik commented on code in PR #4969:
URL: https://github.com/apache/netbeans/pull/4969#discussion_r1023985014


##########
nbbuild/antsrc/org/netbeans/nbbuild/JavadocIndex.java:
##########
@@ -85,90 +91,72 @@ public void execute() throws BuildException {
         } catch (IOException ex) {
             throw new BuildException (ex);
         }
-    }    
+    }
+
+
 
-    
-    
     /** Stores parsed info in classes variable */
     private void parseForClasses (File f) throws BuildException {
         log ("Parsing file: " + f, Project.MSG_DEBUG);
         try {
-            BufferedReader is = new BufferedReader (new FileReader (f));
-            
-            
             String urlPrefix;
             try {
                 String fullDir = f.getParentFile ().getCanonicalPath ();
                 String fullTgz = target.getParentFile ().getCanonicalPath ();
-                
+
                 if (!fullDir.startsWith (fullTgz)) {
                     throw new BuildException ("The directory of target file 
must be above all parsed files. Directory: " + fullTgz + " the file dir: " + 
fullDir);
                 }
-                
+
                 urlPrefix = fullDir.substring (fullTgz.length () + 1);
             } catch (IOException ex) {
                 throw new BuildException (ex);
             }
-            
-            // parse following string
-            // <A HREF="org/openide/xml/XMLUtil.html" title="class in 
org.openide.xml">XMLUtil</A
-            String mask = ".*<A HREF=\"([^\"]*)\" 
title=\"(class|interface|annotation) in 
([^\"]*)\"[><I]*>([\\p{Alnum}\\.]*)</.*A>.*";
-            Pattern p = Pattern.compile (mask, Pattern.CASE_INSENSITIVE);
-            // group 1: relative URL to a class or interface
-            // group 2: interface, class or annotation string
-            // group 3: name of package
-            // group 4: name of class
-            
+
+            Document doc = Jsoup.parse(f, "UTF-8", "");
+            Elements ul = doc.getElementsByTag("ul");
+            // should be only one list
+            if (ul.size() != 1) {
+                throw new BuildException("File is not valid for parsing 
classes : " + f);
+            }
             int matches = 0;
-            for (;;) {
-                String line = is.readLine ();
-                if (line == null) break;
-                
-                Matcher m = p.matcher (line);
-                if (m.matches ()) {
+            for (Element li : ul.first().getElementsByTag("li")) {
+                // class Name is the only text in all the tag
+                String className = li.text();
+                // we need anchor to get the inforation
+                Element anchor = li.getElementsByTag("a").first();
+                // left of title is type of element 
(interface,annotation,class,enum ....)
+                // right of title is package of element
+                String[] title = anchor.attr("title").split(" in ");
+                if (title.length == 2) {
                     matches++;
-                    log ("Accepted line: " + line, Project.MSG_DEBUG);
-                    
-                    if (m.groupCount () != 4) {
-                        StringBuffer sb = new StringBuffer ();
-                        sb.append ("Line " + line + " has " + m.groupCount () 
+ " groups and not four");
-                        for (int i = 0; i <= m.groupCount (); i++) {
-                            sb.append ("\n  " + i + " grp: " + m.group (i));
-                        }
-                        throw new BuildException (sb.toString ());
-                    }
-                   
-                    Clazz c = new Clazz (
-                        m.group (3),
-                        m.group (4),
-                        "interface".equals (m.group (2)),
-                        urlPrefix + "/" + m.group (1)
+                    Clazz c = new Clazz(
+                            title[1].trim(),
+                            className,
+                            "interface".equals(title[0].trim()),
+                            urlPrefix + "/" + anchor.attr("href")
                     );
-                    if (c.name == null) throw new NullPointerException ("Null 
name for " + line + "\nclass: " + c);
-                    if (c.name.length () == 0) throw new IllegalStateException 
("Empty name for " + line + "\nclass: " + c);
-                    
-                    log ("Adding class: " + c, Project.MSG_DEBUG);
-                    
+                    if (c.name.length() == 0) {

Review Comment:
   how about 
   if(c.name.isEmpty()) {



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists

Reply via email to