Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 111389 Details for
Bug 245835
CompletionContext extends non-API type InternalCompletionContext
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
[patch]
Proposed fix
245835.txt (text/plain), 21.20 KB, created by
Jerome Lanneluc
on 2008-09-01 05:13:19 EDT
(
hide
)
Description:
Proposed fix
Filename:
MIME Type:
Creator:
Jerome Lanneluc
Created:
2008-09-01 05:13:19 EDT
Size:
21.20 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.jdt.core >Index: codeassist/org/eclipse/jdt/internal/codeassist/InternalCompletionContext.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/codeassist/org/eclipse/jdt/internal/codeassist/InternalCompletionContext.java,v >retrieving revision 1.12 >diff -u -r1.12 InternalCompletionContext.java >--- codeassist/org/eclipse/jdt/internal/codeassist/InternalCompletionContext.java 27 Jun 2008 16:04:03 -0000 1.12 >+++ codeassist/org/eclipse/jdt/internal/codeassist/InternalCompletionContext.java 1 Sep 2008 09:12:54 -0000 >@@ -10,8 +10,17 @@ > *******************************************************************************/ > package org.eclipse.jdt.internal.codeassist; > >+import org.eclipse.jdt.core.CompletionContext; >+import org.eclipse.jdt.core.ICompilationUnit; >+import org.eclipse.jdt.core.IField; >+import org.eclipse.jdt.core.IJavaElement; >+import org.eclipse.jdt.core.ILocalVariable; >+import org.eclipse.jdt.core.IMember; >+import org.eclipse.jdt.core.IMethod; > import org.eclipse.jdt.core.ITypeRoot; >+import org.eclipse.jdt.core.Signature; > import org.eclipse.jdt.core.WorkingCopyOwner; >+import org.eclipse.jdt.internal.codeassist.complete.CompletionOnJavadoc; > import org.eclipse.jdt.internal.codeassist.complete.CompletionParser; > import org.eclipse.jdt.internal.compiler.ast.ASTNode; > import org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration; >@@ -23,7 +32,7 @@ > * Internal completion context > * @since 3.1 > */ >-public class InternalCompletionContext { >+public class InternalCompletionContext extends CompletionContext { > protected char[][] expectedTypesSignatures; > protected char[][] expectedTypesKeys; > protected int javadoc; >@@ -106,4 +115,257 @@ > this.tokenEnd = 0; > } > } >+ >+ /** >+ * Returns the innermost enclosing Java element which contains the completion location or <code>null</code> if this element cannot be computed. >+ * The returned Java element and all Java elements in the same compilation unit which can be navigated to from the returned Java element are special Java elements: >+ * <ul> >+ * <li>they are based on the current content of the compilation unit's buffer, they are not the result of a reconcile operation</li> >+ * <li>they are not updated if the buffer changes.</li> >+ * <li>they do not contain local types which are not visible from the completion location.</li> >+ * <li>they do not give information about categories. {@link IMember#getCategories()} will return an empty array</li> >+ * </ul> >+ * >+ * Reasons for returning <code>null</code> include: >+ * <ul> >+ * <li>the compilation unit no longer exists</li> >+ * <li>the completion occurred in a binary type. However this restriction might be relaxed in the future.</li> >+ * </ul> >+ * >+ * @return the innermost enclosing Java element which contains the completion location or <code>null</code> if this element cannot be computed. >+ * >+ * @exception UnsupportedOperationException if the context is not an extended context >+ * >+ * @since 3.4 >+ */ >+ public IJavaElement getEnclosingElement() { >+ if (!this.isExtended) throw new UnsupportedOperationException("Operation only supported in extended context"); //$NON-NLS-1$ >+ >+ if (this.extendedContext == null) return null; >+ >+ return this.extendedContext.getEnclosingElement(); >+ } >+ >+ /** >+ * Return keys of expected types of a potential completion proposal at the completion position. >+ * >+ * It's not mandatory to a completion proposal to respect this expectation. >+ * >+ * @return keys of expected types of a potential completion proposal at the completion position or >+ * <code>null</code> if there is no expected types. >+ * >+ * @see org.eclipse.jdt.core.dom.ASTParser#createASTs(ICompilationUnit[], String[], org.eclipse.jdt.core.dom.ASTRequestor, org.eclipse.core.runtime.IProgressMonitor) >+ */ >+ public char[][] getExpectedTypesKeys() { >+ return this.expectedTypesKeys; >+ } >+ >+ /** >+ * Return signatures of expected types of a potential completion proposal at the completion position. >+ * >+ * It's not mandatory to a completion proposal to respect this expectation. >+ * >+ * @return signatures expected types of a potential completion proposal at the completion position or >+ * <code>null</code> if there is no expected types. >+ * >+ * @see Signature >+ */ >+ public char[][] getExpectedTypesSignatures() { >+ return this.expectedTypesSignatures; >+ } >+ >+ /** >+ * Returns the offset position in the source file buffer >+ * after which code assist is requested. >+ * >+ * @return offset position in the source file buffer >+ * @since 3.2 >+ */ >+ public int getOffset() { >+ return this.offset; >+ } >+ >+ /** >+ * Returns the completed token. >+ * This token is either the identifier or Java language keyword >+ * or the string literal under, immediately preceding, >+ * the original request offset. If the original request offset >+ * is not within or immediately after an identifier or keyword or >+ * a string literal then the returned value is <code>null</code>. >+ * >+ * @return completed token or <code>null</code> >+ * @since 3.2 >+ */ >+ public char[] getToken() { >+ return this.token; >+ } >+ >+ /** >+ * Returns the character index of the end (exclusive) of the subrange >+ * in the source file buffer containing the >+ * relevant token. When there is no relevant token, the >+ * range is empty >+ * (<code>getTokenEnd() == getTokenStart() - 1</code>). >+ * >+ * @return character index of token end position (exclusive) >+ * @since 3.2 >+ */ >+ // TODO (david) https://bugs.eclipse.org/bugs/show_bug.cgi?id=132558 >+ public int getTokenEnd() { >+ return this.tokenEnd; >+ } >+ >+ /** >+ * Returns the kind of completion token being proposed. >+ * <p> >+ * The set of different kinds of completion token is >+ * expected to change over time. It is strongly recommended >+ * that clients do <b>not</b> assume that the kind is one of the >+ * ones they know about, and code defensively for the >+ * possibility of unexpected future growth. >+ * </p> >+ * >+ * @return the kind; one of the kind constants declared on >+ * this class whose name starts with <code>TOKEN_KIND</code>, >+ * or possibly a kind unknown to the caller >+ * @since 3.2 >+ */ >+ public int getTokenKind() { >+ return this.tokenKind; >+ } >+ >+ /** >+ * Returns the location of completion token being proposed. >+ * The returned location is a bit mask which can contain some values >+ * of the constants declared on this class whose name starts with <code>TL</code>, >+ * or possibly values unknown to the caller. >+ * >+ * <p> >+ * The set of different location values is expected to change over time. >+ * It is strongly recommended that clients do <b>not</b> assume that >+ * the location contains only known value, and code defensively for >+ * the possibility of unexpected future growth. >+ * </p> >+ * >+ * @return the location >+ * >+ * @since 3.4 >+ */ >+ public int getTokenLocation() { >+ return this.tokenLocation; >+ } >+ >+ /** >+ * Returns the character index of the start of the >+ * subrange in the source file buffer containing the >+ * relevant token being completed. This >+ * token is either the identifier or Java language keyword >+ * under, or immediately preceding, the original request >+ * offset. If the original request offset is not within >+ * or immediately after an identifier or keyword, then the >+ * position returned is original request offset and the >+ * token range is empty. >+ * >+ * @return character index of token start position (inclusive) >+ * @since 3.2 >+ */ >+ public int getTokenStart() { >+ return this.tokenStart; >+ } >+ >+ /** >+ * Return the elements which are visible from the completion location and which can be assigned to the given type. >+ * An element is assignable if its type can be assigned to a variable >+ * of the given type, as specified in section 5.2 of <em>The Java Language >+ * Specification, Third Edition</em> (JLS3). >+ * A visible element is either: >+ * <ul> >+ * <li>a {@link ILocalVariable} - the element type is {@link ILocalVariable#getTypeSignature()}</li> >+ * <li>a {@link IField} - the element type is {@link IField#getTypeSignature()}</li> >+ * <li>a {@link IMethod} - the element type is {@link IMethod#getReturnType()}</li> >+ * </ul> >+ * >+ * Returned elements defined in the completed compilation unit are special Java elements: >+ * <ul> >+ * <li>they are based on the current content of the compilation unit's buffer, they are not the result of a reconcile operation</li> >+ * <li>they are not updated if the buffer changes.</li> >+ * <li>they do not contain local types which are not visible from the completion location.</li> >+ * <li>they do not give information about categories. {@link IMember#getCategories()} will return an empty array</li> >+ * </ul> >+ * >+ * Note the array can be empty if: >+ * <ul> >+ * <li>the compilation unit no longer exists</li> >+ * <li>the completion occurred in a binary type. However this restriction might be relaxed in the future.</li> >+ * </ul> >+ * >+ * @param typeSignature elements which can be assigned to this type are returned. >+ * If <code>null</code> there is no constraint on the type of the returned elements. >+ * >+ * @return elements which are visible from the completion location and which can be assigned to the given type. >+ * >+ * @exception UnsupportedOperationException if the context is not an extended context >+ * >+ * @see #isExtended() >+ * >+ * @since 3.4 >+ */ >+ public IJavaElement[] getVisibleElements(String typeSignature) { >+ if (!this.isExtended) throw new UnsupportedOperationException("Operation only supported in extended context"); //$NON-NLS-1$ >+ >+ if (this.extendedContext == null) return new IJavaElement[0]; >+ >+ return this.extendedContext.getVisibleElements(typeSignature); >+ } >+ >+ /** >+ * Returns whether this completion context is an extended context. >+ * Some methods of this context can be used only if this context is an extended context but an extended context consumes more memory. >+ * >+ * @return <code>true</code> if this completion context is an extended context. >+ * >+ * @since 3.4 >+ */ >+ public boolean isExtended() { >+ return this.isExtended; >+ } >+ >+ /** >+ * Tell user whether completion takes place in a javadoc comment or not. >+ * >+ * @return boolean true if completion takes place in a javadoc comment, false otherwise. >+ * @since 3.2 >+ */ >+ public boolean isInJavadoc() { >+ return this.javadoc != 0; >+ } >+ >+ /** >+ * Tell user whether completion takes place in a formal reference of a javadoc tag or not. >+ * Tags with formal reference are: >+ * <ul> >+ * <li>@see</li> >+ * <li>@throws</li> >+ * <li>@exception</li> >+ * <li>{@link Object}</li> >+ * <li>{@linkplain Object}</li> >+ * <li>{@value} when compiler compliance is set at leats to 1.5</li> >+ * </ul> >+ * >+ * @return boolean true if completion takes place in formal reference of a javadoc tag, false otherwise. >+ * @since 3.2 >+ */ >+ public boolean isInJavadocFormalReference() { >+ return (this.javadoc & CompletionOnJavadoc.FORMAL_REFERENCE) != 0; >+ } >+ >+ /** >+ * Tell user whether completion takes place in text area of a javadoc comment or not. >+ * >+ * @return boolean true if completion takes place in a text area of a javadoc comment, false otherwise. >+ * @since 3.2 >+ */ >+ public boolean isInJavadocText() { >+ return (this.javadoc & CompletionOnJavadoc.TEXT) != 0; >+ } > } >Index: codeassist/org/eclipse/jdt/internal/codeassist/CompletionEngine.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/codeassist/org/eclipse/jdt/internal/codeassist/CompletionEngine.java,v >retrieving revision 1.371 >diff -u -r1.371 CompletionEngine.java >--- codeassist/org/eclipse/jdt/internal/codeassist/CompletionEngine.java 8 Jul 2008 13:29:04 -0000 1.371 >+++ codeassist/org/eclipse/jdt/internal/codeassist/CompletionEngine.java 1 Sep 2008 09:12:54 -0000 >@@ -868,7 +868,7 @@ > CompilationUnitDeclaration compilationUnitDeclaration, > Binding qualifiedBinding, > Scope scope) { >- CompletionContext context = new CompletionContext(); >+ InternalCompletionContext context = new InternalCompletionContext(); > if (this.requestor.isExtendedContextRequired()) { > context.setExtendedData( > this.typeRoot, >@@ -938,7 +938,7 @@ > this.requestor.acceptContext(context); > } > >- private void buildTokenLocationContext(CompletionContext context, Scope scope, ASTNode astNode, ASTNode astNodeParent) { >+ private void buildTokenLocationContext(InternalCompletionContext context, Scope scope, ASTNode astNode, ASTNode astNodeParent) { > if (scope == null || context.isInJavadoc()) return; > > if (astNode instanceof CompletionOnFieldType) { >@@ -2311,7 +2311,7 @@ > if(this.noProposal && this.problem != null) { > if(!contextAccepted) { > contextAccepted = true; >- CompletionContext context = new CompletionContext(); >+ InternalCompletionContext context = new InternalCompletionContext(); > if (this.requestor.isExtendedContextRequired()) context.setExtended(); > this.requestor.acceptContext(context); > } >@@ -2346,7 +2346,7 @@ > } > if(!contextAccepted) { > contextAccepted = true; >- CompletionContext context = new CompletionContext(); >+ InternalCompletionContext context = new InternalCompletionContext(); > if (this.requestor.isExtendedContextRequired()) context.setExtended(); > this.requestor.acceptContext(context); > } >@@ -2567,7 +2567,7 @@ > if(this.noProposal && this.problem != null) { > if(!contextAccepted) { > contextAccepted = true; >- CompletionContext context = new CompletionContext(); >+ InternalCompletionContext context = new InternalCompletionContext(); > context.setOffset(completionPosition - this.offset); > context.setTokenKind(CompletionContext.TOKEN_KIND_UNKNOWN); > if (this.requestor.isExtendedContextRequired()) context.setExtended(); >@@ -2613,7 +2613,7 @@ > reset(); > if(!contextAccepted) { > contextAccepted = true; >- CompletionContext context = new CompletionContext(); >+ InternalCompletionContext context = new InternalCompletionContext(); > context.setTokenKind(CompletionContext.TOKEN_KIND_UNKNOWN); > context.setOffset(completionPosition - this.offset); > if (this.requestor.isExtendedContextRequired()) context.setExtended(); >Index: model/org/eclipse/jdt/core/CompletionContext.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/model/org/eclipse/jdt/core/CompletionContext.java,v >retrieving revision 1.16 >diff -u -r1.16 CompletionContext.java >--- model/org/eclipse/jdt/core/CompletionContext.java 27 Jun 2008 16:04:01 -0000 1.16 >+++ model/org/eclipse/jdt/core/CompletionContext.java 1 Sep 2008 09:12:54 -0000 >@@ -10,9 +10,6 @@ > *******************************************************************************/ > package org.eclipse.jdt.core; > >-import org.eclipse.jdt.internal.codeassist.InternalCompletionContext; >-import org.eclipse.jdt.internal.codeassist.complete.CompletionOnJavadoc; >- > /** > * Completion context. > * >@@ -22,7 +19,7 @@ > * @since 3.1 > * @noinstantiate This class is not intended to be instantiated by clients. > */ >-public final class CompletionContext extends InternalCompletionContext { >+public class CompletionContext { > > /** > * The completed token is the first token of a member declaration.<br> >@@ -82,7 +79,7 @@ > * @since 3.2 > */ > public boolean isInJavadoc() { >- return this.javadoc != 0; >+ return false; // default overridden by concrete implementation > } > > /** >@@ -91,8 +88,8 @@ > * @return boolean true if completion takes place in a text area of a javadoc comment, false otherwise. > * @since 3.2 > */ >- public boolean isInJavadocText() { >- return (this.javadoc & CompletionOnJavadoc.TEXT) != 0; >+ public boolean isInJavadocText() { >+ return false; // default overridden by concrete implementation > } > > /** >@@ -111,7 +108,7 @@ > * @since 3.2 > */ > public boolean isInJavadocFormalReference() { >- return (this.javadoc & CompletionOnJavadoc.FORMAL_REFERENCE) != 0; >+ return false; // default overridden by concrete implementation > } > > /** >@@ -123,7 +120,7 @@ > * @since 3.4 > */ > public boolean isExtended() { >- return this.isExtended; >+ return false; // default overridden by concrete implementation > } > > /** >@@ -137,8 +134,9 @@ > * @see Signature > */ > public char[][] getExpectedTypesSignatures() { >- return this.expectedTypesSignatures; >+ return null; // default overridden by concrete implementation > } >+ > /** > * Return keys of expected types of a potential completion proposal at the completion position. > * >@@ -150,7 +148,7 @@ > * @see org.eclipse.jdt.core.dom.ASTParser#createASTs(ICompilationUnit[], String[], org.eclipse.jdt.core.dom.ASTRequestor, org.eclipse.core.runtime.IProgressMonitor) > */ > public char[][] getExpectedTypesKeys() { >- return this.expectedTypesKeys; >+ return null; // default overridden by concrete implementation > } > > /** >@@ -165,7 +163,7 @@ > * @since 3.2 > */ > public char[] getToken() { >- return this.token; >+ return null; // default overridden by concrete implementation > } > > /** >@@ -184,7 +182,7 @@ > * @since 3.2 > */ > public int getTokenKind() { >- return this.tokenKind; >+ return -1; // default overridden by concrete implementation > } > > /** >@@ -205,7 +203,7 @@ > * @since 3.4 > */ > public int getTokenLocation() { >- return this.tokenLocation; >+ return -1; // default overridden by concrete implementation > } > > /** >@@ -223,7 +221,7 @@ > * @since 3.2 > */ > public int getTokenStart() { >- return this.tokenStart; >+ return -1; // default overridden by concrete implementation > } > > /** >@@ -238,7 +236,7 @@ > */ > // TODO (david) https://bugs.eclipse.org/bugs/show_bug.cgi?id=132558 > public int getTokenEnd() { >- return this.tokenEnd; >+ return -1; // default overridden by concrete implementation > } > > /** >@@ -249,7 +247,7 @@ > * @since 3.2 > */ > public int getOffset() { >- return this.offset; >+ return -1; // default overridden by concrete implementation > } > > /** >@@ -275,11 +273,7 @@ > * @since 3.4 > */ > public IJavaElement getEnclosingElement() { >- if (!this.isExtended) throw new UnsupportedOperationException("Operation only supported in extended context"); //$NON-NLS-1$ >- >- if (this.extendedContext == null) return null; >- >- return this.extendedContext.getEnclosingElement(); >+ return null; // default overridden by concrete implementation > } > > /** >@@ -320,84 +314,7 @@ > * @since 3.4 > */ > public IJavaElement[] getVisibleElements(String typeSignature) { >- if (!this.isExtended) throw new UnsupportedOperationException("Operation only supported in extended context"); //$NON-NLS-1$ >- >- if (this.extendedContext == null) return new IJavaElement[0]; >- >- return this.extendedContext.getVisibleElements(typeSignature); >+ return null; // default overridden by concrete implementation > } > >- public String toString() { >- StringBuffer buffer = new StringBuffer(); >- >- buffer.append("completion offset="); //$NON-NLS-1$ >- buffer.append(this.offset); >- buffer.append('\n'); >- >- buffer.append("completion range=["); //$NON-NLS-1$ >- buffer.append(this.tokenStart); >- buffer.append(", "); //$NON-NLS-1$ >- buffer.append(this.tokenEnd); >- buffer.append("]\n"); //$NON-NLS-1$ >- >- buffer.append("completion token="); //$NON-NLS-1$ >- String string = "null"; //$NON-NLS-1$ >- if(this.token == null) { >- buffer.append(string); >- } else { >- buffer.append('\"'); >- buffer.append(this.token); >- buffer.append('\"'); >- } >- buffer.append('\n'); >- >- buffer.append("expectedTypesSignatures="); //$NON-NLS-1$ >- if(this.expectedTypesSignatures == null) { >- buffer.append(string); >- } else { >- buffer.append('{'); >- for (int i = 0; i < this.expectedTypesSignatures.length; i++) { >- if(i > 0) buffer.append(','); >- buffer.append(this.expectedTypesSignatures[i]); >- >- } >- buffer.append('}'); >- } >- buffer.append('\n'); >- >- buffer.append("expectedTypesKeys="); //$NON-NLS-1$ >- if(this.expectedTypesSignatures == null) { >- buffer.append(string); >- } else { >- buffer.append('{'); >- for (int i = 0; i < this.expectedTypesKeys.length; i++) { >- if(i > 0) buffer.append(','); >- buffer.append(this.expectedTypesKeys[i]); >- >- } >- buffer.append('}'); >- } >- buffer.append('\n'); >- >- if (this.tokenLocation == 0) { >- buffer.append("tokenLocation=UNKNOWN"); //$NON-NLS-1$ >- } else { >- buffer.append("tokenLocation={"); //$NON-NLS-1$ >- boolean first = true; >- if ((this.tokenLocation & CompletionContext.TL_MEMBER_START) != 0) { >- if (!first) buffer.append(','); >- buffer.append("MEMBER_START"); //$NON-NLS-1$ >- first = false; >- } >- if ((this.tokenLocation & CompletionContext.TL_STATEMENT_START) != 0) { >- if (!first) buffer.append(','); >- buffer.append("STATEMENT_START"); //$NON-NLS-1$ >- first = false; >- } >- buffer.append('}'); >- } >- buffer.append('\n'); >- >- return buffer.toString(); >- } > }
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 245835
: 111389