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 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
221 this.source = unitSource; | 221 this.source = unitSource; |
222 proposals.clear(); | 222 proposals.clear(); |
223 // prepare node | 223 // prepare node |
224 node = new NodeLocator(offset).searchWithin(parsedUnit); | 224 node = new NodeLocator(offset).searchWithin(parsedUnit); |
225 if (node == null) { | 225 if (node == null) { |
226 return NO_PROPOSALS; | 226 return NO_PROPOSALS; |
227 } | 227 } |
228 // call proposal methods | 228 // call proposal methods |
229 addUnresolvedProposal_addPart(); | 229 addUnresolvedProposal_addPart(); |
230 // done | 230 // done |
231 return proposals.toArray(new CorrectionProposal[proposals.size()]); | 231 try { |
| 232 return proposals.toArray(new CorrectionProposal[proposals.size()]); |
| 233 } finally { |
| 234 cleanUp(); |
| 235 } |
232 } | 236 } |
233 | 237 |
234 @Override | 238 @Override |
235 public CorrectionProposal[] getProposals(AssistContext context) throws Excepti
on { | 239 public CorrectionProposal[] getProposals(AssistContext context) throws Excepti
on { |
236 if (context == null) { | 240 if (context == null) { |
237 return NO_PROPOSALS; | 241 return NO_PROPOSALS; |
238 } | 242 } |
239 assistContext = context; | 243 assistContext = context; |
240 proposals.clear(); | 244 proposals.clear(); |
241 source = context.getSource(); | 245 source = context.getSource(); |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
278 instrumentation.metric("QuickAssist-Offset", selectionOffset); | 282 instrumentation.metric("QuickAssist-Offset", selectionOffset); |
279 instrumentation.metric("QuickAssist-Length", selectionLength); | 283 instrumentation.metric("QuickAssist-Length", selectionLength); |
280 instrumentation.metric("QuickAssist-ProposalCount", proposals.size()); | 284 instrumentation.metric("QuickAssist-ProposalCount", proposals.size()); |
281 instrumentation.data("QuickAssist-Source", utils.getText()); | 285 instrumentation.data("QuickAssist-Source", utils.getText()); |
282 for (int index = 0; index < proposals.size(); index++) { | 286 for (int index = 0; index < proposals.size(); index++) { |
283 instrumentation.data("QuickAssist-Proposal-" + index, proposals.get(inde
x).getName()); | 287 instrumentation.data("QuickAssist-Proposal-" + index, proposals.get(inde
x).getName()); |
284 } | 288 } |
285 return proposals.toArray(new CorrectionProposal[proposals.size()]); | 289 return proposals.toArray(new CorrectionProposal[proposals.size()]); |
286 } finally { | 290 } finally { |
287 instrumentation.log(); | 291 instrumentation.log(); |
| 292 cleanUp(); |
288 } | 293 } |
289 } | 294 } |
290 | 295 |
291 void addProposal_addTypeAnnotation() throws Exception { | 296 void addProposal_addTypeAnnotation() throws Exception { |
292 // prepare VariableDeclarationList | 297 // prepare VariableDeclarationList |
293 VariableDeclarationList declarationList = node.getAncestor(VariableDeclarati
onList.class); | 298 VariableDeclarationList declarationList = node.getAncestor(VariableDeclarati
onList.class); |
294 if (declarationList == null) { | 299 if (declarationList == null) { |
295 return; | 300 return; |
296 } | 301 } |
297 // may be has type annotation already | 302 // may be has type annotation already |
(...skipping 963 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1261 String assignSource = MessageFormat.format( | 1266 String assignSource = MessageFormat.format( |
1262 "{0} = {1};", | 1267 "{0} = {1};", |
1263 variable.getName().getName(), | 1268 variable.getName().getName(), |
1264 getSource(variable.getInitializer())); | 1269 getSource(variable.getInitializer())); |
1265 SourceRange assignRange = rangeEndLength(statement, 0); | 1270 SourceRange assignRange = rangeEndLength(statement, 0); |
1266 addReplaceEdit(assignRange, eol + indent + assignSource); | 1271 addReplaceEdit(assignRange, eol + indent + assignSource); |
1267 // add proposal | 1272 // add proposal |
1268 addUnitCorrectionProposal(QA_SPLIT_VARIABLE_DECLARATION); | 1273 addUnitCorrectionProposal(QA_SPLIT_VARIABLE_DECLARATION); |
1269 } | 1274 } |
1270 | 1275 |
1271 // private void addLinkedPositionProposal(String group, CorrectionImage icon, S
tring text) { | |
1272 // List<TrackedNodeProposal> nodeProposals = linkedPositionProposals.get(grou
p); | |
1273 // if (nodeProposals == null) { | |
1274 // nodeProposals = Lists.newArrayList(); | |
1275 // linkedPositionProposals.put(group, nodeProposals); | |
1276 // } | |
1277 // nodeProposals.add(new TrackedNodeProposal(icon, text)); | |
1278 // } | |
1279 | |
1280 void addProposal_surroundWith() throws Exception { | 1276 void addProposal_surroundWith() throws Exception { |
1281 // prepare selected statements | 1277 // prepare selected statements |
1282 List<Statement> selectedStatements; | 1278 List<Statement> selectedStatements; |
1283 { | 1279 { |
1284 SourceRange selection = rangeStartLength(selectionOffset, selectionLength)
; | 1280 SourceRange selection = rangeStartLength(selectionOffset, selectionLength)
; |
1285 StatementAnalyzer selectionAnalyzer = new StatementAnalyzer(unit, selectio
n); | 1281 StatementAnalyzer selectionAnalyzer = new StatementAnalyzer(unit, selectio
n); |
1286 unit.accept(selectionAnalyzer); | 1282 unit.accept(selectionAnalyzer); |
1287 List<AstNode> selectedNodes = selectionAnalyzer.getSelectedNodes(); | 1283 List<AstNode> selectedNodes = selectionAnalyzer.getSelectedNodes(); |
1288 // convert nodes to statements | 1284 // convert nodes to statements |
1289 selectedStatements = Lists.newArrayList(); | 1285 selectedStatements = Lists.newArrayList(); |
(...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1538 sb.append("}"); | 1534 sb.append("}"); |
1539 sb.append(eol); | 1535 sb.append(eol); |
1540 // | 1536 // |
1541 addInsertEdit(sb); | 1537 addInsertEdit(sb); |
1542 } | 1538 } |
1543 // add proposal | 1539 // add proposal |
1544 addUnitCorrectionProposal(QA_SURROUND_WITH_TRY_FINALLY); | 1540 addUnitCorrectionProposal(QA_SURROUND_WITH_TRY_FINALLY); |
1545 } | 1541 } |
1546 } | 1542 } |
1547 | 1543 |
| 1544 // private void addLinkedPositionProposal(String group, CorrectionImage icon, S
tring text) { |
| 1545 // List<TrackedNodeProposal> nodeProposals = linkedPositionProposals.get(grou
p); |
| 1546 // if (nodeProposals == null) { |
| 1547 // nodeProposals = Lists.newArrayList(); |
| 1548 // linkedPositionProposals.put(group, nodeProposals); |
| 1549 // } |
| 1550 // nodeProposals.add(new TrackedNodeProposal(icon, text)); |
| 1551 // } |
| 1552 |
1548 private void addInsertEdit(int offset, String text) { | 1553 private void addInsertEdit(int offset, String text) { |
1549 textEdits.add(createInsertEdit(offset, text)); | 1554 textEdits.add(createInsertEdit(offset, text)); |
1550 } | 1555 } |
1551 | 1556 |
1552 private void addInsertEdit(SourceBuilder builder) { | 1557 private void addInsertEdit(SourceBuilder builder) { |
1553 int offset = builder.getOffset(); | 1558 int offset = builder.getOffset(); |
1554 Edit edit = createInsertEdit(offset, builder.toString()); | 1559 Edit edit = createInsertEdit(offset, builder.toString()); |
1555 textEdits.add(edit); | 1560 textEdits.add(edit); |
1556 addLinkedPositions(builder, edit); | 1561 addLinkedPositions(builder, edit); |
1557 } | 1562 } |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1671 String relative = libraryFolderUri.relativize(unitUri).getPath(); | 1676 String relative = libraryFolderUri.relativize(unitUri).getPath(); |
1672 SourceChange change = getInsertPartDirectiveChange(librarySource, relati
ve); | 1677 SourceChange change = getInsertPartDirectiveChange(librarySource, relati
ve); |
1673 if (change == null) { | 1678 if (change == null) { |
1674 continue; | 1679 continue; |
1675 } | 1680 } |
1676 proposals.add(new SourceCorrectionProposal(change, CorrectionKind.QA_ADD
_PART_DIRECTIVE)); | 1681 proposals.add(new SourceCorrectionProposal(change, CorrectionKind.QA_ADD
_PART_DIRECTIVE)); |
1677 } | 1682 } |
1678 } | 1683 } |
1679 } | 1684 } |
1680 | 1685 |
| 1686 private void cleanUp() { |
| 1687 proposals.clear(); |
| 1688 textEdits.clear(); |
| 1689 positionStopEdits.clear(); |
| 1690 linkedPositions.clear(); |
| 1691 linkedPositionProposals.clear(); |
| 1692 assistContext = null; |
| 1693 analysisContext = null; |
| 1694 source = null; |
| 1695 unit = null; |
| 1696 node = null; |
| 1697 unitLibrarySource = null; |
| 1698 unitLibraryElement = null; |
| 1699 unitLibraryFile = null; |
| 1700 unitLibraryFolder = null; |
| 1701 utils = null; |
| 1702 } |
| 1703 |
1681 private Edit createInsertEdit(int offset, String text) { | 1704 private Edit createInsertEdit(int offset, String text) { |
1682 return new Edit(offset, 0, text); | 1705 return new Edit(offset, 0, text); |
1683 } | 1706 } |
1684 | 1707 |
1685 private FunctionBody getEnclosingFunctionBody() { | 1708 private FunctionBody getEnclosingFunctionBody() { |
1686 { | 1709 { |
1687 FunctionExpression function = node.getAncestor(FunctionExpression.class); | 1710 FunctionExpression function = node.getAncestor(FunctionExpression.class); |
1688 if (function != null) { | 1711 if (function != null) { |
1689 return function.getBody(); | 1712 return function.getBody(); |
1690 } | 1713 } |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1748 } | 1771 } |
1749 | 1772 |
1750 private void resetProposalElements() { | 1773 private void resetProposalElements() { |
1751 textEdits.clear(); | 1774 textEdits.clear(); |
1752 linkedPositions.clear(); | 1775 linkedPositions.clear(); |
1753 positionStopEdits.clear(); | 1776 positionStopEdits.clear(); |
1754 linkedPositionProposals.clear(); | 1777 linkedPositionProposals.clear(); |
1755 proposalEndRange = null; | 1778 proposalEndRange = null; |
1756 } | 1779 } |
1757 } | 1780 } |
OLD | NEW |