Skip to content

Commit

Permalink
objectionary#2032: violations
Browse files Browse the repository at this point in the history
  • Loading branch information
levBagryansky committed Jun 16, 2023
1 parent 0593938 commit 48a75ab
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ public void exec() throws IOException {
);
new Native(function, "EOrust.natives").save(
new FtDefault(
generatedDir.toPath().resolve("EOrust").resolve("natives")
this.generatedDir.toPath().resolve("EOrust").resolve("natives")
)
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,36 +23,59 @@
*/
package org.eolang.maven.rust_project;

import java.io.IOException;
import org.eolang.maven.footprint.Footprint;

import java.io.IOException;
/**
* Class for creating and saving class with native method.
* Created class then is used from {@link EOrust}.
*
* @since 0.30
*/
public final class Native {

public class Native {
/**
* The name of created java class.
*/
private final String name;

/**
* Package of the class.
*/
private final String pack;

public Native(String name, String pack) {
/**
* Ctor.
* @param name Name of the class.
* @param pack Package of the class.
*/
public Native(final String name, final String pack) {
this.name = name;
this.pack = pack;
}

/**
* Save the class.
* @param footprint Footprint to save.
* @throws IOException If any issues with IO.
*/
public void save(final Footprint footprint) throws IOException {
footprint.save(
name,
this.name,
"java",
() -> String.join(
System.lineSeparator(),
String.format(
"package %s;",
pack
this.pack
),
String.format(
"public class %s {",
name
this.name
),
String.format(
"public static native int %s ();",
name
this.name
),
"}"
)
Expand Down
12 changes: 5 additions & 7 deletions eo-runtime/src/main/java/EOorg/EOeolang/EOrust.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@
import java.util.concurrent.ConcurrentHashMap;
import org.apache.commons.lang3.NotImplementedException;
import org.apache.commons.lang3.SystemUtils;
import org.cactoos.scalar.IoChecked;
import org.cactoos.text.IoCheckedText;
import org.cactoos.text.TextOf;
import org.eolang.AtComposite;
import org.eolang.AtFree;
Expand All @@ -48,9 +50,6 @@
* Rust.
*
* @since 0.29
* @todo #1326:90min Generate this file at compile phase
* instead of keep it here. It allows to call any
* rust insert depending on its attributes.
* @checkstyle MethodNameCheck (100 lines)
* @checkstyle LineLengthCheck (100 lines)
* @checkstyle TypeNameCheck (5 lines)
Expand Down Expand Up @@ -126,11 +125,12 @@ public EOrust(final Phi sigma) {
);
}
private static ConcurrentHashMap<String, String> load(final String src) throws IOException {
System.out.println(Paths.get(src).toAbsolutePath());
try (ObjectInputStream map = new ObjectInputStream(
new ByteArrayInputStream(
Base64.getDecoder().decode(
new TextOf(Paths.get(src)).asString()
new IoCheckedText(
new TextOf(Paths.get(src))
).asString()
)
)
)) {
Expand All @@ -153,8 +153,6 @@ private static ConcurrentHashMap<String, String> load(final String src) throws I
),
exc
);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
}

0 comments on commit 48a75ab

Please sign in to comment.