private TypeProjection makeTypeProjection(KtScope scope, String typeStr) { WritableScopeImpl withX = new WritableScopeImpl( scope, scope.getContainingDeclaration(), RedeclarationHandler.DO_NOTHING, "With X"); withX.addClassifierDescriptor(x); withX.addClassifierDescriptor(y); withX.changeLockLevel(WritableScope.LockLevel.READING); KtTypeProjection projection = KtPsiFactoryKt.KtPsiFactory(getProject()) .createTypeArguments("<" + typeStr + ">") .getArguments() .get(0); KtTypeReference typeReference = projection.getTypeReference(); assert typeReference != null; KotlinType type = typeResolver.resolveType( TypeTestUtilsKt.asLexicalScope(withX), typeReference, JetTestUtils.DUMMY_TRACE, true); return new TypeProjectionImpl(getProjectionKind(typeStr, projection), type); }
private static Variance getProjectionKind(String typeStr, KtTypeProjection projection) { Variance variance; switch (projection.getProjectionKind()) { case IN: variance = Variance.IN_VARIANCE; break; case OUT: variance = Variance.OUT_VARIANCE; break; case NONE: variance = Variance.INVARIANT; break; default: throw new UnsupportedOperationException("Star projections are not supported: " + typeStr); } return variance; }