Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(4)

Unified Diff: pkg/analyzer/test/generated/resolver_test.dart

Issue 704413005: Report HintCode.UNUSED_ELEMENT for classes. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Fixes for review comments. Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « pkg/analyzer/lib/src/generated/resolver.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/analyzer/test/generated/resolver_test.dart
diff --git a/pkg/analyzer/test/generated/resolver_test.dart b/pkg/analyzer/test/generated/resolver_test.dart
index ce7bce6f13110939b872bb9bcaf4634d40435a88..0e5d325a0347bf3454b42775ba5539d954f68632 100644
--- a/pkg/analyzer/test/generated/resolver_test.dart
+++ b/pkg/analyzer/test/generated/resolver_test.dart
@@ -3208,6 +3208,138 @@ class B {}''');
verify([source, source2]);
}
+ void test_unusedElement_class_noReference() {
+ enableUnusedElement = true;
+ Source source = addSource(r'''
+class _A {}
+main() {
+}''');
+ resolve(source);
+ assertErrors(source, [HintCode.UNUSED_ELEMENT]);
+ verify([source]);
+ }
+
+ void test_unusedElement_class_inConstructorName() {
+ enableUnusedElement = true;
+ Source source = addSource(r'''
+class _A {
+ _A() {}
+ _A.named() {}
+}
+''');
+ resolve(source);
+ assertErrors(source, [HintCode.UNUSED_ELEMENT]);
+ verify([source]);
+ }
+
+ void test_unusedElement_class_inClassMember() {
+ enableUnusedElement = true;
+ Source source = addSource(r'''
+class _A {
+ static staticMethod() {
+ new _A();
+ }
+ instanceMethod() {
+ new _A();
+ }
+}
+''');
+ resolve(source);
+ assertErrors(source, [HintCode.UNUSED_ELEMENT]);
+ verify([source]);
+ }
+
+ void test_unusedElement_class_isExpression() {
+ enableUnusedElement = true;
+ Source source = addSource(r'''
+class _A {}
+main(p) {
+ if (p is _A) {
+ }
+}
+''');
+ resolve(source);
+ assertErrors(source, [HintCode.UNUSED_ELEMENT]);
+ verify([source]);
+ }
+
+ void test_unusedElement_class_variableDeclaration() {
+ enableUnusedElement = true;
+ Source source = addSource(r'''
+class _A {}
+main() {
+ _A v;
+ print(v);
+}
+print(x) {}
+''');
+ resolve(source);
+ assertErrors(source, [HintCode.UNUSED_ELEMENT]);
+ verify([source]);
+ }
+
+ void test_unusedElement_class_isUsed_extends() {
+ enableUnusedElement = true;
+ Source source = addSource(r'''
+class _A {}
+class B extends _A {}
+''');
+ resolve(source);
+ assertNoErrors(source);
+ verify([source]);
+ }
+
+ void test_unusedElement_class_isUsed_implements() {
+ enableUnusedElement = true;
+ Source source = addSource(r'''
+class _A {}
+class B implements _A {}
+''');
+ resolve(source);
+ assertNoErrors(source);
+ verify([source]);
+ }
+
+ void test_unusedElement_class_isUsed_instanceCreation() {
+ enableUnusedElement = true;
+ Source source = addSource(r'''
+class _A {}
+main() {
+ new _A();
+}''');
+ resolve(source);
+ assertNoErrors(source);
+ verify([source]);
+ }
+
+ void test_unusedElement_class_isUsed_staticFieldAccess() {
+ enableUnusedElement = true;
+ Source source = addSource(r'''
+class _A {
+ static const F = 42;
+}
+main() {
+ _A.F;
+}''');
+ resolve(source);
+ assertNoErrors(source);
+ verify([source]);
+ }
+
+ void test_unusedElement_class_isUsed_staticMethodInvocation() {
+ enableUnusedElement = true;
+ Source source = addSource(r'''
+class _A {
+ static m() {}
+}
+main() {
+ _A.m();
+}''');
+ resolve(source);
+ assertNoErrors(source);
+ verify([source]);
+ }
+
void test_unusedLocalVariable() {
enableUnusedLocalVariable = true;
Source source = addSource(r'''
@@ -6334,6 +6466,11 @@ class ResolverTestCase extends EngineTestCase {
AnalysisContextImpl analysisContext2;
/**
+ * Specifies if [assertErrors] should check for [HintCode.UNUSED_ELEMENT].
+ */
+ bool enableUnusedElement = false;
+
+ /**
* Specifies if [assertErrors] should check for [HintCode.UNUSED_LOCAL_VARIABLE].
*/
bool enableUnusedLocalVariable = false;
@@ -6380,6 +6517,10 @@ class ResolverTestCase extends EngineTestCase {
void assertErrors(Source source, [List<ErrorCode> expectedErrorCodes = ErrorCode.EMPTY_LIST]) {
GatheringErrorListener errorListener = new GatheringErrorListener();
for (AnalysisError error in analysisContext2.computeErrors(source)) {
+ if (error.errorCode == HintCode.UNUSED_ELEMENT &&
+ !enableUnusedElement) {
+ continue;
+ }
if (error.errorCode == HintCode.UNUSED_LOCAL_VARIABLE &&
!enableUnusedLocalVariable) {
continue;
« no previous file with comments | « pkg/analyzer/lib/src/generated/resolver.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698