Partial body resolve: to take source Kotlin callables with Nothing type from caches
This commit is contained in:
@@ -28,16 +28,26 @@ import org.jetbrains.jet.lang.psi.JetElement;
|
||||
import org.jetbrains.jet.lang.psi.JetFile;
|
||||
import org.jetbrains.jet.lang.resolve.AdditionalCheckerProvider;
|
||||
import org.jetbrains.jet.lang.resolve.BindingContext;
|
||||
import org.jetbrains.jet.lang.resolve.lazy.DefaultNothingCallableNamesService;
|
||||
import org.jetbrains.jet.lang.resolve.lazy.ElementResolver;
|
||||
import org.jetbrains.jet.lang.resolve.lazy.PossiblyNothingCallableNamesService;
|
||||
import org.jetbrains.jet.lang.resolve.lazy.ResolveSession;
|
||||
import org.jetbrains.jet.plugin.stubindex.JetPossiblyNothingFunctionShortNameIndex;
|
||||
import org.jetbrains.jet.plugin.stubindex.JetPossiblyNothingPropertyShortNameIndex;
|
||||
import org.jetbrains.jet.storage.LazyResolveStorageManager;
|
||||
import org.jetbrains.jet.storage.MemoizedFunctionToNotNull;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
public class ResolveElementCache extends ElementResolver {
|
||||
private final Project project;
|
||||
private final CachedValue<MemoizedFunctionToNotNull<JetElement, BindingContext>> additionalResolveCache;
|
||||
|
||||
public ResolveElementCache(ResolveSession resolveSession, Project project) {
|
||||
super(resolveSession);
|
||||
this.project = project;
|
||||
|
||||
// Recreate internal cache after change of modification count
|
||||
this.additionalResolveCache =
|
||||
@@ -74,4 +84,29 @@ public class ResolveElementCache extends ElementResolver {
|
||||
public AdditionalCheckerProvider getAdditionalCheckerProvider(@NotNull JetFile jetFile) {
|
||||
return TargetPlatformDetector.getPlatform(jetFile).getAdditionalCheckerProvider();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
protected PossiblyNothingCallableNamesService possiblyNothingCallableNamesService() {
|
||||
return new PossiblyNothingCallableNamesService() {
|
||||
@NotNull
|
||||
@Override
|
||||
public Set<String> functionNames() {
|
||||
// we have to add hardcoded-names until we have Kotlin compiled classes in caches
|
||||
Set<String> hardcodedNames = DefaultNothingCallableNamesService.INSTANCE$.functionNames();
|
||||
Collection<String> indexedNames = JetPossiblyNothingFunctionShortNameIndex.getInstance().getAllKeys(project);
|
||||
Set<String> set = new HashSet<String>(hardcodedNames.size() + indexedNames.size());
|
||||
set.addAll(hardcodedNames);
|
||||
set.addAll(indexedNames);
|
||||
return set;
|
||||
//TODO: what about local declarations?
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Set<String> propertyNames() {
|
||||
return new HashSet<String>(JetPossiblyNothingPropertyShortNameIndex.getInstance().getAllKeys(project));
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
+50
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
* Copyright 2010-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.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.jet.plugin.stubindex;
|
||||
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.psi.search.GlobalSearchScope;
|
||||
import com.intellij.psi.stubs.StringStubIndexExtension;
|
||||
import com.intellij.psi.stubs.StubIndexKey;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lang.psi.JetNamedFunction;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
public class JetPossiblyNothingFunctionShortNameIndex extends StringStubIndexExtension<JetNamedFunction> {
|
||||
private static final StubIndexKey<String, JetNamedFunction> KEY = KotlinIndexUtil.createIndexKey(JetPossiblyNothingFunctionShortNameIndex.class);
|
||||
|
||||
private static final JetPossiblyNothingFunctionShortNameIndex ourInstance = new JetPossiblyNothingFunctionShortNameIndex();
|
||||
|
||||
public static JetPossiblyNothingFunctionShortNameIndex getInstance() {
|
||||
return ourInstance;
|
||||
}
|
||||
|
||||
private JetPossiblyNothingFunctionShortNameIndex() {}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public StubIndexKey<String, JetNamedFunction> getKey() {
|
||||
return KEY;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Collection<JetNamedFunction> get(@NotNull String s, @NotNull Project project, @NotNull GlobalSearchScope scope) {
|
||||
return super.get(s, project, JetSourceFilterScope.kotlinSourcesAndLibraries(scope, project));
|
||||
}
|
||||
}
|
||||
+50
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
* Copyright 2010-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.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.jet.plugin.stubindex;
|
||||
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.psi.search.GlobalSearchScope;
|
||||
import com.intellij.psi.stubs.StringStubIndexExtension;
|
||||
import com.intellij.psi.stubs.StubIndexKey;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lang.psi.JetProperty;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
public class JetPossiblyNothingPropertyShortNameIndex extends StringStubIndexExtension<JetProperty> {
|
||||
private static final StubIndexKey<String, JetProperty> KEY = KotlinIndexUtil.createIndexKey(JetPossiblyNothingPropertyShortNameIndex.class);
|
||||
|
||||
private static final JetPossiblyNothingPropertyShortNameIndex ourInstance = new JetPossiblyNothingPropertyShortNameIndex();
|
||||
|
||||
public static JetPossiblyNothingPropertyShortNameIndex getInstance() {
|
||||
return ourInstance;
|
||||
}
|
||||
|
||||
private JetPossiblyNothingPropertyShortNameIndex() {}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public StubIndexKey<String, JetProperty> getKey() {
|
||||
return KEY;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Collection<JetProperty> get(@NotNull String s, @NotNull Project project, @NotNull GlobalSearchScope scope) {
|
||||
return super.get(s, project, JetSourceFilterScope.kotlinSourcesAndLibraries(scope, project));
|
||||
}
|
||||
}
|
||||
@@ -113,6 +113,10 @@ public class StubIndexServiceImpl implements StubIndexService {
|
||||
}
|
||||
}
|
||||
sink.occurrence(JetFunctionShortNameIndex.getInstance().getKey(), name);
|
||||
|
||||
if (stub.isPossiblyNothingType()) {
|
||||
sink.occurrence(JetPossiblyNothingFunctionShortNameIndex.getInstance().getKey(), name);
|
||||
}
|
||||
}
|
||||
// can have special fq name in case of syntactically incorrect function with no name
|
||||
FqName topFQName = stub.getFqName();
|
||||
@@ -136,6 +140,10 @@ public class StubIndexServiceImpl implements StubIndexService {
|
||||
}
|
||||
|
||||
sink.occurrence(JetPropertyShortNameIndex.getInstance().getKey(), name);
|
||||
|
||||
if (stub.isPossiblyNothingType()) {
|
||||
sink.occurrence(JetPossiblyNothingPropertyShortNameIndex.getInstance().getKey(), name);
|
||||
}
|
||||
}
|
||||
// can have special fq name in case of syntactically incorrect function with no name
|
||||
if (stub.isTopLevel()) {
|
||||
|
||||
Reference in New Issue
Block a user