Change Signature: Add support of type parameter substitutions in overriding members

This commit is contained in:
Alexey Sedunov
2014-12-02 14:02:15 +03:00
parent 250940c824
commit c917459926
29 changed files with 638 additions and 131 deletions
@@ -26,18 +26,19 @@ import com.intellij.openapi.util.NullableLazyValue;
import com.intellij.openapi.util.Pair;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.psi.*;
import com.intellij.psi.PsiPackage;
import com.intellij.psi.impl.PsiManagerImpl;
import com.intellij.psi.impl.compiled.ClsFileImpl;
import com.intellij.psi.impl.java.stubs.PsiJavaFileStub;
import com.intellij.psi.impl.light.LightClass;
import com.intellij.psi.impl.light.LightMethod;
import com.intellij.psi.scope.PsiScopeProcessor;
import com.intellij.psi.stubs.PsiClassHolderFileStub;
import com.intellij.psi.util.CachedValue;
import com.intellij.psi.util.CachedValuesManager;
import com.intellij.psi.util.PsiTreeUtil;
import com.intellij.util.ArrayUtil;
import com.intellij.util.IncorrectOperationException;
import jet.runtime.typeinfo.JetValueParameter;
import kotlin.Function1;
import kotlin.KotlinPackage;
import org.jetbrains.annotations.NonNls;
@@ -58,7 +59,6 @@ import org.jetbrains.jet.lexer.JetModifierKeywordToken;
import org.jetbrains.jet.plugin.JetLanguage;
import javax.swing.*;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
@@ -299,6 +299,27 @@ public class KotlinLightClassForExplicitDeclaration extends KotlinWrappingLightC
public PsiClassHolderFileStub getStub() {
return getJavaFileStub();
}
@SuppressWarnings("Contract")
@Override
public boolean processDeclarations(
@NotNull PsiScopeProcessor processor,
@NotNull ResolveState state,
PsiElement lastParent,
@NotNull PsiElement place
) {
if (!super.processDeclarations(processor, state, lastParent, place)) return false;
// We have to explicitly process package declarations if current file belongs to default package
// so that Java resolve can find classes located in that package
String packageName = getPackageName();
if (!packageName.isEmpty()) return true;
PsiPackage aPackage = JavaPsiFacade.getInstance(myManager.getProject()).findPackage(packageName);
if (aPackage != null && !aPackage.processDeclarations(processor, state, null, place)) return false;
return true;
}
};
}
};
@@ -359,6 +380,11 @@ public class KotlinLightClassForExplicitDeclaration extends KotlinWrappingLightC
return parent.getValue();
}
@Override
public PsiElement getContext() {
return getParent();
}
@Nullable
@Override
public PsiTypeParameterList getTypeParameterList() {
@@ -32,6 +32,9 @@ import org.jetbrains.jet.lang.psi.JetClassOrObject
import com.intellij.psi.impl.light.LightTypeParameterListBuilder
import com.intellij.psi.search.SearchScope
import com.intellij.lang.Language
import com.intellij.psi.scope.PsiScopeProcessor
import com.intellij.psi.util.MethodSignature
import com.intellij.psi.util.MethodSignatureBackedByPsiMethod
open public class KotlinLightMethodForDeclaration(
manager: PsiManager,
@@ -43,7 +46,7 @@ open public class KotlinLightMethodForDeclaration(
private val paramsList: CachedValue<PsiParameterList> by Delegates.blockingLazy {
val cacheManager = CachedValuesManager.getManager(delegate.getProject())
cacheManager.createCachedValue<PsiParameterList>({
val parameterBuilder = LightParameterListBuilder(getManager(), JetLanguage.INSTANCE)
val parameterBuilder = LightParameterListBuilder(getManager(), JetLanguage.INSTANCE, this)
for ((index, parameter) in delegate.getParameterList().getParameters().withIndices()) {
parameterBuilder.addParameter(KotlinLightParameter(parameter, index, this))
@@ -56,10 +59,8 @@ open public class KotlinLightMethodForDeclaration(
private val typeParamsList: CachedValue<PsiTypeParameterList> by Delegates.blockingLazy {
val cacheManager = CachedValuesManager.getManager(delegate.getProject())
cacheManager.createCachedValue<PsiTypeParameterList>({
val declaration = if (origin is JetPropertyAccessor) origin.getNonStrictParentOfType<JetProperty>() else origin
val list = if (origin is JetClassOrObject) {
LightTypeParameterListBuilder(getManager(), getLanguage())
KotlinLightTypeParameterListBuilder(getManager())
}
else {
LightClassUtil.buildLightTypeParameterList(this@KotlinLightMethodForDeclaration, origin)
@@ -98,6 +99,13 @@ open public class KotlinLightMethodForDeclaration(
override fun getTypeParameters(): Array<PsiTypeParameter> =
getTypeParameterList()?.let { it.getTypeParameters() } ?: PsiTypeParameter.EMPTY_ARRAY
override fun getSignature(substitutor: PsiSubstitutor): MethodSignature {
if (substitutor == PsiSubstitutor.EMPTY) {
return delegate.getSignature(substitutor)
}
return MethodSignatureBackedByPsiMethod.create(this, substitutor)
}
override fun copy(): PsiElement {
return KotlinLightMethodForDeclaration(getManager()!!, delegate, origin.copy() as JetDeclaration, getContainingClass()!!)
}
@@ -106,6 +114,10 @@ open public class KotlinLightMethodForDeclaration(
override fun getLanguage(): Language = JetLanguage.INSTANCE
override fun processDeclarations(processor: PsiScopeProcessor, state: ResolveState, lastParent: PsiElement?, place: PsiElement): Boolean {
return getTypeParameters().all { processor.execute(it, state) }
}
override fun equals(other: Any?): Boolean =
other is KotlinLightMethodForDeclaration &&
getName() == other.getName() &&
@@ -134,4 +134,10 @@ public class KotlinLightTypeParameter
public Language getLanguage() {
return JetLanguage.INSTANCE;
}
@Override
public boolean equals(Object obj) {
if (obj == this) return true;
return obj instanceof KotlinLightTypeParameter && getOrigin().equals(((KotlinLightTypeParameter) obj).getOrigin());
}
}
@@ -0,0 +1,30 @@
/*
* 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.asJava
import com.intellij.psi.PsiManager
import org.jetbrains.jet.plugin.JetLanguage
import com.intellij.psi.impl.light.LightTypeParameterListBuilder
import com.intellij.psi.scope.PsiScopeProcessor
import com.intellij.psi.ResolveState
import com.intellij.psi.PsiElement
public class KotlinLightTypeParameterListBuilder(manager: PsiManager): LightTypeParameterListBuilder(manager, JetLanguage.INSTANCE) {
override fun processDeclarations(processor: PsiScopeProcessor, state: ResolveState, lastParent: PsiElement?, place: PsiElement): Boolean {
return getTypeParameters().all { processor.execute(it, state) }
}
}
@@ -301,7 +301,7 @@ public class LightClassUtil {
public static PsiTypeParameterList buildLightTypeParameterList(
PsiTypeParameterListOwner owner,
JetDeclaration declaration) {
LightTypeParameterListBuilder builder = new LightTypeParameterListBuilder(owner.getManager(), owner.getLanguage());
LightTypeParameterListBuilder builder = new KotlinLightTypeParameterListBuilder(owner.getManager());
if (declaration instanceof JetTypeParameterListOwner) {
JetTypeParameterListOwner typeParameterListOwner = (JetTypeParameterListOwner) declaration;
List<JetTypeParameter> parameters = typeParameterListOwner.getTypeParameters();
@@ -27,10 +27,12 @@ import java.util.List;
// Copy of com.intellij.psi.impl.light.LightParameterListBuilder
public class LightParameterListBuilder extends LightElement implements PsiParameterList {
private final List<PsiParameter> myParameters = new ArrayList<PsiParameter>();
private final KotlinLightMethod parent;
private PsiParameter[] myCachedParameters;
public LightParameterListBuilder(PsiManager manager, Language language) {
public LightParameterListBuilder(PsiManager manager, Language language, KotlinLightMethod parent) {
super(manager, language);
this.parent = parent;
}
public void addParameter(PsiParameter parameter) {
@@ -38,6 +40,11 @@ public class LightParameterListBuilder extends LightElement implements PsiParame
myCachedParameters = null;
}
@Override
public KotlinLightMethod getParent() {
return parent;
}
@Override
public String toString() {
return "Light parameter lsit";