Skip to content

Commit

Permalink
Add annotation hack to fix tests
Browse files Browse the repository at this point in the history
Signed-off-by: Rob Stryker <rob@oxbeef.net>
  • Loading branch information
robstryker committed Feb 6, 2024
1 parent 80162c7 commit 395d5e9
Showing 1 changed file with 79 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,12 @@
import org.eclipse.core.runtime.CoreException;
import org.eclipse.jdt.core.ICompilationUnit;
import org.eclipse.jdt.core.IJavaElement;
import org.eclipse.jdt.core.compiler.IProblem;
import org.eclipse.jdt.core.dom.ASTNode;
import org.eclipse.jdt.core.dom.CompilationUnit;
import org.eclipse.jdt.core.dom.IVariableBinding;
import org.eclipse.jdt.core.dom.Name;
import org.eclipse.jdt.core.dom.NodeFinder;
import org.eclipse.jdt.core.manipulation.ChangeCorrectionProposalCore;
import org.eclipse.jdt.core.manipulation.TypeKinds;
import org.eclipse.jdt.internal.ui.text.correction.IInvocationContextCore;
Expand All @@ -42,6 +46,7 @@
import org.eclipse.jdt.internal.ui.text.correction.proposals.QualifyTypeProposalCore;
import org.eclipse.jdt.internal.ui.text.correction.proposals.RenameNodeCorrectionProposalCore;
import org.eclipse.jdt.internal.ui.text.correction.proposals.ReplaceCorrectionProposalCore;
import org.eclipse.jdt.ls.core.internal.JavaLanguageServerPlugin;
import org.eclipse.jdt.ls.core.internal.corrections.ProposalKindWrapper;
import org.eclipse.jdt.ls.core.internal.handlers.CodeActionHandler;
import org.eclipse.jdt.ui.text.java.correction.ASTRewriteCorrectionProposalCore;
Expand Down Expand Up @@ -276,4 +281,78 @@ protected ProposalKindWrapper renameNodeProposalToT(RenameNodeCorrectionProposal
return CodeActionHandler.wrap(core, CodeActionKind.QuickFix);
}

@Override
public void collectTypeProposals(IInvocationContextCore context, IProblemLocationCore problem, Collection<ProposalKindWrapper> proposals) throws CoreException {
// This is a hack because upstream does not behave as we expect.
IProblemLocationCore wrap = new ProblemLocationWrapper(problem) {
@Override
public ASTNode getCoveringNode(CompilationUnit astRoot) {
ICompilationUnit cu = context.getCompilationUnit();
ASTNode selectedNode = problem.getCoveringNode(context.getASTRoot());
try {
if (problem.getProblemId() == IProblem.UndefinedType && cu.getBuffer() != null && cu.getBuffer().getChar(problem.getOffset()) == '@') {
int offset = problem.getOffset() + 1;
int length = problem.getLength() - 1;
while (offset < cu.getBuffer().getLength() && length >= 0 && Character.isWhitespace(cu.getBuffer().getChar(offset))) {
offset++;
length--;
}
NodeFinder finder = new NodeFinder(context.getASTRoot(), offset, length);
selectedNode = finder.getCoveringNode();
}
} catch (CoreException ce) {
JavaLanguageServerPlugin.log(ce);
}
return selectedNode;
}
};
super.collectTypeProposals(context, wrap, proposals);
}

private class ProblemLocationWrapper implements IProblemLocationCore {
private IProblemLocationCore delegate;

public ProblemLocationWrapper(IProblemLocationCore del) {
this.delegate = del;
}

@Override
public int getOffset() {
return this.delegate.getOffset();
}

@Override
public int getLength() {
return this.delegate.getLength();
}

@Override
public String getMarkerType() {
return this.delegate.getMarkerType();
}

@Override
public int getProblemId() {
return this.delegate.getProblemId();
}

@Override
public String[] getProblemArguments() {
return this.delegate.getProblemArguments();
}

@Override
public boolean isError() {
return this.delegate.isError();
}

@Override
public ASTNode getCoveringNode(CompilationUnit astRoot) {
return this.delegate.getCoveringNode(astRoot);
}
@Override
public ASTNode getCoveredNode(CompilationUnit astRoot) {
return this.delegate.getCoveredNode(astRoot);
}
}
}

0 comments on commit 395d5e9

Please sign in to comment.