Support named arguments for Java constructors annotated with KotlinSignature
This commit is contained in:
+68
@@ -0,0 +1,68 @@
|
||||
/*
|
||||
* 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.descriptor;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lang.descriptors.ClassDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.annotations.Annotations;
|
||||
import org.jetbrains.jet.lang.descriptors.impl.ConstructorDescriptorImpl;
|
||||
|
||||
public class JavaConstructorDescriptor extends ConstructorDescriptorImpl {
|
||||
private Boolean hasStableParameterNames;
|
||||
|
||||
public JavaConstructorDescriptor(
|
||||
@NotNull ClassDescriptor containingDeclaration,
|
||||
@NotNull Annotations annotations,
|
||||
boolean isPrimary
|
||||
) {
|
||||
super(containingDeclaration, annotations, isPrimary);
|
||||
}
|
||||
|
||||
private JavaConstructorDescriptor(
|
||||
@NotNull ClassDescriptor containingDeclaration,
|
||||
@NotNull JavaConstructorDescriptor original,
|
||||
@NotNull Annotations annotations,
|
||||
boolean isPrimary
|
||||
) {
|
||||
super(containingDeclaration, original, annotations, isPrimary);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasStableParameterNames() {
|
||||
assert hasStableParameterNames != null : "hasStableParameterNames was not set: " + this;
|
||||
return hasStableParameterNames;
|
||||
}
|
||||
|
||||
public void setHasStableParameterNames(boolean hasStableParameterNames) {
|
||||
this.hasStableParameterNames = hasStableParameterNames;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected JavaConstructorDescriptor createSubstitutedCopy(DeclarationDescriptor newOwner, boolean preserveOriginal, Kind kind) {
|
||||
if (kind != Kind.DECLARATION) {
|
||||
throw new IllegalStateException("Attempt at creating a constructor that is not a declaration: \n" +
|
||||
"copy from: " + this + "\n" +
|
||||
"newOwner: " + newOwner + "\n" +
|
||||
"kind: " + kind);
|
||||
}
|
||||
JavaConstructorDescriptor result =
|
||||
new JavaConstructorDescriptor((ClassDescriptor) newOwner, this, Annotations.EMPTY /* TODO */, isPrimary);
|
||||
result.setHasStableParameterNames(hasStableParameterNames());
|
||||
return result;
|
||||
}
|
||||
}
|
||||
+6
-3
@@ -35,6 +35,7 @@ import org.jetbrains.jet.lang.types.TypeUtils
|
||||
import org.jetbrains.jet.lang.descriptors.annotations.Annotations
|
||||
import org.jetbrains.jet.lang.resolve.java.sam.SingleAbstractMethodUtils
|
||||
import org.jetbrains.jet.lang.resolve.java.JavaVisibilities
|
||||
import org.jetbrains.jet.lang.resolve.java.descriptor.JavaConstructorDescriptor
|
||||
|
||||
public class LazyJavaClassMemberScope(
|
||||
c: LazyJavaResolverContextWithTypes,
|
||||
@@ -73,7 +74,7 @@ public class LazyJavaClassMemberScope(
|
||||
}
|
||||
|
||||
private fun resolveConstructor(constructor: JavaMethod, classDescriptor: ClassDescriptor, isStaticClass: Boolean): ConstructorDescriptor {
|
||||
val constructorDescriptor = ConstructorDescriptorImpl(classDescriptor, Annotations.EMPTY, isPrimary = false)
|
||||
val constructorDescriptor = JavaConstructorDescriptor(classDescriptor, Annotations.EMPTY, /* isPrimary = */ false)
|
||||
|
||||
val valueParameters = resolveValueParameters(c, constructorDescriptor, constructor.getValueParameters())
|
||||
val effectiveSignature = c.externalSignatureResolver.resolveAlternativeMethodSignature(
|
||||
@@ -85,6 +86,7 @@ public class LazyJavaClassMemberScope(
|
||||
constructor.getVisibility(),
|
||||
isStaticClass
|
||||
)
|
||||
constructorDescriptor.setHasStableParameterNames(effectiveSignature.hasStableParameterNames())
|
||||
|
||||
constructorDescriptor.setReturnType(classDescriptor.getDefaultType())
|
||||
|
||||
@@ -104,12 +106,13 @@ public class LazyJavaClassMemberScope(
|
||||
return null
|
||||
|
||||
val classDescriptor = getContainingDeclaration()
|
||||
val constructorDescriptor = ConstructorDescriptorImpl(classDescriptor, Annotations.EMPTY, isPrimary = true)
|
||||
val constructorDescriptor = JavaConstructorDescriptor(classDescriptor, Annotations.EMPTY, /* isPrimary = */ true)
|
||||
val typeParameters = classDescriptor.getTypeConstructor().getParameters()
|
||||
val valueParameters = if (isAnnotation) createAnnotationConstructorParameters(constructorDescriptor)
|
||||
else Collections.emptyList<ValueParameterDescriptor>()
|
||||
|
||||
constructorDescriptor.initialize(typeParameters, valueParameters, getConstructorVisibility(classDescriptor), jClass.isStatic())
|
||||
constructorDescriptor.setHasStableParameterNames(true)
|
||||
constructorDescriptor.setReturnType(classDescriptor.getDefaultType())
|
||||
c.javaResolverCache.recordConstructor(jClass, constructorDescriptor);
|
||||
return constructorDescriptor
|
||||
@@ -207,4 +210,4 @@ public class LazyJavaClassMemberScope(
|
||||
override fun getPackage(name: Name) = null
|
||||
|
||||
override fun toString() = "Lazy java member scope for " + jClass.getFqName()
|
||||
}
|
||||
}
|
||||
|
||||
+5
-5
@@ -33,10 +33,10 @@ class LazyJavaTypeParameterDescriptor(
|
||||
) : AbstractLazyTypeParameterDescriptor(
|
||||
c.storageManager,
|
||||
containingDeclaration,
|
||||
name = javaTypeParameter.getName(),
|
||||
variance = Variance.INVARIANT,
|
||||
isReified = false,
|
||||
index = javaTypeParameter.getIndex()
|
||||
javaTypeParameter.getName(),
|
||||
Variance.INVARIANT,
|
||||
/* isReified = */ false,
|
||||
javaTypeParameter.getIndex()
|
||||
) {
|
||||
|
||||
override fun resolveUpperBounds(): Set<JetType> {
|
||||
@@ -51,4 +51,4 @@ class LazyJavaTypeParameterDescriptor(
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user