enum classes are never inner

This commit is contained in:
Alex Tkachman
2012-08-15 10:44:33 +03:00
parent f817b04f84
commit 87a8e0a5dc
3 changed files with 49 additions and 11 deletions
@@ -42,8 +42,9 @@ public class ClosureAnnotator {
private final Map<String, Integer> anonymousSubclassesCount = new HashMap<String, Integer>();
private final Map<ScriptDescriptor, JvmClassName> classNameForScript = new HashMap<ScriptDescriptor, JvmClassName>();
private final Set<JvmClassName> scriptClassNames = new HashSet<JvmClassName>();
private final Map<DeclarationDescriptor, ClassDescriptorImpl> classesForFunctions = new HashMap<DeclarationDescriptor, ClassDescriptorImpl>();
private final Map<DeclarationDescriptor,ClassDescriptor> enclosing = new HashMap<DeclarationDescriptor, ClassDescriptor>();
private final Map<DeclarationDescriptor, ClassDescriptorImpl> classesForFunctions =
new HashMap<DeclarationDescriptor, ClassDescriptorImpl>();
private final Map<DeclarationDescriptor, ClassDescriptor> enclosing = new HashMap<DeclarationDescriptor, ClassDescriptor>();
private final MultiMap<FqName, JetFile> namespaceName2MultiNamespaceFiles = MultiMap.create();
private final MultiMap<FqName, JetFile> namespaceName2Files = MultiMap.create();
@@ -81,7 +82,10 @@ public class ClosureAnnotator {
classDescriptor.initialize(
false,
Collections.<TypeParameterDescriptor>emptyList(),
Collections.singleton((funDescriptor.getReceiverParameter().exists() ? JetStandardClasses.getReceiverFunction(arity) : JetStandardClasses.getFunction(arity)).getDefaultType()), JetScope.EMPTY, Collections.<ConstructorDescriptor>emptySet(), null);
Collections.singleton((funDescriptor.getReceiverParameter().exists()
? JetStandardClasses.getReceiverFunction(arity)
: JetStandardClasses.getFunction(arity)).getDefaultType()), JetScope.EMPTY,
Collections.<ConstructorDescriptor>emptySet(), null);
classesForFunctions.put(funDescriptor, classDescriptor);
}
return classDescriptor;
@@ -169,7 +173,7 @@ public class ClosureAnnotator {
ArrayList<JetFile> namespaceFiles = new ArrayList<JetFile>();
for (JetFile jetFile : entry.getValue()) {
ArrayList<JetDeclaration> fileFunctions = new ArrayList<JetDeclaration>();
Collection<JetDeclaration> fileFunctions = new ArrayList<JetDeclaration>();
for (JetDeclaration declaration : jetFile.getDeclarations()) {
if (declaration instanceof JetNamedFunction) {
fileFunctions.add(declaration);
@@ -181,7 +185,7 @@ public class ClosureAnnotator {
}
}
if(namespaceFiles.size() > 1) {
if (namespaceFiles.size() > 1) {
for (JetFile namespaceFile : namespaceFiles) {
namespaceName2MultiNamespaceFiles.putValue(entry.getKey(), namespaceFile);
}
@@ -214,7 +218,12 @@ public class ClosureAnnotator {
}
public boolean hasThis0(ClassDescriptor classDescriptor) {
if (DescriptorUtils.isClassObject(classDescriptor)) { return false; }
if (DescriptorUtils.isClassObject(classDescriptor)) {
return false;
}
if (classDescriptor.getKind() == ClassKind.ENUM_CLASS || classDescriptor.getKind() == ClassKind.ENUM_ENTRY) {
return false;
}
ClassDescriptor other = enclosing.get(classDescriptor);
return other != null;
@@ -266,6 +275,7 @@ public class ClosureAnnotator {
@Override
public void visitJetFile(JetFile file) {
if (file.isScript()) {
//noinspection ConstantConditions
nameStack.push(classNameForScriptPsi(file.getScript()).getInternalName());
}
else {
@@ -279,6 +289,7 @@ public class ClosureAnnotator {
public void visitClassObject(JetClassObject classObject) {
JvmClassName name = recordClassObject(classObject);
ClassDescriptor classDescriptor = bindingContext.get(BindingContext.CLASS, classObject.getObjectDeclaration());
assert classDescriptor != null;
recordEnclosing(classDescriptor);
recordName(classDescriptor, name);
classStack.push(classDescriptor);
@@ -303,7 +314,9 @@ public class ClosureAnnotator {
if (classDescriptor.getContainingDeclaration() instanceof NamespaceDescriptor) {
nameStack.push(base.isEmpty() ? classDescriptor.getName().getName() : base + '/' + classDescriptor.getName());
}
else { nameStack.push(base + '$' + classDescriptor.getName()); }
else {
nameStack.push(base + '$' + classDescriptor.getName());
}
super.visitObjectDeclaration(declaration);
nameStack.pop();
classStack.pop();
@@ -321,7 +334,9 @@ public class ClosureAnnotator {
if (classDescriptor.getContainingDeclaration() instanceof NamespaceDescriptor) {
nameStack.push(base.isEmpty() ? classDescriptor.getName().getName() : base + '/' + classDescriptor.getName());
}
else { nameStack.push(base + '$' + classDescriptor.getName()); }
else {
nameStack.push(base + '$' + classDescriptor.getName());
}
super.visitClass(klass);
nameStack.pop();
classStack.pop();
@@ -347,7 +362,8 @@ public class ClosureAnnotator {
@Override
public void visitFunctionLiteralExpression(JetFunctionLiteralExpression expression) {
JvmClassName name = recordAnonymousClass(expression.getFunctionLiteral());
FunctionDescriptor declarationDescriptor = (FunctionDescriptor) bindingContext.get(BindingContext.DECLARATION_TO_DESCRIPTOR, expression);
FunctionDescriptor declarationDescriptor =
(FunctionDescriptor) bindingContext.get(BindingContext.DECLARATION_TO_DESCRIPTOR, expression);
// working around a problem with shallow analysis
if (declarationDescriptor == null) return;
ClassDescriptor classDescriptor = classDescriptorForFunctionDescriptor(declarationDescriptor, name);
@@ -368,7 +384,8 @@ public class ClosureAnnotator {
@Override
public void visitNamedFunction(JetNamedFunction function) {
FunctionDescriptor functionDescriptor = (FunctionDescriptor) bindingContext.get(BindingContext.DECLARATION_TO_DESCRIPTOR, function);
FunctionDescriptor functionDescriptor =
(FunctionDescriptor) bindingContext.get(BindingContext.DECLARATION_TO_DESCRIPTOR, function);
// working around a problem with shallow analysis
if (functionDescriptor == null) return;
DeclarationDescriptor containingDeclaration = functionDescriptor.getContainingDeclaration();
@@ -379,7 +396,9 @@ public class ClosureAnnotator {
}
else if (containingDeclaration instanceof NamespaceDescriptor) {
String peek = nameStack.peek();
if (peek.isEmpty()) { peek = "namespace"; }
if (peek.isEmpty()) {
peek = "namespace";
}
else {
peek += "/namespace";
}
@@ -0,0 +1,15 @@
fun box() = if(Context.operatingSystemType == Context.OsType.OTHER) "OK" else "fail"
public class Context
{
class object
{
public enum class OsType {
LINUX;
OTHER
}
public val operatingSystemType: OsType
get() = OsType.OTHER
}
}
@@ -96,4 +96,8 @@ public class EnumGenTest extends CodegenTestCase {
public void testValues() throws ClassNotFoundException, NoSuchMethodException, InvocationTargetException, IllegalAccessException {
blackBoxFile("enum/valueof.kt");
}
public void testInClassObj() throws ClassNotFoundException, NoSuchMethodException, InvocationTargetException, IllegalAccessException {
blackBoxFile("enum/inclassobj.kt");
}
}