Skip to content

Commit

Permalink
Fix for #1059: add quick fix for inaccessible type
Browse files Browse the repository at this point in the history
  • Loading branch information
eric-milles committed Mar 30, 2020
1 parent bf57f8c commit ec41d7f
Showing 1 changed file with 29 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ class GroovyQuickFixProcessor implements IQuickFixProcessor {
0,
IProblem.UndefinedType,
IProblem.IsClassPathCorrect,
IProblem.NotAccessibleType,
IProblem.ParsingError,
IProblem.ParsingErrorInsertTokenAfter,
IProblem.ParsingErrorInsertToComplete,
Expand Down Expand Up @@ -93,6 +94,8 @@ class GroovyQuickFixProcessor implements IQuickFixProcessor {

addChangeModifierProposals(context, locations, proposals)

addRequiresModuleProposals(context, locations, proposals)

addUnimplementedMethodsProposals(context, locations, proposals)
} else {
if (locations.any(MakeJavaGroovyProposal.&appliesTo)) {
Expand Down Expand Up @@ -142,6 +145,32 @@ class GroovyQuickFixProcessor implements IQuickFixProcessor {
}
}

@CompileDynamic
private void addRequiresModuleProposals(IInvocationContext context, IProblemLocation[] locations, Collection<IJavaCompletionProposal> proposals) {
Collection<org.eclipse.jdt.core.dom.Name> names = Arrays.asList(locations).findResults {
if (it.problemId == IProblem.IsClassPathCorrect || it.problemId == IProblem.NotAccessibleType || it.problemId == IProblem.UndefinedType) {
def root = context.ASTRoot, node = it.getCoveredNode(root) ?: it.getCoveringNode(root)
if (!(node instanceof org.eclipse.jdt.core.dom.Name)) {
String[] tokens = it.problemArguments[0].split(/\./)
org.eclipse.jdt.core.dom.Name name = root.AST.newSimpleName(tokens[0])
for (i in 1..<tokens.length) {
name = root.AST.newQualifiedName(name, root.AST.newSimpleName(tokens[i]))
}
return name
}
}
}

if (!names) return

names.each { name ->
org.eclipse.jdt.internal.ui.text.correction.UnresolvedElementsSubProcessor.addRequiresModuleProposals(context.compilationUnit,
name, org.eclipse.jdt.internal.ui.text.correction.IProposalRelevance.IMPORT_NOT_FOUND_ADD_REQUIRES_MODULE, proposals, true)
}

proposals.unique { proposal -> proposal.displayString }
}

@CompileDynamic
private void addUnimplementedMethodsProposals(IInvocationContext context, IProblemLocation[] locations, Collection<IJavaCompletionProposal> proposals) {
for (location in locations) {
Expand Down

0 comments on commit ec41d7f

Please sign in to comment.