diff --git a/java/java-psi-impl/src/com/intellij/lang/java/parser/JavaParserUtil.java b/java/java-psi-impl/src/com/intellij/lang/java/parser/JavaParserUtil.java index 6af4ce564138..f0b086abf5fe 100644 --- a/java/java-psi-impl/src/com/intellij/lang/java/parser/JavaParserUtil.java +++ b/java/java-psi-impl/src/com/intellij/lang/java/parser/JavaParserUtil.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2011 JetBrains s.r.o. + * Copyright 2000-2012 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. @@ -33,10 +33,10 @@ import com.intellij.psi.impl.source.tree.ElementType; import com.intellij.psi.impl.source.tree.JavaDocElementType; import com.intellij.psi.impl.source.tree.JavaElementType; import com.intellij.psi.impl.source.tree.TreeUtil; -import com.intellij.psi.stubs.StubTreeLoader; import com.intellij.psi.tree.IElementType; import com.intellij.psi.tree.TokenSet; import com.intellij.psi.util.PsiUtil; +import com.intellij.util.indexing.IndexingDataKeys; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.PropertyKey; @@ -174,7 +174,7 @@ public class JavaParserUtil { text = chameleon.getChars(); } else { - text = psi.getUserData(StubTreeLoader.FILE_TEXT_CONTENT_KEY); + text = psi.getUserData(IndexingDataKeys.FILE_TEXT_CONTENT_KEY); if (text == null) text = chameleon.getChars(); } diff --git a/java/java-psi-impl/src/com/intellij/psi/impl/compiled/ClsFileImpl.java b/java/java-psi-impl/src/com/intellij/psi/impl/compiled/ClsFileImpl.java index 2569d397f3d3..70f3d3a55359 100644 --- a/java/java-psi-impl/src/com/intellij/psi/impl/compiled/ClsFileImpl.java +++ b/java/java-psi-impl/src/com/intellij/psi/impl/compiled/ClsFileImpl.java @@ -421,7 +421,7 @@ public class ClsFileImpl extends ClsRepositoryPsiElement final StubTree derefd = derefStub(); if (derefd != null) return derefd; - StubTree stubHolder = StubTreeLoader.getInstance().readOrBuild(getProject(), getVirtualFile()); + StubTree stubHolder = StubTreeLoader.getInstance().readOrBuild(getProject(), getVirtualFile(), this); if (stubHolder == null) { // Must be corrupted classfile LOG.info("Class file is corrupted: " + getVirtualFile().getPresentableUrl()); diff --git a/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/PsiResolveHelperImpl.java b/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/PsiResolveHelperImpl.java index 56ff172eab0d..323dca8aeba9 100644 --- a/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/PsiResolveHelperImpl.java +++ b/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/PsiResolveHelperImpl.java @@ -470,11 +470,9 @@ public class PsiResolveHelperImpl implements PsiResolveHelper { PsiType bound = intersectAllExtends(typeParam, arg); return new Pair(bound, ConstraintType.SUPERTYPE); } - /* if (psiClass == null && arg instanceof PsiClassType) { return Pair.create(arg, ConstraintType.EQUALS); } - */ return null; } if (paramClass == null) return null; diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/completion/SmartTypeCompletionTest.java b/java/java-tests/testSrc/com/intellij/codeInsight/completion/SmartTypeCompletionTest.java index 53a49e027f19..95d367151870 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/completion/SmartTypeCompletionTest.java +++ b/java/java-tests/testSrc/com/intellij/codeInsight/completion/SmartTypeCompletionTest.java @@ -234,7 +234,7 @@ public class SmartTypeCompletionTest extends LightFixtureCompletionTestCase { } public void testCastInThrow() throws Exception { doTest(); } - public void _testNonExistentGenericAfterNew() throws Exception { doTest(); } + public void testNonExistentGenericAfterNew() throws Exception { doTest(); } public void testParenAfterNewWithinInnerExpr() throws Exception { String path = "/afterNew"; diff --git a/platform/core-impl/src/com/intellij/psi/impl/source/PsiFileImpl.java b/platform/core-impl/src/com/intellij/psi/impl/source/PsiFileImpl.java index c7f29a62d3f5..40269892c466 100644 --- a/platform/core-impl/src/com/intellij/psi/impl/source/PsiFileImpl.java +++ b/platform/core-impl/src/com/intellij/psi/impl/source/PsiFileImpl.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2012 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. @@ -656,7 +656,7 @@ public abstract class PsiFileImpl extends ElementBase implements PsiFileEx, PsiF final VirtualFile vFile = getVirtualFile(); if (!(vFile instanceof VirtualFileWithId)) return null; - StubTree stubHolder = StubTreeLoader.getInstance().readOrBuild(getProject(), vFile); + StubTree stubHolder = StubTreeLoader.getInstance().readOrBuild(getProject(), vFile, this); if (stubHolder == null) return null; final IElementType contentElementType = getContentElementType(); diff --git a/platform/core-impl/src/com/intellij/psi/stubs/CoreStubTreeLoader.java b/platform/core-impl/src/com/intellij/psi/stubs/CoreStubTreeLoader.java index 0e2bc3d3e887..79d9aba68ac8 100644 --- a/platform/core-impl/src/com/intellij/psi/stubs/CoreStubTreeLoader.java +++ b/platform/core-impl/src/com/intellij/psi/stubs/CoreStubTreeLoader.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2011 JetBrains s.r.o. + * Copyright 2000-2012 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. @@ -22,11 +22,13 @@ import com.intellij.openapi.fileTypes.FileType; import com.intellij.openapi.fileTypes.LanguageFileType; import com.intellij.openapi.project.Project; import com.intellij.openapi.vfs.VirtualFile; +import com.intellij.psi.PsiFile; import com.intellij.psi.tree.IFileElementType; import com.intellij.psi.tree.IStubFileElementType; import com.intellij.util.indexing.FileContent; import com.intellij.util.indexing.FileContentImpl; import com.intellij.util.indexing.IndexingDataKeys; +import org.jetbrains.annotations.Nullable; import java.io.IOException; @@ -35,7 +37,7 @@ import java.io.IOException; */ public class CoreStubTreeLoader extends StubTreeLoader { @Override - public StubTree readOrBuild(Project project, VirtualFile vFile) { + public StubTree readOrBuild(Project project, VirtualFile vFile, @Nullable PsiFile psiFile) { if (!canHaveStub(vFile)) { return null; } diff --git a/platform/core-impl/src/com/intellij/psi/stubs/StubTreeBuilder.java b/platform/core-impl/src/com/intellij/psi/stubs/StubTreeBuilder.java index ae1bb7308faa..87e9ac441b6d 100644 --- a/platform/core-impl/src/com/intellij/psi/stubs/StubTreeBuilder.java +++ b/platform/core-impl/src/com/intellij/psi/stubs/StubTreeBuilder.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2011 JetBrains s.r.o. + * Copyright 2000-2012 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. @@ -24,6 +24,7 @@ import com.intellij.psi.PsiFile; import com.intellij.psi.tree.IFileElementType; import com.intellij.psi.tree.IStubFileElementType; import com.intellij.util.indexing.FileContent; +import com.intellij.util.indexing.IndexingDataKeys; import com.intellij.util.indexing.SubstitutedFileType; import org.jetbrains.annotations.Nullable; @@ -58,7 +59,7 @@ public class StubTreeBuilder { PsiFile psi = inputData.getPsiFile(); CharSequence contentAsText = inputData.getContentAsText(); - psi.putUserData(StubTreeLoader.FILE_TEXT_CONTENT_KEY, contentAsText); + psi.putUserData(IndexingDataKeys.FILE_TEXT_CONTENT_KEY, contentAsText); try { if (type instanceof IStubFileElementType) { @@ -72,7 +73,7 @@ public class StubTreeBuilder { } } finally { - psi.putUserData(StubTreeLoader.FILE_TEXT_CONTENT_KEY, null); + psi.putUserData(IndexingDataKeys.FILE_TEXT_CONTENT_KEY, null); } } diff --git a/platform/core-impl/src/com/intellij/psi/stubs/StubTreeLoader.java b/platform/core-impl/src/com/intellij/psi/stubs/StubTreeLoader.java index 47676ac67fd0..65df0f73aa29 100644 --- a/platform/core-impl/src/com/intellij/psi/stubs/StubTreeLoader.java +++ b/platform/core-impl/src/com/intellij/psi/stubs/StubTreeLoader.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2011 JetBrains s.r.o. + * Copyright 2000-2012 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. @@ -17,20 +17,20 @@ package com.intellij.psi.stubs; import com.intellij.openapi.components.ServiceManager; import com.intellij.openapi.project.Project; -import com.intellij.openapi.util.Key; import com.intellij.openapi.vfs.VirtualFile; +import com.intellij.psi.PsiFile; +import org.jetbrains.annotations.Nullable; /** * @author yole */ public abstract class StubTreeLoader { - public static final Key FILE_TEXT_CONTENT_KEY = Key.create("file text content cached by stub indexer"); public static StubTreeLoader getInstance() { return ServiceManager.getService(StubTreeLoader.class); } - public abstract StubTree readOrBuild(Project project, final VirtualFile vFile); + public abstract StubTree readOrBuild(Project project, final VirtualFile vFile, @Nullable final PsiFile psiFile); public abstract StubTree readFromVFile(Project project, final VirtualFile vFile); diff --git a/platform/core-impl/src/com/intellij/util/indexing/FileContentImpl.java b/platform/core-impl/src/com/intellij/util/indexing/FileContentImpl.java index 87a7c902bcd8..b081fb55e4bb 100644 --- a/platform/core-impl/src/com/intellij/util/indexing/FileContentImpl.java +++ b/platform/core-impl/src/com/intellij/util/indexing/FileContentImpl.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2011 JetBrains s.r.o. + * Copyright 2000-2012 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. @@ -174,6 +174,10 @@ public final class FileContentImpl extends UserDataHolderBase implements FileCon if (myFileType.isBinary()) { throw new IllegalDataException("Cannot obtain text for binary file type : " + myFileType.getDescription()); } + final CharSequence content = getUserData(IndexingDataKeys.FILE_TEXT_CONTENT_KEY); + if (content != null) { + return content; + } if (myContentAsText == null) { if (myContent != null) { myContentAsText = LoadTextUtil.getTextByBinaryPresentation(myContent, myCharset); diff --git a/platform/core-impl/src/com/intellij/util/indexing/IndexingDataKeys.java b/platform/core-impl/src/com/intellij/util/indexing/IndexingDataKeys.java index 6588432e8b3d..9bd34a57b775 100644 --- a/platform/core-impl/src/com/intellij/util/indexing/IndexingDataKeys.java +++ b/platform/core-impl/src/com/intellij/util/indexing/IndexingDataKeys.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2011 JetBrains s.r.o. + * Copyright 2000-2012 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. @@ -27,6 +27,7 @@ public class IndexingDataKeys { public static final Key VIRTUAL_FILE = new Key("Context virtual file"); public static final Key PROJECT = new Key("Context project"); public static final Key PSI_FILE = new Key("PSI for stubs"); + public static final Key FILE_TEXT_CONTENT_KEY = Key.create("file text content cached by stub indexer"); private IndexingDataKeys() { } diff --git a/platform/lang-impl/src/com/intellij/codeInsight/completion/CompletionLookupArranger.java b/platform/lang-impl/src/com/intellij/codeInsight/completion/CompletionLookupArranger.java index 968c6661ad76..24349ac574f6 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/completion/CompletionLookupArranger.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/completion/CompletionLookupArranger.java @@ -34,6 +34,7 @@ import com.intellij.psi.WeighingService; import com.intellij.psi.statistics.StatisticsInfo; import com.intellij.psi.statistics.StatisticsManager; import com.intellij.util.Alarm; +import com.intellij.util.ProcessingContext; import com.intellij.util.containers.ContainerUtil; import com.intellij.util.containers.MultiMap; import gnu.trove.THashMap; @@ -107,7 +108,7 @@ public class CompletionLookupArranger extends LookupArranger { } Classifier classifier = myClassifiers.get(sorter); if (classifier != null) { - classifier.describeItems(subMap); + classifier.describeItems(subMap, new ProcessingContext()); } } @@ -153,7 +154,7 @@ public class CompletionLookupArranger extends LookupArranger { final List byRelevance = new ArrayList(); for (CompletionSorterImpl sorter : myClassifiers.keySet()) { - ContainerUtil.addAll(byRelevance, myClassifiers.get(sorter).classify((List)inputBySorter.get(sorter))); + ContainerUtil.addAll(byRelevance, myClassifiers.get(sorter).classify(inputBySorter.get(sorter), new ProcessingContext())); } LinkedHashSet model = new LinkedHashSet(); diff --git a/platform/lang-impl/src/com/intellij/codeInsight/completion/impl/LiftShorterItemsClassifier.java b/platform/lang-impl/src/com/intellij/codeInsight/completion/impl/LiftShorterItemsClassifier.java index 41beadd8273f..c427e2aac308 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/completion/impl/LiftShorterItemsClassifier.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/completion/impl/LiftShorterItemsClassifier.java @@ -17,6 +17,7 @@ package com.intellij.codeInsight.completion.impl; import com.intellij.codeInsight.lookup.Classifier; import com.intellij.codeInsight.lookup.LookupElement; +import com.intellij.util.ProcessingContext; import com.intellij.util.SmartList; import com.intellij.util.containers.ContainerUtil; import com.intellij.util.containers.MultiMap; @@ -73,19 +74,25 @@ class LiftShorterItemsClassifier extends Classifier { } @Override - public Iterable classify(List source) { - return liftShorterElements(source, new THashSet(TObjectHashingStrategy.IDENTITY)); + public Iterable classify(Iterable source, ProcessingContext context) { + return liftShorterElements(source, new THashSet(TObjectHashingStrategy.IDENTITY), context); } - private List liftShorterElements(List source, THashSet lifted) { - final Set srcSet = new THashSet(source, TObjectHashingStrategy.IDENTITY); + private List liftShorterElements(Iterable source, THashSet lifted, ProcessingContext context) { + final Set srcSet = new THashSet(TObjectHashingStrategy.IDENTITY); + ContainerUtil.addAll(srcSet, source); final Set processed = new THashSet(TObjectHashingStrategy.IDENTITY); final List result = new ArrayList(); - for (LookupElement element : myNext.classify(source)) { + for (LookupElement element : myNext.classify(source, context)) { assert srcSet.contains(element) : myNext; if (processed.add(element)) { - for (String prefix : getSortedPrefixes(element)) { + final List prefixes = new SmartList(); + for (String string : getAllLookupStrings(element)) { + prefixes.addAll(myPrefixes.get(string)); + } + Collections.sort(prefixes); + for (String prefix : prefixes) { List shorter = new SmartList(); for (LookupElement shorterElement : myElements.get(prefix)) { if (srcSet.contains(shorterElement) && processed.add(shorterElement)) { @@ -95,7 +102,7 @@ class LiftShorterItemsClassifier extends Classifier { lifted.addAll(shorter); - ContainerUtil.addAll(result, myNext.classify(shorter)); + ContainerUtil.addAll(result, myNext.classify(shorter, context)); } result.add(element); } @@ -103,24 +110,14 @@ class LiftShorterItemsClassifier extends Classifier { return result; } - private String[] getSortedPrefixes(LookupElement element) { - final List prefixes = new SmartList(); - for (String string : getAllLookupStrings(element)) { - prefixes.addAll(myPrefixes.get(string)); - } - String[] result = prefixes.toArray(new String[prefixes.size()]); - Arrays.sort(result); - return result; - } - private static Set getAllLookupStrings(LookupElement element) { return element.getAllLookupStrings(); } @Override - public void describeItems(LinkedHashMap map) { + public void describeItems(LinkedHashMap map, ProcessingContext context) { final HashSet lifted = new HashSet(); - liftShorterElements(new ArrayList(map.keySet()), new THashSet(TObjectHashingStrategy.IDENTITY)); + liftShorterElements(new ArrayList(map.keySet()), new THashSet(TObjectHashingStrategy.IDENTITY), new ProcessingContext()); if (!lifted.isEmpty()) { for (LookupElement element : map.keySet()) { final StringBuilder builder = map.get(element); @@ -131,6 +128,6 @@ class LiftShorterItemsClassifier extends Classifier { builder.append("liftShorter=").append(lifted.contains(element)); } } - myNext.describeItems(map); + myNext.describeItems(map, context); } } diff --git a/platform/lang-impl/src/com/intellij/codeInsight/lookup/Classifier.java b/platform/lang-impl/src/com/intellij/codeInsight/lookup/Classifier.java index 7e177fd2ec57..bf5d9169eb41 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/lookup/Classifier.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/lookup/Classifier.java @@ -15,8 +15,9 @@ */ package com.intellij.codeInsight.lookup; +import com.intellij.util.ProcessingContext; + import java.util.LinkedHashMap; -import java.util.List; /** * @author peter @@ -24,8 +25,8 @@ import java.util.List; public abstract class Classifier { public abstract void addElement(T t); - public abstract Iterable classify(List source); + public abstract Iterable classify(Iterable source, ProcessingContext context); - public abstract void describeItems(LinkedHashMap map); + public abstract void describeItems(LinkedHashMap map, ProcessingContext context); } diff --git a/platform/lang-impl/src/com/intellij/codeInsight/lookup/ClassifierFactory.java b/platform/lang-impl/src/com/intellij/codeInsight/lookup/ClassifierFactory.java index 25a0a898c32d..ff78f6474270 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/lookup/ClassifierFactory.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/lookup/ClassifierFactory.java @@ -15,6 +15,8 @@ */ package com.intellij.codeInsight.lookup; +import com.intellij.util.ProcessingContext; + import java.util.*; /** @@ -40,12 +42,12 @@ public abstract class ClassifierFactory { } @Override - public Iterable classify(List source) { + public Iterable classify(Iterable source, ProcessingContext context) { return source; } @Override - public void describeItems(LinkedHashMap map) { + public void describeItems(LinkedHashMap map, ProcessingContext context) { } }; } diff --git a/platform/lang-impl/src/com/intellij/codeInsight/lookup/ComparingClassifier.java b/platform/lang-impl/src/com/intellij/codeInsight/lookup/ComparingClassifier.java index 2a2bf9f3ba88..96ccd6c3119b 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/lookup/ComparingClassifier.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/lookup/ComparingClassifier.java @@ -16,6 +16,7 @@ package com.intellij.codeInsight.lookup; import com.intellij.openapi.application.ApplicationManager; +import com.intellij.util.ProcessingContext; import com.intellij.util.SmartList; import com.intellij.util.containers.ContainerUtil; import org.jetbrains.annotations.NotNull; @@ -41,7 +42,7 @@ public abstract class ComparingClassifier extends Classifier { myNext.addElement(t); } - private TreeMap> groupByWeights(List source) { + private TreeMap> groupByWeights(Iterable source) { TreeMap> map = new TreeMap>(); for (T t : source) { final Comparable weight = getWeight(t); @@ -55,16 +56,16 @@ public abstract class ComparingClassifier extends Classifier { } @Override - public Iterable classify(List source) { + public Iterable classify(Iterable source, ProcessingContext context) { List result = new ArrayList(); for (List list : groupByWeights(source).values()) { - ContainerUtil.addAll(result, myNext.classify(list)); + ContainerUtil.addAll(result, myNext.classify(list, context)); } return result; } @Override - public void describeItems(LinkedHashMap map) { + public void describeItems(LinkedHashMap map, ProcessingContext context) { final TreeMap> treeMap = groupByWeights(new ArrayList(map.keySet())); if (treeMap.size() > 1 || ApplicationManager.getApplication().isUnitTestMode()) { for (Map.Entry> entry: treeMap.entrySet()){ @@ -78,6 +79,6 @@ public abstract class ComparingClassifier extends Classifier { } } } - myNext.describeItems(map); + myNext.describeItems(map, context); } } diff --git a/platform/lang-impl/src/com/intellij/ide/projectView/impl/nodes/PsiDirectoryNode.java b/platform/lang-impl/src/com/intellij/ide/projectView/impl/nodes/PsiDirectoryNode.java index 9487d55c8619..79c443dd51aa 100644 --- a/platform/lang-impl/src/com/intellij/ide/projectView/impl/nodes/PsiDirectoryNode.java +++ b/platform/lang-impl/src/com/intellij/ide/projectView/impl/nodes/PsiDirectoryNode.java @@ -91,11 +91,12 @@ public class PsiDirectoryNode extends BasePsiNode implements Navig data.addText(directoryFile.getName(), SimpleTextAttributes.REGULAR_ATTRIBUTES); } - if (parentValue instanceof Project) { + final boolean canAttach = ProjectAttachProcessor.canAttachToProject(); + if (parentValue instanceof Project && !canAttach) { final String location = FileUtil.getLocationRelativeToUserHome(((Project)parentValue).getPresentableUrl()); data.addText(" (" + location + ")", SimpleTextAttributes.GRAYED_ATTRIBUTES); } - else if (parentValue instanceof Module) { + else if (parentValue instanceof Module || (parentValue instanceof Project && canAttach)) { data.addText(" (" + directoryFile.getPresentableUrl() + ")", SimpleTextAttributes.GRAYED_ATTRIBUTES); } else if (ProjectRootsUtil.isSourceOrTestRoot(directoryFile, project)) { diff --git a/platform/lang-impl/src/com/intellij/psi/stubs/StubIndexImpl.java b/platform/lang-impl/src/com/intellij/psi/stubs/StubIndexImpl.java index 2af57b6d6bb2..82e345e4a253 100644 --- a/platform/lang-impl/src/com/intellij/psi/stubs/StubIndexImpl.java +++ b/platform/lang-impl/src/com/intellij/psi/stubs/StubIndexImpl.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2012 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. @@ -19,6 +19,8 @@ */ package com.intellij.psi.stubs; +import com.intellij.diagnostic.LogMessageEx; +import com.intellij.diagnostic.errordialog.Attachment; import com.intellij.lang.ASTNode; import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.application.ModalityState; @@ -289,7 +291,26 @@ public class StubIndexImpl extends StubIndex implements ApplicationComponent, Pe else { final List> plained = stubTree.getPlainList(); for (int i = 0; i < value.size(); i++) { - Psi psi = (Psi)plained.get(value.get(i)).getPsi(); + final int stubTreeIndex = value.get(i); + if (stubTreeIndex >= plained.size()) { + final VirtualFile virtualFile = psiFile.getVirtualFile(); + StubTree stubTreeFromIndex = StubTreeLoader.getInstance().readFromVFile(project, file); + LOG.error(LogMessageEx.createEvent("PSI and index do not match: PSI " + psiFile + ", first stub " + plained.get(0), + "Please report the problem to JetBrains with the file attached", + new Attachment(virtualFile != null ? virtualFile.getPath() : "vFile.txt", psiFile.getText()), + new Attachment("stubTree.txt", ((PsiFileStubImpl)stubTree.getRoot()).printTree()), + new Attachment("stubTreeFromIndex.txt", stubTreeFromIndex == null ? "null" : ((PsiFileStubImpl)stubTreeFromIndex.getRoot()).printTree()))); + + ApplicationManager.getApplication().invokeLater(new Runnable() { + @Override + public void run() { + fileBasedIndex.requestReindex(file); + } + }, ModalityState.NON_MODAL); + + break; + } + Psi psi = (Psi)plained.get(stubTreeIndex).getPsi(); if (!processor.process(psi)) return false; } } diff --git a/platform/lang-impl/src/com/intellij/psi/stubs/StubTreeLoaderImpl.java b/platform/lang-impl/src/com/intellij/psi/stubs/StubTreeLoaderImpl.java index ff4c9c15930e..b36b15eaa8c2 100644 --- a/platform/lang-impl/src/com/intellij/psi/stubs/StubTreeLoaderImpl.java +++ b/platform/lang-impl/src/com/intellij/psi/stubs/StubTreeLoaderImpl.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2011 JetBrains s.r.o. + * Copyright 2000-2012 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. @@ -23,6 +23,7 @@ import com.intellij.openapi.fileEditor.FileDocumentManager; import com.intellij.openapi.project.DumbService; import com.intellij.openapi.project.Project; import com.intellij.openapi.vfs.VirtualFile; +import com.intellij.psi.PsiFile; import com.intellij.psi.search.GlobalSearchScope; import com.intellij.util.indexing.*; import org.jetbrains.annotations.Nullable; @@ -38,7 +39,7 @@ public class StubTreeLoaderImpl extends StubTreeLoader { @Override @Nullable - public StubTree readOrBuild(Project project, final VirtualFile vFile) { + public StubTree readOrBuild(Project project, final VirtualFile vFile, @Nullable PsiFile psiFile) { final StubTree fromIndices = readFromVFile(project, vFile); if (fromIndices != null) { return fromIndices; @@ -51,6 +52,12 @@ public class StubTreeLoaderImpl extends StubTreeLoader { try { final FileContent fc = new FileContentImpl(vFile, vFile.contentsToByteArray()); fc.putUserData(IndexingDataKeys.PROJECT, project); + if (psiFile != null) { + fc.putUserData(IndexingDataKeys.PSI_FILE, psiFile); + if (!vFile.getFileType().isBinary()) { + fc.putUserData(IndexingDataKeys.FILE_TEXT_CONTENT_KEY, psiFile.getViewProvider().getContents()); + } + } final StubElement element = StubTreeBuilder.buildStubTree(fc); if (element instanceof PsiFileStub) { return new StubTree((PsiFileStub)element); diff --git a/plugins/github/github.iml b/plugins/github/github.iml index 7fb4da53f3f1..78782f798f90 100644 --- a/plugins/github/github.iml +++ b/plugins/github/github.iml @@ -12,8 +12,8 @@ - - + +