Lines 538-544
Link Here
|
538 |
* |
538 |
* |
539 |
* @param offset the index of the first character to parse |
539 |
* @param offset the index of the first character to parse |
540 |
* @param length the number of characters to parse, or -1 if |
540 |
* @param length the number of characters to parse, or -1 if |
541 |
* the remainder of the source string is |
541 |
* the remainder of the source string is to be parsed |
542 |
*/ |
542 |
*/ |
543 |
public void setSourceRange(int offset, int length) { |
543 |
public void setSourceRange(int offset, int length) { |
544 |
if (offset < 0 || length < -1) { |
544 |
if (offset < 0 || length < -1) { |
Lines 745-766
Link Here
|
745 |
} |
745 |
} |
746 |
|
746 |
|
747 |
/** |
747 |
/** |
748 |
* Creates bindings for a batch of Java elements. These elements are either |
748 |
* Creates bindings for a batch of Java elements. These elements are either |
749 |
* enclosed in {@link ICompilationUnit}s or in {@link IClassFile}s. |
749 |
* enclosed in {@link ICompilationUnit}s or in {@link IClassFile}s. |
750 |
* <p> |
750 |
* <p> |
751 |
* All enclosing compilation units and class files must |
751 |
* All enclosing compilation units and class files must |
752 |
* come from the same Java project, which must be set beforehand |
752 |
* come from the same Java project, which must be set beforehand |
753 |
* with <code>setProject</code>. |
753 |
* with <code>setProject</code>. |
754 |
* </p> |
754 |
* </p> |
755 |
* <p> |
755 |
* <p> |
756 |
* All elements must exist. If one doesn't exist, an <code>IllegalStateException</code> |
756 |
* All elements must exist. If one doesn't exist, an <code>IllegalStateException</code> |
757 |
* is thrown. |
757 |
* is thrown. |
758 |
* </p> |
758 |
* </p> |
759 |
* <p> |
759 |
* <p> |
760 |
* The returned array has the same size as the given elements array. At a given position |
760 |
* The returned array has the same size as the given elements array. At a given position |
761 |
* it contains the binding of the corresponding Java element, or <code>null</code> |
761 |
* it contains the binding of the corresponding Java element, or <code>null</code> |
762 |
* if no binding could be created. |
762 |
* if no binding could be created. |
763 |
* </p> |
763 |
* </p> |
764 |
* <p> |
764 |
* <p> |
765 |
* Note also the following parser parameters are used, regardless of what |
765 |
* Note also the following parser parameters are used, regardless of what |
766 |
* may have been specified: |
766 |
* may have been specified: |
Lines 771-788
Link Here
|
771 |
* <li>The {@linkplain #setFocalPosition(int) focal position} is not set</li> |
771 |
* <li>The {@linkplain #setFocalPosition(int) focal position} is not set</li> |
772 |
* </ul> |
772 |
* </ul> |
773 |
* </p> |
773 |
* </p> |
774 |
* <p> |
774 |
* <p> |
775 |
* A successful call to this method returns all settings to their |
775 |
* A successful call to this method returns all settings to their |
776 |
* default values so the object is ready to be reused. |
776 |
* default values so the object is ready to be reused. |
777 |
* </p> |
777 |
* </p> |
778 |
* |
778 |
* |
779 |
* @param elements the Java elements to create bindings for |
779 |
* @param elements the Java elements to create bindings for |
780 |
* @return the bindings for the given Java elements, possibly containing <code>null</code>s |
780 |
* @return the bindings for the given Java elements, possibly containing <code>null</code>s |
781 |
* if some bindings could not be created |
781 |
* if some bindings could not be created |
782 |
* @exception IllegalStateException if the settings provided |
782 |
* @exception IllegalStateException if the settings provided |
783 |
* are insufficient, contradictory, or otherwise unsupported |
783 |
* are insufficient, contradictory, or otherwise unsupported |
784 |
* @since 3.1 |
784 |
* @since 3.1 |
785 |
*/ |
785 |
*/ |
786 |
public IBinding[] createBindings(IJavaElement[] elements, IProgressMonitor monitor) { |
786 |
public IBinding[] createBindings(IJavaElement[] elements, IProgressMonitor monitor) { |
787 |
try { |
787 |
try { |
788 |
if (this.project == null) |
788 |
if (this.project == null) |
Lines 803-811
Link Here
|
803 |
case K_CLASS_BODY_DECLARATIONS : |
803 |
case K_CLASS_BODY_DECLARATIONS : |
804 |
case K_EXPRESSION : |
804 |
case K_EXPRESSION : |
805 |
case K_STATEMENTS : |
805 |
case K_STATEMENTS : |
|
|
806 |
if (this.rawSource == null) { |
807 |
if (this.typeRoot != null) { |
808 |
// get the source from the type root |
809 |
if (this.typeRoot instanceof ICompilationUnit) { |
810 |
org.eclipse.jdt.internal.compiler.env.ICompilationUnit sourceUnit = (org.eclipse.jdt.internal.compiler.env.ICompilationUnit) this.typeRoot; |
811 |
this.rawSource = sourceUnit.getContents(); |
812 |
} else if (this.typeRoot instanceof IClassFile) { |
813 |
try { |
814 |
String sourceString = this.typeRoot.getSource(); |
815 |
if (sourceString != null) { |
816 |
this.rawSource = sourceString.toCharArray(); |
817 |
} |
818 |
} catch(JavaModelException e) { |
819 |
// an error occured accessing the java element |
820 |
StringWriter stringWriter = new StringWriter(); |
821 |
PrintWriter writer = null; |
822 |
try { |
823 |
writer = new PrintWriter(stringWriter); |
824 |
e.printStackTrace(writer); |
825 |
} finally { |
826 |
if (writer != null) writer.close(); |
827 |
} |
828 |
throw new IllegalStateException(String.valueOf(stringWriter.getBuffer())); |
829 |
} |
830 |
} |
831 |
} |
832 |
} |
806 |
if (this.rawSource != null) { |
833 |
if (this.rawSource != null) { |
807 |
if (this.sourceOffset + this.sourceLength > this.rawSource.length) { |
834 |
if (this.sourceOffset + this.sourceLength > this.rawSource.length) { |
808 |
throw new IllegalStateException(); |
835 |
throw new IllegalStateException(); |
809 |
} |
836 |
} |
810 |
return internalCreateASTForKind(); |
837 |
return internalCreateASTForKind(); |
811 |
} |
838 |
} |