Skip to content

Commit

Permalink
Don't save overriding method mappings, fix parameters not always saving
Browse files Browse the repository at this point in the history
  • Loading branch information
Runemoro committed Jan 27, 2019
1 parent d65e9d0 commit 96b75a5
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 8 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ plugins {
}

group 'org.dimdev'
version '1.0.3'
version '1.0.4'

sourceCompatibility = 1.8

Expand Down
18 changes: 13 additions & 5 deletions src/main/java/org/dimdev/knit/RenameHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public void handleRename(String oldName, PsiElement element) {
if (element instanceof PsiMethod) {
PsiMethod method = (PsiMethod) element;

if (method.isConstructor()) {
if (method.findSuperMethods().length > 0 || method.isConstructor()) {
return;
}

Expand All @@ -57,13 +57,19 @@ public void handleRename(String oldName, PsiElement element) {
PsiParameter parameter = (PsiParameter) element;

PsiElement declarationScope = parameter.getDeclarationScope();
if (declarationScope instanceof PsiMethod) {
MethodMapping mapping = getOrCreateMethodMapping((PsiMethod) declarationScope, ((PsiMethod) declarationScope).getName());
if (!(declarationScope instanceof PsiMethod)) {
return;
}
PsiMethod method = (PsiMethod) declarationScope;

for (PsiMethod superMethod : method.findDeepestSuperMethods()) {
ClassMapping classMapping = getOrCreateClassMapping(getClassName(method.getContainingClass()));
MethodMapping mapping = getOrCreateMethodMapping(superMethod, superMethod.getName());

if (mapping != null) {
int index = ((PsiMethod) declarationScope).hasModifier(JvmModifier.STATIC) ? 0 : 1;
int index = superMethod.hasModifier(JvmModifier.STATIC) ? 0 : 1;
boolean found = false;
for (PsiParameter currentParameter : ((PsiMethod) declarationScope).getParameterList().getParameters()) {
for (PsiParameter currentParameter : superMethod.getParameterList().getParameters()) {
if (currentParameter.equals(parameter)) {
found = true;
break;
Expand All @@ -75,6 +81,8 @@ public void handleRename(String oldName, PsiElement element) {
mapping.setLocalVariableName(index, parameter.getName());
}
}

classMapping.markDirty();
}
}
}
Expand Down
9 changes: 7 additions & 2 deletions src/main/resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@
<h3>Setting up Minecraft sources</h3>
<ol>
<li>Set up a gradle project with <a href="https://paste.dimdev.org/raw/yoxamudixi">this build.gradle (last updated for 18w50a)</a>.</li>
<li>Set up a gradle project with <a href="https://paste.dimdev.org/raw/yoxamudixi">this build.gradle</a>.</li>
<li>Export source code from enigma to src/main/java</li>
<li>Open the project in IntelliJ with the plugin installed</li>
<li>Move all classes in the default package to a new package named "nopackage" (can't be named something else)</li>
<li>Do a regex find-replace (Ctrl-Shift-R, check "Regex") and replace "\n\nimport" with "\n\nimport nopackage;\nimport"</li>
<li>Do a regex find-replace (Ctrl-Shift-R, check "Regex") and replace "\\n\\nimport" with "\\n\\nimport nopackage;\\nimport"</li>
</ol>
<h3>Enabling remapping</h3>
Expand All @@ -41,6 +41,11 @@

<change-notes>
<![CDATA[
<b>1.0.4</b>
<ul>
<li>Updated to new mapping format (don't save overriding mappings)</li>
<li>Fixed parameter names not being saved when method not renamed</li>
</ul>
<b>1.0.3</b>
<ul>
<li>Fixed bugs related to nested classes</li>
Expand Down

0 comments on commit 96b75a5

Please sign in to comment.