Merge remote-tracking branch 'origin/master'
Conflicts: compiler/frontend/src/org/jetbrains/jet/lang/cfg/JetFlowInformationProvider.java
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package org.jetbrains.jet;
|
||||
|
||||
import com.intellij.core.JavaCoreEnvironment;
|
||||
import com.intellij.lang.java.JavaParserDefinition;
|
||||
import com.intellij.openapi.Disposable;
|
||||
import org.jetbrains.jet.lang.parsing.JetParserDefinition;
|
||||
import org.jetbrains.jet.plugin.JetFileType;
|
||||
@@ -15,6 +16,7 @@ public class JetCoreEnvironment extends JavaCoreEnvironment {
|
||||
registerFileType(JetFileType.INSTANCE, "kts");
|
||||
registerFileType(JetFileType.INSTANCE, "ktm");
|
||||
registerFileType(JetFileType.INSTANCE, "jet");
|
||||
registerParserDefinition(new JavaParserDefinition());
|
||||
registerParserDefinition(new JetParserDefinition());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
package org.jetbrains.jet.lang;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lang.descriptors.NamespaceDescriptor;
|
||||
import org.jetbrains.jet.lang.resolve.BindingTrace;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.WritableScope;
|
||||
|
||||
/**
|
||||
* @author abreslav
|
||||
*/
|
||||
public interface Configuration {
|
||||
Configuration EMPTY = new Configuration() {
|
||||
@Override
|
||||
public void addDefaultImports(BindingTrace trace, WritableScope rootScope) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void extendNamespaceScope(BindingTrace trace, @NotNull NamespaceDescriptor namespaceDescriptor, @NotNull WritableScope namespaceMemberScope) {
|
||||
}
|
||||
};
|
||||
|
||||
void addDefaultImports(BindingTrace trace, WritableScope rootScope);
|
||||
|
||||
/**
|
||||
*
|
||||
* This method is called every time a namespace descriptor is created. Use it to add extra descriptors to the namespace, e.g. merge a Java package with a Kotlin one
|
||||
*/
|
||||
void extendNamespaceScope(BindingTrace trace, @NotNull NamespaceDescriptor namespaceDescriptor, @NotNull WritableScope namespaceMemberScope);
|
||||
}
|
||||
@@ -14,7 +14,6 @@ import org.jetbrains.jet.lang.types.JetType;
|
||||
import org.jetbrains.jet.lang.types.expressions.OperatorConventions;
|
||||
import org.jetbrains.jet.lexer.JetTokens;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
@@ -284,7 +283,7 @@ public class JetControlFlowProcessor {
|
||||
|
||||
@Override
|
||||
public void visitUnaryExpression(JetUnaryExpression expression) {
|
||||
JetSimpleNameExpression operationSign = expression.getOperationSign();
|
||||
JetSimpleNameExpression operationSign = expression.getOperationReference();
|
||||
IElementType operationType = operationSign.getReferencedNameElementType();
|
||||
JetExpression baseExpression = expression.getBaseExpression();
|
||||
if (baseExpression == null) return;
|
||||
|
||||
@@ -288,7 +288,7 @@ public class JetFlowInformationProvider {
|
||||
operationReference = ((JetBinaryExpression) parent).getOperationReference();
|
||||
}
|
||||
else if (parent instanceof JetUnaryExpression) {
|
||||
operationReference = ((JetUnaryExpression) parent).getOperationSign();
|
||||
operationReference = ((JetUnaryExpression) parent).getOperationReference();
|
||||
}
|
||||
if (operationReference != null) {
|
||||
DeclarationDescriptor descriptor = trace.get(BindingContext.REFERENCE_TARGET, operationReference);
|
||||
|
||||
@@ -48,6 +48,16 @@ public class MutableClassDescriptor extends MutableDeclarationDescriptor impleme
|
||||
|
||||
public MutableClassDescriptor(@NotNull BindingTrace trace, @NotNull DeclarationDescriptor containingDeclaration, @NotNull JetScope outerScope, ClassKind kind) {
|
||||
super(containingDeclaration);
|
||||
|
||||
if (containingDeclaration instanceof ClassDescriptor
|
||||
|| containingDeclaration instanceof NamespaceLike
|
||||
|| containingDeclaration instanceof ModuleDescriptor
|
||||
|| containingDeclaration instanceof FunctionDescriptor)
|
||||
{
|
||||
} else {
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
|
||||
TraceBasedRedeclarationHandler redeclarationHandler = new TraceBasedRedeclarationHandler(trace);
|
||||
this.scopeForMemberLookup = new WritableScopeImpl(JetScope.EMPTY, this, redeclarationHandler).setDebugName("MemberLookup").changeLockLevel(WritableScope.LockLevel.BOTH);
|
||||
this.scopeForSupertypeResolution = new WritableScopeImpl(outerScope, this, redeclarationHandler).setDebugName("SupertypeResolution").changeLockLevel(WritableScope.LockLevel.BOTH);
|
||||
|
||||
@@ -8,7 +8,7 @@ import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.descriptors.*;
|
||||
import org.jetbrains.jet.lang.psi.*;
|
||||
import org.jetbrains.jet.lang.types.JetType;
|
||||
import org.jetbrains.jet.lang.types.inference.SolutionStatus;
|
||||
import org.jetbrains.jet.lang.resolve.calls.inference.SolutionStatus;
|
||||
import org.jetbrains.jet.lexer.JetKeywordToken;
|
||||
import org.jetbrains.jet.resolve.DescriptorRenderer;
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@ import org.jetbrains.jet.JetNodeTypes;
|
||||
/**
|
||||
* @author max
|
||||
*/
|
||||
public class JetBinaryExpression extends JetExpression {
|
||||
public class JetBinaryExpression extends JetExpression implements JetOperationExpression {
|
||||
public JetBinaryExpression(@NotNull ASTNode node) {
|
||||
super(node);
|
||||
}
|
||||
@@ -46,6 +46,7 @@ public class JetBinaryExpression extends JetExpression {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public JetSimpleNameExpression getOperationReference() {
|
||||
return (JetSimpleNameExpression) findChildByType(JetNodeTypes.OPERATION_REFERENCE);
|
||||
|
||||
@@ -65,7 +65,7 @@ public class JetCallExpression extends JetExpression implements JetCallElement {
|
||||
}
|
||||
else if (psi instanceof JetPrefixExpression) {
|
||||
JetPrefixExpression prefixExpression = (JetPrefixExpression) psi;
|
||||
if (JetTokens.LABELS.contains(prefixExpression.getOperationSign().getReferencedNameElementType())) {
|
||||
if (JetTokens.LABELS.contains(prefixExpression.getOperationReference().getReferencedNameElementType())) {
|
||||
JetExpression labeledExpression = prefixExpression.getBaseExpression();
|
||||
if (labeledExpression instanceof JetFunctionLiteralExpression) {
|
||||
result.add(labeledExpression);
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
package org.jetbrains.jet.lang.psi;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* @author abreslav
|
||||
*/
|
||||
public interface JetOperationExpression {
|
||||
@NotNull
|
||||
JetSimpleNameExpression getOperationReference();
|
||||
}
|
||||
@@ -25,7 +25,7 @@ public class JetPrefixExpression extends JetUnaryExpression {
|
||||
|
||||
@Nullable @IfNotParsed
|
||||
public JetExpression getBaseExpression() {
|
||||
PsiElement expression = getOperationSign().getNextSibling();
|
||||
PsiElement expression = getOperationReference().getNextSibling();
|
||||
while (expression != null && !(expression instanceof JetExpression)) {
|
||||
expression = expression.getNextSibling();
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ public class JetPsiUtil {
|
||||
}
|
||||
}
|
||||
else if (expression instanceof JetPrefixExpression) {
|
||||
if (JetTokens.LABELS.contains(((JetPrefixExpression) expression).getOperationSign().getReferencedNameElementType())) {
|
||||
if (JetTokens.LABELS.contains(((JetPrefixExpression) expression).getOperationReference().getReferencedNameElementType())) {
|
||||
JetExpression baseExpression = ((JetPrefixExpression) expression).getBaseExpression();
|
||||
if (baseExpression != null) {
|
||||
expression = baseExpression;
|
||||
|
||||
@@ -10,6 +10,9 @@ import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Type reference element.
|
||||
* Underlying token is {@link org.jetbrains.jet.JetNodeTypes#TYPE_REFERENCE}
|
||||
*
|
||||
* @author max
|
||||
*/
|
||||
public class JetTypeReference extends JetElement {
|
||||
|
||||
@@ -8,7 +8,7 @@ import org.jetbrains.jet.JetNodeTypes;
|
||||
/**
|
||||
* @author abreslav
|
||||
*/
|
||||
public abstract class JetUnaryExpression extends JetExpression {
|
||||
public abstract class JetUnaryExpression extends JetExpression implements JetOperationExpression {
|
||||
public JetUnaryExpression(ASTNode node) {
|
||||
super(node);
|
||||
}
|
||||
@@ -16,8 +16,9 @@ public abstract class JetUnaryExpression extends JetExpression {
|
||||
@Nullable @IfNotParsed
|
||||
public abstract JetExpression getBaseExpression();
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public JetSimpleNameExpression getOperationSign() {
|
||||
public JetSimpleNameExpression getOperationReference() {
|
||||
return (JetSimpleNameExpression) findChildByType(JetNodeTypes.OPERATION_REFERENCE);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package org.jetbrains.jet.lang.resolve;
|
||||
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.base.Predicates;
|
||||
import com.google.common.collect.Maps;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.TextRange;
|
||||
@@ -10,6 +9,7 @@ import com.intellij.psi.PsiElementVisitor;
|
||||
import com.intellij.psi.PsiErrorElement;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lang.Configuration;
|
||||
import org.jetbrains.jet.lang.JetSemanticServices;
|
||||
import org.jetbrains.jet.lang.cfg.pseudocode.JetControlFlowDataTraceFactory;
|
||||
import org.jetbrains.jet.lang.descriptors.*;
|
||||
@@ -17,20 +17,24 @@ import org.jetbrains.jet.lang.diagnostics.Diagnostic;
|
||||
import org.jetbrains.jet.lang.diagnostics.DiagnosticHolder;
|
||||
import org.jetbrains.jet.lang.diagnostics.DiagnosticUtils;
|
||||
import org.jetbrains.jet.lang.psi.JetDeclaration;
|
||||
import org.jetbrains.jet.lang.psi.JetFile;
|
||||
import org.jetbrains.jet.lang.psi.JetNamespace;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.JetScope;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.WritableScope;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.WritableScopeImpl;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author abreslav
|
||||
*/
|
||||
public class AnalyzingUtils {
|
||||
public static AnalyzingUtils getInstance(@NotNull ImportingStrategy importingStrategy) {
|
||||
return new AnalyzingUtils(importingStrategy);
|
||||
|
||||
private static final AnalyzingUtils INSTANCE = new AnalyzingUtils();
|
||||
|
||||
public static AnalyzingUtils getInstance() {
|
||||
return INSTANCE;
|
||||
}
|
||||
|
||||
public static void checkForSyntacticErrors(@NotNull PsiElement root) {
|
||||
@@ -69,32 +73,26 @@ public class AnalyzingUtils {
|
||||
}
|
||||
}
|
||||
|
||||
private final ImportingStrategy importingStrategy;
|
||||
|
||||
private AnalyzingUtils(ImportingStrategy importingStrategy) {
|
||||
this.importingStrategy = importingStrategy;
|
||||
}
|
||||
|
||||
public BindingContext analyzeNamespace(@NotNull JetNamespace namespace, @NotNull JetControlFlowDataTraceFactory flowDataTraceFactory) {
|
||||
Project project = namespace.getProject();
|
||||
List<JetDeclaration> declarations = Collections.<JetDeclaration>singletonList(namespace);
|
||||
|
||||
return analyzeNamespaces(project, declarations, Predicates.equalTo(namespace.getContainingFile()), flowDataTraceFactory);
|
||||
}
|
||||
// --------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
public BindingContext analyzeNamespaces(
|
||||
@NotNull Project project,
|
||||
@NotNull Configuration configuration,
|
||||
@NotNull Collection<? extends JetDeclaration> declarations,
|
||||
@NotNull Predicate<PsiFile> filesToAnalyzeCompletely,
|
||||
@NotNull JetControlFlowDataTraceFactory flowDataTraceFactory) {
|
||||
BindingTraceContext bindingTraceContext = new BindingTraceContext();
|
||||
return analyzeNamespacesWithGivenTrace(project, configuration, declarations, filesToAnalyzeCompletely, flowDataTraceFactory, bindingTraceContext);
|
||||
}
|
||||
|
||||
public BindingContext analyzeNamespacesWithGivenTrace(Project project, Configuration configuration, Collection<? extends JetDeclaration> declarations, Predicate<PsiFile> filesToAnalyzeCompletely, JetControlFlowDataTraceFactory flowDataTraceFactory, BindingTraceContext bindingTraceContext) {
|
||||
JetSemanticServices semanticServices = JetSemanticServices.createSemanticServices(project);
|
||||
|
||||
JetScope libraryScope = semanticServices.getStandardLibrary().getLibraryScope();
|
||||
ModuleDescriptor owner = new ModuleDescriptor("<module>");
|
||||
|
||||
final WritableScope scope = new WritableScopeImpl(JetScope.EMPTY, owner, new TraceBasedRedeclarationHandler(bindingTraceContext)).setDebugName("Root scope in analyzeNamespace");
|
||||
importingStrategy.addImports(project, semanticServices, bindingTraceContext, scope);
|
||||
// configuration.addImports(project, semanticServices, bindingTraceContext, scope);
|
||||
scope.importScope(libraryScope);
|
||||
scope.changeLockLevel(WritableScope.LockLevel.BOTH);
|
||||
|
||||
@@ -132,29 +130,8 @@ public class AnalyzingUtils {
|
||||
public ClassObjectStatus setClassObjectDescriptor(@NotNull MutableClassDescriptor classObjectDescriptor) {
|
||||
throw new IllegalStateException("Must be guaranteed not to happen by the parser");
|
||||
}
|
||||
}, declarations, filesToAnalyzeCompletely, flowDataTraceFactory);
|
||||
}, declarations, filesToAnalyzeCompletely, flowDataTraceFactory, configuration);
|
||||
return bindingTraceContext.getBindingContext();
|
||||
}
|
||||
|
||||
public BindingContext shallowAnalyzeFiles(Collection<PsiFile> files) {
|
||||
assert files.size() > 0;
|
||||
|
||||
Project project = files.iterator().next().getProject();
|
||||
|
||||
Collection<JetNamespace> namespaces = collectRootNamespaces(files);
|
||||
|
||||
return analyzeNamespaces(project, namespaces, Predicates.<PsiFile>alwaysFalse(), JetControlFlowDataTraceFactory.EMPTY);
|
||||
}
|
||||
|
||||
public static List<JetNamespace> collectRootNamespaces(Collection<PsiFile> files) {
|
||||
List<JetNamespace> namespaces = new ArrayList<JetNamespace>();
|
||||
|
||||
for (PsiFile file : files) {
|
||||
if (file instanceof JetFile) {
|
||||
namespaces.add(((JetFile) file).getRootNamespace());
|
||||
}
|
||||
}
|
||||
return namespaces;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -41,11 +41,15 @@ public interface BindingContext {
|
||||
WritableSlice<JetExpression, ResolvedCall<FunctionDescriptor>> INDEXED_LVALUE_SET = Slices.createSimpleSlice();
|
||||
|
||||
WritableSlice<JetExpression, JetType> AUTOCAST = Slices.createSimpleSlice();
|
||||
|
||||
/** A scope where type of expression has been resolved */
|
||||
WritableSlice<JetExpression, JetScope> RESOLUTION_SCOPE = Slices.createSimpleSlice();
|
||||
|
||||
WritableSlice<JetExpression, Boolean> VARIABLE_REASSIGNMENT = Slices.createSimpleSetSlice();
|
||||
WritableSlice<ValueParameterDescriptor, Boolean> AUTO_CREATED_IT = Slices.createSimpleSetSlice();
|
||||
WritableSlice<JetExpression, DeclarationDescriptor> VARIABLE_ASSIGNMENT = Slices.createSimpleSlice();
|
||||
|
||||
/** Has type of current expression has been already resolved */
|
||||
WritableSlice<JetExpression, Boolean> PROCESSED = Slices.createSimpleSetSlice();
|
||||
WritableSlice<JetElement, Boolean> STATEMENT = Slices.createRemovableSetSlice();
|
||||
WritableSlice<CallableMemberDescriptor, Boolean> DELEGATED = Slices.createRemovableSetSlice();
|
||||
|
||||
@@ -154,4 +154,14 @@ public class DescriptorUtils {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static String getFQName(DeclarationDescriptor descriptor) {
|
||||
DeclarationDescriptor container = descriptor.getContainingDeclaration();
|
||||
if (container != null && !(container instanceof ModuleDescriptor)) {
|
||||
String baseName = getFQName(container);
|
||||
if (!baseName.isEmpty()) return baseName + "." + descriptor.getName();
|
||||
}
|
||||
|
||||
return descriptor.getName();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,19 +0,0 @@
|
||||
package org.jetbrains.jet.lang.resolve;
|
||||
|
||||
import com.intellij.openapi.project.Project;
|
||||
import org.jetbrains.jet.lang.JetSemanticServices;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.WritableScope;
|
||||
|
||||
/**
|
||||
* @author abreslav
|
||||
*/
|
||||
public interface ImportingStrategy {
|
||||
ImportingStrategy NONE = new ImportingStrategy() {
|
||||
@Override
|
||||
public void addImports(Project project, JetSemanticServices semanticServices, BindingTrace trace, WritableScope rootScope) {
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
void addImports(Project project, JetSemanticServices semanticServices, BindingTrace trace, WritableScope rootScope);
|
||||
}
|
||||
@@ -1,18 +1,13 @@
|
||||
package org.jetbrains.jet.lang.resolve;
|
||||
|
||||
import com.intellij.openapi.util.Pair;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.util.containers.MultiMap;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.descriptors.*;
|
||||
import org.jetbrains.jet.lang.diagnostics.Errors;
|
||||
import org.jetbrains.jet.lang.psi.*;
|
||||
import org.jetbrains.jet.resolve.DescriptorRenderer;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.jetbrains.jet.lang.resolve.BindingContext.DELEGATED;
|
||||
@@ -51,7 +46,7 @@ public class OverloadResolver {
|
||||
}
|
||||
|
||||
Key(NamespaceDescriptor namespaceDescriptor, String name) {
|
||||
this(DescriptorRenderer.getFQName(namespaceDescriptor), name);
|
||||
this(DescriptorUtils.getFQName(namespaceDescriptor), name);
|
||||
}
|
||||
|
||||
public String getNamespace() {
|
||||
|
||||
@@ -6,6 +6,7 @@ import com.google.common.collect.Sets;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lang.Configuration;
|
||||
import org.jetbrains.jet.lang.JetSemanticServices;
|
||||
import org.jetbrains.jet.lang.descriptors.*;
|
||||
import org.jetbrains.jet.lang.psi.*;
|
||||
@@ -23,31 +24,31 @@ import java.util.Set;
|
||||
|
||||
private final ObservableBindingTrace trace;
|
||||
private final JetSemanticServices semanticServices;
|
||||
private final DescriptorResolver descriptorResolver;
|
||||
private final Configuration configuration;
|
||||
|
||||
private final DescriptorResolver descriptorResolver;
|
||||
private final Map<JetClass, MutableClassDescriptor> classes = Maps.newLinkedHashMap();
|
||||
private final Map<JetObjectDeclaration, MutableClassDescriptor> objects = Maps.newLinkedHashMap();
|
||||
protected final Map<JetNamespace, WritableScope> namespaceScopes = Maps.newHashMap();
|
||||
protected final Map<JetNamespace, NamespaceDescriptorImpl> namespaceDescriptors = Maps.newHashMap();
|
||||
|
||||
private final Map<JetDeclaration, JetScope> declaringScopes = Maps.newHashMap();
|
||||
|
||||
private final Map<JetNamedFunction, FunctionDescriptorImpl> functions = Maps.newLinkedHashMap();
|
||||
private final Map<JetSecondaryConstructor, ConstructorDescriptor> constructors = Maps.newLinkedHashMap();
|
||||
private final Map<JetProperty, PropertyDescriptor> properties = Maps.newLinkedHashMap();
|
||||
private final Set<PropertyDescriptor> primaryConstructorParameterProperties = Sets.newHashSet();
|
||||
|
||||
private final Predicate<PsiFile> analyzeCompletely;
|
||||
|
||||
private StringBuilder debugOutput;
|
||||
|
||||
private StringBuilder debugOutput;
|
||||
private boolean analyzingBootstrapLibrary = false;
|
||||
|
||||
public TopDownAnalysisContext(JetSemanticServices semanticServices, BindingTrace trace, Predicate<PsiFile> analyzeCompletely) {
|
||||
public TopDownAnalysisContext(JetSemanticServices semanticServices, BindingTrace trace, Predicate<PsiFile> analyzeCompletely, @NotNull Configuration configuration) {
|
||||
this.trace = new ObservableBindingTrace(trace);
|
||||
this.semanticServices = semanticServices;
|
||||
this.descriptorResolver = semanticServices.getClassDescriptorResolver(trace);
|
||||
this.analyzeCompletely = analyzeCompletely;
|
||||
this.configuration = configuration;
|
||||
}
|
||||
|
||||
public void debug(Object message) {
|
||||
@@ -133,4 +134,8 @@ import java.util.Set;
|
||||
return functions;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Configuration getConfiguration() {
|
||||
return configuration;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import com.google.common.base.Predicate;
|
||||
import com.google.common.base.Predicates;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lang.Configuration;
|
||||
import org.jetbrains.jet.lang.JetSemanticServices;
|
||||
import org.jetbrains.jet.lang.cfg.pseudocode.JetControlFlowDataTraceFactory;
|
||||
import org.jetbrains.jet.lang.descriptors.*;
|
||||
@@ -30,8 +31,10 @@ public class TopDownAnalyzer {
|
||||
@NotNull NamespaceLike owner,
|
||||
@NotNull Collection<? extends JetDeclaration> declarations,
|
||||
@NotNull Predicate<PsiFile> analyzeCompletely,
|
||||
@NotNull JetControlFlowDataTraceFactory flowDataTraceFactory) {
|
||||
process(semanticServices, trace, outerScope, owner, declarations, analyzeCompletely, flowDataTraceFactory, false);
|
||||
@NotNull JetControlFlowDataTraceFactory flowDataTraceFactory,
|
||||
@NotNull Configuration configuration
|
||||
) {
|
||||
process(semanticServices, trace, outerScope, owner, declarations, analyzeCompletely, flowDataTraceFactory, configuration, false);
|
||||
}
|
||||
|
||||
private static void process(
|
||||
@@ -42,8 +45,9 @@ public class TopDownAnalyzer {
|
||||
@NotNull Collection<? extends JetDeclaration> declarations,
|
||||
@NotNull Predicate<PsiFile> analyzeCompletely,
|
||||
@NotNull JetControlFlowDataTraceFactory flowDataTraceFactory,
|
||||
@NotNull Configuration configuration,
|
||||
boolean declaredLocally) {
|
||||
TopDownAnalysisContext context = new TopDownAnalysisContext(semanticServices, trace, analyzeCompletely);
|
||||
TopDownAnalysisContext context = new TopDownAnalysisContext(semanticServices, trace, analyzeCompletely, configuration);
|
||||
doProcess(context, outerScope, owner, declarations, flowDataTraceFactory, declaredLocally);
|
||||
|
||||
}
|
||||
@@ -89,7 +93,7 @@ public class TopDownAnalyzer {
|
||||
@NotNull JetSemanticServices semanticServices,
|
||||
@NotNull BindingTrace trace,
|
||||
@NotNull WritableScope outerScope, @NotNull NamespaceDescriptorImpl standardLibraryNamespace, @NotNull JetNamespace namespace) {
|
||||
TopDownAnalysisContext context = new TopDownAnalysisContext(semanticServices, trace, Predicates.<PsiFile>alwaysTrue());
|
||||
TopDownAnalysisContext context = new TopDownAnalysisContext(semanticServices, trace, Predicates.<PsiFile>alwaysTrue(), Configuration.EMPTY);
|
||||
context.getNamespaceScopes().put(namespace, standardLibraryNamespace.getMemberScope());
|
||||
context.getNamespaceDescriptors().put(namespace, standardLibraryNamespace);
|
||||
context.getDeclaringScopes().put(namespace, outerScope);
|
||||
@@ -135,7 +139,7 @@ public class TopDownAnalyzer {
|
||||
public ClassObjectStatus setClassObjectDescriptor(@NotNull MutableClassDescriptor classObjectDescriptor) {
|
||||
return ClassObjectStatus.NOT_ALLOWED;
|
||||
}
|
||||
}, Collections.<JetDeclaration>singletonList(object), Predicates.equalTo(object.getContainingFile()), JetControlFlowDataTraceFactory.EMPTY, true);
|
||||
}, Collections.<JetDeclaration>singletonList(object), Predicates.equalTo(object.getContainingFile()), JetControlFlowDataTraceFactory.EMPTY, Configuration.EMPTY, true);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -75,6 +75,7 @@ public class TypeHierarchyResolver {
|
||||
|
||||
WriteThroughScope namespaceScope = new WriteThroughScope(outerScope, namespaceDescriptor.getMemberScope(), new TraceBasedRedeclarationHandler(context.getTrace()));
|
||||
namespaceScope.changeLockLevel(WritableScope.LockLevel.BOTH);
|
||||
context.getConfiguration().addDefaultImports(context.getTrace(), namespaceScope);
|
||||
context.getNamespaceScopes().put(namespace, namespaceScope);
|
||||
context.getDeclaringScopes().put(namespace, outerScope);
|
||||
|
||||
@@ -215,6 +216,7 @@ public class TypeHierarchyResolver {
|
||||
WritableScopeImpl scope = new WritableScopeImpl(JetScope.EMPTY, namespaceDescriptor, new TraceBasedRedeclarationHandler(context.getTrace())).setDebugName("Namespace member scope");
|
||||
scope.changeLockLevel(WritableScope.LockLevel.BOTH);
|
||||
namespaceDescriptor.initialize(scope);
|
||||
context.getConfiguration().extendNamespaceScope(context.getTrace(), namespaceDescriptor, scope);
|
||||
owner.addNamespace(namespaceDescriptor);
|
||||
if (namespace != null) {
|
||||
context.getTrace().record(BindingContext.NAMESPACE, namespace, namespaceDescriptor);
|
||||
|
||||
@@ -49,11 +49,14 @@ public class TypeResolver {
|
||||
JetTypeElement typeElement = typeReference.getTypeElement();
|
||||
JetType type = resolveTypeElement(scope, annotations, typeElement, false);
|
||||
trace.record(BindingContext.TYPE, typeReference, type);
|
||||
|
||||
return type;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private JetType resolveTypeElement(final JetScope scope, final List<AnnotationDescriptor> annotations, JetTypeElement typeElement, final boolean nullable) {
|
||||
private JetType resolveTypeElement(final JetScope scope, final List<AnnotationDescriptor> annotations,
|
||||
JetTypeElement typeElement, final boolean nullable) {
|
||||
|
||||
final JetType[] result = new JetType[1];
|
||||
if (typeElement != null) {
|
||||
typeElement.accept(new JetVisitorVoid() {
|
||||
@@ -70,6 +73,7 @@ public class TypeResolver {
|
||||
resolveTypeProjections(scope, ErrorUtils.createErrorType("No type").getConstructor(), type.getTypeArguments());
|
||||
return;
|
||||
}
|
||||
|
||||
if (classifierDescriptor instanceof TypeParameterDescriptor) {
|
||||
TypeParameterDescriptor typeParameterDescriptor = (TypeParameterDescriptor) classifierDescriptor;
|
||||
|
||||
@@ -268,6 +272,8 @@ public class TypeResolver {
|
||||
ClassifierDescriptor classifierDescriptor;
|
||||
if (userType.isAbsoluteInRootNamespace()) {
|
||||
classifierDescriptor = JetModuleUtil.getRootNamespaceType(userType).getMemberScope().getClassifier(referencedName);
|
||||
trace.record(BindingContext.RESOLUTION_SCOPE, userType.getReferenceExpression(),
|
||||
JetModuleUtil.getRootNamespaceType(userType).getMemberScope());
|
||||
}
|
||||
else {
|
||||
JetUserType qualifier = userType.getQualifier();
|
||||
@@ -278,7 +284,9 @@ public class TypeResolver {
|
||||
return ErrorUtils.getErrorClass();
|
||||
}
|
||||
classifierDescriptor = scope.getClassifier(referencedName);
|
||||
trace.record(BindingContext.RESOLUTION_SCOPE, userType.getReferenceExpression(), scope);
|
||||
}
|
||||
|
||||
return classifierDescriptor;
|
||||
}
|
||||
|
||||
|
||||
@@ -162,7 +162,7 @@ public class CallMaker {
|
||||
}
|
||||
|
||||
public static Call makeCall(@NotNull ReceiverDescriptor baseAsReceiver, JetUnaryExpression expression) {
|
||||
return makeCall(expression, baseAsReceiver, null, expression.getOperationSign(), Collections.<ValueArgument>emptyList());
|
||||
return makeCall(expression, baseAsReceiver, null, expression.getOperationReference(), Collections.<ValueArgument>emptyList());
|
||||
}
|
||||
|
||||
public static Call makeArraySetCall(@NotNull ReceiverDescriptor arrayAsReceiver, JetArrayAccessExpression arrayAccessExpression, JetExpression rightHandSide) {
|
||||
|
||||
@@ -19,10 +19,10 @@ import org.jetbrains.jet.lang.resolve.scopes.receivers.ReceiverDescriptor;
|
||||
import org.jetbrains.jet.lang.types.*;
|
||||
import org.jetbrains.jet.lang.types.expressions.ExpressionTypingServices;
|
||||
import org.jetbrains.jet.lang.types.expressions.OperatorConventions;
|
||||
import org.jetbrains.jet.lang.types.inference.ConstraintSystem;
|
||||
import org.jetbrains.jet.lang.types.inference.ConstraintSystemSolution;
|
||||
import org.jetbrains.jet.lang.types.inference.ConstraintSystemImpl;
|
||||
import org.jetbrains.jet.lang.types.inference.SolutionStatus;
|
||||
import org.jetbrains.jet.lang.resolve.calls.inference.ConstraintSystem;
|
||||
import org.jetbrains.jet.lang.resolve.calls.inference.ConstraintSystemSolution;
|
||||
import org.jetbrains.jet.lang.resolve.calls.inference.ConstraintSystemImpl;
|
||||
import org.jetbrains.jet.lang.resolve.calls.inference.SolutionStatus;
|
||||
import org.jetbrains.jet.lexer.JetTokens;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
@@ -6,7 +6,7 @@ import org.jetbrains.jet.lang.descriptors.ValueParameterDescriptor;
|
||||
import org.jetbrains.jet.lang.resolve.BindingTrace;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.receivers.ReceiverDescriptor;
|
||||
import org.jetbrains.jet.lang.types.JetType;
|
||||
import org.jetbrains.jet.lang.types.inference.SolutionStatus;
|
||||
import org.jetbrains.jet.lang.resolve.calls.inference.SolutionStatus;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package org.jetbrains.jet.lang.types.inference;
|
||||
package org.jetbrains.jet.lang.resolve.calls.inference;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lang.descriptors.TypeParameterDescriptor;
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package org.jetbrains.jet.lang.types.inference;
|
||||
package org.jetbrains.jet.lang.resolve.calls.inference;
|
||||
|
||||
import com.google.common.collect.Maps;
|
||||
import com.google.common.collect.Sets;
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package org.jetbrains.jet.lang.types.inference;
|
||||
package org.jetbrains.jet.lang.resolve.calls.inference;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package org.jetbrains.jet.lang.types.inference;
|
||||
package org.jetbrains.jet.lang.resolve.calls.inference;
|
||||
|
||||
/**
|
||||
* @author abreslav
|
||||
+3
-3
@@ -38,7 +38,7 @@ public abstract class WritableScopeWithImports extends JetScopeAdapter implement
|
||||
@Override
|
||||
public WritableScope changeLockLevel(LockLevel lockLevel) {
|
||||
if (lockLevel.ordinal() < this.lockLevel.ordinal()) {
|
||||
throw new IllegalStateException("cannot lower lock level from " + this.lockLevel + " to " + lockLevel);
|
||||
throw new IllegalStateException("cannot lower lock level from " + this.lockLevel + " to " + lockLevel + " at " + debugName);
|
||||
}
|
||||
this.lockLevel = lockLevel;
|
||||
return this;
|
||||
@@ -46,13 +46,13 @@ public abstract class WritableScopeWithImports extends JetScopeAdapter implement
|
||||
|
||||
protected void checkMayRead() {
|
||||
if (lockLevel != LockLevel.READING && lockLevel != LockLevel.BOTH) {
|
||||
throw new IllegalStateException("cannot read with lock level " + lockLevel);
|
||||
throw new IllegalStateException("cannot read with lock level " + lockLevel + " at " + debugName);
|
||||
}
|
||||
}
|
||||
|
||||
protected void checkMayWrite() {
|
||||
if (lockLevel != LockLevel.WRITING && lockLevel != LockLevel.BOTH) {
|
||||
throw new IllegalStateException("cannot write with lock level " + lockLevel);
|
||||
throw new IllegalStateException("cannot write with lock level " + lockLevel + " at " + debugName);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -613,7 +613,7 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
|
||||
public JetType visitUnaryExpression(JetUnaryExpression expression, ExpressionTypingContext context) {
|
||||
JetExpression baseExpression = expression.getBaseExpression();
|
||||
if (baseExpression == null) return null;
|
||||
JetSimpleNameExpression operationSign = expression.getOperationSign();
|
||||
JetSimpleNameExpression operationSign = expression.getOperationReference();
|
||||
if (JetTokens.LABELS.contains(operationSign.getReferencedNameElementType())) {
|
||||
String referencedName = operationSign.getReferencedName();
|
||||
referencedName = referencedName == null ? " <?>" : referencedName;
|
||||
@@ -634,7 +634,7 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
|
||||
|
||||
FunctionDescriptor functionDescriptor = context.resolveCallWithGivenNameToDescriptor(
|
||||
CallMaker.makeCall(receiver, expression),
|
||||
expression.getOperationSign(),
|
||||
expression.getOperationReference(),
|
||||
name);
|
||||
|
||||
if (functionDescriptor == null) return null;
|
||||
|
||||
@@ -109,7 +109,7 @@ public class DataFlowUtils {
|
||||
|
||||
@Override
|
||||
public void visitUnaryExpression(JetUnaryExpression expression) {
|
||||
IElementType operationTokenType = expression.getOperationSign().getReferencedNameElementType();
|
||||
IElementType operationTokenType = expression.getOperationReference().getReferencedNameElementType();
|
||||
if (operationTokenType == JetTokens.EXCL) {
|
||||
JetExpression baseExpression = expression.getBaseExpression();
|
||||
if (baseExpression != null) {
|
||||
|
||||
@@ -18,16 +18,6 @@ import java.util.List;
|
||||
*/
|
||||
public class DescriptorRenderer implements Renderer {
|
||||
|
||||
public static String getFQName(DeclarationDescriptor descriptor) {
|
||||
DeclarationDescriptor container = descriptor.getContainingDeclaration();
|
||||
if (container != null && !(container instanceof ModuleDescriptor)) {
|
||||
String baseName = getFQName(container);
|
||||
if (!baseName.isEmpty()) return baseName + "." + descriptor.getName();
|
||||
}
|
||||
|
||||
return descriptor.getName();
|
||||
}
|
||||
|
||||
public static final DescriptorRenderer TEXT = new DescriptorRenderer();
|
||||
|
||||
public static final DescriptorRenderer HTML = new DescriptorRenderer() {
|
||||
|
||||
Reference in New Issue
Block a user