Skip to content

Commit

Permalink
feat(objectionary#91): add javadocs for DirectivesMethodProperties
Browse files Browse the repository at this point in the history
  • Loading branch information
volodya-lombrozo committed Oct 6, 2023
1 parent 17b0008 commit 066b2e6
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import java.util.Iterator;
import org.objectweb.asm.ClassVisitor;
import org.objectweb.asm.MethodVisitor;
import org.objectweb.asm.Type;
import org.xembly.Directive;
import org.xembly.Directives;

Expand Down Expand Up @@ -141,24 +140,10 @@ public MethodVisitor visitMethod(
if (name.equals("<init>")) {
result = super.visitMethod(access, name, descriptor, signature, exceptions);
} else {
// DirectivesClass.methodName(access, name, descriptor);
this.directives.add("o")
.attr("abstract", "")
.attr("name", name);
// if (Type.getMethodType(descriptor).getArgumentTypes().length > 0) {
// this.directives.add("o")
// .attr("name", "args")
// .up();
// }
// final Type[] arguments = Type.getArgumentTypes(descriptor);
// for (int index = 0; index < arguments.length; ++index) {
// this.directives.add("o")
// .attr("abstract", "")
// .attr("name", String.format("arg__%s__%d", arguments[index], index))
// .up();
// }
this.directives.append(new DirectivesMethodProperties(access, descriptor, signature, exceptions));
this.directives
.attr("name", name)
.append(new DirectivesMethodProperties(access, descriptor, signature, exceptions))
.add("o")
.attr("base", "seq")
.attr("name", "@");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,26 @@
/*
* 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.asm;

import java.util.Iterator;
Expand All @@ -6,23 +29,47 @@
import org.xembly.Directives;
import org.objectweb.asm.Type;

/**
* Method properties as Xembly directives.
* @since 0.1.0
*/
public class DirectivesMethodProperties implements Iterable<Directive> {

/**
* Method access modifiers.
*/
private final int access;
private final String desciptor;

/**
* Method descriptor.
*/
private final String descriptor;

/**
* Method signature.
*/
private final String signature;

/**
* Method exceptions.
*/
private final String[] exceptions;

/**
* Constructor.
* @param access Access modifiers.
* @param descriptor Method descriptor.
* @param signature Method signature.
* @param exceptions Method exceptions.
*/
DirectivesMethodProperties(
final int access,
final String desciptor,
final String descriptor,
final String signature,
final String... exceptions
) {
this.access = access;
this.desciptor = Optional.ofNullable(desciptor).orElse("");
this.descriptor = Optional.ofNullable(descriptor).orElse("");
this.signature = Optional.ofNullable(signature).orElse("");
this.exceptions = Optional.ofNullable(exceptions).orElse(new String[0]).clone();
}
Expand All @@ -31,13 +78,17 @@ public class DirectivesMethodProperties implements Iterable<Directive> {
public Iterator<Directive> iterator() {
return new Directives()
.append(new DirectivesData(this.access, "access").directives())
.append(new DirectivesData(this.desciptor, "descriptor").directives())
.append(new DirectivesData(this.descriptor, "descriptor").directives())
.append(new DirectivesData(this.signature, "signature").directives())
.append(this.exceptions())
.append(this.arguments())
.iterator();
}

/**
* Method exceptions.
* @return Exceptions.
*/
private Directives exceptions() {
final Directives tuple = new Directives()
.add("o")
Expand All @@ -51,9 +102,13 @@ private Directives exceptions() {
return tuple;
}

/**
* Method arguments.
* @return Arguments.
*/
private Directives arguments() {
Directives directives = new Directives();
final Type[] arguments = Type.getArgumentTypes(this.desciptor);
final Type[] arguments = Type.getArgumentTypes(this.descriptor);
for (int index = 0; index < arguments.length; ++index) {
directives.add("o")
.attr("abstract", "")
Expand All @@ -62,5 +117,4 @@ private Directives arguments() {
}
return directives;
}

}

0 comments on commit 066b2e6

Please sign in to comment.