Skip to content

Commit

Permalink
Merge branch '__rultor'
Browse files Browse the repository at this point in the history
  • Loading branch information
rultor committed May 1, 2020
2 parents 2b4d871 + 578a153 commit 05d4100
Show file tree
Hide file tree
Showing 6 changed files with 130 additions and 23 deletions.
30 changes: 17 additions & 13 deletions src/main/java/org/jpeek/graph/XmlGraph.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,17 @@
import org.cactoos.map.MapOf;
import org.cactoos.scalar.Sticky;
import org.cactoos.scalar.Unchecked;
import org.cactoos.text.Joined;
import org.jpeek.skeleton.Skeleton;

/**
* Graph implementation built on skeleton.
* @since 0.30.9
* @todo #441:30min Continue the work started with extracting XmlMethodCall
* and XmlMethodArgs and extract more code from this class pertaining
* to serializing XML to string. The objective is to have tested classes
* and to remove the checkstyle suppression below.
* @todo #445:30min Continue the work started with extracting XmlMethodCall,
* XmlMethodArgs and XmlMethodSignature, and extract more code from this class
* pertaining to serializing XML to string. The objective is to have tested
* classes and to remove the checkstyle suppression below. Finally consider
* extracting the whole 'build' method body into a separate class extending
* ListEnvelope.
* @checkstyle ClassDataAbstractionCouplingCheck (500 lines)
*/
public final class XmlGraph implements Graph {
Expand Down Expand Up @@ -73,28 +74,31 @@ public List<Node> nodes() {
* @param skeleton XML representation on whiwh to build the graph
* @return List of nodes
* @throws IOException If fails
* @todo #445:30min This method works only for skeletons with a single
* class because it assigns all methods in the skeleton to the first class
* it finds. Instead, it should iterate through classes and then through
* methods of each class.
*/
private static List<Node> build(final Skeleton skeleton) throws IOException {
final Map<XML, Node> byxml = new org.cactoos.map.Sticky<>(
method -> method,
method -> new Node.Simple(
new Joined(
"", skeleton.xml().xpath("//class/@id").get(0),
".", method.xpath("@name").get(0),
".", new XmlMethodArgs(method).asString()
new XmlMethodSignature(
skeleton.xml().nodes("//class").get(0),
method
).asString()
), skeleton.xml().nodes(
"//methods/method[@ctor='false' and @abstract='false']"
)
);
final Map<String, Node> byname = new MapOf<>(
node -> node.name(),
Node::name,
node -> node,
byxml.values()
);
for (final XML method : byxml.keySet()) {
final List<XML> calls = method.nodes("ops/op[@code='call']");
final Node caller = byxml.get(method);
for (final Map.Entry<XML, Node> entry : byxml.entrySet()) {
final List<XML> calls = entry.getKey().nodes("ops/op[@code='call']");
final Node caller = entry.getValue();
for (final XML call : calls) {
final String name = new XmlMethodCall(call).asString();
if (byname.containsKey(name)) {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/jpeek/graph/XmlMethodArgs.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public final class XmlMethodArgs implements Text {
public String asString() throws IOException {
return new Joined(
":",
this.method.xpath("op/args/arg/@type")
this.method.xpath("args/arg/@type")
).asString();
}
}
2 changes: 1 addition & 1 deletion src/main/java/org/jpeek/graph/XmlMethodCall.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public final class XmlMethodCall implements Text {
public String asString() throws IOException {
return new Joined(
"", this.call.xpath("op/name/text()").get(0),
".", new XmlMethodArgs(this.call).asString()
".", new XmlMethodArgs(this.call.nodes("op").get(0)).asString()
).asString();
}
}
52 changes: 52 additions & 0 deletions src/main/java/org/jpeek/graph/XmlMethodSignature.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* 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 org.cactoos.text.Joined;
import org.cactoos.text.TextEnvelope;
import org.cactoos.text.TextOf;

/**
* Text signature of a class method, extracted from XML Skeleton.
* @since 0.30.9
*/
public final class XmlMethodSignature extends TextEnvelope {

/**
* Ctor.
* @param clazz The class element of XML skeleton.
* @param method The method element of XML skeleton.
*/
public XmlMethodSignature(final XML clazz, final XML method) {
super(
new Joined(
new TextOf("."),
new TextOf(clazz.xpath("./@id").get(0)),
new TextOf(method.xpath("@name").get(0)),
new XmlMethodArgs(method)
)
);
}
}
12 changes: 4 additions & 8 deletions src/test/java/org/jpeek/graph/XmlMethodArgsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,17 @@
import org.hamcrest.core.IsEqual;
import org.jpeek.FakeBase;
import org.jpeek.skeleton.Skeleton;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.llorllale.cactoos.matchers.Assertion;

/**
* Test case for {@link XmlMethodArgs}.
* @since 0.30.9
*/
public final class XmlMethodArgsTest {
final class XmlMethodArgsTest {

@Test
public void returnsEmptyStringWhenNoArgsSpecificied() throws IOException {
void returnsEmptyStringWhenNoArgsSpecificied() throws IOException {
final XML method = new Skeleton(new FakeBase("MethodMethodCalls")).xml().nodes(
"//method[@name='methodOne']"
).get(0);
Expand All @@ -50,11 +49,8 @@ public void returnsEmptyStringWhenNoArgsSpecificied() throws IOException {
).affirm();
}

@Disabled
// @todo #444:30min This test was disabled because the implementation of XmlMethodArgs
// was modified to comply with what will be done in #437. Wait until #437 is resolved and then
// reenable this test
public void givesArgsForMultipleArgs() throws IOException {
@Test
void givesArgsForMultipleArgs() throws IOException {
final XML method = new Skeleton(new FakeBase("MethodsWithDiffParamTypes")).xml().nodes(
"//method[@name='methodThree']"
).get(0);
Expand Down
55 changes: 55 additions & 0 deletions src/test/java/org/jpeek/graph/XmlMethodSignatureTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
* 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 org.hamcrest.core.IsEqual;
import org.jpeek.FakeBase;
import org.jpeek.skeleton.Skeleton;
import org.junit.jupiter.api.Test;
import org.llorllale.cactoos.matchers.Assertion;

/**
* Test case for {@link XmlMethodSignature}.
* @since 0.30.9
*/
final class XmlMethodSignatureTest {

@Test
void givesArgsForMultipleArgs() throws Exception {
final XML skeleton = new Skeleton(
new FakeBase("MethodsWithDiffParamTypes")
).xml();
new Assertion<>(
"Must create method signature with multiple arguments.",
new XmlMethodSignature(
skeleton.nodes("//class").get(0),
skeleton.nodes("//method[@name='methodThree']").get(0)
).asString(),
new IsEqual<>(
"MethodsWithDiffParamTypes.methodThree.Ljava/lang/String:I"
)
).affirm();
}
}

4 comments on commit 05d4100

@0pdd
Copy link
Collaborator

@0pdd 0pdd commented on 05d4100 May 1, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Puzzle 444-ff900aeb disappeared from src/test/java/org/jpeek/graph/XmlMethodArgsTest.java, that's why I closed #459. Please, remember that the puzzle was not necessarily removed in this particular commit. Maybe it happened earlier, but we discovered this fact only now.

@0pdd
Copy link
Collaborator

@0pdd 0pdd commented on 05d4100 May 1, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Puzzle 441-ed4884a5 disappeared from src/main/java/org/jpeek/graph/XmlGraph.java, that's why I closed #445. Please, remember that the puzzle was not necessarily removed in this particular commit. Maybe it happened earlier, but we discovered this fact only now.

@0pdd
Copy link
Collaborator

@0pdd 0pdd commented on 05d4100 May 1, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Puzzle 445-b9bbd966 discovered in src/main/java/org/jpeek/graph/XmlGraph.java and submitted as #472. Please, remember that the puzzle was not necessarily added in this particular commit. Maybe it was added earlier, but we discovered it only now.

@0pdd
Copy link
Collaborator

@0pdd 0pdd commented on 05d4100 May 1, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Puzzle 445-1cfd81f6 discovered in src/main/java/org/jpeek/graph/XmlGraph.java and submitted as #473. Please, remember that the puzzle was not necessarily added in this particular commit. Maybe it was added earlier, but we discovered it only now.

Please sign in to comment.