| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2013, the Dart project authors. | 2 * Copyright (c) 2013, the Dart project authors. |
| 3 * | 3 * |
| 4 * Licensed under the Eclipse Public License v1.0 (the "License"); you may not u
se this file except | 4 * Licensed under the Eclipse Public License v1.0 (the "License"); you may not u
se this file except |
| 5 * in compliance with the License. You may obtain a copy of the License at | 5 * in compliance with the License. You may obtain a copy of the License at |
| 6 * | 6 * |
| 7 * http://www.eclipse.org/legal/epl-v10.html | 7 * http://www.eclipse.org/legal/epl-v10.html |
| 8 * | 8 * |
| 9 * Unless required by applicable law or agreed to in writing, software distribut
ed under the License | 9 * Unless required by applicable law or agreed to in writing, software distribut
ed under the License |
| 10 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY K
IND, either express | 10 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY K
IND, either express |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 51 } | 51 } |
| 52 | 52 |
| 53 /** | 53 /** |
| 54 * Get the element associated with the selected portion of the given input ele
ment. | 54 * Get the element associated with the selected portion of the given input ele
ment. |
| 55 * | 55 * |
| 56 * @param editor the editor | 56 * @param editor the editor |
| 57 * @param caret the caret position in the editor | 57 * @param caret the caret position in the editor |
| 58 * @return the associated element | 58 * @return the associated element |
| 59 */ | 59 */ |
| 60 public static Element getElementAtOffset(DartEditor editor, int caret) { | 60 public static Element getElementAtOffset(DartEditor editor, int caret) { |
| 61 | 61 ASTNode node = getNodeAtOffset(editor, caret); |
| 62 CompilationUnit cu = editor.getInputUnit(); | |
| 63 if (cu == null) { | |
| 64 return null; | |
| 65 } | |
| 66 | |
| 67 ASTNode node = new NodeLocator(caret).searchWithin(cu); | |
| 68 if (node == null) { | 62 if (node == null) { |
| 69 return null; | 63 return null; |
| 70 } | 64 } |
| 71 | 65 |
| 72 return ElementLocator.locate(node); | 66 return ElementLocator.locate(node); |
| 73 } | 67 } |
| 74 | 68 |
| 75 /** | 69 /** |
| 76 * Get the element associated with the selected portion of the given input ele
ment. | 70 * Get the element associated with the selected portion of the given input ele
ment. |
| 77 * | 71 * |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 165 } | 159 } |
| 166 return null; | 160 return null; |
| 167 } | 161 } |
| 168 | 162 |
| 169 private boolean isNodeEnclosingOffset(ASTNode node) { | 163 private boolean isNodeEnclosingOffset(ASTNode node) { |
| 170 return node.getOffset() <= offset && offset <= node.getEnd(); | 164 return node.getOffset() <= offset && offset <= node.getEnd(); |
| 171 } | 165 } |
| 172 }); | 166 }); |
| 173 return result[0]; | 167 return result[0]; |
| 174 } | 168 } |
| 169 |
| 170 /** |
| 171 * Get the {@link ASTNode} associated with the selected portion of the given e
ditor. |
| 172 * |
| 173 * @param editor the editor |
| 174 * @param caret the caret position in the editor |
| 175 * @return the associated {@link ASTNode} |
| 176 */ |
| 177 public static ASTNode getNodeAtOffset(DartEditor editor, int caret) { |
| 178 CompilationUnit cu = editor.getInputUnit(); |
| 179 if (cu == null) { |
| 180 return null; |
| 181 } |
| 182 return new NodeLocator(caret).searchWithin(cu); |
| 183 } |
| 175 } | 184 } |
| OLD | NEW |