Minor refactoring in TypeUtils
Move out unneeded things in runtime, fix warnings
This commit is contained in:
+15
-1
@@ -67,6 +67,20 @@ public class TypeReconstructionUtil {
|
||||
assert declarationDescriptor != null : "No declaration descriptor for type constructor " + constructor;
|
||||
String name = declarationDescriptor.getName().asString();
|
||||
|
||||
return TypeUtils.getTypeNameAndStarProjectionsString(name, size);
|
||||
return getTypeNameAndStarProjectionsString(name, size);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static String getTypeNameAndStarProjectionsString(@NotNull String name, int size) {
|
||||
StringBuilder builder = new StringBuilder(name);
|
||||
builder.append("<");
|
||||
for (int i = 0; i < size; i++) {
|
||||
builder.append("*");
|
||||
if (i == size - 1) break;
|
||||
builder.append(", ");
|
||||
}
|
||||
builder.append(">");
|
||||
|
||||
return builder.toString();
|
||||
}
|
||||
}
|
||||
|
||||
+25
-1
@@ -1,3 +1,19 @@
|
||||
/*
|
||||
* 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.lang.resolve.java.sam;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -34,13 +50,21 @@ public class SamAdapterOverridabilityCondition implements ExternalOverridability
|
||||
|
||||
for (ValueParameterDescriptor param1 : parameters1) {
|
||||
ValueParameterDescriptor param2 = parameters2.get(param1.getIndex());
|
||||
if (!TypeUtils.equalClasses(param2.getType(), param1.getType())) {
|
||||
if (!equalClasses(param2.getType(), param1.getType())) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private static boolean equalClasses(@NotNull JetType type1, @NotNull JetType type2) {
|
||||
DeclarationDescriptor declarationDescriptor1 = type1.getConstructor().getDeclarationDescriptor();
|
||||
if (declarationDescriptor1 == null) return false; // No class, classes are not equal
|
||||
DeclarationDescriptor declarationDescriptor2 = type2.getConstructor().getDeclarationDescriptor();
|
||||
if (declarationDescriptor2 == null) return false; // Class of type1 is not null
|
||||
return declarationDescriptor1.getOriginal().equals(declarationDescriptor2.getOriginal());
|
||||
}
|
||||
|
||||
// if function is or overrides declaration, returns null; otherwise, return original of sam adapter with substituted type parameters
|
||||
@Nullable
|
||||
private static SimpleFunctionDescriptor getOriginalOfSamAdapterFunction(@NotNull SimpleFunctionDescriptor callable) {
|
||||
|
||||
@@ -23,7 +23,8 @@ import com.google.common.collect.Maps;
|
||||
import com.google.common.collect.Sets;
|
||||
import com.intellij.openapi.util.Pair;
|
||||
import com.intellij.util.Processor;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import kotlin.Function1;
|
||||
import kotlin.KotlinPackage;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.descriptors.ClassDescriptor;
|
||||
@@ -133,6 +134,14 @@ public class TypeUtils {
|
||||
return nullable ? new NullableType(type) : new NotNullType(type);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static JetType makeNullableIfNeeded(@NotNull JetType type, boolean nullable) {
|
||||
if (nullable) {
|
||||
return makeNullable(type);
|
||||
}
|
||||
return type;
|
||||
}
|
||||
|
||||
public static boolean isIntersectionEmpty(@NotNull JetType typeA, @NotNull JetType typeB) {
|
||||
return intersect(JetTypeChecker.INSTANCE, Sets.newLinkedHashSet(Lists.newArrayList(typeA, typeB))) == null;
|
||||
}
|
||||
@@ -342,13 +351,6 @@ public class TypeUtils {
|
||||
return false;
|
||||
}
|
||||
|
||||
public static JetType makeNullableIfNeeded(JetType type, boolean nullable) {
|
||||
if (nullable) {
|
||||
return makeNullable(type);
|
||||
}
|
||||
return type;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static JetType makeUnsubstitutedType(ClassDescriptor classDescriptor, JetScope unsubstitutedMemberScope) {
|
||||
if (ErrorUtils.isError(classDescriptor)) {
|
||||
@@ -374,15 +376,6 @@ public class TypeUtils {
|
||||
return result;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static List<JetType> getDefaultTypes(List<TypeParameterDescriptor> parameters) {
|
||||
List<JetType> result = Lists.newArrayList();
|
||||
for (TypeParameterDescriptor parameterDescriptor : parameters) {
|
||||
result.add(parameterDescriptor.getDefaultType());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private static void collectImmediateSupertypes(@NotNull JetType type, @NotNull Collection<JetType> result) {
|
||||
TypeSubstitutor substitutor = TypeSubstitutor.create(type);
|
||||
for (JetType supertype : type.getConstructor().getSupertypes()) {
|
||||
@@ -438,14 +431,6 @@ public class TypeUtils {
|
||||
return false;
|
||||
}
|
||||
|
||||
public static boolean equalClasses(@NotNull JetType type1, @NotNull JetType type2) {
|
||||
DeclarationDescriptor declarationDescriptor1 = type1.getConstructor().getDeclarationDescriptor();
|
||||
if (declarationDescriptor1 == null) return false; // No class, classes are not equal
|
||||
DeclarationDescriptor declarationDescriptor2 = type2.getConstructor().getDeclarationDescriptor();
|
||||
if (declarationDescriptor2 == null) return false; // Class of type1 is not null
|
||||
return declarationDescriptor1.getOriginal().equals(declarationDescriptor2.getOriginal());
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static ClassDescriptor getClassDescriptor(@NotNull JetType type) {
|
||||
DeclarationDescriptor declarationDescriptor = type.getConstructor().getDeclarationDescriptor();
|
||||
@@ -457,9 +442,9 @@ public class TypeUtils {
|
||||
|
||||
@NotNull
|
||||
public static JetType substituteParameters(@NotNull ClassDescriptor clazz, @NotNull List<JetType> typeArguments) {
|
||||
List<TypeProjection> projections = ContainerUtil.map(typeArguments, new com.intellij.util.Function<JetType, TypeProjection>() {
|
||||
List<TypeProjection> projections = KotlinPackage.map(typeArguments, new Function1<JetType, TypeProjection>() {
|
||||
@Override
|
||||
public TypeProjection fun(JetType type) {
|
||||
public TypeProjection invoke(JetType type) {
|
||||
return new TypeProjectionImpl(type);
|
||||
}
|
||||
});
|
||||
@@ -488,16 +473,6 @@ public class TypeUtils {
|
||||
return JetTypeChecker.INSTANCE.isSubtypeOf(a, b) && JetTypeChecker.INSTANCE.isSubtypeOf(b, a);
|
||||
}
|
||||
|
||||
public static boolean typeConstructorUsedInType(@NotNull TypeConstructor key, @NotNull JetType value) {
|
||||
if (value.getConstructor() == key) return true;
|
||||
for (TypeProjection projection : value.getArguments()) {
|
||||
if (typeConstructorUsedInType(key, projection.getType())) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static boolean dependsOnTypeParameters(@NotNull JetType type, @NotNull Collection<TypeParameterDescriptor> typeParameters) {
|
||||
return dependsOnTypeConstructors(type, Collections2
|
||||
.transform(typeParameters, new Function<TypeParameterDescriptor, TypeConstructor>() {
|
||||
@@ -533,20 +508,6 @@ public class TypeUtils {
|
||||
return false;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static String getTypeNameAndStarProjectionsString(@NotNull String name, int size) {
|
||||
StringBuilder builder = new StringBuilder(name);
|
||||
builder.append("<");
|
||||
for (int i = 0; i < size; i++) {
|
||||
builder.append("*");
|
||||
if (i == size - 1) break;
|
||||
builder.append(", ");
|
||||
}
|
||||
builder.append(">");
|
||||
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static TypeProjection makeStarProjection(@NotNull TypeParameterDescriptor parameterDescriptor) {
|
||||
return new TypeProjectionImpl(parameterDescriptor.getVariance() == Variance.OUT_VARIANCE
|
||||
|
||||
@@ -28,7 +28,7 @@ import org.jetbrains.jet.lang.diagnostics.DiagnosticWithParameters1;
|
||||
import org.jetbrains.jet.lang.diagnostics.DiagnosticWithParameters2;
|
||||
import org.jetbrains.jet.lang.diagnostics.Errors;
|
||||
import org.jetbrains.jet.lang.psi.*;
|
||||
import org.jetbrains.jet.lang.types.TypeUtils;
|
||||
import org.jetbrains.jet.lang.types.expressions.TypeReconstructionUtil;
|
||||
import org.jetbrains.jet.plugin.JetBundle;
|
||||
|
||||
public abstract class AddStarProjectionsFix extends JetIntentionAction<JetUserType> {
|
||||
@@ -43,7 +43,7 @@ public abstract class AddStarProjectionsFix extends JetIntentionAction<JetUserTy
|
||||
@NotNull
|
||||
@Override
|
||||
public String getText() {
|
||||
return JetBundle.message("add.star.projections", TypeUtils.getTypeNameAndStarProjectionsString("", argumentCount));
|
||||
return JetBundle.message("add.star.projections", TypeReconstructionUtil.getTypeNameAndStarProjectionsString("", argumentCount));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -56,7 +56,7 @@ public abstract class AddStarProjectionsFix extends JetIntentionAction<JetUserTy
|
||||
public void invoke(@NotNull Project project, Editor editor, JetFile file) throws IncorrectOperationException {
|
||||
assert element.getTypeArguments().isEmpty();
|
||||
|
||||
String typeString = TypeUtils.getTypeNameAndStarProjectionsString(element.getText(), argumentCount);
|
||||
String typeString = TypeReconstructionUtil.getTypeNameAndStarProjectionsString(element.getText(), argumentCount);
|
||||
JetTypeElement replacement = JetPsiFactory.createType(project, typeString).getTypeElement();
|
||||
assert replacement != null : "No type element after parsing " + typeString;
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@ import com.intellij.util.IncorrectOperationException;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lang.diagnostics.Diagnostic;
|
||||
import org.jetbrains.jet.lang.psi.*;
|
||||
import org.jetbrains.jet.lang.types.TypeUtils;
|
||||
import org.jetbrains.jet.lang.types.expressions.TypeReconstructionUtil;
|
||||
import org.jetbrains.jet.plugin.JetBundle;
|
||||
|
||||
public class ChangeToStarProjectionFix extends JetIntentionAction<JetTypeElement> {
|
||||
@@ -34,7 +34,7 @@ public class ChangeToStarProjectionFix extends JetIntentionAction<JetTypeElement
|
||||
@NotNull
|
||||
@Override
|
||||
public String getText() {
|
||||
String stars = TypeUtils.getTypeNameAndStarProjectionsString("", element.getTypeArgumentsAsTypes().size());
|
||||
String stars = TypeReconstructionUtil.getTypeNameAndStarProjectionsString("", element.getTypeArgumentsAsTypes().size());
|
||||
return JetBundle.message("change.to.star.projection", stars);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user