IDEA-166101 Imports Added for Classes in Same Package

master
Egor.Ushakov 8 years ago
parent a7654eb8c9
commit fe5260df8a
  1. 37
      src/org/jetbrains/java/decompiler/main/collectors/ImportCollector.java
  2. 35
      testData/results/InvalidMethodSignature.dec

@ -1,5 +1,5 @@
/*
* Copyright 2000-2016 JetBrains s.r.o.
* Copyright 2000-2017 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -21,7 +21,7 @@ import org.jetbrains.java.decompiler.main.TextBuffer;
import org.jetbrains.java.decompiler.struct.StructContext;
import java.util.*;
import java.util.Map.Entry;
import java.util.stream.Collectors;
public class ImportCollector {
private static final String JAVA_LANG_PACKAGE = "java.lang";
@ -124,26 +124,17 @@ public class ImportCollector {
}
private List<String> packImports() {
List<Entry<String, String>> lst = new ArrayList<>(mapSimpleNames.entrySet());
Collections.sort(lst, (par0, par1) -> {
int res = par0.getValue().compareTo(par1.getValue());
if (res == 0) {
res = par0.getKey().compareTo(par1.getKey());
}
return res;
});
List<String> res = new ArrayList<>();
for (Entry<String, String> ent : lst) {
// exclude a current class or one of the nested ones, java.lang and empty packages
if (!setNotImportedNames.contains(ent.getKey()) &&
!JAVA_LANG_PACKAGE.equals(ent.getValue()) &&
!ent.getValue().isEmpty()) {
res.add(ent.getValue() + "." + ent.getKey());
}
}
return res;
return mapSimpleNames.entrySet().stream()
.filter(ent ->
// exclude the current class or one of the nested ones
// empty, java.lang and the current packages
!setNotImportedNames.contains(ent.getKey()) &&
!ent.getValue().isEmpty() &&
!JAVA_LANG_PACKAGE.equals(ent.getValue()) &&
!ent.getValue().equals(currentPackagePoint)
)
.sorted(Map.Entry.<String, String>comparingByValue().thenComparing(Map.Entry.comparingByKey()))
.map(ent -> ent.getValue() + "." + ent.getKey())
.collect(Collectors.toList());
}
}

@ -4,7 +4,6 @@ import a.a.a.a.a.k;
import a.a.a.a.c.c;
import a.a.a.a.c.j;
import a.a.a.a.e.bg;
import a.a.a.a.e.f.b;
import java.io.File;
class i implements bg {
@ -27,30 +26,30 @@ class i implements bg {
class 'a/a/a/a/e/f/i' {
method '<init> (La/a/a/a/e/f/b;La/a/a/a/c/j;)V' {
2 14
7 15
e 16
2 13
7 14
e 15
}
method 'a (La/a/a/a/c/c;La/a/a/a/a/k;Z)V' {
1 19
4 19
a 19
f 19
12 20
15 20
1a 20
20 21
1 18
4 18
a 18
f 18
12 19
15 19
1a 19
20 20
}
method 'a (La/a/a/a/c/b;)V' {
0 24
0 23
}
}
Lines mapping:
0 <-> 25
1 <-> 15
2 <-> 20
3 <-> 21
4 <-> 22
0 <-> 24
1 <-> 14
2 <-> 19
3 <-> 20
4 <-> 21

Loading…
Cancel
Save