Redeclaration diagnostics resolved to PsiElements correctly

This commit is contained in:
Andrey Breslav
2011-09-16 13:01:43 +04:00
parent d43242e741
commit 0dd2889c55
25 changed files with 208 additions and 120 deletions
@@ -5,16 +5,11 @@ import com.google.common.collect.HashBiMap;
import com.google.common.collect.Maps;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.lang.resolve.BindingTrace;
import org.jetbrains.jet.lang.resolve.JetScope;
import org.jetbrains.jet.lang.resolve.WritableScope;
import org.jetbrains.jet.lang.resolve.WritableScopeImpl;
import org.jetbrains.jet.lang.resolve.*;
import org.jetbrains.jet.lang.types.*;
import java.util.*;
import static org.jetbrains.jet.lang.types.TypeSubstitutor.TypeSubstitution;
/**
* @author abreslav
*/
@@ -97,7 +92,7 @@ public class FunctionDescriptorUtil {
@NotNull
public static JetScope getFunctionInnerScope(@NotNull JetScope outerScope, @NotNull FunctionDescriptor descriptor, @NotNull BindingTrace trace) {
WritableScope parameterScope = new WritableScopeImpl(outerScope, descriptor, trace).setDebugName("Function inner scope");
WritableScope parameterScope = new WritableScopeImpl(outerScope, descriptor, new TraceBasedRedeclarationHandler(trace)).setDebugName("Function inner scope");
JetType receiverType = descriptor.getReceiverType();
if (receiverType != null) {
parameterScope.setThisType(receiverType);
@@ -40,9 +40,10 @@ public class MutableClassDescriptor extends MutableDeclarationDescriptor impleme
public MutableClassDescriptor(@NotNull BindingTrace trace, @NotNull DeclarationDescriptor containingDeclaration, @NotNull JetScope outerScope, ClassKind kind) {
super(containingDeclaration);
this.scopeForMemberLookup = new WritableScopeImpl(JetScope.EMPTY, this, trace).setDebugName("MemberLookup");
this.scopeForSupertypeResolution = new WritableScopeImpl(outerScope, this, trace).setDebugName("SupertypeResolution");
this.scopeForMemberResolution = new WritableScopeImpl(scopeForSupertypeResolution, this, trace).setDebugName("MemberResolution");
TraceBasedRedeclarationHandler redeclarationHandler = new TraceBasedRedeclarationHandler(trace);
this.scopeForMemberLookup = new WritableScopeImpl(JetScope.EMPTY, this, redeclarationHandler).setDebugName("MemberLookup");
this.scopeForSupertypeResolution = new WritableScopeImpl(outerScope, this, redeclarationHandler).setDebugName("SupertypeResolution");
this.scopeForMemberResolution = new WritableScopeImpl(scopeForSupertypeResolution, this, redeclarationHandler).setDebugName("MemberResolution");
this.kind = kind;
}
@@ -1,9 +1,7 @@
package org.jetbrains.jet.lang.diagnostics;
import com.intellij.lang.ASTNode;
import com.intellij.openapi.util.TextRange;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiFile;
import org.jetbrains.annotations.NotNull;
/**
@@ -29,11 +27,11 @@ public abstract class DiagnosticFactoryWithPsiElement1<T extends PsiElement, A>
@NotNull
public Diagnostic on(@NotNull T element, @NotNull ASTNode node, @NotNull A argument) {
return new DiagnosticWithPsiElement<T>(this, severity, makeMessage(argument), element, node.getTextRange());
return new DiagnosticWithPsiElementImpl<T>(this, severity, makeMessage(argument), element, node.getTextRange());
}
@NotNull
public Diagnostic on(@NotNull T element, @NotNull PsiElement psiElement, @NotNull A argument) {
return new DiagnosticWithPsiElement<T>(this, severity, makeMessage(argument), element, psiElement.getTextRange());
return new DiagnosticWithPsiElementImpl<T>(this, severity, makeMessage(argument), element, psiElement.getTextRange());
}
}
@@ -33,6 +33,6 @@ public abstract class DiagnosticFactoryWithPsiElement2<T extends PsiElement, A,
@NotNull
public Diagnostic on(@NotNull T element, @NotNull ASTNode node, @NotNull A a, @NotNull B b) {
return new DiagnosticWithPsiElement<T>(this, severity, makeMessage(a, b), element, node.getTextRange());
return new DiagnosticWithPsiElementImpl<T>(this, severity, makeMessage(a, b), element, node.getTextRange());
}
}
@@ -1,27 +1,12 @@
package org.jetbrains.jet.lang.diagnostics;
import com.intellij.openapi.util.TextRange;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiFile;
import org.jetbrains.annotations.NotNull;
/**
* @author svtk
* @author abreslav
*/
public class DiagnosticWithPsiElement<T extends PsiElement> extends GenericDiagnostic {
private final T psiElement;
public DiagnosticWithPsiElement(DiagnosticFactory factory, Severity severity, String message, T psiElement) {
this(factory, severity, message, psiElement, psiElement.getTextRange());
}
public DiagnosticWithPsiElement(DiagnosticFactory factory, Severity severity, String message, T psiElement, @NotNull TextRange textRange) {
super(factory, severity, message, psiElement.getContainingFile(), textRange);
this.psiElement = psiElement;
}
public interface DiagnosticWithPsiElement<T extends PsiElement> extends DiagnosticWithTextRange {
@NotNull
public T getPsiElement() {
return psiElement;
}
T getPsiElement();
}
@@ -0,0 +1,27 @@
package org.jetbrains.jet.lang.diagnostics;
import com.intellij.openapi.util.TextRange;
import com.intellij.psi.PsiElement;
import org.jetbrains.annotations.NotNull;
/**
* @author svtk
*/
public class DiagnosticWithPsiElementImpl<T extends PsiElement> extends GenericDiagnostic implements DiagnosticWithPsiElement<T> {
private final T psiElement;
public DiagnosticWithPsiElementImpl(DiagnosticFactory factory, Severity severity, String message, T psiElement) {
this(factory, severity, message, psiElement, psiElement.getTextRange());
}
public DiagnosticWithPsiElementImpl(DiagnosticFactory factory, Severity severity, String message, T psiElement, @NotNull TextRange textRange) {
super(factory, severity, message, psiElement.getContainingFile(), textRange);
this.psiElement = psiElement;
}
@Override
@NotNull
public T getPsiElement() {
return psiElement;
}
}
@@ -46,6 +46,6 @@ public class ParameterizedDiagnosticFactory3<A, B, C> extends DiagnosticFactoryW
@NotNull
public Diagnostic on(@NotNull PsiElement element, @NotNull A a, @NotNull B b, @NotNull C c) {
return new DiagnosticWithPsiElement<PsiElement>(this, severity, makeMessage(a, b, c), element);
return new DiagnosticWithPsiElementImpl<PsiElement>(this, severity, makeMessage(a, b, c), element);
}
}
@@ -1,46 +1,79 @@
package org.jetbrains.jet.lang.diagnostics;
import com.intellij.openapi.util.TextRange;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiFile;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
import org.jetbrains.jet.lang.resolve.BindingContext;
import static org.jetbrains.jet.lang.diagnostics.Severity.ERROR;
/**
* @author abreslav
*/
public class RedeclarationDiagnostic implements Diagnostic {
* @author abreslav
*/
public interface RedeclarationDiagnostic extends DiagnosticWithPsiElement<PsiElement> {
public class SimpleRedeclarationDiagnostic extends DiagnosticWithPsiElementImpl<PsiElement> implements RedeclarationDiagnostic {
private final DeclarationDescriptor a;
private final DeclarationDescriptor b;
public RedeclarationDiagnostic(DeclarationDescriptor a, DeclarationDescriptor b) {
this.a = a;
this.b = b;
public SimpleRedeclarationDiagnostic(@NotNull PsiElement psiElement) {
super(RedeclarationDiagnosticFactory.INSTANCE, ERROR, "Redeclaration", psiElement);
}
}
public DeclarationDescriptor getA() {
return a;
public class RedeclarationDiagnosticWithDeferredResolution implements RedeclarationDiagnostic {
private final DeclarationDescriptor duplicatingDescriptor;
private final BindingContext contextToResolveToDeclaration;
private PsiElement element;
public RedeclarationDiagnosticWithDeferredResolution(@NotNull DeclarationDescriptor duplicatingDescriptor, @NotNull BindingContext contextToResolveToDeclaration) {
this.duplicatingDescriptor = duplicatingDescriptor;
this.contextToResolveToDeclaration = contextToResolveToDeclaration;
}
private PsiElement resolve() {
if (element == null) {
element = contextToResolveToDeclaration.get(BindingContext.DESCRIPTOR_TO_DECLARATION, duplicatingDescriptor);
assert element != null : "No element for descriptor: " + duplicatingDescriptor;
}
return element;
}
@NotNull
@Override
public PsiElement getPsiElement() {
return resolve();
}
@NotNull
@Override
public TextRange getTextRange() {
return resolve().getTextRange();
}
@NotNull
@Override
public PsiFile getPsiFile() {
return resolve().getContainingFile();
}
@NotNull
@Override
public DiagnosticFactory getFactory() {
return Errors.REDECLARATION;
}
@NotNull
@Override
public String getMessage() {
return "Redeclaration";
}
@NotNull
@Override
public Severity getSeverity() {
return ERROR;
}
}
public DeclarationDescriptor getB() {
return b;
}
@NotNull
@Override
public DiagnosticFactory getFactory() {
return RedeclarationDiagnosticFactory.INSTANCE;
}
@NotNull
@Override
public String getMessage() {
return "Redeclaration";
}
@NotNull
@Override
public Severity getSeverity() {
return ERROR;
}
}
@@ -1,9 +1,11 @@
package org.jetbrains.jet.lang.diagnostics;
import com.intellij.openapi.util.TextRange;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiFile;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
import org.jetbrains.jet.lang.resolve.BindingContext;
/**
* @author abreslav
@@ -14,8 +16,12 @@ public class RedeclarationDiagnosticFactory implements DiagnosticFactory {
public RedeclarationDiagnosticFactory() {}
public RedeclarationDiagnostic on(DeclarationDescriptor a, DeclarationDescriptor b) {
return new RedeclarationDiagnostic(a, b);
public RedeclarationDiagnostic on(@NotNull PsiElement duplicatingElement) {
return new RedeclarationDiagnostic.SimpleRedeclarationDiagnostic(duplicatingElement);
}
public Diagnostic on(DeclarationDescriptor duplicatingDescriptor, BindingContext contextToResolveToDeclaration) {
return new RedeclarationDiagnostic.RedeclarationDiagnosticWithDeferredResolution(duplicatingDescriptor, contextToResolveToDeclaration);
}
@NotNull
@@ -18,7 +18,7 @@ public abstract class SimpleDiagnosticFactoryWithPsiElement<T extends PsiElement
@NotNull
public Diagnostic on(@NotNull T element, @NotNull ASTNode node) {
return new DiagnosticWithPsiElement<T>(this, severity, message, element, node.getTextRange());
return new DiagnosticWithPsiElementImpl<T>(this, severity, message, element, node.getTextRange());
}
@NotNull
@@ -8,7 +8,7 @@ import static org.jetbrains.jet.lang.diagnostics.Severity.ERROR;
/**
* @author abreslav
*/
public class UnresolvedReferenceDiagnostic extends DiagnosticWithPsiElement<JetReferenceExpression> {
public class UnresolvedReferenceDiagnostic extends DiagnosticWithPsiElementImpl<JetReferenceExpression> {
public UnresolvedReferenceDiagnostic(JetReferenceExpression referenceExpression) {
super(Errors.UNRESOLVED_REFERENCE, ERROR, "Unresolved reference", referenceExpression);
@@ -69,7 +69,7 @@ public class AnalyzingUtils {
JetScope libraryScope = semanticServices.getStandardLibrary().getLibraryScope();
ModuleDescriptor owner = new ModuleDescriptor("<module>");
final WritableScope scope = new WritableScopeImpl(libraryScope, owner, bindingTraceContext).setDebugName("Root scope in analyzeNamespace");
final WritableScope scope = new WritableScopeImpl(libraryScope, owner, new TraceBasedRedeclarationHandler(bindingTraceContext)).setDebugName("Root scope in analyzeNamespace");
importingStrategy.addImports(project, semanticServices, bindingTraceContext, scope);
TopDownAnalyzer.process(semanticServices, bindingTraceContext, scope, new NamespaceLike.Adapter(owner) {
@@ -500,7 +500,7 @@ public class BodyResolver {
@NotNull
private JetScope getInnerScopeForConstructor(@NotNull ConstructorDescriptor descriptor, @NotNull JetScope declaringScope, boolean primary) {
WritableScope constructorScope = new WritableScopeImpl(declaringScope, declaringScope.getContainingDeclaration(), context.getTrace()).setDebugName("Inner scope for constructor");
WritableScope constructorScope = new WritableScopeImpl(declaringScope, declaringScope.getContainingDeclaration(), new TraceBasedRedeclarationHandler(context.getTrace())).setDebugName("Inner scope for constructor");
for (PropertyDescriptor propertyDescriptor : ((MutableClassDescriptor) descriptor.getContainingDeclaration()).getProperties()) {
constructorScope.addPropertyDescriptorByFieldName("$" + propertyDescriptor.getName(), propertyDescriptor);
}
@@ -567,7 +567,7 @@ public class BodyResolver {
}
private JetScope getPropertyDeclarationInnerScope(@NotNull JetScope outerScope, @NotNull PropertyDescriptor propertyDescriptor) {
WritableScopeImpl result = new WritableScopeImpl(outerScope, propertyDescriptor, context.getTrace()).setDebugName("Property declaration inner scope");
WritableScopeImpl result = new WritableScopeImpl(outerScope, propertyDescriptor, new TraceBasedRedeclarationHandler(context.getTrace())).setDebugName("Property declaration inner scope");
for (TypeParameterDescriptor typeParameterDescriptor : propertyDescriptor.getTypeParameters()) {
result.addTypeParameterDescriptor(typeParameterDescriptor);
}
@@ -581,7 +581,7 @@ public class BodyResolver {
private void resolvePropertyAccessors(JetProperty property, PropertyDescriptor propertyDescriptor, JetScope declaringScope) {
BindingTraceAdapter fieldAccessTrackingTrace = createFieldTrackingTrace(propertyDescriptor);
WritableScope accessorScope = new WritableScopeImpl(getPropertyDeclarationInnerScope(declaringScope, propertyDescriptor), declaringScope.getContainingDeclaration(), context.getTrace()).setDebugName("Accessor scope");
WritableScope accessorScope = new WritableScopeImpl(getPropertyDeclarationInnerScope(declaringScope, propertyDescriptor), declaringScope.getContainingDeclaration(), new TraceBasedRedeclarationHandler(context.getTrace())).setDebugName("Accessor scope");
accessorScope.addPropertyDescriptorByFieldName("$" + propertyDescriptor.getName(), propertyDescriptor);
JetPropertyAccessor getter = property.getGetter();
@@ -142,7 +142,7 @@ public class ClassDescriptorResolver {
annotationResolver.resolveAnnotations(scope, function.getModifierList()),
JetPsiUtil.safeName(function.getName())
);
WritableScope innerScope = new WritableScopeImpl(scope, functionDescriptor, trace).setDebugName("Function descriptor header scope");
WritableScope innerScope = new WritableScopeImpl(scope, functionDescriptor, new TraceBasedRedeclarationHandler(trace)).setDebugName("Function descriptor header scope");
innerScope.addLabeledDeclaration(functionDescriptor);
List<TypeParameterDescriptor> typeParameterDescriptors = resolveTypeParameters(functionDescriptor, innerScope, function.getTypeParameters());
@@ -451,7 +451,7 @@ public class ClassDescriptorResolver {
typeParameterDescriptors = Collections.emptyList();
}
else {
WritableScope writableScope = new WritableScopeImpl(scope, containingDeclaration, trace).setDebugName("Scope with type parameters of a property");
WritableScope writableScope = new WritableScopeImpl(scope, containingDeclaration, new TraceBasedRedeclarationHandler(trace)).setDebugName("Scope with type parameters of a property");
typeParameterDescriptors = resolveTypeParameters(containingDeclaration, writableScope, typeParameters);
resolveGenericBounds(property, writableScope, typeParameterDescriptors);
scopeWithTypeParameters = writableScope;
@@ -659,7 +659,7 @@ public class ClassDescriptorResolver {
typeParameters,
resolveValueParameters(
constructorDescriptor,
new WritableScopeImpl(scope, classDescriptor, trace).setDebugName("Scope with value parameters of a constructor"),
new WritableScopeImpl(scope, classDescriptor, new TraceBasedRedeclarationHandler(trace)).setDebugName("Scope with value parameters of a constructor"),
valueParameters),
Modality.FINAL);
}
@@ -0,0 +1,23 @@
package org.jetbrains.jet.lang.resolve;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
/**
* @author abreslav
*/
public interface RedeclarationHandler {
RedeclarationHandler DO_NOTHING = new RedeclarationHandler() {
@Override
public void handleRedeclaration(@NotNull DeclarationDescriptor first, @NotNull DeclarationDescriptor second) {
}
};
RedeclarationHandler THROW_EXCEPTION = new RedeclarationHandler() {
@Override
public void handleRedeclaration(@NotNull DeclarationDescriptor first, @NotNull DeclarationDescriptor second) {
throw new IllegalStateException("Redeclaration: " + first + " and " + second + "(no line info available)");
}
};
void handleRedeclaration(@NotNull DeclarationDescriptor first, @NotNull DeclarationDescriptor second);
}
@@ -0,0 +1,34 @@
package org.jetbrains.jet.lang.resolve;
import com.intellij.psi.PsiElement;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
import static org.jetbrains.jet.lang.diagnostics.Errors.REDECLARATION;
/**
* @author abreslav
*/
public class TraceBasedRedeclarationHandler implements RedeclarationHandler {
private final BindingTrace trace;
public TraceBasedRedeclarationHandler(@NotNull BindingTrace trace) {
this.trace = trace;
}
@Override
public void handleRedeclaration(@NotNull DeclarationDescriptor first, @NotNull DeclarationDescriptor second) {
report(first);
report(second);
}
private void report(DeclarationDescriptor first) {
PsiElement firstElement = trace.get(BindingContext.DESCRIPTOR_TO_DECLARATION, first);
if (firstElement != null) {
trace.report(REDECLARATION.on(firstElement));
}
else {
trace.report(REDECLARATION.on(first, trace.getBindingContext()));
}
}
}
@@ -71,13 +71,13 @@ public class TypeHierarchyResolver {
Collections.<AnnotationDescriptor>emptyList(), // TODO: annotations
name
);
namespaceDescriptor.initialize(new WritableScopeImpl(JetScope.EMPTY, namespaceDescriptor, context.getTrace()).setDebugName("Namespace member scope"));
namespaceDescriptor.initialize(new WritableScopeImpl(JetScope.EMPTY, namespaceDescriptor, new TraceBasedRedeclarationHandler(context.getTrace())).setDebugName("Namespace member scope"));
owner.addNamespace(namespaceDescriptor);
context.getTrace().record(BindingContext.NAMESPACE, namespace, namespaceDescriptor);
}
context.getNamespaceDescriptors().put(namespace, namespaceDescriptor);
WriteThroughScope namespaceScope = new WriteThroughScope(outerScope, namespaceDescriptor.getMemberScope(), context.getTrace());
WriteThroughScope namespaceScope = new WriteThroughScope(outerScope, namespaceDescriptor.getMemberScope(), new TraceBasedRedeclarationHandler(context.getTrace()));
context.getNamespaceScopes().put(namespace, namespaceScope);
processImports(namespace, namespaceScope, outerScope);
@@ -6,13 +6,10 @@ 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.diagnostics.DiagnosticHolder;
import org.jetbrains.jet.lang.types.JetType;
import java.util.*;
import static org.jetbrains.jet.lang.diagnostics.Errors.REDECLARATION;
/**
* @author abreslav
*/
@@ -40,8 +37,8 @@ public class WritableScopeImpl extends WritableScopeWithImports {
private List<VariableDescriptor> variableDescriptors;
public WritableScopeImpl(@NotNull JetScope scope, @NotNull DeclarationDescriptor owner, @NotNull DiagnosticHolder diagnosticHolder) {
super(scope, diagnosticHolder);
public WritableScopeImpl(@NotNull JetScope scope, @NotNull DeclarationDescriptor owner, @NotNull RedeclarationHandler redeclarationHandler) {
super(scope, redeclarationHandler);
this.ownerDeclarationDescriptor = owner;
}
@@ -139,7 +136,7 @@ public class WritableScopeImpl extends WritableScopeWithImports {
Map<String, DeclarationDescriptor> variableClassOrNamespaceDescriptors = getVariableClassOrNamespaceDescriptors();
DeclarationDescriptor existingDescriptor = variableClassOrNamespaceDescriptors.get(variableDescriptor.getName());
if (existingDescriptor != null) {
diagnosticHolder.report(REDECLARATION.on(existingDescriptor, variableDescriptor));
redeclarationHandler.handleRedeclaration(existingDescriptor, variableDescriptor);
}
// TODO : Should this always happen?
variableClassOrNamespaceDescriptors.put(variableDescriptor.getName(), variableDescriptor);
@@ -230,7 +227,7 @@ public class WritableScopeImpl extends WritableScopeWithImports {
Map<String, DeclarationDescriptor> variableClassOrNamespaceDescriptors = getVariableClassOrNamespaceDescriptors();
DeclarationDescriptor originalDescriptor = variableClassOrNamespaceDescriptors.get(name);
if (originalDescriptor != null) {
diagnosticHolder.report(REDECLARATION.on(originalDescriptor, classifierDescriptor));
redeclarationHandler.handleRedeclaration(originalDescriptor, classifierDescriptor);
}
variableClassOrNamespaceDescriptors.put(name, classifierDescriptor);
allDescriptors.add(classifierDescriptor);
@@ -262,7 +259,7 @@ public class WritableScopeImpl extends WritableScopeWithImports {
Map<String, DeclarationDescriptor> variableClassOrNamespaceDescriptors = getVariableClassOrNamespaceDescriptors();
DeclarationDescriptor oldValue = variableClassOrNamespaceDescriptors.put(namespaceDescriptor.getName(), namespaceDescriptor);
if (oldValue != null) {
diagnosticHolder.report(REDECLARATION.on(oldValue, namespaceDescriptor));
redeclarationHandler.handleRedeclaration(oldValue, namespaceDescriptor);
}
allDescriptors.add(namespaceDescriptor);
}
@@ -3,7 +3,6 @@ package org.jetbrains.jet.lang.resolve;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.lang.descriptors.*;
import org.jetbrains.jet.lang.diagnostics.DiagnosticHolder;
import java.util.ArrayList;
import java.util.List;
@@ -18,11 +17,11 @@ public abstract class WritableScopeWithImports extends JetScopeAdapter implement
@Nullable
private List<JetScope> imports;
private WritableScope currentIndividualImportScope;
protected final DiagnosticHolder diagnosticHolder;
protected final RedeclarationHandler redeclarationHandler;
public WritableScopeWithImports(@NotNull JetScope scope, @NotNull DiagnosticHolder diagnosticHolder) {
public WritableScopeWithImports(@NotNull JetScope scope, @NotNull RedeclarationHandler redeclarationHandler) {
super(scope);
this.diagnosticHolder = diagnosticHolder;
this.redeclarationHandler = redeclarationHandler;
}
public WritableScopeWithImports setDebugName(@NotNull String debugName) {
@@ -97,7 +96,7 @@ public abstract class WritableScopeWithImports extends JetScopeAdapter implement
public void importClassifierAlias(@NotNull String importedClassifierName, @NotNull ClassifierDescriptor classifierDescriptor) {
if (currentIndividualImportScope == null) {
WritableScopeImpl writableScope = new WritableScopeImpl(JetScope.EMPTY, getContainingDeclaration(), DiagnosticHolder.DO_NOTHING).setDebugName("Individual import scope");
WritableScopeImpl writableScope = new WritableScopeImpl(JetScope.EMPTY, getContainingDeclaration(), RedeclarationHandler.DO_NOTHING).setDebugName("Individual import scope");
importScope(writableScope);
currentIndividualImportScope = writableScope;
}
@@ -4,7 +4,6 @@ import com.google.common.collect.Lists;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.lang.descriptors.*;
import org.jetbrains.jet.lang.diagnostics.DiagnosticHolder;
import org.jetbrains.jet.lang.types.JetType;
import java.util.Collection;
@@ -16,8 +15,8 @@ public class WriteThroughScope extends WritableScopeWithImports {
private final WritableScope writableWorker;
private Collection<DeclarationDescriptor> allDescriptors;
public WriteThroughScope(@NotNull JetScope outerScope, @NotNull WritableScope scope, @NotNull DiagnosticHolder diagnosticHolder) {
super(outerScope, diagnosticHolder);
public WriteThroughScope(@NotNull JetScope outerScope, @NotNull WritableScope scope, @NotNull RedeclarationHandler redeclarationHandler) {
super(outerScope, redeclarationHandler);
this.writableWorker = scope;
}
@@ -6,11 +6,7 @@ import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.lang.descriptors.*;
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
import org.jetbrains.jet.lang.diagnostics.DiagnosticHolder;
import org.jetbrains.jet.lang.resolve.JetScope;
import org.jetbrains.jet.lang.resolve.JetScopeImpl;
import org.jetbrains.jet.lang.resolve.WritableScope;
import org.jetbrains.jet.lang.resolve.WritableScopeImpl;
import org.jetbrains.jet.lang.resolve.*;
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
@@ -198,7 +194,7 @@ public class JetStandardClasses {
/*package*/ static final JetScope STANDARD_CLASSES;
static {
WritableScope writableScope = new WritableScopeImpl(JetScope.EMPTY, STANDARD_CLASSES_NAMESPACE, DiagnosticHolder.DO_NOTHING).setDebugName("JetStandardClasses.STANDARD_CLASSES");
WritableScope writableScope = new WritableScopeImpl(JetScope.EMPTY, STANDARD_CLASSES_NAMESPACE, RedeclarationHandler.DO_NOTHING).setDebugName("JetStandardClasses.STANDARD_CLASSES");
STANDARD_CLASSES = writableScope;
writableScope.addClassifierAlias("Unit", getTuple(0));
@@ -9,7 +9,6 @@ import org.jetbrains.jet.lang.descriptors.ClassDescriptor;
import org.jetbrains.jet.lang.descriptors.FunctionGroup;
import org.jetbrains.jet.lang.descriptors.NamespaceDescriptor;
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
import org.jetbrains.jet.lang.diagnostics.DiagnosticHolder;
import org.jetbrains.jet.lang.psi.JetFile;
import org.jetbrains.jet.lang.resolve.*;
import org.jetbrains.jet.plugin.JetFileType;
@@ -99,7 +98,7 @@ public class JetStandardLibrary {
JetSemanticServices bootstrappingSemanticServices = JetSemanticServices.createSemanticServices(this);
BindingTraceContext bindingTraceContext = new BindingTraceContext();
WritableScopeImpl writableScope = new WritableScopeImpl(JetStandardClasses.STANDARD_CLASSES, JetStandardClasses.STANDARD_CLASSES_NAMESPACE, DiagnosticHolder.THROW_EXCEPTION).setDebugName("Root bootstrap scope");
WritableScopeImpl writableScope = new WritableScopeImpl(JetStandardClasses.STANDARD_CLASSES, JetStandardClasses.STANDARD_CLASSES_NAMESPACE, RedeclarationHandler.THROW_EXCEPTION).setDebugName("Root bootstrap scope");
// this.libraryScope = bootstrappingTDA.process(JetStandardClasses.STANDARD_CLASSES, file.getRootNamespace().getDeclarations());
// bootstrappingTDA.process(writableScope, JetStandardClasses.STANDARD_CLASSES_NAMESPACE, file.getRootNamespace().getDeclarations());
TopDownAnalyzer.processStandardLibraryNamespace(bootstrappingSemanticServices, bindingTraceContext, writableScope, JetStandardClasses.STANDARD_CLASSES_NAMESPACE, file.getRootNamespace());
@@ -367,7 +367,7 @@ public class JetTypeInferrer {
}
DeclarationDescriptor containingDescriptor = outerScope.getContainingDeclaration();
WritableScope scope = new WritableScopeImpl(outerScope, containingDescriptor, context.trace).setDebugName("getBlockReturnedType");
WritableScope scope = new WritableScopeImpl(outerScope, containingDescriptor, new TraceBasedRedeclarationHandler(context.trace)).setDebugName("getBlockReturnedType");
return getBlockReturnedTypeWithWritableScope(scope, block, coercionStrategyForLastExpression, context);
}
@@ -1814,7 +1814,7 @@ public class JetTypeInferrer {
}
protected WritableScopeImpl newWritableScopeImpl(JetScope scope, BindingTrace trace) {
return new WritableScopeImpl(scope, scope.getContainingDeclaration(), trace);
return new WritableScopeImpl(scope, scope.getContainingDeclaration(), new TraceBasedRedeclarationHandler(trace));
}
@Override
@@ -13,7 +13,6 @@ import com.intellij.psi.MultiRangeReference;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiReference;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
import org.jetbrains.jet.lang.descriptors.PropertyDescriptor;
import org.jetbrains.jet.lang.descriptors.VariableDescriptor;
import org.jetbrains.jet.lang.diagnostics.*;
@@ -52,7 +51,7 @@ public class JetPsiChecker implements Annotator {
if (errorReportingEnabled) {
Collection<Diagnostic> diagnostics = bindingContext.getDiagnostics();
Set<DeclarationDescriptor> redeclarations = Sets.newHashSet();
Set<PsiElement> redeclarations = Sets.newHashSet();
for (Diagnostic diagnostic : diagnostics) {
Annotation annotation = null;
if (diagnostic.getSeverity() == Severity.ERROR) {
@@ -72,8 +71,7 @@ public class JetPsiChecker implements Annotator {
}
else if (diagnostic instanceof RedeclarationDiagnostic) {
RedeclarationDiagnostic redeclarationDiagnostic = (RedeclarationDiagnostic) diagnostic;
markRedeclaration(redeclarations, redeclarationDiagnostic.getA(), bindingContext, holder);
markRedeclaration(redeclarations, redeclarationDiagnostic.getB(), bindingContext, holder);
markRedeclaration(redeclarations, redeclarationDiagnostic.getPsiElement(), holder);
}
else {
annotation = holder.createErrorAnnotation(diagnostic.getFactory().getTextRange(diagnostic), getMessage(diagnostic));
@@ -82,7 +80,7 @@ public class JetPsiChecker implements Annotator {
else if (diagnostic.getSeverity() == Severity.WARNING) {
annotation = holder.createWarningAnnotation(diagnostic.getFactory().getTextRange(diagnostic), getMessage(diagnostic));
}
if (annotation != null && diagnostic instanceof DiagnosticWithPsiElement) {
if (annotation != null && diagnostic instanceof DiagnosticWithPsiElementImpl) {
DiagnosticWithPsiElement diagnosticWithPsiElement = (DiagnosticWithPsiElement) diagnostic;
if (diagnostic.getFactory() instanceof PsiElementOnlyDiagnosticFactory) {
PsiElementOnlyDiagnosticFactory factory = (PsiElementOnlyDiagnosticFactory) diagnostic.getFactory();
@@ -135,17 +133,16 @@ public class JetPsiChecker implements Annotator {
return diagnostic.getMessage();
}
private void markRedeclaration(Set<DeclarationDescriptor> redeclarations, DeclarationDescriptor redeclaration, BindingContext bindingContext, AnnotationHolder holder) {
private void markRedeclaration(Set<PsiElement> redeclarations, @NotNull PsiElement redeclaration, AnnotationHolder holder) {
if (!redeclarations.add(redeclaration)) return;
PsiElement declarationPsiElement = bindingContext.get(BindingContext.DESCRIPTOR_TO_DECLARATION, redeclaration);
if (declarationPsiElement instanceof JetNamedDeclaration) {
PsiElement nameIdentifier = ((JetNamedDeclaration) declarationPsiElement).getNameIdentifier();
if (redeclaration instanceof JetNamedDeclaration) {
PsiElement nameIdentifier = ((JetNamedDeclaration) redeclaration).getNameIdentifier();
if (nameIdentifier != null) {
holder.createErrorAnnotation(nameIdentifier, "Redeclaration");
}
}
else if (declarationPsiElement != null) {
holder.createErrorAnnotation(declarationPsiElement, "Redeclaration");
else {
holder.createErrorAnnotation(redeclaration, "Redeclaration");
}
}
@@ -13,7 +13,6 @@ import org.jetbrains.jet.lang.JetSemanticServices;
import org.jetbrains.jet.lang.cfg.JetFlowInformationProvider;
import org.jetbrains.jet.lang.descriptors.*;
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
import org.jetbrains.jet.lang.diagnostics.DiagnosticHolder;
import org.jetbrains.jet.lang.psi.*;
import org.jetbrains.jet.lang.resolve.*;
import org.jetbrains.jet.lang.resolve.java.JavaPackageScope;
@@ -527,7 +526,7 @@ public class JetTypeCheckerTest extends LightDaemonAnalyzerTestCase {
}
private WritableScopeImpl addImports(JetScope scope) {
WritableScopeImpl writableScope = new WritableScopeImpl(scope, scope.getContainingDeclaration(), DiagnosticHolder.DO_NOTHING);
WritableScopeImpl writableScope = new WritableScopeImpl(scope, scope.getContainingDeclaration(), RedeclarationHandler.DO_NOTHING);
writableScope.importScope(library.getLibraryScope());
JavaSemanticServices javaSemanticServices = new JavaSemanticServices(getProject(), semanticServices, JetTestUtils.DUMMY_TRACE);
writableScope.importScope(new JavaPackageScope("", null, javaSemanticServices));
@@ -637,7 +636,7 @@ public class JetTypeCheckerTest extends LightDaemonAnalyzerTestCase {
trace.record(BindingContext.CLASS, classElement, classDescriptor);
final WritableScope parameterScope = new WritableScopeImpl(scope, classDescriptor, trace);
final WritableScope parameterScope = new WritableScopeImpl(scope, classDescriptor, new TraceBasedRedeclarationHandler(trace));
// This call has side-effects on the parameterScope (fills it in)
List<TypeParameterDescriptor> typeParameters
@@ -656,7 +655,7 @@ public class JetTypeCheckerTest extends LightDaemonAnalyzerTestCase {
// }
boolean open = classElement.hasModifier(JetTokens.OPEN_KEYWORD);
final WritableScope memberDeclarations = new WritableScopeImpl(JetScope.EMPTY, classDescriptor, trace);
final WritableScope memberDeclarations = new WritableScopeImpl(JetScope.EMPTY, classDescriptor, new TraceBasedRedeclarationHandler(trace));
List<JetDeclaration> declarations = classElement.getDeclarations();
for (JetDeclaration declaration : declarations) {