From 6a4fa2b56c4ea52767af31afa8933f05f6548f6a Mon Sep 17 00:00:00 2001 From: Alexey Kudravtsev Date: Thu, 26 Jun 2014 15:12:58 +0400 Subject: [PATCH 1/5] cleanup --- .../openapi/vfs/impl/FilePointerPartNode.java | 8 ++++---- .../impl/VirtualFilePointerManagerImpl.java | 19 +++++++++---------- 2 files changed, 13 insertions(+), 14 deletions(-) diff --git a/platform/platform-impl/src/com/intellij/openapi/vfs/impl/FilePointerPartNode.java b/platform/platform-impl/src/com/intellij/openapi/vfs/impl/FilePointerPartNode.java index e3821821b8a7..d72696664117 100644 --- a/platform/platform-impl/src/com/intellij/openapi/vfs/impl/FilePointerPartNode.java +++ b/platform/platform-impl/src/com/intellij/openapi/vfs/impl/FilePointerPartNode.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2012 JetBrains s.r.o. + * Copyright 2000-2014 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. @@ -57,7 +57,7 @@ class FilePointerPartNode { } boolean getPointersUnder(@NotNull String path, int start, @NotNull List out) { - checkStructure(); + checkConsistency(); if (pointersUnder == 0) return false; // invariant: upper nodes are matched int index = indexOfFirstDifferentChar(path, start); @@ -76,12 +76,12 @@ class FilePointerPartNode { return false; } - void checkStructure() { + void checkConsistency() { if (!DEBUG) return; int childSum = 0; for (FilePointerPartNode child : children) { childSum += child.pointersUnder; - child.checkStructure(); + child.checkConsistency(); assert child.parent == this; } if (leaf != null) childSum++; diff --git a/platform/platform-impl/src/com/intellij/openapi/vfs/impl/VirtualFilePointerManagerImpl.java b/platform/platform-impl/src/com/intellij/openapi/vfs/impl/VirtualFilePointerManagerImpl.java index ed10fba51e59..e94354d16d0b 100644 --- a/platform/platform-impl/src/com/intellij/openapi/vfs/impl/VirtualFilePointerManagerImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/vfs/impl/VirtualFilePointerManagerImpl.java @@ -37,7 +37,6 @@ import com.intellij.util.containers.ContainerUtil; import com.intellij.util.io.URLUtil; import com.intellij.util.messages.MessageBus; import gnu.trove.THashMap; -import gnu.trove.TObjectHashingStrategy; import gnu.trove.TObjectIntHashMap; import gnu.trove.TObjectIntProcedure; import org.jetbrains.annotations.NonNls; @@ -196,7 +195,7 @@ public class VirtualFilePointerManagerImpl extends VirtualFilePointerManager imp String path; if (file == null) { - path = protocolEnd == -1 ? url : url.substring(protocolEnd + URLUtil.SCHEME_SEPARATOR.length()); + path = url.substring(protocolEnd + URLUtil.SCHEME_SEPARATOR.length()); String cleanPath = cleanupPath(path, isJar); // if newly created path is the same as substringed one then the url did not change, we can reuse it //noinspection StringEquality @@ -263,7 +262,7 @@ public class VirtualFilePointerManagerImpl extends VirtualFilePointerManager imp } pointer.myNode.incrementUsageCount(1); - root.checkStructure(); + root.checkConsistency(); return pointer; } @@ -327,7 +326,7 @@ public class VirtualFilePointerManagerImpl extends VirtualFilePointerManager imp } } - private void addAllPointers(Collection pointers) { + private void addAllPointers(@NotNull Collection pointers) { List out = new ArrayList(); for (FilePointerPartNode root : myPointers.values()) { root.getPointersUnder("", 0, out); @@ -381,9 +380,9 @@ public class VirtualFilePointerManagerImpl extends VirtualFilePointerManager imp return virtualFilePointerContainer; } - @Nullable private List myEvents = Collections.emptyList(); - @Nullable private List myPointersToUpdateUrl = Collections.emptyList(); - @Nullable private List myPointersToFire = Collections.emptyList(); + private List myEvents = Collections.emptyList(); + private List myPointersToUpdateUrl = Collections.emptyList(); + private List myPointersToFire = Collections.emptyList(); @Override public void before(@NotNull final List events) { @@ -518,7 +517,7 @@ public class VirtualFilePointerManagerImpl extends VirtualFilePointerManager imp myEvents = Collections.emptyList(); myPointersToFire = Collections.emptyList(); for (FilePointerPartNode root : myPointers.values()) { - root.checkStructure(); + root.checkConsistency(); } } @@ -528,12 +527,12 @@ public class VirtualFilePointerManagerImpl extends VirtualFilePointerManager imp myPointers.remove(listener); } else { - myPointers.get(listener).checkStructure(); + myPointers.get(listener).checkConsistency(); } } private static class DelegatingDisposable implements Disposable { - private static final ConcurrentMap ourInstances = new ConcurrentHashMap(TObjectHashingStrategy.IDENTITY); + private static final ConcurrentMap ourInstances = new ConcurrentHashMap(ContainerUtil.identityStrategy()); private final TObjectIntHashMap myCounts = new TObjectIntHashMap(); private final Disposable myParent; From ba7f04af95b384ffa734d25347e9e9b15dd95cae Mon Sep 17 00:00:00 2001 From: Alexey Kudravtsev Date: Fri, 27 Jun 2014 13:38:53 +0400 Subject: [PATCH 2/5] cleanup --- .../psi/infos/MethodCandidateInfo.java | 1 + .../intellij/psi/impl/PsiClassImplUtil.java | 2 +- .../tree/java/MethodReferenceResolver.java | 4 +- .../JavaMethodsConflictResolver.java | 72 ++++++++++--------- 4 files changed, 44 insertions(+), 35 deletions(-) diff --git a/java/java-psi-api/src/com/intellij/psi/infos/MethodCandidateInfo.java b/java/java-psi-api/src/com/intellij/psi/infos/MethodCandidateInfo.java index 917a88888d40..e7506ebd92fd 100644 --- a/java/java-psi-api/src/com/intellij/psi/infos/MethodCandidateInfo.java +++ b/java/java-psi-api/src/com/intellij/psi/infos/MethodCandidateInfo.java @@ -158,6 +158,7 @@ public class MethodCandidateInfo extends CandidateInfo{ return level; } + @NotNull public PsiSubstitutor getSiteSubstitutor() { PsiSubstitutor incompleteSubstitutor = super.getSubstitutor(); if (myTypeArguments != null) { diff --git a/java/java-psi-impl/src/com/intellij/psi/impl/PsiClassImplUtil.java b/java/java-psi-impl/src/com/intellij/psi/impl/PsiClassImplUtil.java index 107bff5e60f2..3496b98f5ddf 100644 --- a/java/java-psi-impl/src/com/intellij/psi/impl/PsiClassImplUtil.java +++ b/java/java-psi-impl/src/com/intellij/psi/impl/PsiClassImplUtil.java @@ -760,7 +760,6 @@ public class PsiClassImplUtil { @NotNull private static PsiClass[] getSupersInner(@NotNull PsiClass psiClass) { PsiClassType[] extendsListTypes = psiClass.getExtendsListTypes(); - PsiClassType[] implementsListTypes = psiClass.getImplementsListTypes(); if (psiClass.isInterface()) { return resolveClassReferenceList(extendsListTypes, psiClass.getManager(), psiClass.getResolveScope(), true); @@ -792,6 +791,7 @@ public class PsiClassImplUtil { return resolveClassReferenceList(extendsListTypes, psiClass.getManager(), psiClass.getResolveScope(), false); } + PsiClassType[] implementsListTypes = psiClass.getImplementsListTypes(); PsiClass[] interfaces = resolveClassReferenceList(implementsListTypes, psiClass.getManager(), psiClass.getResolveScope(), false); PsiClass superClass = getSuperClass(psiClass); diff --git a/java/java-psi-impl/src/com/intellij/psi/impl/source/tree/java/MethodReferenceResolver.java b/java/java-psi-impl/src/com/intellij/psi/impl/source/tree/java/MethodReferenceResolver.java index 9e31f7b88656..4066c6cc4a78 100644 --- a/java/java-psi-impl/src/com/intellij/psi/impl/source/tree/java/MethodReferenceResolver.java +++ b/java/java-psi-impl/src/com/intellij/psi/impl/source/tree/java/MethodReferenceResolver.java @@ -219,7 +219,7 @@ public class MethodReferenceResolver implements ResolveCache.PolyVariantContextR } @Override - protected int getPertinentApplicabilityLevel(MethodCandidateInfo conflict) { + protected int getPertinentApplicabilityLevel(@NotNull MethodCandidateInfo conflict) { return conflict.isVarargs() ? MethodCandidateInfo.ApplicabilityLevel.VARARGS : MethodCandidateInfo.ApplicabilityLevel.FIXED_ARITY; } @@ -299,7 +299,7 @@ public class MethodReferenceResolver implements ResolveCache.PolyVariantContextR } @Override - protected boolean nonComparable(CandidateInfo method, CandidateInfo conflict) { + protected boolean nonComparable(@NotNull CandidateInfo method, @NotNull CandidateInfo conflict) { if (method == conflict) return true; PsiElement psiElement = method.getElement(); PsiElement conflictElement = conflict.getElement(); diff --git a/java/java-psi-impl/src/com/intellij/psi/scope/conflictResolvers/JavaMethodsConflictResolver.java b/java/java-psi-impl/src/com/intellij/psi/scope/conflictResolvers/JavaMethodsConflictResolver.java index aa18e6e6b8a4..f136c843aa87 100644 --- a/java/java-psi-impl/src/com/intellij/psi/scope/conflictResolvers/JavaMethodsConflictResolver.java +++ b/java/java-psi-impl/src/com/intellij/psi/scope/conflictResolvers/JavaMethodsConflictResolver.java @@ -131,9 +131,11 @@ public class JavaMethodsConflictResolver implements PsiConflictResolver{ private static PsiLambdaExpression findNestedLambdaExpression(PsiExpression expression) { if (expression instanceof PsiLambdaExpression) { return (PsiLambdaExpression)expression; - } else if (expression instanceof PsiParenthesizedExpression) { + } + else if (expression instanceof PsiParenthesizedExpression) { return findNestedLambdaExpression(((PsiParenthesizedExpression)expression).getExpression()); - } else if (expression instanceof PsiConditionalExpression) { + } + else if (expression instanceof PsiConditionalExpression) { PsiLambdaExpression lambdaExpression = findNestedLambdaExpression(((PsiConditionalExpression)expression).getThenExpression()); if (lambdaExpression != null) { return lambdaExpression; @@ -143,7 +145,7 @@ public class JavaMethodsConflictResolver implements PsiConflictResolver{ return null; } - private static void checkLambdaApplicable(List conflicts, int i, PsiLambdaExpression lambdaExpression) { + private static void checkLambdaApplicable(@NotNull List conflicts, int i, @NotNull PsiLambdaExpression lambdaExpression) { for (Iterator iterator = conflicts.iterator(); iterator.hasNext(); ) { ProgressManager.checkCanceled(); final CandidateInfo conflict = iterator.next(); @@ -192,12 +194,12 @@ public class JavaMethodsConflictResolver implements PsiConflictResolver{ } } - protected boolean nonComparable(CandidateInfo method, CandidateInfo conflict) { + protected boolean nonComparable(@NotNull CandidateInfo method, @NotNull CandidateInfo conflict) { assert method != conflict; return false; } - protected static void checkAccessStaticLevels(List conflicts, boolean checkAccessible) { + protected static void checkAccessStaticLevels(@NotNull List conflicts, boolean checkAccessible) { int conflictsCount = conflicts.size(); int maxCheckLevel = -1; @@ -350,13 +352,13 @@ public class JavaMethodsConflictResolver implements PsiConflictResolver{ } } - private static boolean areTypeParametersAgree(CandidateInfo info) { + private static boolean areTypeParametersAgree(@NotNull CandidateInfo info) { return ((MethodCandidateInfo)info).getPertinentApplicabilityLevel() != MethodCandidateInfo.ApplicabilityLevel.NOT_APPLICABLE; } - private static boolean checkParametersNumber(final List conflicts, - final int argumentsCount, - boolean ignoreIfStaticsProblem) { + private static boolean checkParametersNumber(@NotNull List conflicts, + final int argumentsCount, + boolean ignoreIfStaticsProblem) { boolean atLeastOneMatch = false; TIntArrayList unmatchedIndices = null; for (int i = 0; i < conflicts.size(); i++) { @@ -392,7 +394,7 @@ public class JavaMethodsConflictResolver implements PsiConflictResolver{ } @MethodCandidateInfo.ApplicabilityLevelConstant - protected int checkApplicability(List conflicts) { + protected int checkApplicability(@NotNull List conflicts) { @MethodCandidateInfo.ApplicabilityLevelConstant int maxApplicabilityLevel = 0; boolean toFilter = false; for (CandidateInfo conflict : conflicts) { @@ -420,27 +422,29 @@ public class JavaMethodsConflictResolver implements PsiConflictResolver{ return maxApplicabilityLevel; } - protected int getPertinentApplicabilityLevel(MethodCandidateInfo conflict) { + protected int getPertinentApplicabilityLevel(@NotNull MethodCandidateInfo conflict) { return conflict.getPertinentApplicabilityLevel(); } - private static int getCheckAccessLevel(MethodCandidateInfo method){ + private static int getCheckAccessLevel(@NotNull MethodCandidateInfo method){ boolean visible = method.isAccessible(); return visible ? 1 : 0; } - private static int getCheckStaticLevel(MethodCandidateInfo method){ + private static int getCheckStaticLevel(@NotNull MethodCandidateInfo method){ boolean available = method.isStaticsScopeCorrect(); return (available ? 1 : 0) << 1 | (method.getCurrentFileResolveScope() instanceof PsiImportStaticStatement ? 0 : 1); } + @NotNull private PsiType[] getActualParameterTypes() { - if (myActualParameterTypes == null) { + PsiType[] types = myActualParameterTypes; + if (types == null) { LOG.assertTrue(myArgumentsList instanceof PsiExpressionList, myArgumentsList); - myActualParameterTypes = getArgumentTypes(); + myActualParameterTypes = types = getArgumentTypes(); } - return myActualParameterTypes; + return types; } private int getActualParametersLength() { @@ -451,6 +455,7 @@ public class JavaMethodsConflictResolver implements PsiConflictResolver{ return myActualParameterTypes.length; } + @NotNull protected PsiType[] getArgumentTypes() { return ((PsiExpressionList)myArgumentsList).getExpressionTypes(); } @@ -470,8 +475,8 @@ public class JavaMethodsConflictResolver implements PsiConflictResolver{ return TypeConversionUtil.boxingConversionApplicable(parameterType, argType); } - private Specifics isMoreSpecific(final MethodCandidateInfo info1, - final MethodCandidateInfo info2, + private Specifics isMoreSpecific(@NotNull MethodCandidateInfo info1, + @NotNull MethodCandidateInfo info2, @MethodCandidateInfo.ApplicabilityLevelConstant int applicabilityLevel, @NotNull LanguageLevel languageLevel) { PsiMethod method1 = info1.getElement(); @@ -684,11 +689,11 @@ public class JavaMethodsConflictResolver implements PsiConflictResolver{ return Specifics.NEITHER; } - private boolean isApplicableTo(PsiType[] types2AtSite, - PsiMethod method1, - LanguageLevel languageLevel, + private boolean isApplicableTo(@NotNull PsiType[] types2AtSite, + @NotNull PsiMethod method1, + @NotNull LanguageLevel languageLevel, boolean varargsPosition, - final PsiSubstitutor methodSubstitutor1, + @NotNull PsiSubstitutor methodSubstitutor1, PsiMethod method2, PsiSubstitutor siteSubstitutor1) { if (languageLevel.isAtLeast(LanguageLevel.JDK_1_8) && method2 != null && method1.getTypeParameters().length > 0 && myArgumentsList instanceof PsiExpressionList) { @@ -701,7 +706,8 @@ public class JavaMethodsConflictResolver implements PsiConflictResolver{ return applicabilityLevel > MethodCandidateInfo.ApplicabilityLevel.NOT_APPLICABLE; } - private static PsiType[] typesAtSite(PsiType[] types1, PsiSubstitutor siteSubstitutor1) { + @NotNull + private static PsiType[] typesAtSite(@NotNull PsiType[] types1, @NotNull PsiSubstitutor siteSubstitutor1) { final PsiType[] types = PsiType.createArray(types1.length); for (int i = 0; i < types1.length; i++) { types[i] = siteSubstitutor1.substitute(types1[i]); @@ -709,11 +715,12 @@ public class JavaMethodsConflictResolver implements PsiConflictResolver{ return types; } - private static PsiSubstitutor calculateMethodSubstitutor(final PsiTypeParameter[] typeParameters, - final PsiMethod method, - final PsiSubstitutor siteSubstitutor, - final PsiType[] types1, - final PsiType[] types2, + @NotNull + private static PsiSubstitutor calculateMethodSubstitutor(@NotNull PsiTypeParameter[] typeParameters, + @NotNull PsiMethod method, + @NotNull PsiSubstitutor siteSubstitutor, + @NotNull PsiType[] types1, + @NotNull PsiType[] types2, @NotNull LanguageLevel languageLevel) { PsiSubstitutor substitutor = PsiResolveHelper.SERVICE.getInstance(method.getProject()) .inferTypeArguments(typeParameters, types1, types2, languageLevel); @@ -742,7 +749,7 @@ public class JavaMethodsConflictResolver implements PsiConflictResolver{ return substitutor; } - public void checkPrimitiveVarargs(final List conflicts, + public void checkPrimitiveVarargs(@NotNull List conflicts, final int argumentsCount) { if (JavaVersionService.getInstance().isAtLeast(myArgumentsList, JavaSdkVersion.JDK_1_7)) return; CandidateInfo objectVararg = null; @@ -778,7 +785,7 @@ public class JavaMethodsConflictResolver implements PsiConflictResolver{ } @Nullable - private static PsiType getFunctionalType(int functionalTypeIdx, CandidateInfo candidateInfo) { + private static PsiType getFunctionalType(int functionalTypeIdx, @NotNull CandidateInfo candidateInfo) { final PsiMethod psiMethod = (PsiMethod)candidateInfo.getElement(); LOG.assertTrue(true); final PsiParameter[] methodParameters = psiMethod.getParameterList().getParameters(); @@ -787,8 +794,9 @@ public class JavaMethodsConflictResolver implements PsiConflictResolver{ return ((MethodCandidateInfo)candidateInfo).getSiteSubstitutor().substitute(param.getType()); } - private static Specifics isFunctionalTypeMoreSpecific(CandidateInfo method, - CandidateInfo conflict, + @NotNull + private static Specifics isFunctionalTypeMoreSpecific(@NotNull CandidateInfo method, + @NotNull CandidateInfo conflict, PsiExpression expr, int functionalInterfaceIdx) { if (expr instanceof PsiParenthesizedExpression) { From f20ad376a3ba0289f9ccdbc0732732ebe5899907 Mon Sep 17 00:00:00 2001 From: Alexey Kudravtsev Date: Fri, 27 Jun 2014 14:00:17 +0400 Subject: [PATCH 3/5] add read action but outside lock --- .../vfs/newvfs/impl/VfsRootAccess.java | 8 ++++++- .../com/intellij/openapi/vfs/VfsUtilTest.java | 24 +++++++++++++------ 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/platform/platform-impl/src/com/intellij/openapi/vfs/newvfs/impl/VfsRootAccess.java b/platform/platform-impl/src/com/intellij/openapi/vfs/newvfs/impl/VfsRootAccess.java index 61129cc4e420..b6fa97092059 100644 --- a/platform/platform-impl/src/com/intellij/openapi/vfs/newvfs/impl/VfsRootAccess.java +++ b/platform/platform-impl/src/com/intellij/openapi/vfs/newvfs/impl/VfsRootAccess.java @@ -23,6 +23,7 @@ import com.intellij.openapi.project.Project; import com.intellij.openapi.project.ProjectManager; import com.intellij.openapi.roots.OrderEnumerator; import com.intellij.openapi.roots.ProjectRootManager; +import com.intellij.openapi.util.Computable; import com.intellij.openapi.util.SystemInfo; import com.intellij.openapi.util.io.FileUtil; import com.intellij.openapi.util.text.StringUtil; @@ -67,7 +68,12 @@ public class VfsRootAccess { return; } - Set allowed = allowedRoots(); + Set allowed = ApplicationManager.getApplication().runReadAction(new Computable>() { + @Override + public Set compute() { + return allowedRoots(); + } + }); boolean isUnder = allowed == null || allowed.isEmpty(); if (!isUnder) { diff --git a/platform/platform-tests/testSrc/com/intellij/openapi/vfs/VfsUtilTest.java b/platform/platform-tests/testSrc/com/intellij/openapi/vfs/VfsUtilTest.java index aa06177ea8e6..0acabe1288bb 100644 --- a/platform/platform-tests/testSrc/com/intellij/openapi/vfs/VfsUtilTest.java +++ b/platform/platform-tests/testSrc/com/intellij/openapi/vfs/VfsUtilTest.java @@ -22,6 +22,7 @@ import com.intellij.openapi.application.WriteAction; import com.intellij.openapi.application.ex.PathManagerEx; import com.intellij.openapi.command.WriteCommandAction; import com.intellij.openapi.progress.ProgressManager; +import com.intellij.openapi.util.Computable; import com.intellij.openapi.util.SystemInfo; import com.intellij.openapi.util.io.FileUtil; import com.intellij.openapi.util.io.IoTestUtil; @@ -262,13 +263,13 @@ public class VfsUtilTest extends PlatformLangTestCase { public void testDirAttributeRefreshes() throws IOException { File tempDir = createTempDirectory(); - VirtualFile vDir = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(tempDir); + VirtualFile vDir = refreshAndFindFile(tempDir); assertNotNull(vDir); assertTrue(vDir.isDirectory()); File file = FileUtil.createTempFile(tempDir, "xxx", "yyy", true); assertNotNull(file); - VirtualFile vFile = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(file); + VirtualFile vFile = refreshAndFindFile(file); assertNotNull(vFile); assertFalse(vFile.isDirectory()); @@ -278,11 +279,20 @@ public class VfsUtilTest extends PlatformLangTestCase { assertTrue(created); assertTrue(file.exists()); - VirtualFile vFile2 = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(file); + VirtualFile vFile2 = refreshAndFindFile(file); assertNotNull(vFile2); assertTrue(vFile2.isDirectory()); } + private static VirtualFile refreshAndFindFile(final File file) { + return UIUtil.invokeAndWaitIfNeeded(new Computable() { + @Override + public VirtualFile compute() { + return LocalFileSystem.getInstance().refreshAndFindFileByIoFile(file); + } + }); + } + public void testPresentableUrlSurvivesDeletion() throws IOException { final VirtualFile file = createTempFile("txt", null, "content", Charset.defaultCharset()); String url = file.getPresentableUrl(); @@ -360,7 +370,7 @@ public class VfsUtilTest extends PlatformLangTestCase { public void testFindChildByNamePerformance() throws IOException { File tempDir = createTempDirectory(); - final VirtualFile vDir = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(tempDir); + final VirtualFile vDir = refreshAndFindFile(tempDir); assertNotNull(vDir); assertTrue(vDir.isDirectory()); @@ -398,7 +408,7 @@ public class VfsUtilTest extends PlatformLangTestCase { public void testFindRootWithDenormalizedPath() throws IOException { File tempJar = IoTestUtil.createTestJar(); - VirtualFile jar = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(tempJar); + VirtualFile jar = refreshAndFindFile(tempJar); assertNotNull(jar); JarFileSystem fs = JarFileSystem.getInstance(); @@ -410,7 +420,7 @@ public class VfsUtilTest extends PlatformLangTestCase { public void testFindRootPerformance() throws IOException { File tempJar = IoTestUtil.createTestJar(); - final VirtualFile jar = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(tempJar); + final VirtualFile jar = refreshAndFindFile(tempJar); assertNotNull(jar); final JarFileSystem fs = JarFileSystem.getInstance(); @@ -440,7 +450,7 @@ public class VfsUtilTest extends PlatformLangTestCase { assertTrue(new File(tempDir, "CssInvalidElement").createNewFile()); assertTrue(new File(tempDir, "extFiles").createNewFile()); - VirtualFile vDir = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(tempDir); + VirtualFile vDir = refreshAndFindFile(tempDir); assertNotNull(vDir); assertTrue(vDir.isDirectory()); From f5a2125d02ce30f5bdcb2e41ef6f960c385193f9 Mon Sep 17 00:00:00 2001 From: Alexey Kudravtsev Date: Fri, 27 Jun 2014 14:03:39 +0400 Subject: [PATCH 4/5] add read action but outside lock --- .../vfs/newvfs/impl/VirtualDirectoryImpl.java | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/platform/platform-impl/src/com/intellij/openapi/vfs/newvfs/impl/VirtualDirectoryImpl.java b/platform/platform-impl/src/com/intellij/openapi/vfs/newvfs/impl/VirtualDirectoryImpl.java index 47ef3345885a..2abfd84e8d43 100644 --- a/platform/platform-impl/src/com/intellij/openapi/vfs/newvfs/impl/VirtualDirectoryImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/vfs/newvfs/impl/VirtualDirectoryImpl.java @@ -157,6 +157,7 @@ public class VirtualDirectoryImpl extends VirtualFileSystemEntry { if (name.isEmpty()) return null; } + VirtualFileSystemEntry child; synchronized (myData) { // maybe another doFindChild() sneaked in the middle if (myData.isAdoptedName(name)) return NULL_VIRTUAL_FILE; @@ -173,7 +174,7 @@ public class VirtualDirectoryImpl extends VirtualFileSystemEntry { if (id <= 0) { return null; } - VirtualFileSystemEntry child = createChild(FileNameCache.storeName(name), id, delegate); + child = createChild(FileNameCache.storeName(name), id, delegate); int[] after = myData.myChildrenIds; if (after != array) { @@ -185,8 +186,15 @@ public class VirtualDirectoryImpl extends VirtualFileSystemEntry { insertChildAt(child, indexInReal); assertConsistency(!delegate.isCaseSensitive(), name); } - return child; } + + if (!child.isDirectory()) { + // access check should only be called when child is actually added to the parent, otherwise it may break VirtualFilePointers validity + //noinspection TestOnlyProblems + VfsRootAccess.assertAccessInTests(child, getFileSystem()); + } + + return child; } private VirtualFileSystemEntry[] getArraySafely() { @@ -419,12 +427,6 @@ public class VirtualDirectoryImpl extends VirtualFileSystemEntry { appended[i] = file.getId(); System.arraycopy(array, i, appended, i + 1, array.length - i); myData.myChildrenIds = appended; - - if (!file.isDirectory()) { - // access check should only be called when child is actually added to the parent, otherwise it may break VirtualFilePointers validity - //noinspection TestOnlyProblems - VfsRootAccess.assertAccessInTests(file, getFileSystem()); - } } public void removeChild(@NotNull VirtualFile file) { @@ -538,5 +540,4 @@ public class VirtualDirectoryImpl extends VirtualFileSystemEntry { protected boolean changeUserMap(KeyFMap oldMap, KeyFMap newMap) { return myData.changeUserMap(oldMap, UserDataInterner.internUserData(newMap)); } - } From ddba19c74078b39aaa6ec199ef8a0634babf3dfd Mon Sep 17 00:00:00 2001 From: Alexey Kudravtsev Date: Fri, 27 Jun 2014 14:07:22 +0400 Subject: [PATCH 5/5] do not do expensive consistency checks during performance tests --- .../application/impl/ApplicationInfoImpl.java | 8 ++++++++ .../intellij/openapi/editor/impl/CharArray.java | 7 +++++-- .../intellij/openapi/editor/impl/DocumentImpl.java | 1 - .../openapi/editor/impl/RangeMarkerTree.java | 4 +++- .../vfs/impl/VirtualFilePointerContainerImpl.java | 3 ++- .../src/com/intellij/psi/impl/DebugUtil.java | 5 +++-- .../daemon/impl/PassExecutorService.java | 3 ++- .../vfs/newvfs/impl/VirtualDirectoryImpl.java | 3 ++- .../testFramework/LightPlatformTestCase.java | 3 +++ .../intellij/testFramework/PlatformTestCase.java | 14 ++++++-------- .../com/intellij/testFramework/UsefulTestCase.java | 2 -- 11 files changed, 34 insertions(+), 19 deletions(-) diff --git a/platform/core-impl/src/com/intellij/openapi/application/impl/ApplicationInfoImpl.java b/platform/core-impl/src/com/intellij/openapi/application/impl/ApplicationInfoImpl.java index 4f3c08629128..78ce83cc5154 100644 --- a/platform/core-impl/src/com/intellij/openapi/application/impl/ApplicationInfoImpl.java +++ b/platform/core-impl/src/com/intellij/openapi/application/impl/ApplicationInfoImpl.java @@ -779,4 +779,12 @@ public class ApplicationInfoImpl extends ApplicationInfoEx implements JDOMExtern return myDependentPlugin; } } + + private static volatile boolean myInPerformanceTest; + public static boolean isInPerformanceTest() { + return myInPerformanceTest; + } + public static void setInPerformanceTest(boolean inPerformanceTest) { + myInPerformanceTest = inPerformanceTest; + } } diff --git a/platform/core-impl/src/com/intellij/openapi/editor/impl/CharArray.java b/platform/core-impl/src/com/intellij/openapi/editor/impl/CharArray.java index 5fba46ac4ed7..efa2d2d34a61 100644 --- a/platform/core-impl/src/com/intellij/openapi/editor/impl/CharArray.java +++ b/platform/core-impl/src/com/intellij/openapi/editor/impl/CharArray.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2013 JetBrains s.r.o. + * Copyright 2000-2014 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. @@ -16,6 +16,8 @@ package com.intellij.openapi.editor.impl; import com.intellij.diagnostic.Dumpable; +import com.intellij.openapi.application.ApplicationManager; +import com.intellij.openapi.application.impl.ApplicationInfoImpl; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.editor.event.DocumentEvent; import com.intellij.openapi.util.text.StringUtil; @@ -39,6 +41,7 @@ import java.util.concurrent.locks.ReentrantLock; * @author cdr */ abstract class CharArray implements CharSequenceBackedByArray, Dumpable { + private static final boolean CHECK_DOCUMENT_CONSISTENCY = ApplicationManager.getApplication() != null && ApplicationManager.getApplication().isUnitTestMode() && !ApplicationInfoImpl.isInPerformanceTest(); private static final Logger LOG = Logger.getInstance("#" + CharArray.class.getName()); @SuppressWarnings("UseOfArchaicSystemPropertyAccessors") @@ -77,7 +80,7 @@ abstract class CharArray implements CharSequenceBackedByArray, Dumpable { private final boolean myDebug = isDebug(); boolean isDebug() { - return DEBUG_DEFERRED_PROCESSING || DocumentImpl.CHECK_DOCUMENT_CONSISTENCY; + return DEBUG_DEFERRED_PROCESSING || CHECK_DOCUMENT_CONSISTENCY; } /** diff --git a/platform/core-impl/src/com/intellij/openapi/editor/impl/DocumentImpl.java b/platform/core-impl/src/com/intellij/openapi/editor/impl/DocumentImpl.java index 8a343f7279dd..fa234e109d49 100644 --- a/platform/core-impl/src/com/intellij/openapi/editor/impl/DocumentImpl.java +++ b/platform/core-impl/src/com/intellij/openapi/editor/impl/DocumentImpl.java @@ -56,7 +56,6 @@ import java.util.List; public class DocumentImpl extends UserDataHolderBase implements DocumentEx { private static final Logger LOG = Logger.getInstance("#com.intellij.openapi.editor.impl.DocumentImpl"); - public static boolean CHECK_DOCUMENT_CONSISTENCY = ApplicationManager.getApplication() != null && ApplicationManager.getApplication().isUnitTestMode(); private final Ref myCachedDocumentListeners = Ref.create(null); private final List myDocumentListeners = ContainerUtil.createLockFreeCopyOnWriteList(); diff --git a/platform/core-impl/src/com/intellij/openapi/editor/impl/RangeMarkerTree.java b/platform/core-impl/src/com/intellij/openapi/editor/impl/RangeMarkerTree.java index 2e7ebadc3892..31c135764481 100644 --- a/platform/core-impl/src/com/intellij/openapi/editor/impl/RangeMarkerTree.java +++ b/platform/core-impl/src/com/intellij/openapi/editor/impl/RangeMarkerTree.java @@ -16,6 +16,7 @@ package com.intellij.openapi.editor.impl; import com.intellij.openapi.application.ApplicationManager; +import com.intellij.openapi.application.impl.ApplicationInfoImpl; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.editor.Document; import com.intellij.openapi.editor.event.DocumentEvent; @@ -37,7 +38,8 @@ import java.util.concurrent.atomic.AtomicInteger; */ public class RangeMarkerTree extends IntervalTreeImpl { private static final Logger LOG = Logger.getInstance("#com.intellij.openapi.editor.impl.RangeMarkerTree"); - private static final boolean DEBUG = LOG.isDebugEnabled() || ApplicationManager.getApplication() != null && (ApplicationManager.getApplication().isUnitTestMode() || ApplicationManager.getApplication().isInternal()); + private static final boolean DEBUG = LOG.isDebugEnabled() || ApplicationManager.getApplication() != null && (ApplicationManager.getApplication().isUnitTestMode() && !ApplicationInfoImpl + .isInPerformanceTest() || ApplicationManager.getApplication().isInternal()); private final PrioritizedDocumentListener myListener; private final Document myDocument; diff --git a/platform/core-impl/src/com/intellij/openapi/vfs/impl/VirtualFilePointerContainerImpl.java b/platform/core-impl/src/com/intellij/openapi/vfs/impl/VirtualFilePointerContainerImpl.java index 65dc79bac298..d06cf9939b90 100644 --- a/platform/core-impl/src/com/intellij/openapi/vfs/impl/VirtualFilePointerContainerImpl.java +++ b/platform/core-impl/src/com/intellij/openapi/vfs/impl/VirtualFilePointerContainerImpl.java @@ -17,6 +17,7 @@ package com.intellij.openapi.vfs.impl; import com.intellij.openapi.Disposable; import com.intellij.openapi.application.ApplicationManager; +import com.intellij.openapi.application.impl.ApplicationInfoImpl; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.util.InvalidDataException; import com.intellij.openapi.util.TraceableDisposable; @@ -51,7 +52,7 @@ public class VirtualFilePointerContainerImpl extends TraceableDisposable impleme private volatile long myTimeStampOfCachedThings = -1; @NonNls public static final String URL_ATTR = "url"; private boolean myDisposed; - private static final boolean TRACE_CREATION = LOG.isDebugEnabled() || ApplicationManager.getApplication().isUnitTestMode(); + private static final boolean TRACE_CREATION = LOG.isDebugEnabled() || (ApplicationManager.getApplication().isUnitTestMode() && !ApplicationInfoImpl.isInPerformanceTest()); public VirtualFilePointerContainerImpl(@NotNull VirtualFilePointerManager manager, @NotNull Disposable parentDisposable, @Nullable VirtualFilePointerListener listener) { diff --git a/platform/core-impl/src/com/intellij/psi/impl/DebugUtil.java b/platform/core-impl/src/com/intellij/psi/impl/DebugUtil.java index a7a38fc749e5..2a22a7b0dc66 100644 --- a/platform/core-impl/src/com/intellij/psi/impl/DebugUtil.java +++ b/platform/core-impl/src/com/intellij/psi/impl/DebugUtil.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2012 JetBrains s.r.o. + * Copyright 2000-2014 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,6 +21,7 @@ import com.intellij.lang.LighterASTTokenNode; import com.intellij.lang.impl.PsiBuilderImpl; import com.intellij.openapi.application.Application; import com.intellij.openapi.application.ApplicationManager; +import com.intellij.openapi.application.impl.ApplicationInfoImpl; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.util.Ref; import com.intellij.openapi.util.UserDataHolderBase; @@ -75,7 +76,7 @@ public class DebugUtil { public static final boolean DO_EXPENSIVE_CHECKS; static { Application application = ApplicationManager.getApplication(); - DO_EXPENSIVE_CHECKS = application != null && application.isUnitTestMode(); + DO_EXPENSIVE_CHECKS = application != null && application.isUnitTestMode() && !ApplicationInfoImpl.isInPerformanceTest(); } public static final boolean CHECK_INSIDE_ATOMIC_ACTION_ENABLED = DO_EXPENSIVE_CHECKS; diff --git a/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/PassExecutorService.java b/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/PassExecutorService.java index 4ae10647a17e..cd77283ec701 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/PassExecutorService.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/PassExecutorService.java @@ -26,6 +26,7 @@ import com.intellij.openapi.Disposable; import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.application.ModalityState; import com.intellij.openapi.application.ex.ApplicationManagerEx; +import com.intellij.openapi.application.impl.ApplicationInfoImpl; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.editor.Document; import com.intellij.openapi.editor.Editor; @@ -62,7 +63,7 @@ import java.util.concurrent.atomic.AtomicInteger; */ public class PassExecutorService implements Disposable { private static final Logger LOG = Logger.getInstance("#com.intellij.codeInsight.daemon.impl.PassExecutorService"); - private static final boolean CHECK_CONSISTENCY = ApplicationManager.getApplication().isUnitTestMode(); + private static final boolean CHECK_CONSISTENCY = ApplicationManager.getApplication().isUnitTestMode() && !ApplicationInfoImpl.isInPerformanceTest(); private final Map> mySubmittedPasses = new ConcurrentHashMap>(); private final Project myProject; diff --git a/platform/platform-impl/src/com/intellij/openapi/vfs/newvfs/impl/VirtualDirectoryImpl.java b/platform/platform-impl/src/com/intellij/openapi/vfs/newvfs/impl/VirtualDirectoryImpl.java index 2abfd84e8d43..44357ae7b063 100644 --- a/platform/platform-impl/src/com/intellij/openapi/vfs/newvfs/impl/VirtualDirectoryImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/vfs/newvfs/impl/VirtualDirectoryImpl.java @@ -16,6 +16,7 @@ package com.intellij.openapi.vfs.newvfs.impl; import com.intellij.openapi.application.ApplicationManager; +import com.intellij.openapi.application.impl.ApplicationInfoImpl; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.util.SystemInfo; import com.intellij.openapi.util.io.FileAttributes; @@ -54,7 +55,7 @@ import java.util.List; public class VirtualDirectoryImpl extends VirtualFileSystemEntry { private static final Logger LOG = Logger.getInstance("#com.intellij.openapi.vfs.newvfs.impl.VirtualDirectoryImpl"); - public static boolean CHECK = ApplicationManager.getApplication().isUnitTestMode(); + public static boolean CHECK = ApplicationManager.getApplication().isUnitTestMode() && !ApplicationInfoImpl.isInPerformanceTest(); static final VirtualDirectoryImpl NULL_VIRTUAL_FILE = new VirtualDirectoryImpl(-42, null, null, null, LocalFileSystem.getInstance()) { diff --git a/platform/testFramework/src/com/intellij/testFramework/LightPlatformTestCase.java b/platform/testFramework/src/com/intellij/testFramework/LightPlatformTestCase.java index 42e7c7057962..33051b471049 100644 --- a/platform/testFramework/src/com/intellij/testFramework/LightPlatformTestCase.java +++ b/platform/testFramework/src/com/intellij/testFramework/LightPlatformTestCase.java @@ -37,6 +37,7 @@ import com.intellij.openapi.actionSystem.DataProvider; import com.intellij.openapi.application.Application; import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.application.ex.ApplicationEx; +import com.intellij.openapi.application.impl.ApplicationInfoImpl; import com.intellij.openapi.command.WriteCommandAction; import com.intellij.openapi.command.impl.UndoManagerImpl; import com.intellij.openapi.command.undo.UndoManager; @@ -344,6 +345,8 @@ public abstract class LightPlatformTestCase extends UsefulTestCase implements Da try { LightPlatformTestCase.super.setUp(); initApplication(); + ApplicationInfoImpl.setInPerformanceTest(isPerformanceTest()); + ourApplication.setDataProvider(LightPlatformTestCase.this); doSetup(new SimpleLightProjectDescriptor(getModuleType(), getProjectJDK()), configureLocalInspectionTools(), myAvailableInspectionTools); diff --git a/platform/testFramework/src/com/intellij/testFramework/PlatformTestCase.java b/platform/testFramework/src/com/intellij/testFramework/PlatformTestCase.java index 2fabebfb03bb..49be3c789f74 100644 --- a/platform/testFramework/src/com/intellij/testFramework/PlatformTestCase.java +++ b/platform/testFramework/src/com/intellij/testFramework/PlatformTestCase.java @@ -27,6 +27,7 @@ import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.application.ModalityState; import com.intellij.openapi.application.Result; import com.intellij.openapi.application.WriteAction; +import com.intellij.openapi.application.impl.ApplicationInfoImpl; import com.intellij.openapi.command.CommandProcessor; import com.intellij.openapi.command.WriteCommandAction; import com.intellij.openapi.command.impl.UndoManagerImpl; @@ -48,8 +49,6 @@ import com.intellij.openapi.project.impl.ProjectManagerImpl; import com.intellij.openapi.project.impl.TooManyProjectLeakedException; import com.intellij.openapi.projectRoots.Sdk; import com.intellij.openapi.roots.ModuleRootModificationUtil; -import com.intellij.openapi.roots.impl.DirectoryIndex; -import com.intellij.openapi.roots.impl.DirectoryIndexImpl; import com.intellij.openapi.startup.StartupManager; import com.intellij.openapi.util.Disposer; import com.intellij.openapi.util.EmptyRunnable; @@ -136,13 +135,14 @@ public abstract class PlatformTestCase extends UsefulTestCase implements DataPro autodetectPlatformPrefix(); ourApplication = IdeaTestApplication.getInstance(getApplicationConfigDirPath()); ourApplication.setDataProvider(this); + ApplicationInfoImpl.setInPerformanceTest(isPerformanceTest()); if (firstTime) { cleanPersistedVFSContent(); } } - private static String[] PREFIX_CANDIDATES = new String[] { + private static final String[] PREFIX_CANDIDATES = { "AppCode", "CppIde", "CidrCommon", "Python", "PyCharmCore", "UltimateLangXml", "Idea" }; @@ -412,8 +412,6 @@ public abstract class PlatformTestCase extends UsefulTestCase implements DataPro } try { Project project = getProject(); - DirectoryIndexImpl directoryIndex = - project != null ? (DirectoryIndexImpl)DirectoryIndex.getInstance(project) : null; disposeProject(result); if (project != null) { @@ -789,7 +787,7 @@ public abstract class PlatformTestCase extends UsefulTestCase implements DataPro setContentOnDisk(temp, bom, content, charset); myFilesToDelete.add(temp); - final VirtualFile file = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(temp); + final VirtualFile file = getVirtualFile(temp); assert file != null : temp; return file; } @@ -843,7 +841,7 @@ public abstract class PlatformTestCase extends UsefulTestCase implements DataPro protected static VirtualFile createChildData(@NotNull final VirtualFile dir, @NotNull @NonNls final String name) { return new WriteAction() { @Override - protected void run(Result result) throws Throwable { + protected void run(@NotNull Result result) throws Throwable { result.setResult(dir.createChildData(null, name)); } }.execute().throwException().getResultObject(); @@ -852,7 +850,7 @@ public abstract class PlatformTestCase extends UsefulTestCase implements DataPro protected static VirtualFile createChildDirectory(@NotNull final VirtualFile dir, @NotNull @NonNls final String name) { return new WriteAction() { @Override - protected void run(Result result) throws Throwable { + protected void run(@NotNull Result result) throws Throwable { result.setResult(dir.createChildDirectory(null, name)); } }.execute().throwException().getResultObject(); diff --git a/platform/testFramework/src/com/intellij/testFramework/UsefulTestCase.java b/platform/testFramework/src/com/intellij/testFramework/UsefulTestCase.java index 751a3b9e9538..306d7f76fd93 100644 --- a/platform/testFramework/src/com/intellij/testFramework/UsefulTestCase.java +++ b/platform/testFramework/src/com/intellij/testFramework/UsefulTestCase.java @@ -138,8 +138,6 @@ public abstract class UsefulTestCase extends TestCase { myTempDir = FileUtil.toSystemDependentName(ORIGINAL_TEMP_DIR + "/" + TEMP_DIR_MARKER + testName + "_"+ RNG.nextInt(1000)); FileUtil.resetCanonicalTempPathCache(myTempDir); } - //noinspection AssignmentToStaticFieldFromInstanceMethod - DocumentImpl.CHECK_DOCUMENT_CONSISTENCY = !isPerformanceTest(); } @Override