|
1 | 1 | /* |
2 | | - * Copyright 2009-2023 the original author or authors. |
| 2 | + * Copyright 2009-2024 the original author or authors. |
3 | 3 | * |
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
5 | 5 | * you may not use this file except in compliance with the License. |
|
17 | 17 |
|
18 | 18 | import org.codehaus.groovy.ast.AnnotatedNode; |
19 | 19 | import org.codehaus.groovy.ast.FieldNode; |
| 20 | +import org.codehaus.groovy.ast.MethodNode; |
20 | 21 | import org.codehaus.groovy.eclipse.codeassist.ProposalUtils; |
21 | 22 | import org.codehaus.groovy.eclipse.codeassist.completions.GroovyJavaFieldCompletionProposal; |
22 | 23 | import org.codehaus.groovy.eclipse.codeassist.processors.GroovyCompletionProposal; |
|
31 | 32 | import org.eclipse.jdt.groovy.search.VariableScope; |
32 | 33 | import org.eclipse.jdt.internal.codeassist.InternalCompletionProposal; |
33 | 34 | import org.eclipse.jdt.internal.codeassist.impl.AssistOptions; |
| 35 | +import org.eclipse.jdt.internal.ui.text.java.AbstractJavaCompletionProposal; |
| 36 | +import org.eclipse.jdt.internal.ui.text.java.MemberProposalInfo; |
| 37 | +import org.eclipse.jdt.internal.ui.text.java.ProposalInfo; |
34 | 38 | import org.eclipse.jdt.ui.text.java.IJavaCompletionProposal; |
35 | 39 | import org.eclipse.jdt.ui.text.java.JavaContentAssistInvocationContext; |
36 | 40 | import org.eclipse.jface.viewers.StyledString; |
@@ -105,7 +109,24 @@ public IJavaCompletionProposal createJavaProposal(ContentAssistContext context, |
105 | 109 | proposal.setRequiredProposals(new CompletionProposal[] {importProposal}); |
106 | 110 | } |
107 | 111 |
|
108 | | - return new GroovyJavaFieldCompletionProposal(proposal, createDisplayString(field), javaContext); |
| 112 | + var javaProposal = new GroovyJavaFieldCompletionProposal(proposal, createDisplayString(field), javaContext); |
| 113 | + var groovyMethod = field.<MethodNode>getNodeMetaData("groovy.method"); |
| 114 | + if (groovyMethod != null) { |
| 115 | + try { |
| 116 | + var type = javaContext.getProject().findType(groovyMethod.getDeclaringClass().getName()); |
| 117 | + if (type != null) { |
| 118 | + var method = type.getMethod(groovyMethod.getName(), GroovyUtils.getParameterTypeSignatures(groovyMethod, true)); |
| 119 | + if (method != null && method.exists()) { |
| 120 | + ProposalInfo proposalInfo = ReflectionUtils.executePrivateMethod(AbstractJavaCompletionProposal.class, "getProposalInfo", javaProposal); |
| 121 | + ReflectionUtils.throwableSetPrivateField(MemberProposalInfo.class, "fJavaElementResolved", proposalInfo, Boolean.TRUE); |
| 122 | + ReflectionUtils.throwableSetPrivateField(ProposalInfo.class, "fElement", proposalInfo, method); |
| 123 | + } |
| 124 | + } |
| 125 | + } catch (Exception e) { |
| 126 | + e.printStackTrace(); |
| 127 | + } |
| 128 | + } |
| 129 | + return javaProposal; |
109 | 130 | } |
110 | 131 |
|
111 | 132 | protected StyledString createDisplayString(FieldNode field) { |
|
0 commit comments