read inner classes types from kotlin signature
This commit is contained in:
+45
-25
@@ -17,8 +17,10 @@
|
|||||||
package org.jetbrains.jet.lang.resolve.java;
|
package org.jetbrains.jet.lang.resolve.java;
|
||||||
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.jetbrains.jet.lang.descriptors.ClassDescriptor;
|
import org.jetbrains.jet.lang.descriptors.ClassDescriptor;
|
||||||
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
|
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
|
||||||
|
import org.jetbrains.jet.lang.resolve.DescriptorUtils;
|
||||||
import org.jetbrains.jet.lang.resolve.name.FqName;
|
import org.jetbrains.jet.lang.resolve.name.FqName;
|
||||||
import org.jetbrains.jet.lang.types.*;
|
import org.jetbrains.jet.lang.types.*;
|
||||||
import org.jetbrains.jet.lang.types.lang.JetStandardClasses;
|
import org.jetbrains.jet.lang.types.lang.JetStandardClasses;
|
||||||
@@ -93,40 +95,58 @@ public abstract class JetTypeJetSignatureReader extends JetSignatureExceptionsAd
|
|||||||
.replace('$', '.') // TODO: not sure
|
.replace('$', '.') // TODO: not sure
|
||||||
);
|
);
|
||||||
|
|
||||||
this.classDescriptor = null;
|
enterClass(resolveClassDescriptorByFqName(ourName, forceReal), ourName.getFqName(), nullable);
|
||||||
if (!forceReal) {
|
}
|
||||||
classDescriptor = JavaToKotlinClassMap.getInstance().mapKotlinClass(ourName,
|
|
||||||
JavaTypeTransformer.TypeUsage.MEMBER_SIGNATURE_INVARIANT);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (classDescriptor == null) {
|
private void enterClass(@Nullable ClassDescriptor classDescriptor, @NotNull String className, boolean nullable) {
|
||||||
// TODO: this is the worst code in Kotlin project
|
this.classDescriptor = classDescriptor;
|
||||||
Matcher matcher = Pattern.compile("jet\\.Function(\\d+)").matcher(ourName.getFqName());
|
|
||||||
if (matcher.matches()) {
|
|
||||||
classDescriptor = JetStandardClasses.getFunction(Integer.parseInt(matcher.group(1)));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (classDescriptor == null) {
|
|
||||||
Matcher matcher = Pattern.compile("jet\\.Tuple(\\d+)").matcher(ourName.getFqName());
|
|
||||||
if (matcher.matches()) {
|
|
||||||
classDescriptor = JetStandardClasses.getTuple(Integer.parseInt(matcher.group(1)));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
if (this.classDescriptor == null) {
|
|
||||||
this.classDescriptor = javaDescriptorResolver.resolveClass(ourName, DescriptorSearchRule.INCLUDE_KOTLIN);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.classDescriptor == null) {
|
if (this.classDescriptor == null) {
|
||||||
// TODO: report in to trace
|
// TODO: report in to trace
|
||||||
this.errorType = ErrorUtils.createErrorType("class not found by name: " + ourName);
|
this.errorType = ErrorUtils.createErrorType("class not found by name: " + className);
|
||||||
}
|
}
|
||||||
this.nullable = nullable;
|
this.nullable = nullable;
|
||||||
this.typeArguments = new ArrayList<TypeProjection>();
|
this.typeArguments = new ArrayList<TypeProjection>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
private ClassDescriptor resolveClassDescriptorByFqName(FqName ourName, boolean forceReal) {
|
||||||
|
if (!forceReal) {
|
||||||
|
ClassDescriptor mappedDescriptor = JavaToKotlinClassMap.getInstance().
|
||||||
|
mapKotlinClass(ourName, JavaTypeTransformer.TypeUsage.MEMBER_SIGNATURE_INVARIANT);
|
||||||
|
if (mappedDescriptor != null) {
|
||||||
|
return mappedDescriptor;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: this is the worst code in Kotlin project
|
||||||
|
Matcher functionMatcher = Pattern.compile("jet\\.Function(\\d+)").matcher(ourName.getFqName());
|
||||||
|
if (functionMatcher.matches()) {
|
||||||
|
return JetStandardClasses.getFunction(Integer.parseInt(functionMatcher.group(1)));
|
||||||
|
}
|
||||||
|
|
||||||
|
Matcher patternMatcher = Pattern.compile("jet\\.Tuple(\\d+)").matcher(ourName.getFqName());
|
||||||
|
if (patternMatcher.matches()) {
|
||||||
|
return JetStandardClasses.getTuple(Integer.parseInt(patternMatcher.group(1)));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
return javaDescriptorResolver.resolveClass(ourName, DescriptorSearchRule.INCLUDE_KOTLIN);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void visitInnerClassType(String signatureName, boolean nullable, boolean forceReal) {
|
||||||
|
int index = signatureName.lastIndexOf(".");
|
||||||
|
String outerSignatureName = signatureName.substring(0, index);
|
||||||
|
String innerName = signatureName.substring(index + 1);
|
||||||
|
|
||||||
|
FqName outerFqName = new FqName(outerSignatureName.replace('/', '.'));
|
||||||
|
ClassDescriptor descriptor = resolveClassDescriptorByFqName(outerFqName, forceReal);
|
||||||
|
|
||||||
|
ClassDescriptor innerClassDescriptor = descriptor != null ? DescriptorUtils.getInnerClassByName(descriptor, innerName) : null;
|
||||||
|
enterClass(innerClassDescriptor, signatureName, nullable);
|
||||||
|
}
|
||||||
|
|
||||||
private static Variance parseVariance(JetSignatureVariance variance) {
|
private static Variance parseVariance(JetSignatureVariance variance) {
|
||||||
switch (variance) {
|
switch (variance) {
|
||||||
case INVARIANT: return Variance.INVARIANT;
|
case INVARIANT: return Variance.INVARIANT;
|
||||||
|
|||||||
Reference in New Issue
Block a user