Skip to content

Commit

Permalink
b
Browse files Browse the repository at this point in the history
  • Loading branch information
2xsaiko committed Mar 25, 2021
1 parent 4b175cf commit aa1db5a
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
import cuchaz.enigma.newabstraction.EntryUtil;
import cuchaz.enigma.translation.mapping.EntryMapping;
import cuchaz.enigma.translation.mapping.serde.MappingFormat;
import cuchaz.enigma.translation.representation.entry.ClassEntry;
import cuchaz.enigma.translation.representation.entry.Entry;
import cuchaz.enigma.utils.validation.ValidationContext;

public class EnigmaBackend implements MappingActionSink {

Expand All @@ -35,23 +35,25 @@ public EnigmaBackend(Enigma enigma) {

@Override
public void apply(EntryChange<?> cs) {
ValidationContext vc = new ValidationContext();
Entry<?> target = cs.getTarget();
EntryMapping prev = this.project.getMapper().getDeobfMapping(target);
// EntryMapping mapping = EntryUtil.applyChange(vc, this.project.getMapper(), cs);
//
// boolean renamed = !cs.getDeobfName().isUnchanged();
//
// if (renamed && target instanceof ClassEntry && !((ClassEntry) target).isInnerClass()) {
// this.gui.moveClassTree(target, prev.getTargetName() == null, mapping.getTargetName() == null);
// }
//
// if (!Objects.equals(prev.getTargetName(), mapping.getTargetName())) {
// this.chp.invalidateMapped();
// }
//
// if (!Objects.equals(prev.getJavadoc(), mapping.getJavadoc())) {
// this.chp.invalidateJavadoc(target.getTopLevelClass());
// }
EntryMapping mapping = EntryUtil.applyChange(vc, this.project.getMapper(), cs);
vc.throwOnError();

boolean renamed = !cs.getDeobfName().isUnchanged();

// if (renamed && target instanceof ClassEntry && !((ClassEntry) target).isInnerClass()) {
// this.gui.moveClassTree(target, prev.getTargetName() == null, mapping.getTargetName() == null);
// }

if (!Objects.equals(prev.getTargetName(), mapping.getTargetName())) {
this.chp.invalidateMapped();
}

if (!Objects.equals(prev.getJavadoc(), mapping.getJavadoc())) {
this.chp.invalidateJavadoc(target.getTopLevelClass());
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public static EntryMapping applyChange(ValidationContext vc, EntryRemapper remap
EntryMapping mapping = EntryUtil.applyChange(prev, change);

remapper.putMapping(vc, target, mapping);

return mapping;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package cuchaz.enigma.utils.validation;

import java.io.PrintStream;
import java.util.Arrays;

public class PrintValidatable implements Validatable {
Expand All @@ -8,6 +9,10 @@ public class PrintValidatable implements Validatable {

@Override
public void addMessage(ParameterizedMessage message) {
formatMessage(System.out, message);
}

public static void formatMessage(PrintStream w, ParameterizedMessage message) {
String text = message.getText();
String longText = message.getLongText();
String type;
Expand All @@ -24,9 +29,9 @@ public void addMessage(ParameterizedMessage message) {
default:
throw new IllegalStateException("unreachable");
}
System.out.printf("%s: %s\n", type, text);
w.printf("%s: %s\n", type, text);
if (!longText.isEmpty()) {
Arrays.stream(longText.split("\n")).forEach(s -> System.out.printf(" %s\n", s));
Arrays.stream(longText.split("\n")).forEach(s -> w.printf(" %s\n", s));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,20 @@ public boolean canProceed() {
return messages.stream().noneMatch(m -> m.message.type == Type.ERROR);
}

/**
* If this validation context has at least one error, throw an exception.
*
* @throws IllegalStateException if errors are present
*/
public void throwOnError() {
if (!this.canProceed()) {
for (ParameterizedMessage message : this.messages) {
PrintValidatable.formatMessage(System.err, message);
}
throw new IllegalStateException("Errors encountered; cannot continue! Check error log for details.");
}
}

public List<ParameterizedMessage> getMessages() {
return Collections.unmodifiableList(messages);
}
Expand Down

0 comments on commit aa1db5a

Please sign in to comment.