Move method: defaultInitializer
This commit is contained in:
@@ -12,6 +12,8 @@ import org.jetbrains.jet.lang.psi.JetBlockExpression;
|
||||
import org.jetbrains.jet.lang.psi.JetElement;
|
||||
import org.jetbrains.jet.lang.psi.JetExpression;
|
||||
import org.jetbrains.jet.lang.psi.JetFile;
|
||||
import org.jetbrains.jet.lang.types.JetType;
|
||||
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -132,6 +134,24 @@ public class CodeInsightUtils {
|
||||
return element;
|
||||
}
|
||||
|
||||
public static String defaultInitializer(JetType type) {
|
||||
KotlinBuiltIns builtIns = KotlinBuiltIns.getInstance();
|
||||
if (type.isNullable()) {
|
||||
return "null";
|
||||
}
|
||||
else if (type.equals(builtIns.getIntType()) || type.equals(builtIns.getLongType()) ||
|
||||
type.equals(builtIns.getShortType()) || type.equals(builtIns.getByteType()) ||
|
||||
type.equals(builtIns.getFloatType()) || type.equals(builtIns.getDoubleType()) ||
|
||||
type.equals(builtIns.getCharType())) {
|
||||
return "0";
|
||||
}
|
||||
else if (type.equals(builtIns.getBooleanType())) {
|
||||
return "false";
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private CodeInsightUtils() {
|
||||
}
|
||||
}
|
||||
|
||||
@@ -141,7 +141,7 @@ public abstract class OverrideImplementMethodsHandler implements LanguageCodeIns
|
||||
|
||||
bodyBuilder.append(descriptor.getName()).append(" : ").append(
|
||||
DescriptorRenderer.SHORT_NAMES_IN_TYPES.renderType(descriptor.getType()));
|
||||
String initializer = defaultInitializer(descriptor.getType(), KotlinBuiltIns.getInstance());
|
||||
String initializer = CodeInsightUtils.defaultInitializer(descriptor.getType());
|
||||
if (initializer != null) {
|
||||
bodyBuilder.append(" = ").append(initializer);
|
||||
}
|
||||
@@ -247,22 +247,6 @@ public abstract class OverrideImplementMethodsHandler implements LanguageCodeIns
|
||||
}
|
||||
}
|
||||
|
||||
private static String defaultInitializer(JetType returnType, KotlinBuiltIns builtIns) {
|
||||
if (returnType.isNullable()) {
|
||||
return "null";
|
||||
}
|
||||
else if (returnType.equals(builtIns.getIntType()) || returnType.equals(builtIns.getLongType()) ||
|
||||
returnType.equals(builtIns.getShortType()) || returnType.equals(builtIns.getByteType()) ||
|
||||
returnType.equals(builtIns.getFloatType()) || returnType.equals(builtIns.getDoubleType())) {
|
||||
return "0";
|
||||
}
|
||||
else if (returnType.equals(builtIns.getBooleanType())) {
|
||||
return "false";
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private static String displayableVisibility(MemberDescriptor descriptor) {
|
||||
Visibility visibility = descriptor.getVisibility().normalize();
|
||||
return visibility != Visibilities.INTERNAL ? visibility.toString() + " " : "";
|
||||
|
||||
Reference in New Issue
Block a user