Search in sources :

Example 1 with Extension

use of lombok.eclipse.agent.PatchExtensionMethod.Extension in project lombok by rzwitserloot.

the class PatchExtensionMethodCompletionProposal method getExtensionMethods.

private static List<Extension> getExtensionMethods(CompletionProposalCollector completionProposalCollector) {
    List<Extension> extensions = new ArrayList<Extension>();
    ClassScope classScope = getClassScope(completionProposalCollector);
    if (classScope != null) {
        TypeDeclaration decl = classScope.referenceContext;
        TypeBinding firstParameterType = getFirstParameterType(decl, completionProposalCollector);
        for (EclipseNode typeNode = getTypeNode(decl); typeNode != null; typeNode = upToType(typeNode)) {
            Annotation ann = getAnnotation(ExtensionMethod.class, typeNode);
            extensions.addAll(0, getApplicableExtensionMethods(typeNode, ann, firstParameterType));
        }
    }
    return extensions;
}
Also used : Extension(lombok.eclipse.agent.PatchExtensionMethod.Extension) TypeBinding(org.eclipse.jdt.internal.compiler.lookup.TypeBinding) ArrayList(java.util.ArrayList) EclipseNode(lombok.eclipse.EclipseNode) TypeDeclaration(org.eclipse.jdt.internal.compiler.ast.TypeDeclaration) Annotation(org.eclipse.jdt.internal.compiler.ast.Annotation) ClassScope(org.eclipse.jdt.internal.compiler.lookup.ClassScope)

Example 2 with Extension

use of lombok.eclipse.agent.PatchExtensionMethod.Extension in project lombok by rzwitserloot.

the class PatchExtensionMethodCompletionProposal method getJavaCompletionProposals.

public static IJavaCompletionProposal[] getJavaCompletionProposals(IJavaCompletionProposal[] javaCompletionProposals, CompletionProposalCollector completionProposalCollector) {
    List<IJavaCompletionProposal> proposals = new ArrayList<IJavaCompletionProposal>(Arrays.asList(javaCompletionProposals));
    if (canExtendCodeAssist(proposals)) {
        IJavaCompletionProposal firstProposal = proposals.get(0);
        int replacementOffset = getReplacementOffset(firstProposal);
        for (Extension extension : getExtensionMethods(completionProposalCollector)) {
            for (MethodBinding method : extension.extensionMethods) {
                ExtensionMethodCompletionProposal newProposal = new ExtensionMethodCompletionProposal(replacementOffset);
                copyNameLookupAndCompletionEngine(completionProposalCollector, firstProposal, newProposal);
                ASTNode node = getAssistNode(completionProposalCollector);
                newProposal.setMethodBinding(method, node);
                createAndAddJavaCompletionProposal(completionProposalCollector, newProposal, proposals);
            }
        }
    }
    return proposals.toArray(new IJavaCompletionProposal[proposals.size()]);
}
Also used : Extension(lombok.eclipse.agent.PatchExtensionMethod.Extension) ArrayList(java.util.ArrayList) ASTNode(org.eclipse.jdt.internal.compiler.ast.ASTNode) MethodBinding(org.eclipse.jdt.internal.compiler.lookup.MethodBinding) IJavaCompletionProposal(org.eclipse.jdt.ui.text.java.IJavaCompletionProposal)

Aggregations

ArrayList (java.util.ArrayList)2 Extension (lombok.eclipse.agent.PatchExtensionMethod.Extension)2 EclipseNode (lombok.eclipse.EclipseNode)1 ASTNode (org.eclipse.jdt.internal.compiler.ast.ASTNode)1 Annotation (org.eclipse.jdt.internal.compiler.ast.Annotation)1 TypeDeclaration (org.eclipse.jdt.internal.compiler.ast.TypeDeclaration)1 ClassScope (org.eclipse.jdt.internal.compiler.lookup.ClassScope)1 MethodBinding (org.eclipse.jdt.internal.compiler.lookup.MethodBinding)1 TypeBinding (org.eclipse.jdt.internal.compiler.lookup.TypeBinding)1 IJavaCompletionProposal (org.eclipse.jdt.ui.text.java.IJavaCompletionProposal)1