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 // 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 services.src.correction.util; | 8 library services.src.correction.util; |
| 9 | 9 |
| 10 import 'package:analysis_services/correction/change.dart'; | 10 import 'package:analysis_services/correction/change.dart'; |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 53 if (typeName == "String") { | 53 if (typeName == "String") { |
| 54 return "''"; | 54 return "''"; |
| 55 } | 55 } |
| 56 } | 56 } |
| 57 // no better guess | 57 // no better guess |
| 58 return "null"; | 58 return "null"; |
| 59 } | 59 } |
| 60 | 60 |
| 61 | 61 |
| 62 /** | 62 /** |
| 63 * Return the name of the [Element] kind. | |
| 64 */ | |
| 65 String getElementKindName(Element element) { | |
| 66 return element.kind.displayName; | |
| 67 } | |
| 68 | |
| 69 | |
| 70 /** | |
| 71 * Returns the name to display in the UI for the given [Element]. | |
| 72 */ | |
| 73 String getElementQualifiedName(Element element) { | |
| 74 ElementKind kind = element.kind; | |
| 75 while (true) { | |
| 76 if (kind == ElementKind.FIELD || kind == ElementKind.METHOD) { | |
| 77 return '${element.enclosingElement.displayName}.${element.displayName}'; | |
| 78 } else { | |
| 79 return element.displayName; | |
| 80 } | |
| 81 break; | |
|
Brian Wilkerson
2014/08/12 04:44:40
I don't understand this code. We will never reach
scheglov
2014/08/12 05:09:33
/me is surprised too.
I guess it was a switch/case
| |
| 82 } | |
| 83 } | |
| 84 | |
| 85 | |
| 86 /** | |
| 63 * @return the [ExecutableElement] of the enclosing executable [AstNode]. | 87 * @return the [ExecutableElement] of the enclosing executable [AstNode]. |
| 64 */ | 88 */ |
| 65 ExecutableElement getEnclosingExecutableElement(AstNode node) { | 89 ExecutableElement getEnclosingExecutableElement(AstNode node) { |
| 66 while (node != null) { | 90 while (node != null) { |
| 67 if (node is FunctionDeclaration) { | 91 if (node is FunctionDeclaration) { |
| 68 return node.element; | 92 return node.element; |
| 69 } | 93 } |
| 70 if (node is ConstructorDeclaration) { | 94 if (node is ConstructorDeclaration) { |
| 71 return node.element; | 95 return node.element; |
| 72 } | 96 } |
| 73 if (node is MethodDeclaration) { | 97 if (node is MethodDeclaration) { |
| 74 return node.element; | 98 return node.element; |
| 75 } | 99 } |
| 76 node = node.parent; | 100 node = node.parent; |
| 77 } | 101 } |
| 78 return null; | 102 return null; |
| 79 } | 103 } |
| 80 | 104 |
| 81 | |
| 82 /** | 105 /** |
| 83 * Returns a namespace of the given [ExportElement]. | 106 * Returns a namespace of the given [ExportElement]. |
| 84 */ | 107 */ |
| 85 Map<String, Element> getExportNamespaceForDirective(ExportElement exp) { | 108 Map<String, Element> getExportNamespaceForDirective(ExportElement exp) { |
| 86 Namespace namespace = | 109 Namespace namespace = |
| 87 new NamespaceBuilder().createExportNamespaceForDirective(exp); | 110 new NamespaceBuilder().createExportNamespaceForDirective(exp); |
| 88 return namespace.definedNames; | 111 return namespace.definedNames; |
| 89 } | 112 } |
| 90 | 113 |
| 91 | 114 |
| 92 /** | 115 /** |
| 93 * Returns a export namespace of the given [LibraryElement]. | 116 * Returns a export namespace of the given [LibraryElement]. |
| 94 */ | 117 */ |
| 95 Map<String, Element> getExportNamespaceForLibrary(LibraryElement library) { | 118 Map<String, Element> getExportNamespaceForLibrary(LibraryElement library) { |
| 96 Namespace namespace = | 119 Namespace namespace = |
| 97 new NamespaceBuilder().createExportNamespaceForLibrary(library); | 120 new NamespaceBuilder().createExportNamespaceForLibrary(library); |
| 98 return namespace.definedNames; | 121 return namespace.definedNames; |
| 99 } | 122 } |
| 100 | 123 |
| 101 /** | 124 /** |
| 102 * Returns an [Element] exported from the given [LibraryElement]. | 125 * Returns an [Element] exported from the given [LibraryElement]. |
| 103 */ | 126 */ |
| 104 Element getExportedElement(LibraryElement library, String name) { | 127 Element getExportedElement(LibraryElement library, String name) { |
| 105 if (library == null) { | 128 if (library == null) { |
| 106 return null; | 129 return null; |
| 107 } | 130 } |
| 108 return getExportNamespaceForLibrary(library)[name]; | 131 return getExportNamespaceForLibrary(library)[name]; |
| 109 } | 132 } |
| 110 | 133 |
| 111 | |
| 112 /** | 134 /** |
| 113 * Returns [getExpressionPrecedence] for the parent of [node], | 135 * Returns [getExpressionPrecedence] for the parent of [node], |
| 114 * or `0` if the parent node is [ParenthesizedExpression]. | 136 * or `0` if the parent node is [ParenthesizedExpression]. |
| 115 * | 137 * |
| 116 * The reason is that `(expr)` is always executed after `expr`. | 138 * The reason is that `(expr)` is always executed after `expr`. |
| 117 */ | 139 */ |
| 118 int getExpressionParentPrecedence(AstNode node) { | 140 int getExpressionParentPrecedence(AstNode node) { |
| 119 AstNode parent = node.parent; | 141 AstNode parent = node.parent; |
| 120 if (parent is ParenthesizedExpression) { | 142 if (parent is ParenthesizedExpression) { |
| 121 return 0; | 143 return 0; |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 135 | 157 |
| 136 /** | 158 /** |
| 137 * Returns the namespace of the given [ImportElement]. | 159 * Returns the namespace of the given [ImportElement]. |
| 138 */ | 160 */ |
| 139 Map<String, Element> getImportNamespace(ImportElement imp) { | 161 Map<String, Element> getImportNamespace(ImportElement imp) { |
| 140 NamespaceBuilder builder = new NamespaceBuilder(); | 162 NamespaceBuilder builder = new NamespaceBuilder(); |
| 141 Namespace namespace = builder.createImportNamespaceForDirective(imp); | 163 Namespace namespace = builder.createImportNamespaceForDirective(imp); |
| 142 return namespace.definedNames; | 164 return namespace.definedNames; |
| 143 } | 165 } |
| 144 | 166 |
| 167 | |
| 145 /** | 168 /** |
| 146 * If given [AstNode] is name of qualified property extraction, returns target f rom which | 169 * If given [AstNode] is name of qualified property extraction, returns target f rom which |
| 147 * this property is extracted. Otherwise `null`. | 170 * this property is extracted. Otherwise `null`. |
| 148 */ | 171 */ |
| 149 Expression getQualifiedPropertyTarget(AstNode node) { | 172 Expression getQualifiedPropertyTarget(AstNode node) { |
| 150 AstNode parent = node.parent; | 173 AstNode parent = node.parent; |
| 151 if (parent is PrefixedIdentifier) { | 174 if (parent is PrefixedIdentifier) { |
| 152 PrefixedIdentifier prefixed = parent; | 175 PrefixedIdentifier prefixed = parent; |
| 153 if (prefixed.identifier == node) { | 176 if (prefixed.identifier == node) { |
| 154 return parent.prefix; | 177 return parent.prefix; |
| 155 } | 178 } |
| 156 } | 179 } |
| 157 if (parent is PropertyAccess) { | 180 if (parent is PropertyAccess) { |
| 158 PropertyAccess access = parent; | 181 PropertyAccess access = parent; |
| 159 if (access.propertyName == node) { | 182 if (access.propertyName == node) { |
| 160 return access.realTarget; | 183 return access.realTarget; |
| 161 } | 184 } |
| 162 } | 185 } |
| 163 return null; | 186 return null; |
| 164 } | 187 } |
| 165 | 188 |
| 189 | |
| 166 /** | 190 /** |
| 167 * Returns the given [Statement] if not a [Block], or the first child | 191 * Returns the given [Statement] if not a [Block], or the first child |
| 168 * [Statement] if a [Block], or `null` if more than one child. | 192 * [Statement] if a [Block], or `null` if more than one child. |
| 169 */ | 193 */ |
| 170 Statement getSingleStatement(Statement statement) { | 194 Statement getSingleStatement(Statement statement) { |
| 171 if (statement is Block) { | 195 if (statement is Block) { |
| 172 List<Statement> blockStatements = statement.statements; | 196 List<Statement> blockStatements = statement.statements; |
| 173 if (blockStatements.length != 1) { | 197 if (blockStatements.length != 1) { |
| 174 return null; | 198 return null; |
| 175 } | 199 } |
| (...skipping 708 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 884 int newOperatorPrecedence) { | 908 int newOperatorPrecedence) { |
| 885 if (expr._precedence < newOperatorPrecedence) { | 909 if (expr._precedence < newOperatorPrecedence) { |
| 886 return "(${expr._source})"; | 910 return "(${expr._source})"; |
| 887 } | 911 } |
| 888 return expr._source; | 912 return expr._source; |
| 889 } | 913 } |
| 890 | 914 |
| 891 static _InvertedCondition _simple(String source) => | 915 static _InvertedCondition _simple(String source) => |
| 892 new _InvertedCondition(2147483647, source); | 916 new _InvertedCondition(2147483647, source); |
| 893 } | 917 } |
| OLD | NEW |