diff options
| author | 2019-03-16 09:45:42 +0200 | |
|---|---|---|
| committer | 2019-03-16 09:45:42 +0200 | |
| commit | 19a77fbb472592e116f2f6654657eeec81d40b18 (patch) | |
| tree | e15a39e89887ee8a478ee8c8b7d8cb4b4b64668b /src/main/java/cuchaz/enigma/analysis | |
| parent | Adds a red highlight for overridden methods in method inheritance tree gui (#... (diff) | |
| download | enigma-fork-19a77fbb472592e116f2f6654657eeec81d40b18.tar.gz enigma-fork-19a77fbb472592e116f2f6654657eeec81d40b18.tar.xz enigma-fork-19a77fbb472592e116f2f6654657eeec81d40b18.zip | |
Index lambda local variables to correct declaring method
Diffstat (limited to 'src/main/java/cuchaz/enigma/analysis')
| -rw-r--r-- | src/main/java/cuchaz/enigma/analysis/SourceIndexClassVisitor.java | 11 | ||||
| -rw-r--r-- | src/main/java/cuchaz/enigma/analysis/SourceIndexMethodVisitor.java | 10 |
2 files changed, 12 insertions, 9 deletions
diff --git a/src/main/java/cuchaz/enigma/analysis/SourceIndexClassVisitor.java b/src/main/java/cuchaz/enigma/analysis/SourceIndexClassVisitor.java index a4fe9ee..c977703 100644 --- a/src/main/java/cuchaz/enigma/analysis/SourceIndexClassVisitor.java +++ b/src/main/java/cuchaz/enigma/analysis/SourceIndexClassVisitor.java | |||
| @@ -17,18 +17,15 @@ import com.strobel.assembler.metadata.TypeDefinition; | |||
| 17 | import com.strobel.assembler.metadata.TypeReference; | 17 | import com.strobel.assembler.metadata.TypeReference; |
| 18 | import com.strobel.decompiler.languages.TextLocation; | 18 | import com.strobel.decompiler.languages.TextLocation; |
| 19 | import com.strobel.decompiler.languages.java.ast.*; | 19 | import com.strobel.decompiler.languages.java.ast.*; |
| 20 | import cuchaz.enigma.translation.representation.ProcyonEntryFactory; | ||
| 21 | import cuchaz.enigma.translation.representation.entry.ClassDefEntry; | 20 | import cuchaz.enigma.translation.representation.entry.ClassDefEntry; |
| 22 | import cuchaz.enigma.translation.representation.entry.ClassEntry; | 21 | import cuchaz.enigma.translation.representation.entry.ClassEntry; |
| 23 | import cuchaz.enigma.translation.representation.entry.FieldDefEntry; | 22 | import cuchaz.enigma.translation.representation.entry.FieldDefEntry; |
| 24 | import cuchaz.enigma.translation.representation.entry.MethodDefEntry; | 23 | import cuchaz.enigma.translation.representation.entry.MethodDefEntry; |
| 25 | 24 | ||
| 26 | public class SourceIndexClassVisitor extends SourceIndexVisitor { | 25 | public class SourceIndexClassVisitor extends SourceIndexVisitor { |
| 27 | private final ProcyonEntryFactory entryFactory; | ||
| 28 | private ClassDefEntry classEntry; | 26 | private ClassDefEntry classEntry; |
| 29 | 27 | ||
| 30 | public SourceIndexClassVisitor(ClassDefEntry classEntry) { | 28 | public SourceIndexClassVisitor(ClassDefEntry classEntry) { |
| 31 | this.entryFactory = new ProcyonEntryFactory(); | ||
| 32 | this.classEntry = classEntry; | 29 | this.classEntry = classEntry; |
| 33 | } | 30 | } |
| 34 | 31 | ||
| @@ -60,7 +57,7 @@ public class SourceIndexClassVisitor extends SourceIndexVisitor { | |||
| 60 | @Override | 57 | @Override |
| 61 | public Void visitMethodDeclaration(MethodDeclaration node, SourceIndex index) { | 58 | public Void visitMethodDeclaration(MethodDeclaration node, SourceIndex index) { |
| 62 | MethodDefinition def = node.getUserData(Keys.METHOD_DEFINITION); | 59 | MethodDefinition def = node.getUserData(Keys.METHOD_DEFINITION); |
| 63 | MethodDefEntry methodEntry = entryFactory.getMethodDefEntry(def); | 60 | MethodDefEntry methodEntry = MethodDefEntry.parse(def); |
| 64 | AstNode tokenNode = node.getNameToken(); | 61 | AstNode tokenNode = node.getNameToken(); |
| 65 | if (methodEntry.isConstructor() && methodEntry.getName().equals("<clinit>")) { | 62 | if (methodEntry.isConstructor() && methodEntry.getName().equals("<clinit>")) { |
| 66 | // for static initializers, check elsewhere for the token node | 63 | // for static initializers, check elsewhere for the token node |
| @@ -73,7 +70,7 @@ public class SourceIndexClassVisitor extends SourceIndexVisitor { | |||
| 73 | @Override | 70 | @Override |
| 74 | public Void visitConstructorDeclaration(ConstructorDeclaration node, SourceIndex index) { | 71 | public Void visitConstructorDeclaration(ConstructorDeclaration node, SourceIndex index) { |
| 75 | MethodDefinition def = node.getUserData(Keys.METHOD_DEFINITION); | 72 | MethodDefinition def = node.getUserData(Keys.METHOD_DEFINITION); |
| 76 | MethodDefEntry methodEntry = entryFactory.getMethodDefEntry(def); | 73 | MethodDefEntry methodEntry = MethodDefEntry.parse(def); |
| 77 | index.addDeclaration(node.getNameToken(), methodEntry); | 74 | index.addDeclaration(node.getNameToken(), methodEntry); |
| 78 | return node.acceptVisitor(new SourceIndexMethodVisitor(methodEntry), index); | 75 | return node.acceptVisitor(new SourceIndexMethodVisitor(methodEntry), index); |
| 79 | } | 76 | } |
| @@ -81,7 +78,7 @@ public class SourceIndexClassVisitor extends SourceIndexVisitor { | |||
| 81 | @Override | 78 | @Override |
| 82 | public Void visitFieldDeclaration(FieldDeclaration node, SourceIndex index) { | 79 | public Void visitFieldDeclaration(FieldDeclaration node, SourceIndex index) { |
| 83 | FieldDefinition def = node.getUserData(Keys.FIELD_DEFINITION); | 80 | FieldDefinition def = node.getUserData(Keys.FIELD_DEFINITION); |
| 84 | FieldDefEntry fieldEntry = entryFactory.getFieldDefEntry(def); | 81 | FieldDefEntry fieldEntry = FieldDefEntry.parse(def); |
| 85 | assert (node.getVariables().size() == 1); | 82 | assert (node.getVariables().size() == 1); |
| 86 | VariableInitializer variable = node.getVariables().firstOrNullObject(); | 83 | VariableInitializer variable = node.getVariables().firstOrNullObject(); |
| 87 | index.addDeclaration(variable.getNameToken(), fieldEntry); | 84 | index.addDeclaration(variable.getNameToken(), fieldEntry); |
| @@ -92,7 +89,7 @@ public class SourceIndexClassVisitor extends SourceIndexVisitor { | |||
| 92 | public Void visitEnumValueDeclaration(EnumValueDeclaration node, SourceIndex index) { | 89 | public Void visitEnumValueDeclaration(EnumValueDeclaration node, SourceIndex index) { |
| 93 | // treat enum declarations as field declarations | 90 | // treat enum declarations as field declarations |
| 94 | FieldDefinition def = node.getUserData(Keys.FIELD_DEFINITION); | 91 | FieldDefinition def = node.getUserData(Keys.FIELD_DEFINITION); |
| 95 | FieldDefEntry fieldEntry = entryFactory.getFieldDefEntry(def); | 92 | FieldDefEntry fieldEntry = FieldDefEntry.parse(def); |
| 96 | index.addDeclaration(node.getNameToken(), fieldEntry); | 93 | index.addDeclaration(node.getNameToken(), fieldEntry); |
| 97 | return recurse(node, index); | 94 | return recurse(node, index); |
| 98 | } | 95 | } |
diff --git a/src/main/java/cuchaz/enigma/analysis/SourceIndexMethodVisitor.java b/src/main/java/cuchaz/enigma/analysis/SourceIndexMethodVisitor.java index c4785b6..fde6edf 100644 --- a/src/main/java/cuchaz/enigma/analysis/SourceIndexMethodVisitor.java +++ b/src/main/java/cuchaz/enigma/analysis/SourceIndexMethodVisitor.java | |||
| @@ -101,8 +101,13 @@ public class SourceIndexMethodVisitor extends SourceIndexVisitor { | |||
| 101 | int parameterIndex = def.getSlot(); | 101 | int parameterIndex = def.getSlot(); |
| 102 | 102 | ||
| 103 | if (parameterIndex >= 0) { | 103 | if (parameterIndex >= 0) { |
| 104 | MethodDefEntry ownerMethod = methodEntry; | ||
| 105 | if (def.getMethod() instanceof MethodDefinition) { | ||
| 106 | ownerMethod = MethodDefEntry.parse((MethodDefinition) def.getMethod()); | ||
| 107 | } | ||
| 108 | |||
| 104 | TypeDescriptor parameterType = TypeDescriptor.parse(def.getParameterType()); | 109 | TypeDescriptor parameterType = TypeDescriptor.parse(def.getParameterType()); |
| 105 | LocalVariableDefEntry localVariableEntry = new LocalVariableDefEntry(methodEntry, parameterIndex, node.getName(), true, parameterType); | 110 | LocalVariableDefEntry localVariableEntry = new LocalVariableDefEntry(ownerMethod, parameterIndex, node.getName(), true, parameterType); |
| 106 | Identifier identifier = node.getNameToken(); | 111 | Identifier identifier = node.getNameToken(); |
| 107 | // cache the argument entry and the identifier | 112 | // cache the argument entry and the identifier |
| 108 | identifierEntryCache.put(identifier.getName(), localVariableEntry); | 113 | identifierEntryCache.put(identifier.getName(), localVariableEntry); |
| @@ -170,8 +175,9 @@ public class SourceIndexMethodVisitor extends SourceIndexVisitor { | |||
| 170 | if (originalVariable != null) { | 175 | if (originalVariable != null) { |
| 171 | int variableIndex = originalVariable.getSlot(); | 176 | int variableIndex = originalVariable.getSlot(); |
| 172 | if (variableIndex >= 0) { | 177 | if (variableIndex >= 0) { |
| 178 | MethodDefEntry ownerMethod = MethodDefEntry.parse(originalVariable.getDeclaringMethod()); | ||
| 173 | TypeDescriptor variableType = TypeDescriptor.parse(originalVariable.getVariableType()); | 179 | TypeDescriptor variableType = TypeDescriptor.parse(originalVariable.getVariableType()); |
| 174 | LocalVariableDefEntry localVariableEntry = new LocalVariableDefEntry(methodEntry, variableIndex, initializer.getName(), false, variableType); | 180 | LocalVariableDefEntry localVariableEntry = new LocalVariableDefEntry(ownerMethod, variableIndex, initializer.getName(), false, variableType); |
| 175 | identifierEntryCache.put(identifier.getName(), localVariableEntry); | 181 | identifierEntryCache.put(identifier.getName(), localVariableEntry); |
| 176 | addDeclarationToUnmatched(identifier.getName(), index); | 182 | addDeclarationToUnmatched(identifier.getName(), index); |
| 177 | index.addDeclaration(identifier, localVariableEntry); | 183 | index.addDeclaration(identifier, localVariableEntry); |