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

Side by Side Diff: pkg/csslib/lib/src/css_printer.dart

Issue 60983003: pkg/csslib: fixed analysis error, more cleanup (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: rebase Created 7 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 csslib.visitor; 5 part of csslib.visitor;
6 6
7 /** 7 /**
8 * Visitor that produces a formatted string representation of the CSS tree. 8 * Visitor that produces a formatted string representation of the CSS tree.
9 */ 9 */
10 class CssPrinter extends Visitor { 10 class CssPrinter extends Visitor {
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
97 void visitPageDirective(PageDirective node) { 97 void visitPageDirective(PageDirective node) {
98 emit('$_newLine@page'); 98 emit('$_newLine@page');
99 if (node.hasIdent || node.hasPseudoPage) { 99 if (node.hasIdent || node.hasPseudoPage) {
100 if (node.hasIdent) emit(' '); 100 if (node.hasIdent) emit(' ');
101 emit(node._ident); 101 emit(node._ident);
102 emit(node.hasPseudoPage ? ':${node._pseudoPage}' : ''); 102 emit(node.hasPseudoPage ? ':${node._pseudoPage}' : '');
103 } 103 }
104 emit(' '); 104 emit(' ');
105 105
106 var declsMargin = node._declsMargin; 106 var declsMargin = node._declsMargin;
107 int declsMarginLength = declsMargin.length; 107 int declsMarginLength = declsMargin.length;
terry 2013/11/20 14:07:25 var
108 for (var i = 0; i < declsMarginLength; i++) { 108 for (var i = 0; i < declsMarginLength; i++) {
109 if (i > 0) emit(_newLine); 109 if (i > 0) emit(_newLine);
110 emit('{$_newLine'); 110 emit('{$_newLine');
111 declsMargin[i].visit(this); 111 declsMargin[i].visit(this);
112 emit('}'); 112 emit('}');
113 } 113 }
114 } 114 }
115 115
116 /** @charset "charset encoding" */ 116 /** @charset "charset encoding" */
117 void visitCharsetDirective(CharsetDirective node) { 117 void visitCharsetDirective(CharsetDirective node) {
118 emit('$_newLine@charset "${node.charEncoding}";'); 118 emit('$_newLine@charset "${node.charEncoding}";');
119 } 119 }
120 120
121 void visitImportDirective(ImportDirective node) { 121 void visitImportDirective(ImportDirective node) {
122 bool isStartingQuote(String ch) => ('\'"'.indexOf(ch[0]) >= 0); 122 bool isStartingQuote(String ch) => ('\'"'.indexOf(ch[0]) >= 0);
terry 2013/11/20 14:07:25 var
123 123
124 if (_isTesting) { 124 if (_isTesting) {
125 // Emit assuming url() was parsed; most suite tests use url function. 125 // Emit assuming url() was parsed; most suite tests use url function.
126 emit(' @import url(${node.import})'); 126 emit(' @import url(${node.import})');
127 } else if (isStartingQuote(node.import)) { 127 } else if (isStartingQuote(node.import)) {
128 emit(' @import ${node.import}'); 128 emit(' @import ${node.import}');
129 } else { 129 } else {
130 // url(...) isn't needed only a URI can follow an @import directive; emit 130 // url(...) isn't needed only a URI can follow an @import directive; emit
131 // url as a string. 131 // url as a string.
132 emit(' @import "${node.import}"'); 132 emit(' @import "${node.import}"');
(...skipping 21 matching lines...) Expand all
154 154
155 void visitKeyFrameBlock(KeyFrameBlock node) { 155 void visitKeyFrameBlock(KeyFrameBlock node) {
156 emit('$_sp$_sp'); 156 emit('$_sp$_sp');
157 node._blockSelectors.visit(this); 157 node._blockSelectors.visit(this);
158 emit('$_sp{$_newLine'); 158 emit('$_sp{$_newLine');
159 node._declarations.visit(this); 159 node._declarations.visit(this);
160 emit('$_sp$_sp}$_newLine'); 160 emit('$_sp$_sp}$_newLine');
161 } 161 }
162 162
163 void visitStyletDirective(StyletDirective node) { 163 void visitStyletDirective(StyletDirective node) {
164 emit('/* @stylet export as ${node._dartClassName} */\n'); 164 emit('/* @stylet export as ${node.dartClassName} */\n');
165 } 165 }
166 166
167 void visitNamespaceDirective(NamespaceDirective node) { 167 void visitNamespaceDirective(NamespaceDirective node) {
168 bool isStartingQuote(String ch) => ('\'"'.indexOf(ch) >= 0); 168 bool isStartingQuote(String ch) => ('\'"'.indexOf(ch) >= 0);
terry 2013/11/20 14:07:25 var
terry 2013/11/20 16:45:08 ignore. On 2013/11/20 14:07:25, terry wrote:
169 169
170 if (isStartingQuote(node._uri)) { 170 if (isStartingQuote(node._uri)) {
171 emit(' @namespace ${node.prefix}"${node._uri}"'); 171 emit(' @namespace ${node.prefix}"${node._uri}"');
172 } else { 172 } else {
173 if (_isTesting) { 173 if (_isTesting) {
174 // Emit exactly was we parsed. 174 // Emit exactly was we parsed.
175 emit(' @namespace ${node.prefix}url(${node._uri})'); 175 emit(' @namespace ${node.prefix}url(${node._uri})');
176 } else { 176 } else {
177 // url(...) isn't needed only a URI can follow a: 177 // url(...) isn't needed only a URI can follow a:
178 // @namespace prefix directive. 178 // @namespace prefix directive.
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
217 217
218 void visitRuleSet(RuleSet node) { 218 void visitRuleSet(RuleSet node) {
219 emit("$_newLine"); 219 emit("$_newLine");
220 node._selectorGroup.visit(this); 220 node._selectorGroup.visit(this);
221 emit(" {$_newLine"); 221 emit(" {$_newLine");
222 node._declarationGroup.visit(this); 222 node._declarationGroup.visit(this);
223 emit("}"); 223 emit("}");
224 } 224 }
225 225
226 void visitDeclarationGroup(DeclarationGroup node) { 226 void visitDeclarationGroup(DeclarationGroup node) {
227 var declarations = node._declarations; 227 var declarations = node.declarations;
228 var declarationsLength = declarations.length; 228 var declarationsLength = declarations.length;
229 for (var i = 0; i < declarationsLength; i++) { 229 for (var i = 0; i < declarationsLength; i++) {
230 if (i > 0) emit(_newLine); 230 if (i > 0) emit(_newLine);
231 emit("$_sp$_sp"); 231 emit("$_sp$_sp");
232 declarations[i].visit(this); 232 declarations[i].visit(this);
233 emit(";"); 233 emit(";");
234 } 234 }
235 if (declarationsLength > 0) emit(_newLine); 235 if (declarationsLength > 0) emit(_newLine);
236 } 236 }
237 237
238 void visitMarginGroup(MarginGroup node) { 238 void visitMarginGroup(MarginGroup node) {
239 var margin_sym_name = 239 var margin_sym_name =
240 TokenKind.idToValue(TokenKind.MARGIN_DIRECTIVES, node.margin_sym); 240 TokenKind.idToValue(TokenKind.MARGIN_DIRECTIVES, node.margin_sym);
241 241
242 emit("@$margin_sym_name {$_newLine"); 242 emit("@$margin_sym_name {$_newLine");
243 243
244 visitDeclarationGroup(node); 244 visitDeclarationGroup(node);
245 245
246 emit("}$_newLine"); 246 emit("}$_newLine");
247 } 247 }
248 248
249 void visitDeclaration(Declaration node) { 249 void visitDeclaration(Declaration node) {
250 String importantAsString() => node.important ? '$_sp!important' : ''; 250 String importantAsString() => node.important ? '$_sp!important' : '';
terry 2013/11/20 14:07:25 var
terry 2013/11/20 16:45:08 ignore On 2013/11/20 14:07:25, terry wrote:
251 251
252 emit("${node.property}: "); 252 emit("${node.property}: ");
253 node._expression.visit(this); 253 node._expression.visit(this);
254 254
255 emit("${importantAsString()}"); 255 emit("${importantAsString()}");
256 } 256 }
257 257
258 void visitVarDefinition(VarDefinition node) { 258 void visitVarDefinition(VarDefinition node) {
259 emit("var-${node.definedName}: "); 259 emit("var-${node.definedName}: ");
260 node._expression.visit(this); 260 node._expression.visit(this);
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
331 emit(')'); 331 emit(')');
332 } 332 }
333 333
334 void visitNegationSelector(NegationSelector node) { 334 void visitNegationSelector(NegationSelector node) {
335 emit(':not('); 335 emit(':not(');
336 node.negationArg.visit(this); 336 node.negationArg.visit(this);
337 emit(')'); 337 emit(')');
338 } 338 }
339 339
340 void visitSelectorExpression(SelectorExpression node) { 340 void visitSelectorExpression(SelectorExpression node) {
341 var expressions = node._expressions; 341 var expressions = node.expressions;
342 var expressionsLength = expressions.length; 342 var expressionsLength = expressions.length;
343 for (var i = 0; i < expressionsLength; i++) { 343 for (var i = 0; i < expressionsLength; i++) {
344 // Add space seperator between terms without an operator. 344 // Add space seperator between terms without an operator.
345 var expression = expressions[i]; 345 var expression = expressions[i];
346 expression.visit(this); 346 expression.visit(this);
347 } 347 }
348 } 348 }
349 349
350 void visitUnicodeRangeTerm(UnicodeRangeTerm node) { 350 void visitUnicodeRangeTerm(UnicodeRangeTerm node) {
351 if (node.hasSecond) { 351 if (node.hasSecond) {
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
508 508
509 void visitWildcard(Wildcard node) { 509 void visitWildcard(Wildcard node) {
510 emit('*'); 510 emit('*');
511 } 511 }
512 512
513 void visitDartStyleExpression(DartStyleExpression node) { 513 void visitDartStyleExpression(DartStyleExpression node) {
514 // TODO(terry): TBD 514 // TODO(terry): TBD
515 throw UnimplementedError; 515 throw UnimplementedError;
516 } 516 }
517 } 517 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698