OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2012, the Dart project authors. | 2 * Copyright (c) 2012, 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 |
11 * or implied. See the License for the specific language governing permissions a
nd limitations under | 11 * or implied. See the License for the specific language governing permissions a
nd limitations under |
12 * the License. | 12 * the License. |
13 */ | 13 */ |
14 package com.google.dart.tools.core.internal.formatter; | 14 package com.google.dart.tools.core.internal.formatter; |
15 | 15 |
| 16 import com.google.common.collect.Sets; |
16 import com.google.dart.compiler.DartCompilationError; | 17 import com.google.dart.compiler.DartCompilationError; |
17 import com.google.dart.compiler.DartCompilerListener; | 18 import com.google.dart.compiler.DartCompilerListener; |
18 import com.google.dart.compiler.ast.DartComment; | 19 import com.google.dart.compiler.ast.DartComment; |
19 import com.google.dart.compiler.ast.DartExpression; | 20 import com.google.dart.compiler.ast.DartExpression; |
20 import com.google.dart.compiler.ast.DartMethodDefinition; | 21 import com.google.dart.compiler.ast.DartMethodDefinition; |
21 import com.google.dart.compiler.ast.DartNode; | 22 import com.google.dart.compiler.ast.DartNode; |
22 import com.google.dart.compiler.ast.DartUnit; | 23 import com.google.dart.compiler.ast.DartUnit; |
23 import com.google.dart.compiler.parser.CommentPreservingParser; | 24 import com.google.dart.compiler.parser.DartParser; |
24 import com.google.dart.compiler.parser.DartScannerParserContext; | |
25 import com.google.dart.tools.core.DartCore; | 25 import com.google.dart.tools.core.DartCore; |
26 import com.google.dart.tools.core.utilities.compiler.DartCompilerUtilities; | 26 import com.google.dart.tools.core.utilities.compiler.DartCompilerUtilities; |
27 | 27 |
28 import java.util.ArrayList; | 28 import java.util.ArrayList; |
29 import java.util.List; | 29 import java.util.List; |
30 import java.util.Map; | 30 import java.util.Map; |
31 | 31 |
32 /** | 32 /** |
33 * Utility methods for parsing snippets of code. Not quite sure what goes here. | 33 * Utility methods for parsing snippets of code. Not quite sure what goes here. |
34 * | 34 * |
35 * @deprecated Consider removing this class | 35 * @deprecated Consider removing this class |
36 */ | 36 */ |
37 @Deprecated | 37 @Deprecated |
38 @SuppressWarnings({"unused", "rawtypes"}) | 38 @SuppressWarnings({"rawtypes"}) |
39 public class CodeSnippetParsingUtil { | 39 public class CodeSnippetParsingUtil { |
40 class RecordedParsingInformation { | 40 class RecordedParsingInformation { |
41 public CategorizedProblem[] problems; | 41 public CategorizedProblem[] problems; |
42 public int problemsCount; | 42 public int problemsCount; |
43 public int[] lineEnds; | 43 public int[] lineEnds; |
44 public int[][] commentPositions; | 44 public int[][] commentPositions; |
45 | 45 |
46 public RecordedParsingInformation(CategorizedProblem[] problems, int[] lineE
nds, | 46 public RecordedParsingInformation(CategorizedProblem[] problems, int[] lineE
nds, |
47 int[][] commentPositions) { | 47 int[][] commentPositions) { |
48 this.problems = problems; | 48 this.problems = problems; |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
136 } | 136 } |
137 String sourceCode = new String(source); | 137 String sourceCode = new String(source); |
138 final CompilationResult compilationResult = new CompilationResult(); | 138 final CompilationResult compilationResult = new CompilationResult(); |
139 compilationResult.scanLines(sourceCode); | 139 compilationResult.scanLines(sourceCode); |
140 DartCompilerListener listener = new DartCompilerListener.Empty() { | 140 DartCompilerListener listener = new DartCompilerListener.Empty() { |
141 @Override | 141 @Override |
142 public void onError(DartCompilationError event) { | 142 public void onError(DartCompilationError event) { |
143 compilationResult.problemCount += 1; | 143 compilationResult.problemCount += 1; |
144 } | 144 } |
145 }; | 145 }; |
146 DartScannerParserContext ctx = new DartScannerParserContext(null, sourceCode
, listener); | 146 DartParser parser = new DartParser( |
147 CommentPreservingParser parser = new CommentPreservingParser(sourceCode, lis
tener, false); | 147 null, |
| 148 sourceCode, |
| 149 false, |
| 150 Sets.<String> newHashSet(), |
| 151 listener, |
| 152 null); |
148 DartUnit compilationUnit = DartCompilerUtilities.secureParseUnit(parser, nul
l); | 153 DartUnit compilationUnit = DartCompilerUtilities.secureParseUnit(parser, nul
l); |
149 if (recordParsingInformation) { | 154 if (recordParsingInformation) { |
150 recordedParsingInformation = getRecordedParsingInformation( | 155 recordedParsingInformation = getRecordedParsingInformation( |
151 compilationResult, | 156 compilationResult, |
152 extractCommentLocs(compilationUnit)); | 157 extractCommentLocs(compilationUnit)); |
153 recordedParsingInformation.updateRecordedParsingInformation(compilationRes
ult); | 158 recordedParsingInformation.updateRecordedParsingInformation(compilationRes
ult); |
154 } | 159 } |
155 return compilationUnit; | 160 return compilationUnit; |
156 | 161 |
157 // CompilerOptions compilerOptions = new CompilerOptions(settings); | 162 // CompilerOptions compilerOptions = new CompilerOptions(settings); |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
254 problemsCount); | 259 problemsCount); |
255 } | 260 } |
256 } | 261 } |
257 } | 262 } |
258 return new RecordedParsingInformation( | 263 return new RecordedParsingInformation( |
259 problems, | 264 problems, |
260 compilationResult.getLineSeparatorPositions(), | 265 compilationResult.getLineSeparatorPositions(), |
261 commentPositions); | 266 commentPositions); |
262 } | 267 } |
263 } | 268 } |
OLD | NEW |