EA-64538 (read action)
authorRoman Shevchenko <roman.shevchenko@jetbrains.com>
Sun, 8 Feb 2015 09:27:38 +0000 (10:27 +0100)
committerRoman Shevchenko <roman.shevchenko@jetbrains.com>
Sun, 8 Feb 2015 09:27:38 +0000 (10:27 +0100)
plugins/properties/properties-psi-impl/src/com/intellij/lang/properties/BundleNameEvaluator.java

index 52b57238d1382fe0189c0624b4be544d9ee9c2af..923a48b9c9285389c69f9afd25fa5e51393222d6 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2000-2014 JetBrains s.r.o.
+ * Copyright 2000-2015 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.
  */
 package com.intellij.lang.properties;
 
+import com.intellij.openapi.application.ApplicationManager;
+import com.intellij.openapi.util.Computable;
 import com.intellij.psi.PsiDirectory;
 import com.intellij.psi.PsiFile;
 import org.jetbrains.annotations.Nullable;
 
 public interface BundleNameEvaluator {
-
   BundleNameEvaluator DEFAULT = new BundleNameEvaluator() {
-
     @Nullable
     public String evaluateBundleName(final PsiFile psiFile) {
-      final PsiDirectory directory = psiFile.getParent();
-      if (directory == null) {
-        return null;
-      }
+      PsiDirectory directory = ApplicationManager.getApplication().runReadAction(new Computable<PsiDirectory>() {
+        @Override
+        public PsiDirectory compute() {
+          return psiFile.getParent();
+        }
+      });
+      if (directory == null) return null;
 
-      final String packageQualifiedName = PropertiesUtil.getPackageQualifiedName(directory);
+      String packageQualifiedName = PropertiesUtil.getPackageQualifiedName(directory);
+      if (packageQualifiedName == null) return null;
 
-      if (packageQualifiedName != null) {
-        final StringBuilder qName = new StringBuilder(packageQualifiedName);
-        if (qName.length() > 0) {
-          qName.append(".");
-        }
-        qName.append(ResourceBundleManager.getInstance(psiFile.getProject()).getBaseName(psiFile));
-        return qName.toString();
-      }
-      return null;
+      StringBuilder qName = new StringBuilder(packageQualifiedName);
+      if (qName.length() > 0) qName.append(".");
+      qName.append(ResourceBundleManager.getInstance(psiFile.getProject()).getBaseName(psiFile));
+      return qName.toString();
     }
   };