Merge remote-tracking branch 'origin/master'

This commit is contained in:
nik
2013-11-06 17:19:12 +04:00
8 changed files with 93 additions and 66 deletions
@@ -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();
@@ -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();
}
}
}
@@ -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;
}
}
/**
@@ -419,7 +419,7 @@ public class VcsDirectoryConfigurationPanel extends JPanel implements Configurab
Collection<VcsRootError> 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();
@@ -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()));
}
}
@@ -151,6 +151,7 @@ public class VcsRootErrorsFinderTest extends VcsPlatformTest {
map.put("content_roots", Arrays.asList("content_root"));
Map<String, Collection<String>> errorsMap = new HashMap<String, Collection<String>>();
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<String, Collection<String>> errorsMap = new HashMap<String, Collection<String>>();
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<String, Collection<String>> map = new HashMap<String, Collection<String>>();
map.put("git", Arrays.asList(".", "content_root", "../linked_source_root", "folder"));
map.put("roots", Arrays.asList(PROJECT));
@@ -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();
@@ -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();