Lines 50-55
Link Here
|
50 |
import org.eclipse.jdt.internal.compiler.parser.RecoveryScanner; |
50 |
import org.eclipse.jdt.internal.compiler.parser.RecoveryScanner; |
51 |
import org.eclipse.jdt.internal.compiler.parser.Scanner; |
51 |
import org.eclipse.jdt.internal.compiler.parser.Scanner; |
52 |
import org.eclipse.jdt.internal.compiler.parser.TerminalTokens; |
52 |
import org.eclipse.jdt.internal.compiler.parser.TerminalTokens; |
|
|
53 |
import org.eclipse.jdt.internal.core.util.Util; |
53 |
|
54 |
|
54 |
/** |
55 |
/** |
55 |
* Internal class for converting internal compiler ASTs into public ASTs. |
56 |
* Internal class for converting internal compiler ASTs into public ASTs. |
Lines 1198-1275
Link Here
|
1198 |
} |
1199 |
} |
1199 |
|
1200 |
|
1200 |
public CompilationUnit convert(org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration unit, char[] source) { |
1201 |
public CompilationUnit convert(org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration unit, char[] source) { |
1201 |
if(unit.compilationResult.recoveryScannerData != null) { |
|
|
1202 |
RecoveryScanner recoveryScanner = new RecoveryScanner(this.scanner, unit.compilationResult.recoveryScannerData.removeUnused()); |
1203 |
this.scanner = recoveryScanner; |
1204 |
this.docParser.scanner = this.scanner; |
1205 |
} |
1206 |
this.compilationUnitSource = source; |
1207 |
this.compilationUnitSourceLength = source.length; |
1208 |
this.scanner.setSource(source, unit.compilationResult); |
1209 |
CompilationUnit compilationUnit = new CompilationUnit(this.ast); |
1202 |
CompilationUnit compilationUnit = new CompilationUnit(this.ast); |
1210 |
|
1203 |
try { |
1211 |
// Parse comments |
1204 |
if(unit.compilationResult.recoveryScannerData != null) { |
1212 |
int[][] comments = unit.comments; |
1205 |
RecoveryScanner recoveryScanner = new RecoveryScanner(this.scanner, unit.compilationResult.recoveryScannerData.removeUnused()); |
1213 |
if (comments != null) { |
1206 |
this.scanner = recoveryScanner; |
1214 |
buildCommentsTable(compilationUnit, comments); |
1207 |
this.docParser.scanner = this.scanner; |
1215 |
} |
1208 |
} |
1216 |
|
1209 |
this.compilationUnitSource = source; |
1217 |
// handle the package declaration immediately |
1210 |
this.compilationUnitSourceLength = source.length; |
1218 |
// There is no node corresponding to the package declaration |
1211 |
this.scanner.setSource(source, unit.compilationResult); |
1219 |
if (this.resolveBindings) { |
1212 |
|
1220 |
recordNodes(compilationUnit, unit); |
1213 |
// Parse comments |
1221 |
} |
1214 |
int[][] comments = unit.comments; |
1222 |
if (unit.currentPackage != null) { |
1215 |
if (comments != null) { |
1223 |
PackageDeclaration packageDeclaration = convertPackage(unit); |
1216 |
buildCommentsTable(compilationUnit, comments); |
1224 |
compilationUnit.setPackage(packageDeclaration); |
|
|
1225 |
} |
1226 |
org.eclipse.jdt.internal.compiler.ast.ImportReference[] imports = unit.imports; |
1227 |
if (imports != null) { |
1228 |
int importLength = imports.length; |
1229 |
for (int i = 0; i < importLength; i++) { |
1230 |
compilationUnit.imports().add(convertImport(imports[i])); |
1231 |
} |
1217 |
} |
1232 |
} |
1218 |
|
1233 |
|
1219 |
// handle the package declaration immediately |
1234 |
org.eclipse.jdt.internal.compiler.ast.TypeDeclaration[] types = unit.types; |
1220 |
// There is no node corresponding to the package declaration |
1235 |
if (types != null) { |
1221 |
if (this.resolveBindings) { |
1236 |
int typesLength = types.length; |
1222 |
recordNodes(compilationUnit, unit); |
1237 |
for (int i = 0; i < typesLength; i++) { |
1223 |
} |
1238 |
org.eclipse.jdt.internal.compiler.ast.TypeDeclaration declaration = types[i]; |
1224 |
if (unit.currentPackage != null) { |
1239 |
if (CharOperation.equals(declaration.name, TypeConstants.PACKAGE_INFO_NAME)) { |
1225 |
PackageDeclaration packageDeclaration = convertPackage(unit); |
1240 |
continue; |
1226 |
compilationUnit.setPackage(packageDeclaration); |
|
|
1227 |
} |
1228 |
org.eclipse.jdt.internal.compiler.ast.ImportReference[] imports = unit.imports; |
1229 |
if (imports != null) { |
1230 |
int importLength = imports.length; |
1231 |
for (int i = 0; i < importLength; i++) { |
1232 |
compilationUnit.imports().add(convertImport(imports[i])); |
1241 |
} |
1233 |
} |
1242 |
ASTNode type = convert(declaration); |
1234 |
} |
1243 |
if (type == null) { |
1235 |
|
1244 |
compilationUnit.setFlags(compilationUnit.getFlags() | ASTNode.MALFORMED); |
1236 |
org.eclipse.jdt.internal.compiler.ast.TypeDeclaration[] types = unit.types; |
|
|
1237 |
if (types != null) { |
1238 |
int typesLength = types.length; |
1239 |
for (int i = 0; i < typesLength; i++) { |
1240 |
org.eclipse.jdt.internal.compiler.ast.TypeDeclaration declaration = types[i]; |
1241 |
if (CharOperation.equals(declaration.name, TypeConstants.PACKAGE_INFO_NAME)) { |
1242 |
continue; |
1243 |
} |
1244 |
ASTNode type = convert(declaration); |
1245 |
if (type == null) { |
1246 |
compilationUnit.setFlags(compilationUnit.getFlags() | ASTNode.MALFORMED); |
1247 |
} else { |
1248 |
compilationUnit.types().add(type); |
1249 |
} |
1250 |
} |
1251 |
} |
1252 |
compilationUnit.setSourceRange(unit.sourceStart, unit.sourceEnd - unit.sourceStart + 1); |
1253 |
|
1254 |
int problemLength = unit.compilationResult.problemCount; |
1255 |
if (problemLength != 0) { |
1256 |
CategorizedProblem[] resizedProblems = null; |
1257 |
final CategorizedProblem[] problems = unit.compilationResult.getProblems(); |
1258 |
final int realProblemLength=problems.length; |
1259 |
if (realProblemLength == problemLength) { |
1260 |
resizedProblems = problems; |
1245 |
} else { |
1261 |
} else { |
1246 |
compilationUnit.types().add(type); |
1262 |
System.arraycopy(problems, 0, (resizedProblems = new CategorizedProblem[realProblemLength]), 0, realProblemLength); |
1247 |
} |
1263 |
} |
|
|
1264 |
ASTSyntaxErrorPropagator syntaxErrorPropagator = new ASTSyntaxErrorPropagator(resizedProblems); |
1265 |
compilationUnit.accept(syntaxErrorPropagator); |
1266 |
ASTRecoveryPropagator recoveryPropagator = |
1267 |
new ASTRecoveryPropagator(resizedProblems, unit.compilationResult.recoveryScannerData); |
1268 |
compilationUnit.accept(recoveryPropagator); |
1269 |
compilationUnit.setProblems(resizedProblems); |
1248 |
} |
1270 |
} |
1249 |
} |
1271 |
if (this.resolveBindings) { |
1250 |
compilationUnit.setSourceRange(unit.sourceStart, unit.sourceEnd - unit.sourceStart + 1); |
1272 |
lookupForScopes(); |
1251 |
|
|
|
1252 |
int problemLength = unit.compilationResult.problemCount; |
1253 |
if (problemLength != 0) { |
1254 |
CategorizedProblem[] resizedProblems = null; |
1255 |
final CategorizedProblem[] problems = unit.compilationResult.getProblems(); |
1256 |
final int realProblemLength=problems.length; |
1257 |
if (realProblemLength == problemLength) { |
1258 |
resizedProblems = problems; |
1259 |
} else { |
1260 |
System.arraycopy(problems, 0, (resizedProblems = new CategorizedProblem[realProblemLength]), 0, realProblemLength); |
1261 |
} |
1273 |
} |
1262 |
ASTSyntaxErrorPropagator syntaxErrorPropagator = new ASTSyntaxErrorPropagator(resizedProblems); |
1274 |
compilationUnit.initCommentMapper(this.scanner); |
1263 |
compilationUnit.accept(syntaxErrorPropagator); |
1275 |
} catch(RuntimeException e) { |
1264 |
ASTRecoveryPropagator recoveryPropagator = |
1276 |
// avoid breaking other tools due to internal compiler failure (40334) |
1265 |
new ASTRecoveryPropagator(resizedProblems, unit.compilationResult.recoveryScannerData); |
1277 |
StringBuffer message = new StringBuffer("Exception occurred during problem detection:"); //$NON-NLS-1$ |
1266 |
compilationUnit.accept(recoveryPropagator); |
1278 |
String lineDelimiter = Util.findLineSeparator(source); |
1267 |
compilationUnit.setProblems(resizedProblems); |
1279 |
if (lineDelimiter == null) lineDelimiter = System.getProperty("line.separator");//$NON-NLS-1$ |
1268 |
} |
1280 |
message.append(lineDelimiter); |
1269 |
if (this.resolveBindings) { |
1281 |
message.append("----------------------------------- SOURCE BEGIN -------------------------------------"); //$NON-NLS-1$ |
1270 |
lookupForScopes(); |
1282 |
message.append(lineDelimiter); |
|
|
1283 |
message.append(source); |
1284 |
message.append(lineDelimiter); |
1285 |
message.append("----------------------------------- SOURCE END -------------------------------------"); //$NON-NLS-1$ |
1286 |
Util.log(e, message.toString()); |
1287 |
throw e; |
1271 |
} |
1288 |
} |
1272 |
compilationUnit.initCommentMapper(this.scanner); |
|
|
1273 |
return compilationUnit; |
1289 |
return compilationUnit; |
1274 |
} |
1290 |
} |
1275 |
|
1291 |
|