| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 part of dart2js.js_emitter.full_emitter; | 5 part of dart2js.js_emitter.full_emitter; |
| 6 | 6 |
| 7 class ClassEmitter extends CodeEmitterHelper { | 7 class ClassEmitter extends CodeEmitterHelper { |
| 8 final ClosedWorld closedWorld; | 8 final ClosedWorld closedWorld; |
| 9 | 9 |
| 10 ClassEmitter(this.closedWorld); | 10 ClassEmitter(this.closedWorld); |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 169 } | 169 } |
| 170 // Fields can only be reflected if their declaring class is reflectable | 170 // Fields can only be reflected if their declaring class is reflectable |
| 171 // (as they are only accessible via [ClassMirror.declarations]). | 171 // (as they are only accessible via [ClassMirror.declarations]). |
| 172 // However, set/get operations can be performed on them, so they are | 172 // However, set/get operations can be performed on them, so they are |
| 173 // reflectable in some sense, which leads to [isAccessibleByReflection] | 173 // reflectable in some sense, which leads to [isAccessibleByReflection] |
| 174 // reporting `true`. | 174 // reporting `true`. |
| 175 if (backend.isAccessibleByReflection(fieldElement)) { | 175 if (backend.isAccessibleByReflection(fieldElement)) { |
| 176 fieldNameParts.add(new jsAst.LiteralString('-')); | 176 fieldNameParts.add(new jsAst.LiteralString('-')); |
| 177 if (fieldElement.isTopLevel || | 177 if (fieldElement.isTopLevel || |
| 178 backend.isAccessibleByReflection(fieldElement.enclosingClass)) { | 178 backend.isAccessibleByReflection(fieldElement.enclosingClass)) { |
| 179 DartType type = fieldElement.type; | 179 ResolutionDartType type = fieldElement.type; |
| 180 fieldNameParts.add(task.metadataCollector.reifyType(type)); | 180 fieldNameParts.add(task.metadataCollector.reifyType(type)); |
| 181 } | 181 } |
| 182 } | 182 } |
| 183 jsAst.Literal fieldNameAst = js.concatenateStrings(fieldNameParts); | 183 jsAst.Literal fieldNameAst = js.concatenateStrings(fieldNameParts); |
| 184 builder.addField(fieldNameAst); | 184 builder.addField(fieldNameAst); |
| 185 // Add 1 because adding a field to the class also requires a comma | 185 // Add 1 because adding a field to the class also requires a comma |
| 186 compiler.dumpInfoTask.registerElementAst(fieldElement, fieldNameAst); | 186 compiler.dumpInfoTask.registerElementAst(fieldElement, fieldNameAst); |
| 187 fieldsAdded = true; | 187 fieldsAdded = true; |
| 188 } | 188 } |
| 189 } | 189 } |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 288 ClassBuilder enclosingBuilder, Fragment fragment) { | 288 ClassBuilder enclosingBuilder, Fragment fragment) { |
| 289 ClassElement classElement = cls.element; | 289 ClassElement classElement = cls.element; |
| 290 jsAst.Name className = cls.name; | 290 jsAst.Name className = cls.name; |
| 291 | 291 |
| 292 var metadata = task.metadataCollector.buildMetadataFunction(classElement); | 292 var metadata = task.metadataCollector.buildMetadataFunction(classElement); |
| 293 if (metadata != null) { | 293 if (metadata != null) { |
| 294 classBuilder.addPropertyByName("@", metadata); | 294 classBuilder.addPropertyByName("@", metadata); |
| 295 } | 295 } |
| 296 | 296 |
| 297 if (backend.isAccessibleByReflection(classElement)) { | 297 if (backend.isAccessibleByReflection(classElement)) { |
| 298 List<DartType> typeVars = classElement.typeVariables; | 298 List<ResolutionDartType> typeVars = classElement.typeVariables; |
| 299 Iterable typeVariableProperties = | 299 Iterable typeVariableProperties = |
| 300 emitter.typeVariableHandler.typeVariablesOf(classElement); | 300 emitter.typeVariableHandler.typeVariablesOf(classElement); |
| 301 | 301 |
| 302 ClassElement superclass = classElement.superclass; | 302 ClassElement superclass = classElement.superclass; |
| 303 bool hasSuper = superclass != null; | 303 bool hasSuper = superclass != null; |
| 304 if ((!typeVariableProperties.isEmpty && !hasSuper) || | 304 if ((!typeVariableProperties.isEmpty && !hasSuper) || |
| 305 (hasSuper && !equalElements(superclass.typeVariables, typeVars))) { | 305 (hasSuper && !equalElements(superclass.typeVariables, typeVars))) { |
| 306 classBuilder.addPropertyByName( | 306 classBuilder.addPropertyByName( |
| 307 '<>', new jsAst.ArrayInitializer(typeVariableProperties.toList())); | 307 '<>', new jsAst.ArrayInitializer(typeVariableProperties.toList())); |
| 308 } | 308 } |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 342 String reflectionName = emitter.getReflectionName(classElement, className); | 342 String reflectionName = emitter.getReflectionName(classElement, className); |
| 343 if (reflectionName != null) { | 343 if (reflectionName != null) { |
| 344 if (!backend.isAccessibleByReflection(classElement) || cls.onlyForRti) { | 344 if (!backend.isAccessibleByReflection(classElement) || cls.onlyForRti) { |
| 345 // TODO(herhut): Fix use of reflection name here. | 345 // TODO(herhut): Fix use of reflection name here. |
| 346 enclosingBuilder.addPropertyByName("+$reflectionName", js.number(0)); | 346 enclosingBuilder.addPropertyByName("+$reflectionName", js.number(0)); |
| 347 } else { | 347 } else { |
| 348 List<jsAst.Expression> types = <jsAst.Expression>[]; | 348 List<jsAst.Expression> types = <jsAst.Expression>[]; |
| 349 if (classElement.supertype != null) { | 349 if (classElement.supertype != null) { |
| 350 types.add(task.metadataCollector.reifyType(classElement.supertype)); | 350 types.add(task.metadataCollector.reifyType(classElement.supertype)); |
| 351 } | 351 } |
| 352 for (DartType interface in classElement.interfaces) { | 352 for (ResolutionDartType interface in classElement.interfaces) { |
| 353 types.add(task.metadataCollector.reifyType(interface)); | 353 types.add(task.metadataCollector.reifyType(interface)); |
| 354 } | 354 } |
| 355 // TODO(herhut): Fix use of reflection name here. | 355 // TODO(herhut): Fix use of reflection name here. |
| 356 enclosingBuilder.addPropertyByName( | 356 enclosingBuilder.addPropertyByName( |
| 357 "+$reflectionName", new jsAst.ArrayInitializer(types)); | 357 "+$reflectionName", new jsAst.ArrayInitializer(types)); |
| 358 } | 358 } |
| 359 } | 359 } |
| 360 } | 360 } |
| 361 | 361 |
| 362 void recordMangledField( | 362 void recordMangledField( |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 422 : new Selector.setter( | 422 : new Selector.setter( |
| 423 new Name(member.name, member.library, isSetter: true)); | 423 new Name(member.name, member.library, isSetter: true)); |
| 424 String reflectionName = emitter.getReflectionName(selector, name); | 424 String reflectionName = emitter.getReflectionName(selector, name); |
| 425 if (reflectionName != null) { | 425 if (reflectionName != null) { |
| 426 var reflectable = | 426 var reflectable = |
| 427 js(backend.isAccessibleByReflection(member) ? '1' : '0'); | 427 js(backend.isAccessibleByReflection(member) ? '1' : '0'); |
| 428 builder.addPropertyByName('+$reflectionName', reflectable); | 428 builder.addPropertyByName('+$reflectionName', reflectable); |
| 429 } | 429 } |
| 430 } | 430 } |
| 431 } | 431 } |
| OLD | NEW |