}
return internalCreateASTForKind();
}
break;
case K_COMPILATION_UNIT :
CompilationUnitDeclaration compilationUnitDeclaration = null;
try {
NodeSearcher searcher = null;
org.aspectj.org.eclipse.jdt.internal.compiler.env.ICompilationUnit sourceUnit = null;
WorkingCopyOwner wcOwner = this.workingCopyOwner;
if (this.typeRoot instanceof ICompilationUnit) {
/*
* this.compilationUnitSource is an instance of org.aspectj.org.eclipse.jdt.internal.core.CompilationUnit that implements
* both org.aspectj.org.eclipse.jdt.core.ICompilationUnit and org.aspectj.org.eclipse.jdt.internal.compiler.env.ICompilationUnit
*/
sourceUnit = (org.aspectj.org.eclipse.jdt.internal.compiler.env.ICompilationUnit) this.typeRoot;
/*
* use a BasicCompilation that caches the source instead of using the compilationUnitSource directly
* (if it is a working copy, the source can change between the parse and the AST convertion)
* (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=75632)
*/
sourceUnit = new BasicCompilationUnit(sourceUnit.getContents(), sourceUnit.getPackageName(), new String(sourceUnit.getFileName()), this.project);
wcOwner = ((ICompilationUnit) this.typeRoot).getOwner();
} else if (this.typeRoot instanceof IClassFile) {
try {
String sourceString = this.typeRoot.getSource();
if (sourceString == null) {
throw new IllegalStateException();
}
PackageFragment packageFragment = (PackageFragment) this.typeRoot.getParent();
BinaryType type = (BinaryType) this.typeRoot.findPrimaryType();
IBinaryType binaryType = (IBinaryType) type.getElementInfo();
// file name is used to recreate the Java element, so it has to be the toplevel .class file name
char[] fileName = binaryType.getFileName();
int firstDollar = CharOperation.indexOf('$', fileName);
if (firstDollar != -1) {
char[] suffix = SuffixConstants.SUFFIX_class;
int suffixLength = suffix.length;
char[] newFileName = new char[firstDollar + suffixLength];
System.arraycopy(fileName, 0, newFileName, 0, firstDollar);
System.arraycopy(suffix, 0, newFileName, firstDollar, suffixLength);
fileName = newFileName;
}
sourceUnit = new BasicCompilationUnit(sourceString.toCharArray(), Util.toCharArrays(packageFragment.names), new String(fileName), this.project);
} catch(JavaModelException e) {
// an error occured accessing the java element
throw new IllegalStateException();
}
} else if (this.rawSource != null) {
needToResolveBindings = this.resolveBindings && this.unitName != null && this.project != null && this.compilerOptions != null;
sourceUnit = new BasicCompilationUnit(this.rawSource, null, this.unitName == null ? "" : this.unitName, this.project); //$NON-NLS-1$
} else {
throw new IllegalStateException();
}
if (this.partial) {
searcher = new NodeSearcher(this.focalPointPosition);
}
int flags = 0;
if (this.statementsRecovery) flags |= ICompilationUnit.ENABLE_STATEMENTS_RECOVERY;
if (needToResolveBindings) {
if (this.bindingsRecovery) flags |= ICompilationUnit.ENABLE_BINDINGS_RECOVERY;
try {
// parse and resolve
compilationUnitDeclaration =
CompilationUnitResolver.resolve(
sourceUnit,
this.project,
searcher,
this.compilerOptions,
this.workingCopyOwner,
flags,
monitor);
} catch (JavaModelException e) {
flags &= ~ICompilationUnit.ENABLE_BINDINGS_RECOVERY;
compilationUnitDeclaration = CompilationUnitResolver.parse(
sourceUnit,
searcher,
this.compilerOptions,
flags);
needToResolveBindings = false;
}
} else {
compilationUnitDeclaration = CompilationUnitResolver.parse(
sourceUnit,
searcher,
this.compilerOptions,
flags);
needToResolveBindings = false;
}
CompilationUnit result = CompilationUnitResolver.convert(
compilationUnitDeclaration,
sourceUnit.getContents(),
this.apiLevel,
this.compilerOptions,
needToResolveBindings,
wcOwner,
needToResolveBindings ? new DefaultBindingResolver.BindingTables() : null,
flags,
monitor);
result.setTypeRoot(this.typeRoot);
return result;
} finally {
if (compilationUnitDeclaration != null && this.resolveBindings) {
compilationUnitDeclaration.cleanUp();
}
}
}
throw new IllegalStateException();
}