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

Side by Side Diff: pkg/analyzer/test/generated/engine_test.dart

Issue 813483007: Delegating AST Visitor and Linter refactoring. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 5 years, 11 months 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, 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 // This code was auto-generated, is not intended to be edited, and is subject to 5 // This code was auto-generated, is not intended to be edited, and is subject to
6 // significant change. Please see the README file for more information. 6 // significant change. Please see the README file for more information.
7 7
8 library engine.engine_test; 8 library engine.engine_test;
9 9
10 import 'dart:async'; 10 import 'dart:async';
(...skipping 4072 matching lines...) Expand 10 before | Expand all | Expand 10 after
4083 library lib; 4083 library lib;
4084 '''); 4084 ''');
4085 4085
4086 CompilationUnit unit = 4086 CompilationUnit unit =
4087 context.resolveCompilationUnit2(librarySource, librarySource); 4087 context.resolveCompilationUnit2(librarySource, librarySource);
4088 List<CompilationUnit> units = <CompilationUnit>[]; 4088 List<CompilationUnit> units = <CompilationUnit>[];
4089 units.add(unit); 4089 units.add(unit);
4090 4090
4091 RecordingErrorListener errorListener = new RecordingErrorListener(); 4091 RecordingErrorListener errorListener = new RecordingErrorListener();
4092 4092
4093 LintGeneratorTest_Verifier verifier = new LintGeneratorTest_Verifier(); 4093 LintGeneratorTest_Linter linter = new LintGeneratorTest_Linter();
4094 4094
4095 LintGenerator lintGenerator = 4095 LintGenerator lintGenerator =
4096 new LintGenerator(units, errorListener, [verifier]); 4096 new LintGenerator(units, errorListener, [linter]);
4097 lintGenerator.generate(); 4097 lintGenerator.generate();
4098 4098
4099 verifier.testExpectations(); 4099 linter.testExpectations();
4100 } 4100 }
4101
4102 void test_generate_null_visitor() {
4103
4104 InternalAnalysisContext context = AnalysisContextFactory.contextWithCore();
4105 ChangeSet changeSet = new ChangeSet();
4106 Source librarySource =
4107 new FileBasedSource.con1(FileUtilities2.createFile("/test.dart"));
4108 changeSet.addedSource(librarySource);
4109 context.applyChanges(changeSet);
4110 context.setContents(librarySource, r'''
4111 library lib;
4112 ''');
4113
4114 CompilationUnit unit =
4115 context.resolveCompilationUnit2(librarySource, librarySource);
4116 List<CompilationUnit> units = <CompilationUnit>[];
4117 units.add(unit);
4118
4119 RecordingErrorListener errorListener = new RecordingErrorListener();
4120
4121 Linter badLinter = new LintGeneratorTest_Linter_Null_Visitor();
4122 LintGeneratorTest_Linter goodLinter = new LintGeneratorTest_Linter();
4123
4124 LintGenerator lintGenerator =
4125 new LintGenerator(units, errorListener, [badLinter, goodLinter]);
4126 // Test that generate does not fall down with a null visitor
4127 lintGenerator.generate();
4128 // Well-formed linter should still get called
4129 goodLinter.testExpectations();
4130 }
4131
4101 } 4132 }
4102 4133
4103 4134
4104 class LintGeneratorTest_Verifier extends LintVerifier { 4135 class LintGeneratorTest_Linter extends Linter with SimpleAstVisitor<Object> {
Brian Wilkerson 2015/01/15 14:59:54 Note that the original class name was only chosen
pquitslund 2015/01/15 18:07:30 Thanks. Were this Java, it would be an inner clas
4105 4136
4106 bool visited; 4137 bool visited;
4107 4138
4108 @override 4139 @override
4109 Object visitCompilationUnit(CompilationUnit node) { 4140 Object visitCompilationUnit(CompilationUnit node) {
4110 visited = true; 4141 visited = true;
4111 return null; 4142 return null;
4112 } 4143 }
4113 4144
4114 testExpectations() { 4145 testExpectations() {
4115 expect(reporter, isNotNull); 4146 expect(reporter, isNotNull);
4116 expect(visited, isTrue); 4147 expect(visited, isTrue);
4117 } 4148 }
4149
4150 @override
4151 AstVisitor getVisitor() => this;
4152 }
4153
4154 class LintGeneratorTest_Linter_Null_Visitor extends Linter {
4155 @override
4156 AstVisitor getVisitor() => null;
4118 } 4157 }
4119 4158
4120 4159
4121 @reflectiveTest 4160 @reflectiveTest
4122 class GetContentTaskTest extends EngineTestCase { 4161 class GetContentTaskTest extends EngineTestCase {
4123 void test_accept() { 4162 void test_accept() {
4124 Source source = new TestSource('/test.dart', ''); 4163 Source source = new TestSource('/test.dart', '');
4125 GetContentTask task = new GetContentTask(null, source); 4164 GetContentTask task = new GetContentTask(null, source);
4126 expect(task.accept(new GetContentTaskTestTV_accept()), isTrue); 4165 expect(task.accept(new GetContentTaskTestTV_accept()), isTrue);
4127 } 4166 }
(...skipping 2910 matching lines...) Expand 10 before | Expand all | Expand 10 after
7038 bool contains(Source source) => source == libB; 7077 bool contains(Source source) => source == libB;
7039 } 7078 }
7040 7079
7041 7080
7042 class _UniversalCachePartitionTest_test_setMaxCacheSize implements 7081 class _UniversalCachePartitionTest_test_setMaxCacheSize implements
7043 CacheRetentionPolicy { 7082 CacheRetentionPolicy {
7044 @override 7083 @override
7045 RetentionPriority getAstPriority(Source source, SourceEntry sourceEntry) => 7084 RetentionPriority getAstPriority(Source source, SourceEntry sourceEntry) =>
7046 RetentionPriority.LOW; 7085 RetentionPriority.LOW;
7047 } 7086 }
OLDNEW
« pkg/analyzer/lib/src/generated/visitors.dart ('K') | « pkg/analyzer/lib/src/generated/visitors.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698