From 24f91c2e18dc6b2c5bfd8e5ebed2b93a1b312371 Mon Sep 17 00:00:00 2001 From: Sergey Evdokimov Date: Wed, 6 Nov 2013 16:28:14 +0400 Subject: [PATCH 1/5] IDEA-115474 Maven Dependency template broken in latest Idea Cardea --- .../MavenArtifactCoordinatesArtifactIdConverter.java | 5 +++++ .../converters/MavenArtifactCoordinatesGroupIdConverter.java | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/plugins/maven/src/main/java/org/jetbrains/idea/maven/dom/converters/MavenArtifactCoordinatesArtifactIdConverter.java b/plugins/maven/src/main/java/org/jetbrains/idea/maven/dom/converters/MavenArtifactCoordinatesArtifactIdConverter.java index 62456131d173..24fbf3b3b754 100644 --- a/plugins/maven/src/main/java/org/jetbrains/idea/maven/dom/converters/MavenArtifactCoordinatesArtifactIdConverter.java +++ b/plugins/maven/src/main/java/org/jetbrains/idea/maven/dom/converters/MavenArtifactCoordinatesArtifactIdConverter.java @@ -20,6 +20,7 @@ import com.intellij.codeInsight.completion.InsertHandler; import com.intellij.codeInsight.completion.InsertionContext; import com.intellij.codeInsight.lookup.LookupElement; import com.intellij.codeInsight.lookup.LookupElementBuilder; +import com.intellij.codeInsight.template.TemplateManager; import com.intellij.openapi.project.Project; import com.intellij.openapi.util.text.StringUtil; import com.intellij.psi.PsiElement; @@ -81,6 +82,10 @@ public class MavenArtifactCoordinatesArtifactIdConverter extends MavenArtifactCo @Override public void handleInsert(final InsertionContext context, LookupElement item) { + if (TemplateManager.getInstance(context.getProject()).getActiveTemplate(context.getEditor()) != null) { + return; // Don't brake the template. + } + context.commitDocument(); XmlFile xmlFile = (XmlFile)context.getFile(); diff --git a/plugins/maven/src/main/java/org/jetbrains/idea/maven/dom/converters/MavenArtifactCoordinatesGroupIdConverter.java b/plugins/maven/src/main/java/org/jetbrains/idea/maven/dom/converters/MavenArtifactCoordinatesGroupIdConverter.java index 15b1b2fe853e..3b89a83bf268 100644 --- a/plugins/maven/src/main/java/org/jetbrains/idea/maven/dom/converters/MavenArtifactCoordinatesGroupIdConverter.java +++ b/plugins/maven/src/main/java/org/jetbrains/idea/maven/dom/converters/MavenArtifactCoordinatesGroupIdConverter.java @@ -4,6 +4,7 @@ import com.intellij.codeInsight.completion.InsertHandler; import com.intellij.codeInsight.completion.InsertionContext; import com.intellij.codeInsight.lookup.LookupElement; import com.intellij.codeInsight.lookup.LookupElementBuilder; +import com.intellij.codeInsight.template.TemplateManager; import com.intellij.openapi.util.text.StringUtil; import com.intellij.psi.PsiElement; import com.intellij.psi.util.PsiTreeUtil; @@ -77,6 +78,10 @@ public class MavenArtifactCoordinatesGroupIdConverter extends MavenArtifactCoord @Override public void handleInsert(final InsertionContext context, LookupElement item) { + if (TemplateManager.getInstance(context.getProject()).getActiveTemplate(context.getEditor()) != null) { + return; // Don't brake the template. + } + context.commitDocument(); XmlFile xmlFile = (XmlFile)context.getFile(); From e9b3a8ce948fa13ae4080c1867e173b56005dec4 Mon Sep 17 00:00:00 2001 From: Nadya Zabrodina Date: Wed, 6 Nov 2013 16:48:14 +0400 Subject: [PATCH 2/5] style --- .../vcs/configurable/VcsDirectoryConfigurationPanel.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/configurable/VcsDirectoryConfigurationPanel.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/configurable/VcsDirectoryConfigurationPanel.java index f71688d9c23b..4c5b10c890fb 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/configurable/VcsDirectoryConfigurationPanel.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/configurable/VcsDirectoryConfigurationPanel.java @@ -419,7 +419,7 @@ public class VcsDirectoryConfigurationPanel extends JPanel implements Configurab Collection myErrors = VcsRootErrorsFinder.getInstance(myProject).find(); for (final VcsRootError root : myErrors) { - if (!root.getType().equals(VcsRootError.Type.UNREGISTERED_ROOT)) { + if (!VcsRootError.Type.UNREGISTERED_ROOT.equals(root.getType())) { continue; } final VcsKey vcsKey = root.getVcsKey(); From 75ca45abc99389cc8446ffcc663202e12936c340 Mon Sep 17 00:00:00 2001 From: Nadya Zabrodina Date: Wed, 6 Nov 2013 16:49:27 +0400 Subject: [PATCH 3/5] IDEA-116000 Error message shown if hg root marked as git --- .../com/intellij/openapi/vcs/roots/VcsRootErrorsFinder.java | 2 +- .../intellij/openapi/vcs/roots/VcsRootErrorsFinderTest.java | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/roots/VcsRootErrorsFinder.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/roots/VcsRootErrorsFinder.java index 8674333d4ca5..50240e82c430 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/roots/VcsRootErrorsFinder.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/roots/VcsRootErrorsFinder.java @@ -64,7 +64,7 @@ public class VcsRootErrorsFinder { continue; } if (mapping.isDefaultMapping()) { - if (isEmptyVcsRoots) { + if (!isRoot(mapping)) { errors.add(new VcsRootError(VcsRootError.Type.EXTRA_MAPPING, VcsDirectoryMapping.PROJECT_CONSTANT, mapping.getVcs())); } } diff --git a/platform/vcs-impl/testSrc/com/intellij/openapi/vcs/roots/VcsRootErrorsFinderTest.java b/platform/vcs-impl/testSrc/com/intellij/openapi/vcs/roots/VcsRootErrorsFinderTest.java index 9efe81347b6b..9ab9ba3fbaf6 100644 --- a/platform/vcs-impl/testSrc/com/intellij/openapi/vcs/roots/VcsRootErrorsFinderTest.java +++ b/platform/vcs-impl/testSrc/com/intellij/openapi/vcs/roots/VcsRootErrorsFinderTest.java @@ -151,6 +151,7 @@ public class VcsRootErrorsFinderTest extends VcsPlatformTest { map.put("content_roots", Arrays.asList("content_root")); Map> errorsMap = new HashMap>(); errorsMap.put("unreg", Arrays.asList("content_root")); + errorsMap.put("extra", Arrays.asList(PROJECT)); doTest(map, errorsMap); } @@ -162,12 +163,11 @@ public class VcsRootErrorsFinderTest extends VcsPlatformTest { map.put("content_roots", Arrays.asList(".")); Map> errorsMap = new HashMap>(); errorsMap.put("unreg", Arrays.asList("community")); + errorsMap.put("extra", Arrays.asList(PROJECT)); doTest(map, errorsMap); } - public void testProjectRootGitForFullProjectContentRootLinkedSourceFolderBelowProjectThenErrors() throws IOException - - { + public void testProjectRootGitForFullProjectContentRootLinkedSourceFolderBelowProjectThenErrors() throws IOException { Map> map = new HashMap>(); map.put("git", Arrays.asList(".", "content_root", "../linked_source_root", "folder")); map.put("roots", Arrays.asList(PROJECT)); From 0defb4052f3deaf44c9604a7db17df41b9d84c29 Mon Sep 17 00:00:00 2001 From: peter Date: Wed, 6 Nov 2013 13:49:54 +0100 Subject: [PATCH 4/5] less spam in the logs when there's PSI/document inconsistency during reference search (IDEA-115950) --- .../psi/impl/search/LowLevelSearchUtil.java | 13 +++++-------- .../intellij/util/text/StringSearcher.java | 19 +++++++++++-------- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/platform/indexing-impl/src/com/intellij/psi/impl/search/LowLevelSearchUtil.java b/platform/indexing-impl/src/com/intellij/psi/impl/search/LowLevelSearchUtil.java index 7082b0edfd9e..09fdd72f0e4b 100644 --- a/platform/indexing-impl/src/com/intellij/psi/impl/search/LowLevelSearchUtil.java +++ b/platform/indexing-impl/src/com/intellij/psi/impl/search/LowLevelSearchUtil.java @@ -18,7 +18,6 @@ package com.intellij.psi.impl.search; import com.intellij.lang.ASTNode; import com.intellij.lang.injection.InjectedLanguageManager; -import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.progress.ProgressIndicator; import com.intellij.openapi.project.Project; import com.intellij.openapi.util.Pair; @@ -39,10 +38,6 @@ import org.jetbrains.annotations.Nullable; import java.util.List; public class LowLevelSearchUtil { - private static final Logger LOG = Logger.getInstance("#com.intellij.psi.impl.search.LowLevelSearchUtil"); - - private LowLevelSearchUtil() { - } // TRUE/FALSE -> injected psi has been discovered and processor returned true/false; // null -> there were nothing injected found @@ -95,7 +90,7 @@ public class LowLevelSearchUtil { start = offset - leafElement.getTextRange().getStartOffset() + scopeStartOffset; } if (start < 0) { - LOG.error("offset=" + offset + " scopeStartOffset=" + scopeStartOffset + " leafElement=" + leafElement + " scope=" + scope); + throw new AssertionError("offset=" + offset + " scopeStartOffset=" + scopeStartOffset + " leafElement=" + leafElement + " scope=" + scope); } boolean contains = false; PsiElement prev = null; @@ -159,7 +154,7 @@ public class LowLevelSearchUtil { int startOffset = scopeStart; int endOffset = range.getEndOffset(); if (endOffset > buffer.length()) { - LOG.error("Range for element: '"+scope+"' = "+range+" is out of file '" + file + "' range: " + file.getTextLength()); + throw new AssertionError("Range for element: '"+scope+"' = "+range+" is out of file '" + file + "' range: " + file.getTextLength()); } final char[] bufferArray = CharArrayUtil.fromSequenceWithoutCopying(buffer); @@ -194,7 +189,9 @@ public class LowLevelSearchUtil { int endOffset, @NotNull StringSearcher searcher, @Nullable ProgressIndicator progress) { - LOG.assertTrue(endOffset <= text.length()); + if (endOffset > text.length()) { + throw new AssertionError("end>length"); + } for (int index = startOffset; index < endOffset; index++) { if (progress != null) progress.checkCanceled(); diff --git a/platform/util/src/com/intellij/util/text/StringSearcher.java b/platform/util/src/com/intellij/util/text/StringSearcher.java index f08c33d0ebe6..22e9db2d9428 100644 --- a/platform/util/src/com/intellij/util/text/StringSearcher.java +++ b/platform/util/src/com/intellij/util/text/StringSearcher.java @@ -86,9 +86,13 @@ public class StringSearcher { } public int scan(@NotNull CharSequence text, @Nullable char[] textArray, int _start, int _end) { - LOG.assertTrue(_start <= _end, _start - _end); + if (_start > _end) { + throw new AssertionError("start > end, " + _start + ">" + _end); + } final int textLength = text.length(); - LOG.assertTrue(_end <= textLength, textLength - _end); + if (_end > textLength) { + throw new AssertionError("end > length, " + _end + ">" + textLength); + } if (myForwardDirection) { if (myPatternLength == 1) { // optimization @@ -99,14 +103,14 @@ public class StringSearcher { while (start <= end) { int i = myPatternLength - 1; - char lastChar = textArray != null ? textArray[start + i]:text.charAt(start + i); + char lastChar = textArray != null ? textArray[start + i] : text.charAt(start + i); if (!myCaseSensitive) { lastChar = StringUtil.toLowerCase(lastChar); } if (myPatternArray[i] == lastChar) { i--; while (i >= 0) { - char c = textArray != null ? textArray[start + i]:text.charAt(start + i); + char c = textArray != null ? textArray[start + i] : text.charAt(start + i); if (!myCaseSensitive) { c = StringUtil.toLowerCase(c); } @@ -135,17 +139,17 @@ public class StringSearcher { } else { int start = 1; - int end = _end+1; + int end = _end + 1; while (start <= end - myPatternLength + 1) { int i = myPatternLength - 1; - char lastChar = textArray != null ? textArray[end - (start + i)]:text.charAt(end - (start + i)); + char lastChar = textArray != null ? textArray[end - (start + i)] : text.charAt(end - (start + i)); if (!myCaseSensitive) { lastChar = StringUtil.toLowerCase(lastChar); } if (myPatternArray[myPatternLength - 1 - i] == lastChar) { i--; while (i >= 0) { - char c = textArray != null ? textArray[end - (start + i)]:text.charAt(end - (start + i)); + char c = textArray != null ? textArray[end - (start + i)] : text.charAt(end - (start + i)); if (!myCaseSensitive) { c = StringUtil.toLowerCase(c); } @@ -170,7 +174,6 @@ public class StringSearcher { } return -1; } - } /** From 89f2a7641ca0472e770467c21aec5b885edb16e5 Mon Sep 17 00:00:00 2001 From: Roman Shevchenko Date: Wed, 6 Nov 2013 12:59:47 +0100 Subject: [PATCH 5/5] Minor VFS optimization (cleanup) --- .../newvfs/persistent/PersistentFSImpl.java | 107 ++++++++++-------- 1 file changed, 62 insertions(+), 45 deletions(-) diff --git a/platform/platform-impl/src/com/intellij/openapi/vfs/newvfs/persistent/PersistentFSImpl.java b/platform/platform-impl/src/com/intellij/openapi/vfs/newvfs/persistent/PersistentFSImpl.java index 40f42b33ee88..74230ce2388c 100644 --- a/platform/platform-impl/src/com/intellij/openapi/vfs/newvfs/persistent/PersistentFSImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/vfs/newvfs/persistent/PersistentFSImpl.java @@ -865,10 +865,10 @@ public class PersistentFSImpl extends PersistentFS implements ApplicationCompone @Nullable public VirtualFileSystemEntry findRoot(@NotNull String basePath, @NotNull NewVirtualFileSystem fs) { String rootUrl = normalizeRootUrl(basePath, fs); - boolean isFakeRoot = basePath.isEmpty(); - myRootsLock.readLock().lock(); VirtualFileSystemEntry root; + + myRootsLock.readLock().lock(); try { root = isFakeRoot ? mySuperRoot : myRoots.get(rootUrl); if (root != null) return root; @@ -888,34 +888,7 @@ public class PersistentFSImpl extends PersistentFS implements ApplicationCompone if (isFakeRoot) { // fake super-root - root = new VirtualDirectoryImpl("", null, fs, rootId, 0) { - @SuppressWarnings("NonSynchronizedMethodOverridesSynchronizedMethod") - @Override - @NotNull - public VirtualFile[] getChildren() { - return getRoots(getFileSystem()); - } - - @Override - public VirtualFileSystemEntry findChild(@NotNull String name) { - if (name.isEmpty()) return null; - return findRoot(name, getFileSystem()); - } - - @Override - protected char[] appendPathOnFileSystem(int pathLength, int[] position) { - // getPath() for super-root should never be called. - // however, when new FakeVirtualFile(superRoot, "name") is constructed, - // return garbage to make sure they won't find anything by the name returned - String fakeName = "@&^%$#*/\\("; - int rootPathLength = pathLength + fakeName.length(); - char[] chars = new char[rootPathLength]; - - position[0] = copyString(chars, position[0], fakeName); - - return chars; - } - }; + root = new FakeRoot(fs, rootId); } else if (fs instanceof JarFileSystem) { // optimization: for jar roots do not store base path in the myName field, use local FS file's getPath() @@ -1315,11 +1288,66 @@ public class PersistentFSImpl extends PersistentFS implements ApplicationCompone } - private static class JarRoot extends VirtualDirectoryImpl { + private abstract static class AbstractRoot extends VirtualDirectoryImpl { + protected AbstractRoot(@NotNull NewVirtualFileSystem fs, int id) { + super(FS_ROOT_FAKE_NAME, null, fs, id, 0); + } + + @NotNull + @Override + public abstract String getName(); + + @Override + protected abstract char[] appendPathOnFileSystem(int accumulatedPathLength, int[] positionRef); + + @Override + public final void setParent(@NotNull VirtualFile newParent) { + throw new IncorrectOperationException(); + } + } + + private class FakeRoot extends AbstractRoot { + private FakeRoot(@NotNull NewVirtualFileSystem fs, int rootId) { + super(fs, rootId); + } + + @NotNull + @Override + public String getName() { + return FS_ROOT_FAKE_NAME; + } + + @SuppressWarnings("NonSynchronizedMethodOverridesSynchronizedMethod") + @Override + @NotNull + public VirtualFile[] getChildren() { + return getRoots(getFileSystem()); + } + + @Override + public VirtualFileSystemEntry findChild(@NotNull String name) { + if (name.isEmpty()) return null; + return findRoot(name, getFileSystem()); + } + + @Override + protected char[] appendPathOnFileSystem(int pathLength, int[] position) { + // getPath() for super-root should never be called. + // however, when new FakeVirtualFile(superRoot, "name") is constructed, + // return garbage to make sure they won't find anything by the name returned + String fakeName = "@&^%$#*/\\("; + int rootPathLength = pathLength + fakeName.length(); + char[] chars = new char[rootPathLength]; + position[0] = copyString(chars, position[0], fakeName); + return chars; + } + } + + private static class JarRoot extends AbstractRoot { private final VirtualFile myParentLocalFile; private JarRoot(@NotNull NewVirtualFileSystem fs, int rootId, @NotNull VirtualFile parentLocalFile) { - super(FS_ROOT_FAKE_NAME, null, fs, rootId, 0); + super(fs, rootId); myParentLocalFile = parentLocalFile; } @@ -1337,19 +1365,13 @@ public class PersistentFSImpl extends PersistentFS implements ApplicationCompone positionRef[0] = copyString(chars, positionRef[0], JarFileSystem.JAR_SEPARATOR); return chars; } - - @Override - public void setParent(@NotNull VirtualFile newParent) { - throw new IncorrectOperationException(); - } } - - private static class FsRoot extends VirtualDirectoryImpl { + private static class FsRoot extends AbstractRoot { private final String myName; private FsRoot(@NotNull NewVirtualFileSystem fs, int rootId, @NotNull String basePath) { - super(FS_ROOT_FAKE_NAME, null, fs, rootId, 0); + super(fs, rootId); myName = FileUtil.toSystemIndependentName(basePath); } @@ -1379,10 +1401,5 @@ public class PersistentFSImpl extends PersistentFS implements ApplicationCompone return chars; } - - @Override - public void setParent(@NotNull VirtualFile newParent) { - throw new IncorrectOperationException(); - } } }