Search in sources :

Example 1 with ClassScope

use of org.eclipse.jdt.internal.compiler.lookup.ClassScope 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 ClassScope

use of org.eclipse.jdt.internal.compiler.lookup.ClassScope in project lombok by rzwitserloot.

the class PatchExtensionMethodCompletionProposal method getClassScope.

private static ClassScope getClassScope(CompletionProposalCollector completionProposalCollector) {
    ClassScope scope = null;
    try {
        InternalCompletionContext context = (InternalCompletionContext) Reflection.contextField.get(completionProposalCollector);
        InternalExtendedCompletionContext extendedContext = (InternalExtendedCompletionContext) Reflection.extendedContextField.get(context);
        if (extendedContext != null) {
            Scope assistScope = ((Scope) Reflection.assistScopeField.get(extendedContext));
            if (assistScope != null) {
                scope = assistScope.classScope();
            }
        }
    } catch (IllegalAccessException ignore) {
    // ignore
    }
    return scope;
}
Also used : InternalCompletionContext(org.eclipse.jdt.internal.codeassist.InternalCompletionContext) ClassScope(org.eclipse.jdt.internal.compiler.lookup.ClassScope) Scope(org.eclipse.jdt.internal.compiler.lookup.Scope) InternalExtendedCompletionContext(org.eclipse.jdt.internal.codeassist.InternalExtendedCompletionContext) ClassScope(org.eclipse.jdt.internal.compiler.lookup.ClassScope)

Example 3 with ClassScope

use of org.eclipse.jdt.internal.compiler.lookup.ClassScope in project lombok by rzwitserloot.

the class PatchDelegate method addAllMethodBindings0.

private static void addAllMethodBindings0(List<BindingTuple> list, TypeBinding binding, Set<String> banList, char[] fieldName, ASTNode responsible) throws DelegateRecursion {
    if (binding instanceof SourceTypeBinding) {
        ClassScope scope = ((SourceTypeBinding) binding).scope;
        if (scope != null)
            scope.environment().globalOptions.storeAnnotations = true;
    }
    if (binding == null)
        return;
    TypeBinding inner;
    if (binding instanceof ParameterizedTypeBinding) {
        inner = ((ParameterizedTypeBinding) binding).genericType();
    } else {
        inner = binding;
    }
    if (inner instanceof SourceTypeBinding) {
        ClassScope cs = ((SourceTypeBinding) inner).scope;
        if (cs != null) {
            try {
                Reflection.classScopeBuildFieldsAndMethodsMethod.invoke(cs);
            } catch (Exception e) {
            // See 'Reflection' class for why we ignore this exception.
            }
        }
    }
    if (!(binding instanceof ReferenceBinding)) {
        return;
    }
    ReferenceBinding rb = (ReferenceBinding) binding;
    MethodBinding[] availableMethods = rb.availableMethods();
    FieldBinding[] availableFields = rb.availableFields();
    failIfContainsAnnotation(binding, availableMethods);
    failIfContainsAnnotation(binding, availableFields);
    MethodBinding[] parameterizedSigs = availableMethods;
    MethodBinding[] baseSigs = parameterizedSigs;
    if (binding instanceof ParameterizedTypeBinding) {
        baseSigs = ((ParameterizedTypeBinding) binding).genericType().availableMethods();
        if (baseSigs.length != parameterizedSigs.length) {
            // The last known state of eclipse source says this can't happen, so we rely on it,
            // but if this invariant is broken, better to go with 'arg0' naming instead of crashing.
            baseSigs = parameterizedSigs;
        }
    }
    for (int i = 0; i < parameterizedSigs.length; i++) {
        MethodBinding mb = parameterizedSigs[i];
        String sig = printSig(mb);
        if (mb.isStatic())
            continue;
        if (mb.isBridge())
            continue;
        if (mb.isConstructor())
            continue;
        if (mb.isDefaultAbstract())
            continue;
        if (!mb.isPublic())
            continue;
        if (mb.isSynthetic())
            continue;
        // If add returns false, it was already in there.
        if (!banList.add(sig))
            continue;
        BindingTuple pair = new BindingTuple(mb, baseSigs[i], fieldName, responsible);
        list.add(pair);
    }
    addAllMethodBindings0(list, rb.superclass(), banList, fieldName, responsible);
    ReferenceBinding[] interfaces = rb.superInterfaces();
    if (interfaces != null) {
        for (ReferenceBinding iface : interfaces) addAllMethodBindings0(list, iface, banList, fieldName, responsible);
    }
}
Also used : ParameterizedTypeBinding(org.eclipse.jdt.internal.compiler.lookup.ParameterizedTypeBinding) ParameterizedTypeBinding(org.eclipse.jdt.internal.compiler.lookup.ParameterizedTypeBinding) TypeBinding(org.eclipse.jdt.internal.compiler.lookup.TypeBinding) SourceTypeBinding(org.eclipse.jdt.internal.compiler.lookup.SourceTypeBinding) BaseTypeBinding(org.eclipse.jdt.internal.compiler.lookup.BaseTypeBinding) UnresolvedReferenceBinding(org.eclipse.jdt.internal.compiler.lookup.UnresolvedReferenceBinding) ReferenceBinding(org.eclipse.jdt.internal.compiler.lookup.ReferenceBinding) ClassScope(org.eclipse.jdt.internal.compiler.lookup.ClassScope) FieldBinding(org.eclipse.jdt.internal.compiler.lookup.FieldBinding) MethodBinding(org.eclipse.jdt.internal.compiler.lookup.MethodBinding) SourceTypeBinding(org.eclipse.jdt.internal.compiler.lookup.SourceTypeBinding)

Aggregations

ClassScope (org.eclipse.jdt.internal.compiler.lookup.ClassScope)3 TypeBinding (org.eclipse.jdt.internal.compiler.lookup.TypeBinding)2 ArrayList (java.util.ArrayList)1 EclipseNode (lombok.eclipse.EclipseNode)1 Extension (lombok.eclipse.agent.PatchExtensionMethod.Extension)1 InternalCompletionContext (org.eclipse.jdt.internal.codeassist.InternalCompletionContext)1 InternalExtendedCompletionContext (org.eclipse.jdt.internal.codeassist.InternalExtendedCompletionContext)1 Annotation (org.eclipse.jdt.internal.compiler.ast.Annotation)1 TypeDeclaration (org.eclipse.jdt.internal.compiler.ast.TypeDeclaration)1 BaseTypeBinding (org.eclipse.jdt.internal.compiler.lookup.BaseTypeBinding)1 FieldBinding (org.eclipse.jdt.internal.compiler.lookup.FieldBinding)1 MethodBinding (org.eclipse.jdt.internal.compiler.lookup.MethodBinding)1 ParameterizedTypeBinding (org.eclipse.jdt.internal.compiler.lookup.ParameterizedTypeBinding)1 ReferenceBinding (org.eclipse.jdt.internal.compiler.lookup.ReferenceBinding)1 Scope (org.eclipse.jdt.internal.compiler.lookup.Scope)1 SourceTypeBinding (org.eclipse.jdt.internal.compiler.lookup.SourceTypeBinding)1 UnresolvedReferenceBinding (org.eclipse.jdt.internal.compiler.lookup.UnresolvedReferenceBinding)1