store namespace kind in trace, kill some JavaNamespaceDescriptor usages
JavaNamespaceDescriptor will be killed soon
This commit is contained in:
@@ -27,6 +27,7 @@ import org.jetbrains.jet.lang.descriptors.*;
|
|||||||
import org.jetbrains.jet.lang.psi.*;
|
import org.jetbrains.jet.lang.psi.*;
|
||||||
import org.jetbrains.jet.lang.resolve.BindingContext;
|
import org.jetbrains.jet.lang.resolve.BindingContext;
|
||||||
import org.jetbrains.jet.lang.resolve.DescriptorUtils;
|
import org.jetbrains.jet.lang.resolve.DescriptorUtils;
|
||||||
|
import org.jetbrains.jet.lang.resolve.FqName;
|
||||||
import org.jetbrains.jet.lang.resolve.java.*;
|
import org.jetbrains.jet.lang.resolve.java.*;
|
||||||
import org.jetbrains.jet.lang.resolve.scopes.receivers.ReceiverDescriptor;
|
import org.jetbrains.jet.lang.resolve.scopes.receivers.ReceiverDescriptor;
|
||||||
import org.jetbrains.jet.lang.types.*;
|
import org.jetbrains.jet.lang.types.*;
|
||||||
@@ -112,11 +113,8 @@ public class JetTypeMapper {
|
|||||||
public String getOwner(DeclarationDescriptor descriptor, OwnerKind kind) {
|
public String getOwner(DeclarationDescriptor descriptor, OwnerKind kind) {
|
||||||
String owner;
|
String owner;
|
||||||
DeclarationDescriptor containingDeclaration = descriptor.getContainingDeclaration();
|
DeclarationDescriptor containingDeclaration = descriptor.getContainingDeclaration();
|
||||||
if (containingDeclaration instanceof JavaNamespaceDescriptor) {
|
if (containingDeclaration instanceof NamespaceDescriptor) {
|
||||||
JavaNamespaceDescriptor javaNamespaceDescriptor = (JavaNamespaceDescriptor) containingDeclaration;
|
owner = jvmClassNameForNamespace((NamespaceDescriptor) containingDeclaration);
|
||||||
owner = NamespaceCodegen.getJVMClassName(DescriptorUtils.getFQName(containingDeclaration).toSafe(), javaNamespaceDescriptor.isNamespace());
|
|
||||||
} else if (containingDeclaration instanceof NamespaceDescriptor) {
|
|
||||||
owner = NamespaceCodegen.getJVMClassName(DescriptorUtils.getFQName(containingDeclaration).toSafe(), true);
|
|
||||||
}
|
}
|
||||||
else if (containingDeclaration instanceof ClassDescriptor) {
|
else if (containingDeclaration instanceof ClassDescriptor) {
|
||||||
ClassDescriptor classDescriptor = (ClassDescriptor) containingDeclaration;
|
ClassDescriptor classDescriptor = (ClassDescriptor) containingDeclaration;
|
||||||
@@ -140,6 +138,29 @@ public class JetTypeMapper {
|
|||||||
return owner;
|
return owner;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private String jvmClassNameForNamespace(NamespaceDescriptor namespace) {
|
||||||
|
FqName fqName = DescriptorUtils.getFQName(namespace).toSafe();
|
||||||
|
Boolean javaClassStatics = bindingContext.get(JavaBindingContext.NAMESPACE_IS_CLASS_STATICS, namespace);
|
||||||
|
Boolean src = bindingContext.get(BindingContext.NAMESPACE_IS_SRC, namespace);
|
||||||
|
|
||||||
|
if (javaClassStatics == null && src == null) {
|
||||||
|
throw new IllegalStateException("unknown namespace origin: " + fqName);
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean classStatics;
|
||||||
|
if (javaClassStatics != null) {
|
||||||
|
if (javaClassStatics.booleanValue() && src != null) {
|
||||||
|
throw new IllegalStateException(
|
||||||
|
"conflicting namespace " + fqName + ": it is both java statics and from src");
|
||||||
|
}
|
||||||
|
classStatics = javaClassStatics.booleanValue();
|
||||||
|
} else {
|
||||||
|
classStatics = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return NamespaceCodegen.getJVMClassName(fqName, !classStatics);
|
||||||
|
}
|
||||||
|
|
||||||
@NotNull public Type mapReturnType(@NotNull final JetType jetType) {
|
@NotNull public Type mapReturnType(@NotNull final JetType jetType) {
|
||||||
return mapReturnType(jetType, null);
|
return mapReturnType(jetType, null);
|
||||||
}
|
}
|
||||||
@@ -218,12 +239,9 @@ public class JetTypeMapper {
|
|||||||
if (container instanceof ModuleDescriptor) {
|
if (container instanceof ModuleDescriptor) {
|
||||||
throw new IllegalStateException("missed something");
|
throw new IllegalStateException("missed something");
|
||||||
}
|
}
|
||||||
if(container instanceof JavaNamespaceDescriptor && JavaDescriptorResolver.JAVA_ROOT.equals(container.getName())) {
|
|
||||||
return name;
|
|
||||||
}
|
|
||||||
String baseName = getFQName(container);
|
String baseName = getFQName(container);
|
||||||
if (!baseName.isEmpty()) {
|
if (!baseName.isEmpty()) {
|
||||||
return baseName + (container instanceof JavaNamespaceDescriptor || container instanceof NamespaceDescriptor ? "/" : "$") + name;
|
return baseName + (container instanceof NamespaceDescriptor ? "/" : "$") + name;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -391,11 +409,7 @@ public class JetTypeMapper {
|
|||||||
ClassDescriptor thisClass;
|
ClassDescriptor thisClass;
|
||||||
if (functionParent instanceof NamespaceDescriptor) {
|
if (functionParent instanceof NamespaceDescriptor) {
|
||||||
assert !superCall;
|
assert !superCall;
|
||||||
boolean namespace = true;
|
owner = jvmClassNameForNamespace((NamespaceDescriptor) functionParent);
|
||||||
if (functionParent instanceof JavaNamespaceDescriptor) {
|
|
||||||
namespace = ((JavaNamespaceDescriptor) functionParent).isNamespace();
|
|
||||||
}
|
|
||||||
owner = NamespaceCodegen.getJVMClassName(DescriptorUtils.getFQName(functionParent).toSafe(), namespace);
|
|
||||||
ownerForDefaultImpl = ownerForDefaultParam = owner;
|
ownerForDefaultImpl = ownerForDefaultParam = owner;
|
||||||
invokeOpcode = INVOKESTATIC;
|
invokeOpcode = INVOKESTATIC;
|
||||||
thisClass = null;
|
thisClass = null;
|
||||||
|
|||||||
@@ -55,6 +55,7 @@ public class InjectorForJavaSemanticServices {
|
|||||||
this.javaDescriptorResolver.setNamespaceFactory(namespaceFactoryImpl);
|
this.javaDescriptorResolver.setNamespaceFactory(namespaceFactoryImpl);
|
||||||
this.javaDescriptorResolver.setProject(project);
|
this.javaDescriptorResolver.setProject(project);
|
||||||
this.javaDescriptorResolver.setSemanticServices(javaSemanticServices);
|
this.javaDescriptorResolver.setSemanticServices(javaSemanticServices);
|
||||||
|
this.javaDescriptorResolver.setTrace(bindingTrace);
|
||||||
|
|
||||||
javaBridgeConfiguration.setJavaSemanticServices(javaSemanticServices);
|
javaBridgeConfiguration.setJavaSemanticServices(javaSemanticServices);
|
||||||
javaBridgeConfiguration.setProject(project);
|
javaBridgeConfiguration.setProject(project);
|
||||||
|
|||||||
@@ -190,6 +190,7 @@ public class InjectorForTopDownAnalyzerForJvm {
|
|||||||
javaDescriptorResolver.setNamespaceFactory(namespaceFactoryImpl);
|
javaDescriptorResolver.setNamespaceFactory(namespaceFactoryImpl);
|
||||||
javaDescriptorResolver.setProject(project);
|
javaDescriptorResolver.setProject(project);
|
||||||
javaDescriptorResolver.setSemanticServices(javaSemanticServices);
|
javaDescriptorResolver.setSemanticServices(javaSemanticServices);
|
||||||
|
javaDescriptorResolver.setTrace(observableBindingTrace);
|
||||||
|
|
||||||
javaTypeTransformer.setJavaSemanticServices(javaSemanticServices);
|
javaTypeTransformer.setJavaSemanticServices(javaSemanticServices);
|
||||||
javaTypeTransformer.setResolver(javaDescriptorResolver);
|
javaTypeTransformer.setResolver(javaDescriptorResolver);
|
||||||
|
|||||||
+37
@@ -0,0 +1,37 @@
|
|||||||
|
/*
|
||||||
|
* 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.
|
||||||
|
* 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.java;
|
||||||
|
|
||||||
|
import org.jetbrains.jet.lang.descriptors.NamespaceDescriptor;
|
||||||
|
import org.jetbrains.jet.lang.resolve.BindingContext;
|
||||||
|
import org.jetbrains.jet.util.slicedmap.Slices;
|
||||||
|
import org.jetbrains.jet.util.slicedmap.WritableSlice;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Stepan Koltsov
|
||||||
|
*
|
||||||
|
* @see BindingContext
|
||||||
|
*/
|
||||||
|
public class JavaBindingContext {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see BindingContext#NAMESPACE_IS_SRC
|
||||||
|
*/
|
||||||
|
public static final WritableSlice<NamespaceDescriptor, Boolean> NAMESPACE_IS_CLASS_STATICS =
|
||||||
|
Slices.createSimpleSlice();
|
||||||
|
|
||||||
|
}
|
||||||
+3
@@ -905,6 +905,7 @@ public class JavaDescriptorResolver {
|
|||||||
name == null ? FqName.ROOT : new FqName(psiPackage.getQualifiedName()),
|
name == null ? FqName.ROOT : new FqName(psiPackage.getQualifiedName()),
|
||||||
true
|
true
|
||||||
);
|
);
|
||||||
|
trace.record(JavaBindingContext.NAMESPACE_IS_CLASS_STATICS, namespaceData.namespaceDescriptor, false);
|
||||||
|
|
||||||
namespaceData.namespaceDescriptor.setMemberScope(createJavaPackageScope(new FqName(psiPackage.getQualifiedName()), namespaceData.namespaceDescriptor));
|
namespaceData.namespaceDescriptor.setMemberScope(createJavaPackageScope(new FqName(psiPackage.getQualifiedName()), namespaceData.namespaceDescriptor));
|
||||||
trace.record(BindingContext.NAMESPACE, psiPackage, namespaceData.namespaceDescriptor);
|
trace.record(BindingContext.NAMESPACE, psiPackage, namespaceData.namespaceDescriptor);
|
||||||
@@ -942,6 +943,8 @@ public class JavaDescriptorResolver {
|
|||||||
new FqName(psiClass.getQualifiedName()),
|
new FqName(psiClass.getQualifiedName()),
|
||||||
false
|
false
|
||||||
);
|
);
|
||||||
|
trace.record(JavaBindingContext.NAMESPACE_IS_CLASS_STATICS, namespaceData.namespaceDescriptor, true);
|
||||||
|
|
||||||
namespaceData.namespaceDescriptor.setMemberScope(new JavaClassMembersScope(namespaceData.namespaceDescriptor, psiClass, semanticServices, true));
|
namespaceData.namespaceDescriptor.setMemberScope(new JavaClassMembersScope(namespaceData.namespaceDescriptor, psiClass, semanticServices, true));
|
||||||
trace.record(BindingContext.NAMESPACE, psiClass, namespaceData.namespaceDescriptor);
|
trace.record(BindingContext.NAMESPACE, psiClass, namespaceData.namespaceDescriptor);
|
||||||
return namespaceData;
|
return namespaceData;
|
||||||
|
|||||||
@@ -174,6 +174,11 @@ public interface BindingContext {
|
|||||||
WritableSlice<FqName, ClassDescriptor> FQNAME_TO_CLASS_DESCRIPTOR = new BasicWritableSlice<FqName, ClassDescriptor>(DO_NOTHING, true);
|
WritableSlice<FqName, ClassDescriptor> FQNAME_TO_CLASS_DESCRIPTOR = new BasicWritableSlice<FqName, ClassDescriptor>(DO_NOTHING, true);
|
||||||
WritableSlice<FqName, NamespaceDescriptor> FQNAME_TO_NAMESPACE_DESCRIPTOR = new BasicWritableSlice<FqName, NamespaceDescriptor>(DO_NOTHING);
|
WritableSlice<FqName, NamespaceDescriptor> FQNAME_TO_NAMESPACE_DESCRIPTOR = new BasicWritableSlice<FqName, NamespaceDescriptor>(DO_NOTHING);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Each namespace found in src must be registered here.
|
||||||
|
*/
|
||||||
|
WritableSlice<NamespaceDescriptor, Boolean> NAMESPACE_IS_SRC = Slices.createSimpleSlice();
|
||||||
|
|
||||||
WritableSlice<ClassDescriptor, Boolean> INCOMPLETE_HIERARCHY = Slices.createCollectiveSetSlice();
|
WritableSlice<ClassDescriptor, Boolean> INCOMPLETE_HIERARCHY = Slices.createCollectiveSetSlice();
|
||||||
|
|
||||||
@SuppressWarnings("UnusedDeclaration")
|
@SuppressWarnings("UnusedDeclaration")
|
||||||
|
|||||||
@@ -80,6 +80,7 @@ public class NamespaceFactoryImpl implements NamespaceFactory {
|
|||||||
String namespaceName = JetPsiUtil.safeName(nameExpression.getReferencedName());
|
String namespaceName = JetPsiUtil.safeName(nameExpression.getReferencedName());
|
||||||
|
|
||||||
NamespaceDescriptorImpl namespaceDescriptor = createNamespaceDescriptorIfNeeded(null, currentOwner, namespaceName, false);
|
NamespaceDescriptorImpl namespaceDescriptor = createNamespaceDescriptorIfNeeded(null, currentOwner, namespaceName, false);
|
||||||
|
trace.record(BindingContext.NAMESPACE_IS_SRC, namespaceDescriptor, true);
|
||||||
|
|
||||||
currentOwner = namespaceDescriptor;
|
currentOwner = namespaceDescriptor;
|
||||||
|
|
||||||
@@ -92,7 +93,10 @@ public class NamespaceFactoryImpl implements NamespaceFactory {
|
|||||||
String name = JetPsiUtil.safeName(namespaceHeader.getName());
|
String name = JetPsiUtil.safeName(namespaceHeader.getName());
|
||||||
trace.record(RESOLUTION_SCOPE, namespaceHeader, outerScope);
|
trace.record(RESOLUTION_SCOPE, namespaceHeader, outerScope);
|
||||||
|
|
||||||
return createNamespaceDescriptorIfNeeded(file, currentOwner, name, false);
|
NamespaceDescriptorImpl namespaceDescriptor = createNamespaceDescriptorIfNeeded(file, currentOwner, name, false);
|
||||||
|
trace.record(BindingContext.NAMESPACE_IS_SRC, namespaceDescriptor, true);
|
||||||
|
|
||||||
|
return namespaceDescriptor;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -19,23 +19,9 @@ package org.jetbrains.jet.compiler;
|
|||||||
import com.google.common.io.Files;
|
import com.google.common.io.Files;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.jet.codegen.PropertyCodegen;
|
import org.jetbrains.jet.codegen.PropertyCodegen;
|
||||||
import org.jetbrains.jet.lang.descriptors.ClassDescriptor;
|
import org.jetbrains.jet.lang.descriptors.*;
|
||||||
import org.jetbrains.jet.lang.descriptors.ClassKind;
|
|
||||||
import org.jetbrains.jet.lang.descriptors.ClassifierDescriptor;
|
|
||||||
import org.jetbrains.jet.lang.descriptors.ConstructorDescriptor;
|
|
||||||
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
|
|
||||||
import org.jetbrains.jet.lang.descriptors.FunctionDescriptor;
|
|
||||||
import org.jetbrains.jet.lang.descriptors.Modality;
|
|
||||||
import org.jetbrains.jet.lang.descriptors.ModuleDescriptor;
|
|
||||||
import org.jetbrains.jet.lang.descriptors.NamespaceDescriptor;
|
|
||||||
import org.jetbrains.jet.lang.descriptors.PropertyDescriptor;
|
|
||||||
import org.jetbrains.jet.lang.descriptors.TypeParameterDescriptor;
|
|
||||||
import org.jetbrains.jet.lang.descriptors.ValueParameterDescriptor;
|
|
||||||
import org.jetbrains.jet.lang.descriptors.VariableDescriptor;
|
|
||||||
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
|
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
|
||||||
import org.jetbrains.jet.lang.resolve.DescriptorUtils;
|
import org.jetbrains.jet.lang.resolve.DescriptorUtils;
|
||||||
import org.jetbrains.jet.lang.resolve.java.JavaDescriptorResolver;
|
|
||||||
import org.jetbrains.jet.lang.resolve.java.JavaNamespaceDescriptor;
|
|
||||||
import org.jetbrains.jet.lang.resolve.scopes.JetScope;
|
import org.jetbrains.jet.lang.resolve.scopes.JetScope;
|
||||||
import org.jetbrains.jet.lang.resolve.scopes.receivers.ExtensionReceiver;
|
import org.jetbrains.jet.lang.resolve.scopes.receivers.ExtensionReceiver;
|
||||||
import org.jetbrains.jet.lang.types.JetType;
|
import org.jetbrains.jet.lang.types.JetType;
|
||||||
@@ -43,16 +29,13 @@ import org.jetbrains.jet.lang.types.TypeProjection;
|
|||||||
import org.jetbrains.jet.lang.types.Variance;
|
import org.jetbrains.jet.lang.types.Variance;
|
||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.BufferedReader;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.StringReader;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.nio.charset.Charset;
|
import java.nio.charset.Charset;
|
||||||
import java.util.ArrayList;
|
import java.util.*;
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.Comparator;
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Stepan Koltsov
|
* @author Stepan Koltsov
|
||||||
@@ -457,8 +440,7 @@ class NamespaceComparator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static boolean isRootNs(DeclarationDescriptor ns) {
|
private static boolean isRootNs(DeclarationDescriptor ns) {
|
||||||
// upyachka
|
return ns instanceof NamespaceDescriptor && ns.getContainingDeclaration() instanceof ModuleDescriptor;
|
||||||
return ns instanceof JavaNamespaceDescriptor && JavaDescriptorResolver.JAVA_ROOT.equals(ns.getName());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class NamespacePrefixSerializer extends Serializer {
|
private static class NamespacePrefixSerializer extends Serializer {
|
||||||
|
|||||||
Reference in New Issue
Block a user