Skip to content

Commit d166e04

Browse files
authored
Merge pull request #2439 from Haehnchen/feature/access-bundle-lookup
Fix read thread access of bundle files lookup rendering
2 parents 4dba4c3 + ccaeba9 commit d166e04

File tree

2 files changed

+23
-19
lines changed

2 files changed

+23
-19
lines changed

src/main/java/fr/adrienbrault/idea/symfony2plugin/util/dict/SymfonyBundle.java

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@ public class SymfonyBundle {
1616
@NotNull
1717
final private PhpClass phpClass;
1818

19+
@NotNull
20+
final private String phpClassName;
21+
22+
@NotNull
23+
private final String phpClassNameNamespaceName;
24+
1925
@NotNull
2026
public PhpClass getPhpClass() {
2127
return this.phpClass;
@@ -28,11 +34,14 @@ public String getNamespaceName() {
2834

2935
@NotNull
3036
public String getName() {
31-
return this.phpClass.getName();
37+
return this.phpClassName;
3238
}
3339

3440
public SymfonyBundle(@NotNull PhpClass phpClass) {
3541
this.phpClass = phpClass;
42+
43+
this.phpClassName = this.phpClass.getName();
44+
this.phpClassNameNamespaceName = this.phpClass.getNamespaceName();
3645
}
3746

3847
@Nullable
@@ -41,12 +50,7 @@ public PsiDirectory getDirectory() {
4150
return null;
4251
}
4352

44-
PsiDirectory bundleDirectory = this.phpClass.getContainingFile().getContainingDirectory();
45-
if(null == bundleDirectory) {
46-
return null;
47-
}
48-
49-
return bundleDirectory;
53+
return this.phpClass.getContainingFile().getContainingDirectory();
5054
}
5155

5256
@Nullable
@@ -78,7 +82,7 @@ public String getRelativePath(@NotNull VirtualFile file) {
7882
}
7983

8084
public boolean isInBundle(@NotNull PhpClass phpClass) {
81-
return phpClass.getNamespaceName().startsWith(this.phpClass.getNamespaceName());
85+
return phpClass.getNamespaceName().startsWith(this.phpClassNameNamespaceName);
8286
}
8387

8488
public boolean isInBundle(@NotNull PsiFile psiFile) {

src/main/java/fr/adrienbrault/idea/symfony2plugin/util/dict/SymfonyBundleFileLookupElement.java

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,21 @@
66
import com.intellij.codeInsight.lookup.LookupElementPresentation;
77
import com.intellij.util.IconUtil;
88
import org.jetbrains.annotations.NotNull;
9+
import org.jetbrains.annotations.Nullable;
910

1011
/**
1112
* @author Daniel Espendiller <daniel@espendiller.net>
1213
*/
1314
public class SymfonyBundleFileLookupElement extends LookupElement {
14-
15+
private final @NotNull String bundleName;
1516
private final BundleFile bundleFile;
1617
private InsertHandler<LookupElement> insertHandler = null;
18+
private final @Nullable String shortcutName;
1719

1820
public SymfonyBundleFileLookupElement(BundleFile bundleFile) {
1921
this.bundleFile = bundleFile;
22+
this.shortcutName = bundleFile.getShortcutPath();
23+
this.bundleName = bundleFile.getSymfonyBundle().getName();
2024
}
2125

2226
public SymfonyBundleFileLookupElement(BundleFile bundleFile, InsertHandler<LookupElement> insertHandler) {
@@ -27,23 +31,21 @@ public SymfonyBundleFileLookupElement(BundleFile bundleFile, InsertHandler<Looku
2731
@NotNull
2832
@Override
2933
public String getLookupString() {
30-
String shortcutName = this.bundleFile.getShortcutPath();
31-
if(shortcutName == null) {
34+
if (shortcutName == null) {
3235
return "";
3336
}
3437

3538
// we strip any control char, so only use the pathname
36-
if(shortcutName.startsWith("@")) {
37-
shortcutName = shortcutName.substring(1);
39+
if (shortcutName.startsWith("@")) {
40+
return shortcutName.substring(1);
3841
}
3942

4043
return shortcutName;
4144
}
4245

4346
@Override
44-
public void handleInsert(InsertionContext context) {
45-
46-
if(this.insertHandler != null) {
47+
public void handleInsert(@NotNull InsertionContext context) {
48+
if (this.insertHandler != null) {
4749
this.insertHandler.handleInsert(context, this);
4850
return;
4951
}
@@ -53,10 +55,8 @@ public void handleInsert(InsertionContext context) {
5355

5456
public void renderElement(LookupElementPresentation presentation) {
5557
presentation.setItemText(getLookupString());
56-
presentation.setTypeText(this.bundleFile.getSymfonyBundle().getName());
58+
presentation.setTypeText(bundleName);
5759
presentation.setTypeGrayed(true);
5860
presentation.setIcon(IconUtil.getIcon(this.bundleFile.getVirtualFile(), 0, this.bundleFile.getProject()));
59-
6061
}
61-
6262
}

0 commit comments

Comments
 (0)