Merge remote-tracking branch 'origin/master'
This commit is contained in:
@@ -15,12 +15,6 @@
|
||||
<path id="classpath">
|
||||
<fileset dir="${idea.sdk}" includes="core/*.jar"/>
|
||||
|
||||
<!--
|
||||
Work around this problem: https://gist.github.com/1c4a7d51b61ec81d581b
|
||||
Somebody please fix it properly or delete this comment if this is OK
|
||||
-->
|
||||
<pathelement path="${idea.sdk}/lib/resources_en.jar"/>
|
||||
|
||||
<fileset dir="${basedir}/lib" includes="**/*.jar"/>
|
||||
<fileset dir="${basedir}/dependencies" includes="jline.jar"/>
|
||||
<fileset dir="${basedir}/dependencies" includes="jansi.jar"/>
|
||||
|
||||
@@ -55,7 +55,6 @@ import org.jetbrains.jet.lang.resolve.constants.CompileTimeConstant;
|
||||
import org.jetbrains.jet.lang.resolve.java.AsmTypeConstants;
|
||||
import org.jetbrains.jet.lang.resolve.java.JvmAbi;
|
||||
import org.jetbrains.jet.lang.resolve.java.JvmClassName;
|
||||
import org.jetbrains.jet.lang.resolve.java.JvmPrimitiveType;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.receivers.*;
|
||||
import org.jetbrains.jet.lang.types.JetType;
|
||||
import org.jetbrains.jet.lang.types.checker.JetTypeChecker;
|
||||
@@ -421,22 +420,38 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
|
||||
|
||||
@Override
|
||||
public StackValue visitDoWhileExpression(JetDoWhileExpression expression, StackValue receiver) {
|
||||
Label condition = new Label();
|
||||
v.mark(condition);
|
||||
Label continueLabel = new Label();
|
||||
v.mark(continueLabel);
|
||||
|
||||
Label end = new Label();
|
||||
Label breakLabel = new Label();
|
||||
|
||||
blockStackElements.push(new LoopBlockStackElement(end, condition, targetLabel(expression)));
|
||||
blockStackElements.push(new LoopBlockStackElement(breakLabel, continueLabel, targetLabel(expression)));
|
||||
|
||||
gen(expression.getBody(), Type.VOID_TYPE);
|
||||
JetExpression body = expression.getBody();
|
||||
JetExpression condition = expression.getCondition();
|
||||
StackValue conditionValue;
|
||||
|
||||
final StackValue conditionValue = gen(expression.getCondition());
|
||||
conditionValue.condJump(condition, false, v);
|
||||
if (body instanceof JetBlockExpression) {
|
||||
// If body's a block, it can contain variable declarations which may be used in the condition of a do-while loop.
|
||||
// We handle this case separately because otherwise such variable will be out of the frame map after the block ends
|
||||
List<JetElement> doWhileStatements = ((JetBlockExpression) body).getStatements();
|
||||
|
||||
v.mark(end);
|
||||
List<JetElement> statements = new ArrayList<JetElement>(doWhileStatements.size() + 1);
|
||||
statements.addAll(doWhileStatements);
|
||||
statements.add(condition);
|
||||
|
||||
conditionValue = generateBlock(statements, true);
|
||||
}
|
||||
else {
|
||||
gen(body, Type.VOID_TYPE);
|
||||
conditionValue = gen(condition);
|
||||
}
|
||||
|
||||
conditionValue.condJump(continueLabel, false, v);
|
||||
v.mark(breakLabel);
|
||||
|
||||
blockStackElements.pop();
|
||||
return StackValue.onStack(Type.VOID_TYPE);
|
||||
return StackValue.none();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -47,7 +47,6 @@ import org.jetbrains.jet.lang.resolve.java.JvmClassName;
|
||||
import org.jetbrains.jet.lang.resolve.java.JvmStdlibNames;
|
||||
import org.jetbrains.jet.lang.resolve.java.kt.DescriptorKindUtils;
|
||||
import org.jetbrains.jet.lang.resolve.name.Name;
|
||||
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
@@ -401,6 +400,7 @@ public class FunctionCodegen extends GenerationStateAware {
|
||||
JetValueParameterAnnotationWriter av = JetValueParameterAnnotationWriter.visitParameterAnnotation(mv, i + start);
|
||||
av.writeName(parameterDescriptor.getName().getName());
|
||||
av.writeHasDefaultValue(parameterDescriptor.declaresDefaultValue());
|
||||
av.writeVararg(parameterDescriptor.getVarargElementType() != null);
|
||||
if (kotlinParameterTypes.get(i) != null) {
|
||||
av.writeType(kotlinParameterTypes.get(i + start).getKotlinSignature());
|
||||
}
|
||||
|
||||
@@ -1099,6 +1099,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
|
||||
JetValueParameterAnnotationWriter.visitParameterAnnotation(mv, i);
|
||||
jetValueParameterAnnotation.writeName(valueParameter.getName().getName());
|
||||
jetValueParameterAnnotation.writeHasDefaultValue(valueParameter.declaresDefaultValue());
|
||||
jetValueParameterAnnotation.writeVararg(valueParameter.getVarargElementType() != null);
|
||||
jetValueParameterAnnotation.writeType(constructorMethod.getKotlinParameterType(i));
|
||||
jetValueParameterAnnotation.visitEnd();
|
||||
++i;
|
||||
|
||||
+6
@@ -58,4 +58,10 @@ public class JetValueParameterAnnotationWriter {
|
||||
av.visit(JvmStdlibNames.JET_VALUE_PARAMETER_HAS_DEFAULT_VALUE_FIELD, true);
|
||||
}
|
||||
}
|
||||
|
||||
public void writeVararg(boolean vararg) {
|
||||
if (vararg) {
|
||||
av.visit(JvmStdlibNames.JET_VALUE_PARAMETER_VARARG, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -93,7 +93,6 @@ public class InjectorForJavaDescriptorResolver {
|
||||
this.javaPropertyResolver = new JavaPropertyResolver();
|
||||
|
||||
javaBridgeConfiguration.setJavaSemanticServices(javaSemanticServices);
|
||||
javaBridgeConfiguration.setProject(project);
|
||||
|
||||
this.javaSemanticServices.setDescriptorResolver(javaDescriptorResolver);
|
||||
this.javaSemanticServices.setPsiClassFinder(psiClassFinder);
|
||||
|
||||
@@ -104,7 +104,6 @@ public class InjectorForJavaSemanticServices {
|
||||
this.javaDescriptorResolver.setPropertiesResolver(javaPropertyResolver);
|
||||
|
||||
javaBridgeConfiguration.setJavaSemanticServices(javaSemanticServices);
|
||||
javaBridgeConfiguration.setProject(project);
|
||||
|
||||
this.psiClassFinder.setProject(project);
|
||||
|
||||
|
||||
+6
-1
@@ -40,6 +40,7 @@ import org.jetbrains.jet.lang.resolve.TypeResolver;
|
||||
import org.jetbrains.jet.lang.resolve.QualifiedExpressionResolver;
|
||||
import org.jetbrains.jet.lang.resolve.calls.CandidateResolver;
|
||||
import org.jetbrains.jet.lang.resolve.ImportsResolver;
|
||||
import org.jetbrains.jet.lang.psi.JetImportsFactory;
|
||||
import org.jetbrains.jet.lang.resolve.ScriptHeaderResolver;
|
||||
import org.jetbrains.jet.lang.resolve.OverloadResolver;
|
||||
import org.jetbrains.jet.lang.resolve.OverrideResolver;
|
||||
@@ -89,6 +90,7 @@ public class InjectorForTopDownAnalyzerForJvm implements InjectorForTopDownAnaly
|
||||
private QualifiedExpressionResolver qualifiedExpressionResolver;
|
||||
private CandidateResolver candidateResolver;
|
||||
private ImportsResolver importsResolver;
|
||||
private JetImportsFactory jetImportsFactory;
|
||||
private ScriptHeaderResolver scriptHeaderResolver;
|
||||
private OverloadResolver overloadResolver;
|
||||
private OverrideResolver overrideResolver;
|
||||
@@ -139,6 +141,7 @@ public class InjectorForTopDownAnalyzerForJvm implements InjectorForTopDownAnaly
|
||||
this.qualifiedExpressionResolver = new QualifiedExpressionResolver();
|
||||
this.candidateResolver = new CandidateResolver();
|
||||
this.importsResolver = new ImportsResolver();
|
||||
this.jetImportsFactory = new JetImportsFactory();
|
||||
this.scriptHeaderResolver = new ScriptHeaderResolver();
|
||||
this.overloadResolver = new OverloadResolver();
|
||||
this.overrideResolver = new OverrideResolver();
|
||||
@@ -193,7 +196,6 @@ public class InjectorForTopDownAnalyzerForJvm implements InjectorForTopDownAnaly
|
||||
this.descriptorResolver.setTypeResolver(typeResolver);
|
||||
|
||||
this.moduleConfiguration.setJavaSemanticServices(javaSemanticServices);
|
||||
this.moduleConfiguration.setProject(project);
|
||||
|
||||
javaDescriptorResolver.setClassResolver(javaClassResolver);
|
||||
javaDescriptorResolver.setConstructorResolver(javaConstructorResolver);
|
||||
@@ -240,9 +242,12 @@ public class InjectorForTopDownAnalyzerForJvm implements InjectorForTopDownAnaly
|
||||
|
||||
importsResolver.setConfiguration(moduleConfiguration);
|
||||
importsResolver.setContext(topDownAnalysisContext);
|
||||
importsResolver.setImportsFactory(jetImportsFactory);
|
||||
importsResolver.setQualifiedExpressionResolver(qualifiedExpressionResolver);
|
||||
importsResolver.setTrace(bindingTrace);
|
||||
|
||||
jetImportsFactory.setProject(project);
|
||||
|
||||
scriptHeaderResolver.setContext(topDownAnalysisContext);
|
||||
scriptHeaderResolver.setDependencyClassByQualifiedNameResolver(javaDescriptorResolver);
|
||||
scriptHeaderResolver.setNamespaceFactory(namespaceFactory);
|
||||
|
||||
+6
-10
@@ -19,6 +19,7 @@ package org.jetbrains.jet.lang.resolve.java;
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.base.Predicates;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Sets;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -33,8 +34,6 @@ import org.jetbrains.jet.lang.PlatformToKotlinClassMap;
|
||||
import org.jetbrains.jet.lang.descriptors.ModuleDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.NamespaceDescriptor;
|
||||
import org.jetbrains.jet.lang.psi.JetFile;
|
||||
import org.jetbrains.jet.lang.psi.JetImportDirective;
|
||||
import org.jetbrains.jet.lang.psi.JetPsiFactory;
|
||||
import org.jetbrains.jet.lang.resolve.*;
|
||||
import org.jetbrains.jet.lang.resolve.lazy.FileBasedDeclarationProviderFactory;
|
||||
import org.jetbrains.jet.lang.resolve.lazy.LockBasedStorageManager;
|
||||
@@ -45,9 +44,9 @@ import org.jetbrains.jet.lang.resolve.scopes.JetScope;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.WritableScope;
|
||||
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
|
||||
public enum AnalyzerFacadeForJVM implements AnalyzerFacade {
|
||||
@@ -103,13 +102,10 @@ public enum AnalyzerFacadeForJVM implements AnalyzerFacade {
|
||||
|
||||
ModuleConfiguration moduleConfiguration = new ModuleConfiguration() {
|
||||
@Override
|
||||
public void addDefaultImports(@NotNull Collection<JetImportDirective> directives) {
|
||||
final Collection<ImportPath> defaultImports = Lists.newArrayList(JavaBridgeConfiguration.DEFAULT_JAVA_IMPORTS);
|
||||
defaultImports.addAll(Arrays.asList(DefaultModuleConfiguration.DEFAULT_JET_IMPORTS));
|
||||
|
||||
for (ImportPath defaultJetImport : defaultImports) {
|
||||
directives.add(JetPsiFactory.createImportDirective(fileProject, defaultJetImport));
|
||||
}
|
||||
public List<ImportPath> getDefaultImports() {
|
||||
LinkedHashSet<ImportPath> imports = Sets.newLinkedHashSet(JavaBridgeConfiguration.DEFAULT_JAVA_IMPORTS);
|
||||
imports.addAll(DefaultModuleConfiguration.DEFAULT_JET_IMPORTS);
|
||||
return Lists.newArrayList(imports);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+12
-20
@@ -16,14 +16,14 @@
|
||||
|
||||
package org.jetbrains.jet.lang.resolve.java;
|
||||
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Sets;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lang.DefaultModuleConfiguration;
|
||||
import org.jetbrains.jet.lang.ModuleConfiguration;
|
||||
import org.jetbrains.jet.lang.PlatformToKotlinClassMap;
|
||||
import org.jetbrains.jet.lang.descriptors.NamespaceDescriptor;
|
||||
import org.jetbrains.jet.lang.psi.JetImportDirective;
|
||||
import org.jetbrains.jet.lang.psi.JetPsiFactory;
|
||||
import org.jetbrains.jet.lang.resolve.BindingTrace;
|
||||
import org.jetbrains.jet.lang.resolve.ImportPath;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.JetScope;
|
||||
@@ -31,22 +31,16 @@ import org.jetbrains.jet.lang.resolve.scopes.WritableScope;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import javax.inject.Inject;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
public class JavaBridgeConfiguration implements ModuleConfiguration {
|
||||
|
||||
public static final ImportPath[] DEFAULT_JAVA_IMPORTS = new ImportPath[] { new ImportPath("java.lang.*") };
|
||||
public static final List<ImportPath> DEFAULT_JAVA_IMPORTS = ImmutableList.of(new ImportPath("java.lang.*"));
|
||||
|
||||
|
||||
private Project project;
|
||||
private JavaSemanticServices javaSemanticServices;
|
||||
private ModuleConfiguration delegateConfiguration;
|
||||
|
||||
@Inject
|
||||
public void setProject(@NotNull Project project) {
|
||||
this.project = project;
|
||||
}
|
||||
|
||||
@Inject
|
||||
public void setJavaSemanticServices(@NotNull JavaSemanticServices javaSemanticServices) {
|
||||
this.javaSemanticServices = javaSemanticServices;
|
||||
@@ -54,17 +48,15 @@ public class JavaBridgeConfiguration implements ModuleConfiguration {
|
||||
|
||||
@PostConstruct
|
||||
public void init() {
|
||||
this.delegateConfiguration = DefaultModuleConfiguration.createStandardConfiguration(project);
|
||||
this.delegateConfiguration = DefaultModuleConfiguration.createStandardConfiguration();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public void addDefaultImports(@NotNull Collection<JetImportDirective> directives) {
|
||||
for (ImportPath importPath : DEFAULT_JAVA_IMPORTS) {
|
||||
directives.add(JetPsiFactory.createImportDirective(project, importPath));
|
||||
}
|
||||
delegateConfiguration.addDefaultImports(directives);
|
||||
public List<ImportPath> getDefaultImports() {
|
||||
Set<ImportPath> imports = Sets.newLinkedHashSet(DEFAULT_JAVA_IMPORTS);
|
||||
imports.addAll(delegateConfiguration.getDefaultImports());
|
||||
|
||||
return Lists.newArrayList(imports);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+1
-1
@@ -198,7 +198,7 @@ class JavaToKotlinMethodMapGenerated {
|
||||
pair("java.util.Map boolean isEmpty()", "public abstract fun isEmpty() : jet.Boolean defined in jet.MutableMap"),
|
||||
pair("java.util.Map java.util.Set<K> keySet()", "public abstract fun keySet() : jet.MutableSet<K> defined in jet.MutableMap"),
|
||||
pair("java.util.Map V put(K, V)", "public abstract fun put(key : K, value : V) : V? defined in jet.MutableMap"),
|
||||
pair("java.util.Map void putAll(java.util.Map<? extends K,? extends V>)", "public abstract fun putAll(m : jet.Map<out K, out V>) : Unit defined in jet.MutableMap"),
|
||||
pair("java.util.Map void putAll(java.util.Map<? extends K,? extends V>)", "public abstract fun putAll(m : jet.Map<out K, V>) : Unit defined in jet.MutableMap"),
|
||||
pair("java.util.Map V remove(java.lang.Object)", "public abstract fun remove(key : jet.Any?) : V? defined in jet.MutableMap"),
|
||||
pair("java.util.Map int size()", "public abstract fun size() : jet.Int defined in jet.MutableMap"),
|
||||
pair("java.util.Map java.util.Collection<V> values()", "public abstract fun values() : jet.MutableCollection<V> defined in jet.MutableMap")
|
||||
|
||||
@@ -21,7 +21,7 @@ public class JvmAbi {
|
||||
* This constant is used to identify binary format (class file) versions
|
||||
* If you change class file metadata format and/or naming conventions, please increase this number
|
||||
*/
|
||||
public static final int VERSION = 0;
|
||||
public static final int VERSION = 1;
|
||||
|
||||
public static final String TRAIT_IMPL_CLASS_NAME = "$TImpl";
|
||||
public static final String TRAIT_IMPL_SUFFIX = "$" + TRAIT_IMPL_CLASS_NAME;
|
||||
|
||||
@@ -38,8 +38,7 @@ public class JvmClassName {
|
||||
@NotNull
|
||||
public static JvmClassName byType(@NotNull Type type) {
|
||||
if (type.getSort() != Type.OBJECT) {
|
||||
throw new IllegalArgumentException(
|
||||
"must be an object to be converted to " + JvmClassName.class.getSimpleName());
|
||||
throw new IllegalArgumentException("Type is not convertible to " + JvmClassName.class.getSimpleName() + ": " + type);
|
||||
}
|
||||
return byInternalName(type.getInternalName());
|
||||
}
|
||||
|
||||
@@ -26,6 +26,7 @@ public class JvmStdlibNames {
|
||||
public static final String JET_VALUE_PARAMETER_HAS_DEFAULT_VALUE_FIELD = "hasDefaultValue";
|
||||
public static final String JET_VALUE_PARAMETER_TYPE_FIELD = "type";
|
||||
public static final String JET_VALUE_PARAMETER_RECEIVER_FIELD = "receiver";
|
||||
public static final String JET_VALUE_PARAMETER_VARARG = "vararg";
|
||||
|
||||
|
||||
public static final JvmClassName JET_TYPE_PARAMETER = JvmClassName.byFqNameWithoutInnerClasses("jet.runtime.typeinfo.JetTypeParameter");
|
||||
|
||||
+94
-58
@@ -18,6 +18,7 @@ package org.jetbrains.jet.lang.resolve.java.kotlinSignature;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.annotations.TestOnly;
|
||||
import org.jetbrains.asm4.Type;
|
||||
import org.jetbrains.jet.lang.descriptors.ClassDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.ClassifierDescriptor;
|
||||
@@ -25,7 +26,10 @@ import org.jetbrains.jet.lang.descriptors.TypeParameterDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.TypeParameterDescriptorImpl;
|
||||
import org.jetbrains.jet.lang.psi.*;
|
||||
import org.jetbrains.jet.lang.resolve.DescriptorUtils;
|
||||
import org.jetbrains.jet.lang.resolve.java.*;
|
||||
import org.jetbrains.jet.lang.resolve.java.JavaToKotlinClassMap;
|
||||
import org.jetbrains.jet.lang.resolve.java.JvmClassName;
|
||||
import org.jetbrains.jet.lang.resolve.java.KotlinToJavaTypesMap;
|
||||
import org.jetbrains.jet.lang.resolve.java.TypeUsage;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.JetScope;
|
||||
import org.jetbrains.jet.lang.types.*;
|
||||
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns;
|
||||
@@ -33,9 +37,12 @@ import org.jetbrains.jet.renderer.DescriptorRenderer;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import static org.jetbrains.jet.lang.resolve.java.TypeUsage.*;
|
||||
import static org.jetbrains.jet.lang.resolve.java.TypeUsage.TYPE_ARGUMENT;
|
||||
import static org.jetbrains.jet.lang.types.Variance.INVARIANT;
|
||||
|
||||
public class TypeTransformingVisitor extends JetVisitor<JetType, Void> {
|
||||
private static boolean strictMode = false;
|
||||
|
||||
class TypeTransformingVisitor extends JetVisitor<JetType, Void> {
|
||||
private final JetType originalType;
|
||||
private final Map<TypeParameterDescriptor, TypeParameterDescriptorImpl> originalToAltTypeParameters;
|
||||
|
||||
@@ -92,7 +99,7 @@ class TypeTransformingVisitor extends JetVisitor<JetType, Void> {
|
||||
String shortName = type.getReferenceExpression().getReferencedName();
|
||||
String longName = (qualifier == null ? "" : qualifier.getText() + ".") + shortName;
|
||||
|
||||
if (KotlinBuiltIns.getInstance().UNIT_ALIAS.getName().equals(longName)) {
|
||||
if (KotlinBuiltIns.UNIT_ALIAS.getName().equals(longName)) {
|
||||
return visitCommonType(KotlinBuiltIns.getInstance().getTuple(0), type);
|
||||
}
|
||||
|
||||
@@ -113,60 +120,6 @@ class TypeTransformingVisitor extends JetVisitor<JetType, Void> {
|
||||
throw new AlternativeSignatureMismatchException("Alternative signature type mismatch, expected: %s, actual: %s", qualifiedName, fqName);
|
||||
}
|
||||
|
||||
List<TypeProjection> arguments = originalType.getArguments();
|
||||
|
||||
if (arguments.size() != type.getTypeArgumentsAsTypes().size()) {
|
||||
throw new AlternativeSignatureMismatchException("'%s' type in method signature has %d type arguments, while '%s' in alternative signature has %d of them",
|
||||
DescriptorRenderer.TEXT.renderType(originalType), arguments.size(), type.getText(),
|
||||
type.getTypeArgumentsAsTypes().size());
|
||||
}
|
||||
|
||||
List<TypeProjection> altArguments = new ArrayList<TypeProjection>();
|
||||
for (int i = 0, size = arguments.size(); i < size; i++) {
|
||||
JetTypeReference typeReference = type.getTypeArgumentsAsTypes().get(i);
|
||||
|
||||
if (typeReference == null) {
|
||||
// star projection
|
||||
assert type instanceof JetUserType
|
||||
&& ((JetUserType) type).getTypeArguments().get(i).getProjectionKind() == JetProjectionKind.STAR;
|
||||
|
||||
altArguments.add(arguments.get(i));
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
JetTypeElement argumentAlternativeTypeElement = typeReference.getTypeElement();
|
||||
assert argumentAlternativeTypeElement != null;
|
||||
|
||||
TypeProjection argument = arguments.get(i);
|
||||
JetType alternativeArgumentType = computeType(argumentAlternativeTypeElement, argument.getType(), originalToAltTypeParameters, TYPE_ARGUMENT);
|
||||
Variance projectionKind = argument.getProjectionKind();
|
||||
Variance altProjectionKind;
|
||||
if (type instanceof JetUserType) {
|
||||
JetTypeProjection typeProjection = ((JetUserType) type).getTypeArguments().get(i);
|
||||
switch (typeProjection.getProjectionKind()) {
|
||||
case IN:
|
||||
altProjectionKind = Variance.IN_VARIANCE;
|
||||
break;
|
||||
case OUT:
|
||||
altProjectionKind = Variance.OUT_VARIANCE;
|
||||
break;
|
||||
case STAR:
|
||||
throw new IllegalStateException("star projection should have been processed above");
|
||||
default:
|
||||
altProjectionKind = Variance.INVARIANT;
|
||||
}
|
||||
if (altProjectionKind != projectionKind && projectionKind != Variance.INVARIANT) {
|
||||
throw new AlternativeSignatureMismatchException("Projection kind mismatch, actual: %s, in alternative signature: %s",
|
||||
projectionKind, altProjectionKind);
|
||||
}
|
||||
}
|
||||
else {
|
||||
altProjectionKind = projectionKind;
|
||||
}
|
||||
altArguments.add(new TypeProjection(altProjectionKind, alternativeArgumentType));
|
||||
}
|
||||
|
||||
TypeConstructor typeConstructor;
|
||||
if (classFromLibrary != null) {
|
||||
typeConstructor = classFromLibrary.getTypeConstructor();
|
||||
@@ -178,6 +131,20 @@ class TypeTransformingVisitor extends JetVisitor<JetType, Void> {
|
||||
if (typeConstructorClassifier instanceof TypeParameterDescriptor && originalToAltTypeParameters.containsKey(typeConstructorClassifier)) {
|
||||
typeConstructor = originalToAltTypeParameters.get(typeConstructorClassifier).getTypeConstructor();
|
||||
}
|
||||
|
||||
List<TypeProjection> arguments = originalType.getArguments();
|
||||
|
||||
if (arguments.size() != type.getTypeArgumentsAsTypes().size()) {
|
||||
throw new AlternativeSignatureMismatchException("'%s' type in method signature has %d type arguments, while '%s' in alternative signature has %d of them",
|
||||
DescriptorRenderer.TEXT.renderType(originalType), arguments.size(), type.getText(),
|
||||
type.getTypeArgumentsAsTypes().size());
|
||||
}
|
||||
|
||||
List<TypeProjection> altArguments = new ArrayList<TypeProjection>();
|
||||
for (int i = 0, size = arguments.size(); i < size; i++) {
|
||||
altArguments.add(getAltArgument(type, typeConstructor, i, arguments.get(i)));
|
||||
}
|
||||
|
||||
JetScope memberScope;
|
||||
if (typeConstructorClassifier instanceof TypeParameterDescriptor) {
|
||||
memberScope = ((TypeParameterDescriptor) typeConstructorClassifier).getUpperBoundsAsType().getMemberScope();
|
||||
@@ -193,6 +160,70 @@ class TypeTransformingVisitor extends JetVisitor<JetType, Void> {
|
||||
altArguments, memberScope);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private TypeProjection getAltArgument(
|
||||
@NotNull JetTypeElement type,
|
||||
@NotNull TypeConstructor typeConstructor,
|
||||
int i,
|
||||
@NotNull TypeProjection originalArgument
|
||||
) {
|
||||
JetTypeReference typeReference = type.getTypeArgumentsAsTypes().get(i); // process both function type and user type
|
||||
|
||||
if (typeReference == null) {
|
||||
// star projection
|
||||
assert type instanceof JetUserType
|
||||
&& ((JetUserType) type).getTypeArguments().get(i).getProjectionKind() == JetProjectionKind.STAR;
|
||||
|
||||
return originalArgument;
|
||||
}
|
||||
|
||||
JetTypeElement argumentAlternativeTypeElement = typeReference.getTypeElement();
|
||||
assert argumentAlternativeTypeElement != null;
|
||||
|
||||
TypeParameterDescriptor parameter = typeConstructor.getParameters().get(i);
|
||||
JetType alternativeArgumentType = computeType(argumentAlternativeTypeElement, originalArgument.getType(), originalToAltTypeParameters, TYPE_ARGUMENT);
|
||||
Variance projectionKind = originalArgument.getProjectionKind();
|
||||
Variance altProjectionKind;
|
||||
if (type instanceof JetUserType) {
|
||||
JetTypeProjection typeProjection = ((JetUserType) type).getTypeArguments().get(i);
|
||||
switch (typeProjection.getProjectionKind()) {
|
||||
case IN:
|
||||
altProjectionKind = Variance.IN_VARIANCE;
|
||||
break;
|
||||
case OUT:
|
||||
altProjectionKind = Variance.OUT_VARIANCE;
|
||||
break;
|
||||
case STAR:
|
||||
throw new IllegalStateException("star projection should have been processed above");
|
||||
default:
|
||||
altProjectionKind = Variance.INVARIANT;
|
||||
}
|
||||
if (altProjectionKind != projectionKind && projectionKind != Variance.INVARIANT) {
|
||||
throw new AlternativeSignatureMismatchException("Projection kind mismatch, actual: %s, in alternative signature: %s",
|
||||
projectionKind, altProjectionKind);
|
||||
}
|
||||
if (altProjectionKind != INVARIANT && parameter.getVariance() != INVARIANT) {
|
||||
if (altProjectionKind == parameter.getVariance()) {
|
||||
if (strictMode) {
|
||||
throw new AlternativeSignatureMismatchException("Projection kind '%s' is redundant",
|
||||
altProjectionKind, DescriptorUtils.getFQName(typeConstructor.getDeclarationDescriptor()));
|
||||
}
|
||||
else {
|
||||
altProjectionKind = projectionKind;
|
||||
}
|
||||
}
|
||||
else {
|
||||
throw new AlternativeSignatureMismatchException("Projection kind '%s' is conflicting with variance of %s",
|
||||
altProjectionKind, DescriptorUtils.getFQName(typeConstructor.getDeclarationDescriptor()));
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
altProjectionKind = projectionKind;
|
||||
}
|
||||
return new TypeProjection(altProjectionKind, alternativeArgumentType);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private ClassDescriptor getAutoTypeAnalogWithinBuiltins(String qualifiedName) {
|
||||
Type javaAnalog = KotlinToJavaTypesMap.getInstance().getJavaAnalog(originalType);
|
||||
@@ -216,4 +247,9 @@ class TypeTransformingVisitor extends JetVisitor<JetType, Void> {
|
||||
private static boolean isSameName(String qualifiedName, String fullyQualifiedName) {
|
||||
return fullyQualifiedName.equals(qualifiedName) || fullyQualifiedName.endsWith("." + qualifiedName);
|
||||
}
|
||||
|
||||
@TestOnly
|
||||
public static void setStrictMode(boolean strictMode) {
|
||||
TypeTransformingVisitor.strictMode = strictMode;
|
||||
}
|
||||
}
|
||||
|
||||
+8
-1
@@ -33,6 +33,7 @@ public class JetValueParameterAnnotation extends PsiAnnotationWrapper {
|
||||
private String type;
|
||||
private boolean receiver;
|
||||
private boolean hasDefaultValue;
|
||||
private boolean vararg;
|
||||
|
||||
private JetValueParameterAnnotation(@Nullable PsiAnnotation psiAnnotation) {
|
||||
super(psiAnnotation);
|
||||
@@ -44,6 +45,7 @@ public class JetValueParameterAnnotation extends PsiAnnotationWrapper {
|
||||
type = getStringAttribute(JvmStdlibNames.JET_VALUE_PARAMETER_TYPE_FIELD, "");
|
||||
receiver = getBooleanAttribute(JvmStdlibNames.JET_VALUE_PARAMETER_RECEIVER_FIELD, false);
|
||||
hasDefaultValue = getBooleanAttribute(JvmStdlibNames.JET_VALUE_PARAMETER_HAS_DEFAULT_VALUE_FIELD, false);
|
||||
vararg = getBooleanAttribute(JvmStdlibNames.JET_VALUE_PARAMETER_VARARG, false);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -67,7 +69,12 @@ public class JetValueParameterAnnotation extends PsiAnnotationWrapper {
|
||||
checkInitialized();
|
||||
return hasDefaultValue;
|
||||
}
|
||||
|
||||
|
||||
public boolean vararg() {
|
||||
checkInitialized();
|
||||
return vararg;
|
||||
}
|
||||
|
||||
public static JetValueParameterAnnotation get(PsiParameter psiParameter) {
|
||||
final PsiAnnotation annotation =
|
||||
JavaAnnotationResolver.findOwnAnnotation(psiParameter, JvmStdlibNames.JET_VALUE_PARAMETER.getFqName().getFqName());
|
||||
|
||||
+1
-1
@@ -76,7 +76,7 @@ public final class JavaValueParameterResolver {
|
||||
}
|
||||
|
||||
JetType varargElementType;
|
||||
if (psiType instanceof PsiEllipsisType) {
|
||||
if (psiType instanceof PsiEllipsisType || parameter.getJetValueParameter().vararg()) {
|
||||
varargElementType = KotlinBuiltIns.getInstance().getArrayElementType(TypeUtils.makeNotNullable(outType));
|
||||
outType = TypeUtils.makeNotNullable(outType);
|
||||
}
|
||||
|
||||
@@ -18,21 +18,23 @@ package org.jetbrains.jet.analyzer;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.PlatformToKotlinClassMap;
|
||||
import org.jetbrains.jet.lang.ModuleConfiguration;
|
||||
import org.jetbrains.jet.lang.PlatformToKotlinClassMap;
|
||||
import org.jetbrains.jet.lang.descriptors.NamespaceDescriptor;
|
||||
import org.jetbrains.jet.lang.psi.JetImportDirective;
|
||||
import org.jetbrains.jet.lang.resolve.BindingContext;
|
||||
import org.jetbrains.jet.lang.resolve.BindingTrace;
|
||||
import org.jetbrains.jet.lang.resolve.BodiesResolveContext;
|
||||
import org.jetbrains.jet.lang.resolve.ImportPath;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.WritableScope;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class AnalyzeExhaust {
|
||||
private static final ModuleConfiguration ERROR_CONFIGURATION = new ModuleConfiguration() {
|
||||
@Override
|
||||
public void addDefaultImports(@NotNull Collection<JetImportDirective> directives) {
|
||||
public List<ImportPath> getDefaultImports() {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -26,6 +26,7 @@ import org.jetbrains.jet.lang.resolve.TypeResolver;
|
||||
import org.jetbrains.jet.lang.resolve.lazy.ScopeProvider;
|
||||
import org.jetbrains.jet.lang.resolve.AnnotationResolver;
|
||||
import org.jetbrains.jet.lang.resolve.QualifiedExpressionResolver;
|
||||
import org.jetbrains.jet.lang.psi.JetImportsFactory;
|
||||
import org.jetbrains.jet.lang.resolve.calls.CallResolver;
|
||||
import org.jetbrains.jet.lang.resolve.calls.ArgumentTypeResolver;
|
||||
import org.jetbrains.jet.lang.resolve.calls.CandidateResolver;
|
||||
@@ -45,6 +46,7 @@ public class InjectorForLazyResolve {
|
||||
private ScopeProvider scopeProvider;
|
||||
private AnnotationResolver annotationResolver;
|
||||
private QualifiedExpressionResolver qualifiedExpressionResolver;
|
||||
private JetImportsFactory jetImportsFactory;
|
||||
private CallResolver callResolver;
|
||||
private ArgumentTypeResolver argumentTypeResolver;
|
||||
private CandidateResolver candidateResolver;
|
||||
@@ -65,6 +67,7 @@ public class InjectorForLazyResolve {
|
||||
this.scopeProvider = new ScopeProvider(resolveSession);
|
||||
this.annotationResolver = new AnnotationResolver();
|
||||
this.qualifiedExpressionResolver = new QualifiedExpressionResolver();
|
||||
this.jetImportsFactory = new JetImportsFactory();
|
||||
this.callResolver = new CallResolver();
|
||||
this.argumentTypeResolver = new ArgumentTypeResolver();
|
||||
this.candidateResolver = new CandidateResolver();
|
||||
@@ -86,6 +89,8 @@ public class InjectorForLazyResolve {
|
||||
this.annotationResolver.setCallResolver(callResolver);
|
||||
this.annotationResolver.setExpressionTypingServices(expressionTypingServices);
|
||||
|
||||
this.jetImportsFactory.setProject(project);
|
||||
|
||||
callResolver.setArgumentTypeResolver(argumentTypeResolver);
|
||||
callResolver.setCandidateResolver(candidateResolver);
|
||||
callResolver.setExpressionTypingServices(expressionTypingServices);
|
||||
@@ -126,4 +131,8 @@ public class InjectorForLazyResolve {
|
||||
return this.qualifiedExpressionResolver;
|
||||
}
|
||||
|
||||
public JetImportsFactory getJetImportsFactory() {
|
||||
return this.jetImportsFactory;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -38,6 +38,7 @@ import org.jetbrains.jet.lang.resolve.TypeResolver;
|
||||
import org.jetbrains.jet.lang.resolve.QualifiedExpressionResolver;
|
||||
import org.jetbrains.jet.lang.resolve.calls.CandidateResolver;
|
||||
import org.jetbrains.jet.lang.resolve.ImportsResolver;
|
||||
import org.jetbrains.jet.lang.psi.JetImportsFactory;
|
||||
import org.jetbrains.jet.lang.resolve.ScriptHeaderResolver;
|
||||
import org.jetbrains.jet.lang.resolve.OverloadResolver;
|
||||
import org.jetbrains.jet.lang.resolve.OverrideResolver;
|
||||
@@ -71,6 +72,7 @@ public class InjectorForTopDownAnalyzerBasic {
|
||||
private QualifiedExpressionResolver qualifiedExpressionResolver;
|
||||
private CandidateResolver candidateResolver;
|
||||
private ImportsResolver importsResolver;
|
||||
private JetImportsFactory jetImportsFactory;
|
||||
private ScriptHeaderResolver scriptHeaderResolver;
|
||||
private OverloadResolver overloadResolver;
|
||||
private OverrideResolver overrideResolver;
|
||||
@@ -106,6 +108,7 @@ public class InjectorForTopDownAnalyzerBasic {
|
||||
this.qualifiedExpressionResolver = new QualifiedExpressionResolver();
|
||||
this.candidateResolver = new CandidateResolver();
|
||||
this.importsResolver = new ImportsResolver();
|
||||
this.jetImportsFactory = new JetImportsFactory();
|
||||
this.scriptHeaderResolver = new ScriptHeaderResolver();
|
||||
this.overloadResolver = new OverloadResolver();
|
||||
this.overrideResolver = new OverrideResolver();
|
||||
@@ -180,9 +183,12 @@ public class InjectorForTopDownAnalyzerBasic {
|
||||
|
||||
importsResolver.setConfiguration(moduleConfiguration);
|
||||
importsResolver.setContext(topDownAnalysisContext);
|
||||
importsResolver.setImportsFactory(jetImportsFactory);
|
||||
importsResolver.setQualifiedExpressionResolver(qualifiedExpressionResolver);
|
||||
importsResolver.setTrace(bindingTrace);
|
||||
|
||||
jetImportsFactory.setProject(project);
|
||||
|
||||
scriptHeaderResolver.setContext(topDownAnalysisContext);
|
||||
scriptHeaderResolver.setDependencyClassByQualifiedNameResolver(dependencyClassByQualifiedNameResolverDummy);
|
||||
scriptHeaderResolver.setNamespaceFactory(namespaceFactory);
|
||||
|
||||
@@ -16,38 +16,33 @@
|
||||
|
||||
package org.jetbrains.jet.lang;
|
||||
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lang.descriptors.NamespaceDescriptor;
|
||||
import org.jetbrains.jet.lang.psi.JetImportDirective;
|
||||
import org.jetbrains.jet.lang.psi.JetPsiFactory;
|
||||
import org.jetbrains.jet.lang.resolve.BindingTrace;
|
||||
import org.jetbrains.jet.lang.resolve.DescriptorUtils;
|
||||
import org.jetbrains.jet.lang.resolve.ImportPath;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.WritableScope;
|
||||
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
public class DefaultModuleConfiguration implements ModuleConfiguration {
|
||||
public static final ImportPath[] DEFAULT_JET_IMPORTS = new ImportPath[] {
|
||||
new ImportPath("kotlin.*"), new ImportPath("kotlin.io.*"), new ImportPath("jet.*"), };
|
||||
public static final List<ImportPath> DEFAULT_JET_IMPORTS = ImmutableList.of(
|
||||
new ImportPath("kotlin.*"),
|
||||
new ImportPath("kotlin.io.*"),
|
||||
new ImportPath("jet.*"));
|
||||
|
||||
private final Project project;
|
||||
|
||||
public static DefaultModuleConfiguration createStandardConfiguration(Project project) {
|
||||
return new DefaultModuleConfiguration(project);
|
||||
public static DefaultModuleConfiguration createStandardConfiguration() {
|
||||
return new DefaultModuleConfiguration();
|
||||
}
|
||||
|
||||
private DefaultModuleConfiguration(@NotNull Project project) {
|
||||
this.project = project;
|
||||
private DefaultModuleConfiguration() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addDefaultImports(@NotNull Collection<JetImportDirective> directives) {
|
||||
for (ImportPath defaultJetImport : DEFAULT_JET_IMPORTS) {
|
||||
directives.add(JetPsiFactory.createImportDirective(project, defaultJetImport));
|
||||
}
|
||||
public List<ImportPath> getDefaultImports() {
|
||||
return DEFAULT_JET_IMPORTS;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -18,16 +18,18 @@ package org.jetbrains.jet.lang;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lang.descriptors.NamespaceDescriptor;
|
||||
import org.jetbrains.jet.lang.psi.JetImportDirective;
|
||||
import org.jetbrains.jet.lang.resolve.BindingTrace;
|
||||
import org.jetbrains.jet.lang.resolve.ImportPath;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.WritableScope;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public interface ModuleConfiguration {
|
||||
ModuleConfiguration EMPTY = new ModuleConfiguration() {
|
||||
@Override
|
||||
public void addDefaultImports(@NotNull Collection<JetImportDirective> directives) {
|
||||
public List<ImportPath> getDefaultImports() {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -46,7 +48,7 @@ public interface ModuleConfiguration {
|
||||
}
|
||||
};
|
||||
|
||||
void addDefaultImports(@NotNull Collection<JetImportDirective> directives);
|
||||
List<ImportPath> getDefaultImports();
|
||||
|
||||
/**
|
||||
* This method is called every time a namespace descriptor is created. Use it to add extra descriptors to the namespace, e.g. merge a
|
||||
|
||||
+1
-5
@@ -20,14 +20,10 @@ import com.google.common.collect.Sets;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.psi.JetParameter;
|
||||
import org.jetbrains.jet.lang.resolve.AbstractScopeAdapter;
|
||||
import org.jetbrains.jet.lang.resolve.BindingContextUtils;
|
||||
import org.jetbrains.jet.lang.resolve.BindingTrace;
|
||||
import org.jetbrains.jet.lang.resolve.name.Name;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.JetScope;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.RedeclarationHandler;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.WritableScope;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.WritableScopeImpl;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.*;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
@@ -0,0 +1,67 @@
|
||||
/*
|
||||
* Copyright 2010-2013 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.psi;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.collect.Collections2;
|
||||
import com.google.common.collect.Maps;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.resolve.ImportPath;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
|
||||
public class JetImportsFactory {
|
||||
@NotNull
|
||||
private Project project;
|
||||
|
||||
private final Map<ImportPath, JetImportDirective> importsCache = Maps.newHashMap();
|
||||
|
||||
@Inject
|
||||
public void setProject(@NotNull Project project) {
|
||||
importsCache.clear();
|
||||
this.project = project;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public JetImportDirective createImportDirective(@NotNull ImportPath importPath) {
|
||||
JetImportDirective directive = importsCache.get(importPath);
|
||||
if (directive != null) {
|
||||
return directive;
|
||||
}
|
||||
|
||||
JetImportDirective createdDirective = JetPsiFactory.createImportDirective(project, importPath);
|
||||
importsCache.put(importPath, createdDirective);
|
||||
|
||||
return createdDirective;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Collection<JetImportDirective> createImportDirectives(@NotNull Collection<ImportPath> importPaths) {
|
||||
return Collections2.transform(importPaths,
|
||||
new Function<ImportPath, JetImportDirective>() {
|
||||
@Override
|
||||
public JetImportDirective apply(@Nullable ImportPath path) {
|
||||
assert path != null;
|
||||
return createImportDirective(path);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -26,6 +26,7 @@ import com.intellij.util.LocalTimeCounter;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.resolve.ImportPath;
|
||||
import org.jetbrains.jet.lang.resolve.name.Name;
|
||||
import org.jetbrains.jet.lexer.JetKeywordToken;
|
||||
import org.jetbrains.jet.lexer.JetTokens;
|
||||
import org.jetbrains.jet.plugin.JetFileType;
|
||||
@@ -179,11 +180,6 @@ public class JetPsiFactory {
|
||||
|
||||
@NotNull
|
||||
public static JetImportDirective createImportDirective(Project project, @NotNull ImportPath importPath) {
|
||||
return createImportDirective(project, importPath, null);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static JetImportDirective createImportDirective(Project project, @NotNull ImportPath importPath, @Nullable String aliasName) {
|
||||
if (importPath.fqnPart().isRoot()) {
|
||||
throw new IllegalArgumentException("import path must not be empty");
|
||||
}
|
||||
@@ -191,12 +187,9 @@ public class JetPsiFactory {
|
||||
StringBuilder importDirectiveBuilder = new StringBuilder("import ");
|
||||
importDirectiveBuilder.append(importPath.getPathStr());
|
||||
|
||||
if (aliasName != null) {
|
||||
if (aliasName.isEmpty()) {
|
||||
throw new IllegalArgumentException("Alias must not be empty");
|
||||
}
|
||||
|
||||
importDirectiveBuilder.append(" as ").append(aliasName);
|
||||
Name alias = importPath.getAlias();
|
||||
if (alias != null) {
|
||||
importDirectiveBuilder.append(" as ").append(alias.getName());
|
||||
}
|
||||
|
||||
JetFile namespace = createFile(project, importDirectiveBuilder.toString());
|
||||
|
||||
@@ -35,6 +35,7 @@ import org.jetbrains.jet.lang.types.expressions.OperatorConventions;
|
||||
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns;
|
||||
import org.jetbrains.jet.lexer.JetToken;
|
||||
import org.jetbrains.jet.lexer.JetTokens;
|
||||
import org.jetbrains.jet.util.QualifiedNamesUtil;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
@@ -258,17 +259,22 @@ public class JetPsiUtil {
|
||||
@Nullable
|
||||
@IfNotParsed
|
||||
public static ImportPath getImportPath(JetImportDirective importDirective) {
|
||||
final JetExpression importedReference = importDirective.getImportedReference();
|
||||
if (importedReference == null) {
|
||||
if (PsiTreeUtil.hasErrorElements(importDirective)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (PsiTreeUtil.hasErrorElements(importedReference)) {
|
||||
FqName importFqn = getFQName(importDirective.getImportedReference());
|
||||
if (importFqn == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
final String text = importedReference.getText();
|
||||
return new ImportPath(text.replaceAll(" ", "") + (importDirective.isAllUnder() ? ".*" : ""));
|
||||
Name alias = null;
|
||||
String aliasName = importDirective.getAliasName();
|
||||
if (aliasName != null) {
|
||||
alias = Name.identifier(aliasName);
|
||||
}
|
||||
|
||||
return new ImportPath(importFqn, importDirective.isAllUnder(), alias);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@@ -356,8 +362,7 @@ public class JetPsiUtil {
|
||||
aliasName = referenceExpression != null ? referenceExpression.getReferencedName() : null;
|
||||
}
|
||||
|
||||
//noinspection ConstantConditions
|
||||
return !aliasName.isEmpty() ? Name.identifier(aliasName) : null;
|
||||
return aliasName != null && !aliasName.isEmpty() ? Name.identifier(aliasName) : null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@@ -373,7 +378,8 @@ public class JetPsiUtil {
|
||||
}
|
||||
|
||||
public static boolean isFirstPartInQualified(@NotNull JetSimpleNameExpression nameExpression) {
|
||||
@SuppressWarnings("unchecked") JetUserType userType = PsiTreeUtil.getParentOfType(nameExpression, JetUserType.class, true, JetDeclaration.class);
|
||||
@SuppressWarnings("unchecked") JetUserType userType = PsiTreeUtil.getParentOfType(nameExpression, JetUserType.class, true,
|
||||
JetDeclaration.class);
|
||||
if (userType != null) {
|
||||
return PsiTreeUtil.isAncestor(userType.getFirstChild(), nameExpression, false);
|
||||
}
|
||||
@@ -485,4 +491,40 @@ public class JetPsiUtil {
|
||||
public static boolean isBackingFieldReference(@Nullable JetElement element) {
|
||||
return element instanceof JetSimpleNameExpression && isBackingFieldReference((JetSimpleNameExpression)element);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static FqName getFQName(@Nullable JetExpression expression) {
|
||||
if (expression == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (expression instanceof JetDotQualifiedExpression) {
|
||||
JetDotQualifiedExpression dotQualifiedExpression = (JetDotQualifiedExpression) expression;
|
||||
FqName parentFqn = getFQName(dotQualifiedExpression.getReceiverExpression());
|
||||
Name child = getName(dotQualifiedExpression.getSelectorExpression());
|
||||
|
||||
return parentFqn != null && child != null ? parentFqn.child(child) : null;
|
||||
}
|
||||
else if (expression instanceof JetSimpleNameExpression) {
|
||||
JetSimpleNameExpression simpleNameExpression = (JetSimpleNameExpression) expression;
|
||||
return FqName.topLevel(simpleNameExpression.getReferencedNameAsName());
|
||||
}
|
||||
else {
|
||||
throw new IllegalArgumentException("Can't construct fqn for: " + expression.getClass().toString());
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static Name getName(@Nullable JetExpression expression) {
|
||||
if (expression == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (expression instanceof JetSimpleNameExpression) {
|
||||
return ((JetSimpleNameExpression) expression).getReferencedNameAsName();
|
||||
}
|
||||
else {
|
||||
throw new IllegalArgumentException("Can't construct name for: " + expression.getClass().toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,15 +17,23 @@
|
||||
package org.jetbrains.jet.lang.resolve;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.resolve.name.FqName;
|
||||
import org.jetbrains.jet.lang.resolve.name.Name;
|
||||
|
||||
public final class ImportPath {
|
||||
private final @NotNull FqName fqName;
|
||||
private final @Nullable Name alias;
|
||||
private final boolean isAllUnder;
|
||||
|
||||
public ImportPath(@NotNull FqName fqName, boolean isAllUnder) {
|
||||
this(fqName, isAllUnder, null);
|
||||
}
|
||||
|
||||
public ImportPath(@NotNull FqName fqName, boolean isAllUnder, @Nullable Name alias) {
|
||||
this.fqName = fqName;
|
||||
this.isAllUnder = isAllUnder;
|
||||
this.alias = alias;
|
||||
}
|
||||
|
||||
public ImportPath(@NotNull String pathStr) {
|
||||
@@ -37,6 +45,8 @@ public final class ImportPath {
|
||||
this.isAllUnder = false;
|
||||
this.fqName = new FqName(pathStr);
|
||||
}
|
||||
|
||||
alias = null;
|
||||
}
|
||||
|
||||
public String getPathStr() {
|
||||
@@ -45,7 +55,7 @@ public final class ImportPath {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return getPathStr();
|
||||
return getPathStr() + (alias != null ? " as " + alias.getName() : "");
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -53,21 +63,47 @@ public final class ImportPath {
|
||||
return fqName;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public Name getAlias() {
|
||||
return alias;
|
||||
}
|
||||
|
||||
public boolean hasAlias() {
|
||||
return alias != null;
|
||||
}
|
||||
|
||||
public boolean isAllUnder() {
|
||||
return isAllUnder;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public Name getImportedName() {
|
||||
if (!isAllUnder()) {
|
||||
return alias != null ? alias : fqName.shortName();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
|
||||
ImportPath path = (ImportPath) o;
|
||||
|
||||
if (isAllUnder != path.isAllUnder) return false;
|
||||
if (alias != null ? !alias.equals(path.alias) : path.alias != null) return false;
|
||||
if (!fqName.equals(path.fqName)) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return 31 * fqName.hashCode() + (isAllUnder ? 1 : 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj) return true;
|
||||
if (!(obj instanceof ImportPath)) return false;
|
||||
|
||||
ImportPath other = (ImportPath) obj;
|
||||
return fqName.equals(other.fqName) && (isAllUnder == other.isAllUnder);
|
||||
int result = fqName.hashCode();
|
||||
result = 31 * result + (alias != null ? alias.hashCode() : 0);
|
||||
result = 31 * result + (isAllUnder ? 1 : 0);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,8 +31,7 @@ import org.jetbrains.jet.lang.resolve.scopes.WritableScope;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
/*package*/ interface Importer {
|
||||
|
||||
public interface Importer {
|
||||
void addAllUnderImport(@NotNull DeclarationDescriptor descriptor, @NotNull PlatformToKotlinClassMap platformToKotlinClassMap);
|
||||
|
||||
void addAliasImport(@NotNull DeclarationDescriptor descriptor, @NotNull Name aliasName);
|
||||
|
||||
@@ -19,9 +19,12 @@ package org.jetbrains.jet.lang.resolve;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Maps;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lang.PlatformToKotlinClassMap;
|
||||
import org.jetbrains.jet.lang.ModuleConfiguration;
|
||||
import org.jetbrains.jet.lang.descriptors.*;
|
||||
import org.jetbrains.jet.lang.PlatformToKotlinClassMap;
|
||||
import org.jetbrains.jet.lang.descriptors.ClassDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.NamespaceDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.VariableDescriptor;
|
||||
import org.jetbrains.jet.lang.psi.*;
|
||||
import org.jetbrains.jet.lang.resolve.name.Name;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.JetScope;
|
||||
@@ -32,9 +35,8 @@ import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.jetbrains.jet.lang.diagnostics.Errors.PLATFORM_CLASS_MAPPED_TO_KOTLIN;
|
||||
import static org.jetbrains.jet.lang.diagnostics.Errors.USELESS_HIDDEN_IMPORT;
|
||||
import static org.jetbrains.jet.lang.diagnostics.Errors.USELESS_SIMPLE_IMPORT;
|
||||
import static org.jetbrains.jet.lang.diagnostics.Errors.*;
|
||||
import static org.jetbrains.jet.lang.resolve.QualifiedExpressionResolver.LookupMode;
|
||||
|
||||
public class ImportsResolver {
|
||||
@NotNull
|
||||
@@ -45,6 +47,8 @@ public class ImportsResolver {
|
||||
private QualifiedExpressionResolver qualifiedExpressionResolver;
|
||||
@NotNull
|
||||
private BindingTrace trace;
|
||||
@NotNull
|
||||
private JetImportsFactory importsFactory;
|
||||
|
||||
@Inject
|
||||
public void setContext(@NotNull TopDownAnalysisContext context) {
|
||||
@@ -66,69 +70,77 @@ public class ImportsResolver {
|
||||
this.qualifiedExpressionResolver = qualifiedExpressionResolver;
|
||||
}
|
||||
|
||||
@Inject
|
||||
public void setImportsFactory(@NotNull JetImportsFactory importsFactory) {
|
||||
this.importsFactory = importsFactory;
|
||||
}
|
||||
|
||||
public void processTypeImports(@NotNull JetScope rootScope) {
|
||||
processImports(true, rootScope);
|
||||
processImports(LookupMode.ONLY_CLASSES, rootScope);
|
||||
}
|
||||
|
||||
public void processMembersImports(@NotNull JetScope rootScope) {
|
||||
processImports(false, rootScope);
|
||||
processImports(LookupMode.EVERYTHING, rootScope);
|
||||
}
|
||||
|
||||
private void processImports(boolean onlyClasses, @NotNull JetScope rootScope) {
|
||||
private void processImports(@NotNull LookupMode lookupMode, @NotNull JetScope rootScope) {
|
||||
for (JetFile file : context.getNamespaceDescriptors().keySet()) {
|
||||
WritableScope namespaceScope = context.getNamespaceScopes().get(file);
|
||||
processImportsInFile(onlyClasses, namespaceScope, Lists.newArrayList(file.getImportDirectives()), rootScope);
|
||||
processImportsInFile(lookupMode, namespaceScope, Lists.newArrayList(file.getImportDirectives()), rootScope);
|
||||
}
|
||||
for (JetScript script : context.getScripts().keySet()) {
|
||||
WritableScope scriptScope = context.getScriptScopes().get(script);
|
||||
processImportsInFile(onlyClasses, scriptScope, script.getImportDirectives(), rootScope);
|
||||
processImportsInFile(lookupMode, scriptScope, script.getImportDirectives(), rootScope);
|
||||
}
|
||||
}
|
||||
|
||||
private void processImportsInFile(boolean classes, WritableScope scope, List<JetImportDirective> directives, JetScope rootScope) {
|
||||
processImportsInFile(classes, scope, directives, rootScope, configuration, trace, qualifiedExpressionResolver);
|
||||
private void processImportsInFile(@NotNull LookupMode lookupMode, WritableScope scope, List<JetImportDirective> directives, JetScope rootScope) {
|
||||
processImportsInFile(lookupMode, scope, directives, rootScope, configuration, trace, qualifiedExpressionResolver, importsFactory);
|
||||
}
|
||||
|
||||
public static void processImportsInFile(
|
||||
boolean onlyClasses,
|
||||
LookupMode lookupMode,
|
||||
@NotNull WritableScope namespaceScope,
|
||||
@NotNull List<JetImportDirective> importDirectives,
|
||||
@NotNull JetScope rootScope,
|
||||
@NotNull ModuleConfiguration configuration,
|
||||
@NotNull BindingTrace trace,
|
||||
@NotNull QualifiedExpressionResolver qualifiedExpressionResolver
|
||||
@NotNull QualifiedExpressionResolver qualifiedExpressionResolver,
|
||||
@NotNull JetImportsFactory importsFactory
|
||||
) {
|
||||
|
||||
Importer.DelayedImporter delayedImporter = new Importer.DelayedImporter(namespaceScope);
|
||||
if (!onlyClasses) {
|
||||
if (lookupMode == LookupMode.EVERYTHING) {
|
||||
namespaceScope.clearImports();
|
||||
}
|
||||
Map<JetImportDirective, DeclarationDescriptor> resolvedDirectives = Maps.newHashMap();
|
||||
Collection<JetImportDirective> defaultImportDirectives = Lists.newArrayList();
|
||||
configuration.addDefaultImports(defaultImportDirectives);
|
||||
for (JetImportDirective defaultImportDirective : defaultImportDirectives) {
|
||||
|
||||
for (ImportPath defaultImportPath : configuration.getDefaultImports()) {
|
||||
TemporaryBindingTrace temporaryTrace = TemporaryBindingTrace.create(
|
||||
trace, "transient trace to resolve default imports"); //not to trace errors of default imports
|
||||
|
||||
JetImportDirective defaultImportDirective = importsFactory.createImportDirective(defaultImportPath);
|
||||
qualifiedExpressionResolver.processImportReference(defaultImportDirective, rootScope, namespaceScope, delayedImporter,
|
||||
temporaryTrace, configuration, onlyClasses);
|
||||
temporaryTrace, configuration, lookupMode);
|
||||
}
|
||||
|
||||
Map<JetImportDirective, DeclarationDescriptor> resolvedDirectives = Maps.newHashMap();
|
||||
|
||||
for (JetImportDirective importDirective : importDirectives) {
|
||||
Collection<? extends DeclarationDescriptor> descriptors =
|
||||
qualifiedExpressionResolver.processImportReference(importDirective, rootScope, namespaceScope, delayedImporter,
|
||||
trace, configuration, onlyClasses);
|
||||
trace, configuration, lookupMode);
|
||||
if (descriptors.size() == 1) {
|
||||
resolvedDirectives.put(importDirective, descriptors.iterator().next());
|
||||
}
|
||||
for (DeclarationDescriptor descriptor : descriptors) {
|
||||
JetExpression importedReference = importDirective.getImportedReference();
|
||||
if (onlyClasses || importedReference == null) continue;
|
||||
if (lookupMode == LookupMode.ONLY_CLASSES || importedReference == null) continue;
|
||||
reportPlatformClassMappedToKotlin(configuration, trace, importedReference, descriptor);
|
||||
}
|
||||
}
|
||||
delayedImporter.processImports();
|
||||
|
||||
if (!onlyClasses) {
|
||||
if (lookupMode == LookupMode.EVERYTHING) {
|
||||
for (JetImportDirective importDirective : importDirectives) {
|
||||
reportUselessImport(importDirective, namespaceScope, resolvedDirectives, trace);
|
||||
}
|
||||
|
||||
+52
-32
@@ -36,6 +36,13 @@ import java.util.Set;
|
||||
import static org.jetbrains.jet.lang.diagnostics.Errors.*;
|
||||
|
||||
public class QualifiedExpressionResolver {
|
||||
public enum LookupMode {
|
||||
// Only classifier and packages are resolved
|
||||
ONLY_CLASSES,
|
||||
|
||||
// Resolve all descriptors
|
||||
EVERYTHING
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Collection<? extends DeclarationDescriptor> analyseImportReference(
|
||||
@@ -44,7 +51,7 @@ public class QualifiedExpressionResolver {
|
||||
@NotNull BindingTrace trace,
|
||||
@NotNull ModuleConfiguration moduleConfiguration
|
||||
) {
|
||||
return processImportReference(importDirective, scope, scope, Importer.DO_NOTHING, trace, moduleConfiguration, false);
|
||||
return processImportReference(importDirective, scope, scope, Importer.DO_NOTHING, trace, moduleConfiguration, LookupMode.EVERYTHING);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -55,7 +62,7 @@ public class QualifiedExpressionResolver {
|
||||
@NotNull Importer importer,
|
||||
@NotNull BindingTrace trace,
|
||||
@NotNull ModuleConfiguration moduleConfiguration,
|
||||
boolean onlyClasses
|
||||
@NotNull LookupMode lookupMode
|
||||
) {
|
||||
if (importDirective.isAbsoluteInRootNamespace()) {
|
||||
trace.report(UNSUPPORTED.on(importDirective, "TypeHierarchyResolver")); // TODO
|
||||
@@ -69,16 +76,20 @@ public class QualifiedExpressionResolver {
|
||||
Collection<? extends DeclarationDescriptor> descriptors;
|
||||
if (importedReference instanceof JetQualifiedExpression) {
|
||||
//store result only when we find all descriptors, not only classes on the second phase
|
||||
descriptors = lookupDescriptorsForQualifiedExpression((JetQualifiedExpression)importedReference, scope, scopeToCheckVisibility, trace, onlyClasses, !onlyClasses);
|
||||
descriptors = lookupDescriptorsForQualifiedExpression(
|
||||
(JetQualifiedExpression)importedReference, scope, scopeToCheckVisibility, trace,
|
||||
lookupMode, lookupMode == LookupMode.EVERYTHING);
|
||||
}
|
||||
else {
|
||||
assert importedReference instanceof JetSimpleNameExpression;
|
||||
descriptors = lookupDescriptorsForSimpleNameReference((JetSimpleNameExpression)importedReference, scope, scopeToCheckVisibility, trace, onlyClasses, true, !onlyClasses);
|
||||
descriptors = lookupDescriptorsForSimpleNameReference(
|
||||
(JetSimpleNameExpression)importedReference, scope, scopeToCheckVisibility, trace,
|
||||
lookupMode, true, lookupMode == LookupMode.EVERYTHING);
|
||||
}
|
||||
|
||||
JetSimpleNameExpression referenceExpression = JetPsiUtil.getLastReference(importedReference);
|
||||
if (importDirective.isAllUnder()) {
|
||||
if (referenceExpression == null || !canImportMembersFrom(descriptors, referenceExpression, trace, onlyClasses)) {
|
||||
if (referenceExpression == null || !canImportMembersFrom(descriptors, referenceExpression, trace, lookupMode)) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@@ -101,18 +112,20 @@ public class QualifiedExpressionResolver {
|
||||
}
|
||||
|
||||
private boolean canImportMembersFrom(@NotNull Collection<? extends DeclarationDescriptor> descriptors,
|
||||
@NotNull JetSimpleNameExpression reference, @NotNull BindingTrace trace, boolean onlyClasses) {
|
||||
@NotNull JetSimpleNameExpression reference, @NotNull BindingTrace trace, @NotNull LookupMode lookupMode
|
||||
) {
|
||||
|
||||
if (onlyClasses) {
|
||||
if (lookupMode == LookupMode.ONLY_CLASSES) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (descriptors.size() == 1) {
|
||||
return canImportMembersFrom(descriptors.iterator().next(), reference, trace, onlyClasses);
|
||||
return canImportMembersFrom(descriptors.iterator().next(), reference, trace, lookupMode);
|
||||
}
|
||||
TemporaryBindingTrace temporaryTrace = TemporaryBindingTrace.create(trace, "trace to find out if members can be imported from", reference);
|
||||
boolean canImport = false;
|
||||
for (DeclarationDescriptor descriptor : descriptors) {
|
||||
canImport |= canImportMembersFrom(descriptor, reference, temporaryTrace, onlyClasses);
|
||||
canImport |= canImportMembersFrom(descriptor, reference, temporaryTrace, lookupMode);
|
||||
}
|
||||
if (!canImport) {
|
||||
temporaryTrace.commit();
|
||||
@@ -121,9 +134,10 @@ public class QualifiedExpressionResolver {
|
||||
}
|
||||
|
||||
private boolean canImportMembersFrom(@NotNull DeclarationDescriptor descriptor,
|
||||
@NotNull JetSimpleNameExpression reference, @NotNull BindingTrace trace, boolean onlyClasses) {
|
||||
@NotNull JetSimpleNameExpression reference, @NotNull BindingTrace trace, @NotNull LookupMode lookupMode
|
||||
) {
|
||||
|
||||
assert !onlyClasses;
|
||||
assert lookupMode == LookupMode.EVERYTHING;
|
||||
if (descriptor instanceof NamespaceDescriptor) {
|
||||
return true;
|
||||
}
|
||||
@@ -148,24 +162,26 @@ public class QualifiedExpressionResolver {
|
||||
}
|
||||
JetUserType qualifier = userType.getQualifier();
|
||||
if (qualifier == null) {
|
||||
return lookupDescriptorsForSimpleNameReference(referenceExpression, outerScope, outerScope, trace, true, false, true);
|
||||
return lookupDescriptorsForSimpleNameReference(referenceExpression, outerScope, outerScope, trace, LookupMode.ONLY_CLASSES, false, true);
|
||||
}
|
||||
Collection<? extends DeclarationDescriptor> declarationDescriptors = lookupDescriptorsForUserType(qualifier, outerScope, trace);
|
||||
return lookupSelectorDescriptors(referenceExpression, declarationDescriptors, trace, outerScope, true, true);
|
||||
return lookupSelectorDescriptors(referenceExpression, declarationDescriptors, trace, outerScope, LookupMode.ONLY_CLASSES, true);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Collection<? extends DeclarationDescriptor> lookupDescriptorsForQualifiedExpression(@NotNull JetQualifiedExpression importedReference,
|
||||
@NotNull JetScope outerScope, @NotNull JetScope scopeToCheckVisibility, @NotNull BindingTrace trace, boolean onlyClasses, boolean storeResult) {
|
||||
@NotNull JetScope outerScope, @NotNull JetScope scopeToCheckVisibility, @NotNull BindingTrace trace, @NotNull LookupMode lookupMode, boolean storeResult) {
|
||||
|
||||
JetExpression receiverExpression = importedReference.getReceiverExpression();
|
||||
Collection<? extends DeclarationDescriptor> declarationDescriptors;
|
||||
if (receiverExpression instanceof JetQualifiedExpression) {
|
||||
declarationDescriptors = lookupDescriptorsForQualifiedExpression((JetQualifiedExpression)receiverExpression, outerScope, scopeToCheckVisibility, trace, onlyClasses, storeResult);
|
||||
declarationDescriptors = lookupDescriptorsForQualifiedExpression((JetQualifiedExpression)receiverExpression, outerScope, scopeToCheckVisibility, trace,
|
||||
lookupMode, storeResult);
|
||||
}
|
||||
else {
|
||||
assert receiverExpression instanceof JetSimpleNameExpression;
|
||||
declarationDescriptors = lookupDescriptorsForSimpleNameReference((JetSimpleNameExpression)receiverExpression, outerScope, scopeToCheckVisibility, trace, onlyClasses, true, storeResult);
|
||||
declarationDescriptors = lookupDescriptorsForSimpleNameReference((JetSimpleNameExpression)receiverExpression, outerScope, scopeToCheckVisibility, trace,
|
||||
lookupMode, true, storeResult);
|
||||
}
|
||||
|
||||
JetExpression selectorExpression = importedReference.getSelectorExpression();
|
||||
@@ -175,37 +191,40 @@ public class QualifiedExpressionResolver {
|
||||
|
||||
JetSimpleNameExpression selector = (JetSimpleNameExpression)selectorExpression;
|
||||
JetSimpleNameExpression lastReference = JetPsiUtil.getLastReference(receiverExpression);
|
||||
if (lastReference == null || !canImportMembersFrom(declarationDescriptors, lastReference, trace, onlyClasses)) {
|
||||
if (lastReference == null || !canImportMembersFrom(declarationDescriptors, lastReference, trace, lookupMode)) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
return lookupSelectorDescriptors(selector, declarationDescriptors, trace, scopeToCheckVisibility, onlyClasses, storeResult);
|
||||
return lookupSelectorDescriptors(selector, declarationDescriptors, trace, scopeToCheckVisibility, lookupMode, storeResult);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private Collection<? extends DeclarationDescriptor> lookupSelectorDescriptors(@NotNull JetSimpleNameExpression selector,
|
||||
@NotNull Collection<? extends DeclarationDescriptor> declarationDescriptors, @NotNull BindingTrace trace,
|
||||
@NotNull JetScope scopeToCheckVisibility, boolean onlyClasses, boolean storeResult) {
|
||||
@NotNull JetScope scopeToCheckVisibility, @NotNull LookupMode lookupMode, boolean storeResult) {
|
||||
|
||||
Set<SuccessfulLookupResult> results = Sets.newHashSet();
|
||||
for (DeclarationDescriptor declarationDescriptor : declarationDescriptors) {
|
||||
if (declarationDescriptor instanceof NamespaceDescriptor) {
|
||||
addResult(results, lookupSimpleNameReference(selector, ((NamespaceDescriptor)declarationDescriptor).getMemberScope(), onlyClasses, true));
|
||||
addResult(results, lookupSimpleNameReference(selector, ((NamespaceDescriptor)declarationDescriptor).getMemberScope(),
|
||||
lookupMode, true));
|
||||
}
|
||||
if (declarationDescriptor instanceof ClassDescriptor) {
|
||||
addResult(results, lookupSimpleNameReference(selector, getAppropriateScope((ClassDescriptor)declarationDescriptor, onlyClasses), onlyClasses, false));
|
||||
addResult(results, lookupSimpleNameReference(selector, getAppropriateScope((ClassDescriptor)declarationDescriptor,
|
||||
lookupMode), lookupMode, false));
|
||||
ClassDescriptor classObjectDescriptor = ((ClassDescriptor)declarationDescriptor).getClassObjectDescriptor();
|
||||
if (classObjectDescriptor != null) {
|
||||
addResult(results, lookupSimpleNameReference(selector, getAppropriateScope(classObjectDescriptor, onlyClasses), onlyClasses, false));
|
||||
addResult(results, lookupSimpleNameReference(selector, getAppropriateScope(classObjectDescriptor, lookupMode),
|
||||
lookupMode, false));
|
||||
}
|
||||
}
|
||||
}
|
||||
return filterAndStoreResolutionResult(results, selector, trace, scopeToCheckVisibility, onlyClasses, storeResult);
|
||||
return filterAndStoreResolutionResult(results, selector, trace, scopeToCheckVisibility, lookupMode, storeResult);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private JetScope getAppropriateScope(@NotNull ClassDescriptor classDescriptor, boolean onlyClasses) {
|
||||
return onlyClasses ? classDescriptor.getUnsubstitutedInnerClassesScope() : classDescriptor.getDefaultType().getMemberScope();
|
||||
private JetScope getAppropriateScope(@NotNull ClassDescriptor classDescriptor, @NotNull LookupMode lookupMode) {
|
||||
return lookupMode == LookupMode.ONLY_CLASSES ? classDescriptor.getUnsubstitutedInnerClassesScope() : classDescriptor.getDefaultType().getMemberScope();
|
||||
}
|
||||
|
||||
private void addResult(@NotNull Set<SuccessfulLookupResult> results, @NotNull LookupResult result) {
|
||||
@@ -216,17 +235,18 @@ public class QualifiedExpressionResolver {
|
||||
|
||||
@NotNull
|
||||
public Collection<? extends DeclarationDescriptor> lookupDescriptorsForSimpleNameReference(@NotNull JetSimpleNameExpression referenceExpression,
|
||||
@NotNull JetScope outerScope, @NotNull JetScope scopeToCheckVisibility, @NotNull BindingTrace trace, boolean onlyClasses, boolean namespaceLevel, boolean storeResult) {
|
||||
@NotNull JetScope outerScope, @NotNull JetScope scopeToCheckVisibility, @NotNull BindingTrace trace, @NotNull LookupMode lookupMode, boolean namespaceLevel, boolean storeResult) {
|
||||
|
||||
LookupResult lookupResult = lookupSimpleNameReference(referenceExpression, outerScope, onlyClasses, namespaceLevel);
|
||||
LookupResult lookupResult = lookupSimpleNameReference(referenceExpression, outerScope, lookupMode, namespaceLevel);
|
||||
if (lookupResult == LookupResult.EMPTY) return Collections.emptyList();
|
||||
return filterAndStoreResolutionResult(Collections.singletonList((SuccessfulLookupResult)lookupResult), referenceExpression, trace, scopeToCheckVisibility,
|
||||
onlyClasses, storeResult);
|
||||
lookupMode, storeResult);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private LookupResult lookupSimpleNameReference(@NotNull JetSimpleNameExpression referenceExpression,
|
||||
@NotNull JetScope outerScope, boolean onlyClasses, boolean namespaceLevel) {
|
||||
@NotNull JetScope outerScope, @NotNull LookupMode lookupMode, boolean namespaceLevel) {
|
||||
|
||||
Name referencedName = referenceExpression.getReferencedNameAsName();
|
||||
|
||||
Set<DeclarationDescriptor> descriptors = Sets.newHashSet();
|
||||
@@ -240,7 +260,7 @@ public class QualifiedExpressionResolver {
|
||||
descriptors.add(classifierDescriptor);
|
||||
}
|
||||
|
||||
if (onlyClasses) {
|
||||
if (lookupMode == LookupMode.ONLY_CLASSES) {
|
||||
ClassDescriptor objectDescriptor = outerScope.getObjectDescriptor(referencedName);
|
||||
if (objectDescriptor != null) {
|
||||
descriptors.add(objectDescriptor);
|
||||
@@ -261,7 +281,7 @@ public class QualifiedExpressionResolver {
|
||||
@NotNull
|
||||
private Collection<? extends DeclarationDescriptor> filterAndStoreResolutionResult(@NotNull Collection<SuccessfulLookupResult> lookupResults,
|
||||
@NotNull JetSimpleNameExpression referenceExpression, @NotNull final BindingTrace trace, @NotNull JetScope scopeToCheckVisibility,
|
||||
boolean onlyClasses, boolean storeResult) {
|
||||
@NotNull LookupMode lookupMode, boolean storeResult) {
|
||||
|
||||
if (lookupResults.isEmpty()) {
|
||||
return Collections.emptyList();
|
||||
@@ -284,7 +304,7 @@ public class QualifiedExpressionResolver {
|
||||
}
|
||||
|
||||
Collection<DeclarationDescriptor> filteredDescriptors;
|
||||
if (onlyClasses) {
|
||||
if (lookupMode == LookupMode.ONLY_CLASSES) {
|
||||
filteredDescriptors = Collections2.filter(descriptors, new Predicate<DeclarationDescriptor>() {
|
||||
@Override
|
||||
public boolean apply(@Nullable DeclarationDescriptor descriptor) {
|
||||
|
||||
@@ -0,0 +1,95 @@
|
||||
/*
|
||||
* Copyright 2010-2013 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.lazy;
|
||||
|
||||
import com.google.common.collect.*;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lang.psi.JetImportDirective;
|
||||
import org.jetbrains.jet.lang.psi.JetPsiUtil;
|
||||
import org.jetbrains.jet.lang.resolve.ImportPath;
|
||||
import org.jetbrains.jet.lang.resolve.name.Name;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
class ImportsProvider {
|
||||
private final List<JetImportDirective> importDirectives;
|
||||
|
||||
private ListMultimap<Name, JetImportDirective> nameToDirectives = null;
|
||||
private List<JetImportDirective> allUnderImports = null;
|
||||
private boolean indexed;
|
||||
|
||||
public ImportsProvider(List<JetImportDirective> importDirectives) {
|
||||
this.importDirectives = importDirectives;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public List<JetImportDirective> getImports(@NotNull Name name) {
|
||||
createIndex();
|
||||
return nameToDirectives.containsKey(name) ? nameToDirectives.get(name) : allUnderImports;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public List<JetImportDirective> getAllImports() {
|
||||
return importDirectives;
|
||||
}
|
||||
|
||||
private void createIndex() {
|
||||
if (indexed) {
|
||||
return;
|
||||
}
|
||||
|
||||
ImmutableListMultimap.Builder<Name, JetImportDirective> namesToRelativeImportsBuilder = ImmutableListMultimap.builder();
|
||||
|
||||
Set<Name> processedAliases = Sets.newHashSet();
|
||||
List<JetImportDirective> processedAllUnderImports = Lists.newArrayList();
|
||||
|
||||
for (JetImportDirective anImport : importDirectives) {
|
||||
ImportPath path = JetPsiUtil.getImportPath(anImport);
|
||||
if (path == null) {
|
||||
// Could be some parse errors
|
||||
continue;
|
||||
}
|
||||
|
||||
if (path.isAllUnder()) {
|
||||
processedAllUnderImports.add(anImport);
|
||||
|
||||
// All-Under import is relevant to all names found so far
|
||||
for (Name aliasName : processedAliases) {
|
||||
namesToRelativeImportsBuilder.put(aliasName, anImport);
|
||||
}
|
||||
}
|
||||
else {
|
||||
Name aliasName = path.getImportedName();
|
||||
assert aliasName != null;
|
||||
|
||||
if (!processedAliases.contains(aliasName)) {
|
||||
processedAliases.add(aliasName);
|
||||
|
||||
// Add to relevant imports all all-under imports found by this moment
|
||||
namesToRelativeImportsBuilder.putAll(aliasName, processedAllUnderImports);
|
||||
}
|
||||
|
||||
namesToRelativeImportsBuilder.put(aliasName, anImport);
|
||||
}
|
||||
}
|
||||
|
||||
allUnderImports = ImmutableList.copyOf(processedAllUnderImports);
|
||||
nameToDirectives = namesToRelativeImportsBuilder.build();
|
||||
|
||||
indexed = true;
|
||||
}
|
||||
}
|
||||
@@ -135,7 +135,10 @@ public class LazyClassDescriptor extends ClassDescriptorBase implements LazyDesc
|
||||
scope.changeLockLevel(WritableScope.LockLevel.READING);
|
||||
|
||||
PsiElement scopeAnchor = declarationProvider.getOwnerInfo().getScopeAnchor();
|
||||
scopeForClassHeaderResolution = new ChainedScope(this, scope, getScopeProvider().getResolutionScopeForDeclaration(scopeAnchor));
|
||||
scopeForClassHeaderResolution = new ChainedScope(
|
||||
this,
|
||||
"ScopeForClassHeaderResolution: " + getName(),
|
||||
scope, getScopeProvider().getResolutionScopeForDeclaration(scopeAnchor));
|
||||
}
|
||||
return scopeForClassHeaderResolution;
|
||||
}
|
||||
@@ -147,7 +150,10 @@ public class LazyClassDescriptor extends ClassDescriptorBase implements LazyDesc
|
||||
scope.addLabeledDeclaration(this);
|
||||
scope.changeLockLevel(WritableScope.LockLevel.READING);
|
||||
|
||||
scopeForMemberDeclarationResolution = new ChainedScope(this, scope, getScopeForMemberLookup(), getScopeForClassHeaderResolution());
|
||||
scopeForMemberDeclarationResolution = new ChainedScope(
|
||||
this,
|
||||
"ScopeForMemberDeclarationResolution: " + getName(),
|
||||
scope, getScopeForMemberLookup(), getScopeForClassHeaderResolution());
|
||||
}
|
||||
return scopeForMemberDeclarationResolution;
|
||||
}
|
||||
@@ -167,7 +173,10 @@ public class LazyClassDescriptor extends ClassDescriptorBase implements LazyDesc
|
||||
|
||||
scope.changeLockLevel(WritableScope.LockLevel.READING);
|
||||
|
||||
scopeForPropertyInitializerResolution = new ChainedScope(this, scope, getScopeForMemberDeclarationResolution());
|
||||
scopeForPropertyInitializerResolution = new ChainedScope(
|
||||
this,
|
||||
"ScopeForPropertyInitializerResolution: " + getName(),
|
||||
scope, getScopeForMemberDeclarationResolution());
|
||||
}
|
||||
return scopeForPropertyInitializerResolution;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,268 @@
|
||||
/*
|
||||
* Copyright 2010-2013 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.lazy;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Maps;
|
||||
import com.google.common.collect.Sets;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.descriptors.*;
|
||||
import org.jetbrains.jet.lang.psi.JetFile;
|
||||
import org.jetbrains.jet.lang.psi.JetImportDirective;
|
||||
import org.jetbrains.jet.lang.resolve.BindingTrace;
|
||||
import org.jetbrains.jet.lang.resolve.Importer;
|
||||
import org.jetbrains.jet.lang.resolve.name.FqName;
|
||||
import org.jetbrains.jet.lang.resolve.name.LabelName;
|
||||
import org.jetbrains.jet.lang.resolve.name.Name;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.*;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import static org.jetbrains.jet.lang.resolve.QualifiedExpressionResolver.LookupMode;
|
||||
|
||||
public class LazyImportScope implements JetScope {
|
||||
private static class ImportResolveStatus {
|
||||
private final LookupMode lookupMode;
|
||||
private final JetScope scope;
|
||||
|
||||
ImportResolveStatus(LookupMode lookupMode, JetScope scope) {
|
||||
this.lookupMode = lookupMode;
|
||||
this.scope = scope;
|
||||
}
|
||||
}
|
||||
|
||||
private final ResolveSession resolveSession;
|
||||
private final NamespaceDescriptor packageDescriptor;
|
||||
private final ImportsProvider importsProvider;
|
||||
private final JetScope rootScope;
|
||||
private final BindingTrace traceForImportResolve;
|
||||
private final String debugName;
|
||||
|
||||
private final Map<JetImportDirective, ImportResolveStatus> importedScopes = Maps.newHashMap();
|
||||
private JetImportDirective directiveUnderResolve = null;
|
||||
|
||||
public LazyImportScope(
|
||||
@NotNull ResolveSession resolveSession,
|
||||
@NotNull NamespaceDescriptor packageDescriptor,
|
||||
@NotNull List<JetImportDirective> imports,
|
||||
@NotNull BindingTrace traceForImportResolve,
|
||||
@NotNull String debugName
|
||||
) {
|
||||
this.resolveSession = resolveSession;
|
||||
this.packageDescriptor = packageDescriptor;
|
||||
this.importsProvider = new ImportsProvider(imports);
|
||||
this.traceForImportResolve = traceForImportResolve;
|
||||
this.debugName = debugName;
|
||||
|
||||
NamespaceDescriptor rootPackageDescriptor = resolveSession.getPackageDescriptorByFqName(FqName.ROOT);
|
||||
if (rootPackageDescriptor == null) {
|
||||
throw new IllegalStateException("Root package not found");
|
||||
}
|
||||
rootScope = rootPackageDescriptor.getMemberScope();
|
||||
}
|
||||
|
||||
public static LazyImportScope createImportScopeForFile(
|
||||
@NotNull ResolveSession resolveSession,
|
||||
@NotNull NamespaceDescriptor packageDescriptor,
|
||||
@NotNull JetFile jetFile,
|
||||
@NotNull BindingTrace traceForImportResolve,
|
||||
@NotNull String debugName
|
||||
) {
|
||||
return new LazyImportScope(
|
||||
resolveSession,
|
||||
packageDescriptor,
|
||||
Lists.reverse(jetFile.getImportDirectives()),
|
||||
traceForImportResolve,
|
||||
debugName);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private <D extends DeclarationDescriptor> D selectFirstFromImports(
|
||||
Name name,
|
||||
LookupMode lookupMode,
|
||||
JetScopeSelectorUtil.ScopeByNameSelector<D> descriptorSelector
|
||||
) {
|
||||
for (JetImportDirective directive : importsProvider.getImports(name)) {
|
||||
if (directive == directiveUnderResolve) {
|
||||
// This is the recursion in imports analysis
|
||||
return null;
|
||||
}
|
||||
|
||||
D foundDescriptor = descriptorSelector.get(getImportScope(directive, lookupMode), name);
|
||||
if (foundDescriptor != null) {
|
||||
return foundDescriptor;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private <D extends DeclarationDescriptor> Collection<D> collectFromImports(
|
||||
Name name,
|
||||
LookupMode lookupMode,
|
||||
JetScopeSelectorUtil.ScopeByNameMultiSelector<D> descriptorsSelector
|
||||
) {
|
||||
Set<D> descriptors = Sets.newHashSet();
|
||||
for (JetImportDirective directive : importsProvider.getImports(name)) {
|
||||
if (directive == directiveUnderResolve) {
|
||||
// This is the recursion in imports analysis
|
||||
throw new IllegalStateException("Recursion while resolving many imports: " + directive.getText());
|
||||
}
|
||||
|
||||
descriptors.addAll(descriptorsSelector.get(getImportScope(directive, lookupMode), name));
|
||||
}
|
||||
|
||||
return descriptors;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private <D extends DeclarationDescriptor> Collection<D> collectFromImports(
|
||||
LookupMode lookupMode,
|
||||
JetScopeSelectorUtil.ScopeDescriptorSelector<D> descriptorsSelector
|
||||
) {
|
||||
Set<D> descriptors = Sets.newHashSet();
|
||||
for (JetImportDirective directive : importsProvider.getAllImports()) {
|
||||
if (directive == directiveUnderResolve) {
|
||||
// This is the recursion in imports analysis
|
||||
throw new IllegalStateException("Recursion while resolving many imports: " + directive.getText());
|
||||
}
|
||||
|
||||
descriptors.addAll(descriptorsSelector.get(getImportScope(directive, lookupMode)));
|
||||
}
|
||||
|
||||
return descriptors;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private JetScope getImportScope(JetImportDirective directive, LookupMode lookupMode) {
|
||||
ImportResolveStatus status = importedScopes.get(directive);
|
||||
if (status != null && (lookupMode == status.lookupMode || status.lookupMode == LookupMode.EVERYTHING)) {
|
||||
return status.scope;
|
||||
}
|
||||
|
||||
WritableScope directiveImportScope = new WritableScopeImpl(
|
||||
JetScope.EMPTY, packageDescriptor, RedeclarationHandler.DO_NOTHING,
|
||||
"Scope for import '" + directive.getText() + "' resolve in " + toString());
|
||||
directiveImportScope.changeLockLevel(WritableScope.LockLevel.BOTH);
|
||||
|
||||
Importer.StandardImporter importer = new Importer.StandardImporter(directiveImportScope);
|
||||
directiveUnderResolve = directive;
|
||||
|
||||
try {
|
||||
resolveSession.getInjector().getQualifiedExpressionResolver().processImportReference(
|
||||
directive,
|
||||
rootScope,
|
||||
packageDescriptor.getMemberScope(),
|
||||
importer,
|
||||
traceForImportResolve,
|
||||
resolveSession.getModuleConfiguration(),
|
||||
lookupMode);
|
||||
}
|
||||
finally {
|
||||
directiveUnderResolve = null;
|
||||
directiveImportScope.changeLockLevel(WritableScope.LockLevel.READING);
|
||||
importedScopes.put(directive, new ImportResolveStatus(lookupMode, directiveImportScope));
|
||||
}
|
||||
|
||||
return directiveImportScope;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public ClassifierDescriptor getClassifier(@NotNull Name name) {
|
||||
return selectFirstFromImports(name, LookupMode.ONLY_CLASSES, JetScopeSelectorUtil.CLASSIFIER_DESCRIPTOR_SCOPE_SELECTOR);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public ClassDescriptor getObjectDescriptor(@NotNull Name name) {
|
||||
return selectFirstFromImports(name, LookupMode.ONLY_CLASSES, JetScopeSelectorUtil.NAMED_OBJECT_SCOPE_SELECTOR);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Collection<ClassDescriptor> getObjectDescriptors() {
|
||||
return collectFromImports(LookupMode.ONLY_CLASSES, JetScopeSelectorUtil.OBJECTS_SCOPE_SELECTOR);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public NamespaceDescriptor getNamespace(@NotNull Name name) {
|
||||
return selectFirstFromImports(name, LookupMode.ONLY_CLASSES, JetScopeSelectorUtil.NAMESPACE_SCOPE_SELECTOR);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Collection<VariableDescriptor> getProperties(@NotNull Name name) {
|
||||
return collectFromImports(name, LookupMode.EVERYTHING, JetScopeSelectorUtil.NAMED_PROPERTIES_SCOPE_SELECTOR);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public VariableDescriptor getLocalVariable(@NotNull Name name) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Collection<FunctionDescriptor> getFunctions(@NotNull Name name) {
|
||||
return collectFromImports(name, LookupMode.EVERYTHING, JetScopeSelectorUtil.NAMED_FUNCTION_SCOPE_SELECTOR);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public DeclarationDescriptor getContainingDeclaration() {
|
||||
return packageDescriptor;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Collection<DeclarationDescriptor> getDeclarationsByLabel(@NotNull LabelName labelName) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public PropertyDescriptor getPropertyByFieldReference(@NotNull Name fieldName) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Collection<DeclarationDescriptor> getAllDescriptors() {
|
||||
return collectFromImports(LookupMode.EVERYTHING, JetScopeSelectorUtil.ALL_DESCRIPTORS_SCOPE_SELECTOR);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public List<ReceiverParameterDescriptor> getImplicitReceiversHierarchy() {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Collection<DeclarationDescriptor> getOwnDeclaredDescriptors() {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "LazyImportScope: " + debugName;
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -46,7 +46,7 @@ public class LazyPackageDescriptor extends AbstractNamespaceDescriptorImpl imple
|
||||
|
||||
this.lazyScope = new LazyPackageMemberScope(resolveSession, declarationProvider, this);
|
||||
|
||||
this.memberScope = new ChainedScope(this, lazyScope, scope);
|
||||
this.memberScope = new ChainedScope(this, "Lazy package members scope: " + name, lazyScope, scope);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
+1
-2
@@ -68,8 +68,7 @@ public class LazyPackageMemberScope extends AbstractLazyMemberScope<NamespaceDes
|
||||
@NotNull
|
||||
@Override
|
||||
protected JetScope getScopeForMemberDeclarationResolution(JetDeclaration declaration) {
|
||||
return resolveSession.getInjector().getScopeProvider()
|
||||
.getFileScopeWithImportedClasses((JetFile) declaration.getContainingFile());
|
||||
return resolveSession.getInjector().getScopeProvider().getFileScope((JetFile) declaration.getContainingFile());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -128,6 +128,10 @@ public class ResolveSession {
|
||||
return specialClasses.apply(fqName);
|
||||
}
|
||||
|
||||
public ModuleDescriptor getRootModuleDescriptor() {
|
||||
return module;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
/*package*/ StorageManager getStorageManager() {
|
||||
return storageManager;
|
||||
|
||||
@@ -240,7 +240,7 @@ public class ResolveSessionUtils {
|
||||
ScopeProvider provider = resolveSession.getInjector().getScopeProvider();
|
||||
JetDeclaration parentDeclaration = PsiTreeUtil.getParentOfType(expression, JetDeclaration.class);
|
||||
if (parentDeclaration == null) {
|
||||
return provider.getFileScopeWithAllImported((JetFile) expression.getContainingFile());
|
||||
return provider.getFileScope((JetFile) expression.getContainingFile());
|
||||
}
|
||||
return provider.getResolutionScopeForDeclaration(parentDeclaration);
|
||||
}
|
||||
@@ -285,11 +285,13 @@ public class ResolveSessionUtils {
|
||||
|
||||
if (element instanceof JetDotQualifiedExpression) {
|
||||
descriptors = qualifiedExpressionResolver.lookupDescriptorsForQualifiedExpression(
|
||||
(JetDotQualifiedExpression) element, rootPackage.getMemberScope(), scope, trace, false, false);
|
||||
(JetDotQualifiedExpression) element, rootPackage.getMemberScope(), scope, trace,
|
||||
QualifiedExpressionResolver.LookupMode.EVERYTHING, false);
|
||||
}
|
||||
else {
|
||||
descriptors = qualifiedExpressionResolver.lookupDescriptorsForSimpleNameReference(
|
||||
(JetSimpleNameExpression) element, rootPackage.getMemberScope(), scope, trace, false, false, false);
|
||||
(JetSimpleNameExpression) element, rootPackage.getMemberScope(), scope, trace,
|
||||
QualifiedExpressionResolver.LookupMode.EVERYTHING, false, false);
|
||||
}
|
||||
|
||||
for (DeclarationDescriptor descriptor : descriptors) {
|
||||
|
||||
@@ -17,79 +17,95 @@
|
||||
package org.jetbrains.jet.lang.resolve.lazy;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.intellij.openapi.util.NotNullLazyValue;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lang.descriptors.NamespaceDescriptor;
|
||||
import org.jetbrains.jet.lang.psi.*;
|
||||
import org.jetbrains.jet.lang.resolve.ImportsResolver;
|
||||
import org.jetbrains.jet.lang.resolve.ImportPath;
|
||||
import org.jetbrains.jet.lang.resolve.TemporaryBindingTrace;
|
||||
import org.jetbrains.jet.lang.resolve.name.FqName;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.*;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.ChainedScope;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.InnerClassesScopeWrapper;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.JetScope;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.WeakHashMap;
|
||||
|
||||
public class ScopeProvider {
|
||||
|
||||
private final ResolveSession resolveSession;
|
||||
|
||||
private final Map<JetFile, JetScope> fileScopes = new WeakHashMap<JetFile, JetScope>();
|
||||
|
||||
private final NotNullLazyValue<JetScope> defaultImportsScope = new NotNullLazyValue<JetScope>() {
|
||||
@NotNull
|
||||
@Override
|
||||
protected JetScope compute() {
|
||||
return createScopeWithDefaultImports();
|
||||
}
|
||||
};
|
||||
|
||||
public ScopeProvider(@NotNull ResolveSession resolveSession) {
|
||||
this.resolveSession = resolveSession;
|
||||
}
|
||||
|
||||
private final Map<JetFile, JetScope> fileScopeWithImportedClassesCache = new WeakHashMap<JetFile, JetScope>();
|
||||
private final Map<JetFile, JetScope> fileScopeWithAllImportedCache = new WeakHashMap<JetFile, JetScope>();
|
||||
|
||||
@NotNull
|
||||
public JetScope getFileScopeWithImportedClasses(JetFile file) {
|
||||
JetScope scope = fileScopeWithImportedClassesCache.get(file);
|
||||
public JetScope getFileScope(JetFile file) {
|
||||
JetScope scope = fileScopes.get(file);
|
||||
if (scope == null) {
|
||||
scope = createFileScopeWithImportedClasses(file);
|
||||
fileScopeWithImportedClassesCache.put(file, scope);
|
||||
scope = createFileScope(file);
|
||||
fileScopes.put(file, scope);
|
||||
}
|
||||
return scope;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public JetScope getFileScopeWithAllImported(JetFile file) {
|
||||
JetScope scope = fileScopeWithAllImportedCache.get(file);
|
||||
if (scope == null) {
|
||||
scope = createFileScopeWithAllImported(file);
|
||||
fileScopeWithAllImportedCache.put(file, scope);
|
||||
}
|
||||
return scope;
|
||||
}
|
||||
|
||||
private JetScope createFileScopeWithImportedClasses(JetFile file) {
|
||||
NamespaceDescriptor packageDescriptor = getFilePackageDescriptor(file);
|
||||
|
||||
WritableScope fileScope = new WritableScopeImpl(
|
||||
JetScope.EMPTY, packageDescriptor, RedeclarationHandler.DO_NOTHING, "File scope for declaration resolution with only classes imported");
|
||||
|
||||
fileScope.changeLockLevel(WritableScope.LockLevel.BOTH);
|
||||
|
||||
private JetScope createFileScope(JetFile file) {
|
||||
NamespaceDescriptor rootPackageDescriptor = resolveSession.getPackageDescriptorByFqName(FqName.ROOT);
|
||||
if (rootPackageDescriptor == null) {
|
||||
throw new IllegalStateException("Root package not found");
|
||||
}
|
||||
|
||||
// Don't import twice
|
||||
if (!packageDescriptor.getQualifiedName().equals(FqName.ROOT)) {
|
||||
fileScope.importScope(rootPackageDescriptor.getMemberScope());
|
||||
}
|
||||
NamespaceDescriptor packageDescriptor = getFilePackageDescriptor(file);
|
||||
|
||||
ImportsResolver.processImportsInFile(true, fileScope, Lists.newArrayList(file.getImportDirectives()),
|
||||
rootPackageDescriptor.getMemberScope(),
|
||||
resolveSession.getModuleConfiguration(), resolveSession.getTrace(),
|
||||
resolveSession.getInjector().getQualifiedExpressionResolver());
|
||||
JetScope importsScope = LazyImportScope.createImportScopeForFile(
|
||||
resolveSession,
|
||||
packageDescriptor,
|
||||
file,
|
||||
resolveSession.getTrace(),
|
||||
"Lazy Imports Scope for file " + file.getName());
|
||||
|
||||
fileScope.changeLockLevel(WritableScope.LockLevel.READING);
|
||||
|
||||
return new ChainedScope(packageDescriptor, packageDescriptor.getMemberScope(), fileScope);
|
||||
return new ChainedScope(packageDescriptor,
|
||||
"File scope: " + file.getName(),
|
||||
rootPackageDescriptor.getMemberScope(),
|
||||
packageDescriptor.getMemberScope(),
|
||||
importsScope,
|
||||
defaultImportsScope.getValue());
|
||||
}
|
||||
|
||||
private JetScope createScopeWithDefaultImports() {
|
||||
NamespaceDescriptor rootPackageDescriptor = resolveSession.getPackageDescriptorByFqName(FqName.ROOT);
|
||||
if (rootPackageDescriptor == null) {
|
||||
throw new IllegalStateException("Root package not found");
|
||||
}
|
||||
|
||||
JetImportsFactory importsFactory = resolveSession.getInjector().getJetImportsFactory();
|
||||
List<ImportPath> defaultImports = resolveSession.getModuleConfiguration().getDefaultImports();
|
||||
|
||||
Collection<JetImportDirective> defaultImportDirectives = importsFactory.createImportDirectives(defaultImports);
|
||||
|
||||
return new LazyImportScope(
|
||||
resolveSession,
|
||||
rootPackageDescriptor,
|
||||
Lists.reverse(Lists.newArrayList(defaultImportDirectives)),
|
||||
TemporaryBindingTrace.create(resolveSession.getTrace(), "Transient trace for default imports lazy resolve"),
|
||||
"Lazy default imports scope");
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private NamespaceDescriptor getFilePackageDescriptor(JetFile file) {
|
||||
// package
|
||||
JetNamespaceHeader header = file.getNamespaceHeader();
|
||||
if (header == null) {
|
||||
throw new IllegalArgumentException("Scripts are not supported: " + file.getName());
|
||||
@@ -101,33 +117,10 @@ public class ScopeProvider {
|
||||
if (packageDescriptor == null) {
|
||||
throw new IllegalStateException("Package not found: " + fqName + " maybe the file is not in scope of this resolve session: " + file.getName());
|
||||
}
|
||||
|
||||
return packageDescriptor;
|
||||
}
|
||||
|
||||
private JetScope createFileScopeWithAllImported(JetFile file) {
|
||||
JetScope scopeWithImportedClasses = getFileScopeWithImportedClasses(file);
|
||||
NamespaceDescriptor packageDescriptor = getFilePackageDescriptor(file);
|
||||
|
||||
NamespaceDescriptor rootPackageDescriptor = resolveSession.getPackageDescriptorByFqName(FqName.ROOT);
|
||||
if (rootPackageDescriptor == null) {
|
||||
throw new IllegalStateException("Root package not found");
|
||||
}
|
||||
|
||||
WritableScope fileMemberScope = new WritableScopeImpl(
|
||||
JetScope.EMPTY, packageDescriptor, RedeclarationHandler.DO_NOTHING, "File scope for members declaration resolution with non-class imports");
|
||||
|
||||
fileMemberScope.changeLockLevel(WritableScope.LockLevel.BOTH);
|
||||
|
||||
ImportsResolver.processImportsInFile(false, fileMemberScope, Lists.newArrayList(file.getImportDirectives()),
|
||||
rootPackageDescriptor.getMemberScope(),
|
||||
resolveSession.getModuleConfiguration(), resolveSession.getTrace(),
|
||||
resolveSession.getInjector().getQualifiedExpressionResolver());
|
||||
|
||||
fileMemberScope.changeLockLevel(WritableScope.LockLevel.READING);
|
||||
|
||||
return new ChainedScope(packageDescriptor, scopeWithImportedClasses, fileMemberScope);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public JetScope getResolutionScopeForDeclaration(@NotNull PsiElement elementOfDeclaration) {
|
||||
JetDeclaration jetDeclaration = PsiTreeUtil.getParentOfType(elementOfDeclaration, JetDeclaration.class, false);
|
||||
@@ -137,7 +130,7 @@ public class ScopeProvider {
|
||||
|
||||
JetDeclaration parentDeclaration = PsiTreeUtil.getParentOfType(jetDeclaration, JetDeclaration.class);
|
||||
if (parentDeclaration == null) {
|
||||
return getFileScopeWithAllImported((JetFile) elementOfDeclaration.getContainingFile());
|
||||
return getFileScope((JetFile) elementOfDeclaration.getContainingFile());
|
||||
}
|
||||
|
||||
assert jetDeclaration != null : "Can't happen because of getParentOfType(null, ?) == null";
|
||||
|
||||
+1
-2
@@ -14,13 +14,12 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.jet.lang.resolve;
|
||||
package org.jetbrains.jet.lang.resolve.scopes;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lang.descriptors.*;
|
||||
import org.jetbrains.jet.lang.resolve.name.LabelName;
|
||||
import org.jetbrains.jet.lang.resolve.name.Name;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.JetScope;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
@@ -30,13 +30,20 @@ import java.util.Set;
|
||||
|
||||
public class ChainedScope implements JetScope {
|
||||
private final DeclarationDescriptor containingDeclaration;
|
||||
private final String debugName;
|
||||
private final JetScope[] scopeChain;
|
||||
private Collection<DeclarationDescriptor> allDescriptors;
|
||||
private List<ReceiverParameterDescriptor> implicitReceiverHierarchy;
|
||||
|
||||
public ChainedScope(DeclarationDescriptor containingDeclaration, JetScope... scopes) {
|
||||
this(containingDeclaration, "Untitled chained scope", scopes);
|
||||
}
|
||||
|
||||
public ChainedScope(DeclarationDescriptor containingDeclaration, String debugName, JetScope... scopes) {
|
||||
this.containingDeclaration = containingDeclaration;
|
||||
scopeChain = scopes.clone();
|
||||
|
||||
this.debugName = debugName;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -133,7 +140,7 @@ public class ChainedScope implements JetScope {
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Collection<DeclarationDescriptor> getDeclarationsByLabel(LabelName labelName) {
|
||||
public Collection<DeclarationDescriptor> getDeclarationsByLabel(@NotNull LabelName labelName) {
|
||||
for (JetScope jetScope : scopeChain) {
|
||||
Collection<DeclarationDescriptor> declarationsByLabel = jetScope.getDeclarationsByLabel(labelName);
|
||||
if (!declarationsByLabel.isEmpty()) return declarationsByLabel; // TODO : merge?
|
||||
@@ -169,4 +176,9 @@ public class ChainedScope implements JetScope {
|
||||
public Collection<DeclarationDescriptor> getOwnDeclaredDescriptors() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return debugName;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,22 +25,27 @@ import org.jetbrains.jet.lang.resolve.name.LabelName;
|
||||
import org.jetbrains.jet.lang.resolve.name.Name;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
public class FilteringScope extends JetScopeAdapter {
|
||||
private final Predicate<DeclarationDescriptor> predicate;
|
||||
public class FilteringScope implements JetScope {
|
||||
@NotNull private final JetScope workerScope;
|
||||
@NotNull private final Predicate<DeclarationDescriptor> predicate;
|
||||
|
||||
public FilteringScope(
|
||||
@NotNull JetScope workerScope,
|
||||
@NotNull Predicate<DeclarationDescriptor> predicate
|
||||
) {
|
||||
super(workerScope);
|
||||
public FilteringScope(@NotNull JetScope workerScope, @NotNull Predicate<DeclarationDescriptor> predicate) {
|
||||
this.workerScope = workerScope;
|
||||
this.predicate = predicate;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Collection<FunctionDescriptor> getFunctions(@NotNull Name name) {
|
||||
return Collections2.filter(super.getFunctions(name), predicate);
|
||||
return Collections2.filter(workerScope.getFunctions(name), predicate);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public DeclarationDescriptor getContainingDeclaration() {
|
||||
return workerScope.getContainingDeclaration();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@@ -50,56 +55,62 @@ public class FilteringScope extends JetScopeAdapter {
|
||||
|
||||
@Override
|
||||
public NamespaceDescriptor getNamespace(@NotNull Name name) {
|
||||
return filterDescriptor(super.getNamespace(name));
|
||||
return filterDescriptor(workerScope.getNamespace(name));
|
||||
}
|
||||
|
||||
@Override
|
||||
public ClassifierDescriptor getClassifier(@NotNull Name name) {
|
||||
return filterDescriptor(super.getClassifier(name));
|
||||
return filterDescriptor(workerScope.getClassifier(name));
|
||||
}
|
||||
|
||||
@Override
|
||||
public ClassDescriptor getObjectDescriptor(@NotNull Name name) {
|
||||
return filterDescriptor(super.getObjectDescriptor(name));
|
||||
return filterDescriptor(workerScope.getObjectDescriptor(name));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Collection<ClassDescriptor> getObjectDescriptors() {
|
||||
return Collections2.filter(super.getObjectDescriptors(), predicate);
|
||||
return Collections2.filter(workerScope.getObjectDescriptors(), predicate);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Collection<VariableDescriptor> getProperties(@NotNull Name name) {
|
||||
return Collections2.filter(super.getProperties(name), predicate);
|
||||
return Collections2.filter(workerScope.getProperties(name), predicate);
|
||||
}
|
||||
|
||||
@Override
|
||||
public VariableDescriptor getLocalVariable(@NotNull Name name) {
|
||||
return filterDescriptor(super.getLocalVariable(name));
|
||||
return filterDescriptor(workerScope.getLocalVariable(name));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Collection<DeclarationDescriptor> getAllDescriptors() {
|
||||
return Collections2.filter(super.getAllDescriptors(), predicate);
|
||||
return Collections2.filter(workerScope.getAllDescriptors(), predicate);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Collection<DeclarationDescriptor> getDeclarationsByLabel(LabelName labelName) {
|
||||
return Collections2.filter(super.getDeclarationsByLabel(labelName), predicate);
|
||||
public List<ReceiverParameterDescriptor> getImplicitReceiversHierarchy() {
|
||||
return workerScope.getImplicitReceiversHierarchy();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Collection<DeclarationDescriptor> getDeclarationsByLabel(@NotNull LabelName labelName) {
|
||||
return Collections2.filter(workerScope.getDeclarationsByLabel(labelName), predicate);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PropertyDescriptor getPropertyByFieldReference(@NotNull Name fieldName) {
|
||||
return filterDescriptor(super.getPropertyByFieldReference(fieldName));
|
||||
return filterDescriptor(workerScope.getPropertyByFieldReference(fieldName));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Collection<DeclarationDescriptor> getOwnDeclaredDescriptors() {
|
||||
return Collections2.filter(super.getOwnDeclaredDescriptors(), predicate);
|
||||
return Collections2.filter(workerScope.getOwnDeclaredDescriptors(), predicate);
|
||||
}
|
||||
}
|
||||
|
||||
+4
-5
@@ -24,7 +24,6 @@ import org.jetbrains.jet.lang.descriptors.ClassDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.ClassifierDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.ReceiverParameterDescriptor;
|
||||
import org.jetbrains.jet.lang.resolve.AbstractScopeAdapter;
|
||||
import org.jetbrains.jet.lang.resolve.name.LabelName;
|
||||
import org.jetbrains.jet.lang.resolve.name.Name;
|
||||
|
||||
@@ -45,10 +44,6 @@ public class InnerClassesScopeWrapper extends AbstractScopeAdapter {
|
||||
return actualScope;
|
||||
}
|
||||
|
||||
private boolean isClass(DeclarationDescriptor descriptor) {
|
||||
return descriptor instanceof ClassDescriptor && !((ClassDescriptor) descriptor).getKind().isObject();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ClassifierDescriptor getClassifier(@NotNull Name name) {
|
||||
ClassifierDescriptor classifier = actualScope.getClassifier(name);
|
||||
@@ -90,4 +85,8 @@ public class InnerClassesScopeWrapper extends AbstractScopeAdapter {
|
||||
public String toString() {
|
||||
return "Classes from " + actualScope;
|
||||
}
|
||||
|
||||
private static boolean isClass(DeclarationDescriptor descriptor) {
|
||||
return descriptor instanceof ClassDescriptor && !((ClassDescriptor) descriptor).getKind().isObject();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,7 +17,6 @@
|
||||
package org.jetbrains.jet.lang.resolve.scopes;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lang.resolve.AbstractScopeAdapter;
|
||||
|
||||
public class JetScopeAdapter extends AbstractScopeAdapter {
|
||||
@NotNull
|
||||
|
||||
+131
@@ -0,0 +1,131 @@
|
||||
/*
|
||||
* Copyright 2010-2013 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.scopes;
|
||||
|
||||
import com.google.common.collect.Sets;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.descriptors.*;
|
||||
import org.jetbrains.jet.lang.resolve.name.Name;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Set;
|
||||
|
||||
public class JetScopeSelectorUtil {
|
||||
private JetScopeSelectorUtil() {
|
||||
}
|
||||
|
||||
public interface ScopeByNameSelector<D extends DeclarationDescriptor> {
|
||||
@Nullable
|
||||
D get(@NotNull JetScope scope, @NotNull Name name);
|
||||
}
|
||||
|
||||
public interface ScopeByNameMultiSelector<D extends DeclarationDescriptor> {
|
||||
@NotNull
|
||||
Collection<D> get(JetScope scope, Name name);
|
||||
}
|
||||
|
||||
public interface ScopeDescriptorSelector<D extends DeclarationDescriptor> {
|
||||
@NotNull
|
||||
Collection<D> get(JetScope scope);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static <D extends DeclarationDescriptor> Collection<D> collect(Collection<JetScope> scopes, ScopeByNameMultiSelector<D> selector, Name name) {
|
||||
Set<D> descriptors = Sets.newHashSet();
|
||||
|
||||
for (JetScope scope : scopes) {
|
||||
descriptors.addAll(selector.get(scope, name));
|
||||
}
|
||||
|
||||
return descriptors;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static <D extends DeclarationDescriptor> Collection<D> collect(Collection<JetScope> scopes, ScopeDescriptorSelector<D> selector) {
|
||||
Set<D> descriptors = Sets.newHashSet();
|
||||
|
||||
for (JetScope scope : scopes) {
|
||||
descriptors.addAll(selector.get(scope));
|
||||
}
|
||||
|
||||
return descriptors;
|
||||
}
|
||||
|
||||
public static final ScopeByNameSelector<ClassifierDescriptor> CLASSIFIER_DESCRIPTOR_SCOPE_SELECTOR =
|
||||
new ScopeByNameSelector<ClassifierDescriptor>() {
|
||||
@Nullable
|
||||
@Override
|
||||
public ClassifierDescriptor get(@NotNull JetScope scope, @NotNull Name name) {
|
||||
return scope.getClassifier(name);
|
||||
}
|
||||
};
|
||||
|
||||
public static final ScopeByNameSelector<ClassDescriptor> NAMED_OBJECT_SCOPE_SELECTOR =
|
||||
new ScopeByNameSelector<ClassDescriptor>() {
|
||||
@Nullable
|
||||
@Override
|
||||
public ClassDescriptor get(@NotNull JetScope scope, @NotNull Name name) {
|
||||
return scope.getObjectDescriptor(name);
|
||||
}
|
||||
};
|
||||
|
||||
public static final ScopeByNameSelector<NamespaceDescriptor> NAMESPACE_SCOPE_SELECTOR =
|
||||
new ScopeByNameSelector<NamespaceDescriptor>() {
|
||||
@Nullable
|
||||
@Override
|
||||
public NamespaceDescriptor get(@NotNull JetScope scope, @NotNull Name name) {
|
||||
return scope.getNamespace(name);
|
||||
}
|
||||
};
|
||||
|
||||
public static final ScopeByNameMultiSelector<FunctionDescriptor> NAMED_FUNCTION_SCOPE_SELECTOR =
|
||||
new ScopeByNameMultiSelector<FunctionDescriptor>() {
|
||||
@NotNull
|
||||
@Override
|
||||
public Collection<FunctionDescriptor> get(@NotNull JetScope scope, @NotNull Name name) {
|
||||
return scope.getFunctions(name);
|
||||
}
|
||||
};
|
||||
|
||||
public static final ScopeByNameMultiSelector<VariableDescriptor> NAMED_PROPERTIES_SCOPE_SELECTOR =
|
||||
new ScopeByNameMultiSelector<VariableDescriptor>() {
|
||||
@NotNull
|
||||
@Override
|
||||
public Collection<VariableDescriptor> get(@NotNull JetScope scope, @NotNull Name name) {
|
||||
return scope.getProperties(name);
|
||||
}
|
||||
};
|
||||
|
||||
public static final ScopeDescriptorSelector<ClassDescriptor> OBJECTS_SCOPE_SELECTOR =
|
||||
new ScopeDescriptorSelector<ClassDescriptor>() {
|
||||
@NotNull
|
||||
@Override
|
||||
public Collection<ClassDescriptor> get(@NotNull JetScope scope) {
|
||||
return scope.getObjectDescriptors();
|
||||
}
|
||||
};
|
||||
|
||||
public static final ScopeDescriptorSelector<DeclarationDescriptor> ALL_DESCRIPTORS_SCOPE_SELECTOR =
|
||||
new ScopeDescriptorSelector<DeclarationDescriptor>() {
|
||||
@NotNull
|
||||
@Override
|
||||
public Collection<DeclarationDescriptor> get(@NotNull JetScope scope) {
|
||||
return scope.getAllDescriptors();
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -17,7 +17,6 @@
|
||||
package org.jetbrains.jet.lang.resolve.scopes;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lang.resolve.AbstractScopeAdapter;
|
||||
import org.jetbrains.jet.util.lazy.RecursionIntolerantLazyValue;
|
||||
|
||||
public class LazyScopeAdapter extends AbstractScopeAdapter {
|
||||
|
||||
@@ -53,10 +53,13 @@ public class SubstitutingScope implements JetScope {
|
||||
}
|
||||
|
||||
DeclarationDescriptor substituted = substitutedDescriptors.get(descriptor);
|
||||
if (substituted == null) {
|
||||
if (substituted == null && !substitutedDescriptors.containsKey(descriptor)) {
|
||||
substituted = descriptor.substitute(substitutor);
|
||||
|
||||
//noinspection ConstantConditions
|
||||
substitutedDescriptors.put(descriptor, substituted);
|
||||
}
|
||||
|
||||
//noinspection unchecked
|
||||
return (D) substituted;
|
||||
}
|
||||
@@ -129,7 +132,7 @@ public class SubstitutingScope implements JetScope {
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Collection<DeclarationDescriptor> getDeclarationsByLabel(LabelName labelName) {
|
||||
public Collection<DeclarationDescriptor> getDeclarationsByLabel(@NotNull LabelName labelName) {
|
||||
throw new UnsupportedOperationException(); // TODO
|
||||
}
|
||||
|
||||
@@ -142,14 +145,7 @@ public class SubstitutingScope implements JetScope {
|
||||
@Override
|
||||
public Collection<DeclarationDescriptor> getAllDescriptors() {
|
||||
if (allDescriptors == null) {
|
||||
allDescriptors = Sets.newHashSet();
|
||||
for (DeclarationDescriptor descriptor : workerScope.getAllDescriptors()) {
|
||||
DeclarationDescriptor substitute = substitute(descriptor);
|
||||
// assert substitute != null : descriptor;
|
||||
if (substitute != null) {
|
||||
allDescriptors.add(substitute);
|
||||
}
|
||||
}
|
||||
allDescriptors = substitute(workerScope.getAllDescriptors());
|
||||
}
|
||||
return allDescriptors;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2010-2013 JetBrains s.r.o.
|
||||
* Copyright 2010-2012 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.
|
||||
@@ -228,7 +228,7 @@ public class KotlinBuiltIns {
|
||||
project,
|
||||
storageManager,
|
||||
builtInsModule,
|
||||
new SpecialModuleConfiguration(project),
|
||||
new SpecialModuleConfiguration(),
|
||||
new FileBasedDeclarationProviderFactory(storageManager, files),
|
||||
new Function<FqName, Name>() {
|
||||
@Override
|
||||
@@ -263,17 +263,12 @@ public class KotlinBuiltIns {
|
||||
|
||||
private static class SpecialModuleConfiguration implements ModuleConfiguration {
|
||||
|
||||
private final Project project;
|
||||
|
||||
private SpecialModuleConfiguration(@NotNull Project project) {
|
||||
this.project = project;
|
||||
private SpecialModuleConfiguration() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addDefaultImports(@NotNull Collection<JetImportDirective> directives) {
|
||||
for (ImportPath defaultJetImport : DefaultModuleConfiguration.DEFAULT_JET_IMPORTS) {
|
||||
directives.add(JetPsiFactory.createImportDirective(project, defaultJetImport));
|
||||
}
|
||||
public List<ImportPath> getDefaultImports() {
|
||||
return DefaultModuleConfiguration.DEFAULT_JET_IMPORTS;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -124,6 +124,10 @@ public final class QualifiedNamesUtil {
|
||||
}
|
||||
|
||||
public static boolean isImported(@NotNull ImportPath alreadyImported, @NotNull FqName fqName) {
|
||||
if (alreadyImported.hasAlias()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (alreadyImported.isAllUnder() && !fqName.isRoot()) {
|
||||
return alreadyImported.fqnPart().equals(fqName.parent());
|
||||
}
|
||||
@@ -132,7 +136,7 @@ public final class QualifiedNamesUtil {
|
||||
}
|
||||
|
||||
public static boolean isImported(@NotNull ImportPath alreadyImported, @NotNull ImportPath newImport) {
|
||||
if (newImport.isAllUnder()) {
|
||||
if (newImport.isAllUnder() || newImport.hasAlias()) {
|
||||
return alreadyImported.equals(newImport);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
WARNING: $TESTDATA_DIR$/wrongAbiVersion.kt: (3, 9) Parameter 'x' is never used
|
||||
ERROR: $TESTDATA_DIR$/wrongAbiVersionLib/wrong/WrongPackage.java: (3, 1) Class 'wrong.WrongPackage' was compiled with an incompatible version of Kotlin. Its ABI version is -1, expected ABI version is 0
|
||||
ERROR: $TESTDATA_DIR$/wrongAbiVersionLib/ClassWithWrongAbiVersion.java: (3, 1) Class 'ClassWithWrongAbiVersion' was compiled with an incompatible version of Kotlin. Its ABI version is -1, expected ABI version is 0
|
||||
ERROR: $TESTDATA_DIR$/wrongAbiVersionLib/wrong/WrongPackage.java: (3, 1) Class 'wrong.WrongPackage' was compiled with an incompatible version of Kotlin. Its ABI version is -1, expected ABI version is 1
|
||||
ERROR: $TESTDATA_DIR$/wrongAbiVersionLib/ClassWithWrongAbiVersion.java: (3, 1) Class 'ClassWithWrongAbiVersion' was compiled with an incompatible version of Kotlin. Its ABI version is -1, expected ABI version is 1
|
||||
COMPILATION_ERROR
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
fun box(): String {
|
||||
var x = 0
|
||||
do x++ while (x < 5)
|
||||
if (x != 5) return "Fail 1 $x"
|
||||
|
||||
var y = 0
|
||||
do { y++ } while (y < 5)
|
||||
if (y != 5) return "Fail 2 $y"
|
||||
|
||||
var z = ""
|
||||
do { z += z.length } while (z.length < 5)
|
||||
if (z != "01234") return "Fail 3 $z"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fun box(): String {
|
||||
var fx = 1
|
||||
var fy = 1
|
||||
|
||||
do {
|
||||
var tmp = fy
|
||||
fy = fx + fy
|
||||
fx = tmp
|
||||
} while (fy < 100)
|
||||
|
||||
return if (fy == 144) "OK" else "Fail $fx $fy"
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
fun foo() {
|
||||
var x = 0
|
||||
do {
|
||||
x++
|
||||
var y = x + 5
|
||||
} while (y < 10)
|
||||
if (x != 5) throw AssertionError("$x")
|
||||
}
|
||||
|
||||
fun bar() {
|
||||
var b = false
|
||||
do {
|
||||
var x = "X"
|
||||
var y = "Y"
|
||||
b = true
|
||||
} while (x + y != "XY")
|
||||
if (!b) throw AssertionError()
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
foo()
|
||||
bar()
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
import A.<!SYNTAX!><!>;
|
||||
|
||||
class A
|
||||
@@ -0,0 +1,12 @@
|
||||
// FILE: checkAmbiguityBetweenRootAndPackage.kt
|
||||
package test
|
||||
|
||||
val t = <!OVERLOAD_RESOLUTION_AMBIGUITY!>testFun()<!>
|
||||
|
||||
// FILE: checkAmbiguityBetweenRootAndPackageRoot.kt
|
||||
fun testFun() = 12
|
||||
|
||||
// FILE: checkAmbiguityBetweenRootAndPackageTest.kt
|
||||
package test
|
||||
|
||||
fun testFun() = 12
|
||||
@@ -7,9 +7,13 @@ import <!UNRESOLVED_REFERENCE!>reflect<!>.<!DEBUG_INFO_MISSING_UNRESOLVED!>Const
|
||||
|
||||
import b.*
|
||||
import <!UNRESOLVED_REFERENCE!>d<!>
|
||||
import <!UNRESOLVED_REFERENCE!>d<!>.<!DEBUG_INFO_MISSING_UNRESOLVED!>Test<!>
|
||||
import b.d
|
||||
|
||||
class Some: <!UNRESOLVED_REFERENCE!>Test<!>()
|
||||
|
||||
//FILE:b.kt
|
||||
|
||||
package b.d
|
||||
package b.d
|
||||
|
||||
public open class Test
|
||||
@@ -0,0 +1,9 @@
|
||||
namespace <root>
|
||||
|
||||
// <namespace name="test">
|
||||
namespace test
|
||||
|
||||
internal final val t: [ERROR : Type for testFun()]
|
||||
internal final fun testFun(): jet.Int
|
||||
// </namespace name="test">
|
||||
internal final fun testFun(): jet.Int
|
||||
@@ -3,6 +3,9 @@ namespace <root>
|
||||
// <namespace name="kt1080">
|
||||
namespace kt1080
|
||||
|
||||
internal final class kt1080.Some : jet.Any {
|
||||
public final /*constructor*/ fun <init>(): kt1080.Some
|
||||
}
|
||||
// </namespace name="kt1080">
|
||||
// <namespace name="b">
|
||||
namespace b
|
||||
@@ -10,5 +13,8 @@ namespace b
|
||||
// <namespace name="d">
|
||||
namespace d
|
||||
|
||||
public open class b.d.Test : jet.Any {
|
||||
public final /*constructor*/ fun <init>(): b.d.Test
|
||||
}
|
||||
// </namespace name="d">
|
||||
// </namespace name="b">
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
// FILE: importFunctionWithAllUnderImport.kt
|
||||
package test
|
||||
|
||||
import testOther.*
|
||||
|
||||
class B: A()
|
||||
val inferTypeFromImportedFun = testFun()
|
||||
|
||||
// FILE: importFunctionWithAllUnderImportOther.kt
|
||||
package testOther
|
||||
|
||||
open class A
|
||||
fun testFun() = 1
|
||||
@@ -0,0 +1,7 @@
|
||||
package test
|
||||
|
||||
internal val inferTypeFromImportedFun : jet.Int
|
||||
|
||||
internal final class B : testOther.A {
|
||||
/*primary*/ public constructor B()
|
||||
}
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
//FILE:mainFile.kt
|
||||
//----------------------------------------------------------------------------------
|
||||
package test
|
||||
|
||||
import testing.other.*
|
||||
import testing.TestFun
|
||||
|
||||
// Resolve should be ambiguous
|
||||
val a = TestFun()
|
||||
|
||||
|
||||
//FILE:testing.kt
|
||||
//----------------------------------------------------------------------------------
|
||||
package testing
|
||||
|
||||
class TestFun
|
||||
|
||||
//FILE:testingOther.kt
|
||||
//----------------------------------------------------------------------------------
|
||||
package testing.other
|
||||
|
||||
fun TestFun() = 12
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
package test
|
||||
|
||||
internal val a : [ERROR : Type for TestFun()]
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
// FILE: propertyClassFileDependencyRecursion.kt
|
||||
package test
|
||||
|
||||
import other.prop
|
||||
|
||||
// Note: "prop" is expected to be unresolved and replaced to Any
|
||||
class PropType: prop
|
||||
|
||||
// Note: this time "prop" should be resolved and type should be inferred for "checkTypeProp"
|
||||
val checkTypeProp = prop
|
||||
|
||||
// FILE: propertyClassFileDependencyRecursionOther.kt
|
||||
package other
|
||||
|
||||
import test.PropType
|
||||
|
||||
val prop: PropType? = null
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
package test
|
||||
|
||||
internal val checkTypeProp : test.PropType?
|
||||
|
||||
internal final class PropType {
|
||||
/*primary*/ public constructor PropType()
|
||||
}
|
||||
@@ -5,8 +5,8 @@ import java.util.*;
|
||||
import jet.runtime.typeinfo.KotlinSignature;
|
||||
|
||||
public class MethodWithMappedClasses {
|
||||
@KotlinSignature("fun <T> copy(dest : MutableList<in T>, src : List<out T>)")
|
||||
public <T> void copy(List<? super T> dest, List<? extends T> src) {
|
||||
@KotlinSignature("fun <T> copy(dest : MutableList<in T>, src : List<T>)")
|
||||
public <T> void copy(List<? super T> dest, List<T> src) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,5 +3,5 @@ package test
|
||||
import java.util.*
|
||||
|
||||
public open class MethodWithMappedClasses : Object() {
|
||||
public open fun <T> copy(p0 : MutableList<in T>, p1 : List<out T>) {}
|
||||
public open fun <T> copy(p0 : MutableList<in T>, p1 : List<T>) {}
|
||||
}
|
||||
|
||||
@@ -2,5 +2,5 @@ package test
|
||||
|
||||
public open class MethodWithMappedClasses : java.lang.Object {
|
||||
public constructor MethodWithMappedClasses()
|
||||
public open fun </*0*/ T> copy(/*0*/ p0 : jet.MutableList<in T>, /*1*/ p1 : jet.List<out T>) : Unit
|
||||
public open fun </*0*/ T> copy(/*0*/ p0 : jet.MutableList<in T>, /*1*/ p1 : jet.List<T>) : Unit
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ import java.util.List;
|
||||
import jet.runtime.typeinfo.KotlinSignature;
|
||||
|
||||
public class MethodWithTypeParameters {
|
||||
@KotlinSignature("fun <A, B : Runnable> foo(a : A, b : List<out B>, c: MutableList<in String?>) where B : List<Cloneable>")
|
||||
@KotlinSignature("fun <A, B : Runnable> foo(a : A, b : List<B>, c: MutableList<in String?>) where B : List<Cloneable>")
|
||||
public <A, B extends Runnable & List<Cloneable>> void foo(A a, List<? extends B> b, List<? super String> list) {
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,6 @@ package test
|
||||
import java.util.*
|
||||
|
||||
public open class MethodWithTypeParameters : Object() {
|
||||
public open fun <erased A, erased B : Runnable> foo(p0 : A, p1 : List<out B>, p2: MutableList<in String?>) where B : List<Cloneable> {
|
||||
public open fun <erased A, erased B : Runnable> foo(p0 : A, p1 : List<B>, p2: MutableList<in String?>) where B : List<Cloneable> {
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,5 +2,5 @@ package test
|
||||
|
||||
public open class MethodWithTypeParameters : java.lang.Object {
|
||||
public constructor MethodWithTypeParameters()
|
||||
public open fun </*0*/ A, /*1*/ B> foo(/*0*/ p0 : A, /*1*/ p1 : jet.List<out B>, /*2*/ p2 : jet.MutableList<in jet.String?>) : Unit where B : java.lang.Runnable, B : jet.List<java.lang.Cloneable>
|
||||
public open fun </*0*/ A, /*1*/ B> foo(/*0*/ p0 : A, /*1*/ p1 : jet.List<B>, /*2*/ p2 : jet.MutableList<in jet.String?>) : Unit where B : java.lang.Runnable, B : jet.List<java.lang.Cloneable>
|
||||
}
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
package test;
|
||||
|
||||
import java.lang.Number;
|
||||
import java.util.*;
|
||||
|
||||
import jet.runtime.typeinfo.KotlinSignature;
|
||||
import org.jetbrains.jet.jvm.compiler.annotation.ExpectLoadError;
|
||||
|
||||
public class ConflictingProjectionKind {
|
||||
@ExpectLoadError("Projection kind 'in' is conflicting with variance of jet.List")
|
||||
@KotlinSignature("fun foo(list: List<in Number>)")
|
||||
public void foo(List<Number> list) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package test
|
||||
|
||||
public open class ConflictingProjectionKind : Object() {
|
||||
public open fun foo(p0: List<Number>?) {
|
||||
throw UnsupportedOperationException()
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
package test
|
||||
|
||||
public open class ConflictingProjectionKind : java.lang.Object {
|
||||
public constructor ConflictingProjectionKind()
|
||||
public open fun foo(/*0*/ p0 : jet.List<jet.Number>?) : Unit
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package test;
|
||||
|
||||
import java.lang.Number;
|
||||
import java.util.*;
|
||||
|
||||
import jet.runtime.typeinfo.KotlinSignature;
|
||||
import org.jetbrains.jet.jvm.compiler.annotation.ExpectLoadError;
|
||||
|
||||
public class RedundantProjectionKind {
|
||||
@KotlinSignature("fun foo(list: List<out Number>)")
|
||||
public void foo(List<Number> list) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package test
|
||||
|
||||
public open class RedundantProjectionKind : Object() {
|
||||
public open fun foo(p0: List<Number>) {
|
||||
throw UnsupportedOperationException()
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
package test
|
||||
|
||||
public open class RedundantProjectionKind : java.lang.Object {
|
||||
public constructor RedundantProjectionKind()
|
||||
public open fun foo(/*0*/ p0 : jet.List<jet.Number>) : Unit
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
package test
|
||||
|
||||
class A(vararg a: Int, f: () -> Unit) {}
|
||||
@@ -0,0 +1,5 @@
|
||||
package test
|
||||
|
||||
internal final class A {
|
||||
/*primary*/ public constructor A(/*0*/ vararg a : jet.Int /*jet.IntArray*/, /*1*/ f : () -> Unit)
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
package test
|
||||
|
||||
fun f(vararg t: Int, f: () -> Unit) {}
|
||||
|
||||
fun f(vararg t: String, f: () -> Unit) {}
|
||||
@@ -0,0 +1,4 @@
|
||||
package test
|
||||
|
||||
internal fun f(/*0*/ vararg t : jet.String /*jet.Array<jet.String>*/, /*1*/ f : () -> Unit) : Unit
|
||||
internal fun f(/*0*/ vararg t : jet.Int /*jet.IntArray*/, /*1*/ f : () -> Unit) : Unit
|
||||
@@ -0,0 +1,29 @@
|
||||
//FILE:mainToSecond.kt
|
||||
//----------------------------------------------------------------------------------
|
||||
package test
|
||||
|
||||
import testing.first.*
|
||||
import testing.second.*
|
||||
|
||||
val a1: `second`TestClass? = null
|
||||
|
||||
//FILE:mainToFirst.kt
|
||||
//----------------------------------------------------------------------------------
|
||||
package test
|
||||
|
||||
import testing.second.*
|
||||
import testing.first.*
|
||||
|
||||
val a2: `first`TestClass? = null
|
||||
|
||||
//FILE:importFirst.kt
|
||||
//----------------------------------------------------------------------------------
|
||||
package testing.first
|
||||
|
||||
class ~first~TestClass
|
||||
|
||||
//FILE:importSecond.kt
|
||||
//----------------------------------------------------------------------------------
|
||||
package testing.second
|
||||
|
||||
class ~second~TestClass
|
||||
@@ -0,0 +1,17 @@
|
||||
//FILE:mainFile.jet
|
||||
//----------------------------------------------------------------------------------
|
||||
package test
|
||||
|
||||
import testing.*
|
||||
|
||||
val a1: `fromRoot`TestClass? = null
|
||||
|
||||
//FILE:fromRoot.kt
|
||||
//----------------------------------------------------------------------------------
|
||||
trait ~fromRoot~TestClass
|
||||
|
||||
//FILE:fromOtherPackage.kt
|
||||
//----------------------------------------------------------------------------------
|
||||
package testing
|
||||
|
||||
trait ~fromOtherPackage~TestClass
|
||||
@@ -0,0 +1,20 @@
|
||||
//FILE:mainFile.jet
|
||||
//----------------------------------------------------------------------------------
|
||||
package test
|
||||
|
||||
import otherPackage.*
|
||||
|
||||
val a1: `fromSamePackage`TestClass? = null
|
||||
|
||||
//FILE:fromOtherPackage.kt
|
||||
//----------------------------------------------------------------------------------
|
||||
package otherPackage
|
||||
|
||||
trait ~fromOtherPackage~TestClass
|
||||
|
||||
|
||||
//FILE:fromSamePackage.kt
|
||||
//----------------------------------------------------------------------------------
|
||||
package test
|
||||
|
||||
class ~fromSamePackage~TestClass
|
||||
@@ -0,0 +1,29 @@
|
||||
//FILE:withAllUnderImportsSecond.kt
|
||||
//----------------------------------------------------------------------------------
|
||||
package test
|
||||
|
||||
import testing.first.*
|
||||
import testing.second.*
|
||||
|
||||
val a1 = ~second~testFun()
|
||||
|
||||
//FILE:withAllUnderImportsFirst.kt
|
||||
//----------------------------------------------------------------------------------
|
||||
package test
|
||||
|
||||
import testing.second.*
|
||||
import testing.first.*
|
||||
|
||||
val a1 = ~first~testFun()
|
||||
|
||||
//FILE:importFirst.kt
|
||||
//----------------------------------------------------------------------------------
|
||||
package testing.first
|
||||
|
||||
fun ~first~testFun(): Int = 12
|
||||
|
||||
//FILE:importSecond.kt
|
||||
//----------------------------------------------------------------------------------
|
||||
package testing.second
|
||||
|
||||
fun ~second~testFun(): Int = 12
|
||||
@@ -0,0 +1,34 @@
|
||||
//FILE:mainToSecond.kt
|
||||
//----------------------------------------------------------------------------------
|
||||
package test
|
||||
|
||||
import testing.first.*
|
||||
import testing.second.TestClass
|
||||
|
||||
val a1: `second`TestClass? = null
|
||||
|
||||
|
||||
//FILE:mainToFirst.kt
|
||||
//----------------------------------------------------------------------------------
|
||||
package test
|
||||
|
||||
import testing.second.TestClass
|
||||
import testing.first.*
|
||||
|
||||
// Single import has priority over package import
|
||||
val a2: `first`TestClass? = null
|
||||
|
||||
|
||||
//FILE:importFirst.kt
|
||||
//----------------------------------------------------------------------------------
|
||||
package testing.first
|
||||
|
||||
class ~first~TestClass
|
||||
|
||||
|
||||
//FILE:importSecond.kt
|
||||
//----------------------------------------------------------------------------------
|
||||
package testing.second
|
||||
class testing.second
|
||||
|
||||
class ~second~TestClass
|
||||
@@ -0,0 +1,31 @@
|
||||
//FILE:mainToSecond.kt
|
||||
//----------------------------------------------------------------------------------
|
||||
package test
|
||||
|
||||
import testing.first.TestClass
|
||||
import testing.second.TestClass
|
||||
|
||||
val a1: `second`TestClass? = null
|
||||
|
||||
//FILE:mainToFirst.kt
|
||||
//----------------------------------------------------------------------------------
|
||||
package test
|
||||
|
||||
import testing.second.TestClass
|
||||
import testing.first.TestClass
|
||||
|
||||
val a2: `first`TestClass? = null
|
||||
|
||||
//FILE:importFirst.kt
|
||||
//----------------------------------------------------------------------------------
|
||||
package testing.first
|
||||
|
||||
class ~first~TestClass
|
||||
|
||||
|
||||
//FILE:importSecond.kt
|
||||
//----------------------------------------------------------------------------------
|
||||
package testing.second
|
||||
class testing.second
|
||||
|
||||
class ~second~TestClass
|
||||
@@ -0,0 +1,21 @@
|
||||
//FILE:classObject.kt
|
||||
//----------------------------------------------------------------------------------
|
||||
package test
|
||||
|
||||
import testing.TestClass
|
||||
|
||||
class WithClassObject {
|
||||
class object {
|
||||
class ~class-object~TestClass
|
||||
}
|
||||
|
||||
// TODO: Isn't it a bug?
|
||||
val a2: `testing`TestClass? = null
|
||||
}
|
||||
|
||||
|
||||
//FILE:testing.kt
|
||||
//----------------------------------------------------------------------------------
|
||||
package testing
|
||||
|
||||
class ~testing~TestClass
|
||||
@@ -0,0 +1,16 @@
|
||||
//FILE:sameFile.kt
|
||||
//----------------------------------------------------------------------------------
|
||||
package test
|
||||
|
||||
import testing.TestClass
|
||||
|
||||
class ~same-file~TestClass
|
||||
|
||||
val a1: `same-file`TestClass? = null
|
||||
|
||||
|
||||
//FILE:testing.kt
|
||||
//----------------------------------------------------------------------------------
|
||||
package testing
|
||||
|
||||
class ~testing~TestClass
|
||||
@@ -0,0 +1,18 @@
|
||||
//FILE:insideClass.kt
|
||||
//----------------------------------------------------------------------------------
|
||||
package test
|
||||
|
||||
import testing.TestClass
|
||||
|
||||
class WithInnerClass {
|
||||
inner class ~inner-class~TestClass
|
||||
|
||||
val a3: `inner-class`TestClass? = null
|
||||
}
|
||||
|
||||
|
||||
//FILE:testing.kt
|
||||
//----------------------------------------------------------------------------------
|
||||
package testing
|
||||
|
||||
class ~testing~TestClass
|
||||
@@ -0,0 +1,54 @@
|
||||
//FILE:allPackageImport.kt
|
||||
//----------------------------------------------------------------------------------
|
||||
package test
|
||||
|
||||
import testing.custom.*
|
||||
|
||||
// Non default import has priority over default one. No conflicts are expected.
|
||||
val a1: `custom`List<Int>? = null
|
||||
|
||||
//FILE:javaUtilImport.kt
|
||||
//----------------------------------------------------------------------------------
|
||||
package test
|
||||
|
||||
import java.util.*
|
||||
|
||||
// Mapped declarations are dropped from on-demand imports.
|
||||
// TODO: Fix for lazy resolve test
|
||||
// val a2: 'kotlin::List'List<Int>? = null
|
||||
|
||||
//FILE:allPackageWithJavaUtilImport.kt
|
||||
//----------------------------------------------------------------------------------
|
||||
package test
|
||||
|
||||
import testing.custom.*
|
||||
import java.util.*
|
||||
|
||||
// Mapped declarations are dropped from on-demand "java.util" import. So no conflicts are expected.
|
||||
val a3: `custom`List<Int>? = null
|
||||
|
||||
//FILE:singleClassImportFromJavaUtil.kt
|
||||
//----------------------------------------------------------------------------------
|
||||
package test
|
||||
|
||||
import java.util.List
|
||||
|
||||
// Single import doesn't processed with Java->Kotlin class mapper. This is the way how
|
||||
// java classes can be imported.
|
||||
val a4: `java::java.util.List`List<Int>? = null
|
||||
|
||||
//FILE:singleClassImport.kt
|
||||
//----------------------------------------------------------------------------------
|
||||
package test
|
||||
|
||||
import testing.custom.List
|
||||
|
||||
// Single import doesn't processed with Java->Kotlin class mapper
|
||||
val a5: `custom`List<Int>? = null
|
||||
|
||||
|
||||
//FILE:importFirst.kt
|
||||
//----------------------------------------------------------------------------------
|
||||
package testing.custom
|
||||
|
||||
class ~custom~List<T>
|
||||
@@ -0,0 +1,18 @@
|
||||
//FILE:firstOrder.kt
|
||||
//----------------------------------------------------------------------------------
|
||||
package test
|
||||
|
||||
import testing.InTesting2
|
||||
import testing.InTesting1
|
||||
|
||||
trait ~InTest1~InTest1 : `InTesting1`InTesting1
|
||||
trait ~InTest2~InTest2 : `InTesting2`InTesting2
|
||||
|
||||
//FILE:testing.kt
|
||||
//----------------------------------------------------------------------------------
|
||||
package testing
|
||||
|
||||
import test.InTest2
|
||||
|
||||
trait ~InTesting1~InTesting1 : `InTest2`InTest2
|
||||
trait ~InTesting2~InTesting2
|
||||
@@ -0,0 +1,45 @@
|
||||
//FILE:firstOrder.kt
|
||||
//----------------------------------------------------------------------------------
|
||||
package test
|
||||
|
||||
import testing.other.*
|
||||
import testing.exact.Second
|
||||
import testing.allUnder.*
|
||||
|
||||
// The goal is to activate lazy resolve in order Second, Other
|
||||
class FirstOrder: `other`Other, FirstInternal
|
||||
trait FirstInternal: `allUnder`Second
|
||||
|
||||
|
||||
|
||||
//FILE:secondOrder.kt
|
||||
//----------------------------------------------------------------------------------
|
||||
package test
|
||||
|
||||
import testing.other.*
|
||||
import testing.exact.Second
|
||||
import testing.allUnder.*
|
||||
|
||||
// The goal is to activate lazy resolve in order Other, Second
|
||||
class FirstOrder: FirstInternal, `other`Other
|
||||
trait FirstInternal: `allUnder`Second
|
||||
|
||||
|
||||
|
||||
//FILE:secondForAllUnderImport.kt
|
||||
//----------------------------------------------------------------------------------
|
||||
package testing.allUnder
|
||||
|
||||
trait ~allUnder~Second
|
||||
|
||||
//FILE:secondForExactImport.kt
|
||||
//----------------------------------------------------------------------------------
|
||||
package testing.exact
|
||||
|
||||
trait ~exact~Second
|
||||
|
||||
//FILE:someOther.kt
|
||||
//----------------------------------------------------------------------------------
|
||||
package testing.other
|
||||
|
||||
trait ~other~Other
|
||||
@@ -3319,6 +3319,11 @@ public class JetDiagnosticsTestGenerated extends AbstractDiagnosticsTestWithEage
|
||||
doTest("compiler/testData/diagnostics/tests/regressions/ea40964.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("ea43298.kt")
|
||||
public void testEa43298() throws Exception {
|
||||
doTest("compiler/testData/diagnostics/tests/regressions/ea43298.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("ErrorsOnIbjectExpressionsAsParameters.kt")
|
||||
public void testErrorsOnIbjectExpressionsAsParameters() throws Exception {
|
||||
doTest("compiler/testData/diagnostics/tests/regressions/ErrorsOnIbjectExpressionsAsParameters.kt");
|
||||
@@ -3810,6 +3815,11 @@ public class JetDiagnosticsTestGenerated extends AbstractDiagnosticsTestWithEage
|
||||
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.GenerateTests", new File("compiler/testData/diagnostics/tests/scopes"), "kt", true);
|
||||
}
|
||||
|
||||
@TestMetadata("AmbiguityBetweenRootAndPackage.kt")
|
||||
public void testAmbiguityBetweenRootAndPackage() throws Exception {
|
||||
doTest("compiler/testData/diagnostics/tests/scopes/AmbiguityBetweenRootAndPackage.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("ImportFromCurrentWithDifferentName.kt")
|
||||
public void testImportFromCurrentWithDifferentName() throws Exception {
|
||||
doTest("compiler/testData/diagnostics/tests/scopes/ImportFromCurrentWithDifferentName.kt");
|
||||
|
||||
@@ -1012,6 +1012,16 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
|
||||
blackBoxFileByFullPath("compiler/testData/codegen/box/controlStructures/continueToLabelInFor.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("doWhile.kt")
|
||||
public void testDoWhile() throws Exception {
|
||||
blackBoxFileByFullPath("compiler/testData/codegen/box/controlStructures/doWhile.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("doWhileFib.kt")
|
||||
public void testDoWhileFib() throws Exception {
|
||||
blackBoxFileByFullPath("compiler/testData/codegen/box/controlStructures/doWhileFib.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("finallyOnEmptyReturn.kt")
|
||||
public void testFinallyOnEmptyReturn() throws Exception {
|
||||
blackBoxFileByFullPath("compiler/testData/codegen/box/controlStructures/finallyOnEmptyReturn.kt");
|
||||
@@ -1157,6 +1167,11 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
|
||||
blackBoxFileByFullPath("compiler/testData/codegen/box/controlStructures/kt3273.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("kt3280.kt")
|
||||
public void testKt3280() throws Exception {
|
||||
blackBoxFileByFullPath("compiler/testData/codegen/box/controlStructures/kt3280.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("kt416.kt")
|
||||
public void testKt416() throws Exception {
|
||||
blackBoxFileByFullPath("compiler/testData/codegen/box/controlStructures/kt416.kt");
|
||||
|
||||
@@ -42,6 +42,7 @@ import org.jetbrains.jet.lang.resolve.BindingContext;
|
||||
import org.jetbrains.jet.lang.resolve.DescriptorUtils;
|
||||
import org.jetbrains.jet.lang.resolve.java.JavaDescriptorResolver;
|
||||
import org.jetbrains.jet.lang.resolve.java.JavaToKotlinClassMap;
|
||||
import org.jetbrains.jet.lang.resolve.java.kotlinSignature.TypeTransformingVisitor;
|
||||
import org.jetbrains.jet.lang.resolve.name.FqName;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.JetScope;
|
||||
import org.jetbrains.jet.renderer.DescriptorRenderer;
|
||||
@@ -65,10 +66,22 @@ public class JdkAnnotationsValidityTest extends UsefulTestCase {
|
||||
return new JetCoreEnvironment(parentDisposable, configuration);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
TypeTransformingVisitor.setStrictMode(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void tearDown() throws Exception {
|
||||
TypeTransformingVisitor.setStrictMode(false);
|
||||
super.tearDown();
|
||||
}
|
||||
|
||||
public void testNoErrorsInAlternativeSignatures() {
|
||||
List<FqName> affectedClasses = getAffectedClasses("file://jdk-annotations");
|
||||
|
||||
final Map<String, List<String>> errors = Maps.newHashMap();
|
||||
final Map<String, List<String>> errors = Maps.newLinkedHashMap();
|
||||
|
||||
for (int chunkIndex = 0; chunkIndex < affectedClasses.size() / CLASSES_IN_CHUNK + 1; chunkIndex++) {
|
||||
Disposable parentDisposable = CompileEnvironmentUtil.createMockDisposable();
|
||||
|
||||
@@ -256,6 +256,7 @@ public class LoadCompiledKotlinTestGenerated extends AbstractLoadCompiledKotlinT
|
||||
}
|
||||
|
||||
@TestMetadata("compiler/testData/loadKotlin/constructor")
|
||||
@InnerTestClasses({Constructor.Vararg.class})
|
||||
public static class Constructor extends AbstractLoadCompiledKotlinTest {
|
||||
public void testAllFilesPresentInConstructor() throws Exception {
|
||||
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.GenerateTests", new File("compiler/testData/loadKotlin/constructor"), "kt", true);
|
||||
@@ -286,11 +287,6 @@ public class LoadCompiledKotlinTestGenerated extends AbstractLoadCompiledKotlinT
|
||||
doTest("compiler/testData/loadKotlin/constructor/ConstructorCollectionParameter.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("ConstructorVararg.kt")
|
||||
public void testConstructorVararg() throws Exception {
|
||||
doTest("compiler/testData/loadKotlin/constructor/ConstructorVararg.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("ConstructorWithTwoDefArgs.kt")
|
||||
public void testConstructorWithTwoDefArgs() throws Exception {
|
||||
doTest("compiler/testData/loadKotlin/constructor/ConstructorWithTwoDefArgs.kt");
|
||||
@@ -331,6 +327,30 @@ public class LoadCompiledKotlinTestGenerated extends AbstractLoadCompiledKotlinT
|
||||
doTest("compiler/testData/loadKotlin/constructor/PrivateConstructor1WithParamDefaultValue.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("compiler/testData/loadKotlin/constructor/vararg")
|
||||
public static class Vararg extends AbstractLoadCompiledKotlinTest {
|
||||
public void testAllFilesPresentInVararg() throws Exception {
|
||||
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.GenerateTests", new File("compiler/testData/loadKotlin/constructor/vararg"), "kt", true);
|
||||
}
|
||||
|
||||
@TestMetadata("ConstructorNonLastVararg.kt")
|
||||
public void testConstructorNonLastVararg() throws Exception {
|
||||
doTest("compiler/testData/loadKotlin/constructor/vararg/ConstructorNonLastVararg.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("ConstructorVararg.kt")
|
||||
public void testConstructorVararg() throws Exception {
|
||||
doTest("compiler/testData/loadKotlin/constructor/vararg/ConstructorVararg.kt");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static Test innerSuite() {
|
||||
TestSuite suite = new TestSuite("Constructor");
|
||||
suite.addTestSuite(Constructor.class);
|
||||
suite.addTestSuite(Vararg.class);
|
||||
return suite;
|
||||
}
|
||||
}
|
||||
|
||||
@TestMetadata("compiler/testData/loadKotlin/dataClass")
|
||||
@@ -377,7 +397,7 @@ public class LoadCompiledKotlinTestGenerated extends AbstractLoadCompiledKotlinT
|
||||
}
|
||||
|
||||
@TestMetadata("compiler/testData/loadKotlin/fun")
|
||||
@InnerTestClasses({Fun.GenericWithTypeVariables.class, Fun.GenericWithoutTypeVariables.class, Fun.NonGeneric.class})
|
||||
@InnerTestClasses({Fun.GenericWithTypeVariables.class, Fun.GenericWithoutTypeVariables.class, Fun.NonGeneric.class, Fun.Vararg.class})
|
||||
public static class Fun extends AbstractLoadCompiledKotlinTest {
|
||||
public void testAllFilesPresentInFun() throws Exception {
|
||||
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.GenerateTests", new File("compiler/testData/loadKotlin/fun"), "kt", true);
|
||||
@@ -567,12 +587,26 @@ public class LoadCompiledKotlinTestGenerated extends AbstractLoadCompiledKotlinT
|
||||
|
||||
}
|
||||
|
||||
@TestMetadata("compiler/testData/loadKotlin/fun/vararg")
|
||||
public static class Vararg extends AbstractLoadCompiledKotlinTest {
|
||||
public void testAllFilesPresentInVararg() throws Exception {
|
||||
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.GenerateTests", new File("compiler/testData/loadKotlin/fun/vararg"), "kt", true);
|
||||
}
|
||||
|
||||
@TestMetadata("nonLastVararg.kt")
|
||||
public void testNonLastVararg() throws Exception {
|
||||
doTest("compiler/testData/loadKotlin/fun/vararg/nonLastVararg.kt");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static Test innerSuite() {
|
||||
TestSuite suite = new TestSuite("Fun");
|
||||
suite.addTestSuite(Fun.class);
|
||||
suite.addTestSuite(GenericWithTypeVariables.class);
|
||||
suite.addTestSuite(GenericWithoutTypeVariables.class);
|
||||
suite.addTestSuite(NonGeneric.class);
|
||||
suite.addTestSuite(Vararg.class);
|
||||
return suite;
|
||||
}
|
||||
}
|
||||
@@ -952,7 +986,7 @@ public class LoadCompiledKotlinTestGenerated extends AbstractLoadCompiledKotlinT
|
||||
suite.addTestSuite(Class.class);
|
||||
suite.addTestSuite(ClassFun.class);
|
||||
suite.addTestSuite(ClassObject.class);
|
||||
suite.addTestSuite(Constructor.class);
|
||||
suite.addTest(Constructor.innerSuite());
|
||||
suite.addTestSuite(DataClass.class);
|
||||
suite.addTest(Fun.innerSuite());
|
||||
suite.addTestSuite(Prop.class);
|
||||
|
||||
@@ -343,6 +343,11 @@ public class LoadJavaTestGenerated extends AbstractLoadJavaTest {
|
||||
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.GenerateTests", new File("compiler/testData/loadJava/kotlinSignature/error"), "java", true);
|
||||
}
|
||||
|
||||
@TestMetadata("ConflictingProjectionKind.java")
|
||||
public void testConflictingProjectionKind() throws Exception {
|
||||
doTest("compiler/testData/loadJava/kotlinSignature/error/ConflictingProjectionKind.java");
|
||||
}
|
||||
|
||||
@TestMetadata("ExplicitFieldGettersAndSetters.java")
|
||||
public void testExplicitFieldGettersAndSetters() throws Exception {
|
||||
doTest("compiler/testData/loadJava/kotlinSignature/error/ExplicitFieldGettersAndSetters.java");
|
||||
@@ -368,6 +373,11 @@ public class LoadJavaTestGenerated extends AbstractLoadJavaTest {
|
||||
doTest("compiler/testData/loadJava/kotlinSignature/error/NotVarargReplacedWithVararg.java");
|
||||
}
|
||||
|
||||
@TestMetadata("RedundantProjectionKind.java")
|
||||
public void testRedundantProjectionKind() throws Exception {
|
||||
doTest("compiler/testData/loadJava/kotlinSignature/error/RedundantProjectionKind.java");
|
||||
}
|
||||
|
||||
@TestMetadata("ReturnTypeMissing.java")
|
||||
public void testReturnTypeMissing() throws Exception {
|
||||
doTest("compiler/testData/loadJava/kotlinSignature/error/ReturnTypeMissing.java");
|
||||
|
||||
@@ -16,10 +16,16 @@
|
||||
|
||||
package org.jetbrains.jet.lang.psi;
|
||||
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import junit.framework.Assert;
|
||||
import junit.framework.TestCase;
|
||||
import org.jetbrains.jet.JetLiteFixture;
|
||||
import org.jetbrains.jet.cli.jvm.compiler.JetCoreEnvironment;
|
||||
import org.jetbrains.jet.config.CompilerConfiguration;
|
||||
import org.jetbrains.jet.lang.resolve.ImportPath;
|
||||
import org.jetbrains.jet.lang.resolve.name.FqName;
|
||||
import org.jetbrains.jet.lang.resolve.name.Name;
|
||||
|
||||
public class JetPsiUtilTest extends TestCase {
|
||||
public class JetPsiUtilTest extends JetLiteFixture {
|
||||
|
||||
public void testUnquotedIdentifier() {
|
||||
Assert.assertEquals("", JetPsiUtil.unquoteIdentifier(""));
|
||||
@@ -37,4 +43,37 @@ public class JetPsiUtilTest extends TestCase {
|
||||
Assert.assertEquals("$a2", JetPsiUtil.unquoteIdentifierOrFieldReference("$`a2`"));
|
||||
}
|
||||
|
||||
public void testConvertToImportPath() {
|
||||
Assert.assertEquals(null, getImportPathFromParsed("import "));
|
||||
Assert.assertEquals(null, getImportPathFromParsed("import some."));
|
||||
Assert.assertEquals(null, getImportPathFromParsed("import *"));
|
||||
Assert.assertEquals(null, getImportPathFromParsed("import some.test.* as SomeTest"));
|
||||
Assert.assertEquals(new ImportPath(new FqName("some"), false), getImportPathFromParsed("import some?.Test"));
|
||||
|
||||
Assert.assertEquals(new ImportPath(new FqName("some"), false), getImportPathFromParsed("import some"));
|
||||
Assert.assertEquals(new ImportPath(new FqName("some"), true), getImportPathFromParsed("import some.*"));
|
||||
Assert.assertEquals(new ImportPath(new FqName("some.Test"), false), getImportPathFromParsed("import some.Test"));
|
||||
Assert.assertEquals(new ImportPath(new FqName("some.test"), true), getImportPathFromParsed("import some.test.*"));
|
||||
Assert.assertEquals(new ImportPath(new FqName("some.test"), false, Name.identifier("SomeTest")), getImportPathFromParsed("import some.test as SomeTest"));
|
||||
|
||||
Assert.assertEquals(new ImportPath(new FqName("some.Test"), false), getImportPathFromParsed("import some.\nTest"));
|
||||
Assert.assertEquals(new ImportPath(new FqName("some.Test"), false), getImportPathFromParsed("import some./* hello world */Test"));
|
||||
Assert.assertEquals(new ImportPath(new FqName("some.Test"), false), getImportPathFromParsed("import some. Test"));
|
||||
|
||||
Assert.assertNotSame(new ImportPath(new FqName("some.test"), false), getImportPathFromParsed("import some.Test"));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected JetCoreEnvironment createEnvironment() {
|
||||
return new JetCoreEnvironment(getTestRootDisposable(), new CompilerConfiguration());
|
||||
}
|
||||
|
||||
private ImportPath getImportPathFromParsed(String text) {
|
||||
JetImportDirective importDirective =
|
||||
PsiTreeUtil.findChildOfType(JetPsiFactory.createFile(getProject(), text), JetImportDirective.class);
|
||||
|
||||
assertNotNull("At least one import directive is expected", importDirective);
|
||||
|
||||
return JetPsiUtil.getImportPath(importDirective);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,84 @@
|
||||
/*
|
||||
* Copyright 2010-2013 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.lazy;
|
||||
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import junit.framework.Assert;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.jet.ConfigurationKind;
|
||||
import org.jetbrains.jet.JetLiteFixture;
|
||||
import org.jetbrains.jet.JetTestUtils;
|
||||
import org.jetbrains.jet.cli.jvm.compiler.JetCoreEnvironment;
|
||||
import org.jetbrains.jet.lang.descriptors.NamespaceDescriptor;
|
||||
import org.jetbrains.jet.lang.psi.JetFile;
|
||||
import org.jetbrains.jet.lang.resolve.name.Name;
|
||||
import org.jetbrains.jet.resolve.ExpectedResolveData;
|
||||
import org.jetbrains.jet.resolve.JetExpectedResolveDataUtil;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
|
||||
public abstract class AbstractLazyResolveTest extends JetLiteFixture {
|
||||
private ExpectedResolveData expectedResolveData;
|
||||
|
||||
@Override
|
||||
protected JetCoreEnvironment createEnvironment() {
|
||||
return createEnvironmentWithMockJdk(ConfigurationKind.JDK_AND_ANNOTATIONS);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
expectedResolveData = getExpectedResolveData();
|
||||
}
|
||||
|
||||
protected ExpectedResolveData getExpectedResolveData() {
|
||||
Project project = getProject();
|
||||
|
||||
return new ExpectedResolveData(
|
||||
JetExpectedResolveDataUtil.prepareDefaultNameToDescriptors(project),
|
||||
JetExpectedResolveDataUtil.prepareDefaultNameToDeclaration(project),
|
||||
getEnvironment()) {
|
||||
@Override
|
||||
protected JetFile createJetFile(String fileName, String text) {
|
||||
return createCheckAndReturnPsiFile(fileName, null, text);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
protected void doTest(@NonNls String testFile) throws Exception {
|
||||
String text = FileUtil.loadFile(new File(testFile), true);
|
||||
|
||||
List<JetFile> files = JetTestUtils.createTestFiles("file.kt", text, new JetTestUtils.TestFileFactory<JetFile>() {
|
||||
@Override
|
||||
public JetFile create(String fileName, String text) {
|
||||
return expectedResolveData.createFileFromMarkedUpText(fileName, text);
|
||||
}
|
||||
});
|
||||
|
||||
ResolveSession resolveSession = LazyResolveTestUtil.resolveLazilyWithSession(files, getEnvironment());
|
||||
|
||||
NamespaceDescriptor actual = resolveSession.getPackageDescriptor(Name.identifier("test"));
|
||||
Assert.assertNotNull("Package 'test' was not found", actual);
|
||||
|
||||
resolveSession.forceResolveAll();
|
||||
|
||||
expectedResolveData.checkResult(resolveSession.getBindingContext());
|
||||
}
|
||||
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user