replace 'boolean forCompletion' parameter in PsiResolveHelper with ParameterTypeInferencePolicy class

This commit is contained in:
Dmitry Jemerov
2011-10-17 16:14:48 +02:00
parent 984a7bdb3c
commit 9435ad7311
17 changed files with 317 additions and 133 deletions
@@ -0,0 +1,22 @@
/*
* Copyright 2000-2011 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 com.intellij.psi;
public enum ConstraintType {
EQUALS,
SUBTYPE,
SUPERTYPE
}
@@ -18,6 +18,7 @@ package com.intellij.psi;
import com.intellij.openapi.components.ServiceManager;
import com.intellij.openapi.project.Project;
import com.intellij.pom.java.LanguageLevel;
import com.intellij.psi.impl.source.resolve.ParameterTypeInferencePolicy;
import com.intellij.psi.infos.CandidateInfo;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -122,7 +123,7 @@ public interface PsiResolveHelper {
@NotNull PsiExpression[] arguments,
@NotNull PsiSubstitutor partialSubstitutor,
@Nullable PsiElement parent,
final boolean forCompletion);
final ParameterTypeInferencePolicy policy);
@NotNull
PsiSubstitutor inferTypeArguments(@NotNull PsiTypeParameter[] typeParameters,
@@ -130,7 +131,7 @@ public interface PsiResolveHelper {
@NotNull PsiExpression[] arguments,
@NotNull PsiSubstitutor partialSubstitutor,
@NotNull PsiElement parent,
final boolean forCompletion);
final ParameterTypeInferencePolicy policy);
@NotNull
PsiSubstitutor inferTypeArguments(@NotNull PsiTypeParameter[] typeParameters,
@@ -0,0 +1,54 @@
/*
* Copyright 2000-2011 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 com.intellij.psi.impl.source.resolve;
import com.intellij.openapi.util.Pair;
import com.intellij.psi.*;
import org.jetbrains.annotations.Nullable;
/**
* @author yole
*/
public class DefaultParameterTypeInferencePolicy extends ParameterTypeInferencePolicy {
public static final DefaultParameterTypeInferencePolicy INSTANCE = new DefaultParameterTypeInferencePolicy();
private DefaultParameterTypeInferencePolicy() {
}
@Nullable
@Override
public Pair<PsiType, ConstraintType> inferTypeConstraintFromCallContext(PsiCallExpression innerMethodCall,
PsiExpressionList parent,
PsiCallExpression contextCall,
PsiTypeParameter typeParameter) {
return null;
}
@Override
public PsiType getDefaultExpectedType(PsiCallExpression methodCall) {
return PsiType.getJavaLangObject(methodCall.getManager(), methodCall.getResolveScope());
}
@Override
public Pair<PsiType, ConstraintType> getInferredTypeWithNoConstraint(PsiManager manager, PsiType superType) {
return new Pair<PsiType, ConstraintType>(superType, ConstraintType.SUBTYPE);
}
@Override
public PsiType adjustInferredType(PsiManager manager, PsiType guess, ConstraintType constraintType) {
return guess;
}
}
@@ -0,0 +1,37 @@
/*
* Copyright 2000-2011 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 com.intellij.psi.impl.source.resolve;
import com.intellij.openapi.util.Pair;
import com.intellij.psi.*;
import org.jetbrains.annotations.Nullable;
/**
* @author yole
*/
public abstract class ParameterTypeInferencePolicy {
@Nullable
public abstract Pair<PsiType, ConstraintType> inferTypeConstraintFromCallContext(PsiCallExpression innerMethodCall,
PsiExpressionList parent,
PsiCallExpression contextCall,
PsiTypeParameter typeParameter);
public abstract PsiType getDefaultExpectedType(PsiCallExpression methodCall);
public abstract Pair<PsiType, ConstraintType> getInferredTypeWithNoConstraint(PsiManager manager, PsiType superType);
public abstract PsiType adjustInferredType(PsiManager manager, PsiType guess, ConstraintType second);
}
@@ -17,6 +17,8 @@ package com.intellij.psi.infos;
import com.intellij.pom.java.LanguageLevel;
import com.intellij.psi.*;
import com.intellij.psi.impl.source.resolve.DefaultParameterTypeInferencePolicy;
import com.intellij.psi.impl.source.resolve.ParameterTypeInferencePolicy;
import com.intellij.psi.util.PsiUtil;
import org.jetbrains.annotations.Nullable;
@@ -84,7 +86,7 @@ public class MethodCandidateInfo extends CandidateInfo{
PsiSubstitutor incompleteSubstitutor = super.getSubstitutor();
PsiMethod method = getElement();
if (myTypeArguments == null) {
myCalcedSubstitutor = inferTypeArguments(false);
myCalcedSubstitutor = inferTypeArguments(DefaultParameterTypeInferencePolicy.INSTANCE);
}
else {
PsiTypeParameter[] typeParams = method.getTypeParameters();
@@ -114,13 +116,13 @@ public class MethodCandidateInfo extends CandidateInfo{
return (PsiMethod)super.getElement();
}
public PsiSubstitutor inferTypeArguments(final boolean forCompletion) {
return inferTypeArguments(forCompletion, myArgumentList instanceof PsiExpressionList
public PsiSubstitutor inferTypeArguments(final ParameterTypeInferencePolicy policy) {
return inferTypeArguments(policy, myArgumentList instanceof PsiExpressionList
? ((PsiExpressionList)myArgumentList).getExpressions()
: PsiExpression.EMPTY_ARRAY);
}
public PsiSubstitutor inferTypeArguments(final boolean forCompletion, final PsiExpression[] arguments) {
public PsiSubstitutor inferTypeArguments(final ParameterTypeInferencePolicy policy, final PsiExpression[] arguments) {
PsiMethod method = getElement();
PsiTypeParameter[] typeParameters = method.getTypeParameters();
@@ -133,7 +135,7 @@ public class MethodCandidateInfo extends CandidateInfo{
}
return javaPsiFacade.getResolveHelper().inferTypeArguments(typeParameters, method.getParameterList().getParameters(), arguments, mySubstitutor,
myArgumentList.getParent(), forCompletion);
myArgumentList.getParent(), policy);
}
public boolean isInferencePossible() {