store namespace kind in trace, kill some JavaNamespaceDescriptor usages

JavaNamespaceDescriptor will be killed soon
This commit is contained in:
Stepan Koltsov
2012-03-23 23:44:16 +04:00
parent f73b2c01b4
commit 8517fe6878
8 changed files with 87 additions and 40 deletions
@@ -27,6 +27,7 @@ import org.jetbrains.jet.lang.descriptors.*;
import org.jetbrains.jet.lang.psi.*;
import org.jetbrains.jet.lang.resolve.BindingContext;
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.scopes.receivers.ReceiverDescriptor;
import org.jetbrains.jet.lang.types.*;
@@ -112,11 +113,8 @@ public class JetTypeMapper {
public String getOwner(DeclarationDescriptor descriptor, OwnerKind kind) {
String owner;
DeclarationDescriptor containingDeclaration = descriptor.getContainingDeclaration();
if (containingDeclaration instanceof JavaNamespaceDescriptor) {
JavaNamespaceDescriptor javaNamespaceDescriptor = (JavaNamespaceDescriptor) containingDeclaration;
owner = NamespaceCodegen.getJVMClassName(DescriptorUtils.getFQName(containingDeclaration).toSafe(), javaNamespaceDescriptor.isNamespace());
} else if (containingDeclaration instanceof NamespaceDescriptor) {
owner = NamespaceCodegen.getJVMClassName(DescriptorUtils.getFQName(containingDeclaration).toSafe(), true);
if (containingDeclaration instanceof NamespaceDescriptor) {
owner = jvmClassNameForNamespace((NamespaceDescriptor) containingDeclaration);
}
else if (containingDeclaration instanceof ClassDescriptor) {
ClassDescriptor classDescriptor = (ClassDescriptor) containingDeclaration;
@@ -140,6 +138,29 @@ public class JetTypeMapper {
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) {
return mapReturnType(jetType, null);
}
@@ -218,12 +239,9 @@ public class JetTypeMapper {
if (container instanceof ModuleDescriptor) {
throw new IllegalStateException("missed something");
}
if(container instanceof JavaNamespaceDescriptor && JavaDescriptorResolver.JAVA_ROOT.equals(container.getName())) {
return name;
}
String baseName = getFQName(container);
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;
if (functionParent instanceof NamespaceDescriptor) {
assert !superCall;
boolean namespace = true;
if (functionParent instanceof JavaNamespaceDescriptor) {
namespace = ((JavaNamespaceDescriptor) functionParent).isNamespace();
}
owner = NamespaceCodegen.getJVMClassName(DescriptorUtils.getFQName(functionParent).toSafe(), namespace);
owner = jvmClassNameForNamespace((NamespaceDescriptor) functionParent);
ownerForDefaultImpl = ownerForDefaultParam = owner;
invokeOpcode = INVOKESTATIC;
thisClass = null;
@@ -55,6 +55,7 @@ public class InjectorForJavaSemanticServices {
this.javaDescriptorResolver.setNamespaceFactory(namespaceFactoryImpl);
this.javaDescriptorResolver.setProject(project);
this.javaDescriptorResolver.setSemanticServices(javaSemanticServices);
this.javaDescriptorResolver.setTrace(bindingTrace);
javaBridgeConfiguration.setJavaSemanticServices(javaSemanticServices);
javaBridgeConfiguration.setProject(project);
@@ -190,6 +190,7 @@ public class InjectorForTopDownAnalyzerForJvm {
javaDescriptorResolver.setNamespaceFactory(namespaceFactoryImpl);
javaDescriptorResolver.setProject(project);
javaDescriptorResolver.setSemanticServices(javaSemanticServices);
javaDescriptorResolver.setTrace(observableBindingTrace);
javaTypeTransformer.setJavaSemanticServices(javaSemanticServices);
javaTypeTransformer.setResolver(javaDescriptorResolver);
@@ -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();
}
@@ -905,6 +905,7 @@ public class JavaDescriptorResolver {
name == null ? FqName.ROOT : new FqName(psiPackage.getQualifiedName()),
true
);
trace.record(JavaBindingContext.NAMESPACE_IS_CLASS_STATICS, namespaceData.namespaceDescriptor, false);
namespaceData.namespaceDescriptor.setMemberScope(createJavaPackageScope(new FqName(psiPackage.getQualifiedName()), namespaceData.namespaceDescriptor));
trace.record(BindingContext.NAMESPACE, psiPackage, namespaceData.namespaceDescriptor);
@@ -942,6 +943,8 @@ public class JavaDescriptorResolver {
new FqName(psiClass.getQualifiedName()),
false
);
trace.record(JavaBindingContext.NAMESPACE_IS_CLASS_STATICS, namespaceData.namespaceDescriptor, true);
namespaceData.namespaceDescriptor.setMemberScope(new JavaClassMembersScope(namespaceData.namespaceDescriptor, psiClass, semanticServices, true));
trace.record(BindingContext.NAMESPACE, psiClass, namespaceData.namespaceDescriptor);
return namespaceData;
@@ -173,6 +173,11 @@ public interface BindingContext {
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);
/**
* Each namespace found in src must be registered here.
*/
WritableSlice<NamespaceDescriptor, Boolean> NAMESPACE_IS_SRC = Slices.createSimpleSlice();
WritableSlice<ClassDescriptor, Boolean> INCOMPLETE_HIERARCHY = Slices.createCollectiveSetSlice();
@@ -80,6 +80,7 @@ public class NamespaceFactoryImpl implements NamespaceFactory {
String namespaceName = JetPsiUtil.safeName(nameExpression.getReferencedName());
NamespaceDescriptorImpl namespaceDescriptor = createNamespaceDescriptorIfNeeded(null, currentOwner, namespaceName, false);
trace.record(BindingContext.NAMESPACE_IS_SRC, namespaceDescriptor, true);
currentOwner = namespaceDescriptor;
@@ -92,7 +93,10 @@ public class NamespaceFactoryImpl implements NamespaceFactory {
String name = JetPsiUtil.safeName(namespaceHeader.getName());
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
@@ -19,23 +19,9 @@ package org.jetbrains.jet.compiler;
import com.google.common.io.Files;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.codegen.PropertyCodegen;
import org.jetbrains.jet.lang.descriptors.ClassDescriptor;
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.*;
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
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.receivers.ExtensionReceiver;
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.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.nio.charset.Charset;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.*;
/**
* @author Stepan Koltsov
@@ -457,8 +440,7 @@ class NamespaceComparator {
}
private static boolean isRootNs(DeclarationDescriptor ns) {
// upyachka
return ns instanceof JavaNamespaceDescriptor && JavaDescriptorResolver.JAVA_ROOT.equals(ns.getName());
return ns instanceof NamespaceDescriptor && ns.getContainingDeclaration() instanceof ModuleDescriptor;
}
private static class NamespacePrefixSerializer extends Serializer {