diff --git a/java/java-tests/testSrc/com/intellij/util/indexing/IndexTest.groovy b/java/java-tests/testSrc/com/intellij/util/indexing/IndexTest.groovy index 78ec74be4788..0a7e2c107ea6 100644 --- a/java/java-tests/testSrc/com/intellij/util/indexing/IndexTest.groovy +++ b/java/java-tests/testSrc/com/intellij/util/indexing/IndexTest.groovy @@ -402,9 +402,13 @@ class IndexTest extends JavaCodeInsightFixtureTestCase { CodeStyleManager.getInstance(getProject()).reformat(psiFile) assert JavaPsiFacade.getInstance(project).findClass("Foo", scope) + def stamp = ((FileBasedIndexImpl)FileBasedIndex.instance).getIndexModificationStamp(StubUpdatingIndex.INDEX_ID, project) + IdeaTestUtil.setModuleLanguageLevel(myFixture.module, LanguageLevel.JDK_1_3) assert ((PsiJavaFile)psiFile).importList.node + + assert stamp != ((FileBasedIndexImpl)FileBasedIndex.instance).getIndexModificationStamp(StubUpdatingIndex.INDEX_ID, project) } void "test rename file with indexed associated unsaved document don't lost its data"() { diff --git a/platform/core-api/src/com/intellij/openapi/roots/impl/PushedFilePropertiesRetriever.java b/platform/core-api/src/com/intellij/openapi/roots/impl/PushedFilePropertiesRetriever.java new file mode 100644 index 000000000000..f756ac15c767 --- /dev/null +++ b/platform/core-api/src/com/intellij/openapi/roots/impl/PushedFilePropertiesRetriever.java @@ -0,0 +1,24 @@ +// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +package com.intellij.openapi.roots.impl; + +import com.intellij.openapi.components.ServiceManager; +import com.intellij.openapi.vfs.VirtualFile; +import org.jetbrains.annotations.ApiStatus; +import org.jetbrains.annotations.NotNull; + +import java.util.List; + +/** + * Proof of concept to mix pushed properties to stub index composite indexer data. + */ +@ApiStatus.Experimental +@ApiStatus.Internal +public interface PushedFilePropertiesRetriever { + + static PushedFilePropertiesRetriever getInstance() { + return ServiceManager.getService(PushedFilePropertiesRetriever.class); + } + + @NotNull + List dumpSortedPushedProperties(@NotNull VirtualFile file); +} diff --git a/platform/core-impl/src/com/intellij/psi/stubs/StubBuilderType.java b/platform/core-impl/src/com/intellij/psi/stubs/StubBuilderType.java index c5ad25188ad7..14f1d90e7873 100644 --- a/platform/core-impl/src/com/intellij/psi/stubs/StubBuilderType.java +++ b/platform/core-impl/src/com/intellij/psi/stubs/StubBuilderType.java @@ -3,21 +3,26 @@ package com.intellij.psi.stubs; import com.intellij.diagnostic.PluginException; import com.intellij.openapi.diagnostic.Logger; +import com.intellij.openapi.util.text.StringUtil; import com.intellij.psi.templateLanguages.TemplateLanguage; import com.intellij.psi.tree.IStubFileElementType; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import java.util.Collections; +import java.util.List; import java.util.Objects; class StubBuilderType { private static final Logger LOG = Logger.getInstance(StubBuilderType.class); private final IStubFileElementType myElementType; + private final List myProperties; private final BinaryFileStubBuilder myBinaryFileStubBuilder; private final Object myBinarySubBuilder; - StubBuilderType(@NotNull IStubFileElementType elementType) { + StubBuilderType(@NotNull IStubFileElementType elementType, @NotNull List properties) { myElementType = elementType; + myProperties = properties; myBinaryFileStubBuilder = null; myBinarySubBuilder = null; } @@ -26,6 +31,7 @@ class StubBuilderType { myElementType = null; myBinaryFileStubBuilder = binaryFileStubBuilder; myBinarySubBuilder = null; + myProperties = Collections.emptyList(); } StubBuilderType(@NotNull BinaryFileStubBuilder.CompositeBinaryFileStubBuilder binaryFileStubBuilder, @@ -33,6 +39,7 @@ class StubBuilderType { myElementType = null; myBinaryFileStubBuilder = binaryFileStubBuilder; myBinarySubBuilder = binarySubBuilder; + myProperties = Collections.emptyList(); } BinaryFileStubBuilder getBinaryFileStubBuilder() { @@ -46,7 +53,8 @@ class StubBuilderType { PluginException.logPluginError(LOG, myElementType.getLanguage() + " stub version should call super.getStubVersion()", null, myElementType.getClass()); } - return myElementType.getClass().getName() + ":" + myElementType.getStubVersion(); + String baseVersion = myElementType.getClass().getName() + ":" + myElementType.getStubVersion(); + return myProperties.isEmpty() ? baseVersion : (baseVersion + ":" + StringUtil.join(myProperties, ",")); } else { assert myBinaryFileStubBuilder != null; String baseVersion = myBinaryFileStubBuilder.getClass().getName() + ":" + myBinaryFileStubBuilder.getStubVersion(); @@ -65,11 +73,12 @@ class StubBuilderType { StubBuilderType type = (StubBuilderType)o; return Objects.equals(myElementType, type.myElementType) && Objects.equals(myBinaryFileStubBuilder, type.myBinaryFileStubBuilder) && + Objects.equals(myProperties, type.myProperties) && Objects.equals(myBinarySubBuilder, type.myBinarySubBuilder); } @Override public int hashCode() { - return Objects.hash(myElementType, myBinaryFileStubBuilder, myBinarySubBuilder); + return Objects.hash(myElementType, myBinaryFileStubBuilder, myBinarySubBuilder, myProperties); } } 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 c53c2628a67e..01f151d800cc 100644 --- a/platform/core-impl/src/com/intellij/psi/stubs/StubTreeBuilder.java +++ b/platform/core-impl/src/com/intellij/psi/stubs/StubTreeBuilder.java @@ -21,10 +21,12 @@ import com.intellij.lang.ParserDefinition; import com.intellij.lang.TreeBackedLighterAST; import com.intellij.openapi.fileTypes.FileType; import com.intellij.openapi.fileTypes.LanguageFileType; +import com.intellij.openapi.roots.impl.PushedFilePropertiesRetriever; import com.intellij.openapi.util.Key; import com.intellij.openapi.util.Pair; import com.intellij.openapi.util.Trinity; import com.intellij.openapi.util.text.StringUtil; +import com.intellij.openapi.vfs.VirtualFile; import com.intellij.psi.FileViewProvider; import com.intellij.psi.PsiFile; import com.intellij.psi.StubBuilder; @@ -75,9 +77,11 @@ public class StubTreeBuilder { final IFileElementType elementType = parserDefinition.getFileNodeType(); if (!(elementType instanceof IStubFileElementType)) return null; - boolean shouldBuildStubFor = ((IStubFileElementType)elementType).shouldBuildStubFor(file.getFile()); + VirtualFile vFile = file.getFile(); + boolean shouldBuildStubFor = ((IStubFileElementType)elementType).shouldBuildStubFor(vFile); if (toBuild && !shouldBuildStubFor) return null; - return new StubBuilderType((IStubFileElementType)elementType); + @NotNull List properties = PushedFilePropertiesRetriever.getInstance().dumpSortedPushedProperties(vFile); + return new StubBuilderType((IStubFileElementType)elementType, properties); } return null; diff --git a/platform/lang-impl/src/com/intellij/openapi/roots/impl/PushedFilePropertiesRetrieverImpl.java b/platform/lang-impl/src/com/intellij/openapi/roots/impl/PushedFilePropertiesRetrieverImpl.java new file mode 100644 index 000000000000..7fd636b73171 --- /dev/null +++ b/platform/lang-impl/src/com/intellij/openapi/roots/impl/PushedFilePropertiesRetrieverImpl.java @@ -0,0 +1,45 @@ +// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +package com.intellij.openapi.roots.impl; + +import com.intellij.openapi.vfs.VirtualFile; +import com.intellij.psi.stubs.StubUpdatingIndex; +import com.intellij.util.SmartList; +import com.intellij.util.containers.ContainerUtil; +import org.jetbrains.annotations.NotNull; + +import java.util.Collections; +import java.util.List; + +public class PushedFilePropertiesRetrieverImpl implements PushedFilePropertiesRetriever { + @NotNull + @Override + public List dumpSortedPushedProperties(@NotNull VirtualFile file) { + if (file.isDirectory()) { + throw new IllegalArgumentException("file " + file + " is expected to be a regular file"); + } + if (StubUpdatingIndex.USE_SNAPSHOT_MAPPINGS) { + List> extensions = FilePropertyPusher.EP_NAME.getExtensionList(); + List properties = new SmartList<>(); + for (FilePropertyPusher extension : extensions) { + Object property; + VirtualFile vfsObject; + if (extension.pushDirectoriesOnly()) { + vfsObject = file.getParent(); + } + else { + vfsObject = file; + } + property = vfsObject.getUserData(extension.getFileDataKey()); + if (property != null) { + properties.add(property.toString()); + } + } + + ContainerUtil.sort(properties); + return properties; + } + else { + return Collections.emptyList(); + } + } +} diff --git a/platform/lang-impl/src/com/intellij/psi/stubs/StubUpdatingIndex.java b/platform/lang-impl/src/com/intellij/psi/stubs/StubUpdatingIndex.java index 6fa696001135..787bc3af0ae3 100644 --- a/platform/lang-impl/src/com/intellij/psi/stubs/StubUpdatingIndex.java +++ b/platform/lang-impl/src/com/intellij/psi/stubs/StubUpdatingIndex.java @@ -48,6 +48,8 @@ import java.util.stream.Stream; public final class StubUpdatingIndex extends SingleEntryFileBasedIndexExtension implements CustomImplementationFileBasedIndexExtension { static final Logger LOG = Logger.getInstance(StubUpdatingIndex.class); + public static final boolean USE_SNAPSHOT_MAPPINGS = SystemProperties.is("stubs.use.snapshot.mappings"); + private static final int VERSION = 45 + (PersistentHashMapValueStorage.COMPRESSION_ENABLED ? 1 : 0); // todo remove once we don't need this for stub-ast mismatch debug info @@ -75,7 +77,7 @@ public final class StubUpdatingIndex extends SingleEntryFileBasedIndexExtension< @Override public boolean hasSnapshotMapping() { - return SystemProperties.is("stubs.use.snapshot.mappings"); + return USE_SNAPSHOT_MAPPINGS; } public static boolean canHaveStub(@NotNull VirtualFile file) { diff --git a/platform/platform-resources/src/META-INF/PlatformLangPlugin.xml b/platform/platform-resources/src/META-INF/PlatformLangPlugin.xml index 0d7f9534df45..f438e7e0f014 100644 --- a/platform/platform-resources/src/META-INF/PlatformLangPlugin.xml +++ b/platform/platform-resources/src/META-INF/PlatformLangPlugin.xml @@ -92,6 +92,9 @@ + +