enum classes are never inner
This commit is contained in:
@@ -42,7 +42,8 @@ public class ClosureAnnotator {
|
|||||||
private final Map<String, Integer> anonymousSubclassesCount = new HashMap<String, Integer>();
|
private final Map<String, Integer> anonymousSubclassesCount = new HashMap<String, Integer>();
|
||||||
private final Map<ScriptDescriptor, JvmClassName> classNameForScript = new HashMap<ScriptDescriptor, JvmClassName>();
|
private final Map<ScriptDescriptor, JvmClassName> classNameForScript = new HashMap<ScriptDescriptor, JvmClassName>();
|
||||||
private final Set<JvmClassName> scriptClassNames = new HashSet<JvmClassName>();
|
private final Set<JvmClassName> scriptClassNames = new HashSet<JvmClassName>();
|
||||||
private final Map<DeclarationDescriptor, ClassDescriptorImpl> classesForFunctions = new HashMap<DeclarationDescriptor, ClassDescriptorImpl>();
|
private final Map<DeclarationDescriptor, ClassDescriptorImpl> classesForFunctions =
|
||||||
|
new HashMap<DeclarationDescriptor, ClassDescriptorImpl>();
|
||||||
private final Map<DeclarationDescriptor, ClassDescriptor> enclosing = new HashMap<DeclarationDescriptor, ClassDescriptor>();
|
private final Map<DeclarationDescriptor, ClassDescriptor> enclosing = new HashMap<DeclarationDescriptor, ClassDescriptor>();
|
||||||
|
|
||||||
private final MultiMap<FqName, JetFile> namespaceName2MultiNamespaceFiles = MultiMap.create();
|
private final MultiMap<FqName, JetFile> namespaceName2MultiNamespaceFiles = MultiMap.create();
|
||||||
@@ -81,7 +82,10 @@ public class ClosureAnnotator {
|
|||||||
classDescriptor.initialize(
|
classDescriptor.initialize(
|
||||||
false,
|
false,
|
||||||
Collections.<TypeParameterDescriptor>emptyList(),
|
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);
|
classesForFunctions.put(funDescriptor, classDescriptor);
|
||||||
}
|
}
|
||||||
return classDescriptor;
|
return classDescriptor;
|
||||||
@@ -169,7 +173,7 @@ public class ClosureAnnotator {
|
|||||||
|
|
||||||
ArrayList<JetFile> namespaceFiles = new ArrayList<JetFile>();
|
ArrayList<JetFile> namespaceFiles = new ArrayList<JetFile>();
|
||||||
for (JetFile jetFile : entry.getValue()) {
|
for (JetFile jetFile : entry.getValue()) {
|
||||||
ArrayList<JetDeclaration> fileFunctions = new ArrayList<JetDeclaration>();
|
Collection<JetDeclaration> fileFunctions = new ArrayList<JetDeclaration>();
|
||||||
for (JetDeclaration declaration : jetFile.getDeclarations()) {
|
for (JetDeclaration declaration : jetFile.getDeclarations()) {
|
||||||
if (declaration instanceof JetNamedFunction) {
|
if (declaration instanceof JetNamedFunction) {
|
||||||
fileFunctions.add(declaration);
|
fileFunctions.add(declaration);
|
||||||
@@ -214,7 +218,12 @@ public class ClosureAnnotator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public boolean hasThis0(ClassDescriptor classDescriptor) {
|
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);
|
ClassDescriptor other = enclosing.get(classDescriptor);
|
||||||
return other != null;
|
return other != null;
|
||||||
@@ -266,6 +275,7 @@ public class ClosureAnnotator {
|
|||||||
@Override
|
@Override
|
||||||
public void visitJetFile(JetFile file) {
|
public void visitJetFile(JetFile file) {
|
||||||
if (file.isScript()) {
|
if (file.isScript()) {
|
||||||
|
//noinspection ConstantConditions
|
||||||
nameStack.push(classNameForScriptPsi(file.getScript()).getInternalName());
|
nameStack.push(classNameForScriptPsi(file.getScript()).getInternalName());
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@@ -279,6 +289,7 @@ public class ClosureAnnotator {
|
|||||||
public void visitClassObject(JetClassObject classObject) {
|
public void visitClassObject(JetClassObject classObject) {
|
||||||
JvmClassName name = recordClassObject(classObject);
|
JvmClassName name = recordClassObject(classObject);
|
||||||
ClassDescriptor classDescriptor = bindingContext.get(BindingContext.CLASS, classObject.getObjectDeclaration());
|
ClassDescriptor classDescriptor = bindingContext.get(BindingContext.CLASS, classObject.getObjectDeclaration());
|
||||||
|
assert classDescriptor != null;
|
||||||
recordEnclosing(classDescriptor);
|
recordEnclosing(classDescriptor);
|
||||||
recordName(classDescriptor, name);
|
recordName(classDescriptor, name);
|
||||||
classStack.push(classDescriptor);
|
classStack.push(classDescriptor);
|
||||||
@@ -303,7 +314,9 @@ public class ClosureAnnotator {
|
|||||||
if (classDescriptor.getContainingDeclaration() instanceof NamespaceDescriptor) {
|
if (classDescriptor.getContainingDeclaration() instanceof NamespaceDescriptor) {
|
||||||
nameStack.push(base.isEmpty() ? classDescriptor.getName().getName() : base + '/' + classDescriptor.getName());
|
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);
|
super.visitObjectDeclaration(declaration);
|
||||||
nameStack.pop();
|
nameStack.pop();
|
||||||
classStack.pop();
|
classStack.pop();
|
||||||
@@ -321,7 +334,9 @@ public class ClosureAnnotator {
|
|||||||
if (classDescriptor.getContainingDeclaration() instanceof NamespaceDescriptor) {
|
if (classDescriptor.getContainingDeclaration() instanceof NamespaceDescriptor) {
|
||||||
nameStack.push(base.isEmpty() ? classDescriptor.getName().getName() : base + '/' + classDescriptor.getName());
|
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);
|
super.visitClass(klass);
|
||||||
nameStack.pop();
|
nameStack.pop();
|
||||||
classStack.pop();
|
classStack.pop();
|
||||||
@@ -347,7 +362,8 @@ public class ClosureAnnotator {
|
|||||||
@Override
|
@Override
|
||||||
public void visitFunctionLiteralExpression(JetFunctionLiteralExpression expression) {
|
public void visitFunctionLiteralExpression(JetFunctionLiteralExpression expression) {
|
||||||
JvmClassName name = recordAnonymousClass(expression.getFunctionLiteral());
|
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
|
// working around a problem with shallow analysis
|
||||||
if (declarationDescriptor == null) return;
|
if (declarationDescriptor == null) return;
|
||||||
ClassDescriptor classDescriptor = classDescriptorForFunctionDescriptor(declarationDescriptor, name);
|
ClassDescriptor classDescriptor = classDescriptorForFunctionDescriptor(declarationDescriptor, name);
|
||||||
@@ -368,7 +384,8 @@ public class ClosureAnnotator {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void visitNamedFunction(JetNamedFunction function) {
|
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
|
// working around a problem with shallow analysis
|
||||||
if (functionDescriptor == null) return;
|
if (functionDescriptor == null) return;
|
||||||
DeclarationDescriptor containingDeclaration = functionDescriptor.getContainingDeclaration();
|
DeclarationDescriptor containingDeclaration = functionDescriptor.getContainingDeclaration();
|
||||||
@@ -379,7 +396,9 @@ public class ClosureAnnotator {
|
|||||||
}
|
}
|
||||||
else if (containingDeclaration instanceof NamespaceDescriptor) {
|
else if (containingDeclaration instanceof NamespaceDescriptor) {
|
||||||
String peek = nameStack.peek();
|
String peek = nameStack.peek();
|
||||||
if (peek.isEmpty()) { peek = "namespace"; }
|
if (peek.isEmpty()) {
|
||||||
|
peek = "namespace";
|
||||||
|
}
|
||||||
else {
|
else {
|
||||||
peek += "/namespace";
|
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 {
|
public void testValues() throws ClassNotFoundException, NoSuchMethodException, InvocationTargetException, IllegalAccessException {
|
||||||
blackBoxFile("enum/valueof.kt");
|
blackBoxFile("enum/valueof.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testInClassObj() throws ClassNotFoundException, NoSuchMethodException, InvocationTargetException, IllegalAccessException {
|
||||||
|
blackBoxFile("enum/inclassobj.kt");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user