Lines 17-22
Link Here
|
17 |
import org.eclipse.jdt.core.IClassFile; |
17 |
import org.eclipse.jdt.core.IClassFile; |
18 |
import org.eclipse.jdt.core.ICompilationUnit; |
18 |
import org.eclipse.jdt.core.ICompilationUnit; |
19 |
import org.eclipse.jdt.core.IJavaElement; |
19 |
import org.eclipse.jdt.core.IJavaElement; |
|
|
20 |
import org.eclipse.jdt.core.ITypeRoot; |
20 |
import org.eclipse.jdt.core.IJavaProject; |
21 |
import org.eclipse.jdt.core.IJavaProject; |
21 |
import org.eclipse.jdt.core.JavaCore; |
22 |
import org.eclipse.jdt.core.JavaCore; |
22 |
import org.eclipse.jdt.core.JavaModelException; |
23 |
import org.eclipse.jdt.core.JavaModelException; |
Lines 154-167
Link Here
|
154 |
private char[] rawSource = null; |
155 |
private char[] rawSource = null; |
155 |
|
156 |
|
156 |
/** |
157 |
/** |
157 |
* Java mode compilation unit supplying the source. |
158 |
* Java model class file or compilation unit supplying the source. |
158 |
*/ |
159 |
*/ |
159 |
private ICompilationUnit compilationUnitSource = null; |
160 |
private ITypeRoot typeRoot = null; |
160 |
|
|
|
161 |
/** |
162 |
* Java model class file supplying the source. |
163 |
*/ |
164 |
private IClassFile classFileSource = null; |
165 |
|
161 |
|
166 |
/** |
162 |
/** |
167 |
* Character-based offset into the source string where parsing is to |
163 |
* Character-based offset into the source string where parsing is to |
Lines 218-225
Link Here
|
218 |
private void initializeDefaults() { |
214 |
private void initializeDefaults() { |
219 |
this.astKind = K_COMPILATION_UNIT; |
215 |
this.astKind = K_COMPILATION_UNIT; |
220 |
this.rawSource = null; |
216 |
this.rawSource = null; |
221 |
this.classFileSource = null; |
217 |
this.typeRoot = null; |
222 |
this.compilationUnitSource = null; |
|
|
223 |
this.resolveBindings = false; |
218 |
this.resolveBindings = false; |
224 |
this.sourceLength = -1; |
219 |
this.sourceLength = -1; |
225 |
this.sourceOffset = 0; |
220 |
this.sourceOffset = 0; |
Lines 452-460
Link Here
|
452 |
*/ |
447 |
*/ |
453 |
public void setSource(char[] source) { |
448 |
public void setSource(char[] source) { |
454 |
this.rawSource = source; |
449 |
this.rawSource = source; |
455 |
// clear the others |
450 |
// clear the type root |
456 |
this.compilationUnitSource = null; |
451 |
this.typeRoot = null; |
457 |
this.classFileSource = null; |
|
|
458 |
} |
452 |
} |
459 |
|
453 |
|
460 |
/** |
454 |
/** |
Lines 467-482
Link Here
|
467 |
* is to be parsed, or <code>null</code> if none |
461 |
* is to be parsed, or <code>null</code> if none |
468 |
*/ |
462 |
*/ |
469 |
public void setSource(ICompilationUnit source) { |
463 |
public void setSource(ICompilationUnit source) { |
470 |
this.compilationUnitSource = source; |
464 |
setTypeRoot(source); |
471 |
// clear the others |
|
|
472 |
this.rawSource = null; |
473 |
this.classFileSource = null; |
474 |
if (source != null) { |
475 |
this.project = source.getJavaProject(); |
476 |
Map options = this.project.getOptions(true); |
477 |
options.remove(JavaCore.COMPILER_TASK_TAGS); // no need to parse task tags |
478 |
this.compilerOptions = options; |
479 |
} |
480 |
} |
465 |
} |
481 |
|
466 |
|
482 |
/** |
467 |
/** |
Lines 491-500
Link Here
|
491 |
* is to be parsed, or <code>null</code> if none |
476 |
* is to be parsed, or <code>null</code> if none |
492 |
*/ |
477 |
*/ |
493 |
public void setSource(IClassFile source) { |
478 |
public void setSource(IClassFile source) { |
494 |
this.classFileSource = source; |
479 |
setTypeRoot(source); |
495 |
// clear the others |
480 |
} |
|
|
481 |
|
482 |
/* (non-Javadoc) |
483 |
* Sets the source code to be parsed. |
484 |
*/ |
485 |
void setTypeRoot(ITypeRoot source) { |
486 |
this.typeRoot = source; |
487 |
// clear the raw source |
496 |
this.rawSource = null; |
488 |
this.rawSource = null; |
497 |
this.compilationUnitSource = null; |
|
|
498 |
if (source != null) { |
489 |
if (source != null) { |
499 |
this.project = source.getJavaProject(); |
490 |
this.project = source.getJavaProject(); |
500 |
Map options = this.project.getOptions(true); |
491 |
Map options = this.project.getOptions(true); |
Lines 622-630
Link Here
|
622 |
ASTNode result = null; |
613 |
ASTNode result = null; |
623 |
if (monitor != null) monitor.beginTask("", 1); //$NON-NLS-1$ |
614 |
if (monitor != null) monitor.beginTask("", 1); //$NON-NLS-1$ |
624 |
try { |
615 |
try { |
625 |
if ((this.rawSource == null) |
616 |
if (this.rawSource == null && this.typeRoot == null) { |
626 |
&& (this.compilationUnitSource == null) |
|
|
627 |
&& (this.classFileSource == null)) { |
628 |
throw new IllegalStateException("source not specified"); //$NON-NLS-1$ |
617 |
throw new IllegalStateException("source not specified"); //$NON-NLS-1$ |
629 |
} |
618 |
} |
630 |
result = internalCreateAST(monitor); |
619 |
result = internalCreateAST(monitor); |
Lines 782-809
Link Here
|
782 |
try { |
771 |
try { |
783 |
NodeSearcher searcher = null; |
772 |
NodeSearcher searcher = null; |
784 |
org.eclipse.jdt.internal.compiler.env.ICompilationUnit sourceUnit = null; |
773 |
org.eclipse.jdt.internal.compiler.env.ICompilationUnit sourceUnit = null; |
785 |
IJavaElement element = null; |
774 |
WorkingCopyOwner wcOwner = this.workingCopyOwner; |
786 |
if (this.compilationUnitSource != null) { |
775 |
if (this.typeRoot instanceof ICompilationUnit) { |
787 |
/* |
776 |
/* |
788 |
* this.compilationUnitSource is an instance of org.eclipse.jdt.internal.core.CompilationUnit that implements |
777 |
* this.compilationUnitSource is an instance of org.eclipse.jdt.internal.core.CompilationUnit that implements |
789 |
* both org.eclipse.jdt.core.ICompilationUnit and org.eclipse.jdt.internal.compiler.env.ICompilationUnit |
778 |
* both org.eclipse.jdt.core.ICompilationUnit and org.eclipse.jdt.internal.compiler.env.ICompilationUnit |
790 |
*/ |
779 |
*/ |
791 |
sourceUnit = (org.eclipse.jdt.internal.compiler.env.ICompilationUnit) this.compilationUnitSource; |
780 |
sourceUnit = (org.eclipse.jdt.internal.compiler.env.ICompilationUnit) this.typeRoot; |
792 |
/* |
781 |
/* |
793 |
* use a BasicCompilation that caches the source instead of using the compilationUnitSource directly |
782 |
* use a BasicCompilation that caches the source instead of using the compilationUnitSource directly |
794 |
* (if it is a working copy, the source can change between the parse and the AST convertion) |
783 |
* (if it is a working copy, the source can change between the parse and the AST convertion) |
795 |
* (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=75632) |
784 |
* (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=75632) |
796 |
*/ |
785 |
*/ |
797 |
sourceUnit = new BasicCompilationUnit(sourceUnit.getContents(), sourceUnit.getPackageName(), new String(sourceUnit.getFileName()), this.project); |
786 |
sourceUnit = new BasicCompilationUnit(sourceUnit.getContents(), sourceUnit.getPackageName(), new String(sourceUnit.getFileName()), this.project); |
798 |
element = this.compilationUnitSource; |
787 |
wcOwner = ((ICompilationUnit) this.typeRoot).getOwner(); |
799 |
} else if (this.classFileSource != null) { |
788 |
} else if (this.typeRoot instanceof IClassFile) { |
800 |
try { |
789 |
try { |
801 |
String sourceString = this.classFileSource.getSource(); |
790 |
String sourceString = this.typeRoot.getSource(); |
802 |
if (sourceString == null) { |
791 |
if (sourceString == null) { |
803 |
throw new IllegalStateException(); |
792 |
throw new IllegalStateException(); |
804 |
} |
793 |
} |
805 |
PackageFragment packageFragment = (PackageFragment) this.classFileSource.getParent(); |
794 |
PackageFragment packageFragment = (PackageFragment) this.typeRoot.getParent(); |
806 |
BinaryType type = (BinaryType) this.classFileSource.getType(); |
795 |
BinaryType type = (BinaryType) this.typeRoot.findPrimaryType(); |
807 |
IBinaryType binaryType = (IBinaryType) type.getElementInfo(); |
796 |
IBinaryType binaryType = (IBinaryType) type.getElementInfo(); |
808 |
// file name is used to recreate the Java element, so it has to be the toplevel .class file name |
797 |
// file name is used to recreate the Java element, so it has to be the toplevel .class file name |
809 |
char[] fileName = binaryType.getFileName(); |
798 |
char[] fileName = binaryType.getFileName(); |
Lines 817-823
Link Here
|
817 |
fileName = newFileName; |
806 |
fileName = newFileName; |
818 |
} |
807 |
} |
819 |
sourceUnit = new BasicCompilationUnit(sourceString.toCharArray(), Util.toCharArrays(packageFragment.names), new String(fileName), this.project); |
808 |
sourceUnit = new BasicCompilationUnit(sourceString.toCharArray(), Util.toCharArrays(packageFragment.names), new String(fileName), this.project); |
820 |
element = this.classFileSource; |
|
|
821 |
} catch(JavaModelException e) { |
809 |
} catch(JavaModelException e) { |
822 |
// an error occured accessing the java element |
810 |
// an error occured accessing the java element |
823 |
throw new IllegalStateException(); |
811 |
throw new IllegalStateException(); |
Lines 865-874
Link Here
|
865 |
this.apiLevel, |
853 |
this.apiLevel, |
866 |
this.compilerOptions, |
854 |
this.compilerOptions, |
867 |
needToResolveBindings, |
855 |
needToResolveBindings, |
868 |
this.compilationUnitSource == null ? this.workingCopyOwner : this.compilationUnitSource.getOwner(), |
856 |
wcOwner, |
869 |
needToResolveBindings ? new DefaultBindingResolver.BindingTables() : null, |
857 |
needToResolveBindings ? new DefaultBindingResolver.BindingTables() : null, |
870 |
monitor); |
858 |
monitor); |
871 |
result.setJavaElement(element); |
859 |
result.setTypeRoot(this.typeRoot); |
872 |
return result; |
860 |
return result; |
873 |
} finally { |
861 |
} finally { |
874 |
if (compilationUnitDeclaration != null && this.resolveBindings) { |
862 |
if (compilationUnitDeclaration != null && this.resolveBindings) { |