Skip to content

Commit

Permalink
feat(objectionary#534): use DirectivesAnnotationDefault to read annot…
Browse files Browse the repository at this point in the history
…ations default values
  • Loading branch information
volodya-lombrozo committed Apr 1, 2024
1 parent c376d11 commit 5c78823
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
doubles = {1.0, 2.0, 3.0},
floats = {1.0f, 2.0f, 3.0f},
classes = {AnnotationsApplication.class},
nested = @NestedAnnotation,
nested = @NestedAnnotation(name = "single-nested"),
nestedArray = {
@NestedAnnotation(name = "nested1"),
@NestedAnnotation(name = "nested2")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import java.lang.annotation.Target;

@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
@Target({ElementType.TYPE, ElementType.METHOD})
public @interface NestedAnnotation {
String name() default "nested";
String name() default "nested-default";
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package org.eolang.jeo.representation.directives;

import java.util.Collections;
import java.util.Iterator;
import java.util.concurrent.atomic.AtomicReference;
import org.xembly.Directive;
import org.xembly.Directives;

public final class DirectivesAnnotationDefault implements Iterable<Directive>, Composite {

private final AtomicReference<Iterable<Directive>> value;

public DirectivesAnnotationDefault() {
this(new AtomicReference<>());
}

public DirectivesAnnotationDefault(final AtomicReference<Iterable<Directive>> value) {
this.value = value;
}

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

@Override
public void append(final Iterable<Directive> directives) {
this.value.set(directives);
}

@Override
public Iterable<Directive> build() {
return this;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
*/
package org.eolang.jeo.representation.directives;

import com.jcabi.log.Logger;
import java.util.Arrays;
import java.util.Iterator;
import java.util.stream.Stream;
Expand Down Expand Up @@ -215,6 +216,15 @@ public AnnotationVisitor visitAnnotation(final String descriptor, final boolean
);
}

@Override
public AnnotationVisitor visitAnnotationDefault() {
final AnnotationVisitor visitor = super.visitAnnotationDefault();
Logger.debug(this, String.format("Visit annotation default by %s visitor", visitor));
return new DirectivesAnnotationVisitor(
this.api, visitor, new DirectivesAnnotationDefault()
);
}

@Override
public void visitTryCatchBlock(
final Label start,
Expand Down

0 comments on commit 5c78823

Please sign in to comment.