You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by pa...@apache.org on 2017/04/22 06:08:16 UTC

[1/6] groovy git commit: minor refactor: groovydoc will be more reproducible using LinkedHash{Set|Map} instead of Hash{Set|Map}

Repository: groovy
Updated Branches:
  refs/heads/GROOVY_2_6_X 7eba954a3 -> b84d25803


minor refactor: groovydoc will be more reproducible using LinkedHash{Set|Map} instead of Hash{Set|Map}


Project: http://git-wip-us.apache.org/repos/asf/groovy/repo
Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/891211b2
Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/891211b2
Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/891211b2

Branch: refs/heads/GROOVY_2_6_X
Commit: 891211b23fd289204f3ba7239e0f2a9fd02f0db3
Parents: 7eba954
Author: paulk <pa...@asert.com.au>
Authored: Sat Apr 22 07:28:26 2017 +1000
Committer: paulk <pa...@asert.com.au>
Committed: Sat Apr 22 16:07:37 2017 +1000

----------------------------------------------------------------------
 .../tools/groovydoc/GroovyDocTemplateEngine.java      | 14 +++++++-------
 .../groovy/tools/groovydoc/MockOutputTool.java        |  8 ++++----
 .../groovy/tools/groovydoc/SimpleGroovyClassDoc.java  | 14 +++++++-------
 .../groovydoc/SimpleGroovyClassDocAssembler.java      |  8 ++++----
 .../groovy/tools/groovydoc/SimpleGroovyRootDoc.java   |  8 ++++----
 5 files changed, 26 insertions(+), 26 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/groovy/blob/891211b2/subprojects/groovy-groovydoc/src/main/java/org/codehaus/groovy/tools/groovydoc/GroovyDocTemplateEngine.java
----------------------------------------------------------------------
diff --git a/subprojects/groovy-groovydoc/src/main/java/org/codehaus/groovy/tools/groovydoc/GroovyDocTemplateEngine.java b/subprojects/groovy-groovydoc/src/main/java/org/codehaus/groovy/tools/groovydoc/GroovyDocTemplateEngine.java
index 07f7119..ce63ed5 100644
--- a/subprojects/groovy-groovydoc/src/main/java/org/codehaus/groovy/tools/groovydoc/GroovyDocTemplateEngine.java
+++ b/subprojects/groovy-groovydoc/src/main/java/org/codehaus/groovy/tools/groovydoc/GroovyDocTemplateEngine.java
@@ -32,8 +32,8 @@ import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
 import java.util.Arrays;
-import java.util.HashMap;
 import java.util.Iterator;
+import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
 import java.util.Properties;
@@ -66,9 +66,9 @@ public class GroovyDocTemplateEngine {
         this.docTemplatePaths = Arrays.asList(docTemplates);
         this.packageTemplatePaths = Arrays.asList(packageTemplates);
         this.classTemplatePaths = Arrays.asList(classTemplates);
-        this.docTemplates = new HashMap<String, Template>();
-        this.packageTemplates = new HashMap<String, Template>();
-        this.classTemplates = new HashMap<String, Template>();
+        this.docTemplates = new LinkedHashMap<String, Template>();
+        this.packageTemplates = new LinkedHashMap<String, Template>();
+        this.classTemplates = new LinkedHashMap<String, Template>();
         engine = new GStringTemplateEngine();
 
     }
@@ -82,7 +82,7 @@ public class GroovyDocTemplateEngine {
                 t = engine.createTemplate(resourceManager.getReader(templatePath));
                 classTemplates.put(templatePath, t);
             }
-            Map<String, Object> binding = new HashMap<String, Object>();
+            Map<String, Object> binding = new LinkedHashMap<String, Object>();
             binding.put("classDoc", classDoc);
             binding.put("props", properties);
             templateWithBindingApplied = t.make(binding).toString();
@@ -101,7 +101,7 @@ public class GroovyDocTemplateEngine {
                 t = engine.createTemplate(resourceManager.getReader(template));
                 packageTemplates.put(template, t);
             }
-            Map<String, Object> binding = new HashMap<String, Object>();
+            Map<String, Object> binding = new LinkedHashMap<String, Object>();
             binding.put("packageDoc", packageDoc);
             binding.put("props", properties);
             templateWithBindingApplied = t.make(binding).toString();
@@ -120,7 +120,7 @@ public class GroovyDocTemplateEngine {
                 t = engine.createTemplate(resourceManager.getReader(template));
                 docTemplates.put(template, t);
             }
-            Map<String, Object> binding = new HashMap<String, Object>();
+            Map<String, Object> binding = new LinkedHashMap<String, Object>();
             binding.put("rootDoc", rootDoc);
             binding.put("props", properties);
             templateWithBindingApplied = t.make(binding).toString();

http://git-wip-us.apache.org/repos/asf/groovy/blob/891211b2/subprojects/groovy-groovydoc/src/main/java/org/codehaus/groovy/tools/groovydoc/MockOutputTool.java
----------------------------------------------------------------------
diff --git a/subprojects/groovy-groovydoc/src/main/java/org/codehaus/groovy/tools/groovydoc/MockOutputTool.java b/subprojects/groovy-groovydoc/src/main/java/org/codehaus/groovy/tools/groovydoc/MockOutputTool.java
index 0a384cf..260485d 100644
--- a/subprojects/groovy-groovydoc/src/main/java/org/codehaus/groovy/tools/groovydoc/MockOutputTool.java
+++ b/subprojects/groovy-groovydoc/src/main/java/org/codehaus/groovy/tools/groovydoc/MockOutputTool.java
@@ -18,8 +18,8 @@
  */
 package org.codehaus.groovy.tools.groovydoc;
 
-import java.util.HashMap;
-import java.util.HashSet;
+import java.util.LinkedHashMap;
+import java.util.LinkedHashSet;
 import java.util.Map;
 import java.util.Set;
 
@@ -28,8 +28,8 @@ public class MockOutputTool implements OutputTool {
     Map output;
     
     public MockOutputTool() {
-        outputAreas = new HashSet();
-        output = new HashMap();
+        outputAreas = new LinkedHashSet();
+        output = new LinkedHashMap();
     }
     
     public void makeOutputArea(String filename) {

http://git-wip-us.apache.org/repos/asf/groovy/blob/891211b2/subprojects/groovy-groovydoc/src/main/java/org/codehaus/groovy/tools/groovydoc/SimpleGroovyClassDoc.java
----------------------------------------------------------------------
diff --git a/subprojects/groovy-groovydoc/src/main/java/org/codehaus/groovy/tools/groovydoc/SimpleGroovyClassDoc.java b/subprojects/groovy-groovydoc/src/main/java/org/codehaus/groovy/tools/groovydoc/SimpleGroovyClassDoc.java
index a55aae8..f81f08e 100644
--- a/subprojects/groovy-groovydoc/src/main/java/org/codehaus/groovy/tools/groovydoc/SimpleGroovyClassDoc.java
+++ b/subprojects/groovy-groovydoc/src/main/java/org/codehaus/groovy/tools/groovydoc/SimpleGroovyClassDoc.java
@@ -40,7 +40,7 @@ public class SimpleGroovyClassDoc extends SimpleGroovyAbstractableElementDoc imp
     public static final Pattern NAME_ARGS_REGEX = Pattern.compile("([^(]+)\\(([^)]*)\\)");
     public static final Pattern SPLIT_ARGS_REGEX = Pattern.compile(",\\s*");
     private static final List<String> PRIMITIVES = Arrays.asList("void", "boolean", "byte", "short", "char", "int", "long", "float", "double");
-    private static final Map<String, String> TAG_TEXT = new HashMap<String, String>();
+    private static final Map<String, String> TAG_TEXT = new LinkedHashMap<String, String>();
     static {
         TAG_TEXT.put("see", "See Also");
         TAG_TEXT.put("param", "Parameters");
@@ -91,7 +91,7 @@ public class SimpleGroovyClassDoc extends SimpleGroovyAbstractableElementDoc imp
     }
 
     public SimpleGroovyClassDoc(List<String> importedClassesAndPackages, String name) {
-        this(importedClassesAndPackages, new HashMap<String, String>(), name, new ArrayList<LinkArgument>());
+        this(importedClassesAndPackages, new LinkedHashMap<String, String>(), name, new ArrayList<LinkArgument>());
     }
 
     /**
@@ -249,13 +249,13 @@ public class SimpleGroovyClassDoc extends SimpleGroovyAbstractableElementDoc imp
     }
 
     public Set<GroovyClassDoc> getParentInterfaces() {
-        Set<GroovyClassDoc> result = new HashSet<GroovyClassDoc>();
+        Set<GroovyClassDoc> result = new LinkedHashSet<GroovyClassDoc>();
         result.add(this);
-        Set<GroovyClassDoc> next = new HashSet<GroovyClassDoc>();
+        Set<GroovyClassDoc> next = new LinkedHashSet<GroovyClassDoc>();
         next.addAll(Arrays.asList(this.interfaces()));
         while (!next.isEmpty()) {
             Set<GroovyClassDoc> temp = next;
-            next = new HashSet<GroovyClassDoc>();
+            next = new LinkedHashSet<GroovyClassDoc>();
             for (GroovyClassDoc t : temp) {
                 if (t instanceof SimpleGroovyClassDoc) {
                     next.addAll(((SimpleGroovyClassDoc)t).getParentInterfaces());
@@ -271,7 +271,7 @@ public class SimpleGroovyClassDoc extends SimpleGroovyAbstractableElementDoc imp
     }
 
     private Set<GroovyClassDoc> getJavaInterfaces(ExternalGroovyClassDoc d) {
-        Set<GroovyClassDoc> result = new HashSet<GroovyClassDoc>();
+        Set<GroovyClassDoc> result = new LinkedHashSet<GroovyClassDoc>();
         Class[] interfaces = d.externalClass().getInterfaces();
         if (interfaces != null) {
             for (Class i : interfaces) {
@@ -858,7 +858,7 @@ public class SimpleGroovyClassDoc extends SimpleGroovyAbstractableElementDoc imp
         Matcher matcher = regex.matcher(self + "@endMarker");
         if (matcher.find()) {
             matcher.reset();
-            Map<String, List<String>> savedTags = new HashMap<String, List<String>>();
+            Map<String, List<String>> savedTags = new LinkedHashMap<String, List<String>>();
             StringBuffer sb = new StringBuffer();
             while (matcher.find()) {
                 String tagname = matcher.group(1);

http://git-wip-us.apache.org/repos/asf/groovy/blob/891211b2/subprojects/groovy-groovydoc/src/main/java/org/codehaus/groovy/tools/groovydoc/SimpleGroovyClassDocAssembler.java
----------------------------------------------------------------------
diff --git a/subprojects/groovy-groovydoc/src/main/java/org/codehaus/groovy/tools/groovydoc/SimpleGroovyClassDocAssembler.java b/subprojects/groovy-groovydoc/src/main/java/org/codehaus/groovy/tools/groovydoc/SimpleGroovyClassDocAssembler.java
index 7439ea7..678f2e3 100644
--- a/subprojects/groovy-groovydoc/src/main/java/org/codehaus/groovy/tools/groovydoc/SimpleGroovyClassDocAssembler.java
+++ b/subprojects/groovy-groovydoc/src/main/java/org/codehaus/groovy/tools/groovydoc/SimpleGroovyClassDocAssembler.java
@@ -59,7 +59,7 @@ public class SimpleGroovyClassDocAssembler extends VisitorAdapter implements Gro
         this.isGroovy = isGroovy;
 
         stack = new Stack<GroovySourceAST>();
-        classDocs = new HashMap<String, GroovyClassDoc>();
+        classDocs = new LinkedHashMap<String, GroovyClassDoc>();
         if (file != null) {
             // todo: replace this simple idea of default class name
             int idx = file.lastIndexOf(".");
@@ -70,7 +70,7 @@ public class SimpleGroovyClassDocAssembler extends VisitorAdapter implements Gro
 
         deferSetup = packagePath.equals("DefaultPackage");
         importedClassesAndPackages = new ArrayList<String>();
-        aliases = new HashMap<String, String>();
+        aliases = new LinkedHashMap<String, String>();
         if (!deferSetup) setUpImports(packagePath, links, isGroovy, className);
         lastLineCol = new LineColumn(1, 1);
     }
@@ -128,7 +128,7 @@ public class SimpleGroovyClassDocAssembler extends VisitorAdapter implements Gro
             if (parent != null && isNested() && !insideAnonymousInnerClass()) {
                 className = parent.name() + "." + className;
             } else {
-                foundClasses = new HashMap<String, SimpleGroovyClassDoc>();
+                foundClasses = new LinkedHashMap<String, SimpleGroovyClassDoc>();
             }
             SimpleGroovyClassDoc current = (SimpleGroovyClassDoc) classDocs.get(packagePath + FS + className);
             if (current == null) {
@@ -273,7 +273,7 @@ public class SimpleGroovyClassDocAssembler extends VisitorAdapter implements Gro
             }
             classDocs.put(currentClassDoc.getFullPathName(), currentClassDoc);
             if (foundClasses == null) {
-                foundClasses = new HashMap<String, SimpleGroovyClassDoc>();
+                foundClasses = new LinkedHashMap<String, SimpleGroovyClassDoc>();
             }
             foundClasses.put(className, currentClassDoc);
         }

http://git-wip-us.apache.org/repos/asf/groovy/blob/891211b2/subprojects/groovy-groovydoc/src/main/java/org/codehaus/groovy/tools/groovydoc/SimpleGroovyRootDoc.java
----------------------------------------------------------------------
diff --git a/subprojects/groovy-groovydoc/src/main/java/org/codehaus/groovy/tools/groovydoc/SimpleGroovyRootDoc.java b/subprojects/groovy-groovydoc/src/main/java/org/codehaus/groovy/tools/groovydoc/SimpleGroovyRootDoc.java
index 9ba010f..7c9c172 100644
--- a/subprojects/groovy-groovydoc/src/main/java/org/codehaus/groovy/tools/groovydoc/SimpleGroovyRootDoc.java
+++ b/subprojects/groovy-groovydoc/src/main/java/org/codehaus/groovy/tools/groovydoc/SimpleGroovyRootDoc.java
@@ -24,7 +24,7 @@ import org.codehaus.groovy.groovydoc.GroovyRootDoc;
 
 import java.util.ArrayList;
 import java.util.Collections;
-import java.util.HashMap;
+import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
 
@@ -37,8 +37,8 @@ public class SimpleGroovyRootDoc extends SimpleGroovyDoc implements GroovyRootDo
 
     public SimpleGroovyRootDoc(String name) {
         super(name);
-        packageDocs = new HashMap<String, GroovyPackageDoc>();
-        classDocs = new HashMap<String, GroovyClassDoc>();
+        packageDocs = new LinkedHashMap<String, GroovyPackageDoc>();
+        classDocs = new LinkedHashMap<String, GroovyClassDoc>();
     }
 
     public GroovyClassDoc classNamed(GroovyClassDoc groovyClassDoc, String name) {
@@ -119,7 +119,7 @@ public class SimpleGroovyRootDoc extends SimpleGroovyDoc implements GroovyRootDo
     }
 
     public Map<String, GroovyClassDoc> getVisibleClasses(List importedClassesAndPackages) {
-        Map<String, GroovyClassDoc> visibleClasses = new HashMap<String, GroovyClassDoc>();
+        Map<String, GroovyClassDoc> visibleClasses = new LinkedHashMap<String, GroovyClassDoc>();
         for (String fullClassName : classDocs.keySet()) {
             String equivalentPackageImport = fullClassName.replaceAll("[^/]+$", "*");
             if (importedClassesAndPackages.contains(fullClassName) ||


[3/6] groovy git commit: GROOVY-8117: Do not resolve aliased imports early.

Posted by pa...@apache.org.
GROOVY-8117: Do not resolve aliased imports early.


Project: http://git-wip-us.apache.org/repos/asf/groovy/repo
Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/b70c0920
Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/b70c0920
Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/b70c0920

Branch: refs/heads/GROOVY_2_6_X
Commit: b70c092083457840ff8fae909f60f832e5c930f6
Parents: 092beef
Author: Mikko V�rri <vm...@linuxbox.fi>
Authored: Sun Mar 12 03:48:40 2017 +0200
Committer: paulk <pa...@asert.com.au>
Committed: Sat Apr 22 16:07:39 2017 +1000

----------------------------------------------------------------------
 .../groovy/tools/groovydoc/SimpleGroovyClassDocAssembler.java    | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/groovy/blob/b70c0920/subprojects/groovy-groovydoc/src/main/java/org/codehaus/groovy/tools/groovydoc/SimpleGroovyClassDocAssembler.java
----------------------------------------------------------------------
diff --git a/subprojects/groovy-groovydoc/src/main/java/org/codehaus/groovy/tools/groovydoc/SimpleGroovyClassDocAssembler.java b/subprojects/groovy-groovydoc/src/main/java/org/codehaus/groovy/tools/groovydoc/SimpleGroovyClassDocAssembler.java
index 678f2e3..b7ce2b1 100644
--- a/subprojects/groovy-groovydoc/src/main/java/org/codehaus/groovy/tools/groovydoc/SimpleGroovyClassDocAssembler.java
+++ b/subprojects/groovy-groovydoc/src/main/java/org/codehaus/groovy/tools/groovydoc/SimpleGroovyClassDocAssembler.java
@@ -742,7 +742,7 @@ public class SimpleGroovyClassDocAssembler extends VisitorAdapter implements Gro
         return returnValue;
     }
 
-    // preempt resolve as info is partially available here (star imports won't match here)
+    // preempt resolve as info is partially available here (aliases and star imports won't match here)
     private String extractName(GroovySourceAST typeNode) {
         String typeName = buildName(typeNode);
         if (!typeName.contains("/")) {
@@ -750,7 +750,7 @@ public class SimpleGroovyClassDocAssembler extends VisitorAdapter implements Gro
             // Groovy currently resolves this to last found so traverse in reverse order
             for (int i = importedClassesAndPackages.size() - 1; i >= 0; i--) {
                 String name = importedClassesAndPackages.get(i);
-                if (name.endsWith(slashName)) {
+                if (!aliases.containsValue(name) && name.endsWith(slashName)) {
                     typeName = name;
                     break;
                 }


[6/6] groovy git commit: Differentiate between XML breadthFirst() traversal and * navigation (minor tweaks: closes #517)

Posted by pa...@apache.org.
Differentiate between XML breadthFirst() traversal and * navigation (minor tweaks: closes #517)


Project: http://git-wip-us.apache.org/repos/asf/groovy/repo
Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/b84d2580
Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/b84d2580
Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/b84d2580

Branch: refs/heads/GROOVY_2_6_X
Commit: b84d2580349730e758d5287d5e9af1f1f57e2dd4
Parents: 37f4e64
Author: paulk <pa...@asert.com.au>
Authored: Sat Apr 22 16:04:09 2017 +1000
Committer: paulk <pa...@asert.com.au>
Committed: Sat Apr 22 16:07:41 2017 +1000

----------------------------------------------------------------------
 .../groovy-xml/src/spec/doc/xml-userguide.adoc  | 51 ++++++++++++++------
 .../spec/test/UserGuideXmlSlurperTest.groovy    | 23 +++++++--
 2 files changed, 54 insertions(+), 20 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/groovy/blob/b84d2580/subprojects/groovy-xml/src/spec/doc/xml-userguide.adoc
----------------------------------------------------------------------
diff --git a/subprojects/groovy-xml/src/spec/doc/xml-userguide.adoc b/subprojects/groovy-xml/src/spec/doc/xml-userguide.adoc
index c7fb1d7..84a9cce 100644
--- a/subprojects/groovy-xml/src/spec/doc/xml-userguide.adoc
+++ b/subprojects/groovy-xml/src/spec/doc/xml-userguide.adoc
@@ -219,30 +219,32 @@ the
 
 Both of them are equally valid.
 
-=== Speed things up with * and ** navigation
+=== Flexible navigation with children (\*), depthFirst (**) and breadthFirst
 
-If you ever have used XPath you may have used expressions like
+If you ever have used XPath, you may have used expressions like:
 
-* `//` : Look everywhere
 * `/following-sibling::othernode` : Look for a node "othernode" in the same level
+* `//` : Look everywhere
 
-More or less we have their counterparts in `GPath` with the shortcuts `*` and `**`.
+More or less we have their counterparts in GPath with the shortcuts `\*` (aka `children()`) and `**` (aka `depthFirst()`).
 
 The first example shows a simple use of `*`, which only iterates over the direct children of the node.
 
 [source,groovy]
 .Using *
 ----
-include::{rootProjectDir}/subprojects/groovy-xml/src/spec/test/UserGuideXmlSlurperTest.groovy[tags=testBreadthFirst1,indent=0]
+include::{rootProjectDir}/subprojects/groovy-xml/src/spec/test/UserGuideXmlSlurperTest.groovy[tags=testChildren,indent=0]
 ----
 
-This test searches for any node at the same level of the "books" node
-first. This operation roughly corresponds to the `breadthFirst()` method, except that it only stops at *one level* instead of continuing to the inner levels.
+This test searches for any child nodes of the "books" node matching the given
+condition. In a bit more detail, the expression says: _Look for any node with
+a tag name equal to 'book' having an id with a value of '2' directly under
+the 'books' node_.
 
-The expression says *_Look for any node with a tag name
-equals 'book' having an id with a value of '2' directly under the 'books' node_*.
+This operation roughly corresponds to the `breadthFirst()` method, except that
+it only stops at *one level* instead of continuing to the inner levels.
 
-But what if we would like to look for a given value
+What if we would like to look for a given value
 without having to know exactly where it is. Let's say that the
 only thing we know is the id of the author "Lewis Carroll" . How are
 we going to be able to find that book? Using `**` is the solution:
@@ -253,20 +255,37 @@ we going to be able to find that book? Using `**` is the solution:
 include::{rootProjectDir}/subprojects/groovy-xml/src/spec/test/UserGuideXmlSlurperTest.groovy[tags=testDepthFirst1,indent=0]
 ----
 
-`**` is the same as looking something *everywhere in the
-tree from this point down*. In this case we've used the method
-`find(Closure cl)` to find just the first occurrence. `**` corresponds to the `depthFirst()` method.
+`**` is the same as looking for something _everywhere in the
+tree from this point down_. In this case, we've used the method
+`find(Closure cl)` to find just the first occurrence.
 
-What if we want to collect all book's titles?
+What if we want to collect all book's titles? That's easy, just use `findAll`:
 
 [source,groovy]
-.depthFirst()
 ----
 include::{rootProjectDir}/subprojects/groovy-xml/src/spec/test/UserGuideXmlSlurperTest.groovy[tags=testDepthFirst2,indent=0]
 ----
 
+In the last two examples, `**` is used as a shortcut for the `depthFirst()`
+method. It goes as far down the tree as it can while navigating down the
+tree from a given node. The `breadthFirst()` method finishes off all nodes
+on a given level before traversing down to the next level.
+
+The following example shows the difference between these two methods:
+
+[source,groovy]
+.depthFirst() vs .breadthFirst
+----
+include::{rootProjectDir}/subprojects/groovy-xml/src/spec/test/UserGuideXmlSlurperTest.groovy[tags=testDepthVsBreadth,indent=0]
+----
+
+In this example, we search for any nodes with an id attribute with value 2 or 3.
+There are both `book` and `author` nodes that match that criteria. The different
+traversal orders will find the same nodes in each case but in different orders
+corresponding to how the tree was traversed.
+
 It is worth mentioning again that there are some useful methods
-converting a node's value to an integer, float... etc. Those methods
+converting a node's value to an integer, float, etc. Those methods
 could be convenient when doing comparisons like this:
 
 [source,groovy]

http://git-wip-us.apache.org/repos/asf/groovy/blob/b84d2580/subprojects/groovy-xml/src/spec/test/UserGuideXmlSlurperTest.groovy
----------------------------------------------------------------------
diff --git a/subprojects/groovy-xml/src/spec/test/UserGuideXmlSlurperTest.groovy b/subprojects/groovy-xml/src/spec/test/UserGuideXmlSlurperTest.groovy
index 9d5901f..13e7252 100644
--- a/subprojects/groovy-xml/src/spec/test/UserGuideXmlSlurperTest.groovy
+++ b/subprojects/groovy-xml/src/spec/test/UserGuideXmlSlurperTest.groovy
@@ -94,23 +94,25 @@ class UserGuideXmlSlurperTest  extends GroovyTestCase {
         // end::testGettingAnAttributeText[]
     }
 
-    void testBreadthFirst1() {
-        // tag::testBreadthFirst1[]
+    void testChildren() {
+        // tag::testChildren[]
         def response = new XmlSlurper().parseText(books)
 
+        // .'*' could be replaced by .children()
         def catcherInTheRye = response.value.books.'*'.find { node->
-         /* node.@id == 2 could be expressed as node['@id'] == 2 */
+            // node.@id == 2 could be expressed as node['@id'] == 2
             node.name() == 'book' && node.@id == '2'
         }
 
         assert catcherInTheRye.title.text() == 'Catcher in the Rye'
-        // end::testBreadthFirst1[]
+        // end::testChildren[]
     }
 
     void testDepthFirst1() {
         // tag::testDepthFirst1[]
         def response = new XmlSlurper().parseText(books)
 
+        // .'**' could be replaced by .depthFirst()
         def bookId = response.'**'.find { book->
             book.author.text() == 'Lewis Carroll'
         }.@id
@@ -129,6 +131,19 @@ class UserGuideXmlSlurperTest  extends GroovyTestCase {
         // end::testDepthFirst2[]
     }
 
+    void testDepthVsBreadth() {
+        // tag::testDepthVsBreadth[]
+        def response = new XmlSlurper().parseText(books)
+        def nodeName = { node -> node.name() }
+        def withId2or3 = { node -> node.@id in [2, 3] }
+
+        assert ['book', 'author', 'book', 'author'] ==
+                response.value.books.depthFirst().findAll(withId2or3).collect(nodeName)
+        assert ['book', 'book', 'author', 'author'] ==
+                response.value.books.breadthFirst().findAll(withId2or3).collect(nodeName)
+        // end::testDepthVsBreadth[]
+    }
+
     void testHelpers() {
         // tag::testHelpers[]
         def response = new XmlSlurper().parseText(books)


[4/6] groovy git commit: GROOVY-8117: trivial refactor (closes #512); side effect: close malformed PR (closes #525)

Posted by pa...@apache.org.
GROOVY-8117: trivial refactor (closes #512); side effect: close malformed PR (closes #525)


Project: http://git-wip-us.apache.org/repos/asf/groovy/repo
Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/78304992
Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/78304992
Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/78304992

Branch: refs/heads/GROOVY_2_6_X
Commit: 7830499235c1c005f6086821a6454934e328d1ef
Parents: b70c092
Author: paulk <pa...@asert.com.au>
Authored: Sat Apr 22 10:10:32 2017 +1000
Committer: paulk <pa...@asert.com.au>
Committed: Sat Apr 22 16:07:40 2017 +1000

----------------------------------------------------------------------
 .../tools/groovydoc/SimpleGroovyClassDocAssembler.java       | 8 +++++++-
 .../codehaus/groovy/tools/groovydoc/GroovyDocToolTest.java   | 5 ++++-
 2 files changed, 11 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/groovy/blob/78304992/subprojects/groovy-groovydoc/src/main/java/org/codehaus/groovy/tools/groovydoc/SimpleGroovyClassDocAssembler.java
----------------------------------------------------------------------
diff --git a/subprojects/groovy-groovydoc/src/main/java/org/codehaus/groovy/tools/groovydoc/SimpleGroovyClassDocAssembler.java b/subprojects/groovy-groovydoc/src/main/java/org/codehaus/groovy/tools/groovydoc/SimpleGroovyClassDocAssembler.java
index b7ce2b1..3836dc4 100644
--- a/subprojects/groovy-groovydoc/src/main/java/org/codehaus/groovy/tools/groovydoc/SimpleGroovyClassDocAssembler.java
+++ b/subprojects/groovy-groovydoc/src/main/java/org/codehaus/groovy/tools/groovydoc/SimpleGroovyClassDocAssembler.java
@@ -28,7 +28,13 @@ import org.codehaus.groovy.control.ResolveVisitor;
 import org.codehaus.groovy.groovydoc.*;
 import org.codehaus.groovy.runtime.DefaultGroovyMethods;
 
-import java.util.*;
+import java.util.ArrayList;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+import java.util.Stack;
+import java.util.StringTokenizer;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 

http://git-wip-us.apache.org/repos/asf/groovy/blob/78304992/subprojects/groovy-groovydoc/src/test/groovy/org/codehaus/groovy/tools/groovydoc/GroovyDocToolTest.java
----------------------------------------------------------------------
diff --git a/subprojects/groovy-groovydoc/src/test/groovy/org/codehaus/groovy/tools/groovydoc/GroovyDocToolTest.java b/subprojects/groovy-groovydoc/src/test/groovy/org/codehaus/groovy/tools/groovydoc/GroovyDocToolTest.java
index 7e31ca1..37f5b35 100644
--- a/subprojects/groovy-groovydoc/src/test/groovy/org/codehaus/groovy/tools/groovydoc/GroovyDocToolTest.java
+++ b/subprojects/groovy-groovydoc/src/test/groovy/org/codehaus/groovy/tools/groovydoc/GroovyDocToolTest.java
@@ -21,7 +21,10 @@ package org.codehaus.groovy.tools.groovydoc;
 import groovy.util.GroovyTestCase;
 
 import java.nio.charset.Charset;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Properties;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 


[2/6] groovy git commit: GROOVY-8117: Add test.

Posted by pa...@apache.org.
GROOVY-8117: Add test.


Project: http://git-wip-us.apache.org/repos/asf/groovy/repo
Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/092beef0
Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/092beef0
Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/092beef0

Branch: refs/heads/GROOVY_2_6_X
Commit: 092beef0d4bb6e2169d0dd8d368d9df71acd3347
Parents: 891211b
Author: Mikko V�rri <vm...@linuxbox.fi>
Authored: Sun Mar 12 03:47:51 2017 +0200
Committer: paulk <pa...@asert.com.au>
Committed: Sat Apr 22 16:07:38 2017 +1000

----------------------------------------------------------------------
 .../tools/groovydoc/GroovyDocToolTest.java      | 40 ++++++++++++++++++--
 .../groovydoc/testfiles/alias/FooAdapter.groovy | 32 ++++++++++++++++
 .../groovydoc/testfiles/alias/api/Foo.java      | 26 +++++++++++++
 .../groovydoc/testfiles/alias/lib/Foo.java      | 26 +++++++++++++
 4 files changed, 121 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/groovy/blob/092beef0/subprojects/groovy-groovydoc/src/test/groovy/org/codehaus/groovy/tools/groovydoc/GroovyDocToolTest.java
----------------------------------------------------------------------
diff --git a/subprojects/groovy-groovydoc/src/test/groovy/org/codehaus/groovy/tools/groovydoc/GroovyDocToolTest.java b/subprojects/groovy-groovydoc/src/test/groovy/org/codehaus/groovy/tools/groovydoc/GroovyDocToolTest.java
index 6b68ef4..7e31ca1 100644
--- a/subprojects/groovy-groovydoc/src/test/groovy/org/codehaus/groovy/tools/groovydoc/GroovyDocToolTest.java
+++ b/subprojects/groovy-groovydoc/src/test/groovy/org/codehaus/groovy/tools/groovydoc/GroovyDocToolTest.java
@@ -21,9 +21,7 @@ package org.codehaus.groovy.tools.groovydoc;
 import groovy.util.GroovyTestCase;
 
 import java.nio.charset.Charset;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Properties;
+import java.util.*;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
@@ -658,6 +656,42 @@ public class GroovyDocToolTest extends GroovyTestCase {
         assertEquals("There has to be a reference to class ArrayList", "ArrayList", m.group(2));
     }
 
+    public void testImplementedInterfaceWithAlias() throws Exception {
+        // FooAdapter imports both api.Foo and lib.Foo, using "lib.Foo as FooImpl" to disambiguate.
+        // lib.Foo is imported later that api.Foo, so groovydoc tries to resolve to lib.Foo first.
+        htmlTool.add(Arrays.asList(
+                "org/codehaus/groovy/tools/groovydoc/testfiles/alias/api/Foo.java",
+                "org/codehaus/groovy/tools/groovydoc/testfiles/alias/lib/Foo.java",
+                "org/codehaus/groovy/tools/groovydoc/testfiles/alias/FooAdapter.groovy"
+        ));
+
+        final MockOutputTool output = new MockOutputTool();
+        htmlTool.renderToOutput(output, MOCK_DIR);
+        final String fooAdapterDoc = output.getText(MOCK_DIR + "/org/codehaus/groovy/tools/groovydoc/testfiles/alias/FooAdapter.html");
+
+        // "Interfaces and Traits" section should show "Foo" as one of the implemented interfaces,
+        // and that should link to api/Foo.html, not to lib/Foo.html.
+        final Matcher interfacesAndTraits = Pattern.compile(
+                "<dt>All Implemented Interfaces and Traits:</dt>\\s*" +
+                "<dd><a href='[./]*/org/codehaus/groovy/tools/groovydoc/testfiles/alias/(api|lib)/Foo\\.html'>(Foo|FooImpl)</a></dd>"
+        ).matcher(fooAdapterDoc);
+
+        // Constructor is actually "FooAdapter(FooImpl foo)",
+        // but it should show "Foo" as the link text, not "FooImpl".
+        // The Foo parameter type should link to lib/Foo.html, not api/Foo.html.
+        final Matcher constructor = Pattern.compile(
+                "FooAdapter(</[a-z]+>)*\\(<a href='[./]*/org/codehaus/groovy/tools/groovydoc/testfiles/alias/(api|lib)/Foo.html'>(Foo|FooImpl)</a> foo\\)"
+        ).matcher(fooAdapterDoc);
+
+        assertTrue("Interfaces and Traits pattern should match for this test to make sense", interfacesAndTraits.find());
+        assertTrue("Constructor pattern should match for this test to make sense", constructor.find());
+
+        assertEquals("The implemented interface should link to api.Foo", "api", interfacesAndTraits.group(1));
+        assertEquals("The implemented interface link text should be Foo", "Foo", interfacesAndTraits.group(2));
+        assertEquals("The constructor parameter should link to lib.Foo", "lib", constructor.group(2));
+        assertEquals("The constructor parameter link text should be Foo", "Foo", constructor.group(3));
+    }
+
     public void testScript() throws Exception {
         List<String> srcList = new ArrayList<String>();
         srcList.add("org/codehaus/groovy/tools/groovydoc/testfiles/Script.groovy");

http://git-wip-us.apache.org/repos/asf/groovy/blob/092beef0/subprojects/groovy-groovydoc/src/test/groovy/org/codehaus/groovy/tools/groovydoc/testfiles/alias/FooAdapter.groovy
----------------------------------------------------------------------
diff --git a/subprojects/groovy-groovydoc/src/test/groovy/org/codehaus/groovy/tools/groovydoc/testfiles/alias/FooAdapter.groovy b/subprojects/groovy-groovydoc/src/test/groovy/org/codehaus/groovy/tools/groovydoc/testfiles/alias/FooAdapter.groovy
new file mode 100644
index 0000000..70da911
--- /dev/null
+++ b/subprojects/groovy-groovydoc/src/test/groovy/org/codehaus/groovy/tools/groovydoc/testfiles/alias/FooAdapter.groovy
@@ -0,0 +1,32 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+package org.codehaus.groovy.tools.groovydoc.testfiles.alias
+
+import org.codehaus.groovy.tools.groovydoc.testfiles.alias.api.Foo
+import org.codehaus.groovy.tools.groovydoc.testfiles.alias.lib.Foo as FooImpl
+
+/**
+ * An adapter class that makes an instance of
+ * {@link org.codehaus.groovy.tools.groovydoc.testfiles.alias.lib.Foo library Foo}
+ * appear to be an instance of
+ * {@link org.codehaus.groovy.tools.groovydoc.testfiles.alias.api.Foo API Foo}.
+ */
+class FooAdapter implements Foo {
+    FooAdapter(FooImpl foo) {}
+}

http://git-wip-us.apache.org/repos/asf/groovy/blob/092beef0/subprojects/groovy-groovydoc/src/test/groovy/org/codehaus/groovy/tools/groovydoc/testfiles/alias/api/Foo.java
----------------------------------------------------------------------
diff --git a/subprojects/groovy-groovydoc/src/test/groovy/org/codehaus/groovy/tools/groovydoc/testfiles/alias/api/Foo.java b/subprojects/groovy-groovydoc/src/test/groovy/org/codehaus/groovy/tools/groovydoc/testfiles/alias/api/Foo.java
new file mode 100644
index 0000000..97d0bd3
--- /dev/null
+++ b/subprojects/groovy-groovydoc/src/test/groovy/org/codehaus/groovy/tools/groovydoc/testfiles/alias/api/Foo.java
@@ -0,0 +1,26 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+package org.codehaus.groovy.tools.groovydoc.testfiles.alias.api;
+
+/**
+ * A Foo type defined by some API, unrelated to the
+ * {@link org.codehaus.groovy.tools.groovydoc.testfiles.alias.lib.Foo library Foo}.
+ */
+public interface Foo {
+}

http://git-wip-us.apache.org/repos/asf/groovy/blob/092beef0/subprojects/groovy-groovydoc/src/test/groovy/org/codehaus/groovy/tools/groovydoc/testfiles/alias/lib/Foo.java
----------------------------------------------------------------------
diff --git a/subprojects/groovy-groovydoc/src/test/groovy/org/codehaus/groovy/tools/groovydoc/testfiles/alias/lib/Foo.java b/subprojects/groovy-groovydoc/src/test/groovy/org/codehaus/groovy/tools/groovydoc/testfiles/alias/lib/Foo.java
new file mode 100644
index 0000000..05e2184
--- /dev/null
+++ b/subprojects/groovy-groovydoc/src/test/groovy/org/codehaus/groovy/tools/groovydoc/testfiles/alias/lib/Foo.java
@@ -0,0 +1,26 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+package org.codehaus.groovy.tools.groovydoc.testfiles.alias.lib;
+
+/**
+ * A Foo type defined by some library, unrelated to the
+ * {@link org.codehaus.groovy.tools.groovydoc.testfiles.alias.api.Foo API Foo}.
+ */
+public class Foo {
+}


[5/6] groovy git commit: Differentiate between XML breadthFirst() traversal and * navigation

Posted by pa...@apache.org.
Differentiate between XML breadthFirst() traversal and * navigation

The analogy between '*' and breadthFirst() traversal seems wrong. The former only traverses one level, while the latter searches through the next levels as well. See http://stackoverflow.com/questions/42985716/groovy-xml-tree-traversal-breadthfirst-method-using-as-syntactic-sugar.


Project: http://git-wip-us.apache.org/repos/asf/groovy/repo
Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/37f4e642
Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/37f4e642
Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/37f4e642

Branch: refs/heads/GROOVY_2_6_X
Commit: 37f4e642655273c41f6c7d1a5f05bffdbe3f34fa
Parents: 7830499
Author: manouti <ma...@users.noreply.github.com>
Authored: Thu Mar 23 23:45:20 2017 +0200
Committer: paulk <pa...@asert.com.au>
Committed: Sat Apr 22 16:07:40 2017 +1000

----------------------------------------------------------------------
 .../groovy-xml/src/spec/doc/xml-userguide.adoc  | 24 ++++++++------------
 1 file changed, 10 insertions(+), 14 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/groovy/blob/37f4e642/subprojects/groovy-xml/src/spec/doc/xml-userguide.adoc
----------------------------------------------------------------------
diff --git a/subprojects/groovy-xml/src/spec/doc/xml-userguide.adoc b/subprojects/groovy-xml/src/spec/doc/xml-userguide.adoc
index ec98d16..c7fb1d7 100644
--- a/subprojects/groovy-xml/src/spec/doc/xml-userguide.adoc
+++ b/subprojects/groovy-xml/src/spec/doc/xml-userguide.adoc
@@ -219,47 +219,43 @@ the
 
 Both of them are equally valid.
 
-=== Speed things up with breadthFirst and depthFirst
+=== Speed things up with * and ** navigation
 
 If you ever have used XPath you may have used expressions like
 
 * `//` : Look everywhere
 * `/following-sibling::othernode` : Look for a node "othernode" in the same level
 
-More or less we have their counterparts in `GPath` with the methods
-`breadthFirst()` and `depthFirst()`.
+More or less we have their counterparts in `GPath` with the shortcuts `*` and `**`.
 
-The first example shows a simple use of `breadthFirst()`. The creators of
-this methods created a shorter syntax for it using the symbol `*`.
+The first example shows a simple use of `*`, which only iterates over the direct children of the node.
 
 [source,groovy]
-.breadthFirst()
+.Using *
 ----
 include::{rootProjectDir}/subprojects/groovy-xml/src/spec/test/UserGuideXmlSlurperTest.groovy[tags=testBreadthFirst1,indent=0]
 ----
 
 This test searches for any node at the same level of the "books" node
-first, and *only if* it couldn't find the node we were looking for,
-then it will look deeper in the tree, always taking into account the
-given the expression inside the closure.
+first. This operation roughly corresponds to the `breadthFirst()` method, except that it only stops at *one level* instead of continuing to the inner levels.
 
 The expression says *_Look for any node with a tag name
-equals 'book' having an id with a value of '2'_*.
+equals 'book' having an id with a value of '2' directly under the 'books' node_*.
 
 But what if we would like to look for a given value
 without having to know exactly where it is. Let's say that the
 only thing we know is the id of the author "Lewis Carroll" . How are
-we going to be able to find that book? `depthFirst()` is the solution:
+we going to be able to find that book? Using `**` is the solution:
 
 [source,groovy]
-.depthFirst()
+.Using **
 ----
 include::{rootProjectDir}/subprojects/groovy-xml/src/spec/test/UserGuideXmlSlurperTest.groovy[tags=testDepthFirst1,indent=0]
 ----
 
-`depthFirst()` is the same as looking something *everywhere in the
+`**` is the same as looking something *everywhere in the
 tree from this point down*. In this case we've used the method
-`find(Closure cl)` to find just the first occurrence.
+`find(Closure cl)` to find just the first occurrence. `**` corresponds to the `depthFirst()` method.
 
 What if we want to collect all book's titles?