Skip to content

Commit f03752e

Browse files
committed
Update qulice-maven-plugin version and optimize AddDirective class.
1 parent 33ada7e commit f03752e

39 files changed

Lines changed: 349 additions & 354 deletions

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -449,7 +449,7 @@
449449
<plugin>
450450
<groupId>com.qulice</groupId>
451451
<artifactId>qulice-maven-plugin</artifactId>
452-
<version>0.24.0</version>
452+
<version>0.25.1</version>
453453
<configuration>
454454
<excludes combine.children="append">
455455
<exclude>findbugs:.*</exclude>

src/main/java/org/xembly/AddDirective.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,15 +45,14 @@ public String toString() {
4545
public Directive.Cursor exec(final Node dom,
4646
final Directive.Cursor cursor, final Directive.Stack stack) {
4747
final Collection<Node> targets = new ArrayList<>(cursor.size());
48-
final String label = this.name.raw();
4948
final Document doc;
5049
if (dom.getOwnerDocument() == null) {
5150
doc = Document.class.cast(dom);
5251
} else {
5352
doc = dom.getOwnerDocument();
5453
}
5554
for (final Node node : cursor) {
56-
final Element element = doc.createElement(label);
55+
final Element element = doc.createElement(this.name.raw());
5756
node.appendChild(element);
5857
targets.add(element);
5958
}

src/main/java/org/xembly/AddIfDirective.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,13 @@ public String toString() {
4545
public Directive.Cursor exec(final Node dom,
4646
final Directive.Cursor cursor, final Directive.Stack stack) {
4747
final Collection<Node> targets = new ArrayList<>(cursor.size());
48-
final String label = this.name.raw();
4948
for (final Node node : cursor) {
5049
final NodeList kids = node.getChildNodes();
5150
Node target = null;
5251
final int len = kids.getLength();
5352
for (int idx = 0; idx < len; ++idx) {
5453
if (kids.item(idx).getNodeName()
55-
.compareToIgnoreCase(label) == 0) {
54+
.compareToIgnoreCase(this.name.raw()) == 0) {
5655
target = kids.item(idx);
5756
break;
5857
}

src/main/java/org/xembly/Arg.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public String raw() {
5151
* @return Clean text
5252
* @throws XmlContentException If fails
5353
*/
54-
@SuppressWarnings({ "PMD.AvoidInstantiatingObjectsInLoops", "aibolit.P32" })
54+
@SuppressWarnings({"aibolit.P32", "PMD.ProhibitPublicStaticMethods"})
5555
public static String unescape(final String text)
5656
throws XmlContentException {
5757
final char[] chars = text.toCharArray();
@@ -123,8 +123,7 @@ private static String escape(final String text) {
123123
private static char symbol(final String symbol) throws XmlContentException {
124124
final char chr;
125125
if ('#' == symbol.charAt(0)) {
126-
final int num = Integer.parseInt(symbol.substring(1));
127-
chr = Arg.legal((char) num);
126+
chr = Arg.legal((char) Integer.parseInt(symbol.substring(1)));
128127
} else if ("apos".equalsIgnoreCase(symbol)) {
129128
chr = '\'';
130129
} else if ("quot".equalsIgnoreCase(symbol)) {

src/main/java/org/xembly/Callback.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
* @param <V> Type of computed result
1010
* @since 0.31.0
1111
*/
12+
@FunctionalInterface
1213
public interface Callback<V> {
1314
/**
1415
* Computes a result.

src/main/java/org/xembly/CdataDirective.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,8 @@ public Directive.Cursor exec(final Node dom,
4747
} else {
4848
doc = dom.getOwnerDocument();
4949
}
50-
final String val = this.value.raw();
5150
for (final Node node : cursor) {
52-
final Node cdata = doc.createCDATASection(val);
53-
node.appendChild(cdata);
51+
node.appendChild(doc.createCDATASection(this.value.raw()));
5452
}
5553
return cursor;
5654
}

src/main/java/org/xembly/CommentDirective.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,8 @@ public Directive.Cursor exec(final Node dom,
4747
} else {
4848
doc = dom.getOwnerDocument();
4949
}
50-
final String val = this.value.raw();
5150
for (final Node node : cursor) {
52-
final Node cdata = doc.createComment(val);
53-
node.appendChild(cdata);
51+
node.appendChild(doc.createComment(this.value.raw()));
5452
}
5553
return cursor;
5654
}

src/main/java/org/xembly/Directive.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
*
1717
* @since 0.1
1818
*/
19+
@SuppressWarnings("PMD.ImplicitFunctionalInterface")
1920
public interface Directive {
2021

2122
/**

src/main/java/org/xembly/Directives.java

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,7 @@
5151
* @checkstyle ClassFanOutComplexity (500 lines)
5252
*/
5353
@EqualsAndHashCode(of = "all")
54-
@SuppressWarnings({
55-
"PMD.TooManyMethods",
56-
"PMD.CyclomaticComplexity",
57-
"PMD.GodClass",
58-
"PMD.StdCyclomaticComplexity"
59-
})
54+
@SuppressWarnings("PMD.TooManyMethods")
6055
public final class Directives implements Iterable<Directive> {
6156

6257
/**
@@ -83,7 +78,6 @@ public Directives(final String text) {
8378
* Public ctor.
8479
* @param dirs Directives
8580
*/
86-
@SuppressWarnings("PMD.ConstructorOnlyInitializesOrCallOtherConstructors")
8781
public Directives(final Iterable<Directive> dirs) {
8882
this.all = Collections.synchronizedCollection(Directives.toCollection(dirs));
8983
}
@@ -126,8 +120,8 @@ public Iterator<Directive> iterator() {
126120
@SuppressWarnings(
127121
{
128122
"PMD.CognitiveComplexity",
129-
"PMD.StdCyclomaticComplexity",
130123
"PMD.InefficientEmptyStringCheck",
124+
"PMD.ProhibitPublicStaticMethods",
131125
"aibolit.P20_5"
132126
}
133127
)

src/main/java/org/xembly/DomStack.java

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
import java.util.Deque;
88
import java.util.LinkedList;
99
import java.util.NoSuchElementException;
10+
import java.util.concurrent.locks.Lock;
11+
import java.util.concurrent.locks.ReentrantLock;
1012
import lombok.EqualsAndHashCode;
1113

1214
/**
@@ -25,23 +27,32 @@ final class DomStack implements Directive.Stack {
2527
private final Deque<Directive.Cursor> cursors =
2628
new LinkedList<>();
2729

30+
/**
31+
* Lock for thread safety.
32+
*/
33+
private final Lock lock = new ReentrantLock();
34+
2835
@Override
2936
public void push(final Directive.Cursor cursor) {
30-
synchronized (this.cursors) {
37+
this.lock.lock();
38+
try {
3139
this.cursors.push(cursor);
40+
} finally {
41+
this.lock.unlock();
3242
}
3343
}
3444

3545
@Override
3646
public Directive.Cursor pop() throws ImpossibleModificationException {
37-
synchronized (this.cursors) {
38-
try {
39-
return this.cursors.pop();
40-
} catch (final NoSuchElementException ex) {
41-
throw new ImpossibleModificationException(
42-
"Stack is empty, can't POP", ex
43-
);
44-
}
47+
this.lock.lock();
48+
try {
49+
return this.cursors.pop();
50+
} catch (final NoSuchElementException ex) {
51+
throw new ImpossibleModificationException(
52+
"Stack is empty, can't POP", ex
53+
);
54+
} finally {
55+
this.lock.unlock();
4556
}
4657
}
4758
}

0 commit comments

Comments
 (0)