Skip to content

Commit

Permalink
feat(#226): fix all the rest qulice suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
volodya-lombrozo committed May 16, 2024
1 parent 6544c22 commit ff6c2fb
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 9 deletions.
13 changes: 12 additions & 1 deletion src/main/java/org/eolang/opeo/DecompileMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;
import org.eolang.opeo.decompilation.Decompiler;
import org.eolang.opeo.decompilation.NaiveDecompiler;
import org.eolang.opeo.decompilation.DummyDecompiler;
import org.eolang.opeo.decompilation.NaiveDecompiler;

/**
* Decompiles bytecode in EO representation into high-level EO representation.
Expand Down Expand Up @@ -70,6 +70,17 @@ public final class DecompileMojo extends AbstractMojo {
)
private File outputDir;

/**
* Directory where modified XMIRs are stored.
* It is an optional folder that is used to separate files that were modified.
* In some cases, the decompilation phase might just skip some files because some instructions
* are not supported yet.
* To "see" what we actually decompiled, we store the modified files in this folder.
* It doesn't affect {@link #outputDir}.
*
* @since 0.2.0
* @checkstyle MemberNameCheck (6 lines)
*/
@Parameter(property = "opeo.decompile.modifiedDir")
private File modifiedDir;

Expand Down
37 changes: 30 additions & 7 deletions src/main/java/org/eolang/opeo/SelectiveDecompiler.java
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.opeo;


import com.jcabi.log.Logger;
import java.nio.file.Path;
import java.util.Arrays;
Expand Down Expand Up @@ -65,7 +87,7 @@ public SelectiveDecompiler(final Path input, final Path output) {
* @param supported Supported opcodes are used in selection.
*/
public SelectiveDecompiler(
final Path input, final Path output, String... supported
final Path input, final Path output, final String... supported
) {
this(new FileStorage(input, output), supported);
}
Expand All @@ -76,6 +98,7 @@ public SelectiveDecompiler(
* @param output Output folder where to save the decompiled files.
* @param modified Folder where to save the modified XMIRs.
* @param supported Supported opcodes are used in selection.
* @checkstyle ParameterNumberCheck (5 lines)
*/
public SelectiveDecompiler(
final Path input,
Expand All @@ -91,7 +114,7 @@ public SelectiveDecompiler(
* @param storage Storage from which retrieve the XMIRs and where to save the modified ones.
* @param supported Supported opcodes are used in selection.
*/
public SelectiveDecompiler(final Storage storage, String... supported) {
public SelectiveDecompiler(final Storage storage, final String... supported) {
this(storage, new DummyStorage(), supported);
}

Expand All @@ -106,24 +129,24 @@ public SelectiveDecompiler(
) {
this.storage = storage;
this.modified = modified;
this.supported = supported;
this.supported = supported.clone();
}

@Override
public void decompile() {
this.storage.all().forEach(
entry -> {
final XmirEntry res;
final List<String> xpath = entry.xpath(this.xpath());
if (xpath.isEmpty()) {
final List<String> found = entry.xpath(this.xpath());
if (found.isEmpty()) {
res = entry.transform(xml -> new JeoDecompiler(xml).decompile());
this.modified.save(res);
} else {
Logger.info(
this,
"Skipping %s, because of unsupported opcodes: %s",
entry,
xpath
found
);
res = entry;
}
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/org/eolang/opeo/ast/RawXml.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ public Iterable<Directive> toXmir() {
// method to be more efficient.
return new Directives().append(
new XMLDocument(
new XMLDocument(this.node.node()).toString()).node()
new XMLDocument(this.node.node()).toString()
).node()
);
}
}
28 changes: 28 additions & 0 deletions src/main/java/org/eolang/opeo/storage/DummyStorage.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,36 @@
/*
* 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.opeo.storage;

import com.jcabi.log.Logger;
import java.util.stream.Stream;

/**
* Dummy storage.
* This storage does nothing.
* @since 0.1
*/
public final class DummyStorage implements Storage {
@Override
public Stream<XmirEntry> all() {
Expand Down

3 comments on commit ff6c2fb

@0pdd
Copy link

@0pdd 0pdd commented on ff6c2fb May 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Puzzle 226-8e0dd89c discovered in src/main/java/org/eolang/opeo/ast/RawXml.java) and submitted as #245. Please, remember that the puzzle was not necessarily added in this particular commit. Maybe it was added earlier, but we discovered it only now.

@0pdd
Copy link

@0pdd 0pdd commented on ff6c2fb May 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Puzzle 226-cfd49a39 discovered in src/main/java/org/eolang/opeo/ast/RawXml.java) and submitted as #246. Please, remember that the puzzle was not necessarily added in this particular commit. Maybe it was added earlier, but we discovered it only now.

@0pdd
Copy link

@0pdd 0pdd commented on ff6c2fb May 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Puzzle 226-e20f0b7b discovered in src/test/java/org/eolang/opeo/decompilation/SelectiveDecompilerTest.java) and submitted as #247. Please, remember that the puzzle was not necessarily added in this particular commit. Maybe it was added earlier, but we discovered it only now.

Please sign in to comment.