Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 library services.src.correction.util; | 5 library services.src.correction.util; |
| 6 | 6 |
| 7 import 'dart:math'; | 7 import 'dart:math'; |
| 8 | 8 |
| 9 import 'package:analysis_server/src/protocol.dart' | 9 import 'package:analysis_server/src/protocol.dart' |
| 10 show SourceChange, SourceEdit; | 10 show SourceChange, SourceEdit; |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 136 Token commentToken = token.precedingComments; | 136 Token commentToken = token.precedingComments; |
| 137 while (commentToken != null) { | 137 while (commentToken != null) { |
| 138 ranges.add(rangeToken(commentToken)); | 138 ranges.add(rangeToken(commentToken)); |
| 139 commentToken = commentToken.next; | 139 commentToken = commentToken.next; |
| 140 } | 140 } |
| 141 token = token.next; | 141 token = token.next; |
| 142 } | 142 } |
| 143 return ranges; | 143 return ranges; |
| 144 } | 144 } |
| 145 | 145 |
| 146 /** | |
| 147 * Return the given [element] if it is a [CompilationUnitElement]. | |
| 148 * Return the enclosing [CompilationUnitElement] of the given [element], | |
| 149 * maybe `null`. | |
| 150 */ | |
| 151 CompilationUnitElement getCompilationUnitElement(Element element) { | |
| 152 if (element is CompilationUnitElement) { | |
| 153 return element; | |
| 154 } | |
| 155 return element.getAncestor((e) => e is CompilationUnitElement); | |
| 156 } | |
| 157 | |
| 146 String getDefaultValueCode(DartType type) { | 158 String getDefaultValueCode(DartType type) { |
| 147 if (type != null) { | 159 if (type != null) { |
| 148 String typeName = type.displayName; | 160 String typeName = type.displayName; |
| 149 if (typeName == "bool") { | 161 if (typeName == "bool") { |
| 150 return "false"; | 162 return "false"; |
| 151 } | 163 } |
| 152 if (typeName == "int") { | 164 if (typeName == "int") { |
| 153 return "0"; | 165 return "0"; |
| 154 } | 166 } |
| 155 if (typeName == "double") { | 167 if (typeName == "double") { |
| (...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 434 } | 446 } |
| 435 return parents; | 447 return parents; |
| 436 } | 448 } |
| 437 | 449 |
| 438 /** | 450 /** |
| 439 * Returns a parsed [AstNode] for the given [classElement]. | 451 * Returns a parsed [AstNode] for the given [classElement]. |
| 440 * | 452 * |
| 441 * The resulting AST structure may or may not be resolved. | 453 * The resulting AST structure may or may not be resolved. |
| 442 */ | 454 */ |
| 443 AstNode getParsedClassElementNode(ClassElement classElement) { | 455 AstNode getParsedClassElementNode(ClassElement classElement) { |
| 444 CompilationUnitElement unitElement = | 456 CompilationUnitElement unitElement = getCompilationUnitElement(classElement); |
|
Brian Wilkerson
2015/09/30 00:48:31
Not sure what value this refactoring has. The meth
| |
| 445 classElement.getAncestor((e) => e is CompilationUnitElement); | |
| 446 CompilationUnit unit = getParsedUnit(unitElement); | 457 CompilationUnit unit = getParsedUnit(unitElement); |
| 447 int offset = classElement.nameOffset; | 458 int offset = classElement.nameOffset; |
| 448 AstNode classNameNode = new NodeLocator(offset).searchWithin(unit); | 459 AstNode classNameNode = new NodeLocator(offset).searchWithin(unit); |
| 449 if (classElement.isEnum) { | 460 if (classElement.isEnum) { |
| 450 return classNameNode.getAncestor((node) => node is EnumDeclaration); | 461 return classNameNode.getAncestor((node) => node is EnumDeclaration); |
| 451 } else { | 462 } else { |
| 452 return classNameNode.getAncestor( | 463 return classNameNode.getAncestor( |
| 453 (node) => node is ClassDeclaration || node is ClassTypeAlias); | 464 (node) => node is ClassDeclaration || node is ClassTypeAlias); |
| 454 } | 465 } |
| 455 } | 466 } |
| (...skipping 1109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1565 | 1576 |
| 1566 @override | 1577 @override |
| 1567 Object visitExpression(Expression node) { | 1578 Object visitExpression(Expression node) { |
| 1568 if (node is BinaryExpression && node.operator.type == groupOperatorType) { | 1579 if (node is BinaryExpression && node.operator.type == groupOperatorType) { |
| 1569 return super.visitNode(node); | 1580 return super.visitNode(node); |
| 1570 } | 1581 } |
| 1571 operands.add(node); | 1582 operands.add(node); |
| 1572 return null; | 1583 return null; |
| 1573 } | 1584 } |
| 1574 } | 1585 } |
| OLD | NEW |