summaryrefslogtreecommitdiff
path: root/platform/lang-impl/src/com/intellij/psi/impl/source
diff options
context:
space:
mode:
Diffstat (limited to 'platform/lang-impl/src/com/intellij/psi/impl/source')
-rw-r--r--platform/lang-impl/src/com/intellij/psi/impl/source/PostprocessReformattingAspect.java61
-rw-r--r--platform/lang-impl/src/com/intellij/psi/impl/source/codeStyle/CodeStyleManagerImpl.java3
-rw-r--r--platform/lang-impl/src/com/intellij/psi/impl/source/codeStyle/CodeStyleSchemesImpl.java13
-rw-r--r--platform/lang-impl/src/com/intellij/psi/impl/source/codeStyle/PersistableCodeStyleSchemes.java22
4 files changed, 44 insertions, 55 deletions
diff --git a/platform/lang-impl/src/com/intellij/psi/impl/source/PostprocessReformattingAspect.java b/platform/lang-impl/src/com/intellij/psi/impl/source/PostprocessReformattingAspect.java
index c5b183c3594b..f99d47201a20 100644
--- a/platform/lang-impl/src/com/intellij/psi/impl/source/PostprocessReformattingAspect.java
+++ b/platform/lang-impl/src/com/intellij/psi/impl/source/PostprocessReformattingAspect.java
@@ -56,20 +56,22 @@ import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.TestOnly;
import java.util.*;
-import java.util.concurrent.atomic.AtomicInteger;
public class PostprocessReformattingAspect implements PomModelAspect {
private static final Logger LOG = Logger.getInstance("#com.intellij.psi.impl.source.PostprocessReformattingAspect");
private final Project myProject;
private final PsiManager myPsiManager;
private final TreeAspect myTreeAspect;
- private final Map<FileViewProvider, List<ASTNode>> myReformatElements = new HashMap<FileViewProvider, List<ASTNode>>();
- private volatile int myDisabledCounter = 0;
- private final Set<FileViewProvider> myUpdatedProviders = new HashSet<FileViewProvider>();
- private final AtomicInteger myPostponedCounter = new AtomicInteger();
private static final Key<Throwable> REFORMAT_ORIGINATOR = Key.create("REFORMAT_ORIGINATOR");
private static final boolean STORE_REFORMAT_ORIGINATOR_STACKTRACE = ApplicationManager.getApplication().isInternal();
+ private final ThreadLocal<Context> myContext = new ThreadLocal<Context>() {
+ @Override
+ protected Context initialValue() {
+ return new Context();
+ }
+ };
+
public PostprocessReformattingAspect(Project project, PsiManager psiManager, TreeAspect treeAspect,final CommandProcessor processor) {
myProject = project;
myPsiManager = psiManager;
@@ -113,12 +115,12 @@ public class PostprocessReformattingAspect implements PomModelAspect {
public <T> T disablePostprocessFormattingInside(@NotNull Computable<T> computable) {
try {
- myDisabledCounter++;
+ getContext().myDisabledCounter++;
return computable.compute();
}
finally {
- myDisabledCounter--;
- LOG.assertTrue(myDisabledCounter > 0 || !isDisabled());
+ getContext().myDisabledCounter--;
+ LOG.assertTrue(getContext().myDisabledCounter > 0 || !isDisabled());
}
}
@@ -145,13 +147,13 @@ public class PostprocessReformattingAspect implements PomModelAspect {
}
private void incrementPostponedCounter() {
- myPostponedCounter.incrementAndGet();
+ getContext().myPostponedCounter++;
}
private void decrementPostponedCounter() {
Application application = ApplicationManager.getApplication();
application.assertIsDispatchThread();
- if (myPostponedCounter.decrementAndGet() == 0) {
+ if (--getContext().myPostponedCounter == 0) {
if (application.isWriteAccessAllowed()) {
doPostponedFormatting();
}
@@ -175,7 +177,7 @@ public class PostprocessReformattingAspect implements PomModelAspect {
atomic(new Runnable() {
@Override
public void run() {
- if (isDisabled() || myPostponedCounter.get() == 0 && !ApplicationManager.getApplication().isUnitTestMode()) return;
+ if (isDisabled() || getContext().myPostponedCounter == 0 && !ApplicationManager.getApplication().isUnitTestMode()) return;
final TreeChangeEvent changeSet = (TreeChangeEvent)event.getChangeSet(myTreeAspect);
if (changeSet == null) return;
final PsiElement psiElement = changeSet.getRootElement().getPsi();
@@ -184,7 +186,7 @@ public class PostprocessReformattingAspect implements PomModelAspect {
final FileViewProvider viewProvider = containingFile.getViewProvider();
if (!viewProvider.isEventSystemEnabled()) return;
- myUpdatedProviders.add(viewProvider);
+ getContext().myUpdatedProviders.add(viewProvider);
for (final ASTNode node : changeSet.getChangedElements()) {
final TreeChange treeChange = changeSet.getChangesByElement(node);
for (final ASTNode affectedChild : treeChange.getAffectedChildren()) {
@@ -221,7 +223,7 @@ public class PostprocessReformattingAspect implements PomModelAspect {
public void run() {
if (isDisabled()) return;
try {
- FileViewProvider[] viewProviders = myUpdatedProviders.toArray(new FileViewProvider[myUpdatedProviders.size()]);
+ FileViewProvider[] viewProviders = getContext().myUpdatedProviders.toArray(new FileViewProvider[getContext().myUpdatedProviders.size()]);
for (final FileViewProvider viewProvider : viewProviders) {
doPostponedFormatting(viewProvider);
}
@@ -230,7 +232,7 @@ public class PostprocessReformattingAspect implements PomModelAspect {
LOG.error(e);
}
finally {
- LOG.assertTrue(myReformatElements.isEmpty(), myReformatElements);
+ LOG.assertTrue(getContext().myReformatElements.isEmpty(), getContext().myReformatElements);
}
}
});
@@ -248,7 +250,7 @@ public class PostprocessReformattingAspect implements PomModelAspect {
atomic(new Runnable() {
@Override
public void run() {
- if (isDisabled() || check && !myUpdatedProviders.contains(viewProvider)) return;
+ if (isDisabled() || check && !getContext().myUpdatedProviders.contains(viewProvider)) return;
try {
disablePostprocessFormattingInside(new Runnable() {
@@ -259,8 +261,8 @@ public class PostprocessReformattingAspect implements PomModelAspect {
});
}
finally {
- myUpdatedProviders.remove(viewProvider);
- myReformatElements.remove(viewProvider);
+ getContext().myUpdatedProviders.remove(viewProvider);
+ getContext().myReformatElements.remove(viewProvider);
viewProvider.putUserData(REFORMAT_ORIGINATOR, null);
}
}
@@ -268,7 +270,7 @@ public class PostprocessReformattingAspect implements PomModelAspect {
}
public boolean isViewProviderLocked(@NotNull FileViewProvider fileViewProvider) {
- return myReformatElements.containsKey(fileViewProvider);
+ return getContext().myReformatElements.containsKey(fileViewProvider);
}
public void beforeDocumentChanged(@NotNull FileViewProvider viewProvider) {
@@ -292,10 +294,10 @@ public class PostprocessReformattingAspect implements PomModelAspect {
LOG.assertTrue(oldIndent >= 0,
"for not generated items old indentation must be defined: element=" + child + ", text=" + child.getText());
}
- List<ASTNode> list = myReformatElements.get(viewProvider);
+ List<ASTNode> list = getContext().myReformatElements.get(viewProvider);
if (list == null) {
list = new ArrayList<ASTNode>();
- myReformatElements.put(viewProvider, list);
+ getContext().myReformatElements.put(viewProvider, list);
if (STORE_REFORMAT_ORIGINATOR_STACKTRACE) {
viewProvider.putUserData(REFORMAT_ORIGINATOR, new Throwable());
}
@@ -304,7 +306,7 @@ public class PostprocessReformattingAspect implements PomModelAspect {
}
private void doPostponedFormattingInner(@NotNull FileViewProvider key) {
- final List<ASTNode> astNodes = myReformatElements.remove(key);
+ final List<ASTNode> astNodes = getContext().myReformatElements.remove(key);
final Document document = key.getDocument();
// Sort ranges by end offsets so that we won't need any offset adjustment after reformat or reindent
if (document == null) return;
@@ -370,7 +372,7 @@ public class PostprocessReformattingAspect implements PomModelAspect {
String expectedPsi = treeDebugBuilder.psiToString(psi);
if (!expectedPsi.equals(actualPsiTree)) {
- myReformatElements.clear();
+ getContext().myReformatElements.clear();
assert expectedPsi.equals(actualPsiTree) : "Refactored psi should be the same as result of parsing";
}
}
@@ -627,7 +629,7 @@ public class PostprocessReformattingAspect implements PomModelAspect {
}
public boolean isDisabled() {
- return myDisabledCounter > 0;
+ return getContext().myDisabledCounter > 0;
}
@NotNull
@@ -769,6 +771,17 @@ public class PostprocessReformattingAspect implements PomModelAspect {
@TestOnly
public void clear() {
- myReformatElements.clear();
+ getContext().myReformatElements.clear();
+ }
+
+ private Context getContext() {
+ return myContext.get();
+ }
+
+ private static class Context {
+ private int myPostponedCounter = 0;
+ private int myDisabledCounter = 0;
+ private final Set<FileViewProvider> myUpdatedProviders = new HashSet<FileViewProvider>();
+ private final Map<FileViewProvider, List<ASTNode>> myReformatElements = new HashMap<FileViewProvider, List<ASTNode>>();
}
}
diff --git a/platform/lang-impl/src/com/intellij/psi/impl/source/codeStyle/CodeStyleManagerImpl.java b/platform/lang-impl/src/com/intellij/psi/impl/source/codeStyle/CodeStyleManagerImpl.java
index d51ef1216a59..a9fbe1b4b988 100644
--- a/platform/lang-impl/src/com/intellij/psi/impl/source/codeStyle/CodeStyleManagerImpl.java
+++ b/platform/lang-impl/src/com/intellij/psi/impl/source/codeStyle/CodeStyleManagerImpl.java
@@ -58,8 +58,7 @@ import java.util.List;
import java.util.concurrent.TimeUnit;
public class CodeStyleManagerImpl extends CodeStyleManager {
-
- private static final Logger LOG = Logger.getInstance("#com.intellij.psi.impl.source.codeStyle.CodeStyleManagerImpl");
+ private static final Logger LOG = Logger.getInstance(CodeStyleManagerImpl.class);
private static final ThreadLocal<ProcessingUnderProgressInfo> SEQUENTIAL_PROCESSING_ALLOWED
= new ThreadLocal<ProcessingUnderProgressInfo>()
{
diff --git a/platform/lang-impl/src/com/intellij/psi/impl/source/codeStyle/CodeStyleSchemesImpl.java b/platform/lang-impl/src/com/intellij/psi/impl/source/codeStyle/CodeStyleSchemesImpl.java
index 40ee4adf70f2..b12dee17e9fd 100644
--- a/platform/lang-impl/src/com/intellij/psi/impl/source/codeStyle/CodeStyleSchemesImpl.java
+++ b/platform/lang-impl/src/com/intellij/psi/impl/source/codeStyle/CodeStyleSchemesImpl.java
@@ -13,11 +13,11 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
package com.intellij.psi.impl.source.codeStyle;
import com.intellij.openapi.components.ExportableComponent;
import com.intellij.openapi.components.RoamingType;
+import com.intellij.openapi.components.StoragePathMacros;
import com.intellij.openapi.options.BaseSchemeProcessor;
import com.intellij.openapi.options.SchemeProcessor;
import com.intellij.openapi.options.SchemesManager;
@@ -44,10 +44,10 @@ public abstract class CodeStyleSchemesImpl extends CodeStyleSchemes implements E
public String CURRENT_SCHEME_NAME = DEFAULT_SCHEME_NAME;
private boolean myIsInitialized = false;
- @NonNls static final String CODESTYLES_DIRECTORY = "codestyles";
+ @NonNls static final String CODE_STYLES_DIRECTORY = "codestyles";
private final SchemesManager<CodeStyleScheme, CodeStyleSchemeImpl> mySchemesManager;
- @NonNls private static final String FILE_SPEC = "$ROOT_CONFIG$/" + CODESTYLES_DIRECTORY;
+ @NonNls private static final String FILE_SPEC = StoragePathMacros.ROOT_CONFIG + "/" + CODE_STYLES_DIRECTORY;
public CodeStyleSchemesImpl(SchemesManagerFactory schemesManagerFactory) {
SchemeProcessor<CodeStyleSchemeImpl> processor = new BaseSchemeProcessor<CodeStyleSchemeImpl>() {
@@ -97,6 +97,7 @@ public abstract class CodeStyleSchemesImpl extends CodeStyleSchemes implements E
CURRENT_SCHEME_NAME = schemeName;
}
+ @SuppressWarnings("ForLoopThatDoesntUseLoopVariable")
@Override
public CodeStyleScheme createNewScheme(String preferredName, CodeStyleScheme parentScheme) {
String name;
@@ -154,10 +155,6 @@ public abstract class CodeStyleSchemesImpl extends CodeStyleSchemes implements E
mySchemesManager.addNewScheme(scheme, true);
}
- protected void removeScheme(CodeStyleScheme scheme) {
- mySchemesManager.removeScheme(scheme);
- }
-
protected void init() {
if (myIsInitialized) return;
myIsInitialized = true;
@@ -173,6 +170,4 @@ public abstract class CodeStyleSchemesImpl extends CodeStyleSchemes implements E
public SchemesManager<CodeStyleScheme, CodeStyleSchemeImpl> getSchemesManager() {
return mySchemesManager;
}
-
-
}
diff --git a/platform/lang-impl/src/com/intellij/psi/impl/source/codeStyle/PersistableCodeStyleSchemes.java b/platform/lang-impl/src/com/intellij/psi/impl/source/codeStyle/PersistableCodeStyleSchemes.java
index 3e2acf553815..e3f4fb760fbf 100644
--- a/platform/lang-impl/src/com/intellij/psi/impl/source/codeStyle/PersistableCodeStyleSchemes.java
+++ b/platform/lang-impl/src/com/intellij/psi/impl/source/codeStyle/PersistableCodeStyleSchemes.java
@@ -18,8 +18,6 @@ package com.intellij.psi.impl.source.codeStyle;
import com.intellij.openapi.application.PathManager;
import com.intellij.openapi.components.*;
import com.intellij.openapi.options.SchemesManagerFactory;
-import com.intellij.openapi.ui.Messages;
-import com.intellij.psi.PsiBundle;
import com.intellij.psi.codeStyle.CodeStyleScheme;
import com.intellij.util.xmlb.Accessor;
import com.intellij.util.xmlb.SerializationFilter;
@@ -99,23 +97,7 @@ public class PersistableCodeStyleSchemes extends CodeStyleSchemesImpl implements
@Override
@NotNull
public File[] getExportFiles() {
- File schemesFile = new File(PathManager.getOptionsPath() + File.separator + CODE_STYLE_SCHEMES_FILE);
- return new File[]{getDir(true), schemesFile};
+ return new File[]{new File(PathManager.getConfigPath() + File.separator + CODE_STYLES_DIRECTORY),
+ new File(PathManager.getOptionsPath() + File.separator + CODE_STYLE_SCHEMES_FILE)};
}
-
- @Nullable
- private static File getDir(boolean create) {
- String directoryPath = PathManager.getConfigPath() + File.separator + CODESTYLES_DIRECTORY;
- File directory = new File(directoryPath);
- if (!directory.exists()) {
- if (!create) return null;
- if (!directory.mkdir()) {
- Messages.showErrorDialog(PsiBundle.message("codestyle.cannot.save.settings.directory.cant.be.created.message", directoryPath),
- PsiBundle.message("codestyle.cannot.save.settings.directory.cant.be.created.title"));
- return null;
- }
- }
- return directory;
- }
-
}