Create from usage: Changed type of TypeOrExpressionThereof.typeCandidates to List instead of array.
This commit is contained in:
@@ -143,7 +143,7 @@ public class CreateFunctionFromUsageFix extends CreateFromUsageFixBase {
|
|||||||
private final JetExpression expressionOfType;
|
private final JetExpression expressionOfType;
|
||||||
private final JetType type;
|
private final JetType type;
|
||||||
private final Variance variance;
|
private final Variance variance;
|
||||||
private TypeCandidate[] typeCandidates;
|
private List<TypeCandidate> typeCandidates;
|
||||||
private String[] cachedNameCandidatesFromExpression;
|
private String[] cachedNameCandidatesFromExpression;
|
||||||
|
|
||||||
public TypeOrExpressionThereof(@NotNull JetExpression expressionOfType, Variance variance) {
|
public TypeOrExpressionThereof(@NotNull JetExpression expressionOfType, Variance variance) {
|
||||||
@@ -194,11 +194,9 @@ public class CreateFunctionFromUsageFix extends CreateFromUsageFixBase {
|
|||||||
public void computeTypeCandidates(@NotNull BindingContext context) {
|
public void computeTypeCandidates(@NotNull BindingContext context) {
|
||||||
Collection<JetType> types = getPossibleTypes(context);
|
Collection<JetType> types = getPossibleTypes(context);
|
||||||
|
|
||||||
typeCandidates = new TypeCandidate[types.size()];
|
typeCandidates = new ArrayList<TypeCandidate>();
|
||||||
int i = 0;
|
|
||||||
for (JetType type : types) {
|
for (JetType type : types) {
|
||||||
typeCandidates[i] = new TypeCandidate(type);
|
typeCandidates.add(new TypeCandidate(type));
|
||||||
i++;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -229,16 +227,15 @@ public class CreateFunctionFromUsageFix extends CreateFromUsageFixBase {
|
|||||||
newTypes.add(KotlinBuiltIns.getInstance().getAnyType());
|
newTypes.add(KotlinBuiltIns.getInstance().getAnyType());
|
||||||
}
|
}
|
||||||
|
|
||||||
typeCandidates = new TypeCandidate[newTypes.size()];
|
typeCandidates = new ArrayList<TypeCandidate>();
|
||||||
int i = typeCandidates.length - 1; // reverse order (see explanation above)
|
|
||||||
for (JetType type : newTypes) {
|
for (JetType type : newTypes) {
|
||||||
typeCandidates[i] = new TypeCandidate(type, scope);
|
typeCandidates.add(new TypeCandidate(type, scope));
|
||||||
i--;
|
|
||||||
}
|
}
|
||||||
|
Collections.reverse(typeCandidates); // reverse order (see explanation above)
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public TypeCandidate[] getTypeCandidates() {
|
public List<TypeCandidate> getTypeCandidates() {
|
||||||
assert typeCandidates != null : "call computeTypeCandidates() first";
|
assert typeCandidates != null : "call computeTypeCandidates() first";
|
||||||
return typeCandidates;
|
return typeCandidates;
|
||||||
}
|
}
|
||||||
@@ -379,10 +376,10 @@ public class CreateFunctionFromUsageFix extends CreateFromUsageFixBase {
|
|||||||
|
|
||||||
public TypeExpression(@NotNull TypeOrExpressionThereof type) {
|
public TypeExpression(@NotNull TypeOrExpressionThereof type) {
|
||||||
this.type = type;
|
this.type = type;
|
||||||
TypeCandidate[] candidates = type.getTypeCandidates();
|
List<TypeCandidate> candidates = type.getTypeCandidates();
|
||||||
cachedLookupElements = new LookupElement[candidates.length];
|
cachedLookupElements = new LookupElement[candidates.size()];
|
||||||
for (int i = 0; i < candidates.length; i++) {
|
for (int i = 0; i < candidates.size(); i++) {
|
||||||
cachedLookupElements[i] = LookupElementBuilder.create(candidates[i], candidates[i].getRenderedType());
|
cachedLookupElements[i] = LookupElementBuilder.create(candidates.get(i), candidates.get(i).getRenderedType());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -414,8 +411,7 @@ public class CreateFunctionFromUsageFix extends CreateFromUsageFixBase {
|
|||||||
|
|
||||||
@Nullable("can't be found")
|
@Nullable("can't be found")
|
||||||
public JetType getTypeFromSelection(@NotNull String selection) {
|
public JetType getTypeFromSelection(@NotNull String selection) {
|
||||||
TypeCandidate[] options = type.getTypeCandidates();
|
for (TypeCandidate option : type.getTypeCandidates()) {
|
||||||
for (TypeCandidate option : options) {
|
|
||||||
if (option.getRenderedType().equals(selection)) {
|
if (option.getRenderedType().equals(selection)) {
|
||||||
return option.getType();
|
return option.getType();
|
||||||
}
|
}
|
||||||
@@ -556,10 +552,10 @@ public class CreateFunctionFromUsageFix extends CreateFromUsageFixBase {
|
|||||||
currentFileContext = AnalyzerFacadeWithCache.analyzeFileWithCache(currentFile).getBindingContext();
|
currentFileContext = AnalyzerFacadeWithCache.analyzeFileWithCache(currentFile).getBindingContext();
|
||||||
|
|
||||||
ownerType.computeTypeCandidates(currentFileContext);
|
ownerType.computeTypeCandidates(currentFileContext);
|
||||||
TypeCandidate[] ownerTypeCandidates = ownerType.getTypeCandidates();
|
List<TypeCandidate> ownerTypeCandidates = ownerType.getTypeCandidates();
|
||||||
assert ownerTypeCandidates.length > 0;
|
assert !ownerTypeCandidates.isEmpty();
|
||||||
if (ownerTypeCandidates.length == 1 || ApplicationManager.getApplication().isUnitTestMode()) {
|
if (ownerTypeCandidates.size() == 1 || ApplicationManager.getApplication().isUnitTestMode()) {
|
||||||
selectedReceiverType = ownerTypeCandidates[0];
|
selectedReceiverType = ownerTypeCandidates.get(0);
|
||||||
doInvoke(project);
|
doInvoke(project);
|
||||||
} else {
|
} else {
|
||||||
// class selection
|
// class selection
|
||||||
@@ -773,15 +769,13 @@ public class CreateFunctionFromUsageFix extends CreateFromUsageFixBase {
|
|||||||
allTypeParametersNotInScope.addAll(Arrays.asList(receiverTypeParametersNotInScope));
|
allTypeParametersNotInScope.addAll(Arrays.asList(receiverTypeParametersNotInScope));
|
||||||
|
|
||||||
for (Parameter parameter : parameters) {
|
for (Parameter parameter : parameters) {
|
||||||
TypeCandidate[] parameterTypeCandidates = parameter.getType().getTypeCandidates();
|
for (TypeCandidate parameterTypeCandidate : parameter.getType().getTypeCandidates()) {
|
||||||
for (TypeCandidate parameterTypeCandidate : parameterTypeCandidates) {
|
|
||||||
allTypeParametersNotInScope.addAll(Arrays.asList(parameterTypeCandidate.getTypeParameters()));
|
allTypeParametersNotInScope.addAll(Arrays.asList(parameterTypeCandidate.getTypeParameters()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isUnit) {
|
if (!isUnit) {
|
||||||
TypeCandidate[] returnTypeCandidates = returnType.getTypeCandidates();
|
for (TypeCandidate returnTypeCandidate : returnType.getTypeCandidates()) {
|
||||||
for (TypeCandidate returnTypeCandidate : returnTypeCandidates) {
|
|
||||||
allTypeParametersNotInScope.addAll(Arrays.asList(returnTypeCandidate.getTypeParameters()));
|
allTypeParametersNotInScope.addAll(Arrays.asList(returnTypeCandidate.getTypeParameters()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -898,16 +892,14 @@ public class CreateFunctionFromUsageFix extends CreateFromUsageFixBase {
|
|||||||
String[] receiverTypeParameterNames = selectedReceiverType.getTypeParameterNames();
|
String[] receiverTypeParameterNames = selectedReceiverType.getTypeParameterNames();
|
||||||
|
|
||||||
for (Parameter parameter : parameters) {
|
for (Parameter parameter : parameters) {
|
||||||
TypeCandidate[] parameterTypeCandidates = parameter.getType().getTypeCandidates();
|
for (TypeCandidate parameterTypeCandidate : parameter.getType().getTypeCandidates()) {
|
||||||
for (TypeCandidate parameterTypeCandidate : parameterTypeCandidates) {
|
|
||||||
typeParameterMap.put(parameterTypeCandidate.getRenderedType(), parameterTypeCandidate.getTypeParameterNames());
|
typeParameterMap.put(parameterTypeCandidate.getRenderedType(), parameterTypeCandidate.getTypeParameterNames());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
JetTypeReference returnTypeRef = func.getReturnTypeRef();
|
JetTypeReference returnTypeRef = func.getReturnTypeRef();
|
||||||
if (returnTypeRef != null) {
|
if (returnTypeRef != null) {
|
||||||
TypeCandidate[] returnTypeCandidates = returnType.getTypeCandidates();
|
for (TypeCandidate returnTypeCandidate : returnType.getTypeCandidates()) {
|
||||||
for (TypeCandidate returnTypeCandidate : returnTypeCandidates) {
|
|
||||||
typeParameterMap.put(returnTypeCandidate.getRenderedType(), returnTypeCandidate.getTypeParameterNames());
|
typeParameterMap.put(returnTypeCandidate.getRenderedType(), returnTypeCandidate.getTypeParameterNames());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user