Skip to content

Commit

Permalink
feat(objectionary#534): fix all qulice suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
volodya-lombrozo committed Apr 2, 2024
1 parent bf73fb4 commit 9e38319
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,28 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2016-2023 Objectionary.com
*
* 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.eolang.jeo.representation.directives;

import java.util.Collections;
import java.util.Iterator;
import java.util.concurrent.atomic.AtomicReference;
import org.xembly.Directive;
Expand Down Expand Up @@ -43,17 +65,19 @@ public DirectivesDefaultValue(final AtomicReference<Iterable<Directive>> value)

@Override
public Iterator<Directive> iterator() {
final Iterator<Directive> result;
if (this.value.get() != null) {
final String label = "annotation-default-value";
final Directives directives = new Directives()
.add("o")
.attr("base", label)
.attr("name", label);
directives.append(this.value.get());
return directives.up().iterator();
result = directives.up().iterator();
} else {
return new Directives().iterator();
result = new Directives().iterator();
}
return result;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@
/**
* Directives Method.
* @since 0.1
* @todo #534:90min Refactor DirectivesMethod class to simplify the code.
* Currently, the class has a lot of methods and fields. It's kind of hard to understand
* what this class does. We need to refactor it to make it more readable and understandable.
* Moreover, in many places this class uses null checks, which is not good.
*/
public final class DirectivesMethod implements Iterable<Directive> {

Expand Down Expand Up @@ -65,7 +69,7 @@ public final class DirectivesMethod implements Iterable<Directive> {
/**
* Annotation default value.
*/
private final AtomicReference<DirectivesDefaultValue> defvalue;
private final AtomicReference<DirectivesDefaultValue> dvalue;

/**
* Opcodes counting.
Expand Down Expand Up @@ -113,7 +117,7 @@ public DirectivesMethod(
this.instructions = new ArrayList<>(0);
this.exceptions = new ArrayList<>(0);
this.annotations = new DirectivesAnnotations();
this.defvalue = new AtomicReference<>();
this.dvalue = new AtomicReference<>();
}

/**
Expand Down Expand Up @@ -183,11 +187,11 @@ public Iterator<Directive> iterator() {
this.exceptions.forEach(directives::append);
directives.up();
}
if (Objects.nonNull(this.defvalue)
&& this.defvalue.get() != null
&& !this.defvalue.get().isEmpty()
if (Objects.nonNull(this.dvalue)
&& this.dvalue.get() != null
&& !this.dvalue.get().isEmpty()
) {
directives.append(this.defvalue.get());
directives.append(this.dvalue.get());
}
directives.up();
return directives.iterator();
Expand All @@ -205,7 +209,7 @@ void exception(final Iterable<Directive> exception) {
* Add annotation default value to the directives.
* @param value Default value directives.
*/
public void defvalue(final DirectivesDefaultValue value) {
this.defvalue.set(value);
void defvalue(final DirectivesDefaultValue value) {
this.dvalue.set(value);
}
}

0 comments on commit 9e38319

Please sign in to comment.