-
Notifications
You must be signed in to change notification settings - Fork 347
/
type.dart
53 lines (42 loc) · 1.55 KB
/
type.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
// Copyright 2016 Google Inc. Use of this source code is governed by an
// MIT-style license that can be found in the LICENSE file or at
// https://opensource.org/licenses/MIT.
import 'package:meta/meta.dart';
import '../../extend/functions.dart';
import '../../visitor/interface/selector.dart';
import '../selector.dart';
/// A type selector.
///
/// This selects elements whose name equals the given name.
///
/// {@category Selector}
@sealed
class TypeSelector extends SimpleSelector {
/// The element name being selected.
final QualifiedName name;
int get minSpecificity => 1;
TypeSelector(this.name);
T accept<T>(SelectorVisitor<T> visitor) => visitor.visitTypeSelector(this);
/// @nodoc
@internal
TypeSelector addSuffix(String suffix) => TypeSelector(
QualifiedName(name.name + suffix, namespace: name.namespace));
/// @nodoc
@internal
List<SimpleSelector>? unify(List<SimpleSelector> compound) {
if (compound.first is UniversalSelector || compound.first is TypeSelector) {
var unified = unifyUniversalAndElement(this, compound.first);
if (unified == null) return null;
return [unified, ...compound.skip(1)];
} else {
return [this, ...compound];
}
}
bool isSuperselector(SimpleSelector other) =>
super.isSuperselector(other) ||
(other is TypeSelector &&
name.name == other.name.name &&
(name.namespace == '*' || name.namespace == other.name.namespace));
bool operator ==(Object other) => other is TypeSelector && other.name == name;
int get hashCode => name.hashCode;
}