8000 #1730 TwigPath dont sort via class comparable and dont use clone for … · SylApps/idea-php-symfony2-plugin@cae832a · GitHub
[go: up one dir, main page]

Skip to content

Commit cae832a

Browse files
committed
Haehnchen#1730 TwigPath dont sort via class comparable and dont use clone for being cached elements
1 parent 49a0fbe commit cae832a

File tree

3 files changed

+25
-25
lines changed

3 files changed

+25
-25
lines changed

src/main/java/fr/adrienbrault/idea/symfony2plugin/templating/path/TwigPath.java

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,13 @@
1010
import org.jetbrains.annotations.Nullable;
1111

1212
import java.io.File;
13-
import java.text.Collator;
1413

1514
/**
1615
* @author Daniel Espendiller <daniel@espendiller.net>
1716
*/
18-
public class TwigPath implements Comparable<TwigPath> {
17+
public class TwigPath {
1918
@NotNull
20-
private String path;
19+
private final String path;
2120

2221
@NotNull
2322
private String namespace = TwigUtil.MAIN;
@@ -47,17 +46,16 @@ public TwigPath(@NotNull String path, @NotNull String namespace, @NotNull TwigUt
4746
this.customPath = customPath;
4847
}
4948

50-
@Override
51-
public TwigPath clone() {
52-
try {
53-
super.clone();
54-
} catch (CloneNotSupportedException ignored) {
55-
}
56-
57-
TwigPath twigPath = new TwigPath(this.getPath(), this.getNamespace(), this.getNamespaceType(), this.isCustomPath());
58-
twigPath.setEnabled(this.isEnabled());
49+
public static TwigPath createClone(@NotNull TwigPath twigPath) {
50+
TwigPath newTwigPath = new TwigPath(
51+
twigPath.getPath(),
52+
twigPath.getNamespace(),
53+
twigPath.getNamespaceType(),
54+
twigPath.isCustomPath()
55+
);
5956

60-
return twigPath;
57+
newTwigPath.setEnabled(twigPath.isEnabled());
58+
return newTwigPath;
6159
}
6260

6361
public TwigPath(@NotNull String path, @NotNull String namespace, @NotNull TwigUtil.NamespaceType namespaceType) {
@@ -129,13 +127,6 @@ private VirtualFile getDirectory() {
129127
return VfsUtil.findFileByIoFile(file, true);
130128
}
131129

132-
@Override
133-
public int compareTo(@NotNull TwigPath twigPath) {
134-
Collator collator = Collator.getInstance();
135-
collator.setStrength(Collator.SECONDARY);
136-
return collator.compare(this.getNamespace(), twigPath.getNamespace());
137-
}
138-
139130
public boolean isCustomPath() {
140131
return customPath;
141132
}

src/main/java/fr/adrienbrault/ide 8000 a/symfony2plugin/templating/util/TwigUtil.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@
6666
import org.jetbrains.yaml.psi.*;
6767

6868
import java.io.File;
69+
import java.text.Collator;
6970
import java.util.*;
7071
import java.util.regex.Matcher;
7172
import java.util.regex.Pattern;
@@ -116,6 +117,15 @@ public enum NamespaceType {
116117

117118
public static String TEMPLATE_ANNOTATION_CLASS = "\\Sensio\\Bundle\\FrameworkExtraBundle\\Configuration\\Template";
118119

120+
public static class TwigPathNamespaceComparator implements Comparator<TwigPath> {
121+
@Override
122+
public int compare(TwigPath o1, TwigPath o2) {
123+
Collator collator = Collator.getInstance();
124+
collator.setStrength(Collator.SECONDARY);
125+
return collator.compare(o1.getNamespace(), o2.getNamespace());
126+
}
127+
}
128+
119129
@NotNull
120130
public static String[] getControllerMethodShortcut(@NotNull Method method) {
121131
// indexAction

src/main/java/fr/adrienbrault/idea/symfony2plugin/ui/TwigSettingsForm.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
import java.awt.event.MouseAdapter;
2323
import java.awt.event.MouseEvent;
2424
import java.util.ArrayList;
25-
import java.util.Collections;
2625
import java.util.List;
2726

2827
/**
@@ -59,11 +58,11 @@ private void attachItems() {
5958
}
6059

6160
67E6 List<TwigPath> sortableLookupItems = new ArrayList<>(TwigUtil.getTwigNamespaces(this.project, true));
62-
Collections.sort(sortableLookupItems);
61+
sortableLookupItems.sort(new TwigUtil.TwigPathNamespaceComparator());
6362

6463
for (TwigPath twigPath : sortableLookupItems) {
6564
// dont use managed class here
66-
this.modelList.addRow(twigPath.clone());
65+
this.modelList.addRow(TwigPath.createClone(twigPath));
6766
}
6867
}
6968

@@ -105,12 +104,12 @@ public void mouseClicked(MouseEvent e) {
105104
TwigSettingsForm.this.resetList();
106105

107106
List<TwigPath> sortableLookupItems = new ArrayList<>(TwigUtil.getTwigNamespaces(TwigSettingsForm.this.project, false));
108-
Collections.sort(sortableLookupItems);
107+
sortableLookupItems.sort(new TwigUtil.TwigPathNamespaceComparator());
109108

110109
for (TwigPath twigPath : sortableLookupItems) {
111110
// dont use managed class here
112111
// @TODO state to enabled (should not be here)
113-
TwigSettingsForm.this.modelList.addRow(twigPath.clone().setEnabled(true));
112+
TwigSettingsForm.this.modelList.addRow(TwigPath.createClone(twigPath).setEnabled(true));
114113
}
115114
}
116115
});

0 commit comments

Comments
 (0)
0