package org.eclipse.jdt.internal.codeassist;
import org.eclipse.jdt.core.CompletionContext;
import org.eclipse.jdt.core.IJavaElement;
import org.eclipse.jdt.core.ITypeRoot;
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;
import org.eclipse.jdt.internal.compiler.lookup.FieldBinding;
import org.eclipse.jdt.internal.compiler.lookup.LocalVariableBinding;
import org.eclipse.jdt.internal.compiler.lookup.LookupEnvironment;
import org.eclipse.jdt.internal.compiler.lookup.MethodBinding;
import org.eclipse.jdt.internal.compiler.lookup.Scope;
import org.eclipse.jdt.internal.compiler.util.ObjectVector;
public class InternalCompletionContext extends CompletionContext {
protected char[][] expectedTypesSignatures;
protected char[][] expectedTypesKeys;
protected int javadoc;
protected int offset = -1;
protected int tokenStart = -1;
protected int tokenEnd = -1;
protected char[] token = null;
protected int tokenKind;
protected int tokenLocation;
protected boolean isExtended;
protected InternalExtendedCompletionContext extendedContext;
protected void setExpectedTypesKeys(char[][] expectedTypesKeys) {
this.expectedTypesKeys = expectedTypesKeys;
}
protected void setExpectedTypesSignatures(char[][] expectedTypesSignatures) {
this.expectedTypesSignatures = expectedTypesSignatures;
}
protected void setExtended() {
this.isExtended = true;
}
protected void setExtendedData(
ITypeRoot typeRoot,
CompilationUnitDeclaration compilationUnitDeclaration,
LookupEnvironment lookupEnvironment,
Scope scope,
ASTNode astNode,
ASTNode astNodeParent,
WorkingCopyOwner owner,
CompletionParser parser) {
this.isExtended = true;
this.extendedContext =
new InternalExtendedCompletionContext(
this,
typeRoot,
compilationUnitDeclaration,
lookupEnvironment,
scope,
astNode,
astNodeParent,
owner,
parser);
}
protected void setJavadoc(int javadoc) {
this.javadoc = javadoc;
}
protected void setOffset(int offset) {
this.offset = offset;
}
protected void setToken(char[] token) {
this.token = token;
}
protected void setTokenKind(int tokenKind) {
this.tokenKind = tokenKind;
}
protected void setTokenLocation(int tokenLocation) {
this.tokenLocation = tokenLocation;
}
protected void setTokenRange(int start, int end) {
this.setTokenRange(start, end, -1);
}
protected void setTokenRange(int start, int end, int endOfEmptyToken) {
this.tokenStart = start;
this.tokenEnd = endOfEmptyToken > end ? endOfEmptyToken : end;
if(this.tokenEnd == -1) {
this.tokenEnd = 0;
}
}
@Override
public IJavaElement getEnclosingElement() {
if (!this.isExtended) throw new UnsupportedOperationException("Operation only supported in extended context");
if (this.extendedContext == null) return null;
return this.extendedContext.getEnclosingElement();
}
@Override
public char[][] getExpectedTypesKeys() {
return this.expectedTypesKeys;
}
@Override
public char[][] getExpectedTypesSignatures() {
return this.expectedTypesSignatures;
}
@Override
public int getOffset() {
return this.offset;
}
@Override
public char[] getToken() {
return this.token;
}
@Override
public int getTokenEnd() {
return this.tokenEnd;
}
@Override
public int getTokenKind() {
return this.tokenKind;
}
@Override
public int getTokenLocation() {
return this.tokenLocation;
}
@Override
public int getTokenStart() {
return this.tokenStart;
}
@Override
public IJavaElement[] getVisibleElements(String typeSignature) {
if (!this.isExtended) throw new UnsupportedOperationException("Operation only supported in extended context");
if (this.extendedContext == null) return new IJavaElement[0];
return this.extendedContext.getVisibleElements(typeSignature);
}
@Override
public boolean isExtended() {
return this.isExtended;
}
@Override
public boolean isInJavadoc() {
return this.javadoc != 0;
}
@Override
public boolean isInJavadocFormalReference() {
return (this.javadoc & CompletionOnJavadoc.FORMAL_REFERENCE) != 0;
}
@Override
public boolean isInJavadocText() {
return (this.javadoc & CompletionOnJavadoc.TEXT) != 0;
}
public ASTNode getCompletionNode() {
if (!this.isExtended) throw new UnsupportedOperationException("Operation only supported in extended context");
if (this.extendedContext == null) return null;
return this.extendedContext.getCompletionNode();
}
public ASTNode getCompletionNodeParent() {
if (!this.isExtended) throw new UnsupportedOperationException("Operation only supported in extended context");
if (this.extendedContext == null) return null;
return this.extendedContext.getCompletionNodeParent();
}
public ObjectVector getVisibleLocalVariables() {
if (!this.isExtended) throw new UnsupportedOperationException("Operation only supported in extended context");
if (this.extendedContext == null) return null;
return this.extendedContext.getVisibleLocalVariables();
}
public ObjectVector getVisibleFields() {
if (!this.isExtended) throw new UnsupportedOperationException("Operation only supported in extended context");
if (this.extendedContext == null) return null;
return this.extendedContext.getVisibleFields();
}
public ObjectVector getVisibleMethods() {
if (!this.isExtended) throw new UnsupportedOperationException("Operation only supported in extended context");
if (this.extendedContext == null) return null;
return this.extendedContext.getVisibleMethods();
}
}