diff options
| author | 2019-03-16 09:45:42 +0200 | |
|---|---|---|
| committer | 2019-03-16 09:45:42 +0200 | |
| commit | 19a77fbb472592e116f2f6654657eeec81d40b18 (patch) | |
| tree | e15a39e89887ee8a478ee8c8b7d8cb4b4b64668b /src | |
| parent | Adds a red highlight for overridden methods in method inheritance tree gui (#... (diff) | |
| download | enigma-19a77fbb472592e116f2f6654657eeec81d40b18.tar.gz enigma-19a77fbb472592e116f2f6654657eeec81d40b18.tar.xz enigma-19a77fbb472592e116f2f6654657eeec81d40b18.zip | |
Index lambda local variables to correct declaring method
Diffstat (limited to 'src')
5 files changed, 30 insertions, 48 deletions
diff --git a/src/main/java/cuchaz/enigma/analysis/SourceIndexClassVisitor.java b/src/main/java/cuchaz/enigma/analysis/SourceIndexClassVisitor.java index a4fe9ee9..c9777030 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 c4785b67..fde6edf9 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); |
diff --git a/src/main/java/cuchaz/enigma/translation/representation/ProcyonEntryFactory.java b/src/main/java/cuchaz/enigma/translation/representation/ProcyonEntryFactory.java deleted file mode 100644 index a9ec5fac..00000000 --- a/src/main/java/cuchaz/enigma/translation/representation/ProcyonEntryFactory.java +++ /dev/null | |||
| @@ -1,39 +0,0 @@ | |||
| 1 | /******************************************************************************* | ||
| 2 | * Copyright (c) 2015 Jeff Martin. | ||
| 3 | * All rights reserved. This program and the accompanying materials | ||
| 4 | * are made available under the terms of the GNU Lesser General Public | ||
| 5 | * License v3.0 which accompanies this distribution, and is available at | ||
| 6 | * http://www.gnu.org/licenses/lgpl.html | ||
| 7 | * <p> | ||
| 8 | * Contributors: | ||
| 9 | * Jeff Martin - initial API and implementation | ||
| 10 | ******************************************************************************/ | ||
| 11 | |||
| 12 | package cuchaz.enigma.translation.representation; | ||
| 13 | |||
| 14 | import com.strobel.assembler.metadata.FieldDefinition; | ||
| 15 | import com.strobel.assembler.metadata.MemberReference; | ||
| 16 | import com.strobel.assembler.metadata.MethodDefinition; | ||
| 17 | import cuchaz.enigma.translation.representation.entry.*; | ||
| 18 | |||
| 19 | public class ProcyonEntryFactory { | ||
| 20 | public FieldEntry getFieldEntry(MemberReference def) { | ||
| 21 | ClassEntry classEntry = new ClassEntry(def.getDeclaringType().getInternalName()); | ||
| 22 | return new FieldEntry(classEntry, def.getName(), new TypeDescriptor(def.getErasedSignature())); | ||
| 23 | } | ||
| 24 | |||
| 25 | public FieldDefEntry getFieldDefEntry(FieldDefinition def) { | ||
| 26 | ClassEntry classEntry = new ClassEntry(def.getDeclaringType().getInternalName()); | ||
| 27 | return new FieldDefEntry(classEntry, def.getName(), new TypeDescriptor(def.getErasedSignature()), Signature.createTypedSignature(def.getSignature()), new AccessFlags(def.getModifiers())); | ||
| 28 | } | ||
| 29 | |||
| 30 | public MethodEntry getMethodEntry(MemberReference def) { | ||
| 31 | ClassEntry classEntry = new ClassEntry(def.getDeclaringType().getInternalName()); | ||
| 32 | return new MethodEntry(classEntry, def.getName(), new MethodDescriptor(def.getErasedSignature())); | ||
| 33 | } | ||
| 34 | |||
| 35 | public MethodDefEntry getMethodDefEntry(MethodDefinition def) { | ||
| 36 | ClassEntry classEntry = new ClassEntry(def.getDeclaringType().getInternalName()); | ||
| 37 | return new MethodDefEntry(classEntry, def.getName(), new MethodDescriptor(def.getErasedSignature()), Signature.createSignature(def.getSignature()), new AccessFlags(def.getModifiers())); | ||
| 38 | } | ||
| 39 | } | ||
diff --git a/src/main/java/cuchaz/enigma/translation/representation/entry/FieldDefEntry.java b/src/main/java/cuchaz/enigma/translation/representation/entry/FieldDefEntry.java index 27033015..74176fda 100644 --- a/src/main/java/cuchaz/enigma/translation/representation/entry/FieldDefEntry.java +++ b/src/main/java/cuchaz/enigma/translation/representation/entry/FieldDefEntry.java | |||
| @@ -12,6 +12,7 @@ | |||
| 12 | package cuchaz.enigma.translation.representation.entry; | 12 | package cuchaz.enigma.translation.representation.entry; |
| 13 | 13 | ||
| 14 | import com.google.common.base.Preconditions; | 14 | import com.google.common.base.Preconditions; |
| 15 | import com.strobel.assembler.metadata.FieldDefinition; | ||
| 15 | import cuchaz.enigma.translation.Translator; | 16 | import cuchaz.enigma.translation.Translator; |
| 16 | import cuchaz.enigma.translation.mapping.EntryMapping; | 17 | import cuchaz.enigma.translation.mapping.EntryMapping; |
| 17 | import cuchaz.enigma.translation.representation.AccessFlags; | 18 | import cuchaz.enigma.translation.representation.AccessFlags; |
| @@ -36,6 +37,14 @@ public class FieldDefEntry extends FieldEntry implements DefEntry<ClassEntry> { | |||
| 36 | return new FieldDefEntry(owner, name, new TypeDescriptor(desc), Signature.createTypedSignature(signature), new AccessFlags(access)); | 37 | return new FieldDefEntry(owner, name, new TypeDescriptor(desc), Signature.createTypedSignature(signature), new AccessFlags(access)); |
| 37 | } | 38 | } |
| 38 | 39 | ||
| 40 | public static FieldDefEntry parse(FieldDefinition definition) { | ||
| 41 | ClassEntry owner = ClassEntry.parse(definition.getDeclaringType()); | ||
| 42 | TypeDescriptor descriptor = new TypeDescriptor(definition.getErasedSignature()); | ||
| 43 | Signature signature = Signature.createTypedSignature(definition.getSignature()); | ||
| 44 | AccessFlags access = new AccessFlags(definition.getModifiers()); | ||
| 45 | return new FieldDefEntry(owner, definition.getName(), descriptor, signature, access); | ||
| 46 | } | ||
| 47 | |||
| 39 | @Override | 48 | @Override |
| 40 | public AccessFlags getAccess() { | 49 | public AccessFlags getAccess() { |
| 41 | return access; | 50 | return access; |
diff --git a/src/main/java/cuchaz/enigma/translation/representation/entry/MethodDefEntry.java b/src/main/java/cuchaz/enigma/translation/representation/entry/MethodDefEntry.java index 51842443..bbcaf235 100644 --- a/src/main/java/cuchaz/enigma/translation/representation/entry/MethodDefEntry.java +++ b/src/main/java/cuchaz/enigma/translation/representation/entry/MethodDefEntry.java | |||
| @@ -12,6 +12,7 @@ | |||
| 12 | package cuchaz.enigma.translation.representation.entry; | 12 | package cuchaz.enigma.translation.representation.entry; |
| 13 | 13 | ||
| 14 | import com.google.common.base.Preconditions; | 14 | import com.google.common.base.Preconditions; |
| 15 | import com.strobel.assembler.metadata.MethodDefinition; | ||
| 15 | import cuchaz.enigma.translation.Translator; | 16 | import cuchaz.enigma.translation.Translator; |
| 16 | import cuchaz.enigma.translation.mapping.EntryMapping; | 17 | import cuchaz.enigma.translation.mapping.EntryMapping; |
| 17 | import cuchaz.enigma.translation.representation.AccessFlags; | 18 | import cuchaz.enigma.translation.representation.AccessFlags; |
| @@ -36,6 +37,14 @@ public class MethodDefEntry extends MethodEntry implements DefEntry<ClassEntry> | |||
| 36 | return new MethodDefEntry(owner, name, new MethodDescriptor(desc), Signature.createSignature(signature), new AccessFlags(access)); | 37 | return new MethodDefEntry(owner, name, new MethodDescriptor(desc), Signature.createSignature(signature), new AccessFlags(access)); |
| 37 | } | 38 | } |
| 38 | 39 | ||
| 40 | public static MethodDefEntry parse(MethodDefinition definition) { | ||
| 41 | ClassEntry classEntry = ClassEntry.parse(definition.getDeclaringType()); | ||
| 42 | MethodDescriptor descriptor = new MethodDescriptor(definition.getErasedSignature()); | ||
| 43 | Signature signature = Signature.createSignature(definition.getSignature()); | ||
| 44 | AccessFlags access = new AccessFlags(definition.getModifiers()); | ||
| 45 | return new MethodDefEntry(classEntry, definition.getName(), descriptor, signature, access); | ||
| 46 | } | ||
| 47 | |||
| 39 | @Override | 48 | @Override |
| 40 | public AccessFlags getAccess() { | 49 | public AccessFlags getAccess() { |
| 41 | return access; | 50 | return access; |