This commit is contained in:
Alexey Kudravtsev
2013-12-24 13:33:57 +04:00
parent 9930be003a
commit 62b2dde37f
3 changed files with 26 additions and 15 deletions
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2009 JetBrains s.r.o.
* Copyright 2000-2013 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.
@@ -37,7 +37,9 @@ public interface PsiSubstitutor {
* <b>Example:</b> consider class <code>List&lt;E&gt;</code>. <code>this</code>
* inside class <code>List</code> has type List with EMPTY substitutor.
*/
@NotNull
PsiSubstitutor EMPTY = EmptySubstitutor.getInstance();
@NotNull
PsiSubstitutor UNKNOWN = EMPTY;
/**
@@ -61,7 +63,7 @@ public interface PsiSubstitutor {
//Should be used with great care, be sure to prevent infinite recursion that could arise
// from the use of recursively bounded type parameters
PsiType substituteWithBoundsPromotion(PsiTypeParameter typeParameter);
PsiType substituteWithBoundsPromotion(@NotNull PsiTypeParameter typeParameter);
/**
* Creates a substitutor instance which provides the specified parameter to type mapping in addition
@@ -71,7 +73,8 @@ public interface PsiSubstitutor {
* @param mapping the type to which the parameter is mapped.
* @return the new substitutor instance.
*/
PsiSubstitutor put(PsiTypeParameter classParameter, PsiType mapping);
@NotNull
PsiSubstitutor put(@NotNull PsiTypeParameter classParameter, PsiType mapping);
/**
* Creates a substitutor instance which maps the type parameters of the specified class to the
@@ -81,7 +84,8 @@ public interface PsiSubstitutor {
* @param mappings the types to which the parameters are mapped.
* @return the new substitutor instance.
*/
PsiSubstitutor putAll(PsiClass parentClass, PsiType[] mappings);
@NotNull
PsiSubstitutor putAll(@NotNull PsiClass parentClass, PsiType[] mappings);
/**
* Creates a substitutor instance containing all mappings from this substitutor and the
@@ -90,7 +94,8 @@ public interface PsiSubstitutor {
* @param another the substitutor to get the mappings from.
* @return the new substitutor instance.
*/
PsiSubstitutor putAll(PsiSubstitutor another);
@NotNull
PsiSubstitutor putAll(@NotNull PsiSubstitutor another);
/**
* Returns the map from type parameters to types used for substitution by this substitutor.
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2009 JetBrains s.r.o.
* Copyright 2000-2013 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.
@@ -38,26 +38,29 @@ public final class EmptySubstitutorImpl extends EmptySubstitutor {
}
@Override
public PsiType substituteWithBoundsPromotion(PsiTypeParameter typeParameter) {
public PsiType substituteWithBoundsPromotion(@NotNull PsiTypeParameter typeParameter) {
return JavaPsiFacade.getInstance(typeParameter.getProject()).getElementFactory().createType(typeParameter);
}
@NotNull
@Override
public PsiSubstitutor put(PsiTypeParameter classParameter, PsiType mapping){
public PsiSubstitutor put(@NotNull PsiTypeParameter classParameter, PsiType mapping){
if (mapping != null && !mapping.isValid()) {
LOG.error("Invalid type in substitutor: " + mapping);
}
return new PsiSubstitutorImpl(classParameter, mapping);
}
@NotNull
@Override
public PsiSubstitutor putAll(PsiClass parentClass, PsiType[] mappings){
public PsiSubstitutor putAll(@NotNull PsiClass parentClass, PsiType[] mappings){
if(!parentClass.hasTypeParameters()) return this;
return new PsiSubstitutorImpl(parentClass, mappings);
}
@NotNull
@Override
public PsiSubstitutor putAll(PsiSubstitutor another) {
public PsiSubstitutor putAll(@NotNull PsiSubstitutor another) {
return another;
}
@@ -86,7 +86,7 @@ public class PsiSubstitutorImpl implements PsiSubstitutor {
return mySubstitutionMap.containsKey(typeParameter);
}
private PsiType getFromMap(PsiTypeParameter typeParameter) {
private PsiType getFromMap(@NotNull PsiTypeParameter typeParameter) {
if (typeParameter instanceof LightTypeParameter) {
typeParameter = ((LightTypeParameter)typeParameter).getDelegate();
}
@@ -105,7 +105,7 @@ public class PsiSubstitutorImpl implements PsiSubstitutor {
}
@Override
public PsiType substituteWithBoundsPromotion(PsiTypeParameter typeParameter) {
public PsiType substituteWithBoundsPromotion(@NotNull PsiTypeParameter typeParameter) {
return addBounds(substitute(typeParameter), typeParameter);
}
@@ -306,7 +306,7 @@ public class PsiSubstitutorImpl implements PsiSubstitutor {
return result;
}
private PsiType substituteTypeParameter(final PsiTypeParameter typeParameter) {
private PsiType substituteTypeParameter(@NotNull PsiTypeParameter typeParameter) {
PsiType t = getFromMap(typeParameter);
if (myKind == SubstituteKind.SIMPLE) {
return t;
@@ -350,7 +350,7 @@ public class PsiSubstitutorImpl implements PsiSubstitutor {
}
}
private PsiType addBounds(PsiType substituted, final PsiTypeParameter typeParameter) {
private PsiType addBounds(PsiType substituted, @NotNull PsiTypeParameter typeParameter) {
PsiType oldSubstituted = substituted;
PsiElement captureContext = null;
if (substituted instanceof PsiCapturedWildcardType) {
@@ -432,6 +432,7 @@ public class PsiSubstitutorImpl implements PsiSubstitutor {
return new PsiSubstitutorImpl(mySubstitutionMap);
}
@NotNull
@Override
public PsiSubstitutor put(@NotNull PsiTypeParameter typeParameter, PsiType mapping) {
PsiSubstitutorImpl ret = clone();
@@ -461,6 +462,7 @@ public class PsiSubstitutorImpl implements PsiSubstitutor {
}
}
@NotNull
@Override
public PsiSubstitutor putAll(@NotNull PsiClass parentClass, PsiType[] mappings) {
PsiSubstitutorImpl substitutor = clone();
@@ -468,8 +470,9 @@ public class PsiSubstitutorImpl implements PsiSubstitutor {
return substitutor;
}
@NotNull
@Override
public PsiSubstitutor putAll(PsiSubstitutor another) {
public PsiSubstitutor putAll(@NotNull PsiSubstitutor another) {
if (another instanceof EmptySubstitutorImpl) return this;
final PsiSubstitutorImpl anotherImpl = (PsiSubstitutorImpl)another;
PsiSubstitutorImpl substitutor = clone();