Skip to content

Commit

Permalink
Merge branch 'release-0.4.3'
Browse files Browse the repository at this point in the history
  • Loading branch information
jamierocks committed Oct 27, 2018
2 parents c80ba57 + 32253f0 commit dacd559
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 31 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,14 @@ Lorenz releases can be obtained through Maven Central:
<dependency>
<groupId>me.jamiemansfield</groupId>
<artifactId>lorenz</artifactId>
<version>0.4.2</version>
<version>0.4.3</version>
</dependency>
```

### Gradle

```groovy
compile 'me.jamiemansfield:lorenz:0.4.2'
compile 'me.jamiemansfield:lorenz:0.4.3'
```

You may also find snapshot artifacts on [Sonatype's OSS repository], and for older
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ subprojects {

group = 'me.jamiemansfield'
archivesBaseName = project.name.toLowerCase()
version = '0.4.2'
version = '0.4.3'

repositories {
mavenCentral()
Expand Down
5 changes: 5 additions & 0 deletions changelogs/0.4.3.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Lorenz 0.4.3
============

This version of Lorenz introduces a number of improvements to the Enigma IO classes, namely
fixing support that has been broken under 0.4.x.
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,12 @@
import me.jamiemansfield.lorenz.io.MappingsReader;
import me.jamiemansfield.lorenz.io.TextMappingsReader;
import me.jamiemansfield.lorenz.model.ClassMapping;
import me.jamiemansfield.lorenz.model.Mapping;
import me.jamiemansfield.lorenz.model.MethodMapping;

import java.io.Reader;
import java.util.Stack;
import java.util.ArrayDeque;
import java.util.Deque;
import java.util.stream.Collectors;

/**
Expand Down Expand Up @@ -110,9 +112,7 @@ private static MethodDescriptor handleNonePrefix(final MethodDescriptor descript
);
}

private final Stack<ClassMapping<?>> stack = new Stack<>();
private MethodMapping currentMethod = null;
private int lastIndentLevel = 0;
private final Deque<Mapping<?>> stack = new ArrayDeque<>();

public Processor(final MappingSet mappings) {
super(mappings);
Expand All @@ -126,23 +126,10 @@ public Processor() {
public void accept(final String rawLine) {
final int indentLevel = getIndentLevel(rawLine);

// If there is a change in the indentation level, we will need to alter the
// state as need be.
final int classLevel = indentLevel - (this.currentMethod == null ? 0 : 1);
if (classLevel < this.stack.size()) {
final int difference = this.stack.size() - classLevel;
final int indentDifference = this.lastIndentLevel - indentLevel;

// as the stack is exclusive to classes, don't pop anything when a method
// is the container
if (!(this.currentMethod != null && indentDifference == 1)) {
for (int i = 0; i < difference; i++) {
this.stack.pop();
}
}

// wipe the current method
this.currentMethod = null;
// If there is a change in the indentation level, we will need to pop the stack
// as needed
while (indentLevel < this.stack.size()) {
this.stack.pop();
}

final String line = EnigmaConstants.removeComments(rawLine).trim();
Expand All @@ -168,29 +155,37 @@ else if (key.equals(FIELD_MAPPING_KEY) && len == FIELD_MAPPING_ELEMENT_COUNT) {
final String obfName = split[1];
final String deobfName = split[2];
final String type = handleNonePrefix(FieldType.of(split[3])).toString();
this.stack.peek().getOrCreateFieldMapping(obfName, type)
this.peekClass().getOrCreateFieldMapping(obfName, type)
.setDeobfuscatedName(deobfName);
}
else if (key.equals(METHOD_MAPPING_KEY) && len == METHOD_MAPPING_ELEMENT_WITHOUT_DEOBF_COUNT) {
final String obfName = split[1];
final String descriptor = handleNonePrefix(MethodDescriptor.of(split[2])).toString();
this.currentMethod = this.stack.peek().getOrCreateMethodMapping(obfName, descriptor);
this.stack.push(this.peekClass().getOrCreateMethodMapping(obfName, descriptor));
}
else if (key.equals(METHOD_MAPPING_KEY) && len == METHOD_MAPPING_ELEMENT_WITH_DEOBF_COUNT) {
final String obfName = split[1];
final String deobfName = split[2];
final String descriptor = handleNonePrefix(MethodDescriptor.of(split[3])).toString();
this.currentMethod = this.stack.peek().getOrCreateMethodMapping(obfName, descriptor)
.setDeobfuscatedName(deobfName);
this.stack.push(this.peekClass().getOrCreateMethodMapping(obfName, descriptor)
.setDeobfuscatedName(deobfName));
}
else if (key.equals(PARAM_MAPPING_KEY) && len == PARAM_MAPPING_ELEMENT_COUNT) {
final int index = Integer.parseInt(split[1]);
final String deobfName = split[2];
this.currentMethod.getOrCreateParameterMapping(index)
this.peekMethod().getOrCreateParameterMapping(index)
.setDeobfuscatedName(deobfName);
}
}

protected ClassMapping<?> peekClass() {
if (!(this.stack.peek() instanceof ClassMapping)) throw new UnsupportedOperationException("Not a class on the stack!");
return (ClassMapping<?>) this.stack.peek();
}

this.lastIndentLevel = indentLevel;
protected MethodMapping peekMethod() {
if (!(this.stack.peek() instanceof MethodMapping)) throw new UnsupportedOperationException("Not a method on the stack!");
return (MethodMapping) this.stack.peek();
}

}
Expand Down
8 changes: 7 additions & 1 deletion lorenz/src/test/resources/test.enigma
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,16 @@
CLASS uih uk/jamierocks/CommentTest # CLASS op uk/jr/Operator
CLASS ght uk/jamierocks/Test
CLASS ght$ds Example
CLASS ght$ds$bg Inner
METHOD dup print (I)Z
ARG 0 num
FIELD juh server Luk/jamierocks/Server;
METHOD hyuip isOdd (I)Z
ARG 0 num
CLASS ght$ds$bg Inner
CLASS ght$beep Beep
CLASS ght$beep$boop Boop
METHOD dup print (I)Z
ARG 0 num
FIELD rft log Ljava/util/logging/Logger;
METHOD hyuip isEven (I)Z
ARG 0 num

0 comments on commit dacd559

Please sign in to comment.