EA-36390 Guard rewriting constructor in slice
This commit is contained in:
+65
-55
@@ -446,60 +446,65 @@ public class JavaDescriptorResolver implements DependencyClassByQualifiedNameRes
|
|||||||
constructors.add(createPrimaryConstructorForObject(containingClass));
|
constructors.add(createPrimaryConstructorForObject(containingClass));
|
||||||
}
|
}
|
||||||
else if (psiConstructors.length == 0) {
|
else if (psiConstructors.length == 0) {
|
||||||
// We need to create default constructors for classes and abstract classes.
|
if (trace.get(BindingContext.CONSTRUCTOR, psiClass) != null) {
|
||||||
// Example:
|
constructors.add(trace.get(BindingContext.CONSTRUCTOR, psiClass));
|
||||||
// class Kotlin() : Java() {}
|
|
||||||
// abstract public class Java {}
|
|
||||||
if (!psiClass.isInterface()) {
|
|
||||||
ConstructorDescriptorImpl constructorDescriptor = new ConstructorDescriptorImpl(
|
|
||||||
containingClass,
|
|
||||||
Collections.<AnnotationDescriptor>emptyList(),
|
|
||||||
false);
|
|
||||||
constructorDescriptor.initialize(typeParameters, Collections.<ValueParameterDescriptor>emptyList(), containingClass
|
|
||||||
.getVisibility(), isStatic);
|
|
||||||
constructors.add(constructorDescriptor);
|
|
||||||
trace.record(BindingContext.CONSTRUCTOR, psiClass, constructorDescriptor);
|
|
||||||
}
|
}
|
||||||
if (psiClass.isAnnotationType()) {
|
else {
|
||||||
// A constructor for an annotation type takes all the "methods" in the @interface as parameters
|
// We need to create default constructors for classes and abstract classes.
|
||||||
ConstructorDescriptorImpl constructorDescriptor = new ConstructorDescriptorImpl(
|
// Example:
|
||||||
containingClass,
|
// class Kotlin() : Java() {}
|
||||||
Collections.<AnnotationDescriptor>emptyList(),
|
// abstract public class Java {}
|
||||||
false);
|
if (!psiClass.isInterface()) {
|
||||||
|
ConstructorDescriptorImpl constructorDescriptor = new ConstructorDescriptorImpl(
|
||||||
List<ValueParameterDescriptor> valueParameters = Lists.newArrayList();
|
containingClass,
|
||||||
PsiMethod[] methods = psiClass.getMethods();
|
Collections.<AnnotationDescriptor>emptyList(),
|
||||||
for (int i = 0; i < methods.length; i++) {
|
false);
|
||||||
PsiMethod method = methods[i];
|
constructorDescriptor.initialize(typeParameters, Collections.<ValueParameterDescriptor>emptyList(), containingClass
|
||||||
if (method instanceof PsiAnnotationMethod) {
|
.getVisibility(), isStatic);
|
||||||
PsiAnnotationMethod annotationMethod = (PsiAnnotationMethod) method;
|
constructors.add(constructorDescriptor);
|
||||||
assert annotationMethod.getParameterList().getParameters().length == 0;
|
trace.record(BindingContext.CONSTRUCTOR, psiClass, constructorDescriptor);
|
||||||
|
|
||||||
PsiType returnType = annotationMethod.getReturnType();
|
|
||||||
|
|
||||||
// We take the following heuristical convention:
|
|
||||||
// if the last method of the @interface is an array, we convert it into a vararg
|
|
||||||
JetType varargElementType = null;
|
|
||||||
if (i == methods.length - 1 && (returnType instanceof PsiArrayType)) {
|
|
||||||
varargElementType = semanticServices.getTypeTransformer().transformToType(((PsiArrayType) returnType).getComponentType(), resolverForTypeParameters);
|
|
||||||
}
|
|
||||||
|
|
||||||
assert returnType != null;
|
|
||||||
valueParameters.add(new ValueParameterDescriptorImpl(
|
|
||||||
constructorDescriptor,
|
|
||||||
i,
|
|
||||||
Collections.<AnnotationDescriptor>emptyList(),
|
|
||||||
Name.identifier(method.getName()),
|
|
||||||
false,
|
|
||||||
semanticServices.getTypeTransformer().transformToType(returnType, resolverForTypeParameters),
|
|
||||||
annotationMethod.getDefaultValue() != null,
|
|
||||||
varargElementType));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
if (psiClass.isAnnotationType()) {
|
||||||
|
// A constructor for an annotation type takes all the "methods" in the @interface as parameters
|
||||||
|
ConstructorDescriptorImpl constructorDescriptor = new ConstructorDescriptorImpl(
|
||||||
|
containingClass,
|
||||||
|
Collections.<AnnotationDescriptor>emptyList(),
|
||||||
|
false);
|
||||||
|
|
||||||
constructorDescriptor.initialize(typeParameters, valueParameters, containingClass.getVisibility(), isStatic);
|
List<ValueParameterDescriptor> valueParameters = Lists.newArrayList();
|
||||||
constructors.add(constructorDescriptor);
|
PsiMethod[] methods = psiClass.getMethods();
|
||||||
trace.record(BindingContext.CONSTRUCTOR, psiClass, constructorDescriptor);
|
for (int i = 0; i < methods.length; i++) {
|
||||||
|
PsiMethod method = methods[i];
|
||||||
|
if (method instanceof PsiAnnotationMethod) {
|
||||||
|
PsiAnnotationMethod annotationMethod = (PsiAnnotationMethod) method;
|
||||||
|
assert annotationMethod.getParameterList().getParameters().length == 0;
|
||||||
|
|
||||||
|
PsiType returnType = annotationMethod.getReturnType();
|
||||||
|
|
||||||
|
// We take the following heuristical convention:
|
||||||
|
// if the last method of the @interface is an array, we convert it into a vararg
|
||||||
|
JetType varargElementType = null;
|
||||||
|
if (i == methods.length - 1 && (returnType instanceof PsiArrayType)) {
|
||||||
|
varargElementType = semanticServices.getTypeTransformer().transformToType(((PsiArrayType) returnType).getComponentType(), resolverForTypeParameters);
|
||||||
|
}
|
||||||
|
|
||||||
|
assert returnType != null;
|
||||||
|
valueParameters.add(new ValueParameterDescriptorImpl(
|
||||||
|
constructorDescriptor,
|
||||||
|
i,
|
||||||
|
Collections.<AnnotationDescriptor>emptyList(),
|
||||||
|
Name.identifier(method.getName()),
|
||||||
|
false,
|
||||||
|
semanticServices.getTypeTransformer().transformToType(returnType, resolverForTypeParameters),
|
||||||
|
annotationMethod.getDefaultValue() != null,
|
||||||
|
varargElementType));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
constructorDescriptor.initialize(typeParameters, valueParameters, containingClass.getVisibility(), isStatic);
|
||||||
|
constructors.add(constructorDescriptor);
|
||||||
|
trace.record(BindingContext.CONSTRUCTOR, psiClass, constructorDescriptor);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@@ -527,15 +532,20 @@ public class JavaDescriptorResolver implements DependencyClassByQualifiedNameRes
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (trace.get(BindingContext.CONSTRUCTOR, psiConstructor) != null) {
|
||||||
|
return trace.get(BindingContext.CONSTRUCTOR, psiConstructor);
|
||||||
|
}
|
||||||
|
|
||||||
ConstructorDescriptorImpl constructorDescriptor = new ConstructorDescriptorImpl(
|
ConstructorDescriptorImpl constructorDescriptor = new ConstructorDescriptorImpl(
|
||||||
classData.classDescriptor,
|
classData.classDescriptor,
|
||||||
Collections.<AnnotationDescriptor>emptyList(), // TODO
|
Collections.<AnnotationDescriptor>emptyList(), // TODO
|
||||||
false);
|
false);
|
||||||
|
|
||||||
String context = "constructor of class " + psiClass.getQualifiedName();
|
String context = "constructor of class " + psiClass.getQualifiedName();
|
||||||
ValueParameterDescriptors valueParameterDescriptors = resolveParameterDescriptors(constructorDescriptor,
|
ValueParameterDescriptors valueParameterDescriptors = resolveParameterDescriptors(
|
||||||
constructor.getParameters(),
|
constructorDescriptor, constructor.getParameters(),
|
||||||
TypeVariableResolvers.classTypeVariableResolver(
|
TypeVariableResolvers.classTypeVariableResolver(classData.classDescriptor, context));
|
||||||
classData.classDescriptor, context));
|
|
||||||
if (valueParameterDescriptors.receiverType != null) {
|
if (valueParameterDescriptors.receiverType != null) {
|
||||||
throw new IllegalStateException();
|
throw new IllegalStateException();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user