-
Notifications
You must be signed in to change notification settings - Fork 82
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
#397 Graph infrastructure #402
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* | ||
* The MIT License (MIT) | ||
* | ||
* Copyright (c) 2017-2019 Yegor Bugayenko | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included | ||
* in all copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
* SOFTWARE. | ||
*/ | ||
package org.jpeek.graph; | ||
|
||
import java.util.List; | ||
|
||
/** | ||
* Graph containing list of nodes. | ||
* @since 0.30.9 | ||
*/ | ||
public interface Graph { | ||
|
||
/** | ||
* Nodes composing this graph. | ||
* @return List of the nodes belonging to this graph | ||
*/ | ||
List<Node> nodes(); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
/* | ||
* The MIT License (MIT) | ||
* | ||
* Copyright (c) 2017-2019 Yegor Bugayenko | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included | ||
* in all copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
* SOFTWARE. | ||
*/ | ||
package org.jpeek.graph; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
/** | ||
* Graph node description. It should at least provide its name and its neighbors. | ||
* @since 0.30.9 | ||
*/ | ||
public interface Node { | ||
|
||
/** | ||
* Node name. | ||
* @return A identifier for the node | ||
*/ | ||
String name(); | ||
|
||
/** | ||
* Calculates ingoing and outgoing connected nodes. | ||
* @return List of nodes connected to this node. | ||
*/ | ||
List<Node> connected(); | ||
|
||
/** | ||
* Simple implementation. | ||
* @since 0.30.9 | ||
*/ | ||
final class Simple implements Node { | ||
/** | ||
* Node name. | ||
*/ | ||
private final String nme; | ||
|
||
/** | ||
* Nodes connected to this node. | ||
*/ | ||
private final List<Node> connect; | ||
|
||
/** | ||
* Ctor. | ||
* @param name Node name | ||
*/ | ||
public Simple(final String name) { | ||
this.nme = name; | ||
this.connect = new ArrayList<Node>(1); | ||
} | ||
|
||
@Override | ||
public String name() { | ||
return this.nme; | ||
} | ||
|
||
@Override | ||
public List<Node> connected() { | ||
return this.connect; | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
/* | ||
* The MIT License (MIT) | ||
* | ||
* Copyright (c) 2017-2019 Yegor Bugayenko | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included | ||
* in all copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
* SOFTWARE. | ||
*/ | ||
package org.jpeek.graph; | ||
|
||
import com.jcabi.xml.XML; | ||
import java.io.IOException; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import org.cactoos.text.Joined; | ||
import org.jpeek.skeleton.Skeleton; | ||
|
||
/** | ||
* Graph implementation built on skeleton. | ||
* @since 0.30.9 | ||
*/ | ||
public final class XmlGraph implements Graph { | ||
|
||
/** | ||
* List of the nodes of this graph. | ||
*/ | ||
private final List<Node> nds; | ||
|
||
/** | ||
* Ctor. | ||
* @param skeleton XMl representation on whiwh to build the graph | ||
* @throws IOException If fails | ||
*/ | ||
public XmlGraph(final Skeleton skeleton) throws IOException { | ||
this.nds = XmlGraph.build(skeleton); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @HDouss I don't think it is a good idea to execute code inside constructor. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @fanifieiev generally we can execute code if it is to initialize a final field. I think it would be better than to make the field non final and execute the code later. What do you think? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @HDouss You can use org.cactoos.Scalar for that case. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @fanifieiev Thanks. |
||
} | ||
|
||
@Override | ||
public List<Node> nodes() { | ||
return this.nds; | ||
} | ||
|
||
/** | ||
* Builds the graph from the skeleton. | ||
* @param skeleton XML representation on whiwh to build the graph | ||
* @return List of nodes | ||
* @throws IOException If fails | ||
*/ | ||
private static List<Node> build(final Skeleton skeleton) throws IOException { | ||
final List<XML> methods = skeleton.xml().nodes( | ||
"//methods/method[@ctor='false' and @abstract='false']" | ||
); | ||
final List<Node> result = new ArrayList<>(methods.size()); | ||
for (final XML method:methods) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @fanifieiev absolutely, did not about this class. Thanks! |
||
result.add( | ||
new Node.Simple( | ||
new Joined( | ||
"", method.xpath("@name").get(0), method.xpath("@desc").get(0) | ||
).asString() | ||
) | ||
); | ||
} | ||
return result; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/* | ||
* The MIT License (MIT) | ||
* | ||
* Copyright (c) 2017-2019 Yegor Bugayenko | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included | ||
* in all copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
* SOFTWARE. | ||
*/ | ||
|
||
/** | ||
* JPeek graphs. | ||
* | ||
* @since 0.30.9 | ||
*/ | ||
package org.jpeek.graph; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* | ||
* The MIT License (MIT) | ||
* | ||
* Copyright (c) 2017-2019 Yegor Bugayenko | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included | ||
* in all copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
* SOFTWARE. | ||
*/ | ||
package org.jpeek.graph; | ||
|
||
import java.io.IOException; | ||
import org.hamcrest.core.IsEqual; | ||
import org.junit.jupiter.api.Test; | ||
import org.llorllale.cactoos.matchers.Assertion; | ||
|
||
/** | ||
* Test case for {@link Node.Simple}. | ||
* @since 0.30.9 | ||
*/ | ||
public final class NodeSimpleTest { | ||
|
||
@Test | ||
public void givesName() throws IOException { | ||
final String name = "name"; | ||
final Node.Simple node = new Node.Simple(name); | ||
new Assertion<>( | ||
"Must be more the 2 files", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @HDouss I don't think that this message is related to what is being asserted, please fix it |
||
node.name(), | ||
new IsEqual<>(name) | ||
).affirm(); | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
/* | ||
* The MIT License (MIT) | ||
* | ||
* Copyright (c) 2017-2019 Yegor Bugayenko | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included | ||
* in all copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
* SOFTWARE. | ||
*/ | ||
package org.jpeek.graph; | ||
|
||
import java.io.IOException; | ||
import java.util.List; | ||
import org.cactoos.list.ListOf; | ||
import org.hamcrest.core.AllOf; | ||
import org.jpeek.FakeBase; | ||
import org.jpeek.skeleton.Skeleton; | ||
import org.junit.jupiter.api.Test; | ||
import org.llorllale.cactoos.matchers.Assertion; | ||
import org.llorllale.cactoos.matchers.HasValuesMatching; | ||
|
||
/** | ||
* Test case for {@link XmlGraph}. | ||
* @since 0.30.9 | ||
*/ | ||
public final class XmlGraphTest { | ||
|
||
@Test | ||
@SuppressWarnings("unchecked") | ||
public void buildsMethodsAsNodes() throws IOException { | ||
final List<Node> nodes = new XmlGraph( | ||
new Skeleton(new FakeBase("MethodMethodCalls")) | ||
).nodes(); | ||
new Assertion<>( | ||
"Must build nodes representing methods", | ||
nodes, | ||
new AllOf<Iterable<Node>>( | ||
new ListOf<>( | ||
new HasValuesMatching<>( | ||
node -> { | ||
return node.name().equals("methodOne()I"); | ||
} | ||
), | ||
new HasValuesMatching<>( | ||
node -> { | ||
return node.name().equals("methodTwo()I"); | ||
} | ||
), | ||
new HasValuesMatching<>( | ||
node -> { | ||
return node.name().equals("methodThree()I"); | ||
} | ||
), | ||
new HasValuesMatching<>( | ||
node -> { | ||
return node.name().equals("methodFour()I"); | ||
} | ||
), | ||
new HasValuesMatching<>( | ||
node -> { | ||
return node.name().equals("methodFive()I"); | ||
} | ||
) | ||
) | ||
) | ||
).affirm(); | ||
} | ||
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@HDouss What about
connections
naming?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@fanifieiev Ok.