Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix more CompletionContextTests (down to 43) #1039

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ public int getTokenLocation() {
return getTokenStart() == stmt.getStartPosition() ? TL_STATEMENT_START : 0;
}
if (parent instanceof BodyDeclaration member) {
return getTokenStart() == member.getStartPosition() ? TL_MEMBER_START : 0;
return (member.getParent() instanceof AbstractTypeDeclaration || member.getParent() instanceof AnonymousClassDeclaration) && getTokenStart() == member.getStartPosition() ? TL_MEMBER_START : 0;
}
if (parent instanceof Block block) {
return block.statements().isEmpty() ? TL_STATEMENT_START : 0;
Expand All @@ -195,15 +195,18 @@ public int getTokenLocation() {

@Override
public int getTokenStart() {
if (node instanceof SimpleName name && !Arrays.equals(name.getIdentifier().toCharArray(), RecoveryScanner.FAKE_IDENTIFIER)) {
return node.getStartPosition();
if (this.node instanceof StringLiteral) {
return this.node.getStartPosition();
}
if (this.node instanceof SimpleName name && !Arrays.equals(name.getIdentifier().toCharArray(), RecoveryScanner.FAKE_IDENTIFIER)) {
return this.node.getStartPosition();
}
return this.offset - getToken().length;
}
@Override
public int getTokenEnd() {
if (node instanceof SimpleName) {
return node.getStartPosition() + node.getLength() - 1;
if (this.node instanceof SimpleName || this.node instanceof StringLiteral) {
return this.node.getStartPosition() + this.node.getLength() - 1;
}
int position = this.offset;
while (position <= this.cuBuffer.getLength() && Character.isJavaIdentifierPart(this.cuBuffer.getChar(position))) {
Expand All @@ -212,9 +215,13 @@ public int getTokenEnd() {
return position - 1;
}

private boolean isOpen(StringLiteral literal) {
return this.cuBuffer.getChar(literal.getStartPosition() + literal.getLength() - 1) == '"';
}

@Override
public int getTokenKind() {
return node instanceof StringLiteral ? TOKEN_KIND_STRING_LITERAL : TOKEN_KIND_NAME;
return this.node instanceof StringLiteral ? TOKEN_KIND_STRING_LITERAL : TOKEN_KIND_NAME;
}

/// adapted from org.eclipse.jdt.internal.codeassist.InternalExtendedCompletionContext
Expand Down
Loading