Removed renderTypeWithShortNames from API of DescriptorRenderer.
This commit is contained in:
@@ -81,6 +81,7 @@ public class DescriptorRendererImpl implements Renderer<DeclarationDescriptor> {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
public static final DescriptorRendererImpl TEXT = new DescriptorRendererImpl();
|
public static final DescriptorRendererImpl TEXT = new DescriptorRendererImpl();
|
||||||
|
public static final DescriptorRendererImpl SHORT_NAMES_IN_TYPES = new DescriptorRendererImpl(true);
|
||||||
public static final DescriptorRendererImpl DEBUG_TEXT = new DescriptorRendererImpl() {
|
public static final DescriptorRendererImpl DEBUG_TEXT = new DescriptorRendererImpl() {
|
||||||
@Override
|
@Override
|
||||||
protected boolean hasDefaultValue(ValueParameterDescriptor descriptor) {
|
protected boolean hasDefaultValue(ValueParameterDescriptor descriptor) {
|
||||||
@@ -108,6 +109,16 @@ public class DescriptorRendererImpl implements Renderer<DeclarationDescriptor> {
|
|||||||
};
|
};
|
||||||
private final RenderDeclarationDescriptorVisitor rootVisitor = new RenderDeclarationDescriptorVisitor();
|
private final RenderDeclarationDescriptorVisitor rootVisitor = new RenderDeclarationDescriptorVisitor();
|
||||||
|
|
||||||
|
private final boolean shortNames;
|
||||||
|
|
||||||
|
public DescriptorRendererImpl() {
|
||||||
|
this(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
public DescriptorRendererImpl(boolean shortNames) {
|
||||||
|
this.shortNames = shortNames;
|
||||||
|
}
|
||||||
|
|
||||||
protected boolean hasDefaultValue(ValueParameterDescriptor descriptor) {
|
protected boolean hasDefaultValue(ValueParameterDescriptor descriptor) {
|
||||||
return descriptor.hasDefaultValue();
|
return descriptor.hasDefaultValue();
|
||||||
}
|
}
|
||||||
@@ -139,14 +150,6 @@ public class DescriptorRendererImpl implements Renderer<DeclarationDescriptor> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public String renderType(JetType type) {
|
public String renderType(JetType type) {
|
||||||
return renderType(type, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
public String renderTypeWithShortNames(JetType type) {
|
|
||||||
return renderType(type, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
private String renderType(JetType type, boolean shortNamesOnly) {
|
|
||||||
if (type == null) {
|
if (type == null) {
|
||||||
return escape("[NULL]");
|
return escape("[NULL]");
|
||||||
}
|
}
|
||||||
@@ -157,20 +160,20 @@ public class DescriptorRendererImpl implements Renderer<DeclarationDescriptor> {
|
|||||||
return escape(KotlinBuiltIns.UNIT_ALIAS + (type.isNullable() ? "?" : ""));
|
return escape(KotlinBuiltIns.UNIT_ALIAS + (type.isNullable() ? "?" : ""));
|
||||||
}
|
}
|
||||||
else if (KotlinBuiltIns.getInstance().isFunctionType(type)) {
|
else if (KotlinBuiltIns.getInstance().isFunctionType(type)) {
|
||||||
return escape(renderFunctionType(type, shortNamesOnly));
|
return escape(renderFunctionType(type));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return escape(renderDefaultType(type, shortNamesOnly));
|
return escape(renderDefaultType(type));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private String renderDefaultType(JetType type, boolean shortNamesOnly) {
|
private String renderDefaultType(JetType type) {
|
||||||
StringBuilder sb = new StringBuilder();
|
StringBuilder sb = new StringBuilder();
|
||||||
|
|
||||||
sb.append(renderTypeName(type.getConstructor(), shortNamesOnly));
|
sb.append(renderTypeName(type.getConstructor()));
|
||||||
if (!type.getArguments().isEmpty()) {
|
if (!type.getArguments().isEmpty()) {
|
||||||
sb.append("<");
|
sb.append("<");
|
||||||
appendTypeProjections(sb, type.getArguments(), shortNamesOnly);
|
appendTypeProjections(sb, type.getArguments());
|
||||||
sb.append(">");
|
sb.append(">");
|
||||||
}
|
}
|
||||||
if (type.isNullable()) {
|
if (type.isNullable()) {
|
||||||
@@ -179,7 +182,7 @@ public class DescriptorRendererImpl implements Renderer<DeclarationDescriptor> {
|
|||||||
return sb.toString();
|
return sb.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
private String renderTypeName(@NotNull TypeConstructor typeConstructor, boolean shortNamesOnly) {
|
private String renderTypeName(@NotNull TypeConstructor typeConstructor) {
|
||||||
ClassifierDescriptor cd = typeConstructor.getDeclarationDescriptor();
|
ClassifierDescriptor cd = typeConstructor.getDeclarationDescriptor();
|
||||||
if (cd == null) {
|
if (cd == null) {
|
||||||
return typeConstructor.toString();
|
return typeConstructor.toString();
|
||||||
@@ -188,7 +191,7 @@ public class DescriptorRendererImpl implements Renderer<DeclarationDescriptor> {
|
|||||||
return renderName(cd.getName());
|
return renderName(cd.getName());
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (shortNamesOnly) {
|
if (shortNames) {
|
||||||
List<Name> qualifiedNameElements = Lists.newArrayList();
|
List<Name> qualifiedNameElements = Lists.newArrayList();
|
||||||
|
|
||||||
// for nested classes qualified name should be used
|
// for nested classes qualified name should be used
|
||||||
@@ -209,32 +212,32 @@ public class DescriptorRendererImpl implements Renderer<DeclarationDescriptor> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void appendTypeProjections(StringBuilder result, List<TypeProjection> typeProjections, boolean shortNamesOnly) {
|
private void appendTypeProjections(StringBuilder result, List<TypeProjection> typeProjections) {
|
||||||
for (Iterator<TypeProjection> iterator = typeProjections.iterator(); iterator.hasNext(); ) {
|
for (Iterator<TypeProjection> iterator = typeProjections.iterator(); iterator.hasNext(); ) {
|
||||||
TypeProjection typeProjection = iterator.next();
|
TypeProjection typeProjection = iterator.next();
|
||||||
if (typeProjection.getProjectionKind() != Variance.INVARIANT) {
|
if (typeProjection.getProjectionKind() != Variance.INVARIANT) {
|
||||||
result.append(typeProjection.getProjectionKind()).append(" ");
|
result.append(typeProjection.getProjectionKind()).append(" ");
|
||||||
}
|
}
|
||||||
result.append(renderType(typeProjection.getType(), shortNamesOnly));
|
result.append(renderType(typeProjection.getType()));
|
||||||
if (iterator.hasNext()) {
|
if (iterator.hasNext()) {
|
||||||
result.append(", ");
|
result.append(", ");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private String renderFunctionType(JetType type, boolean shortNamesOnly) {
|
private String renderFunctionType(JetType type) {
|
||||||
StringBuilder sb = new StringBuilder();
|
StringBuilder sb = new StringBuilder();
|
||||||
|
|
||||||
JetType receiverType = KotlinBuiltIns.getInstance().getReceiverType(type);
|
JetType receiverType = KotlinBuiltIns.getInstance().getReceiverType(type);
|
||||||
if (receiverType != null) {
|
if (receiverType != null) {
|
||||||
sb.append(renderType(receiverType, shortNamesOnly));
|
sb.append(renderType(receiverType));
|
||||||
sb.append(".");
|
sb.append(".");
|
||||||
}
|
}
|
||||||
|
|
||||||
sb.append("(");
|
sb.append("(");
|
||||||
appendTypeProjections(sb, KotlinBuiltIns.getInstance().getParameterTypeProjectionsFromFunctionType(type), shortNamesOnly);
|
appendTypeProjections(sb, KotlinBuiltIns.getInstance().getParameterTypeProjectionsFromFunctionType(type));
|
||||||
sb.append(") -> ");
|
sb.append(") -> ");
|
||||||
sb.append(renderType(KotlinBuiltIns.getInstance().getReturnTypeFromFunctionType(type), shortNamesOnly));
|
sb.append(renderType(KotlinBuiltIns.getInstance().getReturnTypeFromFunctionType(type)));
|
||||||
|
|
||||||
if (type.isNullable()) {
|
if (type.isNullable()) {
|
||||||
return "(" + sb + ")?";
|
return "(" + sb + ")?";
|
||||||
|
|||||||
@@ -106,7 +106,7 @@ public class TypeSubstitutorTest extends KotlinTestWithEnvironment {
|
|||||||
|
|
||||||
JetType result = substitutor.substitute(initialType, Variance.INVARIANT);
|
JetType result = substitutor.substitute(initialType, Variance.INVARIANT);
|
||||||
|
|
||||||
assertEquals(expectedTypeStr, DescriptorRendererImpl.TEXT.renderTypeWithShortNames(result));
|
assertEquals(expectedTypeStr, DescriptorRendererImpl.SHORT_NAMES_IN_TYPES.renderType(result));
|
||||||
}
|
}
|
||||||
|
|
||||||
private Map<TypeConstructor, TypeProjection> stringsToSubstitutionMap(Pair<String, String>[] substitutionStrs) {
|
private Map<TypeConstructor, TypeProjection> stringsToSubstitutionMap(Pair<String, String>[] substitutionStrs) {
|
||||||
|
|||||||
@@ -182,7 +182,7 @@ public class GenerateJavaToKotlinMethodMap {
|
|||||||
// "special case": remove(Int) and remove(Any?) in MutableList
|
// "special case": remove(Int) and remove(Any?) in MutableList
|
||||||
if (method.getName().equals("remove") && method.getContainingClass().getName().equals("List")) {
|
if (method.getName().equals("remove") && method.getContainingClass().getName().equals("List")) {
|
||||||
String psiType = method.getParameterList().getParameters()[0].getType().getPresentableText();
|
String psiType = method.getParameterList().getParameters()[0].getType().getPresentableText();
|
||||||
String jetType = DescriptorRendererImpl.TEXT.renderTypeWithShortNames(fun.getValueParameters().get(0).getType());
|
String jetType = DescriptorRendererImpl.SHORT_NAMES_IN_TYPES.renderType(fun.getValueParameters().get(0).getType());
|
||||||
String string = psiType + "|" + jetType;
|
String string = psiType + "|" + jetType;
|
||||||
|
|
||||||
return "int|Int".equals(string) || "Object|Any?".equals(string);
|
return "int|Int".equals(string) || "Object|Any?".equals(string);
|
||||||
|
|||||||
@@ -141,8 +141,8 @@ public abstract class OverrideImplementMethodsHandler implements LanguageCodeIns
|
|||||||
|
|
||||||
addReceiverParameter(descriptor, bodyBuilder);
|
addReceiverParameter(descriptor, bodyBuilder);
|
||||||
|
|
||||||
bodyBuilder.append(descriptor.getName()).append(" : ").append(DescriptorRendererImpl.COMPACT_WITH_MODIFIERS.renderTypeWithShortNames(
|
bodyBuilder.append(descriptor.getName()).append(" : ").append(
|
||||||
descriptor.getType()));
|
DescriptorRendererImpl.SHORT_NAMES_IN_TYPES.renderType(descriptor.getType()));
|
||||||
String initializer = defaultInitializer(descriptor.getType(), KotlinBuiltIns.getInstance());
|
String initializer = defaultInitializer(descriptor.getType(), KotlinBuiltIns.getInstance());
|
||||||
if (initializer != null) {
|
if (initializer != null) {
|
||||||
bodyBuilder.append(" = ").append(initializer);
|
bodyBuilder.append(" = ").append(initializer);
|
||||||
|
|||||||
+1
-6
@@ -53,17 +53,12 @@ import static org.jetbrains.jet.plugin.codeInsight.ktSignature.KotlinSignatureUt
|
|||||||
* @since 16 Aug 2012
|
* @since 16 Aug 2012
|
||||||
*/
|
*/
|
||||||
public class AddKotlinSignatureAnnotation extends BaseIntentionAction implements Iconable {
|
public class AddKotlinSignatureAnnotation extends BaseIntentionAction implements Iconable {
|
||||||
private static final DescriptorRendererImpl RENDERER = new DescriptorRendererImpl() {
|
private static final DescriptorRendererImpl RENDERER = new DescriptorRendererImpl(true) {
|
||||||
@Override
|
@Override
|
||||||
protected boolean shouldRenderDefinedIn() {
|
protected boolean shouldRenderDefinedIn() {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public String renderType(JetType type) {
|
|
||||||
return renderTypeWithShortNames(type);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected boolean shouldRenderModifiers() {
|
protected boolean shouldRenderModifiers() {
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
+1
-1
@@ -151,7 +151,7 @@ public class JetFunctionParameterInfoHandler implements
|
|||||||
builder.append("vararg ");
|
builder.append("vararg ");
|
||||||
}
|
}
|
||||||
builder.append(descriptor.getName()).append(": ").
|
builder.append(descriptor.getName()).append(": ").
|
||||||
append(DescriptorRendererImpl.TEXT.renderTypeWithShortNames(getActualParameterType(descriptor)));
|
append(DescriptorRendererImpl.SHORT_NAMES_IN_TYPES.renderType(getActualParameterType(descriptor)));
|
||||||
if (descriptor.hasDefaultValue()) {
|
if (descriptor.hasDefaultValue()) {
|
||||||
PsiElement element = BindingContextUtils.descriptorToDeclaration(bindingContext, descriptor);
|
PsiElement element = BindingContextUtils.descriptorToDeclaration(bindingContext, descriptor);
|
||||||
String defaultExpression = "?";
|
String defaultExpression = "?";
|
||||||
|
|||||||
Reference in New Issue
Block a user