From 59593d4e45e47ce9a80379240f77ae5d9bfaa3a2 Mon Sep 17 00:00:00 2001 From: Rob Stryker Date: Tue, 6 Feb 2024 16:36:10 -0500 Subject: [PATCH] Fix a test Signed-off-by: Rob Stryker --- .../proposals/ProblemLocationWrapper.java | 64 +++++++++++++++++++ .../proposals/TypeMismatchSubProcessor.java | 18 ++++++ .../UnresolvedElementsSubProcessor.java | 47 -------------- 3 files changed, 82 insertions(+), 47 deletions(-) create mode 100644 org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/corrections/proposals/ProblemLocationWrapper.java diff --git a/org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/corrections/proposals/ProblemLocationWrapper.java b/org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/corrections/proposals/ProblemLocationWrapper.java new file mode 100644 index 0000000000..6b148c0402 --- /dev/null +++ b/org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/corrections/proposals/ProblemLocationWrapper.java @@ -0,0 +1,64 @@ +/******************************************************************************* + * Copyright (c) 2024 Red Hat Inc. and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Red Hat Inc. - initial API and implementation + *******************************************************************************/ +package org.eclipse.jdt.ls.core.internal.corrections.proposals; + +import org.eclipse.jdt.core.dom.ASTNode; +import org.eclipse.jdt.core.dom.CompilationUnit; +import org.eclipse.jdt.internal.ui.text.correction.IProblemLocationCore; + +public 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); + } +} \ No newline at end of file diff --git a/org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/corrections/proposals/TypeMismatchSubProcessor.java b/org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/corrections/proposals/TypeMismatchSubProcessor.java index 375b3ae4de..8253674ab8 100644 --- a/org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/corrections/proposals/TypeMismatchSubProcessor.java +++ b/org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/corrections/proposals/TypeMismatchSubProcessor.java @@ -98,6 +98,24 @@ public static void addTypeMismatchInForEachProposals(IInvocationContextCore cont new TypeMismatchSubProcessor().collectTypeMismatchInForEachProposals(context, problem, proposals); } + @Override + public void collectTypeMismatchProposals(IInvocationContextCore context, IProblemLocationCore problem, Collection proposals) throws CoreException { + IProblemLocationCore wrapped = new ProblemLocationWrapper(problem) { + @Override + public String[] getProblemArguments() { + // This is a hack to get around superclass restrictions + String[] ret = super.getProblemArguments(); + if (ret == null || ret.length == 0) { + return new String[] { "", "" }; + } + if (ret.length == 1) { + return new String[] { ret[0], "" }; + } + return ret; + } + }; + super.collectTypeMismatchProposals(context, wrapped, proposals); + } /* (non-Javadoc) * @see org.eclipse.jdt.internal.ui.text.correction.TypeMismatchBaseSubProcessor#createInsertNullCheckProposal(java.lang.String, org.eclipse.jdt.core.ICompilationUnit, org.eclipse.jdt.core.dom.rewrite.ASTRewrite, int) */ diff --git a/org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/corrections/proposals/UnresolvedElementsSubProcessor.java b/org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/corrections/proposals/UnresolvedElementsSubProcessor.java index 0e9fbd8615..740a84c3b0 100644 --- a/org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/corrections/proposals/UnresolvedElementsSubProcessor.java +++ b/org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/corrections/proposals/UnresolvedElementsSubProcessor.java @@ -308,51 +308,4 @@ public ASTNode getCoveringNode(CompilationUnit astRoot) { }; 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); - } - } }