2013-04-11 12:46:16 +00:00
|
|
|
// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
|
|
|
|
// for details. All rights reserved. Use of this source code is governed by a
|
|
|
|
// BSD-style license that can be found in the LICENSE file.
|
|
|
|
|
2017-10-05 14:05:50 +00:00
|
|
|
// part of "internal_patch.dart";
|
2017-02-20 13:17:14 +00:00
|
|
|
|
2017-03-21 17:07:26 +00:00
|
|
|
@patch
|
|
|
|
class Symbol {
|
|
|
|
@patch
|
|
|
|
const Symbol(String name) : this._name = name;
|
2014-07-11 01:30:50 +00:00
|
|
|
|
2017-03-21 17:07:26 +00:00
|
|
|
@patch
|
2017-11-01 15:16:04 +00:00
|
|
|
toString() => 'Symbol("${computeUnmangledName(this)}")';
|
2015-04-24 17:49:58 +00:00
|
|
|
|
2017-11-01 15:16:04 +00:00
|
|
|
@patch
|
|
|
|
static String computeUnmangledName(Symbol symbol) {
|
2015-04-24 17:49:58 +00:00
|
|
|
String string = Symbol.getName(symbol);
|
|
|
|
|
|
|
|
// get:foo -> foo
|
|
|
|
// set:foo -> foo=
|
|
|
|
// get:_foo@xxx -> _foo
|
|
|
|
// set:_foo@xxx -> _foo=
|
|
|
|
// Class._constructor@xxx -> Class._constructor
|
|
|
|
// _Class@xxx._constructor@xxx -> _Class._constructor
|
|
|
|
// lib._S@xxx with lib._M1@xxx, lib._M2@xxx -> lib._S with lib._M1, lib._M2
|
|
|
|
StringBuffer result = new StringBuffer();
|
|
|
|
bool add_setter_suffix = false;
|
|
|
|
var pos = 0;
|
|
|
|
if (string.length >= 4 && string[3] == ':') {
|
|
|
|
// Drop 'get:' or 'set:' prefix.
|
|
|
|
pos = 4;
|
|
|
|
if (string[0] == 's') {
|
|
|
|
add_setter_suffix = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Skip everything between AT and PERIOD, SPACE, COMMA or END
|
|
|
|
bool skip = false;
|
|
|
|
for (; pos < string.length; pos++) {
|
|
|
|
var char = string[pos];
|
|
|
|
if (char == '@') {
|
|
|
|
skip = true;
|
|
|
|
} else if (char == '.' || char == ' ' || char == ',') {
|
|
|
|
skip = false;
|
|
|
|
}
|
|
|
|
if (!skip) {
|
|
|
|
result.write(char);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (add_setter_suffix) {
|
|
|
|
result.write('=');
|
|
|
|
}
|
|
|
|
return result.toString();
|
|
|
|
}
|
2016-06-03 22:10:51 +00:00
|
|
|
|
2017-03-21 17:07:26 +00:00
|
|
|
@patch
|
|
|
|
int get hashCode {
|
2016-06-03 22:10:51 +00:00
|
|
|
const arbitraryPrime = 664597;
|
|
|
|
return 0x1fffffff & (arbitraryPrime * _name.hashCode);
|
|
|
|
}
|
2013-04-11 12:46:16 +00:00
|
|
|
}
|